コード例 #1
0
ファイル: temp.c プロジェクト: nodish/openthread
void nrf5TempProcess(void)
{
    int32_t  prevTemperature = sTemperature;
    uint64_t now;

#if SOFTDEVICE_PRESENT
    now = nrf5AlarmGetCurrentTime();

    if (now - sLastReadTimestamp > (TEMP_MEASUREMENT_INTERVAL * US_PER_S))
    {
        (void)sd_temp_get(&sTemperature);
        sLastReadTimestamp = now;
    }
#else
    if (NRF_TEMP->EVENTS_DATARDY)
    {
        dataReadyEventClear();

        sTemperature = nrf_temp_read();
    }

    now = nrf5AlarmGetCurrentTime();

    if (now - sLastReadTimestamp > (TEMP_MEASUREMENT_INTERVAL * US_PER_S))
    {
        NRF_TEMP->TASKS_START = 1;
        sLastReadTimestamp    = now;
    }
#endif

    if (prevTemperature != sTemperature)
    {
        nrf_802154_temperature_changed();
    }
}
コード例 #2
0
ファイル: conn_mw_nrf_soc.c プロジェクト: DanielOld/wlock
uint32_t conn_mw_temp_get(uint8_t const * const p_rx_buf,
                          uint32_t              rx_buf_len,
                          uint8_t * const       p_tx_buf,
                          uint32_t * const      p_tx_buf_len)
{
    SER_ASSERT_NOT_NULL(p_rx_buf);
    SER_ASSERT_NOT_NULL(p_tx_buf);
    SER_ASSERT_NOT_NULL(p_tx_buf_len);

    int32_t   temperature;
    int32_t * p_temperature = &temperature;

    uint32_t err_code = NRF_SUCCESS;
    uint32_t sd_err_code;

    err_code = temp_get_req_dec(p_rx_buf, rx_buf_len, &p_temperature);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

    sd_err_code = sd_temp_get(p_temperature);

    err_code = temp_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_temperature);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

    return err_code;
}
コード例 #3
0
/**
  * Updates the temperature sample of this instance of MicroBitThermometer
  * only if isSampleNeeded() indicates that an update is required.
  *
  * This call also will add the thermometer to fiber components to receive
  * periodic callbacks.
  *
  * @return MICROBIT_OK on success.
  */
int MicroBitThermometer::updateSample()
{
    if(!(status & MICROBIT_THERMOMETER_ADDED_TO_IDLE))
    {
        // If we're running under a fiber scheduer, register ourselves for a periodic callback to keep our data up to date.
        // Otherwise, we do just do this on demand, when polled through our read() interface.
        fiber_add_idle_component(this);
        status |= MICROBIT_THERMOMETER_ADDED_TO_IDLE;
    }

    // check if we need to update our sample...
    if(isSampleNeeded())
    {
        int32_t processorTemperature;
        uint8_t sd_enabled;

        // For now, we just rely on the nrf senesor to be the most accurate.
        // The compass module also has a temperature sensor, and has the lowest power consumption, so will run the cooler...
        // ...however it isn't trimmed for accuracy during manufacture, so requires calibration.

        sd_softdevice_is_enabled(&sd_enabled);

        if (sd_enabled)
        {
            // If Bluetooth is enabled, we need to go through the Nordic software to safely do this
            sd_temp_get(&processorTemperature);
        }
        else
        {
            // Othwerwise, we access the information directly...
            uint32_t *TEMP = (uint32_t *)0x4000C508;

            NRF_TEMP->TASKS_START = 1;

            while (NRF_TEMP->EVENTS_DATARDY == 0);

            NRF_TEMP->EVENTS_DATARDY = 0;

            processorTemperature = *TEMP;

            NRF_TEMP->TASKS_STOP = 1;
        }


        // Record our reading...
        temperature = processorTemperature / 4;

        // Schedule our next sample.
        sampleTime = system_timer_current_time() + samplePeriod;

        // Send an event to indicate that we'e updated our temperature.
        MicroBitEvent e(id, MICROBIT_THERMOMETER_EVT_UPDATE);
    }

    return MICROBIT_OK;
};
コード例 #4
0
ファイル: temperature.c プロジェクト: foldedtoad/eddystone
/*---------------------------------------------------------------------------*/
uint16_t temperature_data_get(void)
{
    int32_t temp;

    APP_ERROR_CHECK( sd_temp_get(&temp) );

    int8_t hi = (temp / 4);
    int8_t lo = (temp * 25) % 100;

    return (hi << 8) | lo;
}
コード例 #5
0
void nRF51822::requestTemperature() {
#ifndef __RFduino__
  int32_t rawTemperature = 0;

  sd_temp_get(&rawTemperature);

  float temperature = rawTemperature / 4.0;

  if (this->_eventListener) {
    this->_eventListener->BLEDeviceTemperatureReceived(*this, temperature);
  }
#endif
}
コード例 #6
0
ファイル: main.c プロジェクト: Chadizzm/nrf51-ble-app-temp
uint32_t temperature_data_get(void)
{
    int32_t temp;
    uint32_t err_code;
    
    err_code = sd_temp_get(&temp);
    APP_ERROR_CHECK(err_code);
    
    temp = (temp / 4) * 100;
    
    int8_t exponent = -2;
    return ((exponent & 0xFF) << 24) | (temp & 0x00FFFFFF);
}
コード例 #7
0
/**
 * Updates our recorded temperature from the many sensors on the micro:bit!
 */
