fix various bugs, add random pepper program mode

This commit is contained in:
true 2024-08-06 00:42:03 -07:00
parent 6f9444ab5c
commit 6ca388b6c3
5 changed files with 73 additions and 21 deletions

View File

@ -145,7 +145,7 @@ int main(void)
// after sending LEDs, run our program
// to update the LED buffer for next time
if ((ticnt & 0x3) == 0) {
if ((ticnt & 0x7) == 0) {
ui_render();
}
}

View File

@ -62,6 +62,12 @@ void adc_read()
void adc_set_mode_lsens(uint8_t mode)
{
lsens_mode = mode;
if (mode == LSENS_OUTPUT) {
lsens_gpio.GPIO_Pin = LSENS_A_PIN | LSENS_K_PIN;
lsens_gpio.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LSENS_PORT, &lsens_gpio);
}
}
uint8_t adc_get_mode_lsens()
@ -79,7 +85,7 @@ static void lsens_start()
// set cathode high, let it charge
LSENS_PORT->BSHR = LSENS_K_PIN;
// set anode floating
// set anode low
lsens_gpio.GPIO_Pin = LSENS_A_PIN;
lsens_gpio.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(LSENS_PORT, &lsens_gpio);

View File

@ -130,12 +130,12 @@ void userconf_load()
// program 0: flashing
userconf.pep_conf[0][0] = 0x80; // brightness
userconf.pep_conf[0][1] = 200; // flash rate
userconf.pep_conf[0][1] = 100; // flash rate
// program 2: loops
userconf.pep_conf[2][0] = 0xc0; // brightness
userconf.pep_conf[2][1] = 0; // looping rate
userconf.pep_conf[2][3] = 1; // decay rate
userconf.pep_conf[2][1] = 1; // looping rate
userconf.pep_conf[2][3] = 2; // decay rate
// program 4: alternating
userconf.pep_conf[4][0] = 0x80; // brightness

View File

