display is working
This commit is contained in:
92
mqtt_display/Cargo.lock
generated
92
mqtt_display/Cargo.lock
generated
@@ -267,6 +267,15 @@ dependencies = [
|
|||||||
"syn 2.0.106",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.5.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587"
|
||||||
|
dependencies = [
|
||||||
|
"powerfmt",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
@@ -1169,9 +1178,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "8fe90c1150662e858c7d5f945089b7517b0a80d8bf7ba4b1b5ffc984e7230a5b"
|
checksum = "8fe90c1150662e858c7d5f945089b7517b0a80d8bf7ba4b1b5ffc984e7230a5b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
|
"portable-atomic",
|
||||||
|
"portable-atomic-util",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "line-clipping"
|
||||||
|
version = "0.3.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f4de44e98ddbf09375cbf4d17714d18f39195f4f4894e8524501726fd9a8a4a"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.10.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked_list_allocator"
|
name = "linked_list_allocator"
|
||||||
version = "0.10.5"
|
version = "0.10.5"
|
||||||
@@ -1258,6 +1278,12 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-derive"
|
name = "num-derive"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@@ -1332,6 +1358,12 @@ dependencies = [
|
|||||||
"syn 2.0.106",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "3.4.0"
|
version = "3.4.0"
|
||||||
@@ -1420,6 +1452,7 @@ dependencies = [
|
|||||||
"heapless 0.9.1",
|
"heapless 0.9.1",
|
||||||
"log",
|
"log",
|
||||||
"mousefood",
|
"mousefood",
|
||||||
|
"ratatui",
|
||||||
"rust-mqtt",
|
"rust-mqtt",
|
||||||
"smoltcp",
|
"smoltcp",
|
||||||
"ssd1306",
|
"ssd1306",
|
||||||
@@ -1464,6 +1497,18 @@ version = "0.9.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ratatui"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d1ce67fb8ba4446454d1c8dbaeda0557ff5e94d39d5e5ed7f10a65eb4c8266bc"
|
||||||
|
dependencies = [
|
||||||
|
"instability",
|
||||||
|
"ratatui-core",
|
||||||
|
"ratatui-macros",
|
||||||
|
"ratatui-widgets",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ratatui-core"
|
name = "ratatui-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -1484,6 +1529,35 @@ dependencies = [
|
|||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ratatui-macros"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a7f1342a13e83e4bb9d0b793d0ea762be633f9582048c892ae9041ef39c936f4"
|
||||||
|
dependencies = [
|
||||||
|
"ratatui-core",
|
||||||
|
"ratatui-widgets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ratatui-widgets"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d7dbfa023cd4e604c2553483820c5fe8aa9d71a42eea5aa77c6e7f35756612db"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.10.0",
|
||||||
|
"hashbrown",
|
||||||
|
"indoc",
|
||||||
|
"instability",
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"line-clipping",
|
||||||
|
"ratatui-core",
|
||||||
|
"strum",
|
||||||
|
"time",
|
||||||
|
"unicode-segmentation",
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "riscv"
|
name = "riscv"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@@ -1726,6 +1800,24 @@ dependencies = [
|
|||||||
"syn 2.0.106",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.7.2"
|
version = "0.7.2"
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ embassy-sync = "0.7.2"
|
|||||||
heapless = "0.9.1"
|
heapless = "0.9.1"
|
||||||
mousefood = { git = "https://github.com/j-g00da/mousefood", branch = "main", default-features = false }
|
mousefood = { git = "https://github.com/j-g00da/mousefood", branch = "main", default-features = false }
|
||||||
ssd1306 = "0.10.0"
|
ssd1306 = "0.10.0"
|
||||||
|
ratatui = { version = "0.30.0", default-features = false, features = ["macros", "all-widgets", "portable-atomic"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use projekt_final::mqtt::client::{
|
|||||||
mqtt_events, mqtt_publish, mqtt_subscribe, mqtt_task, IncomingMsg,
|
mqtt_events, mqtt_publish, mqtt_subscribe, mqtt_task, IncomingMsg,
|
||||||
};
|
};
|
||||||
use projekt_final::i2c::com::i2c_check;
|
use projekt_final::i2c::com::i2c_check;
|
||||||
|
use projekt_final::i2c::com::display_task;
|
||||||
use defmt_rtt as _;
|
use defmt_rtt as _;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@@ -102,7 +103,7 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
spawner.spawn(mqtt_task(stack)).expect("failed to spawn MQTT task");
|
spawner.spawn(mqtt_task(stack)).expect("failed to spawn MQTT task");
|
||||||
info!("MQTT task started");
|
info!("MQTT task started");
|
||||||
|
|
||||||
spawner.spawn(i2c_check()).expect("failed to spawn I2C task");
|
spawner.spawn(display_task()).expect("failed to spawn Display task");
|
||||||
info!("I2C scan task started");
|
info!("I2C scan task started");
|
||||||
|
|
||||||
mqtt_publish("esp32/topic", b"hello from ESP32 (init)", QualityOfService::QoS1, false).await;
|
mqtt_publish("esp32/topic", b"hello from ESP32 (init)", QualityOfService::QoS1, false).await;
|
||||||
|
|||||||
@@ -3,35 +3,92 @@
|
|||||||
use embassy_executor::task;
|
use embassy_executor::task;
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
gpio::Io,
|
|
||||||
i2c::master::{Config, I2c},
|
i2c::master::{Config, I2c},
|
||||||
peripherals::Peripherals,
|
peripherals::Peripherals,
|
||||||
};
|
};
|
||||||
use esp_println::println;
|
use ssd1306::mode::BufferedGraphicsMode;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
#[task]
|
||||||
|
pub async fn display_task() {
|
||||||
|
use mousefood::{EmbeddedBackend, EmbeddedBackendConfig};
|
||||||
|
use ratatui::{
|
||||||
|
layout::{Constraint, Direction, Layout},
|
||||||
|
widgets::{Block, Borders, Paragraph},
|
||||||
|
Terminal,
|
||||||
|
};
|
||||||
|
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
||||||
|
|
||||||
|
let peripherals = unsafe { Peripherals::steal() };
|
||||||
|
|
||||||
|
let i2c = I2c::new(peripherals.I2C0, Config::default())
|
||||||
|
.expect("Failed to initialize I2C")
|
||||||
|
.with_sda(peripherals.GPIO21)
|
||||||
|
.with_scl(peripherals.GPIO22);
|
||||||
|
|
||||||
|
let interface = I2CDisplayInterface::new(i2c);
|
||||||
|
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
|
||||||
|
.into_buffered_graphics_mode();
|
||||||
|
|
||||||
|
display.init().unwrap();
|
||||||
|
|
||||||
|
let config = EmbeddedBackendConfig {
|
||||||
|
flush_callback: alloc::boxed::Box::new(|display| {
|
||||||
|
let d: &mut Ssd1306<_, _, BufferedGraphicsMode<DisplaySize128x64>> = display;
|
||||||
|
d.flush().unwrap();
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let backend = EmbeddedBackend::new(&mut display, config);
|
||||||
|
let mut terminal = Terminal::new(backend).unwrap();
|
||||||
|
|
||||||
|
let mut counter = 0;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
terminal
|
||||||
|
.draw(|f| {
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([Constraint::Length(3), Constraint::Min(0)])
|
||||||
|
.split(f.area());
|
||||||
|
|
||||||
|
f.render_widget(
|
||||||
|
Block::default().title(" ESP32 Status ").borders(Borders::ALL),
|
||||||
|
chunks[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
let content = alloc::format!("MQTT Active\nCounter: {}", counter);
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(content).block(
|
||||||
|
Block::default().borders(Borders::LEFT | Borders::RIGHT | Borders::BOTTOM),
|
||||||
|
),
|
||||||
|
chunks[1],
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
counter += 1;
|
||||||
|
Timer::after(Duration::from_millis(1000)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
pub async fn i2c_check() {
|
pub async fn i2c_check() {
|
||||||
let peripherals = unsafe { Peripherals::steal() };
|
let peripherals = unsafe { Peripherals::steal() };
|
||||||
let _io = Io::new(peripherals.IO_MUX);
|
|
||||||
|
|
||||||
let sda = peripherals.GPIO21;
|
|
||||||
let scl = peripherals.GPIO22;
|
|
||||||
|
|
||||||
let mut i2c = I2c::new(peripherals.I2C0, Config::default())
|
let mut i2c = I2c::new(peripherals.I2C0, Config::default())
|
||||||
.expect("Failed to initialize I2C")
|
.expect("Failed to initialize I2C")
|
||||||
.with_sda(sda)
|
.with_sda(peripherals.GPIO21)
|
||||||
.with_scl(scl);
|
.with_scl(peripherals.GPIO22);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("I2C bus scan start");
|
info!("hehe");
|
||||||
// Skenujeme adresy 0x03 až 0x77
|
esp_println::println!("I2C bus scan start");
|
||||||
for addr in 0x03..0x78 {
|
for addr in 0x03..0x78 {
|
||||||
// Skúsime zapísať prázdne dáta na adresu
|
|
||||||
if i2c.write(addr, &[]).is_ok() {
|
if i2c.write(addr, &[]).is_ok() {
|
||||||
println!("Device found at address 0x{:02X}", addr);
|
esp_println::println!("Device found at address 0x{:02X}", addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("Scan finished");
|
|
||||||
Timer::after(Duration::from_secs(5)).await;
|
Timer::after(Duration::from_secs(5)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
pub mod mqtt;
|
pub mod mqtt;
|
||||||
pub mod i2c;
|
pub mod i2c;
|
||||||
|
|||||||
Reference in New Issue
Block a user