feat(pl18): Power LED charge status animation (#4503)
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "battery_driver.h"
|
#include "battery_driver.h"
|
||||||
|
#include "boards/generic_stm32/rgb_leds.h"
|
||||||
|
|
||||||
#define __BATTERY_DRIVER_C__
|
#define __BATTERY_DRIVER_C__
|
||||||
|
|
||||||
@@ -311,6 +312,22 @@ void battery_charge_init()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ledChargingInfo(uint16_t chargeState) {
|
||||||
|
static int ledIdx = 0;
|
||||||
|
ledIdx--;
|
||||||
|
if (ledIdx < 0) {
|
||||||
|
ledIdx = LED_STRIP_LENGTH - 1;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < LED_STRIP_LENGTH; i++) {
|
||||||
|
if (CHARGE_FINISHED == chargeState || ledIdx == i) {
|
||||||
|
rgbSetLedColor(i, 0, 20, 0);
|
||||||
|
} else {
|
||||||
|
rgbSetLedColor(i, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rgbLedColorApply();
|
||||||
|
}
|
||||||
|
|
||||||
void drawChargingInfo(uint16_t chargeState) {
|
void drawChargingInfo(uint16_t chargeState) {
|
||||||
static int progress = 0;
|
static int progress = 0;
|
||||||
const char* text = chargeState == CHARGE_STARTED ? STR_BATTERYCHARGING : STR_BATTERYFULL;
|
const char* text = chargeState == CHARGE_STARTED ? STR_BATTERYCHARGING : STR_BATTERYFULL;
|
||||||
@@ -381,55 +398,54 @@ void handle_battery_charge(uint32_t last_press_time)
|
|||||||
lastState = chargeState;
|
lastState = chargeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(now > info_until) {
|
|
||||||
info_until = 0;
|
|
||||||
lcd->clear();
|
|
||||||
BACKLIGHT_DISABLE();
|
|
||||||
if(lcdInited) {
|
|
||||||
lcdOff();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (updateTime == 0 || ((get_tmr10ms() - updateTime) >= 50))
|
if (updateTime == 0 || ((get_tmr10ms() - updateTime) >= 50))
|
||||||
{
|
{
|
||||||
if (!lcdInited) {
|
|
||||||
backlightInit();
|
|
||||||
lcdInit();
|
|
||||||
lcdInitDisplayDriver();
|
|
||||||
lcdInited = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lcdOn();
|
|
||||||
}
|
|
||||||
updateTime = get_tmr10ms();
|
updateTime = get_tmr10ms();
|
||||||
lcdInitDirectDrawing();
|
ledChargingInfo(chargeState);
|
||||||
lcd->clear();
|
|
||||||
drawChargingInfo(chargeState);
|
|
||||||
|
|
||||||
// DEBUG INFO
|
if(now > info_until) {
|
||||||
|
info_until = 0;
|
||||||
|
lcd->clear();
|
||||||
|
BACKLIGHT_DISABLE();
|
||||||
|
if(lcdInited) {
|
||||||
|
lcdOff();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!lcdInited) {
|
||||||
|
backlightInit();
|
||||||
|
lcdInit();
|
||||||
|
lcdInitDisplayDriver();
|
||||||
|
lcdInited = true;
|
||||||
|
} else {
|
||||||
|
lcdOn();
|
||||||
|
}
|
||||||
|
lcdInitDirectDrawing();
|
||||||
|
lcd->clear();
|
||||||
|
drawChargingInfo(chargeState);
|
||||||
|
|
||||||
|
// DEBUG INFO
|
||||||
#if 0
|
#if 0
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
sprintf(buffer, "%d,%d,%d,%d", uCharger.isChargerDetectionReady, uCharger.hasCharger, IS_UCHARGER_ACTIVE(), uCharger.chargerSamplingCount);
|
sprintf(buffer, "%d,%d,%d,%d", uCharger.isChargerDetectionReady, uCharger.hasCharger, IS_UCHARGER_ACTIVE(), uCharger.chargerSamplingCount);
|
||||||
lcd->drawSizedText(100, 10, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
lcd->drawSizedText(100, 10, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
||||||
|
|
||||||
sprintf(buffer, "%d,%d,%d,%d,%d,", uCharger.isChargingDetectionReady, uCharger.isChargeEnd, IS_UCHARGER_CHARGE_END_ACTIVE(), uCharger.chargingSamplingCount, uCharger.chargeEndSamplingCount);
|
sprintf(buffer, "%d,%d,%d,%d,%d,", uCharger.isChargingDetectionReady, uCharger.isChargeEnd, IS_UCHARGER_CHARGE_END_ACTIVE(), uCharger.chargingSamplingCount, uCharger.chargeEndSamplingCount);
|
||||||
lcd->drawSizedText(100, 40, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
lcd->drawSizedText(100, 40, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
||||||
|
|
||||||
sprintf(buffer, "%d,%d,%d,%d,%d", wCharger.isChargerDetectionReady, wCharger.hasCharger, IS_WCHARGER_ACTIVE(), wCharger.chargerSamplingCount, wCharger.isHighCurrent);
|
sprintf(buffer, "%d,%d,%d,%d,%d", wCharger.isChargerDetectionReady, wCharger.hasCharger, IS_WCHARGER_ACTIVE(), wCharger.chargerSamplingCount, wCharger.isHighCurrent);
|
||||||
lcd->drawSizedText(100, 70, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
lcd->drawSizedText(100, 70, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
||||||
|
|
||||||
sprintf(buffer, "%d,%d,%d,%d,%d,", wCharger.isChargingDetectionReady, wCharger.isChargeEnd, IS_WCHARGER_CHARGE_END_ACTIVE(), wCharger.chargingSamplingCount, wCharger.chargeEndSamplingCount);
|
sprintf(buffer, "%d,%d,%d,%d,%d,", wCharger.isChargingDetectionReady, wCharger.isChargeEnd, IS_WCHARGER_CHARGE_END_ACTIVE(), wCharger.chargingSamplingCount, wCharger.chargeEndSamplingCount);
|
||||||
lcd->drawSizedText(100, 100, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
lcd->drawSizedText(100, 100, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
||||||
|
|
||||||
sprintf(buffer, "%d", isChargerActive());
|
sprintf(buffer, "%d", isChargerActive());
|
||||||
lcd->drawSizedText(100, 130, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
lcd->drawSizedText(100, 130, buffer, strlen(buffer), CENTERED | COLOR_THEME_PRIMARY2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lcdRefresh();
|
lcdRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,9 +50,12 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// common ADC driver
|
// Common ADC driver
|
||||||
extern const etx_hal_adc_driver_t _adc_driver;
|
extern const etx_hal_adc_driver_t _adc_driver;
|
||||||
|
|
||||||
|
// Common LED driver
|
||||||
|
extern const stm32_pulse_timer_t _led_timer;
|
||||||
|
|
||||||
#if defined(SEMIHOSTING)
|
#if defined(SEMIHOSTING)
|
||||||
extern "C" void initialise_monitor_handles();
|
extern "C" void initialise_monitor_handles();
|
||||||
#endif
|
#endif
|
||||||
@@ -88,6 +91,14 @@ void delay_self(int count)
|
|||||||
#define RCC_APB2PeriphMinimum (LCD_RCC_APB2Periph)
|
#define RCC_APB2PeriphMinimum (LCD_RCC_APB2Periph)
|
||||||
#define RCC_APB2PeriphOther (HAPTIC_RCC_APB2Periph)
|
#define RCC_APB2PeriphOther (HAPTIC_RCC_APB2Periph)
|
||||||
|
|
||||||
|
void ledStripOff()
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < LED_STRIP_LENGTH; i++) {
|
||||||
|
ws2812_set_color(i, 0, 0, 0);
|
||||||
|
}
|
||||||
|
ws2812_update(&_led_timer);
|
||||||
|
}
|
||||||
|
|
||||||
void boardInit()
|
void boardInit()
|
||||||
{
|
{
|
||||||
#if defined(SEMIHOSTING)
|
#if defined(SEMIHOSTING)
|
||||||
@@ -123,13 +134,8 @@ void boardInit()
|
|||||||
touchPanelInit();
|
touchPanelInit();
|
||||||
usbInit();
|
usbInit();
|
||||||
|
|
||||||
extern const stm32_pulse_timer_t _led_timer;
|
|
||||||
|
|
||||||
ws2812_init(&_led_timer, LED_STRIP_LENGTH);
|
ws2812_init(&_led_timer, LED_STRIP_LENGTH);
|
||||||
for (uint8_t i = 0; i < LED_STRIP_LENGTH; i++) {
|
ledStripOff();
|
||||||
ws2812_set_color(i, 0, 0, 0);
|
|
||||||
}
|
|
||||||
ws2812_update(&_led_timer);
|
|
||||||
|
|
||||||
uint32_t press_start = 0;
|
uint32_t press_start = 0;
|
||||||
uint32_t press_end = 0;
|
uint32_t press_end = 0;
|
||||||
@@ -204,6 +210,7 @@ void boardOff()
|
|||||||
rtcDisableBackupReg();
|
rtcDisableBackupReg();
|
||||||
|
|
||||||
#if !defined(BOOT)
|
#if !defined(BOOT)
|
||||||
|
ledStripOff();
|
||||||
if (isChargerActive())
|
if (isChargerActive())
|
||||||
{
|
{
|
||||||
delay_ms(100); // Add a delay to wait for lcdOff
|
delay_ms(100); // Add a delay to wait for lcdOff
|
||||||
|
|||||||
Reference in New Issue
Block a user