key lock and rear light

Dependencies:   BLE_API BMA250E mbed nRF51822

/media/uploads/mtmkimi/mbed-bike.jpeg

MtConnect04S Bike Proximity Lock

We have full tutorial, please visit our blog

Revision:
2:7920d3227906
Parent:
1:9f5ecbaa7606
--- a/main.cpp	Thu Nov 24 07:55:46 2016 +0000
+++ b/main.cpp	Mon Dec 19 11:06:00 2016 +0000
@@ -1,8 +1,23 @@
-
+/* Copyright (c) 2016 MtM Technology Corporation, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+ * and associated documentation files (the "Software"), to deal in the Software without restriction, 
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or 
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
 #include "mbed.h"
 #include "ble/BLE.h"
-#include "BMA250.h"
-
+#include "BMA250E.h"
 
 /* UART printf */
 Serial pc(p5, p4);
@@ -14,13 +29,13 @@
 PwmOut bz(p1);
 
 /* Sensor */
-BMA250 bma250(p14, p13, p0, NC);
+BMA250E acclerameter(p14, p13, p0, NC);
 
 /* UUID, Device name */
-uint16_t syncServUUID = 0x180A; /* Synchronize the status of Rear light with Head light */
+uint16_t syncServUUID = GattService::UUID_DEVICE_INFORMATION_SERVICE; /* Synchronize the status of Rear light with Head light */
 uint16_t syncCharUUID = 0x2B03;
-static const char     DEVICE_NAME[] = "ASE_proximity";   //"mbed Proximity";
-static const uint16_t uuid16_list[] = { 0x180A };
+static const char     DEVICE_NAME[] = "MtM Proximity";
+static const uint16_t uuid16_list[] = { syncServUUID };
 
 /* Setup custom characteristics */
 uint8_t syncPayload[1];
@@ -32,7 +47,6 @@
 GattCharacteristic *characteristics[] = {&syncChar};
 GattService syncServ(syncServUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
 
-
 void rl_on(void)
 {
     rl = 1;
@@ -65,7 +79,7 @@
 {
     pc.printf("connection\n");
 
-    bma250.EnterStandbyMode();  // sensor enters standby mode
+    acclerameter.EnterStandbyMode();  // sensor enters standby mode
 
     /* flash and beep 1 times */
     rl_on();
@@ -98,7 +112,7 @@
     rl_off();
     bz_off();
 
-    bma250.LeaveStandbyMode();  // sensor leaves standby mode (enters normal mode)
+    acclerameter.LeaveStandbyMode();  // sensor leaves standby mode (enters normal mode)
 }
     
 void dataWrittenCallback(const GattWriteCallbackParams *params)
@@ -177,7 +191,7 @@
     wait(0.8);
 }
 
-void BMA250_int1Callback() {
+void AcclerameterOnShaked() {
     pc.printf("BMA250_int1\n");
 
 #if 1
@@ -199,6 +213,7 @@
         return;
     }
 
+    ble.setDeviceName((const uint8_t *)DEVICE_NAME);
     ble.gap().onConnection(connectionCallback);
     ble.gap().onDisconnection(disconnectionCallback);
     ble.gattServer().onDataWritten(dataWrittenCallback);
@@ -232,7 +247,7 @@
     bz_off();
 
     /* Config sensor */
-    bma250.ShakeDetection(&BMA250_int1Callback, 1);
+    acclerameter.ShakeDetection(&AcclerameterOnShaked);
 
     /* Main loop */
     while (1) {