Generalize input module to mouse and joystick/gamepad events
Extend the input service beyond the keyboard so mouse and joystick/gamepad drivers can broadcast too, with per-device publish and subscribe methods. - protocol: KeyEvent joins MouseEvent (motion/buttons/scroll) and JoystickEvent (axes/buttons), all carried in a common InputEvent envelope tagged with a DeviceKind. A subscribe request carries a device_mask, so a subscriber names the classes it wants and the service routes each event only to interested subscribers (a mouse-only listener never wakes for keystrokes). - runtime: per-device publish methods (publishKeyboardEvent/publishMouseEvent/ publishJoystickEvent) and subscribe helpers (subscribeKeyboard/Mouse/Joystick, each typed, plus subscribe(mask)/subscribeAll returning the tagged envelope). - service: subscriber table gains a device_mask; broadcast routes by the event's device class. - mouse driver now publishes (synthetic) mouse events like the keyboard driver; input-source cycles all three classes; input-test subscribes to all and only emits its "ok" marker once it has received one of each class — so the passing test proves per-device routing, not just delivery. Real HID decoding stays a follow-up. No kernel changes: ipc_send is generic and the 36-byte InputEvent fits its 64-byte payload. Full QEMU suite 48/48; serial log confirms keyboard, mouse, and joystick all reach one subscription.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
//! system/services/input-source — a hardware-free synthetic keyboard source, used to
|
||||
//! exercise the input service end to end without a real PS/2 controller (the `input` test
|
||||
//! case, and any bring-up where there is no keyboard). It stands in for a driver: it
|
||||
//! connects to the input service and `publish`es a rolling stream of key events, which the
|
||||
//! service broadcasts to every subscriber.
|
||||
//! system/services/input-source — a hardware-free synthetic input source, used to exercise
|
||||
//! the input service end to end without a real PS/2 controller (the `input` test case, and
|
||||
//! any bring-up where there is no hardware). It stands in for a driver: it connects to the
|
||||
//! input service and publishes a rolling stream that cycles through all device classes —
|
||||
//! keyboard, mouse, and joystick/gamepad — which the service routes to interested
|
||||
//! subscribers.
|
||||
//!
|
||||
//! It stays silent after startup (no per-event logging) so it can share the boot serial
|
||||
//! transcript with a subscriber whose output is the test's success marker. The real
|
||||
//! keyboard driver publishes the same synthetic stream today; swapping in decoded
|
||||
//! scancodes is a follow-up (see docs/input.md).
|
||||
//! keyboard and mouse drivers publish their own synthetic streams today; swapping in
|
||||
//! decoded hardware is a follow-up (see docs/input.md).
|
||||
|
||||
const runtime = @import("runtime");
|
||||
const input = runtime.input;
|
||||
@@ -18,11 +19,17 @@ pub fn main() void {
|
||||
_ = system.write("input-source: input service unavailable\n");
|
||||
return;
|
||||
};
|
||||
_ = system.write("input-source: publishing synthetic key events\n");
|
||||
_ = system.write("input-source: publishing synthetic input events\n");
|
||||
|
||||
var step: usize = 0;
|
||||
while (true) : (step +%= 1) {
|
||||
_ = source.publish(input.syntheticEvent(step));
|
||||
// Rotate across the device classes so every publish path (and the service's
|
||||
// per-device routing) is exercised.
|
||||
switch (step % 3) {
|
||||
0 => _ = source.publishKeyboardEvent(input.syntheticKeyEvent(step)),
|
||||
1 => _ = source.publishMouseEvent(input.syntheticMouseEvent(step)),
|
||||
else => _ = source.publishJoystickEvent(input.syntheticJoystickEvent(step)),
|
||||
}
|
||||
system.sleep(200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user