Add UP/DOWN trigger option and optimize constants

pull/4/head
erikkaashoek 6 years ago
parent 84e5abe9ac
commit 37495e9750

@ -5,7 +5,9 @@
# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -Og -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage
USE_OPT = -Og -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage -fsingle-precision-constant
# -Wdouble-promotion
# USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage
endif

@ -167,6 +167,7 @@ static THD_FUNCTION(Thread1, arg)
}
continue;
}
// START_PROFILE
// Process UI inputs
if (!(sweep_mode & SWEEP_SELFTEST))
ui_process();
@ -191,7 +192,9 @@ static THD_FUNCTION(Thread1, arg)
// plot trace and other indications as raster
draw_all(completed); // flush markmap only if scan completed to prevent
// remaining traces
// STOP_PROFILE
}
}
int

@ -607,6 +607,7 @@ typedef struct setting
int8_t unit;
float offset;
float trigger_level;
int trigger_direction;
int trigger;
int linearity_step;
float level;
@ -868,7 +869,7 @@ void SI4432_SetReference(int freq);
// Speed profile definition
#define START_PROFILE systime_t time = chVTGetSystemTimeX();
#define RESTART_PROFILE time = chVTGetSystemTimeX();
#define STOP_PROFILE {char string_buf[12];plot_printf(string_buf, sizeof string_buf, "T:%06d", chVTGetSystemTimeX() - time);ili9341_drawstringV(string_buf, 1, 180);}
#define STOP_PROFILE {char string_buf[12];plot_printf(string_buf, sizeof string_buf, "%06d", (chVTGetSystemTimeX() - time));ili9341_drawstringV(string_buf, 1, 180);}
#define DELTA_TIME (time = chVTGetSystemTimeX() - time)
// Macros for convert define value to string
#define STR1(x) #x
@ -899,6 +900,6 @@ enum {
};
enum {
T_AUTO, T_NORMAL, T_SINGLE, T_DONE
T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN
};
/*EOF*/

@ -23,6 +23,11 @@
#include "chprintf.h"
#include "nanovna.h"
#pragma GCC push_options
// #pragma GCC optimize ("O2") // Makes the code just a bit faster, disable during debugging.
#ifdef __SCROLL__
uint16_t _grid_y = NOSCROLL_GRIDY;
int waterfall = false;
@ -454,6 +459,10 @@ draw_on_strut(int v0, int d, int color)
}
#endif
#define SQRT_50 ((float)7.0710678118654)
#define LOG_10_SQRT_50 ((float)0.84948500216800)
#define POW_30_20 ((float) 0.215443469)
#define POW_SQRT 1.5234153789
/*
* calculate log10(abs(gamma))
*/
@ -463,13 +472,16 @@ value(const float v)
switch(setting.unit)
{
case U_DBMV:
return v + 30.0 + 20.0*log10(sqrt(50));
// return v + 30.0 + 20.0*log10(sqrt(50));
return v + 30.0 + 20.0*LOG_10_SQRT_50; //TODO convert constants to single float number as GCC compiler does runtime calculation
break;
case U_DBUV:
return v + 90.0 + 20.0*log10(sqrt(50.0));
// return v + 90.0 + 20.0*log10(sqrt(50.0)); //TODO convert constants to single float number as GCC compiler does runtime calculation
return v + 90.0 + 20.0*LOG_10_SQRT_50;
break;
case U_VOLT:
return pow(10, (v-30.0)/20.0) * sqrt(50.0);
// return pow(10, v/20.0) * POW_SQRT; //TODO there is an error in this calculation as the outcome is different from the not optimized version
break;
case U_WATT:
return pow(10, v/10.0)/1000.0;
@ -1359,6 +1371,7 @@ void
plot_into_index(measurement_t measured)
{
int t, i;
// START_PROFILE
for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled)
continue;
@ -1367,6 +1380,7 @@ plot_into_index(measurement_t measured)
for (i = 0; i < sweep_points; i++)
index[i] = trace_into_index(t, i, measured[ch]);
}
// STOP_PROFILE
#if 0
for (t = 0; t < TRACES_MAX; t++)
if (trace[t].enabled && trace[t].polar)
@ -2273,3 +2287,6 @@ plot_init(void)
{
force_set_markmap();
}
#pragma GCC pop_options

@ -96,6 +96,7 @@ void reset_settings(int m)
setting.auto_IF = true;
setting.offset = 0.0;
setting.trigger = T_AUTO;
setting.trigger_direction = T_UP;
setting.level_sweep = 0.0;
setting.level = -15.0;
setting.trigger_level = -150.0;
@ -762,13 +763,17 @@ void set_trigger_level(float trigger_level)
void set_trigger(int trigger)
{
setting.trigger = trigger;
if (trigger == T_AUTO) {
trace[TRACE_STORED].enabled = false;
if (trigger == T_UP || trigger == T_DOWN){
setting.trigger_direction = trigger;
} else {
show_stored_trace_at(setting.trigger_level);
setting.trigger = trigger;
if (trigger == T_AUTO) {
trace[TRACE_STORED].enabled = false;
} else {
show_stored_trace_at(setting.trigger_level);
}
sweep_mode = SWEEP_ENABLE;
}
sweep_mode = SWEEP_ENABLE;
dirty = true;
}
@ -1565,8 +1570,9 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
data_level = subRSSI < setting.trigger_level ? T_LEVEL_BELOW : T_LEVEL_ABOVE;
// wait for rising edge
if (!(prev_data_level == T_LEVEL_BELOW &&
data_level == T_LEVEL_ABOVE)) // trigger level change
if (setting.trigger_direction == T_UP && !(prev_data_level == T_LEVEL_BELOW && data_level == T_LEVEL_ABOVE)) // trigger level change
goto wait; // get next rssi
if (setting.trigger_direction == T_DOWN && !(prev_data_level == T_LEVEL_ABOVE && data_level == T_LEVEL_BELOW)) // trigger level change
goto wait; // get next rssi
#ifdef __FAST_SWEEP__
if (i == 0 && setting.frequency_step == 0 && setting.spur == 0 && old_SI4432_step_delay == 0 && setting.repeat == 1 && setting.sweep_time_us < ONE_SECOND_TIME) {

@ -1498,10 +1498,12 @@ static const menuitem_t menu_unit[] =
};
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_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_CALLBACK,T_UP, "UP", menu_trigger_cb},
{ MT_CALLBACK,T_DOWN, "DOWN", menu_trigger_cb},
{ MT_CANCEL, 0, "\032 BACK",NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
@ -1666,6 +1668,9 @@ static void menu_item_modify_attribute(
if (data == setting.trigger){
mark = true;
}
if (data == setting.trigger_direction) {
mark = true;
}
} else if (menu == menu_display /* || menu == menu_displayhigh */) {
if (item ==0 && is_paused()){
mark = true;

Loading…
Cancel
Save

Powered by TurnKey Linux.