Fix out of bounds access + add debug msg
This commit is contained in:
parent
06f955e3d2
commit
ceb5423420
2 changed files with 13 additions and 2 deletions
|
@ -8,6 +8,8 @@ use service_specific::*;
|
||||||
use shared::config::{Config, COMMAND_COUNT, COMMAND_PAUSE};
|
use shared::config::{Config, COMMAND_COUNT, COMMAND_PAUSE};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
println!("startup macroboard service");
|
||||||
|
|
||||||
// azdelivery usart device
|
// azdelivery usart device
|
||||||
// let usb_device = UsbId {
|
// let usb_device = UsbId {
|
||||||
// vendor_id: 0x0403,
|
// vendor_id: 0x0403,
|
||||||
|
@ -37,6 +39,8 @@ fn main() -> Result<()> {
|
||||||
let mut button_infos = [Duration::default(); COMMAND_COUNT];
|
let mut button_infos = [Duration::default(); COMMAND_COUNT];
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
|
println!("service is now listening ...");
|
||||||
|
|
||||||
// loop forever
|
// loop forever
|
||||||
loop {
|
loop {
|
||||||
// handle incoming message
|
// handle incoming message
|
||||||
|
@ -77,8 +81,8 @@ fn execute_button_press(
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that this commands last execution is longer than COMMAND_PAUSE ago
|
// check that this commands last execution is longer than COMMAND_PAUSE ago
|
||||||
if (button_infos[button_id] + COMMAND_PAUSE) < time {
|
if (button_infos[button_id - 1] + COMMAND_PAUSE) < time {
|
||||||
button_infos[button_id] = time;
|
button_infos[button_id - 1] = time;
|
||||||
} else {
|
} else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ impl Port {
|
||||||
pub fn open(usb_device: UsbId, settings: SerialPortSettings) -> Result<Self> {
|
pub fn open(usb_device: UsbId, settings: SerialPortSettings) -> Result<Self> {
|
||||||
let port_path = Self::loop_usb_devices(usb_device)?;
|
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)
|
let port = serialport::new(port_path, settings.baud_rate)
|
||||||
.data_bits(settings.data_bits)
|
.data_bits(settings.data_bits)
|
||||||
.parity(settings.parity)
|
.parity(settings.parity)
|
||||||
|
@ -72,6 +74,11 @@ impl Port {
|
||||||
return Ok(device);
|
return Ok(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"no device found with {}:{}",
|
||||||
|
usb_device.vendor_id, usb_device.product_id
|
||||||
|
);
|
||||||
|
|
||||||
std::thread::sleep(Duration::from_secs(2));
|
std::thread::sleep(Duration::from_secs(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue