Skip to content

Commit 22d5f4c

Browse files
committed
Make the tuning screen update delay configurable over Wi-Fi
1 parent a22e9b0 commit 22d5f4c

File tree

9 files changed

+92
-73
lines changed

9 files changed

+92
-73
lines changed

ats-mini/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ extern TFT_eSprite spr;
129129
extern TFT_eSPI tft;
130130

131131
extern bool tuning_flag;
132+
extern uint8_t tuneHoldOff;
132133
extern bool pushAndRotate;
133134
extern bool seekStop;
134135
extern uint8_t rssi;

ats-mini/Draw.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ void drawScreen(const char *statusLine1, const char *statusLine2)
426426
{
427427
if(sleepOn()) return;
428428

429+
// Do not update the screen while tuning (if enabled)
430+
if(tuneHoldOff && tuning_flag) return;
431+
429432
// Clear screen buffer
430433
spr.fillSprite(TH.bg);
431434

@@ -446,14 +449,5 @@ void drawScreen(const char *statusLine1, const char *statusLine2)
446449
break;
447450
}
448451

449-
#ifdef ENABLE_HOLDOFF
450-
// Update if not tuning
451-
if(!tuning_flag)
452-
{
453-
spr.pushSprite(0, 0);
454-
}
455-
#else
456-
// No hold off
457452
spr.pushSprite(0, 0);
458-
#endif
459453
}

ats-mini/Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ PORT ?= /dev/cu.usbmodem1101
99
DEBUG_LEVEL ?= 0
1010

1111
#
12-
# ENABLE_HOLDOFF : Hold off display updates while tuning
1312
# HALF_STEP : Enable encoder half-steps
1413
#
1514
DEFINES = -DDEBUG=$(DEBUG_LEVEL)
1615

17-
ifdef ENABLE_HOLDOFF
18-
DEFINES += -DENABLE_HOLDOFF
19-
endif
20-
2116
ifdef HALF_STEP
2217
DEFINES += -DHALF_STEP
2318
endif

ats-mini/Network.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ void webSetConfig(AsyncWebServerRequest *request)
387387
prefsSave |= SAVE_SETTINGS;
388388
}
389389

390-
// Save scroll direction and menu zoom
390+
// Save scroll direction, tuning hold off, and menu zoom
391391
scrollDirection = request->hasParam("scroll", true)? -1 : 1;
392+
tuneHoldOff = request->getParam("holdoff", true)->value().toInt();
392393
zoomMenu = request->hasParam("zoom", true);
393394
prefsSave |= SAVE_SETTINGS;
394395

@@ -691,6 +692,11 @@ const String webConfigPage()
691692
(scrollDirection<0? " CHECKED ":"") + "></TD>"
692693
"</TR>"
693694
"<TR>"
695+
"<TD CLASS='LABEL'>Tuning Display Delay</TD>"
696+
"<TD><INPUT TYPE='NUMBER' NAME='holdoff' VALUE='" +
697+
tuneHoldOff + "' MIN='0' MAX='255'></TD>"
698+
"</TR>"
699+
"<TR>"
694700
"<TD CLASS='LABEL'>Zoomed Menu</TD>"
695701
"<TD><INPUT TYPE='CHECKBOX' NAME='zoom' VALUE='on'" +
696702
(zoomMenu? " CHECKED ":"") + "></TD>"

ats-mini/Storage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ void prefsSave(uint32_t items)
185185
prefs.putUChar("SleepMode", sleepModeIdx); // Sleep mode
186186
prefs.putUChar("ZoomMenu", zoomMenu); // TRUE: Zoom menu
187187
prefs.putBool("ScrollDir", scrollDirection<0); // TRUE: Reverse scroll
188+
prefs.putBool("TuneHoldOff", tuneHoldOff); // Tuning hold off
188189
prefs.putUChar("UTCOffset", utcOffsetIdx); // UTC Offset
189190
prefs.putUChar("Squelch", currentSquelch); // Squelch
190191
prefs.putUChar("FmRegion", FmRegionIdx); // FM region
@@ -258,6 +259,7 @@ bool prefsLoad(uint32_t items)
258259
sleepModeIdx = prefs.getUChar("SleepMode", sleepModeIdx); // Sleep mode
259260
zoomMenu = prefs.getUChar("ZoomMenu", zoomMenu); // TRUE: Zoom menu
260261
scrollDirection = prefs.getBool("ScrollDir", scrollDirection<0)? -1:1; // TRUE: Reverse scroll
262+
tuneHoldOff = prefs.getBool("TuneHoldOff", tuneHoldOff); // Tuning hold off
261263
utcOffsetIdx = prefs.getUChar("UTCOffset", utcOffsetIdx); // UTC Offset
262264
currentSquelch = prefs.getUChar("Squelch", currentSquelch); // Squelch
263265
FmRegionIdx = prefs.getUChar("FmRegion", FmRegionIdx); // FM region

ats-mini/ats-mini.ino

