4180 Final Project
Dependencies: 4DGL-uLCD-SE mbed Servo
main.cpp@4:e6b198a22216, 2016-04-12 (annotated)
- Committer:
- pshabbaki3
- Date:
- Tue Apr 12 17:15:23 2016 +0000
- Revision:
- 4:e6b198a22216
- Parent:
- 3:babc3bec33ca
- Child:
- 5:a2fbe5bd2be0
commented all LCD.printf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pshabbaki3 | 0:5d35ff3dc9a5 | 1 | #include "mbed.h" |
pshabbaki3 | 0:5d35ff3dc9a5 | 2 | #include <string> |
pshabbaki3 | 0:5d35ff3dc9a5 | 3 | #include <vector> |
pshabbaki3 | 0:5d35ff3dc9a5 | 4 | #include <iostream> |
pshabbaki3 | 0:5d35ff3dc9a5 | 5 | #include <sstream> |
pshabbaki3 | 0:5d35ff3dc9a5 | 6 | #include <iterator> |
pshabbaki3 | 0:5d35ff3dc9a5 | 7 | #include <stdio.h> |
pshabbaki3 | 0:5d35ff3dc9a5 | 8 | #include <ctype.h> |
pshabbaki3 | 0:5d35ff3dc9a5 | 9 | #include "uLCD_4DGL.h" |
pshabbaki3 | 0:5d35ff3dc9a5 | 10 | |
ecarrick | 1:dd048edb2716 | 11 | LocalFileSystem local("local"); |
pshabbaki3 | 0:5d35ff3dc9a5 | 12 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 13 | DigitalOut myled(LED1); |
pshabbaki3 | 0:5d35ff3dc9a5 | 14 | Serial pc(USBTX,USBRX); |
pshabbaki3 | 0:5d35ff3dc9a5 | 15 | uLCD_4DGL lcd(p28,p27,p30); // serial tx, serial rx, reset pin; |
pshabbaki3 | 0:5d35ff3dc9a5 | 16 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 17 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 18 | vector<char> im; |
pshabbaki3 | 4:e6b198a22216 | 19 | vector<char> pass; |
pshabbaki3 | 0:5d35ff3dc9a5 | 20 | vector<char> name; |
pshabbaki3 | 0:5d35ff3dc9a5 | 21 | vector<char> final; |
pshabbaki3 | 0:5d35ff3dc9a5 | 22 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 23 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 24 | int i = 0; |
pshabbaki3 | 0:5d35ff3dc9a5 | 25 | |
pshabbaki3 | 4:e6b198a22216 | 26 | void checkResult(vector<char> pass, vector<char> name) |
pshabbaki3 | 0:5d35ff3dc9a5 | 27 | { |
pshabbaki3 | 0:5d35ff3dc9a5 | 28 | // This function will check the keypad values and check if the passcode exists or not |
pshabbaki3 | 0:5d35ff3dc9a5 | 29 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 30 | vector<char> ans; //This vector should be the values coming from keypad |
pshabbaki3 | 0:5d35ff3dc9a5 | 31 | ans.push_back('1'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 32 | ans.push_back('2'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 33 | ans.push_back('3'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 34 | ans.push_back('4'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 35 | ans.push_back('5'); |
pshabbaki3 | 0:5d35ff3dc9a5 | 36 | ans.push_back('6'); |
pshabbaki3 | 4:e6b198a22216 | 37 | if (pass.size()==6) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 38 | i++; //use "i" to find which person logged in. |
pshabbaki3 | 4:e6b198a22216 | 39 | if (ans == pass) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 40 | // pc.printf("Found"); |
pshabbaki3 | 0:5d35ff3dc9a5 | 41 | final = name; |
pshabbaki3 | 4:e6b198a22216 | 42 | final.insert(name.end(),pass.begin(),pass.end()); |
pshabbaki3 | 0:5d35ff3dc9a5 | 43 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 44 | } else { |
pshabbaki3 | 0:5d35ff3dc9a5 | 45 | // pc.printf("not found"); |
pshabbaki3 | 4:e6b198a22216 | 46 | //lcd.printf("\nnot found\n"); |
pshabbaki3 | 0:5d35ff3dc9a5 | 47 | final.clear(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 48 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 49 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 50 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 51 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 52 | |
pshabbaki3 | 2:693a3af5af49 | 53 | void checkKeyboard(vector<char> im) |
pshabbaki3 | 0:5d35ff3dc9a5 | 54 | { |
pshabbaki3 | 2:693a3af5af49 | 55 | for (int i = 0; i<im.size(); i++) { |
pshabbaki3 | 4:e6b198a22216 | 56 | // find space |
pshabbaki3 | 2:693a3af5af49 | 57 | if (im[i] ==' ') { |
pshabbaki3 | 4:e6b198a22216 | 58 | // Check the result |
pshabbaki3 | 4:e6b198a22216 | 59 | checkResult(pass,name); |
pshabbaki3 | 4:e6b198a22216 | 60 | // clear pass, name and final |
pshabbaki3 | 4:e6b198a22216 | 61 | pass.clear(); |
pshabbaki3 | 2:693a3af5af49 | 62 | name.clear(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 63 | // pc.printf("clear"); |
pshabbaki3 | 4:e6b198a22216 | 64 | //lcd.printf("clear"); |
pshabbaki3 | 2:693a3af5af49 | 65 | } else { |
pshabbaki3 | 2:693a3af5af49 | 66 | if (isdigit(im[i])) { |
pshabbaki3 | 4:e6b198a22216 | 67 | // write numbers (char) to vector pass |
pshabbaki3 | 4:e6b198a22216 | 68 | pass.push_back(im[i]); |
pshabbaki3 | 2:693a3af5af49 | 69 | |
pshabbaki3 | 2:693a3af5af49 | 70 | } else if (isalpha(im[i])) { |
pshabbaki3 | 2:693a3af5af49 | 71 | // write letters (char) to vector name |
pshabbaki3 | 2:693a3af5af49 | 72 | name.push_back(im[i]); |
pshabbaki3 | 2:693a3af5af49 | 73 | |
pshabbaki3 | 2:693a3af5af49 | 74 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 75 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 76 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 77 | } |
pshabbaki3 | 0:5d35ff3dc9a5 | 78 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 79 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 80 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 81 | int main() |
pshabbaki3 | 0:5d35ff3dc9a5 | 82 | { |
pshabbaki3 | 2:693a3af5af49 | 83 | //load_from_file(); |
pshabbaki3 | 2:693a3af5af49 | 84 | |
pshabbaki3 | 0:5d35ff3dc9a5 | 85 | //interupt driven read from serial port |
pshabbaki3 | 0:5d35ff3dc9a5 | 86 | // calls save_to_file(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 87 | while(1) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 88 | char c = pc.getc(); |
pshabbaki3 | 0:5d35ff3dc9a5 | 89 | if (c!='#') { |
pshabbaki3 | 0:5d35ff3dc9a5 | 90 | im.push_back(c); //writing all the characters into vector |
pshabbaki3 | 2:693a3af5af49 | 91 | checkKeyboard(im); |
pshabbaki3 | 0:5d35ff3dc9a5 | 92 | } else { |
pshabbaki3 | 0:5d35ff3dc9a5 | 93 | for (int cnt = 0; cnt<im.size(); cnt++) { |
pshabbaki3 | 0:5d35ff3dc9a5 | 94 | pc.printf("%c",im[cnt]); |
pshabbaki3 | 4:e6b198a22216 | 95 | //lcd.printf("%c",im[cnt]); |
pshabbaki3 | 0:5d35ff3dc9a5 | 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 |