ジャパンオープン用のメインプログラム

Dependencies:   mbed AQM1602 HMC6352 PID

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers command.cpp Source File

command.cpp

00001 #include "mbed.h"
00002 #include "extern.h"
00003 
00004 void Command(void){
00005     uint8_t SwState,x=0,y=0, z;
00006     uint8_t i;
00007     
00008     sys.jump_flag=JUMP_TAG_MAX;
00009     LcdPrint(&x,&y);
00010     while(1){
00011         SwState = ReadSw();
00012         if(SwState == NONE){
00013             if(x!=0){
00014                 z = item[y].CommandFunction(x);
00015                 if(z==1){
00016                     x=0;
00017                     //jump
00018                     if(sys.jump_flag!=JUMP_TAG_MAX){
00019                         for(i=0; i<STATE_NUM_Y; i++){
00020                             if(sys.jump_flag==item[i].tag_num) break;
00021                         }
00022                         if(i<STATE_NUM_Y){
00023                             y = i;
00024                             y %= STATE_NUM_Y;
00025                         }
00026                         sys.jump_flag=JUMP_TAG_MAX;
00027                     }
00028                     LcdPrint(&x,&y);
00029                 }
00030                 //Z==1...Once
00031                 //Z==0...Endless
00032             }
00033             
00034             continue;
00035         }
00036         if(SwState == UP){
00037             y += -1 + STATE_NUM_Y;
00038             y %= STATE_NUM_Y;
00039             x=0;
00040         }
00041         if(SwState == DOWN){
00042             y++;
00043             y %= STATE_NUM_Y;
00044             x=0;
00045         }
00046         if(SwState == RIGHT){
00047             if(item[y].str_num<=1) x=0;
00048             else x++;
00049             x %= item[y].str_num;
00050         }
00051         if(SwState == LEFT){
00052             x=0;
00053         }
00054         if(x==0){
00055             X_ZERO_Function(&x,&y);
00056         }
00057         else{
00058             X_NZERO_Function(&x,&y);
00059         }
00060         LcdPrint(&x,&y);
00061     }
00062 }
00063 uint8_t X_ZERO_Function(uint8_t *x, uint8_t *y){
00064     uint8_t i;
00065     if(sys.jump_flag!=JUMP_TAG_MAX){//jump
00066         for(i=0; i<STATE_NUM_Y; i++){
00067             if(sys.jump_flag==item[i].tag_num) break;
00068         }
00069         if(i<STATE_NUM_Y){
00070             *y = i;
00071             *y %= STATE_NUM_Y;
00072         }
00073         sys.jump_flag=JUMP_TAG_MAX;
00074     }
00075     
00076     ReadCmps();
00077     //cmps_set.CmpsInitialValue = cmps_set.cmps;
00078     wait_ms(10);
00079     cmps_set.CmpsDiff = REFERENCE - cmps_set.cmps;
00080     cmps_set.FrontDeg=0;
00081     
00082     LineKeeper=LINE_FREE;//line
00083     return 0;
00084 }
00085 uint8_t X_NZERO_Function(uint8_t *x, uint8_t *y){
00086     LineKeeper=LINE_FIX;//line
00087     return 0;
00088 }
00089 uint8_t LcdPrint(uint8_t *x, uint8_t *y){
00090     Lcd.cls();
00091     Lcd.locate(0, 0);
00092     Lcd.print(item[*y].LcdStr[0]);
00093     Lcd.locate(7, 0);
00094     Lcd.print(">");
00095     Lcd.locate(9, 0);
00096     if(*x!=0) Lcd.print(item[*y].LcdStr[*x]);
00097     return 0;
00098 }