make smooth touch and lever operation, rearange cal menu

This commit is contained in:
TT 2017-02-03 07:28:20 +09:00
parent 75288abb91
commit 5a63fe6890
2 changed files with 73 additions and 83 deletions

4
plot.c
View file

@ -1332,9 +1332,10 @@ draw_cal_status(void)
c[1] = '*'; c[1] = '*';
else else
c[1] += lastsaveid; c[1] += lastsaveid;
ili9341_drawstring_5x7(c, x, y, 0xffff, 0x0000); ili9341_drawstring_5x7(c, x, y, 0xffff, 0x0000);
y += YSTEP; y += YSTEP;
}
if (cal_status & CALSTAT_ED) { if (cal_status & CALSTAT_ED) {
ili9341_drawstring_5x7("D", x, y, 0xffff, 0x0000); ili9341_drawstring_5x7("D", x, y, 0xffff, 0x0000);
y += YSTEP; y += YSTEP;
@ -1355,7 +1356,6 @@ draw_cal_status(void)
ili9341_drawstring_5x7("X", x, y, 0xffff, 0x0000); ili9341_drawstring_5x7("X", x, y, 0xffff, 0x0000);
y += YSTEP; y += YSTEP;
} }
}
} }

92
ui.c
View file

@ -43,7 +43,7 @@ struct {
#define BUTTON_DOWN_LONG_TICKS 5000 /* 1sec */ #define BUTTON_DOWN_LONG_TICKS 5000 /* 1sec */
#define BUTTON_DOUBLE_TICKS 5000 /* 500ms */ #define BUTTON_DOUBLE_TICKS 5000 /* 500ms */
#define BUTTON_REPEAT_TICKS 1000 /* 100ms */ #define BUTTON_REPEAT_TICKS 1000 /* 100ms */
#define BUTTON_DEBOUNCE_TICKS 100 #define BUTTON_DEBOUNCE_TICKS 200
/* lever switch assignment */ /* lever switch assignment */
#define BIT_UP1 3 #define BIT_UP1 3
@ -119,7 +119,7 @@ static int btn_check(void)
int status = 0; int status = 0;
uint32_t ticks = chVTGetSystemTime(); uint32_t ticks = chVTGetSystemTime();
if (changed & (1<<BIT_PUSH)) { if (changed & (1<<BIT_PUSH)) {
if (cur_button & (1<<BIT_PUSH) if ((cur_button & (1<<BIT_PUSH))
&& ticks - last_button_down_ticks >= BUTTON_DEBOUNCE_TICKS) { && ticks - last_button_down_ticks >= BUTTON_DEBOUNCE_TICKS) {
// button pushed // button pushed
status |= EVT_BUTTON_SINGLE_CLICK; status |= EVT_BUTTON_SINGLE_CLICK;
@ -127,28 +127,20 @@ static int btn_check(void)
last_button_down_ticks = ticks; last_button_down_ticks = ticks;
} }
if (cur_button & (1<<BIT_UP1)) {
if (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) {
if (changed & (1<<BIT_UP1)) { if (changed & (1<<BIT_UP1)) {
if ((cur_button & (1<<BIT_UP1))
&& (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) {
status |= EVT_UP; status |= EVT_UP;
}
last_button_down_ticks = ticks; last_button_down_ticks = ticks;
} }
if (ticks >= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) {
status |= EVT_UP;
}
}
}
if (cur_button & (1<<BIT_DOWN1)) {
if (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) {
if (changed & (1<<BIT_DOWN1)) { if (changed & (1<<BIT_DOWN1)) {
if ((cur_button & (1<<BIT_DOWN1))
&& (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) {
status |= EVT_DOWN; status |= EVT_DOWN;
}
last_button_down_ticks = ticks; last_button_down_ticks = ticks;
} }
if (ticks >= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) {
status |= EVT_DOWN;
}
}
}
last_button = cur_button; last_button = cur_button;
return status; return status;
@ -164,6 +156,7 @@ static int btn_wait_release(void)
if (changed) { if (changed) {
// finished // finished
last_button = cur_button; last_button = cur_button;
last_button_down_ticks = ticks;
return 0; return 0;
} }
@ -396,7 +389,7 @@ menu_calop_cb(int item)
cal_collect(CAL_THRU); cal_collect(CAL_THRU);
break; break;
} }
selection++; selection = item+1;
draw_cal_status(); draw_cal_status();
draw_menu(); draw_menu();
} }
@ -417,18 +410,17 @@ static void
menu_cal2_cb(int item) menu_cal2_cb(int item)
{ {
switch (item) { switch (item) {
case 0: // RESET case 1: // RESET
cal_status = 0; cal_status = 0;
break; break;
case 1: // OFF case 2: // CORRECTION
cal_status &= ~CALSTAT_APPLY; // toggle applying correction
break; if (cal_status)
case 2: // ON cal_status ^= CALSTAT_APPLY;
cal_status |= CALSTAT_APPLY;
break; break;
} }
draw_cal_status(); draw_cal_status();
menu_move_back(); //menu_move_back();
} }
static void static void
@ -437,6 +429,7 @@ menu_recall_cb(int item)
if (item < 0 || item >= 5) if (item < 0 || item >= 5)
return; return;
if (caldata_recall(item) == 0) { if (caldata_recall(item) == 0) {
menu_move_back();
ui_mode_normal(); ui_mode_normal();
update_grid(); update_grid();
draw_cal_status(); draw_cal_status();
@ -561,7 +554,7 @@ menu_stimulus_cb(int item)
ui_mode_keypad(item); ui_mode_keypad(item);
ui_process_keypad(); ui_process_keypad();
break; break;
case 5: /* TOGGLE SWEEP */ case 5: /* SWEEP */
toggle_sweep(); toggle_sweep();
menu_move_back(); menu_move_back();
ui_mode_normal(); ui_mode_normal();
@ -643,26 +636,14 @@ const menuitem_t menu_save[] = {
}; };
const menuitem_t menu_cal[] = { const menuitem_t menu_cal[] = {
{ MT_SUBMENU, "CALIBRATE", menu_calop },
{ MT_CALLBACK, "RESET", menu_cal2_cb }, { MT_CALLBACK, "RESET", menu_cal2_cb },
{ MT_CALLBACK, "OFF", menu_cal2_cb }, { MT_CALLBACK, "CORRECTION", menu_cal2_cb },
{ MT_CALLBACK, "ON", menu_cal2_cb },
{ MT_SUBMENU, "SAVE", menu_save }, { MT_SUBMENU, "SAVE", menu_save },
{ MT_CANCEL, "BACK", NULL }, { MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
static void
menu_cal_cb(int item)
{
(void)item;
if (cal_status != 0) {
menu_push_submenu(menu_cal);
} else {
menu_push_submenu(menu_calop);
}
}
const menuitem_t menu_trace[] = { const menuitem_t menu_trace[] = {
{ MT_CALLBACK, "TRACE 0", menu_trace_cb }, { MT_CALLBACK, "TRACE 0", menu_trace_cb },
{ MT_CALLBACK, "TRACE 1", menu_trace_cb }, { MT_CALLBACK, "TRACE 1", menu_trace_cb },
@ -724,7 +705,7 @@ const menuitem_t menu_stimulus[] = {
{ MT_CALLBACK, "CENTER", menu_stimulus_cb }, { MT_CALLBACK, "CENTER", menu_stimulus_cb },
{ MT_CALLBACK, "SPAN", menu_stimulus_cb }, { MT_CALLBACK, "SPAN", menu_stimulus_cb },
{ MT_CALLBACK, "CW FREQ", menu_stimulus_cb }, { MT_CALLBACK, "CW FREQ", menu_stimulus_cb },
{ MT_CALLBACK, "\2TOGGLE\0SWEEP", menu_stimulus_cb }, { MT_CALLBACK, "SWEEP", menu_stimulus_cb },
{ MT_CANCEL, "BACK", NULL }, { MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
@ -763,7 +744,7 @@ const menuitem_t menu_top[] = {
{ MT_SUBMENU, "DISPLAY", menu_display }, { MT_SUBMENU, "DISPLAY", menu_display },
{ MT_SUBMENU, "MARKER", menu_marker }, { MT_SUBMENU, "MARKER", menu_marker },
{ MT_SUBMENU, "STIMULUS", menu_stimulus }, { MT_SUBMENU, "STIMULUS", menu_stimulus },
{ MT_CALLBACK, "CAL", menu_cal_cb }, { MT_SUBMENU, "CAL", menu_cal },
{ MT_SUBMENU, "RECALL", menu_recall }, { MT_SUBMENU, "RECALL", menu_recall },
{ MT_CLOSE, "CLOSE", NULL }, { MT_CLOSE, "CLOSE", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
@ -863,7 +844,7 @@ void menu_invoke(int item)
const struct { const struct {
uint16_t x, y; uint16_t x, y;
uint8_t c; int8_t c;
} keypads[] = { } keypads[] = {
{ KP_X(1), KP_Y(3), KP_PERIOD }, { KP_X(1), KP_Y(3), KP_PERIOD },
{ KP_X(0), KP_Y(3), 0 }, { KP_X(0), KP_Y(3), 0 },
@ -881,8 +862,9 @@ const struct {
{ KP_X(3), KP_Y(2), KP_K }, { KP_X(3), KP_Y(2), KP_K },
{ KP_X(3), KP_Y(3), KP_X1 }, { KP_X(3), KP_Y(3), KP_X1 },
{ KP_X(2), KP_Y(3), KP_BS }, { KP_X(2), KP_Y(3), KP_BS },
{ 0, 0, 0 } { 0, 0, -1 }
}; };
#define KEYPADS_LAST_INDEX 15
void void
draw_keypad(void) draw_keypad(void)
@ -1126,9 +1108,9 @@ ui_process_menu(void)
int int
keypad_click(int selection) keypad_click(int key)
{ {
int c = keypads[selection].c; int c = keypads[key].c;
if (c >= KP_X1 && c <= KP_G) { if (c >= KP_X1 && c <= KP_G) {
int n = c - KP_X1; int n = c - KP_X1;
float scale = 1; float scale = 1;
@ -1196,15 +1178,18 @@ keypad_apply_touch(void)
while (keypads[i].x) { while (keypads[i].x) {
if (keypads[i].x-2 < touch_x && touch_x < keypads[i].x+44+2 if (keypads[i].x-2 < touch_x && touch_x < keypads[i].x+44+2
&& keypads[i].y-2 < touch_y && touch_y < keypads[i].y+44+2) { && keypads[i].y-2 < touch_y && touch_y < keypads[i].y+44+2) {
// draw focus
selection = i; selection = i;
draw_keypad(); draw_keypad();
touch_wait_release(); touch_wait_release();
// erase focus
selection = -1; selection = -1;
return TRUE; draw_keypad();
return i;
} }
i++; i++;
} }
return FALSE; return -1;
} }
void void
@ -1221,12 +1206,16 @@ ui_process_keypad(void)
do { do {
if (s & EVT_UP) { if (s & EVT_UP) {
selection--; selection--;
selection %= 16; if (selection < 0)
selection = KEYPADS_LAST_INDEX;
draw_keypad(); draw_keypad();
} }
if (s & EVT_DOWN) { if (s & EVT_DOWN) {
selection++; selection++;
selection %= 16; if (keypads[selection].c < 0) {
// reaches to tail
selection = 0;
}
draw_keypad(); draw_keypad();
} }
s = btn_wait_release(); s = btn_wait_release();
@ -1241,8 +1230,8 @@ ui_process_keypad(void)
status = touch_check(); status = touch_check();
if (status == EVT_TOUCH_PRESSED) { if (status == EVT_TOUCH_PRESSED) {
if (keypad_apply_touch() int key = keypad_apply_touch();
&& keypad_click(selection)) if (key >= 0 && keypad_click(key))
/* exit loop on done or cancel */ /* exit loop on done or cancel */
break; break;
} }
@ -1250,6 +1239,7 @@ ui_process_keypad(void)
ui_mode_normal(); ui_mode_normal();
redraw_all(); redraw_all();
touch_start_watchdog();
} }
void void