Write calibration data
Signed-off-by: fly <merspieler@alwaysdata.com>
This commit is contained in:
parent
384226e543
commit
19c5b1c97e
1 changed files with 9 additions and 10 deletions
|
@ -5,8 +5,6 @@
|
|||
// Silence certain clippy warnings
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(clippy::needless_late_init)]
|
||||
//#![allow()]
|
||||
//#![allow()]
|
||||
|
||||
mod device;
|
||||
|
||||
|
@ -20,7 +18,7 @@ use stm32f1xx_hal::{
|
|||
pac,
|
||||
prelude::*,
|
||||
timer::{Channel, Tim2NoRemap},
|
||||
flash::{FlashWriter, FLASH_START},
|
||||
flash::{FlashWriter, FLASH_START, FlashSize, SectorSize},
|
||||
usb::{Peripheral, UsbBus},
|
||||
};
|
||||
|
||||
|
@ -124,7 +122,6 @@ fn main() -> ! {
|
|||
.build();
|
||||
|
||||
// ====================== ADC setup =================
|
||||
// Setup ADC
|
||||
let mut adc1 = adc::Adc::adc1(p.ADC1, clocks);
|
||||
|
||||
// ====================== Calibration ===============
|
||||
|
@ -151,6 +148,9 @@ fn main() -> ! {
|
|||
let mut calibration_active = false;
|
||||
let mut calibration_min_done = false;
|
||||
|
||||
// ====================== Calibration things ========
|
||||
let mut flash_writer = flash.writer(SectorSize::Sz1K, FlashSize::Sz64K);
|
||||
|
||||
// ====================== Main loop =================
|
||||
loop {
|
||||
let report = get_report(&mut input_pins, &mut adc1, &cal);
|
||||
|
@ -199,9 +199,8 @@ fn main() -> ! {
|
|||
cal.integ_lt.max = CalibrationData::ADC_MAX;
|
||||
}
|
||||
cal.integ_lt.factor = calculate_factor(cal.integ_lt.min, cal.integ_lt.max);
|
||||
// TODO write calibration data
|
||||
// save_calibration(&mut flash, &cal);
|
||||
pwm.set_duty(Channel::C1, 10 * pwm_max);
|
||||
save_calibration(&mut flash_writer, &cal);
|
||||
pwm.set_duty(Channel::C1, pwm_max);
|
||||
}
|
||||
calibration_active = false;
|
||||
calibration_min_done = false;
|
||||
|
@ -218,7 +217,7 @@ fn main() -> ! {
|
|||
|
||||
// Calculate factor from min and max
|
||||
fn calculate_factor(min: u16, max: u16) -> f32 {
|
||||
return (CalibrationData::ADC_MAX as f32 / (CalibrationData::ADC_MAX - min - (CalibrationData::ADC_MAX - max)) as f32);
|
||||
return CalibrationData::ADC_MAX as f32 / (CalibrationData::ADC_MAX - min - (CalibrationData::ADC_MAX - max)) as f32;
|
||||
}
|
||||
|
||||
// Returns a CustomInputReport from the inputs given
|
||||
|
@ -257,7 +256,7 @@ fn save_calibration(flash: &mut FlashWriter, cal: &Calibration) -> bool {
|
|||
let encoded_calibration_data = bytes_of(cal);
|
||||
data[3..][..encoded_calibration_data.len()].copy_from_slice(encoded_calibration_data);
|
||||
|
||||
flash.erase(FLASH_START + 64512, 1024).unwrap();
|
||||
let test = flash.erase(FLASH_START + 64512, 1024);
|
||||
match flash.write(FLASH_START + 64512, &data) {
|
||||
Ok(_ret) => return true,
|
||||
Err(_e) => return false,
|
||||
|
@ -266,7 +265,7 @@ fn save_calibration(flash: &mut FlashWriter, cal: &Calibration) -> bool {
|
|||
|
||||
// Load calibration to flash
|
||||
fn load_calibration() -> Calibration {
|
||||
let mut cal = Calibration::new();
|
||||
let cal = Calibration::new();
|
||||
// TODO reject loading if version is off or no calibration data found
|
||||
// TODO return calibration data
|
||||
return cal;
|
||||
|
|
Loading…
Add table
Reference in a new issue