Compare commits

..

2 Commits

Author SHA1 Message Date
true 1bb0a19f77 fix prng_scale16() not actually scaling
wrong type. oops
2024-08-06 00:53:40 -07:00
true 6ca388b6c3 fix various bugs, add random pepper program mode 2024-08-06 00:42:03 -07:00
6 changed files with 73 additions and 22 deletions

View File

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

View File

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

View File

@ -130,12 +130,12 @@ void userconf_load()
// program 0: flashing // program 0: flashing
userconf.pep_conf[0][0] = 0x80; // brightness 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 // program 2: loops
userconf.pep_conf[2][0] = 0xc0; // brightness userconf.pep_conf[2][0] = 0xc0; // brightness
userconf.pep_conf[2][1] = 0; // looping rate userconf.pep_conf[2][1] = 1; // looping rate
userconf.pep_conf[2][3] = 1; // decay rate userconf.pep_conf[2][3] = 2; // decay rate
// program 4: alternating // program 4: alternating
userconf.pep_conf[4][0] = 0x80; // brightness userconf.pep_conf[4][0] = 0x80; // brightness

View File

@ -4,6 +4,9 @@
#include <stdint.h> #include <stdint.h>
#include "ledprog_pep.h"
#include "adc.h"
#include "config.h" #include "config.h"
#include "led.h" #include "led.h"
#include "lis2dw.h" #include "lis2dw.h"
@ -21,6 +24,9 @@ enum {
static uint16_t pep_rnd; static uint16_t pep_rnd;
static uint8_t pep_work[4]; 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 { } else {
pep_work[0] = rate; pep_work[0] = rate;
pep_work[1]++; pep_work[1]++;
pep_work[1] &= 0x3f;
} }
bot = pep_work[1] * LED_PEP_COUNT; bot = pep_work[1] * LED_PEP_COUNT;
bot >>= 8; bot >>= 6;
for (i = 0; i < LED_PEP_COUNT; i++) { for (i = 0; i < LED_PEP_COUNT; i++) {
if (i == bot) led.section.pep[i] = brite; 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 = pep_work[1] * LED_HAT_COUNT;
top >>= 8; top >>= 6;
for (i = 0; i < LED_HAT_COUNT; i++) { for (i = 0; i < LED_HAT_COUNT; i++) {
if (i == top) led.section.hat[i] = brite; if (i == top) led.section.hat[i] = brite;
@ -213,7 +220,7 @@ static void pep_3_neon_sign(uint8_t tick)
target = rnd & 1; target = rnd & 1;
flicker_count[target] = prng_scale16(1, 4) << 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) { if (rnd & 2) {
flicker_count[target ^ 1] = flicker_count[target]; flicker_count[target ^ 1] = flicker_count[target];
@ -392,6 +399,37 @@ 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*128, 150*128);
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 * make a sharp point at whatever direction is the ground
* note: probably won't be done before con * note: probably won't be done before con
@ -432,8 +470,9 @@ void (*ledprog_pep[8])(uint8_t) = {
pep_3_neon_sign, pep_3_neon_sign,
pep_4_alternate, pep_4_alternate,
pep_5_nom, pep_5_nom,
pep_6_accelerometer, pep_6_random
pep_7_heat //pep_6_accelerometer,
//pep_7_heat
}; };
@ -460,5 +499,9 @@ void ledprog_pep_init()
// per-program initialization // per-program initialization
nom_timeout = 0; nom_timeout = 0;
if ((userconf.pep_prog_ena_map & ~0x80) != 6) {
rand_flash_timeout = 3;
}
// there is none on this badge // there is none on this badge
} }

View File

@ -151,7 +151,7 @@ static uint32_t tinymt32_temper (tinymt32_t* s)
uint16_t prng_scale16(uint16_t min, uint16_t max) uint16_t prng_scale16(uint16_t min, uint16_t max)
{ {
uint16_t rnd; uint32_t rnd;
rnd = prng_get16(); rnd = prng_get16();
rnd *= (max - min); rnd *= (max - min);

View File

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