@@ -172,13 +172,14 @@ func rpcTryUpdate() error {
172
172
return nil
173
173
}
174
174
175
- func rpcSetBacklightSettings (data * BacklightSettings ) error {
175
+ func rpcSetBacklightSettings (params BacklightSettings ) error {
176
176
LoadConfig ()
177
177
178
- blConfig := * data
178
+ blConfig := params
179
179
180
- if blConfig .MaxBrightness > 100 || blConfig .MaxBrightness < 0 {
181
- return fmt .Errorf ("maxBrightness must be between 0 and 100" )
180
+ // NOTE: by default, the frontend limits the brightness to 64, as that's what the device originally shipped with.
181
+ if blConfig .MaxBrightness > 255 || blConfig .MaxBrightness < 0 {
182
+ return fmt .Errorf ("maxBrightness must be between 0 and 255" )
182
183
}
183
184
184
185
if blConfig .DimAfter < 0 {
@@ -190,12 +191,24 @@ func rpcSetBacklightSettings(data *BacklightSettings) error {
190
191
}
191
192
192
193
config .DisplayMaxBrightness = blConfig .MaxBrightness
193
- config .DisplayDimAfterMs = int64 ( blConfig .DimAfter )
194
- config .DisplayOffAfterMs = int64 ( blConfig .OffAfter )
194
+ config .DisplayDimAfterSec = blConfig .DimAfter
195
+ config .DisplayOffAfterSec = blConfig .OffAfter
195
196
196
197
if err := SaveConfig (); err != nil {
197
198
return fmt .Errorf ("failed to save config: %w" , err )
198
199
}
200
+
201
+ log .Printf ("rpc: display: settings applied, max_brightness: %d, dim after: %ds, off after: %ds" , config .DisplayMaxBrightness , config .DisplayDimAfterSec , config .DisplayOffAfterSec )
202
+
203
+ // If the device started up with auto-dim and/or auto-off set to zero, the display init
204
+ // method will not have started the tickers. So in case that has changed, attempt to start the tickers now.
205
+ startBacklightTickers ()
206
+
207
+ // Wake the display after the settings are altered, this ensures the tickers
208
+ // are reset to the new settings, and will bring the display up to maxBrightness.
209
+ // Calling with force set to true, to ignore the current state of the display, and force
210
+ // it to reset the tickers.
211
+ wakeDisplay (true )
199
212
return nil
200
213
}
201
214
@@ -204,8 +217,8 @@ func rpcGetBacklightSettings() (*BacklightSettings, error) {
204
217
205
218
return & BacklightSettings {
206
219
MaxBrightness : config .DisplayMaxBrightness ,
207
- DimAfter : int (config .DisplayDimAfterMs ),
208
- OffAfter : int (config .DisplayOffAfterMs ),
220
+ DimAfter : int (config .DisplayDimAfterSec ),
221
+ OffAfter : int (config .DisplayOffAfterSec ),
209
222
}, nil
210
223
}
211
224
@@ -448,6 +461,6 @@ var rpcHandlers = map[string]*jsonrpc.RPCHandler{
448
461
"pluginList" : {Func : plugin .RpcPluginList },
449
462
"pluginUpdateConfig" : {Func : plugin .RpcPluginUpdateConfig , Params : []string {"name" , "enabled" }},
450
463
"pluginUninstall" : {Func : plugin .RpcPluginUninstall , Params : []string {"name" }},
451
- "setBacklightSettings" : {Func : rpcSetBacklightSettings , Params : []string {"settings " }},
464
+ "setBacklightSettings" : {Func : rpcSetBacklightSettings , Params : []string {"params " }},
452
465
"getBacklightSettings" : {Func : rpcGetBacklightSettings },
453
466
}
0 commit comments