Allow SH1106Dev to fail on new, giving a device that simply ignores commands and issues warnings.
This commit is contained in:
@@ -29,6 +29,7 @@ pub struct SH1106Dev {
|
||||
impl SH1106Dev {
|
||||
pub fn new(delay: &mut Delay, mut i2c: &mut dyn I2c<Error = Error>) -> Self {
|
||||
let mut rx_buff = [0u8; 1];
|
||||
let mut fails = 0;
|
||||
|
||||
loop {
|
||||
let res = match i2c.read(SH1106_I2C_ADDR, &mut rx_buff) {
|
||||
@@ -43,6 +44,15 @@ impl SH1106Dev {
|
||||
break;
|
||||
}
|
||||
|
||||
fails += 1;
|
||||
|
||||
if fails > 10 {
|
||||
warn!("Could not find SH1106. Ignoring.");
|
||||
return Self {
|
||||
ready: false,
|
||||
vertical_flip: false,
|
||||
};
|
||||
}
|
||||
println!("Waiting for sh1106 oled init...");
|
||||
|
||||
delay.delay_ms(500);
|
||||
@@ -68,7 +78,8 @@ impl SH1106Dev {
|
||||
|
||||
pub fn set_vertical_flip(&mut self, i2c: &mut dyn I2c<Error = Error>, flipped: bool) {
|
||||
if !self.ready {
|
||||
panic!("Attempted to use SSH1106 before initialized.");
|
||||
warn!("SSH1106 not initialized, ignoring cmd.");
|
||||
return;
|
||||
}
|
||||
|
||||
self.vertical_flip = flipped;
|
||||
@@ -83,7 +94,8 @@ impl SH1106Dev {
|
||||
|
||||
pub fn blit_framebuffer(&self, i2c: &mut dyn I2c<Error = Error>, gfx_buf: &GraphicsBuf) {
|
||||
if !self.ready {
|
||||
panic!("Attempted to use SSH1106 before initialized.");
|
||||
warn!("SSH1106 not initialized, ignoring cmd.");
|
||||
return;
|
||||
}
|
||||
|
||||
let buf = gfx_buf.get_px_buffer();
|
||||
|
||||
Reference in New Issue
Block a user