File tree Expand file tree Collapse file tree 1 file changed +37
-18
lines changed Expand file tree Collapse file tree 1 file changed +37
-18
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,42 @@ func watchTsEvents() {
193
193
}
194
194
}
195
195
196
+ // startBacklightTickers starts the two tickers for dimming and switching off the display
197
+ // if they're not already set. This is done separately to the init routine as the "never dim"
198
+ // option has the value set to zero, but time.NewTicker only accept positive values.
199
+ func startBacklightTickers () {
200
+ LoadConfig ()
201
+ if dim_ticker == nil && config .DisplayDimAfterSec != 0 {
202
+ fmt .Printf ("display: dim_ticker has started." )
203
+ dim_ticker = time .NewTicker (time .Duration (config .DisplayDimAfterSec ) * time .Second )
204
+ defer dim_ticker .Stop ()
205
+
206
+ go func () {
207
+ for {
208
+ select {
209
+ case <- dim_ticker .C :
210
+ tick_displayDim ()
211
+ }
212
+ }
213
+ }()
214
+ }
215
+
216
+ if off_ticker == nil && config .DisplayOffAfterSec != 0 {
217
+ fmt .Printf ("display: off_ticker has started." )
218
+ off_ticker = time .NewTicker (time .Duration (config .DisplayOffAfterSec ) * time .Second )
219
+ defer off_ticker .Stop ()
220
+
221
+ go func () {
222
+ for {
223
+ select {
224
+ case <- off_ticker .C :
225
+ tick_displayOff ()
226
+ }
227
+ }
228
+ }()
229
+ }
230
+ }
231
+
196
232
func init () {
197
233
go func () {
198
234
waitCtrlClientConnected ()
@@ -205,24 +241,7 @@ func init() {
205
241
requestDisplayUpdate ()
206
242
}()
207
243
208
- go func () {
209
- LoadConfig ()
210
- // Start display auto-sleeping tickers
211
- dim_ticker = time .NewTicker (time .Duration (config .DisplayDimAfterMs ) * time .Millisecond )
212
- defer dim_ticker .Stop ()
213
-
214
- off_ticker = time .NewTicker (time .Duration (config .DisplayOffAfterMs ) * time .Millisecond )
215
- defer off_ticker .Stop ()
216
-
217
- for {
218
- select {
219
- case <- dim_ticker .C :
220
- tick_displayDim ()
221
- case <- off_ticker .C :
222
- tick_displayOff ()
223
- }
224
- }
225
- }()
244
+ startBacklightTickers ()
226
245
227
246
go watchTsEvents ()
228
247
}
You can’t perform that action at this time.
0 commit comments