EEP fORK
Dependencies: BLE_API mbed nRF51822
Fork of MCS_LRF by
Diff: main.cpp
- Revision:
- 18:08184949ab30
- Parent:
- 17:229d78f063fb
- Child:
- 19:b576835175e2
--- a/main.cpp Fri Jun 16 05:09:17 2017 +0000 +++ b/main.cpp Tue Jul 18 05:17:37 2017 +0000 @@ -65,6 +65,7 @@ InterruptIn triggerButton(p18); // Button 2 #else DigitalOut connectionLed(p23); +//PwmOut connectionLed(p23); // good idea using PwmOut but it seems that period can't be set to longer than about 1s DigitalOut redLed(p24); InterruptIn triggerButton(p22); DigitalOut disableLRF(p28); @@ -84,16 +85,23 @@ Timer timer; Ticker batteryChecker; Ticker activityChecker; +Ticker connectionLedBlinker; uint16_t activityTimeout = ACTIVITY_TIMEOUT_SEC; +// settings for blinking the connection LED- Blink to save power +uint16_t connectionLedOffCount = 0; +#define CONNECTION_LED_OFF_TIME_MS 2000 +#define CONNECTION_LED_ON_TIME_MS 20 +#define CONNECTION_LED_OFF_COUNT (CONNECTION_LED_OFF_TIME_MS / CONNECTION_LED_ON_TIME_MS) + const static char DEVICE_NAME[] = "MCS_LRF"; const static char MANUFACTURER[] = "MCS"; const static char MODEL[] = "Model 2"; const static char SERIAL_NO[] = "SN 1234"; const static char HARDWARE_REV[] = "hw-rev 1.1"; -const static char FIRMWARE_REV[] = "fw-rev 1.4"; -const static char SOFTWARE_REV[] = "soft-rev 1.4"; +const static char FIRMWARE_REV[] = "fw-rev 1.5"; +const static char SOFTWARE_REV[] = "soft-rev 1.5"; // these values must macth definitions in the XML file accompanying this device const static uint16_t distanceCmd = 0x0001; @@ -114,14 +122,18 @@ DEBUG("Restarting the advertising process\n\r"); ble.startAdvertising(); isConnected = 0; - connectionLed = isConnected; + // connectionLed = isConnected; + + // turn off blinking LED + // connectionLed.pulsewidth_ms(0); } void connectionCallback(const Gap::ConnectionCallbackParams_t *params) { DEBUG("Connected!\n\r"); isConnected = 1; - connectionLed = isConnected; + //connectionLed = isConnected; + // connectionLed.pulsewidth_ms(25); } static void processData(const GattWriteCallbackParams *params) @@ -261,6 +273,20 @@ uint8_t buf[1]; bleHelper->sendPacketOverBLE(activityTimeoutCmd, buf, 0); } + +void connectionLedBlinkerTask() +{ + if(isConnected) { + if(connectionLed) { + connectionLed = 0; + connectionLedOffCount = 0; + } else if(++connectionLedOffCount > CONNECTION_LED_OFF_COUNT) { + connectionLed = 1; + } + } else { + connectionLed = 0; + } +} void batteryCheckerTask(void) @@ -374,6 +400,10 @@ laserPtr->enableMeasurement(true); laserPtr->setDistaceCallback(&distanceCallcack); laserPtr->turnLaserPowerOn(); + + // setup blinking connectionLed + // connectionLed.period(2.0f); + connectionLedBlinker.attach(connectionLedBlinkerTask, CONNECTION_LED_ON_TIME_MS / 1000.0f); while (true) { ble.waitForEvent();