From b4c208d852fdb7a0f10ceec695f6872e65b5ae85 Mon Sep 17 00:00:00 2001 From: bucanero Date: Tue, 17 Oct 2023 20:23:55 -0300 Subject: [PATCH] Show battery level fix #11 --- include/font-8x16.h | 128 ++++++++++++++++++++--------------------- include/pkgi.h | 1 + source/pkgi.c | 16 +++--- source/pkgi_download.c | 2 +- source/pkgi_psp.c | 55 ++++++++++++++++-- 5 files changed, 124 insertions(+), 78 deletions(-) diff --git a/include/font-8x16.h b/include/font-8x16.h index d324cf9..9b7fdfd 100644 --- a/include/font-8x16.h +++ b/include/font-8x16.h @@ -4665,100 +4665,100 @@ unsigned char console_font_8x16[] = { * code=233, hex=0xE9, ascii="!i" */ 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x38, /* 00111000 */ - 0x6C, /* 01101100 */ - 0xC6, /* 11000110 */ - 0xC6, /* 11000110 */ - 0xFE, /* 11111110 */ - 0xC6, /* 11000110 */ - 0xC6, /* 11000110 */ - 0x6C, /* 01101100 */ - 0x38, /* 00111000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0x66, /* 01100110 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0x7E, /* 01111110 */ + 0x3C, /* 00111100 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ + 0x18, /* 00011000 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ /* * code=234, hex=0xEA, ascii="!j" */ + 0x3C, /* 00111100 */ + 0xFF, /* 11111111 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ 0x00, /* 00000000 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ 0x00, /* 00000000 */ - 0x38, /* 00111000 */ - 0x6C, /* 01101100 */ - 0xC6, /* 11000110 */ - 0xC6, /* 11000110 */ - 0xC6, /* 11000110 */ - 0x6C, /* 01101100 */ - 0x6C, /* 01101100 */ - 0x6C, /* 01101100 */ - 0x6C, /* 01101100 */ - 0xEE, /* 11101110 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0xFF, /* 11111111 */ 0x00, /* 00000000 */ /* * code=235, hex=0xEB, ascii="!k" */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x1E, /* 00011110 */ - 0x30, /* 00110000 */ - 0x18, /* 00011000 */ - 0x0C, /* 00001100 */ - 0x3E, /* 00111110 */ - 0x66, /* 01100110 */ - 0x66, /* 01100110 */ - 0x66, /* 01100110 */ - 0x66, /* 01100110 */ 0x3C, /* 00111100 */ + 0xFF, /* 11111111 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ 0x00, /* 00000000 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ 0x00, /* 00000000 */ - 0x00, /* 00000000 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ 0x00, /* 00000000 */ /* * code=236, hex=0xEC, ascii="!l" */ + 0x3C, /* 00111100 */ + 0xFF, /* 11111111 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ + 0x81, /* 10000001 */ 0x00, /* 00000000 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x7E, /* 01111110 */ - 0xDB, /* 11011011 */ - 0xDB, /* 11011011 */ - 0xDB, /* 11011011 */ - 0x7E, /* 01111110 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ 0x00, /* 00000000 */ /* * code=237, hex=0xED, ascii="!m" */ + 0x3C, /* 00111100 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ 0x00, /* 00000000 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x03, /* 00000011 */ - 0x06, /* 00000110 */ - 0x7E, /* 01111110 */ - 0xDB, /* 11011011 */ - 0xDB, /* 11011011 */ - 0xF3, /* 11110011 */ - 0x7E, /* 01111110 */ - 0x60, /* 01100000 */ - 0xC0, /* 11000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ - 0x00, /* 00000000 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ + 0xFF, /* 11111111 */ 0x00, /* 00000000 */ /* diff --git a/include/pkgi.h b/include/pkgi.h index 25661f2..05b21f3 100644 --- a/include/pkgi.h +++ b/include/pkgi.h @@ -62,6 +62,7 @@ int pkgi_update(pkgi_input* input); void pkgi_swap(void); void pkgi_end(void); +int pkgi_get_battery_charge(int* status); const char* pkgi_get_storage_device(void); uint64_t pkgi_get_free_space(void); diff --git a/source/pkgi.c b/source/pkgi.c index a5da285..4b1e871 100644 --- a/source/pkgi.c +++ b/source/pkgi.c @@ -170,11 +170,14 @@ static const char* friendly_size_str(uint64_t size) int pkgi_check_free_space(uint64_t size) { uint64_t free = pkgi_get_free_space(); - if (size > free + 1024 * 1024) + + size *= 2; // we need at least twice the space to install a package + if (size > free) { char error[256]; - pkgi_snprintf(error, sizeof(error), _("pkg requires %u %s free space, but only %u %s available"), + pkgi_snprintf(error, sizeof(error), _(".pkg requires %u %s free space\n(%s/PKG) only %u %s available"), friendly_size(size), friendly_size_str(size), + pkgi_get_storage_device(), friendly_size(free), friendly_size_str(free) ); @@ -466,7 +469,6 @@ static void pkgi_do_main(pkgi_input* input) if (!pkgi_check_free_space(item->size)) { LOG("[%.9s] %s - no free space", item->content + 7, item->name); - pkgi_dialog_error(_("Not enough free space on HDD")); } else if (item->presence == PresenceInstalled) { @@ -554,11 +556,13 @@ static void pkgi_do_head(void) static void pkgi_do_tail(void) { char text[256]; + int batt, status; pkgi_draw_fill_rect_z(0, bottom_y - font_height/2, PKGI_FONT_Z, PKGI_SCREEN_WIDTH, PKGI_MAIN_HLINE_HEIGHT, PKGI_COLOR_HLINE); - int left = pkgi_text_width(text) + PKGI_MAIN_TEXT_PADDING; - int right = PKGI_MAIN_TEXT_PADDING; + batt = pkgi_get_battery_charge(&status); + pkgi_snprintf(text, sizeof(text), "%c %d%%", status + 0xE9, batt); + pkgi_draw_text_z(PKGI_MAIN_TEXT_PADDING, bottom_y, PKGI_FONT_Z, PKGI_COLOR_TEXT_TAIL, text); if (pkgi_menu_is_open()) { @@ -569,9 +573,7 @@ static void pkgi_do_tail(void) pkgi_snprintf(text, sizeof(text), "%s %s " PKGI_UTF8_T " %s " PKGI_UTF8_S " %s %s %s", pkgi_get_ok_str(), _("Download"), _("Menu"), _("Details"), pkgi_get_cancel_str(), _("Exit")); } - pkgi_clip_set(left, bottom_y, PKGI_SCREEN_WIDTH - right - left, PKGI_SCREEN_HEIGHT - bottom_y); pkgi_draw_text_z((PKGI_SCREEN_WIDTH - pkgi_text_width(text)) / 2, bottom_y, PKGI_FONT_Z, PKGI_COLOR_TEXT_TAIL, text); - pkgi_clip_remove(); } static void pkgi_do_error(void) diff --git a/source/pkgi_download.c b/source/pkgi_download.c index dbed223..55232ed 100644 --- a/source/pkgi_download.c +++ b/source/pkgi_download.c @@ -106,7 +106,7 @@ static int update_progress(void *p, int64_t dltotal, int64_t dlnow, int64_t ulto } pkgi_dialog_update_progress(text, dialog_extra, dialog_eta, percent); - info_update = info_now + 1000; + info_update = info_now + 500; progress_screen_refresh(); } diff --git a/source/pkgi_psp.c b/source/pkgi_psp.c index a6aceb5..cf237af 100644 --- a/source/pkgi_psp.c +++ b/source/pkgi_psp.c @@ -448,7 +448,7 @@ void pkgi_dialog_input_get_text(char* text, uint32_t size) LOG("input: %s", text); } -void load_ttf_fonts(void) +static void load_ttf_fonts(void) { LOG("loading TTF fonts"); texture_mem = malloc(256 * 8 * 4); @@ -768,10 +768,55 @@ void pkgi_end(void) // Stop all SDL sub-systems SDL_Quit(); http_end(); +} + +int pkgi_get_battery_charge(int* status) +{ + static uint32_t t = 0; + static int charge = 0; + + if (t < g_time) + { + charge = (scePowerIsBatteryExist() == 1) ? scePowerGetBatteryLifePercent() : 0; + + if (charge < 0) + charge = 0; + + if (scePowerIsBatteryCharging() == 1) + charge *= (-1); + + t = g_time + 1000; + } + + if (charge <= 0) + { + *status = 0; + return (-charge); + } + else if (charge > 70) + *status = 4; + else if (charge > 40) + *status = 3; + else if (charge > 10) + *status = 2; + else + *status = 1; - //sysProcessExit(0); + return charge; } +/* +static int pspGoIsMemCardInserted(void) { + int status = 0, ret = 0; + + ret = sceIoDevctl("mscmhc0:", 0x02025806, 0, 0, &status, sizeof(status)); + if (ret < 0) + return ret; + + return (status == 1); +} +*/ + static int is_psp_go(void) { static int res = -1; @@ -803,12 +848,13 @@ uint64_t pkgi_get_free_space(void) static uint32_t t = 0; static uint64_t freeSize = 0; - if (t++ % 0x1000 == 0) + if (t < g_time) { cmd.dev_inf = &inf; memset(&inf, 0, sizeof(SceDevInf)); sceIoDevctl(pkgi_get_storage_device(), SCE_PR_GETDEV, &cmd, sizeof(SceDevctlCmd), NULL, 0); freeSize = ((uint64_t) inf.freeClusters) * ((uint64_t) inf.sectorCount) * ((uint64_t) inf.sectorSize); + t = g_time + 1000; } return (freeSize); @@ -1088,7 +1134,6 @@ void pkgi_draw_text_z(int x, int y, int z, uint32_t color, const char* text) } } - void pkgi_draw_text_ttf(int x, int y, int z, uint32_t color, const char* text) { Z_ttf = z; @@ -1101,7 +1146,6 @@ int pkgi_text_width_ttf(const char* text) return (display_ttf_string(0, 0, text, 0, 0, PKGI_FONT_WIDTH+6, PKGI_FONT_HEIGHT+2, NULL)); } - void pkgi_draw_text(int x, int y, uint32_t color, const char* text) { SetFontColor(RGBA_COLOR(PKGI_COLOR_TEXT_SHADOW, 200), 0); @@ -1111,7 +1155,6 @@ void pkgi_draw_text(int x, int y, uint32_t color, const char* text) DrawStringMono((float)x, (float)y, (char *)text); } - int pkgi_text_width(const char* text) { return (strlen(text) * PKGI_FONT_WIDTH) + PKGI_FONT_SHADOW;