From 13f9e8ff2bcbae7143a116f726e92cb0fc4fabc0 Mon Sep 17 00:00:00 2001 From: whowechina Date: Sun, 30 Apr 2023 23:20:03 +0800 Subject: [PATCH] TT theme setup --- firmware/src/main.c | 10 ++++------ firmware/src/rgb.c | 7 +++++-- firmware/src/setup.c | 24 +++++++++++++++++++++--- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/firmware/src/main.c b/firmware/src/main.c index 4acf963..a601e15 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -105,14 +105,12 @@ static void core0_loop() uint16_t angle = turntable_read() >> 4; if (setup_run(buttons, angle)) { rgb_force_display(setup_led_button, setup_led_tt); - report_usb_hid(); - continue; + } else { + hid_report.buttons = buttons; + rgb_set_button_light(buttons); + save_loop(); } - - hid_report.buttons = buttons; report_usb_hid(); - rgb_set_button_light(buttons); - save_loop(); } } diff --git a/firmware/src/rgb.c b/firmware/src/rgb.c index 695dbe7..bffd0c9 100644 --- a/firmware/src/rgb.c +++ b/firmware/src/rgb.c @@ -29,7 +29,7 @@ uint32_t rgb_max_level = 255; static void trap() {} static tt_effect_t effects[10] = { {trap, trap, trap, trap, 0} }; static size_t effect_num = 0; -static size_t current_effect = 0; +static unsigned current_effect = 0; #define _MAP_LED(x) _MAKE_MAPPER(x) #define _MAKE_MAPPER(x) MAP_LED_##x @@ -97,6 +97,8 @@ void set_effect(uint32_t index) if (index < effect_num) { current_effect = index; effects[current_effect].init(effects[current_effect].context); + } else { + current_effect = effect_num; } } @@ -256,7 +258,6 @@ void rgb_init() ws2812_program_init(pio0, 0, pio0_offset, BUTTON_RGB_PIN, 800000, false); /* We don't start the tt LED program yet */ - set_effect(1); } static void follow_mode_change() @@ -276,6 +277,7 @@ static void follow_mode_change() void rgb_update() { follow_mode_change(); + set_effect(iidx_cfg->tt_led.effect); if (time_us_64() > force_expire_time) { effect_update(); button_lights_update(); @@ -289,4 +291,5 @@ void rgb_reg_tt_effect(tt_effect_t effect) { effects[effect_num] = effect; effect_num++; + effects[effect_num] = (tt_effect_t) { trap, trap, trap, trap, 0 }; } diff --git a/firmware/src/setup.c b/firmware/src/setup.c index 707dd99..cb2401a 100644 --- a/firmware/src/setup.c +++ b/firmware/src/setup.c @@ -541,7 +541,7 @@ static void key_theme_key_change() check_exit(); } -static void key_them_loop() +static void key_theme_loop() { for (int i = 0; i < 11; i++) { if (blink_slow) { @@ -552,6 +552,24 @@ static void key_them_loop() } } +static void tt_theme_key_change() +{ + for (int i = 0; i < 7; i++) { + if (JUST_PRESSED(KEY_1 << i)) { + iidx_cfg->tt_led.effect = i; + break; + } + } + check_exit(); +} + +static void tt_theme_loop() +{ + for (int i = 0; i < 7; i++) { + setup_led_button[i] = iidx_cfg->tt_led.effect == i ? SILVER : 0; + } +} + static struct { mode_func key_change; mode_func rotate; @@ -561,8 +579,8 @@ static struct { [MODE_NONE] = { nop, nop, none_loop, nop}, [MODE_TURNTABLE] = { tt_key_change, tt_rotate, tt_loop, tt_enter}, [MODE_ANALOG] = { analog_key_change, analog_rotate, analog_loop, analog_enter}, - [MODE_TT_THEME] = { nop, nop, check_exit, nop}, - [MODE_KEY_THEME] = { key_theme_key_change, nop, key_them_loop, nop}, + [MODE_TT_THEME] = { tt_theme_key_change, nop, tt_theme_loop, nop}, + [MODE_KEY_THEME] = { key_theme_key_change, nop, key_theme_loop, nop}, [MODE_KEY_OFF] = { key_change, key_rotate, key_loop, key_enter}, [MODE_KEY_ON] = { key_change, key_rotate, key_loop, key_enter}, };