/********************************************************************* * @fn SensorTagMov_processCharChangeEvt * * @brief SensorTag Movement event handling * */ void SensorTagMov_processCharChangeEvt(uint8_t paramID) { uint16_t newCfg; uint8_t newValue8; switch (paramID) { case SENSOR_CONF: if ((sensorTestResult() & ST_MPU) == 0) { mpuConfig = ST_CFG_ERROR; } if (mpuConfig != ST_CFG_ERROR) { Movement_getParameter(SENSOR_CONF, &newCfg); if ( (newCfg & MPU_AX_ALL) == ST_CFG_SENSOR_DISABLE) { // All axes off, turn off device power mpuConfig = newCfg; appStateSet(APP_STATE_OFF); } else { // Some axes on; power up and activate MPU mpuConfig = newCfg; appStateSet(APP_STATE_ACTIVE); if (sensorMpu9250PowerIsOn()) { delay_ms(5); mpuConfig = newCfg | (sensorMpu9250AccReadRange() << 8); } } Movement_setParameter(SENSOR_CONF, sizeof(mpuConfig), (uint8_t*)&mpuConfig); } else { // Make sure the previous characteristics value is restored initCharacteristicValue(SENSOR_CONF, mpuConfig, sizeof ( mpuConfig )); } // Data initially zero initCharacteristicValue(SENSOR_DATA, 0, SENSOR_DATA_LEN); break; case SENSOR_PERI: Movement_getParameter(SENSOR_PERI, &newValue8); sensorPeriod = newValue8 * SENSOR_PERIOD_RESOLUTION; Util_rescheduleClock(&periodicClock,sensorPeriod); break; default: // Should not get here break; } }
/********************************************************************* * @fn SensorTagTmp_processCharChangeEvt * * @brief SensorTag IR temperature event handling * */ void SensorTagTmp_processCharChangeEvt(uint8_t paramID) { uint8_t newValue; switch (paramID) { case SENSOR_CONF: if ((sensorTestResult() & ST_IRTEMP) == 0) { sensorConfig = ST_CFG_ERROR; } if (sensorConfig != ST_CFG_ERROR) { IRTemp_getParameter(SENSOR_CONF, &newValue); if (newValue == ST_CFG_SENSOR_DISABLE) { // Reset characteristics initCharacteristicValue(SENSOR_DATA, 0, SENSOR_DATA_LEN); // Deactivate task Task_setPri(Task_handle(&sensorTask), -1); } else { Task_setPri(Task_handle(&sensorTask), SENSOR_TASK_PRIORITY); } sensorConfig = newValue; } else { // Make sure the previous characteristics value is restored initCharacteristicValue(SENSOR_CONF, sensorConfig, sizeof ( uint8_t )); } // Make sure sensor is disabled sensorTmp007Enable(false); break; case SENSOR_PERI: IRTemp_getParameter(SENSOR_PERI, &newValue); sensorPeriod = newValue * SENSOR_PERIOD_RESOLUTION; break; default: // Should not get here break; } }
/********************************************************************* * @fn SensorTagIO_reset * * @brief Reset characteristics * * @param none * * @return none */ void SensorTagIO_reset(void) { ioValue = sensorTestResult(); Io_setParameter( SENSOR_DATA, 1, &ioValue); ioMode = IO_MODE_LOCAL; Io_setParameter( SENSOR_CONF, 1, &ioMode); // Normal mode; make sure LEDs and buzzer are off PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); Clock_stop(buzzClockHandle); PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF); }
/********************************************************************* * @fn SensorTagIO_reset * * @brief Reset characteristics * * @param none * * @return none */ void SensorTagIO_reset(void) { ioValue = sensorTestResult(); Io_setParameter( SENSOR_DATA, 1, &ioValue); ioMode = IO_MODE_LOCAL; Io_setParameter( SENSOR_CONF, 1, &ioMode); // Normal mode; make sure LEDs and buzzer are off PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); if (buzzerOn) { buzzerClose(); buzzerOn = false; } }
/********************************************************************* * @fn SensorTagIO_processCharChangeEvt * * @brief Process a change in the IO characteristics * * @return none */ void SensorTagIO_processCharChangeEvt(uint8_t paramID) { if( paramID == SENSOR_CONF ) { Io_getParameter(SENSOR_CONF, &ioMode); if (ioMode == IO_MODE_SELFTEST) { ioValue = sensorTestResult(); Io_setParameter(SENSOR_DATA, 1, &ioValue); } else { // Mode change: make sure LEDs and buzzer are off Io_setParameter(SENSOR_DATA, 1, &ioValue); PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); Clock_stop(buzzClockHandle); PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF); } } else if (paramID == SENSOR_DATA) { Io_getParameter(SENSOR_DATA, &ioValue); } if (ioMode == IO_MODE_REMOTE) { // Control by remote client: // - possible to operate the LEDs and buzzer // - right key functionality overridden (will not terminate connection) if (!!(ioValue & IO_DATA_LED1)) { PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_ON); } else { PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); } if (!!(ioValue & IO_DATA_LED2)) { PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_ON); } else { PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); } if (!!((ioValue & IO_DATA_BUZZER))) { Clock_start(buzzClockHandle); } else { Clock_stop(buzzClockHandle); PIN_setOutputValue(hGpioPin, Board_BUZZER, Board_BUZZER_OFF); } } }