program 5 works with preview; program selection mode is working

This commit is contained in:
true 2024-08-05 20:45:58 -07:00
parent 184c466c3b
commit 64ac32160b
2 changed files with 123 additions and 81 deletions

View File

@ -366,7 +366,7 @@ void led_rgb_3_alternate(uint8_t preview, uint8_t tick)
uint8_t is_flashing = 0;
if (userconf.cursor_color == CONF_CURSOR_OFF) {
if ((userconf.cursor_color == CONF_CURSOR_OFF) || preview) {
// flash at ~2Hz
tick >>= 5;
if (tick & 1) is_flashing = 1;
@ -387,17 +387,25 @@ void led_rgb_3_alternate(uint8_t preview, uint8_t tick)
if (is_flashing) {
// set TECH
for (j = 5; j < 9; j++) {
rgb[j][0] = prog_rgb[0];
rgb[j][1] = prog_rgb[1];
rgb[j][2] = prog_rgb[2];
if (!preview || ((preview & 0xf) == 3)) {
for (j = 5; j < 9; j++) {
rgb[j][0] = prog_rgb[0];
rgb[j][1] = prog_rgb[1];
rgb[j][2] = prog_rgb[2];
}
}
} else {
// set RETRO
for (j = 0; j < 5; j++) {
rgb[j][0] = prog_rgb[0];
rgb[j][1] = prog_rgb[1];
rgb[j][2] = prog_rgb[2];
if (!preview) {
for (j = 0; j < 5; j++) {
rgb[j][0] = prog_rgb[0];
rgb[j][1] = prog_rgb[1];
rgb[j][2] = prog_rgb[2];
}
} else {
rgb[3][0] = prog_rgb[0];
rgb[3][1] = prog_rgb[1];
rgb[3][2] = prog_rgb[2];
}
}
@ -428,7 +436,7 @@ static const uint8_t idle_glow[3] = {0, 0, 0}; // {12, 8, 8};
static const uint8_t typing[3][3] = {
{255, 240, 240}, // white
{ 0, 240, 0}, // green
{255, 96, 12}, // orange
{255, 16, 4}, // orange
};
static uint8_t typing_idx = 255;
@ -468,34 +476,42 @@ void led_rgb_4_typing(uint8_t preview, uint8_t tick)
for (j = 0; j < 3; j++) {
if ((i < typing_idx) || ((i == typing_idx) && typing_flash_state)) {
// these are on
rgb[i][j] = typing[color][j];
if (!preview || (i == 4) || (((preview & 0xf) == 4) && i >= 5)) {
rgb[i][j] = typing[color][j];
}
} else
if (i > typing_idx) { // || ((i == typing_idx) && !typing_flash_state)) {
// these are idle
rgb[i][j] = idle_glow[j];
if (!preview || (i == 4) || (((preview & 0xf) == 4) && i >= 5)) {
rgb[i][j] = idle_glow[j];
}
} else
// flashing cursor fadeout
if ((i == typing_idx) && !typing_flash_state) {
if (rgb[i][j] > 32) rgb[i][j] -= 32; else rgb[i][j] = 0;
update = 1;
if (!preview || (i == 4) || (((preview & 0xf) == 4) && i >= 5)) {
if ((i == typing_idx) && !typing_flash_state) {
if (rgb[i][j] > 32) rgb[i][j] -= 32; else rgb[i][j] = 0;
update = 1;
}
}
}
}
// set cursor as appropriate
for (i = 0; i < 3; i++) {
cursor[i] = 0;
}
if (!preview) {
for (i = 0; i < 3; i++) {
cursor[i] = 0;
}
// at the cursor
if (typing_idx >= 9) {
cursor[color] = typing_flash_state ? 240 : 12;
if (typing_flash_delay <= 8) {
w = 8 - typing_flash_delay;
cursor[color] >>= w;
if (cursor[color] < 12) cursor[color] = 0; // idle value
// at the cursor
if (typing_idx >= 9) {
cursor[color] = typing_flash_state ? 240 : 12;
if (typing_flash_delay <= 8) {
w = 8 - typing_flash_delay;
cursor[color] >>= w;
if (cursor[color] < 12) cursor[color] = 0; // idle value
}
}
}
@ -504,21 +520,27 @@ void led_rgb_4_typing(uint8_t preview, uint8_t tick)
if (typing_fadeout >= 3) typing_fadeout--;
else typing_fadeout = 0;
for (j = 0; j < 3; j++) {
s = rgb[0][j];
if (!preview || (i == 4) || (((preview & 0xf) == 4) && i >= 5)) {
for (j = 0; j < 3; j++) {
s = rgb[8][j];
s *= typing_fadeout;
rgb[8][j] = s >> 8;
}
}
w = ((preview & 0xf) == 4) ? 5 : 0;
for (i = w; i < 8; i++) {
rgb[i][0] = rgb[8][0];
rgb[i][1] = rgb[8][1];
rgb[i][2] = rgb[8][2];
}
if (!preview) {
s = cursor[color];
s *= typing_fadeout;
rgb[0][j] = s >> 8;
cursor[color] = s >> 8;
}
for (i = 1; i < 9; i++) {
rgb[i][0] = rgb[0][0];
rgb[i][1] = rgb[0][1];
rgb[i][2] = rgb[0][2];
}
s = cursor[color];
s *= typing_fadeout;
cursor[color] = s >> 8;
}
// are we on the next character?
@ -526,6 +548,11 @@ void led_rgb_4_typing(uint8_t preview, uint8_t tick)
// next character
typing_idx++;
// start at this character in preview mode
if (preview && typing_idx < 4) {
typing_idx = 4;
}
if (typing_idx == 9) {
// at the cursor, we wait two max periods
typing_char_delay = TYPING_CHAR_DELAY_MAX << 1;

View File

@ -29,7 +29,7 @@
#define UI_PROG_RUNTIME_MAX (128*120) // 120 seconds
static uint8_t mode = MODE_PROGRAM;
static uint8_t mode = MODE_RUN;
static uint8_t tick = 0;
static uint16_t editor_timeout_timer = 0;
@ -52,7 +52,7 @@ const uint16_t cursor_flash_rates[8] = { // off-to-on flash rates in 1/256
static uint8_t rgb_prog_idx = 0; // currently running rgbled program index
static uint16_t rgb_prog_timer = 9; // timeout until this program is done and switches
static uint8_t rgb_prog_is_editing = 0; // currently editing a program's parameters
static uint8_t preview_idx = 1; // currently selected program preview index
static uint8_t preview_idx = 0; // currently selected program preview index
static uint8_t config_save_timer;
@ -60,8 +60,6 @@ static uint8_t config_save_timer;
void ui_btn_push_cb(uint8_t idx)
{
uint8_t i;
// are both buttons pushed?
if ((btn[0]._mask & BTN_PUSH) && (btn[1]._mask & BTN_PUSH)) {
// are none held?
@ -375,14 +373,24 @@ void ui_init()
btn[1].cb_release = ui_btn_release_cb;
}
static void rgb_prog_timer_generate() {
uint32_t t;
t = prng_get16();
t *= (UI_PROG_RUNTIME_MAX - UI_PROG_RUNTIME_MIN);
t >>= 16;
rgb_prog_timer = t + UI_PROG_RUNTIME_MIN;
}
void ui_render()
{
uint8_t i;
uint16_t w;
uint32_t t;
uint8_t flash;
uint8_t new;
// deal with eeprom
@ -436,32 +444,46 @@ void ui_render()
if (userconf.ledprog_ena_mask) {
// fade and change programs depending on the timer
rgb_prog_timer--;
if (rgb_prog_timer) {
// actually run the program
led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
}
if (rgb_prog_timer <= 17) {
if (rgb_prog_timer > 9) {
// fade out current program
w = (rgb_prog_timer & 0x1f) - 10;
for (i = 0; i < 9; i++) {
rgb[i][0] >>= w;
rgb[i][1] >>= w;
rgb[i][2] >>= w;
led_is_updated();
if (rgb_prog_timer == 17) {
w = prng_get8();
w &= 0x7;
for (i = 0; i < 8; i++) {
new = (w + i) & 0x7;
if (userconf.ledprog_ena_mask & (1 << new)) {
// bias selecting a new program
if (rgb_prog_idx != new) {
rgb_prog_idx = new;
led_rgb_firstrun();
break;
}
}
}
// no new program was selected (likely only one program selected?)
// so just reset the timer
if (i == 8) {
rgb_prog_timer_generate();
}
}
else if (rgb_prog_timer > 9) {
// fade out current program
w = 7 - (rgb_prog_timer - 10);
for (i = 0; i < 9; i++) {
rgb[i][0] >>= w;
rgb[i][1] >>= w;
rgb[i][2] >>= w;
}
} else if (rgb_prog_timer > 7) {
// select a new random program
if (rgb_prog_timer == 8) {
w = prng_get8();
w &= 0x3;
if (w == rgb_prog_idx) w++;
for (i = 0; i < 7; i++) {
if (userconf.ledprog_ena_mask & (1 << ((w + i) & 0x7))) {
rgb_prog_idx = w;
break;
}
}
led_rgb_firstrun();
}
// clear out for now, since new program hasn't actually been run
for (i = 0; i < 9; i++) {
rgb[i][0] = 0;
@ -470,7 +492,7 @@ void ui_render()
}
} else if (rgb_prog_timer >= 1) {
// fade in new program
w = 8 - (rgb_prog_timer & 0x1f);
w = (rgb_prog_timer & 0x7);
for (i = 0; i < 9; i++) {
rgb[i][0] >>= w;
rgb[i][1] >>= w;
@ -478,21 +500,14 @@ void ui_render()
}
} else { // 0
// randomize next program timing
t = prng_get16();
t *= (UI_PROG_RUNTIME_MAX - UI_PROG_RUNTIME_MIN);
t >>= 16;
rgb_prog_timer = t + UI_PROG_RUNTIME_MIN;
rgb_prog_timer_generate();
}
// actually run the program
led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
}
}
// temp: remove me once buttons are tested and working
rgb_prog_idx = 0;
led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
//rgb_prog_idx = 0;
//led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
break;
}
@ -507,7 +522,7 @@ void ui_render()
// always force rendering
led_is_updated();
for (i = 0; i < 2; i++) {
for (i = 0; i < 5; i++) {
// render
if (led_rgbprog[i]) {
led_rgbprog[i](LED_RGBPROG_PREVIEW | preview_idx, tick);
@ -516,9 +531,9 @@ void ui_render()
if (preview_idx == i) {
// flash the selected output
if (flash & 1) {
rgb[i][0] = 32;
rgb[i][1] = 32;
rgb[i][2] = 32;
rgb[i][0] = 16;
rgb[i][1] = 16;
rgb[i][2] = 16;
//rgb[i][0] >>= 3;
//rgb[i][1] >>= 3;
//rgb[i][2] >>= 3;