knob: fix up brightness direction, limits

the knob now adjusts in a human-relatable way for min to max brightness.

the min and max brightness levels are now scaled correctly for the knob.
This commit is contained in:
true 2024-08-02 17:47:17 -07:00
parent 185578ad8d
commit d24d0b6d03
5 changed files with 46 additions and 12 deletions

View File

@ -120,7 +120,7 @@ void adc_stop_lsens()
GPIO_Init(GPIOA, &gpio);
}
uint16_t adc_get_pot()
uint8_t adc_get_pot()
{
uint32_t pot;
@ -135,7 +135,7 @@ uint16_t adc_get_pot()
// 8 bits is good enough for us
pot >>= 2;
return pot & 0xff;
return 255 - (pot & 0xff);
}
uint16_t adc_get_lsens()

View File

@ -20,7 +20,7 @@ void adc_read();
void adc_use_lsens();
void adc_reset_lsens();
uint16_t adc_get_pot();
uint8_t adc_get_pot();
uint16_t adc_get_lsens();

View File

@ -15,6 +15,25 @@
static const uint8_t rgb_map[9] = {0x04, 0x14, 0x01, 0x11, 0x07, 0x0a, 0x1a, 0x0d, 0x1d};
static const uint8_t cursor_map[3] = {0x17, 0x18, 0x19};
static const uint8_t LED_CIE_PWM_256I_256O[] = {
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4,
4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7,
7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11,
11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17,
17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25,
25, 26, 26, 27, 28, 28, 29, 29, 30, 31, 31, 32, 32, 33, 34, 34,
35, 36, 37, 37, 38, 39, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47,
47, 48, 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 79,
80, 81, 82, 83, 85, 86, 87, 88, 90, 91, 92, 94, 95, 96, 98, 99,
100, 102, 103, 105, 106, 108, 109, 110, 112, 113, 115, 116, 118, 120, 121, 123,
124, 126, 128, 129, 131, 132, 134, 136, 138, 139, 141, 143, 145, 146, 148, 150,
152, 154, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181,
183, 185, 187, 189, 191, 193, 196, 198, 200, 202, 204, 207, 209, 211, 214, 216,
218, 220, 223, 225, 228, 230, 232, 235, 237, 240, 242, 245, 247, 250, 252, 255,
};
uint16_t rgb[9][3] = {0};
@ -66,3 +85,8 @@ void led_send()
is31fl3729_set_outputs(FL3729_ADDR, 1, out, 16+15);
}
}
uint8_t led_gamma(uint8_t in)
{
return LED_CIE_PWM_256I_256O[in];
}

View File

@ -30,6 +30,8 @@ void led_init();
void led_is_updated();
void led_send();
uint8_t led_gamma(uint8_t in);
#endif /* USER_SRC_LED_H_ */

View File

@ -20,8 +20,8 @@
#define MODE_PROGRAM 1
#define MODE_PARAMETER 2
#define MIN_GC 4
#define MAX_GC 60
#define MIN_GC 2
#define MAX_GC 26
#define UI_CONF_SAVE_TIMEOUT 160
@ -324,7 +324,7 @@ static void ui_cursor_flash()
// set the level on the cursor
if (cursor[color] != level) {
cursor[color] = level;
cursor[color] = led_gamma(level);
led_is_updated();
}
@ -376,10 +376,11 @@ void ui_init()
void ui_render()
{
uint8_t i;
uint16_t w;
uint32_t t;
uint8_t i;
uint8_t w;
uint8_t flash;
@ -409,10 +410,17 @@ void ui_render()
case MODE_RUN: { // render an existing program
tick++;
// set brightness from knob 64 times/second
// (the value actually updates less frequently, but we need to fade nicely)
if (tick & 3 == 3) {
w = adc_get_pot() >> 2;
// set brightness from knob 32 times/second
// (the knob value updates less frequently, but we need to fade nicely)
if (tick & 7 == 7) {
w = adc_get_pot();
if (w < 2) w = 0;
else {
w *= MAX_GC - MIN_GC;
w >>= 8;
w += MIN_GC;
}
if (!w) {
if (target_gc) target_gc--; // full off = full off.
} else if (w < target_gc) {