Skip to content

Commit

Permalink
ddcci-multi-monitor@tim-we: Retry setting brightness and raise timeouts
Browse files Browse the repository at this point in the history
Add a retry mechanism for setting the brightness (currently 16 times) and raise some timeouts (5s setting brightness, 500ms querying brightness)
  • Loading branch information
qwertz19281 committed Sep 18, 2024
1 parent 9801a22 commit 558121e
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Monitor {
this.index = index;
this.name = name;
this.brightness = 50;
this.send_brightness = null;
this.sent_brightness = null;
this.bus = bus;
this.menuLabel = null;
this.menuSlider = null;
Expand All @@ -50,7 +52,7 @@ class Monitor {
const cmd = `ddcutil --bus=${this.bus} getvcp 10`;
Util.spawnCommandLineAsyncIO(cmd, (stdout, stderr, exitCode) => {
// guarantee resolve, even if the following code fails
setTimeout(resolve, 10);
setTimeout(resolve, 500);

if (exitCode == 0) {
// regex from ddcci-monitor-control@andr35
Expand Down Expand Up @@ -82,18 +84,44 @@ class Monitor {

setBrightness(value) {
this.brightness = Math.round(value);
this.send_brightness = this.brightness;
this.updateMenu();
this.#promises = this.#promises.then(() => {
return new Promise((resolve, reject) => {
Util.spawnCommandLineAsync(
`ddcutil --bus=${this.bus} setvcp 10 ${this.brightness}`,
resolve,
reject
);
setTimeout(resolve, 5000);
log(`trySetBrightness start`);
this.trySetBrightness(resolve, reject, 16);
});
});
}

trySetBrightness(resolve, reject, attempts) {
log(`trySetBrightness attempt ${attempts}`);
if (attempts <= 0) {
log(`trySetBrightness out of attempts`);
return resolve();
}
const target_brightness = this.send_brightness;
log(`trySetBrightness target=${target_brightness} sent=${this.sent_brightness}`);
if (target_brightness !== this.sent_brightness) {
Util.spawnCommandLineAsync(
`ddcutil --bus=${this.bus} setvcp 10 ${target_brightness}`,
() => {
log(`trySetBrightness success (target=${target_brightness})`);
this.sent_brightness = target_brightness;
resolve();
},
() => {
log(`trySetBrightness fail (target=${target_brightness})`);
this.trySetBrightness(resolve, reject, attempts - 1);
},
);
} else {
log(`trySetBrightness resolve`);
resolve();
}
}

addToMenu(menu) {
// create & add label
const menuLabel = new PopupMenu.PopupMenuItem(this.name, {
Expand Down

0 comments on commit 558121e

Please sign in to comment.