mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Full screen keyboard
Custom buttons draw support
This commit is contained in:
parent
34a3eeafce
commit
8894110423
|
|
@ -102,7 +102,6 @@ enum stimulus_type {
|
||||||
ST_START=0, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
|
ST_START=0, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
|
||||||
};
|
};
|
||||||
|
|
||||||
int shell_printf(const char *fmt, ...);
|
|
||||||
|
|
||||||
void set_sweep_frequency(int type, uint32_t frequency);
|
void set_sweep_frequency(int type, uint32_t frequency);
|
||||||
uint32_t get_sweep_frequency(int type);
|
uint32_t get_sweep_frequency(int type);
|
||||||
|
|
|
||||||
125
ui.c
125
ui.c
|
|
@ -1283,15 +1283,24 @@ menu_invoke(int item)
|
||||||
#define MENU_BUTTON_MAX 8
|
#define MENU_BUTTON_MAX 8
|
||||||
// Menu buttons size
|
// Menu buttons size
|
||||||
#define MENU_BUTTON_WIDTH 60
|
#define MENU_BUTTON_WIDTH 60
|
||||||
#define MENU_BUTTON_HEIGHT 30
|
#define MENU_BUTTON_HEIGHT 29
|
||||||
|
#define MENU_BUTTON_BORDER 1
|
||||||
// Height of numerical input field (at bottom)
|
// Height of numerical input field (at bottom)
|
||||||
#define NUM_INPUT_HEIGHT 30
|
#define NUM_INPUT_HEIGHT 32
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
#define KP_WIDTH ((LCD_WIDTH) / 4) // numeric keypad button width
|
||||||
|
#define KP_HEIGHT ((LCD_HEIGHT - NUM_INPUT_HEIGHT) / 4) // numeric keypad button height
|
||||||
|
// Key x, y position (0 - 15) on screen
|
||||||
|
#define KP_GET_X(posx) ((posx) * KP_WIDTH) // numeric keypad left
|
||||||
|
#define KP_GET_Y(posy) ((posy) * KP_HEIGHT) // numeric keypad top
|
||||||
|
#else
|
||||||
#define KP_WIDTH 48
|
#define KP_WIDTH 48
|
||||||
#define KP_HEIGHT 48
|
#define KP_HEIGHT 48
|
||||||
// Key x, y position (0 - 15) on screen
|
// Key x, y position (0 - 15) on screen
|
||||||
#define KP_GET_X(posx) ((posx)*KP_WIDTH + (LCD_WIDTH-64-KP_WIDTH*4))
|
#define KP_GET_X(posx) ((posx)*KP_WIDTH + (LCD_WIDTH-64-KP_WIDTH*4))
|
||||||
#define KP_GET_Y(posy) ((posy)*KP_HEIGHT + 12 )
|
#define KP_GET_Y(posy) ((posy)*KP_HEIGHT + 12 )
|
||||||
|
#endif
|
||||||
|
|
||||||
// Key names
|
// Key names
|
||||||
#define KP_0 0
|
#define KP_0 0
|
||||||
|
|
@ -1399,6 +1408,18 @@ static const char * const keypad_mode_label[] = {
|
||||||
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY"
|
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
draw_button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t border_colour, uint16_t bg_colour)
|
||||||
|
{
|
||||||
|
// background
|
||||||
|
const uint16_t bw = MENU_BUTTON_BORDER;
|
||||||
|
ili9341_fill(x + bw, y + bw, w - (bw * 2), h - (bw * 2), bg_colour);
|
||||||
|
ili9341_fill(x, y, w, bw, border_colour); // top
|
||||||
|
ili9341_fill(x + w - bw, y, bw, h, border_colour); // right
|
||||||
|
ili9341_fill(x, y, bw, h, border_colour); // left
|
||||||
|
ili9341_fill(x, y + h - bw, w, bw, border_colour); // bottom
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_keypad(void)
|
draw_keypad(void)
|
||||||
{
|
{
|
||||||
|
|
@ -1411,7 +1432,7 @@ draw_keypad(void)
|
||||||
ili9341_set_background(bg);
|
ili9341_set_background(bg);
|
||||||
int x = KP_GET_X(keypads[i].x);
|
int x = KP_GET_X(keypads[i].x);
|
||||||
int y = KP_GET_Y(keypads[i].y);
|
int y = KP_GET_Y(keypads[i].y);
|
||||||
ili9341_fill(x+2, y+2, KP_WIDTH-4, KP_HEIGHT-4, bg);
|
draw_button(x, y, KP_WIDTH, KP_HEIGHT, DEFAULT_BG_COLOR, bg);
|
||||||
ili9341_drawfont(keypads[i].c,
|
ili9341_drawfont(keypads[i].c,
|
||||||
x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2,
|
x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2,
|
||||||
y + (KP_HEIGHT - NUM_FONT_GET_HEIGHT) / 2);
|
y + (KP_HEIGHT - NUM_FONT_GET_HEIGHT) / 2);
|
||||||
|
|
@ -1484,111 +1505,91 @@ static void
|
||||||
menu_item_modify_attribute(const menuitem_t *menu, int item,
|
menu_item_modify_attribute(const menuitem_t *menu, int item,
|
||||||
uint16_t *fg, uint16_t *bg)
|
uint16_t *fg, uint16_t *bg)
|
||||||
{
|
{
|
||||||
|
bool swap = false;
|
||||||
if (menu == menu_trace && item < TRACES_MAX) {
|
if (menu == menu_trace && item < TRACES_MAX) {
|
||||||
if (trace[item].enabled)
|
if (trace[item].enabled){
|
||||||
*bg = config.trace_color[item];
|
*bg = config.trace_color[item];
|
||||||
|
if (item == selection) *fg = ~config.trace_color[item];
|
||||||
|
}
|
||||||
} else if (menu == menu_marker_sel) {
|
} else if (menu == menu_marker_sel) {
|
||||||
if (item < 4) {
|
if ((item < 4 && markers[item].enabled) ||
|
||||||
if (markers[item].enabled) {
|
(item == 5 && uistat.marker_delta))
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
swap = true;
|
||||||
*fg = config.menu_normal_color;
|
else if (item == 5 && uistat.marker_delta)
|
||||||
}
|
swap = true;
|
||||||
} else if (item == 5) {
|
|
||||||
if (uistat.marker_delta) {
|
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (menu == menu_marker_search) {
|
} else if (menu == menu_marker_search) {
|
||||||
if (item == 4 && uistat.marker_tracking) {
|
if (item == 4 && uistat.marker_tracking)
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
swap = true;
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_marker_smith) {
|
} else if (menu == menu_marker_smith) {
|
||||||
|
if (marker_smith_format == item)
|
||||||
if (marker_smith_format == item) {
|
swap = true;
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_calop) {
|
} else if (menu == menu_calop) {
|
||||||
if ((item == 0 && (cal_status & CALSTAT_OPEN))
|
if ((item == 0 && (cal_status & CALSTAT_OPEN))
|
||||||
|| (item == 1 && (cal_status & CALSTAT_SHORT))
|
|| (item == 1 && (cal_status & CALSTAT_SHORT))
|
||||||
|| (item == 2 && (cal_status & CALSTAT_LOAD))
|
|| (item == 2 && (cal_status & CALSTAT_LOAD))
|
||||||
|| (item == 3 && (cal_status & CALSTAT_ISOLN))
|
|| (item == 3 && (cal_status & CALSTAT_ISOLN))
|
||||||
|| (item == 4 && (cal_status & CALSTAT_THRU))) {
|
|| (item == 4 && (cal_status & CALSTAT_THRU)))
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
swap = true;
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_stimulus) {
|
} else if (menu == menu_stimulus) {
|
||||||
if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) {
|
if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE))
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
swap = true;
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_cal) {
|
} else if (menu == menu_cal) {
|
||||||
if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY)) {
|
if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY))
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
swap = true;
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_bandwidth) {
|
} else if (menu == menu_bandwidth) {
|
||||||
if (menu_bandwidth[item].data == config.bandwidth) {
|
if (menu_bandwidth[item].data == config.bandwidth)
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
swap = true;
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_sweep_points) {
|
} else if (menu == menu_sweep_points) {
|
||||||
if (menu_sweep_points[item].data == sweep_points) {
|
if (menu_sweep_points[item].data == sweep_points)
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
swap = true;
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_transform) {
|
} else if (menu == menu_transform) {
|
||||||
if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME)
|
if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME)
|
||||||
|| (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE)
|
|| (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE)
|
||||||
|| (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP)
|
|| (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP)
|
||||||
|| (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS)
|
|| (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS)
|
||||||
) {
|
) swap = true;
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
} else if (menu == menu_transform_window) {
|
} else if (menu == menu_transform_window) {
|
||||||
if ((item == 0 && (domain_mode & TD_WINDOW) == TD_WINDOW_MINIMUM)
|
if ((item == 0 && (domain_mode & TD_WINDOW) == TD_WINDOW_MINIMUM)
|
||||||
|| (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL)
|
|| (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL)
|
||||||
|| (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM)
|
|| (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM)
|
||||||
) {
|
) swap = true;
|
||||||
*bg = DEFAULT_MENU_TEXT_COLOR;
|
|
||||||
*fg = config.menu_normal_color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (swap) {uint16_t t = *bg;*bg=*fg;*fg = t;}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_menu_buttons(const menuitem_t *menu)
|
draw_menu_buttons(const menuitem_t *menu)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0, y = 0;
|
||||||
for (i = 0; i < MENU_BUTTON_MAX; i++) {
|
for (i = 0; i < MENU_BUTTON_MAX; i++, y+=MENU_BUTTON_HEIGHT) {
|
||||||
const char *l1, *l2;
|
const char *l1, *l2;
|
||||||
if (menu[i].type == MT_NONE)
|
if (menu[i].type == MT_NONE)
|
||||||
break;
|
break;
|
||||||
if (menu[i].type == MT_BLANK)
|
if (menu[i].type == MT_BLANK)
|
||||||
continue;
|
continue;
|
||||||
int y = MENU_BUTTON_HEIGHT*i;
|
|
||||||
uint16_t bg = config.menu_normal_color;
|
uint16_t bg = config.menu_normal_color;
|
||||||
uint16_t fg = DEFAULT_MENU_TEXT_COLOR;
|
uint16_t fg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
// focus only in MENU mode but not in KEYPAD mode
|
// focus only in MENU mode but not in KEYPAD mode
|
||||||
if (ui_mode == UI_MENU && i == selection)
|
if (ui_mode == UI_MENU && i == selection)
|
||||||
bg = config.menu_active_color;
|
bg = config.menu_active_color;
|
||||||
ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg);
|
|
||||||
|
|
||||||
menu_item_modify_attribute(menu, i, &fg, &bg);
|
menu_item_modify_attribute(menu, i, &fg, &bg);
|
||||||
ili9341_set_foreground(fg);
|
ili9341_set_foreground(fg);
|
||||||
ili9341_set_background(bg);
|
ili9341_set_background(bg);
|
||||||
|
|
||||||
|
draw_button(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT, fg, bg);
|
||||||
|
|
||||||
if (menu_is_multiline(menu[i].label, &l1, &l2)) {
|
if (menu_is_multiline(menu[i].label, &l1, &l2)) {
|
||||||
ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH+3, y+MENU_BUTTON_HEIGHT/2-FONT_GET_HEIGHT-3, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg);
|
ili9341_drawstring(l1, LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER+4, y+MENU_BUTTON_HEIGHT/2-FONT_GET_HEIGHT-1);
|
||||||
ili9341_drawstring(l1, LCD_WIDTH-MENU_BUTTON_WIDTH+5, y+MENU_BUTTON_HEIGHT/2-FONT_GET_HEIGHT-1);
|
ili9341_drawstring(l2, LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER+4, y+MENU_BUTTON_HEIGHT/2);
|
||||||
ili9341_drawstring(l2, LCD_WIDTH-MENU_BUTTON_WIDTH+5, y+MENU_BUTTON_HEIGHT/2);
|
|
||||||
} else {
|
} else {
|
||||||
ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH+3, y+(MENU_BUTTON_HEIGHT-FONT_GET_HEIGHT-6)/2, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+2, bg);
|
ili9341_drawstring(menu[i].label, LCD_WIDTH-MENU_BUTTON_WIDTH+MENU_BUTTON_BORDER+4, y+(MENU_BUTTON_HEIGHT-FONT_GET_HEIGHT-6)/2+2);
|
||||||
ili9341_drawstring(menu[i].label, LCD_WIDTH-MENU_BUTTON_WIDTH+5, y+(MENU_BUTTON_HEIGHT-FONT_GET_HEIGHT-6)/2+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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -1632,7 +1633,7 @@ draw_menu(void)
|
||||||
static void
|
static void
|
||||||
erase_menu_buttons(void)
|
erase_menu_buttons(void)
|
||||||
{
|
{
|
||||||
ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, DEFAULT_BG_COLOR);
|
// ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, DEFAULT_BG_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue