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.
This commit is contained in:
parent
74e23a5b5f
commit
43f63c002b
10
src/main.rs
10
src/main.rs
@ -208,6 +208,16 @@ fn main() {
|
||||
{
|
||||
check_length(&pedal, &input);
|
||||
|
||||
let mut unused_pedals: Vec<u8> = 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());
|
||||
}
|
||||
|
@ -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<u8>) {
|
||||
|
||||
// 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!"),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user