Created
November 10, 2020 09:08
-
-
Save kimsama/0c3e82a9c97732bfb4ae8e1ff2466256 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct packet | |
{ | |
char name[16]; | |
unsigned short id; | |
char state_01; // 0: safety / 1: fire / 2: reload :==> safety / reload는 무시. | |
char state_02; // reserved. | |
unsigned short buttonState; // buttons | |
}; | |
const int ButtonCount = 14; | |
const unsinged short controller::buttonInputID[buttonCount] = | |
{ | |
XCONTROLLER_BUTTON_PTT, // 0x0001 | |
XCONTROLLER_BUTTON_LOCK, // 0x0002 | |
XCONTROLLER_BUTTON_LEFT_A, // 0x0004 | |
XCONTROLLER_BUTTON_LEFT_B, // 0x0008 | |
XCONTROLLER_BUTTON_LEFT_C, // 0x0010 | |
XCONTROLLER_BUTTON_LEFT_D, // 0x0020 | |
XCONTROLLER_BUTTON_RIGHT_W, // 0x0040 | |
XCONTROLLER_BUTTON_RIGHT_X, // 0x0080 | |
XCONTROLLER_BUTTON_RIGHT_Y, // 0x0100 | |
XCONTROLLER_BUTTON_RIGHT_Z, // 0x0200 | |
XCONTROLLER_BUTTON_UNUSED01, // 0x1000 | |
XCONTROLLER_BUTTON_UNUSED02, // 0x2000 | |
XCONTROLLER_BUTTON_UNUSED03, // 0x4000 | |
XCONTROLLER_BUTTON_UNUSED04 // 0x8000 | |
}; | |
void controller::update(float deltaTime) | |
{ | |
... | |
// received packet from the gun controller. | |
struct packet recv_data; | |
unsigned int size = sizeof(packet); | |
memcpy(&recv_data, data, size); | |
switch (recv_data.state_01) | |
{ | |
case '0': // turn on the power button | |
_powerOn = true; | |
_enableNV = (XCONTROLLER_BUTTON_LOCK & recv_data.buttonState) ? true : false; | |
break; | |
case '1': // N/A | |
break; | |
case '2': // N/A | |
break; | |
case '3': // button | |
{ | |
unsigned short buttonStates = recv_data.buttonStaste; | |
for (int i=0; i<buttonCount; ++i) | |
{ | |
// !!check whether the button is pressed or not!! | |
bool pressed = (butonStates & buttonInputID[i]) != 0; | |
setButtonPressed(i, pressed); | |
} | |
} | |
break; | |
} | |
} | |
void controller::setButtonPressed( ButtonID buttonID, bool pressed ) | |
{ | |
if ( buttonID >= ButtonCount ) | |
return; | |
if ( !hasButton(buttonID) ) | |
return; | |
if ( _iButtonPressed[buttonID] == pressed ) | |
return; | |
_isButtonPressed[buttonID] = pressed; | |
// Notify | |
for ( Listeners::iterator itr=mListeners.begin(); itr!=mListeners.end(); ++itr ) | |
(*itr)->onComponentChanged( this, ComponentType_Button, buttonID ); | |
} | |
bool controller::isButtonPressed(ButtonID buttonID) | |
{ | |
return _isButtonPressed[buttonID]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment