freemyipod r765 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r764‎ | r765 | r766 >
Date:22:36, 23 August 2011
Author:user890104
Status:new
Tags:
Comment:
bootmenu-ipodclassic, bootmenu-ipodnano2g: fix battery meter and clock not being shown while displaying the Tools menu
Modified paths:
  • /apps/bootmenu-ipodclassic/main.c (modified) (history)
  • /apps/bootmenu-ipodnano2g/main.c (modified) (history)

Diff [purge]

Index: apps/bootmenu-ipodclassic/main.c
@@ -258,6 +258,22 @@
259259 message(106, "Data partition has", "been reformatted.");
260260 }
261261
 262+bool update_display(struct chooser_data* data)
 263+{
 264+ char buf[6];
 265+ struct rtc_datetime dt;
 266+ rtc_read_datetime(&dt);
 267+ snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
 268+ // clock
 269+ rendertext(framebuf, 287, 4, 320, 0xffffcccc, 0, buf);
 270+ unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
 271+ // remaining battery level
 272+ ui->blendcolor(batt_level, 6, 0xc0ffcccc, framebuf, 5, 5, 320, framebuf, 5, 5, 320);
 273+ // background of the rest space
 274+ ui->blendcolor(22 - batt_level, 6, 0x40000000, framebuf, 5 + batt_level, 5, 320, framebuf, 5 + batt_level, 5, 320);
 275+ return false;
 276+}
 277+
262278 struct chooser_renderer_list_params toolchooser_rparams =
263279 {
264280 .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
@@ -276,7 +292,7 @@
277293 .blit_dest = LIBUI_POINT(0, 0),
278294 .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
279295 LIBUI_POINT(320, 240)),
280 - .preblit = NULL,
 296+ .preblit = update_display,
281297 .postblit = NULL
282298 };
283299
@@ -348,22 +364,12 @@
349365
350366 bool mainchooser_preblit(struct chooser_data* data)
351367 {
352 - char buf[6];
353 - struct rtc_datetime dt;
354 - rtc_read_datetime(&dt);
355 - snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
356 - // clock
357 - rendertext(framebuf, 287, 4, 320, 0xffffcccc, 0, buf);
 368+ char buf[4];
358369 struct chooser_action_handler_wheel_data* adata;
359370 adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
360371 snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
361 - // remaining time
362372 rendertext(framebuf, 299, 229, 320, 0xffffcccc, 0, buf);
363 - unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
364 - // remaining battery level
365 - ui->blendcolor(batt_level, 6, 0xc0ffcccc, framebuf, 5, 5, 320, framebuf, 5, 5, 320);
366 - // background of the rest space
367 - ui->blendcolor(22 - batt_level, 6, 0x40000000, framebuf, 5 + batt_level, 5, 320, framebuf, 5 + batt_level, 5, 320);
 373+ update_display(data);
368374 return false;
369375 }
370376
Index: apps/bootmenu-ipodnano2g/main.c
@@ -318,6 +318,22 @@
319319 }
320320 }
321321
 322+bool update_display(struct chooser_data* data)
 323+{
 324+ char buf[6];
 325+ struct rtc_datetime dt;
 326+ rtc_read_datetime(&dt);
 327+ snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
 328+ // clock
 329+ rendertext(framebuf, 143, 4, 176, 0xffffcccc, 0, buf);
 330+ unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
 331+ // remaining battery level
 332+ ui->blendcolor(batt_level, 6, 0xc0ffcccc, framebuf, 5, 5, 176, framebuf, 5, 5, 176);
 333+ // background of the rest space
 334+ ui->blendcolor(22 - batt_level, 6, 0x40000000, framebuf, 5 + batt_level, 5, 176, framebuf, 5 + batt_level, 5, 176);
 335+ return false;
 336+}
 337+
322338 struct chooser_renderer_list_params toolchooser_rparams =
323339 {
324340 .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
@@ -336,7 +352,7 @@
337353 .blit_dest = LIBUI_POINT(0, 0),
338354 .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
339355 LIBUI_POINT(176, 132)),
340 - .preblit = NULL,
 356+ .preblit = update_display,
341357 .postblit = NULL
342358 };
343359
@@ -418,22 +434,12 @@
419435
420436 bool mainchooser_preblit(struct chooser_data* data)
421437 {
422 - char buf[6];
423 - struct rtc_datetime dt;
424 - rtc_read_datetime(&dt);
425 - snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
426 - // clock
427 - rendertext(framebuf, 143, 4, 176, 0xffffcccc, 0, buf);
 438+ char buf[4];
428439 struct chooser_action_handler_wheel_data* adata;
429440 adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
430441 snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
431 - // remaining time
432442 rendertext(framebuf, 155, 121, 176, 0xffffcccc, 0, buf);
433 - unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
434 - // remaining battery level
435 - ui->blendcolor(batt_level, 6, 0xc0ffcccc, framebuf, 5, 5, 176, framebuf, 5, 5, 176);
436 - // background of the rest space
437 - ui->blendcolor(22 - batt_level, 6, 0x40000000, framebuf, 5 + batt_level, 5, 176, framebuf, 5 + batt_level, 5, 176);
 443+ update_display(data);
438444 return false;
439445 }
440446