Skip to content

Commit 91a8f68

Browse files
committed
Adding h0051 manufacturing result command
1 parent de0578c commit 91a8f68

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

hid-io-kiibohd/src/lib.rs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,20 @@ pub unsafe extern "C" fn h0001_info_data(info: *mut HidioHostInfo) -> bool {
484484
}
485485
};
486486

487+
// Set string pointers
488+
intf.hostinfo.os_version = match CUtf8::from_str(intf.os_version.as_str()) {
489+
Ok(cstr) => cstr.as_bytes_with_nul().as_ptr() as *const c_char,
490+
Err(_) => {
491+
return false;
492+
}
493+
};
494+
intf.hostinfo.host_software_name = match CUtf8::from_str(intf.host_software_name.as_str()) {
495+
Ok(cstr) => cstr.as_bytes_with_nul().as_ptr() as *const c_char,
496+
Err(_) => {
497+
return false;
498+
}
499+
};
500+
487501
*info = intf.hostinfo.clone();
488502
true
489503
}
@@ -609,6 +623,46 @@ pub unsafe extern "C" fn hidio_h0034_terminalout(output: *const c_char) -> Hidio
609623
HidioStatus::Success
610624
}
611625

626+
/// # Safety
627+
/// Sends the result of a manufacturing test
628+
/// Will return an ACK, but this confirmation isn't used
629+
#[no_mangle]
630+
pub unsafe extern "C" fn hidio_h0051_manufacturingres(
631+
command: u16,
632+
argument: u16,
633+
data: *mut u8,
634+
len: u16,
635+
) -> HidioStatus {
636+
use h0051::*;
637+
638+
// Retrieve interface
639+
let intf = match INTF.as_mut() {
640+
Some(intf) => intf,
641+
None => {
642+
return HidioStatus::ErrorNotInitialized;
643+
}
644+
};
645+
646+
// Prepare data
647+
let data = match Vec::from_slice(core::slice::from_raw_parts(data, len as usize)) {
648+
Ok(vec) => vec,
649+
Err(_) => {
650+
return HidioStatus::ErrorBufSizeTooSmall;
651+
}
652+
};
653+
654+
// Send command
655+
if let Err(err) = intf.h0051_manufacturingres(Cmd {
656+
command,
657+
argument,
658+
data,
659+
}) {
660+
return intf.error_handler(err);
661+
}
662+
663+
HidioStatus::Success
664+
}
665+
612666
// ----- Command Interface -----
613667

614668
struct CommandInterface<
@@ -675,8 +729,8 @@ where
675729
minor_version: 0,
676730
patch_version: 0,
677731
os: 0,
678-
os_version: os_version.as_ptr() as *const c_char,
679-
host_software_name: host_software_name.as_ptr() as *const c_char,
732+
os_version: core::ptr::null(),
733+
host_software_name: core::ptr::null(),
680734
};
681735

682736
Ok(CommandInterface {
@@ -1095,4 +1149,8 @@ where
10951149
}
10961150
}
10971151
}
1152+
1153+
fn h0051_manufacturingres_ack(&mut self, _data: h0051::Ack) -> Result<(), CommandError> {
1154+
Ok(())
1155+
}
10981156
}

0 commit comments

Comments
 (0)