Repository navigation
feat(mchose): support the Ace 68 V2 III keyboard #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
66de082
3daf1c5
bfcf485
46f1367
551cbbb
4761cab
47b2043
d20c255
b073ed3
8d77666
702bfef
24f3e12
310700f
a75356e
45013c1
b989764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import { invoke } from "@tauri-apps/api/core"; | ||
| import { VIA_USAGE, VIA_USAGE_PAGE } from "@openmouse/keyboard-protocol/via"; | ||
| import { WUQUE_FEATURES, wuqueOp } from "./keyboard-wuque"; | ||
| import { isMchoseKeyboardControl, MCHOSE_FEATURES, mchoseOp, mchoseSections, writeMchoseKeyboard } from "./keyboard-mchose"; | ||
| import { DEVICE_DRIVERS, type DeviceDriver } from "@openmouse/keyboard-protocol/drivers/registry"; | ||
| import { SUPPORTED_HID_FILTERS } from "@openmouse/keyboard-protocol/drivers/vendors"; | ||
| import { listHidInterfaces, TauriHidDevice, type HidInterfaceInfo } from "./native-hid/tauri-hid-device"; | ||
|
|
@@ -171,7 +172,7 @@ export function describeKeyboard(key: string, brand: string, status: any) { | |
| status: { | ||
| ...status, | ||
| firmware: version ? [version] : status.firmware ?? [], | ||
| keyboardFeatures: brand === "Wuque Studio" ? WUQUE_FEATURES : null, | ||
| keyboardFeatures: brand === "Wuque Studio" ? WUQUE_FEATURES : brand === "MCHOSE" ? MCHOSE_FEATURES : null, | ||
| }, | ||
| controls: null, | ||
| tabs: { | ||
|
|
@@ -189,7 +190,7 @@ export async function connectKeyboard(info: KeyboardInterface) { | |
| const rates = status.logitech ?? await polling(client); | ||
| const sections = status.logitech?.onboardMemory | ||
| ? await logitechKeyboardSections(client, info.key, status.logitech) | ||
| : []; | ||
| : brand === "MCHOSE" ? await mchoseSections(client) : []; | ||
| const readout = describeKeyboard(info.key, brand, { | ||
| ...status, pollingRateHz: rates.pollingRateHz, supportedPollingRates: rates.supportedPollingRates, | ||
| // These controls are offered only after the hardware returns a profile. | ||
|
|
@@ -200,11 +201,12 @@ export async function connectKeyboard(info: KeyboardInterface) { | |
| }); | ||
| } | ||
|
|
||
| /** Keys, actuation and lighting, where this app can change them. */ | ||
| /** Keys, actuation and lighting, where this app can change them (Wuque Studio; MCHOSE lighting). */ | ||
| export async function keyboardOp(info: HidInterfaceInfo, op: string, args: any): Promise<unknown> { | ||
| return withKeyboard(info, async (client, brand) => { | ||
| if (brand !== "Wuque Studio") throw new Error("This app can't change that on this keyboard yet."); | ||
| return wuqueOp(client, op, args); | ||
| if (brand === "Wuque Studio") return wuqueOp(client, op, args); | ||
| if (brand === "MCHOSE") return mchoseOp(client, op, args); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Read calibration status without acquiring the device lock. The status handler reads only in-memory state. This route still acquires the device lock and waits for
|
||
| throw new Error("This app can't change that on this keyboard yet."); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -220,6 +222,15 @@ export async function writeKeyboard(info: KeyboardInterface, action: string, val | |
| return { tabs: { ...readout.tabs, advanced: [...sections, ...readout.tabs.advanced] } }; | ||
| }); | ||
| } | ||
| if (isMchoseKeyboardControl(action)) { | ||
| return withKeyboard(info, async (client, brand) => { | ||
| if (brand !== "MCHOSE") throw new Error("This control requires an MCHOSE keyboard."); | ||
| await writeMchoseKeyboard(client, action, value); | ||
| const status = await client.readStatus(); | ||
|
onyxhq-dev marked this conversation as resolved.
Resolved
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| const readout = describeKeyboard(info.key, brand, status); | ||
| return { tabs: { ...readout.tabs, advanced: [...await mchoseSections(client), ...readout.tabs.advanced] } }; | ||
| }); | ||
| } | ||
| if (action !== "pollingRate") throw new Error("This app can't change that on a keyboard yet."); | ||
| return withKeyboard(info, async (client, brand) => { | ||
| if (brand === "Logitech") { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -414,7 +414,8 @@ impl AppView { | |
| Ok(Ok(applied)) => { | ||
| // Keyboard profile edits return verified tabs with canonical values. | ||
| // The typed expression may differ from the value stored by the device. | ||
| let confirmed_tabs = id.starts_with("logi.keyboard."); | ||
| let confirmed_tabs = id.starts_with("logi.keyboard.") | ||
| || (id.starts_with("mchose.kb.") && applied.get("tabs").is_some()); | ||
| if !confirmed_tabs { | ||
| expected.push(Expected { action: format!("control:{id}"), value: value.clone() }); | ||
| } | ||
|
|
@@ -427,6 +428,9 @@ impl AppView { | |
| r.tabs = tabs; | ||
|
onyxhq-dev marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
| if id == "mchose.kb.calibrate" { | ||
| v.follow_calibration(key.clone(), cx); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep one progress poller across Start over. Start launches a poller. A successful Start over launches another, and the first keeps running because the same control still shows Running. Each restart adds device requests. Track the active poller by device and reuse it on Start over, or cancel it before launching another.
|
||
| } | ||
| // A Logitech button: reflect it in the stored profile we hold. | ||
| if let Some(n) = id.strip_prefix("logi.button.primary.").and_then(|n| n.parse::<usize>().ok()) { | ||
| if let Some(running) = v | ||
|
|
@@ -463,6 +467,38 @@ impl AppView { | |
| .detach(); | ||
| } | ||
|
|
||
| /// While a keyboard calibration runs, refreshes its progress line twice a second. | ||
| fn follow_calibration(&mut self, key: String, cx: &mut Context<Self>) { | ||
| let service = self.hid_service(); | ||
| cx.spawn(async move |view, cx| { | ||
| loop { | ||
| cx.background_executor().timer(std::time::Duration::from_millis(500)).await; | ||
| let control = service.keyboard(&key, "calibrationStatus", serde_json::json!({})).await; | ||
| let Ok(Ok(control)) = control else { continue }; | ||
|
macroscopeapp[bot] marked this conversation as resolved.
Resolved
|
||
| let Ok(control) = serde_json::from_value::<crate::hid::ControlSpec>(control) else { continue }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| let running = control.options.first().is_some_and(|o| o.label.starts_with("Running")); | ||
| let alive = view | ||
| .update(cx, |v: &mut Self, cx| { | ||
| let Some(tile) = v.devices.tiles.iter_mut().find(|t| t.key == key) else { return false }; | ||
| let TileStatus::Connected(r) = &mut tile.status else { return false }; | ||
| let Some(slot) = r.tabs.controls_mut().find(|c| c.id == control.id) else { return false }; | ||
| // Only while the page still shows a running calibration (a later reload ends this). | ||
| if !slot.options.first().is_some_and(|o| o.label.starts_with("Running")) && running { | ||
| return false; | ||
| } | ||
| *slot = control.clone(); | ||
| cx.notify(); | ||
| true | ||
| }) | ||
| .unwrap_or(false); | ||
| if !alive || !running { | ||
| break; | ||
| } | ||
| } | ||
| }) | ||
| .detach(); | ||
| } | ||
|
|
||
| /// The lighting as it would be written now: staged fields over the device's. | ||
| pub(super) fn effective_lighting(&self, spec: &crate::hid::LightingSpec) -> serde_json::Value { | ||
| let e = &self.devices.staged.light; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.