Lines changed: 72 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#define NTP_CHECK_TIME 60000 // NTP time refresh period (ms)
2626
#define SCHEDULE_CHECK_TIME 2000 // How often to identify the same frequency (ms)
2727
#define BACKGROUND_REFRESH_TIME 5000 // Background screen refresh time. Covers the situation where there are no other events causing a refresh
28-
#define TUNE_HOLDOFF_TIME 90 // Timer to hold off display whilst tuning
2928

3029
// =================================
3130
// CONSTANTS AND VARIABLES
@@ -80,6 +79,7 @@ int8_t scrollDirection = 1; // Menu scroll direction
8079
uint32_t background_timer = millis(); // Background screen refresh timer.
8180
uint32_t tuning_timer = millis(); // Tuning hold off timer.
8281
bool tuning_flag = false; // Flag to indicate tuning
82+
uint8_t tuneHoldOff = 90; // Timer to hold off display whilst tuning
8383

8484
//
8585
// Current parameters
@@ -336,32 +336,6 @@ void useBand(const Band *band)
336336
snr = 0;
337337
}
338338

339-
// This function is called by the seek function process.
340-
bool checkStopSeeking()
341-
{
342-
// Returns true if the user rotates the encoder
343-
if(seekStop) return true;
344-
345-
// Checking isPressed without debouncing because this callback
346-
// is not invoked often enough to register a click
347-
if(pb1.update(digitalRead(ENCODER_PUSH_BUTTON) == LOW, 0).isPressed)
348-
{
349-
// Wait till the button is released, otherwise the main loop will register a click
350-
while(pb1.update(digitalRead(ENCODER_PUSH_BUTTON) == LOW).isPressed)
351-
delay(100);
352-
return true;
353-
}
354-
355-
return false;
356-
}
357-
358-
// This function is called by the seek function process.
359-
void showFrequencySeek(uint16_t freq)
360-
{
361-
currentFrequency = freq;
362-
drawScreen();
363-
}
364-
365339
//
366340
// Tune using BFO, using algorithm from Goshante's ATS-20_EX firmware
367341
//
@@ -452,6 +426,45 @@ bool updateFrequency(int newFreq, bool wrap)
452426
return true;
453427
}
454428

429+
// This function is called by the seek function process.
430+
bool checkStopSeeking()
431+
{
432+
// Returns true if the user rotates the encoder
433+
if(seekStop) return true;
434+
435+
// Checking isPressed without debouncing because this callback
436+
// is not invoked often enough to register a click
437+
if(pb1.update(digitalRead(ENCODER_PUSH_BUTTON) == LOW, 0).isPressed)
438+
{
439+
// Wait till the button is released, otherwise the main loop will register a click
440+
while(pb1.update(digitalRead(ENCODER_PUSH_BUTTON) == LOW).isPressed)
441+
delay(100);
442+
return true;
443+
}
444+
445+
return false;
446+
}
447+
448+
// This function is called by the seek function process.
449+
void showFrequencySeek(uint16_t freq)
450+
{
451+
// Check if tuning flag is set
452+
if(tuneHoldOff)
453+
{
454+
if(tuning_flag)
455+
{
456+
if((millis() - tuning_timer) > tuneHoldOff)
457+
tuning_flag = false;
458+
}
459+
else
460+
{
461+
tuning_timer = millis();
462+
tuning_flag = true;
463+
}
464+
}
465+
currentFrequency = freq;
466+
drawScreen();
467+
}
455468

