1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-21 15:25:12 +03:00

Startup / shutdown refactoring

This commit is contained in:
Bertrand Songis 2019-08-16 16:12:34 +02:00
parent f7a6d44d1e
commit a611d9e10f
No known key found for this signature in database
GPG key ID: F189F79290FEC50F
26 changed files with 382 additions and 268 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -5,6 +5,7 @@ set(GUI_SRC
fonts.cpp
popups.cpp
widgets.cpp
startup_shutdown.cpp
menu_model.cpp
model_select.cpp
model_setup.cpp

View file

@ -24,6 +24,7 @@
#include "gui_common.h"
#include "menus.h"
#include "popups.h"
#include "common/stdlcd/draw_functions.h"
#define MENUS_SCROLLBAR_WIDTH 0
@ -192,7 +193,6 @@ swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags attr, event_t e
#if defined(GVARS)
#define GVAR_MENU_ITEM(x, y, v, min, max, attr, editflags, event) editGVarFieldValue(x, y, v, min, max, attr, editflags, event)
int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int16_t max, LcdFlags attr, uint8_t editflags, event_t event);
void drawGVarName(coord_t x, coord_t y, int8_t index, LcdFlags flags=0);
void drawGVarValue(coord_t x, coord_t y, uint8_t gvar, gvar_t value, LcdFlags flags=0);
void editGVarValue(coord_t x, coord_t y, event_t event, uint8_t gvar, uint8_t flightMode, LcdFlags flags);
#define displayGVar(x, y, v, min, max) GVAR_MENU_ITEM(x, y, v, min, max, 0, 0, 0)

View file

@ -122,9 +122,7 @@ void lcdDrawNumber(coord_t x, coord_t y, int val, LcdFlags mode, uint8_t len);
void lcdDrawNumber(coord_t x, coord_t y, int val, LcdFlags mode=0);
void lcdDraw8bitsNumber(coord_t x, coord_t y, int8_t val);
void drawStringWithIndex(coord_t x, coord_t y, const char * str, uint8_t idx, LcdFlags att=0);
void putsModelName(coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att);
void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att = 0);
#if !defined(BOOT) // TODO not here ...
void drawSwitch(coord_t x, coord_t y, swsrc_t swtch, LcdFlags att=0);
void drawSource(coord_t x, coord_t y, mixsrc_t idx, LcdFlags att=0);
@ -141,14 +139,6 @@ void putsChnLetter(coord_t x, coord_t y, uint8_t idx, LcdFlags attr);
void putsVolts(coord_t x, coord_t y, uint16_t volts, LcdFlags att);
void putsVBat(coord_t x, coord_t y, LcdFlags att);
void drawRtcTime(coord_t x, coord_t y, LcdFlags att);
void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att, LcdFlags att2);
void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverIdx, LcdFlags flags=0);
inline void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att)
{
drawTimer(x, y, tme, att, att);
}
#define SOLID 0xff
#define DOTTED 0x55
@ -209,8 +199,6 @@ inline display_t getPixel(uint8_t x, uint8_t y)
const char * writeScreenshot();
void drawShutdownAnimation(uint32_t index, const char * message);
uint8_t getTextWidth(const char * s, uint8_t len=0, LcdFlags flags=0);
#endif // _LCD_H_

View file

@ -0,0 +1,81 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
#define PWR_PRESS_DURATION_MIN 100 // 1s
#define PWR_PRESS_DURATION_MAX 500 // 5s
#define SLEEP_BITMAP_WIDTH 60
#define SLEEP_BITMAP_HEIGHT 60
const unsigned char bmp_sleep[] = {
#include "sleep.lbm"
};
void drawStartupAnimation(uint32_t duration)
{
uint8_t index = limit<uint8_t>(0, duration / (PWR_PRESS_DURATION_MIN / 4), 3);
lcdRefreshWait();
lcdClear();
for (uint8_t i = 0; i < 4; i++) {
if (index >= i) {
lcdDrawFilledRect(LCD_W / 2 - 18 + 10 * i, LCD_H / 2 - 3, 6, 6, SOLID, 0);
}
}
lcdRefresh();
lcdRefreshWait();
}
void drawShutdownAnimation(uint32_t duration, const char * message)
{
uint8_t index = limit<uint8_t>(0, duration / (PWR_PRESS_SHUTDOWN_DELAY / 5), 4);
lcdRefreshWait();
lcdClear();
for (uint8_t i = 0; i < 4; i++) {
if (3 - index >= i) {
lcdDrawFilledRect(LCD_W / 2 - 18 + 10 * i, LCD_H / 2 - 3, 6, 6, SOLID, 0);
}
}
if (message) {
lcdDrawText((LCD_W - getTextWidth(message)) / 2, LCD_H-2*FH, message);
}
lcdRefresh();
lcdRefreshWait();
}
void drawSleepBitmap()
{
lcdRefreshWait();
lcdClear();
lcdDraw1bitBitmap((LCD_W - SLEEP_BITMAP_WIDTH) / 2, (LCD_H - SLEEP_BITMAP_HEIGHT) / 2, bmp_sleep, 0);
lcdRefresh();
lcdRefreshWait();
}

