Extended trigger and level rounding

tinySA-v0.2
erikkaashoek 6 years ago
parent 12a4bd67b1
commit 4ea1157b8b

@ -564,7 +564,8 @@ typedef struct setting
int8_t _active_marker;
int8_t unit;
float offset;
float trigger;
float trigger_level;
int trigger;
uint32_t checksum;
}setting_t;
@ -792,7 +793,8 @@ void set_offset(float);
void set_unit(int);
void set_RBW(int);
void set_switches(int);
void set_trigger(float);
void set_trigger_level(float);
void set_trigger(int);
//extern int setting_measurement;
void self_test(int);
//extern int setting_test;
@ -803,4 +805,7 @@ enum {
M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND
};
enum {
T_AUTO, T_NORMAL, T_SINGLE, T_DONE
};
/*EOF*/

@ -47,7 +47,8 @@ void reset_settings(int m)
setting.measurement = M_OFF;
setting.frequency_IF = 433800000;
setting.offset = 0.0;
setting.trigger = -150.0;
setting.trigger = T_AUTO;
setting.trigger_level = -150.0;
trace[TRACE_STORED].enabled = false;
trace[TRACE_TEMP].enabled = false;
#ifdef __SPUR__
@ -454,15 +455,25 @@ void set_offset(float offset)
dirty = true;
}
void set_trigger(float trigger)
void set_trigger_level(float trigger_level)
{
setting.trigger_level = trigger_level;
if (setting.trigger != T_AUTO) {
for (int j = 0; j < setting._sweep_points; j++)
stored_t[j] = trigger_level;
}
dirty = true;
}
void set_trigger(int trigger)
{
setting.trigger = trigger;
if (trigger != -150.0) {
if (trigger == T_AUTO) {
trace[TRACE_STORED].enabled = false;
} else {
for (int j = 0; j < setting._sweep_points; j++)
stored_t[j] = trigger;
stored_t[j] = setting.trigger_level;
trace[TRACE_STORED].enabled = true;
} else {
trace[TRACE_STORED].enabled = false;
}
sweep_mode = SWEEP_ENABLE;
dirty = true;
@ -1019,7 +1030,7 @@ again:
int wait_for_trigger = false;
int old_actual_step_delay = actualStepDelay;
if (i == 0 && setting.frequency_step == 0 && setting.trigger != -150.0) { // [repare for wait for trigger to happen
if (i == 0 && setting.frequency_step == 0 && setting.trigger != T_AUTO) { // [repare for wait for trigger to happen
wait_for_trigger = true;
actualStepDelay = 0; // fastest possible in trigger mode
}
@ -1030,15 +1041,12 @@ again:
if (wait_for_trigger) { // wait for trigger to happen
if (operation_requested && break_on_operation)
break; // abort
if (subRSSI < setting.trigger)
if (subRSSI < setting.trigger_level)
goto wait;
actualStepDelay = old_actual_step_delay; // Trigger happened, restore step delay
if (setting.trigger == T_SINGLE)
pause_sweep(); // Trigger once so pause after this sweep has completed!!!!!!!
}
if (setting.trigger != -150.0 && setting.frequency_step > 0 && subRSSI > setting.trigger) {
pause_sweep(); // Stop scanning after completing this sweep if above trigger
draw_cal_status(); // To show trigger happened
}
#ifdef __SPUR__
if (setting.spur == 1) { // If first spur pass
@ -1068,8 +1076,10 @@ int16_t cur_max = 0;
static bool sweep(bool break_on_operation)
{
float RSSI;
int16_t downslope = true;
int16_t downslope;
// START_PROFILE;
again:
downslope = true;
palClearPad(GPIOB, GPIOB_LED);
temppeakLevel = -150;
float temp_min_level = 100;
@ -1177,6 +1187,17 @@ static bool sweep(bool break_on_operation)
temp_min_level = actual_t[i];
}
if (setting.trigger != T_AUTO && setting.frequency_step > 0) { // Trigger active
if (actual_t[max_index[0]] < setting.trigger_level) {
goto again;
} else {
if (setting.trigger == T_SINGLE)
pause_sweep(); // Stop scanning after completing this sweep if above trigger
}
scandirty = true; // To show trigger happened
}
if (scandirty) {
scandirty = false;
draw_cal_status();
@ -1428,6 +1449,32 @@ const char *averageText[] = { "OFF", "MIN", "MAX", "MAXD", " A 4", "A 16"};
const char *dBText[] = { "1dB/", "2dB/", "5dB/", "10dB/", "20dB/"};
const int refMHz[] = { 30, 15, 10, 4, 3, 2, 1 };
float my_round(float v)
{
float m = 1;
int sign = 1;
if (v < 0) {
sign = -1;
v = -v;
}
while (v < 100) {
v = v * 10;
m = m / 10;
}
while (v > 1000) {
v = v / 10;
m = m * 10;
}
v = (int)(v+0.5);
v = v * m;
if (sign == -1) {
v = -v;
}
return v;
}
const char *unit_string[] = { "dBm", "dBmV", "dBuV", "V", "mW" };
void draw_cal_status(void)
{
#define BLEN 10
@ -1436,6 +1483,11 @@ void draw_cal_status(void)
int x = 0;
int y = OFFSETY;
unsigned int color;
int rounding = false;
if (setting.unit != U_VOLT && setting.unit != U_MWATT)
rounding = true;
const char *unit = unit_string[setting.unit];
#define XSTEP 40
@ -1449,7 +1501,10 @@ void draw_cal_status(void)
ili9341_set_background(DEFAULT_BG_COLOR);
float yMax = setting.reflevel;
plot_printf(buf, BLEN, "%f", yMax);
if (rounding)
plot_printf(buf, BLEN, "%d%s", (int)yMax, unit);
else
plot_printf(buf, BLEN, "%f%s", yMax, unit);
buf[5]=0;
if (level_is_calibrated()) {
if (setting.auto_reflevel)
@ -1465,7 +1520,10 @@ void draw_cal_status(void)
color = DEFAULT_FG_COLOR;
ili9341_set_foreground(color);
y += YSTEP + YSTEP/2 ;
plot_printf(buf, BLEN, "%f/",setting.scale);
if (rounding)
plot_printf(buf, BLEN, "%d%s/",(int)setting.scale, unit);
else
plot_printf(buf, BLEN, "%f%s/",setting.scale, unit);
ili9341_drawstring(buf, x, y);
if (setting.auto_attenuation)
@ -1571,12 +1629,12 @@ void draw_cal_status(void)
ili9341_drawstring("Amp:", x, y);
y += YSTEP;
plot_printf(buf, BLEN, "%fdB",setting.offset);
plot_printf(buf, BLEN, "%.1fdB",setting.offset);
buf[5]=0;
ili9341_drawstring(buf, x, y);
}
if (setting.trigger != -150.0) {
if (setting.trigger != T_AUTO) {
if (is_paused()) {
ili9341_set_foreground(BRIGHT_COLOR_GREEN);
} else {
@ -1586,7 +1644,7 @@ void draw_cal_status(void)
ili9341_drawstring("TRIG:", x, y);
y += YSTEP;
plot_printf(buf, BLEN, "%ddBm",(int)setting.trigger);
plot_printf(buf, BLEN, "%ddBm",(int)setting.trigger_level);
buf[5]=0;
ili9341_drawstring(buf, x, y);
}
@ -1600,7 +1658,10 @@ void draw_cal_status(void)
y = HEIGHT-7 + OFFSETY;
plot_printf(buf, BLEN, "%f", (yMax - setting.scale * NGRIDY));
if (rounding)
plot_printf(buf, BLEN, "%d%s", (int)(yMax - setting.scale * NGRIDY), unit);
else
plot_printf(buf, BLEN, "%f%s", (yMax - setting.scale * NGRIDY), unit);
buf[5]=0;
if (level_is_calibrated())
if (setting.auto_reflevel)

@ -854,6 +854,15 @@ static void menu_scale_per_cb(int item, uint8_t data)
// draw_cal_status();
}
static void menu_trigger_cb(int item, uint8_t data)
{
(void)item;
set_trigger(data);
// menu_move_back();
ui_mode_normal();
draw_cal_status();
}
#if 0
static void choose_active_trace(void)
{
@ -923,6 +932,7 @@ static void menu_pause_cb(int item, uint8_t data)
// draw_cal_status();
}
//const int menu_drive_value[]={5,10,15,20};
const char *menu_drive_text[]={"-38dBm","-35dBm","-33dBm","-30dBm","-27dBm","-24dBm","-21dBm"," -19dBm", " -7dBm"," -4dBm"," -2dBm"," 1dBm"," 4dBm"," 7dBm"," 10dBm"," 13dBm"};
@ -1362,6 +1372,14 @@ static const menuitem_t menu_unit[] =
{ MT_NONE, 0, NULL, NULL } // sentinel
};
static const menuitem_t menu_trigger[] = {
{ MT_CALLBACK,T_AUTO, "AUTO", menu_trigger_cb},
{ MT_CALLBACK,T_NORMAL, "NORMAL", menu_trigger_cb},
{ MT_CALLBACK,T_SINGLE, "SINGLE", menu_trigger_cb},
{ MT_KEYPAD, KM_TRIGGER, "LEVEL", NULL},
{ MT_CANCEL, 0, S_LARROW" BACK",NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
static const menuitem_t menu_levelhigh[] = {
@ -1371,7 +1389,7 @@ static const menuitem_t menu_levelhigh[] = {
{ MT_SUBMENU,0, "AVER", menu_average},
{ MT_SUBMENU, 0, "UNIT", menu_unit},
{ MT_KEYPAD, KM_OFFSET, "\2EXTERN\0AMP", NULL},
{ MT_KEYPAD, KM_TRIGGER, "\2TRIGGER\0LEVEL", NULL},
{ MT_SUBMENU, 0, "TRIGGER", menu_trigger},
{ MT_CANCEL, 0, S_LARROW" BACK",NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
@ -1384,7 +1402,7 @@ static const menuitem_t menu_level[] = {
{ MT_SUBMENU,0, "AVER", menu_average},
{ MT_SUBMENU, 0, "UNIT", menu_unit},
{ MT_KEYPAD, KM_OFFSET, "\2EXTERN\0AMP", NULL},
{ MT_KEYPAD, KM_TRIGGER, "\2TRIGGER\0LEVEL", NULL},
{ MT_SUBMENU, 0, "TRIGGER", menu_trigger},
{ MT_CANCEL, 0, S_LARROW" BACK",NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
@ -1530,6 +1548,10 @@ static void menu_item_modify_attribute(
if (data == setting.modulation){
mark = true;
}
} else if (menu == menu_trigger && MT_MASK(menu[item].type) == MT_CALLBACK) {
if (data == setting.trigger){
mark = true;
}
} else if (menu == menu_display || menu == menu_displayhigh) {
if (item ==0 && is_paused()){
mark = true;
@ -1693,7 +1715,7 @@ static void fetch_numeric_target(void)
plot_printf(uistat.text, sizeof uistat.text, "%fdB", uistat.value);
break;
case KM_TRIGGER:
uistat.value = setting.trigger;
uistat.value = setting.trigger_level;
plot_printf(uistat.text, sizeof uistat.text, "%fdB", uistat.value);
break;
@ -1776,7 +1798,7 @@ set_numeric_value(void)
set_offset(uistat.value);
break;
case KM_TRIGGER:
set_trigger(uistat.value);
set_trigger_level(uistat.value);
break;
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.