Exemple #1
0
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
{
	poco_assert (_fd == -1);

	_pos = 0;
	_path = path;
	setMode(mode);
	resetBuffers();

	int flags(0);
	if (mode & std::ios::trunc)
		flags |= O_TRUNC;
	if (mode & std::ios::app)
		flags |= O_APPEND;
	if (mode & std::ios::out)
		flags |= O_CREAT;
	if ((mode & std::ios::in) && (mode & std::ios::out))
		flags |= O_RDWR;
	else if (mode & std::ios::in)
		flags |= O_RDONLY;
	else
		flags |= O_WRONLY;
			
	_fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
	if (_fd == -1)
		File::handleLastError(_path);
		
	if ((mode & std::ios::app) || (mode & std::ios::ate))
		seekoff(0, std::ios::end, mode);
}
Exemple #2
0
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
{
	if (_fd == -1 || !(getMode() & mode)) 
		return -1;

	if (getMode() & std::ios::out)
		sync();

	std::streamoff adj;
	if (mode & std::ios::in)
		adj = static_cast<std::streamoff>(egptr() - gptr());
	else
		adj = 0;

	resetBuffers();

	int whence = SEEK_SET;
	if (dir == std::ios::cur)
	{
		whence = SEEK_CUR;
		off -= adj;
	}
	else if (dir == std::ios::end)
	{
		whence = SEEK_END;
	}
	_pos = lseek(_fd, off, whence);
	return _pos;
}
void KinectGrabber::setKinectROI(ofRectangle ROI){
    minX = static_cast<int>(ROI.getMinX());
    maxX = static_cast<int>(ROI.getMaxX());
    minY = static_cast<int>(ROI.getMinY());
    maxY = static_cast<int>(ROI.getMaxY());
    ROIwidth = maxX-minX;
    ROIheight = maxY-minY;
    resetBuffers();
}
Exemple #4
0
int main(int argc, char** argv) {

	saveBuffer.data = read_img("img.tif", &saveBuffer.w, &saveBuffer.h);

	if (saveBuffer.data == NULL) {
		printf("Error loading image file img.tif\n");
		return 1;
	}

	printf("Basic Functions: \n");
	printf("R: Reset \nS: Save \nQ: Quit  \n\n");

	printf("Display Functions: \n");
	printf("A: Only Red Channel   \nB: Only Blue Channel \n");
	printf("C: Channel Swap \nD: only Green Channel   \n");
	printf("G: Greyfilter \nM: Monochrome  \nN: Grey NTSC Filter  \n\n");

	printf("Basic Filter Functions:  \n");
	printf("E: Maximum Filter \nH: Minimum Filter  \nI: Intensify Red \n");
	printf("J: Intensify Blue \nK: Intensify Green \n\n");

	printf("Funny Filter Functions:   \n");
	printf("L: CrazyFilter \nO: Blur Filter \nP: Sobel Edge Detection \n");
	printf("U: MyFilter1  \nV: MyFilter2 \n");
	printf("W: Quantize Random   \nX: Qantize predefined Colors \n\n");

	printf("Other Stuff: \n");
	printf("F: Filter    \nT: Triangle  \n");
	printf("Y: Maikes Filter 1 \nZ: Maikes Filter 2\n\n");

	displayBuffer.h = saveBuffer.h;
	displayBuffer.w = saveBuffer.w;
	displayBuffer.data = (pixel *)malloc((saveBuffer.h)*(saveBuffer.w)*sizeof(pixel *));

	workBuffer.h = saveBuffer.h;
	workBuffer.w = saveBuffer.w;
	workBuffer.data = (pixel *)malloc((saveBuffer.h)*(saveBuffer.w)*sizeof(pixel *));

	resetBuffers();

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

	glutInitWindowSize(displayBuffer.w, displayBuffer.h);
	glutCreateWindow("Funny Stuff Happens Here"); // Window-Title
	glShadeModel(GL_SMOOTH);
	glutDisplayFunc(display_image); 
	glutKeyboardFunc(keyboard);
	glMatrixMode(GL_PROJECTION);
	glOrtho(0, displayBuffer.w, 0, displayBuffer.h, 0, 1);
	createMenu();

	glutMainLoop();

	return 0;
} //main
Exemple #5
0
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
{
	if (_fd == -1 || !(getMode() & mode)) 
		return -1;

	if (getMode() & std::ios::out)
		sync();

	resetBuffers();

	_pos = lseek(_fd, pos, SEEK_SET);
	return _pos;
}
serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallbackPtr callback, uint32_t baud, portOptions_t options)
{
    softSerial_t *softSerial = &(softSerialPorts[portIndex]);

#ifdef USE_SOFTSERIAL1
    if (portIndex == SOFTSERIAL1) {
        softSerial->rxTimerHardware = &(timerHardware[SOFTSERIAL_1_TIMER_RX_HARDWARE]);
        softSerial->txTimerHardware = &(timerHardware[SOFTSERIAL_1_TIMER_TX_HARDWARE]);
    }
#endif

#ifdef USE_SOFTSERIAL2
    if (portIndex == SOFTSERIAL2) {
        softSerial->rxTimerHardware = &(timerHardware[SOFTSERIAL_2_TIMER_RX_HARDWARE]);
        softSerial->txTimerHardware = &(timerHardware[SOFTSERIAL_2_TIMER_TX_HARDWARE]);
    }
#endif

    softSerial->port.vTable = softSerialVTable;
    softSerial->port.baudRate = baud;
    softSerial->port.mode = MODE_RXTX;
    softSerial->port.options = options;
    softSerial->port.callback = callback;

    resetBuffers(softSerial);

    softSerial->isTransmittingData = false;

    softSerial->isSearchingForStartBit = true;
    softSerial->rxBitIndex = 0;

    softSerial->transmissionErrors = 0;
    softSerial->receiveErrors = 0;

    softSerial->softSerialPortIndex = portIndex;

    softSerial->txIO = IOGetByTag(softSerial->txTimerHardware->tag);
    serialOutputPortConfig(softSerial->txTimerHardware->tag, portIndex);

    softSerial->rxIO = IOGetByTag(softSerial->rxTimerHardware->tag);
    serialInputPortConfig(softSerial->rxTimerHardware->tag, portIndex);

    setTxSignal(softSerial, ENABLE);
    delay(50);

    serialTimerTxConfig(softSerial->txTimerHardware, portIndex, baud);
    serialTimerRxConfig(softSerial->rxTimerHardware, portIndex, options);

    return &softSerial->port;
}
    //-------------------------------------------------------------------------
    void
    ManualObject::end()
    {
        if( m_section == nullptr )
        {
			OGRE_EXCEPT( Ogre::Exception::ERR_INVALIDPARAMS,
				"You cannot end a section without beginning one first",
				"ManualObject::end");
        }

        m_mesh->_setBounds( m_bbox );
        m_mesh->_setBoundingSphereRadius( m_radius );
        m_section = nullptr;
        resetBuffers();
    }
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
{
	if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
		return -1;

	if (getMode() & std::ios::out)
		sync();

	resetBuffers();

	LARGE_INTEGER li;
	li.QuadPart = pos;
	li.LowPart  = SetFilePointerEx(_handle, li, NULL, FILE_BEGIN);

	if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
		File::handleLastError(_path);
	_pos = li.QuadPart;
	return std::streampos(static_cast<std::streamoff>(_pos));
}
serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallbackPtr callback, uint32_t baud, serialInversion_e inversion)
{
    softSerial_t *softSerial = &(softSerialPorts[portIndex]);

    if (portIndex == SOFTSERIAL1) {
        softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_RX_HARDWARE]);
        softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_TX_HARDWARE]);
    }

    if (portIndex == SOFTSERIAL2) {
        softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_2_TIMER_RX_HARDWARE]);
        softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_2_TIMER_TX_HARDWARE]);
    }

    softSerial->port.vTable = softSerialVTable;
    softSerial->port.baudRate = baud;
    softSerial->port.mode = MODE_RXTX;
    softSerial->port.inversion = inversion;
    softSerial->port.callback = callback;

    resetBuffers(softSerial);

    softSerial->isTransmittingData = false;

    softSerial->isSearchingForStartBit = true;
    softSerial->rxBitIndex = 0;

    softSerial->transmissionErrors = 0;
    softSerial->receiveErrors = 0;

    softSerial->softSerialPortIndex = portIndex;

    serialOutputPortConfig(softSerial->txTimerHardware);
    serialInputPortConfig(softSerial->rxTimerHardware);

    setTxSignal(softSerial, ENABLE);
    delay(50);

    serialTimerTxConfig(softSerial->txTimerHardware, portIndex, baud);
    serialTimerRxConfig(softSerial->rxTimerHardware, portIndex, inversion);

    return &softSerial->port;
}
serialPort_t *openEscSerial(escSerialPortIndex_e portIndex, serialReceiveCallbackPtr callback, uint16_t output, uint32_t baud, portOptions_t options, uint8_t mode)
{
    escSerial_t *escSerial = &(escSerialPorts[portIndex]);

    escSerial->rxTimerHardware = &(timerHardware[output]);
    escSerial->txTimerHardware = &(timerHardware[ESCSERIAL_TIMER_TX_HARDWARE]);

    escSerial->port.vTable = escSerialVTable;
    escSerial->port.baudRate = baud;
    escSerial->port.mode = MODE_RXTX;
    escSerial->port.options = options;
    escSerial->port.callback = callback;

    resetBuffers(escSerial);

    escSerial->isTransmittingData = false;

    escSerial->isSearchingForStartBit = true;
    escSerial->rxBitIndex = 0;

    escSerial->transmissionErrors = 0;
    escSerial->receiveErrors = 0;
    escSerial->receiveTimeout = 0;

    escSerial->escSerialPortIndex = portIndex;

    serialInputPortConfig(escSerial->rxTimerHardware);

    setTxSignal(escSerial, ENABLE);
    delay(50);

	if(mode==0){
		serialTimerTxConfig(escSerial->txTimerHardware, portIndex);
		serialTimerRxConfig(escSerial->rxTimerHardware, portIndex);
	}
	if(mode==1){
		serialTimerTxConfigBL(escSerial->txTimerHardware, portIndex, baud);
		serialTimerRxConfigBL(escSerial->rxTimerHardware, portIndex, options);
	}

    return &escSerial->port;
}
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
{
	poco_assert (_handle == INVALID_HANDLE_VALUE);

	_path = path;
	_pos = 0;
	setMode(mode);
	resetBuffers();

	DWORD access = 0;
	if (mode & std::ios::in)
		access |= GENERIC_READ;
	if (mode & std::ios::out)
		access |= GENERIC_WRITE;

	DWORD shareMode = FILE_SHARE_READ;
	if (!(mode & std::ios::out))
		shareMode |= FILE_SHARE_WRITE;
		
	DWORD creationDisp = OPEN_EXISTING;
	if (mode & std::ios::trunc)
		creationDisp = CREATE_ALWAYS;
	else if (mode & std::ios::out)
		creationDisp = OPEN_ALWAYS;

	DWORD flags = FILE_ATTRIBUTE_NORMAL;
	
#if defined (POCO_WIN32_UTF8)
	std::wstring utf16Path;
	UnicodeConverter::toUTF16(path, utf16Path);
	_handle = CreateFile2(utf16Path.c_str(), access, shareMode, creationDisp, NULL);
#else
	_handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
#endif

	if (_handle == INVALID_HANDLE_VALUE)
		File::handleLastError(_path);
		
	if ((mode & std::ios::ate) || (mode & std::ios::app))
		seekoff(0, std::ios::end, mode);
}
Exemple #12
0
bool RayCastRenderer::reset_impl(int w, int h)
{
  F();

  if ((m_data_width <= 0) || (m_data_height <= 0) || (m_data_depth <= 0))
  {
    ERRORM("RayCastRenderer: grid size is not set");
    return false;
  }

  if ((m_cell_starts_buf.get() == nullptr) || (m_cell_ends_buf.get() == nullptr))
  {
    ERRORM("RayCastRenderer: cell_starts or cell_ends buffer is not set");
    return false;
  }

  return resetDataTexture() &&
      resetBuffers() &&
      resetFramebuffer(w, h) &&
      resetTransferFunctionTexture();
}
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
{
	if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
		return -1;
	
	if (getMode() & std::ios::out)
		sync();

	std::streamoff adj;
	if (mode & std::ios::in)
		adj = static_cast<std::streamoff>(egptr() - gptr());
	else
		adj = 0;

	resetBuffers();

	DWORD offset = FILE_BEGIN;
	if (dir == std::ios::cur)
	{
		offset = FILE_CURRENT;
		off -= adj;
	}
	else if (dir == std::ios::end)
	{
		offset = FILE_END;
	}
	
	LARGE_INTEGER li;
	li.QuadPart = off;
	li.LowPart  = SetFilePointerEx(_handle, li, NULL, offset);

	if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
		File::handleLastError(_path);
	_pos = li.QuadPart;
	return std::streampos(static_cast<std::streamoff>(_pos));
}
Exemple #14
0
void QQnxWindow::setBufferSize(const QSize &size)
{
    qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "size =" << size;

    // libscreen fails when creating empty buffers
    const QSize nonEmptySize = size.isEmpty() ? QSize(1, 1) : size;
    int format = pixelFormat();

    if (nonEmptySize == m_bufferSize || format == -1)
        return;

    Q_SCREEN_CRITICALERROR(
            screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, &format),
            "Failed to set window format");

    if (m_bufferSize.isValid()) {
        // destroy buffers first, if resized
        Q_SCREEN_CRITICALERROR(screen_destroy_window_buffers(m_window),
                               "Failed to destroy window buffers");
    }

    int val[2] = { nonEmptySize.width(), nonEmptySize.height() };
    Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val),
                        "Failed to set window buffer size");

    Q_SCREEN_CRITICALERROR(screen_create_window_buffers(m_window, MAX_BUFFER_COUNT),
                           "Failed to create window buffers");

    // check if there are any buffers available
    int bufferCount = 0;
    Q_SCREEN_CRITICALERROR(
        screen_get_window_property_iv(m_window, SCREEN_PROPERTY_RENDER_BUFFER_COUNT, &bufferCount),
        "Failed to query render buffer count");

    if (bufferCount != MAX_BUFFER_COUNT) {
        qFatal("QQnxWindow: invalid buffer count. Expected = %d, got = %d.",
                MAX_BUFFER_COUNT, bufferCount);
    }

    // Set the transparency. According to QNX technical support, setting the window
    // transparency property should always be done *after* creating the window
    // buffers in order to guarantee the property is paid attention to.
    if (window()->requestedFormat().alphaBufferSize() == 0) {
        // To avoid overhead in the composition manager, disable blending
        // when the underlying window buffer doesn't have an alpha channel.
        val[0] = SCREEN_TRANSPARENCY_NONE;
    } else {
        // Normal alpha blending. This doesn't commit us to translucency; the
        // normal backfill during the painting will contain a fully opaque
        // alpha channel unless the user explicitly intervenes to make something
        // transparent.
        val[0] = SCREEN_TRANSPARENCY_SOURCE_OVER;
    }

    Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, val),
                        "Failed to set window transparency");

    // Cache new buffer size
    m_bufferSize = nonEmptySize;
    resetBuffers();
}
Exemple #15
0
INT32 _mongoSession::run()
{
   INT32 rc                     = SDB_OK ;
   BOOLEAN bigEndian            = FALSE ;
   UINT32 msgSize               = 0 ;
   UINT32  headerLen            = sizeof( mongoMsgHeader ) - sizeof( INT32 ) ;
   CHAR *pBuff                  = NULL ;
   const CHAR *pBody            = NULL ;
   INT32 bodyLen                = 0 ;
   engine::pmdEDUMgr *pmdEDUMgr = NULL ;
   std::vector< msgBuffer * >::iterator itr ;

   if ( !_pEDUCB )
   {
      rc = SDB_SYS ;
      goto error ;
   }

   pmdEDUMgr = _pEDUCB->getEDUMgr() ;
   bigEndian = checkBigEndian() ;
   while ( !_pEDUCB->isDisconnected() && !_socket.isClosed() )
   {
      _pEDUCB->resetInterrupt() ;
      _pEDUCB->resetInfo( engine::EDU_INFO_ERROR ) ;
      _pEDUCB->resetLsn() ;

      rc = recvData( (CHAR*)&msgSize, sizeof(UINT32) ) ;
      if ( rc )
      {
         if ( SDB_APP_FORCED != rc )
         {
            PD_LOG( PDERROR, "Session[%s] failed to recv msg size, "
                    "rc: %d", sessionName(), rc ) ;
         }
         break ;
      }

      if ( bigEndian )
      {
      }

      if ( msgSize < headerLen || msgSize > SDB_MAX_MSG_LENGTH )
      {
         PD_LOG( PDERROR, "Session[%s] recv msg size[%d] is less than "
                 "mongoMsgHeader size[%d] or more than max msg size[%d]",
                 sessionName(), msgSize, sizeof( mongoMsgHeader ),
                 SDB_MAX_MSG_LENGTH ) ;
         rc = SDB_INVALIDARG ;
         break ;
      }
      else
      {
         pBuff = getBuff( msgSize + 1 ) ;
         if ( !pBuff )
         {
            rc = SDB_OOM ;
            break ;
         }
         *(UINT32*)pBuff = msgSize ;
         rc = recvData( pBuff + sizeof(UINT32), msgSize - sizeof(UINT32) ) ;
         if ( rc )
         {
            if ( SDB_APP_FORCED != rc )
            {
               PD_LOG( PDERROR, "Session failed to recv rest msg, rc: %d",
                       sessionName(), rc ) ;
            }
            break ;
         }
         pBuff[ msgSize ] = 0 ;

         {
            resetBuffers() ;
            _converter->loadFrom( pBuff, msgSize ) ;
            rc = _converter->convert( _inBufferVec ) ;
            if ( SDB_OK != rc )
            {
               if ( SDB_OPTION_NOT_SUPPORT == rc )
               {
               }
               else
               {
                  goto error ;
               }
            }

            if ( _preProcessMsg( _converter->getParser(),
                                 _resource, _contextBuff ) )
            {
               goto reply ;
            }
            itr = _inBufferVec.begin() ;
            for ( ; itr != _inBufferVec.end() ; ++itr )
            {
               _pEDUCB->incEventCount() ;
               _needReply = FALSE ;
               if ( SDB_OK != ( rc = pmdEDUMgr->activateEDU( _pEDUCB ) ) )
               {
                  PD_LOG( PDERROR, "Session[%s] activate edu failed, rc: %d",
                          sessionName(), rc ) ;
                  goto error ;
               }
               rc = _processMsg( (*itr)->data() ) ;
               if ( rc )
               {
                  if ( SDB_DMS_CS_EXIST == rc &&
                       OP_CMD_CREATE == _converter->getOpType())
                  {
                     _contextBuff.release() ;
                  }
                  else
                  {
                     goto reply ;
                  }
               }
               if ( SDB_OK != ( rc = pmdEDUMgr->waitEDU( _pEDUCB ) ) )
               {
                  PD_LOG( PDERROR, "Session[%s] wait edu failed, rc: %d",
                          sessionName(), rc ) ;
                  goto error ;
               }
            }
         reply:
            pBody = _contextBuff.data() ;
            bodyLen = _contextBuff.size() ;
            INT32 rcTmp = _reply( &_replyHeader, pBody, bodyLen ) ;
            if ( rcTmp )
            {
               PD_LOG( PDERROR, "Session[%s] failed to send response, rc: %d",
                       sessionName(), rcTmp ) ;
               goto error ;
            }
            pBody = NULL ;
            bodyLen = 0 ;
         }
      }
   } // end while
done:
   disconnect() ;
   return rc ;
error:
   goto done ;
}
Exemple #16
0
serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallbackPtr rxCallback, uint32_t baud, portMode_t mode, portOptions_t options)
{
    softSerial_t *softSerial = &(softSerialPorts[portIndex]);

    int pinCfgIndex = portIndex + RESOURCE_SOFT_OFFSET;

    ioTag_t tagRx = serialPinConfig()->ioTagRx[pinCfgIndex];
    ioTag_t tagTx = serialPinConfig()->ioTagTx[pinCfgIndex];

    const timerHardware_t *timerRx = timerGetByTag(tagRx, TIM_USE_ANY);
    const timerHardware_t *timerTx = timerGetByTag(tagTx, TIM_USE_ANY);

    IO_t rxIO = IOGetByTag(tagRx);
    IO_t txIO = IOGetByTag(tagTx);

    if (options & SERIAL_BIDIR) {
        // If RX and TX pins are both assigned, we CAN use either with a timer.
        // However, for consistency with hardware UARTs, we only use TX pin,
        // and this pin must have a timer.
        if (!timerTx)
            return NULL;

        softSerial->timerHardware = timerTx;
        softSerial->txIO = txIO;
        softSerial->rxIO = txIO;
        IOInit(txIO, OWNER_SERIAL_TX, RESOURCE_INDEX(portIndex) + RESOURCE_SOFT_OFFSET);
    } else {
        if (mode & MODE_RX) {
            // Need a pin & a timer on RX
            if (!(tagRx && timerRx))
                return NULL;

            softSerial->rxIO = rxIO;
            softSerial->timerHardware = timerRx;
            IOInit(rxIO, OWNER_SERIAL_RX, RESOURCE_INDEX(portIndex) + RESOURCE_SOFT_OFFSET);
        }

        if (mode & MODE_TX) {
            // Need a pin on TX
            if (!tagTx)
                return NULL;

            softSerial->txIO = txIO;

            if (!(mode & MODE_RX)) {
                // TX Simplex, must have a timer
                if (!timerTx)
                    return NULL;
                softSerial->timerHardware = timerTx;
            } else {
                // Duplex
                softSerial->exTimerHardware = timerTx;
            }
            IOInit(txIO, OWNER_SERIAL_TX, RESOURCE_INDEX(portIndex) + RESOURCE_SOFT_OFFSET);
        }
    }

    softSerial->port.vTable = &softSerialVTable;
    softSerial->port.baudRate = baud;
    softSerial->port.mode = mode;
    softSerial->port.options = options;
    softSerial->port.rxCallback = rxCallback;

    resetBuffers(softSerial);

    softSerial->softSerialPortIndex = portIndex;

    softSerial->transmissionErrors = 0;
    softSerial->receiveErrors = 0;

    softSerial->rxActive = false;
    softSerial->isTransmittingData = false;

    // Configure master timer (on RX); time base and input capture

    serialTimerConfigureTimebase(softSerial->timerHardware, baud);
    timerChConfigIC(softSerial->timerHardware, (options & SERIAL_INVERTED) ? ICPOLARITY_RISING : ICPOLARITY_FALLING, 0);

    // Initialize callbacks
    timerChCCHandlerInit(&softSerial->edgeCb, onSerialRxPinChange);
    timerChOvrHandlerInit(&softSerial->overCb, onSerialTimerOverflow);

    // Configure bit clock interrupt & handler.
    // If we have an extra timer (on TX), it is initialized and configured
    // for overflow interrupt.
    // Receiver input capture is configured when input is activated.

    if ((mode & MODE_TX) && softSerial->exTimerHardware && softSerial->exTimerHardware->tim != softSerial->timerHardware->tim) {
        softSerial->timerMode = TIMER_MODE_DUAL;
        serialTimerConfigureTimebase(softSerial->exTimerHardware, baud);
        timerChConfigCallbacks(softSerial->exTimerHardware, NULL, &softSerial->overCb);
        timerChConfigCallbacks(softSerial->timerHardware, &softSerial->edgeCb, NULL);
    } else {
        softSerial->timerMode = TIMER_MODE_SINGLE;
        timerChConfigCallbacks(softSerial->timerHardware, &softSerial->edgeCb, &softSerial->overCb);
    }

#ifdef USE_HAL_DRIVER
    softSerial->timerHandle = timerFindTimerHandle(softSerial->timerHardware->tim);
#endif

    if (!(options & SERIAL_BIDIR)) {
        serialOutputPortActivate(softSerial);
        setTxSignal(softSerial, ENABLE);
    }

    serialInputPortActivate(softSerial);

    return &softSerial->port;
}
Exemple #17
0
void draw(){


	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);

	


	glLoadIdentity();             // Reset
	glPushMatrix();

