Robin Thoni пре 8 година
родитељ
комит
aa48159b17
2 измењених фајлова са 32 додато и 13 уклоњено
  1. 8
    3
      config.h
  2. 24
    10
      main.ino

+ 8
- 3
config.h Прегледај датотеку

@@ -16,9 +16,9 @@
16 16
 #define SELF_TEST_ERROR_LABEL "Error: "
17 17
 #define UID_LABEL "UID:"
18 18
 #define PWD_LABEL "PWD:"
19
-#define LOGIN_IN_PROGRESS "Login..."
20
-#define LOGIN_FAILED "Login failed"
21
-#define LOGIN_SUCCESS "Access granted"
19
+#define LOGIN_IN_PROGRESS_LABEL "Login..."
20
+#define LOGIN_FAILED_LABEL "Login failed"
21
+#define LOGIN_SUCCESS_LABEL "Access granted"
22 22
 
23 23
 #define UID_MAX_LEN 12
24 24
 #define PWD_MAX_LEN 12
@@ -26,6 +26,7 @@
26 26
 #define MAX_IDLE_TIME 20
27 27
 
28 28
 #define LOGIN_FAILED_TIME 2
29
+#define MAX_LOGIN_TIME 5
29 30
 
30 31
 #define SELF_TEST_INTERVAL 60
31 32
 #define SELF_TEST_ERROR_INTERVAL 2
@@ -44,6 +45,10 @@
44 45
 #define PACKET_SELF_TEST 2
45 46
 #define PACKET_LOGIN 3
46 47
 
48
+#define LOGIN_OK 0
49
+#define LOGIN_FAILED 1
50
+#define LOGIN_ERROR 2
51
+
47 52
 #define DEBUG
48 53
 
49 54
 

+ 24
- 10
main.ino Прегледај датотеку

@@ -150,13 +150,13 @@ void updateLcd()
150 150
         }
151 151
     }
152 152
     else if (status == LoginInProgress) {
153
-        lcd.print(LOGIN_IN_PROGRESS);
153
+        lcd.print(LOGIN_IN_PROGRESS_LABEL);
154 154
     }
155 155
     else if (status == LoginFailed) {
156
-        lcd.print(LOGIN_FAILED);
156
+        lcd.print(LOGIN_FAILED_LABEL);
157 157
     }
158 158
     else if (status == LoginSuccess) {
159
-        lcd.print(LOGIN_SUCCESS);
159
+        lcd.print(LOGIN_SUCCESS_LABEL);
160 160
     }
161 161
 }
162 162
 
@@ -173,16 +173,30 @@ void login(String uid, String password)
173 173
     status = LoginInProgress;
174 174
     updateLcd();
175 175
 
176
-    delay(LOGIN_FAILED_TIME * 1000);
177
-
178 176
     hostCommunication.login(uid, password);
179 177
 
180
-    status = LoginSuccess;
181
-    updateLcd();
182
-
183
-    delay(LOGIN_FAILED_TIME * 1000);
178
+    HostCommunicationResult res = hostCommunication.read(MAX_LOGIN_TIME * 1000);
184 179
 
185
-    askUidPassword();
180
+    if (!res.isSuccess || res.length != sizeof(SERIAL_PACKET_TYPE_INT)) {
181
+        selfTest();
182
+        return;
183
+    }
184
+    else {
185
+        int loginRes = *(SERIAL_PACKET_TYPE_INT*)res.data;
186
+        if (loginRes == LOGIN_OK) {
187
+            status = LoginSuccess;
188
+        }
189
+        else if (loginRes == LOGIN_FAILED) {
190
+            status = LoginFailed;
191
+        }
192
+        else {
193
+            selfTest();
194
+            return;
195
+        }
196
+        updateLcd();
197
+        delay(LOGIN_FAILED_TIME * 1000);
198
+        askUidPassword();
199
+    }
186 200
 }
187 201
 
188 202
 void selfTest()

Loading…
Откажи
Сачувај