Skip to content

Commit

Permalink
Keyboard fix. Still WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas GUILLEMIN committed Oct 4, 2024
1 parent 01b0088 commit fb50f6b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
34 changes: 24 additions & 10 deletions SugarPiWin32/KeyboardHardwareImplemetationWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

KeyboardHardwareImplemetationWin::KeyboardHardwareImplemetationWin(KeyboardPi* keyboard) : keyboard_(keyboard)
{
select_ = keyboard_->GetSelect();
action_buttons_ = keyboard_->GetActionButtons();
gamepad_active_ = keyboard_->GetGamepadActive();
keyboard_lines_ = keyboard_->GetKeyboardLine();
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];
//gamepad_list_.push_back(def);
gamepad_active_[0] = def;// gamepad_list_[0];

}

Expand All @@ -31,20 +35,30 @@ void KeyboardHardwareImplemetationWin::UpdatePlugnPlay()

}

#define action(y) keyboard_->action_buttons_ = activated ? (keyboard_->action_buttons_ |y):(keyboard_->action_buttons_&=~y)
#define action(y) *action_buttons_ = activated ? (*action_buttons_ |y):(*action_buttons_&=~y)
void KeyboardHardwareImplemetationWin::CodeAction(long keycode, bool activated)
{
// todo : hardcoded values
switch (keycode)
{
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;
case VK_LEFT: gamepad_active_[0]->game_pad_button_left.UpdateMap(0, activated); action(GamePadButtonLeft); break;
case VK_RIGHT: gamepad_active_[0]->game_pad_button_right.UpdateMap(0, activated); action(GamePadButtonRight); break;
case VK_TAB: *select_ = activated; action(GamePadButtonSelect); break;
case VK_SCROLL: if (gamepad_active_[0] != nullptr) { gamepad_active_[0]->game_pad_button_start.UpdateMap(0, activated); action(GamePadButtonStart); } break;
case VK_UP: if (gamepad_active_[0] != nullptr) {
gamepad_active_[0]->game_pad_button_up.UpdateMap(0, activated); action(GamePadButtonUp);
} break;
case VK_DOWN: if (gamepad_active_[0] != nullptr) {
gamepad_active_[0]->game_pad_button_down.UpdateMap(0, activated); action(GamePadButtonDown);
} break;
case VK_LEFT: if (gamepad_active_[0] != nullptr) {
gamepad_active_[0]->game_pad_button_left.UpdateMap(0, activated); action(GamePadButtonLeft);
} break;
case VK_RIGHT: if (gamepad_active_[0] != nullptr) {
gamepad_active_[0]->game_pad_button_right.UpdateMap(0, activated); action(GamePadButtonRight);
} break;
//case VK_SHIFT:gamepad_active_[0]->game_pad_button_A.UpdateMap(0, activated); action(GamePadButtonA);break;
case VK_CONTROL:gamepad_active_[0]->game_pad_button_X.UpdateMap(0, activated); action(GamePadButtonX); break;
case VK_CONTROL:if (gamepad_active_[0] != nullptr) {
gamepad_active_[0]->game_pad_button_X.UpdateMap(0, activated); action(GamePadButtonX);
} break;
default:
if (activated)
keyboard_->PressKey(keycode);
Expand Down
13 changes: 6 additions & 7 deletions SugarPiWin32/KeyboardHardwareImplemetationWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ class KeyboardHardwareImplemetationWin : public KeyboardHardwareImplemetation
void Presskey(long keyCode);
void Unpresskey(long keyCode);

//bool select_;

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

KeyboardPi* keyboard_;
KeyboardPi* keyboard_;
KeyboardHandler handler_;
unsigned char keyboard_lines_[10];

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

//unsigned int action_buttons_;
bool* select_;
unsigned int* action_buttons_;
unsigned char* keyboard_lines_;

GamepadDef** gamepad_active_;
};
6 changes: 2 additions & 4 deletions SugarPiWin32/SugarPiSetupDesktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ void SugarPiSetup::Load()
}

// Keyboard layout (if any)
if (config_->GetConfiguration (SECTION_SETUP, KEY_LAYOUT, DEFAULT_LAYOUT, buffer, SIZE_OF_BUFFER ))
{
keyboard_->LoadKeyboard (buffer);
}
config_->GetConfiguration(SECTION_SETUP, KEY_LAYOUT, DEFAULT_LAYOUT, buffer, SIZE_OF_BUFFER);
keyboard_->LoadKeyboard (buffer);

// Language
language_id_ = config_->GetConfigurationInt(SECTION_SETUP, LANGUAUGE_ID, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/KeyboardPi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ KeyboardPi::KeyboardPi(CLogger* logger) :
{
memset(keyboard_lines_, 0xff, sizeof(keyboard_lines_));

for (unsigned i = 0; i < MAX_GAMEPADS; i++)
{
gamepad_active_[i] = nullptr;
}

InitKeyboard(default_raw_map);
this_ptr_ = this;

Expand Down
14 changes: 11 additions & 3 deletions src/KeyboardPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ 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);

unsigned int *GetActionButtons() {return &action_buttons_; }
bool* GetSelect() { return &select_; }
TGamePadState* GetGamepadState() {return gamepad_state_;}
TGamePadState* GetGamepadStateBuffered() { return gamepad_state_buffered_; }
unsigned char* GetKeyboardLine() { return keyboard_lines_; }
GamepadDef** GetGamepadActive() {
return gamepad_active_;
}

protected:

Expand All @@ -62,6 +67,9 @@ class KeyboardPi : public IKeyboardHandler
CSpinLock mutex_;
*/
unsigned int action_buttons_;
bool select_;

TGamePadState gamepad_state_[MAX_GAMEPADS];
TGamePadState gamepad_state_buffered_[MAX_GAMEPADS];

Expand Down

0 comments on commit fb50f6b

Please sign in to comment.