fix some bugs, finish RGB programs, prepare for release
This commit is contained in:
parent
411d46531d
commit
d311b923ac
|
@ -11,6 +11,16 @@
|
|||
|
||||
|
||||
|
||||
static const uint8_t led_brightness_map[] = {
|
||||
47, 40, 34, 32, // 0 = maybe outside, or really bright inside. 1-3 = indoors
|
||||
30, 28, 27, 25, // 4-7 = indoors
|
||||
23, 21, 19, 18, // 8-11 = indoors normal
|
||||
17, 16, 15, 13, // 12 = dimmest normal, 13 = darker, 14-15 darker still
|
||||
11, 9, 7, 5 // 16-19 = from night room light to computer light
|
||||
};
|
||||
|
||||
|
||||
|
||||
static GPIO_InitTypeDef lsens_gpio = {
|
||||
.GPIO_Mode = GPIO_Mode_Out_PP,
|
||||
.GPIO_Pin = LSENS_A_PIN | LSENS_K_PIN,
|
||||
|
@ -172,3 +182,22 @@ uint8_t adc_get_lsens_coarse()
|
|||
{
|
||||
return lsens_coarse;
|
||||
}
|
||||
|
||||
uint8_t adc_get_brightness_map(uint8_t level)
|
||||
{
|
||||
if (!level) {
|
||||
// are you outside? why? it's too fucking hot
|
||||
// we'll shut down when in the presence of big nuclear fire
|
||||
if (adc_get_lsens() < 400) {
|
||||
// yup, outside or in a spotlight at 3ft away or something
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (level > sizeof(led_brightness_map)) {
|
||||
return led_brightness_map[sizeof(led_brightness_map) - 1];
|
||||
|
||||
}
|
||||
|
||||
return led_brightness_map[level];
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ void adc_process_lsens();
|
|||
uint16_t adc_get_lsens();
|
||||
uint8_t adc_get_lsens_coarse();
|
||||
|
||||
uint8_t adc_get_brightness_map(uint8_t level);
|
||||
|
||||
|
||||
|
||||
#endif /* USER_SRC_ADC_H_ */
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "ledprog_pep.h"
|
||||
#include "ledprog_rgb.h"
|
||||
|
||||
#include "adc.h"
|
||||
|
||||
|
||||
|
||||
#define FL3729_SW_COUNT 4 // switches utilized
|
||||
|
@ -153,10 +155,27 @@ void led_matrix_send()
|
|||
|
||||
void led_rgb_update()
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t scale[3];
|
||||
|
||||
uint8_t lsens = adc_get_lsens_coarse();
|
||||
uint8_t max = adc_get_brightness_map(lsens);
|
||||
|
||||
// this isn't a matrix so we can just update whenever
|
||||
// but we need to scale to ambient light level
|
||||
for (i = 0; i < 3; i++) {
|
||||
// first, scale to 75% of max scale
|
||||
scale[i] = max * rgb[i];
|
||||
scale[i] >>= 6;
|
||||
|
||||
// then get to 100% of max
|
||||
scale[i] *= 3;
|
||||
scale[i] >>= 1;
|
||||
}
|
||||
|
||||
TIM_CtrlPWMOutputs(RGB_TIM, DISABLE);
|
||||
RGB_TIM->CH1CVR = rgb_pwm_gamma(rgb[2]);
|
||||
RGB_TIM->CH2CVR = rgb_pwm_gamma(rgb[1]);
|
||||
RGB_TIM->CH3CVR = rgb_pwm_gamma(rgb[0]);
|
||||
RGB_TIM->CH1CVR = rgb_pwm_gamma(scale[2]);
|
||||
RGB_TIM->CH2CVR = rgb_pwm_gamma(scale[1]);
|
||||
RGB_TIM->CH3CVR = rgb_pwm_gamma(scale[0]);
|
||||
TIM_CtrlPWMOutputs(RGB_TIM, ENABLE);
|
||||
}
|
||||
|
|
|
@ -213,26 +213,25 @@ static void pep_3_neon_sign(uint8_t tick)
|
|||
uint16_t rnd;
|
||||
uint8_t target;
|
||||
|
||||
if (tick & 4) {
|
||||
if ((tick & 0x7) == 0) {
|
||||
rnd = prng_get8();
|
||||
if (rnd >= 0xfc) {
|
||||
if (rnd >= 0xfa) {
|
||||
// do a flicker
|
||||
target = rnd & 1;
|
||||
|
||||
flicker_count[target] = prng_scale16(1, 4) << 1;
|
||||
flicker_delay[target] = prng_scale16(6, 120);
|
||||
flicker_delay[target] = prng_scale16(1, 11);
|
||||
|
||||
if (rnd & 2) {
|
||||
// 1/3 chance both of the elements flicker
|
||||
if (rnd >= 0xfe) {
|
||||
flicker_count[target ^ 1] = flicker_count[target];
|
||||
flicker_delay[target ^ 1] = flicker_delay[target];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// todo: implement flickering on/off
|
||||
// like a flourescent tube warming up or failing
|
||||
// like a fluorescent tube warming up or failing
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (flicker_count[i]) {
|
||||
if (flicker_timer[i]) {
|
||||
|
@ -406,7 +405,7 @@ static void pep_6_random(uint8_t tick)
|
|||
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;
|
||||
if (!rand_flash_timeout) rand_flash_timeout = 777;
|
||||
} else {
|
||||
if (adc_get_mode_lsens() == LSENS_OUTPUT) {
|
||||
// restore lsens
|
||||
|
@ -418,7 +417,7 @@ static void pep_6_random(uint8_t tick)
|
|||
rand_flash_timeout--;
|
||||
|
||||
if (!rand_timeout) {
|
||||
rand_timeout = prng_scale16(20*128, 150*128);
|
||||
rand_timeout = prng_scale16(20*128, 121*128);
|
||||
|
||||
rand_program = 6 * prng_get8();
|
||||
rand_program >>= 8;
|
||||
|
|
|
@ -28,7 +28,11 @@ static void rgb_0_nothing(uint8_t tick)
|
|||
*/
|
||||
static void rgb_1_rainbow(uint8_t tick)
|
||||
{
|
||||
rgb_work[0] += 8;
|
||||
rgb_work[0] %= (256*6);
|
||||
|
||||
|
||||
hsv2rgb_8b(rgb_work[0], 255, 255, &rgb[0], &rgb[1], &rgb[2]);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -36,7 +40,16 @@ static void rgb_1_rainbow(uint8_t tick)
|
|||
*/
|
||||
static void rgb_2_candle(uint8_t tick)
|
||||
{
|
||||
uint16_t hue = 12; // pepper red-orange
|
||||
|
||||
if ((tick & 0x7) == 0) {
|
||||
rgb_work[0] = 191;
|
||||
rgb_work[0] += prng_get8() >> 3;
|
||||
}
|
||||
|
||||
// cut brightness in half
|
||||
|
||||
hsv2rgb_8b(hue, 255, rgb_work[0] & 0xff, &rgb[0], &rgb[1], &rgb[2]);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -44,7 +57,16 @@ static void rgb_2_candle(uint8_t tick)
|
|||
*/
|
||||
static void rgb_3_alternate(uint8_t tick)
|
||||
{
|
||||
uint16_t hue = 0;
|
||||
|
||||
tick >>= 4;
|
||||
tick &= 1;
|
||||
|
||||
if (tick) {
|
||||
hue = 85*6;
|
||||
}
|
||||
|
||||
hsv2rgb_8b(hue, 255, 255, &rgb[0], &rgb[1], &rgb[2]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,15 +28,6 @@
|
|||
|
||||
|
||||
|
||||
static const uint8_t led_gc_map[] = {
|
||||
48, 40, 34, 32, // 0 = maybe outside, or really bright inside. 1-3 = indoors
|
||||
30, 28, 27, 25, // 4-7 = indoors
|
||||
23, 21, 19, 18, // 8-11 = indoors normal
|
||||
17, 16, 15, 13, // 12 = dimmest normal, 13 = darker, 14-15 darker still
|
||||
11, 9, 7, 5, // 16-19 = from night room light to computer light
|
||||
0 // 20 = outside mode turns off the LEDs
|
||||
};
|
||||
|
||||
static uint8_t mode = MODE_RUN;
|
||||
static uint8_t tick = 0;
|
||||
|
||||
|
@ -148,34 +139,7 @@ void ui_render()
|
|||
}
|
||||
}
|
||||
|
||||
// set LED current based on brightness
|
||||
// set LED current based on ambient light level
|
||||
w = adc_get_lsens_coarse();
|
||||
if (w > 19) w = 19;
|
||||
if (!w) {
|
||||
// are you outside? why? it's too fucking hot
|
||||
// we'll shut down when in the presence of big nuclear fire
|
||||
if (adc_get_lsens() < 400) {
|
||||
// yup, outside or in a spotlight at 3ft away or something
|
||||
w = 20;
|
||||
}
|
||||
}
|
||||
is31fl3729_set_global_current(FL3729_ADDR, led_gc_map[w]);
|
||||
|
||||
// temporary: testing
|
||||
|
||||
// ledprog_pep[prog_run](tick);
|
||||
/*
|
||||
if ((tick & 3) == 3) {
|
||||
|
||||
tmp++;
|
||||
tmp &= 0x3f;
|
||||
|
||||
for (uint8_t i = 0; i < 64; i++) {
|
||||
if (i == tmp) led.all[i] = 255;
|
||||
else led.all[i] = 0;
|
||||
}
|
||||
|
||||
led_matrix_is_updated();
|
||||
}
|
||||
*/
|
||||
is31fl3729_set_global_current(FL3729_ADDR, adc_get_brightness_map(w));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue