Finished do-not-purge feature. Closes #3
This feature is not yet tested on the Append:: functions since not all functions are yet implemented. As soon as they get implemented, this feature will be verified on them as well. Furthermore, a Clear function is added. Finally, in this commit, mouse_left, mouse_right, mouse_middle, and mouse_double got abbreviated to left, right, middle, and double.
This commit is contained in:
parent
43f63c002b
commit
44c542d99a
@ -196,7 +196,7 @@ static KEY_MAP : &[(&str, u8)] = &[
|
|||||||
("(" , 0xaf),
|
("(" , 0xaf),
|
||||||
(")" , 0xb0),
|
(")" , 0xb0),
|
||||||
("|" , 0xb1),
|
("|" , 0xb1),
|
||||||
("|" , 0xb2),
|
("|" , 0xb2),
|
||||||
(":" , 0xb3),
|
(":" , 0xb3),
|
||||||
("\"" , 0xb4),
|
("\"" , 0xb4),
|
||||||
("~" , 0xb5),
|
("~" , 0xb5),
|
||||||
@ -261,7 +261,7 @@ static KEY_MAP : &[(&str, u8)] = &[
|
|||||||
("XF86WWW" , 0xf0),
|
("XF86WWW" , 0xf0),
|
||||||
("XF86Back" , 0xf1),
|
("XF86Back" , 0xf1),
|
||||||
("XF86Forward" , 0xf2),
|
("XF86Forward" , 0xf2),
|
||||||
("Cancel" , 0xf3),
|
("Cancel" , 0xf3),
|
||||||
("Find" , 0xf4),
|
("Find" , 0xf4),
|
||||||
("XF86ScrollUp" , 0xf5),
|
("XF86ScrollUp" , 0xf5),
|
||||||
("XF86ScrollDown" , 0xf6),
|
("XF86ScrollDown" , 0xf6),
|
||||||
@ -314,10 +314,10 @@ pub enum MouseButton {
|
|||||||
impl MouseButton {
|
impl MouseButton {
|
||||||
pub fn str_to_enum(mousebutton:&str) -> Option<MouseButton> {
|
pub fn str_to_enum(mousebutton:&str) -> Option<MouseButton> {
|
||||||
match mousebutton {
|
match mousebutton {
|
||||||
"mouse_left" => Some(MouseButton::MouseLeft),
|
"left" => Some(MouseButton::MouseLeft),
|
||||||
"mouse_right" => Some(MouseButton::MouseRight),
|
"right" => Some(MouseButton::MouseRight),
|
||||||
"mouse_middle" => Some(MouseButton::MouseMiddle),
|
"middle" => Some(MouseButton::MouseMiddle),
|
||||||
"mouse_double" => Some(MouseButton::MouseDouble),
|
"double" => Some(MouseButton::MouseDouble),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,10 +334,10 @@ impl MouseButton {
|
|||||||
|
|
||||||
pub fn enum_to_string(mousebutton:MouseButton) -> String {
|
pub fn enum_to_string(mousebutton:MouseButton) -> String {
|
||||||
match mousebutton {
|
match mousebutton {
|
||||||
MouseButton::MouseLeft => "mouse_left".to_string(),
|
MouseButton::MouseLeft => "left".to_string(),
|
||||||
MouseButton::MouseRight => "mouse_right".to_string(),
|
MouseButton::MouseRight => "right".to_string(),
|
||||||
MouseButton::MouseMiddle => "mouse_middle".to_string(),
|
MouseButton::MouseMiddle => "middle".to_string(),
|
||||||
MouseButton::MouseDouble => "mouse_double".to_string(),
|
MouseButton::MouseDouble => "double".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -404,7 +404,7 @@ pub fn print_key(response: &[u8]) -> Option<String> {
|
|||||||
return Some(key_combo);
|
return Some(key_combo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ pub fn print_mouse_key(response: &[u8]) -> Option<String> {
|
|||||||
},
|
},
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(key_mouse_string)
|
Some(key_mouse_string)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,10 +454,10 @@ pub fn print_key_map(rows: usize) {
|
|||||||
print!("{}", " ‖ Key Name ¦ Value ".repeat(rows));
|
print!("{}", " ‖ Key Name ¦ Value ".repeat(rows));
|
||||||
println!(" ‖");
|
println!(" ‖");
|
||||||
|
|
||||||
println!(" {}", "-".repeat(rows*36));
|
println!(" {}", "-".repeat(rows*36));
|
||||||
for (i, key) in KEY_MAP.iter().enumerate() {
|
for (i, key) in KEY_MAP.iter().enumerate() {
|
||||||
|
|
||||||
print!(" ‖ {name:<-name_width$} ¦ <0x{value:>0value_width$x}> ",
|
print!(" ‖ {name:<-name_width$} ¦ <0x{value:>0value_width$x}> ",
|
||||||
name=key.0, name_width=20, value = key.1, value_width = 2);
|
name=key.0, name_width=20, value = key.1, value_width = 2);
|
||||||
|
|
||||||
if (i + 1) % rows == 0 {
|
if (i + 1) % rows == 0 {
|
||||||
|
102
src/main.rs
102
src/main.rs
@ -1,7 +1,7 @@
|
|||||||
//! Footswitch-RS
|
//! Footswitch-RS
|
||||||
//!
|
//!
|
||||||
//! `footswitch-rs` enables you to use footswitches of <xxx>
|
//! `footswitch-rs` enables you to use footswitches of <xxx>
|
||||||
//!
|
//!
|
||||||
|
|
||||||
extern crate structopt;
|
extern crate structopt;
|
||||||
extern crate users;
|
extern crate users;
|
||||||
@ -55,7 +55,7 @@ enum Command {
|
|||||||
#[structopt(short = "p", long = "pedal")]
|
#[structopt(short = "p", long = "pedal")]
|
||||||
pedal: Vec<u8>,
|
pedal: Vec<u8>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Read from the footpedal
|
/// Read from the footpedal
|
||||||
#[structopt(name = "read")]
|
#[structopt(name = "read")]
|
||||||
Read {
|
Read {
|
||||||
@ -83,7 +83,7 @@ enum Set {
|
|||||||
input: Vec<String>,
|
input: Vec<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Set a mousebutton to one or more pedals
|
/// Set a mousebutton (left/right/middle/double) to one or more pedals
|
||||||
#[structopt(name = "mousebutton")]
|
#[structopt(name = "mousebutton")]
|
||||||
SetMousebutton {
|
SetMousebutton {
|
||||||
/// Specify pedal(s) to modify: [0 | 1 | 2]
|
/// Specify pedal(s) to modify: [0 | 1 | 2]
|
||||||
@ -94,7 +94,7 @@ enum Set {
|
|||||||
#[structopt(short = "i", long = "input")]
|
#[structopt(short = "i", long = "input")]
|
||||||
input: Vec<String>,
|
input: Vec<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Set X, Y, and W movement of the mouse pointer for one or more pedals
|
/// Set X, Y, and W movement of the mouse pointer for one or more pedals
|
||||||
#[structopt(name = "mousemovement")]
|
#[structopt(name = "mousemovement")]
|
||||||
SetMousemovement {
|
SetMousemovement {
|
||||||
@ -142,7 +142,7 @@ enum Append {
|
|||||||
input: Vec<String>,
|
input: Vec<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Append a modifier to one or more pedals
|
/// Append a modifier (ctrl/shift/alt/win) to one or more pedals
|
||||||
#[structopt(name = "modifier")]
|
#[structopt(name = "modifier")]
|
||||||
AppendModifier {
|
AppendModifier {
|
||||||
/// Specify pedal(s) to modify: [0 | 1 | 2]
|
/// Specify pedal(s) to modify: [0 | 1 | 2]
|
||||||
@ -160,10 +160,10 @@ fn main() {
|
|||||||
|
|
||||||
welcome();
|
welcome();
|
||||||
check_sudo();
|
check_sudo();
|
||||||
|
|
||||||
// All options that don't need the device to be open
|
// All options that don't need the device to be open
|
||||||
// Print all keys and exit application
|
// Print all keys and exit application
|
||||||
match opt.cmd {
|
match opt.cmd {
|
||||||
Some(Command::ListKeys { columns }) => {
|
Some(Command::ListKeys { columns }) => {
|
||||||
key_operations::print_key_map(columns);
|
key_operations::print_key_map(columns);
|
||||||
goodbye();
|
goodbye();
|
||||||
@ -171,12 +171,58 @@ fn main() {
|
|||||||
_ => { /* Do nothing, there are still lots of other options further below */ }
|
_ => { /* Do nothing, there are still lots of other options further below */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut pedals = pedal_operations::Pedals::new();
|
let mut pedals = pedal_operations::Pedals::new();
|
||||||
|
|
||||||
|
// Make sure that the application does not purge pedals that are not explicitly set
|
||||||
|
// by refreshing pedals that are not in use.
|
||||||
|
//
|
||||||
|
// When Command::Clear is set, refresh only the pedals that are NOT defined.
|
||||||
|
let mut unused_pedals: Vec<u8> = Vec::new();
|
||||||
|
|
||||||
|
match &opt.cmd {
|
||||||
|
Some(Command::Set { cmd }) => {
|
||||||
|
match cmd {
|
||||||
|
Set::SetKey { pedal, .. } |
|
||||||
|
Set::SetMousebutton { pedal, .. } |
|
||||||
|
Set::SetMousemovement { pedal, .. } => {
|
||||||
|
for number in 0..3 {
|
||||||
|
if !pedal.contains(&(number as u8)) {
|
||||||
|
unused_pedals.push(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some(Command::Append { cmd }) => {
|
||||||
|
match cmd {
|
||||||
|
Append::AppendKey { pedal, .. } |
|
||||||
|
Append::AppendString { pedal, .. } |
|
||||||
|
Append::AppendModifier { pedal, .. } => {
|
||||||
|
for number in 0..3 {
|
||||||
|
if !pedal.contains(&(number as u8)) {
|
||||||
|
unused_pedals.push(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some(Command::Clear { pedal }) => {
|
||||||
|
for number in 0..3 {
|
||||||
|
if !pedal.contains(&(number as u8)) {
|
||||||
|
unused_pedals.push(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => { /* Do nothing, statement below will cover this */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
pedals.refresh_values(unused_pedals);
|
||||||
|
|
||||||
// All options that need the device to be open
|
// All options that need the device to be open
|
||||||
match opt.cmd {
|
match opt.cmd {
|
||||||
|
|
||||||
Some(Command::Append { cmd }) => {
|
Some(Command::Append { cmd }) => {
|
||||||
match cmd {
|
match cmd {
|
||||||
Append::AppendKey { pedal, input } =>
|
Append::AppendKey { pedal, input } =>
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -185,7 +231,7 @@ fn main() {
|
|||||||
{
|
{
|
||||||
check_length(&pedal, &input);
|
check_length(&pedal, &input);
|
||||||
|
|
||||||
for (i, pedal) in pedal.iter().enumerate() {
|
for (i, pedal) in pedal.iter().enumerate() {
|
||||||
pedals.set_string(*pedal as usize, input[i].as_str());
|
pedals.set_string(*pedal as usize, input[i].as_str());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -193,7 +239,7 @@ fn main() {
|
|||||||
{
|
{
|
||||||
check_length(&pedal, &input);
|
check_length(&pedal, &input);
|
||||||
|
|
||||||
for (i, pedal) in pedal.iter().enumerate() {
|
for (i, pedal) in pedal.iter().enumerate() {
|
||||||
pedals.set_modifier(*pedal as usize, input[i].as_str());
|
pedals.set_modifier(*pedal as usize, input[i].as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,37 +254,27 @@ fn main() {
|
|||||||
{
|
{
|
||||||
check_length(&pedal, &input);
|
check_length(&pedal, &input);
|
||||||
|
|
||||||
let mut unused_pedals: Vec<u8> = Vec::new();
|
for (i, pedal) in pedal.iter().enumerate() {
|
||||||
|
pedals.set_key(*pedal as usize, input[i].as_str());
|
||||||
for number in 0..3 {
|
|
||||||
if !pedal.contains(&(number as u8)) {
|
|
||||||
unused_pedals.push(number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pedals.refresh_values(unused_pedals);
|
|
||||||
|
|
||||||
for (i, pedal) in pedal.iter().enumerate() {
|
|
||||||
pedals.set_key(*pedal as usize, input[i].as_str());
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Set::SetMousebutton { pedal, input } =>
|
Set::SetMousebutton { pedal, input } =>
|
||||||
{
|
{
|
||||||
check_length(&pedal, &input);
|
check_length(&pedal, &input);
|
||||||
|
|
||||||
for (i, pedal) in pedal.iter().enumerate() {
|
for (i, pedal) in pedal.iter().enumerate() {
|
||||||
pedals.set_mousebutton(*pedal as usize, input[i].as_str());
|
pedals.set_mousebutton(*pedal as usize, input[i].as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set::SetMousemovement { pedal, x, y, w } =>
|
Set::SetMousemovement { pedal, x, y, w } =>
|
||||||
{
|
{
|
||||||
|
|
||||||
if pedal.len() != x.len() || x.len() != y.len() || y.len() != w.len() {
|
if pedal.len() != x.len() || x.len() != y.len() || y.len() != w.len() {
|
||||||
error!("You must define X, Y, and W for every pedal. If a direction is not needed, set it to 0!");
|
error!("You must define x, y, and w for every pedal. If a direction is not needed, set it to 0!");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, pedal) in pedal.iter().enumerate() {
|
for (i, pedal) in pedal.iter().enumerate() {
|
||||||
pedals.set_mouse_xyw(*pedal as usize, x[i], 5);
|
pedals.set_mouse_xyw(*pedal as usize, x[i], 5);
|
||||||
pedals.set_mouse_xyw(*pedal as usize, y[i], 6);
|
pedals.set_mouse_xyw(*pedal as usize, y[i], 6);
|
||||||
pedals.set_mouse_xyw(*pedal as usize, w[i], 7);
|
pedals.set_mouse_xyw(*pedal as usize, w[i], 7);
|
||||||
@ -249,10 +285,10 @@ fn main() {
|
|||||||
pedals.update_and_close();
|
pedals.update_and_close();
|
||||||
},
|
},
|
||||||
|
|
||||||
Some(Command::Clear { pedal }) => {
|
Some(Command::Clear { .. }) => {
|
||||||
|
pedals.update_and_close();
|
||||||
},
|
},
|
||||||
|
|
||||||
Some(Command::Read {all: all_var, pedals: ped_list}) => {
|
Some(Command::Read {all: all_var, pedals: ped_list}) => {
|
||||||
if ped_list.len() > 3 {
|
if ped_list.len() > 3 {
|
||||||
error!("Number of pedals may not be bigger than 3!");
|
error!("Number of pedals may not be bigger than 3!");
|
||||||
|
@ -84,7 +84,7 @@ impl Pedals {
|
|||||||
error!("Could not open device. Make sure your device is connected. Maybe try to reconnect it.")
|
error!("Could not open device. Make sure your device is connected. Maybe try to reconnect it.")
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prepare variables
|
// Prepare variables
|
||||||
let start = [0x01u8, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00];
|
let start = [0x01u8, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ impl Pedals {
|
|||||||
default_data[0] = 0x08;
|
default_data[0] = 0x08;
|
||||||
|
|
||||||
// Initialize actual object
|
// Initialize actual object
|
||||||
Pedals {
|
Pedals {
|
||||||
dev: dev,
|
dev: dev,
|
||||||
start: start,
|
start: start,
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ impl Pedals {
|
|||||||
length: 8,
|
length: 8,
|
||||||
},
|
},
|
||||||
PedalsData {
|
PedalsData {
|
||||||
header: header_2,
|
header: header_2,
|
||||||
data: default_data,
|
data: default_data,
|
||||||
length: 8, },
|
length: 8, },
|
||||||
]
|
]
|
||||||
@ -146,7 +146,7 @@ impl Pedals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print header
|
// Print header
|
||||||
println!("├{}┐", "─".repeat(total_width));
|
println!("├{}┐", "─".repeat(total_width));
|
||||||
println!("│{name:^width$}│", name = "Programmed Keys", width = total_width);
|
println!("│{name:^width$}│", name = "Programmed Keys", width = total_width);
|
||||||
println!("╞{}╡", "═".repeat(total_width));
|
println!("╞{}╡", "═".repeat(total_width));
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ impl Pedals {
|
|||||||
self.dev.write(&self.ped_data[ped].data[up..(self.ped_data[ped].length as usize)]).unwrap();
|
self.dev.write(&self.ped_data[ped].data[up..(self.ped_data[ped].length as usize)]).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method writes all data from Pedals.peddata to the device
|
/// This method writes all data from Pedals.peddata to the device
|
||||||
pub fn write_pedals(&self) {
|
pub fn write_pedals(&self) {
|
||||||
self.dev.write(&self.start).unwrap();
|
self.dev.write(&self.start).unwrap();
|
||||||
@ -278,7 +278,7 @@ impl Pedals {
|
|||||||
pub fn set_mousebutton(& mut self, ped:usize, mousebutton:&str) {
|
pub fn set_mousebutton(& mut self, ped:usize, mousebutton:&str) {
|
||||||
let mousebutton = match key_operations::MouseButton::str_to_enum(mousebutton) {
|
let mousebutton = match key_operations::MouseButton::str_to_enum(mousebutton) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => error!("Unknown mousebutton! Please use one of the following: mouse_left, mouse_middle, mouse_right, mouse_double."),
|
None => error!("Unknown mousebutton! Please use one of the following: left, middle, right, double."),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.set_type(ped, Type::Mouse);
|
self.set_type(ped, Type::Mouse);
|
||||||
@ -369,22 +369,21 @@ impl Pedals {
|
|||||||
/// Update device and close application
|
/// Update device and close application
|
||||||
pub fn update_and_close(& mut self) {
|
pub fn update_and_close(& mut self) {
|
||||||
self.write_pedals();
|
self.write_pedals();
|
||||||
|
|
||||||
info!("Successfully wrote everything to footpedal!");
|
info!("Successfully wrote everything to footpedal!");
|
||||||
info!("The current state of the device is shown below.");
|
info!("The current state of the device is shown below.");
|
||||||
|
|
||||||
// Show user current state of pedal
|
// Show user current state of pedal
|
||||||
self.read_pedals(vec![0,1,2]);
|
self.read_pedals(vec![0,1,2]);
|
||||||
|
|
||||||
goodbye();
|
goodbye();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prevent the application from purging pedals that are not
|
/// Prevent the application from purging pedals that are not explicitly set
|
||||||
/// explicitly set
|
|
||||||
pub fn refresh_values(& mut self, peds: Vec<u8>) {
|
pub fn refresh_values(& mut self, peds: Vec<u8>) {
|
||||||
|
|
||||||
// First read from pedals that are defined in peds
|
// First read from pedals that are defined in peds
|
||||||
for (i, ped) in peds.iter().enumerate() {
|
for ped in peds.iter() {
|
||||||
// Read value from pedal and directly translate it to a key
|
// Read value from pedal and directly translate it to a key
|
||||||
let mut key_value = self.read_pedal(ped);
|
let mut key_value = self.read_pedal(ped);
|
||||||
|
|
||||||
@ -393,9 +392,21 @@ impl Pedals {
|
|||||||
self.set_type(*ped as usize, Type::Key);
|
self.set_type(*ped as usize, Type::Key);
|
||||||
self.ped_data[*ped as usize].data[3] = key_value[3];
|
self.ped_data[*ped as usize].data[3] = key_value[3];
|
||||||
},
|
},
|
||||||
|
Some(Type::Mouse) => {
|
||||||
|
self.set_type(*ped as usize, Type::Mouse);
|
||||||
|
self.ped_data[*ped as usize].data[4] = key_value[4];
|
||||||
|
},
|
||||||
|
Some(Type::MouseKey) => {
|
||||||
|
self.set_type(*ped as usize, Type::MouseKey);
|
||||||
|
self.ped_data[*ped as usize].data[3] = key_value[3];
|
||||||
|
self.ped_data[*ped as usize].data[4] = key_value[4];
|
||||||
|
},
|
||||||
|
Some(Type::String) => {
|
||||||
|
self.set_type(*ped as usize, Type::String);
|
||||||
|
},
|
||||||
|
|
||||||
None => error!("The key type which was returned by the pedal was invalid!"),
|
None => error!("The key type which was returned by the pedal was invalid!"),
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user