X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/2f7e8f0d886a19a7407e80fa8e5e7b064237b3fc..cb0bd1585f0e7ca7fb0f23b571ca558fd810a48f:/badge/main.c diff --git a/badge/main.c b/badge/main.c index c225b4e..c62cd7d 100644 --- a/badge/main.c +++ b/badge/main.c @@ -53,12 +53,15 @@ #include "core/cmd/cmd.h" #endif +#include "fahrplan.h" #include "init.h" +#include "ui/browser.h" #include "ui/display.h" #include "ui/event.h" #include "ui/font.h" #include "ui/menu.h" #include "ui/sprite.h" +#include "ui/vanity.h" #include "util/util.h" #include "jumpnrun/jumpnrun.h" @@ -109,16 +112,6 @@ void rbInit() { uint32_t volatile *reg; gpioPullupMode_t mode; } const input_pins[] = { -#ifdef HOB_REV2 - { RB_BTN0 , &RB_BTN0_IO , gpioPullupMode_PullDown }, - { RB_BTN1 , &RB_BTN1_IO , gpioPullupMode_PullDown }, - { RB_BTN2 , &RB_BTN2_IO , gpioPullupMode_PullDown }, - { RB_BTN3 , &RB_BTN3_IO , gpioPullupMode_PullDown }, - { RB_BTN4 , &RB_BTN4_IO , gpioPullupMode_PullDown }, - { RB_HB0 , &RB_HB0_IO , gpioPullupMode_PullDown }, - { RB_HB1 , &RB_HB1_IO , gpioPullupMode_PullDown }, - { RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullDown } -#else { RB_BTN0 , &RB_BTN0_IO , gpioPullupMode_PullUp }, { RB_BTN1 , &RB_BTN1_IO , gpioPullupMode_PullUp }, { RB_BTN2 , &RB_BTN2_IO , gpioPullupMode_PullUp }, @@ -127,7 +120,6 @@ void rbInit() { { RB_HB0 , &RB_HB0_IO , gpioPullupMode_PullUp }, { RB_HB1 , &RB_HB1_IO , gpioPullupMode_PullUp }, { RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullUp } -#endif }; for(int i = 0; i < ARRAY_SIZE(input_pins); ++i) { @@ -184,60 +176,55 @@ void rbInit() { #endif -void usbmode(void) { - badge_framebuffer fb = { { { 0 } } }; +static void usbmode(void) { + badge_event_stop(); - badge_framebuffer_render_text(&fb, 23, 30, "USB-Modus"); + badge_framebuffer fb = { { { 0 } } }; + badge_framebuffer_render_text(&fb, 22, 20, "USB-Modus"); +// badge_framebuffer_render_text(&fb, 10, 35, "Reset to exit"); + badge_framebuffer_render_text(&fb, 16, 35, "Zurück mit"); + badge_framebuffer_render_text(&fb, 32, 45, "Reset"); /* badge_framebuffer_render_number(&fb, 23, 50, sizeof(jumpnrun_tile)); badge_framebuffer_render_number(&fb, 33, 50, sizeof(jumpnrun_item)); badge_framebuffer_render_number(&fb, 48, 50, sizeof(jumpnrun_enemy)); */ - badge_framebuffer_flush(&fb); - usbMSCInit(); - for(;;); + badge_framebuffer_flush(&fb); + + usbMSCInit(); + + for(;;) { +// pmuSleep(); + } } -void scrolltest(void) { - char menu_buf[][15] = { - "foo", - "bar", - "baz", - "qux", - "foo", - "bar", - "baz", - "qux", - "foo", - "bar", - "baz", - "qux", - "foo", - "bar", - "baz", - "qux", +uint8_t main_menu_show(uint8_t selected) { + // first_visible = 0, weil das Menü so kurz ist. Sollte es + // größer werden: Parameter aus main_menu empfangen und merken. + uint8_t first_visible = 0; + char const *const menu[] = { + "Titelbild", + "Super Hackio", + "Fahrplan", + "USB-Modus" }; - char const * menu_index[] = { - menu_buf[0], - menu_buf[1], - menu_buf[2], - menu_buf[3], - menu_buf[4], - menu_buf[5], - menu_buf[6], - menu_buf[7], - menu_buf[8], - menu_buf[9], - menu_buf[10], - menu_buf[11], - menu_buf[12], - menu_buf[13], - menu_buf[14], - menu_buf[15] - }; + f_chdir("/"); + return (uint8_t) badge_menu(menu, ARRAY_SIZE(menu), &first_visible, selected); +} - badge_scroll_text(menu_index, 16); +void main_menu(void) { + uint8_t selected = 0; + + for(;;) { + selected = main_menu_show(selected); + switch(selected) { + case 0: badge_vanity_show(); break; + case 1: jumpnrun_play (); break; + case 2: badge_fahrplan (); break; + case 3: usbmode (); break; + } + } } int main(void) @@ -245,7 +232,7 @@ int main(void) cpuInit(); systickInit(CFG_SYSTICK_DELAY_IN_MS); - // pmuInit(); + pmuInit(); // adcInit(); #ifdef R0KET rbInit(); @@ -256,18 +243,24 @@ int main(void) FATFS fs; f_mount(0, &fs); +#ifdef USBONLY + if(badge_input_raw() & BADGE_EVENT_KEY_LEFT) { + gpioSetValue(HOB_PORT(HOB_LED_LEFT), HOB_PIN(HOB_LED_LEFT) , 1); + } + if(badge_input_raw() & BADGE_EVENT_KEY_RIGHT) { + gpioSetValue(HOB_PORT(HOB_LED_RIGHT), HOB_PIN(HOB_LED_RIGHT) , 1); + } + + for(;;) usbmode(); +#else if(badge_input_raw() & BADGE_EVENT_KEY_DOWN) { usbmode(); } badge_event_start(); - - if(badge_input_raw() & BADGE_EVENT_KEY_UP) { - scrolltest(); - } - - jumpnrun_play(); - usbmode(); + badge_vanity_show(); + main_menu(); +#endif return 0; }