summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergiusz 'q3k' Bazański <q3k@q3k.org>2015-03-24 18:40:39 +0100
committerSergiusz 'q3k' Bazański <q3k@q3k.org>2015-03-24 18:40:39 +0100
commit1079e497e4561bb6be02cc83c7c8f1ac147b0ed7 (patch)
treea44b3f815ae9ed297b8bcf790bb0b673c4c75f3e
parenteb0a11c7068955c74786ff5475a827c01d3cd64d (diff)
downloaddoorman-1079e497e4561bb6be02cc83c7c8f1ac147b0ed7.tar.gz
doorman-1079e497e4561bb6be02cc83c7c8f1ac147b0ed7.tar.bz2
doorman-1079e497e4561bb6be02cc83c7c8f1ac147b0ed7.zip
Reset the NFC reader every 30 minutes
This should fix an apparent crash in the NFC reader firmware.
-rw-r--r--arduino/src/config.h3
-rw-r--r--arduino/src/rf.cpp26
2 files changed, 18 insertions, 11 deletions
diff --git a/arduino/src/config.h b/arduino/src/config.h
index aa676c7..29b60c0 100644
--- a/arduino/src/config.h
+++ b/arduino/src/config.h
@@ -26,7 +26,8 @@
/** Max length of message from or to PC. */
#define PC_MAX_BYTES (2+1+4+1+EMEM_HASH_SIZE*2+1+PC_MAC_SIZE*2+1)
/** Period for quering rfid reader. */
-#define RF_PERIOD_MS (500)
+#define RF_PERIOD_SEEK_MS (500)
+#define RF_PERIOD_RESET_MS (30 * 60 * 1000)
/** PC Communications MAC secret **/
#define PC_MAC_SECRET ("hackme")
diff --git a/arduino/src/rf.cpp b/arduino/src/rf.cpp
index c85e61a..181b784 100644
--- a/arduino/src/rf.cpp
+++ b/arduino/src/rf.cpp
@@ -41,20 +41,26 @@ void rf_seek() {
* @return Returns true when authorized user rfid was rd.
*/
boolean rf_comm(unsigned long * p_rfid) {
- static unsigned long last_millis = 0;
- static unsigned long new_millis = 0;
+ static unsigned long last_millis_seek = 0;
+ static unsigned long last_millis_reset = 0;
+
+ unsigned long new_millis = millis();
+
(*p_rfid) = 0;
- new_millis = millis();
- if (new_millis<last_millis){
- last_millis=new_millis;
- } else if ((millis()-last_millis ) > RF_PERIOD_MS ){
+ if (new_millis < last_millis_seek) {
+ last_millis_seek = new_millis;
+ } else if ((new_millis - last_millis_seek) > RF_PERIOD_SEEK_MS) {
rf_seek();
- last_millis = new_millis;
+ last_millis_seek = new_millis;
}
+ if (new_millis < last_millis_reset) {
+ last_millis_reset = new_millis;
+ } else if ((new_millis - last_millis_reset) > RF_PERIOD_RESET_MS) {
+ rf_reset();
+ last_millis_reset = new_millis;
+ }
+
if (rfid.available()){
- /*if(rf_bytes[2] > 2 && rf_bytes[3]==0x82){
- //Message has id
- }*/
//Message received
uint8_t *rf_bytes = rfid.getTagNumber();
#ifdef DEBUG