Set key(p20)を押したあと、Upper key(p19)、Down key(p18)をクリックしても、表示されるアドレス(ipe[4][4][3])が変化しない。もう一度Set keyを押さないと表示されない。ループで回している以上、逐次表示されるはずでは? あと、Right key(p16), Left key(p19)をおすと、表示される数字が、 Right:42, 41 , 00 Left: 41 , 40, 32 という数字。 なのに、実際数字が入力される配列は、 ipe[0][0〜2]の、3つのみである。 本当に不可解。
main.cpp@0:4c9b6e0bb8d5, 2012-05-19 (annotated)
- Committer:
- _muki
- Date:
- Sat May 19 20:35:17 2012 +0000
- Revision:
- 0:4c9b6e0bb8d5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
_muki | 0:4c9b6e0bb8d5 | 1 | #include "mbed.h" |
_muki | 0:4c9b6e0bb8d5 | 2 | #include "EthernetNetIf.h" |
_muki | 0:4c9b6e0bb8d5 | 3 | #include "HTTPServer.h" |
_muki | 0:4c9b6e0bb8d5 | 4 | #include "TextLCD.h" |
_muki | 0:4c9b6e0bb8d5 | 5 | |
_muki | 0:4c9b6e0bb8d5 | 6 | EthernetNetIf *eth; |
_muki | 0:4c9b6e0bb8d5 | 7 | IpAddr ipaddr, netmask, gateway, nameserver; |
_muki | 0:4c9b6e0bb8d5 | 8 | |
_muki | 0:4c9b6e0bb8d5 | 9 | DigitalOut led1(LED1); |
_muki | 0:4c9b6e0bb8d5 | 10 | DigitalOut led2(LED2); |
_muki | 0:4c9b6e0bb8d5 | 11 | DigitalIn Setkey(p20); |
_muki | 0:4c9b6e0bb8d5 | 12 | DigitalIn Leftkey(p19); |
_muki | 0:4c9b6e0bb8d5 | 13 | DigitalIn Downkey(p18); |
_muki | 0:4c9b6e0bb8d5 | 14 | DigitalIn Upperkey(p17); |
_muki | 0:4c9b6e0bb8d5 | 15 | DigitalIn Rightkey(p16); |
_muki | 0:4c9b6e0bb8d5 | 16 | |
_muki | 0:4c9b6e0bb8d5 | 17 | TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d0-d3 |
_muki | 0:4c9b6e0bb8d5 | 18 | LocalFileSystem local("local"); |
_muki | 0:4c9b6e0bb8d5 | 19 | |
_muki | 0:4c9b6e0bb8d5 | 20 | |
_muki | 0:4c9b6e0bb8d5 | 21 | struct keystate{ |
_muki | 0:4c9b6e0bb8d5 | 22 | int state; // push(0) or left(1)? |
_muki | 0:4c9b6e0bb8d5 | 23 | }; |
_muki | 0:4c9b6e0bb8d5 | 24 | |
_muki | 0:4c9b6e0bb8d5 | 25 | struct keystate port20; // setup key |
_muki | 0:4c9b6e0bb8d5 | 26 | struct keystate port19; // left key |
_muki | 0:4c9b6e0bb8d5 | 27 | struct keystate port18; // down key |
_muki | 0:4c9b6e0bb8d5 | 28 | struct keystate port17; // up key |
_muki | 0:4c9b6e0bb8d5 | 29 | struct keystate port16; // right key |
_muki | 0:4c9b6e0bb8d5 | 30 | |
_muki | 0:4c9b6e0bb8d5 | 31 | |
_muki | 0:4c9b6e0bb8d5 | 32 | void ipe_print(int ipe[4][4][3], int mode){ |
_muki | 0:4c9b6e0bb8d5 | 33 | lcd.locate(0,1); |
_muki | 0:4c9b6e0bb8d5 | 34 | lcd.printf("%d%d%d.%d%d%d.%d%d%d.%d%d%d", |
_muki | 0:4c9b6e0bb8d5 | 35 | ipe[mode][0][0],ipe[mode][0][1],ipe[mode][0][2], |
_muki | 0:4c9b6e0bb8d5 | 36 | ipe[mode][1][0],ipe[mode][1][1],ipe[mode][1][2], |
_muki | 0:4c9b6e0bb8d5 | 37 | ipe[mode][2][0],ipe[mode][2][1],ipe[mode][2][2], |
_muki | 0:4c9b6e0bb8d5 | 38 | ipe[mode][3][0],ipe[mode][3][1],ipe[mode][3][2]); |
_muki | 0:4c9b6e0bb8d5 | 39 | |
_muki | 0:4c9b6e0bb8d5 | 40 | }; |
_muki | 0:4c9b6e0bb8d5 | 41 | |
_muki | 0:4c9b6e0bb8d5 | 42 | |
_muki | 0:4c9b6e0bb8d5 | 43 | void edit(){ |
_muki | 0:4c9b6e0bb8d5 | 44 | int ipe[4][4][3]= |
_muki | 0:4c9b6e0bb8d5 | 45 | {{{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, |
_muki | 0:4c9b6e0bb8d5 | 46 | {{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, |
_muki | 0:4c9b6e0bb8d5 | 47 | {{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, |
_muki | 0:4c9b6e0bb8d5 | 48 | {{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; |
_muki | 0:4c9b6e0bb8d5 | 49 | // ipe[mode][i][j]; |
_muki | 0:4c9b6e0bb8d5 | 50 | |
_muki | 0:4c9b6e0bb8d5 | 51 | int ip[4][4]={0,0,0,0}; |
_muki | 0:4c9b6e0bb8d5 | 52 | int mono=0, keta=0; |
_muki | 0:4c9b6e0bb8d5 | 53 | int mode = 0; // 0:IP Adress, 1:NetMask, 2: Gateway, 3:DNS |
_muki | 0:4c9b6e0bb8d5 | 54 | char address[4][16]; // address[mode][Address] |
_muki | 0:4c9b6e0bb8d5 | 55 | char word[4][16] = {"IP Address","NetMask", "Gateway", "Domain Name"}; |
_muki | 0:4c9b6e0bb8d5 | 56 | |
_muki | 0:4c9b6e0bb8d5 | 57 | lcd.locate(0,0); |
_muki | 0:4c9b6e0bb8d5 | 58 | lcd.printf("%d %s",mode,word[mode]); |
_muki | 0:4c9b6e0bb8d5 | 59 | |
_muki | 0:4c9b6e0bb8d5 | 60 | while(mode < 4){ /*edit Address*/ |
_muki | 0:4c9b6e0bb8d5 | 61 | ipe_print(ipe,mode); |
_muki | 0:4c9b6e0bb8d5 | 62 | |
_muki | 0:4c9b6e0bb8d5 | 63 | /* ----Settei Key -----*/ |
_muki | 0:4c9b6e0bb8d5 | 64 | if((Setkey == 0 )&& (port20.state==1)){ |
_muki | 0:4c9b6e0bb8d5 | 65 | lcd.locate(14,0); |
_muki | 0:4c9b6e0bb8d5 | 66 | lcd.printf("S"); |
_muki | 0:4c9b6e0bb8d5 | 67 | |
_muki | 0:4c9b6e0bb8d5 | 68 | port20.state = 0; |
_muki | 0:4c9b6e0bb8d5 | 69 | mode = mode + 1; |
_muki | 0:4c9b6e0bb8d5 | 70 | if(mode >= 4){ |
_muki | 0:4c9b6e0bb8d5 | 71 | lcd.locate(0,0);// lcd.printf("%s",address[mode]); |
_muki | 0:4c9b6e0bb8d5 | 72 | lcd.printf("edited\n"); |
_muki | 0:4c9b6e0bb8d5 | 73 | break; |
_muki | 0:4c9b6e0bb8d5 | 74 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 75 | |
_muki | 0:4c9b6e0bb8d5 | 76 | lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 77 | lcd.locate(0,0);// lcd.printf("%s",address[mode]); |
_muki | 0:4c9b6e0bb8d5 | 78 | lcd.printf("%d %s",mode,word[mode]); |
_muki | 0:4c9b6e0bb8d5 | 79 | |
_muki | 0:4c9b6e0bb8d5 | 80 | }else if((Setkey == 1 )&& (port20.state == 0)){ |
_muki | 0:4c9b6e0bb8d5 | 81 | port20.state = 1; |
_muki | 0:4c9b6e0bb8d5 | 82 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 83 | |
_muki | 0:4c9b6e0bb8d5 | 84 | /* ----Right Key -----*/ |
_muki | 0:4c9b6e0bb8d5 | 85 | if((Rightkey == 0 )&& (port16.state== 1)){ |
_muki | 0:4c9b6e0bb8d5 | 86 | port16.state = 0; |
_muki | 0:4c9b6e0bb8d5 | 87 | keta = keta+1; |
_muki | 0:4c9b6e0bb8d5 | 88 | if( keta >= 3){ |
_muki | 0:4c9b6e0bb8d5 | 89 | keta = 0; |
_muki | 0:4c9b6e0bb8d5 | 90 | mono = mono+1; |
_muki | 0:4c9b6e0bb8d5 | 91 | if( mono = 4 ){ |
_muki | 0:4c9b6e0bb8d5 | 92 | mono = 0; |
_muki | 0:4c9b6e0bb8d5 | 93 | }else{ //i == 0, 1, 2, 3 |
_muki | 0:4c9b6e0bb8d5 | 94 | ; |
_muki | 0:4c9b6e0bb8d5 | 95 | } |
_muki | 0:4c9b6e0bb8d5 | 96 | }else{ // j == 0, 1, 2; |
_muki | 0:4c9b6e0bb8d5 | 97 | ; |
_muki | 0:4c9b6e0bb8d5 | 98 | } |
_muki | 0:4c9b6e0bb8d5 | 99 | /* debug */ |
_muki | 0:4c9b6e0bb8d5 | 100 | lcd.locate(15,0); |
_muki | 0:4c9b6e0bb8d5 | 101 | lcd.printf("R"); |
_muki | 0:4c9b6e0bb8d5 | 102 | lcd.locate(13,0); |
_muki | 0:4c9b6e0bb8d5 | 103 | lcd.printf("%d%d",mono, keta); |
_muki | 0:4c9b6e0bb8d5 | 104 | }else if((Rightkey == 1) && (port16.state == 0)){ |
_muki | 0:4c9b6e0bb8d5 | 105 | port16.state = 1; |
_muki | 0:4c9b6e0bb8d5 | 106 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 107 | |
_muki | 0:4c9b6e0bb8d5 | 108 | /* ----Left Key -----*/ |
_muki | 0:4c9b6e0bb8d5 | 109 | if((Leftkey == 0) && (port19.state==1)){ |
_muki | 0:4c9b6e0bb8d5 | 110 | |
_muki | 0:4c9b6e0bb8d5 | 111 | port19.state = 0; |
_muki | 0:4c9b6e0bb8d5 | 112 | keta = keta - 1; |
_muki | 0:4c9b6e0bb8d5 | 113 | if( keta < 0){ // j== 0, 1, 2; |
_muki | 0:4c9b6e0bb8d5 | 114 | keta = 2; |
_muki | 0:4c9b6e0bb8d5 | 115 | mono = mono - 1; |
_muki | 0:4c9b6e0bb8d5 | 116 | if( mono < 0 ){ // i == 0, 1, 2, 3 |
_muki | 0:4c9b6e0bb8d5 | 117 | mono = 3; |
_muki | 0:4c9b6e0bb8d5 | 118 | }else{ |
_muki | 0:4c9b6e0bb8d5 | 119 | ; |
_muki | 0:4c9b6e0bb8d5 | 120 | } |
_muki | 0:4c9b6e0bb8d5 | 121 | }else{ |
_muki | 0:4c9b6e0bb8d5 | 122 | ; |
_muki | 0:4c9b6e0bb8d5 | 123 | } |
_muki | 0:4c9b6e0bb8d5 | 124 | /* debug */ |
_muki | 0:4c9b6e0bb8d5 | 125 | lcd.locate(15,0); |
_muki | 0:4c9b6e0bb8d5 | 126 | lcd.printf("L"); |
_muki | 0:4c9b6e0bb8d5 | 127 | lcd.locate(13,0); |
_muki | 0:4c9b6e0bb8d5 | 128 | lcd.printf("%d%d",mono,keta); |
_muki | 0:4c9b6e0bb8d5 | 129 | |
_muki | 0:4c9b6e0bb8d5 | 130 | }else if((Leftkey == 1 )&& (port19.state == 0)){ |
_muki | 0:4c9b6e0bb8d5 | 131 | port19.state = 1; |
_muki | 0:4c9b6e0bb8d5 | 132 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 133 | |
_muki | 0:4c9b6e0bb8d5 | 134 | /* ----Down Key -----*/ |
_muki | 0:4c9b6e0bb8d5 | 135 | if((Downkey == 0) && (port18.state==1)){ |
_muki | 0:4c9b6e0bb8d5 | 136 | port18.state = 0; |
_muki | 0:4c9b6e0bb8d5 | 137 | ipe[mode][mono][keta] = ipe[mode][mono][keta]-1; |
_muki | 0:4c9b6e0bb8d5 | 138 | if(ipe[mode][mono][keta] < 0){ |
_muki | 0:4c9b6e0bb8d5 | 139 | ipe[mode][mono][keta] = 9; |
_muki | 0:4c9b6e0bb8d5 | 140 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 141 | /* debug */ |
_muki | 0:4c9b6e0bb8d5 | 142 | lcd.locate(15,0); |
_muki | 0:4c9b6e0bb8d5 | 143 | lcd.printf("D"); |
_muki | 0:4c9b6e0bb8d5 | 144 | lcd.locate(13,0); |
_muki | 0:4c9b6e0bb8d5 | 145 | lcd.printf("%d ",ipe[mode][mono][keta]); |
_muki | 0:4c9b6e0bb8d5 | 146 | }else if((Downkey == 1 )&& (port18.state == 0)){ |
_muki | 0:4c9b6e0bb8d5 | 147 | port18.state = 1; |
_muki | 0:4c9b6e0bb8d5 | 148 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 149 | |
_muki | 0:4c9b6e0bb8d5 | 150 | /* ----Upper Key -----*/ |
_muki | 0:4c9b6e0bb8d5 | 151 | if((Upperkey == 0 )&& (port17.state==1)){ |
_muki | 0:4c9b6e0bb8d5 | 152 | port17.state = 0; |
_muki | 0:4c9b6e0bb8d5 | 153 | ipe[mode][mono][keta] = ipe[mode][mono][keta]+1; |
_muki | 0:4c9b6e0bb8d5 | 154 | if(ipe[mode][mono][keta] > 9){ |
_muki | 0:4c9b6e0bb8d5 | 155 | ipe[mode][mono][keta] = 0; |
_muki | 0:4c9b6e0bb8d5 | 156 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 157 | /* debug */ |
_muki | 0:4c9b6e0bb8d5 | 158 | lcd.locate(15,0); |
_muki | 0:4c9b6e0bb8d5 | 159 | lcd.printf("U"); |
_muki | 0:4c9b6e0bb8d5 | 160 | lcd.locate(13,0); |
_muki | 0:4c9b6e0bb8d5 | 161 | lcd.printf("%d ",ipe[mode][mono][keta]); |
_muki | 0:4c9b6e0bb8d5 | 162 | |
_muki | 0:4c9b6e0bb8d5 | 163 | |
_muki | 0:4c9b6e0bb8d5 | 164 | }else if((Upperkey == 1) && (port17.state == 0)){ |
_muki | 0:4c9b6e0bb8d5 | 165 | port17.state = 1; |
_muki | 0:4c9b6e0bb8d5 | 166 | }else{;} |
_muki | 0:4c9b6e0bb8d5 | 167 | |
_muki | 0:4c9b6e0bb8d5 | 168 | // lcd.locate(1,0); lcd.printf("%d.%d.%d.%d", ip[0],ip[1],ip[2],ip[3]); |
_muki | 0:4c9b6e0bb8d5 | 169 | |
_muki | 0:4c9b6e0bb8d5 | 170 | |
_muki | 0:4c9b6e0bb8d5 | 171 | |
_muki | 0:4c9b6e0bb8d5 | 172 | for(mono=0; mono<4; mono++){ |
_muki | 0:4c9b6e0bb8d5 | 173 | ip[mode][mono] = 100*ipe[mode][mono][0] + 10*ipe[mode][mono][1] + ipe[mode][mono][2]; |
_muki | 0:4c9b6e0bb8d5 | 174 | } |
_muki | 0:4c9b6e0bb8d5 | 175 | sprintf(address[mode],"%3d.%3d.%3d.%3d", ip[mode][0],ip[mode][1],ip[mode][2],ip[mode][3]); |
_muki | 0:4c9b6e0bb8d5 | 176 | // lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 177 | // lcd.locate(0,0); lcd.printf("%s",address[mode]); |
_muki | 0:4c9b6e0bb8d5 | 178 | // lcd.printf("%s\n",word[mode]); |
_muki | 0:4c9b6e0bb8d5 | 179 | |
_muki | 0:4c9b6e0bb8d5 | 180 | |
_muki | 0:4c9b6e0bb8d5 | 181 | wait(0.2); |
_muki | 0:4c9b6e0bb8d5 | 182 | } |
_muki | 0:4c9b6e0bb8d5 | 183 | |
_muki | 0:4c9b6e0bb8d5 | 184 | // config_write(); |
_muki | 0:4c9b6e0bb8d5 | 185 | lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 186 | // return 0; |
_muki | 0:4c9b6e0bb8d5 | 187 | } |
_muki | 0:4c9b6e0bb8d5 | 188 | |
_muki | 0:4c9b6e0bb8d5 | 189 | /* |
_muki | 0:4c9b6e0bb8d5 | 190 | int config_write(int *IP[4], int *NM[4], int *GW[4], int *NS[4]){ |
_muki | 0:4c9b6e0bb8d5 | 191 | FILE *conf_fp; |
_muki | 0:4c9b6e0bb8d5 | 192 | char buf[80], name[16]; |
_muki | 0:4c9b6e0bb8d5 | 193 | int ip0, ip1, ip2, ip3; |
_muki | 0:4c9b6e0bb8d5 | 194 | |
_muki | 0:4c9b6e0bb8d5 | 195 | conf_fp = fopen("/local/ipconfig.txt","w"); |
_muki | 0:4c9b6e0bb8d5 | 196 | if(NULL == conf_fp){ |
_muki | 0:4c9b6e0bb8d5 | 197 | //printf("\r\nError: The message file cannot be accessed\r\n"); |
_muki | 0:4c9b6e0bb8d5 | 198 | lcd.printf("File access error"); |
_muki | 0:4c9b6e0bb8d5 | 199 | return -1; |
_muki | 0:4c9b6e0bb8d5 | 200 | } |
_muki | 0:4c9b6e0bb8d5 | 201 | |
_muki | 0:4c9b6e0bb8d5 | 202 | fclose(conf_fp); r |
_muki | 0:4c9b6e0bb8d5 | 203 | return 0; |
_muki | 0:4c9b6e0bb8d5 | 204 | } |
_muki | 0:4c9b6e0bb8d5 | 205 | */ |
_muki | 0:4c9b6e0bb8d5 | 206 | |
_muki | 0:4c9b6e0bb8d5 | 207 | |
_muki | 0:4c9b6e0bb8d5 | 208 | int config_read(){ |
_muki | 0:4c9b6e0bb8d5 | 209 | FILE *conf_fp; |
_muki | 0:4c9b6e0bb8d5 | 210 | char buf[80], name[16]; |
_muki | 0:4c9b6e0bb8d5 | 211 | int ip0, ip1, ip2, ip3; |
_muki | 0:4c9b6e0bb8d5 | 212 | |
_muki | 0:4c9b6e0bb8d5 | 213 | conf_fp = fopen("/local/ipconfig.txt","r"); |
_muki | 0:4c9b6e0bb8d5 | 214 | if(NULL == conf_fp){ |
_muki | 0:4c9b6e0bb8d5 | 215 | //printf("\r\nError: The message file cannot be accessed\r\n"); |
_muki | 0:4c9b6e0bb8d5 | 216 | lcd.printf("File access error"); |
_muki | 0:4c9b6e0bb8d5 | 217 | return -1; |
_muki | 0:4c9b6e0bb8d5 | 218 | } |
_muki | 0:4c9b6e0bb8d5 | 219 | |
_muki | 0:4c9b6e0bb8d5 | 220 | while( fgets(buf,sizeof(buf),conf_fp) != NULL){ |
_muki | 0:4c9b6e0bb8d5 | 221 | lcd.cls(); //debug |
_muki | 0:4c9b6e0bb8d5 | 222 | //lcd.locate(0,0);lcd.printf("%s\n",buf); // debug |
_muki | 0:4c9b6e0bb8d5 | 223 | if(sscanf(buf, "%s %d,%d,%d,%d", name, &ip0, &ip1, &ip2, &ip3) != 0){ |
_muki | 0:4c9b6e0bb8d5 | 224 | //lcd.locate(0,0); |
_muki | 0:4c9b6e0bb8d5 | 225 | //lcd.printf("%s\n%3d,%3d,%3d,%3d", name, ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 226 | }else{ |
_muki | 0:4c9b6e0bb8d5 | 227 | lcd.printf("error..."); |
_muki | 0:4c9b6e0bb8d5 | 228 | return -1; |
_muki | 0:4c9b6e0bb8d5 | 229 | } |
_muki | 0:4c9b6e0bb8d5 | 230 | |
_muki | 0:4c9b6e0bb8d5 | 231 | if(strcmp(name,"IPAddress")==0){ |
_muki | 0:4c9b6e0bb8d5 | 232 | lcd.printf("IP Address\n"); |
_muki | 0:4c9b6e0bb8d5 | 233 | lcd.printf("%d.%d.%d.%d",ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 234 | ipaddr = IpAddr(ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 235 | |
_muki | 0:4c9b6e0bb8d5 | 236 | } |
_muki | 0:4c9b6e0bb8d5 | 237 | if(strcmp(name,"NetworkMask")==0){ |
_muki | 0:4c9b6e0bb8d5 | 238 | lcd.printf("NetworkMask\n"); |
_muki | 0:4c9b6e0bb8d5 | 239 | lcd.printf("%d.%d.%d.%d",ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 240 | netmask = IpAddr(ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 241 | } |
_muki | 0:4c9b6e0bb8d5 | 242 | if(strcmp(name,"Gateway")==0){ |
_muki | 0:4c9b6e0bb8d5 | 243 | lcd.printf("Gateway\n"); |
_muki | 0:4c9b6e0bb8d5 | 244 | lcd.printf("%d.%d.%d.%d",ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 245 | gateway = IpAddr(ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 246 | } |
_muki | 0:4c9b6e0bb8d5 | 247 | if(strcmp(name,"DNS")==0){ |
_muki | 0:4c9b6e0bb8d5 | 248 | lcd.printf("Domain Name\n"); |
_muki | 0:4c9b6e0bb8d5 | 249 | lcd.printf("%d.%d.%d.%d",ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 250 | nameserver = IpAddr(ip0, ip1, ip2, ip3); |
_muki | 0:4c9b6e0bb8d5 | 251 | } |
_muki | 0:4c9b6e0bb8d5 | 252 | wait(3); |
_muki | 0:4c9b6e0bb8d5 | 253 | }; |
_muki | 0:4c9b6e0bb8d5 | 254 | |
_muki | 0:4c9b6e0bb8d5 | 255 | fclose(conf_fp); |
_muki | 0:4c9b6e0bb8d5 | 256 | return 0; |
_muki | 0:4c9b6e0bb8d5 | 257 | } |
_muki | 0:4c9b6e0bb8d5 | 258 | |
_muki | 0:4c9b6e0bb8d5 | 259 | |
_muki | 0:4c9b6e0bb8d5 | 260 | int setup(){ |
_muki | 0:4c9b6e0bb8d5 | 261 | if (ipaddr[0] == 255) { |
_muki | 0:4c9b6e0bb8d5 | 262 | // dhcp ip address |
_muki | 0:4c9b6e0bb8d5 | 263 | eth = new EthernetNetIf; |
_muki | 0:4c9b6e0bb8d5 | 264 | } else { |
_muki | 0:4c9b6e0bb8d5 | 265 | // static ip address |
_muki | 0:4c9b6e0bb8d5 | 266 | eth = new EthernetNetIf(ipaddr, netmask, gateway, nameserver); |
_muki | 0:4c9b6e0bb8d5 | 267 | } |
_muki | 0:4c9b6e0bb8d5 | 268 | |
_muki | 0:4c9b6e0bb8d5 | 269 | EthernetErr ethErr = eth->setup(); |
_muki | 0:4c9b6e0bb8d5 | 270 | |
_muki | 0:4c9b6e0bb8d5 | 271 | if(ethErr){ |
_muki | 0:4c9b6e0bb8d5 | 272 | lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 273 | lcd.printf("Error %d in setup.", ethErr); |
_muki | 0:4c9b6e0bb8d5 | 274 | return -1; |
_muki | 0:4c9b6e0bb8d5 | 275 | } |
_muki | 0:4c9b6e0bb8d5 | 276 | |
_muki | 0:4c9b6e0bb8d5 | 277 | return 0; |
_muki | 0:4c9b6e0bb8d5 | 278 | } |
_muki | 0:4c9b6e0bb8d5 | 279 | |
_muki | 0:4c9b6e0bb8d5 | 280 | int test(){ |
_muki | 0:4c9b6e0bb8d5 | 281 | led2 = 1; |
_muki | 0:4c9b6e0bb8d5 | 282 | return 0; |
_muki | 0:4c9b6e0bb8d5 | 283 | } |
_muki | 0:4c9b6e0bb8d5 | 284 | |
_muki | 0:4c9b6e0bb8d5 | 285 | |
_muki | 0:4c9b6e0bb8d5 | 286 | int main() { |
_muki | 0:4c9b6e0bb8d5 | 287 | int i=0; |
_muki | 0:4c9b6e0bb8d5 | 288 | |
_muki | 0:4c9b6e0bb8d5 | 289 | lcd.printf("Setting up..."); |
_muki | 0:4c9b6e0bb8d5 | 290 | config_read(); |
_muki | 0:4c9b6e0bb8d5 | 291 | if(setup() != 0){ |
_muki | 0:4c9b6e0bb8d5 | 292 | return -1; |
_muki | 0:4c9b6e0bb8d5 | 293 | } |
_muki | 0:4c9b6e0bb8d5 | 294 | |
_muki | 0:4c9b6e0bb8d5 | 295 | |
_muki | 0:4c9b6e0bb8d5 | 296 | lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 297 | lcd.printf("Setup OK"); |
_muki | 0:4c9b6e0bb8d5 | 298 | |
_muki | 0:4c9b6e0bb8d5 | 299 | IpAddr ip = eth->getIp() ; |
_muki | 0:4c9b6e0bb8d5 | 300 | |
_muki | 0:4c9b6e0bb8d5 | 301 | lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 302 | lcd.printf("IP Address\n"); |
_muki | 0:4c9b6e0bb8d5 | 303 | lcd.printf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); |
_muki | 0:4c9b6e0bb8d5 | 304 | // wait(5); |
_muki | 0:4c9b6e0bb8d5 | 305 | |
_muki | 0:4c9b6e0bb8d5 | 306 | // Timer tm; |
_muki | 0:4c9b6e0bb8d5 | 307 | // tm.start(); |
_muki | 0:4c9b6e0bb8d5 | 308 | |
_muki | 0:4c9b6e0bb8d5 | 309 | |
_muki | 0:4c9b6e0bb8d5 | 310 | //Listen indefinitely |
_muki | 0:4c9b6e0bb8d5 | 311 | while(true){ |
_muki | 0:4c9b6e0bb8d5 | 312 | |
_muki | 0:4c9b6e0bb8d5 | 313 | Net::poll(); |
_muki | 0:4c9b6e0bb8d5 | 314 | //if(tm.read()>.5){ |
_muki | 0:4c9b6e0bb8d5 | 315 | |
_muki | 0:4c9b6e0bb8d5 | 316 | |
_muki | 0:4c9b6e0bb8d5 | 317 | if(i>5){ |
_muki | 0:4c9b6e0bb8d5 | 318 | led1=!led1; //Show that we are alive |
_muki | 0:4c9b6e0bb8d5 | 319 | i=0; |
_muki | 0:4c9b6e0bb8d5 | 320 | }else{ |
_muki | 0:4c9b6e0bb8d5 | 321 | i++; |
_muki | 0:4c9b6e0bb8d5 | 322 | } |
_muki | 0:4c9b6e0bb8d5 | 323 | // lcd.printf("main loop\n"); |
_muki | 0:4c9b6e0bb8d5 | 324 | |
_muki | 0:4c9b6e0bb8d5 | 325 | |
_muki | 0:4c9b6e0bb8d5 | 326 | if(Setkey == 0 && port20.state==1){ |
_muki | 0:4c9b6e0bb8d5 | 327 | port20.state = 0; |
_muki | 0:4c9b6e0bb8d5 | 328 | test(); |
_muki | 0:4c9b6e0bb8d5 | 329 | |
_muki | 0:4c9b6e0bb8d5 | 330 | // led2 = !led2; |
_muki | 0:4c9b6e0bb8d5 | 331 | edit(); |
_muki | 0:4c9b6e0bb8d5 | 332 | |
_muki | 0:4c9b6e0bb8d5 | 333 | lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 334 | lcd.printf("IP Address\n"); |
_muki | 0:4c9b6e0bb8d5 | 335 | //lcd.printf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); |
_muki | 0:4c9b6e0bb8d5 | 336 | //lcd.printf("main loop\n"); |
_muki | 0:4c9b6e0bb8d5 | 337 | lcd.printf("%3d.%3d.%3d.%3d.", ip[0], ip[1], ip[2], ip[3]); |
_muki | 0:4c9b6e0bb8d5 | 338 | |
_muki | 0:4c9b6e0bb8d5 | 339 | /* if((config_read() != 0) && (setup() !=0)){ |
_muki | 0:4c9b6e0bb8d5 | 340 | return -1; |
_muki | 0:4c9b6e0bb8d5 | 341 | } |
_muki | 0:4c9b6e0bb8d5 | 342 | IpAddr ip = eth->getIp() ; |
_muki | 0:4c9b6e0bb8d5 | 343 | */ |
_muki | 0:4c9b6e0bb8d5 | 344 | }else if(Setkey == 1 && port20.state == 0){ |
_muki | 0:4c9b6e0bb8d5 | 345 | port20.state = 1; |
_muki | 0:4c9b6e0bb8d5 | 346 | led2 = 0; |
_muki | 0:4c9b6e0bb8d5 | 347 | }else if(Setkey == 0 && port20.state == 0){ // state == 0 |
_muki | 0:4c9b6e0bb8d5 | 348 | // led2 = !led2; |
_muki | 0:4c9b6e0bb8d5 | 349 | }else{ //Setkey ==1 && state == 1 |
_muki | 0:4c9b6e0bb8d5 | 350 | // led2 = !led2; |
_muki | 0:4c9b6e0bb8d5 | 351 | } |
_muki | 0:4c9b6e0bb8d5 | 352 | // tm.start(); |
_muki | 0:4c9b6e0bb8d5 | 353 | // } |
_muki | 0:4c9b6e0bb8d5 | 354 | wait(0.1); |
_muki | 0:4c9b6e0bb8d5 | 355 | } |
_muki | 0:4c9b6e0bb8d5 | 356 | |
_muki | 0:4c9b6e0bb8d5 | 357 | lcd.cls(); |
_muki | 0:4c9b6e0bb8d5 | 358 | lcd.printf("bye!"); |
_muki | 0:4c9b6e0bb8d5 | 359 | return 0; |
_muki | 0:4c9b6e0bb8d5 | 360 | } |