View file

@ -65,15 +65,15 @@ void menuStatisticsView(event_t event)
// Session and Total timers
lcdDrawText(STATS_1ST_COLUMN, FH*1+1, "SES", BOLD);
drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*1+1, sessionTimer, 0, 0);
drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*1+1, sessionTimer);
lcdDrawText(STATS_1ST_COLUMN, FH*2+1, "TOT", BOLD);
drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*2+1, g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR, 0);
// Throttle special timers
lcdDrawText(STATS_2ND_COLUMN, FH*0+1, "THR", BOLD);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*0+1, s_timeCumThr, 0, 0);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*0+1, s_timeCumThr);
lcdDrawText(STATS_2ND_COLUMN, FH*1+1, "TH%", BOLD);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*1+1, s_timeCum16ThrP/16, 0, 0);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*1+1, s_timeCum16ThrP/16);
// Timers
for (int i=0; i<TIMERS; i++) {
@ -81,7 +81,7 @@ void menuStatisticsView(event_t event)
if (timersStates[i].val > 3600)
drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, TIMEHOUR, 0);
else
drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, 0, 0);
drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val);
}
#if defined(THRTRACE)

View file

@ -235,17 +235,3 @@ void drawStatusLine()
}
}
#endif
const unsigned char SLEEP_BITMAP[] = {
#include "sleep.lbm"
};
#define SLEEP_BITMAP_WIDTH 60
#define SLEEP_BITMAP_HEIGHT 60
void drawSleepBitmap()
{
lcdClear();
lcdDraw1bitBitmap((LCD_W-SLEEP_BITMAP_WIDTH)/2, (LCD_H-SLEEP_BITMAP_HEIGHT)/2, SLEEP_BITMAP, 0);
lcdRefresh();
}

View file

@ -5,6 +5,7 @@ set(GUI_SRC
fonts.cpp
popups.cpp
widgets.cpp
startup_shutdown.cpp
menu_model.cpp
model_select.cpp
model_setup.cpp

View file

@ -25,6 +25,7 @@
#include "lcd.h"
#include "menus.h"
#include "popups.h"
#include "common/stdlcd/draw_functions.h"
#define HEADER_LINE 0
#define HEADER_LINE_COLUMNS
@ -215,7 +216,6 @@ swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags attr, event_t e
#define ON_OFF_MENU_ITEM(value, x, y, label, attr, event) value = editCheckBox(value, x, y, label, attr, event)
#if defined(GVARS)
void drawGVarName(coord_t x, coord_t y, int8_t index, LcdFlags flags=0);
void drawGVarValue(coord_t x, coord_t y, uint8_t gvar, gvar_t value, LcdFlags flags=0);
int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int16_t max, LcdFlags attr, uint8_t editflags, event_t event);
#define GVAR_MENU_ITEM(x, y, v, min, max, lcdattr, editflags, event) editGVarFieldValue(x, y, v, min, max, lcdattr, editflags, event)
@ -226,9 +226,6 @@ swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags attr, event_t e
#define displayGVar(x, y, v, min, max) lcdDrawNumber(x, y, v)
#endif
void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att = 0);
void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverIdx, LcdFlags flags=0);
void gvarWeightItem(coord_t x, coord_t y, MixData * md, LcdFlags attr, event_t event);
extern uint8_t s_curveChan;

View file

@ -117,7 +117,6 @@ void lcdDrawHexNumber(coord_t x, coord_t y, uint32_t val, LcdFlags mode=0);
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags mode, uint8_t len);
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags mode=0);
void drawStringWithIndex(coord_t x, coord_t y, const char *str, uint8_t idx, LcdFlags att=0);
void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att);
void drawSwitch(coord_t x, coord_t y, int32_t swtch, LcdFlags att=0);
void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att=0);
@ -132,13 +131,6 @@ void putsChnLetter(coord_t x, coord_t y, uint8_t idx, LcdFlags attr);
void putsVolts(coord_t x, coord_t y, uint16_t volts, LcdFlags att);
void putsVBat(coord_t x, coord_t y, LcdFlags att);
void drawRtcTime(coord_t x, coord_t y, LcdFlags att);
void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att, LcdFlags att2);
inline void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att)
{
drawTimer(x, y, tme, att, att);
}
#define SOLID 0xff
#define DOTTED 0x55
@ -163,8 +155,6 @@ inline void lcdDrawSquare(coord_t x, coord_t y, coord_t w, LcdFlags att=0)
void lcdInvertLine(int8_t line);
#define lcdInvertLastLine() lcdInvertLine(LCD_LINES-1)
void drawShutdownAnimation(uint32_t index, const char * message);
void drawSleepBitmap();
void drawTelemetryTopBar();
#define V_BAR(xx, yy, ll) \

View file

@ -0,0 +1,82 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
#define PWR_PRESS_DURATION_MIN 100 // 1s
#define PWR_PRESS_DURATION_MAX 500 // 5s
#define ANIMATIONS_BITMAP_WIDTH 60
#define ANIMATIONS_BITMAP_HEIGHT 60
const unsigned char bmp_startup[] = {
#include "startup.lbm"
};
const unsigned char bmp_lock[] = {
#include "lock.lbm"
};
const unsigned char bmp_shutdown[] = {
#include "shutdown.lbm"
};
const unsigned char bmp_sleep[] = {
#include "sleep.lbm"
};
void drawStartupAnimation(uint32_t duration)
{
uint8_t index = limit<uint8_t>(0, duration / (PWR_PRESS_DURATION_MIN / 5), 4);
lcdRefreshWait();
lcdClear();
if (index == 0)
lcdDrawBitmap((LCD_W - ANIMATIONS_BITMAP_WIDTH) / 2, (LCD_H - ANIMATIONS_BITMAP_HEIGHT) / 2, bmp_lock, 0, ANIMATIONS_BITMAP_WIDTH);
else
lcdDrawBitmap((LCD_W - ANIMATIONS_BITMAP_WIDTH) / 2, (LCD_H - ANIMATIONS_BITMAP_HEIGHT) / 2, bmp_startup, (index - 1) * ANIMATIONS_BITMAP_WIDTH, ANIMATIONS_BITMAP_WIDTH);
lcdRefresh();
}
void drawShutdownAnimation(uint32_t duration, const char * message)
{
uint8_t index = limit<uint8_t>(0, duration / (PWR_PRESS_SHUTDOWN_DELAY / 4), 3);
lcdRefreshWait();
lcdClear();
lcdDrawBitmap((LCD_W - ANIMATIONS_BITMAP_WIDTH) / 2, (LCD_H - ANIMATIONS_BITMAP_HEIGHT) / 2, bmp_shutdown, (3 - index) * ANIMATIONS_BITMAP_WIDTH, ANIMATIONS_BITMAP_WIDTH);
if (message) {
lcdDrawText((LCD_W - getTextWidth(message)) / 2, LCD_H - 2*FH, message);
}
lcdRefresh();
}
void drawSleepBitmap()
{
lcdRefreshWait();
lcdClear();
lcdDrawBitmap((LCD_W - ANIMATIONS_BITMAP_WIDTH) / 2, (LCD_H - ANIMATIONS_BITMAP_HEIGHT) / 2, bmp_sleep, 0);
lcdRefresh();
lcdRefreshWait();
}

View file

@ -59,15 +59,15 @@ void menuStatisticsView(event_t event)
// Session and Total timers
lcdDrawText(STATS_1ST_COLUMN, FH*1+1, "SES", BOLD);
drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*1+1, sessionTimer, 0, 0);
drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*1+1, sessionTimer);
lcdDrawText(STATS_1ST_COLUMN, FH*2+1, "TOT", BOLD);
drawTimer(STATS_1ST_COLUMN + STATS_LABEL_WIDTH, FH*2+1, g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR, 0);
// Throttle special timers
lcdDrawText(STATS_2ND_COLUMN, FH*0+1, "THR", BOLD);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*0+1, s_timeCumThr, 0, 0);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*0+1, s_timeCumThr);
lcdDrawText(STATS_2ND_COLUMN, FH*1+1, "TH%", BOLD);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*1+1, s_timeCum16ThrP/16, 0, 0);
drawTimer(STATS_2ND_COLUMN + STATS_LABEL_WIDTH, FH*1+1, s_timeCum16ThrP/16);
// Timers
for (int i=0; i<TIMERS; i++) {
@ -75,7 +75,7 @@ void menuStatisticsView(event_t event)
if (timersStates[i].val > 3600)
drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, TIMEHOUR, 0);
else
drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val, 0, 0);
drawTimer(STATS_3RD_COLUMN + STATS_LABEL_WIDTH, FH*i+1, timersStates[i].val);
}
#if defined(THRTRACE)

View file

@ -20,19 +20,6 @@
#include "opentx.h"
const unsigned char SLEEP_BITMAP[] = {
#include "../../bitmaps/212x64/sleep.lbm"
};
#define SLEEP_BITMAP_WIDTH 60
#define SLEEP_BITMAP_HEIGHT 60
void drawSleepBitmap()
{
lcdClear();
lcdDrawBitmap((LCD_W-SLEEP_BITMAP_WIDTH)/2, (LCD_H-SLEEP_BITMAP_HEIGHT)/2, SLEEP_BITMAP, 0, SLEEP_BITMAP_WIDTH);
lcdRefresh();
}
void drawStick(coord_t centrex, int16_t xval, int16_t yval)
{
#define BOX_CENTERY (LCD_H-BOX_WIDTH/2-10)

View file

@ -142,12 +142,8 @@ void lcdDrawHexNumber(coord_t x, coord_t y, uint32_t val, LcdFlags mode=0);
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags=0, uint8_t len=0, const char * prefix=NULL, const char * suffix=NULL);
#if !defined(BOOT)
#define putstime_t int32_t
void drawRtcTime(coord_t x, coord_t y, LcdFlags att=0);
void drawTimer(coord_t x, coord_t y, putstime_t tme, LcdFlags att=0);
void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverIdx, LcdFlags flags=0);
void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att=0);
void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att);
void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att=0);
@ -159,7 +155,6 @@ void drawTrimMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att
#define putsChn(x, y, idx, att) drawSource(x, y, MIXSRC_CH1+idx-1, att)
void putsChnLetter(coord_t x, coord_t y, uint8_t idx, LcdFlags attr);
#endif // !BOOT
#define SOLID 0xff

View file

@ -391,20 +391,20 @@ void drawSleepBitmap()
}
#define SHUTDOWN_CIRCLE_DIAMETER 150
void drawShutdownAnimation(uint32_t index, const char * message)
void drawShutdownAnimation(uint32_t duration, const char * message)
{
static uint32_t last_index = 0xffffffff;
static uint32_t lastDuration = 0xffffffff;
static const BitmapBuffer * shutdown = BitmapBuffer::load(getThemePath("shutdown.bmp"));
if (shutdown) {
if (index < last_index) {
if (duration < lastDuration) {
theme->drawBackground();
lcd->drawBitmap((LCD_W-shutdown->getWidth())/2, (LCD_H-shutdown->getHeight())/2, shutdown);
lcdStoreBackupBuffer();
}
else {
lcdRestoreBackupBuffer();
int quarter = index / (PWR_PRESS_SHUTDOWN_DELAY / 5);
int quarter = duration / (PWR_PRESS_SHUTDOWN_DELAY / 5);
if (quarter >= 1) lcdDrawBitmapPattern(LCD_W/2, (LCD_H-SHUTDOWN_CIRCLE_DIAMETER)/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, 0, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 2) lcdDrawBitmapPattern(LCD_W/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER/2, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 3) lcdDrawBitmapPattern((LCD_W-SHUTDOWN_CIRCLE_DIAMETER)/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER, SHUTDOWN_CIRCLE_DIAMETER/2);
@ -413,7 +413,7 @@ void drawShutdownAnimation(uint32_t index, const char * message)
}
else {
lcd->clear();
int quarter = index / (PWR_PRESS_SHUTDOWN_DELAY / 5);
int quarter = duration / (PWR_PRESS_SHUTDOWN_DELAY / 5);
for (int i=1; i<=4; i++) {
if (quarter >= i) {
lcd->drawSolidFilledRect(LCD_W / 2 - 70 + 24 * i, LCD_H / 2 - 10, 20, 20, TEXT_BGCOLOR);
@ -422,5 +422,5 @@ void drawShutdownAnimation(uint32_t index, const char * message)
}
lcdRefresh();
last_index = index;
lastDuration = duration;
}

View file

@ -28,8 +28,6 @@
#define OPTION_MENU_TITLE_BAR 0x02
#define OPTION_MENU_NO_SCROLLBAR 0x04
#define OPTION_SLIDER_INVERS INVERS
#define OPTION_SLIDER_BLINK BLINK
#define OPTION_SLIDER_VERTICAL 0x04
#define OPTION_SLIDER_EMPTY_BAR 0x08
#define OPTION_SLIDER_DBL_COLOR 0x10
@ -68,10 +66,10 @@ int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int
#endif
// Screen templates
void drawMenuTemplate(const char * title, uint8_t icon, const uint8_t * icons=NULL, uint32_t options=0);
void drawMenuTemplate(const char * title, uint8_t icon, const uint8_t * icons=nullptr, uint32_t options=0);
void drawSplash();
void drawSleepBitmap();
void drawShutdownAnimation(uint32_t index, const char * message);
void drawShutdownAnimation(uint32_t duration, const char * message);
// Main view standard widgets
void drawTopBar();

View file

@ -0,0 +1,43 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _COMMON_DRAW_FUNCTIONS_H_
#define _COMMON_DRAW_FUNCTIONS_H_
#include "lcd.h"
void drawStringWithIndex(coord_t x, coord_t y, const char * str, uint8_t idx, LcdFlags att=0);
void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att = 0);
void drawGVarName(coord_t x, coord_t y, int8_t index, LcdFlags flags=0);
void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverIdx, LcdFlags flags=0);
void drawRtcTime(coord_t x, coord_t y, LcdFlags att);
void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att, LcdFlags att2);
inline void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att = 0)
{
drawTimer(x, y, tme, att, att);
}
void drawStartupAnimation(uint32_t duration);
void drawShutdownAnimation(uint32_t duration, const char * message);
void drawSleepBitmap();
#endif // _COMMON_DRAW_FUNCTIONS_H_

View file

