mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
add button repeat. change numeric input
This commit is contained in:
parent
9c3296ad0d
commit
8014d3442e
11
main.c
11
main.c
|
|
@ -204,9 +204,11 @@ static struct {
|
||||||
int16_t ave[2];
|
int16_t ave[2];
|
||||||
int callback_count;
|
int callback_count;
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t last_counter_value;
|
int32_t last_counter_value;
|
||||||
int32_t interval_cycles;
|
int32_t interval_cycles;
|
||||||
int32_t busy_cycles;
|
int32_t busy_cycles;
|
||||||
|
#endif
|
||||||
} stat;
|
} stat;
|
||||||
|
|
||||||
int16_t rx_buffer[AUDIO_BUFFER_LEN * 2];
|
int16_t rx_buffer[AUDIO_BUFFER_LEN * 2];
|
||||||
|
|
@ -1090,8 +1092,13 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
//extern adcsample_t adc_samples[2];
|
//extern adcsample_t adc_samples[2];
|
||||||
//chprintf(chp, "adc: %d %d\r\n", adc_samples[0], adc_samples[1]);
|
//chprintf(chp, "adc: %d %d\r\n", adc_samples[0], adc_samples[1]);
|
||||||
int x, y;
|
int x, y;
|
||||||
test_touch(&x, &y);
|
for (i = 0; i < 50; i++) {
|
||||||
chprintf(chp, "adc: %d %d\r\n", x, y);
|
test_touch(&x, &y);
|
||||||
|
chprintf(chp, "adc: %d %d\r\n", x, y);
|
||||||
|
chThdSleepMilliseconds(200);
|
||||||
|
}
|
||||||
|
//extern int touch_x, touch_y;
|
||||||
|
//chprintf(chp, "adc: %d %d\r\n", touch_x, touch_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_gain(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_gain(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
|
||||||
118
ui.c
118
ui.c
|
|
@ -37,9 +37,10 @@ struct {
|
||||||
#define EVT_DOWN 0x20
|
#define EVT_DOWN 0x20
|
||||||
#define EVT_REPEAT 0x40
|
#define EVT_REPEAT 0x40
|
||||||
|
|
||||||
#define BUTTON_DOWN_LONG_TICKS 10000 /* 1sec */
|
#define BUTTON_DOWN_LONG_TICKS 5000 /* 1sec */
|
||||||
#define BUTTON_DOUBLE_TICKS 5000 /* 500ms */
|
#define BUTTON_DOUBLE_TICKS 5000 /* 500ms */
|
||||||
#define BUTTON_DEBOUNCE_TICKS 200
|
#define BUTTON_REPEAT_TICKS 1000 /* 100ms */
|
||||||
|
#define BUTTON_DEBOUNCE_TICKS 100
|
||||||
|
|
||||||
/* lever switch assignment */
|
/* lever switch assignment */
|
||||||
#define BIT_UP1 3
|
#define BIT_UP1 3
|
||||||
|
|
@ -51,6 +52,7 @@ struct {
|
||||||
|
|
||||||
static uint16_t last_button = 0b0000;
|
static uint16_t last_button = 0b0000;
|
||||||
static uint32_t last_button_down_ticks;
|
static uint32_t last_button_down_ticks;
|
||||||
|
static uint32_t last_button_repeat_ticks;
|
||||||
uint8_t operation_requested = FALSE;
|
uint8_t operation_requested = FALSE;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
@ -87,7 +89,8 @@ 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) && ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) {
|
if (cur_button & (1<<BIT_PUSH)
|
||||||
|
&& ticks - last_button_down_ticks >= BUTTON_DEBOUNCE_TICKS) {
|
||||||
// button pushed
|
// button pushed
|
||||||
status |= EVT_BUTTON_SINGLE_CLICK;
|
status |= EVT_BUTTON_SINGLE_CLICK;
|
||||||
}
|
}
|
||||||
|
|
@ -134,13 +137,15 @@ static int btn_wait_release(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticks - last_button_down_ticks >= BUTTON_DOWN_LONG_TICKS) {
|
if (ticks - last_button_down_ticks >= BUTTON_DOWN_LONG_TICKS
|
||||||
|
&& ticks - last_button_repeat_ticks >= BUTTON_REPEAT_TICKS) {
|
||||||
if (cur_button & (1<<BIT_DOWN1)) {
|
if (cur_button & (1<<BIT_DOWN1)) {
|
||||||
status |= EVT_DOWN | EVT_REPEAT;
|
status |= EVT_DOWN | EVT_REPEAT;
|
||||||
}
|
}
|
||||||
if (cur_button & (1<<BIT_UP1)) {
|
if (cur_button & (1<<BIT_UP1)) {
|
||||||
status |= EVT_UP | EVT_REPEAT;
|
status |= EVT_UP | EVT_REPEAT;
|
||||||
}
|
}
|
||||||
|
last_button_repeat_ticks = ticks;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -258,7 +263,6 @@ static void
|
||||||
menu_format2_cb(int item)
|
menu_format2_cb(int item)
|
||||||
{
|
{
|
||||||
menu_format_cb(item + 5);
|
menu_format_cb(item + 5);
|
||||||
ui_mode_normal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -267,6 +271,7 @@ menu_channel_cb(int item)
|
||||||
if (item < 0 || item >= 2)
|
if (item < 0 || item >= 2)
|
||||||
return;
|
return;
|
||||||
set_trace_channel(uistat.current_trace, item);
|
set_trace_channel(uistat.current_trace, item);
|
||||||
|
menu_move_back();
|
||||||
ui_mode_normal();
|
ui_mode_normal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -554,9 +559,9 @@ const struct {
|
||||||
{ KP_X(0), KP_Y(0), 7 },
|
{ KP_X(0), KP_Y(0), 7 },
|
||||||
{ KP_X(1), KP_Y(0), 8 },
|
{ KP_X(1), KP_Y(0), 8 },
|
||||||
{ KP_X(2), KP_Y(0), 9 },
|
{ KP_X(2), KP_Y(0), 9 },
|
||||||
//{ KP_X(3), KP_Y(0), KP_G },
|
{ KP_X(3), KP_Y(0), KP_G },
|
||||||
{ KP_X(3), KP_Y(1), KP_M },
|
{ KP_X(3), KP_Y(1), KP_M },
|
||||||
//{ 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, 0 }
|
||||||
|
|
@ -712,38 +717,49 @@ ui_process_menu(void)
|
||||||
if (status & EVT_BUTTON_SINGLE_CLICK) {
|
if (status & EVT_BUTTON_SINGLE_CLICK) {
|
||||||
menu_invoke(selection);
|
menu_invoke(selection);
|
||||||
} else {
|
} else {
|
||||||
if (status & EVT_UP
|
do {
|
||||||
&& menu_stack[menu_current_level][selection+1].type != MT_NONE) {
|
if (status & EVT_UP
|
||||||
selection++;
|
&& menu_stack[menu_current_level][selection+1].type != MT_NONE) {
|
||||||
draw_menu();
|
selection++;
|
||||||
}
|
draw_menu();
|
||||||
if (status & EVT_DOWN
|
}
|
||||||
&& selection > 0) {
|
if (status & EVT_DOWN
|
||||||
selection--;
|
&& selection > 0) {
|
||||||
draw_menu();
|
selection--;
|
||||||
}
|
draw_menu();
|
||||||
|
}
|
||||||
|
status = btn_wait_release();
|
||||||
|
} while (status != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#define NUMINPUT_LEN 10
|
||||||
|
|
||||||
void
|
void
|
||||||
ui_process_keypad(void)
|
ui_process_keypad(void)
|
||||||
{
|
{
|
||||||
int status = btn_check();
|
int status = btn_check();
|
||||||
char buf[15];
|
char buf[11];
|
||||||
char *p = buf;
|
int i = 0;
|
||||||
float scale;
|
float scale;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (status & EVT_UP) {
|
if (status & (EVT_UP|EVT_DOWN)) {
|
||||||
selection--;
|
int s = status;
|
||||||
selection %= 16;
|
do {
|
||||||
draw_keypad();
|
if (s & EVT_UP) {
|
||||||
}
|
selection--;
|
||||||
if (status & EVT_DOWN) {
|
selection %= 16;
|
||||||
selection++;
|
draw_keypad();
|
||||||
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 (status == EVT_BUTTON_SINGLE_CLICK) {
|
||||||
int c = keypads[selection].c;
|
int c = keypads[selection].c;
|
||||||
if (c >= KP_X1 && c <= KP_G) {
|
if (c >= KP_X1 && c <= KP_G) {
|
||||||
|
|
@ -751,18 +767,23 @@ ui_process_keypad(void)
|
||||||
scale = 1;
|
scale = 1;
|
||||||
while (n-- > 0)
|
while (n-- > 0)
|
||||||
scale *= 1000;
|
scale *= 1000;
|
||||||
|
/* numeric input done */
|
||||||
break;
|
break;
|
||||||
} else if (c <= 9)
|
} else if (c <= 9 && i < NUMINPUT_LEN)
|
||||||
*p++ = '0' + c;
|
buf[i++] = '0' + c;
|
||||||
else if (c == KP_PERIOD)
|
else if (c == KP_PERIOD && i < NUMINPUT_LEN) {
|
||||||
*p++ = '.';
|
int j;
|
||||||
else if (c == KP_BS) {
|
for (j = 0; j < i && buf[j] != '.'; j++)
|
||||||
if (p == buf) {
|
;
|
||||||
|
if (buf[j] != '.')
|
||||||
|
buf[i++] = '.';
|
||||||
|
} else if (c == KP_BS) {
|
||||||
|
if (i == 0) {
|
||||||
goto cancel;
|
goto cancel;
|
||||||
}
|
}
|
||||||
--p;
|
--i;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
buf[i] = '\0';
|
||||||
draw_numeric_input(buf);
|
draw_numeric_input(buf);
|
||||||
}
|
}
|
||||||
status = btn_check();
|
status = btn_check();
|
||||||
|
|
@ -857,35 +878,40 @@ static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n)
|
||||||
(void)n;
|
(void)n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_touch(int *x, int *y);
|
||||||
|
|
||||||
int awd_count;
|
int awd_count;
|
||||||
|
int touch_x, touch_y;
|
||||||
|
|
||||||
static void adcerrorcallback(ADCDriver *adcp, adcerror_t err)
|
static void adcerrorcallback(ADCDriver *adcp, adcerror_t err)
|
||||||
{
|
{
|
||||||
(void)adcp;
|
(void)adcp;
|
||||||
if (err == ADC_ERR_AWD) {
|
if (err == ADC_ERR_AWD) {
|
||||||
awd_count++;
|
awd_count++;
|
||||||
|
// does not work in callback
|
||||||
|
//test_touch(&touch_x, &touch_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GPTConfig gpt3cfg = {
|
static const GPTConfig gpt3cfg = {
|
||||||
1000, /* 1kHz timer clock.*/
|
1000, /* 1kHz timer clock.*/
|
||||||
NULL, /* Timer callback.*/
|
NULL, /* Timer callback.*/
|
||||||
0x0040,
|
0x0020,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ADC_GRP1_NUM_CHANNELS 1
|
#define ADC_GRP1_NUM_CHANNELS 1
|
||||||
#define ADC_GRP1_BUF_DEPTH 8
|
#define ADC_GRP1_BUF_DEPTH 1
|
||||||
|
|
||||||
static const ADCConversionGroup adcgrpcfg1 = {
|
static const ADCConversionGroup adcgrpcfg1 = {
|
||||||
TRUE,
|
TRUE,
|
||||||
ADC_GRP1_NUM_CHANNELS,
|
ADC_GRP1_NUM_CHANNELS,
|
||||||
adccallback,
|
adccallback,
|
||||||
adcerrorcallback,
|
adcerrorcallback,
|
||||||
ADC_CFGR1_CONT | ADC_CFGR1_RES_12BIT | ADC_CFGR1_AWDEN |
|
ADC_CFGR1_RES_12BIT | ADC_CFGR1_AWDEN
|
||||||
ADC_CFGR1_EXTEN_0 | // rising edge of external trigger
|
| ADC_CFGR1_EXTEN_0 | // rising edge of external trigger
|
||||||
ADC_CFGR1_EXTSEL_0 | ADC_CFGR1_EXTSEL_1, // TRG3 /* CFGR1 */
|
ADC_CFGR1_EXTSEL_0 | ADC_CFGR1_EXTSEL_1, // TRG3 , /* CFGR1 */
|
||||||
ADC_TR(1000, 0), /* TR */
|
ADC_TR(2048, 0), /* TR */
|
||||||
ADC_SMPR_SMP_28P5, /* SMPR */
|
ADC_SMPR_SMP_28P5, /* SMPR */
|
||||||
ADC_CHSELR_CHSEL7 /* CHSELR */
|
ADC_CHSELR_CHSEL7 /* CHSELR */
|
||||||
};
|
};
|
||||||
|
|
@ -958,7 +984,7 @@ test_touch(int *x, int *y)
|
||||||
*x = touch_measure_x();
|
*x = touch_measure_x();
|
||||||
*y = touch_measure_y();
|
*y = touch_measure_y();
|
||||||
touch_wait_sense();
|
touch_wait_sense();
|
||||||
adcStartConversion(&ADCD1, &adcgrpcfg1, adc_samples, 8);
|
adcStartConversion(&ADCD1, &adcgrpcfg1, adc_samples, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -969,10 +995,12 @@ ui_init()
|
||||||
*/
|
*/
|
||||||
extStart(&EXTD1, &extcfg);
|
extStart(&EXTD1, &extcfg);
|
||||||
|
|
||||||
|
#if 1
|
||||||
gptStart(&GPTD3, &gpt3cfg);
|
gptStart(&GPTD3, &gpt3cfg);
|
||||||
gptPolledDelay(&GPTD3, 10); /* Small delay.*/
|
gptPolledDelay(&GPTD3, 10); /* Small delay.*/
|
||||||
|
|
||||||
gptStartContinuous(&GPTD3, 5000);
|
gptStartContinuous(&GPTD3, 10);
|
||||||
|
#endif
|
||||||
|
|
||||||
touch_wait_sense();
|
touch_wait_sense();
|
||||||
/*
|
/*
|
||||||
|
|
@ -981,5 +1009,5 @@ ui_init()
|
||||||
adcStart(&ADCD1, NULL);
|
adcStart(&ADCD1, NULL);
|
||||||
adcSTM32SetCCR(ADC_CCR_VREFEN);
|
adcSTM32SetCCR(ADC_CCR_VREFEN);
|
||||||
|
|
||||||
adcStartConversion(&ADCD1, &adcgrpcfg1, adc_samples, 8);
|
adcStartConversion(&ADCD1, &adcgrpcfg1, adc_samples, 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue