Fix out of bounds access + add debug msg

This commit is contained in:
hodasemi 2022-07-21 09:36:38 +02:00
parent 06f955e3d2
commit ceb5423420
2 changed files with 13 additions and 2 deletions

View file

@ -8,6 +8,8 @@ use service_specific::*;
use shared::config::{Config, COMMAND_COUNT, COMMAND_PAUSE};
fn main() -> Result<()> {
println!("startup macroboard service");
// azdelivery usart device
// let usb_device = UsbId {
// vendor_id: 0x0403,
@ -37,6 +39,8 @@ fn main() -> Result<()> {
let mut button_infos = [Duration::default(); COMMAND_COUNT];
let start_time = Instant::now();
println!("service is now listening ...");
// loop forever
loop {
// handle incoming message
@ -77,8 +81,8 @@ fn execute_button_press(
}
// check that this commands last execution is longer than COMMAND_PAUSE ago
if (button_infos[button_id] + COMMAND_PAUSE) < time {
button_infos[button_id] = time;
if (button_infos[button_id - 1] + COMMAND_PAUSE) < time {
button_infos[button_id - 1] = time;
} else {
return Ok(());
}

View file

@ -32,6 +32,8 @@ impl Port {
pub fn open(usb_device: UsbId, settings: SerialPortSettings) -> Result<Self> {
let port_path = Self::loop_usb_devices(usb_device)?;
println!("found device at path {}", port_path);
let port = serialport::new(port_path, settings.baud_rate)
.data_bits(settings.data_bits)
.parity(settings.parity)
@ -72,6 +74,11 @@ impl Port {
return Ok(device);
}
println!(
"no device found with {}:{}",
usb_device.vendor_id, usb_device.product_id
);
std::thread::sleep(Duration::from_secs(2));
}
}