Selaa lähdekoodia

only redraw battery indicator when needed

Thomas Buck 1 vuosi sitten
vanhempi
commit
3f60298a6e
1 muutettua tiedostoa jossa 12 lisäystä ja 1 poistoa
  1. 12
    1
      src/image.c

+ 12
- 1
src/image.c Näytä tiedosto

17
  */
17
  */
18
 
18
 
19
 #include <stdio.h>
19
 #include <stdio.h>
20
+#include <string.h>
20
 
21
 
21
 #include "config.h"
22
 #include "config.h"
22
 #include "lcd.h"
23
 #include "lcd.h"
90
 
91
 
91
 void draw_battery_indicator(void) {
92
 void draw_battery_indicator(void) {
92
     static const float batt_warn_limit = 15.0f;
93
     static const float batt_warn_limit = 15.0f;
93
-    static char s[30];
94
+    static char prev_s[30] = {0};
95
+    static uint32_t prev_c = 0;
96
+
97
+    char s[30] = {0};
94
     float v = lipo_voltage();
98
     float v = lipo_voltage();
95
     uint32_t c = RGB_565(0xFF, 0x00, 0x00);
99
     uint32_t c = RGB_565(0xFF, 0x00, 0x00);
96
     if (lipo_charging()) {
100
     if (lipo_charging()) {
107
         }
111
         }
108
     }
112
     }
109
 
113
 
114
+    // only re-draw battery indicator when it has changed
115
+    if ((strcmp(s, prev_s) == 0) && (prev_c == c)) {
116
+        return;
117
+    }
118
+    strcpy(prev_s, s);
119
+    prev_c = c;
120
+
110
     static struct text_font font = {
121
     static struct text_font font = {
111
         .fontname = "fixed_10x20",
122
         .fontname = "fixed_10x20",
112
         .font = NULL,
123
         .font = NULL,

Loading…
Peruuta
Tallenna