Fix velocity factor on numeric value input multiple

Remove comments
Little code optimisation
This commit is contained in:
DiSlord 2020-01-26 20:56:45 +03:00
parent d3f4ef5dc1
commit b10e29c01f
2 changed files with 25 additions and 43 deletions

35
plot.c
View file

@ -12,9 +12,6 @@ void frequency_string(char *buf, size_t len, uint32_t freq, char *prefix);
void frequency_string_short(char *buf, size_t len, int32_t freq, char prefix); void frequency_string_short(char *buf, size_t len, int32_t freq, char prefix);
void markmap_all_markers(void); void markmap_all_markers(void);
//#define GRID_COLOR 0x0863
//uint16_t grid_color = 0x1084;
/* indicate dirty cells */ /* indicate dirty cells */
uint16_t markmap[2][8]; uint16_t markmap[2][8];
uint16_t current_mappage = 0; uint16_t current_mappage = 0;
@ -294,16 +291,16 @@ smith_grid2(int x, int y, float scale)
#endif #endif
const int cirs[][4] = { const int cirs[][4] = {
{ 0, 58/2, 58/2, 0 }, // Constant Reactance Circle: 2j : R/2 = 58 { 0, 58/2, 58/2, 0 }, // Constant Reactance Circle: 2j : R/2 = 58
{ 29/2, 0, 29/2, 1 }, // Constant Resistance Circle: 3 : R/4 = 29 { 29/2, 0, 29/2, 1 }, // Constant Resistance Circle: 3 : R/4 = 29
{ 0, 115/2, 115/2, 0 }, // Constant Reactance Circle: 1j : R = 115 { 0, 115/2, 115/2, 0 }, // Constant Reactance Circle: 1j : R = 115
{ 58/2, 0, 58/2, 1 }, // Constant Resistance Circle: 1 : R/2 = 58 { 58/2, 0, 58/2, 1 }, // Constant Resistance Circle: 1 : R/2 = 58
{ 0, 230/2, 230/2, 0 }, // Constant Reactance Circle: 1/2j : R*2 = 230 { 0, 230/2, 230/2, 0 }, // Constant Reactance Circle: 1/2j : R*2 = 230
{ 86/2, 0, 86/2, 1 }, // Constant Resistance Circle: 1/3 : R*3/4 = 86 { 86/2, 0, 86/2, 1 }, // Constant Resistance Circle: 1/3 : R*3/4 = 86
{ 0, 460/2, 460/2, 0 }, // Constant Reactance Circle: 1/4j : R*4 = 460 { 0, 460/2, 460/2, 0 }, // Constant Reactance Circle: 1/4j : R*4 = 460
{ 115/2, 0, 115/2, 1 }, // Constant Resistance Circle: 0 : R { 115/2, 0, 115/2, 1 }, // Constant Resistance Circle: 0 : R
{ 173/2, 0, 173/2, 1 }, // Constant Resistance Circle: -1/3 : R*3/2 = 173 { 173/2, 0, 173/2, 1 }, // Constant Resistance Circle: -1/3 : R*3/2 = 173
{ 0, 0, 0, 0 } // sentinel { 0, 0, 0, 0 } // sentinel
}; };
int int
@ -500,18 +497,6 @@ cartesian_scale(float re, float im, int *xp, int *yp, float scale)
float float
groupdelay_from_array(int i, float array[POINTS_COUNT][2]) groupdelay_from_array(int i, float array[POINTS_COUNT][2])
{ {
/*
if (i == 0) {
float deltaf = frequencies[1] - frequencies[0];
return groupdelay(array[0], array[1], deltaf);
} else if (i == 100) {
float deltaf = frequencies[i] - frequencies[i-1];
return groupdelay(array[i-1], array[i], deltaf);
} else {
float deltaf = frequencies[i+1] - frequencies[i-1];
return groupdelay(array[i-1], array[i+1], deltaf);
}
*/
int bottom = (i == 0) ? 0 : i - 1; int bottom = (i == 0) ? 0 : i - 1;
int top = (i == POINTS_COUNT-1) ? POINTS_COUNT-1 : i + 1; int top = (i == POINTS_COUNT-1) ? POINTS_COUNT-1 : i + 1;
float deltaf = frequencies[top] - frequencies[bottom]; float deltaf = frequencies[top] - frequencies[bottom];

33
ui.c
View file

@ -33,7 +33,6 @@ uistat_t uistat = {
marker_delta: FALSE, marker_delta: FALSE,
}; };
#define NO_EVENT 0 #define NO_EVENT 0
#define EVT_BUTTON_SINGLE_CLICK 0x01 #define EVT_BUTTON_SINGLE_CLICK 0x01
#define EVT_BUTTON_DOUBLE_CLICK 0x02 #define EVT_BUTTON_DOUBLE_CLICK 0x02
@ -72,9 +71,9 @@ enum {
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY
}; };
uint8_t ui_mode = UI_NORMAL; static uint8_t ui_mode = UI_NORMAL;
uint8_t keypad_mode; static uint8_t keypad_mode;
int8_t selection = 0; static int8_t selection = 0;
// Set structure align as WORD (save flash memory) // Set structure align as WORD (save flash memory)
#pragma pack(push, 2) #pragma pack(push, 2)
@ -86,9 +85,11 @@ typedef struct {
} menuitem_t; } menuitem_t;
#pragma pack(pop) #pragma pack(pop)
int8_t last_touch_status = FALSE; // Touch screen
int16_t last_touch_x; static int8_t last_touch_status = FALSE;
int16_t last_touch_y; static int16_t last_touch_x;
static int16_t last_touch_y;
//int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 }; //int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 };
//int16_t touch_cal[4] = { 620, 600, 130, 180 }; //int16_t touch_cal[4] = { 620, 600, 130, 180 };
#define EVT_TOUCH_NONE 0 #define EVT_TOUCH_NONE 0
@ -108,7 +109,6 @@ int awd_count;
char kp_buf[11]; char kp_buf[11];
int8_t kp_index = 0; int8_t kp_index = 0;
void ui_mode_normal(void); void ui_mode_normal(void);
void ui_mode_menu(void); void ui_mode_menu(void);
void ui_mode_numeric(int _keypad_mode); void ui_mode_numeric(int _keypad_mode);
@ -439,7 +439,6 @@ enter_dfu(void)
NVIC_SystemReset(); NVIC_SystemReset();
} }
// type of menu item // type of menu item
enum { enum {
MT_NONE, MT_NONE,
@ -574,6 +573,7 @@ choose_active_trace(void)
static void static void
menu_trace_cb(int item, uint8_t data) menu_trace_cb(int item, uint8_t data)
{ {
(void)item;
if (trace[data].enabled) { if (trace[data].enabled) {
if (data == uistat.current_trace) { if (data == uistat.current_trace) {
// disable if active trace is selected // disable if active trace is selected
@ -581,11 +581,11 @@ menu_trace_cb(int item, uint8_t data)
choose_active_trace(); choose_active_trace();
} else { } else {
// make active selected trace // make active selected trace
uistat.current_trace = item; uistat.current_trace = data;
} }
} else { } else {
trace[data].enabled = TRUE; trace[data].enabled = TRUE;
uistat.current_trace = item; uistat.current_trace = data;
} }
request_to_redraw_grid(); request_to_redraw_grid();
draw_menu(); draw_menu();
@ -740,7 +740,7 @@ menu_marker_op_cb(int item, uint8_t data)
if (previous_marker == -1 || active_marker == previous_marker) { if (previous_marker == -1 || active_marker == previous_marker) {
// if only 1 marker is active, keep center freq and make span the marker comes to the edge // if only 1 marker is active, keep center freq and make span the marker comes to the edge
uint32_t center = get_sweep_frequency(ST_CENTER); uint32_t center = get_sweep_frequency(ST_CENTER);
uint32_t span = center > freq ? center - freq : freq - center; uint32_t span = get_sweep_frequency(ST_SPAN);
set_sweep_frequency(ST_SPAN, span * 2); set_sweep_frequency(ST_SPAN, span * 2);
} else { } else {
// if 2 or more marker active, set start and stop freq to each marker // if 2 or more marker active, set start and stop freq to each marker
@ -1480,8 +1480,7 @@ erase_menu_buttons(void)
void void
erase_numeric_input(void) erase_numeric_input(void)
{ {
uint16_t bg = 0; ili9341_fill(0, 240-32, 320, 32, DEFAULT_BG_COLOR);
ili9341_fill(0, 240-32, 320, 32, bg);
} }
void void
@ -1571,7 +1570,7 @@ void set_numeric_value(void)
set_electrical_delay(uistat.value); set_electrical_delay(uistat.value);
break; break;
case KM_VELOCITY_FACTOR: case KM_VELOCITY_FACTOR:
velocity_factor = uistat.value; velocity_factor = uistat.value/100.0;
break; break;
} }
} }
@ -1584,7 +1583,6 @@ draw_numeric_area(void)
draw_numeric_input(buf); draw_numeric_input(buf);
} }
void void
ui_mode_menu(void) ui_mode_menu(void)
{ {
@ -1718,12 +1716,11 @@ lever_zoom_span(int status)
uint32_t span = get_sweep_frequency(ST_SPAN); uint32_t span = get_sweep_frequency(ST_SPAN);
if (status & EVT_UP) { if (status & EVT_UP) {
span = step_round(span - 1); span = step_round(span - 1);
set_sweep_frequency(ST_SPAN, span);
} else if (status & EVT_DOWN) { } else if (status & EVT_DOWN) {
span = step_round(span + 1); span = step_round(span + 1);
span = step_round(span * 3); span = step_round(span * 3);
set_sweep_frequency(ST_SPAN, span);
} }
set_sweep_frequency(ST_SPAN, span);
} }
static void static void