Skip to content

Commit 295ec10

Browse files
committed
set scale and refpos temporally
1 parent 75ea630 commit 295ec10

File tree

6 files changed

+144
-125
lines changed

6 files changed

+144
-125
lines changed

main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static THD_WORKING_AREA(waThread1, 440);
4646
static THD_FUNCTION(Thread1, arg)
4747
{
4848
(void)arg;
49-
chRegSetThreadName("blink");
49+
chRegSetThreadName("sweep");
5050

5151
while (1) {
5252
if (sweep_enabled) {
@@ -1060,7 +1060,9 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
10601060
if (trace[t].enabled) {
10611061
const char *type = trc_type_name[trace[t].type];
10621062
const char *channel = trc_channel_name[trace[t].channel];
1063-
chprintf(chp, "%d %s %s\r\n", t, type, channel);
1063+
float scale = trace[t].scale;
1064+
float refpos = trace[t].refpos;
1065+
chprintf(chp, "%d %s %s %f %f\r\n", t, type, channel, scale, refpos);
10641066
}
10651067
}
10661068
return;

nanovna.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ extern config_t config;
188188
void set_trace_type(int t, int type);
189189
void set_trace_channel(int t, int channel);
190190
void set_trace_scale(int t, float scale);
191+
void set_trace_refpos(int t, float refpos);
191192

192193
// marker
193194

@@ -209,6 +210,7 @@ void redraw_marker(int marker, int update_info);
209210
void trace_get_info(int t, char *buf, int len);
210211
void plot_into_index(float measured[2][101][2]);
211212
void force_set_markmap(void);
213+
void draw_all_cells(void);
212214

213215
void draw_cal_status(void);
214216

plot.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,19 @@ trace_into_index(int x, int t, int i, float coeff[2])
481481
int y = 0;
482482
float v = 0;
483483
float refpos = 8 - trace[t].refpos;
484+
float scale = trace[t].scale;
484485
switch (trace[t].type) {
485486
case TRC_LOGMAG:
486-
v = refpos - logmag(coeff);
487+
v = refpos - logmag(coeff) * scale;
487488
break;
488489
case TRC_PHASE:
489-
v = refpos - phase(coeff);
490+
v = refpos - phase(coeff) * scale;
490491
break;
491492
case TRC_LINEAR:
492-
v = refpos + linear(coeff);
493+
v = refpos + linear(coeff) * scale;
493494
break;
494495
case TRC_SWR:
495-
v = refpos+1 - swr(coeff);
496+
v = refpos+ (1 - swr(coeff)) * scale;
496497
break;
497498
case TRC_SMITH:
498499
//case TRC_ADMIT:

python/NanoVNA-example.ipynb

Lines changed: 91 additions & 102 deletions
Large diffs are not rendered by default.

python/nanovna.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def reflect_coeff_from_rawwave(self, freq = None):
158158
def resume(self):
159159
self.send_command("resume\r")
160160

161+
def pause(self):
162+
self.send_command("pause\r")
163+
161164
def scan(self, port = None):
162165
self.set_port(port)
163166
return np.vectorize(self.gamma)(self.frequencies)
@@ -176,6 +179,15 @@ def data(self, array = 0):
176179
x.append(float(d[0])+float(d[1])*1.j)
177180
return np.array(x)
178181

182+
def fetch_frequencies(self):
183+
self.send_command("frequencies\r")
184+
data = self.fetch_data()
185+
x = []
186+
for line in data.split('\n'):
187+
if line:
188+
x.append(float(line))
189+
self._frequencies = np.array(x)
190+
179191
def logmag(self, x):
180192
pl.grid(True)
181193
pl.plot(self.frequencies, 20*np.log10(np.abs(x)))

ui.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ enum {
6565
};
6666

6767
enum {
68-
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE
68+
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY
6969
};
7070

7171
uint8_t ui_mode = UI_NORMAL;
@@ -89,7 +89,7 @@ int16_t last_touch_y;
8989
#define EVT_TOUCH_RELEASED 3
9090

9191
int awd_count;
92-
int touch_x, touch_y;
92+
//int touch_x, touch_y;
9393

9494
#define NUMINPUT_LEN 10
9595

@@ -184,6 +184,7 @@ static int btn_wait_release(void)
184184
int
185185
touch_measure_y(void)
186186
{
187+
int v;
187188
// open Y line
188189
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_PULLDOWN );
189190
palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_PULLDOWN );
@@ -193,14 +194,17 @@ touch_measure_y(void)
193194
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL );
194195
palSetPad(GPIOA, 6);
195196

196-
chThdSleepMilliseconds(1);
197-
198-
return adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
197+
chThdSleepMilliseconds(2);
198+
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
199+
chThdSleepMilliseconds(2);
200+
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
201+
return v/2;
199202
}
200203

