![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
newest
Dependencies: BME280 BMP280 TextLCD mbed
Fork of CW_watchdog_08012018 by
putty.h@0:7023c3f98f36, 2018-01-06 (annotated)
- Committer:
- ckalintra
- Date:
- Sat Jan 06 17:28:05 2018 +0000
- Revision:
- 0:7023c3f98f36
- Child:
- 1:dc21a6fce3af
code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ckalintra | 0:7023c3f98f36 | 1 | #include "mbed.h" |
ckalintra | 0:7023c3f98f36 | 2 | #include "data.h" |
ckalintra | 0:7023c3f98f36 | 3 | Serial pc(USBTX, USBRX); |
ckalintra | 0:7023c3f98f36 | 4 | char user_command[40] = {0}; |
ckalintra | 0:7023c3f98f36 | 5 | char user_command2[40] = {0}; |
ckalintra | 0:7023c3f98f36 | 6 | int n, datan = 0, datac = 0, counterd = 0, dates, times, interrupt = 0; |
ckalintra | 0:7023c3f98f36 | 7 | float t; |
ckalintra | 0:7023c3f98f36 | 8 | |
ckalintra | 0:7023c3f98f36 | 9 | |
ckalintra | 0:7023c3f98f36 | 10 | void readall() |
ckalintra | 0:7023c3f98f36 | 11 | { |
ckalintra | 0:7023c3f98f36 | 12 | datan = counterw; |
ckalintra | 0:7023c3f98f36 | 13 | pc.printf("readall selected\n\r"); |
ckalintra | 0:7023c3f98f36 | 14 | if (full == 1) |
ckalintra | 0:7023c3f98f36 | 15 | { |
ckalintra | 0:7023c3f98f36 | 16 | datac = 120; |
ckalintra | 0:7023c3f98f36 | 17 | } |
ckalintra | 0:7023c3f98f36 | 18 | else |
ckalintra | 0:7023c3f98f36 | 19 | { |
ckalintra | 0:7023c3f98f36 | 20 | datac = counterw; |
ckalintra | 0:7023c3f98f36 | 21 | } |
ckalintra | 0:7023c3f98f36 | 22 | pc.printf("printting %i datas\n\r", datac); |
ckalintra | 0:7023c3f98f36 | 23 | while (counterd < datac) |
ckalintra | 0:7023c3f98f36 | 24 | { |
ckalintra | 0:7023c3f98f36 | 25 | pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r", data_light[datan], data_temp [datan], data_press[datan]); |
ckalintra | 0:7023c3f98f36 | 26 | if (datan == 0) |
ckalintra | 0:7023c3f98f36 | 27 | { |
ckalintra | 0:7023c3f98f36 | 28 | datan = 121; |
ckalintra | 0:7023c3f98f36 | 29 | } |
ckalintra | 0:7023c3f98f36 | 30 | datan--; |
ckalintra | 0:7023c3f98f36 | 31 | counterd++; |
ckalintra | 0:7023c3f98f36 | 32 | } |
ckalintra | 0:7023c3f98f36 | 33 | counterd = 0; |
ckalintra | 0:7023c3f98f36 | 34 | } |
ckalintra | 0:7023c3f98f36 | 35 | |
ckalintra | 0:7023c3f98f36 | 36 | void readn() |
ckalintra | 0:7023c3f98f36 | 37 | { |
ckalintra | 0:7023c3f98f36 | 38 | |
ckalintra | 0:7023c3f98f36 | 39 | counterd = 0; |
ckalintra | 0:7023c3f98f36 | 40 | n = atoi(user_command2); |
ckalintra | 0:7023c3f98f36 | 41 | pc.printf("read %i datas\n\r",n); |
ckalintra | 0:7023c3f98f36 | 42 | if (n > counterw) |
ckalintra | 0:7023c3f98f36 | 43 | { |
ckalintra | 0:7023c3f98f36 | 44 | pc.printf("we only have %i datas \n\r", counterw); |
ckalintra | 0:7023c3f98f36 | 45 | } |
ckalintra | 0:7023c3f98f36 | 46 | else |
ckalintra | 0:7023c3f98f36 | 47 | { |
ckalintra | 0:7023c3f98f36 | 48 | while (counterd < n) |
ckalintra | 0:7023c3f98f36 | 49 | { |
ckalintra | 0:7023c3f98f36 | 50 | pc.printf("light: %2.4f, temp: %3.4f, press: %3.4f\n\r",data_light[datan], data_temp [datan], data_press[datan]); |
ckalintra | 0:7023c3f98f36 | 51 | if (datan == 0) |
ckalintra | 0:7023c3f98f36 | 52 | { |
ckalintra | 0:7023c3f98f36 | 53 | datan = 121; |
ckalintra | 0:7023c3f98f36 | 54 | } |
ckalintra | 0:7023c3f98f36 | 55 | datan--; |
ckalintra | 0:7023c3f98f36 | 56 | counterd++; |
ckalintra | 0:7023c3f98f36 | 57 | } |
ckalintra | 0:7023c3f98f36 | 58 | } |
ckalintra | 0:7023c3f98f36 | 59 | } |
ckalintra | 0:7023c3f98f36 | 60 | |
ckalintra | 0:7023c3f98f36 | 61 | void deleteall() |
ckalintra | 0:7023c3f98f36 | 62 | { |
ckalintra | 0:7023c3f98f36 | 63 | pc.printf("deleted %i datas \n\r", counterw); |
ckalintra | 0:7023c3f98f36 | 64 | counterw = 0; |
ckalintra | 0:7023c3f98f36 | 65 | int counter = 0; |
ckalintra | 0:7023c3f98f36 | 66 | while (counter < 121) |
ckalintra | 0:7023c3f98f36 | 67 | { |
ckalintra | 0:7023c3f98f36 | 68 | data_light[counter] = 0; |
ckalintra | 0:7023c3f98f36 | 69 | data_temp [counter] = 0; |
ckalintra | 0:7023c3f98f36 | 70 | data_press[counter] = 0; |
ckalintra | 0:7023c3f98f36 | 71 | counter ++; |
ckalintra | 0:7023c3f98f36 | 72 | full = 0; |
ckalintra | 0:7023c3f98f36 | 73 | } |
ckalintra | 0:7023c3f98f36 | 74 | } |
ckalintra | 0:7023c3f98f36 | 75 | |
ckalintra | 0:7023c3f98f36 | 76 | void deleten() |
ckalintra | 0:7023c3f98f36 | 77 | { |
ckalintra | 0:7023c3f98f36 | 78 | datan = counterw; |
ckalintra | 0:7023c3f98f36 | 79 | counterd = 0; |
ckalintra | 0:7023c3f98f36 | 80 | n = atoi(user_command2); |
ckalintra | 0:7023c3f98f36 | 81 | if (n > counterw && full == 0) |
ckalintra | 0:7023c3f98f36 | 82 | { |
ckalintra | 0:7023c3f98f36 | 83 | pc.printf("we only have %i datas \n\r", counterw); |
ckalintra | 0:7023c3f98f36 | 84 | } |
ckalintra | 0:7023c3f98f36 | 85 | else if(full == 1 && n> 120) |
ckalintra | 0:7023c3f98f36 | 86 | { |
ckalintra | 0:7023c3f98f36 | 87 | pc.printf("we only have 120 datas \n\r"); |
ckalintra | 0:7023c3f98f36 | 88 | } |
ckalintra | 0:7023c3f98f36 | 89 | else if(full == 0 && n < counterw) |
ckalintra | 0:7023c3f98f36 | 90 | { |
ckalintra | 0:7023c3f98f36 | 91 | pc.printf("deleted %i datas \n\r", n); |
ckalintra | 0:7023c3f98f36 | 92 | counterw = counterw-n; |
ckalintra | 0:7023c3f98f36 | 93 | while (counterd < n) |
ckalintra | 0:7023c3f98f36 | 94 | { |
ckalintra | 0:7023c3f98f36 | 95 | data_light[datan] = 0; |
ckalintra | 0:7023c3f98f36 | 96 | data_temp [datan] = 0; |
ckalintra | 0:7023c3f98f36 | 97 | data_press[datan] = 0; |
ckalintra | 0:7023c3f98f36 | 98 | counterd ++; |
ckalintra | 0:7023c3f98f36 | 99 | datan--; |
ckalintra | 0:7023c3f98f36 | 100 | } |
ckalintra | 0:7023c3f98f36 | 101 | } |
ckalintra | 0:7023c3f98f36 | 102 | else if(full == 1 && n < 120) |
ckalintra | 0:7023c3f98f36 | 103 | { |
ckalintra | 0:7023c3f98f36 | 104 | pc.printf("deleted %i datas \n\r", n); |
ckalintra | 0:7023c3f98f36 | 105 | counterw = counterw-n; |
ckalintra | 0:7023c3f98f36 | 106 | while (counterd < 120) |
ckalintra | 0:7023c3f98f36 | 107 | { |
ckalintra | 0:7023c3f98f36 | 108 | data_light[datan] = 0; |
ckalintra | 0:7023c3f98f36 | 109 | data_temp [datan] = 0; |
ckalintra | 0:7023c3f98f36 | 110 | data_press[datan] = 0; |
ckalintra | 0:7023c3f98f36 | 111 | counterd ++; |
ckalintra | 0:7023c3f98f36 | 112 | datan--; |
ckalintra | 0:7023c3f98f36 | 113 | } |
ckalintra | 0:7023c3f98f36 | 114 | } |
ckalintra | 0:7023c3f98f36 | 115 | } |
ckalintra | 0:7023c3f98f36 | 116 | //void fill(char c[20], char c2[20]) |
ckalintra | 0:7023c3f98f36 | 117 | //{ |
ckalintra | 0:7023c3f98f36 | 118 | // int counterino = 0; |
ckalintra | 0:7023c3f98f36 | 119 | // while (counterino <21) |
ckalintra | 0:7023c3f98f36 | 120 | // { |
ckalintra | 0:7023c3f98f36 | 121 | // user_command[counterino] = c[counterino]; |
ckalintra | 0:7023c3f98f36 | 122 | // user_command2[counterino] = c2[counterino]; |
ckalintra | 0:7023c3f98f36 | 123 | // counterino++; |
ckalintra | 0:7023c3f98f36 | 124 | // } |
ckalintra | 0:7023c3f98f36 | 125 | |
ckalintra | 0:7023c3f98f36 | 126 | //} |
ckalintra | 0:7023c3f98f36 | 127 | void clear() |
ckalintra | 0:7023c3f98f36 | 128 | { |
ckalintra | 0:7023c3f98f36 | 129 | int counter = 0; |
ckalintra | 0:7023c3f98f36 | 130 | while (counter < 40) |
ckalintra | 0:7023c3f98f36 | 131 | { |
ckalintra | 0:7023c3f98f36 | 132 | user_command[counter] = 0; |
ckalintra | 0:7023c3f98f36 | 133 | counter ++; |
ckalintra | 0:7023c3f98f36 | 134 | } |
ckalintra | 0:7023c3f98f36 | 135 | } |
ckalintra | 0:7023c3f98f36 | 136 | |
ckalintra | 0:7023c3f98f36 | 137 | |
ckalintra | 0:7023c3f98f36 | 138 | void clear2() |
ckalintra | 0:7023c3f98f36 | 139 | { |
ckalintra | 0:7023c3f98f36 | 140 | int counter = 0; |
ckalintra | 0:7023c3f98f36 | 141 | while (counter < 40) |
ckalintra | 0:7023c3f98f36 | 142 | { |
ckalintra | 0:7023c3f98f36 | 143 | user_command2[counter] = 0; |
ckalintra | 0:7023c3f98f36 | 144 | counter ++; |
ckalintra | 0:7023c3f98f36 | 145 | } |
ckalintra | 0:7023c3f98f36 | 146 | } |
ckalintra | 0:7023c3f98f36 | 147 | |
ckalintra | 0:7023c3f98f36 | 148 | void selection() |
ckalintra | 0:7023c3f98f36 | 149 | { |
ckalintra | 0:7023c3f98f36 | 150 | counterd = 0; |
ckalintra | 0:7023c3f98f36 | 151 | datan = counterw-1; |
ckalintra | 0:7023c3f98f36 | 152 | if (user_command[0] == 'R'&& user_command[1] == 'E'&& user_command[2] == 'A'&& user_command[3] == 'D') |
ckalintra | 0:7023c3f98f36 | 153 | { |
ckalintra | 0:7023c3f98f36 | 154 | if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L') |
ckalintra | 0:7023c3f98f36 | 155 | { |
ckalintra | 0:7023c3f98f36 | 156 | readall(); |
ckalintra | 0:7023c3f98f36 | 157 | } |
ckalintra | 0:7023c3f98f36 | 158 | |
ckalintra | 0:7023c3f98f36 | 159 | else |
ckalintra | 0:7023c3f98f36 | 160 | { |
ckalintra | 0:7023c3f98f36 | 161 | readn(); |
ckalintra | 0:7023c3f98f36 | 162 | } |
ckalintra | 0:7023c3f98f36 | 163 | } |
ckalintra | 0:7023c3f98f36 | 164 | |
ckalintra | 0:7023c3f98f36 | 165 | else if (user_command[0] == 'D'&& user_command[1] == 'E'&& user_command[2] == 'L'&& user_command[3] == 'E' && user_command[4] == 'T' && user_command[5] == 'E') |
ckalintra | 0:7023c3f98f36 | 166 | { |
ckalintra | 0:7023c3f98f36 | 167 | if (user_command2[0] == 'A'&& user_command2[1]== 'L'&& user_command2[2]== 'L') |
ckalintra | 0:7023c3f98f36 | 168 | { |
ckalintra | 0:7023c3f98f36 | 169 | pc.printf("deleteall selected\n\r"); |
ckalintra | 0:7023c3f98f36 | 170 | deleteall(); |
ckalintra | 0:7023c3f98f36 | 171 | } |
ckalintra | 0:7023c3f98f36 | 172 | |
ckalintra | 0:7023c3f98f36 | 173 | else |
ckalintra | 0:7023c3f98f36 | 174 | { |
ckalintra | 0:7023c3f98f36 | 175 | n = atoi(user_command2); |
ckalintra | 0:7023c3f98f36 | 176 | pc.printf("delete %i\n\r",n); |
ckalintra | 0:7023c3f98f36 | 177 | deleten(); |
ckalintra | 0:7023c3f98f36 | 178 | } |
ckalintra | 0:7023c3f98f36 | 179 | } |
ckalintra | 0:7023c3f98f36 | 180 | |
ckalintra | 0:7023c3f98f36 | 181 | else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'D' && user_command[4] == 'A' && user_command[5] == 'T' && user_command[6] == 'E') |
ckalintra | 0:7023c3f98f36 | 182 | { |
ckalintra | 0:7023c3f98f36 | 183 | dates = atoi(user_command2); |
ckalintra | 0:7023c3f98f36 | 184 | yyyy = dates%10; |
ckalintra | 0:7023c3f98f36 | 185 | dates /= 10; |
ckalintra | 0:7023c3f98f36 | 186 | yyy = dates%10; |
ckalintra | 0:7023c3f98f36 | 187 | dates /= 10; |
ckalintra | 0:7023c3f98f36 | 188 | yy = dates%10; |
ckalintra | 0:7023c3f98f36 | 189 | dates /= 10; |
ckalintra | 0:7023c3f98f36 | 190 | y = dates%10; |
ckalintra | 0:7023c3f98f36 | 191 | dates /= 10; |
ckalintra | 0:7023c3f98f36 | 192 | mm = dates%10; |
ckalintra | 0:7023c3f98f36 | 193 | dates /= 10; |
ckalintra | 0:7023c3f98f36 | 194 | m = dates%10; |
ckalintra | 0:7023c3f98f36 | 195 | dates /= 10; |
ckalintra | 0:7023c3f98f36 | 196 | dd = dates%10; |
ckalintra | 0:7023c3f98f36 | 197 | dates /= 10; |
ckalintra | 0:7023c3f98f36 | 198 | d = dates%10; |
ckalintra | 0:7023c3f98f36 | 199 | pc.printf("you set the date to %i%i/%i%i/%i%i%i%i\n\r", d,dd,m,mm,y,yy,yyy,yyyy); |
ckalintra | 0:7023c3f98f36 | 200 | } |
ckalintra | 0:7023c3f98f36 | 201 | else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T' && user_command[4] == 'I' && user_command[5] == 'M' && user_command[6] == 'E') |
ckalintra | 0:7023c3f98f36 | 202 | { |
ckalintra | 0:7023c3f98f36 | 203 | times = atoi(user_command2); |
ckalintra | 0:7023c3f98f36 | 204 | ss = times%10; |
ckalintra | 0:7023c3f98f36 | 205 | times /= 10; |
ckalintra | 0:7023c3f98f36 | 206 | s = times%10; |
ckalintra | 0:7023c3f98f36 | 207 | times /= 10; |
ckalintra | 0:7023c3f98f36 | 208 | mmi = times%10; |
ckalintra | 0:7023c3f98f36 | 209 | times /= 10; |
ckalintra | 0:7023c3f98f36 | 210 | mi = times%10; |
ckalintra | 0:7023c3f98f36 | 211 | times /= 10; |
ckalintra | 0:7023c3f98f36 | 212 | hh = times%10; |
ckalintra | 0:7023c3f98f36 | 213 | times /= 10; |
ckalintra | 0:7023c3f98f36 | 214 | h = times%10; |
ckalintra | 0:7023c3f98f36 | 215 | pc.printf("you set the time to %i%i:%i%i:%i%i\n\r", h,hh,mi,mmi,s,ss); |
ckalintra | 0:7023c3f98f36 | 216 | } |
ckalintra | 0:7023c3f98f36 | 217 | else if (user_command[0] == 'S'&& user_command[1] == 'E'&& user_command[2] == 'T'&& user_command[3] == 'T') |
ckalintra | 0:7023c3f98f36 | 218 | { |
ckalintra | 0:7023c3f98f36 | 219 | t = atof(user_command2); |
ckalintra | 0:7023c3f98f36 | 220 | pc.printf("you set the period to %2.2f", t); |
ckalintra | 0:7023c3f98f36 | 221 | interrupt = 1; |
ckalintra | 0:7023c3f98f36 | 222 | } |
ckalintra | 0:7023c3f98f36 | 223 | } |
ckalintra | 0:7023c3f98f36 | 224 | //int main() |
ckalintra | 0:7023c3f98f36 | 225 | //{ |
ckalintra | 0:7023c3f98f36 | 226 | // pc.printf("putty ready\n\r"); |
ckalintra | 0:7023c3f98f36 | 227 | // while(1) |
ckalintra | 0:7023c3f98f36 | 228 | // { |
ckalintra | 0:7023c3f98f36 | 229 | // clear(); |
ckalintra | 0:7023c3f98f36 | 230 | // clear2(); |
ckalintra | 0:7023c3f98f36 | 231 | // while (user_command[0] == 0) |
ckalintra | 0:7023c3f98f36 | 232 | // { |
ckalintra | 0:7023c3f98f36 | 233 | // pc.scanf("%s",user_command); |
ckalintra | 0:7023c3f98f36 | 234 | // pc.scanf("%s",user_command2); |
ckalintra | 0:7023c3f98f36 | 235 | // pc.printf("you typed: %s %s\n\r",user_command,user_command2); |
ckalintra | 0:7023c3f98f36 | 236 | // } |
ckalintra | 0:7023c3f98f36 | 237 | // |
ckalintra | 0:7023c3f98f36 | 238 | // selection(); |
ckalintra | 0:7023c3f98f36 | 239 | // } |
ckalintra | 0:7023c3f98f36 | 240 | //} |
ckalintra | 0:7023c3f98f36 | 241 | |
ckalintra | 0:7023c3f98f36 | 242 | |
ckalintra | 0:7023c3f98f36 | 243 | void putty_write () |
ckalintra | 0:7023c3f98f36 | 244 | { |
ckalintra | 0:7023c3f98f36 | 245 | int count = 0; |
ckalintra | 0:7023c3f98f36 | 246 | int wcount = 0; |
ckalintra | 0:7023c3f98f36 | 247 | while (user_command[wcount]!= ' ') |
ckalintra | 0:7023c3f98f36 | 248 | { |
ckalintra | 0:7023c3f98f36 | 249 | user_command[count] = pc.getc(); |
ckalintra | 0:7023c3f98f36 | 250 | pc.putc(user_command[count]); |
ckalintra | 0:7023c3f98f36 | 251 | count++; |
ckalintra | 0:7023c3f98f36 | 252 | wcount = count -1; |
ckalintra | 0:7023c3f98f36 | 253 | } |
ckalintra | 0:7023c3f98f36 | 254 | int count2 = 0; |
ckalintra | 0:7023c3f98f36 | 255 | int wcount2 = 0; |
ckalintra | 0:7023c3f98f36 | 256 | while(user_command2[wcount2]!= '\r') |
ckalintra | 0:7023c3f98f36 | 257 | { |
ckalintra | 0:7023c3f98f36 | 258 | user_command2[count2] = pc.getc(); |
ckalintra | 0:7023c3f98f36 | 259 | pc.putc(user_command2[count2]); |
ckalintra | 0:7023c3f98f36 | 260 | count2++; |
ckalintra | 0:7023c3f98f36 | 261 | wcount2 = count2 -1; |
ckalintra | 0:7023c3f98f36 | 262 | } |
ckalintra | 0:7023c3f98f36 | 263 | |
ckalintra | 0:7023c3f98f36 | 264 | |
ckalintra | 0:7023c3f98f36 | 265 | pc.printf("you typed: %s %s\n\r",user_command,user_command2); |
ckalintra | 0:7023c3f98f36 | 266 | selection(); |
ckalintra | 0:7023c3f98f36 | 267 | clear(); |
ckalintra | 0:7023c3f98f36 | 268 | clear2(); |
ckalintra | 0:7023c3f98f36 | 269 | |
ckalintra | 0:7023c3f98f36 | 270 | } |