tweak the ambient light level stuff

This commit is contained in:
true 2024-08-06 17:28:40 -07:00
parent d311b923ac
commit f6e48a1708
5 changed files with 34 additions and 11 deletions

View File

@ -3,6 +3,8 @@
* GAT Addon Firmware
* by true
*
* version 0.0.1
*
* code was made for different random addons I designed for dc32,
* then adapted to each one. so things might be a mess.
*
@ -17,7 +19,8 @@
*
* notes:
*
* - last 2K of flash memory is reserved for configuration storage.
* - last 2K of flash memory is reserved for configuration storage
* - accelerometer code isn't done by DC32
*/
#include <ch32v20x.h>

View File

@ -10,14 +10,33 @@
#include "adc.h"
/* original map when ADC was being more constrained
static const uint8_t led_brightness_map[] = {
47, 40, 34, 32, // 0 = maybe outside, or really bright inside. 1-3 = indoors
47, 40, 35, 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
};
*/
// new map now that ADC is acting different
// still don't know why
// but there is a lot of self-illumination problem
static const uint8_t led_brightness_map[] = {
47, 44, 42, 41,
40, 38, 36, 34,
32, 31, 30, 29,
27, 25, 21, 19,
17, 16, 15, 15, // indoors normal brightness
14, 14, 13, 13,
12, 12, 12, 11,
11, 11, 10, 10,
10, 9, 9, 9,
8, 8, 8, 8,
7, 7, 7, 7,
7, 6, 6, 6
};
@ -150,7 +169,7 @@ void adc_process_lsens()
// calculate adjustments
if (lsens_val > LSENS_COARSE_UP) {
lsens_coarse++;
if (lsens_coarse > 0x7f) lsens_coarse = 0x7f;
if (lsens_coarse > 0x3f) lsens_coarse = 0x3f;
} else if (lsens_val < LSENS_COARSE_DOWN) {
if (lsens_coarse) lsens_coarse--;
}
@ -183,7 +202,7 @@ uint8_t adc_get_lsens_coarse()
return lsens_coarse;
}
uint8_t adc_get_brightness_map(uint8_t level)
uint8_t adc_get_brightness(uint8_t level)
{
if (!level) {
// are you outside? why? it's too fucking hot
@ -194,7 +213,7 @@ uint8_t adc_get_brightness_map(uint8_t level)
}
}
if (level > sizeof(led_brightness_map)) {
if (level >= sizeof(led_brightness_map)) {
return led_brightness_map[sizeof(led_brightness_map) - 1];
}

View File

@ -17,8 +17,8 @@
#define LSENS_K_PIN GPIO_Pin_3
#define LSENS_ADC_CH ADC_Channel_3
#define LSENS_COARSE_UP 0x680 // counts higher than this increase lsens_coarse, maximum 64
#define LSENS_COARSE_DOWN 0x580 // counts lower than this decrease lsens_coarse, minimum 1
#define LSENS_COARSE_UP 0x690 // counts higher than this increase lsens_coarse, maximum 64
#define LSENS_COARSE_DOWN 0x5a0 // counts lower than this decrease lsens_coarse, minimum 1
enum lsens_mode {
LSENS_READING_IDLE = 0,
@ -43,7 +43,7 @@ void adc_process_lsens();
uint16_t adc_get_lsens();
uint8_t adc_get_lsens_coarse();
uint8_t adc_get_brightness_map(uint8_t level);
uint8_t adc_get_brightness(uint8_t level);

View File

@ -159,7 +159,7 @@ void led_rgb_update()
uint16_t scale[3];
uint8_t lsens = adc_get_lsens_coarse();
uint8_t max = adc_get_brightness_map(lsens);
uint8_t max = adc_get_brightness(lsens);
// this isn't a matrix so we can just update whenever
// but we need to scale to ambient light level

View File

@ -141,5 +141,6 @@ void ui_render()
// set LED current based on ambient light level
w = adc_get_lsens_coarse();
is31fl3729_set_global_current(FL3729_ADDR, adc_get_brightness_map(w));
w = adc_get_brightness(w);
is31fl3729_set_global_current(FL3729_ADDR, w);
}