From 43f63c002b82f1f77d15fc753cdafcf310ec2217 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 14 Nov 2018 01:29:39 +0100 Subject: [PATCH] Added beginning of function to preserve settings This is the beginning of a solution to issue #3. Right now, it is only able to preserve keys. In a later commit, modifiers, mouse settings, etc. will be added as well. --- src/main.rs | 10 ++++++++++ src/pedal_operations.rs | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/main.rs b/src/main.rs index 3c42f9a..31d7858 100644 --- a/src/main.rs +++ b/src/main.rs @@ -208,6 +208,16 @@ fn main() { { check_length(&pedal, &input); + let mut unused_pedals: Vec = Vec::new(); + + 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()); } diff --git a/src/pedal_operations.rs b/src/pedal_operations.rs index e6bf9a2..cfe1e74 100644 --- a/src/pedal_operations.rs +++ b/src/pedal_operations.rs @@ -378,4 +378,25 @@ impl Pedals { goodbye(); } + + /// Prevent the application from purging pedals that are not + /// explicitly set + pub fn refresh_values(& mut self, peds: Vec) { + + // First read from pedals that are defined in peds + for (i, ped) in peds.iter().enumerate() { + // Read value from pedal and directly translate it to a key + let mut key_value = self.read_pedal(ped); + + match Type::u8_to_enum(key_value[1]) { + Some(Type::Key) => { + self.set_type(*ped as usize, Type::Key); + self.ped_data[*ped as usize].data[3] = key_value[3]; + }, + + None => error!("The key type which was returned by the pedal was invalid!"), + _ => {} + }; + } + } }