diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-06-29 22:00:26 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-06-29 22:00:26 +0200 |
| commit | 82620f74d6e40617b725dcb8e50cdd94eb3e3e86 (patch) | |
| tree | f3c7e118b85cdf711617a1c1b82f61545c6ccd6c /ThrottleQuadrant.hpp | |
| parent | d7c2a8029c4aefc295719174a863129645d6ab99 (diff) | |
| download | throttle-quadrant-master.tar.xz throttle-quadrant-master.zip | |
Diffstat (limited to 'ThrottleQuadrant.hpp')
| -rw-r--r-- | ThrottleQuadrant.hpp | 49 |
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 |
