From a64e59bf9903ededa4492f2499991bb0e22a94ca Mon Sep 17 00:00:00 2001 From: StapleButter Date: Fri, 14 Dec 2018 03:45:27 +0100 Subject: [PATCH] hook lid close/open to the actual hotkey system --- src/libui_sdl/main.cpp | 57 +++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 981496ac..0f202fae 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -279,6 +279,23 @@ void MicCallback(void* data, Uint8* stream, int len) MicBufferWritePos &= (kMicBufferSize-1); } +bool JoyButtonPressed(int btnid, int njoybuttons, Uint8* joybuttons, Uint32 hat) +{ + bool pressed; + if (btnid == 0x101) // up + pressed = (hat & SDL_HAT_UP); + else if (btnid == 0x104) // down + pressed = (hat & SDL_HAT_DOWN); + else if (btnid == 0x102) // right + pressed = (hat & SDL_HAT_RIGHT); + else if (btnid == 0x108) // left + pressed = (hat & SDL_HAT_LEFT); + else + pressed = (btnid < njoybuttons) ? joybuttons[btnid] : false; + + return pressed; +} + int EmuThreadFunc(void* burp) { NDS::Init(); @@ -294,6 +311,13 @@ int EmuThreadFunc(void* burp) LidCommand = false; LidStatus = false; + Uint8* joybuttons = NULL; int njoybuttons = 0; + if (Joystick) + { + njoybuttons = SDL_JoystickNumButtons(Joystick); + if (njoybuttons) joybuttons = new Uint8[njoybuttons]; + } + u32 nframes = 0; u32 starttick = SDL_GetTicks(); u32 lasttick = starttick; @@ -319,22 +343,15 @@ int EmuThreadFunc(void* burp) Sint16 axisX = SDL_JoystickGetAxis(Joystick, 0); Sint16 axisY = SDL_JoystickGetAxis(Joystick, 1); + for (int i = 0; i < njoybuttons; i++) + joybuttons[i] = SDL_JoystickGetButton(Joystick, i); + for (int i = 0; i < 12; i++) { int btnid = Config::JoyMapping[i]; if (btnid < 0) continue; - bool pressed; - if (btnid == 0x101) // up - pressed = (hat & SDL_HAT_UP); - else if (btnid == 0x104) // down - pressed = (hat & SDL_HAT_DOWN); - else if (btnid == 0x102) // right - pressed = (hat & SDL_HAT_RIGHT); - else if (btnid == 0x108) // left - pressed = (hat & SDL_HAT_LEFT); - else - pressed = SDL_JoystickGetButton(Joystick, btnid); + bool pressed = JoyButtonPressed(btnid, njoybuttons, joybuttons, hat); if (i == 4) // right pressed = pressed || (axisX >= 16384); @@ -347,6 +364,16 @@ int EmuThreadFunc(void* burp) if (pressed) joymask &= ~(1<Scancode == Config::KeyMapping[i]) KeyInputMask &= ~(1<Scancode == 0x44) // F10, test + if (evt->Scancode == Config::HKKeyMapping[HK_Lid]) { LidStatus = !LidStatus; LidCommand = true; } + if (evt->Scancode == Config::HKKeyMapping[HK_Mic]) + { + // microphone shit here + } if (evt->Scancode == 0x57) // F11 NDS::debug(0);