456469
//
457470
// Handle encoder rotation in seek mode
@@ -464,11 +477,12 @@ bool doSeek(int8_t dir)
464477
{
465478
if(isSSB())
466479
{
467-
#ifdef ENABLE_HOLDOFF
468-
// Tuning timer to hold off (FM/AM) display updates
469-
tuning_flag = true;
470-
tuning_timer = millis();
471-
#endif
480+
if(tuneHoldOff)
481+
{
482+
// Tuning timer to hold off (FM/AM) display updates
483+
tuning_flag = true;
484+
tuning_timer = millis();
485+
}
472486

473487
updateBFO(currentBFO + dir * getCurrentStep(true)->step, true);
474488
}
@@ -481,6 +495,7 @@ bool doSeek(int8_t dir)
481495
// Flag is set by rotary encoder and cleared on seek/scan entry
482496
seekStop = false;
483497
rx.seekStationProgress(showFrequencySeek, checkStopSeeking, dir>0? 1 : 0);
498+
if(tuneHoldOff) tuning_flag = false;
484499
updateFrequency(rx.getFrequency(), true);
485500
}
486501
}
@@ -518,11 +533,12 @@ bool doTune(int8_t dir, bool fast = false)
518533
//
519534
if(isSSB())
520535
{
521-
#ifdef ENABLE_HOLDOFF
522-
// Tuning timer to hold off (SSB) display updates
523-
tuning_flag = true;
524-
tuning_timer = millis();
525-
#endif
536+
if(tuneHoldOff)
537+
{
538+
// Tuning timer to hold off (SSB) display updates
539+
tuning_flag = true;
540+
tuning_timer = millis();
541+
}
526542

527543
uint32_t step = getCurrentStep(fast)->step;
528544
uint32_t stepAdjust = (currentFrequency * 1000 + currentBFO) % step;
@@ -536,11 +552,12 @@ bool doTune(int8_t dir, bool fast = false)
536552
//
537553
else
538554
{
539-
#ifdef ENABLE_HOLDOFF
540-
// Tuning timer to hold off (FM/AM) display updates
541-
tuning_flag = true;
542-
tuning_timer = millis();
543-
#endif
555+
if(tuneHoldOff)
556+
{
557+
// Tuning timer to hold off (FM/AM) display updates
558+
tuning_flag = true;
559+
tuning_timer = millis();
560+
}
544561

545562
uint16_t step = getCurrentStep(fast)->step;
546563
uint16_t stepAdjust = currentFrequency % step;
@@ -569,11 +586,12 @@ bool doDigit(int8_t dir)
569586
// SSB tuning
570587
if(isSSB())
571588
{
572-
#ifdef ENABLE_HOLDOFF
573-
// Tuning timer to hold off (SSB) display updates
574-
tuning_flag = true;
575-
tuning_timer = millis();
576-
#endif
589+
if(tuneHoldOff)
590+
{
591+
// Tuning timer to hold off (SSB) display updates
592+
tuning_flag = true;
593+
tuning_timer = millis();
594+
}
577595

578596
updated = updateBFO(currentBFO + dir * getFreqInputStep(), false);
579597
}
@@ -583,11 +601,12 @@ bool doDigit(int8_t dir)
583601
//
584602
else
585603
{
586-
#ifdef ENABLE_HOLDOFF
587-
// Tuning timer to hold off (FM/AM) display updates
588-
tuning_flag = true;
589-
tuning_timer = millis();
590-
#endif
604+
if(tuneHoldOff)
605+
{
606+
// Tuning timer to hold off (FM/AM) display updates
607+
tuning_flag = true;
608+
tuning_timer = millis();
609+
}
591610

592611
// Tune to a new frequency
593612
updated = updateFrequency(currentFrequency + getFreqInputStep() * dir, false);
@@ -913,14 +932,12 @@ void loop()
913932
// Tick NETWORK time, connecting to WiFi if requested
914933
netTickTime();
915934

916-
#ifdef ENABLE_HOLDOFF
917935
// Check if tuning flag is set
918-
if(tuning_flag && ((currentTime - tuning_timer) > TUNE_HOLDOFF_TIME))
936+
if(tuneHoldOff && tuning_flag && ((currentTime - tuning_timer) > tuneHoldOff))
919937
{
920938
tuning_flag = false;
921939
needRedraw = true;
922940
}
923-
#endif
924941

925942
// Run clock
926943
needRedraw |= clockTickTime();

changelog/+holdoff.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Screen update delay while tuning is now configurable via Wi-Fi settings page (previously it was a compile-time option).

docs/source/development.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ arduino-cli compile --clean -e -p COM_PORT -u ats-mini
2323

2424
The available options are:
2525

26-
* `ENABLE_HOLDOFF` - enable delayed screen update while tuning
2726
* `HALF_STEP` - enable encoder half-steps (useful for EC11E encoder)
2827

2928
To set an option, add the `--build-property` command line argument like this:
3029

3130
```shell
32-
arduino-cli compile --build-property "compiler.cpp.extra_flags=-DENABLE_HOLDOFF" --clean -e -p COM_PORT -u ats-mini
31+
arduino-cli compile --build-property "compiler.cpp.extra_flags=-DHALF_STEP" --clean -e -p COM_PORT -u ats-mini
3332
```
3433

3534
## Enabling the pre-commit hooks
@@ -43,7 +42,7 @@ arduino-cli compile --build-property "compiler.cpp.extra_flags=-DENABLE_HOLDOFF"
4342
You can do all of the above using the `make` command as well:
4443

4544
```shell
46-
ENABLE_HOLDOFF=1 PORT=/dev/tty.usbmodem14401 make upload
45+
HALF_STEP=1 PORT=/dev/tty.usbmodem14401 make upload
4746
```
4847

4948
## Decoding stack traces

docs/source/manual.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ From now on you can switch the modes as you want and connect to your receiver ei
113113
When on the go, you can set up a mobile Wi-Fi hotspot on your smartphone and use it to connect the receiver to the internet.
114114
```
115115

116+
### Receiver settings available via Wi-Fi only
117+
118+
* **Tuning Display Delay** - time in milliseconds to delay screen updates while tuning/seeking, 0 (disabled) ... 255. Makes the tuning process a bit faster because the screen is updated less often.
119+
116120
## Schedule
117121

118122
The receiver can download the [EiBi](http://eibispace.de/dx/eibi.txt) shortwave schedule and use it to display broadcasting stations, allowing you to quickly tune to them. Here’s how it works:

0 commit comments

Comments
 (0)