2017-08-01 21:29:57 +00:00
|
|
|
#include <stdint.h>
|
2017-08-02 20:21:59 +00:00
|
|
|
#include <stdlib.h>
|
2017-08-01 21:29:57 +00:00
|
|
|
#include <util/delay.h>
|
|
|
|
#include <ssd1306xled.h>
|
2017-08-02 14:54:31 +00:00
|
|
|
#include "power.h"
|
2017-08-02 14:17:23 +00:00
|
|
|
#include "buttons.h"
|
2017-08-05 19:59:07 +00:00
|
|
|
#include "screen/state.h"
|
2017-08-01 21:29:57 +00:00
|
|
|
#include "screen/counter.h"
|
2017-08-05 19:59:07 +00:00
|
|
|
#include "screen/menu.h"
|
2017-08-01 21:29:57 +00:00
|
|
|
|
2017-08-02 14:17:23 +00:00
|
|
|
|
2017-08-01 21:29:57 +00:00
|
|
|
// Forward declarations
|
|
|
|
void handleCurrentScreen();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2017-08-02 14:54:31 +00:00
|
|
|
// Delay is required on power-on for the SSD1306 to initialize,
|
|
|
|
_delay_ms(40);
|
|
|
|
ssd1306_init();
|
2017-08-02 15:53:12 +00:00
|
|
|
ssd1306_clear();
|
2017-08-02 14:54:31 +00:00
|
|
|
|
2017-08-02 14:17:23 +00:00
|
|
|
buttons_init();
|
|
|
|
|
2017-08-05 19:59:07 +00:00
|
|
|
setCurrentScreen(Counter);
|
|
|
|
|
2017-08-01 21:29:57 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2017-08-02 14:17:23 +00:00
|
|
|
checkPower();
|
2017-08-05 19:59:07 +00:00
|
|
|
if (powerState == On)
|
2017-08-02 14:54:31 +00:00
|
|
|
{
|
2017-08-05 19:59:07 +00:00
|
|
|
handleCurrentScreen();
|
2017-08-02 20:21:59 +00:00
|
|
|
|
2017-08-05 19:59:07 +00:00
|
|
|
if (!buttons_active() && !peekScreenInvalidated())
|
|
|
|
sleepUntilButton(_BV(BUTTON_UP) | _BV(BUTTON_DOWN) | _BV(BUTTON_OPTION));
|
2017-08-02 14:54:31 +00:00
|
|
|
}
|
2017-08-01 21:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-05 19:59:07 +00:00
|
|
|
void handleCurrentScreen()
|
2017-08-01 21:29:57 +00:00
|
|
|
{
|
2017-08-05 19:59:07 +00:00
|
|
|
switch (currentScreen)
|
2017-08-02 14:17:23 +00:00
|
|
|
{
|
2017-08-05 19:59:07 +00:00
|
|
|
case Counter: handleCounterScreen(); break;
|
|
|
|
case Menu: handleMenuScreen(); break;
|
2017-08-02 14:17:23 +00:00
|
|
|
}
|
2017-08-01 21:29:57 +00:00
|
|
|
}
|