diff --git a/main.c b/main.c index 7c2d352..5327b2f 100644 --- a/main.c +++ b/main.c @@ -375,7 +375,7 @@ config_t config = { /* menu_active_color */ 0x7777, /* trace_colors[4] */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) }, ///* touch_cal[4] */ { 620, 600, 160, 190 }, - /* touch_cal[4] */ { 620, 600, 130, 180 }, + /* touch_cal[4] */ { 693, 605, 124, 171 }, /* default_loadcal */ 0, /* checksum */ 0 }; @@ -546,6 +546,8 @@ set_sweep_frequency(int type, float frequency) freq_mode_startstop(); if (frequency < START_MIN) freq = START_MIN; + if (frequency > STOP_MAX) + freq = STOP_MAX; if (frequency0 != freq) { ensure_edit_config(); frequency0 = freq; @@ -559,6 +561,8 @@ set_sweep_frequency(int type, float frequency) freq_mode_startstop(); if (frequency > STOP_MAX) freq = STOP_MAX; + if (frequency < START_MIN) + freq = START_MIN; if (frequency1 != freq) { ensure_edit_config(); frequency1 = freq; @@ -1228,6 +1232,18 @@ static void cmd_touchcal(BaseSequentialStream *chp, int argc, char *argv[]) touch_start_watchdog(); } +static void cmd_touchtest(BaseSequentialStream *chp, int argc, char *argv[]) +{ + (void)chp; + (void)argc; + (void)argv; + chMtxLock(&mutex); + do { + touch_draw_test(); + } while(argc); + chMtxUnlock(&mutex); +} + static void cmd_frequencies(BaseSequentialStream *chp, int argc, char *argv[]) { int i; @@ -1388,6 +1404,7 @@ static const ShellCommand commands[] = { "sweep", cmd_sweep }, { "test", cmd_test }, { "touchcal", cmd_touchcal }, + { "touchtest", cmd_touchtest }, { "pause", cmd_pause }, { "resume", cmd_resume }, { "cal", cmd_cal }, diff --git a/nanovna.h b/nanovna.h index b8ac09d..76cf74a 100644 --- a/nanovna.h +++ b/nanovna.h @@ -307,6 +307,7 @@ void handle_touch_interrupt(void); #define TOUCH_THRESHOLD 2000 void touch_cal_exec(void); +void touch_draw_test(void); /* * adc.c diff --git a/ui.c b/ui.c index 4a69dd4..e82aac1 100644 --- a/ui.c +++ b/ui.c @@ -196,9 +196,9 @@ touch_measure_y(void) chThdSleepMilliseconds(2); v = adc_single_read(ADC1, ADC_CHSELR_CHSEL7); - chThdSleepMilliseconds(2); - v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7); - return v/2; + //chThdSleepMilliseconds(2); + //v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7); + return v; } int @@ -216,9 +216,9 @@ touch_measure_x(void) chThdSleepMilliseconds(2); v = adc_single_read(ADC1, ADC_CHSELR_CHSEL6); - chThdSleepMilliseconds(2); - v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6); - return v/2; + //chThdSleepMilliseconds(2); + //v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6); + return v; } void @@ -252,8 +252,13 @@ int touch_check(void) { int stat = touch_status(); if (stat) { - last_touch_x = touch_measure_x(); - last_touch_y = touch_measure_y(); + chThdSleepMilliseconds(10); + int x = touch_measure_x(); + int y = touch_measure_y(); + if (touch_status()) { + last_touch_x = x; + last_touch_y = y; + } touch_prepare_sense(); } @@ -289,12 +294,20 @@ touch_cal_exec(void) adc_stop(ADC1); + ili9341_fill(0, 0, 320, 240, 0); + ili9341_line(0, 0, 0, 32, 0xffff); + ili9341_line(0, 0, 32, 0, 0xffff); + do { status = touch_check(); } while(status != EVT_TOUCH_PRESSED); x1 = last_touch_x; y1 = last_touch_y; + ili9341_fill(0, 0, 320, 240, 0); + ili9341_line(320-1, 240-1, 320-1, 240-32, 0xffff); + ili9341_line(320-1, 240-1, 320-32, 240-1, 0xffff); + do { status = touch_check(); } while(status != EVT_TOUCH_PRESSED); @@ -305,8 +318,38 @@ touch_cal_exec(void) config.touch_cal[1] = y1; config.touch_cal[2] = (x2 - x1) * 16 / 320; config.touch_cal[3] = (y2 - y1) * 16 / 240; + + touch_start_watchdog(); + redraw_all(); +} + +void +touch_draw_test(void) +{ + int status; + int x0, y0; + int x1, y1; + + adc_stop(ADC1); + + do { + status = touch_check(); + } while(status != EVT_TOUCH_PRESSED); + touch_position(&x0, &y0); + + do { + status = touch_check(); + touch_position(&x1, &y1); + ili9341_line(x0, y0, x1, y1, 0xffff); + x0 = x1; + y0 = y1; + chThdSleepMilliseconds(50); + } while(status != EVT_TOUCH_RELEASED); + + touch_start_watchdog(); } + void touch_position(int *x, int *y) { @@ -1233,7 +1276,9 @@ void drag_marker(int t, int m) int touch_x, touch_y; int index; touch_position(&touch_x, &touch_y); - index = search_nearest_index(touch_x + OFFSETX, touch_y + OFFSETY, t); + touch_x -= OFFSETX; + touch_y -= OFFSETY; + index = search_nearest_index(touch_x, touch_y, t); if (index >= 0) { markers[m].index = index; redraw_marker(m, TRUE); @@ -1255,8 +1300,8 @@ touch_pickup_marker(void) int touch_x, touch_y; int m, t; touch_position(&touch_x, &touch_y); - touch_x += OFFSETX; - touch_y += OFFSETY; + touch_x -= OFFSETX; + touch_y -= OFFSETY; for (m = 0; m < 4; m++) { if (!markers[m].enabled)