Skip to content

Commit

Permalink
Add some more hints for exercise 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
diondokter authored and tdittr committed Nov 26, 2024
1 parent 45c9332 commit 738b8df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,17 @@ impl Dial {
self.cols.iter_mut().for_each(|c| c.set_high());
}

pub fn light_only(&mut self, dir: Direction) {
pub fn set_light_direction(&mut self, dir: Direction) {
let (row, col) = dir.led_index();
self.clear();
self.rows[row].set_high();
self.cols[col].set_low();
}

/// Operate the dial. This function is useful for running
/// Operate the dial autonomously. This function is useful for running
/// in a separate task.
///
/// Useful for exercise 8.1.2
pub async fn run(
mut self,
receiver: embassy_sync::channel::Receiver<'_, NoopRawMutex, Direction, 4>,
Expand Down
12 changes: 8 additions & 4 deletions exercises/8-embedded/3-async-on-embedded/1-compass/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use dial::{dir_channel, Dial, Direction};
use embassy_nrf::{self as hal, peripherals::TWISPI0, twim::Twim};
use embassy_time::Delay;
use embedded_hal_async::delay::DelayNs;
use hal::twim;
use lsm303agr::{interface::I2cInterface, mode::MagOneShot, Lsm303agr, MagnetometerId};
Expand All @@ -19,7 +18,6 @@ hal::bind_interrupts!(struct Irqs {

#[embassy_executor::main]
async fn main(s: embassy_executor::Spawner) -> ! {

// Init RTT control block
rtt_init_print!();

Expand All @@ -31,21 +29,27 @@ async fn main(s: embassy_executor::Spawner) -> ! {

let config = twim::Config::default();
let twim0 = Twim::new(dp.TWISPI0, Irqs, dp.P0_16, dp.P0_08, config);
let delay = embassy_time::Delay;

let dial: Dial = todo!("Initialize Dial");

let mut sensor: Lsm303agr<I2cInterface<Twim<TWISPI0>>, MagOneShot> = todo!("Initialize LSM303AGR driver given the twim0 peripheral");
let mut sensor: Lsm303agr<I2cInterface<Twim<TWISPI0>>, MagOneShot> =
todo!("Initialize LSM303AGR driver given the twim0 peripheral");
let id: MagnetometerId = todo!("Read the magnetometer ID using the driver");
rprintln!("{:#02x?}", id);

todo!("Initialize the driver");
todo!("Set magnetometer mode to high resolution and output data rate to 100Hz");


todo!("Change the magnetometer to continuous mode");
todo!("Enable magnetometer offset cancellation");

loop {
todo!("Read data and update the dial accordingly");

// Steps:
// - Read the MagneticField data
// - Convert to a direction using: Direction::from(mag_data)
// - Update the dial: dial.set_light_direction(direction)
}
}

0 comments on commit 738b8df

Please sign in to comment.