freemyipod r879 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r878‎ | r879 | r880 >
Date:14:11, 1 August 2013
Author:theseven
Status:new
Tags:
Comment:
emCORE Boot Menus: Cache PMU/RTC data for 10 seconds to avoid spamming the I2C bus
Modified paths:
  • /apps/bootmenu-ipodclassic-wintertheme/util.c (modified) (history)
  • /apps/bootmenu-ipodclassic/util.c (modified) (history)
  • /apps/bootmenu-ipodnano2g-wintertheme/util.c (modified) (history)
  • /apps/bootmenu-ipodnano2g/util.c (modified) (history)

Diff [purge]

Index: apps/bootmenu-ipodclassic-wintertheme/util.c
@@ -26,6 +26,11 @@
2727 #include "main.h"
2828
2929
 30+static struct rtc_datetime datetime;
 31+static unsigned int batt_level;
 32+static long next_refresh = 0;
 33+
 34+
3035 struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
3136 {
3237 struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
@@ -48,9 +53,13 @@
4954 bool update_display(struct chooser_data* data)
5055 {
5156 char buf[6];
52 - struct rtc_datetime dt;
53 - rtc_read_datetime(&dt);
54 - snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
 57+ if (!next_refresh || TIMEOUT_EXPIRED(next_refresh, 10000000))
 58+ {
 59+ rtc_read_datetime(&datetime);
 60+ batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
 61+ next_refresh = USEC_TIMER;
 62+ }
 63+ snprintf(buf, sizeof(buf), "%02d:%02d", datetime.hour, datetime.minute);
5564 // clock
5665 rendertext(framebuf, 287, 4, 320, 0xff3f0000, 0x3fffffff, buf);
5766 // draw the battery meter box
@@ -64,7 +73,6 @@
6574 ui->blendcolor(1, 6, 0xcf7f0000, framebuf, 27, 5, 320, framebuf, 27, 5, 320);
6675 // top - right
6776 ui->blendcolor(1, 4, 0xcf7f0000, framebuf, 28, 6, 320, framebuf, 28, 6, 320);
68 - unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
6977 // remaining battery level
7078 ui->blendcolor(batt_level, 6, 0x7fff7f7f, framebuf, 5, 5, 320, framebuf, 5, 5, 320);
7179 // background of the rest space
Index: apps/bootmenu-ipodnano2g-wintertheme/util.c
@@ -26,6 +26,11 @@
2727 #include "main.h"
2828
2929
 30+static struct rtc_datetime datetime;
 31+static unsigned int batt_level;
 32+static long next_refresh = 0;
 33+
 34+
3035 struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
3136 {
3237 struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
@@ -48,9 +53,13 @@
4954 bool update_display(struct chooser_data* data)
5055 {
5156 char buf[6];
52 - struct rtc_datetime dt;
53 - rtc_read_datetime(&dt);
54 - snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
 57+ if (!next_refresh || TIMEOUT_EXPIRED(next_refresh, 10000000))
 58+ {
 59+ rtc_read_datetime(&datetime);
 60+ batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
 61+ next_refresh = USEC_TIMER;
 62+ }
 63+ snprintf(buf, sizeof(buf), "%02d:%02d", datetime.hour, datetime.minute);
5564 // clock
5665 rendertext(framebuf, 143, 4, 176, 0xff3f0000, 0x3fffffff, buf);
5766 // draw the battery meter box
@@ -64,7 +73,6 @@
6574 ui->blendcolor(1, 6, 0xcf7f0000, framebuf, 27, 5, 176, framebuf, 27, 5, 176);
6675 // top - right
6776 ui->blendcolor(1, 4, 0xcf7f0000, framebuf, 28, 6, 176, framebuf, 28, 6, 176);
68 - unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
6977 // remaining battery level
7078 ui->blendcolor(batt_level, 6, 0x7fff7f7f, framebuf, 5, 5, 176, framebuf, 5, 5, 176);
7179 // background of the rest space
Index: apps/bootmenu-ipodclassic/util.c
@@ -26,6 +26,11 @@
2727 #include "main.h"
2828
2929
 30+static struct rtc_datetime datetime;
 31+static unsigned int batt_level;
 32+static long next_refresh = 0;
 33+
 34+
3035 struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
3136 {
3237 struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
@@ -48,9 +53,13 @@
4954 bool update_display(struct chooser_data* data)
5055 {
5156 char buf[6];
52 - struct rtc_datetime dt;
53 - rtc_read_datetime(&dt);
54 - snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
 57+ if (!next_refresh || TIMEOUT_EXPIRED(next_refresh, 10000000))
 58+ {
 59+ rtc_read_datetime(&datetime);
 60+ batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
 61+ next_refresh = USEC_TIMER;
 62+ }
 63+ snprintf(buf, sizeof(buf), "%02d:%02d", datetime.hour, datetime.minute);
5564 // clock
5665 rendertext(framebuf, 287, 4, 320, 0xffffcccc, 0, buf);
5766 // draw the battery meter box
@@ -64,7 +73,6 @@
6574 ui->blendcolor(1, 6, 0xffffcccc, framebuf, 27, 5, 320, framebuf, 27, 5, 320);
6675 // top - right
6776 ui->blendcolor(1, 4, 0xffffcccc, framebuf, 28, 6, 320, framebuf, 28, 6, 320);
68 - unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
6977 // remaining battery level
7078 ui->blendcolor(batt_level, 6, 0xc0ffcccc, framebuf, 5, 5, 320, framebuf, 5, 5, 320);
7179 // background of the rest space
Index: apps/bootmenu-ipodnano2g/util.c
@@ -26,6 +26,11 @@
2727 #include "main.h"
2828
2929
 30+static struct rtc_datetime datetime;
 31+static unsigned int batt_level;
 32+static long next_refresh = 0;
 33+
 34+
3035 struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
3136 {
3237 struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
@@ -48,9 +53,13 @@
4954 bool update_display(struct chooser_data* data)
5055 {
5156 char buf[6];
52 - struct rtc_datetime dt;
53 - rtc_read_datetime(&dt);
54 - snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
 57+ if (!next_refresh || TIMEOUT_EXPIRED(next_refresh, 10000000))
 58+ {
 59+ rtc_read_datetime(&datetime);
 60+ batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
 61+ next_refresh = USEC_TIMER;
 62+ }
 63+ snprintf(buf, sizeof(buf), "%02d:%02d", datetime.hour, datetime.minute);
5564 // clock
5665 rendertext(framebuf, 143, 4, 176, 0xffffcccc, 0, buf);
5766 // draw the battery meter box
@@ -64,7 +73,6 @@
6574 ui->blendcolor(1, 6, 0xffffcccc, framebuf, 27, 5, 176, framebuf, 27, 5, 176);
6675 // tip - right
6776 ui->blendcolor(1, 4, 0xffffcccc, framebuf, 28, 6, 176, framebuf, 28, 6, 176);
68 - unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
6977 // remaining battery level
7078 ui->blendcolor(batt_level, 6, 0xc0ffcccc, framebuf, 5, 5, 176, framebuf, 5, 5, 176);
7179 // background of the rest space