@ -4,6 +4,9 @@
#include <stdint.h>
#include "ledprog_pep.h"
#include "adc.h"
#include "config.h"
#include "led.h"
#include "lis2dw.h"
@ -21,6 +24,9 @@ enum {
static uint16_t pep_rnd;
static uint8_t pep_work[4];
static uint16_t rand_program = 0;
static uint32_t rand_timeout = 0;
static uint16_t rand_flash_timeout;
/*
@ -162,10 +168,11 @@ static void pep_2_loops(uint8_t tick)
} else {
pep_work[0] = rate;
pep_work[1]++;
pep_work[1] &= 0x3f;
}
bot = pep_work[1] * LED_PEP_COUNT;
bot >>= 8;
bot >>= 6;
for (i = 0; i < LED_PEP_COUNT; i++) {
if (i == bot) led.section.pep[i] = brite;
@ -176,7 +183,7 @@ static void pep_2_loops(uint8_t tick)
}
top = pep_work[1] * LED_HAT_COUNT;
top >>= 8;
top >>= 6;
for (i = 0; i < LED_HAT_COUNT; i++) {
if (i == top) led.section.hat[i] = brite;
@ -213,7 +220,7 @@ static void pep_3_neon_sign(uint8_t tick)
target = rnd & 1;
flicker_count[target] = prng_scale16(1, 4) << 1;
flicker_delay[target] = prng_scale16(12, 240);
flicker_delay[target] = prng_scale16(6, 120);
if (rnd & 2) {
flicker_count[target ^ 1] = flicker_count[target];
@ -392,6 +399,38 @@ static void pep_5_nom(uint8_t tick)
}
}
static void pep_6_random(uint8_t tick)
{
if (rand_flash_timeout <= 2) {
// light lsens
adc_set_mode_lsens(LSENS_OUTPUT);
LSENS_PORT->BSHR = LSENS_A_PIN;
LSENS_PORT->BCR = LSENS_K_PIN;
if (!rand_flash_timeout) rand_flash_timeout = 600;
} else {
if (adc_get_mode_lsens() == LSENS_OUTPUT) {
// restore lsens
LSENS_PORT->BCR = LSENS_A_PIN;
adc_set_mode_lsens(LSENS_READING_IDLE);
}
}
rand_flash_timeout--;
if (!rand_timeout) {
rand_timeout = prng_scale16(20, 150);
rand_timeout <<= 7;
rand_program = 6 * prng_get8();
rand_program >>= 8;
ledprog_pep_init();
}
rand_timeout--;
ledprog_pep[rand_program](tick);
}
/*
* make a sharp point at whatever direction is the ground
* note: probably won't be done before con
@ -432,8 +471,9 @@ void (*ledprog_pep[8])(uint8_t) = {
pep_3_neon_sign,
pep_4_alternate,
pep_5_nom,
pep_6_accelerometer,
pep_7_heat
pep_6_random
//pep_6_accelerometer,
//pep_7_heat
};
@ -460,5 +500,9 @@ void ledprog_pep_init()
// per-program initialization
nom_timeout = 0;
if ((userconf.pep_prog_ena_map & ~0x80) != 6) {
rand_flash_timeout = 3;
}
// there is none on this badge
}

View File

@ -19,12 +19,12 @@
#define MODE_PROGRAM 1
#define MODE_PARAMETER 2
#define UI_CONF_SAVE_TIMEOUT 512
#define UI_CONF_SAVE_TIMEOUT 384
#define UI_PROG_RUNTIME_MIN (128*15) // 15 seconds
#define UI_PROG_RUNTIME_MAX (128*120) // 120 seconds
#define PROG_REPEAT 0x80
#define PROG_RANDOM 0x80
@ -51,16 +51,18 @@ void ui_btn_push_cb(uint8_t idx)
void ui_btn_hold_cb(uint8_t idx)
{
/*
switch (idx) {
case 0: { // left pepper hat
userconf.pep_prog_ena_map ^= PROG_REPEAT;
userconf.pep_prog_ena_map ^= PROG_RANDOM;
break;
}
case 1: { // right pepper hat
userconf.rgb_prog_ena_map ^= PROG_REPEAT;
userconf.rgb_prog_ena_map ^= PROG_RANDOM;
break;
}
}
*/
}
void ui_btn_release_cb(uint8_t idx)
@ -69,18 +71,18 @@ void ui_btn_release_cb(uint8_t idx)
switch (idx) {
case 0: { // left pepper hat
update = userconf.pep_prog_ena_map & ~(PROG_REPEAT);
update = userconf.pep_prog_ena_map & ~(PROG_RANDOM);
update++;
if (update > 5) update = 0;
userconf.pep_prog_ena_map = update | (userconf.pep_prog_ena_map & PROG_REPEAT);
if (update > 6) update = 0;
userconf.pep_prog_ena_map = update | (userconf.pep_prog_ena_map & PROG_RANDOM);
ledprog_pep_init();
break;
}
case 1: { // right pepper hat
update = userconf.rgb_prog_ena_map & ~(PROG_REPEAT);
update = userconf.rgb_prog_ena_map & ~(PROG_RANDOM);
update++;
if (update > 3) update = 0;
userconf.rgb_prog_ena_map = update | (userconf.rgb_prog_ena_map & PROG_REPEAT);
userconf.rgb_prog_ena_map = update | (userconf.rgb_prog_ena_map & PROG_RANDOM);
ledprog_rgb_init();
break;
}
@ -113,8 +115,8 @@ void ui_render()
tick++;
uint8_t prog_pep_idx = userconf.pep_prog_ena_map & ~(PROG_REPEAT);
uint8_t prog_rgb_idx = userconf.rgb_prog_ena_map & ~(PROG_REPEAT);
uint8_t prog_pep_idx = userconf.pep_prog_ena_map & ~(PROG_RANDOM);
uint8_t prog_rgb_idx = userconf.rgb_prog_ena_map & ~(PROG_RANDOM);
switch (mode) {
case MODE_RUN: {