![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Main Program
Dependencies: mbed AQM1602 HMC6352 PID
main_processing/setup_command_active/command.cpp
- Committer:
- lilac0112_1
- Date:
- 2016-02-25
- Revision:
- 45:c23f25c00d0d
- Parent:
- 44:a793dd45f84c
File content as of revision 45:c23f25c00d0d:
#include "mbed.h" #include "extern.h" void CommandLoop(void){ uint8_t SwState,x=0,y=0, z; uint8_t (*Function[STATE_NUM_Y])(uint8_t x) = { LoopFunction0, LoopFunction1, LoopFunction2, LoopFunction3, LoopFunction4, LoopFunction5, LoopFunction6, LoopFunction7, LoopFunction8, LoopFunction9, LoopFunctionA, LoopFunctionB, LoopFunctionC, LoopFunctionD, LoopFunctionE, LoopFunctionF }; data.init_point_flag=0; while(1){ SwState = ReadSw(); if(SwState == NONE){ if(x!=0){ z = (*Function[y])(x); if(z==1){ if((x!=0)&&(data.init_point_flag==1)){ data.init_point_flag=0; y = 1; } x=0; Lcd.cls(); Lcd.locate(0, 0); Lcd.print(lcdstr[y][0]); Lcd.locate(7, 0); Lcd.print(">"); Lcd.locate(9, 0); if(x!=0) Lcd.print(lcdstr[y][x]); } //Z==1...Once //Z==0...Endless } continue; } if(SwState == UP){ y += -1 + STATE_NUM_Y; y %= STATE_NUM_Y; x=0; } if(SwState == DOWN){ y++; y %= STATE_NUM_Y; x=0; } if(SwState == RIGHT){ if(lcdstr[y][1][0]==0) x=0; else x++; if(x==STATE_NUM_X) x=0; if(lcdstr[y][x][0]==0) x=0; else x %= STATE_NUM_X; } if(SwState == LEFT){ if((x!=0)&&(data.init_point_flag==1)){ data.init_point_flag=0; y = 1; } x=0; } Lcd.cls(); Lcd.locate(0, 0); Lcd.print(lcdstr[y][0]); Lcd.locate(7, 0); Lcd.print(">"); Lcd.locate(9, 0); if(x!=0) Lcd.print(lcdstr[y][x]); } } uint8_t LoopFunction0(uint8_t x){ char buf[0x10]; if(x==1){ sprintf(buf, "Strategy:%2d", data.strategy); Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; } else{//x==2 sprintf(buf, "SeeYouAgain!"); Lcd.locate(0, 1);Lcd.print(buf);wait(0.5); NVIC_SystemReset(); return 1; } } uint8_t LoopFunction1(uint8_t x){ char buf[0x10]; sprintf(buf, "CatPot"); Lcd.locate(0, 1);Lcd.print(buf); data.strategy=0; ActiveLoop(); return 1; } uint8_t LoopFunction2(uint8_t x){ char buf[0x10]; ReadIr(); if(x==1) sprintf(buf, "SHRT:%2d, LNG:%2d", data.irSpot[0], data.irSpot[1]); if(x==2) sprintf(buf, "NOTE:%2d", data.irNotice); if(x==3) sprintf(buf, "POSITION:%2d", data.irPosition); Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; } uint8_t LoopFunction3(uint8_t x){ char buf[0x10]; if(x==1){ sprintf(buf, "A:%1d B:%1d C:%1d ", Line[0].read(), Line[1].read(), Line[2].read()); Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; } if(x==2){ ReadPing(); sprintf(buf, "L:%3d R:%3d", data.ping[L_PING], data.ping[R_PING]); Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; } if(x==3){ ReadIr(); sprintf(buf, "IR_KEY:%2d", data.irKey); Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; } return 0; } uint8_t LoopFunction4(uint8_t x){ char buf[0x10]; PidUpdate(); sprintf(buf, "In:%03.0f Out:%+02d", data.InputPID, data.OutputPID); Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; } uint8_t LoopFunction5(uint8_t x){ char buf[0x10]; sprintf(buf, "Enter"); Lcd.locate(0, 1);Lcd.print(buf); hmc.setCalibrationMode(HMC6352_EXIT_CALIB); return 1; } uint8_t LoopFunction6(uint8_t x){ char buf[0x10]; sprintf(buf, "Exit"); Lcd.locate(0, 1);Lcd.print(buf); hmc.setCalibrationMode(HMC6352_ENTER_CALIB); return 1; } uint8_t LoopFunction7(uint8_t x){ char buf[0x10]; data.init_point_flag=1; sprintf(buf, "FaceToFront!"); Lcd.locate(0, 1);Lcd.print(buf); for(int i=0; i<5; i++){ ReadCmps(); data.CmpsInitialValue = data.cmps; wait_ms(100); } data.CmpsDiff = REFERENCE - data.cmps; data.FrontDeg=0; return 1; } uint8_t LoopFunction8(uint8_t x){ char buf[0x10]; if(x==1){ data.s_pow = 20; data.l_pow = 20; } if(x==2){ data.s_pow = 30; data.l_pow = 30; } if(x==3){ data.s_pow = 40; data.l_pow = 40; } sprintf(buf, "TuningS_power"); Lcd.locate(0, 1);Lcd.print(buf);return 0; } uint8_t LoopFunction9(uint8_t x){ char buf[0x10]; if(x==1){ data.s_pow = 20; data.l_pow = 30; } if(x==2){ data.s_pow = 25; data.l_pow = 35; } if(x==3){ data.s_pow = 35; data.l_pow = 45; } sprintf(buf, "TuningL_power"); Lcd.locate(0, 1);Lcd.print(buf);return 0; } uint8_t LoopFunctionA(uint8_t x){ char buf[0x10]; sprintf(buf, "SeeYouAgain!"); Lcd.locate(0, 1);Lcd.print(buf);wait(0.5); NVIC_SystemReset(); return 1; } uint8_t LoopFunctionB(uint8_t x){ char buf[0x10]; if(x==1) data.strategy = 6; if(x==2) data.strategy = 7; if(x==3) data.strategy = 8; data.init_point_flag=1; sprintf(buf, "Make a strategy"); Lcd.locate(0, 1);Lcd.print(buf);return 0; } uint8_t LoopFunctionC(uint8_t x){ char buf[0x10]; if(x==1) data.strategy = 9; if(x==2) data.strategy = 10; if(x==3) data.strategy = 11; data.init_point_flag=1; sprintf(buf, "Make a strategy"); Lcd.locate(0, 1);Lcd.print(buf);return 0; } uint8_t LoopFunctionD(uint8_t x){ char buf[0x10]; if(x==1) data.strategy = 0; if(x==2) data.strategy = 1; if(x==3) data.strategy = 2; data.init_point_flag=1; sprintf(buf, "Make a strategy"); Lcd.locate(0, 1);Lcd.print(buf);return 0; } uint8_t LoopFunctionE(uint8_t x){ char buf[0x10]; if(x==1) data.strategy = 3; if(x==2) data.strategy = 4; if(x==3) data.strategy = 5; data.init_point_flag=1; sprintf(buf, "Make a strategy"); Lcd.locate(0, 1);Lcd.print(buf);return 0; } uint8_t LoopFunctionF(uint8_t x){ char buf[0x10]; sprintf(buf, "CatPotForDebug"); Lcd.locate(0, 1);Lcd.print(buf); ActiveLoop(); return 1; }