From 01b0088ea70cf535351a606318d573c5840db912 Mon Sep 17 00:00:00 2001 From: Thomas Guillemin Date: Sun, 29 Sep 2024 22:11:33 +0200 Subject: [PATCH] Keyboard refactoring, to have same behaviour for test / main Sugarpi --- SugarPiWin32/KeyboardHardwareImplemetationWin.cpp | 12 ++++++++++-- SugarPiWin32/KeyboardHardwareImplemetationWin.h | 6 +++--- src/KeyboardPi.cpp | 2 +- src/KeyboardPi.h | 7 +++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/SugarPiWin32/KeyboardHardwareImplemetationWin.cpp b/SugarPiWin32/KeyboardHardwareImplemetationWin.cpp index 94f3365..574dd36 100644 --- a/SugarPiWin32/KeyboardHardwareImplemetationWin.cpp +++ b/SugarPiWin32/KeyboardHardwareImplemetationWin.cpp @@ -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]; } @@ -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; diff --git a/SugarPiWin32/KeyboardHardwareImplemetationWin.h b/SugarPiWin32/KeyboardHardwareImplemetationWin.h index 8499454..c6ef4c6 100644 --- a/SugarPiWin32/KeyboardHardwareImplemetationWin.h +++ b/SugarPiWin32/KeyboardHardwareImplemetationWin.h @@ -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_; @@ -31,7 +32,6 @@ class KeyboardHardwareImplemetationWin : public KeyboardHardwareImplemetation std::vector gamepad_list_; GamepadDef* gamepad_active_[MAX_GAMEPADS]; - unsigned int action_buttons_; - bool select_; + //unsigned int action_buttons_; }; diff --git a/src/KeyboardPi.cpp b/src/KeyboardPi.cpp index 2d945e1..0a4af9f 100644 --- a/src/KeyboardPi.cpp +++ b/src/KeyboardPi.cpp @@ -97,7 +97,7 @@ bool GamepadActionHandler::IsPressed(TGamePadState* state) void GamepadActionHandler::UpdateMap(unsigned int nDeviceIndex, bool pressed) { - if (pressed) + if (pressed) { *line_[nDeviceIndex] &= ~(1< gamepad_list_; GamepadDef* gamepad_active_[MAX_GAMEPADS]; - bool select_; struct RawToCPC {