fix jump of touch sense, add touchtest command, draw on touch cal, fix gap of drag marker position

pull/4/head
TT 9 years ago
parent 73926f3c93
commit b42749e57d

@ -375,7 +375,7 @@ config_t config = {
/* menu_active_color */ 0x7777, /* menu_active_color */ 0x7777,
/* trace_colors[4] */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) }, /* 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, 160, 190 },
/* touch_cal[4] */ { 620, 600, 130, 180 }, /* touch_cal[4] */ { 693, 605, 124, 171 },
/* default_loadcal */ 0, /* default_loadcal */ 0,
/* checksum */ 0 /* checksum */ 0
}; };
@ -546,6 +546,8 @@ set_sweep_frequency(int type, float frequency)
freq_mode_startstop(); freq_mode_startstop();
if (frequency < START_MIN) if (frequency < START_MIN)
freq = START_MIN; freq = START_MIN;
if (frequency > STOP_MAX)
freq = STOP_MAX;
if (frequency0 != freq) { if (frequency0 != freq) {
ensure_edit_config(); ensure_edit_config();
frequency0 = freq; frequency0 = freq;
@ -559,6 +561,8 @@ set_sweep_frequency(int type, float frequency)
freq_mode_startstop(); freq_mode_startstop();
if (frequency > STOP_MAX) if (frequency > STOP_MAX)
freq = STOP_MAX; freq = STOP_MAX;
if (frequency < START_MIN)
freq = START_MIN;
if (frequency1 != freq) { if (frequency1 != freq) {
ensure_edit_config(); ensure_edit_config();
frequency1 = freq; frequency1 = freq;
@ -1228,6 +1232,18 @@ static void cmd_touchcal(BaseSequentialStream *chp, int argc, char *argv[])
touch_start_watchdog(); 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[]) static void cmd_frequencies(BaseSequentialStream *chp, int argc, char *argv[])
{ {
int i; int i;
@ -1388,6 +1404,7 @@ static const ShellCommand commands[] =
{ "sweep", cmd_sweep }, { "sweep", cmd_sweep },
{ "test", cmd_test }, { "test", cmd_test },
{ "touchcal", cmd_touchcal }, { "touchcal", cmd_touchcal },
{ "touchtest", cmd_touchtest },
{ "pause", cmd_pause }, { "pause", cmd_pause },
{ "resume", cmd_resume }, { "resume", cmd_resume },
{ "cal", cmd_cal }, { "cal", cmd_cal },

@ -307,6 +307,7 @@ void handle_touch_interrupt(void);
#define TOUCH_THRESHOLD 2000 #define TOUCH_THRESHOLD 2000
void touch_cal_exec(void); void touch_cal_exec(void);
void touch_draw_test(void);
/* /*
* adc.c * adc.c

67
ui.c

@ -196,9 +196,9 @@ touch_measure_y(void)
chThdSleepMilliseconds(2); chThdSleepMilliseconds(2);
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL7); v = adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
chThdSleepMilliseconds(2); //chThdSleepMilliseconds(2);
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7); //v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
return v/2; return v;
} }
int int
@ -216,9 +216,9 @@ touch_measure_x(void)
chThdSleepMilliseconds(2); chThdSleepMilliseconds(2);
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL6); v = adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
chThdSleepMilliseconds(2); //chThdSleepMilliseconds(2);
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6); //v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
return v/2; return v;
} }
void void
@ -252,8 +252,13 @@ int touch_check(void)
{ {
int stat = touch_status(); int stat = touch_status();
if (stat) { if (stat) {
last_touch_x = touch_measure_x(); chThdSleepMilliseconds(10);
last_touch_y = touch_measure_y(); int x = touch_measure_x();
int y = touch_measure_y();
if (touch_status()) {
last_touch_x = x;
last_touch_y = y;
}
touch_prepare_sense(); touch_prepare_sense();
} }
@ -289,12 +294,20 @@ touch_cal_exec(void)
adc_stop(ADC1); 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 { do {
status = touch_check(); status = touch_check();
} while(status != EVT_TOUCH_PRESSED); } while(status != EVT_TOUCH_PRESSED);
x1 = last_touch_x; x1 = last_touch_x;
y1 = last_touch_y; 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 { do {
status = touch_check(); status = touch_check();
} while(status != EVT_TOUCH_PRESSED); } while(status != EVT_TOUCH_PRESSED);
@ -305,8 +318,38 @@ touch_cal_exec(void)
config.touch_cal[1] = y1; config.touch_cal[1] = y1;
config.touch_cal[2] = (x2 - x1) * 16 / 320; config.touch_cal[2] = (x2 - x1) * 16 / 320;
config.touch_cal[3] = (y2 - y1) * 16 / 240; 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 void
touch_position(int *x, int *y) touch_position(int *x, int *y)
{ {
@ -1233,7 +1276,9 @@ void drag_marker(int t, int m)
int touch_x, touch_y; int touch_x, touch_y;
int index; int index;
touch_position(&touch_x, &touch_y); 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) { if (index >= 0) {
markers[m].index = index; markers[m].index = index;
redraw_marker(m, TRUE); redraw_marker(m, TRUE);
@ -1255,8 +1300,8 @@ touch_pickup_marker(void)
int touch_x, touch_y; int touch_x, touch_y;
int m, t; int m, t;
touch_position(&touch_x, &touch_y); touch_position(&touch_x, &touch_y);
touch_x += OFFSETX; touch_x -= OFFSETX;
touch_y += OFFSETY; touch_y -= OFFSETY;
for (m = 0; m < 4; m++) { for (m = 0; m < 4; m++) {
if (!markers[m].enabled) if (!markers[m].enabled)

Loading…
Cancel
Save

Powered by TurnKey Linux.