Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Little speed optimisations of boot #884

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 42 additions & 46 deletions src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,43 @@ void drawSubmenu(int index,std::vector<Option>& options, String system) {

}

void drawMainBorder(bool clear) {
void drawStatusBar() {
#if defined(HAS_RTC)
cplus_RTC _rtc;
RTC_TimeTypeDef _time;
#endif
int i=0;
uint8_t bat = getBattery();
uint8_t bat_margin = 85;
if(bat>0) {
drawBatteryStatus(bat);
} else bat_margin = 20;
if(sdcardMounted) { tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); tft.setTextSize(FP); tft.drawString("SD", tftWidth - (bat_margin + 20*i),12); i++; } // Indication for SD card on screen
if(gpsConnected) { drawGpsSmall(tftWidth - (bat_margin + 20*i), 7); i++; }
if(wifiConnected) { drawWifiSmall(tftWidth - (bat_margin + 20*i), 7); i++;} //Draw Wifi Symbol beside battery
if(BLEConnected) { drawBLESmall(tftWidth - (bat_margin + 20*i), 7); i++; } //Draw BLE beside Wifi
if(isConnectedWireguard) { drawWireguardStatus(tftWidth - (bat_margin + 21*i), 7); i++; }//Draw Wg bedide BLE, if the others exist, if not, beside battery


tft.drawRoundRect(5, 5, tftWidth - 10, tftHeight - 10, 5, bruceConfig.priColor);
tft.drawLine(5, 25, tftWidth - 6, 25, bruceConfig.priColor);
if (clock_set) {
setTftDisplay(12, 12, bruceConfig.priColor, 1, bruceConfig.bgColor);
#if defined(HAS_RTC)
cplus_RTC _rtc;
RTC_TimeTypeDef _time;
_rtc.GetTime(&_time);
snprintf(timeStr, sizeof(timeStr), "%02d:%02d", _time.Hours, _time.Minutes);
tft.print(timeStr);
#else
updateTimeStr(rtc.getTimeStruct());
tft.print(timeStr);
#endif
} else {
setTftDisplay(12, 12, bruceConfig.priColor, 1, bruceConfig.bgColor);
tft.print("BRUCE " + String(BRUCE_VERSION));
}
}

void drawMainBorder(bool clear) {
if(clear){
tft.fillScreen(bruceConfig.bgColor);
tft.fillScreen(bruceConfig.bgColor);
Expand All @@ -560,36 +592,8 @@ void drawMainBorder(bool clear) {

// if(wifiConnected) {tft.print(timeStr);} else {tft.print("BRUCE 1.0b");}

int i=0;
uint8_t bat = getBattery();
uint8_t bat_margin = 85;
if(bat>0) {
drawBatteryStatus(bat);
} else bat_margin = 20;
if(sdcardMounted) { tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); tft.setTextSize(FP); tft.drawString("SD", tftWidth - (bat_margin + 20*i),12); i++; } // Indication for SD card on screen
if(gpsConnected) { drawGpsSmall(tftWidth - (bat_margin + 20*i), 7); i++; }
if(wifiConnected) { drawWifiSmall(tftWidth - (bat_margin + 20*i), 7); i++;} //Draw Wifi Symbol beside battery
if(BLEConnected) { drawBLESmall(tftWidth - (bat_margin + 20*i), 7); i++; } //Draw BLE beside Wifi
if(isConnectedWireguard) { drawWireguardStatus(tftWidth - (bat_margin + 21*i), 7); i++; }//Draw Wg bedide BLE, if the others exist, if not, beside battery


tft.drawRoundRect(5, 5, tftWidth - 10, tftHeight - 10, 5, bruceConfig.priColor);
tft.drawLine(5, 25, tftWidth - 6, 25, bruceConfig.priColor);
if (clock_set) {
setTftDisplay(12, 12, bruceConfig.priColor, 1, bruceConfig.bgColor);
#if defined(HAS_RTC)
_rtc.GetTime(&_time);
snprintf(timeStr, sizeof(timeStr), "%02d:%02d", _time.Hours, _time.Minutes);
tft.print(timeStr);
#else
updateTimeStr(rtc.getTimeStruct());
tft.print(timeStr);
#endif
}
else {
setTftDisplay(12, 12, bruceConfig.priColor, 1, bruceConfig.bgColor);
tft.print("BRUCE " + String(BRUCE_VERSION));
}
drawStatusBar();

#if defined(HAS_TOUCH)
TouchFooter();
#endif
Expand Down Expand Up @@ -1086,18 +1090,10 @@ bool Gif::openGIF(FS *fs, const char *filename) {
GIFDraw
)
) {
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif->getCanvasWidth(), gif->getCanvasHeight());
GIFINFO gi;
if (gif->getInfo(&gi)) {
Serial.printf("frame count: %d\n", gi.iFrameCount);
Serial.printf("duration: %d ms\n", gi.iDuration);
Serial.printf("max delay: %d ms\n", gi.iMaxDelay);
Serial.printf("min delay: %d ms\n", gi.iMinDelay);
return true;
}
return true;
}

Serial.printf("GIF opening error: %d\n", gif->getLastError());
log_e("GIF opening error: %d\n", gif->getLastError());
return false;
}

