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

Dependencies:   mbed AQM1602 HMC6352 PID

Committer:
lilac0112_1
Date:
Thu Mar 03 11:47:49 2016 +0000
Revision:
3:c49ea7ad8e91
Parent:
2:635947de1583
Child:
4:52da8da146d4
somehow

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lilac0112_1 0:ea35c18c85fc 1 #include "mbed.h"
lilac0112_1 0:ea35c18c85fc 2 #include "extern.h"
lilac0112_1 0:ea35c18c85fc 3
lilac0112_1 0:ea35c18c85fc 4 void CommandLoop(void){
lilac0112_1 0:ea35c18c85fc 5 uint8_t SwState,x=0,y=0, z;
lilac0112_1 0:ea35c18c85fc 6 uint8_t (*Function[STATE_NUM_Y])(uint8_t x) = {
lilac0112_1 0:ea35c18c85fc 7 LoopFunction0,
lilac0112_1 0:ea35c18c85fc 8 LoopFunction1,
lilac0112_1 0:ea35c18c85fc 9 LoopFunction2,
lilac0112_1 0:ea35c18c85fc 10 LoopFunction3,
lilac0112_1 0:ea35c18c85fc 11 LoopFunction4,
lilac0112_1 0:ea35c18c85fc 12 LoopFunction5,
lilac0112_1 0:ea35c18c85fc 13 LoopFunction6,
lilac0112_1 0:ea35c18c85fc 14 LoopFunction7,
lilac0112_1 0:ea35c18c85fc 15 LoopFunction8,
lilac0112_1 0:ea35c18c85fc 16 LoopFunction9,
lilac0112_1 0:ea35c18c85fc 17 LoopFunctionA,
lilac0112_1 0:ea35c18c85fc 18 LoopFunctionB,
lilac0112_1 0:ea35c18c85fc 19 LoopFunctionC,
lilac0112_1 0:ea35c18c85fc 20 LoopFunctionD,
lilac0112_1 0:ea35c18c85fc 21 LoopFunctionE,
lilac0112_1 0:ea35c18c85fc 22 LoopFunctionF
lilac0112_1 0:ea35c18c85fc 23 };
lilac0112_1 2:635947de1583 24 sys.jump_flag=STATE_NUM_Y;
lilac0112_1 0:ea35c18c85fc 25 while(1){
lilac0112_1 2:635947de1583 26
lilac0112_1 0:ea35c18c85fc 27 if(x==0){
lilac0112_1 2:635947de1583 28 LineKeeper=0x7;
lilac0112_1 0:ea35c18c85fc 29 }
lilac0112_1 0:ea35c18c85fc 30 else{
lilac0112_1 2:635947de1583 31 LineKeeper=0x0;
lilac0112_1 0:ea35c18c85fc 32 }
lilac0112_1 2:635947de1583 33
lilac0112_1 0:ea35c18c85fc 34 SwState = ReadSw();
lilac0112_1 0:ea35c18c85fc 35 if(SwState == NONE){
lilac0112_1 0:ea35c18c85fc 36 if(x!=0){
lilac0112_1 0:ea35c18c85fc 37 z = (*Function[y])(x);
lilac0112_1 0:ea35c18c85fc 38 if(z==1){
lilac0112_1 2:635947de1583 39 if((x!=0)&&(sys.jump_flag!=STATE_NUM_Y)){
lilac0112_1 2:635947de1583 40 y = sys.jump_flag;
lilac0112_1 2:635947de1583 41 sys.jump_flag=STATE_NUM_Y;
lilac0112_1 0:ea35c18c85fc 42 }
lilac0112_1 0:ea35c18c85fc 43 x=0;
lilac0112_1 0:ea35c18c85fc 44 Lcd.cls();
lilac0112_1 0:ea35c18c85fc 45 Lcd.locate(0, 0);
lilac0112_1 0:ea35c18c85fc 46 Lcd.print(lcdstr[y][0]);
lilac0112_1 0:ea35c18c85fc 47 Lcd.locate(7, 0);
lilac0112_1 0:ea35c18c85fc 48 Lcd.print(">");
lilac0112_1 0:ea35c18c85fc 49 Lcd.locate(9, 0);
lilac0112_1 0:ea35c18c85fc 50 if(x!=0) Lcd.print(lcdstr[y][x]);
lilac0112_1 0:ea35c18c85fc 51 }
lilac0112_1 0:ea35c18c85fc 52 //Z==1...Once
lilac0112_1 0:ea35c18c85fc 53 //Z==0...Endless
lilac0112_1 0:ea35c18c85fc 54 }
lilac0112_1 0:ea35c18c85fc 55 continue;
lilac0112_1 0:ea35c18c85fc 56 }
lilac0112_1 0:ea35c18c85fc 57 if(SwState == UP){
lilac0112_1 0:ea35c18c85fc 58 y += -1 + STATE_NUM_Y;
lilac0112_1 0:ea35c18c85fc 59 y %= STATE_NUM_Y;
lilac0112_1 0:ea35c18c85fc 60 x=0;
lilac0112_1 0:ea35c18c85fc 61 }
lilac0112_1 0:ea35c18c85fc 62 if(SwState == DOWN){
lilac0112_1 0:ea35c18c85fc 63 y++;
lilac0112_1 0:ea35c18c85fc 64 y %= STATE_NUM_Y;
lilac0112_1 0:ea35c18c85fc 65 x=0;
lilac0112_1 0:ea35c18c85fc 66 }
lilac0112_1 0:ea35c18c85fc 67 if(SwState == RIGHT){
lilac0112_1 0:ea35c18c85fc 68 if(lcdstr[y][1][0]==0) x=0;
lilac0112_1 0:ea35c18c85fc 69 else x++;
lilac0112_1 0:ea35c18c85fc 70 if(x==STATE_NUM_X) x=0;
lilac0112_1 0:ea35c18c85fc 71 if(lcdstr[y][x][0]==0) x=0;
lilac0112_1 0:ea35c18c85fc 72 else x %= STATE_NUM_X;
lilac0112_1 0:ea35c18c85fc 73 }
lilac0112_1 0:ea35c18c85fc 74 if(SwState == LEFT){
lilac0112_1 2:635947de1583 75 if((x!=0)&&(sys.jump_flag!=STATE_NUM_Y)){
lilac0112_1 2:635947de1583 76 y = sys.jump_flag;
lilac0112_1 2:635947de1583 77 sys.jump_flag=STATE_NUM_Y;
lilac0112_1 2:635947de1583 78
lilac0112_1 0:ea35c18c85fc 79 }
lilac0112_1 0:ea35c18c85fc 80 x=0;
lilac0112_1 0:ea35c18c85fc 81 }
lilac0112_1 0:ea35c18c85fc 82 Lcd.cls();
lilac0112_1 0:ea35c18c85fc 83 Lcd.locate(0, 0);
lilac0112_1 0:ea35c18c85fc 84 Lcd.print(lcdstr[y][0]);
lilac0112_1 0:ea35c18c85fc 85 Lcd.locate(7, 0);
lilac0112_1 0:ea35c18c85fc 86 Lcd.print(">");
lilac0112_1 0:ea35c18c85fc 87 Lcd.locate(9, 0);
lilac0112_1 0:ea35c18c85fc 88 if(x!=0) Lcd.print(lcdstr[y][x]);
lilac0112_1 0:ea35c18c85fc 89 }
lilac0112_1 0:ea35c18c85fc 90 }
lilac0112_1 3:c49ea7ad8e91 91 uint8_t X_ZERO_Function(uint8_t *x, uint8_t *y){
lilac0112_1 3:c49ea7ad8e91 92 if(sys.jump_flag!=STATE_NUM_Y){
lilac0112_1 3:c49ea7ad8e91 93 *y = sys.jump_flag;
lilac0112_1 3:c49ea7ad8e91 94 while(item[*y].str_num<2){
lilac0112_1 3:c49ea7ad8e91 95 *y++;
lilac0112_1 3:c49ea7ad8e91 96 *y %= STATE_NUM_Y;
lilac0112_1 3:c49ea7ad8e91 97 *x=0;
lilac0112_1 3:c49ea7ad8e91 98 }
lilac0112_1 3:c49ea7ad8e91 99 sys.jump_flag=STATE_NUM_Y;
lilac0112_1 0:ea35c18c85fc 100 }
lilac0112_1 3:c49ea7ad8e91 101 LineKeeper=0x7;
lilac0112_1 3:c49ea7ad8e91 102 return 0;
lilac0112_1 0:ea35c18c85fc 103 }
lilac0112_1 3:c49ea7ad8e91 104 uint8_t X_NZERO_Function(uint8_t *x, uint8_t *y){
lilac0112_1 3:c49ea7ad8e91 105 LineKeeper=0x0;
lilac0112_1 3:c49ea7ad8e91 106 return 0;
lilac0112_1 0:ea35c18c85fc 107 }
lilac0112_1 3:c49ea7ad8e91 108 uint8_t LcdPrint(uint8_t *x, uint8_t *y){
lilac0112_1 3:c49ea7ad8e91 109 Lcd.cls();
lilac0112_1 3:c49ea7ad8e91 110 Lcd.locate(0, 0);
lilac0112_1 3:c49ea7ad8e91 111 Lcd.print(item[*y].LcdStr[0]);
lilac0112_1 3:c49ea7ad8e91 112 Lcd.locate(7, 0);
lilac0112_1 3:c49ea7ad8e91 113 Lcd.print(">");
lilac0112_1 3:c49ea7ad8e91 114 Lcd.locate(9, 0);
lilac0112_1 3:c49ea7ad8e91 115 if(*x!=0) Lcd.print(item[*y].LcdStr[*x]);
lilac0112_1 0:ea35c18c85fc 116 return 0;
lilac0112_1 0:ea35c18c85fc 117 }
lilac0112_1 3:c49ea7ad8e91 118 void Command(void){
lilac0112_1 3:c49ea7ad8e91 119 uint8_t SwState,x=0,y=0, z;
lilac0112_1 3:c49ea7ad8e91 120 sys.jump_flag=STATE_NUM_Y;
lilac0112_1 3:c49ea7ad8e91 121 while(1){
lilac0112_1 3:c49ea7ad8e91 122 SwState = ReadSw();
lilac0112_1 3:c49ea7ad8e91 123 if(SwState == NONE){
lilac0112_1 3:c49ea7ad8e91 124 if(x!=0){
lilac0112_1 3:c49ea7ad8e91 125 z = item[y].CommandFunction(x);
lilac0112_1 3:c49ea7ad8e91 126 if(z==1){
lilac0112_1 3:c49ea7ad8e91 127 x=0;
lilac0112_1 3:c49ea7ad8e91 128 LcdPrint(&x,&y);
lilac0112_1 3:c49ea7ad8e91 129 }
lilac0112_1 3:c49ea7ad8e91 130 //Z==1...Once
lilac0112_1 3:c49ea7ad8e91 131 //Z==0...Endless
lilac0112_1 3:c49ea7ad8e91 132 }
lilac0112_1 3:c49ea7ad8e91 133 //if((x==0)&&(sys.jump_flag!=STATE_NUM_Y)){jump&lcd}
lilac0112_1 3:c49ea7ad8e91 134 continue;
lilac0112_1 3:c49ea7ad8e91 135 }
lilac0112_1 3:c49ea7ad8e91 136 if(SwState == UP){
lilac0112_1 3:c49ea7ad8e91 137 do{
lilac0112_1 3:c49ea7ad8e91 138 y += -1 + STATE_NUM_Y;
lilac0112_1 3:c49ea7ad8e91 139 y %= STATE_NUM_Y;
lilac0112_1 3:c49ea7ad8e91 140 x=0;
lilac0112_1 3:c49ea7ad8e91 141 }while(item[y].str_num<2);
lilac0112_1 3:c49ea7ad8e91 142 }
lilac0112_1 3:c49ea7ad8e91 143 if(SwState == DOWN){
lilac0112_1 3:c49ea7ad8e91 144 do{
lilac0112_1 3:c49ea7ad8e91 145 y++;
lilac0112_1 3:c49ea7ad8e91 146 y %= STATE_NUM_Y;
lilac0112_1 3:c49ea7ad8e91 147 x=0;
lilac0112_1 3:c49ea7ad8e91 148 }while(item[y].str_num<2);
lilac0112_1 3:c49ea7ad8e91 149 }
lilac0112_1 3:c49ea7ad8e91 150 if(SwState == RIGHT){
lilac0112_1 3:c49ea7ad8e91 151
lilac0112_1 3:c49ea7ad8e91 152 if(item[y].str_num==1) x=0;
lilac0112_1 3:c49ea7ad8e91 153 else x++;
lilac0112_1 3:c49ea7ad8e91 154 if(x==item[y].str_num) x=0;
lilac0112_1 3:c49ea7ad8e91 155 if(x>=item[y].str_num) x=0;
lilac0112_1 3:c49ea7ad8e91 156 else x %= STATE_NUM_X;
lilac0112_1 3:c49ea7ad8e91 157
lilac0112_1 3:c49ea7ad8e91 158
lilac0112_1 3:c49ea7ad8e91 159 /*
lilac0112_1 3:c49ea7ad8e91 160 if(lcdstr[y][1][0]==0) x=0;
lilac0112_1 3:c49ea7ad8e91 161 else x++;
lilac0112_1 3:c49ea7ad8e91 162 if(x==STATE_NUM_X) x=0;
lilac0112_1 3:c49ea7ad8e91 163 if(lcdstr[y][x][0]==0) x=0;
lilac0112_1 3:c49ea7ad8e91 164 else x %= STATE_NUM_X;
lilac0112_1 3:c49ea7ad8e91 165 */
lilac0112_1 3:c49ea7ad8e91 166 }
lilac0112_1 3:c49ea7ad8e91 167 if(SwState == LEFT){
lilac0112_1 3:c49ea7ad8e91 168 if((x!=0)&&(sys.jump_flag!=STATE_NUM_Y)){
lilac0112_1 3:c49ea7ad8e91 169 y = sys.jump_flag;
lilac0112_1 3:c49ea7ad8e91 170 sys.jump_flag=STATE_NUM_Y;
lilac0112_1 3:c49ea7ad8e91 171
lilac0112_1 3:c49ea7ad8e91 172 }
lilac0112_1 3:c49ea7ad8e91 173 x=0;
lilac0112_1 3:c49ea7ad8e91 174 }
lilac0112_1 3:c49ea7ad8e91 175 if(x==0){
lilac0112_1 3:c49ea7ad8e91 176 X_ZERO_Function(&x,&y);
lilac0112_1 3:c49ea7ad8e91 177 }
lilac0112_1 3:c49ea7ad8e91 178 else{
lilac0112_1 3:c49ea7ad8e91 179 X_NZERO_Function(&x,&y);
lilac0112_1 3:c49ea7ad8e91 180 }
lilac0112_1 3:c49ea7ad8e91 181 LcdPrint(&x,&y);
lilac0112_1 0:ea35c18c85fc 182 }
lilac0112_1 0:ea35c18c85fc 183 }
lilac0112_1 3:c49ea7ad8e91 184
lilac0112_1 3:c49ea7ad8e91 185
lilac0112_1 3:c49ea7ad8e91 186