From 6903ebdadfcfa22d24062e87a129f2afabff1f62 Mon Sep 17 00:00:00 2001
From: fly <merspieler@alwaysdata.com>
Date: Tue, 14 May 2024 13:51:39 +0200
Subject: [PATCH] Fix not always reading reports, do proper solution with timer
 later

Signed-off-by: fly <merspieler@alwaysdata.com>
---
 Pedestal/firmware/src/main.rs | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/Pedestal/firmware/src/main.rs b/Pedestal/firmware/src/main.rs
index ec831e0..6403d92 100644
--- a/Pedestal/firmware/src/main.rs
+++ b/Pedestal/firmware/src/main.rs
@@ -5,6 +5,7 @@
 // Silence certain clippy warnings
 #![allow(non_upper_case_globals)]
 #![allow(clippy::needless_late_init)]
+#![allow(clippy::needless_return)]
 
 mod device;
 
@@ -133,7 +134,7 @@ fn main() -> ! {
 		pa2: gpioa.pa2.into_analog(&mut gpioa.crl),
 	};
 
-	let mut last = get_report(&mut input_pins, &mut adc1, &cal);
+//	let mut last = get_report(&mut input_pins, &mut adc1, &cal);
 
 	// ====================== PWM setup =================
 	let mut afio = p.AFIO.constrain();
@@ -144,23 +145,26 @@ fn main() -> ! {
 	pwm.enable(Channel::C1);
 	let pwm_max = pwm.get_max_duty(); //48000 in our case
 
+	// ====================== Timer setup ===============
+//	let timer = Instant;
+//	let mut last_report_sent = timer.elapsed();
 
 	// ====================== Main loop =================
 	loop {
 		let report = get_report(&mut input_pins, &mut adc1, &cal);
-		if report != last {
+// TODO figure out timer and only send in like 1ms intervals or on change
+//		if report != last {
 			match consumer.device().write_report(&report) {
 				Err(UsbHidError::WouldBlock) => {}
 				Ok(_) => {
-					last = report;
+//					last = report;
 				}
 				Err(e) => {
 					core::panic!("Failed to write consumer report: {:?}", e)
 				}
 			}
-		}
+//		}
 
-		// TODO figure out why we only land here after we've sent a report
 		if usb_dev.poll(&mut [&mut consumer]) {
 			match consumer.device().read_report() {
 				Err(UsbHidError::WouldBlock) => {}
@@ -305,7 +309,7 @@ fn load_calibration(flash: &mut FlashWriter) -> Calibration {
 			let dummy = bytes_of(&cal);
 			let dummy2 = &data[3..][..dummy.len()];
 			let dummy3 = bytes_of_mut(&mut cal);
-			dummy3.copy_from_slice(&dummy2);
+			dummy3.copy_from_slice(dummy2);
 			return cal;
 		},
 		Err(_e) => {