2020-02-12 18:43:25 +00:00
|
|
|
#ifndef fader_h
|
|
|
|
#define fader_h
|
|
|
|
|
|
|
|
|
2020-02-13 16:29:52 +00:00
|
|
|
/*
|
|
|
|
1. wait for 0x0a packet
|
|
|
|
send_response_0()
|
|
|
|
wait 50 ms
|
|
|
|
send_heart_beat()
|
|
|
|
2. wait for next host packet
|
|
|
|
send_response_1()
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-02-12 18:43:25 +00:00
|
|
|
class fader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
kOkRC,
|
|
|
|
kTimeOutRC,
|
|
|
|
kUnknownMsgRC
|
|
|
|
} rc_t;
|
|
|
|
|
|
|
|
// Function to send TCP messages to the host.
|
|
|
|
typedef void (*hostCallback_t)( void* arg, const void* buf, unsigned bufByteN );
|
|
|
|
|
2020-02-13 16:29:52 +00:00
|
|
|
fader( printCallback_t printCbFunc, const unsigned char faderMac[6], uint32_t faderInetAddr, hostCallback_t hostCbFunc, void* cbArg, unsigned ticksPerHeartBeat, unsigned chN = 8 );
|
2020-02-12 18:43:25 +00:00
|
|
|
virtual ~fader();
|
|
|
|
|
|
|
|
// Called by the TCP receive function to update the faders state
|
|
|
|
// based on host state changes.
|
|
|
|
// Return kUnknownMsgRC if the received msg is not recognized.
|
2020-02-13 16:29:52 +00:00
|
|
|
rc_t receive( const void* buf, unsigned bufByteN );
|
2020-02-16 23:23:34 +00:00
|
|
|
rc_t receive_old( const void* buf, unsigned bufByteN );
|
2020-02-12 18:43:25 +00:00
|
|
|
|
|
|
|
// Called by the application to drive time dependent functions.
|
|
|
|
// Return kTimeOut if the protocol state machine has timed out.
|
|
|
|
rc_t tick();
|
|
|
|
|
|
|
|
// Call these function to generate messages to the host when
|
|
|
|
// the controls physical state changes.
|
|
|
|
rc_t physical_fader_touched( uint16_t chIdx );
|
|
|
|
rc_t physical_fader_moved( uint16_t chIdx, uint16_t newPosition );
|
2020-02-16 23:23:34 +00:00
|
|
|
rc_t physical_mute_switched( uint16_t chIdx, uint16_t newMuteFl );
|
|
|
|
|
|
|
|
rc_t virtual_fader_moved( uint16_t chIdx, uint16_t newPosition );
|
|
|
|
rc_t virtual_mute_switched( uint16_t chIdx, uint16_t newMuteFl );
|
2020-02-12 18:43:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
kWaitForHandshake_0_Id,
|
|
|
|
kWaitForHandshake_Tick_Id,
|
|
|
|
kWaitForHandshake_1_Id,
|
|
|
|
kWaitForHeartBeat_Id
|
|
|
|
} protoState_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2020-02-16 23:23:34 +00:00
|
|
|
int16_t position;
|
2020-02-12 18:43:25 +00:00
|
|
|
bool muteFl;
|
2020-02-16 23:23:34 +00:00
|
|
|
bool incrFl;
|
|
|
|
bool touchFl;
|
|
|
|
|
2020-02-12 18:43:25 +00:00
|
|
|
} ch_t;
|
|
|
|
|
2020-02-16 23:23:34 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint16_t id; // message prefix - identifies the type of message
|
|
|
|
uint16_t byteN; // length of the message in bytes
|
|
|
|
} msgRef_t;
|
|
|
|
|
|
|
|
static msgRef_t _msgRefA[];
|
|
|
|
|
|
|
|
|
2020-02-13 16:29:52 +00:00
|
|
|
printCallback_t _printCbFunc;
|
2020-02-12 18:43:25 +00:00
|
|
|
uint32_t _inetAddr;
|
2020-02-13 16:29:52 +00:00
|
|
|
unsigned _tickN;
|
2020-02-12 18:43:25 +00:00
|
|
|
ch_t* _chArray;
|
|
|
|
unsigned _chN;
|
|
|
|
hostCallback_t _hostCbFunc;
|
|
|
|
void* _hostCbArg;
|
|
|
|
protoState_t _protoState;
|
|
|
|
unsigned char _mac[6];
|
2020-02-13 16:29:52 +00:00
|
|
|
unsigned _ticksPerHeartBeat;
|
2020-02-12 18:43:25 +00:00
|
|
|
|
2020-02-16 23:23:34 +00:00
|
|
|
uint8_t _msgTypeId; //
|
|
|
|
unsigned _msgByteIdx; // current index into the message being parsed.
|
|
|
|
unsigned _msgByteN; // count of bytes in the message currently being parsed
|
|
|
|
unsigned char _msg[8]; //
|
|
|
|
|
2020-02-12 18:43:25 +00:00
|
|
|
void _send_response_0();
|
2020-02-13 16:29:52 +00:00
|
|
|
void _send_response_1();
|
2020-02-12 18:43:25 +00:00
|
|
|
void _send_heartbeat();
|
|
|
|
void _send( const void* buf, unsigned bufByteN );
|
|
|
|
void _on_fader_receive( uint16_t chanIdx, uint16_t position );
|
|
|
|
void _on_mute_receive( uint16_t chanIdx, bool muteFl );
|
2020-02-16 23:23:34 +00:00
|
|
|
void _send_fader( uint16_t chIdx );
|
|
|
|
void _send_touch( uint16_t chIdx, bool touchFl );
|
|
|
|
void _send_mute( uint16_t chIdx, bool muteFl );
|
|
|
|
void _auto_incr_fader( uint16_t chIdx );
|
2020-02-12 18:43:25 +00:00
|
|
|
|
2020-02-16 23:23:34 +00:00
|
|
|
|
|
|
|
uint8_t _get_msg_byte_count( uint8_t msgTypeId );
|
|
|
|
void _handleChMsg(const uint8_t* msg);
|
|
|
|
void _on_msg_complete( const uint8_t typeId );
|
|
|
|
|
2020-02-12 18:43:25 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|