diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-06-20 22:23:48 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-06-20 22:44:43 +0200 |
| commit | d7c2a8029c4aefc295719174a863129645d6ab99 (patch) | |
| tree | d2f36ab8721dd32235dc63a60218378eb35922c8 /protocol.hpp | |
| download | throttle-quadrant-master.tar.xz throttle-quadrant-master.zip | |
Diffstat (limited to 'protocol.hpp')
| -rw-r--r-- | protocol.hpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/protocol.hpp b/protocol.hpp new file mode 100644 index 0000000..c71b7d3 --- /dev/null +++ b/protocol.hpp @@ -0,0 +1,88 @@ +#ifndef THROTTLE_QUADRANT_PROTOCOL_HPP +#define THROTTLE_QUADRANT_PROTOCOL_HPP + +#include "utilities.hpp" + +#include <Arduino.h> + +//! All our custom code lives in its own name space to avoid collisions. +namespace tq::protocol { + +//! A message as received from the throttle quadrant. +struct [[gnu::packed]] message { + //! The current throttle value (unit TBD). + byte throttle; + //! The current propeller speed value (unit TBD). + byte propeller_speed; + //! The current mixture value (unit TBD). + byte mixture; + + //! The state (pressed/released) of the first trigger. + byte trigger_1 : 1; + //! The state (pressed/released) of the second trigger. + byte trigger_2 : 1; + //! The state (pressed/released) of the third trigger. + byte trigger_3 : 1; + //! The state (pressed/released) of the fourth trigger. + byte trigger_4 : 1; + //! The state (pressed/released) of the fifth trigger. + byte trigger_5 : 1; + //! The state (pressed/released) of the sixth trigger. + byte trigger_6 : 1; + + //! Whether the throttle is idle or not. + byte throttle_idle : 1; + + //! Whether the throttle is feathered or not (?). + byte propeller_feather : 1; + + //! Whether the mixture is cut off or not. + byte mixture_cutoff : 1; + + //! Reserved bits. + byte : 7; +}; + +//! Initialize the protocol handling subsystem. +auto init() -> void; + +//! Start a run of the protocol handling subsystem. +//! +//! A new run is only started if there is not current run ongoing. +//! +//! @return true iff. a new run was started, false otherwise. +auto start() -> bool; + +//! Perform the synchronous SPI transfer, if one is pending. +//! +//! Perform the final synchronous transfer from the throttle quadrant. If no +//! new data is available, an empty optional is returned. +//! +//! @return An optional object containing a new message if one is available. +auto perform_transfer() -> optional<message>; + +//! @internal +//! Process the "data ready" signal coming from the throttle quadrant. +//! +//! When the throttle quadrant pulls the "data ready" line low, we know that +//! there is new data available to be read out. We must adhere to a somewhat +//! strict timing protocol, as detailed in the implemenation of this function. +auto on_data_ready() -> void; + +//! @internal +//! Process the "start delay" signal coming from the throttle quadrant. +//! +//! After notifying us about the data being ready, the "data ready" line will +//! be deasserted. However, we must wait an additional 1.2ms before we start +//! the transfer. +auto on_start_delay() -> void; + +//! @internal +//! Process the end of the start delay. +//! +//! The data is of the throttle quadrant is now ready to be read. +auto on_start_delay_passed() -> void; + +} + +#endif
\ No newline at end of file |