@ -233,20 +233,3 @@ void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverI
lcdDrawText(x, y, "External", flags);
}
}
#if defined(PWR_BUTTON_PRESS)
void drawShutdownAnimation(uint32_t index, const char * message)
{
lcdClear();
int quarter = index / (PWR_PRESS_SHUTDOWN_DELAY / 5);
for (int i=1; i<=4; i++) {
if (4 - quarter >= i) {
lcdDrawFilledRect(LCD_W / 2 - 28 + 10 * i, LCD_H / 2 - 3, 6, 6, SOLID, 0);
}
}
if (message) {
lcdDrawText((LCD_W - getTextWidth(message)) / 2, LCD_H-2*FH, message);
}
lcdRefresh();
}
#endif

View file

@ -1728,6 +1728,38 @@ void copyTrimsToOffset(uint8_t ch)
storageDirty(EE_MODEL);
}
#if defined(STARTUP_ANIMATION)
#define PWR_PRESS_DURATION_MIN 100 // 1s
#define PWR_PRESS_DURATION_MAX 500 // 5s
void runStartupAnimation()
{
tmr10ms_t start = get_tmr10ms();
tmr10ms_t duration = 0;
bool isPowerOn = false;
while (pwrPressed()) {
duration = get_tmr10ms() - start;
if (duration < PWR_PRESS_DURATION_MIN) {
drawStartupAnimation(duration);
}
else if (duration >= PWR_PRESS_DURATION_MAX) {
drawSleepBitmap();
backlightDisable();
}
else if (!isPowerOn) {
isPowerOn = true;
pwrOn();
haptic.play(15, 3, PLAY_NOW);
}
}
if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) {
boardOff();
}
}
#endif
void moveTrimsToOffsets() // copy state of 3 primary to subtrim
{
int16_t zeros[MAX_OUTPUT_CHANNELS];
@ -1783,14 +1815,23 @@ void opentxInit()
#endif
#endif
#if defined(RTCLOCK) && !defined(COPROCESSOR)
rtcInit(); // RTC must be initialized before rambackupRestore() is called
#endif
#if defined(EEPROM)
storageReadRadioSettings();
#endif
BACKLIGHT_ENABLE(); // we start the backlight during the startup animation
#if defined(STARTUP_ANIMATION)
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
pwrOn();
}
else {
runStartupAnimation();
}
#else // defined(PWR_BUTTON_PRESS)
pwrOn();
#endif
// Radios handle UNEXPECTED_SHUTDOWN() differently:
// * radios with WDT and EEPROM and CPU controlled power use Reset status register
// and eeGeneral.unexpectedShutdown
@ -1963,7 +2004,7 @@ int main()
stackPaint();
#endif
#if defined(SPLASH) && (defined(PCBTARANIS) || defined(PCBHORUS))
#if defined(SPLASH) && !defined(STARTUP_ANIMATION)
drawSplash();
#endif

View file

@ -429,7 +429,7 @@ extern uint16_t adcValues[NUM_ANALOGS];
#if NUM_PWMSTICKS > 0
#define STICKS_PWM_ENABLED() (!hardwareOptions.sticksPwmDisabled)
void sticksPwmInit(void);
void sticksPwmInit();
void sticksPwmRead(uint16_t * values);
extern volatile uint32_t pwm_interrupt_count;
#else
@ -457,13 +457,13 @@ extern "C" {
#define SOFT_PWR_CTRL
extern uint32_t shutdownRequest; // Stores intentional shutdown to avoid reboot loop
extern uint32_t shutdownReason; // Used for detecting unexpected reboots regardless of reason
void pwrInit(void);
uint32_t pwrCheck(void);
void pwrOn(void);
void pwrOff(void);
void pwrResetHandler(void);
uint32_t pwrPressed(void);
uint32_t pwrPressedDuration(void);
void pwrInit();
uint32_t pwrCheck();
void pwrOn();
void pwrOff();
void pwrResetHandler();
bool pwrPressed();
uint32_t pwrPressedDuration();
#if defined(SIMU) || defined(NO_UNEXPECTED_SHUTDOWN)
#define UNEXPECTED_SHUTDOWN() (false)
#else
@ -471,10 +471,10 @@ uint32_t pwrPressedDuration(void);
#endif
// Led driver
void ledInit(void);
void ledOff(void);
void ledRed(void);
void ledBlue(void);
void ledInit();
void ledOff();
void ledRed();
void ledBlue();
#if defined(PCBX10)
void ledGreen();
#endif
@ -483,15 +483,15 @@ void ledBlue(void);
#define LCD_W 480
#define LCD_H 272
#define LCD_DEPTH 16
void lcdInit(void);
void lcdRefresh(void);
void lcdInit();
void lcdRefresh();
void lcdCopy(void * dest, void * src);
void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h);
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format);
void lcdStoreBackupBuffer(void);
int lcdRestoreBackupBuffer(void);
void lcdStoreBackupBuffer();
int lcdRestoreBackupBuffer();
void lcdSetContrast();
#define lcdOff() backlightEnable(0) /* just disable the backlight */
#define lcdSetRefVolt(...)

