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 bmi270::AxisData;
use embassy_futures::select::{select, select3, select_array, Either, Either3};
use embassy_futures::select::{select, select3, Either, Either3};
use embassy_time::{Duration, Timer};
use embedded_graphics::{
image::Image,
......@@ -109,7 +108,7 @@ pub async fn draw_start_screen(display: &mut Display) {
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 mut inputs = input.split();
......@@ -125,8 +124,7 @@ pub async fn imu_demo(display: &mut Display /*imu: &mut ImuHandler*/) {
let mut offset = (0i32, 0i32);
loop {
match select(inputs.sw2_center.wait_for_press(), async {
//let imu_value = imu.rotation().unwrap();
let imu_value = AxisData { x: 5, y: 5, z: 0 };
let imu_value = imu.rotation().unwrap();
offset = (
(-80).max(80.min(offset.0 + imu_value.x as i32)),
(-80).max(80.min(offset.1 + imu_value.y as i32)),
......
......@@ -11,10 +11,11 @@ impl ImuHandler {
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 chip_id = bmi270.get_chip_id().unwrap();
if let Some(chip_id) = bmi270.get_chip_id().ok() {
println!("imu chip id: {}", chip_id);
}
bmi270.init().unwrap();
bmi270.init().ok();
let pwr_ctrl = PwrCtrl {
aux_en: false,
......@@ -22,7 +23,7 @@ impl ImuHandler {
acc_en: true,
temp_en: false,
};
bmi270.set_pwr_ctrl(pwr_ctrl).unwrap();
bmi270.set_pwr_ctrl(pwr_ctrl).ok();
Self { imu: bmi270 }
}
......
use self::badgelink::BadgeLink;
use self::captouch::CaptouchHandler;
use self::display::Display;
//use self::imu::ImuHandler;
use self::imu::ImuHandler;
use self::input::InputHandler;
use self::leds::Leds;
......@@ -18,7 +18,7 @@ pub struct Flow3r {
pub badgelink: BadgeLink,
pub captouch: CaptouchHandler,
pub display: Display,
//pub imu: ImuHandler,
pub imu: ImuHandler,
pub inputs: InputHandler,
pub leds: Leds,
}
......@@ -28,7 +28,7 @@ impl Flow3r {
badgelink: BadgeLink,
captouch: CaptouchHandler,
display: Display,
//imu: ImuHandler,
imu: ImuHandler,
inputs: InputHandler,
leds: Leds,
) -> Self {
......@@ -36,7 +36,7 @@ impl Flow3r {
badgelink,
captouch,
display,
//imu,
imu,
inputs,
leds,
}
......
......@@ -9,10 +9,10 @@ use embedded_graphics::{
use crate::{
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 apps = ["input_test", "imu_test", "captouch_test"];
......@@ -39,7 +39,7 @@ pub async fn main_menu(mut display: Display, inputs: InputHandler) -> ! {
.await
{
Either3::First(_) => {
start_current_app(apps[selected], &mut display).await;
start_current_app(apps[selected], &mut display, &mut imu).await;
display
.fill_solid(&display.bounding_box(), Rgb565::BLACK)
.unwrap();
......@@ -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 {
"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,
_ => (),
}
......
......@@ -29,9 +29,8 @@ async fn main(mut flow3r: Flow3r) -> ! {
let spawner = Spawner::for_current_executor().await;
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;
main_menu(flow3r.display, flow3r.inputs).await
main_menu(flow3r.display, flow3r.inputs, flow3r.imu).await
}
......@@ -19,8 +19,8 @@ use static_cell::StaticCell;
use crate::flow3r::{
badgelink::BadgeLink,
captouch::{captouch_controller, CaptouchHandler},
display::{display_refresh, Display},
//imu::ImuHandler,
display::Display,
imu::ImuHandler,
input::{input_controller, InputHandler},
leds::init_leds,
Flow3r,
......@@ -31,7 +31,7 @@ const READ_BUF_SIZE: usize = 64;
static RNG: StaticCell<Rng> = 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();
pub fn start_runtime() -> ! {
......@@ -44,10 +44,10 @@ pub fn start_runtime() -> ! {
#[embassy_executor::task]
async fn start_app_core(mut cpu_control: CpuControl) -> ! {
let mut app_core_function = || {
let executor = APP_CORE_EXECUTOR.init(Executor::new());
/*let executor = APP_CORE_EXECUTOR.init(Executor::new());
executor.run(|spawner| {
spawner.spawn(display_refresh()).ok();
})
})*/
};
let _guard = cpu_control.start_app_core(&mut app_core_function).unwrap();
loop {
......@@ -176,12 +176,12 @@ async fn init_runtime() {
// Init Flow3r components
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 captouch = CaptouchHandler;
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment