Skip to content

Commit

Permalink
Fixed low battery warning overlapping other battery icons (#1358)
Browse files Browse the repository at this point in the history
This fix disabled the low battery warning when MainUI and other apps
with a battery displayed are running

---------

Co-authored-by: Aemiii91 <44569252+Aemiii91@users.noreply.github.com>
  • Loading branch information
schmurtzm and Aemiii91 committed Jan 6, 2024
1 parent 1f1a659 commit 3936bab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/batmon/batmon.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "batmon.h"
#include "system/device_model.h"
#include "utils/process.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -123,13 +124,15 @@ int main(int argc, char *argv[])
}

#ifdef PLATFORM_MIYOOMINI
if (is_suspended || current_percentage == 500)
if (is_suspended || current_percentage == 500) {
batteryWarning_hide();
else if (current_percentage < warn_at &&
!config_flag_get(".noBatteryWarning"))
}
else if (current_percentage < warn_at && !warningDisabled()) {
batteryWarning_show();
else
}
else {
batteryWarning_hide();
}
#endif
if (battery_current_state_duration > MAX_DURATION_BEFORE_UPDATE)
update_current_duration();
Expand Down Expand Up @@ -384,6 +387,8 @@ int batteryPercentage(int value)
static void *batteryWarning_thread(void *param)
{
while (1) {
if (temp_flag_get("hasBatteryDisplay"))
break;
display_drawBatteryIcon(0x00FF0000, 15, RENDER_HEIGHT - 30, 10,
0x00FF0000); // draw red battery icon
usleep(0x4000);
Expand All @@ -407,3 +412,8 @@ void batteryWarning_hide(void)
pthread_join(adc_pt, NULL);
adcthread_active = false;
}

bool warningDisabled(void)
{
return config_flag_get(".noBatteryWarning") || temp_flag_get("hasBatteryDisplay") || process_isRunning("MainUI");
}
1 change: 1 addition & 0 deletions src/batmon/batmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ int batteryPercentage(int);
static void *batteryWarning_thread(void *param);
void batteryWarning_show(void);
void batteryWarning_hide(void);
bool warningDisabled(void);

#endif // ADC_H__
15 changes: 14 additions & 1 deletion src/common/theme/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include <SDL/SDL_ttf.h>
#include <stdbool.h>

#include "./config.h"
#include "system/lang.h"
#include "utils/flags.h"
#include "utils/log.h"

#include "./config.h"

#define RES_MAX_REQUESTS 200

typedef enum theme_images {
Expand Down Expand Up @@ -97,6 +99,15 @@ SDL_Surface *_loadImage(ThemeImages request)
Theme_s *t = theme();
int real_location, backup_location;

if (request == BATTERY_0 ||
request == BATTERY_20 ||
request == BATTERY_50 ||
request == BATTERY_80 ||
request == BATTERY_100 ||
request == BATTERY_CHARGING) {
temp_flag_set("hasBatteryDisplay", true);
}

switch (request) {
case BG_TITLE:
return theme_loadImage(t->path, "bg-title");
Expand Down Expand Up @@ -301,6 +312,8 @@ SDL_Surface *resource_getBrightness(int brightness)

void resources_free()
{
temp_flag_set("hasBatteryDisplay", false);

for (int i = 0; i < images_count; i++)
if (resources.surfaces[i] != NULL)
SDL_FreeSurface(resources.surfaces[i]);
Expand Down

0 comments on commit 3936bab

Please sign in to comment.