From 64b0e2852a6e3a7e4f1530108feeb6a3e4d8a484 Mon Sep 17 00:00:00 2001 From: Jen Tak Date: Mon, 11 Dec 2023 18:59:12 +0100 Subject: [PATCH] Debug rotary encoder ticks --- Cargo.lock | 3 +++ Cargo.toml | 1 + src/counter.rs | 4 ++++ src/main.rs | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 30212b3..a44cbe8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aligned" version = "0.3.4" @@ -210,6 +212,7 @@ dependencies = [ name = "panel-firmware" version = "0.3.0" dependencies = [ + "arrayvec", "cortex-m 0.7.2", "cortex-m-rt", "embedded-hal", diff --git a/Cargo.toml b/Cargo.toml index a023675..05c5340 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ license = "MIT" edition = "2018" [dependencies] +arrayvec = { version = "0.5.2", default-features = false } stm32f4xx-hal = { version = "0.9", features = ["rt", "stm32f411", "usb_fs"] } embedded-hal = "0.2" cortex-m = "0.7" diff --git a/src/counter.rs b/src/counter.rs index a100a7a..c5f8a60 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -23,4 +23,8 @@ impl Counter { None } } + + pub fn current_count(&self) -> u16 { + self.qei.count() + } } diff --git a/src/main.rs b/src/main.rs index 6e7a07d..5dc0062 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,8 @@ use crate::{ rgb_led::{LedStrip, Pulser}, serial::{Command, Report, SerialProtocol}, }; +use arrayvec::ArrayString; +use core::fmt::Write; use cortex_m_rt::entry; use embedded_hal::digital::v2::OutputPin; use hal::{ @@ -184,6 +186,10 @@ fn main() -> ! { _ => {}, } + let mut buf = ArrayString::<[u8; 256]>::new(); + write!(&mut buf, "count: {}", counter.current_count()).expect("can write count"); + protocol.debug(buf.as_str()); + if let Some(diff) = counter.poll() { if !encoder_button.is_pressed() { protocol.report(Report::DialValue { diff }).unwrap();