First Release
Embed:
(wiki syntax)
Show/hide line numbers
Out_PS3USB.cpp
00001 #include "NiseKabuto.h" 00002 00003 // 00004 // Constructor 00005 // 00006 Out_PS3USB::Out_PS3USB(InputStatus *inputStatus) 00007 { 00008 // wait(1); 00009 _InputStatus = inputStatus; 00010 _MyJS = new USBJoystick(); 00011 Initialize(); 00012 } 00013 00014 // 00015 // Initialize 00016 // 00017 void Out_PS3USB::Initialize() 00018 { 00019 00020 // Pin Setting 00021 00022 // Class Variable Setting 00023 00024 // Interrupt Setting 00025 _USBUpdateTicker.attach_us(this, &Out_PS3USB::USBUpdate, USBUPDATEINTERVAL__MSEC*1000); 00026 } 00027 00028 00029 // 00030 // USB Joystick Update Method 00031 // 00032 void Out_PS3USB::USBUpdate() 00033 { 00034 int16_t x; 00035 int16_t y; 00036 int16_t z; 00037 int16_t rz; 00038 uint32_t buttons; 00039 uint8_t button_hat; 00040 00041 int in_Buttons; 00042 00043 in_Buttons = _InputStatus->Buttons; 00044 00045 // Dボタンが押されている/押されていないで送る情報を変える 00046 00047 if( (in_Buttons & 0x0010) ) 00048 { 00049 // Dボタン押されてない 00050 00051 x = (int)(0x80 + _InputStatus->Ch1)& 0xff; // x 00052 y = (int)(0x80 + _InputStatus->Ch0)& 0xff; // y 00053 z = (int)(0x80 + 0x80) & 0xff; // z 00054 rz = (int)(0x80 + _InputStatus->Ch2)& 0xff; // rz 00055 00056 buttons = 00057 ((in_Buttons & 0x0020)? 0: 0x0001) | // button □ 00058 ((in_Buttons & 0x0100)? 0: 0x0002) | // × 00059 ((in_Buttons & 0x0200)? 0: 0x0004) | // ○ 00060 0 | // △ 00061 ((in_Buttons & 0x0008)? 0: 0x0010) | // L1 00062 ((in_Buttons & 0x0004)? 0: 0x0020) | // R1 00063 0 | // L2 00064 0 | // R2 00065 ((in_Buttons & 0x0001)? 0: 0x0100) | // SELECT 00066 ((in_Buttons & 0x0002)? 0: 0x0200) | // START 00067 0 | // L3 00068 0 | // R3 00069 0 ; // PS button 00070 00071 button_hat = 0; 00072 00073 } 00074 else 00075 { 00076 // Dボタン押されてる 00077 00078 x = (int)(0x80 + 0x80)& 0xff; // x 00079 y = (int)(0x80 + 0x80)& 0xff; // y 00080 z = (int)(0x80 + _InputStatus->Ch2) & 0xff; // z 00081 rz = (int)(0x80 + 0x80)& 0xff; // rz 00082 00083 buttons = 00084 0 | // button □ 00085 0 | // × 00086 0 | // ○ 00087 ((in_Buttons & 0x0100)? 0: 0x0008) | // △ 00088 0 | // L1 00089 0 | // R1 00090 ((in_Buttons & 0x0008)? 0: 0x0040) | // L2 00091 ((in_Buttons & 0x0004)? 0: 0x0080) | // R2 00092 0 | // SELECT 00093 0 | // START 00094 ((in_Buttons & 0x0200)? 0: 0x0400) | // L3 00095 ((in_Buttons & 0x0020)? 0: 0x0800) | // R3 00096 ((in_Buttons & 0x0002)? 0: 0x1000) ; // PS button 00097 00098 button_hat = 00099 (( (_InputStatus->Ch0<0x20) )? 0x01: 0) | // hat up 00100 (( (_InputStatus->Ch0>0xe0) )? 0x02: 0) | // down 00101 (( (_InputStatus->Ch1<0x10) )? 0x04: 0) | // left 00102 (( (_InputStatus->Ch1>0xe0) )? 0x08: 0) ; // right 00103 } 00104 00105 _MyJS->update(x, y, z, rz, buttons, button_hat); 00106 00107 /* 00108 _MyJS->update( //int16_t x, int16_t y, int16_t z, int16_t rz, uint32_t buttons, uint8_t button_hat 00109 (int)(0x80 + _InputStatus->Ch1)& 0xff, // x 00110 (int)(0x80 + _InputStatus->Ch0)& 0xff, // y 00111 (int)(0x80 + 0x80) & 0xff, // z 00112 (int)(0x80 + _InputStatus->Ch2)& 0xff, // rz 00113 00114 ((_InputStatus->Buttons & 0x0020)? 0: 0x0001) | // button □ 00115 ((_InputStatus->Buttons & 0x0100)? 0: 0x0002) | // × 00116 ((_InputStatus->Buttons & 0x0200)? 0: 0x0004) | // ○ 00117 ((!(_InputStatus->Buttons & 0x0010) && !(_InputStatus->Buttons & 0x0100))? 0x0008: 0) | // △ 00118 ((_InputStatus->Buttons & 0x0008)? 0: 0x0010) | // L1 00119 ((_InputStatus->Buttons & 0x0004)? 0: 0x0020) | // R2 00120 ((!(_InputStatus->Buttons & 0x0010) && !(_InputStatus->Buttons & 0x0008))? 0x0040: 0) | // L2 00121 ((!(_InputStatus->Buttons & 0x0010) && !(_InputStatus->Buttons & 0x0004))? 0x0080: 0) | // R2 00122 ((_InputStatus->Buttons & 0x0001)? 0: 0x0100) | // SELECT 00123 ((_InputStatus->Buttons & 0x0002)? 0: 0x0200) | // START 00124 ((!(_InputStatus->Buttons & 0x0010) && (_InputStatus->Ch2<0x20))? 0x0400: 0) | // L3? 00125 ((!(_InputStatus->Buttons & 0x0010) && (_InputStatus->Ch2>0xe0))? 0x0800: 0) | // R3? 00126 ((!(_InputStatus->Buttons & 0x0010) && !(_InputStatus->Buttons & 0x0002))? 0x1000: 0), // PS button 00127 00128 ((!(_InputStatus->Buttons & 0x0010) && (_InputStatus->Ch0<0x20))? 0x01: 0) | // hat up 00129 ((!(_InputStatus->Buttons & 0x0010) && (_InputStatus->Ch0>0xe0))? 0x02: 0) | // down 00130 ((!(_InputStatus->Buttons & 0x0010) && (_InputStatus->Ch1<0x10))? 0x04: 0) | // left 00131 ((!(_InputStatus->Buttons & 0x0010) && (_InputStatus->Ch1>0xe0))? 0x08: 0) // right 00132 ); 00133 */ 00134 } 00135 00136 00137 00138 00139 00140 void Out_PS3USB::SetupInputControll(void (*startInputFunction)(void), void (*stopInputFunction)(void)) 00141 { 00142 StartInputFunction = startInputFunction; 00143 StopInputFunction = stopInputFunction; 00144 } 00145 00146 void Out_PS3USB::EnableInput(void) 00147 { 00148 if(_InputInstance && StartInputMethod) 00149 { 00150 (_InputInstance->*StartInputMethod)(); 00151 } 00152 else if(StartInputFunction) 00153 { 00154 StartInputFunction(); 00155 } 00156 } 00157 00158 void Out_PS3USB::DisableInput(void) 00159 { 00160 if(_InputInstance && StopInputMethod) 00161 { 00162 (_InputInstance->*StopInputMethod)(); 00163 } 00164 else if(StopInputFunction) 00165 { 00166 StopInputFunction(); 00167 } 00168 } 00169 00170
Generated on Thu Jul 14 2022 14:49:55 by 1.7.2