Skip to content

Commit

Permalink
feat: added UG slider to control brightness (#450)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Parcet <alex@dygma.com>
  • Loading branch information
AlexDygma authored Jun 23, 2023
1 parent 7a258e7 commit 0e72cc1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/renderer/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,9 @@ const English = {
},
led: {
title: "LED",
brightness: "LED brightness",
brightness: "LED backlight brightness",
brightnesssub: " - From 0 to 254",
brightnessUG: "LED underglow brightness",
idleDisabled: "Disabled",
idleTimeLimit: "Time before LEDs turn off",
idle: {
Expand Down
36 changes: 36 additions & 0 deletions src/renderer/modules/Settings/KeyboardSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ class KeyboardSettings extends React.Component {
}));
this.props.setKbData(this.state);
};

setBrightnessUG = async value => {
await this.setState(state => ({
ledBrightnessUG: (value * 255) / 100,
modified: true
}));
this.props.setKbData(this.state);
};

setHoldTimeout = async value => {
await this.setState(state => ({
qukeysHoldTimeout: value,
Expand Down Expand Up @@ -424,6 +433,7 @@ class KeyboardSettings extends React.Component {
modified,
showDefaults,
ledBrightness,
ledBrightnessUG,
ledIdleTimeLimit,
qukeysHoldTimeout,
qukeysOverlapThreshold,
Expand Down Expand Up @@ -570,6 +580,32 @@ class KeyboardSettings extends React.Component {
</Row>
</Form.Group>
)}
{ledBrightnessUG >= 0 && (
<Form.Group controlId="brightnessUGControl" className="formGroup">
<Row>
<Col>
<Form.Label>{i18n.keyboardSettings.led.brightnessUG}</Form.Label>
</Col>
</Row>
<Row>
<Col xs={2} md={1} className="p-0 text-center align-self-center">
<span className="tagsfix">None</span>
</Col>
<Col xs={8} md={10} className="px-2">
<Slider
min={0}
max={100}
step={5}
value={Math.round((ledBrightnessUG * 100) / 255)}
onChange={this.setBrightnessUG}
/>
</Col>
<Col xs={2} md={1} className="p-0 text-center align-self-center">
<span className="tagsfix">Max</span>
</Col>
</Row>
</Form.Group>
)}
</Card.Body>
</Card>
<Card className="overflowFix card-preferences mt-4">
Expand Down
17 changes: 9 additions & 8 deletions src/renderer/views/Preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Preferences extends React.Component {
onlyCustom: true
},
ledBrightness: 255,
ledBrightnessUG: 255,
defaultLayer: 126,
ledIdleTimeLimit: 0,
qukeysHoldTimeout: 0,
Expand Down Expand Up @@ -144,6 +145,11 @@ class Preferences extends React.Component {
this.kbData.ledBrightness = brightness;
});

await focus.command("led.brightnessUG").then(brightness => {
brightness = brightness ? parseInt(brightness) : -1;
this.kbData.ledBrightnessUG = brightness;
});

await focus.command("idleleds.time_limit").then(limit => {
this.kbData.ledIdleTimeLimit = limit ? parseInt(limit) : -1;
});
Expand Down Expand Up @@ -274,11 +280,6 @@ class Preferences extends React.Component {
await focus.command("wireless.rf.stability").then(rfStability => {
this.kbData.wireless.rf.stability = rfStability;
});

// Additional commands
await focus.command("led.brightness.underglow").then(UGBrightness => {
this.kbData.ledBrightnessUG = UGBrightness;
});
}

//Save in state
Expand All @@ -293,6 +294,7 @@ class Preferences extends React.Component {
defaultLayer,
showDefaults,
ledBrightness,
ledBrightnessUG,
ledIdleTimeLimit,
qukeysHoldTimeout,
qukeysOverlapThreshold,
Expand All @@ -308,13 +310,13 @@ class Preferences extends React.Component {
mouseWheelSpeed,
mouseWheelDelay,
mouseSpeedLimit,
wireless,
ledBrightnessUG
wireless
} = this.kbData;

await await focus.command("keymap.onlyCustom", keymap.onlyCustom);
await await focus.command("settings.defaultLayer", defaultLayer);
await await focus.command("led.brightness", ledBrightness);
await await focus.command("led.brightnessUG", ledBrightnessUG);
if (ledIdleTimeLimit >= 0) await await focus.command("idleleds.time_limit", ledIdleTimeLimit);
store.set("settings.showDefaults", showDefaults);
// QUKEYS
Expand Down Expand Up @@ -348,7 +350,6 @@ class Preferences extends React.Component {
await await focus.command("wireless.rf.channelHop", wireless.rf.channelHop);
await await focus.command("wireless.rf.state", wireless.rf.state);
await await focus.command("wireless.rf.stability", wireless.rf.stability);
await await focus.command("led.brightness.underglow", ledBrightnessUG);
}

//TODO: Review toast popup on try/catch works well.
Expand Down

0 comments on commit 0e72cc1

Please # to comment.