Skip to content

Commit

Permalink
Keyboard refactoring, to have same behaviour for test / main Sugarpi
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom1975 committed Sep 29, 2024
1 parent ae16161 commit 01b0088
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
12 changes: 10 additions & 2 deletions SugarPiWin32/KeyboardHardwareImplemetationWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

KeyboardHardwareImplemetationWin::KeyboardHardwareImplemetationWin(KeyboardPi* keyboard) : keyboard_(keyboard)
{
for (unsigned i = 0; i < MAX_GAMEPADS; i++)
{
gamepad_active_[i] = nullptr;
}

GamepadDef* def = new GamepadDef(keyboard_lines_);
gamepad_list_.push_back(def);
gamepad_active_[0] = gamepad_list_[0];

}

Expand All @@ -23,13 +31,13 @@ void KeyboardHardwareImplemetationWin::UpdatePlugnPlay()

}

#define action(y) action_buttons_ = activated ? (action_buttons_ |y):(action_buttons_&=~y)
#define action(y) keyboard_->action_buttons_ = activated ? (keyboard_->action_buttons_ |y):(keyboard_->action_buttons_&=~y)
void KeyboardHardwareImplemetationWin::CodeAction(long keycode, bool activated)
{
// todo : hardcoded values
switch (keycode)
{
case VK_TAB: select_ = activated; action(GamePadButtonSelect); break;
case VK_TAB: keyboard_->select_ = activated; action(GamePadButtonSelect); break;
case VK_SCROLL: gamepad_active_[0]->game_pad_button_start.UpdateMap(0, activated); action(GamePadButtonStart); break;
case VK_UP: gamepad_active_[0]->game_pad_button_up.UpdateMap(0, activated); action(GamePadButtonUp); break;
case VK_DOWN: gamepad_active_[0]->game_pad_button_down.UpdateMap(0, activated); action(GamePadButtonDown); break;
Expand Down
6 changes: 3 additions & 3 deletions SugarPiWin32/KeyboardHardwareImplemetationWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class KeyboardHardwareImplemetationWin : public KeyboardHardwareImplemetation
void Presskey(long keyCode);
void Unpresskey(long keyCode);

protected:
//bool select_;
protected:
void CodeAction(long keycode, bool activated);

KeyboardPi* keyboard_;
Expand All @@ -31,7 +32,6 @@ class KeyboardHardwareImplemetationWin : public KeyboardHardwareImplemetation
std::vector<GamepadDef*> gamepad_list_;
GamepadDef* gamepad_active_[MAX_GAMEPADS];

unsigned int action_buttons_;
bool select_;
//unsigned int action_buttons_;

};
2 changes: 1 addition & 1 deletion src/KeyboardPi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool GamepadActionHandler::IsPressed(TGamePadState* state)

void GamepadActionHandler::UpdateMap(unsigned int nDeviceIndex, bool pressed)
{
if (pressed)
if (pressed)
{
*line_[nDeviceIndex] &= ~(1<<index_[nDeviceIndex]);
}
Expand Down
7 changes: 5 additions & 2 deletions src/KeyboardPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ class KeyboardPi : public IKeyboardHandler

void LoadGameControllerDB();

unsigned int action_buttons_;
bool select_;

//static void GamePadRemovedHandler (CDevice *pDevice, void *pContext);
static void KeyStatusHandlerRaw (unsigned char ucModifiers, const unsigned char RawKeys[6]);
//static void KeyboardRemovedHandler (CDevice *pDevice, void *pContext);


protected:

KeyboardHardwareImplemetation* hard_imlementation_;
Expand All @@ -60,7 +65,6 @@ class KeyboardPi : public IKeyboardHandler
TGamePadState gamepad_state_[MAX_GAMEPADS];
TGamePadState gamepad_state_buffered_[MAX_GAMEPADS];

unsigned action_buttons_;

// Keyboard definition
unsigned char keyboard_lines_ [10];
Expand All @@ -69,7 +73,6 @@ class KeyboardPi : public IKeyboardHandler

std::vector<GamepadDef*> gamepad_list_;
GamepadDef* gamepad_active_[MAX_GAMEPADS];
bool select_;

struct RawToCPC
{
Expand Down

0 comments on commit 01b0088

Please sign in to comment.