![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
commit
Dependencies: MPU6050_SIM5320_TEST
Fork of MPU_SDCARD by
main.cpp@1:75966605a6a3, 2017-11-10 (annotated)
- Committer:
- suads
- Date:
- Fri Nov 10 15:35:26 2017 +0000
- Revision:
- 1:75966605a6a3
- Parent:
- 0:203cf529f52a
mbed cli
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suads | 0:203cf529f52a | 1 | #include "mbed.h" |
suads | 0:203cf529f52a | 2 | #include "MPU6050.h" |
suads | 1:75966605a6a3 | 3 | #include "I2Cdev.h" |
suads | 1:75966605a6a3 | 4 | #include <CaseFsm.h> |
suads | 1:75966605a6a3 | 5 | #include <CaseEvents.h> |
suads | 1:75966605a6a3 | 6 | #include <Fsm.h> |
suads | 1:75966605a6a3 | 7 | #include <Events.h> |
suads | 1:75966605a6a3 | 8 | #include "MFRC522.h" |
suads | 1:75966605a6a3 | 9 | |
suads | 1:75966605a6a3 | 10 | #include "log.h" |
suads | 1:75966605a6a3 | 11 | #include "DataLogger.h" |
suads | 1:75966605a6a3 | 12 | |
suads | 1:75966605a6a3 | 13 | #define CURRENT_TIME 1510164886 |
suads | 1:75966605a6a3 | 14 | |
suads | 1:75966605a6a3 | 15 | #define SPI_MOSI PA_7 |
suads | 1:75966605a6a3 | 16 | #define SPI_MISO PA_6 |
suads | 1:75966605a6a3 | 17 | #define SPI_SCK PA_5 |
suads | 1:75966605a6a3 | 18 | #define SPI_CS PA_8 |
suads | 1:75966605a6a3 | 19 | |
suads | 1:75966605a6a3 | 20 | |
suads | 1:75966605a6a3 | 21 | |
suads | 1:75966605a6a3 | 22 | |
suads | 1:75966605a6a3 | 23 | int cbx[20]; |
suads | 1:75966605a6a3 | 24 | int cby[20]; |
suads | 1:75966605a6a3 | 25 | int cbz[20]; |
suads | 1:75966605a6a3 | 26 | |
suads | 1:75966605a6a3 | 27 | |
suads | 1:75966605a6a3 | 28 | Log mojlog; |
suads | 1:75966605a6a3 | 29 | DataLogger <Log> mojlogger; |
suads | 1:75966605a6a3 | 30 | // mojlogger.print(); |
suads | 1:75966605a6a3 | 31 | // mojlogger.savelog(mojlog); |
suads | 1:75966605a6a3 | 32 | // mojlogger.print(); |
suads | 0:203cf529f52a | 33 | |
suads | 0:203cf529f52a | 34 | |
suads | 0:203cf529f52a | 35 | |
suads | 1:75966605a6a3 | 36 | DigitalOut rfidpower(PA_12); |
suads | 1:75966605a6a3 | 37 | |
suads | 1:75966605a6a3 | 38 | int x=0; |
suads | 1:75966605a6a3 | 39 | |
suads | 1:75966605a6a3 | 40 | DigitalOut led1(LED1); |
suads | 1:75966605a6a3 | 41 | //Serial pc(USBTX,USBRX); |
suads | 1:75966605a6a3 | 42 | |
suads | 1:75966605a6a3 | 43 | bool XnegMD, XposMD, YnegMD, YposMD, ZnegMD, ZposMD; |
suads | 1:75966605a6a3 | 44 | int8_t threshold; |
suads | 1:75966605a6a3 | 45 | bool zero_detect; |
suads | 1:75966605a6a3 | 46 | float temp; |
suads | 1:75966605a6a3 | 47 | |
suads | 1:75966605a6a3 | 48 | //void flip(){test=1;} |
suads | 1:75966605a6a3 | 49 | Fsm* motionFsm; |
suads | 1:75966605a6a3 | 50 | CaseFsm* caseFsm; |
suads | 1:75966605a6a3 | 51 | SwitchPosition switchPosition; |
suads | 1:75966605a6a3 | 52 | RFIDEvent rfidEvent; |
suads | 1:75966605a6a3 | 53 | TimerEnd timerEnd; |
suads | 1:75966605a6a3 | 54 | Move move; |
suads | 1:75966605a6a3 | 55 | Stop stop; |
suads | 1:75966605a6a3 | 56 | uint8_t print=0; |
suads | 1:75966605a6a3 | 57 | //#include "PinDetect.h" |
suads | 1:75966605a6a3 | 58 | |
suads | 1:75966605a6a3 | 59 | InterruptIn button1(PD_2); |
suads | 1:75966605a6a3 | 60 | InterruptIn button2(PC_11); |
suads | 1:75966605a6a3 | 61 | InterruptIn button3(PC_10); |
suads | 1:75966605a6a3 | 62 | InterruptIn button4(PC_12);//PRINT |
suads | 1:75966605a6a3 | 63 | |
suads | 1:75966605a6a3 | 64 | |
suads | 1:75966605a6a3 | 65 | InterruptIn mpuInterrupt(PB_5); |
suads | 0:203cf529f52a | 66 | |
suads | 1:75966605a6a3 | 67 | volatile uint8_t test = 0; |
suads | 1:75966605a6a3 | 68 | volatile uint8_t mot=0; |
suads | 1:75966605a6a3 | 69 | |
suads | 1:75966605a6a3 | 70 | bool flag = false; |
suads | 1:75966605a6a3 | 71 | bool DeviceIsFull = false; |
suads | 1:75966605a6a3 | 72 | |
suads | 1:75966605a6a3 | 73 | void button1PressedCallback() |
suads | 1:75966605a6a3 | 74 | { |
suads | 1:75966605a6a3 | 75 | // printf("button1\n"); |
suads | 1:75966605a6a3 | 76 | caseFsm->handle(switchPosition); |
suads | 1:75966605a6a3 | 77 | } |
suads | 1:75966605a6a3 | 78 | |
suads | 1:75966605a6a3 | 79 | void button2PressedCallback() |
suads | 1:75966605a6a3 | 80 | { |
suads | 1:75966605a6a3 | 81 | //printf("button2\n"); |
suads | 1:75966605a6a3 | 82 | caseFsm->handle(rfidEvent); |
suads | 1:75966605a6a3 | 83 | |
suads | 1:75966605a6a3 | 84 | } |
suads | 1:75966605a6a3 | 85 | void button3PressedCallback() |
suads | 1:75966605a6a3 | 86 | { |
suads | 1:75966605a6a3 | 87 | //printf("button3\n"); |
suads | 1:75966605a6a3 | 88 | caseFsm->handle(timerEnd); |
suads | 1:75966605a6a3 | 89 | |
suads | 1:75966605a6a3 | 90 | } |
suads | 1:75966605a6a3 | 91 | |
suads | 1:75966605a6a3 | 92 | void button4PressedCallback() |
suads | 1:75966605a6a3 | 93 | { |
suads | 1:75966605a6a3 | 94 | print=1; |
suads | 1:75966605a6a3 | 95 | |
suads | 1:75966605a6a3 | 96 | } |
suads | 1:75966605a6a3 | 97 | |
suads | 0:203cf529f52a | 98 | void mpuInterruptCallback() |
suads | 0:203cf529f52a | 99 | { |
suads | 1:75966605a6a3 | 100 | test=1; |
suads | 0:203cf529f52a | 101 | } |
suads | 0:203cf529f52a | 102 | |
suads | 1:75966605a6a3 | 103 | |
suads | 0:203cf529f52a | 104 | MPU6050 mpu; |
suads | 1:75966605a6a3 | 105 | uint8_t nomotion=0; |
suads | 1:75966605a6a3 | 106 | uint8_t motionlogged=0; |
suads | 1:75966605a6a3 | 107 | |
suads | 1:75966605a6a3 | 108 | void getXYZMotions() |
suads | 1:75966605a6a3 | 109 | { |
suads | 1:75966605a6a3 | 110 | wait(0.1); |
suads | 1:75966605a6a3 | 111 | uint8_t motionByte = mpu.readThisByte(MPU6050_RA_MOT_DETECT_STATUS); |
suads | 1:75966605a6a3 | 112 | // motionLog.motionByte = motionByte; |
suads | 1:75966605a6a3 | 113 | //motionLog.timeStamp = time(NULL); |
suads | 1:75966605a6a3 | 114 | //mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); |
suads | 1:75966605a6a3 | 115 | uint8_t b; |
suads | 1:75966605a6a3 | 116 | bool zero = false; |
suads | 1:75966605a6a3 | 117 | char x,y,z; |
suads | 1:75966605a6a3 | 118 | int mx=0; |
suads | 1:75966605a6a3 | 119 | int my=0; |
suads | 1:75966605a6a3 | 120 | int mz=0; |
suads | 1:75966605a6a3 | 121 | x=y=z='0'; |
suads | 1:75966605a6a3 | 122 | for(int i = 0; i<=7; i++) { |
suads | 1:75966605a6a3 | 123 | b = motionByte & (1<<i); |
suads | 1:75966605a6a3 | 124 | if(i==0 && b==1) { |
suads | 1:75966605a6a3 | 125 | //time_t sec = time(NULL); |
suads | 1:75966605a6a3 | 126 | //printf("Current time is: %s\r\n", ctime(&sec)); |
suads | 1:75966605a6a3 | 127 | zero = true; |
suads | 1:75966605a6a3 | 128 | printf("ZERO MOTION detected.\r\n"); |
suads | 1:75966605a6a3 | 129 | //pc.printf(" %c %c %c | ",x,y,z); |
suads | 1:75966605a6a3 | 130 | //pc.printf("%d;%d;%d;%d;%d;%d ZERO DETECTED\r\n",ax,ay,az,gx,gy,gz); |
suads | 1:75966605a6a3 | 131 | } |
suads | 1:75966605a6a3 | 132 | if(i==1 && b==2) { |
suads | 1:75966605a6a3 | 133 | printf("This should not happen :).\r\n"); |
suads | 1:75966605a6a3 | 134 | } |
suads | 1:75966605a6a3 | 135 | if(i==6 && b==64) { |
suads | 1:75966605a6a3 | 136 | x='+'; |
suads | 1:75966605a6a3 | 137 | mx=1; |
suads | 1:75966605a6a3 | 138 | printf("X POSITIVE motion detected.\r\n"); |
suads | 1:75966605a6a3 | 139 | } |
suads | 1:75966605a6a3 | 140 | if(i==7 && b==128) { |
suads | 1:75966605a6a3 | 141 | x='-'; |
suads | 1:75966605a6a3 | 142 | mx=1; |
suads | 1:75966605a6a3 | 143 | printf("X NEGATIVE motion detected.\r\n"); |
suads | 1:75966605a6a3 | 144 | } |
suads | 1:75966605a6a3 | 145 | if(i==4 && b==16) { |
suads | 1:75966605a6a3 | 146 | y='+'; |
suads | 1:75966605a6a3 | 147 | my=1; |
suads | 1:75966605a6a3 | 148 | printf("Y POSITIVE motion detected.\r\n"); |
suads | 1:75966605a6a3 | 149 | } |
suads | 1:75966605a6a3 | 150 | if(i==5 && b==32) { |
suads | 1:75966605a6a3 | 151 | y='-'; |
suads | 1:75966605a6a3 | 152 | my=1; |
suads | 1:75966605a6a3 | 153 | printf("Y NEGATIVE motion detected.\r\n"); |
suads | 1:75966605a6a3 | 154 | } |
suads | 1:75966605a6a3 | 155 | if(i==2 && b==4) { |
suads | 1:75966605a6a3 | 156 | z='+'; |
suads | 1:75966605a6a3 | 157 | mz=1; |
suads | 1:75966605a6a3 | 158 | printf("Z POSITIVE motion detected.\r\n"); |
suads | 1:75966605a6a3 | 159 | } |
suads | 1:75966605a6a3 | 160 | if(i==3 && b==8) { |
suads | 1:75966605a6a3 | 161 | z='-'; |
suads | 1:75966605a6a3 | 162 | mz=1; |
suads | 1:75966605a6a3 | 163 | printf("Z NEGATIVE motion detected.\r\n"); |
suads | 1:75966605a6a3 | 164 | } |
suads | 1:75966605a6a3 | 165 | } |
suads | 1:75966605a6a3 | 166 | printf("%d %d %d\r\n",mx,my,mz); |
suads | 1:75966605a6a3 | 167 | |
suads | 1:75966605a6a3 | 168 | if(mx==0 && my==0 && mz==0) { |
suads | 1:75966605a6a3 | 169 | nomotion++; |
suads | 1:75966605a6a3 | 170 | if(nomotion==3 && motionlogged==0) { |
suads | 1:75966605a6a3 | 171 | printf("SAVE NO motion\n"); |
suads | 1:75966605a6a3 | 172 | //motionFsm->handle(stop); |
suads | 1:75966605a6a3 | 173 | mojlog.setLog(900,0,0,900); |
suads | 1:75966605a6a3 | 174 | mojlogger.savelog(mojlog); |
suads | 1:75966605a6a3 | 175 | motionlogged=1; |
suads | 1:75966605a6a3 | 176 | nomotion=0; |
suads | 1:75966605a6a3 | 177 | } |
suads | 1:75966605a6a3 | 178 | } |
suads | 1:75966605a6a3 | 179 | |
suads | 1:75966605a6a3 | 180 | else if(motionlogged==1) { |
suads | 1:75966605a6a3 | 181 | printf("SAVE motion\n"); |
suads | 1:75966605a6a3 | 182 | motionlogged=0; |
suads | 1:75966605a6a3 | 183 | //motionFsm->handle(move); |
suads | 1:75966605a6a3 | 184 | mojlog.setLog(2222,0,1,2222); |
suads | 1:75966605a6a3 | 185 | mojlogger.savelog(mojlog); |
suads | 1:75966605a6a3 | 186 | nomotion=0; |
suads | 1:75966605a6a3 | 187 | } |
suads | 1:75966605a6a3 | 188 | |
suads | 1:75966605a6a3 | 189 | |
suads | 1:75966605a6a3 | 190 | |
suads | 1:75966605a6a3 | 191 | |
suads | 1:75966605a6a3 | 192 | |
suads | 1:75966605a6a3 | 193 | |
suads | 1:75966605a6a3 | 194 | |
suads | 1:75966605a6a3 | 195 | |
suads | 1:75966605a6a3 | 196 | } |
suads | 1:75966605a6a3 | 197 | |
suads | 1:75966605a6a3 | 198 | |
suads | 1:75966605a6a3 | 199 | |
suads | 1:75966605a6a3 | 200 | |
suads | 1:75966605a6a3 | 201 | |
suads | 1:75966605a6a3 | 202 | |
suads | 1:75966605a6a3 | 203 | |
suads | 1:75966605a6a3 | 204 | MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, PB_4); |
suads | 1:75966605a6a3 | 205 | |
suads | 0:203cf529f52a | 206 | int main() |
suads | 0:203cf529f52a | 207 | { |
suads | 1:75966605a6a3 | 208 | |
suads | 1:75966605a6a3 | 209 | rfidpower=1; |
suads | 1:75966605a6a3 | 210 | |
suads | 1:75966605a6a3 | 211 | |
suads | 1:75966605a6a3 | 212 | |
suads | 1:75966605a6a3 | 213 | CaseFsm caseF; |
suads | 1:75966605a6a3 | 214 | caseFsm = &caseF; |
suads | 1:75966605a6a3 | 215 | |
suads | 1:75966605a6a3 | 216 | //mpuInterrupt.mode(PullUp); |
suads | 1:75966605a6a3 | 217 | button1.mode(PullUp); |
suads | 1:75966605a6a3 | 218 | button2.mode(PullUp); |
suads | 1:75966605a6a3 | 219 | button3.mode(PullUp); |
suads | 1:75966605a6a3 | 220 | button4.mode(PullUp); //print |
suads | 1:75966605a6a3 | 221 | button4.fall(button4PressedCallback); |
suads | 1:75966605a6a3 | 222 | button3.fall(button3PressedCallback); |
suads | 1:75966605a6a3 | 223 | button2.fall(button2PressedCallback); |
suads | 1:75966605a6a3 | 224 | button1.fall(&button1PressedCallback); |
suads | 1:75966605a6a3 | 225 | |
suads | 1:75966605a6a3 | 226 | //mpuInterrupt.fall(mpuInterruptCallback); |
suads | 1:75966605a6a3 | 227 | |
suads | 1:75966605a6a3 | 228 | RfChip.PCD_Init(); |
suads | 1:75966605a6a3 | 229 | wait(0.2); |
suads | 1:75966605a6a3 | 230 | |
suads | 1:75966605a6a3 | 231 | |
suads | 1:75966605a6a3 | 232 | |
suads | 1:75966605a6a3 | 233 | |
suads | 1:75966605a6a3 | 234 | |
suads | 1:75966605a6a3 | 235 | |
suads | 1:75966605a6a3 | 236 | ////////////////////MPU INTERUPT RADI////////////////////////////////////// |
suads | 1:75966605a6a3 | 237 | |
suads | 0:203cf529f52a | 238 | mpuInterrupt.fall(mpuInterruptCallback); |
suads | 1:75966605a6a3 | 239 | wait(0.2); |
suads | 0:203cf529f52a | 240 | mpu.calibrate(accelBias, gyroBias); |
suads | 0:203cf529f52a | 241 | mpu.initialize(); |
suads | 0:203cf529f52a | 242 | mpu.setSleepEnabled(0); |
suads | 1:75966605a6a3 | 243 | wait(0.2); |
suads | 0:203cf529f52a | 244 | mpu.setIntFreefallEnabled(1); |
suads | 1:75966605a6a3 | 245 | mpu.setIntZeroMotionEnabled(1); |
suads | 0:203cf529f52a | 246 | mpu.setIntMotionEnabled(1); |
suads | 0:203cf529f52a | 247 | printf("Setting mpu parameters...\r\n"); |
suads | 0:203cf529f52a | 248 | mpu.setMotionDetectionThreshold(1); |
suads | 0:203cf529f52a | 249 | mpu.setMotionDetectionDuration(15); |
suads | 1:75966605a6a3 | 250 | mpu.setZeroMotionDetectionThreshold(1); |
suads | 1:75966605a6a3 | 251 | mpu.setZeroMotionDetectionDuration(5); |
suads | 0:203cf529f52a | 252 | |
suads | 1:75966605a6a3 | 253 | |
suads | 1:75966605a6a3 | 254 | ///////////////////////////////////////////////////////////////////////////// |
suads | 1:75966605a6a3 | 255 | /* |
suads | 1:75966605a6a3 | 256 | mpu.calibrate(accelBias, gyroBias); |
suads | 1:75966605a6a3 | 257 | mpu.initialize(); |
suads | 1:75966605a6a3 | 258 | mpu.setSleepEnabled(0); |
suads | 1:75966605a6a3 | 259 | mpu.setIntDMPEnabled(1); |
suads | 1:75966605a6a3 | 260 | |
suads | 1:75966605a6a3 | 261 | uint8_t pinValue = mpu.getIntEnabled(); |
suads | 1:75966605a6a3 | 262 | printf("Is int enabled? : %d\n", pinValue); |
suads | 1:75966605a6a3 | 263 | printf("MPU6050 testing connection \n"); |
suads | 1:75966605a6a3 | 264 | |
suads | 1:75966605a6a3 | 265 | |
suads | 0:203cf529f52a | 266 | wait(2); |
suads | 1:75966605a6a3 | 267 | bool mpu6050TestResult = mpu.testConnection(); |
suads | 1:75966605a6a3 | 268 | if(mpu6050TestResult) { |
suads | 1:75966605a6a3 | 269 | printf("MPU6050 test passed \n"); |
suads | 1:75966605a6a3 | 270 | } else { |
suads | 1:75966605a6a3 | 271 | printf("MPU6050 test failed \n"); |
suads | 1:75966605a6a3 | 272 | } |
suads | 0:203cf529f52a | 273 | |
suads | 0:203cf529f52a | 274 | |
suads | 1:75966605a6a3 | 275 | mpu.setIntEnabled(1); |
suads | 1:75966605a6a3 | 276 | //mpu.setIntFreefallEnabled(1); |
suads | 1:75966605a6a3 | 277 | //mpu.setIntZeroMotionEnabled(0); |
suads | 1:75966605a6a3 | 278 | //mpu.setIntMotionEnabled(1); |
suads | 1:75966605a6a3 | 279 | mpu.setDHPFMode(1); |
suads | 0:203cf529f52a | 280 | |
suads | 1:75966605a6a3 | 281 | //******************************************************************************************************************************* |
suads | 1:75966605a6a3 | 282 | |
suads | 1:75966605a6a3 | 283 | printf("\n\n\n"); |
suads | 1:75966605a6a3 | 284 | uint8_t motionDetectionThreshold = mpu.getMotionDetectionThreshold(); |
suads | 1:75966605a6a3 | 285 | //printf("MPU6050 motion detection threshold is: %d \r\n", motionDetectionThreshold); |
suads | 1:75966605a6a3 | 286 | //printf("MPU6050 set motion detection threshold to 2\r\n"); |
suads | 1:75966605a6a3 | 287 | mpu.setMotionDetectionThreshold(1); |
suads | 1:75966605a6a3 | 288 | motionDetectionThreshold = mpu.getMotionDetectionThreshold(); |
suads | 1:75966605a6a3 | 289 | //printf("MPU6050 motion detection threshold now is: %d \r\n", motionDetectionThreshold); |
suads | 1:75966605a6a3 | 290 | printf("Motion detection threshold is: %d \r\n", motionDetectionThreshold); |
suads | 1:75966605a6a3 | 291 | uint8_t motionDetectionDuration = mpu.getMotionDetectionDuration(); |
suads | 1:75966605a6a3 | 292 | //printf("MPU6050 motion detection duration is: %d \r\n", motionDetectionDuration); |
suads | 1:75966605a6a3 | 293 | //printf("MPU6050 set motion detection duration to 40\r\n"); |
suads | 1:75966605a6a3 | 294 | mpu.setMotionDetectionDuration(20); |
suads | 1:75966605a6a3 | 295 | motionDetectionDuration = mpu.getMotionDetectionDuration(); |
suads | 1:75966605a6a3 | 296 | //printf("MPU6050 motion detection duration now is: %d \r\n", motionDetectionDuration); |
suads | 1:75966605a6a3 | 297 | printf("Motion detection duration is: %d \r\n", motionDetectionDuration); |
suads | 1:75966605a6a3 | 298 | |
suads | 1:75966605a6a3 | 299 | //******************************************************************************************************************************* |
suads | 0:203cf529f52a | 300 | |
suads | 1:75966605a6a3 | 301 | //printf("\n\n\n"); |
suads | 1:75966605a6a3 | 302 | uint8_t zeroMotionDetectionThreshold = mpu.getZeroMotionDetectionThreshold(); |
suads | 1:75966605a6a3 | 303 | //printf("MPU6050 zero motion detection threshold is: %d \r\n", zeroMotionDetectionThreshold); |
suads | 1:75966605a6a3 | 304 | //printf("MPU6050 set zero motion detection threshold to 2\r\n"); |
suads | 1:75966605a6a3 | 305 | mpu.setZeroMotionDetectionThreshold(2); |
suads | 1:75966605a6a3 | 306 | zeroMotionDetectionThreshold = mpu.getZeroMotionDetectionThreshold(); |
suads | 1:75966605a6a3 | 307 | //printf("MPU6050 zero motion detection threshold now is: %d \r\n", zeroMotionDetectionThreshold); |
suads | 1:75966605a6a3 | 308 | printf("Zero motion detection threshold is: %d \r\n", zeroMotionDetectionThreshold); |
suads | 1:75966605a6a3 | 309 | //printf("\n\n\n"); |
suads | 1:75966605a6a3 | 310 | int8_t zeroMotionDetectionDuration = mpu.getZeroMotionDetectionDuration(); |
suads | 1:75966605a6a3 | 311 | //printf("MPU6050 zero motion detection duration is: %d \r\n", zeroMotionDetectionDuration); |
suads | 1:75966605a6a3 | 312 | //printf("MPU6050 set zero motion detection duration to 1\r\n"); |
suads | 1:75966605a6a3 | 313 | mpu.setZeroMotionDetectionDuration(1); |
suads | 1:75966605a6a3 | 314 | zeroMotionDetectionDuration = mpu.getZeroMotionDetectionDuration(); |
suads | 1:75966605a6a3 | 315 | //printf("MPU6050 zero motion detection duration now is: %d \r\n", zeroMotionDetectionDuration); |
suads | 1:75966605a6a3 | 316 | printf("Zero motion detection duration is: %d \r\n", zeroMotionDetectionDuration); |
suads | 1:75966605a6a3 | 317 | |
suads | 1:75966605a6a3 | 318 | //******************************************************************************************************************************* |
suads | 1:75966605a6a3 | 319 | |
suads | 1:75966605a6a3 | 320 | //printf("\n\n\n"); |
suads | 1:75966605a6a3 | 321 | int8_t freefallDetectionThreshold = mpu.getFreefallDetectionThreshold(); |
suads | 1:75966605a6a3 | 322 | //printf("MPU6050 freefall motion detection threshold is: %d \r\n", freefallDetectionThreshold); |
suads | 1:75966605a6a3 | 323 | //printf("MPU6050 set freefall motion detection threshold to 40\r\n"); |
suads | 1:75966605a6a3 | 324 | //mpu.setFreefallDetectionThreshold(2); |
suads | 1:75966605a6a3 | 325 | freefallDetectionThreshold = mpu.getFreefallDetectionThreshold(); |
suads | 1:75966605a6a3 | 326 | //printf("MPU6050 freefall motion detection threshold now is: %d \r\n", freefallDetectionThreshold); |
suads | 1:75966605a6a3 | 327 | printf("Freefall motion detection threshold is: %d \r\n", freefallDetectionThreshold); |
suads | 1:75966605a6a3 | 328 | //printf("\n\n\n"); |
suads | 1:75966605a6a3 | 329 | int8_t freefallDetectionDuration = mpu.getFreefallDetectionDuration(); |
suads | 1:75966605a6a3 | 330 | //printf("MPU6050 freefall motion detection duration is: %d \r\n", freefallDetectionDuration); |
suads | 1:75966605a6a3 | 331 | //printf("MPU6050 set freefall motion detection duration to 40\r\n"); |
suads | 1:75966605a6a3 | 332 | //mpu.setFreefallDetectionDuration(40); |
suads | 1:75966605a6a3 | 333 | freefallDetectionDuration = mpu.getFreefallDetectionDuration(); |
suads | 1:75966605a6a3 | 334 | //printf("MPU6050 freefall motion detection duration now is: %d \r\n", freefallDetectionDuration); |
suads | 1:75966605a6a3 | 335 | printf("Freefall motion detection duration is: %d \r\n", freefallDetectionDuration); |
suads | 1:75966605a6a3 | 336 | printf("\n\n\n"); |
suads | 1:75966605a6a3 | 337 | printf("MPU6050 test\n\n"); |
suads | 1:75966605a6a3 | 338 | |
suads | 1:75966605a6a3 | 339 | |
suads | 1:75966605a6a3 | 340 | //******************************************************************************************************************************* |
suads | 1:75966605a6a3 | 341 | */ |
suads | 0:203cf529f52a | 342 | |
suads | 0:203cf529f52a | 343 | |
suads | 0:203cf529f52a | 344 | |
suads | 0:203cf529f52a | 345 | while(1) { |
suads | 1:75966605a6a3 | 346 | |
suads | 1:75966605a6a3 | 347 | if(test==1) { |
suads | 1:75966605a6a3 | 348 | wait(0.2); |
suads | 1:75966605a6a3 | 349 | test = 0; |
suads | 1:75966605a6a3 | 350 | getXYZMotions(); |
suads | 1:75966605a6a3 | 351 | //mot=2; |
suads | 0:203cf529f52a | 352 | } |
suads | 1:75966605a6a3 | 353 | |
suads | 1:75966605a6a3 | 354 | |
suads | 1:75966605a6a3 | 355 | |
suads | 1:75966605a6a3 | 356 | if(print==1) { |
suads | 1:75966605a6a3 | 357 | mojlogger.print(); |
suads | 1:75966605a6a3 | 358 | print=0; |
suads | 1:75966605a6a3 | 359 | } |
suads | 0:203cf529f52a | 360 | |
suads | 0:203cf529f52a | 361 | |
suads | 0:203cf529f52a | 362 | |
suads | 1:75966605a6a3 | 363 | //printf("caseFsm->DeviceInFullState()=%d\n",caseFsm->DeviceInFullState()); |
suads | 1:75966605a6a3 | 364 | //This goes into caseFsm, but for now we are testing in main.cpp |
suads | 1:75966605a6a3 | 365 | if(caseFsm->DeviceInFullState()) { |
suads | 1:75966605a6a3 | 366 | printf("Waiting 5 seconds for RFID event...\r\n"); |
suads | 1:75966605a6a3 | 367 | while (caseFsm->DeviceInFullState()) { |
suads | 1:75966605a6a3 | 368 | // Look for new cards |
suads | 1:75966605a6a3 | 369 | |
suads | 1:75966605a6a3 | 370 | |
suads | 1:75966605a6a3 | 371 | if ( ! RfChip.PICC_IsNewCardPresent()) { |
suads | 1:75966605a6a3 | 372 | wait_ms(500); |
suads | 1:75966605a6a3 | 373 | printf("!RfChip.PICC_IsNewCardPresent()\n"); |
suads | 1:75966605a6a3 | 374 | continue; |
suads | 1:75966605a6a3 | 375 | } |
suads | 1:75966605a6a3 | 376 | |
suads | 1:75966605a6a3 | 377 | // Select one of the cards |
suads | 1:75966605a6a3 | 378 | if ( ! RfChip.PICC_ReadCardSerial()) { |
suads | 1:75966605a6a3 | 379 | printf("!RfChip.PICC_ReadCardSerial()\n"); |
suads | 1:75966605a6a3 | 380 | wait_ms(500); |
suads | 1:75966605a6a3 | 381 | continue; |
suads | 1:75966605a6a3 | 382 | } |
suads | 0:203cf529f52a | 383 | |
suads | 1:75966605a6a3 | 384 | // Print Card UID |
suads | 1:75966605a6a3 | 385 | printf("Card UID: "); |
suads | 1:75966605a6a3 | 386 | for (uint8_t i = 0; i < RfChip.uid.size; i++) { |
suads | 1:75966605a6a3 | 387 | rfidEvent.uid[i] = RfChip.uid.uidByte[i]; |
suads | 1:75966605a6a3 | 388 | printf("%X ", RfChip.uid.uidByte[i]); |
suads | 0:203cf529f52a | 389 | } |
suads | 1:75966605a6a3 | 390 | rfidEvent.size = RfChip.uid.size; |
suads | 1:75966605a6a3 | 391 | printf("\n\r"); |
suads | 1:75966605a6a3 | 392 | |
suads | 1:75966605a6a3 | 393 | // Print Card type |
suads | 1:75966605a6a3 | 394 | uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); |
suads | 1:75966605a6a3 | 395 | printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); |
suads | 1:75966605a6a3 | 396 | wait_ms(1000); |
suads | 1:75966605a6a3 | 397 | rfidEvent.cardType = piccType; |
suads | 1:75966605a6a3 | 398 | //phone inserted |
suads | 1:75966605a6a3 | 399 | caseFsm->handle(rfidEvent); |
suads | 1:75966605a6a3 | 400 | printf("_%d_\n",caseFsm->DeviceInPhoneDetectedState()); |
suads | 1:75966605a6a3 | 401 | if(caseFsm->DeviceInPhoneDetectedState()) { |
suads | 1:75966605a6a3 | 402 | wait(0.3); |
suads | 1:75966605a6a3 | 403 | x++; |
suads | 1:75966605a6a3 | 404 | printf("snimi\n"); |
suads | 1:75966605a6a3 | 405 | mojlog.setLog(600,1,0,600); |
suads | 1:75966605a6a3 | 406 | mojlogger.savelog(mojlog); |
suads | 1:75966605a6a3 | 407 | ;//LOGOVATI INSERTED |
suads | 1:75966605a6a3 | 408 | |
suads | 1:75966605a6a3 | 409 | } |
suads | 1:75966605a6a3 | 410 | |
suads | 1:75966605a6a3 | 411 | } |
suads | 1:75966605a6a3 | 412 | if(caseFsm->DeviceInDeviceEmptyState()) { |
suads | 1:75966605a6a3 | 413 | wait(0.3); |
suads | 1:75966605a6a3 | 414 | printf("ne snimi\n"); |
suads | 1:75966605a6a3 | 415 | x++; //LOGOVATI REMOVED |
suads | 1:75966605a6a3 | 416 | mojlog.setLog(400,0,0,400); |
suads | 1:75966605a6a3 | 417 | mojlogger.savelog(mojlog); |
suads | 1:75966605a6a3 | 418 | } |
suads | 0:203cf529f52a | 419 | } |
suads | 0:203cf529f52a | 420 | |
suads | 0:203cf529f52a | 421 | |
suads | 0:203cf529f52a | 422 | |
suads | 1:75966605a6a3 | 423 | } |
suads | 0:203cf529f52a | 424 | |
suads | 0:203cf529f52a | 425 | } |