Added append key feature

By adding this feature, all initially planned functionality is now covered by
the application.
This commit is contained in:
Dennis Potter 2018-11-26 13:11:51 +01:00
parent daf88336eb
commit bdb4a01487
2 changed files with 28 additions and 0 deletions

View File

@ -225,7 +225,11 @@ fn main() {
match cmd { match cmd {
Append::AppendKey { pedal, input } => Append::AppendKey { pedal, input } =>
{ {
check_length(&pedal, &input);
for (i, pedal) in pedal.iter().enumerate() {
pedals.append_key(*pedal as usize, input[i].as_str());
}
}, },
Append::AppendString { pedal, input } => Append::AppendString { pedal, input } =>
{ {

View File

@ -264,6 +264,20 @@ impl Pedals {
} }
} }
pub fn append_key(& mut self, ped:usize, key:&str) {
if let Some(encoded_key) = key_operations::encode_byte(key) {
self.set_type(ped, Type::String);
let mut key = Vec::new();
key.push(encoded_key);
self.compile_string_data(ped,key);
}
else {
error!("Key '{}' is not recognized! Please provide a valid key, listed in './footswitch-rs --listkeys 4'", key);
}
}
pub fn set_modifier(& mut self, ped:usize, modifier:&str) { pub fn set_modifier(& mut self, ped:usize, modifier:&str) {
let modifier = match key_operations::Modifier::str_to_enum(modifier) { let modifier = match key_operations::Modifier::str_to_enum(modifier) {
Some(x) => x, Some(x) => x,
@ -403,6 +417,16 @@ impl Pedals {
}, },
Some(Type::String) => { Some(Type::String) => {
self.set_type(*ped as usize, Type::String); self.set_type(*ped as usize, Type::String);
// Start byte should be 2
let mut key_vec = Vec::new();
for (i, c) in key_value.iter().enumerate() {
if i >= 2 && *c != 0 {
key_vec.push(*c);
}
}
self.compile_string_data(*ped as usize, key_vec);
}, },
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!"),