add touch operation on keypad

This commit is contained in:
TT 2016-12-17 20:33:04 +09:00
parent 0bf87f42aa
commit ed6aeb873c

191
ui.c
View file

@ -218,7 +218,7 @@ int8_t last_touch_status = FALSE;
int16_t last_touch_x; int16_t last_touch_x;
int16_t last_touch_y; int16_t last_touch_y;
//int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 }; //int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 };
int16_t touch_cal[4] = { 653, 600, 130, 180 }; int16_t touch_cal[4] = { 630, 600, 130, 180 };
#define EVT_TOUCH_NONE 0 #define EVT_TOUCH_NONE 0
#define EVT_TOUCH_DOWN 1 #define EVT_TOUCH_DOWN 1
#define EVT_TOUCH_PRESSED 2 #define EVT_TOUCH_PRESSED 2
@ -247,7 +247,7 @@ int touch_check(void)
} }
} }
int touch_wait_release(void) void touch_wait_release(void)
{ {
int status; int status;
/* wait touch release */ /* wait touch release */
@ -494,9 +494,9 @@ menu_cal_cb(int item)
{ {
(void)item; (void)item;
if (cal_status != 0) { if (cal_status != 0) {
menu_push_submenu(&menu_cal); menu_push_submenu(menu_cal);
} else { } else {
menu_push_submenu(&menu_calop); menu_push_submenu(menu_calop);
} }
} }
@ -906,16 +906,96 @@ ui_process_menu(void)
} }
} }
} }
#define NUMINPUT_LEN 10 #define NUMINPUT_LEN 10
#define KP_CONTINUE 0
#define KP_DONE 1
#define KP_CANCEL 2
char kp_buf[11];
int8_t kp_index = 0;
int
keypad_click(int selection)
{
int c = keypads[selection].c;
if (c >= KP_X1 && c <= KP_G) {
int n = c - KP_X1;
float scale = 1;
while (n-- > 0)
scale *= 1000;
/* numeric input done */
float value = my_atof(kp_buf) * scale;
switch (keypad_mode) {
case KM_START:
set_sweep_frequency(ST_START, value);
break;
case KM_STOP:
set_sweep_frequency(ST_STOP, value);
break;
case KM_CENTER:
set_sweep_frequency(ST_CENTER, value);
break;
case KM_SPAN:
set_sweep_frequency(ST_SPAN, value);
break;
case KM_CW:
set_sweep_frequency(ST_CW, value);
break;
case KM_SCALE:
set_trace_scale(uistat.current_trace, value);
break;
}
return KP_DONE;
} else if (c <= 9 && kp_index < NUMINPUT_LEN)
kp_buf[kp_index++] = '0' + c;
else if (c == KP_PERIOD && kp_index < NUMINPUT_LEN) {
// check period in former input
int j;
for (j = 0; j < kp_index && kp_buf[j] != '.'; j++)
;
// append period if there are no period
if (kp_index == j)
kp_buf[kp_index++] = '.';
} else if (c == KP_BS) {
if (kp_index == 0) {
return KP_CANCEL;
}
--kp_index;
}
kp_buf[kp_index] = '\0';
draw_numeric_input(kp_buf);
return KP_CONTINUE;
}
int
keypad_apply_touch(int touch_x, int touch_y)
{
int i = 0;
while (keypads[i].x) {
if (keypads[i].x < touch_x && touch_x < keypads[i].x+44
&& keypads[i].y < touch_y && touch_y < keypads[i].y+44) {
selection = i;
draw_keypad();
touch_wait_release();
return TRUE;
}
i++;
}
return FALSE;
}
void void
ui_process_keypad(void) ui_process_keypad(void)
{ {
int status = btn_check(); int status;
char buf[11]; adc_stop(ADC1);
int i = 0;
float scale; kp_index = 0;
while (TRUE) { while (TRUE) {
status = btn_check();
if (status & (EVT_UP|EVT_DOWN)) { if (status & (EVT_UP|EVT_DOWN)) {
int s = status; int s = status;
do { do {
@ -934,59 +1014,22 @@ ui_process_keypad(void)
} }
if (status == EVT_BUTTON_SINGLE_CLICK) { if (status == EVT_BUTTON_SINGLE_CLICK) {
int c = keypads[selection].c; if (keypad_click(selection))
if (c >= KP_X1 && c <= KP_G) { /* exit loop on done or cancel */
int n = c - KP_X1; break;
scale = 1; }
while (n-- > 0)
scale *= 1000; status = touch_check();
/* numeric input done */ if (status == EVT_TOUCH_PRESSED) {
int x, y;
touch_position(&x, &y);
if (keypad_apply_touch(x, y)
&& keypad_click(selection))
/* exit loop on done or cancel */
break; break;
} else if (c <= 9 && i < NUMINPUT_LEN)
buf[i++] = '0' + c;
else if (c == KP_PERIOD && i < NUMINPUT_LEN) {
// check period in former input
int j;
for (j = 0; j < i && buf[j] != '.'; j++)
;
// append period if there are no period
if (i == j)
buf[i++] = '.';
} else if (c == KP_BS) {
if (i == 0) {
goto cancel;
}
--i;
}
buf[i] = '\0';
draw_numeric_input(buf);
} }
status = btn_check();
} }
float value = my_atof(buf) * scale;
switch (keypad_mode) {
case KM_START:
set_sweep_frequency(ST_START, value);
break;
case KM_STOP:
set_sweep_frequency(ST_STOP, value);
break;
case KM_CENTER:
set_sweep_frequency(ST_CENTER, value);
break;
case KM_SPAN:
set_sweep_frequency(ST_SPAN, value);
break;
case KM_CW:
set_sweep_frequency(ST_CW, value);
break;
case KM_SCALE:
set_trace_scale(uistat.current_trace, value);
break;
}
cancel:
ui_mode_normal(); ui_mode_normal();
redraw(); redraw();
force_set_markmap(); force_set_markmap();
@ -1016,22 +1059,24 @@ void ui_process_touch(void)
awd_count++; awd_count++;
adc_stop(ADC1); adc_stop(ADC1);
while (TRUE) { int status = touch_check();
int status = touch_check(); if (status == EVT_TOUCH_PRESSED) {
if (status == EVT_TOUCH_PRESSED) { switch (ui_mode) {
switch (ui_mode) { case UI_NORMAL:
case UI_NORMAL: touch_wait_release();
ui_mode_menu(); ui_mode_menu();
break; break;
case UI_MENU:
touch_position(&x, &y); case UI_MENU:
menu_apply_touch(x, y); touch_position(&x, &y);
break; menu_apply_touch(x, y);
case UI_KEYPAD: break;
ui_mode_normal();
break; case UI_KEYPAD:
} #if 0
} else if (status == EVT_TOUCH_RELEASED) { touch_position(&x, &y);
keypad_apply_touch(x, y);
#endif
break; break;
} }
} }