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: BLE_API mbed nRF51822
Fork of SensorModulePIR by
Diff: main.cpp
- Revision:
- 5:173ffbf84b3a
- Parent:
- 4:de22f0d73c12
- Child:
- 6:80f2517965bb
--- a/main.cpp Mon May 08 14:28:30 2017 +0000
+++ b/main.cpp Mon May 08 14:34:36 2017 +0000
@@ -43,6 +43,46 @@
DigitalOut ledB(PIN_BLED_PCB, 1);
DigitalOut ledR(PIN_RLED_PCB, 1);
+
+bool presence = false;
+bool presenceL = false;
+uint8_t presence_count = 0;
+bool ledOn = 0;
+bool battNotify = 1;
+static volatile bool triggerPresencePolling = false;
+
+
+/* BLE CONFIGURATION */
+
+BLE ble;
+static const char DEVICE_NAME[] = "SM4";
+static const uint16_t uuid16_list[] = {GattService::UUID_HEALTH_THERMOMETER_SERVICE};
+static volatile bool triggerSensorPolling = false;
+static char fwversion[31] = "CAT-1817";
+static uint8_t batteryLevel = 100;
+static int8_t TxPower = +4;
+
+static HealthThermometerService *thermometerServicePtr;
+PresenceDetectionService *presenceService = NULL;
+HumidityMeasureService *humidityService = NULL;
+UARTService *uart;
+const static uint8_t ManufData[] = {0x01,0x02,0x03,0x04,0x05}; // Set up to 26B of advertising data to use for the Manufacturer data.
+
+// Firmware
+GattCharacteristic fwChars(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, (uint8_t *)fwversion, sizeof(fwversion), sizeof(fwversion),GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
+GattCharacteristic *firmwareChars[] = {&fwChars };
+GattService firmwareService(GattService::UUID_DEVICE_INFORMATION_SERVICE, firmwareChars, sizeof(firmwareChars) / sizeof(GattCharacteristic *));
+
+//Battery
+GattCharacteristic batteryPercentage(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, (uint8_t *)batteryLevel, sizeof(batteryLevel), sizeof(batteryLevel), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
+GattCharacteristic *batteryChars[] = {&batteryPercentage};
+GattService batteryService(GattService::UUID_BATTERY_SERVICE, batteryChars, sizeof(batteryChars) / sizeof(GattCharacteristic *));
+
+//Power
+GattCharacteristic TxPowerChar(GattCharacteristic::UUID_TX_POWER_LEVEL_CHAR, (uint8_t*)&TxPower, sizeof(TxPower), sizeof(TxPower), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
+GattCharacteristic *charTable[] = {&TxPowerChar};
+GattService TxPowerService(GattService::UUID_TX_POWER_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
+
/* BATTERY MEASUREMENT */
void my_analogin_init(void)
{
@@ -99,44 +139,6 @@
return battLevel;
}
-/* BLE CONFIGURATION */
-
-BLE ble;
-static const char DEVICE_NAME[] = "SM4";
-static const uint16_t uuid16_list[] = {GattService::UUID_HEALTH_THERMOMETER_SERVICE};
-static volatile bool triggerSensorPolling = false;
-static char fwversion[31] = "CAT-1817";
-static uint8_t batteryLevel = 100;
-static int8_t TxPower = +4;
-
-static HealthThermometerService *thermometerServicePtr;
-PresenceDetectionService *presenceService = NULL;
-HumidityMeasureService *humidityService = NULL;
-UARTService *uart;
-const static uint8_t ManufData[] = {0x01,0x02,0x03,0x04,0x05}; // Set up to 26B of advertising data to use for the Manufacturer data.
-
-// Firmware
-GattCharacteristic fwChars(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, (uint8_t *)fwversion, sizeof(fwversion), sizeof(fwversion),GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
-GattCharacteristic *firmwareChars[] = {&fwChars };
-GattService firmwareService(GattService::UUID_DEVICE_INFORMATION_SERVICE, firmwareChars, sizeof(firmwareChars) / sizeof(GattCharacteristic *));
-
-//Battery
-GattCharacteristic batteryPercentage(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, (uint8_t *)batteryLevel, sizeof(batteryLevel), sizeof(batteryLevel), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
-GattCharacteristic *batteryChars[] = {&batteryPercentage};
-GattService batteryService(GattService::UUID_BATTERY_SERVICE, batteryChars, sizeof(batteryChars) / sizeof(GattCharacteristic *));
-
-//Power
-GattCharacteristic TxPowerChar(GattCharacteristic::UUID_TX_POWER_LEVEL_CHAR, (uint8_t*)&TxPower, sizeof(TxPower), sizeof(TxPower), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
-GattCharacteristic *charTable[] = {&TxPowerChar};
-GattService TxPowerService(GattService::UUID_TX_POWER_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
-
-
-bool presence = false;
-bool presenceL = false;
-uint8_t presence_count = 0;
-bool ledOn = 0;
-static volatile bool triggerPresencePolling = false;
-
void blinkLed (bool enable, int color)
{
if (enable) {
@@ -380,7 +382,7 @@
// Red LED blinks if low battery, at every connection
if (batteryLevel <= 10) {
- blinkLed(1,2);
+ blinkLed(battNotify,2);
}
} else {
