auto reconnect
This commit is contained in:
parent
f10f8d8f6e
commit
9e93f8b9f7
3 changed files with 26 additions and 3 deletions
|
|
@ -31,12 +31,15 @@ mod screen;
|
||||||
|
|
||||||
pub use input::ANGLE;
|
pub use input::ANGLE;
|
||||||
|
|
||||||
|
use crate::screen::overwrite_lcd;
|
||||||
|
|
||||||
const WIFI_NETWORK: &str = "flamme";
|
const WIFI_NETWORK: &str = "flamme";
|
||||||
const WIFI_PASSWORD: &str = "12345678";
|
const WIFI_PASSWORD: &str = "12345678";
|
||||||
const TARGET_IP: &str = "84.238.32.253";
|
const TARGET_IP: &str = "84.238.32.253";
|
||||||
const TARGET_PORT: u16 = 7070;
|
const TARGET_PORT: u16 = 7070;
|
||||||
const WHEEL_PRECISION: i32 = 32;
|
const WHEEL_PRECISION: i32 = 32;
|
||||||
const WHEEL_INVERTED: bool = false;
|
const WHEEL_INVERTED: bool = false;
|
||||||
|
const DEVICE_ID: &str = "esp32-1";
|
||||||
|
|
||||||
enum QuestionType {
|
enum QuestionType {
|
||||||
Choice,
|
Choice,
|
||||||
|
|
@ -75,6 +78,16 @@ static WHEEL_VALUE: Mutex<CriticalSectionRawMutex, WheelData> = Mutex::new(Wheel
|
||||||
accumulated: 0,
|
accumulated: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pub async fn reset_state() {
|
||||||
|
*QUESTION.lock().await = None;
|
||||||
|
*WHEEL_VALUE.lock().await = WheelData {
|
||||||
|
value: 0,
|
||||||
|
min: 0,
|
||||||
|
max: 0,
|
||||||
|
accumulated: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &core::panic::PanicInfo) -> ! {
|
fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||||
println!("PANIC! {:?}", info);
|
println!("PANIC! {:?}", info);
|
||||||
|
|
@ -116,6 +129,10 @@ pub async fn tcp_read_loop(
|
||||||
accumulated: 0,
|
accumulated: 0,
|
||||||
};
|
};
|
||||||
for line in str.lines() {
|
for line in str.lines() {
|
||||||
|
if line == "##" {
|
||||||
|
overwrite_lcd("Waiting", DEVICE_ID).await;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if line == "$$" {
|
if line == "$$" {
|
||||||
counter = 1;
|
counter = 1;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -189,6 +206,10 @@ pub async fn tcp_write_loop(
|
||||||
mut write: TcpWriter<'_>,
|
mut write: TcpWriter<'_>,
|
||||||
cancel: &Signal<CriticalSectionRawMutex, ()>,
|
cancel: &Signal<CriticalSectionRawMutex, ()>,
|
||||||
) -> Result<(), TcpDisconnect> {
|
) -> Result<(), TcpDisconnect> {
|
||||||
|
if write.write(DEVICE_ID.as_bytes()).await.is_err() {
|
||||||
|
cancel.signal(());
|
||||||
|
return Err(TcpDisconnect::WriteError);
|
||||||
|
}
|
||||||
let mut buffer = buffer::WriteBuffer::<256>::new();
|
let mut buffer = buffer::WriteBuffer::<256>::new();
|
||||||
loop {
|
loop {
|
||||||
let input_fut = input::INPUT.receive();
|
let input_fut = input::INPUT.receive();
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ pub async fn network_setup_task(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
overwrite_lcd("Connection closed", "").await;
|
overwrite_lcd("Connection close", "").await;
|
||||||
Timer::after_millis(500).await;
|
Timer::after_millis(500).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,10 @@ pub async fn overwrite_lcd(line1: &str, line2: &str) {
|
||||||
buffer.line2_ptr = 0;
|
buffer.line2_ptr = 0;
|
||||||
buffer.line1.fill(0);
|
buffer.line1.fill(0);
|
||||||
buffer.line2.fill(0);
|
buffer.line2.fill(0);
|
||||||
buffer.line1[..line1.len()].copy_from_slice(line1.as_bytes());
|
let len1 = line1.len().min(buffer.line1.len());
|
||||||
buffer.line2[..line2.len()].copy_from_slice(line2.as_bytes());
|
let len2 = line2.len().min(buffer.line2.len());
|
||||||
|
buffer.line1[..len1].copy_from_slice(line1[..len1].as_bytes());
|
||||||
|
buffer.line2[..len2].copy_from_slice(line2[..len2].as_bytes());
|
||||||
LCD_UPDATE.signal(());
|
LCD_UPDATE.signal(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue