added ringbuffer

This commit is contained in:
Empire 2025-01-26 18:00:35 +01:00
parent b8fc6477b2
commit ef002e918c
2 changed files with 26 additions and 3 deletions

View File

@ -81,6 +81,7 @@ eeprom24x = "0.7.2"
url = "2.5.3" url = "2.5.3"
crc = "3.2.1" crc = "3.2.1"
bincode = "1.3.3" bincode = "1.3.3"
ringbuffer = "0.15.0"
[patch.crates-io] [patch.crates-io]

View File

@ -30,6 +30,7 @@ use esp_idf_sys::esp_restart;
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use anyhow::{bail, Ok, Result}; use anyhow::{bail, Ok, Result};
use ringbuffer::{ConstGenericRingBuffer, RingBuffer};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::ffi::CString; use std::ffi::CString;
use std::fs::{self, File}; use std::fs::{self, File};
@ -45,7 +46,7 @@ use std::time::Duration;
use embedded_hal::digital::OutputPin; use embedded_hal::digital::OutputPin;
use esp_idf_hal::delay::Delay; use esp_idf_hal::delay::Delay;
use esp_idf_hal::gpio::{AnyInputPin, Gpio18, Gpio5, IOPin, InputOutput, Level, PinDriver, Pull}; use esp_idf_hal::gpio::{AnyInputPin, Gpio18, Gpio5, Gpio7, Gpio8, IOPin, InputOutput, Level, PinDriver, Pull};
use esp_idf_hal::pcnt::{ use esp_idf_hal::pcnt::{
PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex, PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex,
}; };
@ -127,6 +128,12 @@ static mut LOW_VOLTAGE_DETECTED: bool = false;
#[link_section = ".rtc.data"] #[link_section = ".rtc.data"]
static mut RESTART_TO_CONF: bool = false; static mut RESTART_TO_CONF: bool = false;
const BUFFER_SIZE:usize = 120;
const ENTRY_SIZE:usize = 120;
#[link_section = ".rtc.data"]
static mut BUFFER:ConstGenericRingBuffer::<heapless::String<ENTRY_SIZE>, BUFFER_SIZE> = ConstGenericRingBuffer::<heapless::String<ENTRY_SIZE>, BUFFER_SIZE>::new();
pub struct FileSystemSizeInfo { pub struct FileSystemSizeInfo {
pub total_size: usize, pub total_size: usize,
pub used_size: usize, pub used_size: usize,
@ -274,6 +281,20 @@ impl PlantCtrlBoard<'_> {
if checksum != header.crc16 { if checksum != header.crc16 {
bail!("Invalid checksum, got {} but expected {}", checksum, header.crc16 ); bail!("Invalid checksum, got {} but expected {}", checksum, header.crc16 );
} }
unsafe {
let value = heapless::String::try_from("dummy").unwrap();
BUFFER.push(value);
}
unsafe {
for entry in BUFFER.iter() {
let test = entry.as_bytes().to_owned();
for p in test {
data_buffer.push(p);
}
}
}
Ok(data_buffer) Ok(data_buffer)
} }
@ -1415,6 +1436,7 @@ impl PlantHal {
LAST_WATERING_TIMESTAMP = [0; PLANT_COUNT]; LAST_WATERING_TIMESTAMP = [0; PLANT_COUNT];
CONSECUTIVE_WATERING_PLANT = [0; PLANT_COUNT]; CONSECUTIVE_WATERING_PLANT = [0; PLANT_COUNT];
LOW_VOLTAGE_DETECTED = false; LOW_VOLTAGE_DETECTED = false;
BUFFER = ConstGenericRingBuffer::<heapless::String<ENTRY_SIZE>, BUFFER_SIZE>::new();
RESTART_TO_CONF = to_config_mode; RESTART_TO_CONF = to_config_mode;
}; };
} else { } else {
@ -1482,7 +1504,7 @@ impl PlantHal {
let tank_channel: AdcChannelDriver<Gpio5, AdcDriver<esp_idf_hal::adc::ADC1>> = let tank_channel: AdcChannelDriver<Gpio5, AdcDriver<esp_idf_hal::adc::ADC1>> =
AdcChannelDriver::new(tank_driver, peripherals.pins.gpio5, &adc_config)?; AdcChannelDriver::new(tank_driver, peripherals.pins.gpio5, &adc_config)?;
let mut solar_is_day = PinDriver::input(peripherals.pins.gpio8.downgrade())?; let mut solar_is_day = PinDriver::input(peripherals.pins.gpio7.downgrade())?;
solar_is_day.set_pull(Pull::Floating)?; solar_is_day.set_pull(Pull::Floating)?;
let mut boot_button = PinDriver::input(peripherals.pins.gpio9.downgrade())?; let mut boot_button = PinDriver::input(peripherals.pins.gpio9.downgrade())?;