Skip to content

Commit 6410859

Browse files
committed
max7219: bugfixes for night shutoff to work properly
1 parent 1dc6ec7 commit 6410859

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

arduino-nixie/dispMAX7219.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@ void cycleDisplay(){
8383
if((unsigned long)(now-displayBlinkStart)>=500){ displayBlinkStart = 0; sendToMAX7219(0,5); }
8484
}
8585
//Other display code decides whether we should dim per function or time of day
86-
bool dim = (displayDim==1?1:0); //2 should also 0
86+
char dim = displayDim; //2=normal, 1=dim, 0=off
8787
//But if we're setting, decide here to dim for every other 500ms since we started setting
8888
if(fnSetPg>0) {
8989
if(setStartLast==0) setStartLast = now;
90-
dim = 1-(((unsigned long)(now-setStartLast)/500)%2);
90+
dim = (1-(((unsigned long)(now-setStartLast)/500)%2))+1;
9191
} else {
9292
if(setStartLast>0) setStartLast=0;
9393
}
94-
if(curBrightness!=(dim? BRIGHTNESS_DIM: BRIGHTNESS_FULL)){
95-
curBrightness = (dim? BRIGHTNESS_DIM: BRIGHTNESS_FULL);
96-
for(int i=0; i<NUM_MAX; i++) { lc.setIntensity(i,curBrightness); }
94+
if(curBrightness!=(dim==2? BRIGHTNESS_FULL: (dim==1? BRIGHTNESS_DIM: -1))){
95+
curBrightness = (dim==2? BRIGHTNESS_FULL: (dim==1? BRIGHTNESS_DIM: -1));
96+
if(curBrightness==-1) for(int i=0; i<NUM_MAX; i++) { lc.clearDisplay(i); }
97+
else for(int i=0; i<NUM_MAX; i++) { lc.setIntensity(i,curBrightness); }
9798
}
9899
}
99100

100101
void editDisplay(word n, byte posStart, byte posEnd, bool leadingZeros, bool fade){
102+
if(curBrightness==-1) return;
101103
//Splits n into digits, sets them into displayNext in places posSt-posEnd (inclusive), with or without leading zeros
102104
//If there are blank places (on the left of a non-leading-zero number), uses value 15 to blank tube
103105
//If number has more places than posEnd-posStart, the higher places are truncated off (e.g. 10015 on 4 tubes --> 0015)
@@ -114,13 +116,13 @@ void editDisplay(word n, byte posStart, byte posEnd, bool leadingZeros, bool fad
114116
}
115117
displayNext[posEnd-i] = (i==0&&n==0 ? 0 : (n>=place ? (n/place)%10 : (leadingZeros?0:15)));
116118
}
117-
cycleDisplay(); //fixes brightness
118119
sendToMAX7219(posStart,posEnd);
120+
cycleDisplay(); //fixes brightness
119121
}
120122
void blankDisplay(byte posStart, byte posEnd, byte fade){
121123
for(byte i=posStart; i<=posEnd; i++) { displayNext[i]=15; }
122-
cycleDisplay(); //fixes brightness
123124
sendToMAX7219(posStart,posEnd);
125+
cycleDisplay(); //fixes brightness
124126
}
125127

126128
//void startScroll() {}

0 commit comments

Comments
 (0)