Skip to content

Commit 06c569f

Browse files
committed
Bugfix/enhancements to half-minute date triggering and scrolling
1 parent e27c116 commit 06c569f

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

arduino-nixie/arduino-nixie.ino

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,9 @@ void setup(){
198198
initOutputs(); //depends on some EEPROM settings
199199
}
200200

201-
unsigned long pollCleanLast = 0; //every cleanSpeed ms
202-
unsigned long pollScrollLast = 0; //every scrollSpeed ms
203201
void loop(){
204-
unsigned long now = millis();
205-
//If we're running a tube cleaning, advance it every cleanSpeed ms.
206-
if(cleanRemain && (unsigned long)(now-pollCleanLast)>=cleanSpeed) { //account for rollover
207-
pollCleanLast=now;
208-
cleanRemain--;
209-
if(cleanRemain<1) calcSun(tod.year(),tod.month(),tod.day()); //take this opportunity to perform a calculation that blanks the display for a bit
210-
updateDisplay();
211-
}
212-
//If we're scrolling an animation, advance it every scrollSpeed ms.
213-
else if(scrollRemain!=0 && scrollRemain!=-128 && (unsigned long)(now-pollScrollLast)>=scrollSpeed) {
214-
pollScrollLast=now;
215-
if(scrollRemain<0) {
216-
scrollRemain++; updateDisplay();
217-
} else {
218-
scrollRemain--; updateDisplay();
219-
if(scrollRemain==0) scrollRemain=-128;
220-
}
221-
}
222202
//Every loop cycle, check the RTC and inputs (previously polled, but works fine without and less flicker)
203+
checkEffects(false); //cleaning and scrolling display effects - not handled by checkRTC since they have their own timing
223204
checkRTC(false); //if clock has ticked, decrement timer if running, and updateDisplay
224205
millisApplyDrift();
225206
checkInputs(); //if inputs have changed, this will do things + updateDisplay as needed
@@ -334,6 +315,25 @@ void ctrlEvt(byte ctrl, byte evt){
334315
updateDisplay();
335316
return;
336317
}
318+
//If a scroll is waiting to scroll out, cancel it, and let the button event do what it will
319+
if(scrollRemain==-128 && evt==1){
320+
scrollRemain = 0;
321+
}
322+
//If a scroll is going, fast-forward to end of scroll in/out - see also checkRTC
323+
else if(scrollRemain!=0 && evt==1){
324+
btnStop();
325+
if(scrollRemain>0) scrollRemain = 1;
326+
else scrollRemain = -1;
327+
checkEffects(true);
328+
return;
329+
}
330+
//If the version display is going, any press should cancel it, with a display update
331+
if(versionRemain>0 && evt==1){
332+
versionRemain = 0;
333+
btnStop();
334+
updateDisplay();
335+
return;
336+
}
337337

338338
//Is it a press for an un-off?
339339
unoffRemain = unoffDur; //always do this so continued button presses during an unoff keep it alive
@@ -845,13 +845,18 @@ void checkRTC(bool force){
845845
}
846846
//Paged-display function timeout //TODO change fnIsDate to consts? //TODO timeoutPageFn var
847847
else if(fn==fnIsDate && (unsigned long)(now-inputLast)>=3000) { //3sec per date page
848+
//If a scroll in is going, fast-forward to end - see also ctrlEvt
849+
if(scrollRemain>0) {
850+
scrollRemain = 1;
851+
checkEffects(true);
852+
}
848853
//Here we just have to increment the page and decide when to reset. updateDisplay() will do the rendering
849854
fnPg++; inputLast+=3000; //but leave inputLastTODMins alone so the subsequent page displays will be based on the same TOD
850855
while(fnPg<fnDatePages && fnPg<200 && ( //skip inapplicable date pages. The 200 is an extra failsafe
851856
(!readEEPROM(10,true) && !readEEPROM(12,true) && //if no lat+long specified, skip weather/rise/set
852857
(fnPg==fnDateWeathernow || fnPg==fnDateWeathernext || fnPg==fnDateSunlast || fnPg==fnDateSunnext))
853858
)) fnPg++;
854-
if(fnPg >= fnDatePages){ fnPg = 0; fn = fnIsTime; }
859+
if(fnPg >= fnDatePages){ fnPg = 0; fn = fnIsTime; } // when we run out of pages, go back to time. When the half-minute date is triggered, fnPg is set to 254, so it will be 255 here and be cancelled after just the one page.
855860
force=true;
856861
}
857862
//Temporary-display function timeout: if we're *not* in a permanent one (time, or running/signaling timer)
@@ -922,7 +927,7 @@ void checkRTC(bool force){
922927
} //end alarm trigger
923928
}
924929
//At bottom of minute, see if we should show the date
925-
if(tod.second()==30 && fn==fnIsTime && fnSetPg==0 && unoffRemain==0) {
930+
if(tod.second()==30 && fn==fnIsTime && fnSetPg==0 && unoffRemain==0 && cleanRemain==0 && scrollRemain==0 && versionRemain==0) {
926931
if(readEEPROM(18,false)>=2) { fn = fnIsDate; inputLast = now; inputLastTODMins = tod.hour()*60+tod.minute(); fnPg = 254; updateDisplay(); }
927932
if(readEEPROM(18,false)==3) { startScroll(); }
928933
}
@@ -1292,6 +1297,30 @@ byte displayNext[6] = {15,15,15,15,15,15}; //Internal representation of display.
12921297
byte displayLast[6] = {11,11,11,11,11,11}; //for noticing changes to displayNext and fading the display to it
12931298
byte scrollDisplay[6] = {15,15,15,15,15,15}; //For animating a value into displayNext from right, and out to left
12941299

1300+
unsigned long pollCleanLast = 0; //every cleanSpeed ms
1301+
unsigned long pollScrollLast = 0; //every scrollSpeed ms
1302+
void checkEffects(bool force){
1303+
//control the cleaning/scrolling effects - similar to checkRTC but it has its own timings
1304+
unsigned long now = millis();
1305+
//If we're running a tube cleaning, advance it every cleanSpeed ms.
1306+
if(cleanRemain && (unsigned long)(now-pollCleanLast)>=cleanSpeed) { //account for rollover
1307+
pollCleanLast=now;
1308+
cleanRemain--;
1309+
if(cleanRemain<1) calcSun(tod.year(),tod.month(),tod.day()); //take this opportunity to perform a calculation that blanks the display for a bit
1310+
updateDisplay();
1311+
}
1312+
//If we're scrolling an animation, advance it every scrollSpeed ms.
1313+
else if(scrollRemain!=0 && scrollRemain!=-128 && ((unsigned long)(now-pollScrollLast)>=scrollSpeed || force)) {
1314+
pollScrollLast=now;
1315+
if(scrollRemain<0) {
1316+
scrollRemain++; updateDisplay();
1317+
} else {
1318+
scrollRemain--; updateDisplay();
1319+
if(scrollRemain==0) scrollRemain = -128;
1320+
}
1321+
}
1322+
}
1323+
12951324
void updateDisplay(){
12961325
//Run as needed to update display when the value being shown on it has changed
12971326
//This formats the new value and puts it in displayNext[] for cycleDisplay() to pick up

arduino-nixie/configs/v5-4tube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const word velThreshold = 0; //ms
6767

6868
// What is the "frame rate" of the tube cleaning and display scrolling? up to 65535 ms
6969
const word cleanSpeed = 200; //ms
70-
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30 - to give the illusion of a slow scroll that doesn't pause, use (timeoutTempFn*1000)/(displaySize+1) - e.g. 714 for displaySize=6 and timeoutTempFn=5
70+
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30
7171

7272
// What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
7373
const unsigned long timeoutSet = 300; //sec

arduino-nixie/configs/v5-6tube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const word velThreshold = 0; //ms
6767

6868
// What is the "frame rate" of the tube cleaning and display scrolling? up to 65535 ms
6969
const word cleanSpeed = 200; //ms
70-
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30 - to give the illusion of a slow scroll that doesn't pause, use (timeoutTempFn*1000)/(displaySize+1) - e.g. 714 for displaySize=6 and timeoutTempFn=5
70+
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30
7171

7272
// What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
7373
const unsigned long timeoutSet = 300; //sec

arduino-nixie/configs/v8-4tube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const word velThreshold = 0; //ms
7373

7474
// What is the "frame rate" of the tube cleaning and display scrolling? up to 65535 ms
7575
const word cleanSpeed = 200; //ms
76-
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30 - to give the illusion of a slow scroll that doesn't pause, use (timeoutTempFn*1000)/(displaySize+1) - e.g. 714 for displaySize=6 and timeoutTempFn=5
76+
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30
7777

7878
// What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
7979
const unsigned long timeoutSet = 300; //sec

arduino-nixie/configs/v8-6tube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const word velThreshold = 0; //ms
7373

7474
// What is the "frame rate" of the tube cleaning and display scrolling? up to 65535 ms
7575
const word cleanSpeed = 200; //ms
76-
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30 - to give the illusion of a slow scroll that doesn't pause, use (timeoutTempFn*1000)/(displaySize+1) - e.g. 714 for displaySize=6 and timeoutTempFn=5
76+
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30
7777

7878
// What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
7979
const unsigned long timeoutSet = 300; //sec

arduino-nixie/configs/v9-6tube-relay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const word velThreshold = 0; //ms
7474

7575
// What is the "frame rate" of the tube cleaning and display scrolling? up to 65535 ms
7676
const word cleanSpeed = 200; //ms
77-
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30 - to give the illusion of a slow scroll that doesn't pause, use (timeoutTempFn*1000)/(displaySize+1) - e.g. 714 for displaySize=6 and timeoutTempFn=5
77+
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30
7878

7979
// What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
8080
const unsigned long timeoutSet = 300; //sec

arduino-nixie/configs/v9-6tube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const word velThreshold = 0; //ms
7474

7575
// What is the "frame rate" of the tube cleaning and display scrolling? up to 65535 ms
7676
const word cleanSpeed = 200; //ms
77-
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30 - to give the illusion of a slow scroll that doesn't pause, use (timeoutTempFn*1000)/(displaySize+1) - e.g. 714 for displaySize=6 and timeoutTempFn=5
77+
const word scrollSpeed = 100; //ms - e.g. scroll-in-and-out date at :30
7878

7979
// What are the timeouts for setting and temporarily-displayed functions? up to 65535 sec
8080
const unsigned long timeoutSet = 300; //sec

0 commit comments

Comments
 (0)