HRM1017による温度計のサンプルコード。ADT7410で使えるように修正しています。
Dependencies: ADT7410 BLE_API TMP102 mbed nRF51822
Fork of BLE_HTM_HRM1017 by
Revision 8:11d990f689fe, committed 2014-12-04
- Comitter:
- nobukuma
- Date:
- Thu Dec 04 12:53:00 2014 +0000
- Parent:
- 7:794248dbc19b
- Child:
- 9:7b2f0da06ac3
- Commit message:
- modified for ADT7410
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ADT7410.lib Thu Dec 04 12:53:00 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tkreyche/code/ADT7410/#e1aee50340ec
--- a/BLE_API.lib Sat Sep 13 09:32:10 2014 +0000 +++ b/BLE_API.lib Thu Dec 04 12:53:00 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#0fb20195102b +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#4b68a819ab4f
--- 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);
--- a/nRF51822.lib Sat Sep 13 09:32:10 2014 +0000 +++ b/nRF51822.lib Thu Dec 04 12:53:00 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#98215c4f3a25 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#b4a3693da52b