Skip to content

Commit

Permalink
Fixes for PixelSetting and DirectSet capnp rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
haata committed Oct 6, 2022
1 parent c742cf7 commit 5394d79
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
17 changes: 10 additions & 7 deletions examples/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,10 @@ async fn try_main() -> Result<(), ::capnp::Error> {
hidio_capnp::node::pixel_setting::ControlArg::Disable
}
Some(("enable-pause", _)) => {
hidio_capnp::node::pixel_setting::ControlArg::EnableStart
hidio_capnp::node::pixel_setting::ControlArg::EnablePause
}
Some(("enable-start", _)) => {
hidio_capnp::node::pixel_setting::ControlArg::EnablePause
hidio_capnp::node::pixel_setting::ControlArg::EnableStart
}
_ => todo!(),
};
Expand Down Expand Up @@ -690,14 +690,17 @@ async fn try_main() -> Result<(), ::capnp::Error> {
let node = node?;

// Retrieve arguments
let start_address: u16 = *submatches
.get_one::<u16>("START_ADDRESS")
.expect("Required");
let start_address: u16 = u16::try_from(
*submatches
.get_one::<u64>("START_ADDRESS")
.expect("Required"),
)
.unwrap();
let data: Vec<u8> = submatches
.get_many::<u8>("DATA")
.get_many::<u64>("DATA")
.into_iter()
.flatten()
.copied()
.map(|val| u8::try_from(*val).unwrap())
.collect::<Vec<_>>();

let direct_resp = {
Expand Down
22 changes: 11 additions & 11 deletions hid-io-protocol/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,13 +1735,13 @@ pub trait Commands<
}
fn h001a_sleepmode_ack(&mut self, _data: h001a::Ack) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::FlashMode,
HidIoCommandId::SleepMode,
HidIoPacketType::Ack,
))
}
fn h001a_sleepmode_nak(&mut self, _data: h001a::Nak) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::FlashMode,
HidIoCommandId::SleepMode,
HidIoPacketType::Nak,
))
}
Expand Down Expand Up @@ -1800,19 +1800,19 @@ pub trait Commands<
}
fn h0020_klltrigger_nacmd(&mut self, _data: h0020::Cmd) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::KllState,
HidIoPacketType::NaData,
))
}
fn h0020_klltrigger_ack(&mut self, _data: h0020::Ack) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::KllState,
HidIoPacketType::Ack,
))
}
fn h0020_klltrigger_nak(&mut self, _data: h0020::Nak) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::KllState,
HidIoPacketType::Nak,
))
}
Expand Down Expand Up @@ -1876,19 +1876,19 @@ pub trait Commands<
}
fn h0021_pixelsetting_nacmd(&mut self, _data: h0021::Cmd) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::PixelSetting,
HidIoPacketType::NaData,
))
}
fn h0021_pixelsetting_ack(&mut self, _data: h0021::Ack) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::PixelSetting,
HidIoPacketType::Ack,
))
}
fn h0021_pixelsetting_nak(&mut self, _data: h0021::Nak) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::PixelSetting,
HidIoPacketType::Nak,
))
}
Expand Down Expand Up @@ -1967,19 +1967,19 @@ pub trait Commands<
}
fn h0026_directset_nacmd(&mut self, _data: h0026::Cmd<HSUB2>) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::DirectSet,
HidIoPacketType::NaData,
))
}
fn h0026_directset_ack(&mut self, _data: h0026::Ack) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::DirectSet,
HidIoPacketType::Ack,
))
}
fn h0026_directset_nak(&mut self, _data: h0026::Nak) -> Result<(), CommandError> {
Err(CommandError::IdNotImplemented(
HidIoCommandId::UnicodeState,
HidIoCommandId::DirectSet,
HidIoPacketType::Nak,
))
}
Expand Down
31 changes: 17 additions & 14 deletions src/api/capnp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl hidio_capnp::node::Server for KeyboardNodeImpl {
fn pixel_set(
&mut self,
params: hidio_capnp::node::PixelSetParams,
_results: hidio_capnp::node::PixelSetResults,
mut results: hidio_capnp::node::PixelSetResults,
) -> Promise<(), Error> {
let src = mailbox::Address::ApiCapnp { uid: self.node.uid };
let dst = mailbox::Address::DeviceHidio { uid: self.uid };
Expand Down Expand Up @@ -1026,6 +1026,7 @@ impl hidio_capnp::node::Server for KeyboardNodeImpl {

let params = params.get().unwrap();
let start_address: u16 = params.get_command().unwrap().get_start_address();
let status = results.get().init_status();

match params.get_command().unwrap().get_type().unwrap() {
hidio_capnp::node::pixel_set::Type::DirectSet => {
Expand All @@ -1034,10 +1035,9 @@ impl hidio_capnp::node::Server for KeyboardNodeImpl {
) {
Ok(data) => data,
Err(e) => {
return Promise::err(capnp::Error {
kind: ::capnp::ErrorKind::Failed,
description: format!("Error (pixel_set - directset - data): {:?}", e),
});
error!("Error (pixel_set - directset - data): {:?}", e);
status.init_error();
return Promise::ok(());
}
};
if let Err(e) = intf.h0026_directset(
Expand All @@ -1047,21 +1047,21 @@ impl hidio_capnp::node::Server for KeyboardNodeImpl {
},
true,
) {
return Promise::err(capnp::Error {
kind: ::capnp::ErrorKind::Failed,
description: format!("Error (pixel_set - directset): {:?}", e),
});
error!("Error (pixel_set - directset): {:?}", e);
status.init_error();
return Promise::ok(());
}
}
}

status.init_success();
Promise::ok(())
}

fn pixel_setting(
&mut self,
params: hidio_capnp::node::PixelSettingParams,
_results: hidio_capnp::node::PixelSettingResults,
mut results: hidio_capnp::node::PixelSettingResults,
) -> Promise<(), Error> {
let src = mailbox::Address::ApiCapnp { uid: self.node.uid };
let dst = mailbox::Address::DeviceHidio { uid: self.uid };
Expand Down Expand Up @@ -1150,12 +1150,13 @@ impl hidio_capnp::node::Server for KeyboardNodeImpl {
},
};

let status = results.get().init_status();
if let Err(e) = intf.h0021_pixelsetting(h0021::Cmd { command, argument }, true) {
return Promise::err(capnp::Error {
kind: ::capnp::ErrorKind::Failed,
description: format!("Error (pixel_setting): {:?}", e),
});
status.init_error();
error!("Error (pixel_setting): {:?}", e);
return Promise::ok(());
}
status.init_success();
Promise::ok(())
}

Expand Down Expand Up @@ -2623,12 +2624,14 @@ async fn server_subscriptions(
/// Supported Ids by this module
pub fn supported_ids() -> Vec<HidIoCommandId> {
vec![
HidIoCommandId::DirectSet,
HidIoCommandId::FlashMode,
HidIoCommandId::GetInfo,
HidIoCommandId::HostMacro,
HidIoCommandId::KllState,
HidIoCommandId::ManufacturingResult,
HidIoCommandId::ManufacturingTest,
HidIoCommandId::PixelSetting,
HidIoCommandId::SleepMode,
HidIoCommandId::SupportedIds,
HidIoCommandId::TerminalCmd,
Expand Down

0 comments on commit 5394d79

Please sign in to comment.