HRM1017による温度計のサンプルコード。ADT7410で使えるように修正しています。
Dependencies: ADT7410 BLE_API TMP102 mbed nRF51822
Fork of BLE_HTM_HRM1017 by
Diff: main.cpp
- Revision:
- 8:11d990f689fe
- Parent:
- 6:c3d9dbadd654
--- a/main.cpp Sat Sep 13 09:32:10 2014 +0000 +++ b/main.cpp Thu Dec 04 12:53:00 2014 +0000 @@ -1,5 +1,7 @@ +// original: http://developer.mbed.org/users/ytsuboi/code/BLE_HTM_HRM1017/shortlog +// modified for ADT7410 + #include "mbed.h" -#include "TMP102.h" #include "BLEDevice.h" #include "ble_hts.h" @@ -17,8 +19,16 @@ static volatile bool triggerSensorPolling = false; BLEDevice ble; + +#define UseADT7410 +#ifdef UseADT7410 +#include "ADT7410.h" +//ADT7410 healthThemometer(p13, p15, 0x90, 100000); +ADT7410 healthThemometer(p22, p20, 0x90, 100000); +#else +#include "TMP102.h" TMP102 healthThemometer(p22, p20, 0x90); /* The TMP102 connected to our board */ -//TMP102 healthThemometer(I2C_SDA1, I2C_SCL1, 0x90); /* The TMP102 connected to our board */ +#endif /* LEDs for indication: */ DigitalOut oneSecondLed(LED1); /* LED1 is toggled every second. */ @@ -27,20 +37,20 @@ /* Health Thermometer Service */ uint8_t thermTempPayload[5] = { 0, 0, 0, 0, 0 }; - GattCharacteristic tempChar (GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, thermTempPayload, 5, 5, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE); +GattCharacteristic *htmChars[] = {&tempChar, }; +GattService htmService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, htmChars, + sizeof(htmChars) / sizeof(GattCharacteristic *)); + /* Battery Level Service */ uint8_t batt = 100; /* Battery level */ uint8_t read_batt = 0; /* Variable to hold battery level reads */ GattCharacteristic battLevel ( GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, (uint8_t *)batt, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); -GattCharacteristic *htmChars[] = {&tempChar, }; GattCharacteristic *battChars[] = {&battLevel, }; -GattService htmService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, htmChars, - sizeof(htmChars) / sizeof(GattCharacteristic *)); GattService battService(GattService::UUID_BATTERY_SERVICE, battChars, sizeof(battChars) / sizeof(GattCharacteristic *)); @@ -117,6 +127,9 @@ ble.addService(htmService); ble.addService(battService); DEBUG("Add Service\n"); + + healthThemometer.reset(); + //healthThemometer.setConfig(ONE_SPS_MODE); while (true) { if (triggerSensorPolling) { @@ -133,13 +146,18 @@ @brief Ticker callback to switch advertisingStateLed state */ /**************************************************************************/ +#include <stdlib.h> void updateServiceValues(void) { /* Decrement the battery level. */ batt <=50 ? batt=100 : batt--; /* Update the temperature. Note that we need to convert to an ieee11073 format float. */ +#ifdef UseADT7410 + float temperature = healthThemometer.getTemp(); +#else float temperature = healthThemometer.read(); +#endif DEBUG("temp:%f\n", temperature); uint32_t temp_ieee11073 = quick_ieee11073_from_float(temperature); memcpy(thermTempPayload+1, &temp_ieee11073, 4);