201204
int
202205
touch_measure_x(void)
203206
{
207+
int v;
204208
// open X line
205209
palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_PULLDOWN );
206210
palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLDOWN );
@@ -210,9 +214,11 @@ touch_measure_x(void)
210214
palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL );
211215
palClearPad(GPIOA, 7);
212216

213-
chThdSleepMilliseconds(1);
214-
215-
return adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
217+
chThdSleepMilliseconds(2);
218+
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
219+
chThdSleepMilliseconds(2);
220+
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
221+
return v/2;
216222
}
217223

218224
void
@@ -497,8 +503,7 @@ menu_single_trace_cb(int item)
497503
static void
498504
menu_scale_cb(int item)
499505
{
500-
(void)item;
501-
ui_mode_keypad(KM_SCALE);
506+
ui_mode_keypad(KM_SCALE + item);
502507
ui_process_keypad();
503508
}
504509

@@ -514,7 +519,7 @@ menu_stimulus_cb(int item)
514519
ui_mode_keypad(item);
515520
ui_process_keypad();
516521
break;
517-
case 5:
522+
case 5: /* TOGGLE SWEEP */
518523
toggle_sweep();
519524
menu_move_back();
520525
ui_mode_normal();
@@ -852,7 +857,7 @@ draw_keypad(void)
852857
}
853858

854859
const char *keypad_mode_label[] = {
855-
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE"
860+
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY"
856861
};
857862

858863
void
@@ -958,8 +963,8 @@ menu_apply_touch(void)
958963
if (menu[i].type == MT_BLANK)
959964
continue;
960965
int y = 32*i;
961-
if (y < touch_y && touch_y < y+30
962-
&& 320-60 < touch_x && touch_x < 320) {
966+
if (y-2 < touch_y && touch_y < y+30+2
967+
&& 320-60 < touch_x) {
963968
menu_select_touch(i);
964969
return;
965970
}
@@ -1107,6 +1112,12 @@ keypad_click(int selection)
11071112
case KM_SCALE:
11081113
set_trace_scale(uistat.current_trace, value);
11091114
break;
1115+
case KM_REFPOS:
1116+
set_trace_refpos(uistat.current_trace, value);
1117+
break;
1118+
case KM_EDELAY:
1119+
//set_trace_edelay(uistat.current_trace, value);
1120+
break;
11101121
}
11111122

11121123
return KP_DONE;
@@ -1140,8 +1151,8 @@ keypad_apply_touch(void)
11401151
touch_position(&touch_x, &touch_y);
11411152

11421153
while (keypads[i].x) {
1143-
if (keypads[i].x < touch_x && touch_x < keypads[i].x+44
1144-
&& keypads[i].y < touch_y && touch_y < keypads[i].y+44) {
1154+
if (keypads[i].x-2 < touch_x && touch_x < keypads[i].x+44+2
1155+
&& keypads[i].y-2 < touch_y && touch_y < keypads[i].y+44+2) {
11451156
selection = i;
11461157
draw_keypad();
11471158
touch_wait_release();
@@ -1222,7 +1233,7 @@ void drag_marker(int t, int m)
12221233
int touch_x, touch_y;
12231234
int index;
12241235
touch_position(&touch_x, &touch_y);
1225-
index = search_nearest_index(touch_x, touch_y, t);
1236+
index = search_nearest_index(touch_x + OFFSETX, touch_y + OFFSETY, t);
12261237
if (index >= 0) {
12271238
markers[m].index = index;
12281239
redraw_marker(m, TRUE);
@@ -1244,6 +1255,8 @@ touch_pickup_marker(void)
12441255
int touch_x, touch_y;
12451256
int m, t;
12461257
touch_position(&touch_x, &touch_y);
1258+
touch_x += OFFSETX;
1259+
touch_y += OFFSETY;
12471260

12481261
for (m = 0; m < 4; m++) {
12491262
if (!markers[m].enabled)

0 commit comments

Comments
 (0)