From 212dc173824e78d0c224504c3380d0aead04464e Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Fri, 6 Apr 2018 19:05:11 -0500 Subject: [PATCH 01/16] add 'examples/compass_screen.rs' as a demo for gyro and led matrix --- examples/compass_screen.rs | 176 +++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 examples/compass_screen.rs diff --git a/examples/compass_screen.rs b/examples/compass_screen.rs new file mode 100644 index 0000000..cf24d72 --- /dev/null +++ b/examples/compass_screen.rs @@ -0,0 +1,176 @@ +extern crate sensehat; +#[cfg(feature = "led-matrix")] +extern crate sensehat_screen; + +use sensehat::SenseHat; +#[cfg(feature = "led-matrix")] +use sensehat_screen::{FrameLine, PixelColor, Screen}; + +#[cfg(feature = "led-matrix")] +fn main() { + let mut sense_hat = SenseHat::new().expect("Couldn't create Sense HAT object"); + let mut screen = Screen::open("/dev/fb1").expect("Couldn't find Sense HAT LED matrix"); + + //let dark_px = PixelColor::new(0, 0, 0); + let blue_px = PixelColor::new(0, 0, 255); + let grey_px = PixelColor::new(0, 0, 0); + let red_px = PixelColor::new(255, 0, 0); + let background_pixels = vec![ + &blue_px, &blue_px, &grey_px, &grey_px, &grey_px, &grey_px, &blue_px, &blue_px, + &blue_px, &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, &blue_px, + &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, + &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, + &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, + &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, + &blue_px, &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, &blue_px, + &blue_px, &blue_px, &grey_px, &grey_px, &grey_px, &grey_px, &blue_px, &blue_px, + ]; + + let right = { + let mut pxs = background_pixels.clone(); + pxs[31] = &red_px; + pxs[39] = &red_px; + pxs + }; + let right_up = { + let mut pxs = background_pixels.clone(); + pxs[14] = &red_px; + pxs[23] = &red_px; + pxs + }; + let right_down = { + let mut pxs = background_pixels.clone(); + pxs[47] = &red_px; + pxs[54] = &red_px; + pxs + }; + + let up = { + let mut pxs = background_pixels.clone(); + pxs[3] = &red_px; + pxs[4] = &red_px; + pxs + }; + + let up_left = { + let mut pxs = background_pixels.clone(); + pxs[2] = &red_px; + pxs[9] = &red_px; + pxs + }; + let up_right = { + let mut pxs = background_pixels.clone(); + pxs[5] = &red_px; + pxs[14] = &red_px; + pxs + }; + + let left = { + let mut pxs = background_pixels.clone(); + pxs[24] = &red_px; + pxs[32] = &red_px; + pxs + }; + let left_up = { + let mut pxs = background_pixels.clone(); + pxs[9] = &red_px; + pxs[16] = &red_px; + pxs + }; + let left_down = { + let mut pxs = background_pixels.clone(); + pxs[40] = &red_px; + pxs[49] = &red_px; + pxs + }; + + let down = { + let mut pxs = background_pixels.clone(); + pxs[59] = &red_px; + pxs[60] = &red_px; + pxs + }; + let down_left = { + let mut pxs = background_pixels.clone(); + pxs[49] = &red_px; + pxs[58] = &red_px; + pxs + }; + let down_right = { + let mut pxs = background_pixels.clone(); + pxs[54] = &red_px; + pxs[61] = &red_px; + pxs + }; + let bg_frame = FrameLine::from_pixels(&background_pixels); + let left_frame = FrameLine::from_pixels(&left); + let left_up_frame = FrameLine::from_pixels(&left_up); + let left_down_frame = FrameLine::from_pixels(&left_down); + + let right_frame = FrameLine::from_pixels(&right); + let right_up_frame = FrameLine::from_pixels(&right_up); + let right_down_frame = FrameLine::from_pixels(&right_down); + + let up_frame = FrameLine::from_pixels(&up); + let up_left_frame = FrameLine::from_pixels(&up_left); + let up_right_frame = FrameLine::from_pixels(&up_right); + + let down_frame = FrameLine::from_pixels(&down); + let down_left_frame = FrameLine::from_pixels(&down_left); + let down_right_frame = FrameLine::from_pixels(&down_right); + + screen.write_frame(&bg_frame); + + loop { + if let Ok(needle) = sense_hat.get_compass() { + // println!("Compass needle @{}", needle.as_degrees()); + match needle.as_degrees() { + angle if angle > -15.0 && angle <= 15.0 => { + screen.write_frame(&right_frame); + }, + angle if angle > 15.0 && angle <= 45.0 => { + screen.write_frame(&right_up_frame); + }, + angle if angle > 45.0 && angle <= 75.0 => { + screen.write_frame(&up_right_frame); + }, + angle if angle > 75.0 && angle <= 105.0 => { + screen.write_frame(&up_frame); + }, + angle if angle > 105.0 && angle <= 135.0 => { + screen.write_frame(&up_left_frame); + }, + angle if angle > 135.0 && angle <= 165.0 => { + screen.write_frame(&left_up_frame); + }, + angle if (angle > 165.0 && angle <= 180.0) || (angle < -165.0 && angle >= -180.0) => { + screen.write_frame(&left_frame); + }, + angle if angle < -15.0 && angle >= -45.0 => { + screen.write_frame(&right_down_frame); + }, + angle if angle < -45.0 && angle >= -75.0 => { + screen.write_frame(&down_right_frame); + }, + angle if angle < -75.0 && angle >= -105.0 => { + screen.write_frame(&down_frame); + }, + angle if angle < -105.0 && angle >= -135.0 => { + screen.write_frame(&down_left_frame); + }, + angle if angle < -135.0 && angle >= -165.0 => { + screen.write_frame(&left_down_frame); + }, + _ => screen.write_frame(&bg_frame), + } + } + } +} + +#[cfg(not(feature = "led-matrix"))] +fn main() { + println!("the 'led-matrix' feature is required to run this example."); + println!("To run with the 'led-matrix' feature, try:"); + println!(); + println!(" cargo run --features=\"led-matrix\" --example compass_screen") +} From 266c56c35b532d95709c3cbf46e60301a58bf77e Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Fri, 6 Apr 2018 21:44:11 -0500 Subject: [PATCH 02/16] cargo fmt examples/compass_screen.rs --- examples/compass_screen.rs | 124 +++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/examples/compass_screen.rs b/examples/compass_screen.rs index cf24d72..cad26ff 100644 --- a/examples/compass_screen.rs +++ b/examples/compass_screen.rs @@ -27,80 +27,80 @@ fn main() { ]; let right = { - let mut pxs = background_pixels.clone(); - pxs[31] = &red_px; - pxs[39] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[31] = &red_px; + pxs[39] = &red_px; + pxs }; let right_up = { - let mut pxs = background_pixels.clone(); - pxs[14] = &red_px; - pxs[23] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[14] = &red_px; + pxs[23] = &red_px; + pxs }; let right_down = { - let mut pxs = background_pixels.clone(); - pxs[47] = &red_px; - pxs[54] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[47] = &red_px; + pxs[54] = &red_px; + pxs }; let up = { - let mut pxs = background_pixels.clone(); - pxs[3] = &red_px; - pxs[4] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[3] = &red_px; + pxs[4] = &red_px; + pxs }; let up_left = { - let mut pxs = background_pixels.clone(); - pxs[2] = &red_px; - pxs[9] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[2] = &red_px; + pxs[9] = &red_px; + pxs }; let up_right = { - let mut pxs = background_pixels.clone(); - pxs[5] = &red_px; - pxs[14] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[5] = &red_px; + pxs[14] = &red_px; + pxs }; let left = { - let mut pxs = background_pixels.clone(); - pxs[24] = &red_px; - pxs[32] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[24] = &red_px; + pxs[32] = &red_px; + pxs }; let left_up = { - let mut pxs = background_pixels.clone(); - pxs[9] = &red_px; - pxs[16] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[9] = &red_px; + pxs[16] = &red_px; + pxs }; let left_down = { - let mut pxs = background_pixels.clone(); - pxs[40] = &red_px; - pxs[49] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[40] = &red_px; + pxs[49] = &red_px; + pxs }; let down = { - let mut pxs = background_pixels.clone(); - pxs[59] = &red_px; - pxs[60] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[59] = &red_px; + pxs[60] = &red_px; + pxs }; let down_left = { - let mut pxs = background_pixels.clone(); - pxs[49] = &red_px; - pxs[58] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[49] = &red_px; + pxs[58] = &red_px; + pxs }; let down_right = { - let mut pxs = background_pixels.clone(); - pxs[54] = &red_px; - pxs[61] = &red_px; - pxs + let mut pxs = background_pixels.clone(); + pxs[54] = &red_px; + pxs[61] = &red_px; + pxs }; let bg_frame = FrameLine::from_pixels(&background_pixels); let left_frame = FrameLine::from_pixels(&left); @@ -127,40 +127,42 @@ fn main() { match needle.as_degrees() { angle if angle > -15.0 && angle <= 15.0 => { screen.write_frame(&right_frame); - }, + } angle if angle > 15.0 && angle <= 45.0 => { screen.write_frame(&right_up_frame); - }, + } angle if angle > 45.0 && angle <= 75.0 => { screen.write_frame(&up_right_frame); - }, + } angle if angle > 75.0 && angle <= 105.0 => { screen.write_frame(&up_frame); - }, + } angle if angle > 105.0 && angle <= 135.0 => { screen.write_frame(&up_left_frame); - }, + } angle if angle > 135.0 && angle <= 165.0 => { screen.write_frame(&left_up_frame); - }, - angle if (angle > 165.0 && angle <= 180.0) || (angle < -165.0 && angle >= -180.0) => { + } + angle + if (angle > 165.0 && angle <= 180.0) || (angle < -165.0 && angle >= -180.0) => + { screen.write_frame(&left_frame); - }, + } angle if angle < -15.0 && angle >= -45.0 => { screen.write_frame(&right_down_frame); - }, + } angle if angle < -45.0 && angle >= -75.0 => { screen.write_frame(&down_right_frame); - }, + } angle if angle < -75.0 && angle >= -105.0 => { screen.write_frame(&down_frame); - }, + } angle if angle < -105.0 && angle >= -135.0 => { screen.write_frame(&down_left_frame); - }, + } angle if angle < -135.0 && angle >= -165.0 => { screen.write_frame(&left_down_frame); - }, + } _ => screen.write_frame(&bg_frame), } } From 096353c2271f3358ae4bc72b81c0a1d6ab72af6d Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Sun, 8 Apr 2018 16:29:45 -0500 Subject: [PATCH 03/16] remove 'led-matrix' attributes on examples/compass_screen.rs, update pixel color usage --- examples/compass_screen.rs | 87 ++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 50 deletions(-) diff --git a/examples/compass_screen.rs b/examples/compass_screen.rs index cad26ff..cf436bd 100644 --- a/examples/compass_screen.rs +++ b/examples/compass_screen.rs @@ -1,105 +1,100 @@ extern crate sensehat; -#[cfg(feature = "led-matrix")] -extern crate sensehat_screen; -use sensehat::SenseHat; -#[cfg(feature = "led-matrix")] -use sensehat_screen::{FrameLine, PixelColor, Screen}; +use sensehat::{SenseHat, FrameLine, PixelColor, Screen}; -#[cfg(feature = "led-matrix")] fn main() { let mut sense_hat = SenseHat::new().expect("Couldn't create Sense HAT object"); let mut screen = Screen::open("/dev/fb1").expect("Couldn't find Sense HAT LED matrix"); - //let dark_px = PixelColor::new(0, 0, 0); - let blue_px = PixelColor::new(0, 0, 255); - let grey_px = PixelColor::new(0, 0, 0); - let red_px = PixelColor::new(255, 0, 0); + let blue_px = PixelColor::BLUE; + let red_px = PixelColor::RED; + let black_px = PixelColor::BLACK; + let background_pixels = vec![ - &blue_px, &blue_px, &grey_px, &grey_px, &grey_px, &grey_px, &blue_px, &blue_px, - &blue_px, &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, &blue_px, - &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, - &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, - &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, - &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, - &blue_px, &grey_px, &blue_px, &blue_px, &blue_px, &blue_px, &grey_px, &blue_px, - &blue_px, &blue_px, &grey_px, &grey_px, &grey_px, &grey_px, &blue_px, &blue_px, + blue_px, blue_px, black_px, black_px, black_px, black_px, blue_px, blue_px, + blue_px, black_px, blue_px, blue_px, blue_px, blue_px, black_px, blue_px, + black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, + black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, + black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, + black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, + blue_px, black_px, blue_px, blue_px, blue_px, blue_px, black_px, blue_px, + blue_px, blue_px, black_px, black_px, black_px, black_px, blue_px, blue_px, ]; let right = { let mut pxs = background_pixels.clone(); - pxs[31] = &red_px; - pxs[39] = &red_px; + pxs[31] = red_px; + pxs[39] = red_px; pxs }; let right_up = { let mut pxs = background_pixels.clone(); - pxs[14] = &red_px; - pxs[23] = &red_px; + pxs[14] = red_px; + pxs[23] = red_px; pxs }; let right_down = { let mut pxs = background_pixels.clone(); - pxs[47] = &red_px; - pxs[54] = &red_px; + pxs[47] = red_px; + pxs[54] = red_px; pxs }; let up = { let mut pxs = background_pixels.clone(); - pxs[3] = &red_px; - pxs[4] = &red_px; + pxs[3] = red_px; + pxs[4] = red_px; pxs }; let up_left = { let mut pxs = background_pixels.clone(); - pxs[2] = &red_px; - pxs[9] = &red_px; + pxs[2] = red_px; + pxs[9] = red_px; pxs }; let up_right = { let mut pxs = background_pixels.clone(); - pxs[5] = &red_px; - pxs[14] = &red_px; + pxs[5] = red_px; + pxs[14] = red_px; pxs }; let left = { let mut pxs = background_pixels.clone(); - pxs[24] = &red_px; - pxs[32] = &red_px; + pxs[24] = red_px; + pxs[32] = red_px; pxs }; let left_up = { let mut pxs = background_pixels.clone(); - pxs[9] = &red_px; - pxs[16] = &red_px; + pxs[9] = red_px; + pxs[16] = red_px; pxs }; let left_down = { let mut pxs = background_pixels.clone(); - pxs[40] = &red_px; - pxs[49] = &red_px; + pxs[40] = red_px; + pxs[49] = red_px; pxs }; let down = { let mut pxs = background_pixels.clone(); - pxs[59] = &red_px; - pxs[60] = &red_px; + pxs[59] = red_px; + pxs[60] = red_px; pxs }; let down_left = { let mut pxs = background_pixels.clone(); - pxs[49] = &red_px; - pxs[58] = &red_px; + pxs[49] = red_px; + pxs[58] = red_px; pxs }; let down_right = { let mut pxs = background_pixels.clone(); - pxs[54] = &red_px; - pxs[61] = &red_px; + pxs[54] = red_px; + pxs[61] = red_px; pxs }; let bg_frame = FrameLine::from_pixels(&background_pixels); @@ -168,11 +163,3 @@ fn main() { } } } - -#[cfg(not(feature = "led-matrix"))] -fn main() { - println!("the 'led-matrix' feature is required to run this example."); - println!("To run with the 'led-matrix' feature, try:"); - println!(); - println!(" cargo run --features=\"led-matrix\" --example compass_screen") -} From 7a205f6dc766ef7b354caf853015a85f045b6745 Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Sun, 15 Apr 2018 14:34:49 -0500 Subject: [PATCH 04/16] slim-down code in examples/compass_screen.rs --- examples/compass_screen.rs | 142 +++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 78 deletions(-) diff --git a/examples/compass_screen.rs b/examples/compass_screen.rs index cf436bd..2d83b16 100644 --- a/examples/compass_screen.rs +++ b/examples/compass_screen.rs @@ -2,163 +2,149 @@ extern crate sensehat; use sensehat::{SenseHat, FrameLine, PixelColor, Screen}; +const DARK: PixelColor = PixelColor::BLACK; +const BLUE: PixelColor = PixelColor::BLUE; +const RED: PixelColor = PixelColor::RED; + fn main() { let mut sense_hat = SenseHat::new().expect("Couldn't create Sense HAT object"); let mut screen = Screen::open("/dev/fb1").expect("Couldn't find Sense HAT LED matrix"); - let blue_px = PixelColor::BLUE; - let red_px = PixelColor::RED; - let black_px = PixelColor::BLACK; - let background_pixels = vec![ - blue_px, blue_px, black_px, black_px, black_px, black_px, blue_px, blue_px, - blue_px, black_px, blue_px, blue_px, blue_px, blue_px, black_px, blue_px, - black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, - black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, - black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, - black_px, blue_px, blue_px, blue_px, blue_px, blue_px, blue_px, black_px, - blue_px, black_px, blue_px, blue_px, blue_px, blue_px, black_px, blue_px, - blue_px, blue_px, black_px, black_px, black_px, black_px, blue_px, blue_px, + BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // + BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // + BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // + BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // ]; + let background = FrameLine::from_pixels(&background_pixels); + let right = { let mut pxs = background_pixels.clone(); - pxs[31] = red_px; - pxs[39] = red_px; - pxs + pxs[31] = RED; + pxs[39] = RED; + FrameLine::from_pixels(&pxs) }; let right_up = { let mut pxs = background_pixels.clone(); - pxs[14] = red_px; - pxs[23] = red_px; - pxs + pxs[14] = RED; + pxs[23] = RED; + FrameLine::from_pixels(&pxs) }; let right_down = { let mut pxs = background_pixels.clone(); - pxs[47] = red_px; - pxs[54] = red_px; - pxs + pxs[47] = RED; + pxs[54] = RED; + FrameLine::from_pixels(&pxs) }; let up = { let mut pxs = background_pixels.clone(); - pxs[3] = red_px; - pxs[4] = red_px; - pxs + pxs[3] = RED; + pxs[4] = RED; + FrameLine::from_pixels(&pxs) }; let up_left = { let mut pxs = background_pixels.clone(); - pxs[2] = red_px; - pxs[9] = red_px; - pxs + pxs[2] = RED; + pxs[9] = RED; + FrameLine::from_pixels(&pxs) }; let up_right = { let mut pxs = background_pixels.clone(); - pxs[5] = red_px; - pxs[14] = red_px; - pxs + pxs[5] = RED; + pxs[14] = RED; + FrameLine::from_pixels(&pxs) }; let left = { let mut pxs = background_pixels.clone(); - pxs[24] = red_px; - pxs[32] = red_px; - pxs + pxs[24] = RED; + pxs[32] = RED; + FrameLine::from_pixels(&pxs) }; let left_up = { let mut pxs = background_pixels.clone(); - pxs[9] = red_px; - pxs[16] = red_px; - pxs + pxs[9] = RED; + pxs[16] = RED; + FrameLine::from_pixels(&pxs) }; let left_down = { let mut pxs = background_pixels.clone(); - pxs[40] = red_px; - pxs[49] = red_px; - pxs + pxs[40] = RED; + pxs[49] = RED; + FrameLine::from_pixels(&pxs) }; let down = { let mut pxs = background_pixels.clone(); - pxs[59] = red_px; - pxs[60] = red_px; - pxs + pxs[59] = RED; + pxs[60] = RED; + FrameLine::from_pixels(&pxs) }; let down_left = { let mut pxs = background_pixels.clone(); - pxs[49] = red_px; - pxs[58] = red_px; - pxs + pxs[49] = RED; + pxs[58] = RED; + FrameLine::from_pixels(&pxs) }; let down_right = { let mut pxs = background_pixels.clone(); - pxs[54] = red_px; - pxs[61] = red_px; - pxs + pxs[54] = RED; + pxs[61] = RED; + FrameLine::from_pixels(&pxs) }; - let bg_frame = FrameLine::from_pixels(&background_pixels); - let left_frame = FrameLine::from_pixels(&left); - let left_up_frame = FrameLine::from_pixels(&left_up); - let left_down_frame = FrameLine::from_pixels(&left_down); - - let right_frame = FrameLine::from_pixels(&right); - let right_up_frame = FrameLine::from_pixels(&right_up); - let right_down_frame = FrameLine::from_pixels(&right_down); - - let up_frame = FrameLine::from_pixels(&up); - let up_left_frame = FrameLine::from_pixels(&up_left); - let up_right_frame = FrameLine::from_pixels(&up_right); - - let down_frame = FrameLine::from_pixels(&down); - let down_left_frame = FrameLine::from_pixels(&down_left); - let down_right_frame = FrameLine::from_pixels(&down_right); - screen.write_frame(&bg_frame); + screen.write_frame(&background); loop { if let Ok(needle) = sense_hat.get_compass() { // println!("Compass needle @{}", needle.as_degrees()); match needle.as_degrees() { angle if angle > -15.0 && angle <= 15.0 => { - screen.write_frame(&right_frame); + screen.write_frame(&right); } angle if angle > 15.0 && angle <= 45.0 => { - screen.write_frame(&right_up_frame); + screen.write_frame(&right_up); } angle if angle > 45.0 && angle <= 75.0 => { - screen.write_frame(&up_right_frame); + screen.write_frame(&up_right); } angle if angle > 75.0 && angle <= 105.0 => { - screen.write_frame(&up_frame); + screen.write_frame(&up); } angle if angle > 105.0 && angle <= 135.0 => { - screen.write_frame(&up_left_frame); + screen.write_frame(&up_left); } angle if angle > 135.0 && angle <= 165.0 => { - screen.write_frame(&left_up_frame); + screen.write_frame(&left_up); } angle if (angle > 165.0 && angle <= 180.0) || (angle < -165.0 && angle >= -180.0) => { - screen.write_frame(&left_frame); + screen.write_frame(&left); } angle if angle < -15.0 && angle >= -45.0 => { - screen.write_frame(&right_down_frame); + screen.write_frame(&right_down); } angle if angle < -45.0 && angle >= -75.0 => { - screen.write_frame(&down_right_frame); + screen.write_frame(&down_right); } angle if angle < -75.0 && angle >= -105.0 => { - screen.write_frame(&down_frame); + screen.write_frame(&down); } angle if angle < -105.0 && angle >= -135.0 => { - screen.write_frame(&down_left_frame); + screen.write_frame(&down_left); } angle if angle < -135.0 && angle >= -165.0 => { - screen.write_frame(&left_down_frame); + screen.write_frame(&left_down); } - _ => screen.write_frame(&bg_frame), + _ => screen.write_frame(&background), } } } From d2da0c4a8592a44a0785de6af902121269ffaf2c Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Sun, 22 Apr 2018 22:01:46 -0500 Subject: [PATCH 05/16] update sensehat-screen to v0.1.6 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3cee34b..e2c69ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" measurements = "0.10.2" i2cdev = "0.4.0" byteorder = "1.0" -sensehat-screen = "0.1.4" +sensehat-screen = "0.1.6" # sensehat-screen = { path = "../sensehat-screen-rs" } libc = { version = "0.2", optional = true } From 985d5d2189d6d66f67f8ac1b01ec554dd20b4e88 Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Mon, 30 Apr 2018 19:17:09 -0500 Subject: [PATCH 06/16] update sensehat-screen to v0.1.8 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e2c69ff..391a8d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" measurements = "0.10.2" i2cdev = "0.4.0" byteorder = "1.0" -sensehat-screen = "0.1.6" +sensehat-screen = "0.1.8" # sensehat-screen = { path = "../sensehat-screen-rs" } libc = { version = "0.2", optional = true } From 5e9172960ab3f402bcf43b1128546ca11ca2869a Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Mon, 30 Apr 2018 19:17:37 -0500 Subject: [PATCH 07/16] update path to FramebufferError --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bbf71a7..d387f6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,7 +103,7 @@ pub enum SenseHatError { PositionOutOfBounds, I2CError(LinuxI2CError), LSM9DS1Error(lsm9ds1::Error), - FramebufferError(sensehat_screen::FramebufferError) + FramebufferError(sensehat_screen::framebuffer::FramebufferError) } /// An image on the LED matrix @@ -363,8 +363,8 @@ impl From for SenseHatError { } } -impl From for SenseHatError { - fn from(err: sensehat_screen::FramebufferError) -> SenseHatError { +impl From for SenseHatError { + fn from(err: sensehat_screen::framebuffer::FramebufferError) -> SenseHatError { SenseHatError::FramebufferError(err) } } From cdbf6f043140b254ad5e09285b0b44528bfe99bb Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Mon, 30 Apr 2018 19:18:40 -0500 Subject: [PATCH 08/16] update examples/compass_screen.rs to use newer PixelFrame type instead of FrameLine --- examples/compass_screen.rs | 126 +++++++++++++------------------------ 1 file changed, 44 insertions(+), 82 deletions(-) diff --git a/examples/compass_screen.rs b/examples/compass_screen.rs index 2d83b16..3060476 100644 --- a/examples/compass_screen.rs +++ b/examples/compass_screen.rs @@ -1,6 +1,8 @@ extern crate sensehat; +extern crate sensehat_screen; use sensehat::{SenseHat, FrameLine, PixelColor, Screen}; +use sensehat_screen::PixelFrame; const DARK: PixelColor = PixelColor::BLACK; const BLUE: PixelColor = PixelColor::BLUE; @@ -11,140 +13,100 @@ fn main() { let mut screen = Screen::open("/dev/fb1").expect("Couldn't find Sense HAT LED matrix"); let background_pixels = vec![ - BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // - BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // - BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // - BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // + BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // 0-7 + BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // 8-15 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 16-23 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 24-31 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 32-39 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 40-47 + BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // 48-55 + BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // 56-63 ]; - let background = FrameLine::from_pixels(&background_pixels); + let background = PixelFrame::new(&background_pixels); let right = { let mut pxs = background_pixels.clone(); + pxs[23] = RED.dim(0.5); + pxs[47] = RED; pxs[31] = RED; - pxs[39] = RED; - FrameLine::from_pixels(&pxs) + pxs[39] = RED;.dim(0.5) + PixelFrame::new(&pxs) }; let right_up = { let mut pxs = background_pixels.clone(); + pxs[5] = RED.dim(0.5); pxs[14] = RED; pxs[23] = RED; - FrameLine::from_pixels(&pxs) + pxs[31] = RED.dim(0.5); + PixelFrame::new(&pxs) }; let right_down = { let mut pxs = background_pixels.clone(); + pxs[39] = RED.dim(0.5); pxs[47] = RED; pxs[54] = RED; - FrameLine::from_pixels(&pxs) + pxs[61] = RED.dim(0.5); + PixelFrame::new(&pxs) }; - let up = { - let mut pxs = background_pixels.clone(); - pxs[3] = RED; - pxs[4] = RED; - FrameLine::from_pixels(&pxs) - }; + let up = right.rotate_left(); + let up_left = right_up.rotate_left(); + let up_right = right_down.rotate_left(); - let up_left = { - let mut pxs = background_pixels.clone(); - pxs[2] = RED; - pxs[9] = RED; - FrameLine::from_pixels(&pxs) - }; - let up_right = { - let mut pxs = background_pixels.clone(); - pxs[5] = RED; - pxs[14] = RED; - FrameLine::from_pixels(&pxs) - }; - - let left = { - let mut pxs = background_pixels.clone(); - pxs[24] = RED; - pxs[32] = RED; - FrameLine::from_pixels(&pxs) - }; - let left_up = { - let mut pxs = background_pixels.clone(); - pxs[9] = RED; - pxs[16] = RED; - FrameLine::from_pixels(&pxs) - }; - let left_down = { - let mut pxs = background_pixels.clone(); - pxs[40] = RED; - pxs[49] = RED; - FrameLine::from_pixels(&pxs) - }; + let left = right.rotate_180(); + let left_up = right_down.rotate_180(); + let left_down = right_up.rotate_180(); - let down = { - let mut pxs = background_pixels.clone(); - pxs[59] = RED; - pxs[60] = RED; - FrameLine::from_pixels(&pxs) - }; - let down_left = { - let mut pxs = background_pixels.clone(); - pxs[49] = RED; - pxs[58] = RED; - FrameLine::from_pixels(&pxs) - }; - let down_right = { - let mut pxs = background_pixels.clone(); - pxs[54] = RED; - pxs[61] = RED; - FrameLine::from_pixels(&pxs) - }; + let down = up.rotate_180(); + let down_left = up_right.rotate_180(); + let down_right = up_left.rotate_180(); - screen.write_frame(&background); + screen.write_frame(&background.frame_line()); loop { if let Ok(needle) = sense_hat.get_compass() { // println!("Compass needle @{}", needle.as_degrees()); match needle.as_degrees() { angle if angle > -15.0 && angle <= 15.0 => { - screen.write_frame(&right); + screen.write_frame(&right.frame_line()); } angle if angle > 15.0 && angle <= 45.0 => { - screen.write_frame(&right_up); + screen.write_frame(&right_up.frame_line()); } angle if angle > 45.0 && angle <= 75.0 => { - screen.write_frame(&up_right); + screen.write_frame(&up_right.frame_line()); } angle if angle > 75.0 && angle <= 105.0 => { - screen.write_frame(&up); + screen.write_frame(&up.frame_line()); } angle if angle > 105.0 && angle <= 135.0 => { - screen.write_frame(&up_left); + screen.write_frame(&up_left.frame_line()); } angle if angle > 135.0 && angle <= 165.0 => { - screen.write_frame(&left_up); + screen.write_frame(&left_up.frame_line()); } angle if (angle > 165.0 && angle <= 180.0) || (angle < -165.0 && angle >= -180.0) => { - screen.write_frame(&left); + screen.write_frame(&left.frame_line()); } angle if angle < -15.0 && angle >= -45.0 => { - screen.write_frame(&right_down); + screen.write_frame(&right_down.frame_line()); } angle if angle < -45.0 && angle >= -75.0 => { - screen.write_frame(&down_right); + screen.write_frame(&down_right.frame_line()); } angle if angle < -75.0 && angle >= -105.0 => { - screen.write_frame(&down); + screen.write_frame(&down.frame_line()); } angle if angle < -105.0 && angle >= -135.0 => { - screen.write_frame(&down_left); + screen.write_frame(&down_left.frame_line()); } angle if angle < -135.0 && angle >= -165.0 => { - screen.write_frame(&left_down); + screen.write_frame(&left_down.frame_line()); } - _ => screen.write_frame(&background), + _ => screen.write_frame(&background.frame_line()), } } } From 1289df58515c758bb1a056c77c627ec716d04706 Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Mon, 30 Apr 2018 23:52:37 -0500 Subject: [PATCH 09/16] change Image([PixelColor; 64]) to Image(PixelFrame) from sensehat_screen Update Image methods to take advantage of the PixelFrame API --- src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d387f6e..27c6512 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,7 +108,7 @@ pub enum SenseHatError { /// An image on the LED matrix #[derive(Clone)] -pub struct Image([PixelColor; LED_NUM_PIXELS]); +pub struct Image(PixelFrame); /// A shortcut for Results that can return `T` or `SenseHatError` pub type SenseHatResult = Result; @@ -128,7 +128,6 @@ impl<'a> SenseHat<'a> { /// Will open the relevant I2C devices and then attempt to initialise the /// chips on the Sense HAT. pub fn new() -> SenseHatResult> { - let blue_pixel = PixelColor::new(0, 0, 255); Ok(SenseHat { humidity_chip: hts221::Hts221::new(LinuxI2CDevice::new("/dev/i2c-1", 0x5f)?)?, pressure_chip: lps25h::Lps25h::new(LinuxI2CDevice::new("/dev/i2c-1", 0x5c)?)?, @@ -139,7 +138,7 @@ impl<'a> SenseHat<'a> { yaw: Angle::from_degrees(0.0), }, rotation: Rotation::Normal, - image: Image([blue_pixel; LED_NUM_PIXELS]), + image: Image(PixelFrame::BLUE), screen: Screen::open("/dev/fb1")? }) } @@ -301,9 +300,7 @@ impl<'a> SenseHat<'a> { /// Clear the display pub fn clear(&mut self, color: PixelColor, redraw: DrawMode) -> SenseHatResult<()> { - for pixel in self.image.0.iter_mut() { - *pixel = color; - } + self.image = Image(PixelFrame::new(&[color; LED_NUM_PIXELS])); match redraw { DrawMode::OutputNow => self.redraw(), _ => {} @@ -313,7 +310,7 @@ impl<'a> SenseHat<'a> { pub fn redraw(&mut self) { let image = self.image.rotate_copy(self.rotation); - let frame = FrameLine::from_pixels(&image.0); + let frame = image.0.frame_line(); self.screen.write_frame(&frame); } } @@ -333,13 +330,13 @@ impl Image { match rotation { Rotation::Normal => {}, Rotation::Clockwise90 => { - unimplemented!() + self.0.rotate(Rotate::Ccw270); } Rotation::Clockwise180 => { - unimplemented!() + self.0.rotate(Rotate::Ccw180); } Rotation::Clockwise270 => { - unimplemented!() + self.0.rotate(Rotate::Ccw90); } } } From 497ef6e510c042915c3eea7e9a6caa5e9bf42f2e Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Tue, 1 May 2018 00:02:28 -0500 Subject: [PATCH 10/16] create PixelFrame from [PixelColor; 64 in ::clear --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 27c6512..0a617ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ pub use measurements::Pressure; pub use measurements::Angle; pub use rh::RelativeHumidity; -pub use sensehat_screen::{FrameLine, PixelColor, Screen}; +pub use sensehat_screen::{FrameLine, PixelFrame, PixelColor, Rotate, Screen}; use i2cdev::linux::{LinuxI2CDevice, LinuxI2CError}; @@ -300,7 +300,7 @@ impl<'a> SenseHat<'a> { /// Clear the display pub fn clear(&mut self, color: PixelColor, redraw: DrawMode) -> SenseHatResult<()> { - self.image = Image(PixelFrame::new(&[color; LED_NUM_PIXELS])); + self.image = Image([color; LED_NUM_PIXELS].into()); match redraw { DrawMode::OutputNow => self.redraw(), _ => {} From 6139da5ce37c2970a2930bb97da86980d2216902 Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Tue, 1 May 2018 00:03:32 -0500 Subject: [PATCH 11/16] update examples/compass_screen.rs to use latest screen version --- examples/compass_screen.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/compass_screen.rs b/examples/compass_screen.rs index 3060476..67e14a3 100644 --- a/examples/compass_screen.rs +++ b/examples/compass_screen.rs @@ -1,8 +1,8 @@ extern crate sensehat; extern crate sensehat_screen; -use sensehat::{SenseHat, FrameLine, PixelColor, Screen}; -use sensehat_screen::PixelFrame; +use sensehat::{SenseHat, PixelColor, Screen}; +use sensehat_screen::{PixelFrame, Rotate}; const DARK: PixelColor = PixelColor::BLACK; const BLUE: PixelColor = PixelColor::BLUE; @@ -12,7 +12,7 @@ fn main() { let mut sense_hat = SenseHat::new().expect("Couldn't create Sense HAT object"); let mut screen = Screen::open("/dev/fb1").expect("Couldn't find Sense HAT LED matrix"); - let background_pixels = vec![ + let background_pixels = [ BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // 0-7 BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // 8-15 DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 16-23 @@ -26,15 +26,15 @@ fn main() { let background = PixelFrame::new(&background_pixels); let right = { - let mut pxs = background_pixels.clone(); + let mut pxs = background_pixels; pxs[23] = RED.dim(0.5); pxs[47] = RED; pxs[31] = RED; - pxs[39] = RED;.dim(0.5) + pxs[39] = RED.dim(0.5); PixelFrame::new(&pxs) }; let right_up = { - let mut pxs = background_pixels.clone(); + let mut pxs = background_pixels; pxs[5] = RED.dim(0.5); pxs[14] = RED; pxs[23] = RED; @@ -42,7 +42,7 @@ fn main() { PixelFrame::new(&pxs) }; let right_down = { - let mut pxs = background_pixels.clone(); + let mut pxs = background_pixels; pxs[39] = RED.dim(0.5); pxs[47] = RED; pxs[54] = RED; @@ -50,17 +50,17 @@ fn main() { PixelFrame::new(&pxs) }; - let up = right.rotate_left(); - let up_left = right_up.rotate_left(); - let up_right = right_down.rotate_left(); + let up = right.rotate(Rotate::Ccw90); + let up_left = right_up.rotate(Rotate::Ccw90); + let up_right = right_down.rotate(Rotate::Ccw90); - let left = right.rotate_180(); - let left_up = right_down.rotate_180(); - let left_down = right_up.rotate_180(); + let left = right.rotate(Rotate::Ccw180); + let left_up = right_down.rotate(Rotate::Ccw180); + let left_down = right_up.rotate(Rotate::Ccw180); - let down = up.rotate_180(); - let down_left = up_right.rotate_180(); - let down_right = up_left.rotate_180(); + let down = up.rotate(Rotate::Ccw180); + let down_left = up_right.rotate(Rotate::Ccw180); + let down_right = up_left.rotate(Rotate::Ccw180); screen.write_frame(&background.frame_line()); From f4a629ecb381cf859bd4af8b4a9b0e182785d02b Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Tue, 1 May 2018 01:08:23 -0500 Subject: [PATCH 12/16] Image implements Copy and Debug --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0a617ef..1996804 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,7 +107,7 @@ pub enum SenseHatError { } /// An image on the LED matrix -#[derive(Clone)] +#[derive(Copy, Clone, Debug)] pub struct Image(PixelFrame); /// A shortcut for Results that can return `T` or `SenseHatError` From a25221eb21a65543e6e9800f5432e7f0b47c1a89 Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Tue, 1 May 2018 01:08:57 -0500 Subject: [PATCH 13/16] make Image::rotate_copy a public method --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1996804..03c9e4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -341,8 +341,8 @@ impl Image { } } - fn rotate_copy(&self, rotation: Rotation) -> Image { - let mut im = self.clone(); + pub fn rotate_copy(&self, rotation: Rotation) -> Image { + let mut im = *self; im.rotate_mut(rotation); im } From 811d7965d358ab99ed84864fcf473781c560a2b5 Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Tue, 1 May 2018 01:09:29 -0500 Subject: [PATCH 14/16] Image implements From<[PixelColor; LED_NUM_PIXELS]> --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 03c9e4f..dae77c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -366,4 +366,9 @@ impl From for SenseHatError { } } +impl From<[PixelColor; LED_NUM_PIXELS]> for Image { + fn from(array: [PixelColor; 64]) -> Self { + Image(array.into()) + } +} // End of file From 837e6a04e08d8c740fca160570f6f9b77adf6e11 Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Tue, 1 May 2018 01:10:06 -0500 Subject: [PATCH 15/16] update examples/compass_screen to use the Matrix API --- examples/compass_screen.rs | 92 +++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/examples/compass_screen.rs b/examples/compass_screen.rs index 67e14a3..b9f02eb 100644 --- a/examples/compass_screen.rs +++ b/examples/compass_screen.rs @@ -1,112 +1,110 @@ extern crate sensehat; extern crate sensehat_screen; -use sensehat::{SenseHat, PixelColor, Screen}; -use sensehat_screen::{PixelFrame, Rotate}; +use sensehat::{Image, PixelColor, Rotation, SenseHat}; const DARK: PixelColor = PixelColor::BLACK; const BLUE: PixelColor = PixelColor::BLUE; const RED: PixelColor = PixelColor::RED; +const BACKGROUND: [PixelColor; 64] = [ + BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // 0-7 + BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // 8-15 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 16-23 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 24-31 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 32-39 + DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 40-47 + BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // 48-55 + BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // 56-63 +]; + fn main() { let mut sense_hat = SenseHat::new().expect("Couldn't create Sense HAT object"); - let mut screen = Screen::open("/dev/fb1").expect("Couldn't find Sense HAT LED matrix"); - - let background_pixels = [ - BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // 0-7 - BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // 8-15 - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 16-23 - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 24-31 - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 32-39 - DARK, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, DARK, // 40-47 - BLUE, DARK, BLUE, BLUE, BLUE, BLUE, DARK, BLUE, // 48-55 - BLUE, BLUE, DARK, DARK, DARK, DARK, BLUE, BLUE, // 56-63 - ]; - let background = PixelFrame::new(&background_pixels); + let background: Image = BACKGROUND.into(); - let right = { - let mut pxs = background_pixels; + let right: Image = { + let mut pxs = BACKGROUND; pxs[23] = RED.dim(0.5); pxs[47] = RED; pxs[31] = RED; pxs[39] = RED.dim(0.5); - PixelFrame::new(&pxs) + pxs.into() }; - let right_up = { - let mut pxs = background_pixels; + let right_up: Image = { + let mut pxs = BACKGROUND; pxs[5] = RED.dim(0.5); pxs[14] = RED; pxs[23] = RED; pxs[31] = RED.dim(0.5); - PixelFrame::new(&pxs) + pxs.into() }; - let right_down = { - let mut pxs = background_pixels; + let right_down: Image = { + let mut pxs = BACKGROUND; pxs[39] = RED.dim(0.5); pxs[47] = RED; pxs[54] = RED; pxs[61] = RED.dim(0.5); - PixelFrame::new(&pxs) + pxs.into() }; - let up = right.rotate(Rotate::Ccw90); - let up_left = right_up.rotate(Rotate::Ccw90); - let up_right = right_down.rotate(Rotate::Ccw90); + let up = right.rotate_copy(Rotation::Clockwise270); + let up_left = right_up.rotate_copy(Rotation::Clockwise270); + let up_right = right_down.rotate_copy(Rotation::Clockwise270); - let left = right.rotate(Rotate::Ccw180); - let left_up = right_down.rotate(Rotate::Ccw180); - let left_down = right_up.rotate(Rotate::Ccw180); + let left = right.rotate_copy(Rotation::Clockwise180); + let left_up = right_down.rotate_copy(Rotation::Clockwise180); + let left_down = right_up.rotate_copy(Rotation::Clockwise180); - let down = up.rotate(Rotate::Ccw180); - let down_left = up_right.rotate(Rotate::Ccw180); - let down_right = up_left.rotate(Rotate::Ccw180); + let down = up.rotate_copy(Rotation::Clockwise180); + let down_left = up_right.rotate_copy(Rotation::Clockwise180); + let down_right = up_left.rotate_copy(Rotation::Clockwise180); - screen.write_frame(&background.frame_line()); + sense_hat.set_pixels(background).unwrap(); loop { if let Ok(needle) = sense_hat.get_compass() { // println!("Compass needle @{}", needle.as_degrees()); match needle.as_degrees() { angle if angle > -15.0 && angle <= 15.0 => { - screen.write_frame(&right.frame_line()); + sense_hat.set_pixels(right).unwrap(); } angle if angle > 15.0 && angle <= 45.0 => { - screen.write_frame(&right_up.frame_line()); + sense_hat.set_pixels(right_up).unwrap(); } angle if angle > 45.0 && angle <= 75.0 => { - screen.write_frame(&up_right.frame_line()); + sense_hat.set_pixels(up_right).unwrap(); } angle if angle > 75.0 && angle <= 105.0 => { - screen.write_frame(&up.frame_line()); + sense_hat.set_pixels(up).unwrap(); } angle if angle > 105.0 && angle <= 135.0 => { - screen.write_frame(&up_left.frame_line()); + sense_hat.set_pixels(up_left).unwrap(); } angle if angle > 135.0 && angle <= 165.0 => { - screen.write_frame(&left_up.frame_line()); + sense_hat.set_pixels(left_up).unwrap(); } angle if (angle > 165.0 && angle <= 180.0) || (angle < -165.0 && angle >= -180.0) => { - screen.write_frame(&left.frame_line()); + sense_hat.set_pixels(left).unwrap(); } angle if angle < -15.0 && angle >= -45.0 => { - screen.write_frame(&right_down.frame_line()); + sense_hat.set_pixels(right_down).unwrap(); } angle if angle < -45.0 && angle >= -75.0 => { - screen.write_frame(&down_right.frame_line()); + sense_hat.set_pixels(down_right).unwrap(); } angle if angle < -75.0 && angle >= -105.0 => { - screen.write_frame(&down.frame_line()); + sense_hat.set_pixels(down).unwrap(); } angle if angle < -105.0 && angle >= -135.0 => { - screen.write_frame(&down_left.frame_line()); + sense_hat.set_pixels(down_left).unwrap(); } angle if angle < -135.0 && angle >= -165.0 => { - screen.write_frame(&left_down.frame_line()); + sense_hat.set_pixels(left_down).unwrap(); } - _ => screen.write_frame(&background.frame_line()), + _ => sense_hat.set_pixels(background).unwrap(), } } } From 07efb93d48b4b9148b7c841defe11c916a6fb18e Mon Sep 17 00:00:00 2001 From: Joaquin Rosales Date: Tue, 1 May 2018 23:52:26 -0500 Subject: [PATCH 16/16] update to sensehat-screen v0.1.9 in Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 391a8d9..a95e75f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" measurements = "0.10.2" i2cdev = "0.4.0" byteorder = "1.0" -sensehat-screen = "0.1.8" +sensehat-screen = "0.1.9" # sensehat-screen = { path = "../sensehat-screen-rs" } libc = { version = "0.2", optional = true }