Skip to content

Commit

Permalink
set scale and refpos temporally
Browse files Browse the repository at this point in the history
  • Loading branch information
edy555 committed Jan 17, 2017
1 parent 75ea630 commit 295ec10
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 125 deletions.
6 changes: 4 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static THD_WORKING_AREA(waThread1, 440);
static THD_FUNCTION(Thread1, arg)
{
(void)arg;
chRegSetThreadName("blink");
chRegSetThreadName("sweep");

while (1) {
if (sweep_enabled) {
Expand Down Expand Up @@ -1060,7 +1060,9 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
if (trace[t].enabled) {
const char *type = trc_type_name[trace[t].type];
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;
Expand Down
2 changes: 2 additions & 0 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ extern config_t config;
void set_trace_type(int t, int type);
void set_trace_channel(int t, int channel);
void set_trace_scale(int t, float scale);
void set_trace_refpos(int t, float refpos);

// marker

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

void draw_cal_status(void);

Expand Down
9 changes: 5 additions & 4 deletions plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,19 @@ trace_into_index(int x, int t, int i, float coeff[2])
int y = 0;
float v = 0;
float refpos = 8 - trace[t].refpos;
float scale = trace[t].scale;
switch (trace[t].type) {
case TRC_LOGMAG:
v = refpos - logmag(coeff);
v = refpos - logmag(coeff) * scale;
break;
case TRC_PHASE:
v = refpos - phase(coeff);
v = refpos - phase(coeff) * scale;
break;
case TRC_LINEAR:
v = refpos + linear(coeff);
v = refpos + linear(coeff) * scale;
break;
case TRC_SWR:
v = refpos+1 - swr(coeff);
v = refpos+ (1 - swr(coeff)) * scale;
break;
case TRC_SMITH:
//case TRC_ADMIT:
Expand Down
193 changes: 91 additions & 102 deletions python/NanoVNA-example.ipynb

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions python/nanovna.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def reflect_coeff_from_rawwave(self, freq = None):
def resume(self):
self.send_command("resume\r")

def pause(self):
self.send_command("pause\r")

def scan(self, port = None):
self.set_port(port)
return np.vectorize(self.gamma)(self.frequencies)
Expand All @@ -176,6 +179,15 @@ def data(self, array = 0):
x.append(float(d[0])+float(d[1])*1.j)
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):
pl.grid(True)
pl.plot(self.frequencies, 20*np.log10(np.abs(x)))
Expand Down
47 changes: 30 additions & 17 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ 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;
Expand All @@ -89,7 +89,7 @@ int16_t last_touch_y;
#define EVT_TOUCH_RELEASED 3

int awd_count;
int touch_x, touch_y;
//int touch_x, touch_y;

#define NUMINPUT_LEN 10

Expand Down Expand Up @@ -184,6 +184,7 @@ static int btn_wait_release(void)
int
touch_measure_y(void)
{
int v;
// open Y line
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_PULLDOWN );
palSetPadMode(GPIOA, 7, PAL_MODE_INPUT_PULLDOWN );
Expand All @@ -193,14 +194,17 @@ touch_measure_y(void)
palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL );
palSetPad(GPIOA, 6);

chThdSleepMilliseconds(1);

return adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
chThdSleepMilliseconds(2);
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
chThdSleepMilliseconds(2);
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL7);
return v/2;
}

int
touch_measure_x(void)
{
int v;
// open X line
palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_PULLDOWN );
palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_PULLDOWN );
Expand All @@ -210,9 +214,11 @@ touch_measure_x(void)
palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL );
palClearPad(GPIOA, 7);

chThdSleepMilliseconds(1);

return adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
chThdSleepMilliseconds(2);
v = adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
chThdSleepMilliseconds(2);
v += adc_single_read(ADC1, ADC_CHSELR_CHSEL6);
return v/2;
}

void
Expand Down Expand Up @@ -497,8 +503,7 @@ menu_single_trace_cb(int item)
static void
menu_scale_cb(int item)
{
(void)item;
ui_mode_keypad(KM_SCALE);
ui_mode_keypad(KM_SCALE + item);
ui_process_keypad();
}

Expand All @@ -514,7 +519,7 @@ menu_stimulus_cb(int item)
ui_mode_keypad(item);
ui_process_keypad();
break;
case 5:
case 5: /* TOGGLE SWEEP */
toggle_sweep();
menu_move_back();
ui_mode_normal();
Expand Down Expand Up @@ -852,7 +857,7 @@ draw_keypad(void)
}

const char *keypad_mode_label[] = {
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE"
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY"
};

void
Expand Down Expand Up @@ -958,8 +963,8 @@ menu_apply_touch(void)
if (menu[i].type == MT_BLANK)
continue;
int y = 32*i;
if (y < touch_y && touch_y < y+30
&& 320-60 < touch_x && touch_x < 320) {
if (y-2 < touch_y && touch_y < y+30+2
&& 320-60 < touch_x) {
menu_select_touch(i);
return;
}
Expand Down Expand Up @@ -1107,6 +1112,12 @@ keypad_click(int selection)
case KM_SCALE:
set_trace_scale(uistat.current_trace, value);
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;
Expand Down Expand Up @@ -1140,8 +1151,8 @@ keypad_apply_touch(void)
touch_position(&touch_x, &touch_y);

while (keypads[i].x) {
if (keypads[i].x < touch_x && touch_x < keypads[i].x+44
&& keypads[i].y < touch_y && touch_y < keypads[i].y+44) {
if (keypads[i].x-2 < touch_x && touch_x < keypads[i].x+44+2
&& keypads[i].y-2 < touch_y && touch_y < keypads[i].y+44+2) {
selection = i;
draw_keypad();
touch_wait_release();
Expand Down Expand Up @@ -1222,7 +1233,7 @@ void drag_marker(int t, int m)
int touch_x, touch_y;
int index;
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) {
markers[m].index = index;
redraw_marker(m, TRUE);
Expand All @@ -1244,6 +1255,8 @@ touch_pickup_marker(void)
int touch_x, touch_y;
int m, t;
touch_position(&touch_x, &touch_y);
touch_x += OFFSETX;
touch_y += OFFSETY;

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

0 comments on commit 295ec10

Please sign in to comment.