Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed AQM1602 HMC6352 PID
command.cpp
00001 #include "mbed.h" 00002 #include "extern.h" 00003 00004 void CommandLoop(void){ 00005 uint8_t SwState,x=0,y=0, z; 00006 uint8_t (*Function[STATE_NUM_Y])(uint8_t x) = { 00007 LoopFunction0, 00008 LoopFunction1, 00009 LoopFunction2, 00010 LoopFunction3, 00011 LoopFunction4, 00012 LoopFunction5, 00013 LoopFunction6, 00014 LoopFunction7, 00015 LoopFunction8, 00016 LoopFunction9, 00017 LoopFunctionA, 00018 LoopFunctionB, 00019 LoopFunctionC, 00020 LoopFunctionD, 00021 LoopFunctionE, 00022 LoopFunctionF 00023 }; 00024 data.init_point_flag=0; 00025 while(1){ 00026 SwState = ReadSw(); 00027 if(SwState == NONE){ 00028 if(x!=0){ 00029 z = (*Function[y])(x); 00030 if(z==1){ 00031 if((x!=0)&&(data.init_point_flag==1)){ 00032 data.init_point_flag=0; 00033 y = 1; 00034 } 00035 x=0; 00036 Lcd.cls(); 00037 Lcd.locate(0, 0); 00038 Lcd.print(lcdstr[y][0]); 00039 Lcd.locate(7, 0); 00040 Lcd.print(">"); 00041 Lcd.locate(9, 0); 00042 if(x!=0) Lcd.print(lcdstr[y][x]); 00043 } 00044 //Z==1...Once 00045 //Z==0...Endless 00046 } 00047 continue; 00048 } 00049 if(SwState == UP){ 00050 y += -1 + STATE_NUM_Y; 00051 y %= STATE_NUM_Y; 00052 x=0; 00053 } 00054 if(SwState == DOWN){ 00055 y++; 00056 y %= STATE_NUM_Y; 00057 x=0; 00058 } 00059 if(SwState == RIGHT){ 00060 if(lcdstr[y][1][0]==0) x=0; 00061 else x++; 00062 if(x==STATE_NUM_X) x=0; 00063 if(lcdstr[y][x][0]==0) x=0; 00064 else x %= STATE_NUM_X; 00065 } 00066 if(SwState == LEFT){ 00067 if((x!=0)&&(data.init_point_flag==1)){ 00068 data.init_point_flag=0; 00069 y = 1; 00070 } 00071 x=0; 00072 } 00073 Lcd.cls(); 00074 Lcd.locate(0, 0); 00075 Lcd.print(lcdstr[y][0]); 00076 Lcd.locate(7, 0); 00077 Lcd.print(">"); 00078 Lcd.locate(9, 0); 00079 if(x!=0) Lcd.print(lcdstr[y][x]); 00080 } 00081 } 00082 uint8_t LoopFunction0(uint8_t x){ 00083 char buf[0x10]; 00084 if(x==1){ 00085 sprintf(buf, "Strategy:%2d", data.strategy); 00086 Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; 00087 } 00088 else{//x==2 00089 sprintf(buf, "SeeYouAgain!"); 00090 Lcd.locate(0, 1);Lcd.print(buf);wait(0.5); 00091 NVIC_SystemReset(); 00092 return 1; 00093 } 00094 } 00095 uint8_t LoopFunction1(uint8_t x){ 00096 char buf[0x10]; 00097 sprintf(buf, "CatPot"); 00098 Lcd.locate(0, 1);Lcd.print(buf); 00099 data.strategy=0; 00100 ActiveLoop(); 00101 return 1; 00102 } 00103 uint8_t LoopFunction2(uint8_t x){ 00104 char buf[0x10]; 00105 ReadIr(); 00106 00107 if(x==1) sprintf(buf, "SHRT:%2d, LNG:%2d", data.irSpot[0], data.irSpot[1]); 00108 if(x==2) sprintf(buf, "NOTE:%2d", data.irNotice); 00109 if(x==3) sprintf(buf, "POSITION:%2d", data.irPosition); 00110 Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; 00111 } 00112 uint8_t LoopFunction3(uint8_t x){ 00113 char buf[0x10]; 00114 if(x==1){ 00115 sprintf(buf, "A:%1d B:%1d C:%1d ", Line[0].read(), Line[1].read(), Line[2].read()); 00116 Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; 00117 } 00118 if(x==2){ 00119 ReadPing(); 00120 sprintf(buf, "L:%3d R:%3d", data.ping[L_PING], data.ping[R_PING]); 00121 Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; 00122 } 00123 if(x==3){ 00124 ReadIr(); 00125 sprintf(buf, "IR_KEY:%2d", data.irKey); 00126 Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; 00127 } 00128 return 0; 00129 } 00130 uint8_t LoopFunction4(uint8_t x){ 00131 char buf[0x10]; 00132 PidUpdate(); 00133 sprintf(buf, "In:%03.0f Out:%+02d", data.InputPID, data.OutputPID); 00134 Lcd.locate(0, 1);Lcd.print(buf);wait_ms(50);return 0; 00135 } 00136 uint8_t LoopFunction5(uint8_t x){ 00137 char buf[0x10]; 00138 sprintf(buf, "Enter"); 00139 Lcd.locate(0, 1);Lcd.print(buf); 00140 hmc.setCalibrationMode(HMC6352_EXIT_CALIB); 00141 return 1; 00142 } 00143 uint8_t LoopFunction6(uint8_t x){ 00144 char buf[0x10]; 00145 sprintf(buf, "Exit"); 00146 Lcd.locate(0, 1);Lcd.print(buf); 00147 hmc.setCalibrationMode(HMC6352_ENTER_CALIB); 00148 return 1; 00149 } 00150 uint8_t LoopFunction7(uint8_t x){ 00151 char buf[0x10]; 00152 data.init_point_flag=1; 00153 sprintf(buf, "FaceToFront!"); 00154 Lcd.locate(0, 1);Lcd.print(buf); 00155 for(int i=0; i<5; i++){ 00156 ReadCmps(); 00157 data.CmpsInitialValue = data.cmps; 00158 wait_ms(100); 00159 } 00160 data.CmpsDiff = REFERENCE - data.cmps; 00161 data.FrontDeg=0; 00162 return 1; 00163 } 00164 uint8_t LoopFunction8(uint8_t x){ 00165 char buf[0x10]; 00166 if(x==1){ 00167 data.s_pow = 20; 00168 data.l_pow = 20; 00169 } 00170 if(x==2){ 00171 data.s_pow = 30; 00172 data.l_pow = 30; 00173 } 00174 if(x==3){ 00175 data.s_pow = 40; 00176 data.l_pow = 40; 00177 } 00178 sprintf(buf, "TuningS_power"); 00179 Lcd.locate(0, 1);Lcd.print(buf);return 0; 00180 } 00181 uint8_t LoopFunction9(uint8_t x){ 00182 char buf[0x10]; 00183 if(x==1){ 00184 data.s_pow = 20; 00185 data.l_pow = 30; 00186 } 00187 if(x==2){ 00188 data.s_pow = 25; 00189 data.l_pow = 35; 00190 } 00191 if(x==3){ 00192 data.s_pow = 35; 00193 data.l_pow = 45; 00194 } 00195 sprintf(buf, "TuningL_power"); 00196 Lcd.locate(0, 1);Lcd.print(buf);return 0; 00197 } 00198 uint8_t LoopFunctionA(uint8_t x){ 00199 char buf[0x10]; 00200 sprintf(buf, "SeeYouAgain!"); 00201 Lcd.locate(0, 1);Lcd.print(buf);wait(0.5); 00202 NVIC_SystemReset(); 00203 return 1; 00204 } 00205 uint8_t LoopFunctionB(uint8_t x){ 00206 char buf[0x10]; 00207 if(x==1) data.strategy = 6; 00208 if(x==2) data.strategy = 7; 00209 if(x==3) data.strategy = 8; 00210 data.init_point_flag=1; 00211 sprintf(buf, "Make a strategy"); 00212 Lcd.locate(0, 1);Lcd.print(buf);return 0; 00213 } 00214 uint8_t LoopFunctionC(uint8_t x){ 00215 char buf[0x10]; 00216 if(x==1) data.strategy = 9; 00217 if(x==2) data.strategy = 10; 00218 if(x==3) data.strategy = 11; 00219 data.init_point_flag=1; 00220 sprintf(buf, "Make a strategy"); 00221 Lcd.locate(0, 1);Lcd.print(buf);return 0; 00222 } 00223 uint8_t LoopFunctionD(uint8_t x){ 00224 char buf[0x10]; 00225 if(x==1) data.strategy = 0; 00226 if(x==2) data.strategy = 1; 00227 if(x==3) data.strategy = 2; 00228 data.init_point_flag=1; 00229 sprintf(buf, "Make a strategy"); 00230 Lcd.locate(0, 1);Lcd.print(buf);return 0; 00231 } 00232 uint8_t LoopFunctionE(uint8_t x){ 00233 char buf[0x10]; 00234 if(x==1) data.strategy = 3; 00235 if(x==2) data.strategy = 4; 00236 if(x==3) data.strategy = 5; 00237 data.init_point_flag=1; 00238 sprintf(buf, "Make a strategy"); 00239 Lcd.locate(0, 1);Lcd.print(buf);return 0; 00240 } 00241 uint8_t LoopFunctionF(uint8_t x){ 00242 char buf[0x10]; 00243 sprintf(buf, "CatPotForDebug"); 00244 Lcd.locate(0, 1);Lcd.print(buf); 00245 ActiveLoop(); 00246 return 1; 00247 }
Generated on Tue Jul 12 2022 23:12:38 by
