Door controller and proximity switch detection.

Dependencies:   mbed-rtos mbed VodafoneUSBModem_bleedingedge

This program takes in a digital input - which is a reed switch for a door - and an output to a relay. The door is open with a simple 'text' to the modem on the USB bus (i used k3770 vodafone dongle).

The door will send an alarm message to your nominated numbers at the start of the program if the door is open without a command being sent.

Very simple - and just meant as a demonstration of how to incorporate GSM/3G functionality to a evice.

Files at this revision

API Documentation at this revision

Comitter:
nherriot
Date:
Thu Feb 21 09:29:20 2013 +0000
Parent:
26:b9a0fa0f2469
Child:
28:8191f8a516d9
Commit message:
watchdog timer used to restart the device if the modem fails to come up.

Changed in this revision

VodafoneUSBModem_bleedingedge.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/VodafoneUSBModem_bleedingedge.lib	Sun Feb 10 20:28:33 2013 +0000
+++ b/VodafoneUSBModem_bleedingedge.lib	Thu Feb 21 09:29:20 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#8ad4cb12749d
\ No newline at end of file
+http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#b70519f17a22
--- a/main.cpp	Sun Feb 10 20:28:33 2013 +0000
+++ b/main.cpp	Thu Feb 21 09:29:20 2013 +0000
@@ -23,13 +23,11 @@
 
 #define __DEBUG__ 4 //Maximum verbosity
 #ifndef __MODULE__
-//#define __MODULE__ "net_voda_k3770_test.cpp"
 #endif
 
 #define MY_PHONE_NUMBER "+447717275049"     // Nicholas' Number
 #define BACKUP_NUMBER "+447825608771"       // Ashleys Number
 
-//#include "core/fwk.h"
 #include "mbed.h"
 #include "rtos.h"
 #include "VodafoneUSBModem.h"
@@ -62,7 +60,36 @@
     return(mydigital.read());
 }
 
-void test(void const*) {
+
+// http://mbed.org/forum/mbed/topic/508/
+class Watchdog 
+{
+    public:
+    // Load timeout value in watchdog timer and enable
+        void setTimeOut(float s) 
+        {
+            LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+            uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
+            LPC_WDT->WDTC = s * (float)clk;
+            LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
+            kick();
+        }
+    // "kick" or "feed" the dog - reset the watchdog timer
+    // by writing this required bit pattern
+        void kick() 
+        {
+            LPC_WDT->WDFEED = 0xAA;
+            LPC_WDT->WDFEED = 0x55;
+        }
+};
+ 
+
+// Setup the watchdog timer
+Watchdog watchDogTimer;
+
+
+
+void doorController(void const*) {
 
   DBG("Hello world and Vodafone Connection Manager test program!");
   DBG("Waiting 30 seconds for modem to settle down");
@@ -279,6 +306,8 @@
       
     }
     Thread::wait(500);
+    DBG("Main loop. Make sure we kick the dog to stop a restart happening!");
+    watchDogTimer.kick();
   }
 }
 
@@ -290,21 +319,35 @@
    }
 }
 
-void tick()
-{
-  led4=!led4;
-}
 
 int main() {
-  //Ticker t;
-  //t.attach(tick,1);
-  DBG_INIT();
-  DBG_SET_SPEED(115200);
-  test(NULL);
-  //Thread testTask(test, NULL, osPriorityNormal, 1024*5);
+    // On reset, indicate a watchdog reset has happened by switching all lights on for 3 seconds
+    if ((LPC_WDT->WDMOD >> 2) & 1)
+    {
+        led1 = 1;
+        led2 = 1;
+        led3 = 1;
+        led4 = 1;
+        Thread::wait(3000);
+        led1 = 0;
+        led2 = 0;
+        led3 = 0;
+        led4 = 0;
 
-  keepAlive(NULL);
+    }
+
+        
+    // setup a 30 second timeout on watchdog timer hardware
+    // needs to be longer than worst case main loop exection time
+    watchDogTimer.setTimeOut(30.0);  
+ 
+    DBG_INIT();
+    DBG_SET_SPEED(115200);
+    doorController(NULL);
+    //Thread testTask(test, NULL, osPriorityNormal, 1024*5);
+
+    keepAlive(NULL);
 
     
-    return 0;
+  return 0;
 }
--- a/mbed-rtos.lib	Sun Feb 10 20:28:33 2013 +0000
+++ b/mbed-rtos.lib	Thu Feb 21 09:29:20 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
+http://mbed.org/users/mbed_official/code/mbed-rtos/#53e6cccd8782
--- a/mbed.bld	Sun Feb 10 20:28:33 2013 +0000
+++ b/mbed.bld	Thu Feb 21 09:29:20 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/0954ebd79f59
\ No newline at end of file