freemyipod r764 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r763‎ | r764 | r765 >
Date:23:44, 22 August 2011
Author:user890104
Status:new
Tags:
Comment:
bootmenu-ipodnano2g, bootmenu-ipodclassic: add a battery meter and a clock to the bootmenu. Tested on both Nano2G and Classic
Modified paths:
  • /apps/beeper/convert.php (modified) (history)
  • /apps/bootmenu-ipodclassic/main.c (modified) (history)
  • /apps/bootmenu-ipodnano2g/main.c (modified) (history)

Diff [purge]

Index: apps/bootmenu-ipodclassic/main.c
@@ -348,11 +348,22 @@
349349
350350 bool mainchooser_preblit(struct chooser_data* data)
351351 {
352 - char buf[4];
 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);
353358 struct chooser_action_handler_wheel_data* adata;
354359 adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
355360 snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
356 - rendertext(framebuf, 302, 232, 320, 0xffffcccc, 0, buf);
 361+ // remaining time
 362+ 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);
357368 return false;
358369 }
359370
@@ -543,6 +554,17 @@
544555 boot = (struct libboot_api*)libboot->api;
545556 struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER, LIBUI_API_VERSION, "libui ");
546557 ui = (struct libui_api*)libui->api;
 558+ // draw the battery meter box
 559+ // top line
 560+ ui->blendcolor(24, 1, 0xffffcccc, bg, 4, 4, 320, bg, 4, 4, 320);
 561+ // bottom line
 562+ ui->blendcolor(24, 1, 0xffffcccc, bg, 4, 11, 320, bg, 4, 11, 320);
 563+ // left line
 564+ ui->blendcolor(1, 6, 0xffffcccc, bg, 4, 5, 320, bg, 4, 5, 320);
 565+ // right line
 566+ ui->blendcolor(1, 6, 0xffffcccc, bg, 27, 5, 320, bg, 27, 5, 320);
 567+ // tip - right
 568+ ui->blendcolor(1, 4, 0xffffcccc, bg, 28, 6, 320, bg, 28, 6, 320);
547569 framebuf = malloc(320 * 240 * 3);
548570 if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
549571
Index: apps/bootmenu-ipodnano2g/main.c
@@ -418,11 +418,22 @@
419419
420420 bool mainchooser_preblit(struct chooser_data* data)
421421 {
422 - char buf[4];
 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);
423428 struct chooser_action_handler_wheel_data* adata;
424429 adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
425430 snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
426 - rendertext(framebuf, 158, 124, 176, 0xffffcccc, 0, buf);
 431+ // remaining time
 432+ 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);
427438 return false;
428439 }
429440
@@ -673,6 +684,17 @@
674685 boot = (struct libboot_api*)libboot->api;
675686 struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER, LIBUI_API_VERSION, "libui ");
676687 ui = (struct libui_api*)libui->api;
 688+ // draw the battery meter box
 689+ // top line
 690+ ui->blendcolor(24, 1, 0xffffcccc, bg, 4, 4, 176, bg, 4, 4, 176);
 691+ // bottom line
 692+ ui->blendcolor(24, 1, 0xffffcccc, bg, 4, 11, 176, bg, 4, 11, 176);
 693+ // left line
 694+ ui->blendcolor(1, 6, 0xffffcccc, bg, 4, 5, 176, bg, 4, 5, 176);
 695+ // right line
 696+ ui->blendcolor(1, 6, 0xffffcccc, bg, 27, 5, 176, bg, 27, 5, 176);
 697+ // tip - right
 698+ ui->blendcolor(1, 4, 0xffffcccc, bg, 28, 6, 176, bg, 28, 6, 176);
677699 framebuf = malloc(176 * 132 * 3);
678700 if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
679701 framebuf2 = malloc(176 * 132 * 3);
Index: apps/beeper/convert.php
@@ -82,6 +82,7 @@
8383 '4+1/2' => 1.5,
8484 '4' => 1,
8585 '8' => .5,
 86+ '8.5' => .75,
8687 '8+1/2+1/4' => .3 + 5/4,
8788 '16' => .25,
8889 '32' => .125,