diff --git a/main.c b/main.c index d2f0132..a420f9b 100644 --- a/main.c +++ b/main.c @@ -963,7 +963,7 @@ config_t config = { .touch_cal = { 347, 495, 160, 205 }, // 2.8 inch LCD panel #endif #ifdef TINYSA4 - .touch_cal = { 278, 513, 115, 154 }, // 4 inch panel + .touch_cal = { 444, 715, 3552, 3499 }, // 4 inch panel #endif ._mode = _MODE_USB | _MODE_AUTO_FILENAME, ._serial_speed = SERIAL_DEFAULT_BITRATE, diff --git a/nanovna.h b/nanovna.h index 6851b05..d50b145 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1384,7 +1384,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e5C /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e5D /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/plot.c b/plot.c index 99ad700..f0e5ed6 100644 --- a/plot.c +++ b/plot.c @@ -38,6 +38,7 @@ static void update_waterfall(void); #ifdef __LEVEL_METER__ static void update_level_meter(void); char level_text[20]; +char freq_text[20]; #endif void cell_draw_test_info(int x0, int y0); int cell_printf(int16_t x, int16_t y, const char *fmt, ...); @@ -1255,6 +1256,9 @@ draw_all(bool flush) if (isFullScreenMode()) return; #ifdef __LEVEL_METER__ level_text[0] = 0; // Clear level text +#ifdef TINYSA4 + freq_text[0] = 0; // Clear level text +#endif #endif if (redraw_request & REDRAW_AREA) // this set all area for update force_set_markmap(); @@ -1544,6 +1548,11 @@ static void trace_print_value_string( // Only used at one place #endif plot_printf(ptr2, sizeof(buf2) - 9, "%9.*QHz", digits, freq); } +#ifdef __LEVEL_METER__ +#ifdef TINYSA4 + if (freq_text[0] == 0) strcpy(freq_text, &ptr2[3]); +#endif +#endif const char *format; if (UNIT_IS_LINEAR(setting.unit)) format = FONT_s"%s %.3F%s%s%s%s"; // 5 characters incl u, m, etc... @@ -1556,8 +1565,9 @@ static void trace_print_value_string( // Only used at one place #endif cell_printf(xpos, ypos, format, buf2, v, unit_string[unit_index], (mtype & M_DELTA?"c":"") , (mtype & M_NOISE?"/Hz":""), (mtype & M_AVER?"/T":"")); #ifdef __LEVEL_METER__ - if (level_text[0] == 0) + if (level_text[0] == 0){ plot_printf(level_text, sizeof(level_text), &format[3], v, unit_string[unit_index], (mtype & M_DELTA?"c":"") , (mtype & M_NOISE?"/Hz":"") ,(mtype & M_AVER?"/T":"")); + } #endif } @@ -2118,6 +2128,11 @@ static void update_level_meter(void){ int w = ili9341_drawstring_size(level_text, OFFSETX + 3, graph_bottom + 3,BIG_SIZE, x_max); // TODO Size 4 does not transfer to remote desktop?????? if (w < x_max) ili9341_fill(w, graph_bottom+3, x_max - w, BIG_SIZE * wFONT_GET_HEIGHT); +#ifdef TINYSA4 + w = ili9341_drawstring_size(freq_text, OFFSETX + 3, graph_bottom + 3 + BIG_SIZE * wFONT_STR_HEIGHT ,BIG_SIZE, x_max); // TODO Size 4 does not transfer to remote desktop?????? + if (w < x_max) + ili9341_fill(w, graph_bottom+3+ BIG_SIZE * wFONT_STR_HEIGHT, x_max - w, BIG_SIZE * wFONT_GET_HEIGHT); +#endif } void diff --git a/ui.c b/ui.c index cfdb14f..2b21b78 100644 --- a/ui.c +++ b/ui.c @@ -408,6 +408,8 @@ touch_wait_released(void) ; } + +#if 0 void touch_cal_exec(void) { @@ -444,11 +446,58 @@ touch_cal_exec(void) config.flip = old_flip; - config_save(); // Auto save touch calibration //redraw_all(); } +#else + +#define CALIBRATION_OFFSET 16 +#define TOUCH_MARK_W 9 +#define TOUCH_MARK_H 9 +#define TOUCH_MARK_X 4 +#define TOUCH_MARK_Y 4 +static const uint8_t touch_bitmap[]={ + _BMP16(0b0000100000000000), + _BMP16(0b0100100100000000), + _BMP16(0b0010101000000000), + _BMP16(0b0000100000000000), + _BMP16(0b1111011110000000), + _BMP16(0b0000100000000000), + _BMP16(0b0010101000000000), + _BMP16(0b0100100100000000), + _BMP16(0b0000100000000000), +}; + +static void getTouchPoint(uint16_t x, uint16_t y, const char *name, int16_t *data) { + // Clear screen and ask for press + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); + ili9341_clear_screen(); + ili9341_blitBitmap(x, y, TOUCH_MARK_W, TOUCH_MARK_H, touch_bitmap); + lcd_printf((LCD_WIDTH-18*FONT_WIDTH)/2, (LCD_HEIGHT-FONT_GET_HEIGHT)/2, "TOUCH %s *", name); + // Wait release, and fill data + touch_wait_released(); + data[0] = last_touch_x; + data[1] = last_touch_y; +} + +void +touch_cal_exec(void) +{ + const uint16_t x1 = CALIBRATION_OFFSET - TOUCH_MARK_X; + const uint16_t y1 = CALIBRATION_OFFSET - TOUCH_MARK_Y; + const uint16_t x2 = LCD_WIDTH - 1 - CALIBRATION_OFFSET - TOUCH_MARK_X; + const uint16_t y2 = LCD_HEIGHT - 1 - CALIBRATION_OFFSET - TOUCH_MARK_Y; + uint16_t p1 = 0, p2 = 2; + if (config.flip) {p1 = 2, p2 = 0;} + getTouchPoint(x1, y1, "UPPER LEFT", &config.touch_cal[p1]); + getTouchPoint(x2, y2, "LOWER RIGHT", &config.touch_cal[p2]); + config_save(); // Auto save touch calibration +} + + +#endif void touch_draw_test(void) { @@ -458,7 +507,7 @@ touch_draw_test(void) ili9341_set_foreground(LCD_FG_COLOR); ili9341_set_background(LCD_BG_COLOR); ili9341_clear_screen(); - ili9341_drawstring("TOUCH TEST: DRAG PANEL, PRESS BUTTON TO FINISH", OFFSETX, LCD_HEIGHT - FONT_GET_HEIGHT); + ili9341_drawstring("TOUCH PANEL, DRAW LINES, PRESS BUTTON TO FINISH", OFFSETX, LCD_HEIGHT - FONT_GET_HEIGHT); int old_button_state = 0; lcd_set_font(FONT_NORMAL); @@ -496,9 +545,17 @@ touch_position(int *x, int *y) return; } #endif +#if 0 + int tx = (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2]; int ty = (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]; +#else + int tx = ((LCD_WIDTH-1-CALIBRATION_OFFSET)*(last_touch_x - config.touch_cal[0]) + CALIBRATION_OFFSET * (config.touch_cal[2] - last_touch_x)) / (config.touch_cal[2] - config.touch_cal[0]); + if (tx<0) tx = 0; else if (tx>=LCD_WIDTH ) tx = LCD_WIDTH -1; + int ty = ((LCD_HEIGHT-1-CALIBRATION_OFFSET)*(last_touch_y - config.touch_cal[1]) + CALIBRATION_OFFSET * (config.touch_cal[3] - last_touch_y)) / (config.touch_cal[3] - config.touch_cal[1]); + if (ty<0) ty = 0; else if (ty>=LCD_HEIGHT) ty = LCD_HEIGHT-1; +#endif if (config.flip) { tx = LCD_WIDTH - 1 - tx; ty = LCD_HEIGHT - 1 - ty; @@ -707,8 +764,12 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb) case 4: // marker -> ref level { float l = actual_t[markers[active_marker].index]; +#if 1 + user_set_reflevel(l); +#else float s_max = value(l)/setting.scale; user_set_reflevel(setting.scale*(floorf(s_max)+2)); +#endif } break; #ifdef __VNA__