From e51ca7c51334df7103b0946085b885e566470624 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 18 Dec 2021 15:47:04 +0100 Subject: [PATCH] DiSlord remote screen update --- ili9341.c | 8 +++---- main.c | 66 ++++++++++++++++++------------------------------------- nanovna.h | 22 +++++++++++-------- ui.c | 41 ++++++++++++++-------------------- 4 files changed, 55 insertions(+), 82 deletions(-) diff --git a/ili9341.c b/ili9341.c index 3249d62..c1a39f1 100644 --- a/ili9341.c +++ b/ili9341.c @@ -610,8 +610,8 @@ void ili9341_fill(int x, int y, int w, int h) #endif #ifdef __REMOTE_DESKTOP__ if (auto_capture) { - send_region("fill", x, y, w, h); - send_buffer((uint8_t *)&background_color, sizeof(pixel_t)); + remote_region_t rd = {"fill\r\n", x, y, w, h}; + send_region(&rd, (uint8_t *)&background_color, sizeof(pixel_t)); } #endif #if 1 @@ -632,8 +632,8 @@ static void ili9341_DMA_bulk(uint16_t x, uint16_t y, uint16_t w, uint16_t h, pix #endif #ifdef __REMOTE_DESKTOP__ if (auto_capture) { - send_region("bulk", x, y, w, h); - send_buffer((uint8_t *)buffer, w *h * sizeof(pixel_t)); + remote_region_t rd = {"bulk\r\n", x, y, w, h}; + send_region(&rd, (uint8_t *)buffer, w * h * sizeof(pixel_t)); } #endif // while (SPI_IN_TX_RX(LCD_SPI)); diff --git a/main.c b/main.c index bb1e09e..b00cfa0 100644 --- a/main.c +++ b/main.c @@ -82,7 +82,6 @@ static bool sweep(bool break_on_operation); uint8_t sweep_mode = SWEEP_ENABLE; uint16_t redraw_request = 0; // contains REDRAW_XXX flags -uint8_t auto_capture = false; // Version text, displayed in Config->Version menu, also send by info command const char *info_about[]={ BOARD_NAME, @@ -699,6 +698,20 @@ VNA_SHELL_FUNCTION(cmd_dump) #endif #ifdef __REMOTE_DESKTOP__ +uint8_t remote_mouse_down = false; +uint8_t auto_capture = false; + +void send_region(remote_region_t *rd, uint8_t * buf, uint16_t size) +{ + if (SDU1.config->usbp->state == USB_ACTIVE) { + streamWrite(shell_stream, (void*) rd, sizeof(remote_region_t)); + streamWrite(shell_stream, (void*) buf, size); + streamWrite(shell_stream, (void*)"ch> \r\n", 6); + } + else + auto_capture = false; +} + VNA_SHELL_FUNCTION(cmd_refresh) { // read pixel count at one time (PART*2 bytes required for read buffer) @@ -708,27 +721,19 @@ VNA_SHELL_FUNCTION(cmd_refresh) } } -int16_t mouse_x = 0; -int16_t mouse_y = 0; -uint8_t mouse_down = false; - VNA_SHELL_FUNCTION(cmd_touch) { - if (argc == 2){ - mouse_x = my_atoi(argv[0]); - mouse_y = my_atoi(argv[1]); - mouse_down = true; - handle_touch_interrupt(); - } + if (argc != 2) return; + touch_set(my_atoi(argv[0]), my_atoi(argv[1])); + remote_mouse_down = true; + handle_touch_interrupt(); } VNA_SHELL_FUNCTION(cmd_release) { - if (argc==2) { - mouse_x = my_atoi(argv[0]); - mouse_y = my_atoi(argv[1]); - } - mouse_down = false; + if (argc == 2) + touch_set(my_atoi(argv[0]), my_atoi(argv[1])); + remote_mouse_down = false; handle_touch_interrupt(); } #endif @@ -757,35 +762,6 @@ VNA_SHELL_FUNCTION(cmd_capture) } } -void send_region(const char *t, int16_t x, int16_t y, int16_t w, int16_t h) -{ - if (SDU1.config->usbp->state == USB_ACTIVE) { - shell_printf(t); - struct { - char new_str[2]; - int16_t x; - int16_t y; - int16_t w; - int16_t h; - } region={"\r\n", x,y,w,h}; - streamWrite(shell_stream, (void*)®ion, sizeof(region)); - } - else - auto_capture = false; -} - -void send_buffer(uint8_t * buf, int s) -{ - if (SDU1.config->usbp->state == USB_ACTIVE) { - while (s > 0) { - streamWrite(shell_stream, (void*) buf, (s > 128 ? 128 : s)); - buf = buf+128; - s -= 128; - } - streamWrite(shell_stream, (void*)"ch> \r\n", 6); - } -} - #ifdef ENABLE_SD_CARD_CMD #ifndef __USE_SD_CARD__ #error "Need enable SD card support __USE_SD_CARD__ in nanovna.h, for use ENABLE_SD_CARD_CMD" diff --git a/nanovna.h b/nanovna.h index 8540ee3..e2bbc06 100644 --- a/nanovna.h +++ b/nanovna.h @@ -198,13 +198,6 @@ extern freq_t maxFreq; extern const char TINYSA_VERSION[]; -#ifdef __REMOTE_DESKTOP__ -extern uint8_t auto_capture; -extern int16_t mouse_x; -extern int16_t mouse_y; -extern uint8_t mouse_down; -#endif - #define MAX_FREQ_TYPE 5 enum stimulus_type { ST_START=0, ST_STOP, ST_CENTER, ST_SPAN, ST_CW, ST_DUMMY // Last is used in marker ops @@ -218,10 +211,20 @@ void my_microsecond_delay(int t); float my_atof(const char *p); freq_t my_atoui(const char *p); int shell_printf(const char *fmt, ...); + #ifdef __REMOTE_DESKTOP__ -void send_region(const char *t, int16_t x, int16_t y, int16_t w, int16_t h); -void send_buffer(uint8_t * buf, int s); +extern uint8_t remote_mouse_down; +extern uint8_t auto_capture; +typedef struct { + char new_str[6]; + int16_t x; + int16_t y; + int16_t w; + int16_t h; +} remote_region_t; +void send_region(remote_region_t *rd, uint8_t * buf, uint16_t size); #endif + void set_marker_frequency(int m, freq_t f); void set_marker_time(int m, float f); void set_marker_index(int m, int16_t idx); @@ -1319,6 +1322,7 @@ void draw_menu(void); void draw_menu_mask(uint32_t mask); void refres_sweep_menu(void); int check_touched(void); +void touch_set(int16_t x, int16_t y); int invoke_quick_menu(int); bool ui_process_listen_lever(void); void refresh_sweep_menu(int i); diff --git a/ui.c b/ui.c index d75a23c..d7aa2e1 100644 --- a/ui.c +++ b/ui.c @@ -336,14 +336,9 @@ touch_check(void) last_touch_y = y; } #ifdef __REMOTE_DESKTOP__ - mouse_down = false; - } - if (!stat) { - stat = mouse_down; - if (mouse_down) { - last_touch_x = mouse_x; - last_touch_y = mouse_y; - } + remote_mouse_down = false; + } else { + stat = remote_mouse_down; #endif } if (stat != last_touch_status) { @@ -357,6 +352,11 @@ touch_check(void) //******************************************************************************* #endif // end SOFTWARE_TOUCH +void touch_set(int16_t x, int16_t y) { + last_touch_x = x; + last_touch_y = y; +} + void touch_wait_release(void) { @@ -458,12 +458,14 @@ void touch_position(int *x, int *y) { #ifdef __REMOTE_DESKTOP__ - *x = (mouse_down ? mouse_x : (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2]); - *y = (mouse_down ? mouse_y : (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]); -#else + if (remote_mouse_down) { + *x = last_touch_x; + *y = last_touch_y; + return; + } +#endif *x = (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2]; *y = (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]; -#endif } void @@ -2278,11 +2280,6 @@ void ui_process_touch(void) } static uint16_t previous_button_state = 0; -#ifdef __REMOTE_DESKTOP__ -static uint16_t previous_mouse_state = 0; -static int16_t previous_mouse_x = 0; -static int16_t previous_mouse_y = 0; -#endif void ui_process(void) @@ -2292,17 +2289,13 @@ ui_process(void) selection = -1; // hide keyboard mode selection ui_mode_menu(); } - if (operation_requested&OP_LEVER || previous_button_state != button_state) { + if ((operation_requested&OP_LEVER) || previous_button_state != button_state) { ui_process_lever(); previous_button_state = button_state; operation_requested = OP_NONE; } - if (operation_requested&OP_TOUCH -#ifdef __REMOTE_DESKTOP__ - || previous_mouse_state != mouse_down || previous_mouse_x != mouse_x || previous_mouse_y != mouse_y -#endif - ) { - ui_process_touch(); + if (operation_requested&OP_TOUCH) { + ui_process_touch(); operation_requested = OP_NONE; } touch_start_watchdog();