diff --git a/ui.c b/ui.c index cad9e3d..e7b710a 100644 --- a/ui.c +++ b/ui.c @@ -64,7 +64,11 @@ static uint16_t last_button = 0b0000; static uint32_t last_button_down_ticks; static uint32_t last_button_repeat_ticks; -//static uint16_t menu_button_height = MENU_BUTTON_HEIGHT_N(MENU_BUTTON_MIN); +#define MENU_USE_AUTOHEIGHT +#ifdef MENU_USE_AUTOHEIGHT +static uint16_t menu_button_height = MENU_BUTTON_HEIGHT_N(MENU_BUTTON_MIN); +#endif + volatile uint8_t operation_requested = OP_NONE; int8_t previous_marker = MARKER_INVALID; @@ -641,6 +645,8 @@ enum { //#define MT_LEAVE 0x20 #define MT_MASK(x) (0xF & (x)) +#define MT_CUSTOM_LABEL 0 + // Call back functions for MT_CALLBACK type typedef void (*menuaction_cb_t)(int item, uint16_t data); #define UI_FUNCTION_CALLBACK(ui_function_name) void ui_function_name(int item, uint16_t data) @@ -820,7 +826,9 @@ ensure_selection(void) if (MT_MASK(menu[0].type) == MT_TITLE && selection == 0) selection = 1; if (i < MENU_BUTTON_MIN) i = MENU_BUTTON_MIN; if (i >= MENU_BUTTON_MAX) i = MENU_BUTTON_MAX; -// menu_button_height = MENU_BUTTON_HEIGHT_N(i); +#ifdef MENU_USE_AUTOHEIGHT + menu_button_height = MENU_BUTTON_HEIGHT_N(i); +#endif } static void @@ -1118,9 +1126,10 @@ static int menu_is_multiline(const char *label) { int n = 1; - while (*label) - if (*label++ == '\n') - n++; + if (label) + while (*label) + if (*label++ == '\n') + n++; return n; } @@ -1343,11 +1352,13 @@ static const uint8_t check_box[] = { static const char *step_text[5] = {"-10dB", "-1dB", "set", "+1dB", "+10dB"}; static char step_text_freq[5][10] = { "-100MHz", "-10MHz", "set", "+10MHz", "+100MHz" }; -#ifdef TINYS4 +#ifndef MENU_USE_AUTOHEIGHT +#ifdef TINYSA4 #define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/10 : LCD_HEIGHT/12 ) #else #define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/8 : LCD_HEIGHT/10 ) #endif +#endif static void draw_menu_buttons(const menuitem_t *menu, int only) @@ -1390,22 +1401,26 @@ draw_menu_buttons(const menuitem_t *menu, int only) // Need replace this obsolete bad function on new MT_ADV_CALLBACK variant menu_item_modify_attribute(menu, i, &button); // before plot_printf to create status text - + char *text; // MT_ADV_CALLBACK - allow change button data in callback, more easy and correct if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK){ menuaction_acb_t cb = (menuaction_acb_t)menu[i].reference; if (cb) (*cb)(i, menu[i].data, &button); + // Apply custom text, from button label and + if (menu[i].label != MT_CUSTOM_LABEL) + plot_printf(button.text, sizeof(button.text), menu[i].label, button.param_1.u); + text = button.text; } + else + text = menu[i].label; // Only keypad retrieves value if (menu[i].type & MT_FORM && MT_MASK(menu[i].type) == MT_KEYPAD) { keypad_mode = menu[i].data; fetch_numeric_target(); - button.param_1.text = uistat.text; + plot_printf(button.text, sizeof button.text, menu[i].label, uistat.text); + text = button.text; } - // Prepare button label - plot_printf(button.text, sizeof button.text, menu[i].label, button.param_1.u, button.param_2.u); - if (menu[i].type & MT_FORM) { int button_width = MENU_FORM_WIDTH; int button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; // At center of screen @@ -1454,8 +1469,8 @@ draw_menu_buttons(const menuitem_t *menu, int only) goto draw_slider; } } -// ili9341_drawstring_size(button.text, text_offs, y+(button_height-2*FONT_GET_HEIGHT)/2-local_text_shift, 2); - ili9341_drawstring_10x14(button.text, text_offs, y+(button_height-wFONT_GET_HEIGHT)/2-local_text_shift); +// ili9341_drawstring_size(text, text_offs, y+(button_height-2*FONT_GET_HEIGHT)/2-local_text_shift, 2); + ili9341_drawstring_10x14(text, text_offs, y+(button_height-wFONT_GET_HEIGHT)/2-local_text_shift); } else { int button_width = MENU_BUTTON_WIDTH; int button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; @@ -1466,12 +1481,12 @@ draw_menu_buttons(const menuitem_t *menu, int only) ili9341_blitBitmap(button_start+2, y+(button_height-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); text_offs = button_start+2+ICON_WIDTH; } - int lines = menu_is_multiline(button.text); + int lines = menu_is_multiline(text); #define BIG_BUTTON_FONT 1 #ifdef BIG_BUTTON_FONT - ili9341_drawstring_7x13(button.text, text_offs, y+(button_height-lines*bFONT_GET_HEIGHT)/2); + ili9341_drawstring_7x13(text, text_offs, y+(button_height-lines*bFONT_GET_HEIGHT)/2); #else - ili9341_drawstring(button.text, text_offs, y+(button_height-linesFONT_GET_HEIGHT)/2); + ili9341_drawstring(text, text_offs, y+(button_height-linesFONT_GET_HEIGHT)/2); #endif } y += menu_button_height; diff --git a/ui_sa.c b/ui_sa.c index 45e70ae..0c480f7 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -747,12 +747,10 @@ static UI_FUNCTION_ADV_CALLBACK(menu_load_preset_acb) (void)item; if(b){ setting_t *p = caldata_pointer(data); - char *t = (char *)spi_buffer; if (p) - plot_printf(t, 64, "%.6FHz\n%.6FHz", (float)p->frequency0, (float)p->frequency1);//\n%d-drstx8 + plot_printf(b->text, sizeof(b->text), "%.6FHz\n%.6FHz", (float)p->frequency0, (float)p->frequency1); else - plot_printf(t, 64, "EMPTY %d", (int)data); - b->param_1.text = t; + plot_printf(b->text, sizeof(b->text), "EMPTY %d", (int)data); return; } if (caldata_recall(data) == -1) { @@ -923,10 +921,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){ (void)data; if(b){ if (setting.modulation == MO_NONE || setting.modulation == MO_EXTERNAL) - b->param_1.text = menu_modulation_text[setting.modulation]; + plot_printf(b->text, sizeof b->text, "MOD: %s", menu_modulation_text[setting.modulation]); else { - plot_printf(uistat.text, sizeof uistat.text, "%5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]); - b->param_1.text = uistat.text; + plot_printf(b->text, sizeof b->text, "MOD: %5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]); } return; } @@ -1970,11 +1967,11 @@ static const menuitem_t menu_store_preset_high[8] = static const menuitem_t menu_load_preset_high[] = { - { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP",menu_load_preset_acb}, - { MT_ADV_CALLBACK, 5, "LOAD %s", menu_load_preset_acb}, - { MT_ADV_CALLBACK, 6, "LOAD %s", menu_load_preset_acb}, - { MT_ADV_CALLBACK, 7, "LOAD %s", menu_load_preset_acb}, - { MT_ADV_CALLBACK, 8, "LOAD %s", menu_load_preset_acb}, + { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb}, + { MT_ADV_CALLBACK, 5, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 6, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 7, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 8, MT_CUSTOM_LABEL, menu_load_preset_acb}, { MT_SUBMENU, 0, "STORE" , menu_store_preset_high}, { MT_CANCEL, 255, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel @@ -1995,11 +1992,11 @@ static const menuitem_t menu_store_preset[] = static const menuitem_t menu_load_preset[] = { - { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP",menu_load_preset_acb}, - { MT_ADV_CALLBACK, 1, "%s" , menu_load_preset_acb}, - { MT_ADV_CALLBACK, 2, "%s" , menu_load_preset_acb}, - { MT_ADV_CALLBACK, 3, "%s" , menu_load_preset_acb}, - { MT_ADV_CALLBACK, 4, "%s" , menu_load_preset_acb}, + { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb}, + { MT_ADV_CALLBACK, 1, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 2, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 3, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 4, MT_CUSTOM_LABEL, menu_load_preset_acb}, { MT_SUBMENU, 0, "STORE" , menu_store_preset}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel @@ -2054,7 +2051,7 @@ static const menuitem_t menu_lowoutputmode[] = { // { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("10kHz..350MHz","10kHz..850MHz")}, { MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", low_level_help_text}, - { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, #ifdef __SWEEP_RESTART__ { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, @@ -2071,7 +2068,7 @@ static const menuitem_t menu_highoutputmode[] = { { MT_FORM | MT_ADV_CALLBACK, 0, "HIGH OUTPUT %s", menu_outputmode_acb}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("240MHz..960MHz",range_text)}, { MT_FORM | MT_KEYPAD, KM_HIGHOUTLEVEL, "LEVEL: %s", low_level_help_text /* "-76..-6" */}, - { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, #ifdef __SWEEP_RESTART__ { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, @@ -2315,7 +2312,7 @@ static const menuitem_t menu_dfu[] = { #ifdef __HARMONIC__ static const menuitem_t menu_harmonic[] = { - { MT_ADV_CALLBACK, 0, "OFF", menu_harmonic_acb}, + { MT_ADV_CALLBACK, 0, "OFF", menu_harmonic_acb}, { MT_ADV_CALLBACK, 2, "2", menu_harmonic_acb}, { MT_ADV_CALLBACK, 3, "3", menu_harmonic_acb}, { MT_ADV_CALLBACK, 4, "4", menu_harmonic_acb}, @@ -2390,8 +2387,8 @@ static const menuitem_t menu_settings3[] = { #ifdef TINYSA4 // { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, - { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, - { MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb}, + { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, + { MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb}, { MT_KEYPAD, KM_LPF, "ULTRA\nSTART", "Enter ULTRA mode start freq"}, // { MT_KEYPAD | MT_LOW, KM_IF2, "IF2 FREQ", "Set to zero for no IF2"}, { MT_KEYPAD, KM_R, "R", "Set R"},