add touch operation on keypad

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

165
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,65 +906,27 @@ ui_process_menu(void)
} }
} }
} }
#define NUMINPUT_LEN 10 #define NUMINPUT_LEN 10
void #define KP_CONTINUE 0
ui_process_keypad(void) #define KP_DONE 1
{ #define KP_CANCEL 2
int status = btn_check();
char buf[11];
int i = 0;
float scale;
while (TRUE) {
if (status & (EVT_UP|EVT_DOWN)) {
int s = status;
do {
if (s & EVT_UP) {
selection--;
selection %= 16;
draw_keypad();
}
if (s & EVT_DOWN) {
selection++;
selection %= 16;
draw_keypad();
}
s = btn_wait_release();
} while (s != 0);
}
if (status == EVT_BUTTON_SINGLE_CLICK) { char kp_buf[11];
int8_t kp_index = 0;
int
keypad_click(int selection)
{
int c = keypads[selection].c; int c = keypads[selection].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;
scale = 1; float scale = 1;
while (n-- > 0) while (n-- > 0)
scale *= 1000; scale *= 1000;
/* numeric input done */ /* numeric input done */
break; float value = my_atof(kp_buf) * scale;
} 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) { switch (keypad_mode) {
case KM_START: case KM_START:
set_sweep_frequency(ST_START, value); set_sweep_frequency(ST_START, value);
@ -986,7 +948,88 @@ ui_process_keypad(void)
break; break;
} }
cancel: 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
ui_process_keypad(void)
{
int status;
adc_stop(ADC1);
kp_index = 0;
while (TRUE) {
status = btn_check();
if (status & (EVT_UP|EVT_DOWN)) {
int s = status;
do {
if (s & EVT_UP) {
selection--;
selection %= 16;
draw_keypad();
}
if (s & EVT_DOWN) {
selection++;
selection %= 16;
draw_keypad();
}
s = btn_wait_release();
} while (s != 0);
}
if (status == EVT_BUTTON_SINGLE_CLICK) {
if (keypad_click(selection))
/* exit loop on done or cancel */
break;
}
status = touch_check();
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;
}
}
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: case UI_MENU:
touch_position(&x, &y); touch_position(&x, &y);
menu_apply_touch(x, y); menu_apply_touch(x, y);
break; break;
case UI_KEYPAD: case UI_KEYPAD:
ui_mode_normal(); #if 0
break; touch_position(&x, &y);
} keypad_apply_touch(x, y);
} else if (status == EVT_TOUCH_RELEASED) { #endif
break; break;
} }
} }