Half-arsed visuals for virtual anime

This commit is contained in:
Luke D. Jones
2023-05-02 16:42:21 +12:00
parent 2a38f69cc4
commit 002dc8516d
8 changed files with 530 additions and 23 deletions

View File

@@ -21,11 +21,6 @@ detect = ["sysfs-class"]
name = "rog_anime"
path = "src/lib.rs"
[[bin]]
name = "anime_sim"
path = "src/simulator.rs"
[dependencies]
png_pong.workspace = true
pix.workspace = true
@@ -41,7 +36,5 @@ zbus = { workspace = true, optional = true }
sysfs-class = { workspace = true, optional = true }
uhid-virt = "^0.0.6"
[dev-dependencies]
cargo-husky.workspace = true

View File

@@ -19,11 +19,11 @@ const BLOCK_END: usize = 634;
const PANE_LEN: usize = BLOCK_END - BLOCK_START;
/// First packet is for GA401 + GA402
const USB_PREFIX1: [u8; 7] = [0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02];
pub const USB_PREFIX1: [u8; 7] = [0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02];
/// Second packet is for GA401 + GA402
const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02];
pub const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02];
/// Third packet is for GA402 matrix
const USB_PREFIX3: [u8; 7] = [0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02];
pub const USB_PREFIX3: [u8; 7] = [0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02];
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]

View File

@@ -1,126 +0,0 @@
use std::error::Error;
use log::error;
use rog_anime::usb::{PROD_ID, VENDOR_ID};
use uhid_virt::{Bus, CreateParams, UHIDDevice};
pub struct VirtAnimeMatrix {
device: UHIDDevice<std::fs::File>,
}
impl Default for VirtAnimeMatrix {
fn default() -> Self {
Self::new()
}
}
impl VirtAnimeMatrix {
pub fn new() -> Self {
VirtAnimeMatrix {
device: UHIDDevice::create(CreateParams {
name: String::from("ROG_Virtual Anime Matrix"),
phys: String::from(""),
uniq: String::from(""),
bus: Bus::USB,
vendor: VENDOR_ID as u32,
product: PROD_ID as u32,
version: 0,
country: 0,
// This is a device which emits the usage code as a whole, rather than as bits
rd_data: [
0x06, 0x31, 0xff, // Usage Page (Vendor Defined 0xFF31)
0x09, 0x76, // Usage (0x76)
0xa1, 0x01, // Collection (Application)
0x85, 0x5a, // Report ID (90)
0x19, 0x00, // Usage Minimum (0x00)
0x2a, 0xff, 0x00, // Usage Maximum (0xFF)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xff, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x05, // Report Count (5)
0x81,
0x00, /* Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null
* Position) */
0x19, 0x00, // Usage Minimum (0x00)
0x2a, 0xff, 0x00, // Usage Maximum (0xFF)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xff, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x3f, // Report Count (63)
0xb1,
0x00, /* Feature (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null
* Position,Non-volatile) */
0xc0, // End Collection
0x06, 0x31, 0xff, // Usage Page (Vendor Defined 0xFF31)
0x09, 0x80, // Usage (0x80)
0xa1, 0x01, // Collection (Application)
0x85, 0x5e, // Report ID (94)
0x19, 0x00, // Usage Minimum (0x00)
0x2a, 0xff, 0x00, // Usage Maximum (0xFF)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xff, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x05, // Report Count (5)
0x81,
0x00, /* Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null
* Position) */
0x19, 0x00, // Usage Minimum (0x00)
0x2a, 0xff, 0x00, // Usage Maximum (0xFF)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xff, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x96, 0x7f, 0x02, // Report Count (639)
0xb1,
0x00, /* Feature (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null
* Position,Non-volatile) */
0xc0, /* End Collection */
/* 85 bytes */
]
.to_vec(),
})
.map_err(|err| error!("Could not create virtual device: {:?}", err))
.expect("Could not create virtual device"),
}
}
/// A single on/off key press
pub fn press(&mut self, input: [u8; 32]) {
self.device.write(&input).unwrap();
let mut reset = [0u8; 32];
reset[0] = input[0];
self.device.write(&reset).unwrap();
}
pub fn read(&mut self) {
if let Ok(event) = self.device.read() {
match event {
// uhid_virt::OutputEvent::Start { dev_flags } => todo!(),
// uhid_virt::OutputEvent::Stop => todo!(),
// uhid_virt::OutputEvent::Open => todo!(),
// uhid_virt::OutputEvent::Close => todo!(),
uhid_virt::OutputEvent::Output { data } => {
dbg!(data);
}
uhid_virt::OutputEvent::GetReport {
id,
report_number,
report_type,
} => {
dbg!(id, report_number, report_type);
}
// uhid_virt::OutputEvent::SetReport { id, report_number, report_type, data } =>
// todo!(),
_ => {}
}
}
}
}
fn main() -> Result<(), Box<dyn Error>> {
let mut dev = VirtAnimeMatrix::new();
loop {
dev.read();
}
}