Skip to content

Commit

Permalink
Enabled wireless view communications with the keyboard
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Parcet <[email protected]>
  • Loading branch information
AlexDygma committed Jun 27, 2023
1 parent c9797cc commit 0eb773c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
20 changes: 15 additions & 5 deletions src/renderer/modules/Settings/BatterySettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ padding-top: 24px;
}
`;

const BatterySettings = ({ bLeft, bRight, isSavingMode, setIsSavingMode, isCharging }) => {
const BatterySettings = ({ wireless, toggleSavingMode, changeWireless }) => {
return (
<Styles>
<Card className="overflowFix card-preferences">
Expand All @@ -51,16 +51,26 @@ const BatterySettings = ({ bLeft, bRight, isSavingMode, setIsSavingMode, isCharg
</Card.Title>
<Card.Body className="py-0">
<div className="battery-defy--indicator">
<BatteryStatusSide side="left" batteryLevel={bLeft} size="lg" isSavingMode={isSavingMode} isCharging={isCharging} />
<BatteryStatusSide side="right" batteryLevel={bRight} size="lg" isSavingMode={isSavingMode} isCharging={isCharging} />
<BatteryStatusSide
side="left"
batteryLevel={wireless.battery ? wireless.battery.LeftLevel : 100}
isSavingMode={wireless.battery ? wireless.battery.savingMode : false}
size="lg"
/>
<BatteryStatusSide
side="right"
batteryLevel={wireless.battery ? wireless.battery.RightLevel : 100}
isSavingMode={wireless.battery ? wireless.battery.savingMode : false}
size="lg"
/>
</div>
<Form className="batterySettingItem batterySetSavingMode">
<div className="batterySettingLabel">Saving Mode</div>
<Form.Check
type="switch"
id="settingSavingMode"
checked={isSavingMode}
onChange={() => setIsSavingMode(!isSavingMode)}
checked={wireless.battery ? wireless.battery.savingMode : false}
onChange={toggleSavingMode}
/>
</Form>
<div
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/modules/Settings/RFSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ padding-top: 24px;
}
`;

const RFSettings = props => {
const RFSettings = ({ sendRePair, wireless, changeWireless }) => {
return (
<Styles>
<Card className="overflowFix card-preferences">
Expand All @@ -47,7 +47,7 @@ const RFSettings = props => {
<Title text={i18n.wireless.RFPreferences.repairChannel} headingLevel={4} />
<RegularButton
buttonText={i18n.wireless.RFPreferences.reconnectSides}
onClick={() => console.log("CLick!")}
onClick={sendRePair}
style="outline gradient"
size="sm"
/>
Expand Down
44 changes: 26 additions & 18 deletions src/renderer/views/Wireless.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const Styles = Styled.div`
const Wireless = ({ inContext, connected, allowBeta, updateAllowBeta, cancelContext, startContext }) => {
const [wireless, setWireless] = useState({});
const [modified, setModified] = useState(false);
const [isSavingMode, setIsSavingMode] = useState(false);
const [isCharging, setIsCharging] = useState(false);
const [loading, setLoading] = useState(true);

useEffect(() => {
Expand All @@ -46,20 +44,34 @@ const Wireless = ({ inContext, connected, allowBeta, updateAllowBeta, cancelCont
console.log("command returned", result);
}

async function toggleSavingMode() {
let focus = new Focus();
await focus.command("wireless.battery.savingMode", !wireless.battery.savingMode);
let newWireless = { ...wireless };
newWireless.battery.savingMode = !wireless.battery.savingMode;
setWireless(newWireless);
}

async function destroyContext() {
setWireless({});
setModified(false);
getWirelessPreferences();
cancelContext();
}

async function changeWireless(wireless) {
setWireless(wireless);
if (!modified) {
setModified(true);
startContext();
}
}

async function saveWirelessChanges() {
const focus = new Focus();

// Commands to be sent to the keyboard
await focus.command("wireless.battery.level", wireless.battery.level);
await focus.command("wireless.battery.state", wireless.battery.state);
await focus.command("wireless.battery.mode", wireless.battery.mode);
await focus.command("wireless.battery.savingMode", wireless.battery.savingMode);
await focus.command("wireless.energy.modes", wireless.energy.modes);
await focus.command("wireless.energy.currentMode", wireless.energy.currentMode);
await focus.command("wireless.energy.disable", wireless.energy.disable);
Expand All @@ -84,11 +96,14 @@ const Wireless = ({ inContext, connected, allowBeta, updateAllowBeta, cancelCont
await focus.command("wireless.battery.right.level").then(batteryLevel => {
wireless.battery.RightLevel = batteryLevel ? parseInt(batteryLevel) : 100;
});
await focus.command("wireless.battery.state").then(batteryState => {
wireless.battery.state = batteryState;
await focus.command("wireless.battery.left.state").then(state => {
wireless.battery.LeftState = state ? parseInt(state) : 0;
});
await focus.command("wireless.battery.right.state").then(state => {
wireless.battery.RightState = state ? parseInt(state) : 0;
});
await focus.command("wireless.battery.mode").then(batteryMode => {
wireless.battery.mode = batteryMode;
await focus.command("wireless.battery.savingMode").then(batteryMode => {
wireless.battery.savingMode = batteryMode;
});

// Energy commands
Expand Down Expand Up @@ -147,17 +162,10 @@ const Wireless = ({ inContext, connected, allowBeta, updateAllowBeta, cancelCont
<div className="wirelessInner">
<Row>
<Col md={6}>
<BatterySettings
bLeft={wireless.battery ? wireless.battery.LeftLevel : 100}
bRight={wireless.battery ? wireless.battery.RightLevel : 100}
isSavingMode={isSavingMode}
setIsSavingMode={setIsSavingMode}
isCharging={isCharging}
setModified={setModified}
/>
<BatterySettings wireless={wireless} changeWireless={changeWireless} toggleSavingMode={toggleSavingMode} />
</Col>
<Col md={6}>
<RFSettings />
<RFSettings wireless={wireless} changeWireless={changeWireless} sendRePair={sendRePairCommand} />
</Col>
</Row>
</div>
Expand Down

0 comments on commit 0eb773c

Please sign in to comment.