Revision 1b054655
Fixes. It tooltrons at a basic level now.
toolbox/main.c | ||
---|---|---|
19 | 19 |
|
20 | 20 |
static enum toolstate_t toolstate = TS_INIT; |
21 | 21 |
static uint8_t coils; |
22 |
static uint8_t latest_reading[RFID_SERNO_SIZE]; |
|
22 | 23 |
static uint8_t current_user[RFID_SERNO_SIZE]; |
23 | 24 |
|
24 | 25 |
static inline void set_coil(char coil, char bit) { |
... | ... | |
32 | 33 |
static inline void tool_enable() {PORTA |= _BV(PA1);} |
33 | 34 |
static inline void tool_disable() {PORTA &= ~ _BV(PA1);} |
34 | 35 |
|
36 |
static char serno_zero(uint8_t *serno) { |
|
37 |
memset(serno, 0, RFID_SERNO_SIZE); |
|
38 |
} |
|
39 |
|
|
40 |
static char serno_is_nonzero(uint8_t *serno) { |
|
41 |
int i; |
|
42 |
for (i = 0; i < RFID_SERNO_SIZE; i++) { |
|
43 |
if (serno[i]) { |
|
44 |
return 1; |
|
45 |
} |
|
46 |
} |
|
47 |
return 0; |
|
48 |
} |
|
49 |
|
|
50 |
static char serno_equal(uint8_t *a, uint8_t *b) { |
|
51 |
return memcmp(a, b, RFID_SERNO_SIZE) == 0; |
|
52 |
} |
|
53 |
|
|
54 |
static void serno_cpy(uint8_t *dest, uint8_t *src) { |
|
55 |
memcpy(dest, src, RFID_SERNO_SIZE); |
|
56 |
} |
|
57 |
|
|
35 | 58 |
static void tool_main() { |
36 | 59 |
|
37 | 60 |
switch (toolstate) { |
... | ... | |
46 | 69 |
break; |
47 | 70 |
|
48 | 71 |
case TS_OFF: |
49 |
if (rfid_nonzero()) { |
|
50 |
rfid_get_serno(current_user); |
|
72 |
led_red(); |
|
73 |
if (serno_is_nonzero(latest_reading)) { |
|
74 |
serno_cpy(current_user, latest_reading); |
|
51 | 75 |
set_coil(MB_COIL_NEW, 1); |
52 | 76 |
toolstate = TS_WAIT_ACCESS; |
53 | 77 |
} |
54 | 78 |
break; |
55 | 79 |
|
56 | 80 |
case TS_WAIT_ACCESS: |
81 |
led_yellow(); |
|
57 | 82 |
if (get_coil(MB_COIL_EN)) { |
58 | 83 |
tool_enable(); |
59 | 84 |
toolstate = TS_ON; |
... | ... | |
73 | 98 |
set_coil(MB_COIL_EN, 0); |
74 | 99 |
set_coil(MB_COIL_REQ_DIS, 0); |
75 | 100 |
tool_disable(); |
101 |
serno_zero(current_user); |
|
76 | 102 |
toolstate = TS_OFF; |
77 | 103 |
} |
78 | 104 |
break; |
... | ... | |
83 | 109 |
toolstate = TS_OFF; |
84 | 110 |
} else if (get_coil(MB_COIL_REQ_DIS)) { |
85 | 111 |
toolstate = TS_REQ_DIS; |
86 |
} else if (rfid_check_serno(current_user)) {
|
|
112 |
} else if (serno_equal(current_user, latest_reading)) {
|
|
87 | 113 |
toolstate = TS_ON; |
88 | 114 |
} else { |
89 | 115 |
if (led_blink_done()) { |
90 | 116 |
set_coil(MB_COIL_EN, 0); |
91 | 117 |
tool_disable(); |
118 |
serno_zero(current_user); |
|
92 | 119 |
toolstate = TS_OFF; |
93 | 120 |
} |
94 | 121 |
} |
95 | 122 |
break; |
96 | 123 |
|
97 | 124 |
case TS_ON: |
125 |
led_green(); |
|
98 | 126 |
if (!get_coil(MB_COIL_EN)) { |
99 | 127 |
tool_disable(); |
128 |
serno_zero(current_user); |
|
100 | 129 |
toolstate = TS_OFF; |
101 | 130 |
} else if(get_coil(MB_COIL_REQ_DIS)) { |
102 | 131 |
toolstate = TS_REQ_DIS; |
103 |
} else if (!rfid_check_serno(current_user)) {
|
|
132 |
} else if (!serno_equal(current_user, latest_reading)) {
|
|
104 | 133 |
toolstate = TS_MISSING_ID; |
105 |
led_blink_start(); |
|
134 |
led_blink_start(666, 6);
|
|
106 | 135 |
} |
107 | 136 |
break; |
108 | 137 |
|
... | ... | |
231 | 260 |
rfid_start_read(); |
232 | 261 |
while (1) { |
233 | 262 |
if (rfid_poll()) { |
234 |
rfid_get_serno(current_user);
|
|
263 |
rfid_get_serno(latest_reading);
|
|
235 | 264 |
rfid_start_read(); |
236 | 265 |
} |
237 | 266 |
tool_main(); |
Also available in: Unified diff