Updated

Dependents:   PROJECTTEST

Committer:
Swabey89
Date:
Sat Jan 05 15:03:05 2019 +0000
Revision:
0:3ee5598a77a3
Updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Swabey89 0:3ee5598a77a3 1 #include "switches.h"
Swabey89 0:3ee5598a77a3 2
Swabey89 0:3ee5598a77a3 3 /*
Swabey89 0:3ee5598a77a3 4 //Thread events
Swabey89 0:3ee5598a77a3 5 osEvent evt1;
Swabey89 0:3ee5598a77a3 6 osEvent evt2;
Swabey89 0:3ee5598a77a3 7
Swabey89 0:3ee5598a77a3 8 //Thread ID
Swabey89 0:3ee5598a77a3 9 osThreadId sw1functionid;
Swabey89 0:3ee5598a77a3 10 osThreadId sw2functionid;
Swabey89 0:3ee5598a77a3 11 osThreadId startid;
Swabey89 0:3ee5598a77a3 12
Swabey89 0:3ee5598a77a3 13 InterruptIn sw1(PE_12);
Swabey89 0:3ee5598a77a3 14 InterruptIn sw2(PE_14);
Swabey89 0:3ee5598a77a3 15
Swabey89 0:3ee5598a77a3 16 SwitchDebounce* sm1;
Swabey89 0:3ee5598a77a3 17 SwitchDebounce* sm2;
Swabey89 0:3ee5598a77a3 18
Swabey89 0:3ee5598a77a3 19 //Date and Time Iniziliazation
Swabey89 0:3ee5598a77a3 20 int dd=00; //Reresents day
Swabey89 0:3ee5598a77a3 21 int mm=00; //Reresents month
Swabey89 0:3ee5598a77a3 22 int yy=00; //Reresents year
Swabey89 0:3ee5598a77a3 23
Swabey89 0:3ee5598a77a3 24 int hh=00; //Represents Hour
Swabey89 0:3ee5598a77a3 25 int minute=00; //Represents minute
Swabey89 0:3ee5598a77a3 26 int ss=00; //Represents Seconds
Swabey89 0:3ee5598a77a3 27
Swabey89 0:3ee5598a77a3 28 //Thread Iniziliazation
Swabey89 0:3ee5598a77a3 29 Thread t1;
Swabey89 0:3ee5598a77a3 30 Thread t2;
Swabey89 0:3ee5598a77a3 31 Thread t3;
Swabey89 0:3ee5598a77a3 32 */
Swabey89 0:3ee5598a77a3 33
Swabey89 0:3ee5598a77a3 34 //Interrupt service routine for handling the timeout
Swabey89 0:3ee5598a77a3 35 void userswTimeOutHandler() {
Swabey89 0:3ee5598a77a3 36 userswTimeOut.detach(); //Stop the timeout counter firing
Swabey89 0:3ee5598a77a3 37
Swabey89 0:3ee5598a77a3 38 //Which event does this follow?
Swabey89 0:3ee5598a77a3 39 switch (userswState) {
Swabey89 0:3ee5598a77a3 40 case EDGE_RISEN:
Swabey89 0:3ee5598a77a3 41 usersw.fall(&userswFallingEdge); //Now wait for a falling edge
Swabey89 0:3ee5598a77a3 42 break;
Swabey89 0:3ee5598a77a3 43 case EDGE_FALLEN:
Swabey89 0:3ee5598a77a3 44 usersw.rise(&userswRisingEdge); //Now wait for a rising edge
Swabey89 0:3ee5598a77a3 45 break;
Swabey89 0:3ee5598a77a3 46 } //end switch
Swabey89 0:3ee5598a77a3 47 }
Swabey89 0:3ee5598a77a3 48
Swabey89 0:3ee5598a77a3 49 //Interrupt service routine for a rising edge (press)
Swabey89 0:3ee5598a77a3 50 void userswRisingEdge() {
Swabey89 0:3ee5598a77a3 51 usersw.rise(NULL); //Disable detecting more rising edges
Swabey89 0:3ee5598a77a3 52 userswState = EDGE_RISEN; //Flag state
Swabey89 0:3ee5598a77a3 53 userswTimeOut.attach(&userswTimeOutHandler, 0.2); //Start timeout timer
Swabey89 0:3ee5598a77a3 54 }
Swabey89 0:3ee5598a77a3 55
Swabey89 0:3ee5598a77a3 56 //Interrupt service routive for SW1 falling edge (release)
Swabey89 0:3ee5598a77a3 57 void userswFallingEdge() {
Swabey89 0:3ee5598a77a3 58 usersw.fall(NULL); //Disable this interrupt
Swabey89 0:3ee5598a77a3 59 SDqueue.call(SDmount);
Swabey89 0:3ee5598a77a3 60 userswState = EDGE_FALLEN; //Flag state
Swabey89 0:3ee5598a77a3 61 userswTimeOut.attach(&userswTimeOutHandler, 10); //Start timeout counter
Swabey89 0:3ee5598a77a3 62 }