Commit bafea443 authored by tibut's avatar tibut
Browse files

rust-plot-example

parent 43188626
Pipeline #3412 failed with stage
in 5 minutes and 12 seconds
......@@ -3,6 +3,7 @@ members = [
"l0dable",
"example",
"rust-plot-example",
"bhi160-loop",
"rkanoid",
]
default-members = [
......
......@@ -5,7 +5,7 @@ version = "0.0.0"
authors = ["mwall <atzebadekappe@d00m.org>"]
[dependencies]
l0dable = { path = "../l0dable" }
card10-l0dable = { path = "../l0dable" }
[build-dependencies]
cc = "1.0"
use core::fmt::Write;
use l0dable::*;
use card10_l0dable::*;
pub struct LinePlot<'a> {
min: isize,
......
#![no_std]
#![no_main]
use core::fmt::Write;
use l0dable::*;
use core::fmt::{self, Write};
use card10_l0dable::*;
mod line_plot;
main!(main);
......@@ -23,7 +24,7 @@ const SENSOR_ORDER: [SensorType;2] = [SensorType::BME680_GAS, SensorType::BHI160
fn plot_welcome_screen(display: &Display){
// first row
display.print(0, 0, b"BME-sensor\0", Color::white(), Color::black());
display.
// second row
display.print(0, 20, b"visuals\0", Color::white(), Color::black());
......@@ -39,9 +40,16 @@ fn plot_welcome_screen(display: &Display){
}
fn main() {
let result = run();
if let Err(error) = result {
writeln!(UART, "error: {}\r", error);
}
}
fn run() -> Result<(), Error> {
let display = Display::open();
let bme_sensor = BME680::start();
let bhi_acc = BHI160::<Accelerometer>::start();
let bhi_acc = BHI160::<Accelerometer>::start()?;
let mut gas_plot = line_plot::LinePlot::new(0,500000,Color::blue(),&display);
......@@ -54,8 +62,9 @@ fn main() {
loop{
display.clear(Color::white());
gas_plot.update(bme_sensor.read().unwrap().gas_resistance as isize);
for d in &bhi_acc.read() {
let bme_data = bme_sensor.read().unwrap();
gas_plot.update(bme_data.gas_resistance as isize);
for d in &bhi_acc.read()? {
writeln!(UART, "BHI {:?}\r", d).unwrap();
acc_plot_x.update((d.x * 100.0) as isize);
......@@ -111,5 +120,35 @@ fn main() {
}
display.update();
};
}
// -----------------------------------------------------------------------------
// Error
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub enum Error {
UartWriteFailed(fmt::Error),
SensorInteractionFailed(BHI160Error),
}
impl From<fmt::Error> for Error {
fn from(error: fmt::Error) -> Self {
Error::UartWriteFailed(error)
}
}
impl From<BHI160Error> for Error {
fn from(error: BHI160Error) -> Self {
Error::SensorInteractionFailed(error)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::UartWriteFailed(error) => error.fmt(f),
Error::SensorInteractionFailed(error) => error.fmt(f),
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment