2013-08-26 01:08:00 +02:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdint.h>
|
2012-07-17 01:05:27 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
#include <avr/io.h>
|
2012-07-26 01:34:49 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
#include <pentabug/app.h>
|
|
|
|
#include <pentabug/lifecycle.h>
|
2012-10-11 18:59:09 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
static inline void reset_hw(void) {
|
|
|
|
DDRB = 0;
|
|
|
|
DDRC = 0;
|
|
|
|
DDRD = 0;
|
2012-10-03 23:41:15 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
PORTB = 0;
|
|
|
|
PORTC = 0;
|
|
|
|
PORTD = 0;
|
2012-10-11 00:29:15 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
PINB = 0;
|
|
|
|
PINC = 0;
|
|
|
|
PIND = 0;
|
|
|
|
}
|
2012-10-10 04:15:06 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
static inline void run_app(struct app_t* app) {
|
|
|
|
if(enter_app()) {
|
|
|
|
// this is the exit
|
|
|
|
if(app->cleanup) {
|
|
|
|
app->cleanup();
|
|
|
|
}
|
2012-10-07 00:52:53 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
return;
|
2012-10-11 14:44:38 +02:00
|
|
|
}
|
2013-08-26 01:08:00 +02:00
|
|
|
|
|
|
|
if(app->init) {
|
|
|
|
app->init();
|
2012-10-11 14:44:38 +02:00
|
|
|
}
|
2013-08-26 01:08:00 +02:00
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
app->run();
|
|
|
|
test_stop_app();
|
2012-10-11 14:44:38 +02:00
|
|
|
}
|
2012-10-07 00:52:53 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
int main(void) {
|
|
|
|
uint8_t app_index = 0;
|
|
|
|
int8_t direction = 1;
|
2012-10-11 14:44:38 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
// we need to get real fast (8MHz) to handle 38kHz IR frequency ...
|
2012-10-11 18:59:09 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
CLKPR = 0b10000000;
|
|
|
|
CLKPR = 0b00000000;
|
|
|
|
|
|
|
|
// cycle through apps
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
reset_hw();
|
|
|
|
|
|
|
|
run_app(&apps[app_index]);
|
|
|
|
|
|
|
|
for(;;);
|
2012-10-11 18:59:09 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
if(direction > 0) {
|
|
|
|
app_index++;
|
|
|
|
|
|
|
|
if(apps[app_index].run == NULL) {
|
|
|
|
app_index = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(app_index == 0) {
|
|
|
|
app_index = MAX_APPS - 1;
|
|
|
|
while(apps[app_index].run == NULL) --app_index;
|
|
|
|
} else {
|
|
|
|
app_index--;
|
|
|
|
}
|
2012-10-10 04:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-26 01:08:00 +02:00
|
|
|
|
2012-07-18 15:55:20 +02:00
|
|
|
}
|