Remove variable, use speep_mode flag

This commit is contained in:
DiSlord 2020-03-07 22:21:02 +03:00
parent e896f32803
commit bb7127fdd0
3 changed files with 14 additions and 12 deletions

20
main.c
View file

@ -78,8 +78,8 @@ static MUTEX_DECL(mutex);
static int32_t frequency_offset = 5000; static int32_t frequency_offset = 5000;
static uint32_t frequency = 10000000; static uint32_t frequency = 10000000;
static int8_t drive_strength = DRIVE_STRENGTH_AUTO; static int8_t drive_strength = DRIVE_STRENGTH_AUTO;
int8_t sweep_enabled = TRUE; int8_t sweep_mode = SWEEP_ENABLE;
volatile int8_t sweep_once = FALSE;
volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags
int16_t vbat = 0; int16_t vbat = 0;
@ -91,10 +91,10 @@ static THD_FUNCTION(Thread1, arg)
while (1) { while (1) {
bool completed = false; bool completed = false;
if (sweep_enabled || sweep_once) { if (sweep_mode&(SWEEP_ENABLE|SWEEP_ONCE)) {
chMtxLock(&mutex); chMtxLock(&mutex);
completed = sweep(true); completed = sweep(true);
sweep_once = FALSE; sweep_mode&=~SWEEP_ONCE;
chMtxUnlock(&mutex); chMtxUnlock(&mutex);
} else { } else {
__WFI(); __WFI();
@ -103,7 +103,7 @@ static THD_FUNCTION(Thread1, arg)
chMtxLock(&mutex); chMtxLock(&mutex);
ui_process(); ui_process();
if (sweep_enabled) { if (sweep_mode&SWEEP_ENABLE) {
if (vbat != -1) { if (vbat != -1) {
adc_stop(ADC1); adc_stop(ADC1);
vbat = adc_vbat_read(ADC1); vbat = adc_vbat_read(ADC1);
@ -136,19 +136,19 @@ static THD_FUNCTION(Thread1, arg)
static inline void static inline void
pause_sweep(void) pause_sweep(void)
{ {
sweep_enabled = FALSE; sweep_mode&=~SWEEP_ENABLE;
} }
static inline void static inline void
resume_sweep(void) resume_sweep(void)
{ {
sweep_enabled = TRUE; sweep_mode|=SWEEP_ENABLE;
} }
void void
toggle_sweep(void) toggle_sweep(void)
{ {
sweep_enabled = !sweep_enabled; sweep_mode^=SWEEP_ENABLE;
} }
static float static float
@ -842,11 +842,11 @@ VNA_SHELL_FUNCTION(cmd_scan)
if (cal_auto_interpolate && (cal_status & CALSTAT_APPLY)) if (cal_auto_interpolate && (cal_status & CALSTAT_APPLY))
cal_interpolate(lastsaveid); cal_interpolate(lastsaveid);
sweep_once = TRUE; sweep_mode|= SWEEP_ONCE;
chMtxUnlock(&mutex); chMtxUnlock(&mutex);
// wait finishing sweep // wait finishing sweep
while (sweep_once) while (sweep_mode&SWEEP_ONCE)
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);
} }

View file

@ -86,7 +86,9 @@ double my_atof(const char *p);
void toggle_sweep(void); void toggle_sweep(void);
void loadDefaultProps(void); void loadDefaultProps(void);
extern int8_t sweep_enabled; #define SWEEP_ENABLE 0x01
#define SWEEP_ONCE 0x02
extern int8_t sweep_mode;
/* /*
* dsp.c * dsp.c

2
ui.c
View file

@ -1358,7 +1358,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
*fg = config.menu_normal_color; *fg = config.menu_normal_color;
} }
} else if (menu == menu_stimulus) { } else if (menu == menu_stimulus) {
if (item == 5 /* PAUSE */ && !sweep_enabled) { if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) {
*bg = DEFAULT_MENU_TEXT_COLOR; *bg = DEFAULT_MENU_TEXT_COLOR;
*fg = config.menu_normal_color; *fg = config.menu_normal_color;
} }