Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas GUILLEMIN committed Oct 16, 2024
1 parent 87db655 commit 1439672
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
30 changes: 18 additions & 12 deletions src/KeyboardHardwareImplemetationPi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ KeyboardHardwareImplemetationPi::keyboardPi_ = nullptr;

KeyboardHardwareImplemetationPi::KeyboardHardwareImplemetationPi(KeyboardPi* keyboard, CUSBHCIDevice* dwhci_device, CDeviceNameService* device_name_service):
device_name_service_(device_name_service),
dwhci_device_(dwhci_device),
keyboardPi_(keyboard)
dwhci_device_(dwhci_device)
{
keyboardPi_ = keyboard;
select_ = keyboardPi_->GetSelect();
action_buttons_ = keyboardPi_->GetActionButtons();
gamepad_active_ = keyboardPi_->GetGamepadActive();
keyboard_lines_ = keyboardPi_->GetKeyboardLine();
gamepad_state_ = keyboardPi_->GetGamepadState();

for (unsigned i = 0; i < MAX_GAMEPADS; i++)
{
gamepad_[i] = 0;
Expand All @@ -31,9 +37,9 @@ void KeyboardHardwareImplemetationPi::Initialize()
{
if (dwhci_device_->Initialize() == false)
{
logger_->Write("Keyboard", LogPanic, "Initialize failed !");
CLogger::Get ()->Write("Keyboard", LogPanic, "Initialize failed !");
}
logger_->Write("Keyboard", LogNotice, "Initialize done.");
CLogger::Get ()->Write("Keyboard", LogNotice, "Initialize done.");

}

Expand Down Expand Up @@ -61,21 +67,21 @@ void KeyboardHardwareImplemetationPi::UpdatePlugnPlay()
CString* gamepad_name = gamepad_[nDevice - 1]->GetDevice()->GetNames();
const TUSBDeviceDescriptor* descriptor = gamepad_[nDevice - 1]->GetDevice()->GetDeviceDescriptor();

logger_->Write("Keyboard", LogNotice, "Gamepad : %s - VID=%X; PID=%X; bcdDevice = %X", (const char*)(*gamepad_name), descriptor->idVendor,
CLogger::Get ()->Write("Keyboard", LogNotice, "Gamepad : %s - VID=%X; PID=%X; bcdDevice = %X", (const char*)(*gamepad_name), descriptor->idVendor,
descriptor->idProduct, descriptor->bcdDevice);
delete gamepad_name;
const TGamePadState* pState = gamepad_[nDevice - 1]->GetInitialState();
assert(pState != 0);

memcpy(&gamepad_state_[nDevice - 1], pState, sizeof(TGamePadState));
logger_->Write("Keyboard", LogNotice, "Gamepad %u: %d Button(s) %d Hat(s)",
CLogger::Get ()->Write("Keyboard", LogNotice, "Gamepad %u: %d Button(s) %d Hat(s)",
nDevice, pState->nbuttons, pState->nhats);

gamepad_[nDevice - 1]->RegisterRemovedHandler(GamePadRemovedHandler, this);
gamepad_[nDevice - 1]->RegisterStatusHandler(GamePadStatusHandler);
gamepad_[nDevice - 1]->RegisterRemovedHandler(KeyboardHardwareImplemetationPi::GamePadRemovedHandler, this);
gamepad_[nDevice - 1]->RegisterStatusHandler(KeyboardHardwareImplemetationPi::GamePadStatusHandler);
gamepad_active_[nDevice - 1] = LookForDevice(descriptor);

logger_->Write("Keyboard", LogNotice, "Use your gamepad controls!");
CLogger::Get ()->Write("Keyboard", LogNotice, "Use your gamepad controls!");
}

// Keyboard
Expand All @@ -87,7 +93,7 @@ void KeyboardHardwareImplemetationPi::UpdatePlugnPlay()
keyboard_->RegisterRemovedHandler(KeyboardRemovedHandler);
keyboard_->RegisterKeyStatusHandlerRaw(KeyStatusHandlerRaw);

logger_->Write("Keyboard", LogNotice, "Just type something!");
CLogger::Get ()->Write("Keyboard", LogNotice, "Just type something!");
}
}
}
Expand Down Expand Up @@ -204,11 +210,11 @@ GamepadDef* KeyboardHardwareImplemetationPi::LookForDevice(const TUSBDeviceDescr
{
if (gamepad_list_[index]->vid == descriptor->idVendor && gamepad_list_[index]->pid == descriptor->idProduct && gamepad_list_[index]->version == descriptor->bcdDevice)
{
logger_->Write("KeyboardPi", LogNotice, "Gamepad found in database !");
CLogger::Get ()->Write("KeyboardPi", LogNotice, "Gamepad found in database !");
return gamepad_list_[index];
}
}

logger_->Write("KeyboardPi", LogNotice, "Unknown gamepad...");
CLogger::Get ()->Write("KeyboardPi", LogNotice, "Unknown gamepad...");
return gamepad;
}
8 changes: 7 additions & 1 deletion src/KeyboardHardwareImplemetationPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class KeyboardHardwareImplemetationPi : public KeyboardHardwareImplemetation

protected:

bool* select_;
unsigned int* action_buttons_;
unsigned char* keyboard_lines_;
GamepadDef** gamepad_active_;
TGamePadState** gamepad_state_;

static void KeyStatusHandlerRaw(unsigned char ucModifiers, const unsigned char RawKeys[6]);
GamepadDef* LookForDevice (const TUSBDeviceDescriptor* descriptor);

Expand All @@ -33,5 +39,5 @@ class KeyboardHardwareImplemetationPi : public KeyboardHardwareImplemetation
static CUSBKeyboardDevice* keyboard_;

CSpinLock mutex_;
KeyboardPi* keyboardPi_;
static KeyboardPi* keyboardPi_;
};
4 changes: 2 additions & 2 deletions src/KeyboardPi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifdef __circle__
#include <circle/spinlock.h>
static CSpinLock mutex_;
static void Lock() { Lock(); }
static void Unlock() { Unlock(); }
static void Lock() { mutex_.Acquire(); }
static void Unlock() { mutex_.Release(); }
#else
#include <mutex>
static std::mutex mutex_;
Expand Down

0 comments on commit 1439672

Please sign in to comment.