Skip to content

Commit

Permalink
added gyro status display
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkamprath committed May 8, 2024
1 parent af2434e commit 25930e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ where
// - button one will select the current function and execute it
// - if no button is pressed for the idle wait time, return to idle state

const FUNCTIONS: [&str; 2] = ["Select Path", "Calibrate Gyro"];
const FUNCTIONS: [&str; 3] = ["Select Path", "Calibrate Gyro", "Heading Display"];
let mut function_idx: usize = 0;
let mut last_interaction_millis = millis();
self.robot.clear_display_reset_timer();
Expand Down Expand Up @@ -290,6 +290,7 @@ where
self.robot
.set_idle_message_line2(self.selected_path.clone());
}
self.robot.start_display_reset_timer();
}
1 => {
write!(
Expand All @@ -299,12 +300,16 @@ where
.ok();
self.robot.calibrate_gyro(&mut self.delay);
write!(self.robot.set_lcd_cursor(0, 1), " Done ",).ok();
self.robot.start_display_reset_timer();
}
2 => {
self.robot.display_heading().ok();
self.robot.set_display_to_idle();
}
_ => {
warn!("handle_functions_menu: invalid function index");
}
}
self.robot.start_display_reset_timer();
return;
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,36 @@ where
self
}

//--------------------------------------------------------------------------
// Test functions
//--------------------------------------------------------------------------
pub fn display_heading(&mut self) -> Result<(), adafruit_lcd_backpack::Error<TWI_ERR>> {
write!(self.lcd.clear()?.set_cursor(0, 0)?, "Heading:").ok();
self.heading_calculator.reset();
let mut continue_loop = true;

let mut last_update_millis = 0;
while continue_loop {
self.handle_loop();
if self.button1_pressed() || self.button2_pressed() {
continue_loop = false;
}
if millis() - last_update_millis > 500 {
let heading = self.heading_calculator.heading();
if let Err(error) = core::write!(
self.lcd.set_cursor(0, 1)?,
"{:.2}{: <16}",
heading,
DEGREES_STRING
) {
error!("Error writing to LCD: {}", error.to_string().as_str());
}
last_update_millis = millis();
}
}

Ok(())
}
//--------------------------------------------------------------------------
// LCD functions
//--------------------------------------------------------------------------
Expand Down

0 comments on commit 25930e6

Please sign in to comment.