| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#ifndef __HID_IO_H__ |
| 37 |
#define __HID_IO_H__ |
| 38 |
|
| 39 |
#include "chuck_def.h" |
| 40 |
#include "util_buffers.h" |
| 41 |
#include "util_thread.h" |
| 42 |
|
| 43 |
#include "util_hid.h" |
| 44 |
|
| 45 |
|
| 46 |
struct PhyHidDevIn; |
| 47 |
struct PhyHidDevOut; |
| 48 |
|
| 49 |
|
| 50 |
#define CK_MAX_HID_DEVICES 1024 |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
class HidOut |
| 57 |
{ |
| 58 |
public: |
| 59 |
HidOut(); |
| 60 |
~HidOut(); |
| 61 |
|
| 62 |
public: |
| 63 |
t_CKBOOL open( t_CKUINT device_num = 0 ); |
| 64 |
t_CKBOOL close(); |
| 65 |
t_CKBOOL good() { return m_valid; } |
| 66 |
t_CKINT num() { return m_valid ? (t_CKINT)m_device_num : -1; } |
| 67 |
|
| 68 |
public: |
| 69 |
void set_suppress( t_CKBOOL print_or_not ) |
| 70 |
{ m_suppress_output = print_or_not; } |
| 71 |
t_CKBOOL get_suppress() |
| 72 |
{ return m_suppress_output; } |
| 73 |
|
| 74 |
public: |
| 75 |
t_CKUINT send( const HidMsg * msg ); |
| 76 |
|
| 77 |
public: |
| 78 |
PhyHidDevOut * phout; |
| 79 |
std::vector<unsigned char> m_msg; |
| 80 |
t_CKUINT m_device_num; |
| 81 |
t_CKBOOL m_valid; |
| 82 |
t_CKBOOL m_suppress_output; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
struct HidIn : public Chuck_Event |
| 90 |
{ |
| 91 |
public: |
| 92 |
HidIn(); |
| 93 |
~HidIn(); |
| 94 |
|
| 95 |
public: |
| 96 |
t_CKBOOL open( Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg = FALSE ); |
| 97 |
t_CKBOOL open( Chuck_VM * vm, t_CKINT device_type , std::string & name, t_CKBOOL suppressErrMsg = FALSE ); |
| 98 |
t_CKBOOL close(); |
| 99 |
t_CKBOOL read( t_CKINT type, t_CKINT num, HidMsg * msg ); |
| 100 |
t_CKBOOL send( const HidMsg * msg ); |
| 101 |
t_CKBOOL good() { return m_valid; } |
| 102 |
t_CKINT num() { return m_valid ? (t_CKINT)m_device_num : -1; } |
| 103 |
|
| 104 |
public: |
| 105 |
void set_suppress( t_CKBOOL print_or_not ) |
| 106 |
{ m_suppress_output = print_or_not; } |
| 107 |
t_CKBOOL get_suppress() |
| 108 |
{ return m_suppress_output; } |
| 109 |
|
| 110 |
public: |
| 111 |
t_CKBOOL empty(); |
| 112 |
t_CKUINT recv( HidMsg * msg ); |
| 113 |
std::string name(); |
| 114 |
|
| 115 |
public: |
| 116 |
PhyHidDevIn * phin; |
| 117 |
CBufferAdvance * m_buffer; |
| 118 |
t_CKUINT m_read_index; |
| 119 |
t_CKBOOL m_valid; |
| 120 |
t_CKINT m_device_num; |
| 121 |
Chuck_Object * SELF; |
| 122 |
t_CKBOOL m_suppress_output; |
| 123 |
}; |
| 124 |
|
| 125 |
class HidInManager |
| 126 |
{ |
| 127 |
public: |
| 128 |
static void init(); |
| 129 |
static void init_default_drivers(); |
| 130 |
static void cleanup( t_CKUINT msWait = 0 ); |
| 131 |
static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg = FALSE ); |
| 132 |
static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, std::string & device_name, t_CKBOOL suppressErrMsg = FALSE ); |
| 133 |
static t_CKBOOL close( HidIn * hin ); |
| 134 |
static void cleanup_buffer( Chuck_VM * vm ); |
| 135 |
|
| 136 |
static void probeHidIn(); |
| 137 |
static void probeHidOut(); |
| 138 |
|
| 139 |
#ifndef __PLATFORM_WINDOWS__ |
| 140 |
static void * cb_hid_input( void * ); |
| 141 |
#else |
| 142 |
static unsigned __stdcall cb_hid_input( void * ); |
| 143 |
#endif |
| 144 |
|
| 145 |
static void push_message( HidMsg & msg ); |
| 146 |
|
| 147 |
static std::map< Chuck_VM *, CBufferSimple * > m_event_buffers; |
| 148 |
|
| 149 |
protected: |
| 150 |
static std::vector< std::vector<PhyHidDevIn *> > the_matrix; |
| 151 |
static XThread * the_thread; |
| 152 |
static CBufferSimple * msg_buffer; |
| 153 |
static t_CKBOOL thread_going; |
| 154 |
static t_CKBOOL has_init; |
| 155 |
}; |
| 156 |
|
| 157 |
|
| 158 |
class HidOutManager |
| 159 |
{ |
| 160 |
public: |
| 161 |
static t_CKBOOL open( HidOut * hout, t_CKINT device_num ); |
| 162 |
static t_CKBOOL close( HidOut * hout ); |
| 163 |
|
| 164 |
protected: |
| 165 |
HidOutManager(); |
| 166 |
~HidOutManager(); |
| 167 |
|
| 168 |
static std::vector<PhyHidDevOut *> the_phouts; |
| 169 |
}; |
| 170 |
|
| 171 |
extern Chuck_Hid_Driver * default_drivers; |
| 172 |
|
| 173 |
#endif |