void MicroBitThermometer::updateTemperature()
{
    int32_t processorTemperature;

    // For now, we just rely on the nrf senesor to be the most accurate.
    // The compass module also has a temperature sensor, and has the lowest power consumption, so will run the cooler...
    // ...however it isn't trimmed for accuracy during manufacture, so requires calibration.

    if (uBit.ble)
    {
        // If Bluetooth is enabled, we need to go through the Nordic software to safely do this
        sd_temp_get(&processorTemperature);
    }
    else
    {
        // Othwerwise, we access the information directly...
        uint32_t *TEMP = (uint32_t *)0x4000C508;

        NRF_TEMP->TASKS_START = 1;

        while (NRF_TEMP->EVENTS_DATARDY == 0);

        NRF_TEMP->EVENTS_DATARDY = 0;  

        processorTemperature = *TEMP;

        NRF_TEMP->TASKS_STOP = 1;
    }


    // Record our reading...
    temperature = processorTemperature / 4;

    // Schedule our next sample.
    sampleTime = ticks + samplePeriod;
    
    // Send an event to indicate that we'e updated our temperature.
    MicroBitEvent e(id, MICROBIT_THERMOMETER_EVT_UPDATE);
}
コード例 #8
0
ファイル: main.c プロジェクト: ruuvi/ruuvitag_fw
static void main_sensor_task(void* p_data, uint16_t length)
{
  // Signal mode by led color.
  if (RAWv1 == tag_mode) { RED_LED_ON; }
  else { GREEN_LED_ON; }

  int32_t  raw_t  = 0;
  uint32_t raw_p = 0;
  uint32_t raw_h = 0;
  lis2dh12_sensor_buffer_t buffer;
  int32_t acc[3] = {0};

  if (fast_advertising && ((millis() - fast_advertising_start) > ADVERTISING_STARTUP_PERIOD))
  {
    fast_advertising = false;
    bluetooth_configure_advertisement_type(APPLICATION_ADVERTISEMENT_TYPE);

    bluetooth_configure_advertising_interval(advertising_rates[tag_mode] + advertisement_delay);
    bluetooth_apply_configuration();
  }

  // If we have all the sensors.
  if (model_plus)
  {
    // Get raw environmental data.
    bme280_read_measurements();
    raw_t = bme280_get_temperature();
    raw_p = bme280_get_pressure();
    raw_h = bme280_get_humidity();

    // Get accelerometer data.
    lis2dh12_read_samples(&buffer, 1);
    acc[0] = buffer.sensor.x;
    acc[1] = buffer.sensor.y;
    acc[2] = buffer.sensor.z;
  }
  // If only temperature sensor is present.
  else
  {
    int32_t temp;                                        // variable to hold temp reading
    (void)sd_temp_get(&temp);                            // get new temperature
    temp *= 25;                                          // SD returns temp * 4. Ruuvi format expects temp * 100. 4*25 = 100.
    raw_t = (int32_t) temp;
  }

  // Embed data into structure for parsing.
  parseSensorData(&data, raw_t, raw_p, raw_h, vbat, acc);
  NRF_LOG_DEBUG("temperature: %d, pressure: %d, humidity: %d x: %d y: %d z: %d\r\n", raw_t, raw_p, raw_h, acc[0], acc[1], acc[2]);
  NRF_LOG_DEBUG("VBAT: %d send %d \r\n", vbat, data.vbat);
  // Prepare bytearray to broadcast.
  bme280_data_t environmental;
  environmental.temperature = raw_t;
  environmental.humidity = raw_h;
  environmental.pressure = raw_p;

  switch(tag_mode)
  {
    case RAWv2_FAST:
    case RAWv2_SLOW:
      encodeToRawFormat5(data_buffer, &environmental, &buffer.sensor, acceleration_events, vbat, BLE_TX_POWER);
      break;
    
    case RAWv1:
    default:
      encodeToSensorDataFormat(data_buffer, &data);
      break;
  }

  updateAdvertisement();
  watchdog_feed();
}