Skip to content

Commit

Permalink
switched LCD interface to i2c-character-display
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkamprath committed Sep 30, 2024
1 parent 9845930 commit 20047ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mpu6050 = { git = "https://github.com/michaelkamprath/mpu6050.git", branch = "mi
"defmt",
] }
embedded-alloc = "0.6"
adafruit-lcd-backpack = { version = "0.2", features = ["defmt"] }
i2c-character-display = { version = "0.1", features = ["defmt"] }
ini_core = "0.2"

# We're using a Pico by default on this template
Expand Down Expand Up @@ -99,6 +99,5 @@ opt-level = 3
mpu6050 = { path = "../mpu6050" }

[patch.crates-io]
adafruit-lcd-backpack = { path = "../adafruit-lcd-backpack-rust" }
mcp230xx = { path = "../mcp230xx" }
shared-bus = { path = "../shared-bus" }
19 changes: 10 additions & 9 deletions src/robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
},
system::millis::millis,
};
use adafruit_lcd_backpack::{LcdBackpack, LcdDisplayType};
use alloc::{
string::{String, ToString},
vec,
Expand All @@ -35,6 +34,8 @@ use embedded_hal::{
pwm::SetDutyCycle,
spi::SpiDevice,
};
use embedded_hal_bus::i2c::CriticalSectionDevice;
use i2c_character_display::{AdafruitLCDBackpack, LcdDisplayType};
use micromath::F32Ext;
use rp_pico::hal::gpio;
use rp_pico::hal::{
Expand Down Expand Up @@ -110,7 +111,7 @@ pub struct Robot<
button2: DebouncedButton<BUTT2, false, BUTTON_DEBOUNCE_TIME_MS>,
pub heading_calculator:
HeadingCalculator<embedded_hal_bus::i2c::CriticalSectionDevice<'a, TWI>, DELAY>,
lcd: LcdBackpack<embedded_hal_bus::i2c::CriticalSectionDevice<'a, TWI>, DELAY>,
lcd: AdafruitLCDBackpack<CriticalSectionDevice<'a, TWI>, DELAY>,
pub sd_card: FileStorage<SPI_DEV, DELAY>,
reset_display_start_millis: u32,
log_index: u32,
Expand Down Expand Up @@ -174,7 +175,7 @@ where

// let i2c_device = embedded_hal_bus::i2c::RefCellDevice::new(i2c_refcell);
let i2c_device = embedded_hal_bus::i2c::CriticalSectionDevice::new(i2c_refcell);
let mut lcd = LcdBackpack::new(LcdDisplayType::Lcd16x2, i2c_device, delay.clone());
let mut lcd = AdafruitLCDBackpack::new(i2c_device, LcdDisplayType::Lcd16x2, delay.clone());
match lcd.init() {
Ok(_) => {
info!("LCD initialized");
Expand Down Expand Up @@ -206,8 +207,8 @@ where
debug!("Writing to LCD first message");
if let Err(_e) = lcd
.home()
.and_then(LcdBackpack::clear)
.and_then(|lcd| LcdBackpack::print(lcd, "Calibrating Gyro"))
.and_then(AdafruitLCDBackpack::clear)
.and_then(|lcd| AdafruitLCDBackpack::print(lcd, "Calibrating Gyro"))
{
error!("Error writing to LCD");
}
Expand All @@ -220,15 +221,15 @@ where

if let Err(_e) = lcd
.home()
.and_then(LcdBackpack::clear)
.and_then(|lcd| LcdBackpack::print(lcd, "Robot Started"))
.and_then(AdafruitLCDBackpack::clear)
.and_then(|lcd| AdafruitLCDBackpack::print(lcd, "Robot Started"))
.and_then(|lcd| {
write!(
lcd.set_cursor(0, 1)?,
"SD: {} GB",
sd_card.volume_size().unwrap_or(0) / 1_073_741_824
)
.map_err(|_e| adafruit_lcd_backpack::BackpackError::FormattingError)
.map_err(i2c_character_display::Error::FormattingError)
})
{
error!("Error writing to LCD");
Expand Down Expand Up @@ -679,7 +680,7 @@ where
//--------------------------------------------------------------------------
pub fn display_heading(
&mut self,
) -> Result<(), adafruit_lcd_backpack::BackpackError<TWI::Error>> {
) -> Result<(), i2c_character_display::Error<CriticalSectionDevice<'a, TWI>>> {
write!(self.lcd.clear()?.set_cursor(0, 0)?, "Heading:").ok();
self.heading_calculator.reset();
let mut continue_loop = true;
Expand Down

0 comments on commit 20047ab

Please sign in to comment.