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
 
22
 
23
 
23
 
24
 #define SELF_TEST_LABEL "Self testing..."
24
 #define SELF_TEST_LABEL "Self testing..."
25
+#define SELF_TEST_ERROR_LABEL "Error: "
25
 #define UID_LABEL "UID:"
26
 #define UID_LABEL "UID:"
26
 #define PWD_LABEL "PWD:"
27
 #define PWD_LABEL "PWD:"
27
 #define UID_MAX_LEN 12
28
 #define UID_MAX_LEN 12
37
 
38
 
38
 #define MAX_IDLE_TIME 20
39
 #define MAX_IDLE_TIME 20
39
 unsigned long lastActivity = 0;
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
 unsigned long lastSelfTest = 0;
44
 unsigned long lastSelfTest = 0;
45
+#define SELF_TEST_NO_ERROR '0'
46
+int lastSelfTestResult = SELF_TEST_NO_ERROR;
42
 
47
 
43
 void setup() {
48
 void setup() {
44
     Serial.begin(9600);
49
     Serial.begin(9600);
48
     lcd.blink();
53
     lcd.blink();
49
     lcd.noAutoscroll();
54
     lcd.noAutoscroll();
50
 
55
 
51
-    reset();
56
+    selfTest();
52
 }
57
 }
53
 
58
 
54
 String makeChars(char c, int count) {
59
 String makeChars(char c, int count) {
82
         updateLcd();
87
         updateLcd();
83
     }
88
     }
84
     if ((uid.length() != 0 || password.length() != 0) && secs - lastActivity >= MAX_IDLE_TIME) {
89
     if ((uid.length() != 0 || password.length() != 0) && secs - lastActivity >= MAX_IDLE_TIME) {
85
-        reset();
90
+        askUidPassword();
86
     }
91
     }
87
     if (uid.length() == 0 && password.length() == 0 && secs - lastSelfTest >= SELF_TEST_INTERVAL) {
92
     if (uid.length() == 0 && password.length() == 0 && secs - lastSelfTest >= SELF_TEST_INTERVAL) {
88
         selfTest();
93
         selfTest();
140
     }
145
     }
141
     else if (status == SelfTest) {
146
     else if (status == SelfTest) {
142
         lcd.print(SELF_TEST_LABEL);
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
     status = Uid;
158
     status = Uid;
149
     uid = "";
159
     uid = "";
155
 {
165
 {
156
     Serial.println(uid);
166
     Serial.println(uid);
157
     Serial.println(password);
167
     Serial.println(password);
158
-    reset();
168
+    askUidPassword();
159
 }
169
 }
160
 
170
 
161
 void selfTest()
171
 void selfTest()
162
 {
172
 {
173
+    lastSelfTest = SELF_TEST_NO_ERROR;
163
     status = SelfTest;
174
     status = SelfTest;
164
     updateLcd();
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
     lastSelfTest = millis() / 1000;
193
     lastSelfTest = millis() / 1000;
169
-    reset();
194
+    askUidPassword();
170
 }
195
 }

Loading…
Cancel
Save