mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 03:06:38 +00:00
Keep leds sysfs files open
Change-type: patch
This commit is contained in:
parent
cb8168de41
commit
227bad9e99
@ -21,17 +21,26 @@ import * as settings from './settings';
|
||||
import { observe } from './store';
|
||||
|
||||
class Led {
|
||||
private handle: fs.FileHandle;
|
||||
private lastValue?: number;
|
||||
|
||||
constructor(private path: string) {}
|
||||
|
||||
private async open() {
|
||||
if (this.handle === undefined) {
|
||||
this.handle = await fs.open(this.path, 'w');
|
||||
}
|
||||
}
|
||||
|
||||
public async setIntensity(intensity: number) {
|
||||
if (intensity < 0 || intensity > 1) {
|
||||
throw new Error('Led intensity must be between 0 and 1');
|
||||
}
|
||||
const value = Math.round(intensity * 255);
|
||||
if (value !== this.lastValue) {
|
||||
await fs.writeFile(this.path, value.toString());
|
||||
await this.open();
|
||||
await this.handle.write(value.toString(), 0);
|
||||
// On a regular file we would also need to truncate to the written value length but it looks like it's not the case on sysfs files
|
||||
this.lastValue = value;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user