mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
set scale and refpos temporally
This commit is contained in:
parent
75ea6308ed
commit
295ec105e6
6
main.c
6
main.c
|
|
@ -46,7 +46,7 @@ static THD_WORKING_AREA(waThread1, 440);
|
||||||
static THD_FUNCTION(Thread1, arg)
|
static THD_FUNCTION(Thread1, arg)
|
||||||
{
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
chRegSetThreadName("blink");
|
chRegSetThreadName("sweep");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (sweep_enabled) {
|
if (sweep_enabled) {
|
||||||
|
|
@ -1060,7 +1060,9 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
if (trace[t].enabled) {
|
if (trace[t].enabled) {
|
||||||
const char *type = trc_type_name[trace[t].type];
|
const char *type = trc_type_name[trace[t].type];
|
||||||
const char *channel = trc_channel_name[trace[t].channel];
|
const char *channel = trc_channel_name[trace[t].channel];
|
||||||
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
float scale = trace[t].scale;
|
||||||
|
float refpos = trace[t].refpos;
|
||||||
|
chprintf(chp, "%d %s %s %f %f\r\n", t, type, channel, scale, refpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,7 @@ extern config_t config;
|
||||||
void set_trace_type(int t, int type);
|
void set_trace_type(int t, int type);
|
||||||
void set_trace_channel(int t, int channel);
|
void set_trace_channel(int t, int channel);
|
||||||
void set_trace_scale(int t, float scale);
|
void set_trace_scale(int t, float scale);
|
||||||
|
void set_trace_refpos(int t, float refpos);
|
||||||
|
|
||||||
// marker
|
// marker
|
||||||
|
|
||||||
|
|
@ -209,6 +210,7 @@ void redraw_marker(int marker, int update_info);
|
||||||
void trace_get_info(int t, char *buf, int len);
|
void trace_get_info(int t, char *buf, int len);
|
||||||
void plot_into_index(float measured[2][101][2]);
|
void plot_into_index(float measured[2][101][2]);
|
||||||
void force_set_markmap(void);
|
void force_set_markmap(void);
|
||||||
|
void draw_all_cells(void);
|
||||||
|
|
||||||
void draw_cal_status(void);
|
void draw_cal_status(void);
|
||||||
|
|
||||||
|
|
|
||||||
9
plot.c
9
plot.c
|
|
@ -481,18 +481,19 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
||||||
int y = 0;
|
int y = 0;
|
||||||
float v = 0;
|
float v = 0;
|
||||||
float refpos = 8 - trace[t].refpos;
|
float refpos = 8 - trace[t].refpos;
|
||||||
|
float scale = trace[t].scale;
|
||||||
switch (trace[t].type) {
|
switch (trace[t].type) {
|
||||||
case TRC_LOGMAG:
|
case TRC_LOGMAG:
|
||||||
v = refpos - logmag(coeff);
|
v = refpos - logmag(coeff) * scale;
|
||||||
break;
|
break;
|
||||||
case TRC_PHASE:
|
case TRC_PHASE:
|
||||||
v = refpos - phase(coeff);
|
v = refpos - phase(coeff) * scale;
|
||||||
break;
|
break;
|
||||||
case TRC_LINEAR:
|
case TRC_LINEAR:
|
||||||
v = refpos + linear(coeff);
|
v = refpos + linear(coeff) * scale;
|
||||||
break;
|
break;
|
||||||
case TRC_SWR:
|
case TRC_SWR:
|
||||||
v = refpos+1 - swr(coeff);
|
v = refpos+ (1 - swr(coeff)) * scale;
|
||||||
break;
|
break;
|
||||||
case TRC_SMITH:
|
case TRC_SMITH:
|
||||||
//case TRC_ADMIT:
|
//case TRC_ADMIT:
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -158,6 +158,9 @@ class NanoVNA():
|
||||||
def resume(self):
|
def resume(self):
|
||||||
self.send_command("resume\r")
|
self.send_command("resume\r")
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
self.send_command("pause\r")
|
||||||
|
|
||||||
def scan(self, port = None):
|
def scan(self, port = None):
|
||||||
self.set_port(port)
|
self.set_port(port)
|
||||||
return np.vectorize(self.gamma)(self.frequencies)
|
return np.vectorize(self.gamma)(self.frequencies)
|
||||||
|
|
@ -176,6 +179,15 @@ class NanoVNA():
|
||||||
x.append(float(d[0])+float(d[1])*1.j)
|
x.append(float(d[0])+float(d[1])*1.j)
|
||||||
return np.array(x)
|
return np.array(x)
|
||||||
|
|
||||||
|
def fetch_frequencies(self):
|
||||||
|
self.send_command("frequencies\r")
|
||||||
|
data = self.fetch_data()
|
||||||
|
x = []
|
||||||
|
for line in data.split('\n'):
|
||||||
|
if line:
|
||||||
|
x.append(float(line))
|
||||||
|
self._frequencies = np.array(x)
|
||||||
|
|
||||||
def logmag(self, x):
|
def logmag(self, x):
|
||||||
pl.grid(True)
|
pl.grid(True)
|
||||||
pl.plot(self.frequencies, 20*np.log10(np.abs(x)))
|
pl.plot(self.frequencies, 20*np.log10(np.abs(x)))
|
||||||
|
|
|
||||||
47
ui.c
47
ui.c
|
|
@ -65,7 +65,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE
|
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t ui_mode = UI_NORMAL;
|
uint8_t ui_mode = UI_NORMAL;
|
||||||
|
|
@ -89,7 +89,7 @@ int16_t last_touch_y;
|
||||||
#define EVT_TOUCH_RELEASED 3
|
#define EVT_TOUCH_RELEASED 3
|
||||||
|
|
||||||
int awd_count;
|
int awd_count;
|
||||||
int touch_x, touch_y;
|
//int touch_x, touch_y;
|
||||||
|
|
||||||
#define NUMINPUT_LEN 10
|
#define NUMINPUT_LEN 10
|
||||||
|
|
||||||
|
|
@ -184,6 +184,7 @@ static int btn_wait_release(void)
|
||||||
int
|
int
|
||||||
touch_measure_y(void)
|
touch_measure_y(void)
|
||||||
{
|
{
|
||||||
|
int v;
|
||||||
// open Y line
|
// open Y line
|
||||||
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_PULLDOWN );
|
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_PULLDOWN );
|
||||||
palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_PULLDOWN );
|
palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_PULLDOWN );
|
||||||
|
|
@ -193,14 +194,17 @@ touch_measure_y(void)
|
||||||
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL );
|
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL );
|
||||||
palSetPad(GPIOA, 6);
|
palSetPad(GPIOA, 6);
|
||||||
|
|
||||||
chThdSleepMilliseconds(1);
|
chThdSleepMilliseconds(2);
|
||||||
|
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
|
||||||
return adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
|
chThdSleepMilliseconds(2);
|
||||||
|
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
|
||||||
|
return v/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
touch_measure_x(void)
|
touch_measure_x(void)
|
||||||
{
|
{
|
||||||
|
int v;
|
||||||
// open X line
|
// open X line
|
||||||
palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_PULLDOWN );
|
palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_PULLDOWN );
|
||||||
palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLDOWN );
|
palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLDOWN );
|
||||||
|
|
@ -210,9 +214,11 @@ touch_measure_x(void)
|
||||||
palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL );
|
palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL );
|
||||||
palClearPad(GPIOA, 7);
|
palClearPad(GPIOA, 7);
|
||||||
|
|
||||||
chThdSleepMilliseconds(1);
|
chThdSleepMilliseconds(2);
|
||||||
|
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
|
||||||
return adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
|
chThdSleepMilliseconds(2);
|
||||||
|
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
|
||||||
|
return v/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -497,8 +503,7 @@ menu_single_trace_cb(int item)
|
||||||
static void
|
static void
|
||||||
menu_scale_cb(int item)
|
menu_scale_cb(int item)
|
||||||
{
|
{
|
||||||
(void)item;
|
ui_mode_keypad(KM_SCALE + item);
|
||||||
ui_mode_keypad(KM_SCALE);
|
|
||||||
ui_process_keypad();
|
ui_process_keypad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -514,7 +519,7 @@ menu_stimulus_cb(int item)
|
||||||
ui_mode_keypad(item);
|
ui_mode_keypad(item);
|
||||||
ui_process_keypad();
|
ui_process_keypad();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5: /* TOGGLE SWEEP */
|
||||||
toggle_sweep();
|
toggle_sweep();
|
||||||
menu_move_back();
|
menu_move_back();
|
||||||
ui_mode_normal();
|
ui_mode_normal();
|
||||||
|
|
@ -852,7 +857,7 @@ draw_keypad(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *keypad_mode_label[] = {
|
const char *keypad_mode_label[] = {
|
||||||
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE"
|
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY"
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -958,8 +963,8 @@ menu_apply_touch(void)
|
||||||
if (menu[i].type == MT_BLANK)
|
if (menu[i].type == MT_BLANK)
|
||||||
continue;
|
continue;
|
||||||
int y = 32*i;
|
int y = 32*i;
|
||||||
if (y < touch_y && touch_y < y+30
|
if (y-2 < touch_y && touch_y < y+30+2
|
||||||
&& 320-60 < touch_x && touch_x < 320) {
|
&& 320-60 < touch_x) {
|
||||||
menu_select_touch(i);
|
menu_select_touch(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1107,6 +1112,12 @@ keypad_click(int selection)
|
||||||
case KM_SCALE:
|
case KM_SCALE:
|
||||||
set_trace_scale(uistat.current_trace, value);
|
set_trace_scale(uistat.current_trace, value);
|
||||||
break;
|
break;
|
||||||
|
case KM_REFPOS:
|
||||||
|
set_trace_refpos(uistat.current_trace, value);
|
||||||
|
break;
|
||||||
|
case KM_EDELAY:
|
||||||
|
//set_trace_edelay(uistat.current_trace, value);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return KP_DONE;
|
return KP_DONE;
|
||||||
|
|
@ -1140,8 +1151,8 @@ keypad_apply_touch(void)
|
||||||
touch_position(&touch_x, &touch_y);
|
touch_position(&touch_x, &touch_y);
|
||||||
|
|
||||||
while (keypads[i].x) {
|
while (keypads[i].x) {
|
||||||
if (keypads[i].x < touch_x && touch_x < keypads[i].x+44
|
if (keypads[i].x-2 < touch_x && touch_x < keypads[i].x+44+2
|
||||||
&& keypads[i].y < touch_y && touch_y < keypads[i].y+44) {
|
&& keypads[i].y-2 < touch_y && touch_y < keypads[i].y+44+2) {
|
||||||
selection = i;
|
selection = i;
|
||||||
draw_keypad();
|
draw_keypad();
|
||||||
touch_wait_release();
|
touch_wait_release();
|
||||||
|
|
@ -1222,7 +1233,7 @@ void drag_marker(int t, int m)
|
||||||
int touch_x, touch_y;
|
int touch_x, touch_y;
|
||||||
int index;
|
int index;
|
||||||
touch_position(&touch_x, &touch_y);
|
touch_position(&touch_x, &touch_y);
|
||||||
index = search_nearest_index(touch_x, touch_y, t);
|
index = search_nearest_index(touch_x + OFFSETX, touch_y + OFFSETY, t);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
markers[m].index = index;
|
markers[m].index = index;
|
||||||
redraw_marker(m, TRUE);
|
redraw_marker(m, TRUE);
|
||||||
|
|
@ -1244,6 +1255,8 @@ touch_pickup_marker(void)
|
||||||
int touch_x, touch_y;
|
int touch_x, touch_y;
|
||||||
int m, t;
|
int m, t;
|
||||||
touch_position(&touch_x, &touch_y);
|
touch_position(&touch_x, &touch_y);
|
||||||
|
touch_x += OFFSETX;
|
||||||
|
touch_y += OFFSETY;
|
||||||
|
|
||||||
for (m = 0; m < 4; m++) {
|
for (m = 0; m < 4; m++) {
|
||||||
if (!markers[m].enabled)
|
if (!markers[m].enabled)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue