Abdul Alf / Mbed 2 deprecated SDP_Version3_Abdul

Dependencies:   BLE_API mbed nRF51822

Fork of SDP_Version3_Abdul by Michael Galis

Revision:
6:60f89e533491
Parent:
4:caab577334f0
Child:
7:79e6de3b27d4
--- a/main.cpp	Sun Feb 26 03:24:30 2017 +0000
+++ b/main.cpp	Sun Feb 26 06:22:32 2017 +0000
@@ -11,13 +11,18 @@
 #include "AcclerationService.h"
 #include "ReedSwitchService.h"
 #include "BLE_Init.h"
+//#include <PortInOut.h>
+#include <DigitalIn.h>
 
 #define REED_SWITCH     P0_5
 
 MMA8452Q accel(P0_10, P0_8, 0x1D);  //Declare accel object at I2C pins(P0_0 -> SDA, P0_1 -> SCL, 0x1D -> Accelerometer Address )
 Ticker ticker;
+Ticker reedTicker;
 float x,y,z;                        //variables assigned values to read x, y, and z accelerometer numbers
-InterruptIn button(REED_SWITCH);
+//InterruptIn button(REED_SWITCH);
+DigitalIn reedPin(REED_SWITCH); // or use DigitalIn readPin(REED_SWITCH, MODE), mode is the initial state of the pin
+                                // Modes: PullUp, PullDown, PullNone, or OpenDrain 
 
 enum {                                                  //Different states of the reed switch
     RELEASED = 0,
@@ -43,10 +48,33 @@
     
 }
 
+bool reedBit_is_clear(){
+    if(!reedPin.read()){
+        return true;
+        }
+    else{
+        return false;   
+    }
+}
+
+void checkForRev(){ //looks the falling edge
+  static uint16_t state = 0; //do need to change the type? the status you have is the same, "static uint16_t"
+  state = (state << 1) | (! reedBit_is_clear()) | 0xE000;
+  if (state == 0xF000) {
+       // in this if statement we want to tell the MCU/App
+       // "hey this is an actual revolution not the switch bouncing"
+       // i.e. something like " switchCount++ "
+       
+       //something like
+       //reedSwitchServicePtr->updateReedSwitchState(PRESSED);
+      // ??
+  }
+}
+
 int main(void)
 {
-    button.fall(reedSwitchPressedCallback);
-    button.rise(reedSwitchReleasedCallback);
+//    button.fall(reedSwitchPressedCallback);
+//    button.rise(reedSwitchReleasedCallback);
     
     BLE &ble = BLE::Instance();
     ble.init(bleInitComplete);
@@ -54,13 +82,15 @@
     accel.init();
     ticker.attach(periodicCallback,0.2);
     
+    reedTicker.attach_us(checkForRev, 10000); // calls checkForRev every 10ms
+    
     /* SpinWait for initialization to complete. This is necessary because the
      * BLE object is used in the main loop below. */
     while (ble.hasInitialized()  == false) { /* spin loop */ }
     
     while (true) {
         if (reedSwitchState != IDLE) {                                      //When the Reed Switch changes states
-            reedSwitchServicePtr->updateReedSwitchState(reedSwitchState);   //update the value over ble
+//           reedSwitchServicePtr->updateReedSwitchState(reedSwitchState);   //update the value over ble
             reedSwitchState = IDLE;
         }
         if (triggerSensorPolling && ble.getGapState().connected)