summaryrefslogtreecommitdiff
path: root/throttle-quadrant.ino
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2026-06-29 22:00:26 +0200
committerFelix Morgner <felix.morgner@gmail.com>2026-06-29 22:00:26 +0200
commit82620f74d6e40617b725dcb8e50cdd94eb3e3e86 (patch)
treef3c7e118b85cdf711617a1c1b82f61545c6ccd6c /throttle-quadrant.ino
parentd7c2a8029c4aefc295719174a863129645d6ab99 (diff)
downloadthrottle-quadrant-82620f74d6e40617b725dcb8e50cdd94eb3e3e86.tar.xz
throttle-quadrant-82620f74d6e40617b725dcb8e50cdd94eb3e3e86.zip
tq: rewrite for shift register semanticsHEADmaster
Diffstat (limited to 'throttle-quadrant.ino')
-rw-r--r--throttle-quadrant.ino42
1 files changed, 17 insertions, 25 deletions
diff --git a/throttle-quadrant.ino b/throttle-quadrant.ino
index 7c213a1..54740d9 100644
--- a/throttle-quadrant.ino
+++ b/throttle-quadrant.ino
@@ -1,32 +1,24 @@
-#include "protocol.hpp"
+#include "ThrottleQuadrant.hpp"
-//! Set up any global state.
-//!
-//! This function is executed once during the start of the firmware.
-auto setup() -> void {
- // Initialize the protocol subsystem.
- tq::protocol::init();
+namespace {
- // Initialize the serial output stream.
- Serial.begin(9600);
-}
+//! The time point (in milliseconds since boot) when we last read out the data of the throttle quadrant.
+auto lastReadTimePoint = 0ul;
-//! Perform one iteration through the firmare logic.
-//!
-//! This function is called in an endless loop after the firmware has started.
-auto loop() -> void {
- // Always try to start a new transfer.
- tq::protocol::start();
+}
- // Receive a new message if one is available.
- auto maybe_message = tq::protocol::perform_transfer();
+void setup() {
+ Serial.begin(115200);
+ ThrottleQuadrant.begin(2, 3, 4);
+}
- if (maybe_message.has_value()) {
- // Extract the received message.
- auto const& message = maybe_message.value();
+void loop() {
+ auto currentTimePoint = millis();
- Serial.write("new message: ");
- Serial.write("throttle == ");
- Serial.print(static_cast<int>(message.throttle));
+ // Read out the throttle quadrant if the minimum amount of wait time has passed.
+ if ((currentTimePoint - lastReadTimePoint) >= ThrottleQuadrant.readDelayMillis) {
+ auto data = ThrottleQuadrant.read();
+ lastReadTimePoint = millis();
+ Serial.write(reinterpret_cast<byte const *>(&data), sizeof(data));
}
-} \ No newline at end of file
+}