Add formatted prinbt function for LCD menu and use systick vonversion in uptime shell command

This commit is contained in:
Mario Hüttel 2020-06-14 14:45:58 +02:00
parent 372be53471
commit 679d4534cb
4 changed files with 33 additions and 20 deletions

View File

@ -68,6 +68,8 @@ void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_imme
void menu_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text);
void menu_lcd_outputf(struct lcd_menu *menu, uint8_t row_num, const char *format, ...);
void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom_row);
int16_t menu_get_rotary_delta(const struct lcd_menu *menu);

View File

@ -115,7 +115,6 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry
uint32_t uptime_days;
int16_t rot_delta;
enum button_state push_button;
char buff[20];
if (entry_type == MENU_ENTRY_FIRST_ENTER) {
uptime_secs = 0ULL;
@ -124,18 +123,8 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry
button_ready = false;
menu_display_clear(menu);
menu_ack_rotary_delta(menu);
/* menu->update_display(0, LCD_SHIMATTA_STRING " Reflow");
snprintf(buff, sizeof(buff), "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
menu->update_display(1, buff);
if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) {
snprintf(buff, sizeof(buff), "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]);
menu->update_display(2, buff);
}
menu->update_display(3, __DATE__);
*/ }
switch (page) {
case 0:
menu_lcd_output(menu, 0, LCD_SHIMATTA_STRING " Shimatta");
@ -145,11 +134,9 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry
break;
case 1:
menu_lcd_output(menu, 0, "Version Number:");
snprintf(buff, sizeof(buff), "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
menu_lcd_output(menu, 1, buff);
menu_lcd_outputf(menu, 1, "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) {
snprintf(buff, sizeof(buff), "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]);
menu_lcd_output(menu, 2, buff);
menu_lcd_outputf(menu, 2, "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]);
}
menu_lcd_output(menu, 3, "<-About Uptime->");
break;
@ -158,8 +145,8 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry
if (new_uptime_secs != uptime_secs) {
uptime_secs = new_uptime_secs;
menu_lcd_output(menu, 0, "Uptime:");
snprintf(buff, sizeof(buff), "%lu days %02lu:%02lu:%02lu", uptime_days, uptime_hours, uptime_mins, uptime_secs);
menu_lcd_output(menu, 1, buff);
menu_lcd_outputf(menu, 1, "%lu days %02lu:%02lu:%02lu",
uptime_days, uptime_hours, uptime_mins, uptime_secs);
menu_lcd_output(menu, 3, "<-Version");
}
break;

View File

@ -189,8 +189,18 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
{
(void)arguments;
(void)length;
uint32_t days;
uint32_t hours;
uint32_t mins;
uint32_t secs;
shellmatta_printf(handle, "Uptime: %llu secs", global_tick_ms/1000);
systick_get_uptime_from_tick(&days, &hours, &mins, &secs);
shellmatta_printf(handle, "Uptime: %u day%s %02u:%02u:%02u",
days, (days == 1 ? "" : "s"),
hours,
mins,
secs);
return SHELLMATTA_OK;
}

View File

@ -21,6 +21,7 @@
#include <reflow-controller/ui/menu.h>
#include <stddef.h>
#include <stdio.h>
#include <stdarg.h>
void menu_handle(struct lcd_menu *menu, int16_t rotary_encoder_delta, enum button_state push_button)
{
@ -96,6 +97,18 @@ void menu_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text)
menu->update_display(row_num, text);
}
void menu_lcd_outputf(struct lcd_menu *menu, uint8_t row_num, const char *format, ...)
{
char buff[64];
va_list valist;
va_start(valist, format);
vsnprintf(buff, sizeof(buff), format, valist);
buff[sizeof(buff) - 1] = '\0';
menu_lcd_output(menu, row_num, buff);
va_end(valist);
}
void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom_row)
{
uint8_t row_count;
@ -146,7 +159,8 @@ void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom
if (current_idx >= list->entry_count)
break;
snprintf(workbuff, sizeof(workbuff), "%c%s", (current_idx == list->currently_selected ? '>' : ' '), list->entry_names[current_idx]);
snprintf(workbuff, sizeof(workbuff), "%c%s", (current_idx == list->currently_selected ? '>' : ' '),
list->entry_names[current_idx]);
workbuff[sizeof(workbuff)-1] = 0;
list->update_display((uint8_t)current_row, workbuff);
}