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