workss
Dependencies: mbed BLE_API nRF51822 VL53L0X
Diff: main.cpp
- Revision:
- 27:903ec28ea7a0
- Parent:
- 26:793d65b08afb
- Child:
- 28:ca14866eec64
diff -r 793d65b08afb -r 903ec28ea7a0 main.cpp --- a/main.cpp Thu Mar 07 19:09:08 2019 +0000 +++ b/main.cpp Wed Mar 13 14:19:08 2019 +0000 @@ -2,8 +2,6 @@ #include "ble/BLE.h" #include "VL53L0X.h" #include "ble/services/HeartRateService.h" -#include "ble/services/BatteryService.h" -#include "ble/services/DeviceInformationService.h" #define range1_addr (0x56) #define range2_addr (0x60) @@ -28,6 +26,8 @@ uint32_t distance1; uint32_t distance2; +int dist1; +int dist2; int status1; int status2; @@ -35,7 +35,6 @@ static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; //Custom UUID, FFFF is reserved for development HeartRateService *hrService; -DeviceInformationService *deviceInfo; uint8_t hrmCounter = 0; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *) @@ -64,17 +63,34 @@ ble.gap().startAdvertising(); } + +int format_dist(int distance) { + // local variable declaration + int result; + + if (distance > 1270) + result = 127; + else + result = distance/10; + + return result; +} + void wakeup_event_cb() { led != led; status1 = range1.get_distance(&distance1); status2 = range2.get_distance(&distance2); + dist1 = format_dist(distance1); + dist2 = format_dist(distance2); + if (status1 == VL53L0X_ERROR_NONE) { - printf("Range1 [mm]: %6ld\r\n", distance1); - if (distance1 > 40 && distance1 < 2200) { + printf("Range1 [mm]: %6ld\r\n", dist1); + if (dist1 > 4 && dist1 < 220) { led1 = 0; - hrmCounter++; + hrmCounter = dist1; + hrService->updateHeartRate(hrmCounter); } else { led1 = 1; @@ -84,16 +100,16 @@ led1 = 1; } if (status2 == VL53L0X_ERROR_NONE) { - printf("Range2 [mm]: %6ld\r\n", distance2); - if (distance2 > 40 && distance2 < 2200) { - led2 = 0; - hrmCounter++; - } + printf("Range2 [mm]: %6ld\r\n", dist2); + if (dist2 > 4 && dist2 < 220) { + led2 = 0; + hrmCounter = dist2; + hrService->updateHeartRate(hrmCounter); + } } else { printf("Range2 [mm]: --\r\n"); led2 = 1; } - hrService->updateHeartRate(hrmCounter); } int main(void)