From 17db1b8a45c90d431c67388b0c89ff78b14a3556 Mon Sep 17 00:00:00 2001 From: Empire Date: Mon, 20 Nov 2023 01:46:19 +0100 Subject: [PATCH] adjust folder to be shorter --- plant-ctrl2/src/main.rs | 79 --------- {plant-ctrl2 => rust}/.cargo/config.toml | 0 {plant-ctrl2 => rust}/.gitignore | 0 {plant-ctrl2 => rust}/.idea/.gitignore | 0 .../inspectionProfiles/Project_Default.xml | 0 {plant-ctrl2 => rust}/.idea/modules.xml | 0 {plant-ctrl2 => rust}/.idea/plant-ctrl2.iml | 0 {plant-ctrl2 => rust}/.idea/vcs.xml | 0 {plant-ctrl2 => rust}/Cargo.toml | 0 {plant-ctrl2 => rust}/build.rs | 0 {plant-ctrl2 => rust}/rust-toolchain.toml | 0 {plant-ctrl2 => rust}/sdkconfig.defaults | 0 {plant-ctrl2 => rust}/setup.txt | 0 rust/src/main.rs | 166 ++++++++++++++++++ 14 files changed, 166 insertions(+), 79 deletions(-) delete mode 100644 plant-ctrl2/src/main.rs rename {plant-ctrl2 => rust}/.cargo/config.toml (100%) rename {plant-ctrl2 => rust}/.gitignore (100%) rename {plant-ctrl2 => rust}/.idea/.gitignore (100%) rename {plant-ctrl2 => rust}/.idea/inspectionProfiles/Project_Default.xml (100%) rename {plant-ctrl2 => rust}/.idea/modules.xml (100%) rename {plant-ctrl2 => rust}/.idea/plant-ctrl2.iml (100%) rename {plant-ctrl2 => rust}/.idea/vcs.xml (100%) rename {plant-ctrl2 => rust}/Cargo.toml (100%) rename {plant-ctrl2 => rust}/build.rs (100%) rename {plant-ctrl2 => rust}/rust-toolchain.toml (100%) rename {plant-ctrl2 => rust}/sdkconfig.defaults (100%) rename {plant-ctrl2 => rust}/setup.txt (100%) create mode 100644 rust/src/main.rs diff --git a/plant-ctrl2/src/main.rs b/plant-ctrl2/src/main.rs deleted file mode 100644 index db6b565..0000000 --- a/plant-ctrl2/src/main.rs +++ /dev/null @@ -1,79 +0,0 @@ -use embedded_hal::digital::v1_compat::OldOutputPin; -use shift_register_driver::sipo::{ShiftRegister24, ShiftRegisterPin}; -use esp_idf_hal::gpio::{PinDriver}; -use esp_idf_hal::prelude::Peripherals; -use dummy_pin::DummyPin; -use embedded_hal::digital::v2::OutputPin; - -#[macro_use] -extern crate shift_register_driver; - -trait PlantCtrlBoardInteraction{ - fn measure_moisture() -> i16; - fn default() -> Self; -} - -trait Plant{ - fn setPump(pump:bool); - - -} - -struct PlantHal<'d>{ - pump:ShiftRegisterPin<'d> -} - -struct PlantCtrlBoard{ - dummy:i32 -} - -impl PlantCtrlBoardInteraction for PlantCtrlBoard { - fn measure_moisture() -> i16 { - //pcnr here - return 1_i16; - } - - - fn default() -> Self { - let peripherals = Peripherals::take().unwrap(); - - let clock = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio21).unwrap()); - let latch = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio22).unwrap()); - let data = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio19).unwrap()); - - - let shift_register = ShiftRegister24::new(clock, latch, data); - let registerOutput = shift_register.decompose(); - - - - Self { dummy: 12 } - } -} - -const PLANT_COUNT:usize = 8; -#[link_section = ".rtc.data"] -static mut LAST_WATERING_TIMESTAMP: [u64; PLANT_COUNT] = [0; PLANT_COUNT]; -#[link_section = ".rtc.data"] -static mut CONSECUTIVE_WATERING_PLANT: [u64; PLANT_COUNT] = [0; PLANT_COUNT]; -#[link_section = ".rtc.data"] -static mut LOW_VOLTAGE_DETECTED:bool = false; - - - - -fn main() { - - // It is necessary to call this function once. Otherwise some patches to the runtime - // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 - esp_idf_svc::sys::link_patches(); - - // Bind the log crate to the ESP Logging facilities - esp_idf_svc::log::EspLogger::initialize_default(); - - log::info!("Hello, world!"); - - - let board = PlantCtrlBoard::default(); - -} diff --git a/plant-ctrl2/.cargo/config.toml b/rust/.cargo/config.toml similarity index 100% rename from plant-ctrl2/.cargo/config.toml rename to rust/.cargo/config.toml diff --git a/plant-ctrl2/.gitignore b/rust/.gitignore similarity index 100% rename from plant-ctrl2/.gitignore rename to rust/.gitignore diff --git a/plant-ctrl2/.idea/.gitignore b/rust/.idea/.gitignore similarity index 100% rename from plant-ctrl2/.idea/.gitignore rename to rust/.idea/.gitignore diff --git a/plant-ctrl2/.idea/inspectionProfiles/Project_Default.xml b/rust/.idea/inspectionProfiles/Project_Default.xml similarity index 100% rename from plant-ctrl2/.idea/inspectionProfiles/Project_Default.xml rename to rust/.idea/inspectionProfiles/Project_Default.xml diff --git a/plant-ctrl2/.idea/modules.xml b/rust/.idea/modules.xml similarity index 100% rename from plant-ctrl2/.idea/modules.xml rename to rust/.idea/modules.xml diff --git a/plant-ctrl2/.idea/plant-ctrl2.iml b/rust/.idea/plant-ctrl2.iml similarity index 100% rename from plant-ctrl2/.idea/plant-ctrl2.iml rename to rust/.idea/plant-ctrl2.iml diff --git a/plant-ctrl2/.idea/vcs.xml b/rust/.idea/vcs.xml similarity index 100% rename from plant-ctrl2/.idea/vcs.xml rename to rust/.idea/vcs.xml diff --git a/plant-ctrl2/Cargo.toml b/rust/Cargo.toml similarity index 100% rename from plant-ctrl2/Cargo.toml rename to rust/Cargo.toml diff --git a/plant-ctrl2/build.rs b/rust/build.rs similarity index 100% rename from plant-ctrl2/build.rs rename to rust/build.rs diff --git a/plant-ctrl2/rust-toolchain.toml b/rust/rust-toolchain.toml similarity index 100% rename from plant-ctrl2/rust-toolchain.toml rename to rust/rust-toolchain.toml diff --git a/plant-ctrl2/sdkconfig.defaults b/rust/sdkconfig.defaults similarity index 100% rename from plant-ctrl2/sdkconfig.defaults rename to rust/sdkconfig.defaults diff --git a/plant-ctrl2/setup.txt b/rust/setup.txt similarity index 100% rename from plant-ctrl2/setup.txt rename to rust/setup.txt diff --git a/rust/src/main.rs b/rust/src/main.rs new file mode 100644 index 0000000..ef43439 --- /dev/null +++ b/rust/src/main.rs @@ -0,0 +1,166 @@ +use chrono::Utc; +use embedded_hal::digital::v1_compat::OldOutputPin; +use esp_idf_hal::adc::config::Config; +use esp_idf_hal::adc::{AdcDriver, AdcChannelDriver, attenuation}; +use shift_register_driver::sipo::{ShiftRegister24, ShiftRegisterPin}; +use esp_idf_hal::gpio::PinDriver; +use esp_idf_hal::prelude::Peripherals; + +const PLANT_COUNT:usize = 8; +#[link_section = ".rtc.data"] +static mut LAST_WATERING_TIMESTAMP: [u64; PLANT_COUNT] = [0; PLANT_COUNT]; +#[link_section = ".rtc.data"] +static mut CONSECUTIVE_WATERING_PLANT: [u64; PLANT_COUNT] = [0; PLANT_COUNT]; +#[link_section = ".rtc.data"] +static mut LOW_VOLTAGE_DETECTED:bool = false; + +struct BatteryState { + state_charge_percent: u8, + max_error_percent: u8, + remaining_milli_ampere_hour: u32, + max_milli_ampere_hour: u32, + design_milli_ampere_hour:u32, + voltage_milli_volt: u16, + average_current_milli_ampere: u16, + temperature_tenth_kelvin: u32, + average_time_to_empty_minute: u16, + average_time_to_full_minute: u16, + average_discharge_power_cycle_milli_watt: u16, + cycle_count: u16, + state_health_percent: u8 +} +trait PlantCtrlBoardInteraction{ + fn battery_state() -> BatteryState; + + fn is_day() -> bool; + fn water_temperature_c() -> u16; + fn tank_sensor_mv() -> u16; + + fn set_low_voltage_in_cycle(); + fn clear_low_voltage_in_cycle(); + fn low_voltage_in_cycle(low_voltage:bool); + + + //keep state during deepsleep + fn light(enable:bool); + + fn plant_count() -> i8; + fn measure_moisture_b_hz(plant:i8) -> i16; + fn measure_moisture_a_hz(plant:i8) -> i16; + fn measure_moisture_p_hz(plant:i8) -> i16; + fn pump(plant:i8, enable:bool); + fn last_pump_time(plant:i8) -> chrono::DateTime; + fn store_last_pump_time(plant:i8, time: chrono::DateTime); + fn store_consecutive_pump_count(plant:i8, count:i16); + fn consecutive_pump_count(plant:i8) -> i16; + + //keep state during deepsleep + fn fault(plant:i8, enable:bool); + + fn default() -> Self; +} + +trait Plant{ + fn setPump(pump:bool); + + +} + +struct PlantHal<'d>{ + pump:ShiftRegisterPin<'d> +} + +struct PlantCtrlBoard{ + dummy:i32 +} + +impl PlantCtrlBoardInteraction for PlantCtrlBoard { + fn default() -> Self { + let peripherals = Peripherals::take().unwrap(); + + let mut adc = AdcDriver::new(peripherals.adc1, &Config::new().calibration(true)).unwrap(); + let mut adc_pin: esp_idf_hal::adc::AdcChannelDriver<{ attenuation::DB_11 }, _> = AdcChannelDriver::new(peripherals.pins.gpio39).unwrap(); + let analog_value = adc.read(&mut adc_pin); + + let clock = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio21).unwrap()); + let latch = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio22).unwrap()); + let data = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio19).unwrap()); + + + let shift_register = ShiftRegister24::new(clock, latch, data); + let registerOutput = shift_register.decompose(); + + + + Self { dummy: 12 } + } + + fn plant_count() -> i8 { + todo!() + } + + fn fault(plant:i8, state:bool) { + todo!() + } + + fn pump(plant:i8, state:bool) { + todo!() + } + + fn battery_state() -> BatteryState { + todo!() + } + + fn is_day() -> bool { + todo!() + } + + fn water_temperature_c() -> u16 { + todo!() + } + + fn tank_sensor_mv() -> u16 { + todo!() + } + + fn light(enable:bool) { + todo!() + } + + fn measure_moisture_b_hz(plant:i8) -> i16 { + todo!() + } + + fn measure_moisture_a_hz(plant:i8) -> i16 { + todo!() + } + + fn measure_moisture_p_hz(plant:i8) -> i16 { + todo!() + } + + fn last_watering_time(plant:i8) -> chrono::DateTime { + todo!() + } +} + + + + + + +fn main() { + + // It is necessary to call this function once. Otherwise some patches to the runtime + // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 + esp_idf_svc::sys::link_patches(); + + // Bind the log crate to the ESP Logging facilities + esp_idf_svc::log::EspLogger::initialize_default(); + + log::info!("Hello, world!"); + + + let board = PlantCtrlBoard::default(); + +}