Exemple #1
0
void MysensorTag_updateAdvertisingData(void)
{

 uint16_t RawTemperature, RawHumidity;
 bStatus_t st1,st2,st3, st4;
 uint8_t period, config, HumiditySensorON=1;
 uint8_t HumRawData[4]; // humidity sensor raw data
 float temperature,humidity; // temperature and humidity measurements in Celcius and %

// set parameter
 st1 =  Humidity_setParameter(SENSOR_CONF,1,&HumiditySensorON); // turn on
 //SensorTagHum_processCharChangeEvt(SENSOR_CONF); // enable humidity sensing
 // SensorTag_enqueueMsg(ST_CHAR_CHANGE_EVT, SERVICE_ID_HUM, SENOSR_CONF);


 // get parameter
 st2 =  Humidity_getParameter(SENSOR_PERI, &period);
 st3 =  Humidity_getParameter(SENSOR_CONF, &config);
 st4 =  Humidity_getParameter(SENSOR_DATA, &HumRawData);

 // raw temperature and humidity
 RawTemperature = HumRawData[0] | (HumRawData[1]<<8);
 RawHumidity = HumRawData[2] | (HumRawData[3]<<8);
 sensorHdc1000Convert(RawTemperature, RawHumidity,&temperature, &humidity);

 // update advertisement data
 advertData[KEY_STATE_OFFSET+1] = (uint8_t)temperature;
 advertData[KEY_STATE_OFFSET+2] = (uint8_t)humidity;
 GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
}
/*********************************************************************
 * @fn      SensorTagHum_processCharChangeEvt
 *
 * @brief   SensorTag Humidity event handling
 *
 * @param   none
 *
 * @return  none
 */
void SensorTagHum_processCharChangeEvt(uint8_t paramID)
{
  uint8_t newValue;

  switch (paramID)
  {
  case  SENSOR_CONF:
    if ((SensorTag_testResult() & SENSOR_HUM_TEST_BM) == 0)
    {
      sensorConfig = ST_CFG_ERROR;
    }

    if (sensorConfig != ST_CFG_ERROR)
    {
      Humidity_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
      {
        // Activate task
        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));
    }
    break;

  case SENSOR_PERI:
    Humidity_getParameter(SENSOR_PERI, &newValue);
    sensorPeriod = newValue * SENSOR_PERIOD_RESOLUTION;
    break;

  default:
    // Should not get here
    break;
  }
}