4180 Final Project
Dependencies: 4DGL-uLCD-SE mbed Servo
main.cpp@6:50a82641d07b, 2016-04-18 (annotated)
- Committer:
- ecarrick
- Date:
- Mon Apr 18 17:51:33 2016 +0000
- Revision:
- 6:50a82641d07b
- Parent:
- 5:a2fbe5bd2be0
- Child:
- 7:52b51f507ee5
adding wifi and ntp functions
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" |
pshabbaki3 | 0:5d35ff3dc9a5 | 11 | |
ecarrick | 1:dd048edb2716 | 12 | LocalFileSystem local("local"); |
pshabbaki3 | 0:5d35ff3dc9a5 | 13 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 14 | DigitalOut myled(LED1); |
pshabbaki3 | 0:5d35ff3dc9a5 | 15 | Serial pc(USBTX,USBRX); |
pshabbaki3 | 0:5d35ff3dc9a5 | 16 | uLCD_4DGL lcd(p28,p27,p30); // serial tx, serial rx, reset pin; |
pshabbaki3 | 0:5d35ff3dc9a5 | 17 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 18 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 19 | vector<char> im; |
pshabbaki3 | 4:e6b198a22216 | 20 | vector<char> pass; |
pshabbaki3 | 0:5d35ff3dc9a5 | 21 | vector<char> name; |
pshabbaki3 | 0:5d35ff3dc9a5 | 22 | vector<char> final; |
pshabbaki3 | 0:5d35ff3dc9a5 | 23 | |
ecarrick | 5:a2fbe5bd2be0 | 24 | void save_to_file(){ |
ecarrick | 5:a2fbe5bd2be0 | 25 | FILE * fp = fopen("/local/users.txt", "w"); |
ecarrick | 5:a2fbe5bd2be0 | 26 | if(fp != NULL){ |
ecarrick | 5:a2fbe5bd2be0 | 27 | for(unsigned i=0; i< im.size(); i++){ |
ecarrick | 6:50a82641d07b | 28 | fprintf(fp,"%c",im[i]); |
ecarrick | 5:a2fbe5bd2be0 | 29 | } |
ecarrick | 5:a2fbe5bd2be0 | 30 | } |
ecarrick | 5:a2fbe5bd2be0 | 31 | fclose(fp); |
ecarrick | 5:a2fbe5bd2be0 | 32 | } |
ecarrick | 5:a2fbe5bd2be0 | 33 | |
ecarrick | 5:a2fbe5bd2be0 | 34 | void load_from_file(){ |
ecarrick | 5:a2fbe5bd2be0 | 35 | FILE * fp = fopen("/local/users.txt", "r"); |
ecarrick | 5:a2fbe5bd2be0 | 36 | if(fp != NULL){ |
ecarrick | 5:a2fbe5bd2be0 | 37 | im.clear(); |
ecarrick | 5:a2fbe5bd2be0 | 38 | do{ |
ecarrick | 6:50a82641d07b | 39 | im.push_back(fgetc(fp)); |
ecarrick | 5:a2fbe5bd2be0 | 40 | } |
ecarrick | 6:50a82641d07b | 41 | while(im.back() != '#'); |
ecarrick | 5:a2fbe5bd2be0 | 42 | } |
ecarrick | 5:a2fbe5bd2be0 | 43 | fclose(fp); |
ecarrick | 5:a2fbe5bd2be0 | 44 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 45 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 46 | int i = 0; |
pshabbaki3 | 0:5d35ff3dc9a5 | 47 | |
pshabbaki3 | 4:e6b198a22216 | 48 | void checkResult(vector<char> pass, vector<char> name) |
pshabbaki3 | 0:5d35ff3dc9a5 | 49 | { |
pshabbaki3 | 0:5d35ff3dc9a5 | 50 | // This function will check the keypad values and check if the passcode exists or not |
pshabbaki3 | 0:5d35ff3dc9a5 | 51 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 52 | vector<char> ans; //This vector should be the values coming from keypad |
pshabbaki3 | 0:5d35ff3dc9a5 | 53 | ans.push_back('1'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 54 | ans.push_back('2'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 55 | ans.push_back('3'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 56 | ans.push_back('4'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 57 | ans.push_back('5'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 58 | ans.push_back('6'); |
pshabbaki3 | 4:e6b198a22216 | 59 | if (pass.size()==6) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 60 | i++; //use "i" to find which person logged in. |
pshabbaki3 | 4:e6b198a22216 | 61 | if (ans == pass) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 62 | // pc.printf("Found"); |
pshabbaki3 | 0:5d35ff3dc9a5 | 63 | final = name; |
pshabbaki3 | 4:e6b198a22216 | 64 | final.insert(name.end(),pass.begin(),pass.end()); |
pshabbaki3 | 0:5d35ff3dc9a5 | 65 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 66 | } else { |
pshabbaki3 | 0:5d35ff3dc9a5 | 67 | // pc.printf("not found"); |
pshabbaki3 | 4:e6b198a22216 | 68 | //lcd.printf("\nnot found\n"); |
pshabbaki3 | 0:5d35ff3dc9a5 | 69 | final.clear(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 70 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 71 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 72 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 73 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 74 | |
pshabbaki3 | 2:693a3af5af49 | 75 | void checkKeyboard(vector<char> im) |
pshabbaki3 | 0:5d35ff3dc9a5 | 76 | { |
pshabbaki3 | 2:693a3af5af49 | 77 | for (int i = 0; i<im.size(); i++) { |
pshabbaki3 | 4:e6b198a22216 | 78 | // find space |
pshabbaki3 | 2:693a3af5af49 | 79 | if (im[i] ==' ') { |
pshabbaki3 | 4:e6b198a22216 | 80 | // Check the result |
pshabbaki3 | 4:e6b198a22216 | 81 | checkResult(pass,name); |
pshabbaki3 | 4:e6b198a22216 | 82 | // clear pass, name and final |
pshabbaki3 | 4:e6b198a22216 | 83 | pass.clear(); |
pshabbaki3 | 2:693a3af5af49 | 84 | name.clear(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 85 | // pc.printf("clear"); |
pshabbaki3 | 4:e6b198a22216 | 86 | //lcd.printf("clear"); |
pshabbaki3 | 2:693a3af5af49 | 87 | } else { |
pshabbaki3 | 2:693a3af5af49 | 88 | if (isdigit(im[i])) { |
pshabbaki3 | 4:e6b198a22216 | 89 | // write numbers (char) to vector pass |
pshabbaki3 | 4:e6b198a22216 | 90 | pass.push_back(im[i]); |
pshabbaki3 | 2:693a3af5af49 | 91 | |
pshabbaki3 | 2:693a3af5af49 | 92 | } else if (isalpha(im[i])) { |
pshabbaki3 | 2:693a3af5af49 | 93 | // write letters (char) to vector name |
pshabbaki3 | 2:693a3af5af49 | 94 | name.push_back(im[i]); |
pshabbaki3 | 2:693a3af5af49 | 95 | |
pshabbaki3 | 2:693a3af5af49 | 96 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 97 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 98 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 99 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 100 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 101 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 102 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 103 | int main() |
pshabbaki3 | 0:5d35ff3dc9a5 | 104 | { |
pshabbaki3 | 2:693a3af5af49 | 105 | //load_from_file(); |
pshabbaki3 | 2:693a3af5af49 | 106 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 107 | //interupt driven read from serial port |
pshabbaki3 | 0:5d35ff3dc9a5 | 108 | // calls save_to_file(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 109 | while(1) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 110 | char c = pc.getc(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 111 | if (c!='#') { |
pshabbaki3 | 0:5d35ff3dc9a5 | 112 | im.push_back(c); //writing all the characters into vector |
pshabbaki3 | 2:693a3af5af49 | 113 | checkKeyboard(im); |
pshabbaki3 | 0:5d35ff3dc9a5 | 114 | } else { |
pshabbaki3 | 0:5d35ff3dc9a5 | 115 | for (int cnt = 0; cnt<im.size(); cnt++) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 116 | pc.printf("%c",im[cnt]); |
pshabbaki3 | 4:e6b198a22216 | 117 | //lcd.printf("%c",im[cnt]); |
pshabbaki3 | 0:5d35ff3dc9a5 | 118 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 119 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 120 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 121 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 122 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 123 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 124 |