libcw/dns_sd/fader.h

85 lines
2.1 KiB
C
Raw Normal View History

2020-02-12 18:43:25 +00:00
#ifndef fader_h
#define fader_h
/*
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 );
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.
rc_t receive( 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 );
rc_t physical_mute_switched( uint16_t chIdx, bool newMuteFl );
private:
typedef enum
{
kWaitForHandshake_0_Id,
kWaitForHandshake_Tick_Id,
kWaitForHandshake_1_Id,
kWaitForHeartBeat_Id
} protoState_t;
typedef struct
{
uint16_t position;
bool muteFl;
} ch_t;
printCallback_t _printCbFunc;
2020-02-12 18:43:25 +00:00
uint32_t _inetAddr;
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];
unsigned _ticksPerHeartBeat;
2020-02-12 18:43:25 +00:00
void _send_response_0();
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 );
};
#endif