Revision 94548bf4 toolbox/main.c

View differences:

toolbox/main.c
8 8
#include "rfid.h"
9 9
#include "led.h"
10 10
#include "current.h"
11
#include "time.h"
11 12

  
12 13
enum toolstate_t {
13 14
  TS_INIT,
......
58 59
  memcpy(dest, src, RFID_SERNO_SIZE);
59 60
}
60 61

  
61
static void tool_main() {
62
static void tool_tick() {
62 63

  
63 64
  switch (toolstate) {
64 65

  
......
261 262
}
262 263

  
263 264
int main() {
265
  char rfid_ticks = 0;
264 266

  
267
  time_init();
265 268
  led_init();
266 269
  tool_init();
267 270
  rfid_init();
271
  current_init();
268 272

  
269 273
  eMBInit(MB_RTU, SLAVE_ADDR, 0, MB_BAUD, MB_PAR_NONE);
270 274
  eMBEnable();
......
273 277

  
274 278
  rfid_start_read();
275 279
  while (1) {
276
    if (rfid_poll()) {
277
      rfid_get_serno(latest_reading);
278
      rfid_start_read();
280
    if (++rfid_ticks >= RFID_PERIOD/TICK_MS)
281
    {
282
      rfid_ticks = 0;
283
      if (rfid_poll()) {
284
        rfid_get_serno(latest_reading);
285
        rfid_start_read();
286
      } else {
287
        /* TODO count # times rfid_poll returns each value and see how often we
288
         * have to wait */
289
      }
279 290
    }
280 291
    current = current_read();
281
    tool_main();
292
    tool_tick();
293
    led_tick();
282 294
    eMBPoll();
283
    _delay_ms(100);
295
    time_wait();
284 296
  }
285 297

  
286 298
  return 0;

Also available in: Unified diff