fix lcd
This commit is contained in:
parent
ea1f1a3358
commit
40f6c0dffd
4 changed files with 21 additions and 5 deletions
|
|
@ -227,8 +227,10 @@ impl DeviceState {
|
|||
|
||||
let question = self.question.as_ref()?;
|
||||
let title_line = if question.text.len() > 16 {
|
||||
self.title_offset %= question.text.len() - 16;
|
||||
OwnedStr::from_str(&question.text[self.title_offset..self.title_offset + 16]).unwrap()
|
||||
// overscroll, should show spaces after the end
|
||||
self.title_offset %= question.text.len() - 31;
|
||||
let end = usize::min(self.title_offset + 16, question.text.len());
|
||||
OwnedStr::from_str(&question.text[self.title_offset..end]).unwrap()
|
||||
} else {
|
||||
OwnedStr::from_str(&question.text).unwrap()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::String;
|
||||
use device_state::DeviceState;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::select::{Either, select};
|
||||
|
|
@ -133,8 +135,9 @@ pub async fn tcp_write_loop(
|
|||
#[embassy_executor::task]
|
||||
pub async fn main_loop() {
|
||||
println!("Main loop started");
|
||||
let mut last = (String::new(), String::new());
|
||||
loop {
|
||||
embassy_time::Timer::after_millis(50).await;
|
||||
embassy_time::Timer::after_millis(100).await;
|
||||
let mut state = STATE.lock().await;
|
||||
state.tick();
|
||||
let lines = state.render_lines();
|
||||
|
|
@ -143,7 +146,15 @@ pub async fn main_loop() {
|
|||
let Some((title_line, second_line)) = lines else {
|
||||
continue;
|
||||
};
|
||||
println!("lcd: {} {}", title_line, second_line);
|
||||
let rendered = (
|
||||
title_line.as_str().to_owned(),
|
||||
second_line.as_str().to_owned(),
|
||||
);
|
||||
if rendered == last {
|
||||
continue;
|
||||
}
|
||||
last = rendered;
|
||||
println!("lcd1: {}\nlcd2: {}", title_line, second_line);
|
||||
screen::overwrite_lcd(&title_line, &second_line).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use esp_radio::wifi::sta::StationConfig;
|
|||
use esp_radio::wifi::{Config, ControllerConfig, scan::ScanConfig};
|
||||
|
||||
use crate::screen::overwrite_lcd;
|
||||
use crate::{WIFI_NETWORK, WIFI_PASSWORD};
|
||||
use crate::{WIFI_NETWORK, WIFI_PASSWORD, main_loop};
|
||||
use crate::{buffer::wait_for_config, tcp_read_loop, tcp_write_loop};
|
||||
use crate::{reconnecting_state, reset_state};
|
||||
|
||||
|
|
@ -68,6 +68,7 @@ pub async fn network_setup_task(
|
|||
seed,
|
||||
);
|
||||
spawner.spawn(net_task(runner).expect("spawn net task"));
|
||||
spawner.spawn(main_loop().expect("spawn main loop"));
|
||||
|
||||
loop {
|
||||
loop {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,9 @@ pub async fn lcd_display_task(config: LcdConfig) {
|
|||
for byte in &buffer.line1 {
|
||||
lcd.write(*byte);
|
||||
}
|
||||
Timer::after_micros(500).await;
|
||||
lcd.set_position(0, 1);
|
||||
Timer::after_micros(500).await;
|
||||
for byte in &buffer.line2 {
|
||||
lcd.write(*byte);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue