Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADT7410 BLE_API TMP102 mbed nRF51822
Fork of BLE_HTM_HRM1017 by
Revision 2:daf2344afc28, committed 2014-09-05
- Comitter:
- todotani
- Date:
- Fri Sep 05 14:26:54 2014 +0000
- Parent:
- 1:50056f53e2ac
- Child:
- 3:104e7760e176
- Commit message:
- BLE_Health_Thermometer for mbed HRM1017 with BLE library 0.1.0
Changed in this revision
--- a/BLE_API.lib Fri Aug 22 11:32:14 2014 +0000 +++ b/BLE_API.lib Fri Sep 05 14:26:54 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#189ff241dae1 +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#ca826083980e
--- a/main.cpp Fri Aug 22 11:32:14 2014 +0000
+++ b/main.cpp Fri Sep 05 14:26:54 2014 +0000
@@ -14,6 +14,7 @@
#endif /* #if NEED_CONSOLE_OUTPUT */
const static char DEVICE_NAME[] = "HRM1017_HTM";
+static volatile bool triggerSensorPolling = false;
BLEDevice ble;
TMP102 healthThemometer(p22, p20, 0x90); /* The TMP102 connected to our board */
@@ -50,7 +51,7 @@
static Gap::ConnectionParams_t connectionParams;
-void disconnectionCallback(Gap::Handle_t handle)
+void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) // Mod
{
advertisingStateLed = 1;
@@ -59,7 +60,7 @@
ble.startAdvertising();
}
-void onConnectionCallback(Gap::Handle_t handle)
+void onConnectionCallback(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) //Mod
{
advertisingStateLed = 0;
@@ -71,6 +72,15 @@
}
}
+void periodicCallback(void)
+{
+ oneSecondLed = !oneSecondLed; /* Do blinky on LED1 while we're waiting for BLE events */
+
+ /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
+ * heavy-weight sensor polling from the main thread. */
+ triggerSensorPolling = true;
+}
+
/**************************************************************************/
/*!
@brief Program entry point
@@ -81,9 +91,12 @@
/* Setup blinky led */
oneSecondLed = 1;
-
- DEBUG("Initialising the nRF51822\n\r");
+ Ticker ticker;
+ ticker.attach(periodicCallback, 1);
+
+ DEBUG("Initialising the nRF51822\n");
ble.init();
+ DEBUG("Init done\n");
ble.onDisconnection(disconnectionCallback);
ble.onConnection(onConnectionCallback);
@@ -98,16 +111,19 @@
ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
ble.startAdvertising();
advertisingStateLed = 1;
+ DEBUG("Start Advertising\n");
ble.addService(htmService);
ble.addService(battService);
+ DEBUG("Add Service\n");
- for (;;)
- {
- /* Now that we're live, update the battery level & temperature characteristics */
- updateServiceValues();
- wait(1);
- ble.waitForEvent();
+ while (true) {
+ if (triggerSensorPolling) {
+ triggerSensorPolling = false;
+ updateServiceValues();
+ } else {
+ ble.waitForEvent();
+ }
}
}
@@ -118,9 +134,6 @@
/**************************************************************************/
void updateServiceValues(void)
{
- /* Toggle the one second LEDs */
- oneSecondLed = !oneSecondLed;
-
/* Decrement the battery level. */
batt <=50 ? batt=100 : batt--;
@@ -129,8 +142,8 @@
DEBUG("temp:%f\n", temperature);
uint32_t temp_ieee11073 = quick_ieee11073_from_float(temperature);
memcpy(thermTempPayload+1, &temp_ieee11073, 4);
- ble.updateCharacteristicValue(tempChar.getHandle(), thermTempPayload, sizeof(thermTempPayload));
- ble.updateCharacteristicValue(battLevel.getHandle(), (uint8_t *)&batt, sizeof(batt));
+ ble.updateCharacteristicValue(tempChar.getValueAttribute().getHandle(), thermTempPayload, sizeof(thermTempPayload)); //Mod
+ ble.updateCharacteristicValue(battLevel.getValueAttribute().getHandle(), (uint8_t *)&batt, sizeof(batt)); //Mod
}
/**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Fri Sep 05 14:26:54 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/todotani/code/mbed-src/#59cc78a25982
--- a/mbed.bld Fri Aug 22 11:32:14 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file
--- a/nRF51822.lib Fri Aug 22 11:32:14 2014 +0000 +++ b/nRF51822.lib Fri Sep 05 14:26:54 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/todotani/code/nRF51822/#f3badab88f02 +http://mbed.org/users/todotani/code/nRF51822-60/#214f61f4d5f8
