Ejemplo n.º 1
0
int i2c_write_bytes(i2c_t dev, uint8_t address, char *data, int length)
{
    if ((unsigned int)dev >= I2C_NUMOF) {
        return -1;
    }

    I2C_TypeDef *i2c = i2c_config[dev].dev;

    /* start transmission and send slave address */
    DEBUG("sending start sequence\n");
    _start(i2c, address, I2C_FLAG_WRITE);
    _clear_addr(i2c);
    /* send out data bytes */
    _write(i2c, data, length);
    /* end transmission */
    DEBUG("Ending transmission\n");
    _stop(i2c);
    DEBUG("STOP condition was send out\n");
    return length;
}
Ejemplo n.º 2
0
int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, char *data, int length)
{
    if ((unsigned int)dev >= I2C_NUMOF) {
        return -1;
    }

    I2C_TypeDef *i2c = i2c_config[dev].dev;

    /* start transmission and send slave address */
    _start(i2c, address, I2C_FLAG_WRITE);
    _clear_addr(i2c);
    /* send register address and wait for complete transfer to be finished*/
    _write(i2c, (char *)(&reg), 1);
    /* write data to register */
    _write(i2c, data, length);
    /* finish transfer */
    _stop(i2c);
    /* return number of bytes send */
    return length;
}
/*
 * Ponto de entrada principal
 */
