mirror of
https://github.com/whowechina/iidx_pico.git
synced 2025-02-11 16:43:05 +01:00
Better setup mode
This commit is contained in:
parent
5344ea93c5
commit
dad3945300
Binary file not shown.
@ -47,7 +47,7 @@ uint8_t button_gpio(uint8_t id)
|
||||
}
|
||||
|
||||
/* If a switch flips, it freezes for a while */
|
||||
#define DEBOUNCE_FREEZE_TIME_US 1000
|
||||
#define DEBOUNCE_FREEZE_TIME_US 5000
|
||||
uint16_t button_read()
|
||||
{
|
||||
uint64_t now = time_us_64();
|
||||
|
@ -32,8 +32,6 @@ static tt_effect_t effects[10] = { {trap, trap, trap, trap, 0} };
|
||||
static size_t effect_num = 0;
|
||||
static size_t current_effect = 0;
|
||||
|
||||
static uint8_t current_mode = 0;
|
||||
|
||||
#define _MAP_LED(x) _MAKE_MAPPER(x)
|
||||
#define _MAKE_MAPPER(x) MAP_LED_##x
|
||||
#define MAP_LED_RGB { c1 = r; c2 = g; c3 = b; }
|
||||
@ -222,8 +220,6 @@ void rgb_force_display(uint32_t *buttons, uint32_t *tt)
|
||||
force_expire_time = time_us_64() + FORCE_EXPIRE_DURATION;
|
||||
}
|
||||
|
||||
static bool pio1_loaded = false;
|
||||
|
||||
static void wipe_out_tt_led()
|
||||
{
|
||||
sleep_ms(5);
|
||||
@ -233,66 +229,50 @@ static void wipe_out_tt_led()
|
||||
sleep_ms(5);
|
||||
}
|
||||
|
||||
static void start_pio1()
|
||||
static uint pio1_offset;
|
||||
static bool pio1_running = false;
|
||||
|
||||
static void pio1_run()
|
||||
{
|
||||
if (pio1_loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_set_drive_strength(TT_RGB_PIN, GPIO_DRIVE_STRENGTH_8MA);
|
||||
uint offset = pio_add_program(pio1, &ws2812_program);
|
||||
ws2812_program_init(pio1, 0, offset, TT_RGB_PIN, 800000, false);
|
||||
rgb_set_level(8);
|
||||
set_effect(1);
|
||||
|
||||
pio1_loaded = true;
|
||||
ws2812_program_init(pio1, 0, pio1_offset, TT_RGB_PIN, 800000, false);
|
||||
}
|
||||
|
||||
static void stop_pio1()
|
||||
static void pio1_stop()
|
||||
{
|
||||
if (!pio1_loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
wipe_out_tt_led();
|
||||
|
||||
pio_sm_set_enabled(pio1, 0, false);
|
||||
pio_clear_instruction_memory(pio1);
|
||||
|
||||
gpio_set_function(TT_RGB_PIN, GPIO_FUNC_SIO);
|
||||
gpio_set_dir(TT_RGB_PIN, GPIO_IN);
|
||||
gpio_disable_pulls(TT_RGB_PIN);
|
||||
|
||||
pio1_loaded = false;
|
||||
}
|
||||
|
||||
void rgb_tt_init()
|
||||
{
|
||||
current_mode = iidx_cfg->tt_led.mode;
|
||||
if (current_mode == 2) {
|
||||
stop_pio1();
|
||||
} else {
|
||||
start_pio1();
|
||||
}
|
||||
}
|
||||
|
||||
static void rgb_button_init()
|
||||
{
|
||||
gpio_set_drive_strength(BUTTON_RGB_PIN, GPIO_DRIVE_STRENGTH_2MA);
|
||||
uint offset = pio_add_program(pio0, &ws2812_program);
|
||||
ws2812_program_init(pio0, 0, offset, BUTTON_RGB_PIN, 800000, false);
|
||||
}
|
||||
|
||||
void rgb_init()
|
||||
{
|
||||
rgb_tt_init();
|
||||
rgb_button_init();
|
||||
uint pio0_offset = pio_add_program(pio0, &ws2812_program);
|
||||
pio1_offset = pio_add_program(pio1, &ws2812_program);
|
||||
|
||||
gpio_set_drive_strength(BUTTON_RGB_PIN, GPIO_DRIVE_STRENGTH_2MA);
|
||||
ws2812_program_init(pio0, 0, pio0_offset, BUTTON_RGB_PIN, 800000, false);
|
||||
|
||||
/* We don't start the tt LED program yet */
|
||||
|
||||
rgb_set_level(8);
|
||||
set_effect(1);
|
||||
}
|
||||
|
||||
static void follow_mode_change()
|
||||
{
|
||||
if (current_mode != iidx_cfg->tt_led.mode) {
|
||||
rgb_tt_init();
|
||||
bool pio1_should_run = (iidx_cfg->tt_led.mode != 2);
|
||||
if (pio1_should_run == pio1_running) {
|
||||
return;
|
||||
}
|
||||
pio1_running = pio1_should_run;
|
||||
if (pio1_should_run) {
|
||||
pio1_run();
|
||||
} else {
|
||||
pio1_stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,9 +133,8 @@ static void mode_none_loop()
|
||||
}
|
||||
|
||||
static struct {
|
||||
bool adjust_led_start;
|
||||
uint8_t adjust_led; /* 0: nothing, 1: adjust start, 2: adjust stop */
|
||||
int16_t start_angle;
|
||||
uint8_t counter;
|
||||
} tt_ctx;
|
||||
|
||||
void mode_tt_enter()
|
||||
@ -146,10 +145,10 @@ void mode_tt_enter()
|
||||
static void mode_tt_key_change()
|
||||
{
|
||||
if (JUST_PRESSED(E_START)) {
|
||||
tt_ctx.adjust_led_start = true;
|
||||
tt_ctx.adjust_led = (tt_ctx.adjust_led == 1) ? 0 : 1;
|
||||
tt_ctx.start_angle = input.angle;
|
||||
} else if (JUST_PRESSED(E_EFFECT)) {
|
||||
tt_ctx.adjust_led_start = false;
|
||||
tt_ctx.adjust_led = (tt_ctx.adjust_led == 2) ? 0 : 2;
|
||||
tt_ctx.start_angle = input.angle;
|
||||
} else if (JUST_PRESSED(E_VEFX)) {
|
||||
iidx_cfg->tt_led.mode = (iidx_cfg->tt_led.mode + 1) % 3;
|
||||
@ -175,7 +174,7 @@ static void mode_tt_rotate()
|
||||
#define LED_START iidx_cfg->tt_led.start
|
||||
#define LED_NUM iidx_cfg->tt_led.num
|
||||
|
||||
if (tt_ctx.adjust_led_start) {
|
||||
if (tt_ctx.adjust_led == 1) {
|
||||
if ((delta > 0) & (LED_START < 8)) {
|
||||
LED_START++;
|
||||
if (LED_NUM > 1) {
|
||||
@ -185,7 +184,7 @@ static void mode_tt_rotate()
|
||||
LED_START--;
|
||||
LED_NUM++;
|
||||
}
|
||||
} else {
|
||||
} else if (tt_ctx.adjust_led == 2) {
|
||||
if ((delta > 0) & (LED_NUM + LED_START < 128)) {
|
||||
LED_NUM++;
|
||||
} else if ((delta < 0) & (LED_NUM > 1)) { // at least 1 led
|
||||
@ -211,14 +210,14 @@ void mode_tt_loop()
|
||||
|
||||
setup_led_tt[head] = tt_rgb32(0xa0, 0, 0, false);
|
||||
setup_led_tt[tail] = tt_rgb32(0, 0xa0, 0, false);
|
||||
setup_led_button[LED_E_EFFECT] = tt_rgb32(0, 10, 0, false);
|
||||
setup_led_button[LED_E_START] = tt_rgb32(10, 0, 0, false);
|
||||
|
||||
if (tt_ctx.adjust_led_start) {
|
||||
if (tt_ctx.adjust_led == 1) {
|
||||
setup_led_tt[head] &= mask;
|
||||
setup_led_button[LED_E_START] = tt_rgb32(128, 0, 0, false) & mask;
|
||||
setup_led_button[LED_E_EFFECT] = tt_rgb32(0, 10, 0, false);
|
||||
} else {
|
||||
} else if (tt_ctx.adjust_led == 2) {
|
||||
setup_led_tt[tail] &= mask;
|
||||
setup_led_button[LED_E_START] = tt_rgb32(10, 0, 0, false);
|
||||
setup_led_button[LED_E_EFFECT] = tt_rgb32(0, 128, 0, false) & mask;
|
||||
}
|
||||
|
||||
@ -230,10 +229,10 @@ void mode_tt_loop()
|
||||
|
||||
switch (iidx_cfg->tt_led.mode) {
|
||||
case 0:
|
||||
setup_led_button[LED_E_VEFX] = cyan;
|
||||
setup_led_button[LED_E_VEFX] = green;
|
||||
break;
|
||||
case 1:
|
||||
setup_led_button[LED_E_VEFX] = yellow;
|
||||
setup_led_button[LED_E_VEFX] = red;
|
||||
break;
|
||||
default:
|
||||
setup_led_button[LED_E_VEFX] = 0;
|
||||
|
@ -50,7 +50,7 @@ static void follow_mode_change()
|
||||
void turntable_init()
|
||||
{
|
||||
current_mode = iidx_cfg->tt_sensor.mode;
|
||||
if (current_mode & 0x02) {
|
||||
if (current_mode > 1) {
|
||||
init_i2c();
|
||||
} else {
|
||||
init_analog();
|
||||
@ -171,10 +171,10 @@ static void update_i2c()
|
||||
void turntable_update()
|
||||
{
|
||||
follow_mode_change();
|
||||
if (current_mode) {
|
||||
update_analog();
|
||||
} else {
|
||||
if (current_mode > 1) {
|
||||
update_i2c();
|
||||
} else {
|
||||
update_analog();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user