View file

@ -96,14 +96,14 @@ void pwrOff()
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
}
uint32_t pwrPressed()
bool pwrPressed()
{
return GPIO_ReadInputDataBit(PWR_ON_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET;
}
void pwrResetHandler()
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOJEN;
RCC->AHB1ENR |= PWR_RCC_AHB1Periph;
// these two NOPs are needed (see STM32F errata sheet) before the peripheral
// register can be written after the peripheral clock was enabled
@ -137,9 +137,11 @@ void pwrResetHandler()
if (shutdownReason == DIRTY_SHUTDOWN) {
powerupReason = DIRTY_SHUTDOWN;
}
#else
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
#endif
pwrOn();
}
#else
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
pwrOn();
}
#endif
}

View file

@ -458,11 +458,7 @@ uint32_t pwrCheck()
return simu_shutdown ? e_power_off : e_power_on;
}
void pwrOff()
{
}
uint32_t pwrPressed()
bool pwrPressed()
{
// TODO: simulate power button
#if defined(PWR_SWITCH_GPIO) // STM32
@ -478,6 +474,14 @@ void pwrInit()
{
}
void pwrOn()
{
}
void pwrOff()
{
}
void readKeysAndTrims()
{
uint8_t index = 0;

View file

@ -76,7 +76,7 @@ void backlightInit()
BACKLIGHT_TIMER->CCMR2 = TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2; // PWM
BACKLIGHT_TIMER->CCER = TIM_CCER_CC4E | TIM_CCER_CC2E;
BACKLIGHT_TIMER->CCR2 = 0;
BACKLIGHT_TIMER->CCR4 = 100;
BACKLIGHT_TIMER->CCR4 = 0;
BACKLIGHT_TIMER->EGR = 0;
BACKLIGHT_TIMER->CR1 = TIM_CR1_CEN; // Counter enable
}

View file

@ -41,21 +41,6 @@ void watchdogInit(unsigned int duration)
IWDG->KR = 0xCCCC; // start
}
#if defined(PWR_BUTTON_PRESS)
#define PWR_PRESS_DURATION_MIN 100 // 1s
#define PWR_PRESS_DURATION_MAX 500 // 5s
#if LCD_DEPTH > 1
const unsigned char bmp_startup[] = {
#include "startup.lbm"
};
const unsigned char bmp_lock[] = {
#include "lock.lbm"
};
#endif
#endif
#if defined(SPORT_UPDATE_PWR_GPIO)
void sportUpdateInit()
{
@ -189,63 +174,6 @@ void boardInit()
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif
#if defined(PWR_BUTTON_PRESS)
if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
lcdClear();
#if LCD_DEPTH > 1
lcdDrawBitmap(76, 2, bmp_lock, 0, 60);
#else
lcdDrawFilledRect(LCD_W / 2 - 18, LCD_H / 2 - 3, 6, 6, SOLID, 0);
#endif
lcdRefresh();
lcdRefreshWait();
tmr10ms_t start = get_tmr10ms();
tmr10ms_t duration = 0;
uint8_t pwr_on = 0;
while (pwrPressed()) {
duration = get_tmr10ms() - start;
if (duration < PWR_PRESS_DURATION_MIN) {
unsigned index = duration / (PWR_PRESS_DURATION_MIN / 4);
lcdClear();
#if LCD_DEPTH > 1
lcdDrawBitmap(76, 2, bmp_startup, index*60, 60);
#else
for(uint8_t i = 0; i < 4; i++) {
if (index >= i) {
lcdDrawFilledRect(LCD_W / 2 - 18 + 10 * i, LCD_H / 2 - 3, 6, 6, SOLID, 0);
}
}
#endif
}
else if (duration >= PWR_PRESS_DURATION_MAX) {
drawSleepBitmap();
backlightDisable();
}
else {
if (pwr_on != 1) {
pwr_on = 1;
pwrOn();
backlightInit();
haptic.play(15, 3, PLAY_NOW);
}
}
lcdRefresh();
lcdRefreshWait();
}
if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) {
boardOff();
}
}
else {
pwrOn();
backlightInit();
}
#else // defined(PWR_BUTTON_PRESS)
pwrOn();
backlightInit();
#endif
#if defined(TOPLCD_GPIO)
toplcdInit();
#endif
@ -266,6 +194,12 @@ void boardInit()
#if defined(GYRO)
gyroInit();
#endif
#if defined(RTCLOCK) && !defined(COPROCESSOR)
rtcInit(); // RTC must be initialized before rambackupRestore() is called
#endif
backlightInit();
}
void boardOff()

View file