void __attribute__((weak,naked,alias("Default_Handler"))) Reset_Handler(void) {
unsigned long *pSource;
unsigned long *pDest;

    /* Passo 1 : Copiar dados inicializados da flash para RAM (section DATA) */
    pSource = &_text_end;
    pDest   = &_data_start;
    while( pDest < &_data_end ) {
        *pDest++ = *pSource++;
    }

    /* Passo 2 : Zerar variaveis nao inicializadas (section BSS) */
    pDest = &_bss_start;
    while( pDest < &_bss_end ) {
        *pDest++ = 0;
    }

#ifdef ENABLE_FPU
    //
    // Enable the floating-point unit.  This must be done here to handle the
    // case where main() uses floating-point and the function prologue saves
    // floating-point registers (which will fault if floating-point is not
    // enabled).

    //
    uint32_t t = SCB->CPACR;
    t &= ~(SCB_CPACR_CP11_M|SCB_CPACR_CP10_M);
    t |= SCB_CPACR_CP11_FULL_V|SCB_CPACR_CP10_FULL_V ;
    SCB->CPACR = t;
#endif
    /* Passo 3 : Chamar SystemInit conforme CMSIS */
    SystemInit();

    /* Passo 4 : Chamar _main para inicializar biblioteca */
    _main();

    /* Passo 5 : Chamar main */
    main();

    _stop();
}
Ejemplo n.º 4
0
Control_bar::Control_bar(Input::Session_component &input)
:
	_input(input), _playing(true)
{
	update_style_id(_play_pause_button, "play");

	_volume_slider->setOrientation(Qt::Horizontal);
	_volume_slider->setRange(0, 100);
	_volume_slider->setTickInterval(10);
	_volume_slider->setValue(100);

	_layout->addWidget(_play_pause_button);
	_layout->addWidget(_stop_button);
	_layout->addStretch();
	_layout->addWidget(_volume_label);
	_layout->addWidget(_volume_slider);

	connect(_play_pause_button, SIGNAL(clicked()), this, SLOT(_pause_resume()));
	connect(_stop_button, SIGNAL(clicked()), this, SLOT(_stop()));
	connect(_volume_slider, SIGNAL(valueChanged(int)), this, SIGNAL(volume_changed(int)));
}
Ejemplo n.º 5
0
static void _ftdi_unload(usbh_baseclassdriver_t *drv) {
    osalDbgCheck(drv != NULL);
    USBHFTDIDriver *const ftdip = (USBHFTDIDriver *)drv;
    USBHFTDIPortDriver *ftdipp = ftdip->ports;

    osalMutexLock(&ftdip->mtx);
    while (ftdipp) {
        _stop(ftdipp);
        ftdipp = ftdipp->next;
    }

    ftdipp = ftdip->ports;
    osalSysLock();
    while (ftdipp) {
        USBHFTDIPortDriver *next = ftdipp->next;
        usbhftdipObjectInit(ftdipp);
        ftdipp = next;
    }
    osalSysUnlock();
    osalMutexUnlock(&ftdip->mtx);
}
Ejemplo n.º 6
0
static void
_process_emotion_commands(struct _App *app)
{
   int cmd = _em_cmd_read(app);
   switch (cmd) {
      case EM_CMD_FILE_SET:
	 _file_set(app);
	 break;
      case EM_CMD_FILE_SET_DONE:
	 _file_set_done(app);
	 break;
      case EM_CMD_FILE_CLOSE:
	 _file_close(app);
	 break;
      case EM_CMD_PLAY:
	 _play(app);
	 break;
      case EM_CMD_STOP:
	 _stop(app);
	 break;
      case EM_CMD_POSITION_SET:
	 _position_set(app);
	 break;
      case EM_CMD_SPEED_SET:
	 _speed_set(app);
	 break;
      case EM_CMD_AUDIO_MUTE_SET:
	 _mute_set(app);
	 break;
      case EM_CMD_VOLUME_SET:
	 _volume_set(app);
	 break;
      case EM_CMD_AUDIO_TRACK_SET:
	 _audio_track_set(app);
	 break;
      case EM_CMD_VIDEO_TRACK_SET:
	 _video_track_set(app);
	 break;
   };
}
Ejemplo n.º 7
0
int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg, void *data, int length)
{
    assert(length > 0);

    if (!(dev < I2C_NUMOF)) {
        return -1;
    }

    /* start transmission and send slave address */
    if (_start(address, I2C_FLAG_WRITE) != 0) {
        return 0;
    }

    /* send register address and wait for complete transfer to be finished*/
    if (_write(&reg, 1) != 1) {
        _stop();
        return 0;
    }

    /* now start a new start condition and receive data */
    return i2c_read_bytes(dev, address, data, length);
}
Ejemplo n.º 8
0
Archivo: i2c.c Proyecto: OTAkeys/RIOT
static inline int _write(SercomI2cm *dev, const uint8_t *data, int length,
                         uint8_t stop)
{
    uint8_t count = 0;

    /* Write data buffer until the end. */
    DEBUG("Looping through bytes\n");
    while (length--) {
        /* Check that bus ownership is not lost. */
        if ((dev->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE_Msk)
            != BUSSTATE_OWNER) {
            DEBUG("STATUS_ERR_PACKET_COLLISION\n");
            return -EAGAIN;
        }

        /* Wait for hardware module to sync */
        while (dev->SYNCBUSY.reg & SERCOM_I2CM_SYNCBUSY_MASK) {}

        DEBUG("Written byte #%i to data reg, now waiting for DR"
              " to be empty again\n", count);
        dev->DATA.reg = data[count++];

        /* Wait for response on bus. */
        if (_wait_for_response(dev, SAMD21_I2C_TIMEOUT) < 0) {
            return -ETIMEDOUT;
        }

        /* Check for NACK from slave. */
        if (dev->STATUS.reg & SERCOM_I2CM_STATUS_RXNACK) {
            DEBUG("STATUS_ERR_OVERFLOW\n");
            return -EIO;
        }
    }
    if (stop) {
        /* Issue stop command */
        _stop(dev);
    }
    return 0;
}
Ejemplo n.º 9
0
Archivo: i2c.c Proyecto: OTAkeys/RIOT
static inline int _read(SercomI2cm *dev, uint8_t *data, int length,
                        uint8_t stop)
{
    uint8_t count = 0;

    /* Set action to ack. */
    dev->CTRLB.reg &= ~SERCOM_I2CM_CTRLB_ACKACT;

    /* Read data buffer. */
    while (length--) {
        /* Check that bus ownership is not lost. */
        if ((dev->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE_Msk)
            != BUSSTATE_OWNER) {
            DEBUG("STATUS_ERR_PACKET_COLLISION\n");
            return -EAGAIN;
        }

        /* Wait for hardware module to sync */
        while (dev->SYNCBUSY.reg & SERCOM_I2CM_SYNCBUSY_MASK) {}
        /* Check if this is the last byte to read */
        if (length == 0 && stop) {
            /* Send NACK before STOP */
            dev->CTRLB.reg |= SERCOM_I2CM_CTRLB_ACKACT;
            /* Prepare stop command before read last byte otherwise
               hardware will request an extra byte to read */
            _stop(dev);
        }
        /* Save data to buffer. */
        data[count] = dev->DATA.reg;

        /* Wait for response on bus. */
        if (length > 0) {
            if (_wait_for_response(dev, SAMD21_I2C_TIMEOUT) < 0)
                return -ETIMEDOUT;
        }
        count++;
    }
    return 0;
}
Ejemplo n.º 10
0
uint8_t Softi2c::_wait_ack()
{
	uint8_t cErrTime = 5;
	pinMode(_SDApin,INPUT_PULLUP);
	digitalWrite(_SCLpin,1);delay_us(delaytimes);
	while(digitalRead(_SDApin))
	{
		cErrTime--;
		delay_us(delaytimes);
		if(cErrTime == 0)
		{
			pinMode(_SDApin,OUTPUT);
			_stop();
			return 0;
		
		}
	
	}
	pinMode(_SDApin,OUTPUT);
	digitalWrite(_SCLpin,0);delay_us(delaytimes);
	return 1;
}
Ejemplo n.º 11
0
app_result_e mengine_play(void* msg_ptr)
{
    bool ret_vals;
     
    if (g_play_mode == PLAY_NO_PLAY)
    {
        ret_vals = _stop(STOP_PAUSE);//暂停播放
        change_engine_state(ENGINE_STATE_PAUSE);
        //清零setfile标志,播放需要重新set
        g_set_file_flag = FALSE;

    }
    else
    {
        ret_vals = _play(g_play_mode);//播放
    }
    g_play_mode = PLAY_NORMAL;
    //mengine_info.eg_playinfo.cur_file_switch |= 0x01;
    mengine_reply_msg(msg_ptr, ret_vals);

    return RESULT_IGNORE;
}
Ejemplo n.º 12
0
app_result_e mengine_play_cuemusic(void* msg_ptr)
{
    bool ret_vals;

    //消息指针
    private_msg_t* data_ptr = (private_msg_t*) msg_ptr;

    //mengine_status_t *eg_status = &mengine_info.eg_status;
    mengine_config_t *eg_cfg = &mengine_info.eg_config;

    //void * data_ptr = msg_ptr->msg.content.addr;//存放书签断点的数据指针

    //当前是播放状态,则停止播放

    ret_vals = _stop(STOP_PAUSE);//暂停播放,由内部保证是播放状态才停止
    if (ret_vals == FALSE)
    {
        goto msg_end;
    }

    //保存断点,必须在_stop之后,因为_stop中会获取断点,放在_stop之前断点会被覆盖
    libc_memcpy(&eg_cfg->bk_infor, data_ptr->msg.content.addr, sizeof(mmm_mp_bp_info_t));

    //重新开始播放, 设置文件
    //ret_vals = _set_file();
    //if (ret_vals == FALSE)
    //{
    //    goto msg_end;
    //}

    ret_vals = _play(PLAY_RESUME);//播放

    msg_end:
    //返回成功
    mengine_reply_msg(msg_ptr, TRUE);

    return RESULT_IGNORE;
}
Ejemplo n.º 13
0
int i2c_write_bytes(i2c_t dev, uint8_t address, const void *data, int length)
{
    int bytes = 0;

    assert(length > 0);

    if (!(dev < I2C_NUMOF)) {
        return -1;
    }

    /* start transmission and send slave address */
    if (_start(address, I2C_FLAG_WRITE) != 0) {
        return 0;
    }

    /* send out data bytes */
    bytes = _write(data, length);

    /* end transmission */
    _stop();

    return bytes;
}
Ejemplo n.º 14
0
Archivo: i2c.c Proyecto: jfairman/RIOT
int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg, char *data, int length)
{
    I2C_TypeDef *i2c;

    switch (dev) {
#if I2C_0_EN
        case I2C_0:
            i2c = I2C_0_DEV;
            break;
#endif
        default:
            return -1;
    }

    /* send start condition and slave address */
    DEBUG("Send slave address and clear ADDR flag\n");
    _start(i2c, address, I2C_FLAG_WRITE);
    _clear_addr(i2c);
    DEBUG("Write reg into DR\n");
    i2c->DR = reg;
    _stop(i2c);
    DEBUG("Now start a read transaction\n");
    return i2c_read_bytes(dev, address, data, length);
}
Ejemplo n.º 15
0
int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, const void *data, int length)
{
    int bytes = 0;

    assert(length > 0);

    if (!(dev < I2C_NUMOF)) {
        return -1;
    }

    /* start transmission and send slave address */
    if (_start(address, I2C_FLAG_WRITE) != 0) {
        return 0;
    }
    /* send register address and wait for complete transfer to be finished*/
    if (_write(&reg, 1)) {
        /* write data to register */
        bytes = _write(data, length);
    }
    /* finish transfer */
    _stop();
    /* return number of bytes send */
    return bytes;
}
Ejemplo n.º 16
0
app_result_e mengine_play_prev(void* msg_ptr)
{
    play_status_e play_status = g_eg_status_p->play_status;

    //大于5s重头开始播歌,不向前切歌
    if (g_eg_playinfo_p->cur_time > 5000)
    {
        g_eg_playinfo_p->cur_time = 0;
        
        //清除断点
        libc_memset(&(g_eg_cfg_p->bk_infor), 0, sizeof(mmm_mp_bp_info_t));
        
        _stop(STOP_NORMAL);//停止播放
        
        if (play_status == PlaySta)
        {
            _set_file();
            _play(PLAY_NORMAL);//播放 
        }
        mengine_reply_msg(msg_ptr, TRUE);
        return RESULT_IGNORE;
    }
    return mengine_play_switch(msg_ptr, FORCE_SWITCH_PREV);
}
Ejemplo n.º 17
0
Archivo: stop.c Proyecto: UIKit0/flux
void stop(void) {
	_stop(gettid());
}
void CommandProcessor::stop(void) {
	*mLog.debug() << UTILS_STR_FUNCTION;
	_stop();
}
Ejemplo n.º 19
0
void Controller::stop()
{
    _stop();
}
Ejemplo n.º 20
0
int hpx_init(int *argc, char ***argv) {
  int status = HPX_SUCCESS;

  // Start the internal clock
  libhpx_time_start();

  here = malloc(sizeof(*here));
  if (!here) {
    status = log_error("failed to allocate a locality.\n");
    goto unwind0;
  }

  here->rank = -1;
  here->ranks = 0;
  here->epoch = 0;

  sigset_t set;
  sigemptyset(&set);
  dbg_check(pthread_sigmask(SIG_BLOCK, &set, &here->mask));

  here->config = config_new(argc, argv);
  if (!here->config) {
    status = log_error("failed to create a configuration.\n");
    goto unwind1;
  }

  // check to see if everyone is waiting
  if (config_dbg_waitat_isset(here->config, HPX_LOCALITY_ALL)) {
    dbg_wait();
  }

  // bootstrap
  here->boot = boot_new(here->config->boot);
  if (!here->boot) {
    status = log_error("failed to bootstrap.\n");
    goto unwind1;
  }
  here->rank = boot_rank(here->boot);
  here->ranks = boot_n_ranks(here->boot);

  // initialize the debugging system
  // @todo We would like to do this earlier but MPI_init() for the bootstrap
  //       network overwrites our segv handler.
  if (LIBHPX_OK != dbg_init(here->config)) {
    goto unwind1;
  }

  // Now that we know our rank, we can be more specific about waiting.
  if (config_dbg_waitat_isset(here->config, here->rank)) {
    // Don't wait twice.
    if (!config_dbg_waitat_isset(here->config, HPX_LOCALITY_ALL)) {
      dbg_wait();
    }
  }

  // see if we're supposed to output the configuration, only do this at rank 0
  if (config_log_level_isset(here->config, HPX_LOG_CONFIG)) {
    if (here->rank == 0) {
      config_print(here->config, stdout);
    }
  }

  // topology discovery and initialization
  here->topology = topology_new(here->config);
  if (!here->topology) {
    status = log_error("failed to discover topology.\n");
    goto unwind1;
  }

  // Initialize our instrumentation.
  if (inst_init(here->config)) {
    log_dflt("error detected while initializing instrumentation\n");
  }

  // Allocate the global heap.
  here->gas = gas_new(here->config, here->boot);
  if (!here->gas) {
    status = log_error("failed to create the global address space.\n");
    goto unwind1;
  }
  HPX_HERE = HPX_THERE(here->rank);

  here->percolation = percolation_new();
  if (!here->percolation) {
    status = log_error("failed to activate percolation.\n");
    goto unwind1;
  }

  int cores = system_get_available_cores();
  dbg_assert(cores > 0);

  if (!here->config->threads) {
    here->config->threads = cores;
  }
  log_dflt("HPX running %d worker threads on %d cores\n", here->config->threads,
           cores);

  here->net = network_new(here->config, here->boot, here->gas);
  if (!here->net) {
    status = log_error("failed to create network.\n");
    goto unwind1;
  }

  // thread scheduler
  here->sched = scheduler_new(here->config);
  if (!here->sched) {
    status = log_error("failed to create scheduler.\n");
    goto unwind1;
  }

#ifdef HAVE_APEX
  // initialize APEX, give this main thread a name
  apex_init("HPX WORKER THREAD");
  apex_set_node_id(here->rank);
#endif

  action_registration_finalize();
  inst_start();

  // start the scheduler, this will return after scheduler_shutdown()
  if (scheduler_startup(here->sched, here->config) != LIBHPX_OK) {
    log_error("scheduler shut down with error.\n");
    goto unwind1;
  }

  if ((here->ranks > 1 && here->config->gas != HPX_GAS_AGAS) ||
      !here->config->opt_smp) {
    status = hpx_run(&_hpx_143_fix);
  }

  return status;
 unwind1:
  _stop(here);
  _cleanup(here);
 unwind0:
  return status;
}
Ejemplo n.º 21
0
void DepthCamera::_captureLoop()
{
  uint consecutiveCaptureFails = 0;
  
  while(_running)
  {
    uint32_t callBackTypesToBeCalled = _callBackTypesRegistered;
    
    if(consecutiveCaptureFails > 100)
    {
      logger(LOG_ERROR) << "DepthCamera: 100 consecutive failures in capture of frame. Stopping stream for " << id() << std::endl;
      _running = false;
      continue;
    }
    
    if((_callBackTypesRegistered == 0 || _callBackTypesRegistered == FRAME_RAW_FRAME_UNPROCESSED) && !isSavingFrameStream()) // Only unprocessed frame types requested or none requested?
    {
      auto f = _rawFrameBuffers.get();
      
      if(!_captureRawUnprocessedFrame(*f))
      {
        consecutiveCaptureFails++;
        continue;
      }
      
      if(_callback[FRAME_RAW_FRAME_UNPROCESSED])
      {
        FilterSet<RawFrame>::FrameSequence _frameBuffers;
        _frameBuffers.push_front(f);
        
        if(!_unprocessedFilters.applyFilter(_frameBuffers))
        {
          logger(LOG_ERROR) << "DepthCamera: Failed to apply filters on raw unprocessed frame" << std::endl;
          consecutiveCaptureFails++;
          continue;
        }
        
        if(!_isPaused)
          _callback[FRAME_RAW_FRAME_UNPROCESSED](*this, (Frame &)(**_frameBuffers.begin()), FRAME_RAW_FRAME_UNPROCESSED);
        
        _writeToFrameStream(**_frameBuffers.begin());
      }
      else
      {
        _writeToFrameStream(*f);
      }
      
      consecutiveCaptureFails = 0;
    }
    else
    {
      auto f1 = _rawFrameBuffers.get();
      if(!_captureRawUnprocessedFrame(*f1))
      {
        consecutiveCaptureFails++;
        continue;
      }
      
      FilterSet<RawFrame>::FrameSequence _unprocessedFrameBuffers;
      _unprocessedFrameBuffers.push_front(f1);
      
      if(!_unprocessedFilters.applyFilter(_unprocessedFrameBuffers))
      {
        logger(LOG_ERROR) << "DepthCamera: Failed to apply filters on raw unprocessed frame" << std::endl;
        consecutiveCaptureFails++;
        continue;
      }
      
      if(!_callbackAndContinue(callBackTypesToBeCalled, FRAME_RAW_FRAME_UNPROCESSED, ***_unprocessedFrameBuffers.begin()) && !isSavingFrameStream())
      {
        consecutiveCaptureFails = 0;
        continue;
      }
      
      auto f = _rawFrameBuffers.get();
      
      if(!_processRawFrame(**_unprocessedFrameBuffers.begin(), *f))
      {
        consecutiveCaptureFails++;
        continue;
      }
      
      FilterSet<RawFrame>::FrameSequence _processedFrameBuffers;
      _processedFrameBuffers.push_front(f);
      
      if(!_processedFilters.applyFilter(_processedFrameBuffers))
      {
        logger(LOG_ERROR) << "DepthCamera: Failed to apply filters on raw processed frame" << std::endl;
        consecutiveCaptureFails++;
        continue;
      }
      
      if(!_callbackAndContinue(callBackTypesToBeCalled, FRAME_RAW_FRAME_PROCESSED, ***_processedFrameBuffers.begin())  && !isSavingFrameStream())
      {
        consecutiveCaptureFails = 0;
        continue;
      }
      
      auto d = _depthFrameBuffers.get();
      
      if(!_convertToDepthFrame(**_processedFrameBuffers.begin(), *d))
      {
        consecutiveCaptureFails++;
        continue;
      }
      
      FilterSet<DepthFrame>::FrameSequence _depthFrameBuffers;
      _depthFrameBuffers.push_front(d);
      
      if(!_depthFilters.applyFilter(_depthFrameBuffers))
      {
        logger(LOG_ERROR) << "DepthCamera: Failed to apply filters on depth frame" << std::endl;
        consecutiveCaptureFails++;
        continue;
      }
      
      if(!_callbackAndContinue(callBackTypesToBeCalled, FRAME_DEPTH_FRAME, ***_depthFrameBuffers.begin()) && !isSavingFrameStream())
      {
        consecutiveCaptureFails = 0;
        continue;
      }
      
      auto p = _pointCloudBuffers.get();
      
      if(!_convertToPointCloudFrame(**_depthFrameBuffers.begin(), *p))
      {
        consecutiveCaptureFails++;
        continue;
      }
      
      _callbackAndContinue(callBackTypesToBeCalled, FRAME_XYZI_POINT_CLOUD_FRAME, **p);
      consecutiveCaptureFails = 0;
      
      _writeToFrameStream(**_unprocessedFrameBuffers.begin());
    }
  }
  
  if(!_running)
  {
    closeFrameStream();
    _stop();
  }
  
  logger(LOG_INFO) << "DepthCamera: Streaming stopped." << std::endl;
}
Ejemplo n.º 22
0
		void Module::Stop()
		{
			IOAssert(_type == Type::Extension, "Only extensions can be stopped");
			_stop(this);
		}
