Stairs/module/src/main.c

84 lines
1.2 KiB
C
Raw Normal View History

/*
* Stairs lighting
* Copyright 2017 (c) Mark van Renswoude
*
* https://git.x2software.net/pub/Stairs
*/
#include <stdint.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "lib/TinyMillis.h"
#include "lib/TinyUART.h"
#include "lib/TinyRS485.h"
#include "global.h"
#include "display.h"
#define STEPS_DELAY_SHORT 200
#define STEPS_DELAY 800
#define STEPS_DELAY_LONG 2000
uint8_t uartRead(void)
{
return uart_getc();
}
uint8_t uartAvailable(void)
{
return uart_available();
}
void uartWrite(uint8_t what)
{
uart_putc(what);
}
typedef enum
{
WaitingForComm,
Connected
} State;
State currentState = WaitingForComm;
int main(void)
{
// Allow peripherals to start up before sending messages
_delay_ms(40);
global_init();
millis_init();
sei();
uart_init();
rs485_begin(uartRead, uartAvailable, uartWrite, 20);
display_init();
for (;;)
{
if (rs485_update())
{
// TODO get data
currentState = Connected;
}
switch (currentState)
{
case WaitingForComm:
display_drawWait();
break;
case Connected:
display_drawIndex();
break;
}
}
return 0;
}