Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Dec 29, 2024
1 parent 5a6ec39 commit 9db9539
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ irq = "0.2.3"

# no_proto = "0.9.60"
# protobuf-codegen = "3.5.0"
femtopb = "0.4.5"
femtopb = "0.6.0"
serial-line-ip = { git = "https://github.com/Panduza/serial-line-ip-rs", branch = "stream_buffer_feature" }

fugit = "0.3.7"

rp2040-flash = "0.5.1"

[build-dependencies]
femtopb-build = "0.4.5"
femtopb-build = "0.6.0"

# cargo build/run
[profile.dev]
Expand Down
28 changes: 14 additions & 14 deletions firmware/src/api_dio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::femtopb::Message)]
#[derive(Clone, Copy, PartialEq, ::femtopb::Message)]
pub struct PicohaDioRequest<'a> {
#[femtopb(enumeration, tag = 1)]
pub r#type: ::femtopb::enumeration::EnumValue<RequestType>,
Expand All @@ -10,7 +9,6 @@ pub struct PicohaDioRequest<'a> {
#[femtopb(unknown_fields)]
pub unknown_fields: femtopb::UnknownFields<'a>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::femtopb::Message)]
pub struct PicohaDioAnswer<'a> {
#[femtopb(enumeration, tag = 1)]
Expand Down Expand Up @@ -50,11 +48,11 @@ impl RequestType {
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
RequestType::Ping => "PING",
RequestType::SetPinDirection => "SET_PIN_DIRECTION",
RequestType::SetPinValue => "SET_PIN_VALUE",
RequestType::GetPinDirection => "GET_PIN_DIRECTION",
RequestType::GetPinValue => "GET_PIN_VALUE",
Self::Ping => "PING",
Self::SetPinDirection => "SET_PIN_DIRECTION",
Self::SetPinValue => "SET_PIN_VALUE",
Self::GetPinDirection => "GET_PIN_DIRECTION",
Self::GetPinValue => "GET_PIN_VALUE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -69,6 +67,8 @@ impl RequestType {
}
}
}
/// This structure should be splitted
/// 1 for values and 1 for directions
#[derive(
Clone,
Copy,
Expand Down Expand Up @@ -96,10 +96,10 @@ impl PinValue {
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
PinValue::Low => "LOW",
PinValue::High => "HIGH",
PinValue::Input => "INPUT",
PinValue::Output => "OUTPUT",
Self::Low => "LOW",
Self::High => "HIGH",
Self::Input => "INPUT",
Self::Output => "OUTPUT",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand Down Expand Up @@ -138,8 +138,8 @@ impl AnswerType {
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
AnswerType::Success => "SUCCESS",
AnswerType::Failure => "FAILURE",
Self::Success => "SUCCESS",
Self::Failure => "FAILURE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand Down
22 changes: 19 additions & 3 deletions firmware/src/dio_request_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,19 @@ impl DioRequestProcessor {
Ok(())
}

///
/// Process a request, main entry point
///
pub fn process_request(
&mut self,
serial: &mut SerialPort<rp2040_hal::usb::UsbBus>,
request: PicohaDioRequest,
) {
//
// Debug log
print_debug_message!("+ processing request: {:?}", request);

//
// Choose the correct process function
match request.r#type {
femtopb::EnumValue::Known(k) => match k {
crate::api_dio::RequestType::Ping => Self::process_request_ping(serial),
Expand Down Expand Up @@ -300,7 +304,12 @@ impl DioRequestProcessor {
serial: &mut SerialPort<rp2040_hal::usb::UsbBus>,
request: PicohaDioRequest,
) {
//
// Debug log
print_debug_message!(b"\tprocessing request: SET_PIN_VALUE\r\n");

//
// Process the request
let r = match request.value {
femtopb::EnumValue::Known(v) => match v {
crate::api_dio::PinValue::Low => self.set_pin_low(request.pin_num),
Expand Down Expand Up @@ -372,11 +381,17 @@ impl DioRequestProcessor {
serial: &mut SerialPort<rp2040_hal::usb::UsbBus>,
request: PicohaDioRequest,
) {
//
// Debug log
print_debug_message!(b" * processing request: GET_PIN_VALUE\r\n");

//
// Prepare a default answer
let mut answer = PicohaDioAnswer::default();
answer.r#type = femtopb::EnumValue::Known(crate::api_dio::AnswerType::Success);


//
// Fill the return message
match self.get_internal_pin_value(request.pin_num as usize) {
Some(val) => {
answer.r#type = femtopb::EnumValue::Known(crate::api_dio::AnswerType::Success);
Expand All @@ -396,7 +411,8 @@ impl DioRequestProcessor {
},
}


//
// Send back the message
Self::send_answer(serial, answer);
}

Expand Down

0 comments on commit 9db9539

Please sign in to comment.