add initial flashing of batery and 3.1 adjustments

This commit is contained in:
Empire 2024-07-31 20:45:06 +02:00
parent f0e0781100
commit 3ece894592
14 changed files with 12337 additions and 11019 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"board": {
"active_layer": 36,
"active_layer": 1,
"active_layer_preset": "",
"auto_track_width": false,
"hidden_netclasses": [],

View File

@ -59,23 +59,51 @@
}
],
"drc_exclusions": [
"footprint_symbol_mismatch|177050000|59025000|a624af3d-bffa-4ff7-9554-e16d3c677f69|00000000-0000-0000-0000-000000000000",
"footprint_symbol_mismatch|237580000|53970000|c9d8d35b-26b7-4992-9d25-be9130d57b1a|00000000-0000-0000-0000-000000000000",
"footprint_symbol_mismatch|256580000|49370000|b33af7ef-63da-4a51-8d8a-183cadd974de|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|09cad967-1882-4dd3-8900-445282e228e5|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|20ab85c0-b3f3-4826-a86d-065fee01e11f|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|3da9717d-9800-42f9-97d1-56d23bf085aa|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|444aab2b-3a9b-444e-b60c-b5b5ff830942|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|6b067fd3-d374-4937-8779-958994d9163b|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|9839c562-7672-4ea8-a74d-bea83ae26677|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|9ce2df19-edf4-40d2-8e85-8c33008b8df0|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|a8ab716a-cd1e-4842-ad8e-3d6d1db9770b|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|aaf09ae3-4ace-49d7-a050-44cb4c93d63b|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|af55e8a2-ba8d-462e-807f-99ca5906f801|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|c36efd78-869f-40e7-86fc-97e5ed683fec|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|d668fda0-e4be-4e1f-95b8-8cd59a67cb21|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|d99401c6-2b75-46f7-8616-cdd7755709ee|00000000-0000-0000-0000-000000000000",
"net_conflict|177050000|59025000|f1fd5816-e8bd-4ba6-9d53-54b58d25e2dc|00000000-0000-0000-0000-000000000000"
"clearance|176260000|58370000|aaf09ae3-4ace-49d7-a050-44cb4c93d63b|ee82357c-9139-4ef8-a542-8725e3254fe0",
"clearance|176660000|56270000|3da9717d-9800-42f9-97d1-56d23bf085aa|d5ef1ade-5176-4779-aaf0-75a583095401",
"clearance|176660000|57520000|09cad967-1882-4dd3-8900-445282e228e5|aaecf811-fc68-432e-8032-ac52f2f4c632",
"clearance|176660000|58770000|a8ab716a-cd1e-4842-ad8e-3d6d1db9770b|ee82357c-9139-4ef8-a542-8725e3254fe0",
"clearance|177110000|56270000|3da9717d-9800-42f9-97d1-56d23bf085aa|02c6a0d6-d749-439d-8aea-2a55ff23d509",
"clearance|177110000|57520000|09cad967-1882-4dd3-8900-445282e228e5|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"clearance|177110000|58770000|a8ab716a-cd1e-4842-ad8e-3d6d1db9770b|173bfee3-0343-4ee2-91d9-e73a12cffe08",
"clearance|177510000|56670000|444aab2b-3a9b-444e-b60c-b5b5ff830942|02c6a0d6-d749-439d-8aea-2a55ff23d509",
"clearance|177510000|57120000|444aab2b-3a9b-444e-b60c-b5b5ff830942|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"clearance|177510000|57920000|f1fd5816-e8bd-4ba6-9d53-54b58d25e2dc|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"clearance|177510000|58370000|f1fd5816-e8bd-4ba6-9d53-54b58d25e2dc|173bfee3-0343-4ee2-91d9-e73a12cffe08",
"clearance|177910000|56270000|9ce2df19-edf4-40d2-8e85-8c33008b8df0|02c6a0d6-d749-439d-8aea-2a55ff23d509",
"clearance|177910000|57520000|c36efd78-869f-40e7-86fc-97e5ed683fec|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"clearance|177910000|58770000|d668fda0-e4be-4e1f-95b8-8cd59a67cb21|173bfee3-0343-4ee2-91d9-e73a12cffe08",
"clearance|178360000|56270000|9ce2df19-edf4-40d2-8e85-8c33008b8df0|50a027a2-4230-4974-b6cb-9aa24d6b855f",
"clearance|178360000|57520000|c36efd78-869f-40e7-86fc-97e5ed683fec|ae02705d-fc4c-4270-b7c5-41495037850e",
"clearance|178360000|58770000|d668fda0-e4be-4e1f-95b8-8cd59a67cb21|08dd9140-8967-4746-a078-91e200a8f376",
"clearance|178760000|56670000|20ab85c0-b3f3-4826-a86d-065fee01e11f|50a027a2-4230-4974-b6cb-9aa24d6b855f",
"clearance|178760000|57120000|20ab85c0-b3f3-4826-a86d-065fee01e11f|ae02705d-fc4c-4270-b7c5-41495037850e",
"clearance|178760000|57920000|6b067fd3-d374-4937-8779-958994d9163b|ae02705d-fc4c-4270-b7c5-41495037850e",
"clearance|178760000|58370000|6b067fd3-d374-4937-8779-958994d9163b|08dd9140-8967-4746-a078-91e200a8f376",
"solder_mask_bridge|176260000|56670000|9839c562-7672-4ea8-a74d-bea83ae26677|d5ef1ade-5176-4779-aaf0-75a583095401",
"solder_mask_bridge|176260000|57120000|9839c562-7672-4ea8-a74d-bea83ae26677|aaecf811-fc68-432e-8032-ac52f2f4c632",
"solder_mask_bridge|176260000|57920000|aaf09ae3-4ace-49d7-a050-44cb4c93d63b|aaecf811-fc68-432e-8032-ac52f2f4c632",
"solder_mask_bridge|176260000|58370000|aaf09ae3-4ace-49d7-a050-44cb4c93d63b|ee82357c-9139-4ef8-a542-8725e3254fe0",
"solder_mask_bridge|176660000|56270000|3da9717d-9800-42f9-97d1-56d23bf085aa|d5ef1ade-5176-4779-aaf0-75a583095401",
"solder_mask_bridge|176660000|57520000|09cad967-1882-4dd3-8900-445282e228e5|aaecf811-fc68-432e-8032-ac52f2f4c632",
"solder_mask_bridge|176660000|58770000|a8ab716a-cd1e-4842-ad8e-3d6d1db9770b|ee82357c-9139-4ef8-a542-8725e3254fe0",
"solder_mask_bridge|177110000|56270000|3da9717d-9800-42f9-97d1-56d23bf085aa|02c6a0d6-d749-439d-8aea-2a55ff23d509",
"solder_mask_bridge|177110000|57520000|09cad967-1882-4dd3-8900-445282e228e5|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"solder_mask_bridge|177110000|58770000|a8ab716a-cd1e-4842-ad8e-3d6d1db9770b|173bfee3-0343-4ee2-91d9-e73a12cffe08",
"solder_mask_bridge|177510000|56670000|444aab2b-3a9b-444e-b60c-b5b5ff830942|02c6a0d6-d749-439d-8aea-2a55ff23d509",
"solder_mask_bridge|177510000|57120000|444aab2b-3a9b-444e-b60c-b5b5ff830942|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"solder_mask_bridge|177510000|57920000|f1fd5816-e8bd-4ba6-9d53-54b58d25e2dc|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"solder_mask_bridge|177510000|58370000|f1fd5816-e8bd-4ba6-9d53-54b58d25e2dc|173bfee3-0343-4ee2-91d9-e73a12cffe08",
"solder_mask_bridge|177910000|56270000|9ce2df19-edf4-40d2-8e85-8c33008b8df0|02c6a0d6-d749-439d-8aea-2a55ff23d509",
"solder_mask_bridge|177910000|57520000|c36efd78-869f-40e7-86fc-97e5ed683fec|b83e5527-c0f3-4e61-bd5b-3079ced0723c",
"solder_mask_bridge|177910000|58770000|d668fda0-e4be-4e1f-95b8-8cd59a67cb21|173bfee3-0343-4ee2-91d9-e73a12cffe08",
"solder_mask_bridge|178360000|56270000|9ce2df19-edf4-40d2-8e85-8c33008b8df0|50a027a2-4230-4974-b6cb-9aa24d6b855f",
"solder_mask_bridge|178360000|57520000|c36efd78-869f-40e7-86fc-97e5ed683fec|ae02705d-fc4c-4270-b7c5-41495037850e",
"solder_mask_bridge|178360000|58770000|d668fda0-e4be-4e1f-95b8-8cd59a67cb21|08dd9140-8967-4746-a078-91e200a8f376",
"solder_mask_bridge|178760000|56670000|20ab85c0-b3f3-4826-a86d-065fee01e11f|50a027a2-4230-4974-b6cb-9aa24d6b855f",
"solder_mask_bridge|178760000|57120000|20ab85c0-b3f3-4826-a86d-065fee01e11f|ae02705d-fc4c-4270-b7c5-41495037850e",
"solder_mask_bridge|178760000|57920000|6b067fd3-d374-4937-8779-958994d9163b|ae02705d-fc4c-4270-b7c5-41495037850e",
"solder_mask_bridge|178760000|58370000|6b067fd3-d374-4937-8779-958994d9163b|08dd9140-8967-4746-a078-91e200a8f376"
],
"meta": {
"filename": "board_design_settings.json",

File diff suppressed because it is too large Load Diff

View File

@ -4,11 +4,11 @@ target = "riscv32imac-esp-espidf"
[target.riscv32imac-esp-espidf]
linker = "ldproxy"
# runner = "espflash flash --monitor --partition-table partitions.csv -b no-reset" # Select this runner for espflash v2.x.x
runner = "espflash flash --monitor --partition-table partitions.csv -b no-reset" # Select this runner for espflash v2.x.x
# runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv -b no-reset" # Select this runner for espflash v2.x.x
# runner = espflash erase-parts otadata
runner = "cargo runner"
#runner = "cargo runner"
rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110
[unstable]

View File

@ -68,7 +68,7 @@ serde_json = "1.0.108"
strum = { version = "0.26.1", features = ["derive"] }
once_cell = "1.19.0"
measurements = "0.11.0"
bq34z100 = "0.2.1"
bq34z100 = { version = "0.3.0" , features = ["flashstream"] }
[patch.crates-io]
#esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal.git" }
@ -76,6 +76,7 @@ esp-idf-hal = { git = "https://github.com/empirephoenix/esp-idf-hal.git" }
#esp-idf-sys = { git = "https://github.com/empirephoenix/esp-idf-sys.git" }
#esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys.git" }
#esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc.git" }
#bq34z100 = { path = "../../bq34z100_rust" }
[build-dependencies]
embuild = "0.31.3"

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,7 @@ mod config;
pub mod espota;
pub mod plant_hal;
const MOIST_SENSOR_MAX_FREQUENCY: u32 = 5200; // 60kHz (500Hz margin)
const MOIST_SENSOR_MAX_FREQUENCY: u32 = 50000; // 60kHz (500Hz margin)
const MOIST_SENSOR_MIN_FREQUENCY: u32 = 500; // 0.5kHz (500Hz margin)
const FROM: (f32, f32) = (
@ -73,7 +73,9 @@ struct LightState {
#[derive(Debug, PartialEq, Default)]
struct PlantState {
a: Option<u8>,
a_raw: Option<i32>,
b: Option<u8>,
b_raw: Option<i32>,
consecutive_pump_count: u32,
after_p: Option<u8>,
do_water: bool,
@ -117,7 +119,9 @@ struct TankStateMQTT {
#[derive(Serialize)]
struct PlantStateMQTT<'a> {
a: &'a str,
a_raw: &'a str,
b: &'a str,
b_raw: &'a str,
mode: &'a str,
consecutive_pump_count: u32,
dry: bool,
@ -657,6 +661,7 @@ fn determine_state_target_moisture_for_plant(
}
match board.measure_moisture_hz(plant, plant_hal::Sensor::A) {
Ok(a) => {
state.a_raw = Some(a);
let mapped = map_range_moisture(a as f32);
match mapped {
Ok(result) => state.a = Some(result),
@ -672,6 +677,7 @@ fn determine_state_target_moisture_for_plant(
if plant_config.sensor_b {
match board.measure_moisture_hz(plant, plant_hal::Sensor::B) {
Ok(b) => {
state.b_raw = Some(b);
let mapped = map_range_moisture(b as f32);
match mapped {
Ok(result) => state.b = Some(result),
@ -885,7 +891,9 @@ fn update_plant_state(
&state.sensor_error_a,
plant_config.mode != Mode::OFF,
),
a_raw: &state.a_raw.unwrap_or(0).to_string(),
b: &sensor_to_string(&state.b, &state.sensor_error_b, plant_config.sensor_b),
b_raw: &state.b_raw.unwrap_or(0).to_string(),
active: state.active,
mode: &mode,
last_pump: &time_to_string_utc(board.last_pump_time(plant)),

View File

@ -48,10 +48,11 @@ use esp_idf_sys::{esp, gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError};
use one_wire_bus::OneWire;
use crate::config::{self, Config, WifiConfig};
use crate::STAY_ALIVE;
use crate::{plant_hal, STAY_ALIVE};
//Only support for 8 right now!
pub const PLANT_COUNT: usize = 8;
const REPEAT_MOIST_MEASURE: usize = 3;
const SPIFFS_PARTITION_NAME: &str = "storage";
const WIFI_CONFIG_FILE: &str = "/spiffs/wifi.cfg";
@ -190,6 +191,7 @@ pub trait PlantCtrlBoardInteraction {
fn mqtt_publish(&mut self, config: &Config, subtopic: &str, message: &[u8]) -> Result<()>;
fn sensor_multiplexer(&mut self, n: u8) -> Result<()>;
fn flash_bq34_z100(&mut self, line: &str, dryrun:bool) -> Result<()>;
}
pub trait CreatePlantHal<'a> {
@ -401,14 +403,6 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
}
fn measure_moisture_hz(&mut self, plant: usize, sensor: Sensor) -> Result<i32> {
self.signal_counter.counter_pause()?;
self.signal_counter.counter_clear()?;
//Disable all
self.shift_register.decompose()[MS_4]
.set_high()
.unwrap();
let sensor_channel = match sensor {
Sensor::A => match plant {
0 => SENSOR_A_1,
@ -434,34 +428,51 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
},
};
self.sensor_multiplexer(sensor_channel)?;
self.shift_register.decompose()[MS_4]
.set_low()
.unwrap();
self.shift_register.decompose()[SENSOR_ON]
.set_high()
.unwrap();
let delay = Delay::new_default();
let measurement = 100;
let factor = 1000 as f32 / measurement as f32;
//give some time to stabilize
delay.delay_ms(10);
self.signal_counter.counter_resume()?;
delay.delay_ms(measurement);
self.signal_counter.counter_pause()?;
self.shift_register.decompose()[MS_4]
let mut results = [0;REPEAT_MOIST_MEASURE];
for repeat in 0..REPEAT_MOIST_MEASURE {
self.signal_counter.counter_pause()?;
self.signal_counter.counter_clear()?;
//Disable all
self.shift_register.decompose()[MS_4]
.set_high()
.unwrap();
self.sensor_multiplexer(sensor_channel)?;
self.shift_register.decompose()[MS_4]
.set_low()
.unwrap();
self.shift_register.decompose()[SENSOR_ON]
.set_high()
.unwrap();
self.shift_register.decompose()[SENSOR_ON]
.set_low()
.unwrap();
let unscaled = self.signal_counter.get_counter_value()? as i32;
let hz = (unscaled as f32 * factor) as i32;
println!("Measuring {:?} @ {} with {}", sensor, plant, hz);
Ok(hz)
let delay = Delay::new_default();
let measurement = 10;
let factor = 1000 as f32 / measurement as f32;
//give some time to stabilize
delay.delay_ms(10);
self.signal_counter.counter_resume()?;
delay.delay_ms(measurement);
self.signal_counter.counter_pause()?;
self.shift_register.decompose()[MS_4]
.set_high()
.unwrap();
self.shift_register.decompose()[SENSOR_ON]
.set_low()
.unwrap();
delay.delay_ms(10);
let unscaled = self.signal_counter.get_counter_value()? as i32;
let hz = (unscaled as f32 * factor) as i32;
results[repeat] = hz;
//println!("Measuring {:?} @ {} with {}", sensor, plant, hz);
}
results.sort();
let mid = results.len() / 2;
Ok(results[mid])
}
fn general_fault(&mut self, enable: bool) {
@ -634,27 +645,9 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
}
fn wifi_scan(&mut self) -> Result<Vec<AccessPointInfo>> {
//remove this parts
for i in 1..11 {
println!("Scanning channel {}", i);
self.wifi_driver.start_scan(
&ScanConfig {
scan_type: ScanType::Passive(Duration::from_secs(1)),
show_hidden: false,
channel: Some(i),
..Default::default()
},
true,
)?;
let sr = self.wifi_driver.get_scan_result()?;
for r in sr.iter() {
println!("Found wifi {}", r.ssid);
}
}
self.wifi_driver.start_scan(
&ScanConfig {
scan_type: ScanType::Passive(Duration::from_secs(1)),
scan_type: ScanType::Passive(Duration::from_secs(5)),
show_hidden: false,
..Default::default()
},
@ -685,24 +678,25 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
unsafe { vTaskDelay(500) };
self.light(false)?;
unsafe { vTaskDelay(500) };
for i in 0..8 {
for i in 0..PLANT_COUNT {
self.fault(i, true);
unsafe { vTaskDelay(500) };
self.fault(i, false);
unsafe { vTaskDelay(500) };
}
for i in 0..8 {
for i in 0..PLANT_COUNT {
self.pump(i, true)?;
unsafe { vTaskDelay(100) };
self.pump(i, false)?;
unsafe { vTaskDelay(100) };
}
for i in 0..8 {
self.measure_moisture_hz(i, Sensor::A)?;
}
for i in 0..8 {
self.measure_moisture_hz(i, Sensor::B)?;
for plant in 0..PLANT_COUNT {
let a = self.measure_moisture_hz(plant, plant_hal::Sensor::A);
let b = self.measure_moisture_hz(plant, plant_hal::Sensor::B);
print!("P:{} a:{:?} b:{:?}", plant, a ,b)
}
println!();
Delay::new_default().delay_ms(10);
Ok(())
}
@ -1012,6 +1006,16 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
}
Ok(())
}
fn flash_bq34_z100(&mut self, line: &str, dryrun: bool) -> Result<()> {
match &mut self.battery_driver {
Some(driver) => match driver.write_flash_stream_i2c(line, dryrun) {
OkStd(r) => Ok(r),
Err(err) => bail!("Error reading SoC {:?}", err),
},
None => bail!("Error reading SoC bq34z100 not found"),
}
}
}
fn print_battery(
@ -1096,7 +1100,7 @@ impl CreatePlantHal<'_> for PlantHal {
let mut battery_driver: Bq34z100g1Driver<I2cDriver, Delay> = Bq34z100g1Driver {
i2c: driver,
delay: Delay::new_default(),
delay: Delay::new(0),
flash_block_data: [0; 32],
};
@ -1115,6 +1119,8 @@ impl CreatePlantHal<'_> for PlantHal {
one_wire_pin.set_pull(Pull::Floating).unwrap();
//disable all
let ms0 = &mut shift_register.decompose()[MS_0];
ms0.set_low()?;
let ms1 = &mut shift_register.decompose()[MS_1];
ms1.set_low()?;
let ms2 = &mut shift_register.decompose()[MS_2];
@ -1123,7 +1129,7 @@ impl CreatePlantHal<'_> for PlantHal {
ms3.set_low()?;
let ms4 = &mut shift_register.decompose()[MS_4];
ms4.set_low()?;
ms4.set_high()?;
//init,reset rtc memory depending on cause
let reasons = ResetReason::get();
@ -1249,8 +1255,8 @@ impl CreatePlantHal<'_> for PlantHal {
println!("Managed to comunnicate with battery");
}
let mut shift_register_enable_invert = PinDriver::output(peripherals.pins.gpio21.downgrade())?;
shift_register_enable_invert.set_low().unwrap();
let shift_register_enable_invert = PinDriver::output(peripherals.pins.gpio21.downgrade())?;
let rv = Mutex::new(PlantCtrlBoard {
shift_register,
@ -1269,6 +1275,15 @@ impl CreatePlantHal<'_> for PlantHal {
//battery_driver: None,
battery_driver: Some(battery_driver),
});
let _ = rv.lock().is_ok_and(|mut board|{
unsafe { gpio_hold_dis(board.shift_register_enable_invert.pin())};
board.shift_register_enable_invert.set_low().unwrap();
unsafe { gpio_hold_en(board.shift_register_enable_invert.pin())};
return true;
});
Ok(rv)
}
}

View File

@ -0,0 +1,197 @@
;--------------------------------------------------------
;Verify Existing Firmware Version
;--------------------------------------------------------
W: AA 00 01 00
C: AA 00 00 01
W: AA 00 02 00
C: AA 00 02 02
;--------------------------------------------------------
;Unseal device
;--------------------------------------------------------
W: AA 00 14 04
W: AA 00 72 36
W: AA 00 FF FF
W: AA 00 FF FF
X: 1000
;--------------------------------------------------------
;Go To ROM Mode
;--------------------------------------------------------
W: AA 00 00 0F
X: 1000
;--------------------------------------------------------
;Data Block
;--------------------------------------------------------
W: 16 00 03 00 00
W: 16 64 03 00
X: 20
C: 16 66 00
W: 16 00 02 00 00 00 EA FF 33 FA FA 33 B5 FB 33 95 FE 33 AD FE 33 FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F 02 02 3F 58 CB 33 C3 A0 08 1F 00 00 00 00 00 FF AA 0E FB A7 0E FF A6 0E FF A1 0E FF A0 0E FE A3 0E 54 A2 0E DE FF 3A 67 FF 3A E2 FF 33 FF AF 0E
W: 16 64 3D 38
X: 2
C: 16 66 00
W: 16 00 02 01 00 00 01 4F 03 3F 11 0C D9 FF 30 E0 FF 35 2F 10 0C E0 FF 35 FF FF 23 E3 AF 04 E2 BF 04 D1 FF 36 E2 A0 04 E3 A1 04 00 C7 02 01 C6 02 E5 AF 04 E3 BF 01 E4 AF 04 E2 BF 01 FF AC 0E E1 1C 04 8A FF 31 E2 A0 04 E3 A1 04 02 AB 18 7F 2B 0E FF 1B 0E BF FF 32 FC FA 0E FB AF 0C 02 2B 18 FF 1B 0E 98 FF 36
W: 16 64 AE 2C
X: 2
C: 16 66 00
W: 16 00 05
W: 16 64 05 00
X: 170
C: 16 66 00
C: 16 04 0A 91 AF DC
W: 16 00 0C 00 00 00 83 DE
W: 16 64 6D 01
X: 400
C: 16 66 00
W: 16 00 0A 00 00 00 7E 22 B7 35 92 38 D0 0B F9 F1 E5 BC 00 00 14 B0 51 F6 C9 F4 14 52 09 21 32 6D 00 00 00 00 D0 7E
W: 16 64 0B 0D
X: 2
C: 16 66 00
W: 16 00 0A 01 00 00 17 DF 00 00 17 F3 00 00 3A 36 FD 91 00 25 30 01 00 EF 02 11 05 01 00 00 10 01 00 3C 00 50 3C 00
W: 16 64 40 06
X: 2
C: 16 66 00
W: 16 00 0A 02 00 00 64 3C 00 20 03 E8 00 00 04 10 68 FE D5 FB 95 00 02 00 14 03 E8 01 00 01 F4 00 1E 00 3C 0E 10 00
W: 16 64 05 08
X: 2
C: 16 66 00
W: 16 00 0A 03 00 00 0A 46 05 32 01 0F 01 F4 00 64 46 50 0A 0D 0C 0C C0 01 90 00 64 19 00 01 00 14 00 01 00 14 03 23
W: 16 64 E0 04
X: 2
C: 16 66 00
W: 16 00 0A 04 00 00 07 08 25 5A 32 0F 64 60 00 A0 0B B8 00 C8 28 01 F4 00 00 00 00 00 00 00 00 00 00 43 80 04 00 00
W: 16 64 B0 05
X: 2
C: 16 66 00
W: 16 00 0A 05 00 00 0F 00 2A 04 0A 7D 00 00 01 0A FE 76 E7 54 00 28 03 E8 02 01 2C F0 00 04 18 0D 5B 0D 28 0D 02 0D
W: 16 64 94 06
X: 2
C: 16 66 00
W: 16 00 0A 06 00 00 0A 0D 06 0D 06 0D 07 0D 06 0D 05 0D 04 0D 04 0D 03 0D 08 0D 04 0C F9 0C ED 0C EC 0C E0 0C DA 0C
W: 16 64 A5 05
X: 2
C: 16 66 00
W: 16 00 0A 07 00 00 D6 0C D7 0C DA 0C D9 0C D9 0C D8 0C D5 0C D2 0C D2 0C D0 0C C9 0C BE 0C B4 0C A7 0C 9A 0C 8A 0C
W: 16 64 31 0D
X: 2
C: 16 66 00
W: 16 00 0A 08 00 00 85 0C 7E 0C 2D 0B 64 09 64 FD 9E 03 6B 05 37 00 58 01 FA 01 D6 01 17 01 50 01 94 01 E2 01 CE 02
W: 16 64 57 09
X: 2
C: 16 66 00
W: 16 00 0A 09 00 00 62 FF 67 01 99 03 7D 05 9C 00 DA 02 CB 03 AD 04 A1 04 72 02 F1 03 A0 03 85 03 E7 04 86 04 EE 02
W: 16 64 8E 0B
X: 2
C: 16 66 00
W: 16 00 0A 0A 00 00 AB 01 0C FE D1 FE EE FF 28 FF 76 FF 51 00 13 00 88 FE 42 FD 29 05 9B 23 48 FF 7E FF 8B FF 6C FF
W: 16 64 F0 11
X: 2
C: 16 66 00
W: 16 00 0A 0B 00 00 46 FF 97 FF 8D FF 97 FF 98 FF 84 FF 8C FF AB FF B1 FF B1 FF 92 FF 74 FF 35 FF 0B FF 06 FF 5E FF
W: 16 64 65 17
X: 2
C: 16 66 00
W: 16 00 0A 0C 00 00 13 FF 17 FF 10 FE C7 FE D8 FF 0C FF 05 FE E3 FF 2E FF 1D FE B7 00 00 01 C2 00 32 FF CE 02 26 64
W: 16 64 25 11
X: 2
C: 16 66 00
W: 16 00 0A 0D 00 00 7B 1F BE 77 60 7E 00 00 00 00 64 00 19 00 64 28 63 5F 64 62 00 64 00 1E 00 B4 00 64 00 F0 00 FA
W: 16 64 D9 08
X: 2
C: 16 66 00
W: 16 00 0A 0E 00 00 11 10 10 68 49 FA 18 37 09 18 00 04 00 14 00 00 0A F0 00 0A 05 00 32 01 C2 14 14 00 00 3C 00 4B
W: 16 64 29 05
X: 2
C: 16 66 00
W: 16 00 0A 0F 00 00 00 28 00 3C 3C 01 90 36 72 04 14 FF FF FF FF 01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10 04
W: 16 64 02 0E
X: 2
C: 16 66 00
W: 16 00 0A 10 00 00 01 75 FE 79 08 1E FF 83 7F FF 00 AF 00 04 0A 64 01 00 3C 00 00 00 00 00 00 00 00 00 00 00 00 00
W: 16 64 8B 06
X: 2
C: 16 66 00
W: 16 00 0A 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
W: 16 64 1B 00
X: 2
C: 16 66 00
W: 16 00 0A 12 00 00 02 26 02 01 F4 02 58 02 02 26 0E 00 00 00 00 00 00 00 00 00 00 00 00 17 00 DC 84 E5 5F 60 1C 0E
W: 16 64 12 05
X: 2
C: 16 66 00
W: 16 00 0A 13 00 00 10 00 21 00 01 00 01 03 E8 64 17 70 64 00 FE 70 10 68 10 68 10 04 0A 32 1E 00 0A 2D 37 01 01 03
W: 16 64 C9 05
X: 2
C: 16 66 00
W: 16 00 0A 14 00 00 0B 62 71 33 34 7A 31 30 30 2D 47 31 0B 54 65 78 61 73 20 49 6E 73 74 2E 04 4C 49 46 4F 00 96 00
W: 16 64 D3 08
X: 2
C: 16 66 00
W: 16 00 0A 15 00 00 AF 00 4B 00 64 0A F0 02 0B 54 10 CC 02 10 68 64 01 03 05 00 00 00 00 00 00 00 00 00 00 00 00 00
W: 16 64 9B 04
X: 2
C: 16 66 00
W: 16 00 0A 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF
W: 16 64 13 0D
X: 2
C: 16 66 00
W: 16 00 0A 17 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
W: 16 64 01 20
X: 2
C: 16 66 00
W: 16 00 0A 18 00 00 FF 55 00 1A 00 1C 00 23 00 35 00 1E 00 20 00 27 00 22 00 25 00 42 00 3F 00 41 00 76 00 9D 02 0A
W: 16 64 91 04
X: 2
C: 16 66 00
W: 16 00 0A 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
W: 16 64 23 00
X: 2
C: 16 66 00
W: 16 00 0A 1A 00 00 FF FF 00 1A 00 1C 00 23 00 35 00 1E 00 20 00 27 00 22 00 25 00 42 00 3F 00 41 00 76 00 9D 02 0A
W: 16 64 3D 05
X: 2
C: 16 66 00
W: 16 00 0A 1B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
W: 16 64 25 00
X: 2
C: 16 66 00
W: 16 00 0A 1C 00 00 11 10 10 68 49 FA 18 37 09 18 00 04 00 14 00 00 0A F0 00 0A 05 00 32 01 C2 14 14 00 00 3C 00 4B
W: 16 64 37 05
X: 2
C: 16 66 00
W: 16 00 0A 1D 00 00 00 28 00 3C 3C 01 90 36 72 04 14 FF FF FF FF 01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10 04
W: 16 64 10 0E
X: 2
C: 16 66 00
W: 16 00 0A 1E 00 00 FF FF FF FF 00 00 02 6B FF FF FD 93 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
W: 16 64 0B 1C
X: 2
C: 16 66 00
W: 16 00 0A 1F 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
W: 16 64 09 20
X: 2
C: 16 66 00
W: 16 00 08
W: 16 64 08 00
X: 2
C: 16 66 00
C: 16 04 F1 4C
W: 16 00 05
W: 16 64 05 00
X: 170
C: 16 66 00
C: 16 04 0A 91 AF DC
W: 16 00 01 00 00 05 54 54 15
W: 16 64 C3 00
X: 20
C: 16 66 00
W: 16 00 05
W: 16 64 05 00
X: 170
C: 16 66 00
C: 16 04 5F E5 84 DC
;--------------------------------------------------------
;Execute Flash Code
;--------------------------------------------------------
W: 16 00 0F
W: 16 64 0F 00
X: 4000

View File

@ -17,8 +17,9 @@
<p id="loaded_n_total"></p>
</form>
<h2>Battery Firmeware (bq34z100 may be R2)</h2>
<button id="flash5ah12vlifepo">Flash 6AH 12V Lifepo replacement (built in)</button>
<div style="height: 100px; display: block; overflow-y: auto;" id = "flash_message"></div>
<h2>config</h2>
<div id="configform">

View File

@ -1,13 +1,13 @@
//offer ota and config mode
use std::{
str::from_utf8,
sync::{atomic::AtomicBool, Arc},
io::BufRead, str::from_utf8, sync::{atomic::AtomicBool, Arc}
};
use crate::{espota::OtaUpdate, BOARD_ACCESS};
use core::result::Result::Ok;
use embedded_svc::http::Method;
use esp_idf_hal::{delay::Delay, io::Write};
use esp_idf_svc::http::server::{Configuration, EspHttpServer};
use heapless::String;
use serde::{Deserialize, Serialize};
@ -289,4 +289,46 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
})
.unwrap();
server
.fn_handler("/flashbattery", Method::Post, move |request| {
let mut board = BOARD_ACCESS.lock().unwrap();
let mut response = request.into_ok_response().unwrap();
let delay = Delay::new(0);
let firmware = include_bytes!("0100_2_02-bq34z100.df.fs");
response.write("Checking pass: \n".as_bytes()).unwrap();
for iter in firmware.lines() {
delay.delay_us(1);
let line = iter?;
let msg = format!("{line}<br>");
println!("{line}");
response.write(msg.as_bytes()).unwrap();
let validate = board.flash_bq34_z100(&line, true);
if validate.is_err() {
response.write(validate.unwrap_err().to_string().as_bytes()).unwrap();
}
}
response.write("Executing flashing: \n".as_bytes()).unwrap();
let mut toggle = true;
for iter in firmware.lines() {
delay.delay_us(1);
let line = iter?;
let msg = format!("{line}<br>");
println!("{line}");
response.write(msg.as_bytes()).unwrap();
board.general_fault(toggle);
toggle = !toggle;
let write = board.flash_bq34_z100(&line, false);
if write.is_err() {
response.write(write.unwrap_err().to_string().as_bytes()).unwrap();
}
}
board.general_fault(false);
anyhow::Ok(())
})
.unwrap();
server
}

View File

@ -0,0 +1,40 @@
interface FirmeWareFlashRequest{
name: string
}
let flash5ah12vlifepo = document.getElementById("flash5ah12vlifepo") as HTMLButtonElement;
let flash_message = document.getElementById("flash_message") as HTMLElement;
export async function streamToText(stream: ReadableStream<Uint8Array>): Promise<string> {
let result = '';
const reader = stream.pipeThrough(new TextDecoderStream()).getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
result += value;
flash_message.innerHTML = result;
flash_message.scrollTop = flash_message.scrollHeight;
}
return result;
}
flash5ah12vlifepo.onclick = async function (){
var body:FirmeWareFlashRequest = {
name: "flash5ah12vlifepo"
}
var pretty = JSON.stringify(body, undefined, 1);
fetch("/flashbattery", {
method :"POST",
body: pretty
}).then((response) => response.body)
.then((body) => {
streamToText(body)
});
};

View File

@ -3,7 +3,7 @@ const path = require('path');
module.exports = {
mode: "development",
entry: ['./src/form.ts','./src/ota.ts','./src/wifi.ts'],
entry: ['./src/form.ts','./src/ota.ts','./src/wifi.ts', "./src/battery.ts"],
devtool: 'inline-source-map',
module: {
rules: [