Add switch rumble and motion feedbacks

This commit is contained in:
h0neybadger 2021-01-11 20:03:28 +01:00
commit acf15480f2
7 changed files with 255 additions and 100 deletions

View file

@ -69,12 +69,6 @@ class PSRemotePlay : public brls::View
// to send gamepad inputs
Host *host;
brls::Label *label;
ChiakiControllerState state = {0};
// FPS calculation
// double base_time;
// int frame_counter = 0;
// int fps = 0;
public:
PSRemotePlay(Host *host);
~PSRemotePlay();

View file

@ -54,7 +54,9 @@ class Host
std::function<void()> chiaki_regist_event_type_finished_success = nullptr;
std::function<void()> chiaki_event_connected_cb = nullptr;
std::function<void(bool)> chiaki_even_login_pin_request_cb = nullptr;
std::function<void(uint8_t, uint8_t)> chiaki_event_rumble_cb = nullptr;
std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
std::function<void(ChiakiControllerState *)> io_read_controller_cb = nullptr;
// internal state
bool discovered = false;
@ -73,6 +75,7 @@ class Host
std::string server_nickname;
ChiakiTarget target = CHIAKI_TARGET_PS4_UNKNOWN;
ChiakiDiscoveryHostState state = CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN;
ChiakiControllerState controller_state = {0};
// mac address = 48 bits
uint8_t server_mac[6] = {0};
@ -96,7 +99,7 @@ class Host
int FiniSession();
void StopSession();
void StartSession();
void SendFeedbackState(ChiakiControllerState *);
void SendFeedbackState();
void RegistCB(ChiakiRegistEvent *);
void ConnectionEventCB(ChiakiEvent *);
bool GetVideoResolution(int *ret_width, int *ret_height);
@ -110,7 +113,9 @@ class Host
void SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success);
void SetEventConnectedCallback(std::function<void()> chiaki_event_connected_cb);
void SetEventLoginPinRequestCallback(std::function<void(bool)> chiaki_even_login_pin_request_cb);
void SetEventRumbleCallback(std::function<void(uint8_t, uint8_t)> chiaki_event_rumble_cb);
void SetEventQuitCallback(std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb);
void SetReadControllerCallback(std::function<void(ChiakiControllerState *)> io_read_controller_cb);
bool IsRegistered();
bool IsDiscovered();
bool IsReady();

View file

@ -28,6 +28,12 @@ Omit khrplatform: False
Reproducible: False
*/
#ifdef __SWITCH__
#include <switch.h>
#else
#include <iostream>
#endif
#include <mutex>
extern "C"
{
@ -65,6 +71,11 @@ class IO
SDL_AudioDeviceID sdl_audio_device_id = 0;
SDL_Event sdl_event;
SDL_Joystick *sdl_joystick_ptr[SDL_JOYSTICK_COUNT] = {0};
#ifdef __SWITCH__
PadState pad;
HidSixAxisSensorHandle sixaxis_handles[4];
HidVibrationDeviceHandle vibration_handles[2][2];
#endif
GLuint vao;
GLuint vbo;
GLuint tex[PLANES_COUNT];
@ -86,7 +97,7 @@ class IO
void SetOpenGlYUVPixels(AVFrame *frame);
bool ReadGameKeys(SDL_Event *event, ChiakiControllerState *state);
bool ReadGameTouchScreen(ChiakiControllerState *state);
bool ReadGameSixAxis(ChiakiControllerState *state);
public:
// singleton configuration
IO(const IO&) = delete;
@ -100,9 +111,11 @@ class IO
void AudioCB(int16_t *buf, size_t samples_count);
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
bool FreeVideo();
bool InitJoystick();
bool FreeJoystick();
bool MainLoop(ChiakiControllerState *state);
bool InitController();
bool FreeController();
bool MainLoop();
void UpdateControllerState(ChiakiControllerState *state);
void SetRumble(uint8_t left, uint8_t right);
};
#endif //CHIAKI_IO_H