Skip to content
Snippets Groups Projects
Commit b3a86794 authored by zdmx's avatar zdmx :crab:
Browse files

reenable imu, just ignore errors for now

parent b02f3a6c
No related branches found
No related tags found
No related merge requests found
use crate::flow3r::{captouch::CaptouchHandler, display::Display, imu::ImuHandler}; use crate::flow3r::{captouch::CaptouchHandler, display::Display, imu::ImuHandler};
use bmi270::AxisData; use embassy_futures::select::{select, select3, Either, Either3};
use embassy_futures::select::{select, select3, select_array, Either, Either3};
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use embedded_graphics::{ use embedded_graphics::{
image::Image, image::Image,
...@@ -109,7 +108,7 @@ pub async fn draw_start_screen(display: &mut Display) { ...@@ -109,7 +108,7 @@ pub async fn draw_start_screen(display: &mut Display) {
display.set_backlight(100).unwrap(); display.set_backlight(100).unwrap();
} }
pub async fn imu_demo(display: &mut Display /*imu: &mut ImuHandler*/) { pub async fn imu_demo(display: &mut Display, imu: &mut ImuHandler) {
let input = InputHandler; let input = InputHandler;
let mut inputs = input.split(); let mut inputs = input.split();
...@@ -125,8 +124,7 @@ pub async fn imu_demo(display: &mut Display /*imu: &mut ImuHandler*/) { ...@@ -125,8 +124,7 @@ pub async fn imu_demo(display: &mut Display /*imu: &mut ImuHandler*/) {
let mut offset = (0i32, 0i32); let mut offset = (0i32, 0i32);
loop { loop {
match select(inputs.sw2_center.wait_for_press(), async { match select(inputs.sw2_center.wait_for_press(), async {
//let imu_value = imu.rotation().unwrap(); let imu_value = imu.rotation().unwrap();
let imu_value = AxisData { x: 5, y: 5, z: 0 };
offset = ( offset = (
(-80).max(80.min(offset.0 + imu_value.x as i32)), (-80).max(80.min(offset.0 + imu_value.x as i32)),
(-80).max(80.min(offset.1 + imu_value.y as i32)), (-80).max(80.min(offset.1 + imu_value.y as i32)),
......
...@@ -11,10 +11,11 @@ impl ImuHandler { ...@@ -11,10 +11,11 @@ impl ImuHandler {
pub fn new(i2c: I2cProxy<'static, XtensaMutex<I2C<'static, I2C0>>>) -> Self { pub fn new(i2c: I2cProxy<'static, XtensaMutex<I2C<'static, I2C0>>>) -> Self {
let mut bmi270 = Bmi270::new_i2c(i2c, bmi270::I2cAddr::Default, bmi270::Burst::Max); let mut bmi270 = Bmi270::new_i2c(i2c, bmi270::I2cAddr::Default, bmi270::Burst::Max);
let chip_id = bmi270.get_chip_id().unwrap(); if let Some(chip_id) = bmi270.get_chip_id().ok() {
println!("imu chip id: {}", chip_id); println!("imu chip id: {}", chip_id);
}
bmi270.init().unwrap(); bmi270.init().ok();
let pwr_ctrl = PwrCtrl { let pwr_ctrl = PwrCtrl {
aux_en: false, aux_en: false,
...@@ -22,7 +23,7 @@ impl ImuHandler { ...@@ -22,7 +23,7 @@ impl ImuHandler {
acc_en: true, acc_en: true,
temp_en: false, temp_en: false,
}; };
bmi270.set_pwr_ctrl(pwr_ctrl).unwrap(); bmi270.set_pwr_ctrl(pwr_ctrl).ok();
Self { imu: bmi270 } Self { imu: bmi270 }
} }
......
use self::badgelink::BadgeLink; use self::badgelink::BadgeLink;
use self::captouch::CaptouchHandler; use self::captouch::CaptouchHandler;
use self::display::Display; use self::display::Display;
//use self::imu::ImuHandler; use self::imu::ImuHandler;
use self::input::InputHandler; use self::input::InputHandler;
use self::leds::Leds; use self::leds::Leds;
...@@ -18,7 +18,7 @@ pub struct Flow3r { ...@@ -18,7 +18,7 @@ pub struct Flow3r {
pub badgelink: BadgeLink, pub badgelink: BadgeLink,
pub captouch: CaptouchHandler, pub captouch: CaptouchHandler,
pub display: Display, pub display: Display,
//pub imu: ImuHandler, pub imu: ImuHandler,
pub inputs: InputHandler, pub inputs: InputHandler,
pub leds: Leds, pub leds: Leds,
} }
...@@ -28,7 +28,7 @@ impl Flow3r { ...@@ -28,7 +28,7 @@ impl Flow3r {
badgelink: BadgeLink, badgelink: BadgeLink,
captouch: CaptouchHandler, captouch: CaptouchHandler,
display: Display, display: Display,
//imu: ImuHandler, imu: ImuHandler,
inputs: InputHandler, inputs: InputHandler,
leds: Leds, leds: Leds,
) -> Self { ) -> Self {
...@@ -36,7 +36,7 @@ impl Flow3r { ...@@ -36,7 +36,7 @@ impl Flow3r {
badgelink, badgelink,
captouch, captouch,
display, display,
//imu, imu,
inputs, inputs,
leds, leds,
} }
......
...@@ -9,10 +9,10 @@ use embedded_graphics::{ ...@@ -9,10 +9,10 @@ use embedded_graphics::{
use crate::{ use crate::{
demo_tasks::{display_demo, imu_demo, captouch_demo}, demo_tasks::{display_demo, imu_demo, captouch_demo},
flow3r::{display::Display, input::InputHandler}, flow3r::{display::Display, input::InputHandler, imu::ImuHandler},
}; };
pub async fn main_menu(mut display: Display, inputs: InputHandler) -> ! { pub async fn main_menu(mut display: Display, inputs: InputHandler, mut imu: ImuHandler) -> ! {
let mut inputs = inputs.split(); let mut inputs = inputs.split();
let apps = ["input_test", "imu_test", "captouch_test"]; let apps = ["input_test", "imu_test", "captouch_test"];
...@@ -39,7 +39,7 @@ pub async fn main_menu(mut display: Display, inputs: InputHandler) -> ! { ...@@ -39,7 +39,7 @@ pub async fn main_menu(mut display: Display, inputs: InputHandler) -> ! {
.await .await
{ {
Either3::First(_) => { Either3::First(_) => {
start_current_app(apps[selected], &mut display).await; start_current_app(apps[selected], &mut display, &mut imu).await;
display display
.fill_solid(&display.bounding_box(), Rgb565::BLACK) .fill_solid(&display.bounding_box(), Rgb565::BLACK)
.unwrap(); .unwrap();
...@@ -103,10 +103,10 @@ async fn play_transition_animation<'a>( ...@@ -103,10 +103,10 @@ async fn play_transition_animation<'a>(
} }
} }
async fn start_current_app(app: &str, display: &mut Display) { async fn start_current_app(app: &str, display: &mut Display, imu: &mut ImuHandler) {
match app { match app {
"input_test" => display_demo(display).await, "input_test" => display_demo(display).await,
"imu_test" => imu_demo(display).await, "imu_test" => imu_demo(display, imu).await,
"captouch_test" => captouch_demo(display).await, "captouch_test" => captouch_demo(display).await,
_ => (), _ => (),
} }
......
...@@ -29,9 +29,8 @@ async fn main(mut flow3r: Flow3r) -> ! { ...@@ -29,9 +29,8 @@ async fn main(mut flow3r: Flow3r) -> ! {
let spawner = Spawner::for_current_executor().await; let spawner = Spawner::for_current_executor().await;
spawner.spawn(demo_tasks::leds_fade(flow3r.leds)).ok(); spawner.spawn(demo_tasks::leds_fade(flow3r.leds)).ok();
// spawner.spawn(demo_tasks::display_demo(flow3r.display)).ok();
Timer::after(Duration::from_secs(3)).await; Timer::after(Duration::from_secs(3)).await;
main_menu(flow3r.display, flow3r.inputs).await main_menu(flow3r.display, flow3r.inputs, flow3r.imu).await
} }
...@@ -19,8 +19,8 @@ use static_cell::StaticCell; ...@@ -19,8 +19,8 @@ use static_cell::StaticCell;
use crate::flow3r::{ use crate::flow3r::{
badgelink::BadgeLink, badgelink::BadgeLink,
captouch::{captouch_controller, CaptouchHandler}, captouch::{captouch_controller, CaptouchHandler},
display::{display_refresh, Display}, display::Display,
//imu::ImuHandler, imu::ImuHandler,
input::{input_controller, InputHandler}, input::{input_controller, InputHandler},
leds::init_leds, leds::init_leds,
Flow3r, Flow3r,
...@@ -31,7 +31,7 @@ const READ_BUF_SIZE: usize = 64; ...@@ -31,7 +31,7 @@ const READ_BUF_SIZE: usize = 64;
static RNG: StaticCell<Rng> = StaticCell::new(); static RNG: StaticCell<Rng> = StaticCell::new();
static EXECUTOR: StaticCell<Executor> = StaticCell::new(); static EXECUTOR: StaticCell<Executor> = StaticCell::new();
static APP_CORE_EXECUTOR: StaticCell<Executor> = StaticCell::new(); //static APP_CORE_EXECUTOR: StaticCell<Executor> = StaticCell::new();
static CLOCKS: StaticCell<Clocks> = StaticCell::new(); static CLOCKS: StaticCell<Clocks> = StaticCell::new();
pub fn start_runtime() -> ! { pub fn start_runtime() -> ! {
...@@ -44,10 +44,10 @@ pub fn start_runtime() -> ! { ...@@ -44,10 +44,10 @@ pub fn start_runtime() -> ! {
#[embassy_executor::task] #[embassy_executor::task]
async fn start_app_core(mut cpu_control: CpuControl) -> ! { async fn start_app_core(mut cpu_control: CpuControl) -> ! {
let mut app_core_function = || { let mut app_core_function = || {
let executor = APP_CORE_EXECUTOR.init(Executor::new()); /*let executor = APP_CORE_EXECUTOR.init(Executor::new());
executor.run(|spawner| { executor.run(|spawner| {
spawner.spawn(display_refresh()).ok(); spawner.spawn(display_refresh()).ok();
}) })*/
}; };
let _guard = cpu_control.start_app_core(&mut app_core_function).unwrap(); let _guard = cpu_control.start_app_core(&mut app_core_function).unwrap();
loop { loop {
...@@ -176,12 +176,12 @@ async fn init_runtime() { ...@@ -176,12 +176,12 @@ async fn init_runtime() {
// Init Flow3r components // Init Flow3r components
let badgelink = BadgeLink::new(i2c_busmanager.acquire_i2c()); let badgelink = BadgeLink::new(i2c_busmanager.acquire_i2c());
//let imu = ImuHandler::new(i2c_busmanager.acquire_i2c()); let imu = ImuHandler::new(i2c_busmanager.acquire_i2c());
let inputs = InputHandler; let inputs = InputHandler;
let captouch = CaptouchHandler; let captouch = CaptouchHandler;
let leds = init_leds(pulse.channel0, io.pins.gpio14); let leds = init_leds(pulse.channel0, io.pins.gpio14);
let flow3r = Flow3r::new(badgelink, captouch, display, inputs, leds); let flow3r = Flow3r::new(badgelink, captouch, display, imu, inputs, leds);
// Spawn background tasks // Spawn background tasks
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment