4180 Final Project
Dependencies: 4DGL-uLCD-SE mbed Servo
main.cpp@25:2e95a5731412, 2016-04-28 (annotated)
- Committer:
- ecarrick
- Date:
- Thu Apr 28 19:26:59 2016 +0000
- Revision:
- 25:2e95a5731412
- Parent:
- 24:94e8b3e00c24
- Child:
- 26:f08205fa22d3
added log and wifi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pshabbaki3 | 0:5d35ff3dc9a5 | 1 | #include "mbed.h" |
ecarrick | 6:50a82641d07b | 2 | #include "wifi.h" |
pshabbaki3 | 0:5d35ff3dc9a5 | 3 | #include <string> |
pshabbaki3 | 0:5d35ff3dc9a5 | 4 | #include <vector> |
pshabbaki3 | 0:5d35ff3dc9a5 | 5 | #include <iostream> |
pshabbaki3 | 0:5d35ff3dc9a5 | 6 | #include <sstream> |
pshabbaki3 | 0:5d35ff3dc9a5 | 7 | #include <iterator> |
pshabbaki3 | 0:5d35ff3dc9a5 | 8 | #include <stdio.h> |
pshabbaki3 | 0:5d35ff3dc9a5 | 9 | #include <ctype.h> |
pshabbaki3 | 0:5d35ff3dc9a5 | 10 | #include "uLCD_4DGL.h" |
ecarrick | 25:2e95a5731412 | 11 | #include "Servo.h" |
pshabbaki3 | 0:5d35ff3dc9a5 | 12 | |
mbedTrent | 7:52b51f507ee5 | 13 | #include <list> |
mbedTrent | 7:52b51f507ee5 | 14 | #include <mpr121.h> |
mbedTrent | 7:52b51f507ee5 | 15 | |
ecarrick | 1:dd048edb2716 | 16 | LocalFileSystem local("local"); |
ecarrick | 25:2e95a5731412 | 17 | Servo lock(p25); // a pwm pin, 0 for unlocked; 1 for locked; |
pshabbaki3 | 0:5d35ff3dc9a5 | 18 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 19 | DigitalOut myled(LED1); |
ecarrick | 17:632c56db3c0a | 20 | DigitalOut ledr(p5); |
ecarrick | 17:632c56db3c0a | 21 | DigitalOut ledg(p6); |
ecarrick | 17:632c56db3c0a | 22 | DigitalOut ledb(p7); |
ecarrick | 17:632c56db3c0a | 23 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 24 | Serial pc(USBTX,USBRX); |
ecarrick | 16:fb2a50f0ecde | 25 | //uLCD_4DGL lcd(p28,p27,p30); // serial tx, serial rx, reset pin; |
pshabbaki3 | 0:5d35ff3dc9a5 | 26 | |
mbedTrent | 7:52b51f507ee5 | 27 | // Create the interrupt receiver object on pin 26 |
mbedTrent | 7:52b51f507ee5 | 28 | InterruptIn interrupt(p26); |
mbedTrent | 7:52b51f507ee5 | 29 | |
mbedTrent | 7:52b51f507ee5 | 30 | // Setup the i2c bus on pins 28 and 27 |
mbedTrent | 7:52b51f507ee5 | 31 | I2C i2c(p9, p10); |
mbedTrent | 7:52b51f507ee5 | 32 | |
mbedTrent | 7:52b51f507ee5 | 33 | // Setup the Mpr121: |
mbedTrent | 7:52b51f507ee5 | 34 | // constructor(i2c object, i2c address of the mpr121) |
mbedTrent | 7:52b51f507ee5 | 35 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
mbedTrent | 7:52b51f507ee5 | 36 | |
ecarrick | 25:2e95a5731412 | 37 | // log for web page |
ecarrick | 25:2e95a5731412 | 38 | vector<string> accessLog; |
ecarrick | 25:2e95a5731412 | 39 | unsigned logLength = 10; |
ecarrick | 25:2e95a5731412 | 40 | volatile bool updateAccessLog = false; |
ecarrick | 25:2e95a5731412 | 41 | |
ecarrick | 25:2e95a5731412 | 42 | // save to file flag |
ecarrick | 25:2e95a5731412 | 43 | volatile bool saveToFileFlag = false; |
ecarrick | 25:2e95a5731412 | 44 | volatile bool newData = false; |
ecarrick | 25:2e95a5731412 | 45 | |
ecarrick | 25:2e95a5731412 | 46 | // time |
ecarrick | 25:2e95a5731412 | 47 | time_t rtc; |
pshabbaki3 | 0:5d35ff3dc9a5 | 48 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 49 | vector<char> im; |
pshabbaki3 | 4:e6b198a22216 | 50 | vector<char> pass; |
pshabbaki3 | 0:5d35ff3dc9a5 | 51 | vector<char> name; |
pshabbaki3 | 0:5d35ff3dc9a5 | 52 | vector<char> final; |
pshabbaki3 | 11:1ca1f07896b0 | 53 | vector<char> ans; |
pshabbaki3 | 0:5d35ff3dc9a5 | 54 | |
ecarrick | 25:2e95a5731412 | 55 | string print_vector(vector<char>& vec){ |
ecarrick | 25:2e95a5731412 | 56 | string str; |
ecarrick | 25:2e95a5731412 | 57 | str.append(vec.begin(),vec.end()); |
ecarrick | 25:2e95a5731412 | 58 | return str; |
ecarrick | 25:2e95a5731412 | 59 | } |
ecarrick | 25:2e95a5731412 | 60 | |
mbedTrent | 10:cf127bd9b857 | 61 | vector<char> password; |
mbedTrent | 15:3d43fe8e108b | 62 | unsigned maxLength = 18; //random length chosen |
mbedTrent | 15:3d43fe8e108b | 63 | unsigned minLength = 6; //random length chosen |
mbedTrent | 10:cf127bd9b857 | 64 | |
ecarrick | 24:94e8b3e00c24 | 65 | void print_to_serial() |
ecarrick | 24:94e8b3e00c24 | 66 | { |
ecarrick | 24:94e8b3e00c24 | 67 | for(unsigned i=0; i< im.size(); i++) { |
ecarrick | 24:94e8b3e00c24 | 68 | pc.printf("%c",im[i]); |
ecarrick | 24:94e8b3e00c24 | 69 | } |
ecarrick | 24:94e8b3e00c24 | 70 | pc.printf("\r\n"); |
ecarrick | 24:94e8b3e00c24 | 71 | } |
pshabbaki3 | 12:22444d5f5920 | 72 | |
mbedTrent | 10:cf127bd9b857 | 73 | //function for debugging |
pshabbaki3 | 12:22444d5f5920 | 74 | void printPW() |
pshabbaki3 | 12:22444d5f5920 | 75 | { |
mbedTrent | 10:cf127bd9b857 | 76 | for (int i=0; i<password.size(); i++) { |
ecarrick | 24:94e8b3e00c24 | 77 | pc.printf("%c", password[i]); |
mbedTrent | 10:cf127bd9b857 | 78 | } |
mbedTrent | 10:cf127bd9b857 | 79 | pc.printf("\r\n"); |
mbedTrent | 10:cf127bd9b857 | 80 | } |
mbedTrent | 7:52b51f507ee5 | 81 | |
ecarrick | 25:2e95a5731412 | 82 | bool foundResult = false; |
ecarrick | 16:fb2a50f0ecde | 83 | void checkResult(vector<char> pass, vector<char> name) |
ecarrick | 16:fb2a50f0ecde | 84 | { |
ecarrick | 25:2e95a5731412 | 85 | /* |
ecarrick | 24:94e8b3e00c24 | 86 | for (int i=0; i<pass.size(); i++) { |
ecarrick | 24:94e8b3e00c24 | 87 | pc.printf("%d", int(pass[i])); |
ecarrick | 24:94e8b3e00c24 | 88 | } |
ecarrick | 25:2e95a5731412 | 89 | */ |
ecarrick | 25:2e95a5731412 | 90 | |
ecarrick | 25:2e95a5731412 | 91 | //pc.printf("\r\n"); |
ecarrick | 16:fb2a50f0ecde | 92 | // This function will check the keypad values and check if the passcode exists or not |
ecarrick | 16:fb2a50f0ecde | 93 | |
ecarrick | 16:fb2a50f0ecde | 94 | if (pass.size()==6) { |
ecarrick | 24:94e8b3e00c24 | 95 | if (password == pass) { |
ecarrick | 25:2e95a5731412 | 96 | //pc.printf("Found"); |
ecarrick | 16:fb2a50f0ecde | 97 | final = name; |
ecarrick | 16:fb2a50f0ecde | 98 | final.push_back(' '); |
ecarrick | 16:fb2a50f0ecde | 99 | final.insert(final.end(),pass.begin(),pass.end()); |
ecarrick | 25:2e95a5731412 | 100 | foundResult=true; |
ecarrick | 25:2e95a5731412 | 101 | ledb =0; |
ecarrick | 25:2e95a5731412 | 102 | ledr =0; |
ecarrick | 25:2e95a5731412 | 103 | ledg =1; |
ecarrick | 25:2e95a5731412 | 104 | lock = 0; |
ecarrick | 25:2e95a5731412 | 105 | //wait(0.01); |
ecarrick | 25:2e95a5731412 | 106 | //ledg =0; |
ecarrick | 16:fb2a50f0ecde | 107 | |
ecarrick | 16:fb2a50f0ecde | 108 | } else { |
ecarrick | 25:2e95a5731412 | 109 | //pc.printf("not found"); |
ecarrick | 16:fb2a50f0ecde | 110 | //lcd.printf("\nnot found\n"); |
ecarrick | 16:fb2a50f0ecde | 111 | final.clear(); |
ecarrick | 16:fb2a50f0ecde | 112 | } |
ecarrick | 16:fb2a50f0ecde | 113 | } |
ecarrick | 16:fb2a50f0ecde | 114 | } |
ecarrick | 16:fb2a50f0ecde | 115 | |
ecarrick | 16:fb2a50f0ecde | 116 | |
ecarrick | 16:fb2a50f0ecde | 117 | void checkKeyboard() |
ecarrick | 16:fb2a50f0ecde | 118 | { |
pshabbaki3 | 23:e23578000e42 | 119 | //load_from_file(); |
ecarrick | 25:2e95a5731412 | 120 | //pc.printf("CHECKING PASSWORD\n\r"); |
ecarrick | 25:2e95a5731412 | 121 | //pc.printf("\n\r"); |
pshabbaki3 | 19:6fce7b88de5e | 122 | bool colon = false; |
ecarrick | 25:2e95a5731412 | 123 | vector<char> empty; |
ecarrick | 25:2e95a5731412 | 124 | swap(empty, pass); |
ecarrick | 25:2e95a5731412 | 125 | vector<char> empty2; |
ecarrick | 25:2e95a5731412 | 126 | swap(empty2, name); |
ecarrick | 25:2e95a5731412 | 127 | //pass.clear(); |
ecarrick | 25:2e95a5731412 | 128 | //name.clear(); |
ecarrick | 16:fb2a50f0ecde | 129 | for (int i = 0; i<im.size(); i++) { |
pshabbaki3 | 19:6fce7b88de5e | 130 | |
ecarrick | 16:fb2a50f0ecde | 131 | // find space |
ecarrick | 16:fb2a50f0ecde | 132 | if (im[i] ==' ') { |
ecarrick | 16:fb2a50f0ecde | 133 | checkResult(pass,name); |
pshabbaki3 | 19:6fce7b88de5e | 134 | colon = false; |
ecarrick | 25:2e95a5731412 | 135 | if(foundResult){ |
ecarrick | 25:2e95a5731412 | 136 | //foundResult=false; |
ecarrick | 25:2e95a5731412 | 137 | break; |
ecarrick | 25:2e95a5731412 | 138 | } |
ecarrick | 25:2e95a5731412 | 139 | vector<char> empty; |
ecarrick | 25:2e95a5731412 | 140 | swap(empty, pass); |
ecarrick | 25:2e95a5731412 | 141 | vector<char> empty2; |
ecarrick | 25:2e95a5731412 | 142 | swap(empty2, name); |
ecarrick | 25:2e95a5731412 | 143 | //pass.clear(); |
ecarrick | 25:2e95a5731412 | 144 | //name.clear(); |
pshabbaki3 | 19:6fce7b88de5e | 145 | |
pshabbaki3 | 19:6fce7b88de5e | 146 | } else if (im[i] == ':') { |
pshabbaki3 | 19:6fce7b88de5e | 147 | colon = true; |
ecarrick | 16:fb2a50f0ecde | 148 | } else { |
pshabbaki3 | 19:6fce7b88de5e | 149 | if(colon) |
ecarrick | 24:94e8b3e00c24 | 150 | pass.push_back(unsigned(im[i])); |
pshabbaki3 | 19:6fce7b88de5e | 151 | else |
ecarrick | 24:94e8b3e00c24 | 152 | name.push_back(char(im[i])); |
ecarrick | 16:fb2a50f0ecde | 153 | } |
ecarrick | 16:fb2a50f0ecde | 154 | } |
ecarrick | 16:fb2a50f0ecde | 155 | } |
ecarrick | 16:fb2a50f0ecde | 156 | |
pshabbaki3 | 9:11a6f6c8c54b | 157 | void fallInterrupt() |
pshabbaki3 | 9:11a6f6c8c54b | 158 | { |
mbedTrent | 7:52b51f507ee5 | 159 | int key_code=0; |
mbedTrent | 7:52b51f507ee5 | 160 | int i=0; |
mbedTrent | 7:52b51f507ee5 | 161 | int value=mpr121.read(0x00); |
mbedTrent | 7:52b51f507ee5 | 162 | value +=mpr121.read(0x01)<<8; |
mbedTrent | 10:cf127bd9b857 | 163 | |
mbedTrent | 10:cf127bd9b857 | 164 | //checks every key for press |
mbedTrent | 7:52b51f507ee5 | 165 | for (i=0; i<=11; i++) { |
pshabbaki3 | 12:22444d5f5920 | 166 | |
mbedTrent | 10:cf127bd9b857 | 167 | //if key 10 (clr) is pressed, clear the last value on the vector will be popped off |
mbedTrent | 10:cf127bd9b857 | 168 | if ((((value>>i)&0x01)==1)&&(i==10)) { |
ecarrick | 25:2e95a5731412 | 169 | |
mbedTrent | 10:cf127bd9b857 | 170 | if (!password.empty()) { |
ecarrick | 17:632c56db3c0a | 171 | ledb = 1; |
mbedTrent | 10:cf127bd9b857 | 172 | password.pop_back(); //pop off last value on the vector |
ecarrick | 25:2e95a5731412 | 173 | //printPW();//for debugging |
ecarrick | 25:2e95a5731412 | 174 | //pc.printf("container size: %d\r\n", password.size());//for dubugging |
mbedTrent | 10:cf127bd9b857 | 175 | } |
mbedTrent | 15:3d43fe8e108b | 176 | break; |
mbedTrent | 10:cf127bd9b857 | 177 | } |
pshabbaki3 | 12:22444d5f5920 | 178 | |
mbedTrent | 10:cf127bd9b857 | 179 | //if key 11 (ENTER) is pressed, the password will be submitted IF it is long enough |
mbedTrent | 10:cf127bd9b857 | 180 | else if ((((value>>i)&0x01)==1)&&(i==11)) { |
ecarrick | 25:2e95a5731412 | 181 | if(lock == 0){ |
ecarrick | 25:2e95a5731412 | 182 | lock = 1.0; |
ecarrick | 25:2e95a5731412 | 183 | break; |
ecarrick | 25:2e95a5731412 | 184 | } |
mbedTrent | 10:cf127bd9b857 | 185 | //if the password is long enough, check passwords, and clear vector. |
mbedTrent | 15:3d43fe8e108b | 186 | if (password.size() >= minLength) { |
mbedTrent | 10:cf127bd9b857 | 187 | //CALL checkResult() FUNCTION, OR SET A FLAG INDICATING THAT PASSWORD IS COMPLETE AND AVAILABLE TO BE CHECKED! |
ecarrick | 25:2e95a5731412 | 188 | //ledb = 1; |
ecarrick | 24:94e8b3e00c24 | 189 | //ans = password; |
ecarrick | 25:2e95a5731412 | 190 | //pc.printf("ENTER KEY PRESSED\n\r"); |
ecarrick | 25:2e95a5731412 | 191 | //printPW(); |
ecarrick | 25:2e95a5731412 | 192 | //for(unsigned k =0; k<password.size(); k++) |
ecarrick | 25:2e95a5731412 | 193 | // ans.push_back(password[k]); |
ecarrick | 16:fb2a50f0ecde | 194 | checkKeyboard(); |
ecarrick | 25:2e95a5731412 | 195 | rtc = time(NULL); |
ecarrick | 25:2e95a5731412 | 196 | if(foundResult){ |
ecarrick | 25:2e95a5731412 | 197 | foundResult=false; |
ecarrick | 25:2e95a5731412 | 198 | char buf[128]; |
ecarrick | 25:2e95a5731412 | 199 | sprintf(buf,"%s %s SUCCESS", print_vector(name).c_str(), ctime(&rtc)); |
ecarrick | 25:2e95a5731412 | 200 | if(accessLog.size()<logLength){ |
ecarrick | 25:2e95a5731412 | 201 | accessLog.push_back(buf); |
ecarrick | 25:2e95a5731412 | 202 | } else{ |
ecarrick | 25:2e95a5731412 | 203 | vector<string> empty; |
ecarrick | 25:2e95a5731412 | 204 | swap(accessLog,empty); |
ecarrick | 25:2e95a5731412 | 205 | //accessLog.clear(); |
ecarrick | 25:2e95a5731412 | 206 | accessLog.push_back(buf); |
ecarrick | 25:2e95a5731412 | 207 | } |
ecarrick | 25:2e95a5731412 | 208 | } else{ |
ecarrick | 25:2e95a5731412 | 209 | ledr = 1; |
ecarrick | 25:2e95a5731412 | 210 | char buf[128]; |
ecarrick | 25:2e95a5731412 | 211 | sprintf(buf,"%s %s FAILURE", print_vector(password).c_str(), ctime(&rtc)); |
ecarrick | 25:2e95a5731412 | 212 | if(accessLog.size()<logLength){ |
ecarrick | 25:2e95a5731412 | 213 | accessLog.push_back(buf); |
ecarrick | 25:2e95a5731412 | 214 | } else{ |
ecarrick | 25:2e95a5731412 | 215 | vector<string> empty; |
ecarrick | 25:2e95a5731412 | 216 | swap(accessLog,empty); |
ecarrick | 25:2e95a5731412 | 217 | //accessLog.clear(); |
ecarrick | 25:2e95a5731412 | 218 | accessLog.push_back(buf); |
ecarrick | 25:2e95a5731412 | 219 | } |
ecarrick | 25:2e95a5731412 | 220 | } |
ecarrick | 25:2e95a5731412 | 221 | //update_log(accessLog); |
ecarrick | 25:2e95a5731412 | 222 | updateAccessLog = true; |
ecarrick | 25:2e95a5731412 | 223 | //wait(0.005); |
ecarrick | 25:2e95a5731412 | 224 | ledg=0; |
ecarrick | 25:2e95a5731412 | 225 | ledr=0; |
mbedTrent | 15:3d43fe8e108b | 226 | vector<char> empty; |
mbedTrent | 15:3d43fe8e108b | 227 | swap(empty, password); |
ecarrick | 25:2e95a5731412 | 228 | //password.clear(); |
mbedTrent | 10:cf127bd9b857 | 229 | } |
pshabbaki3 | 12:22444d5f5920 | 230 | |
mbedTrent | 10:cf127bd9b857 | 231 | else { |
ecarrick | 25:2e95a5731412 | 232 | //pc.printf("The password must be at least %d characters long\r\n", minLength); |
mbedTrent | 10:cf127bd9b857 | 233 | } |
mbedTrent | 15:3d43fe8e108b | 234 | break; |
pshabbaki3 | 12:22444d5f5920 | 235 | } |
pshabbaki3 | 12:22444d5f5920 | 236 | |
mbedTrent | 10:cf127bd9b857 | 237 | //if keys 0 through 9 are pressed |
mbedTrent | 10:cf127bd9b857 | 238 | else if (((value>>i)&0x01)==1) { |
mbedTrent | 7:52b51f507ee5 | 239 | |
mbedTrent | 10:cf127bd9b857 | 240 | //if max pw length has not been reached, push onto password vector |
mbedTrent | 10:cf127bd9b857 | 241 | if (password.size() < maxLength) { |
ecarrick | 17:632c56db3c0a | 242 | ledb = 1; |
ecarrick | 18:107fe4158212 | 243 | |
ecarrick | 17:632c56db3c0a | 244 | |
mbedTrent | 7:52b51f507ee5 | 245 | key_code=i; |
ecarrick | 24:94e8b3e00c24 | 246 | password.push_back((char)(key_code+48)); |
ecarrick | 25:2e95a5731412 | 247 | //printPW(); //for debugging |
ecarrick | 25:2e95a5731412 | 248 | //pc.printf("times: %d\r\n", password.size()); |
mbedTrent | 15:3d43fe8e108b | 249 | |
mbedTrent | 15:3d43fe8e108b | 250 | if (password.size() == maxLength) { |
mbedTrent | 15:3d43fe8e108b | 251 | //pc.printf("Max password length reached. Press clr to delete character. Press any number key to reset.\r\n"); |
ecarrick | 25:2e95a5731412 | 252 | ledb = 0; |
ecarrick | 25:2e95a5731412 | 253 | ledr = 1; |
ecarrick | 25:2e95a5731412 | 254 | wait(0.05); |
ecarrick | 25:2e95a5731412 | 255 | ledr = 0; |
mbedTrent | 15:3d43fe8e108b | 256 | vector<char> empty; |
mbedTrent | 15:3d43fe8e108b | 257 | swap(empty, password); |
mbedTrent | 15:3d43fe8e108b | 258 | //password.clear(); |
mbedTrent | 15:3d43fe8e108b | 259 | } |
mbedTrent | 15:3d43fe8e108b | 260 | } |
mbedTrent | 15:3d43fe8e108b | 261 | |
mbedTrent | 15:3d43fe8e108b | 262 | //if max password length has been reached |
mbedTrent | 15:3d43fe8e108b | 263 | else { |
ecarrick | 25:2e95a5731412 | 264 | //pc.printf("Maximum password length reached, password has been cleared. \r\n"); |
ecarrick | 25:2e95a5731412 | 265 | //password.clear(); |
ecarrick | 25:2e95a5731412 | 266 | vector<char> empty; |
ecarrick | 25:2e95a5731412 | 267 | swap(empty, password); |
mbedTrent | 15:3d43fe8e108b | 268 | } |
mbedTrent | 15:3d43fe8e108b | 269 | break; |
mbedTrent | 15:3d43fe8e108b | 270 | } |
mbedTrent | 15:3d43fe8e108b | 271 | |
mbedTrent | 15:3d43fe8e108b | 272 | } |
ecarrick | 25:2e95a5731412 | 273 | wait(0.005); |
ecarrick | 18:107fe4158212 | 274 | ledb = 0; |
mbedTrent | 15:3d43fe8e108b | 275 | |
mbedTrent | 15:3d43fe8e108b | 276 | } |
mbedTrent | 15:3d43fe8e108b | 277 | |
ecarrick | 16:fb2a50f0ecde | 278 | |
ecarrick | 24:94e8b3e00c24 | 279 | |
mbedTrent | 7:52b51f507ee5 | 280 | |
pshabbaki3 | 9:11a6f6c8c54b | 281 | void save_to_file() |
pshabbaki3 | 9:11a6f6c8c54b | 282 | { |
ecarrick | 5:a2fbe5bd2be0 | 283 | FILE * fp = fopen("/local/users.txt", "w"); |
pshabbaki3 | 9:11a6f6c8c54b | 284 | if(fp != NULL) { |
pshabbaki3 | 9:11a6f6c8c54b | 285 | for(unsigned i=0; i< im.size(); i++) { |
ecarrick | 6:50a82641d07b | 286 | fprintf(fp,"%c",im[i]); |
ecarrick | 5:a2fbe5bd2be0 | 287 | } |
ecarrick | 5:a2fbe5bd2be0 | 288 | } |
ecarrick | 5:a2fbe5bd2be0 | 289 | fclose(fp); |
ecarrick | 5:a2fbe5bd2be0 | 290 | } |
ecarrick | 5:a2fbe5bd2be0 | 291 | |
pshabbaki3 | 9:11a6f6c8c54b | 292 | void load_from_file() |
pshabbaki3 | 9:11a6f6c8c54b | 293 | { |
ecarrick | 5:a2fbe5bd2be0 | 294 | FILE * fp = fopen("/local/users.txt", "r"); |
pshabbaki3 | 9:11a6f6c8c54b | 295 | if(fp != NULL) { |
ecarrick | 5:a2fbe5bd2be0 | 296 | im.clear(); |
pshabbaki3 | 9:11a6f6c8c54b | 297 | do { |
ecarrick | 6:50a82641d07b | 298 | im.push_back(fgetc(fp)); |
pshabbaki3 | 9:11a6f6c8c54b | 299 | } while(im.back() != '#'); |
ecarrick | 5:a2fbe5bd2be0 | 300 | } |
ecarrick | 5:a2fbe5bd2be0 | 301 | fclose(fp); |
ecarrick | 5:a2fbe5bd2be0 | 302 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 303 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 304 | int i = 0; |
pshabbaki3 | 0:5d35ff3dc9a5 | 305 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 306 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 307 | |
pshabbaki3 | 12:22444d5f5920 | 308 | //Interrupt |
pshabbaki3 | 12:22444d5f5920 | 309 | void Rx_interrupt() |
pshabbaki3 | 0:5d35ff3dc9a5 | 310 | { |
ecarrick | 25:2e95a5731412 | 311 | newData = true; |
pshabbaki3 | 19:6fce7b88de5e | 312 | |
pshabbaki3 | 12:22444d5f5920 | 313 | return; |
pshabbaki3 | 0:5d35ff3dc9a5 | 314 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 315 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 316 | |
pshabbaki3 | 12:22444d5f5920 | 317 | int main() |
pshabbaki3 | 12:22444d5f5920 | 318 | { |
ecarrick | 25:2e95a5731412 | 319 | |
ecarrick | 25:2e95a5731412 | 320 | pc.printf("\r\n\r\nMBED RESET\r\n"); |
ecarrick | 25:2e95a5731412 | 321 | lock = 1.0; |
ecarrick | 25:2e95a5731412 | 322 | pc.printf("Setting up WIFI\r\n"); |
ecarrick | 25:2e95a5731412 | 323 | setup_wifi(); |
ecarrick | 25:2e95a5731412 | 324 | pc.printf("Setting Up HTTP\r\n"); |
ecarrick | 25:2e95a5731412 | 325 | setup_http(); |
ecarrick | 25:2e95a5731412 | 326 | // pc.printf("updating access log\r\n"); |
ecarrick | 25:2e95a5731412 | 327 | // accessLog.push_back("test 1"); |
ecarrick | 25:2e95a5731412 | 328 | // accessLog.push_back("Hey Edison"); |
ecarrick | 25:2e95a5731412 | 329 | // accessLog.push_back("Great job!"); |
ecarrick | 25:2e95a5731412 | 330 | //update_log(accessLog); |
ecarrick | 25:2e95a5731412 | 331 | pc.printf("Setting up NTP\r\n"); |
ecarrick | 25:2e95a5731412 | 332 | setup_ntp(); |
ecarrick | 25:2e95a5731412 | 333 | pc.printf("Updating NTP\r\n"); |
ecarrick | 25:2e95a5731412 | 334 | update_ntp(); |
ecarrick | 25:2e95a5731412 | 335 | rtc = time(NULL); |
ecarrick | 25:2e95a5731412 | 336 | pc.printf("%s\r\n", ctime(&rtc)); |
ecarrick | 25:2e95a5731412 | 337 | |
ecarrick | 25:2e95a5731412 | 338 | |
ecarrick | 24:94e8b3e00c24 | 339 | load_from_file(); |
ecarrick | 16:fb2a50f0ecde | 340 | print_to_serial(); |
ecarrick | 25:2e95a5731412 | 341 | |
pshabbaki3 | 12:22444d5f5920 | 342 | interrupt.fall(&fallInterrupt); |
pshabbaki3 | 12:22444d5f5920 | 343 | interrupt.mode(PullUp); |
pshabbaki3 | 12:22444d5f5920 | 344 | //load_from_file(); |
pshabbaki3 | 12:22444d5f5920 | 345 | |
pshabbaki3 | 12:22444d5f5920 | 346 | //interupt driven read from serial port |
pshabbaki3 | 12:22444d5f5920 | 347 | // calls save_to_file(); |
pshabbaki3 | 12:22444d5f5920 | 348 | pc.attach(&Rx_interrupt, Serial::RxIrq); |
ecarrick | 25:2e95a5731412 | 349 | |
ecarrick | 25:2e95a5731412 | 350 | ledg = 1; |
ecarrick | 25:2e95a5731412 | 351 | wait(0.3); |
ecarrick | 25:2e95a5731412 | 352 | ledg = 0; |
ecarrick | 25:2e95a5731412 | 353 | wait(0.3); |
ecarrick | 25:2e95a5731412 | 354 | ledg = 1; |
ecarrick | 25:2e95a5731412 | 355 | wait(0.3); |
ecarrick | 25:2e95a5731412 | 356 | ledg = 0; |
ecarrick | 25:2e95a5731412 | 357 | |
ecarrick | 25:2e95a5731412 | 358 | while(1){ |
ecarrick | 25:2e95a5731412 | 359 | if(updateAccessLog){ |
ecarrick | 25:2e95a5731412 | 360 | update_log(accessLog); |
ecarrick | 25:2e95a5731412 | 361 | updateAccessLog = false; |
ecarrick | 25:2e95a5731412 | 362 | } |
ecarrick | 25:2e95a5731412 | 363 | |
ecarrick | 25:2e95a5731412 | 364 | if(saveToFileFlag){ |
ecarrick | 25:2e95a5731412 | 365 | save_to_file(); |
ecarrick | 25:2e95a5731412 | 366 | saveToFileFlag = false; |
ecarrick | 25:2e95a5731412 | 367 | } |
ecarrick | 25:2e95a5731412 | 368 | |
ecarrick | 25:2e95a5731412 | 369 | if(newData){ |
ecarrick | 25:2e95a5731412 | 370 | //pc.printf("read in from serial\r\n"); |
ecarrick | 25:2e95a5731412 | 371 | ledb = 1; |
ecarrick | 25:2e95a5731412 | 372 | vector<char> empty; |
ecarrick | 25:2e95a5731412 | 373 | swap(empty, im); |
ecarrick | 25:2e95a5731412 | 374 | while (1) { |
ecarrick | 25:2e95a5731412 | 375 | char c = pc.getc(); |
ecarrick | 25:2e95a5731412 | 376 | if (c!='#') { |
ecarrick | 25:2e95a5731412 | 377 | im.push_back(c); //writing all the characters into vector |
ecarrick | 25:2e95a5731412 | 378 | |
ecarrick | 25:2e95a5731412 | 379 | //checkKeyboard(im); |
ecarrick | 25:2e95a5731412 | 380 | } else { |
ecarrick | 25:2e95a5731412 | 381 | im.push_back(c); |
ecarrick | 25:2e95a5731412 | 382 | saveToFileFlag = true; |
ecarrick | 25:2e95a5731412 | 383 | newData = false; |
ecarrick | 25:2e95a5731412 | 384 | break; |
ecarrick | 25:2e95a5731412 | 385 | } |
ecarrick | 25:2e95a5731412 | 386 | |
ecarrick | 25:2e95a5731412 | 387 | } |
ecarrick | 25:2e95a5731412 | 388 | ledb = 0; |
ecarrick | 25:2e95a5731412 | 389 | |
ecarrick | 25:2e95a5731412 | 390 | } |
ecarrick | 25:2e95a5731412 | 391 | wait(0.1); |
ecarrick | 25:2e95a5731412 | 392 | //sleep(); |
ecarrick | 25:2e95a5731412 | 393 | |
ecarrick | 25:2e95a5731412 | 394 | } |
ecarrick | 25:2e95a5731412 | 395 | |
pshabbaki3 | 12:22444d5f5920 | 396 | } |
pshabbaki3 | 12:22444d5f5920 | 397 | |
pshabbaki3 | 12:22444d5f5920 | 398 |