init

Dependencies:   MPU6050 PinDetect circular_buffer

Committer:
OsmanKameric
Date:
Tue Nov 07 16:35:14 2017 +0000
Revision:
0:b416214256cd
FIRST

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OsmanKameric 0:b416214256cd 1 #include "mbed.h"
OsmanKameric 0:b416214256cd 2 #include "MPU6050.h"
OsmanKameric 0:b416214256cd 3 #include "I2Cdev.h"
OsmanKameric 0:b416214256cd 4 #include <Fsm.h>
OsmanKameric 0:b416214256cd 5 #include <CaseFsm.h>
OsmanKameric 0:b416214256cd 6 #include <CaseEvents.h>
OsmanKameric 0:b416214256cd 7 #include <Events.h>
OsmanKameric 0:b416214256cd 8 #include "log.h"
OsmanKameric 0:b416214256cd 9 #include "DataLogger.h"
OsmanKameric 0:b416214256cd 10
OsmanKameric 0:b416214256cd 11 //#include "circular_buffer.h"
OsmanKameric 0:b416214256cd 12 #include "MFRC522.h"
OsmanKameric 0:b416214256cd 13 #include "PinDetect.h"
OsmanKameric 0:b416214256cd 14
OsmanKameric 0:b416214256cd 15
OsmanKameric 0:b416214256cd 16 #define CURRENT_TIME 1504029000
OsmanKameric 0:b416214256cd 17
OsmanKameric 0:b416214256cd 18 #define SPI_MOSI PA_7
OsmanKameric 0:b416214256cd 19 #define SPI_MISO PA_6
OsmanKameric 0:b416214256cd 20 #define SPI_SCK PA_5
OsmanKameric 0:b416214256cd 21 #define SPI_CS PB_6
OsmanKameric 0:b416214256cd 22 #define MF_RESET PB_3
OsmanKameric 0:b416214256cd 23
OsmanKameric 0:b416214256cd 24
OsmanKameric 0:b416214256cd 25
OsmanKameric 0:b416214256cd 26
OsmanKameric 0:b416214256cd 27
OsmanKameric 0:b416214256cd 28 struct CaseFsmLog {
OsmanKameric 0:b416214256cd 29 int caseState;
OsmanKameric 0:b416214256cd 30 uint32_t timeStamp;
OsmanKameric 0:b416214256cd 31 };
OsmanKameric 0:b416214256cd 32
OsmanKameric 0:b416214256cd 33 CaseFsmLog caseFsmLog;
OsmanKameric 0:b416214256cd 34 CaseFsm* caseFsm;
OsmanKameric 0:b416214256cd 35 struct SwitchPosition switchPosition;
OsmanKameric 0:b416214256cd 36
OsmanKameric 0:b416214256cd 37 DigitalOut led1(LED1);
OsmanKameric 0:b416214256cd 38 Serial pc(USBTX,USBRX);
OsmanKameric 0:b416214256cd 39 struct RFIDEvent rfidEvent;
OsmanKameric 0:b416214256cd 40 struct TimerEnd timerEnd;
OsmanKameric 0:b416214256cd 41 /*
OsmanKameric 0:b416214256cd 42 struct MotionLog {
OsmanKameric 0:b416214256cd 43 int motX;
OsmanKameric 0:b416214256cd 44 int motY;
OsmanKameric 0:b416214256cd 45 int motZ;
OsmanKameric 0:b416214256cd 46 uint32_t timeStamp;
OsmanKameric 0:b416214256cd 47 uint8_t motionByte;
OsmanKameric 0:b416214256cd 48 };
OsmanKameric 0:b416214256cd 49
OsmanKameric 0:b416214256cd 50 struct MotionFsmLog {
OsmanKameric 0:b416214256cd 51 int motionState;
OsmanKameric 0:b416214256cd 52 uint32_t timeStamp;
OsmanKameric 0:b416214256cd 53 };
OsmanKameric 0:b416214256cd 54 MotionLog motionLog;
OsmanKameric 0:b416214256cd 55 MotionFsmLog motionFsmLog;
OsmanKameric 0:b416214256cd 56
OsmanKameric 0:b416214256cd 57
OsmanKameric 0:b416214256cd 58 circular_buffer<MotionLog> cb(20);
OsmanKameric 0:b416214256cd 59 circular_buffer<MotionFsmLog> mfl(20);
OsmanKameric 0:b416214256cd 60 circular_buffer<CaseFsmLog> cfl(20);
OsmanKameric 0:b416214256cd 61 MPU6050 mpu;
OsmanKameric 0:b416214256cd 62 bool zero_detect;
OsmanKameric 0:b416214256cd 63 Fsm* motionFsm;
OsmanKameric 0:b416214256cd 64
OsmanKameric 0:b416214256cd 65
OsmanKameric 0:b416214256cd 66
OsmanKameric 0:b416214256cd 67
OsmanKameric 0:b416214256cd 68 bool XnegMD, XposMD, YnegMD, YposMD, ZnegMD, ZposMD;
OsmanKameric 0:b416214256cd 69 int8_t threshold;
OsmanKameric 0:b416214256cd 70
OsmanKameric 0:b416214256cd 71 float temp;
OsmanKameric 0:b416214256cd 72 bool test=0;
OsmanKameric 0:b416214256cd 73 void flip()
OsmanKameric 0:b416214256cd 74 {
OsmanKameric 0:b416214256cd 75 test=1;
OsmanKameric 0:b416214256cd 76 }
OsmanKameric 0:b416214256cd 77
OsmanKameric 0:b416214256cd 78
OsmanKameric 0:b416214256cd 79
OsmanKameric 0:b416214256cd 80
OsmanKameric 0:b416214256cd 81 struct Move move;
OsmanKameric 0:b416214256cd 82 struct Stop stop;
OsmanKameric 0:b416214256cd 83
OsmanKameric 0:b416214256cd 84
OsmanKameric 0:b416214256cd 85
OsmanKameric 0:b416214256cd 86 */
OsmanKameric 0:b416214256cd 87
OsmanKameric 0:b416214256cd 88 InterruptIn button1(D7);
OsmanKameric 0:b416214256cd 89 //PinDetect button1(PA_9);
OsmanKameric 0:b416214256cd 90 InterruptIn button2(D8);
OsmanKameric 0:b416214256cd 91 InterruptIn button3(D9);
OsmanKameric 0:b416214256cd 92 //InterruptIn button4(PA_7);
OsmanKameric 0:b416214256cd 93
OsmanKameric 0:b416214256cd 94 //InterruptIn mpuInterrupt(PA_10);
OsmanKameric 0:b416214256cd 95 bool flag = false;
OsmanKameric 0:b416214256cd 96 int flag_switch=0;
OsmanKameric 0:b416214256cd 97 int flag_rfid_Event=0;
OsmanKameric 0:b416214256cd 98 int flag_timerend=0;
OsmanKameric 0:b416214256cd 99 bool DeviceIsFull = false;
OsmanKameric 0:b416214256cd 100 void button1PressedCallback()
OsmanKameric 0:b416214256cd 101 {
OsmanKameric 0:b416214256cd 102 flag_switch=1;
OsmanKameric 0:b416214256cd 103 caseFsm->handle(switchPosition);
OsmanKameric 0:b416214256cd 104 }
OsmanKameric 0:b416214256cd 105
OsmanKameric 0:b416214256cd 106 void button2PressedCallback()
OsmanKameric 0:b416214256cd 107 {
OsmanKameric 0:b416214256cd 108 flag_rfid_Event=1;
OsmanKameric 0:b416214256cd 109 caseFsm->handle(rfidEvent);
OsmanKameric 0:b416214256cd 110
OsmanKameric 0:b416214256cd 111 }
OsmanKameric 0:b416214256cd 112 void button3PressedCallback()
OsmanKameric 0:b416214256cd 113 {
OsmanKameric 0:b416214256cd 114 flag_timerend=1;
OsmanKameric 0:b416214256cd 115 caseFsm->handle(timerEnd);
OsmanKameric 0:b416214256cd 116 }
OsmanKameric 0:b416214256cd 117
OsmanKameric 0:b416214256cd 118
OsmanKameric 0:b416214256cd 119
OsmanKameric 0:b416214256cd 120 Log mojlog;
OsmanKameric 0:b416214256cd 121 DataLogger <Log> mojlogger;
OsmanKameric 0:b416214256cd 122 mojlogger.print();
OsmanKameric 0:b416214256cd 123 mojlogger.savelog(mojlog);
OsmanKameric 0:b416214256cd 124 mojlogger.print();
OsmanKameric 0:b416214256cd 125
OsmanKameric 0:b416214256cd 126
OsmanKameric 0:b416214256cd 127
OsmanKameric 0:b416214256cd 128 flagswitch=0;
OsmanKameric 0:b416214256cd 129 flag_rfid_Event=0;
OsmanKameric 0:b416214256cd 130 flag_timerend=0;
OsmanKameric 0:b416214256cd 131
OsmanKameric 0:b416214256cd 132 if(flagswitch==1){
OsmanKameric 0:b416214256cd 133
OsmanKameric 0:b416214256cd 134 if(caseFsm->DeviceInFullState()) {
OsmanKameric 0:b416214256cd 135 pc.printf("Waiting 5 seconds for RFID event...\r\n");
OsmanKameric 0:b416214256cd 136 while (caseFsm->DeviceInFullState()) {
OsmanKameric 0:b416214256cd 137 // Look for new cards
OsmanKameric 0:b416214256cd 138
OsmanKameric 0:b416214256cd 139
OsmanKameric 0:b416214256cd 140
OsmanKameric 0:b416214256cd 141 }
OsmanKameric 0:b416214256cd 142
OsmanKameric 0:b416214256cd 143 }
OsmanKameric 0:b416214256cd 144 }
OsmanKameric 0:b416214256cd 145
OsmanKameric 0:b416214256cd 146
OsmanKameric 0:b416214256cd 147 }
OsmanKameric 0:b416214256cd 148 }
OsmanKameric 0:b416214256cd 149