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 20:39:15 +02:00
|
|
|
#include <pentabug/hal.h>
|
2013-08-26 01:08:00 +02:00
|
|
|
#include <pentabug/app.h>
|
|
|
|
#include <pentabug/lifecycle.h>
|
2013-08-27 00:22:38 +02:00
|
|
|
#include <pentabug/music.h>
|
|
|
|
#include <pentabug/helper.h>
|
|
|
|
|
2013-08-29 23:09:01 +02:00
|
|
|
static uint16_t up_mldy[] = { NOTE_C, NOTE_D, MLDY_LENGTH, 2, NOTE_F, NOTE_PAUSE };
|
|
|
|
static uint16_t down_mldy[] = { NOTE_F, NOTE_E, MLDY_LENGTH, 2, NOTE_C, NOTE_PAUSE };
|
2012-10-11 18:59:09 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
static inline void run_app(struct app_t* app) {
|
2013-08-26 20:39:15 +02:00
|
|
|
app_should_stop = 0;
|
|
|
|
|
2013-08-26 02:30:05 +02:00
|
|
|
if(setjmp(app_jmp_buf) == 0) {
|
2013-08-26 20:39:15 +02:00
|
|
|
// initial call
|
|
|
|
|
2013-08-26 02:30:05 +02:00
|
|
|
if(app->init) {
|
|
|
|
app->init();
|
2013-08-26 01:08:00 +02:00
|
|
|
}
|
2012-10-07 00:52:53 +02:00
|
|
|
|
2013-08-26 02:30:05 +02:00
|
|
|
for(;;) {
|
|
|
|
app->run();
|
|
|
|
test_stop_app();
|
|
|
|
}
|
2012-10-11 14:44:38 +02:00
|
|
|
}
|
2013-08-26 01:08:00 +02:00
|
|
|
|
2013-08-26 20:39:15 +02:00
|
|
|
// returned after longjmp()
|
|
|
|
|
2013-08-26 02:30:05 +02:00
|
|
|
if(app->cleanup) {
|
|
|
|
app->cleanup();
|
2012-10-11 14:44:38 +02:00
|
|
|
}
|
2013-08-26 01:08:00 +02:00
|
|
|
|
2013-08-26 02:30:05 +02:00
|
|
|
return;
|
2012-10-07 00:52:53 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
int main(void) {
|
|
|
|
uint8_t app_index = 0;
|
2012-10-11 18:59:09 +02:00
|
|
|
|
2013-08-26 20:39:15 +02:00
|
|
|
init_hw();
|
2013-08-26 01:08:00 +02:00
|
|
|
|
|
|
|
// cycle through apps
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
reset_hw();
|
|
|
|
|
|
|
|
run_app(&apps[app_index]);
|
|
|
|
|
2013-08-27 00:22:38 +02:00
|
|
|
reset_hw();
|
|
|
|
|
2013-08-26 20:39:15 +02:00
|
|
|
if(app_direction > 0) {
|
2013-08-29 23:09:01 +02:00
|
|
|
play_melody(up_mldy, ARRAY_SIZE(up_mldy), 4, 100);
|
2013-08-27 00:22:38 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
app_index++;
|
|
|
|
|
|
|
|
if(apps[app_index].run == NULL) {
|
|
|
|
app_index = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2013-08-29 23:09:01 +02:00
|
|
|
play_melody(down_mldy, ARRAY_SIZE(down_mldy), 4, 100);
|
2013-08-27 00:22:38 +02:00
|
|
|
|
2013-08-26 01:08:00 +02:00
|
|
|
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
|
|
|
}
|