diff --git a/src/main.rs b/src/main.rs index 4b1f94c..0799f9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ //! `footswitch-rs` enables you to use footswitches of mod key_operations; +mod pedal_operations; #[macro_use] extern crate structopt; @@ -30,8 +31,9 @@ struct Opt { output: Option, } - fn main() { + let pedals = pedal_operations::Pedals::new(); + println!("{:?}", pedals.ped_data[1].length); check_sudo(); let opt = Opt::from_args(); @@ -81,6 +83,7 @@ fn check_sudo() { } /// Read the current values of the pedals +//ToDo: Move to pedals struct and split read and interpret functionality fn read_pedals(dev: & hidapi::HidDevice) { let column_width = 15; let total_width = (column_width+3)*3; @@ -111,5 +114,4 @@ fn read_pedals(dev: & hidapi::HidDevice) { // Print simple footer println!("‖\n {}", "-".repeat(total_width)); -} - +} \ No newline at end of file diff --git a/src/pedal_operations.rs b/src/pedal_operations.rs new file mode 100644 index 0000000..40d8e95 --- /dev/null +++ b/src/pedal_operations.rs @@ -0,0 +1,62 @@ +extern crate hidapi; + +pub struct PedalsData { + header: [u8; 8], + data: [u8; 48], + pub length: i32, +} + +pub struct Pedals { + start: [u8; 8], + pub ped_data: Vec, +} + +impl Pedals { + pub fn new() -> Pedals { + // Prepare variables + let start = [0x01u8, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00]; + + let header_0 = [0x01u8, 0x81, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00]; + let header_1 = [0x01u8, 0x81, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00]; + let header_2 = [0x01u8, 0x81, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00]; + + let mut default_data = [0u8; 48]; + default_data[0] = 0x08; + + // Initialize actual object + Pedals { + start: start, + + ped_data: vec![ + PedalsData { + header: header_0, + data: default_data, + length: 8, + }, + PedalsData { + header: header_1, + data: default_data, + length: 8, + }, + PedalsData { + header: header_2, + data: default_data, + length: 8, + }, + ] + } + } + + fn write_pedal(&self, dev: & hidapi::HidDevice, pedal: & PedalsData) { + dev.write(&pedal.header).unwrap(); + } + + pub fn write_pedals(&self, dev: & hidapi::HidDevice) { + dev.write(&self.start).unwrap(); + + for pedal in self.ped_data.iter() { + self.write_pedal(dev, &pedal) + } + } + +}