diff --git a/.cproject b/.cproject
index fb00609..f734b95 100644
--- a/.cproject
+++ b/.cproject
@@ -66,7 +66,7 @@
-
+
diff --git a/main.c b/main.c
index be7a870..996207f 100644
--- a/main.c
+++ b/main.c
@@ -1008,6 +1008,7 @@ config_t config = {
.high_out_adf4350 = true,
#endif
.sweep_voltage = 3.3,
+ .switch_offset = 0.0,
};
//properties_t current_props;
diff --git a/nanovna.h b/nanovna.h
index 4c1241b..690609a 100644
--- a/nanovna.h
+++ b/nanovna.h
@@ -623,6 +623,7 @@ typedef struct config {
int8_t cor_nfm;
uint8_t high_out_adf4350;
float sweep_voltage;
+ float switch_offset;
uint32_t dummy;
// uint8_t _reserved[22];
freq_t checksum;
diff --git a/plot.c b/plot.c
index 6064a45..8b6e12e 100644
--- a/plot.c
+++ b/plot.c
@@ -1697,6 +1697,7 @@ redraw_marker(int marker)
redraw_request|=REDRAW_AREA;
}
+#if 0 // Not used
void
request_to_draw_cells_behind_menu(void)
{
@@ -1715,6 +1716,7 @@ request_to_draw_cells_behind_numeric_input(void)
invalidate_rect(0, LCD_HEIGHT-NUM_INPUT_HEIGHT, LCD_WIDTH-1, LCD_HEIGHT-1);
redraw_request |= REDRAW_CELLS;
}
+#endif
static void
cell_blit_bitmap(int x, int y, uint16_t w, uint16_t h, const uint8_t *bmp)
diff --git a/sa_cmd.c b/sa_cmd.c
index e8d511c..efd9a65 100644
--- a/sa_cmd.c
+++ b/sa_cmd.c
@@ -250,10 +250,12 @@ VNA_SHELL_FUNCTION(cmd_levelchange)
VNA_SHELL_FUNCTION(cmd_leveloffset)
{
if (argc == 0) {
- shell_printf("leveloffset low %.1f\r\n", config.low_level_offset);
- shell_printf("leveloffset high %.1f\r\n", config.high_level_offset);
- shell_printf("leveloffset low output %.1f\r\n", config.low_level_output_offset);
- shell_printf("leveloffset high output %.1f\r\n", config.high_level_output_offset);
+ const char *p = "leveloffset %s %.1f\r\n";
+ shell_printf(p, "low", config.low_level_offset);
+ shell_printf(p, "high", config.high_level_offset);
+ shell_printf(p, "low output", config.low_level_output_offset);
+ shell_printf(p, "high output", config.high_level_output_offset);
+ shell_printf(p, "switch", config.switch_offset);
return;
} else if (argc == 2) {
float v = my_atof(argv[1]);
@@ -261,6 +263,8 @@ VNA_SHELL_FUNCTION(cmd_leveloffset)
config.low_level_offset = v;
else if (strcmp(argv[0],"high") == 0)
config.high_level_offset = v;
+ else if (strcmp(argv[0],"switch") == 0)
+ config.switch_offset = v;
else
goto usage;
dirty = true;
@@ -275,7 +279,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset)
dirty = true;
} else {
usage:
- shell_printf("leveloffset [low|high] {output} []\r\n");
+ shell_printf("leveloffset [low|high|switch] {output} [-20..+20]\r\n");
}
}
diff --git a/sa_core.c b/sa_core.c
index 62d439c..fd9a1eb 100644
--- a/sa_core.c
+++ b/sa_core.c
@@ -82,7 +82,7 @@ const int8_t drive_dBm [16] = {-38, -32, -30, -27, -24, -19, -15, -12, -5, -2, 0
#endif
#ifdef TINYSA4
-#define SWITCH_ATTENUATION (setting.mode == M_GENHIGH && config.high_out_adf4350 ? 0 : 37)
+#define SWITCH_ATTENUATION (setting.mode == M_GENHIGH && config.high_out_adf4350 ? 0 : 37 - config.switch_offset)
//#define POWER_OFFSET -18 // Max level with all enabled
//#define POWER_RANGE 70
#define MAX_DRIVE (setting.mode == M_GENHIGH && config.high_out_adf4350 ? 3 : 18)
@@ -99,7 +99,7 @@ const int8_t drive_dBm [16] = {-38, -32, -30, -27, -24, -19, -15, -12, -5, -2, 0
#else
-#define SWITCH_ATTENUATION 30
+#define SWITCH_ATTENUATION (30 - config.switch_offset)
#define POWER_OFFSET 15
#define MAX_DRIVE (setting.mode == M_GENHIGH ? 15 : 11)
#define MIN_DRIVE 8
@@ -4516,35 +4516,39 @@ void calibrate(void)
in_selftest = true;
reset_calibration();
reset_settings(M_LOW);
- for (int j= 0; j < CALIBRATE_RBWS; j++ ) {
-// set_RBW(power_rbw[j]);
-// set_sweep_points(21);
- test_prepare(TEST_POWER);
- setting.step_delay_mode = SD_PRECISE;
+ for (int k = 0; k<2; k++) {
+ for (int j= 0; j < CALIBRATE_RBWS; j++ ) {
+ // set_RBW(power_rbw[j]);
+ // set_sweep_points(21);
+ test_prepare(TEST_POWER);
+ setting.step_delay_mode = SD_PRECISE;
#ifndef TINYSA4
- setting.agc = S_OFF;
- setting.lna = S_OFF;
-#endif
- test_acquire(TEST_POWER); // Acquire test
- local_test_status = test_validate(TEST_POWER); // Validate test
- if (peakLevel < -50) {
- ili9341_set_foreground(LCD_BRIGHT_COLOR_RED);
- ili9341_drawstring_7x13("Signal level too low", 30, 140);
- ili9341_drawstring_7x13("Check cable between High and Low connectors", 30, 160);
- goto quit;
- }
-// chThdSleepMilliseconds(1000);
- if (local_test_status != TS_PASS) {
- ili9341_set_foreground(LCD_BRIGHT_COLOR_RED);
- ili9341_drawstring_7x13("Calibration failed", 30, 140);
- goto quit;
- } else {
+ setting.agc = S_OFF;
+ setting.lna = S_OFF;
+#endif
+ test_acquire(TEST_POWER); // Acquire test
+ local_test_status = test_validate(TEST_POWER); // Validate test
+ if (k ==0 || k == 1) {
+ if (peakLevel < -50) {
+ ili9341_set_foreground(LCD_BRIGHT_COLOR_RED);
+ ili9341_drawstring_7x13("Signal level too low", 30, 140);
+ ili9341_drawstring_7x13("Check cable between High and Low connectors", 30, 160);
+ goto quit;
+ }
+ // chThdSleepMilliseconds(1000);
+ if (local_test_status != TS_PASS) {
+ ili9341_set_foreground(LCD_BRIGHT_COLOR_RED);
+ ili9341_drawstring_7x13("Calibration failed", 30, 140);
+ goto quit;
+ } else {
#ifdef TINYSA4
- set_actual_power(-30.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3)
+ set_actual_power(-30.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3)
#else
- set_actual_power(-25.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3)
+ set_actual_power(-25.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3)
#endif
- chThdSleepMilliseconds(1000);
+ chThdSleepMilliseconds(1000);
+ }
+ }
}
}
#if 0 // No high input calibration as CAL OUTPUT is unreliable
diff --git a/ui.c b/ui.c
index 5b03b4f..9c027ac 100644
--- a/ui.c
+++ b/ui.c
@@ -26,7 +26,7 @@
#include
#pragma GCC push_options
-#pragma GCC optimize ("Os")
+#pragma GCC optimize ("Og")
uistat_t uistat = {
digit: 6,
@@ -1318,7 +1318,6 @@ menu_move_back(void)
if (current_menu_is_form()) {
redraw_frame();
- redraw_request |= REDRAW_BATTERY;
area_width = 0;
} else {
// redraw_frame();
@@ -1351,7 +1350,6 @@ menu_push_submenu(const menuitem_t *submenu)
ensure_selection();
if (menu_is_form(submenu)) {
redraw_frame();
- redraw_request |= REDRAW_BATTERY;
area_width = 0;
} else {
// redraw_frame();
@@ -1973,6 +1971,8 @@ draw_menu_buttons(const menuitem_t *menu)
ili9341_set_background(LCD_BG_COLOR);
for (; y < MENU_BUTTON_MAX*MENU_BUTTON_HEIGHT; y+=MENU_BUTTON_HEIGHT)
ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT);
+// if (menu[i].type & MT_FORM)
+// draw_battery_status();
}
static systime_t prev_touch_time = 0;
@@ -2028,7 +2028,7 @@ menu_select_touch(int i, int pos)
if (touch_x != prev_touch_x /* - 1 || prev_touch_x + 1 < touch_x */ ) {
keypad_mode = keypad;
fetch_numeric_target();
- int new_slider = touch_x - LCD_WIDTH/2;
+ volatile int new_slider = (int)touch_x - LCD_WIDTH/2; // Can have negative outcome
if (new_slider < - (MENU_FORM_WIDTH-8)/2)
new_slider = -(MENU_FORM_WIDTH-8)/2;
if (new_slider > (MENU_FORM_WIDTH-8)/2)
@@ -2044,7 +2044,9 @@ menu_select_touch(int i, int pos)
}
}
if (mode == SL_MOVE ) {
- uistat.value = uistat.value - setting.slider_position * (setting.slider_span/(MENU_FORM_WIDTH-8)) + new_slider * (setting.slider_span/(MENU_FORM_WIDTH-8));
+ uistat.value = uistat.value - setting.slider_position * ((int)setting.slider_span/(MENU_FORM_WIDTH-8)) + new_slider * ((int)setting.slider_span/(MENU_FORM_WIDTH-8));
+ if (uistat.value < 0)
+ uistat.value = 0;
if (uistat.value < minFreq)
uistat.value = minFreq;
if (uistat.value > maxFreq)
@@ -2123,6 +2125,7 @@ menu_select_touch(int i, int pos)
if (dt > BUTTON_DOWN_LONG_TICKS || do_exit) {
selection = -1;
draw_menu();
+ redraw_request = 0; // Remove request to redraw grid
return;
}
if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_LOWOUTLEVEL) {
@@ -2148,10 +2151,10 @@ menu_select_touch(int i, int pos)
} else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_CENTER) {
switch (pos) {
case 0:
- step = -setting.slider_span;
+ step = -(int)setting.slider_span;
break;
case 1:
- step = -setting.slider_span/10;
+ step = -(int)setting.slider_span/10;
break;
case 2:
goto nogo;
@@ -2758,6 +2761,8 @@ ui_process_keypad(void)
ui_mode_menu(); //Reactivate menu after keypad
selection = -1;
ensure_selection();
+ // redraw_request = 0; // Clear all draw requests
+ redraw_request = REDRAW_BATTERY; // Only redraw battery
} else {
ui_mode_normal();
// request_to_redraw_grid();
diff --git a/ui_sa.c b/ui_sa.c
index f8af129..a06a999 100644
--- a/ui_sa.c
+++ b/ui_sa.c
@@ -428,6 +428,7 @@ enum {
#ifdef TINYSA4
KM_LPF,
#endif
+ // #35
KM_NONE // always at enum end
};
@@ -472,7 +473,7 @@ static const struct {
#endif
{keypads_positive , "ATTACK"}, // KM_ATTACK
#ifdef TINYSA4
- {keypads_freq , "ULTRA\nSTART"}, // KM_LPF #34
+ {keypads_freq , "ULTRA\nSTART"}, // KM_LPF
#endif
};
#if 0 // Not used