Add ZKNS-001 support, HID reliability fix

This commit is contained in:
Marc Riera 2023-04-23 23:20:53 +02:00
parent 029f5c7af3
commit 97a561f644
10 changed files with 256 additions and 114 deletions

View file

@ -1,4 +1,6 @@
use std::thread;
use std::thread::sleep;
use std::time::Duration;
use std::fs;
use std::fs::File;
use std::io::{Read, Write};
@ -6,6 +8,7 @@ use std::process::Command;
use std::path::Path;
use crate::controller::physical::ControllerState;
mod dgoc44u;
mod tcpp20009;
mod tcpp20011;
@ -14,6 +17,7 @@ mod sotp031201_p4b2b7;
mod sotp031201_p5b5;
mod sotp031201_p5b7;
mod vok00106;
mod zkns001;
const FFS_MOUNT: &str = "/tmp/ffs";
const ENDPOINT0: &str = "/tmp/ffs/ep0";
@ -30,6 +34,7 @@ pub enum ControllerModel {
SOTP031201P5B5,
SOTP031201P5B7,
VOK00106,
ZKNS001,
}
pub struct DeviceDescriptor {
@ -46,11 +51,16 @@ pub fn set_model(state: &ControllerState) -> Option<ControllerModel> {
let model;
let model_name;
let descriptors: (&DeviceDescriptor, &[u8], &[u8]);
if !state.button_right {
if state.button_right {
model_name = "DGOC44-U";
model = ControllerModel::DGOC44U;
descriptors = (&dgoc44u::DEVICE_DESCRIPTOR, &dgoc44u::DESCRIPTORS, &dgoc44u::STRINGS);
}
else if state.button_up {
model_name = "ZKNS-001";
model = ControllerModel::ZKNS001;
descriptors = (&zkns001::DEVICE_DESCRIPTOR, &zkns001::DESCRIPTORS, &zkns001::STRINGS);
}
else if state.button_d {
model_name = "TCPP-20009";
model = ControllerModel::TCPP20009;
@ -120,16 +130,24 @@ pub fn set_state(state: &mut ControllerState, model: &ControllerModel) {
ControllerModel::VOK00106 => {
vok00106::update_gadget(state);
}
ControllerModel::ZKNS001 => {
zkns001::update_gadget(state);
}
}
}
pub fn handle_ctrl_transfer(model: ControllerModel, data: &[u8]) {
if data[1] == 6 {
let report;
println!("CTRL TRANSFER: {:?}", data);
if data[1] == 6 && data[3] == 34 {
// Get HID report descriptor
let report: Option<&[u8]>;
match model {
ControllerModel::DGOC44U => {
report = Some(&dgoc44u::HID_REPORT_DESCRIPTOR);
}
ControllerModel::ZKNS001 => {
report = Some(&zkns001::HID_REPORT_DESCRIPTOR);
}
_ => {
report = None;
}
@ -143,8 +161,9 @@ pub fn handle_ctrl_transfer(model: ControllerModel, data: &[u8]) {
None => (),
}
}
else {
else if data[1] == 9 {
// Other control transfer, pass it to emulated controller loop
super::physical::set_lamp(true);
}
}
@ -173,8 +192,9 @@ fn init_gadget(model: &ControllerModel, (device, descriptors, strings): (&Device
// Control transfer received
handle_ctrl_transfer(controller_model, &buffer[0..8]);
}
}
// Wait between cycles
sleep(Duration::from_millis(10));
}
}
});