#ifdef ANIMATION_SHOW 
	glRotatef(fRotateViewPhi, 1.0f, 0.0f, 0.0f);
	glRotatef(fRotateViewSigma, 0.0f, 1.0f, 0.0f);

#else
	glRotatef((float)mousex,0.0f,1.0f,0.0f);
	glRotatef((float)mousey,1.0f,0.0f,0.0f);

//	glRotatef(45.0f,1.0f,0.0f,0.0f);
//	glRotatef(45.0f,0.0f,1.0f,0.0f);
#endif

#ifdef ANIMATION_SHOW
	glScalef(0.5f, 0.5f, 0.5f);
#else
	glScalef(0.4f, 0.4f, 0.4f);
#endif
	glTranslatef(-1.5f,-1.5f,-1.5f);


#ifdef ANIMATION_SHOW
	drawCube(fRotateSlice);
#else
	resetBuffers();

	int iInc;
	for(iInc = 0; iInc < 54; iInc++){
//		if(cMoveArr[2][iInc] == 1)
			drawNumberedFace(CUBE_SIZE, CORNER_RADIUS, iInc);
	}

	//	Cubes Being Rotated
	drawFullCube(CUBE_SIZE, CORNER_RADIUS);
#endif
	glPopMatrix();

#ifdef ANIMATION_SHOW
	//	code to update permutations when move has completed
	if(fRotateSlice >= 90.0f){
		fRotateSlice = 0.0f;
		unsigned char cFace = 0;
		unsigned char cDir = 0;
		unsigned char cMove = 0;

		if(iMoveState == MOVE_STATE_BACKWARD){	// Working the way back on permutations
			cFace = (*cMarker) & MOVE_FACES;					// filter out Direction (Face remains)
			cDir = (~((*cMarker) & MOVE_DIRS)) & MOVE_DIRS;				// filter out Face (Direciton remains) then Reverse Direction
			cMove = cFace | cDir;							// combine to apply effective going in reverse
			cApplySingleMove(&cMove);

			if(cMarker == cMoves){
				generateRandomMoves((unsigned char)(0));
				cMarker = cMoves;
				iMoveState = MOVE_STATE_FORWARD;
			}else
				cMarker--;

		}else if(iMoveState == MOVE_STATE_FORWARD){
			cApplySingleMove(cMarker);

			if((cMarker - cMoves) >= (iArrayCount - 1))
				iMoveState = MOVE_STATE_BACKWARD;				//	reverse direction
			else
				cMarker++;

		}

	}else
		fRotateSlice += SPEED_SLICE;


	fRotateViewPhi += SPEED_VIEW_PHI;
	fRotateViewSigma += SPEED_VIEW_SIGMA;

#endif

//	glutPostRedisplay();

	glutSwapBuffers();


}