fix(pa01): power on and charging animation fixes (#6733)
This commit is contained in:
@@ -376,7 +376,8 @@ void handle_battery_charge(uint32_t last_press_time)
|
||||
#endif
|
||||
}
|
||||
|
||||
#define BRIGHTNESS_MAX 255
|
||||
#define MAX_BRIGHT 255
|
||||
#define CHARGING_BRIGHT 20
|
||||
|
||||
void rgbPowerOn(uint8_t color) {
|
||||
// Sequential RGB On
|
||||
@@ -384,25 +385,25 @@ void rgbPowerOn(uint8_t color) {
|
||||
switch (power_on_step)
|
||||
{
|
||||
case RGB_STEP_POWER_AROUND:
|
||||
setLedGroupColor(4, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(5, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(6, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(4, color, MAX_BRIGHT);
|
||||
setLedGroupColor(5, color, MAX_BRIGHT);
|
||||
setLedGroupColor(6, color, MAX_BRIGHT);
|
||||
break;
|
||||
|
||||
case RGB_STEP_FUNC1:
|
||||
setLedGroupColor(0, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(0, color, MAX_BRIGHT);
|
||||
break;
|
||||
|
||||
case RGB_STEP_FUNC2:
|
||||
setLedGroupColor(1, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(1, color, MAX_BRIGHT);
|
||||
break;
|
||||
|
||||
case RGB_STEP_FUNC3:
|
||||
setLedGroupColor(2, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(2, color, MAX_BRIGHT);
|
||||
break;
|
||||
|
||||
case RGB_STEP_FUNC4:
|
||||
setLedGroupColor(3, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(3, color, MAX_BRIGHT);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -441,7 +442,7 @@ void rgbBatteryLevelInfo(uint8_t power_level, uint8_t rgb_state) {
|
||||
color = RGB_COLOR_PURPLE;
|
||||
if (rgb_state == RGB_STATE_CHARGE) {
|
||||
breath_index |= RGB_GROUP_MASK_FUNC_2;
|
||||
setLedGroupColor(0, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(0, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(2, color, 0);
|
||||
setLedGroupColor(3, color, 0);
|
||||
}
|
||||
@@ -451,8 +452,8 @@ void rgbBatteryLevelInfo(uint8_t power_level, uint8_t rgb_state) {
|
||||
color = RGB_COLOR_YELLOW;
|
||||
if (rgb_state == RGB_STATE_CHARGE) {
|
||||
breath_index |= RGB_GROUP_MASK_FUNC_3;
|
||||
setLedGroupColor(0, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(1, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(0, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(1, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(3, color, 0);
|
||||
}
|
||||
break;
|
||||
@@ -461,19 +462,19 @@ void rgbBatteryLevelInfo(uint8_t power_level, uint8_t rgb_state) {
|
||||
color = RGB_COLOR_GREEN;
|
||||
if (rgb_state == RGB_STATE_CHARGE) {
|
||||
breath_index |= RGB_GROUP_MASK_FUNC_4;
|
||||
setLedGroupColor(0, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(1, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(2, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(0, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(1, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(2, color, CHARGING_BRIGHT);
|
||||
}
|
||||
break;
|
||||
|
||||
case POWER_LEVEL_FULL:
|
||||
color = RGB_COLOR_GREEN;
|
||||
if (rgb_state == RGB_STATE_CHARGE) {
|
||||
setLedGroupColor(0, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(1, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(2, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(3, color, BRIGHTNESS_MAX);
|
||||
setLedGroupColor(0, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(1, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(2, color, CHARGING_BRIGHT);
|
||||
setLedGroupColor(3, color, CHARGING_BRIGHT);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -554,10 +555,10 @@ void setLedGroupColor(uint8_t index, uint8_t color, uint8_t brightness) {
|
||||
ws2812_set_color(rgbMapping[index] + 1, scaled_r, scaled_g, scaled_b);
|
||||
}
|
||||
|
||||
uint8_t ledBreathBright(float angle) {
|
||||
uint8_t ledBreathBright(float angle, uint8_t maxBright) {
|
||||
float brightness = sin(angle) * 0.5 + 0.5; // map range 0-1
|
||||
brightness = pow(brightness, GAMMA); // gamma correction
|
||||
uint8_t bright = (uint8_t)(brightness * 255);
|
||||
uint8_t bright = (uint8_t)(brightness * maxBright);
|
||||
return bright;
|
||||
}
|
||||
|
||||
@@ -573,7 +574,7 @@ void ledBreathUpdate(uint8_t state, uint8_t color, uint8_t group) {
|
||||
uint8_t bright = 0;
|
||||
static float breath_angle = 0;
|
||||
|
||||
bright = ledBreathBright(breath_angle);
|
||||
bright = ledBreathBright(breath_angle, state == RGB_STATE_CHARGE ? CHARGING_BRIGHT : MAX_BRIGHT);
|
||||
breath_angle += BREATH_STEP;
|
||||
if (breath_angle > PI) breath_angle = 0; // reset angle
|
||||
|
||||
|
||||
@@ -129,6 +129,21 @@ void boardBLInit()
|
||||
flashRegisterDriver(QSPI_BASE, 8 * 1024 * 1024, &extflash_driver);
|
||||
}
|
||||
|
||||
bool pwrPressedDebounced()
|
||||
{
|
||||
static bool debouncedState = 0;
|
||||
static bool lastState = 0;
|
||||
|
||||
bool state = pwrPressed();
|
||||
|
||||
if (state == lastState)
|
||||
debouncedState = state;
|
||||
else
|
||||
lastState = state;
|
||||
|
||||
return debouncedState;
|
||||
}
|
||||
|
||||
void boardInit()
|
||||
{
|
||||
// enable interrupts
|
||||
@@ -175,7 +190,12 @@ void boardInit()
|
||||
uint32_t now = 0;
|
||||
|
||||
pwrOn();
|
||||
hapticInit(); // Ensure the hapatic is initialized during charging
|
||||
|
||||
// Init debounce
|
||||
pwrPressedDebounced();
|
||||
pwrPressedDebounced();
|
||||
|
||||
// Handle charging state if charger is active
|
||||
if (isChargerActive()) {
|
||||
static uint32_t adc_sample_time = 0; // Hardware ADC sample tick
|
||||
@@ -190,7 +210,7 @@ void boardInit()
|
||||
is_charging = isChargerActive();
|
||||
}
|
||||
// Exit conditions: button pressed or charger disconnected
|
||||
if (!pwrPressed() && is_charging) {
|
||||
if (!pwrPressedDebounced() && is_charging) {
|
||||
updateBatteryState(RGB_STATE_CHARGE);
|
||||
} else {
|
||||
rgbLedClearAll();
|
||||
@@ -203,17 +223,19 @@ void boardInit()
|
||||
}
|
||||
|
||||
// First stage: Detect initial button press and handle press duration
|
||||
first_short_press = timersGetMsTick();
|
||||
while (pwrPressed()) {
|
||||
now = timersGetMsTick();
|
||||
short_press = now;
|
||||
last_pulse = now;
|
||||
updateBatteryState(RGB_STATE_BREATH);
|
||||
if (!isChargerActive()) {
|
||||
first_short_press = timersGetMsTick();
|
||||
while (pwrPressedDebounced()) {
|
||||
now = timersGetMsTick();
|
||||
short_press = now;
|
||||
last_pulse = now;
|
||||
updateBatteryState(RGB_STATE_BREATH);
|
||||
|
||||
// Shutdown after 10s continuous press
|
||||
if (now - first_short_press > FRIST_PRESS_TIMEOUT) {
|
||||
rgbLedClearAll();
|
||||
boardOff();
|
||||
// Shutdown after 10s continuous press
|
||||
if (now - first_short_press > FIRST_PRESS_TIMEOUT) {
|
||||
rgbLedClearAll();
|
||||
boardOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +244,7 @@ void boardInit()
|
||||
{
|
||||
now = timersGetMsTick();
|
||||
|
||||
if (pwrPressed()) {
|
||||
if (pwrPressedDebounced()) {
|
||||
if (long_press == 0) {
|
||||
updateBatteryState(RGB_STATE_OFF);
|
||||
long_press = now;
|
||||
@@ -247,7 +269,8 @@ void boardInit()
|
||||
// 1. Incomplete secondary press (released too soon)
|
||||
// 2. Timeout between press sequences
|
||||
if ((long_press != 0) || (now - short_press > INTER_PRESS_TIMEOUT)) {
|
||||
boardOff();
|
||||
rgbLedClearAll();
|
||||
boardOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -296,7 +319,6 @@ void boardInit()
|
||||
keysInit();
|
||||
switchInit();
|
||||
audioInit();
|
||||
hapticInit();
|
||||
|
||||
#if defined(RTCLOCK)
|
||||
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
||||
@@ -353,6 +375,7 @@ void boardOff()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int usbPlugged()
|
||||
{
|
||||
|
||||
@@ -129,10 +129,10 @@ extern "C" {
|
||||
|
||||
// Power driver
|
||||
#define SOFT_PWR_CTRL
|
||||
#define POWER_ON_DELAY 1500 // 1.5s
|
||||
#define POWER_ON_STEP 250 // 300ms
|
||||
#define INTER_PRESS_TIMEOUT 5000 // 5s
|
||||
#define FRIST_PRESS_TIMEOUT 10000 // 10s
|
||||
#define POWER_ON_STEP 200 // 200ms
|
||||
#define POWER_ON_DELAY (POWER_ON_STEP * 5)
|
||||
#define INTER_PRESS_TIMEOUT 5000 // 5s
|
||||
#define FIRST_PRESS_TIMEOUT 10000 // 10s
|
||||
void pwrInit();
|
||||
void extModuleInit();
|
||||
uint32_t pwrCheck();
|
||||
|
||||
Reference in New Issue
Block a user