Scott Jenson / Mbed 2 deprecated BLE_EddystoneBeaconConfigService_Button

Dependencies:   BLE_API_EddystoneConfigService_2 mbed nRF51822

Fork of BLE_EddystoneBeaconConfigService_3 by URIBeacon

Revision:
4:4440953bde10
Parent:
0:c04d932e96c9
Child:
6:e90c398b03e0
diff -r 8020d6d4455a -r 4440953bde10 ZipBeaconConfigService.h
--- a/ZipBeaconConfigService.h	Thu May 14 16:54:00 2015 +0000
+++ b/ZipBeaconConfigService.h	Fri May 15 08:13:35 2015 +0000
@@ -261,6 +261,21 @@
             params.txPowerMode = *(writeParams->data);
         } else if (handle == beaconPeriodChar.getValueHandle()) {
             params.beaconPeriod = *((uint16_t *)(writeParams->data));
+
+            /* Re-map beaconPeriod to within permissible bounds if necessary. */
+            if (params.beaconPeriod != 0) {
+                bool paramsUpdated = false;
+                if (params.beaconPeriod < ble.getMinAdvertisingInterval()) {
+                    params.beaconPeriod = ble.getMinAdvertisingInterval();
+                    paramsUpdated = true;
+                } else if (params.beaconPeriod > ble.getMaxAdvertisingInterval()) {
+                    params.beaconPeriod = ble.getMaxAdvertisingInterval();
+                    paramsUpdated = true;
+                }
+                if (paramsUpdated) {
+                    ble.updateCharacteristicValue(beaconPeriodChar.getValueHandle(), reinterpret_cast<uint8_t *>(&params.beaconPeriod), sizeof(uint16_t));
+                }
+            }
         } else if (handle == resetChar.getValueHandle()) {
             resetToDefaults();
         }