This commit is contained in:
cho45 2019-10-12 04:18:41 +09:00
parent 887108ebde
commit dc97e90e31
3 changed files with 62 additions and 8 deletions

36
main.c
View file

@ -56,6 +56,7 @@ int8_t sweep_once = FALSE;
int8_t cal_auto_interpolate = TRUE;
uint16_t redraw_request = 0; // contains REDRAW_XXX flags
int16_t vbat = 0;
uint8_t avg = 1;
static THD_WORKING_AREA(waThread1, 640);
@ -657,24 +658,53 @@ ensure_edit_config(void)
// main loop for measurement
bool sweep(bool break_on_operation)
{
int i;
int i, j;
float tmp[2];
for (i = 0; i < sweep_points; i++) {
int delay = set_frequency(frequencies[i]);
tlv320aic3204_select_in3(); // CH0:REFLECT
wait_dsp(delay);
wait_dsp(delay-1);
// blink LED while scanning
palClearPad(GPIOC, GPIOC_LED);
/* calculate reflection coeficient */
if (avg > 1) {
measured[0][i][0] = 0.0;
measured[0][i][1] = 0.0;
for (j = 0; j < avg; j++) {
wait_dsp(1);
(*sample_func)(tmp);
measured[0][i][0] += tmp[0];
measured[0][i][1] += tmp[1];
}
measured[0][i][0] /= avg;
measured[0][i][1] /= avg;
} else {
wait_dsp(1);
(*sample_func)(measured[0][i]);
}
tlv320aic3204_select_in1(); // CH1:TRANSMISSION
wait_dsp(delay + DELAY_CHANNEL_CHANGE);
wait_dsp(delay + DELAY_CHANNEL_CHANGE - 1);
/* calculate transmission coeficient */
if (avg > 1) {
measured[1][i][0] = 0.0;
measured[1][i][1] = 0.0;
for (j = 0; j < avg; j++) {
wait_dsp(1);
(*sample_func)(tmp);
measured[1][i][0] += tmp[0];
measured[1][i][1] += tmp[1];
}
measured[1][i][0] /= avg;
measured[1][i][1] /= avg;
} else {
wait_dsp(1);
(*sample_func)(measured[1][i]);
}
// blink LED while scanning
palSetPad(GPIOC, GPIOC_LED);

View file

@ -258,6 +258,7 @@ extern uint16_t redraw_request;
#define REDRAW_MARKER (1<<3)
extern int16_t vbat;
extern uint8_t avg;
/*
* ili9341.c

29
ui.c
View file

@ -68,7 +68,7 @@ enum {
};
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, KM_AVG
};
uint8_t ui_mode = UI_NORMAL;
@ -726,6 +726,22 @@ menu_transform_cb(int item)
}
}
static void
menu_avg_cb(void)
{
int status;
status = btn_wait_release();
if (status & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(KM_AVG);
ui_process_numeric();
} else {
ui_mode_keypad(KM_AVG);
ui_process_keypad();
}
ui_mode_normal();
}
static void
choose_active_marker(void)
{
@ -986,6 +1002,7 @@ const menuitem_t menu_display[] = {
{ MT_SUBMENU, "SCALE", menu_scale },
{ MT_SUBMENU, "CHANNEL", menu_channel },
{ MT_SUBMENU, "TRANSFORM", menu_transform },
{ MT_CALLBACK, "AVG", menu_avg_cb },
{ MT_CANCEL, S_LARROW" BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
@ -1227,11 +1244,12 @@ const keypads_t * const keypads_mode_tbl[] = {
keypads_scale, // refpos
keypads_time, // electrical delay
keypads_scale, // velocity factor
keypads_time // scale of delay
keypads_time, // scale of delay
keypads_scale // avg
};
const char * const keypad_mode_label[] = {
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY"
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY", "AVG"
};
void
@ -1494,6 +1512,9 @@ fetch_numeric_target(void)
case KM_SCALEDELAY:
uistat.value = get_trace_scale(uistat.current_trace) * 1e12;
break;
case KM_AVG:
uistat.value = avg;
break;
}
{
@ -1723,6 +1744,8 @@ keypad_click(int key)
case KM_SCALEDELAY:
set_trace_scale(uistat.current_trace, value * 1e-12); // pico second
break;
case KM_AVG:
avg = value;
}
return KP_DONE;