@ -30,8 +30,8 @@
#if defined(ROTARY_ENCODER_NAVIGATION)
// Rotary Encoder driver
void rotaryEncoderInit(void);
void rotaryEncoderCheck(void);
void rotaryEncoderInit();
void rotaryEncoderCheck();
#endif
#define FLASHSIZE 0x80000
@ -54,8 +54,8 @@ void rotaryEncoderCheck(void);
extern uint16_t sessionTimer;
// Board driver
void boardInit(void);
void boardOff(void);
void boardInit();
void boardOff();
// Timers driver
void init2MhzTimer();
@ -64,8 +64,8 @@ void init5msTimer();
// SD driver
#define BLOCK_SIZE 512 /* Block Size in Bytes */
#if !defined(SIMU) || defined(SIMU_DISKIO)
uint32_t sdIsHC(void);
uint32_t sdGetSpeed(void);
uint32_t sdIsHC();
uint32_t sdGetSpeed();
#define SD_IS_HC() (sdIsHC())
#define SD_GET_SPEED() (sdGetSpeed())
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
@ -83,18 +83,18 @@ uint32_t sdGetSpeed(void);
#define sdMount()
#define SD_CARD_PRESENT() true
#else
void sdInit(void);
void sdMount(void);
void sdDone(void);
void sdPoll10ms(void);
uint32_t sdMounted(void);
void sdInit();
void sdMount();
void sdDone();
void sdPoll10ms();
uint32_t sdMounted();
#define SD_CARD_PRESENT() ((SD_GPIO_PRESENT_GPIO->IDR & SD_GPIO_PRESENT_GPIO_PIN) == 0)
#endif
// Flash Write driver
#define FLASH_PAGESIZE 256
void unlockFlash(void);
void lockFlash(void);
void unlockFlash();
void lockFlash();
void flashWrite(uint32_t * address, uint32_t * buffer);
uint32_t isFirmwareStart(const uint8_t * buffer);
uint32_t isBootloaderStart(const uint8_t * buffer);
@ -603,15 +603,16 @@ extern "C" {
// Power driver
#define SOFT_PWR_CTRL
void pwrInit(void);
uint32_t pwrCheck(void);
void pwrOn(void);
void pwrOff(void);
uint32_t pwrPressed(void);
void pwrInit();
uint32_t pwrCheck();
void pwrOn();
void pwrOff();
bool pwrPressed();
#if defined(PWR_BUTTON_PRESS)
uint32_t pwrPressedDuration(void);
#define STARTUP_ANIMATION
uint32_t pwrPressedDuration();
#endif
void pwrResetHandler(void);
void pwrResetHandler();
#if defined(SIMU)
#define UNEXPECTED_SHUTDOWN() false
@ -620,10 +621,10 @@ void pwrResetHandler(void);
#endif
// Backlight driver
void backlightInit(void);
void backlightDisable(void);
void backlightInit();
void backlightDisable();
#define BACKLIGHT_DISABLE() backlightDisable()
uint8_t isBacklightEnabled(void);
uint8_t isBacklightEnabled();
#if defined(PCBX9E) || defined(PCBX9DP)
void backlightEnable(uint8_t level, uint8_t color);
#define BACKLIGHT_ENABLE() backlightEnable(g_eeGeneral.backlightBright, g_eeGeneral.backlightColor)
@ -646,7 +647,7 @@ uint8_t isBacklightEnabled(void);
// I2C driver: EEPROM + Audio Volume
#define EEPROM_SIZE (32*1024)
void i2cInit(void);
void i2cInit();
void eepromReadBlock(uint8_t * buffer, size_t address, size_t size);
void eepromStartWrite(uint8_t * buffer, size_t address, size_t size);
uint8_t eepromIsTransferComplete();
@ -656,8 +657,8 @@ void debugPutc(const char c);
// Telemetry driver
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
void telemetryPortSetDirectionInput(void);
void telemetryPortSetDirectionOutput(void);
void telemetryPortSetDirectionInput();
void telemetryPortSetDirectionOutput();
void sportSendByte(uint8_t byte);
void sportSendByteLoop(uint8_t byte);
void sportStopSendByteLoop();
@ -678,9 +679,9 @@ extern uint32_t telemetryErrors;
// Sport update driver
#if defined(SPORT_UPDATE_PWR_GPIO)
void sportUpdateInit(void);
void sportUpdatePowerOn(void);
void sportUpdatePowerOff(void);
void sportUpdateInit();
void sportUpdatePowerOn();
void sportUpdatePowerOff();
#define SPORT_UPDATE_POWER_ON() sportUpdatePowerOn()
#define SPORT_UPDATE_POWER_OFF() sportUpdatePowerOff()
#else
@ -690,38 +691,38 @@ void sportUpdatePowerOff(void);
#endif
// Audio driver
void audioInit(void) ;
void audioEnd(void) ;
void dacStart(void);
void dacStop(void);
void audioInit() ;
void audioEnd() ;
void dacStart();
void dacStop();
void setSampleRate(uint32_t frequency);
#define VOLUME_LEVEL_MAX 23
#define VOLUME_LEVEL_DEF 12
#if !defined(SOFTWARE_VOLUME)
void setScaledVolume(uint8_t volume);
void setVolume(uint8_t volume);
int32_t getVolume(void);
int32_t getVolume();
#endif
#if defined(AUDIO_SPEAKER_ENABLE_GPIO)
void initSpeakerEnable(void);
void initSpeakerEnable();
void enableSpeaker();
void disableSpeaker();
#else
static inline void initSpeakerEnable(void) { }
static inline void enableSpeaker(void) { }
static inline void disableSpeaker(void) { }
static inline void initSpeakerEnable() { }
static inline void enableSpeaker() { }
static inline void disableSpeaker() { }
#endif
#if defined(HEADPHONE_TRAINER_SWITCH_GPIO)
void initHeadphoneTrainerSwitch(void);
void enableHeadphone(void);
void enableTrainer(void);
void initHeadphoneTrainerSwitch();
void enableHeadphone();
void enableTrainer();
#else
static inline void initHeadphoneTrainerSwitch(void) { }
static inline void enableHeadphone(void) { }
static inline void enableTrainer(void) { }
static inline void initHeadphoneTrainerSwitch() { }
static inline void enableHeadphone() { }
static inline void enableTrainer() { }
#endif
#if defined(JACK_DETECT_GPIO)
void initJackDetect(void);
void initJackDetect();
bool isJackPlugged();
#endif
void audioConsumeCurrentBuffer();
@ -729,12 +730,12 @@ void audioConsumeCurrentBuffer();
#define audioEnableIrq() __enable_irq()
// Haptic driver
void hapticInit(void);
void hapticOff(void);
void hapticInit();
void hapticOff();
#if defined(HAPTIC_PWM)
void hapticOn(uint32_t pwmPercent);
#else
void hapticOn(void);
void hapticOn();
#endif
// Second serial port driver
@ -745,8 +746,8 @@ extern uint8_t auxSerialMode;
void auxSerialInit(unsigned int mode, unsigned int protocol);
void auxSerialPutc(char c);
#define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
void auxSerialSbusInit(void);
void auxSerialStop(void);
void auxSerialSbusInit();
void auxSerialStop();
#endif
// BT driver
@ -760,9 +761,9 @@ void auxSerialStop(void);
#define BT_TX_FIFO_SIZE 64
#define BT_RX_FIFO_SIZE 128
void bluetoothInit(uint32_t baudrate, bool enable);
void bluetoothWriteWakeup(void);
uint8_t bluetoothIsWriting(void);
void bluetoothDisable(void);
void bluetoothWriteWakeup();
uint8_t bluetoothIsWriting();
void bluetoothDisable();
#if defined(PCBX9LITE)
#define IS_BLUETOOTH_CHIP_PRESENT() (false)
#elif (defined(PCBX7) || defined(PCBXLITE)) && !defined(SIMU)
@ -773,11 +774,11 @@ void bluetoothDisable(void);
#endif
// LED driver
void ledInit(void);
void ledOff(void);
void ledRed(void);
void ledGreen(void);
void ledBlue(void);
void ledInit();
void ledOff();
void ledRed();
void ledGreen();
void ledBlue();
// LCD driver
#if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E)
@ -803,9 +804,9 @@ void ledBlue(void);
#define IS_LCD_RESET_NEEDED() true
#endif
void lcdInit(void);
void lcdInitFinish(void);
void lcdOff(void);
void lcdInit();
void lcdInitFinish();
void lcdOff();
// TODO lcdRefreshWait() stub in simpgmspace and remove LCD_DUAL_BUFFER
#if defined(LCD_DMA) && !defined(LCD_DUAL_BUFFER) && !defined(SIMU)
@ -814,19 +815,19 @@ void lcdRefreshWait();
#define lcdRefreshWait()
#endif
#if defined(PCBX9D) || defined(SIMU) || !defined(__cplusplus)
void lcdRefresh(void);
void lcdRefresh();
#else
void lcdRefresh(bool wait=true); // TODO uint8_t wait to simplify this
#endif
void lcdSetRefVolt(unsigned char val);
void lcdSetContrast(void);
void lcdSetContrast();
// Top LCD driver
#if defined(TOPLCD_GPIO)
void toplcdInit(void);
void toplcdOff(void);
void toplcdRefreshStart(void);
void toplcdRefreshEnd(void);
void toplcdInit();
void toplcdOff();
void toplcdRefreshStart();
void toplcdRefreshEnd();
void setTopFirstTimer(int32_t value);
void setTopSecondTimer(uint32_t value);
void setTopRssi(uint32_t rssi);

View file

@ -83,14 +83,14 @@ void pwrOff()
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
}
uint32_t pwrPressed()
bool pwrPressed()
{
return GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET;
}
void pwrResetHandler()
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN;
RCC->AHB1ENR |= PWR_RCC_AHB1Periph;
// these two NOPs are needed (see STM32F errata sheet) before the peripheral
// register can be written after the peripheral clock was enabled