Skip to content

Commit

Permalink
Enable SD card commands
Browse files Browse the repository at this point in the history
Enable load config.ini from SD card
Smooth menu/keyboard update
  • Loading branch information
DiSlord committed May 30, 2021
1 parent 323f379 commit 4bc232d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static volatile vna_shellcmd_t shell_function = 0;
// Enable usart command
#define ENABLE_USART_COMMAND
// Enable SD card console command
//#define ENABLE_SD_CARD_CMD
#define ENABLE_SD_CARD_CMD

static void apply_CH0_error_term_at(int i);
static void apply_CH1_error_term_at(int i);
Expand Down
2 changes: 1 addition & 1 deletion nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// Add SD card support, req enable RTC (additional settings for file system see FatFS lib ffconf.h)
#define __USE_SD_CARD__
// Allow run commands from SD card (config.ini in root)
//#define __SD_CARD_LOAD__
#define __SD_CARD_LOAD__
// If enabled serial in halconf.h, possible enable serial console control
#define __USE_SERIAL_CONSOLE__
// Add LC match function
Expand Down
49 changes: 30 additions & 19 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1836,12 +1836,13 @@ static void drawMessageBox(char *header, char *text, uint32_t delay){
}

static void
draw_keypad(void)
draw_keypad(uint32_t mask)
{
int i = 0;
int i;
button_t button;
button.fg = LCD_MENU_TEXT_COLOR;
do {
for(i = 0; keypads[i].c != KP_NONE; i++) {
if ((mask&(1<<i)) == 0) continue;
if (i == selection){
button.bg = LCD_MENU_ACTIVE_COLOR;
button.border = KEYBOARD_BUTTON_BORDER|BUTTON_BORDER_FALLING;
Expand All @@ -1856,7 +1857,7 @@ draw_keypad(void)
lcd_drawfont(keypads[i].c,
x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2,
y + (KP_HEIGHT - NUM_FONT_GET_HEIGHT) / 2);
}while (keypads[++i].c != KP_NONE);
}
}

static int period_pos(void) {int j; for (j = 0; j < kp_index && kp_buf[j] != '.'; j++); return j;}
Expand Down Expand Up @@ -2004,15 +2005,15 @@ static const uint8_t button_icons[] = {
};

static void
draw_menu_buttons(const menuitem_t *menu)
draw_menu_buttons(const menuitem_t *menu, uint32_t mask)
{
uint16_t i, y;
for (i = 0, y = 1; i < MENU_BUTTON_MAX; i++, y+=menu_button_height) {
if (menu[i].type == MT_NONE)
break;
if (menu[i].type == MT_BLANK)
continue;

if ((mask&(1<<i)) == 0) continue;
button_t button;
button.fg = LCD_MENU_TEXT_COLOR;
button.icon = BUTTON_ICON_NONE;
Expand Down Expand Up @@ -2057,7 +2058,13 @@ draw_menu_buttons(const menuitem_t *menu)
static void
draw_menu(void)
{
draw_menu_buttons(menu_stack[menu_current_level]);
draw_menu_buttons(menu_stack[menu_current_level], -1);
}

static void
draw_menu_mask(uint32_t mask)
{
draw_menu_buttons(menu_stack[menu_current_level], mask);
}

#if 0
Expand Down Expand Up @@ -2093,6 +2100,7 @@ ui_process_menu_lever(uint16_t status)
return;
}
do {
uint32_t mask = 1<<selection;
if (status & EVT_UP)
selection++;
if (status & EVT_DOWN)
Expand All @@ -2102,8 +2110,8 @@ ui_process_menu_lever(uint16_t status)
ui_mode_normal();
return;
}
draw_menu();
chThdSleepMilliseconds(200);
draw_menu_mask(mask|(1<<selection));
chThdSleepMilliseconds(100);
} while ((status = btn_wait_release()) != 0);
}

Expand All @@ -2118,11 +2126,12 @@ menu_apply_touch(int touch_x, int touch_y)
if (menu[i].type == MT_BLANK)
continue;
if (y < touch_y && touch_y < y+menu_button_height && LCD_WIDTH-MENU_BUTTON_WIDTH < touch_x) {
selection = i;
draw_menu();
touch_wait_release();
selection = -1;
menu_invoke(i);
uint32_t mask = (1<<i)|(1<<selection);
selection = i;
draw_menu_mask(mask);
touch_wait_release();
selection = -1;
menu_invoke(i);
return;
}
}
Expand Down Expand Up @@ -2302,7 +2311,7 @@ ui_mode_keypad(int _keypad_mode)
kp_index = 0;
ui_mode = UI_KEYPAD;
draw_menu();
draw_keypad();
draw_keypad(-1);
draw_numeric_area_frame();
}

Expand Down Expand Up @@ -2359,12 +2368,13 @@ keypad_apply_touch(int touch_x, int touch_y)
int y = KP_GET_Y(keypads[i].y);
if (x < touch_x && touch_x < x+KP_WIDTH && y < touch_y && touch_y < y+KP_HEIGHT) {
// draw focus
uint32_t mask = (1<<i)|(1<<selection);
selection = i;
draw_keypad();
draw_keypad(mask);
touch_wait_release();
// erase focus
selection = -1;
draw_keypad();
draw_keypad(1<<i);
// Exit loop on done or cancel
if (keypad_click(i) != KP_CONTINUE)
ui_mode_normal();
Expand All @@ -2389,12 +2399,13 @@ ui_process_keypad_lever(uint16_t status)
for (keypads_last_index = 0; keypads[keypads_last_index+1].c != KP_NONE; keypads_last_index++)
;
do {
uint32_t mask = 1<<selection;
if ((status & EVT_DOWN) && --selection < 0)
selection = keypads_last_index;
if ((status & EVT_UP) && ++selection > keypads_last_index)
selection = 0;
draw_keypad();
chThdSleepMilliseconds(200);
draw_keypad(mask|(1<<selection));
chThdSleepMilliseconds(100);
} while ((status = btn_wait_release()) != 0);
}
//========================== end keyboard input =======================
Expand Down

0 comments on commit 4bc232d

Please sign in to comment.