RELEASE v0.0.1: parameter editor works, fixed bugs

This commit is contained in:
true 2024-08-05 22:28:20 -07:00
parent 64ac32160b
commit 4e7985273b
3 changed files with 75 additions and 25 deletions

View File

@ -3,6 +3,8 @@
* GAT Addon Firmware * GAT Addon Firmware
* by true * by true
* *
* version 0.0.1
*
* code was made for different random addons I designed for dc32, * code was made for different random addons I designed for dc32,
* then adapted to each one. so things might be a mess. * then adapted to each one. so things might be a mess.
* *
@ -52,8 +54,12 @@ void gpio_init()
gpio.GPIO_Pin = GPIO_Pin_1; gpio.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA, &gpio); GPIO_Init(GPIOA, &gpio);
// lightsense LED cathode
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
gpio.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOA, &gpio);
// lightsense LED anode // lightsense LED anode
gpio.GPIO_Mode = GPIO_Mode_Out_OD;
gpio.GPIO_Pin = GPIO_Pin_0; gpio.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOD, &gpio); GPIO_Init(GPIOD, &gpio);

View File

@ -221,7 +221,7 @@ void led_rgb_1_lite_then_fade(uint8_t preview, uint8_t tick)
end = 5; end = 5;
} }
} else { } else {
if ((preview & 0xf) != 1) { if (preview && ((preview & 0xf) != 1)) {
start = 9; start = 9;
} else { } else {
start = 5; start = 5;

View File

@ -60,6 +60,7 @@ static uint8_t config_save_timer;
void ui_btn_push_cb(uint8_t idx) void ui_btn_push_cb(uint8_t idx)
{ {
uint8_t i, w;
// are both buttons pushed? // are both buttons pushed?
if ((btn[0]._mask & BTN_PUSH) && (btn[1]._mask & BTN_PUSH)) { if ((btn[0]._mask & BTN_PUSH) && (btn[1]._mask & BTN_PUSH)) {
// are none held? // are none held?
@ -74,10 +75,29 @@ void ui_btn_push_cb(uint8_t idx)
// both buttons are pushed at the same time quickly, and not held // both buttons are pushed at the same time quickly, and not held
// this will toggle modes // this will toggle modes
mode++; mode++;
// parameter mode only works if a program is enabled to adjust
if (mode == MODE_PARAMETER) {
if (!userconf.ledprog_ena_mask) mode = MODE_RUN;
}
// parameter mode is the last mode
if (mode > MODE_PARAMETER) { if (mode > MODE_PARAMETER) {
mode = MODE_RUN; mode = MODE_RUN;
} }
// ensure a valid program is selected
if (mode == MODE_PARAMETER) {
w = preview_idx;
for (i = 0; i < 8; i++) {
w &= 0x7;
if (userconf.ledprog_ena_mask & (1 << w)) {
preview_idx = w;
break;
}
w++;
}
}
// reset any LED program // reset any LED program
led_rgb_firstrun(); led_rgb_firstrun();
@ -159,7 +179,17 @@ void ui_btn_push_cb(uint8_t idx)
void ui_btn_hold_cb(uint8_t idx) void ui_btn_hold_cb(uint8_t idx)
{ {
switch (mode) {
case MODE_PARAMETER: {
switch (idx) {
case 0: {
if (rgb_prog_is_editing) {
userconf.ledprog_setting[preview_idx][0]++;
}
}
}
}
}
} }
void ui_btn_release_cb(uint8_t idx) void ui_btn_release_cb(uint8_t idx)
@ -216,8 +246,7 @@ void ui_btn_release_cb(uint8_t idx)
* PROGRAM CHANGE MODE: cursor is on. * PROGRAM CHANGE MODE: cursor is on.
* *
* letters in RETRO show programs. by default, all are disabled. * letters in RETRO show programs. by default, all are disabled.
* enabled programs are bright. disabled programs are dim. * selected program will flash.
* selected program will flash. if program is on, will flash brightly. if off, it will flash dimly.
* *
* letters in TECH preview the currently selected program. * letters in TECH preview the currently selected program.
* letters in RETRO will each preview their own program (any flash / twinkle will always have idle light) * letters in RETRO will each preview their own program (any flash / twinkle will always have idle light)
@ -259,32 +288,25 @@ void ui_btn_release_cb(uint8_t idx)
*/ */
case MODE_PARAMETER: { case MODE_PARAMETER: {
switch (idx) { switch (idx) {
case 0: { // - top button: tapped or held: increment some parameter, with loop (speed, etc) case 0: { // - top button: when editing disabled: selects the next program
userconf.ledprog_setting[preview_idx][0]++; // when editing enabled: tapped or held: increments a value, with loop
break;
}
case 1: { // - bot button: when editing disabled: selects the next program
// when editing enabled: decrements some parameter, with loop (speed, etc)
// held: enables / disables editing the program (done in other callback)
if (rgb_prog_is_editing) { if (rgb_prog_is_editing) {
if (userconf.ledprog_setting[preview_idx][0]) { userconf.ledprog_setting[preview_idx][0]++;
userconf.ledprog_setting[preview_idx][0]--;
} else { } else {
userconf.ledprog_setting[preview_idx][0] = 0xff;
}
} else {
// select new program, except the last program, since that doesn't have a user editable config
w = preview_idx; w = preview_idx;
for (i = 0; i < 4; i++) { for (i = 0; i < 8; i++) {
w++; w++;
if (w > 4) w = 0; w &= 0x7;
if (userconf.ledprog_ena_mask & (1 << w)) { if (userconf.ledprog_ena_mask & (1 << w)) {
preview_idx = w; preview_idx = w;
break; break;
} }
} }
} }
break;
}
case 1: { // - bot button: enables / disables editing of selected program
rgb_prog_is_editing = !rgb_prog_is_editing;
break; break;
} }
@ -338,6 +360,11 @@ static void ui_cursor_flash()
cursor[color] = led_gamma(level); cursor[color] = led_gamma(level);
led_is_updated(); led_is_updated();
} }
} else {
// clear any cursors that may have been left on
cursor[0] = 0;
cursor[1] = 0;
cursor[2] = 0;
} }
} }
@ -350,8 +377,8 @@ static void ui_cursor_flash()
break; break;
} }
case MODE_PARAMETER: { case MODE_PARAMETER: {
// cursor is always off // cursor is on when program is being edited
cursor[color] = 0; cursor[0] = rgb_prog_is_editing ? 127 : 0;
break; break;
} }
@ -361,7 +388,7 @@ static void ui_cursor_flash()
void ui_init() void ui_init()
{ {
btn[0].hold = 330 >> 1; btn[0].hold = 330 >> 1;
btn[0].repeat = 0; // (1000 / 20) >> 1; btn[0].repeat = (1000 / 20) >> 1;
btn[0].cb_push = ui_btn_push_cb; btn[0].cb_push = ui_btn_push_cb;
btn[0].cb_hold = ui_btn_hold_cb; btn[0].cb_hold = ui_btn_hold_cb;
btn[0].cb_release = ui_btn_release_cb; btn[0].cb_release = ui_btn_release_cb;
@ -419,6 +446,9 @@ void ui_render()
switch (mode) { switch (mode) {
case MODE_RUN: { // render an existing program case MODE_RUN: { // render an existing program
// ensure rear LED is not on
GPIOD->BCR = GPIO_Pin_0;
// set brightness from knob 32 times/second // set brightness from knob 32 times/second
// (the knob value updates less frequently, but we need to fade nicely) // (the knob value updates less frequently, but we need to fade nicely)
if (tick & 7 == 7) { if (tick & 7 == 7) {
@ -450,6 +480,8 @@ void ui_render()
led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick); led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
} }
// todo: the fade goes way too fast and looks bad
// make it look nicer
if (rgb_prog_timer <= 17) { if (rgb_prog_timer <= 17) {
led_is_updated(); led_is_updated();
@ -516,6 +548,11 @@ void ui_render()
// always postpone config saving // always postpone config saving
config_save_timer = UI_CONF_SAVE_TIMEOUT; config_save_timer = UI_CONF_SAVE_TIMEOUT;
// rapidly flash lsens
if ((tick >> 3) & 1) {
GPIOD->OUTDR ^= GPIO_Pin_0;
}
// always increase brightness of LEDs while editing // always increase brightness of LEDs while editing
is31fl3729_set_global_current(FL3729_ADDR, FL3729_GCC_MAX); is31fl3729_set_global_current(FL3729_ADDR, FL3729_GCC_MAX);
@ -555,6 +592,11 @@ void ui_render()
// always postpone config saving // always postpone config saving
config_save_timer = UI_CONF_SAVE_TIMEOUT; config_save_timer = UI_CONF_SAVE_TIMEOUT;
// slowly flash lsnes
if ((tick >> 5) & 1) {
GPIOD->OUTDR ^= GPIO_Pin_0;
}
// always increase brightness of LEDs while editing // always increase brightness of LEDs while editing
is31fl3729_set_global_current(FL3729_ADDR, FL3729_GCC_MAX); is31fl3729_set_global_current(FL3729_ADDR, FL3729_GCC_MAX);
@ -569,7 +611,9 @@ void ui_render()
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
// render // render
if (userconf.ledprog_ena_mask & (1 << i)) { if (userconf.ledprog_ena_mask & (1 << i)) {
if (led_rgbprog[i]) {
led_rgbprog[i](LED_RGBPROG_PREVIEW | preview_idx, tick); led_rgbprog[i](LED_RGBPROG_PREVIEW | preview_idx, tick);
}
if (preview_idx == i) { if (preview_idx == i) {
// flash the selected output // flash the selected output