2018-06-19 14:53:41 +01:00
|
|
|
/*
|
2018-08-05 12:40:32 +01:00
|
|
|
* Copyright (c) 2018 naehrwert
|
|
|
|
* Copyright (c) 2018 CTCaer
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2019-02-11 22:34:35 +00:00
|
|
|
#include "di.h"
|
2018-05-01 06:15:48 +01:00
|
|
|
#include "tui.h"
|
2018-08-13 09:58:24 +01:00
|
|
|
#include "../utils/btn.h"
|
|
|
|
#include "../config/config.h"
|
|
|
|
#include "../power/max17050.h"
|
|
|
|
#include "../utils/util.h"
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-06-19 15:10:59 +01:00
|
|
|
#ifdef MENU_LOGO_ENABLE
|
|
|
|
extern u8 *Kc_MENU_LOGO;
|
2018-07-01 02:56:58 +01:00
|
|
|
#define X_MENU_LOGO 119
|
|
|
|
#define Y_MENU_LOGO 57
|
|
|
|
#define X_POS_MENU_LOGO 577
|
2018-07-09 14:06:17 +01:00
|
|
|
#define Y_POS_MENU_LOGO 1179
|
2018-06-19 15:10:59 +01:00
|
|
|
#endif //MENU_LOGO_ENABLE
|
|
|
|
|
2018-07-09 14:06:17 +01:00
|
|
|
extern hekate_config h_cfg;
|
|
|
|
|
2018-08-13 10:12:53 +01:00
|
|
|
void tui_sbar(gfx_con_t *con, bool force_update)
|
2018-07-09 14:06:17 +01:00
|
|
|
{
|
2018-08-21 02:26:14 +01:00
|
|
|
u32 cx, cy;
|
|
|
|
|
2018-07-09 14:06:17 +01:00
|
|
|
u32 timePassed = get_tmr_s() - h_cfg.sbar_time_keeping;
|
|
|
|
if (!force_update)
|
|
|
|
if (timePassed < 5)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u8 prevFontSize = con->fntsz;
|
|
|
|
con->fntsz = 16;
|
|
|
|
h_cfg.sbar_time_keeping = get_tmr_s();
|
|
|
|
|
|
|
|
u32 battPercent = 0;
|
|
|
|
int battVoltCurr = 0;
|
|
|
|
|
2018-08-21 02:26:14 +01:00
|
|
|
gfx_con_getpos(con, &cx, &cy);
|
2018-07-09 14:06:17 +01:00
|
|
|
gfx_con_setpos(con, 0, 1260);
|
|
|
|
|
|
|
|
max17050_get_property(MAX17050_RepSOC, (int *)&battPercent);
|
|
|
|
max17050_get_property(MAX17050_VCELL, &battVoltCurr);
|
|
|
|
|
|
|
|
gfx_clear_partial_grey(con->gfx_ctxt, 0x30, 1256, 24);
|
|
|
|
gfx_printf(con, "%K%k Battery: %d.%d%% (%d mV) - Charge:", 0xFF303030, 0xFF888888,
|
|
|
|
(battPercent >> 8) & 0xFF, (battPercent & 0xFF) / 26, battVoltCurr);
|
|
|
|
|
|
|
|
max17050_get_property(MAX17050_AvgCurrent, &battVoltCurr);
|
|
|
|
|
|
|
|
if (battVoltCurr >= 0)
|
2018-09-18 21:38:54 +01:00
|
|
|
gfx_printf(con, " %k+%d mA%k%K\n",
|
2018-07-22 13:18:30 +01:00
|
|
|
0xFF008800, battVoltCurr / 1000, 0xFFCCCCCC, 0xFF1B1B1B);
|
2018-07-09 14:06:17 +01:00
|
|
|
else
|
2018-09-18 21:38:54 +01:00
|
|
|
gfx_printf(con, " %k-%d mA%k%K\n",
|
2018-07-22 13:18:30 +01:00
|
|
|
0xFF880000, (~battVoltCurr) / 1000, 0xFFCCCCCC, 0xFF1B1B1B);
|
2018-07-09 14:06:17 +01:00
|
|
|
con->fntsz = prevFontSize;
|
2018-08-21 02:26:14 +01:00
|
|
|
gfx_con_setpos(con, cx, cy);
|
2018-07-09 14:06:17 +01:00
|
|
|
}
|
|
|
|
|
2018-06-01 17:02:13 +01:00
|
|
|
void tui_pbar(gfx_con_t *con, int x, int y, u32 val, u32 fgcol, u32 bgcol)
|
2018-05-01 06:15:48 +01:00
|
|
|
{
|
|
|
|
u32 cx, cy;
|
2018-06-26 17:00:46 +01:00
|
|
|
if (val > 200)
|
|
|
|
val = 200;
|
2018-05-01 06:15:48 +01:00
|
|
|
|
|
|
|
gfx_con_getpos(con, &cx, &cy);
|
|
|
|
|
|
|
|
gfx_con_setpos(con, x, y);
|
|
|
|
|
2018-06-03 07:07:03 +01:00
|
|
|
gfx_printf(con, "%k[%3d%%]%k", fgcol, val, 0xFFCCCCCC);
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-06-27 22:21:05 +01:00
|
|
|
x += 7 * con->fntsz;
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-06-27 22:21:05 +01:00
|
|
|
for (int i = 0; i < (con->fntsz >> 3) * 6; i++)
|
2018-05-01 06:15:48 +01:00
|
|
|
{
|
2018-06-01 17:02:13 +01:00
|
|
|
gfx_line(con->gfx_ctxt, x, y + i + 1, x + 3 * val, y + i + 1, fgcol);
|
|
|
|
gfx_line(con->gfx_ctxt, x + 3 * val, y + i + 1, x + 3 * 100, y + i + 1, bgcol);
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx_con_setpos(con, cx, cy);
|
2018-07-09 14:06:17 +01:00
|
|
|
|
|
|
|
// Update status bar.
|
2018-08-13 10:12:53 +01:00
|
|
|
tui_sbar(con, false);
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void *tui_do_menu(gfx_con_t *con, menu_t *menu)
|
|
|
|
{
|
2018-06-13 00:34:32 +01:00
|
|
|
int idx = 0, prev_idx = 0, cnt = 0x7FFFFFFF;
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-07-09 14:06:17 +01:00
|
|
|
gfx_clear_partial_grey(con->gfx_ctxt, 0x1B, 0, 1256);
|
2018-08-13 10:12:53 +01:00
|
|
|
tui_sbar(con, true);
|
2018-07-09 14:06:17 +01:00
|
|
|
|
2018-06-19 15:10:59 +01:00
|
|
|
#ifdef MENU_LOGO_ENABLE
|
|
|
|
gfx_set_rect_rgb(con->gfx_ctxt, Kc_MENU_LOGO,
|
|
|
|
X_MENU_LOGO, Y_MENU_LOGO, X_POS_MENU_LOGO, Y_POS_MENU_LOGO);
|
|
|
|
#endif //MENU_LOGO_ENABLE
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-09-18 21:38:54 +01:00
|
|
|
while (true)
|
2018-05-01 06:15:48 +01:00
|
|
|
{
|
2018-05-24 22:29:41 +01:00
|
|
|
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
|
2018-05-01 06:15:48 +01:00
|
|
|
gfx_con_setpos(con, menu->x, menu->y);
|
|
|
|
gfx_printf(con, "[%s]\n\n", menu->caption);
|
|
|
|
|
2018-06-15 12:28:27 +01:00
|
|
|
// Skip caption or seperator lines selection.
|
2018-05-24 22:33:11 +01:00
|
|
|
while (menu->ents[idx].type == MENT_CAPTION ||
|
|
|
|
menu->ents[idx].type == MENT_CHGLINE)
|
|
|
|
{
|
2018-06-15 12:28:27 +01:00
|
|
|
if (prev_idx <= idx || (!idx && prev_idx == cnt - 1))
|
2018-06-13 00:34:32 +01:00
|
|
|
{
|
2018-05-24 22:33:11 +01:00
|
|
|
idx++;
|
|
|
|
if (idx > (cnt - 1))
|
|
|
|
{
|
|
|
|
idx = 0;
|
|
|
|
prev_idx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx--;
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
|
|
|
idx = cnt - 1;
|
|
|
|
prev_idx = cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prev_idx = idx;
|
|
|
|
|
2018-06-19 14:53:41 +01:00
|
|
|
// Draw the menu.
|
2018-05-01 06:15:48 +01:00
|
|
|
for (cnt = 0; menu->ents[cnt].type != MENT_END; cnt++)
|
|
|
|
{
|
|
|
|
if (cnt == idx)
|
2018-05-24 22:29:41 +01:00
|
|
|
gfx_con_setcol(con, 0xFF1B1B1B, 1, 0xFFCCCCCC);
|
2018-05-01 06:15:48 +01:00
|
|
|
else
|
2018-05-24 22:29:41 +01:00
|
|
|
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
|
2018-06-13 00:34:32 +01:00
|
|
|
if (menu->ents[cnt].type == MENT_CAPTION)
|
2018-05-24 22:33:11 +01:00
|
|
|
gfx_printf(con, "%k %s", menu->ents[cnt].color, menu->ents[cnt].caption);
|
2018-06-13 00:34:32 +01:00
|
|
|
else if (menu->ents[cnt].type != MENT_CHGLINE)
|
2018-05-24 22:33:11 +01:00
|
|
|
gfx_printf(con, " %s", menu->ents[cnt].caption);
|
2018-05-01 06:15:48 +01:00
|
|
|
if(menu->ents[cnt].type == MENT_MENU)
|
2018-06-19 14:53:41 +01:00
|
|
|
gfx_printf(con, "%k...", 0xFF0099EE);
|
2018-05-24 22:33:11 +01:00
|
|
|
gfx_printf(con, " \n");
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|
2018-05-24 22:29:41 +01:00
|
|
|
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
|
2018-05-01 06:15:48 +01:00
|
|
|
gfx_putc(con, '\n');
|
|
|
|
|
2018-06-24 20:38:32 +01:00
|
|
|
// Print help and battery status.
|
2018-09-18 22:04:58 +01:00
|
|
|
gfx_con_setpos(con, 0, 1127);
|
|
|
|
if (h_cfg.errors)
|
|
|
|
{
|
|
|
|
gfx_printf(con, "%k Warning: %k", 0xFF800000, 0xFF555555);
|
|
|
|
if (h_cfg.errors & ERR_LIBSYS_LP0)
|
|
|
|
gfx_printf(con, "Sleep mode library is missing!\n");
|
|
|
|
}
|
2018-07-09 14:06:17 +01:00
|
|
|
gfx_con_setpos(con, 0, 1191);
|
|
|
|
gfx_printf(con, "%k VOL: Move up/down\n PWR: Select option%k", 0xFF555555, 0xFFCCCCCC);
|
2018-06-24 20:38:32 +01:00
|
|
|
|
2018-09-18 22:01:42 +01:00
|
|
|
display_backlight_brightness(h_cfg.backlight, 1000);
|
|
|
|
|
2018-06-19 14:53:41 +01:00
|
|
|
// Wait for user command.
|
2018-05-01 06:15:48 +01:00
|
|
|
u32 btn = btn_wait();
|
|
|
|
|
2018-05-21 09:43:56 +01:00
|
|
|
if (btn & BTN_VOL_DOWN && idx < (cnt - 1))
|
2018-05-01 06:15:48 +01:00
|
|
|
idx++;
|
2018-05-21 09:43:56 +01:00
|
|
|
else if (btn & BTN_VOL_DOWN && idx == (cnt - 1))
|
2018-09-24 21:22:19 +01:00
|
|
|
{
|
2018-05-21 09:43:56 +01:00
|
|
|
idx = 0;
|
2018-09-24 21:22:19 +01:00
|
|
|
prev_idx = -1;
|
|
|
|
}
|
2018-05-01 06:15:48 +01:00
|
|
|
if (btn & BTN_VOL_UP && idx > 0)
|
|
|
|
idx--;
|
2018-05-21 09:43:56 +01:00
|
|
|
else if (btn & BTN_VOL_UP && idx == 0)
|
2018-09-24 21:22:19 +01:00
|
|
|
{
|
2018-05-21 09:43:56 +01:00
|
|
|
idx = cnt - 1;
|
2018-09-24 21:22:19 +01:00
|
|
|
prev_idx = cnt;
|
|
|
|
}
|
2018-05-01 06:15:48 +01:00
|
|
|
if (btn & BTN_POWER)
|
|
|
|
{
|
|
|
|
ment_t *ent = &menu->ents[idx];
|
|
|
|
switch (ent->type)
|
|
|
|
{
|
|
|
|
case MENT_HANDLER:
|
|
|
|
ent->handler(ent->data);
|
|
|
|
break;
|
|
|
|
case MENT_MENU:
|
|
|
|
return tui_do_menu(con, ent->menu);
|
|
|
|
break;
|
2018-09-24 21:22:19 +01:00
|
|
|
case MENT_DATA:
|
2018-05-01 06:15:48 +01:00
|
|
|
return ent->data;
|
|
|
|
break;
|
|
|
|
case MENT_BACK:
|
|
|
|
return NULL;
|
|
|
|
break;
|
2018-08-21 02:26:14 +01:00
|
|
|
case MENT_HDLR_RE:
|
2018-12-16 18:21:59 +00:00
|
|
|
ent->handler(ent);
|
|
|
|
if (!ent->data)
|
|
|
|
return NULL;
|
|
|
|
break;
|
2018-05-24 22:33:11 +01:00
|
|
|
default:
|
|
|
|
break;
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|
2018-06-27 22:21:05 +01:00
|
|
|
con->fntsz = 16;
|
2018-07-09 14:06:17 +01:00
|
|
|
gfx_clear_partial_grey(con->gfx_ctxt, 0x1B, 0, 1256);
|
2018-06-19 15:10:59 +01:00
|
|
|
#ifdef MENU_LOGO_ENABLE
|
|
|
|
gfx_set_rect_rgb(con->gfx_ctxt, Kc_MENU_LOGO,
|
|
|
|
X_MENU_LOGO, Y_MENU_LOGO, X_POS_MENU_LOGO, Y_POS_MENU_LOGO);
|
|
|
|
#endif //MENU_LOGO_ENABLE
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|
2018-08-13 10:12:53 +01:00
|
|
|
tui_sbar(con, false);
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|