Duy tran / Mbed OS BLE_Bike

Dependencies:   DHT22

Revision:
2:65ed7cd0480c
Parent:
1:8db3d642a94f
Child:
3:d6fbd4f3a3d4
--- a/source/main.cpp	Thu Nov 02 17:44:51 2017 +0000
+++ b/source/main.cpp	Thu Nov 02 18:38:02 2017 +0000
@@ -4,12 +4,12 @@
   * the bike, turn on the alarm system of the bike, turn on the light...
   * Temperature sensor is also included in the device. User can view the temperature when he/she gets
   * near the bike.
-  * For the next version, humidity and air quality sensor are also added.
   
   * Revision:
   * v0_1: only one switch is used.
   * v0_5: another switch is added.
   * v0_7: thermometer is added. User can view thermomether data on the phone. 
+  * v0_8: humidity and air quality are added. User can view measured data on the phone. 
   */
 
 /* ======================== INCLUDES ========================= */
@@ -22,7 +22,9 @@
 
 /* ======================= VARIABLES ========================= */
 /* GLOBAL VARIABLES */
-int16_t currentTemperature;
+int16_t currentTemperature = 19;
+uint8_t currentHumidity    = 35;
+uint16_t currentAirQuality = 550;
 
 /* PRIVATE VARIABLES */
 const static char     DEVICE_NAME[] = "WAVE ALPHA 8214";
@@ -40,15 +42,17 @@
 /* A connection should be re-enabled after the device and the device
  * disconnected
  */
-void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
-{
+void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) {
     (void) params;
     BLE::Instance().gap().startAdvertising();
 }
 
-void main_event(void)
-{
+void main_event(void) {
     /* Any code can be added here */
+    currentTemperature++;
+    currentHumidity += 7;
+    currentAirQuality += 129;
+    bikeServicePtr->updateAllCharacteristics(currentTemperature, currentHumidity, currentAirQuality);
 }
 
 /**
@@ -100,7 +104,7 @@
     ble.gattServer().onDataWritten(receiveDataCallback);
 
     bool initialSwitchState = false;
-    bikeServicePtr = new bikeService(ble, initialSwitchState);
+    bikeServicePtr = new bikeService(ble, initialSwitchState, currentTemperature, currentHumidity, currentAirQuality);
 
     /* setup advertising */
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);