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!"), + _ => {} + }; + } + } }