@@ 2,7 2,7 @@ use super::sipo;
pub struct FilledSipo {
shift_register: sipo::Sipo,
- data: u16,
+ data: [u8; 2],
update_step: u8
}
@@ 10,12 10,12 @@ impl FilledSipo {
pub fn create(shift_register: sipo::Sipo) -> FilledSipo {
FilledSipo {
shift_register,
- data: 0,
+ data: [0,0],
update_step: 0
}
}
- pub fn set_data(&mut self, data: u16) {
+ pub fn set_data(&mut self, data: [u8; 2]) {
self.data = data;
self.reset();
}
@@ 27,7 27,13 @@ impl FilledSipo {
}
pub fn step(&mut self) -> bool {
- self.shift_register.shift_value((self.data >> (15 - self.update_step)) & 1 == 1);
+ let mut index = 0;
+ let mut move_factor = self.update_step;
+ if self.update_step >= 8 {
+ index = 1;
+ move_factor -= 8;
+ }
+ self.shift_register.shift_value((self.data[index] >> (7 - move_factor)) & 1 == 1);
if self.update_step >= 15 {
self.update_step = 0;
@@ 45,7 51,7 @@ impl FilledSipo {
}
pub fn clear(&mut self) {
- self.set_data(0);
+ self.set_data([0, 0]);
self.reset();
}
}
@@ 91,13 91,10 @@ impl SevenSegment {
segments = !segments;
}
- let segments: u16 = segments.into();
- let digit_selector: u16 = digit_selector.into();
-
if self.dp {
- sipo.set_data(digit_selector << 8 | segments);
+ sipo.set_data([digit_selector, segments]);
} else {
- sipo.set_data(digit_selector << 7 | (segments & 0x7F));
+ sipo.set_data([digit_selector >> 1, (digit_selector & 0x01 << 7) | (segments & 0x7F)]);
}
return true;
}