mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Initial hal changes
This commit is contained in:
parent
d6cbd1bcdd
commit
12b402f994
77 changed files with 924 additions and 672 deletions
|
@ -16,16 +16,23 @@ static const float heartbeat_peak1 = 0.80;
|
|||
static const float heartbeat_peak2 = 0.55;
|
||||
static const float heartbeat_deviation = 0.05;
|
||||
|
||||
static LED led(datalayer.battery.status.led_mode);
|
||||
static LED* led;
|
||||
|
||||
void led_init(void) {
|
||||
led.init();
|
||||
bool led_init(void) {
|
||||
if (!esp32hal->alloc_pins("LED", esp32hal->LED_PIN())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
led = new LED(datalayer.battery.status.led_mode, esp32hal->LED_PIN(), esp32hal->LED_MAX_BRIGHTNESS());
|
||||
led->init();
|
||||
|
||||
return true;
|
||||
}
|
||||
void led_exe(void) {
|
||||
led.exe();
|
||||
led->exe();
|
||||
}
|
||||
led_color led_get_color() {
|
||||
return led.color;
|
||||
return led->color;
|
||||
}
|
||||
|
||||
void LED::exe(void) {
|
||||
|
@ -61,7 +68,7 @@ void LED::exe(void) {
|
|||
break;
|
||||
case EVENT_LEVEL_ERROR:
|
||||
color = led_color::RED;
|
||||
pixels.setPixelColor(0, COLOR_RED(LED_MAX_BRIGHTNESS)); // Red LED full brightness
|
||||
pixels.setPixelColor(0, COLOR_RED(esp32hal->LED_MAX_BRIGHTNESS())); // Red LED full brightness
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -126,7 +133,7 @@ void LED::heartbeat_run(void) {
|
|||
brightness_f = map_float(period_pct, 0.55f, 1.00f, heartbeat_base + heartbeat_deviation * 2, heartbeat_base);
|
||||
}
|
||||
|
||||
brightness = (uint8_t)(brightness_f * LED_MAX_BRIGHTNESS);
|
||||
brightness = (uint8_t)(brightness_f * esp32hal->LED_MAX_BRIGHTNESS());
|
||||
}
|
||||
|
||||
uint8_t LED::up_down(float middle_point_f) {
|
||||
|
@ -138,7 +145,7 @@ uint8_t LED::up_down(float middle_point_f) {
|
|||
if (ms < middle_point) {
|
||||
brightness = map_uint16(ms, 0, middle_point, 0, max_brightness);
|
||||
} else {
|
||||
brightness = LED_MAX_BRIGHTNESS - map_uint16(ms, middle_point, LED_PERIOD_MS, 0, max_brightness);
|
||||
brightness = esp32hal->LED_MAX_BRIGHTNESS() - map_uint16(ms, middle_point, LED_PERIOD_MS, 0, max_brightness);
|
||||
}
|
||||
return CONSTRAIN(brightness, 0, max_brightness);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue