Browse Source

self testing

develop
Robin Thoni 8 years ago
parent
commit
c5f6cab1e5
1 changed files with 34 additions and 9 deletions
  1. 34
    9
      main.ino

+ 34
- 9
main.ino View File

@@ -22,6 +22,7 @@ LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
22 22
 
23 23
 
24 24
 #define SELF_TEST_LABEL "Self testing..."
25
+#define SELF_TEST_ERROR_LABEL "Error: "
25 26
 #define UID_LABEL "UID:"
26 27
 #define PWD_LABEL "PWD:"
27 28
 #define UID_MAX_LEN 12
@@ -37,8 +38,12 @@ Status status = Uid;
37 38
 
38 39
 #define MAX_IDLE_TIME 20
39 40
 unsigned long lastActivity = 0;
40
-#define SELF_TEST_INTERVAL 10
41
+#define SELF_TEST_INTERVAL 60
42
+#define SELF_TEST_ERROR_INTERVAL 2
43
+#define MAX_SELF_TEST_TIME 5
41 44
 unsigned long lastSelfTest = 0;
45
+#define SELF_TEST_NO_ERROR '0'
46
+int lastSelfTestResult = SELF_TEST_NO_ERROR;
42 47
 
43 48
 void setup() {
44 49
     Serial.begin(9600);
@@ -48,7 +53,7 @@ void setup() {
48 53
     lcd.blink();
49 54
     lcd.noAutoscroll();
50 55
 
51
-    reset();
56
+    selfTest();
52 57
 }
53 58
 
54 59
 String makeChars(char c, int count) {
@@ -82,7 +87,7 @@ void loop() {
82 87
         updateLcd();
83 88
     }
84 89
     if ((uid.length() != 0 || password.length() != 0) && secs - lastActivity >= MAX_IDLE_TIME) {
85
-        reset();
90
+        askUidPassword();
86 91
     }
87 92
     if (uid.length() == 0 && password.length() == 0 && secs - lastSelfTest >= SELF_TEST_INTERVAL) {
88 93
         selfTest();
@@ -140,10 +145,15 @@ void updateLcd()
140 145
     }
141 146
     else if (status == SelfTest) {
142 147
         lcd.print(SELF_TEST_LABEL);
148
+        if (lastSelfTestResult != SELF_TEST_NO_ERROR) {
149
+            lcd.setCursor(0, 1);
150
+            lcd.print(SELF_TEST_ERROR_LABEL);
151
+            lcd.print(lastSelfTestResult);
152
+        }
143 153
     }
144 154
 }
145 155
 
146
-void reset()
156
+void askUidPassword()
147 157
 {
148 158
     status = Uid;
149 159
     uid = "";
@@ -155,16 +165,31 @@ void login(String uid, String password)
155 165
 {
156 166
     Serial.println(uid);
157 167
     Serial.println(password);
158
-    reset();
168
+    askUidPassword();
159 169
 }
160 170
 
161 171
 void selfTest()
162 172
 {
173
+    lastSelfTest = SELF_TEST_NO_ERROR;
163 174
     status = SelfTest;
164 175
     updateLcd();
165
-    Serial.println("Self Testing");
166
-//    while (Serial.available() == 0);
167
-    Serial.read();
176
+
177
+    bool test = true;
178
+    while (test) {
179
+        unsigned long secs = millis() / 1000;
180
+        Serial.println("Self Testing");
181
+        while (Serial.available() == 0 && (millis() / 1000) - secs < MAX_SELF_TEST_TIME);
182
+        if (Serial.available() > 0) {
183
+            lastSelfTestResult = Serial.read();
184
+            if (lastSelfTestResult == SELF_TEST_NO_ERROR) {
185
+                test = false;
186
+            }
187
+            else {
188
+                updateLcd();
189
+                delay(SELF_TEST_ERROR_INTERVAL * 1000);
190
+            }
191
+        }
192
+    }
168 193
     lastSelfTest = millis() / 1000;
169
-    reset();
194
+    askUidPassword();
170 195
 }

Loading…
Cancel
Save