Ejemplo n.º 23
0
void MPSimpleBoard::gameOverFlag()
{
	Q_ASSERT( BS_Play );
	_stop(TRUE);
	state = BS_Stop;
}
Ejemplo n.º 24
0
void MPSimpleBoard::stopFlag()
{
	_stop(FALSE);
	state = BS_Standby;
}
Ejemplo n.º 25
0
exit()
{
	_stop("Exit called");
}
Ejemplo n.º 26
0
static PyObject*
stop(PyObject *self)
{
    _stop();
    Py_RETURN_NONE;
}
Ejemplo n.º 27
0
void
BLEPeripheral::end()
{
    _stop();
}
Ejemplo n.º 28
0
void process_platform() {
	if(getOrderID() != MP.completed_order) {
		if(!(getOrderState()&ORDER_ACTIVE)) {
			switch(getOrderType()) {
				case(ORDER_TYPE_FORWARD):
					orderStartForward();
					break;
				case(ORDER_TYPE_LEFT_TURN):
					orderStartLeftTurn();
					break;
				case(ORDER_TYPE_RIGHT_TURN):
					orderStartRightTurn();
					break;
			}
		} else {
			if(MP._rotary_driver_state&ROTARY_DRIVER_ACTIVE) {
				if(rotaryDriverDone()) {
					deactivatePID();
					set_stop();
					setOrderDone();
					MP.completed_order = getOrderID();
					rotaryDriverStop();
					rotaryDriverReset();
					MP.adjust_state = 0;
				}
			} else {
				if(MP._state == PLATFORM_FORWARD) {
					if(getOrderTargetTicks() < cmtoticks(PLATFORM_PID_THRESHOLD)) {
						deactivatePID();
						//set_forward(MOTOR_DEFAULT_SPEED, MOTOR_DEFAULT_SPEED);
						if(getOrderCurrentTicks() >= getOrderTargetTicks()) {
							set_stop();
							setOrderDone();
							MP.completed_order = getOrderID();
							MP.adjust_state = 0;
						}
					} else {

						if(!MP.adjust_state&PLATFORM_ADJUST_DONE) {
							if(getOrderLengthToWall() < 7.0) {
								if(getOrderCurrentTicks() >= getOrderTargetTicks()*0.40 && getOrderCurrentTicks() <= getOrderTargetTicks()*0.60) {
									platformFineAdjust();
								}
							}
						}

						if(getOrderCurrentTicks() >= getOrderTargetTicks()*0.6) {

							if(!checkFrontRight()) {
								deactivatePID();
								set_forward(MP._originalLspeed, MP._originalRspeed);
							}

							if((!checkBackRight() && !checkFrontRight()) || (!checkBackLeft() && !checkFrontLeft())) {
								set_stop();
								deactivatePID();
								if(getOrderLengthToWall() >= 7.0) {
									rotaryDriverStartCM(8);
								} else {
									rotaryDriverStartCM(10);
								}

							}
						}
					}
				} else if(MP._state == PLATFORM_LEFT || MP._state == PLATFORM_RIGHT) {
					deactivatePID();
					if(getOrderCurrentTicks() >= getOrderTargetTicks()) {
						set_stop();
						setOrderDone();
						MP.completed_order = getOrderID();
					}
				}

			}
		}
	}

	if(change==1){
		switch(MP._state){
			case(PLATFORM_STOP):
				_stop();
				break;
			case(PLATFORM_FORWARD):
				_go_forward();
				break;
			case(PLATFORM_BACKWARD):
				_go_backward();
				break;
			case(PLATFORM_LEFT):
				_turn_left();
				break;
			case(PLATFORM_RIGHT):
				_turn_right();
				break;
			default:
				_stop();
				break;
		}
		change=0;
	}
}
Ejemplo n.º 29
0
    //-----------------------------------------------------------------------------
    void MusicStream::_play(size_t id,size_t pos,float fadeIn,bool loop)
    {
        // Checks bounds
        if (id == 0 || id > Database::getSingleton().musics.size())
        {
            SONETTO_THROW("Unknown music ID");
        }

        int errCode;
        char fill;
        std::string path = Music::FOLDER + Database::getSingleton().musics[id-1].
                filename;
        char *constlessStr = new char[path.length()+1];

        // We use this `constlessStr' here because ov_fopen() needs a char *
        // argument as filename, but std::string::c_str() returns a const char *,
        // and I don't like const-casts
        strcpy(constlessStr,path.c_str());

        // Stops current music, if any
        _stop(0.0f);

        // Opens file and checks for errors
        errCode = ov_fopen(constlessStr,&mFile);
        if (errCode != 0)
        {
            SONETTO_THROW("Failed opening OGG/Vorbis file ("+
                    Ogre::StringConverter::toString(errCode)+")");
        }

        // We don't need this anymore
        delete[] constlessStr;

        // Tells the length of our stream
        mStreamLen = static_cast<size_t>(ov_pcm_total(&mFile,-1));
        if ((int)mStreamLen == OV_EINVAL)
        {
            SONETTO_THROW("Failed telling OGG/Vorbis stream length ("+
                    Ogre::StringConverter::toString((int)mStreamLen)+")");
        }

        // Sets current music index
        mMusic = id;

        // Sets fade state and speed
        mFadeSpd = Math::clamp(fadeIn,0.0f,1.0f);
        if (mFadeSpd == 0.0f) {
            mFadeVolume = 1.0f;
            mFade = MF_NO_FADE;
        } else {
            mFadeVolume = 0.0f;
            mFade = MF_FADE_IN;
        }

        // Sets whether to loop or not
        mLoop = loop;

        // Resets stream state
        mState = MSS_IDLE;

        // Seeks stream
        if (pos != 0)
        {
            errCode = ov_pcm_seek(&mFile,pos);
            if (errCode != 0)
            {
                SONETTO_THROW("Couldn't seek OGG/Vorbis stream position");
            }
        }

        // Fills buffers
        fill = 1;
        pullStream(mMusicBuf[0]);
        if (loop) {
            fill = 2;
            pullStream(mMusicBuf[1]);
        } else {
            if (mState != MSS_ENDED)
            {
                fill = 2;
                pullStream(mMusicBuf[1]);
            }
        }

        // Queues buffers
        alSourceQueueBuffers(mMusicSrc,fill,mMusicBuf);
        mAudioMan->_alErrorCheck("MusicStream::_play()",
                                "Failed queuing music buffers");

        // Sets source volume
        alSourcef(mMusicSrc,AL_GAIN,mFadeVolume*mMaxVolume);
        mAudioMan->_alErrorCheck("MusicStream::_play()",
                                "Failed setting music source volume");

        // Starts playing the music
        alSourcePlay(mMusicSrc);
        mAudioMan->_alErrorCheck("MusicStream::_play()",
                                "Failed playing music source");
    }
Ejemplo n.º 30
0
void _turn_right(void) {
	_stop();
	PWM_SetDC(PLATFORM_LEFT_FORWARD ,PLATFORM_PERIOD_PERCENTAGE*MP._Lspeed*MP._left_side._calibrate_speed);
	PWM_SetDC(PLATFORM_RIGHT_BACKWARD ,PLATFORM_PERIOD_PERCENTAGE*MP._Rspeed*MP._right_side._calibrate_speed);
}