working
Dependencies: mbed BLE_API nRF51822 VL53L0X
Revision 24:931eeb8a70fc, committed 2019-03-07
- Comitter:
- vazbyte
- Date:
- Thu Mar 07 14:44:31 2019 +0000
- Parent:
- 23:52e8e05df60c
- Commit message:
- working;
Changed in this revision
| VL53L0X.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VL53L0X.lib Thu Mar 07 14:44:31 2019 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/teams/ST/code/VL53L0X/#d25c4fa216af
--- a/main.cpp Thu Mar 07 14:18:32 2019 +0000
+++ b/main.cpp Thu Mar 07 14:44:31 2019 +0000
@@ -1,11 +1,34 @@
#include "mbed.h"
#include "ble/BLE.h"
+#include "mbed.h"
+#include "VL53L0X.h"
-DigitalOut led(LED1, 1);
+#define range1_addr (0x56)
+#define range2_addr (0x60)
+#define range1_XSHUT p15
+#define range2_XSHUT p16
+#define VL53L0_I2C_SDA p30
+#define VL53L0_I2C_SCL p7
+
+Serial pc(USBTX, USBRX);
+static DevI2C devI2c(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led(LED3, 1);
uint16_t customServiceUUID = 0xA000;
uint16_t readCharUUID = 0xA001;
uint16_t writeCharUUID = 0xA002;
+static DigitalOut shutdown1_pin(range1_XSHUT);
+static VL53L0X range1(&devI2c, &shutdown1_pin, NC);
+static DigitalOut shutdown2_pin(range2_XSHUT);
+static VL53L0X range2(&devI2c, &shutdown2_pin, NC);
+
+uint32_t distance1;
+uint32_t distance2;
+int status1;
+int status2;
+
const static char DEVICE_NAME[] = "OCCUPY-CRICHTON-ST"; // change this
static const uint16_t uuid16_list[] = {0xFFFF}; //Custom UUID, FFFF is reserved for development
@@ -20,9 +43,6 @@
GattCharacteristic *characteristics[] = {&readChar, &writeChar};
GattService customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
-/*
- * Restart advertising when phone app disconnects
-*/
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *)
{
BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
@@ -49,9 +69,7 @@
BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(readChar.getValueHandle(), params->data, params->len);
}
}
-/*
- * Initialization callback
- */
+
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
{
BLE &ble = params->ble;
@@ -79,22 +97,48 @@
}
void wakeup_event_cb() {
led != led;
+
+ status1 = range1.get_distance(&distance1);
+ status2 = range2.get_distance(&distance2);
+ if (status1 == VL53L0X_ERROR_NONE) {
+ printf("Range1 [mm]: %6ld\r\n", distance1);
+ if (distance1 > 40 && distance1 < 2200) {
+ led1 = 0;
+ }
+ else {
+ led1 = 1;
+ }
+ } else {
+ printf("Range1 [mm]: --\r\n");
+ led1 = 1;
+ }
+ if (status2 == VL53L0X_ERROR_NONE) {
+ printf("Range2 [mm]: %6ld\r\n", distance2);
+ if (distance2 > 40 && distance2 < 2200) {
+ led2 = 0;
+ }
+ } else {
+ printf("Range2 [mm]: --\r\n");
+ led2 = 1;
+ }
+// wait(0.2);
}
int main(void)
{
- /* initialize stuff */
+ range1.init_sensor(range1_addr);
+ range2.init_sensor(range2_addr);
+
printf("\n\r********* Starting Main Loop *********\n\r");
-
+
BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
ble.init(bleInitComplete);
Ticker ticker;
- int counter = 0;
+
ticker.attach(wakeup_event_cb, 0.3);
+
while (ble.hasInitialized()) {
- counter++;
- printf("hello %i!\n", counter);
- ble.waitForEvent(); /* Save power */
+ ble.waitForEvent();
}
}
\ No newline at end of file