diff --git a/f103-ledmatrix.pro b/f103-ledmatrix.pro index 3a64fc6..7c40550 100644 --- a/f103-ledmatrix.pro +++ b/f103-ledmatrix.pro @@ -93,7 +93,9 @@ HEADERS += \ lib/cmsis/DSP_Lib/Include/core_cmSimd.h \ project/mode_audio.h \ project/font.h \ - project/scrolltext.h + project/scrolltext.h \ + project/mode_snake.h \ + project/mode_life.h SOURCES += \ lib/cmsis/core_cm3.c \ @@ -425,7 +427,9 @@ SOURCES += \ lib/cmsis/DSP_Lib/Source/TransformFunctions/arm_rfft_q15.c \ lib/cmsis/DSP_Lib/Source/TransformFunctions/arm_rfft_q31.c \ project/mode_audio.c \ - project/scrolltext.c + project/scrolltext.c \ + project/mode_snake.c \ + project/mode_life.c DISTFILES += \ style.astylerc \ diff --git a/project/main.c b/project/main.c index 7c00c77..856b351 100644 --- a/project/main.c +++ b/project/main.c @@ -15,8 +15,11 @@ #include "dotmatrix.h" -#include "arm_math.h" +#include + #include "mode_audio.h" +#include "mode_snake.h" +#include "mode_life.h" #include "scrolltext.h" @@ -68,21 +71,20 @@ static void activate_mode(void) info("MODE: Life"); scrolltext("Game of Life", SCROLL_STEP); - // + mode_life_start(); } else { - // + mode_life_stop(); } // --- Snake Minigame --- if (app_mode == MODE_SNAKE) { info("MODE: Snake"); - scrolltext("Snake", SCROLL_STEP); - // + mode_snake_start(); } else { - // + mode_snake_stop(); } } @@ -94,11 +96,12 @@ int main(void) banner("*** FFT dot matrix display ***"); banner_info("(c) Ondrej Hruska, 2016"); - scrolltext("STM32 LED MATRIX DEMO", SCROLL_STEP); - gamepad_iface->rx_callback = gamepad_rx; mode_audio_init(); + mode_life_init(); + mode_snake_init(); + mode_audio_start(); ms_time_t last; @@ -137,14 +140,29 @@ static void poll_subsystems(void) static void gamepad_rx(ComIface *iface) { - uint8_t ch; - while(com_rx(iface, &ch)) { -// com_tx(debug_iface, ch); -// com_tx(debug_iface, '\n'); - - /* SELECT */ - if (ch == 'I') { - tq_post(switch_mode, NULL); + char ch; + while(com_rx(iface, (uint8_t*)&ch)) { + switch (ch) { + case 'I': // Select pressed + tq_post(switch_mode, NULL); + break; + case 'i': // Select released + break; + + default: + switch (app_mode) { + case MODE_AUDIO: + // discard + break; + + case MODE_LIFE: + mode_life_btn(ch); + break; + + case MODE_SNAKE: + mode_snake_btn(ch); + break; + } } } } diff --git a/project/mode_audio.c b/project/mode_audio.c index 332ffa4..5c06f6f 100644 --- a/project/mode_audio.c +++ b/project/mode_audio.c @@ -24,9 +24,9 @@ static union samp_buf_union samp_buf; static task_pid_t capture_task_id; - // prototypes static void audio_capture_done(void* unused); +static void capture_audio(void *unused); static void boot_animation(void) @@ -102,12 +102,7 @@ void DMA1_Channel1_IRQHandler(void) TIM_Cmd(TIM3, DISABLE); ADC_DMACmd(ADC1, DISABLE); - if (audio_mode_active) { - tq_post(audio_capture_done, NULL); - } else { - // unset 'pending' - capture_pending = false; - } + tq_post(audio_capture_done, NULL); } @@ -116,6 +111,11 @@ static void audio_capture_done(void* unused) { (void)unused; + if (! audio_mode_active) { + capture_pending = false; + return; + } + const int samp_count = SAMP_BUF_LEN/2; const int bin_count = SAMP_BUF_LEN/4; diff --git a/project/mode_audio.h b/project/mode_audio.h index 445d896..8c4e08c 100644 --- a/project/mode_audio.h +++ b/project/mode_audio.h @@ -3,8 +3,6 @@ #include "main.h" -void capture_audio(void *unused); - void mode_audio_init(void); void mode_audio_start(void); void mode_audio_stop(void); diff --git a/project/mode_life.c b/project/mode_life.c new file mode 100644 index 0000000..8fd4138 --- /dev/null +++ b/project/mode_life.c @@ -0,0 +1,21 @@ +#include "mode_life.h" + +void mode_life_init(void) +{ + // +} + +void mode_life_start(void) +{ + // +} + +void mode_life_stop(void) +{ + // +} + +void mode_life_btn(char key) +{ + // +} diff --git a/project/mode_life.h b/project/mode_life.h new file mode 100644 index 0000000..57dc015 --- /dev/null +++ b/project/mode_life.h @@ -0,0 +1,11 @@ +#ifndef MODE_LIFE_H +#define MODE_LIFE_H + +#include "main.h" + +void mode_life_init(void); +void mode_life_start(void); +void mode_life_stop(void); +void mode_life_btn(char key); + +#endif // MODE_LIFE_H diff --git a/project/mode_snake.c b/project/mode_snake.c new file mode 100644 index 0000000..8a2d2a5 --- /dev/null +++ b/project/mode_snake.c @@ -0,0 +1,21 @@ +#include "mode_snake.h" + +void mode_snake_init(void) +{ + // +} + +void mode_snake_start(void) +{ + // +} + +void mode_snake_stop(void) +{ + // +} + +void mode_snake_btn(char key) +{ + // +} diff --git a/project/mode_snake.h b/project/mode_snake.h new file mode 100644 index 0000000..8b4c91e --- /dev/null +++ b/project/mode_snake.h @@ -0,0 +1,11 @@ +#ifndef MODE_SNAKE_H +#define MODE_SNAKE_H + +#include "main.h" + +void mode_snake_init(void); +void mode_snake_start(void); +void mode_snake_stop(void); +void mode_snake_btn(char key); + +#endif // MODE_SNAKE_H