Started to work on pedal_operations
Created a seperate struct for the pedals. Write functions are still empty. Later, I'll move the read function to this struct too.
This commit is contained in:
parent
a8169788c5
commit
b2a026e5e0
@ -3,6 +3,7 @@
|
|||||||
//! `footswitch-rs` enables you to use footswitches of <xxx>
|
//! `footswitch-rs` enables you to use footswitches of <xxx>
|
||||||
|
|
||||||
mod key_operations;
|
mod key_operations;
|
||||||
|
mod pedal_operations;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate structopt;
|
extern crate structopt;
|
||||||
@ -30,8 +31,9 @@ struct Opt {
|
|||||||
output: Option<PathBuf>,
|
output: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let pedals = pedal_operations::Pedals::new();
|
||||||
|
println!("{:?}", pedals.ped_data[1].length);
|
||||||
check_sudo();
|
check_sudo();
|
||||||
|
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
@ -81,6 +83,7 @@ fn check_sudo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Read the current values of the pedals
|
/// Read the current values of the pedals
|
||||||
|
//ToDo: Move to pedals struct and split read and interpret functionality
|
||||||
fn read_pedals(dev: & hidapi::HidDevice) {
|
fn read_pedals(dev: & hidapi::HidDevice) {
|
||||||
let column_width = 15;
|
let column_width = 15;
|
||||||
let total_width = (column_width+3)*3;
|
let total_width = (column_width+3)*3;
|
||||||
@ -112,4 +115,3 @@ fn read_pedals(dev: & hidapi::HidDevice) {
|
|||||||
// Print simple footer
|
// Print simple footer
|
||||||
println!("‖\n {}", "-".repeat(total_width));
|
println!("‖\n {}", "-".repeat(total_width));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
62
src/pedal_operations.rs
Normal file
62
src/pedal_operations.rs
Normal file
@ -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<PedalsData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user