[Taranis X9E] 2.5s Timer with small graphics for Power OFF
This commit is contained in:
@@ -53,6 +53,9 @@ void displayScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t
|
||||
void displayMenuBar(const MenuItem *menu, int index);
|
||||
void displayProgressBar(const char *label);
|
||||
void updateProgressBar(int num, int den);
|
||||
#if defined(REV9E)
|
||||
void displayShutdownProgress(uint32_t progress);
|
||||
#endif
|
||||
|
||||
extern coord_t scrollbar_X;
|
||||
#define SET_SCROLLBAR_X(x) scrollbar_X = (x);
|
||||
|
||||
@@ -63,6 +63,15 @@ void menu_lcd_onoff(coord_t x, coord_t y, uint8_t value, LcdFlags attr)
|
||||
lcd_square(x, y, 7);
|
||||
}
|
||||
|
||||
void displayShutdownProgress(uint32_t progress)
|
||||
{
|
||||
drawFilledRect((LCD_W-44)/2, LCD_H/2-5, 28, 10, SOLID, ERASE);
|
||||
lcd_rect((LCD_W-44)/2, LCD_H/2-5, 28, 10);
|
||||
for (int i=(progress/100); i>=0; i--) {
|
||||
drawFilledRect((LCD_W-44)/2+3+i*8, LCD_H/2-3, 6, 6, SOLID);
|
||||
}
|
||||
}
|
||||
|
||||
void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr)
|
||||
{
|
||||
lcd_outdezAtt(LCD_W, 0, count, attr);
|
||||
|
||||
@@ -185,6 +185,13 @@ void perMain()
|
||||
drawStatusLine();
|
||||
}
|
||||
|
||||
#if defined(REV9E) && !defined(SIMU)
|
||||
uint32_t pwr_pressed_duration = pwrPressedDuration();
|
||||
if (pwr_pressed_duration > 0) {
|
||||
displayShutdownProgress(pwr_pressed_duration);
|
||||
}
|
||||
#endif
|
||||
|
||||
lcdRefresh();
|
||||
|
||||
#if defined(REV9E) && !defined(SIMU)
|
||||
|
||||
@@ -243,6 +243,10 @@ extern "C" {
|
||||
void pwrInit(void);
|
||||
uint32_t pwrCheck(void);
|
||||
void pwrOff(void);
|
||||
#if defined(REV9E)
|
||||
uint32_t pwrPressed(void);
|
||||
uint32_t pwrPressedDuration(void);
|
||||
#endif
|
||||
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
|
||||
|
||||
// Backlight driver
|
||||
|
||||
@@ -791,11 +791,17 @@ int main()
|
||||
}
|
||||
}
|
||||
|
||||
if (pwrCheck() == e_power_off && state != ST_FLASHING && state != ST_USB) {
|
||||
lcdOff(); // this drains LCD caps
|
||||
pwrOff();
|
||||
for (;;) {
|
||||
// Wait for power to go off
|
||||
if (state != ST_FLASHING && state != ST_USB) {
|
||||
#if defined(REV9E)
|
||||
if (pwrPressed()) {
|
||||
#else
|
||||
if (pwrCheck() == e_power_off) {
|
||||
#endif
|
||||
lcdOff(); // this drains LCD caps
|
||||
pwrOff();
|
||||
for (;;) {
|
||||
// Wait for power to go off
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,14 +37,8 @@
|
||||
#include "board_taranis.h"
|
||||
#include "../../pwr.h"
|
||||
|
||||
#ifdef REV9E
|
||||
#define POWER_STATE_OFF 0
|
||||
#define POWER_STATE_START 1
|
||||
#define POWER_STATE_RUNNING 2
|
||||
#define POWER_STATE_STOPPING 3
|
||||
#define POWER_STATE_STOPPED 4
|
||||
uint8_t PowerState = POWER_STATE_OFF ;
|
||||
#endif
|
||||
extern volatile uint32_t g_tmr10ms;
|
||||
#define get_tmr10ms() g_tmr10ms
|
||||
|
||||
void pwrInit()
|
||||
{
|
||||
@@ -99,6 +93,10 @@ void pwrInit()
|
||||
|
||||
// Soft power ON
|
||||
GPIO_SetBits(GPIOPWR, PIN_MCU_PWR);
|
||||
|
||||
#if defined(REV9E)
|
||||
while (pwrPressed()) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void pwrOff()
|
||||
@@ -106,41 +104,45 @@ void pwrOff()
|
||||
GPIO_ResetBits(GPIOPWR, PIN_MCU_PWR);
|
||||
}
|
||||
|
||||
// TODO enums should be UPPERCASE
|
||||
#if defined(REV9E)
|
||||
uint32_t pwrPressed()
|
||||
{
|
||||
return GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET;
|
||||
}
|
||||
#if !defined(BOOT)
|
||||
uint32_t pwrPressTime = 0;
|
||||
uint32_t pwrPressedDuration()
|
||||
{
|
||||
if (pwrPressTime == 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return get_tmr10ms() - pwrPressTime;
|
||||
}
|
||||
}
|
||||
uint32_t pwrCheck()
|
||||
{
|
||||
if (pwrPressed()) {
|
||||
if (pwrPressTime == 0) {
|
||||
pwrPressTime = get_tmr10ms();
|
||||
}
|
||||
else {
|
||||
if (get_tmr10ms() - pwrPressTime > 250) {
|
||||
return e_power_off;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
pwrPressTime = 0;
|
||||
}
|
||||
return e_power_on;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
uint32_t pwrCheck()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
return e_power_on;
|
||||
#elif defined(REV9E)
|
||||
uint32_t switchValue = GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET;
|
||||
switch ( PowerState )
|
||||
{
|
||||
case POWER_STATE_OFF :
|
||||
PowerState = POWER_STATE_START ;
|
||||
return e_power_on ;
|
||||
|
||||
case POWER_STATE_START :
|
||||
if ( !switchValue ) {
|
||||
PowerState = POWER_STATE_RUNNING ;
|
||||
}
|
||||
return e_power_on ;
|
||||
|
||||
case POWER_STATE_RUNNING :
|
||||
if ( switchValue ) {
|
||||
PowerState = POWER_STATE_STOPPING ;
|
||||
// return e_power_on;
|
||||
}
|
||||
return e_power_on ;
|
||||
|
||||
case POWER_STATE_STOPPING :
|
||||
if ( !switchValue ) {
|
||||
PowerState = POWER_STATE_STOPPED ;
|
||||
}
|
||||
return e_power_off ;
|
||||
|
||||
case POWER_STATE_STOPPED :
|
||||
return e_power_off ;
|
||||
}
|
||||
#else
|
||||
if (GPIO_ReadInputDataBit(GPIOPWR, PIN_PWR_STATUS) == Bit_RESET)
|
||||
return e_power_on;
|
||||
@@ -150,3 +152,4 @@ uint32_t pwrCheck()
|
||||
return e_power_off;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user