summaryrefslogtreecommitdiff
path: root/ThrottleQuadrant.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'ThrottleQuadrant.hpp')
-rw-r--r--ThrottleQuadrant.hpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/ThrottleQuadrant.hpp b/ThrottleQuadrant.hpp
new file mode 100644
index 0000000..8776aab
--- /dev/null
+++ b/ThrottleQuadrant.hpp
@@ -0,0 +1,49 @@
+#ifndef SAITEK_THROTTLE_QUADRANT_HPP
+#define SAITEK_THROTTLE_QUADRANT_HPP
+
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+
+struct SaitekThrottleQuadrant {
+
+ //! The data read from the throttle quadrant.
+ struct [[gnu::packed]] Data {
+ uint8_t left;
+ uint8_t right;
+ uint8_t middle;
+ uint16_t buttons : 9;
+ uint16_t : 0;
+ };
+
+ //! The minimum delay between successive read operations.
+ auto constexpr static readDelayMillis = 25u;
+
+ //! Initialize the throttle quadrant interface.
+ auto begin(unsigned clock_pin, unsigned latch_pin, unsigned data_pin) noexcept -> void;
+
+ //! Read the current state of the throttle quadrant.
+ auto read() noexcept -> Data;
+
+private:
+ //! The time for the clock to propagate.
+ auto constexpr static clockDelayMicros = 25u;
+
+ //! The time for the latch to settle.
+ auto constexpr static latchDelayMicros = 5u;
+
+ //! The number of buttons on the throttle quadrant.
+ auto constexpr static numberOfButtons = 9u;
+
+ auto beginTransaction() -> void;
+ auto endTransaction() -> void;
+
+ template<typename T, size_t Bits = sizeof(T) * CHAR_BIT>
+ auto doRead() -> T;
+
+ unsigned clock_pin{};
+ unsigned latch_pin{};
+ unsigned data_pin{};
+} static ThrottleQuadrant;
+
+#endif \ No newline at end of file