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.

Committer:
nherriot
Date:
Wed Jul 17 08:54:57 2013 +0000
Revision:
29:dc1458c071ba
Parent:
27:a265d336f088
First commit of the Vodafone door controller.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nherriot 29:dc1458c071ba 1
nherriot 0:5136cdfaebd0 2 /*
nherriot 29:dc1458c071ba 3 Copyright (C) 2012 Vodafone Limited.
nherriot 0:5136cdfaebd0 4
nherriot 0:5136cdfaebd0 5 Permission is hereby granted, free of charge, to any person obtaining a copy of
nherriot 0:5136cdfaebd0 6 this software and associated documentation files (the "Software"), to deal in
nherriot 0:5136cdfaebd0 7 the Software without restriction, including without limitation the rights to
nherriot 0:5136cdfaebd0 8 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
nherriot 0:5136cdfaebd0 9 of the Software, and to permit persons to whom the Software is furnished to do
nherriot 0:5136cdfaebd0 10 so, subject to the following conditions:
nherriot 0:5136cdfaebd0 11
nherriot 0:5136cdfaebd0 12 The above copyright notice and this permission notice shall be included in all
nherriot 0:5136cdfaebd0 13 copies or substantial portions of the Software.
nherriot 0:5136cdfaebd0 14
nherriot 0:5136cdfaebd0 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
nherriot 0:5136cdfaebd0 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
nherriot 0:5136cdfaebd0 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
nherriot 0:5136cdfaebd0 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
nherriot 0:5136cdfaebd0 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nherriot 0:5136cdfaebd0 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
nherriot 0:5136cdfaebd0 21 SOFTWARE.
nherriot 0:5136cdfaebd0 22 */
nherriot 0:5136cdfaebd0 23
nherriot 0:5136cdfaebd0 24 #define __DEBUG__ 4 //Maximum verbosity
nherriot 0:5136cdfaebd0 25 #ifndef __MODULE__
nherriot 0:5136cdfaebd0 26 #endif
nherriot 0:5136cdfaebd0 27
nherriot 22:87d73be30243 28 #define MY_PHONE_NUMBER "+447717275049" // Nicholas' Number
nherriot 22:87d73be30243 29 #define BACKUP_NUMBER "+447825608771" // Ashleys Number
nherriot 0:5136cdfaebd0 30
nherriot 0:5136cdfaebd0 31 #include "mbed.h"
nherriot 0:5136cdfaebd0 32 #include "rtos.h"
nherriot 10:c8a6f2822068 33 #include "VodafoneUSBModem.h"
nherriot 0:5136cdfaebd0 34
nherriot 2:bcc9256ecaab 35 #include <string>
nherriot 2:bcc9256ecaab 36
nherriot 0:5136cdfaebd0 37 extern "C" void HardFault_Handler() {
nherriot 0:5136cdfaebd0 38 error("Hard Fault!\n");
nherriot 0:5136cdfaebd0 39 }
nherriot 0:5136cdfaebd0 40
nherriot 8:1b4e84f4c451 41 DigitalOut led1(LED1); // LED 1 is used to show the state of the door. ON is door open, and OFF is door close.
nherriot 16:9245c3a37491 42 DigitalOut led2(LED2); // LED 2 is used to indicate that the main process is still running.
nherriot 8:1b4e84f4c451 43 DigitalOut led3(LED3); // LED 3 is use to indicate if the relay is being switched on to open the door
nherriot 22:87d73be30243 44 DigitalOut led4(LED4); // LED 4 indicate the state of the ALARM - If it's on the door is armed.
nherriot 8:1b4e84f4c451 45 DigitalOut doorContactorRelay(p5); // create a digital pin object to control the door contactor relay
nherriot 11:769f2b28b236 46 DigitalIn doorProximitySwitch(p6); // create a digital pin object to sense door position proximity switch, this works in reverse
nherriot 8:1b4e84f4c451 47 // the switch senses positive when the door is closed - need to be sure when it's closed! :-)
nherriot 8:1b4e84f4c451 48 bool openTheDoor = false; // create a state variable which is set to indicate the mbed should open the door
nherriot 8:1b4e84f4c451 49 // this variable will be used hold the latch open until it knows the door has been open.
nherriot 15:262da03e3e20 50 bool detectRegState = true; // this boolean variable will force the while loop to detect reg state - if the connection manager
nherriot 22:87d73be30243 51 // is not registered it will stay in this 'detec' phase for ever.
nherriot 22:87d73be30243 52 bool alarmActive = false; // this alarm flag will only be true if the door is open - but no signal has been detected
nherriot 22:87d73be30243 53 // to open the door. in other words there is a break in!
nherriot 22:87d73be30243 54 bool closeTheDoor = false; // this flag is used when the door is in an open legal state. once it's closed after a legal state
nherriot 22:87d73be30243 55 // it will set the alarm to active.
nherriot 22:87d73be30243 56
nherriot 22:87d73be30243 57
nherriot 10:c8a6f2822068 58 int read_digital(void) {
nherriot 10:c8a6f2822068 59 DigitalIn mydigital(p6);
nherriot 10:c8a6f2822068 60 return(mydigital.read());
nherriot 10:c8a6f2822068 61 }
nherriot 0:5136cdfaebd0 62
nherriot 27:a265d336f088 63
nherriot 27:a265d336f088 64 // http://mbed.org/forum/mbed/topic/508/
nherriot 27:a265d336f088 65 class Watchdog
nherriot 27:a265d336f088 66 {
nherriot 27:a265d336f088 67 public:
nherriot 27:a265d336f088 68 // Load timeout value in watchdog timer and enable
nherriot 27:a265d336f088 69 void setTimeOut(float s)
nherriot 27:a265d336f088 70 {
nherriot 27:a265d336f088 71 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
nherriot 27:a265d336f088 72 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
nherriot 27:a265d336f088 73 LPC_WDT->WDTC = s * (float)clk;
nherriot 27:a265d336f088 74 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
nherriot 27:a265d336f088 75 kick();
nherriot 27:a265d336f088 76 }
nherriot 27:a265d336f088 77 // "kick" or "feed" the dog - reset the watchdog timer
nherriot 27:a265d336f088 78 // by writing this required bit pattern
nherriot 27:a265d336f088 79 void kick()
nherriot 27:a265d336f088 80 {
nherriot 27:a265d336f088 81 LPC_WDT->WDFEED = 0xAA;
nherriot 27:a265d336f088 82 LPC_WDT->WDFEED = 0x55;
nherriot 27:a265d336f088 83 }
nherriot 27:a265d336f088 84 };
nherriot 27:a265d336f088 85
nherriot 27:a265d336f088 86
nherriot 27:a265d336f088 87 // Setup the watchdog timer
nherriot 27:a265d336f088 88 Watchdog watchDogTimer;
nherriot 27:a265d336f088 89
nherriot 27:a265d336f088 90
nherriot 27:a265d336f088 91
nherriot 27:a265d336f088 92 void doorController(void const*) {
nherriot 0:5136cdfaebd0 93
nherriot 22:87d73be30243 94 DBG("Hello world and Vodafone Connection Manager test program!");
nherriot 22:87d73be30243 95 DBG("Waiting 30 seconds for modem to settle down");
nherriot 23:28b693d586ee 96 Thread::wait(10000);
nherriot 23:28b693d586ee 97 VodafoneUSBModem connectionManager; // create a connection manager object
nherriot 0:5136cdfaebd0 98
nherriot 10:c8a6f2822068 99 char num[17]; // create a buffer to hold the telephone number in
nherriot 10:c8a6f2822068 100 char msg[160]; // create a buffer to hold the text message in
nherriot 10:c8a6f2822068 101 size_t count;
nherriot 15:262da03e3e20 102 LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_UNKNOWN; // an enum to hold the registration state of the connection manager
nherriot 15:262da03e3e20 103 LinkMonitor::BEARER bearer = LinkMonitor::BEARER_UNKNOWN; // an enum to hold the type of bearer established by the connection manager
nherriot 15:262da03e3e20 104 int rssi = -1000; // a signal strength indicator variable - set to a very default low value.
nherriot 15:262da03e3e20 105
nherriot 22:87d73be30243 106 // this is a fudge to let the modem settle down - we wait for 30 seconds
nherriot 23:28b693d586ee 107
nherriot 22:87d73be30243 108 DBG("Wait over - initialising the modem manager");
nherriot 23:28b693d586ee 109
nherriot 23:28b693d586ee 110
nherriot 23:28b693d586ee 111
nherriot 17:9b57d29e2eab 112 int ret = connectionManager.getLinkState(&rssi, &regState, &bearer);
donatien 21:7068b39d3006 113
nherriot 16:9245c3a37491 114 // LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_HOME_NETWORK;
nherriot 16:9245c3a37491 115
nherriot 15:262da03e3e20 116 // before we do anything we need to make sure we have a connection to a network.
nherriot 15:262da03e3e20 117 // so let us check that first!
nherriot 15:262da03e3e20 118
nherriot 16:9245c3a37491 119
nherriot 15:262da03e3e20 120 while(detectRegState)
nherriot 15:262da03e3e20 121 {
nherriot 17:9b57d29e2eab 122 if (detectRegState ==1)
nherriot 15:262da03e3e20 123 {
nherriot 15:262da03e3e20 124 if(rssi==-1000)
nherriot 15:262da03e3e20 125 {
nherriot 15:262da03e3e20 126 DBG("Checking signal strength - RSSI: Error.");
nherriot 15:262da03e3e20 127 }
nherriot 15:262da03e3e20 128 else
nherriot 15:262da03e3e20 129 {
nherriot 15:262da03e3e20 130 DBG("Signal strength is: RSSI: %d",rssi);
nherriot 15:262da03e3e20 131 }
nherriot 15:262da03e3e20 132
nherriot 15:262da03e3e20 133 switch(regState)
nherriot 15:262da03e3e20 134 {
nherriot 15:262da03e3e20 135 case LinkMonitor::REGISTRATION_STATE_UNKNOWN:
nherriot 15:262da03e3e20 136 DBG("regState: UNKNOWN. Failing.");
nherriot 15:262da03e3e20 137 break;
nherriot 15:262da03e3e20 138 case LinkMonitor::REGISTRATION_STATE_REGISTERING:
nherriot 15:262da03e3e20 139 DBG("regState: REGISTERING");
nherriot 15:262da03e3e20 140 break;
nherriot 15:262da03e3e20 141 case LinkMonitor::REGISTRATION_STATE_DENIED:
nherriot 15:262da03e3e20 142 DBG("regState: DENIED");
nherriot 15:262da03e3e20 143 break;
nherriot 15:262da03e3e20 144 case LinkMonitor::REGISTRATION_STATE_NO_SIGNAL:
nherriot 15:262da03e3e20 145 DBG("regState: NO SIGNAL");
nherriot 15:262da03e3e20 146 break;
nherriot 23:28b693d586ee 147 case HARDWARE_NO_RESPONSE:
nherriot 23:28b693d586ee 148 DBG("Looks like there is no modem inserted, or power to the modem module has failed?");
nherriot 23:28b693d586ee 149 break;
nherriot 15:262da03e3e20 150 case LinkMonitor::REGISTRATION_STATE_HOME_NETWORK:
nherriot 15:262da03e3e20 151 detectRegState = false;
nherriot 15:262da03e3e20 152 DBG("regState: HOME NETWORK");
nherriot 15:262da03e3e20 153 break;
nherriot 15:262da03e3e20 154 case LinkMonitor::REGISTRATION_STATE_ROAMING:
nherriot 15:262da03e3e20 155 detectRegState = false;
nherriot 15:262da03e3e20 156 DBG("regState: ROAMING");
nherriot 15:262da03e3e20 157 break;
nherriot 15:262da03e3e20 158 default:
nherriot 15:262da03e3e20 159 DBG("regState: ERROR. Failing.");
nherriot 17:9b57d29e2eab 160
nherriot 15:262da03e3e20 161 }
nherriot 15:262da03e3e20 162 }
nherriot 16:9245c3a37491 163 Thread::wait(500);
nherriot 23:28b693d586ee 164 int ret = connectionManager.getLinkState(&rssi, &regState, &bearer);
nherriot 15:262da03e3e20 165 }
nherriot 15:262da03e3e20 166
nherriot 22:87d73be30243 167 // let the boss man know I'm alive and entering my main loop
nherriot 22:87d73be30243 168 ret = connectionManager.sendSM(MY_PHONE_NUMBER, "Hello from Vodafone door controller 2013 - Alarm Active");
nherriot 22:87d73be30243 169 ret = connectionManager.sendSM(BACKUP_NUMBER, "Hello from Vodafone door controller 2013- Alarm Active");
nherriot 26:b9a0fa0f2469 170
nherriot 22:87d73be30243 171 // better let the boss know that I'm on a roamed network as this could cost some money! or present some routing problems
nherriot 22:87d73be30243 172 if (regState==LinkMonitor::REGISTRATION_STATE_ROAMING)
nherriot 22:87d73be30243 173 {
nherriot 22:87d73be30243 174 //ret = connectionManager.sendSM(MY_PHONE_NUMBER, "Warning sir - I'm on a roamed network!");
nherriot 22:87d73be30243 175 ret = connectionManager.sendSM(BACKUP_NUMBER, "Warning sir - I'm on a roamed network!");
nherriot 22:87d73be30243 176 }
nherriot 22:87d73be30243 177
nherriot 10:c8a6f2822068 178
nherriot 10:c8a6f2822068 179
nherriot 0:5136cdfaebd0 180 while(true)
nherriot 0:5136cdfaebd0 181 {
nherriot 8:1b4e84f4c451 182
nherriot 8:1b4e84f4c451 183 // if this state variable has been set I need to keep the doorContactor on until the door is open
nherriot 15:262da03e3e20 184 if ((openTheDoor) && (read_digital() == 0))
nherriot 3:0a8eebcb0acf 185 {
nherriot 15:262da03e3e20 186 DBG("The door is open now and I'm switching off the relay and reseting the state variable");
nherriot 8:1b4e84f4c451 187 doorContactorRelay = 0; // door must be open now so switch relay off.
nherriot 8:1b4e84f4c451 188 openTheDoor = false; // the door is open now so set it to false.
nherriot 8:1b4e84f4c451 189 led3 = 0; // switch the LED light off to indicate I'm switching the relay off
nherriot 22:87d73be30243 190 closeTheDoor = true; // now set the flag to indicate we are waiting for a closed door event allowing us to then activate the alarm
nherriot 22:87d73be30243 191 DBG("The closeTheDoor is now set to TRUE");
nherriot 8:1b4e84f4c451 192
nherriot 8:1b4e84f4c451 193 }
nherriot 3:0a8eebcb0acf 194
nherriot 22:87d73be30243 195 if ((read_digital() != 0) && ( closeTheDoor == true))
nherriot 22:87d73be30243 196 {
nherriot 22:87d73be30243 197 closeTheDoor = false; // the door is now closed after a legal open so reset the flag
nherriot 22:87d73be30243 198 alarmActive = true; // OK we can now activate the ALARM again
nherriot 22:87d73be30243 199 led4 = 1; // switch the alarm light on
nherriot 22:87d73be30243 200 DBG("The door is now closed after an open and the ALARM is no re-activated");
nherriot 22:87d73be30243 201
nherriot 22:87d73be30243 202 }
nherriot 22:87d73be30243 203
nherriot 22:87d73be30243 204 // check to see if the door is open and the alarm is on - if it is send warning message - but just once!!!!
nherriot 22:87d73be30243 205 if ((read_digital() == 0) && (alarmActive == true))
nherriot 22:87d73be30243 206 {
nherriot 22:87d73be30243 207 DBG("The door is now open - but the ALARM is active - send emergency text to warn our boss!");
nherriot 22:87d73be30243 208 DBG("*******************************************************************");
nherriot 22:87d73be30243 209 DBG("WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
nherriot 22:87d73be30243 210 DBG("*******************************************************************");
nherriot 22:87d73be30243 211 alarmActive = false; // set the alarm off as we don't want to keep sending text messages
nherriot 22:87d73be30243 212 led4 = 0; // set the alarm light to off
nherriot 22:87d73be30243 213 connectionManager.sendSM(BACKUP_NUMBER, "ALARM - ALARM - ALARM - Your door is open but I've not received an 'open' command!!!" );
nherriot 22:87d73be30243 214 connectionManager.sendSM(MY_PHONE_NUMBER, "ALARM - ALARM - ALARM - Your door is open but I've not received an 'open' command!!!" );
nherriot 22:87d73be30243 215
nherriot 22:87d73be30243 216 }
nherriot 22:87d73be30243 217
nherriot 22:87d73be30243 218 // check to see that the door is closed and the alarm can be reset. this will happen if the openTheDoor state variable
nherriot 22:87d73be30243 219 // is FALSE (indicating that the system is not trying to hold the relay open to allow accesss, the door is closed and the ALARM is false
nherriot 22:87d73be30243 220 if ((openTheDoor == false) && (read_digital() !=0) && (alarmActive == false))
nherriot 22:87d73be30243 221 {
nherriot 22:87d73be30243 222 DBG("Resetting the ALARM to active again");
nherriot 22:87d73be30243 223 alarmActive = true; // set the alarm on as the door is closed again
nherriot 22:87d73be30243 224 led4 = 1;
nherriot 22:87d73be30243 225 }
nherriot 22:87d73be30243 226
nherriot 22:87d73be30243 227
nherriot 8:1b4e84f4c451 228 // check the state of the door and switch the LED light to 'ON' for door open and 'OFF' for door closed.
nherriot 10:c8a6f2822068 229 //if (doorProximitySwitch.read() == 0)
nherriot 10:c8a6f2822068 230 if (read_digital() == 0)
nherriot 8:1b4e84f4c451 231 {
nherriot 15:262da03e3e20 232 // DBG("The door proximity switch is: %d so I think it's open", doorProximitySwitch.read() );
nherriot 8:1b4e84f4c451 233 led1 = 1;
nherriot 3:0a8eebcb0acf 234 }
nherriot 8:1b4e84f4c451 235 else
nherriot 8:1b4e84f4c451 236 {
nherriot 15:262da03e3e20 237 // DBG("The door proximity switch is: %d so I think it's closed", doorProximitySwitch.read() );
nherriot 8:1b4e84f4c451 238 led1 = 0;
nherriot 8:1b4e84f4c451 239 }
nherriot 8:1b4e84f4c451 240
nherriot 8:1b4e84f4c451 241
nherriot 8:1b4e84f4c451 242
nherriot 7:316c2dac06a5 243 int ret = connectionManager.getSMCount(&count); // check to see if there is an incoming SMS message
nherriot 0:5136cdfaebd0 244 if(ret)
nherriot 0:5136cdfaebd0 245 {
nherriot 0:5136cdfaebd0 246 WARN("getSMCount returned %d", ret);
nherriot 10:c8a6f2822068 247 Thread::wait(125);
nherriot 0:5136cdfaebd0 248 continue;
nherriot 0:5136cdfaebd0 249 }
nherriot 10:c8a6f2822068 250
nherriot 23:28b693d586ee 251 // DBG("The SMS count is now at: %d for this modem", count);
nherriot 7:316c2dac06a5 252 if( count > 0) // if there are messages in the mailbox start pulling them off the queue
nherriot 0:5136cdfaebd0 253 {
nherriot 0:5136cdfaebd0 254 DBG("%d SMS to read", count);
nherriot 10:c8a6f2822068 255 ret = connectionManager.getSM(num, msg, 160);
nherriot 8:1b4e84f4c451 256
nherriot 0:5136cdfaebd0 257 if(ret)
nherriot 0:5136cdfaebd0 258 {
nherriot 0:5136cdfaebd0 259 WARN("getSM returned %d", ret);
nherriot 10:c8a6f2822068 260 Thread::wait(125);
nherriot 0:5136cdfaebd0 261 continue;
nherriot 0:5136cdfaebd0 262 }
nherriot 0:5136cdfaebd0 263
nherriot 6:5a892c3d738e 264 DBG("The message is from number: %s and the message is: \"%s\"", num, msg);
nherriot 6:5a892c3d738e 265
nherriot 15:262da03e3e20 266 // if the SMS is from your own number, ignore it!
nherriot 15:262da03e3e20 267 if(strcmp(num,"+447785666088")==0)
nherriot 15:262da03e3e20 268 {
nherriot 15:262da03e3e20 269 DBG("The message appears to be from my MSISDN number: %s, I'll do nothing.", num);
nherriot 15:262da03e3e20 270 continue;
nherriot 15:262da03e3e20 271 }
nherriot 15:262da03e3e20 272
nherriot 15:262da03e3e20 273
nherriot 15:262da03e3e20 274
nherriot 15:262da03e3e20 275 if ((strcmp (msg, "open") ==0)|| (strcmp(num,"TrackaPhone")==0))
nherriot 8:1b4e84f4c451 276 {
nherriot 2:bcc9256ecaab 277 DBG("The SMS message indicates I should open the door");
nherriot 7:316c2dac06a5 278
nherriot 7:316c2dac06a5 279 // check the door is not already open if it is do nothing and send a warning back to the sender
nherriot 7:316c2dac06a5 280 // for this door the switch 'true' then its closed - we have to have an active signal to show it's securely closed
nherriot 8:1b4e84f4c451 281
nherriot 15:262da03e3e20 282 if (read_digital() == 0 )
nherriot 7:316c2dac06a5 283 {
nherriot 7:316c2dac06a5 284 DBG("The door is already open - so I'll do nothing");
nherriot 8:1b4e84f4c451 285 connectionManager.sendSM(num, " WARNING - The door is already open sir! ");
nherriot 7:316c2dac06a5 286 }
nherriot 7:316c2dac06a5 287 else
nherriot 7:316c2dac06a5 288 {
nherriot 7:316c2dac06a5 289 doorContactorRelay = 1;
nherriot 8:1b4e84f4c451 290 openTheDoor = true; // set the state vairable to let the door contoller know it needs to open the door
nherriot 22:87d73be30243 291 alarmActive = false; // set the alarm OFF until the door is open
nherriot 22:87d73be30243 292 led4 = 0; // set the alarm light to off
nherriot 22:87d73be30243 293 DBG("The ALARM is now set to %d: ", alarmActive);
nherriot 7:316c2dac06a5 294 led3 = 1;
nherriot 7:316c2dac06a5 295 DBG("The relay has been activated to open the door");
nherriot 8:1b4e84f4c451 296 connectionManager.sendSM(num, " Door open sir... Welcome home! " );
nherriot 8:1b4e84f4c451 297 }
nherriot 8:1b4e84f4c451 298 }
nherriot 8:1b4e84f4c451 299 else
nherriot 8:1b4e84f4c451 300 {
nherriot 2:bcc9256ecaab 301 DBG("The SMS message is not recognized");
nherriot 7:316c2dac06a5 302 connectionManager.sendSM(num, " Wrong password sir... Try 'open' and I'll open! ;-) ");
nherriot 2:bcc9256ecaab 303 }
nherriot 2:bcc9256ecaab 304
nherriot 2:bcc9256ecaab 305
nherriot 2:bcc9256ecaab 306
nherriot 0:5136cdfaebd0 307 }
nherriot 6:5a892c3d738e 308 Thread::wait(500);
nherriot 27:a265d336f088 309 DBG("Main loop. Make sure we kick the dog to stop a restart happening!");
nherriot 27:a265d336f088 310 watchDogTimer.kick();
nherriot 0:5136cdfaebd0 311 }
nherriot 0:5136cdfaebd0 312 }
nherriot 0:5136cdfaebd0 313
nherriot 0:5136cdfaebd0 314 void keepAlive(void const*) {
nherriot 0:5136cdfaebd0 315 while(1)
nherriot 0:5136cdfaebd0 316 {
nherriot 8:1b4e84f4c451 317 led2=!led2;
nherriot 0:5136cdfaebd0 318 Thread::wait(500);
nherriot 0:5136cdfaebd0 319 }
nherriot 0:5136cdfaebd0 320 }
nherriot 0:5136cdfaebd0 321
nherriot 0:5136cdfaebd0 322
nherriot 0:5136cdfaebd0 323 int main() {
nherriot 27:a265d336f088 324 // On reset, indicate a watchdog reset has happened by switching all lights on for 3 seconds
nherriot 27:a265d336f088 325 if ((LPC_WDT->WDMOD >> 2) & 1)
nherriot 27:a265d336f088 326 {
nherriot 27:a265d336f088 327 led1 = 1;
nherriot 27:a265d336f088 328 led2 = 1;
nherriot 27:a265d336f088 329 led3 = 1;
nherriot 27:a265d336f088 330 led4 = 1;
nherriot 27:a265d336f088 331 Thread::wait(3000);
nherriot 27:a265d336f088 332 led1 = 0;
nherriot 27:a265d336f088 333 led2 = 0;
nherriot 27:a265d336f088 334 led3 = 0;
nherriot 27:a265d336f088 335 led4 = 0;
nherriot 0:5136cdfaebd0 336
nherriot 27:a265d336f088 337 }
nherriot 27:a265d336f088 338
nherriot 27:a265d336f088 339
nherriot 27:a265d336f088 340 // setup a 30 second timeout on watchdog timer hardware
nherriot 27:a265d336f088 341 // needs to be longer than worst case main loop exection time
nherriot 27:a265d336f088 342 watchDogTimer.setTimeOut(30.0);
nherriot 27:a265d336f088 343
nherriot 27:a265d336f088 344 DBG_INIT();
nherriot 27:a265d336f088 345 DBG_SET_SPEED(115200);
nherriot 27:a265d336f088 346 doorController(NULL);
nherriot 27:a265d336f088 347 //Thread testTask(test, NULL, osPriorityNormal, 1024*5);
nherriot 27:a265d336f088 348
nherriot 27:a265d336f088 349 keepAlive(NULL);
nherriot 0:5136cdfaebd0 350
nherriot 0:5136cdfaebd0 351
nherriot 27:a265d336f088 352 return 0;
nherriot 0:5136cdfaebd0 353 }