mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
add dragging marker
This commit is contained in:
parent
9037593831
commit
7943a3fe96
6
flash.c
6
flash.c
|
|
@ -66,7 +66,7 @@ void flash_unlock(void)
|
|||
|
||||
|
||||
static uint32_t
|
||||
checksum(void *start, size_t len)
|
||||
checksum(const void *start, size_t len)
|
||||
{
|
||||
uint32_t *p = (uint32_t*)start;
|
||||
uint32_t *tail = (uint32_t*)(start + len);
|
||||
|
|
@ -85,7 +85,7 @@ int
|
|||
config_save(void)
|
||||
{
|
||||
uint16_t *src = (uint16_t*)&config;
|
||||
uint16_t *dst = save_config_area;
|
||||
uint16_t *dst = (uint16_t*)save_config_area;
|
||||
int count = sizeof(config_t) / sizeof(uint16_t);
|
||||
|
||||
config.magic = CONFIG_MAGIC;
|
||||
|
|
@ -109,7 +109,7 @@ config_save(void)
|
|||
int
|
||||
config_recall(void)
|
||||
{
|
||||
config_t *src = save_config_area;
|
||||
const config_t *src = (const config_t*)save_config_area;
|
||||
void *dst = &config;
|
||||
|
||||
if (src->magic != CONFIG_MAGIC)
|
||||
|
|
|
|||
|
|
@ -206,6 +206,8 @@ void draw_cal_status(void);
|
|||
|
||||
void markmap_all_markers(void);
|
||||
|
||||
void marker_position(int m, int t, int *x, int *y);
|
||||
int search_nearest_index(int x, int y, int t);
|
||||
|
||||
/*
|
||||
* ili9341.c
|
||||
|
|
|
|||
31
plot.c
31
plot.c
|
|
@ -885,6 +885,37 @@ draw_marker(int w, int h, int x, int y, int c, int ch)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
marker_position(int m, int t, int *x, int *y)
|
||||
{
|
||||
uint32_t index = trace_index[t][markers[m].index];
|
||||
*x = CELL_X(index);
|
||||
*y = CELL_Y(index);
|
||||
}
|
||||
|
||||
int
|
||||
search_nearest_index(int x, int y, int t)
|
||||
{
|
||||
uint32_t *index = trace_index[t];
|
||||
int min_i = -1;
|
||||
int min_d = 1000;
|
||||
int i;
|
||||
for (i = 0; i < 101; i++) {
|
||||
int dx = x - CELL_X(index[i]) - OFFSETX;
|
||||
int dy = y - CELL_Y(index[i]) - OFFSETY;
|
||||
if (dx < 0) dx = -dx;
|
||||
if (dy < 0) dy = -dy;
|
||||
if (dx > 20 && dy > 20)
|
||||
continue;
|
||||
int d = dx*dx + dy*dy;
|
||||
if (d < min_d) {
|
||||
min_i = i;
|
||||
}
|
||||
}
|
||||
|
||||
return min_i;
|
||||
}
|
||||
|
||||
void
|
||||
cell_draw_markers(int m, int n, int w, int h)
|
||||
{
|
||||
|
|
|
|||
65
ui.c
65
ui.c
|
|
@ -1152,6 +1152,64 @@ ui_process_lever(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void drag_marker(int t, int m)
|
||||
{
|
||||
int status;
|
||||
/* wait touch release */
|
||||
do {
|
||||
int touch_x, touch_y;
|
||||
int index;
|
||||
touch_position(&touch_x, &touch_y);
|
||||
index = search_nearest_index(touch_x, touch_y, t);
|
||||
if (index >= 0) {
|
||||
markers[m].index = index;
|
||||
redraw_marker(m, TRUE);
|
||||
}
|
||||
|
||||
status = touch_check();
|
||||
} while(status != EVT_TOUCH_RELEASED);
|
||||
}
|
||||
|
||||
static int
|
||||
sq_distance(int x0, int y0)
|
||||
{
|
||||
return x0*x0 + y0*y0;
|
||||
}
|
||||
|
||||
int
|
||||
touch_pickup_marker(void)
|
||||
{
|
||||
int touch_x, touch_y;
|
||||
int m, t;
|
||||
touch_position(&touch_x, &touch_y);
|
||||
|
||||
for (m = 0; m < 4; m++) {
|
||||
if (!markers[m].enabled)
|
||||
continue;
|
||||
|
||||
for (t = 0; t < 4; t++) {
|
||||
int x, y;
|
||||
if (!trace[t].enabled)
|
||||
continue;
|
||||
|
||||
marker_position(m, t, &x, &y);
|
||||
|
||||
if (sq_distance(x - touch_x, y - touch_y) < 400) {
|
||||
active_marker = m;
|
||||
redraw_marker(active_marker, TRUE);
|
||||
|
||||
drag_marker(t, m);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ui_process_touch(void)
|
||||
{
|
||||
awd_count++;
|
||||
|
|
@ -1161,7 +1219,14 @@ void ui_process_touch(void)
|
|||
if (status == EVT_TOUCH_PRESSED) {
|
||||
switch (ui_mode) {
|
||||
case UI_NORMAL:
|
||||
|
||||
if (touch_pickup_marker()) {
|
||||
break;
|
||||
}
|
||||
|
||||
touch_wait_release();
|
||||
|
||||
// switch menu mode
|
||||
selection = -1;
|
||||
ui_mode_menu();
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in a new issue