mirror of
https://github.com/FliegendeWurst/raspi-oled.git
synced 2024-11-22 02:14:58 +00:00
Hook up two more buttons
This commit is contained in:
parent
10ad65df73
commit
c73ba50caf
@ -1,5 +1,4 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
|
||||||
thread::sleep_ms,
|
thread::sleep_ms,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
@ -12,19 +11,23 @@ use embedded_graphics::{
|
|||||||
text::Text,
|
text::Text,
|
||||||
Drawable,
|
Drawable,
|
||||||
};
|
};
|
||||||
use gpiocdev::line::{Bias, EdgeDetection};
|
use gpiocdev::line::{Bias, EdgeDetection, Value};
|
||||||
use raspi_oled::FrameOutput;
|
use raspi_oled::FrameOutput;
|
||||||
use rppal::{
|
use rppal::{
|
||||||
gpio::Gpio,
|
gpio::{Gpio, OutputPin},
|
||||||
hal::Delay,
|
hal::Delay,
|
||||||
spi::{Bus, Mode, SlaveSelect, Spi},
|
spi::{Bus, Mode, SlaveSelect, Spi},
|
||||||
};
|
};
|
||||||
|
use ssd1351::display::display::Ssd1351;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use time_tz::{timezones::db::europe::BERLIN, OffsetDateTimeExt};
|
use time_tz::{timezones::db::europe::BERLIN, OffsetDateTimeExt};
|
||||||
|
|
||||||
static STAR: &'static [u8] = include_bytes!("../star.raw");
|
static STAR: &'static [u8] = include_bytes!("../star.raw");
|
||||||
static RPI: &'static [u8] = include_bytes!("../rpi.raw");
|
static RPI: &'static [u8] = include_bytes!("../rpi.raw");
|
||||||
|
|
||||||
|
static BLACK: Rgb565 = Rgb565::new(0, 0, 0);
|
||||||
|
static TIME_COLOR: Rgb565 = Rgb565::new(0b01_111, 0b011_111, 0b01_111);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if rppal::system::DeviceInfo::new().is_ok() {
|
if rppal::system::DeviceInfo::new().is_ok() {
|
||||||
rpi_main();
|
rpi_main();
|
||||||
@ -208,7 +211,7 @@ fn rpi_main() {
|
|||||||
|
|
||||||
// Init SPI
|
// Init SPI
|
||||||
let spii = SPIInterfaceNoCS::new(spi, dc);
|
let spii = SPIInterfaceNoCS::new(spi, dc);
|
||||||
let mut disp = ssd1351::display::display::Ssd1351::new(spii);
|
let mut disp = Ssd1351::new(spii);
|
||||||
|
|
||||||
// Reset & init
|
// Reset & init
|
||||||
disp.reset(&mut rst, &mut Delay).unwrap();
|
disp.reset(&mut rst, &mut Delay).unwrap();
|
||||||
@ -217,14 +220,18 @@ fn rpi_main() {
|
|||||||
main_loop(disp);
|
main_loop(disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_loop<D: DrawTarget<Color = Rgb565>>(mut disp: D)
|
fn main_loop(mut disp: Ssd1351<SPIInterfaceNoCS<Spi, OutputPin>>) {
|
||||||
where
|
disp.clear(BLACK).unwrap();
|
||||||
D::Error: Debug,
|
|
||||||
{
|
|
||||||
let mut last_min = 0xff;
|
let mut last_min = 0xff;
|
||||||
let mut last_button = Instant::now();
|
let mut last_button = Instant::now();
|
||||||
|
|
||||||
let mut menu = vec![];
|
let mut menu = vec![];
|
||||||
|
let _high_outputs = gpiocdev::Request::builder()
|
||||||
|
.on_chip("/dev/gpiochip0")
|
||||||
|
.with_lines(&[23, 24])
|
||||||
|
.as_output(Value::Active)
|
||||||
|
.request()
|
||||||
|
.unwrap();
|
||||||
let lines = gpiocdev::Request::builder()
|
let lines = gpiocdev::Request::builder()
|
||||||
.on_chip("/dev/gpiochip0")
|
.on_chip("/dev/gpiochip0")
|
||||||
.with_line(19)
|
.with_line(19)
|
||||||
@ -261,6 +268,7 @@ where
|
|||||||
println!("unknown offset: {}", e.offset);
|
println!("unknown offset: {}", e.offset);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
println!("menu: {menu:?}");
|
||||||
}
|
}
|
||||||
// clean up stale menu selection
|
// clean up stale menu selection
|
||||||
if !menu.is_empty() && Instant::now().duration_since(last_button).as_secs() >= 10 {
|
if !menu.is_empty() && Instant::now().duration_since(last_button).as_secs() >= 10 {
|
||||||
@ -275,6 +283,7 @@ where
|
|||||||
if let Err(e) = loop_iter(&mut disp) {
|
if let Err(e) = loop_iter(&mut disp) {
|
||||||
println!("error: {:?}", e);
|
println!("error: {:?}", e);
|
||||||
}
|
}
|
||||||
|
let _ = disp.flush(); // ignore bus write errors, they are harmless
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +296,7 @@ fn loop_iter<D: DrawTarget<Color = Rgb565>>(disp: &mut D) -> Result<(), D::Error
|
|||||||
fn display_clock<D: DrawTarget<Color = Rgb565>>(disp: &mut D, time: &OffsetDateTime) -> Result<(), D::Error> {
|
fn display_clock<D: DrawTarget<Color = Rgb565>>(disp: &mut D, time: &OffsetDateTime) -> Result<(), D::Error> {
|
||||||
let text_style_clock = MonoTextStyleBuilder::new()
|
let text_style_clock = MonoTextStyleBuilder::new()
|
||||||
.font(&FONT_10X20)
|
.font(&FONT_10X20)
|
||||||
.text_color(Rgb565::new(0xff, 0xff, 0xff))
|
.text_color(TIME_COLOR)
|
||||||
.build();
|
.build();
|
||||||
let hour = time.hour();
|
let hour = time.hour();
|
||||||
let minute = time.minute();
|
let minute = time.minute();
|
||||||
|
@ -161,7 +161,7 @@ impl From<gpiocdev::Error> for SensorError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn am2302_reading() -> Result<(u16, u16), SensorError> {
|
pub fn am2302_reading() -> Result<(u16, u16), SensorError> {
|
||||||
let mut out = gpiocdev::Request::builder()
|
let out = gpiocdev::Request::builder()
|
||||||
.on_chip("/dev/gpiochip0")
|
.on_chip("/dev/gpiochip0")
|
||||||
.with_line(26)
|
.with_line(26)
|
||||||
.as_output(Value::Active)
|
.as_output(Value::Active)
|
||||||
|
Loading…
Reference in New Issue
Block a user