Add base support for dynamic button text

Save some flash size
pull/130/head
DiSlord 5 years ago
parent 156e21f4ee
commit 6b25d86128

@ -931,8 +931,8 @@ bool sweep(bool break_on_operation, uint16_t sweep_mode)
return p_sweep == sweep_points;
}
uint32_t get_bandwidth_frequency(void){
return (AUDIO_ADC_FREQ/AUDIO_SAMPLES_COUNT)/(config.bandwidth+1);
uint32_t get_bandwidth_frequency(uint16_t bw_freq){
return (AUDIO_ADC_FREQ/AUDIO_SAMPLES_COUNT)/(bw_freq+1);
}
VNA_SHELL_FUNCTION(cmd_bandwidth)
@ -941,7 +941,7 @@ VNA_SHELL_FUNCTION(cmd_bandwidth)
goto result;
config.bandwidth = my_atoui(argv[0])&0xFF;
result:
shell_printf("bandwidth %d (%uHz)\r\n", config.bandwidth, get_bandwidth_frequency());
shell_printf("bandwidth %d (%uHz)\r\n", config.bandwidth, get_bandwidth_frequency(config.bandwidth));
}
void set_sweep_points(uint16_t points){

@ -114,7 +114,7 @@ enum stimulus_type {
void set_sweep_frequency(int type, uint32_t frequency);
uint32_t get_sweep_frequency(int type);
uint32_t get_bandwidth_frequency(void);
uint32_t get_bandwidth_frequency(uint16_t bw_freq);
double my_atof(const char *p);
@ -131,7 +131,6 @@ extern const char *info_about[];
/*
* dsp.c
*/
// 5ms @ 96kHz
// Define aic3204 source clock frequency (for 8MHz used fractional multiplier, and possible little phase error)
#define AUDIO_CLOCK_REF ( 8000000U)
//#define AUDIO_CLOCK_REF (10752000U)
@ -147,8 +146,10 @@ extern const char *info_about[];
#define AUDIO_BUFFER_LEN (AUDIO_SAMPLES_COUNT*2)
// Bandwidth depend from AUDIO_SAMPLES_COUNT and audio ADC frequency
// for AUDIO_SAMPLES_COUNT = 48 and ADC = 96kHz one measure give 96000/48=2000Hz
// define additional measure count
// for AUDIO_SAMPLES_COUNT = 48 and ADC = 48kHz one measure give 48000/48=1000Hz
// for AUDIO_SAMPLES_COUNT = 48 and ADC = 96kHz one measure give 96000/48=2000Hz
// for AUDIO_SAMPLES_COUNT = 48 and ADC = 192kHz one measure give 192000/48=4000Hz
// Define additional measure count for menus
#if AUDIO_ADC_FREQ/AUDIO_SAMPLES_COUNT == 4000
#define BANDWIDTH_4000 ( 1 - 1)
#define BANDWIDTH_2000 ( 2 - 1)

@ -1693,7 +1693,7 @@ draw_frequencies(void)
buf2[0] = S_SARROW[0];
ili9341_drawstring(buf1, FREQUENCIES_XPOS1, FREQUENCIES_YPOS);
ili9341_drawstring(buf2, FREQUENCIES_XPOS2, FREQUENCIES_YPOS);
plot_printf(buf1, sizeof(buf1), "bw:%uHz %up", get_bandwidth_frequency(), sweep_points);
plot_printf(buf1, sizeof(buf1), "bw:%uHz %up", get_bandwidth_frequency(config.bandwidth), sweep_points);
ili9341_set_foreground(DEFAULT_GRID_COLOR);
ili9341_drawstring(buf1, FREQUENCIES_XPOS3, FREQUENCIES_YPOS);
}

84
ui.c

@ -143,6 +143,12 @@ typedef struct {
uint16_t fg;
uint8_t border;
int8_t icon;
union {
int32_t i;
uint32_t u;
const char *text;
} p1, p2; // void data for label printf
} button_t;
// Call back functions for MT_CALLBACK type
@ -573,9 +579,13 @@ static UI_FUNCTION_ADV_CALLBACK(menu_cal2_acb)
//menu_move_back();
}
static UI_FUNCTION_CALLBACK(menu_recall_cb)
static UI_FUNCTION_ADV_CALLBACK(menu_recall_acb)
{
(void)item;
if (b){
b->p1.i = data;
return;
}
load_properties(data);
// menu_move_back(true);
update_grid();
@ -616,9 +626,13 @@ static UI_FUNCTION_CALLBACK(menu_dfu_cb)
enter_dfu();
}
static UI_FUNCTION_CALLBACK(menu_save_cb)
static UI_FUNCTION_ADV_CALLBACK(menu_save_acb)
{
(void)item;
if (b){
b->p1.u = data;
return;
}
if (caldata_save(data) == 0) {
menu_move_back(true);
draw_cal_status();
@ -649,6 +663,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_trace_acb)
if (uistat.current_trace == data)
b->icon = BUTTON_ICON_CHECK;
}
b->p1.u = data;
return;
}
@ -736,6 +751,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_bandwidth_acb)
(void)item;
if (b){
b->icon = config.bandwidth == data ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
b->p1.u = get_bandwidth_frequency(data);
return;
}
config.bandwidth = data;
@ -748,6 +764,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_points_acb)
(void)item;
if (b){
b->icon = sweep_points == data ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP;
b->p1.u = data;
return;
}
set_sweep_points(data);
@ -1053,16 +1070,16 @@ static const menuitem_t menu_calop[] = {
};
const menuitem_t menu_save[] = {
{ MT_CALLBACK, 0, "SAVE 0", menu_save_cb },
{ MT_CALLBACK, 1, "SAVE 1", menu_save_cb },
{ MT_CALLBACK, 2, "SAVE 2", menu_save_cb },
{ MT_CALLBACK, 3, "SAVE 3", menu_save_cb },
{ MT_CALLBACK, 4, "SAVE 4", menu_save_cb },
{ MT_ADV_CALLBACK, 0, "SAVE %d", menu_save_acb },
{ MT_ADV_CALLBACK, 1, "SAVE %d", menu_save_acb },
{ MT_ADV_CALLBACK, 2, "SAVE %d", menu_save_acb },
{ MT_ADV_CALLBACK, 3, "SAVE %d", menu_save_acb },
{ MT_ADV_CALLBACK, 4, "SAVE %d", menu_save_acb },
#if SAVEAREA_MAX > 5
{ MT_CALLBACK, 5, "SAVE 5", menu_save_cb },
{ MT_ADV_CALLBACK, 5, "SAVE %d", menu_save_acb },
#endif
#if SAVEAREA_MAX > 6
{ MT_CALLBACK, 6, "SAVE 6", menu_save_cb },
{ MT_ADV_CALLBACK, 6, "SAVE %d", menu_save_acb },
#endif
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
@ -1078,10 +1095,10 @@ const menuitem_t menu_cal[] = {
};
const menuitem_t menu_trace[] = {
{ MT_ADV_CALLBACK, 0, "TRACE 0", menu_trace_acb },
{ MT_ADV_CALLBACK, 1, "TRACE 1", menu_trace_acb },
{ MT_ADV_CALLBACK, 2, "TRACE 2", menu_trace_acb },
{ MT_ADV_CALLBACK, 3, "TRACE 3", menu_trace_acb },
{ MT_ADV_CALLBACK, 0, "TRACE %d", menu_trace_acb },
{ MT_ADV_CALLBACK, 1, "TRACE %d", menu_trace_acb },
{ MT_ADV_CALLBACK, 2, "TRACE %d", menu_trace_acb },
{ MT_ADV_CALLBACK, 3, "TRACE %d", menu_trace_acb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
@ -1145,17 +1162,17 @@ const menuitem_t menu_transform[] = {
const menuitem_t menu_bandwidth[] = {
#ifdef BANDWIDTH_4000
{ MT_ADV_CALLBACK, BANDWIDTH_4000, "4 kHz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_4000, "%u Hz", menu_bandwidth_acb },
#endif
#ifdef BANDWIDTH_2000
{ MT_ADV_CALLBACK, BANDWIDTH_2000, "2 kHz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_2000, "%u Hz", menu_bandwidth_acb },
#endif
{ MT_ADV_CALLBACK, BANDWIDTH_1000, "1 kHz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_333, "333 Hz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_100, "100 Hz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_30, "30 Hz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_1000, "%u Hz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_333, "%u Hz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_100, "%u Hz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_30, "%u Hz", menu_bandwidth_acb },
#ifdef BANDWIDTH_10
{ MT_ADV_CALLBACK, BANDWIDTH_10, "10 Hz", menu_bandwidth_acb },
{ MT_ADV_CALLBACK, BANDWIDTH_10, "%u Hz", menu_bandwidth_acb },
#endif
{ MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
@ -1173,10 +1190,10 @@ const menuitem_t menu_display[] = {
};
const menuitem_t menu_sweep_points[] = {
{ MT_ADV_CALLBACK, POINTS_SET_51, " 51 pt", menu_points_acb },
{ MT_ADV_CALLBACK, POINTS_SET_101, "101 pt", menu_points_acb },
{ MT_ADV_CALLBACK, POINTS_SET_51, "% 3d pt", menu_points_acb },
{ MT_ADV_CALLBACK, POINTS_SET_101, "% 3d pt", menu_points_acb },
#ifdef POINTS_SET_201
{ MT_ADV_CALLBACK, POINTS_SET_201, "201 pt", menu_points_acb },
{ MT_ADV_CALLBACK, POINTS_SET_201, "% 3d pt", menu_points_acb },
#endif
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
@ -1245,16 +1262,16 @@ const menuitem_t menu_marker[] = {
};
const menuitem_t menu_recall[] = {
{ MT_CALLBACK, 0, "RECALL 0", menu_recall_cb },
{ MT_CALLBACK, 1, "RECALL 1", menu_recall_cb },
{ MT_CALLBACK, 2, "RECALL 2", menu_recall_cb },
{ MT_CALLBACK, 3, "RECALL 3", menu_recall_cb },
{ MT_CALLBACK, 4, "RECALL 4", menu_recall_cb },
{ MT_ADV_CALLBACK, 0, "RECALL %d", menu_recall_acb },
{ MT_ADV_CALLBACK, 1, "RECALL %d", menu_recall_acb },
{ MT_ADV_CALLBACK, 2, "RECALL %d", menu_recall_acb },
{ MT_ADV_CALLBACK, 3, "RECALL %d", menu_recall_acb },
{ MT_ADV_CALLBACK, 4, "RECALL %d", menu_recall_acb },
#if SAVEAREA_MAX > 5
{ MT_CALLBACK, 5, "RECALL 5", menu_recall_cb },
{ MT_ADV_CALLBACK, 5, "RECALL %d", menu_recall_acb },
#endif
#if SAVEAREA_MAX > 6
{ MT_CALLBACK, 6, "RECALL 6", menu_recall_cb },
{ MT_ADV_CALLBACK, 6, "RECALL %d", menu_recall_acb },
#endif
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
@ -1728,19 +1745,20 @@ draw_menu_buttons(const menuitem_t *menu)
menuaction_acb_t cb = (menuaction_acb_t)menu[i].reference;
if (cb) (*cb)(i, menu[i].data, &button);
}
char button_text[32];
plot_printf(button_text, sizeof(button_text), menu[i].label, button.p1.u, button.p1.u);
draw_button(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT, &button);
ili9341_set_foreground(button.fg);
ili9341_set_background(button.bg);
uint16_t text_offs = LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER + 5;
if (button.icon >=0){
ili9341_blitBitmap(LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER + 1, y+(MENU_BUTTON_HEIGHT-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]);
text_offs=LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER+1+ICON_WIDTH;
}
int lines = menu_is_multiline(menu[i].label);
ili9341_drawstring(menu[i].label, text_offs, y+(MENU_BUTTON_HEIGHT-lines*FONT_GET_HEIGHT)/2);
int lines = menu_is_multiline(button_text);
ili9341_drawstring(button_text, text_offs, y+(MENU_BUTTON_HEIGHT-lines*FONT_GET_HEIGHT)/2);
}
for (; i < MENU_BUTTON_MAX; i++, y+=MENU_BUTTON_HEIGHT) {
ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT, DEFAULT_BG_COLOR);

Loading…
Cancel
Save

Powered by TurnKey Linux.