Revision bbf2f5ad
Added flushing before write to rfid reader
And other various fixes and changes, which I don't remember. Changed
rfid reading to read every tick, but only try writing if enough ticks
have passed.
toolbox/rfid.c | ||
---|---|---|
8 | 8 |
static uint8_t read_cmd[] = {'!', 'R', 'W', 1, 32}; |
9 | 9 |
|
10 | 10 |
static int serno_idx; |
11 |
static char n_failures; |
|
12 | 11 |
static uint8_t serno[RFID_SERNO_SIZE]; |
13 | 12 |
|
14 | 13 |
static void zero_serno() { |
... | ... | |
22 | 21 |
serial_init(); |
23 | 22 |
} |
24 | 23 |
|
25 |
static void restart_read() {
|
|
24 |
void rfid_start_read() {
|
|
26 | 25 |
serno_idx = -1; |
26 |
serial_flush(); |
|
27 | 27 |
serial_write(read_cmd, sizeof(read_cmd)); |
28 | 28 |
} |
29 | 29 |
|
30 |
void rfid_start_read() { |
|
31 |
n_failures = 0; |
|
32 |
restart_read(); |
|
33 |
} |
|
34 |
|
|
35 | 30 |
char rfid_poll() { |
36 | 31 |
int c; |
37 | 32 |
|
... | ... | |
39 | 34 |
|
40 | 35 |
if (serno_idx < 0) { |
41 | 36 |
if (c != RFID_OK) { |
42 |
n_failures++; |
|
43 |
if (n_failures >= RFID_N_FAILURES) { |
|
44 |
zero_serno(); |
|
45 |
return 1; |
|
46 |
} else { |
|
47 |
restart_read(); |
|
48 |
return 0; |
|
49 |
} |
|
37 |
zero_serno(); |
|
38 |
return 1; |
|
50 | 39 |
} |
51 | 40 |
} else { |
52 | 41 |
serno[serno_idx] = c; |
Also available in: Unified diff