6 * @brief Abstract class that is extended to provide an interface to a handset.
8 * There are three implementations of the Handset class
10 * - CRSFHandset - implements the CRSF protocol for communicating with the handset
11 * - PPMHandset - PPM protocol, can be connected to the DSC/trainer port for simple non-CRSF handsets
12 * - AutoDetect - this implementation uses an RMT channel to auto-detect a PPM or CRSF handset and swap the
13 * global `handset` variable to point to instance of the actual implementation. This allows a TX module
14 * to be moved between a CRSF capable handset and PPM only handset e.g. an EdgeTX radio and a surface radio.
20 * @brief Start the handset protocol
22 virtual void Begin() = 0;
25 * @brief End the handset protocol
27 virtual void End() = 0;
30 * @brief register a function to be called when the protocol has read an RC data packet from the handset
33 void setRCDataCallback(void (*callback
)()) { RCdataCallback
= callback
; }
35 * @brief register a function to be called when a request to update a parameter is send from the handset
38 void registerParameterUpdateCallback(void (*callback
)(uint8_t type
, uint8_t index
, uint8_t arg
)) { RecvParameterUpdate
= callback
; }
40 * Register callback functions for state information about the connection or handset
41 * @param connectedCallback called when the protocol detects a stable connection to the handset
42 * @param disconnectedCallback called when the protocol loses its connection to the handset
43 * @param RecvModelUpdateCallback called when the handset sends a message to set the current model number
45 void registerCallbacks(void (*connectedCallback
)(), void (*disconnectedCallback
)(), void (*RecvModelUpdateCallback
)(), void (*bindingCommandCallback
)())
47 connected
= connectedCallback
;
48 disconnected
= disconnectedCallback
;
49 RecvModelUpdate
= RecvModelUpdateCallback
;
50 OnBindingCommand
= bindingCommandCallback
;
54 * @brief Process any pending input data from the handset
56 virtual void handleInput() = 0;
59 * @return true if the protocol detects that the arming state is active
61 virtual bool IsArmed() = 0;
64 * Called to set the expected packet interval from the handset.
65 * This can be used to synchronise the packets from the handset.
66 * @param PacketInterval in microseconds
68 virtual void setPacketInterval(int32_t PacketInterval
) { RequestedRCpacketInterval
= PacketInterval
; }
71 * @return the maximum number of bytes that the protocol can send to the handset in a single message
73 virtual uint8_t GetMaxPacketBytes() const { return 255; }
76 * Depending on the baud-rate selected and the module type (full/half duplex) will determine the minimum
77 * supported packet interval.
78 * @return the minimum interval between packets supported by the current configuration.
80 virtual int getMinPacketInterval() const { return 1; }
83 * @brief Called to indicate to the protocol that a packet has just been sent over-the-air
84 * This is used to synchronise the packets from the handset to the OTA protocol to minimise latency
86 virtual void JustSentRFpacket() {}
88 * Send a telemetry packet back to the handset
91 virtual void sendTelemetryToTX(uint8_t *data
) {}
94 * @return the time in microseconds when the last RC packet was received from the handset
96 uint32_t GetRCdataLastRecv() const { return RCdataLastRecv
; }
98 #if defined(DEBUG_TX_FREERUN)
100 * @brief Can be used to force a connected callback for debugging
102 void forceConnection() { if (connected
) connected(); }
106 virtual ~Handset() = default;
108 bool controllerConnected
= false;
109 void (*RCdataCallback
)() = nullptr; // called when there is new RC data
110 void (*disconnected
)() = nullptr; // called when RC packet stream is lost
111 void (*connected
)() = nullptr; // called when RC packet stream is regained
112 void (*RecvModelUpdate
)() = nullptr; // called when model id changes, ie command from Radio
113 void (*RecvParameterUpdate
)(uint8_t type
, uint8_t index
, uint8_t arg
) = nullptr; // called when recv parameter update req, ie from LUA
114 void (*OnBindingCommand
)() = nullptr; // Called when a binding command is received
116 volatile uint32_t RCdataLastRecv
= 0;
117 int32_t RequestedRCpacketInterval
= 5000; // default to 200hz as per 'normal'
121 extern Handset
*handset
;