switch to oneshoot adc, as that seems to work
This commit is contained in:
parent
e2d00bc939
commit
b6abebd012
@ -4,6 +4,9 @@ use chrono_tz::Europe::Berlin;
|
|||||||
use embedded_svc::wifi::{
|
use embedded_svc::wifi::{
|
||||||
AccessPointConfiguration, AccessPointInfo, AuthMethod, ClientConfiguration, Configuration,
|
AccessPointConfiguration, AccessPointInfo, AuthMethod, ClientConfiguration, Configuration,
|
||||||
};
|
};
|
||||||
|
use esp_idf_hal::adc::attenuation;
|
||||||
|
use esp_idf_hal::adc::oneshot::config::AdcChannelConfig;
|
||||||
|
use esp_idf_hal::adc::oneshot::{AdcChannelDriver, AdcDriver};
|
||||||
use esp_idf_hal::i2c::{APBTickType, I2cConfig, I2cDriver, I2cError};
|
use esp_idf_hal::i2c::{APBTickType, I2cConfig, I2cDriver, I2cError};
|
||||||
use esp_idf_hal::units::FromValueType;
|
use esp_idf_hal::units::FromValueType;
|
||||||
use esp_idf_svc::eventloop::EspSystemEventLoop;
|
use esp_idf_svc::eventloop::EspSystemEventLoop;
|
||||||
@ -32,7 +35,6 @@ use std::sync::{Arc, Mutex};
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use embedded_hal::digital::OutputPin;
|
use embedded_hal::digital::OutputPin;
|
||||||
use esp_idf_hal::adc::{attenuation, AdcChannelDriver, AdcDriver};
|
|
||||||
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, IOPin, InputOutput, Level, PinDriver, Pull};
|
||||||
use esp_idf_hal::pcnt::{
|
use esp_idf_hal::pcnt::{
|
||||||
@ -161,8 +163,7 @@ pub struct PlantCtrlBoard<'a> {
|
|||||||
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
|
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
|
||||||
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
|
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
|
||||||
>,
|
>,
|
||||||
tank_driver: AdcDriver<'a, esp_idf_hal::adc::ADC1>,
|
tank_channel: AdcChannelDriver<'a, Gpio5, AdcDriver<'a, esp_idf_hal::adc::ADC1>>,
|
||||||
tank_channel: esp_idf_hal::adc::AdcChannelDriver<'a, { attenuation::DB_11 }, Gpio5>,
|
|
||||||
solar_is_day: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Input>,
|
solar_is_day: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Input>,
|
||||||
boot_button: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Input>,
|
boot_button: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Input>,
|
||||||
signal_counter: PcntDriver<'a>,
|
signal_counter: PcntDriver<'a>,
|
||||||
@ -222,7 +223,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
|
|
||||||
let mut store = [0_u16; TANK_MULTI_SAMPLE];
|
let mut store = [0_u16; TANK_MULTI_SAMPLE];
|
||||||
for multisample in 0..TANK_MULTI_SAMPLE {
|
for multisample in 0..TANK_MULTI_SAMPLE {
|
||||||
let value = self.tank_driver.read(&mut self.tank_channel)?;
|
let value = self.tank_channel.read()?;
|
||||||
store[multisample] = value;
|
store[multisample] = value;
|
||||||
}
|
}
|
||||||
store.sort();
|
store.sort();
|
||||||
@ -696,9 +697,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
.store(false, std::sync::atomic::Ordering::Relaxed);
|
.store(false, std::sync::atomic::Ordering::Relaxed);
|
||||||
println!("Mqtt error");
|
println!("Mqtt error");
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@ -950,7 +949,6 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
fn create() -> Result<Mutex<PlantCtrlBoard<'static>>> {
|
fn create() -> Result<Mutex<PlantCtrlBoard<'static>>> {
|
||||||
let peripherals = Peripherals::take()?;
|
let peripherals = Peripherals::take()?;
|
||||||
|
|
||||||
|
|
||||||
let i2c = peripherals.i2c0;
|
let i2c = peripherals.i2c0;
|
||||||
let config = I2cConfig::new()
|
let config = I2cConfig::new()
|
||||||
.scl_enable_pullup(true)
|
.scl_enable_pullup(true)
|
||||||
@ -961,10 +959,10 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
let sda = peripherals.pins.gpio20.downgrade();
|
let sda = peripherals.pins.gpio20.downgrade();
|
||||||
|
|
||||||
let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap();
|
let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap();
|
||||||
|
|
||||||
let i2c_port = driver.port();
|
let i2c_port = driver.port();
|
||||||
let mut timeout:i32 = 0;
|
let mut timeout: i32 = 0;
|
||||||
esp!(unsafe { esp_idf_sys::i2c_get_timeout(i2c_port, &mut timeout)}).unwrap();
|
esp!(unsafe { esp_idf_sys::i2c_get_timeout(i2c_port, &mut timeout) }).unwrap();
|
||||||
println!("init i2c timeout is {}", timeout);
|
println!("init i2c timeout is {}", timeout);
|
||||||
|
|
||||||
//esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 22)}).unwrap();
|
//esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 22)}).unwrap();
|
||||||
@ -1075,13 +1073,14 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
let nvs = EspDefaultNvsPartition::take()?;
|
let nvs = EspDefaultNvsPartition::take()?;
|
||||||
let wifi_driver = EspWifi::new(peripherals.modem, sys_loop, Some(nvs))?;
|
let wifi_driver = EspWifi::new(peripherals.modem, sys_loop, Some(nvs))?;
|
||||||
|
|
||||||
let adc_config = esp_idf_hal::adc::config::Config {
|
let adc_config = AdcChannelConfig {
|
||||||
|
attenuation: attenuation::DB_11,
|
||||||
resolution: esp_idf_hal::adc::config::Resolution::Resolution12Bit,
|
resolution: esp_idf_hal::adc::config::Resolution::Resolution12Bit,
|
||||||
calibration: true
|
calibration: true,
|
||||||
};
|
};
|
||||||
let tank_driver = AdcDriver::new(peripherals.adc1, &adc_config)?;
|
let tank_driver = AdcDriver::new(peripherals.adc1)?;
|
||||||
let tank_channel: AdcChannelDriver<'_, { attenuation::DB_11 }, Gpio5> =
|
let tank_channel: AdcChannelDriver<Gpio5, AdcDriver<esp_idf_hal::adc::ADC1>> =
|
||||||
AdcChannelDriver::new(peripherals.pins.gpio5)?;
|
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.gpio8.downgrade())?;
|
||||||
solar_is_day.set_pull(Pull::Floating)?;
|
solar_is_day.set_pull(Pull::Floating)?;
|
||||||
@ -1113,7 +1112,6 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
}
|
}
|
||||||
let rv = Mutex::new(PlantCtrlBoard {
|
let rv = Mutex::new(PlantCtrlBoard {
|
||||||
shift_register,
|
shift_register,
|
||||||
tank_driver,
|
|
||||||
tank_channel,
|
tank_channel,
|
||||||
solar_is_day,
|
solar_is_day,
|
||||||
boot_button,
|
boot_button,
|
||||||
@ -1126,7 +1124,7 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
wifi_driver,
|
wifi_driver,
|
||||||
mqtt_client: None,
|
mqtt_client: None,
|
||||||
//battery_driver: None,
|
//battery_driver: None,
|
||||||
battery_driver: Some(battery_driver)
|
battery_driver: Some(battery_driver),
|
||||||
});
|
});
|
||||||
Ok(rv)
|
Ok(rv)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user