Expand All @@ -1107,8 +1103,8 @@ bool Gif::openGIF(FS *fs, const char *filename) {
// 1 = good result and more frames exist
// 0 = no more frames exist, a frame may or may not have been played: use getLastError() and look for GIF_SUCCESS to know if a frame was played
// -1 = error
int Gif::playFrame(int x, int y) {
if ((millis() - lTime) >= *delayMilliseconds) {
int Gif::playFrame(int x, int y, bool bSync) {
if (bSync && ((millis() - lTime) >= *delayMilliseconds)) {
lTime = millis();
gifPosition.x = x;
gifPosition.y = y;
Expand Down Expand Up @@ -1148,7 +1144,7 @@ bool showGif(FS *fs, const char *filename, int x, int y, bool center, int playDu
long timeStart = millis();
do {
result = gif.playFrame(x, y);
if (result == -1) Serial.printf("GIF playFrame error: %d\n", gif.getLastError());
if (result == -1) log_e("GIF playFrame error: %d\n", gif.getLastError());

if(check(AnyKeyPress)) break;

Expand Down
3 changes: 2 additions & 1 deletion src/core/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Gif {

bool openGIF(FS *fs, const char *filename);

int playFrame(int x, int y);
int playFrame(int x = 0, int y = 0, bool bSync = true);

int getInfo(GIFINFO *pInfo) {
return gif->getInfo(pInfo);
Expand Down Expand Up @@ -141,6 +141,7 @@ Opt_Coord drawOptions(int index,std::vector<Option>& options, uint16_t fgcolor,

void drawSubmenu(int index,std::vector<Option>& options, String system);

void drawStatusBar();
void drawMainBorder(bool clear = true);
void drawMainBorderWithTitle(String title, bool clear = true);
void printTitle(String title);
Expand Down
14 changes: 8 additions & 6 deletions src/core/wifi_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bool wifiConnectMenu(wifi_mode_t mode)
return wifiConnected;
}

void wifiConnectTask(int maxSearch)
void wifiConnectTask(void * pvParameters)
{
if (WiFi.status() == WL_CONNECTED) return;

Expand All @@ -145,23 +145,25 @@ void wifiConnectTask(int maxSearch)
String ssid;
String pwd;

for (int i = 0; i < min(nets, maxSearch); i++) {
ssid = WiFi.SSID(i).c_str();
for (int i = 0; i < nets; i++) {
ssid = WiFi.SSID(i);
pwd = bruceConfig.getWifiPassword(ssid);
if (pwd == "") continue;

WiFi.begin(ssid, pwd);
for (int i = 0; i<20; i++) {
for (int i = 0; i<50; i++) {
if (WiFi.status() == WL_CONNECTED) {
wifiConnected = true;
wifiIP = WiFi.localIP().toString();
updateClockTimezone();
return;
drawStatusBar();
break;
}
delay(300);
delay(100);
}
}

vTaskDelete(NULL);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/wifi_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ String checkMAC();
* using stored passwords
* @TODO fix: rn it skips open networks due to password == "" check
*/
void wifiConnectTask(int maxSearch = 5);
void wifiConnectTask(void * pvParameters);


// private
Expand Down
28 changes: 16 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,13 @@ void boot_screen_anim() {
// checks for boot.jpg in SD and LittleFS for customization
int boot_img=0;
bool drawn=false;
if(SD.exists("/boot.jpg")) boot_img = 1;
else if(LittleFS.exists("/boot.jpg")) boot_img = 2;
else if(SD.exists("/boot.gif")) boot_img = 3;
else if(LittleFS.exists("/boot.gif")) boot_img = 4;
if(sdcardMounted) {
if(SD.exists("/boot.jpg")) boot_img = 1;
else if(SD.exists("/boot.gif")) boot_img = 3;
}
if(boot_img == 0 && LittleFS.exists("/boot.jpg")) boot_img = 2;
else if(boot_img == 0 && LittleFS.exists("/boot.gif")) boot_img = 4;

tft.drawPixel(0,0,0); // Forces back communication with TFT, to avoid ghosting
// Start image loop
while(millis()<i+7000) { // boot image lasts for 5 secs
Expand Down Expand Up @@ -327,7 +330,6 @@ void setup() {
tft.begin();
#endif
begin_storage();
bruceConfig.fromFile();
begin_tft();
init_clock();
init_led();
Expand All @@ -353,9 +355,14 @@ void setup() {
startup_sound();

if (bruceConfig.wifiAtStartup) {
displayInfo("Connecting WiFi...");
wifiConnectTask();
tft.fillScreen(bruceConfig.bgColor);
xTaskCreate(
wifiConnectTask, // Task function
"wifiConnectTask", // Task Name
4096, // Stack size
NULL, // Task parameters
2, // Task priority (0 to 3), loopTask has priority 2.
NULL // Task handle (not used)
);
}

#if ! defined(HAS_SCREEN)
Expand Down Expand Up @@ -392,16 +399,14 @@ void loop() {
interpreter_start=false;
interpreter();
previousMillis = millis(); // ensure that will not dim screen when get back to menu
//goto END;
}
#endif
#endif
tft.fillScreen(bruceConfig.bgColor);
bruceConfig.fromFile();


while(1){
if(interpreter_start) goto END;
if(interpreter_start) break;
if (returnToMenu) {
returnToMenu = false;
tft.fillScreen(bruceConfig.bgColor); //fix any problem with the mainMenu screen when coming back from submenus or functions
Expand Down Expand Up @@ -461,7 +466,6 @@ void loop() {
clock_update=millis();
}
}
END:
delay(1);
}
#else
Expand Down