mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 05:23:12 -07:00
Refactor IO class as singleton
This commit is contained in:
parent
a1b081bfce
commit
d31fb46ae8
8 changed files with 462 additions and 379 deletions
|
@ -11,13 +11,13 @@
|
||||||
|
|
||||||
#include <borealis.hpp>
|
#include <borealis.hpp>
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "host.h"
|
|
||||||
#include "settings.h"
|
|
||||||
#include "discoverymanager.h"
|
#include "discoverymanager.h"
|
||||||
|
#include "host.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
class HostInterface : public brls::List
|
class HostInterface : public brls::List
|
||||||
{
|
{
|
||||||
|
@ -26,19 +26,19 @@ class HostInterface : public brls::List
|
||||||
Host *host;
|
Host *host;
|
||||||
Settings *settings;
|
Settings *settings;
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HostInterface(IO * io, Host * host, Settings * settings);
|
HostInterface(Host *host);
|
||||||
~HostInterface();
|
~HostInterface();
|
||||||
|
|
||||||
static void Register(IO * io, Host * host,
|
static void Register(Host *host, std::function<void()> success_cb = nullptr);
|
||||||
Settings * settings, std::function<void()> success_cb = nullptr);
|
|
||||||
void Register();
|
void Register();
|
||||||
void Wakeup(brls::View *view);
|
void Wakeup(brls::View *view);
|
||||||
void Connect(brls::View *view);
|
void Connect(brls::View *view);
|
||||||
void ConnectSession();
|
void ConnectSession();
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
bool Stream();
|
void Stream();
|
||||||
bool CloseStream(ChiakiQuitEvent * quit);
|
void CloseStream(ChiakiQuitEvent *quit);
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainApplication
|
class MainApplication
|
||||||
|
@ -57,9 +57,9 @@ class MainApplication
|
||||||
|
|
||||||
bool BuildConfigurationMenu(brls::List *, Host *host = nullptr);
|
bool BuildConfigurationMenu(brls::List *, Host *host = nullptr);
|
||||||
void BuildAddHostConfigurationMenu(brls::List *);
|
void BuildAddHostConfigurationMenu(brls::List *);
|
||||||
public:
|
|
||||||
MainApplication(DiscoveryManager * discoverymanager, IO * io);
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainApplication(DiscoveryManager *discoverymanager);
|
||||||
~MainApplication();
|
~MainApplication();
|
||||||
bool Load();
|
bool Load();
|
||||||
};
|
};
|
||||||
|
@ -80,11 +80,10 @@ class PSRemotePlay : public brls::View
|
||||||
// int fps = 0;
|
// int fps = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PSRemotePlay(IO * io, Host * host);
|
PSRemotePlay(Host *host);
|
||||||
~PSRemotePlay();
|
~PSRemotePlay();
|
||||||
|
|
||||||
void draw(NVGcontext *vg, int x, int y, unsigned width, unsigned height, brls::Style *style, brls::FrameContext *ctx) override;
|
void draw(NVGcontext *vg, int x, int y, unsigned width, unsigned height, brls::Style *style, brls::FrameContext *ctx) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHIAKI_GUI_H
|
#endif // CHIAKI_GUI_H
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ static void Discovery(ChiakiDiscoveryHost *, void *);
|
||||||
static void InitAudioCB(unsigned int channels, unsigned int rate, void *user);
|
static void InitAudioCB(unsigned int channels, unsigned int rate, void *user);
|
||||||
static bool VideoCB(uint8_t *buf, size_t buf_size, void *user);
|
static bool VideoCB(uint8_t *buf, size_t buf_size, void *user);
|
||||||
static void AudioCB(int16_t *buf, size_t samples_count, void *user);
|
static void AudioCB(int16_t *buf, size_t samples_count, void *user);
|
||||||
static void RegistEventCB(ChiakiRegistEvent * event, void * user);
|
|
||||||
static void EventCB(ChiakiEvent *event, void *user);
|
static void EventCB(ChiakiEvent *event, void *user);
|
||||||
|
static void RegistEventCB(ChiakiRegistEvent *event, void *user);
|
||||||
|
|
||||||
enum RegistError
|
enum RegistError
|
||||||
{
|
{
|
||||||
|
@ -52,6 +52,9 @@ class Host
|
||||||
std::function<void()> chiaki_regist_event_type_finished_canceled = nullptr;
|
std::function<void()> chiaki_regist_event_type_finished_canceled = nullptr;
|
||||||
std::function<void()> chiaki_regist_event_type_finished_failed = nullptr;
|
std::function<void()> chiaki_regist_event_type_finished_failed = nullptr;
|
||||||
std::function<void()> chiaki_regist_event_type_finished_success = nullptr;
|
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(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
|
||||||
|
|
||||||
// internal state
|
// internal state
|
||||||
bool discovered = false;
|
bool discovered = false;
|
||||||
|
@ -95,6 +98,7 @@ class Host
|
||||||
void StartSession();
|
void StartSession();
|
||||||
void SendFeedbackState(ChiakiControllerState *);
|
void SendFeedbackState(ChiakiControllerState *);
|
||||||
void RegistCB(ChiakiRegistEvent *);
|
void RegistCB(ChiakiRegistEvent *);
|
||||||
|
void ConnectionEventCB(ChiakiEvent *);
|
||||||
bool GetVideoResolution(int *ret_width, int *ret_height);
|
bool GetVideoResolution(int *ret_width, int *ret_height);
|
||||||
std::string GetHostName();
|
std::string GetHostName();
|
||||||
std::string GetHostAddr();
|
std::string GetHostAddr();
|
||||||
|
@ -104,6 +108,9 @@ class Host
|
||||||
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled);
|
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled);
|
||||||
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed);
|
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed);
|
||||||
void SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success);
|
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 SetEventQuitCallback(std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb);
|
||||||
bool IsRegistered();
|
bool IsRegistered();
|
||||||
bool IsDiscovered();
|
bool IsDiscovered();
|
||||||
bool IsReady();
|
bool IsReady();
|
||||||
|
|
|
@ -3,15 +3,14 @@
|
||||||
#ifndef CHIAKI_IO_H
|
#ifndef CHIAKI_IO_H
|
||||||
#define CHIAKI_IO_H
|
#define CHIAKI_IO_H
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <glad.h> // glad library (OpenGL loader)
|
#include <glad.h> // glad library (OpenGL loader)
|
||||||
|
|
||||||
#include <chiaki/session.h>
|
#include <chiaki/session.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
https://github.com/devkitPro/switch-glad/blob/master/include/glad/glad.h
|
https://github.com/devkitPro/switch-glad/blob/master/include/glad/glad.h
|
||||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&api=gl%3D4.3&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic
|
https://glad.dav1d.de/#profile=core&language=c&specification=gl&api=gl%3D4.3&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic
|
||||||
|
@ -37,8 +36,8 @@ extern "C"
|
||||||
#include <libswscale/swscale.h>
|
#include <libswscale/swscale.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <chiaki/log.h>
|
|
||||||
#include <chiaki/controller.h>
|
#include <chiaki/controller.h>
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
|
||||||
|
@ -47,6 +46,9 @@ extern "C"
|
||||||
|
|
||||||
class IO
|
class IO
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
IO();
|
||||||
|
static IO * instance;
|
||||||
private:
|
private:
|
||||||
ChiakiLog *log;
|
ChiakiLog *log;
|
||||||
int video_width;
|
int video_width;
|
||||||
|
@ -57,9 +59,6 @@ class IO
|
||||||
// default nintendo switch res
|
// default nintendo switch res
|
||||||
int screen_width = 1280;
|
int screen_width = 1280;
|
||||||
int screen_height = 720;
|
int screen_height = 720;
|
||||||
std::function<bool()> chiaki_event_connected_cb = nullptr;
|
|
||||||
std::function<bool(bool)> chiaki_even_login_pin_request_cb = nullptr;
|
|
||||||
std::function<bool(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
|
|
||||||
AVCodec *codec;
|
AVCodec *codec;
|
||||||
AVCodecContext *codec_context;
|
AVCodecContext *codec_context;
|
||||||
AVFrame *frame;
|
AVFrame *frame;
|
||||||
|
@ -73,7 +72,6 @@ class IO
|
||||||
GLuint vert;
|
GLuint vert;
|
||||||
GLuint frag;
|
GLuint frag;
|
||||||
GLuint prog;
|
GLuint prog;
|
||||||
private:
|
|
||||||
bool InitAVCodec();
|
bool InitAVCodec();
|
||||||
bool InitOpenGl();
|
bool InitOpenGl();
|
||||||
bool InitOpenGlTextures();
|
bool InitOpenGlTextures();
|
||||||
|
@ -88,26 +86,18 @@ class IO
|
||||||
void SetOpenGlYUVPixels(AVFrame *frame);
|
void SetOpenGlYUVPixels(AVFrame *frame);
|
||||||
bool ReadGameKeys(SDL_Event *event, ChiakiControllerState *state);
|
bool ReadGameKeys(SDL_Event *event, ChiakiControllerState *state);
|
||||||
bool ReadGameTouchScreen(ChiakiControllerState *state);
|
bool ReadGameTouchScreen(ChiakiControllerState *state);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IO(ChiakiLog * log);
|
// singleton configuration
|
||||||
|
IO(const IO&) = delete;
|
||||||
|
void operator=(const IO&) = delete;
|
||||||
|
static IO * GetInstance();
|
||||||
|
|
||||||
~IO();
|
~IO();
|
||||||
void SetMesaConfig();
|
void SetMesaConfig();
|
||||||
bool VideoCB(uint8_t *buf, size_t buf_size);
|
bool VideoCB(uint8_t *buf, size_t buf_size);
|
||||||
void SetEventConnectedCallback(std::function<bool()> chiaki_event_connected_cb)
|
|
||||||
{
|
|
||||||
this->chiaki_event_connected_cb = chiaki_event_connected_cb;
|
|
||||||
};
|
|
||||||
void SetEventLoginPinRequestCallback(std::function<bool(bool)> chiaki_even_login_pin_request_cb)
|
|
||||||
{
|
|
||||||
this->chiaki_even_login_pin_request_cb = chiaki_even_login_pin_request_cb;
|
|
||||||
};
|
|
||||||
void SetEventQuitCallback(std::function<bool(ChiakiQuitEvent *)> chiaki_event_quit_cb)
|
|
||||||
{
|
|
||||||
this->chiaki_event_quit_cb = chiaki_event_quit_cb;
|
|
||||||
};
|
|
||||||
void InitAudioCB(unsigned int channels, unsigned int rate);
|
void InitAudioCB(unsigned int channels, unsigned int rate);
|
||||||
void AudioCB(int16_t *buf, size_t samples_count);
|
void AudioCB(int16_t *buf, size_t samples_count);
|
||||||
void EventCB(ChiakiEvent *event);
|
|
||||||
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
|
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
|
||||||
bool FreeVideo();
|
bool FreeVideo();
|
||||||
bool InitJoystick();
|
bool InitJoystick();
|
||||||
|
@ -117,5 +107,3 @@ class IO
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CHIAKI_IO_H
|
#endif //CHIAKI_IO_H
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||||
|
|
||||||
#include <chiaki/log.h>
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
#define SCREEN_W 1280
|
#define SCREEN_W 1280
|
||||||
#define SCREEN_H 720
|
#define SCREEN_H 720
|
||||||
|
@ -11,8 +11,7 @@ using namespace brls::i18n::literals; // for _i18n
|
||||||
|
|
||||||
#define DIALOG(dialog, r) \
|
#define DIALOG(dialog, r) \
|
||||||
brls::Dialog *d_##dialog = new brls::Dialog(r); \
|
brls::Dialog *d_##dialog = new brls::Dialog(r); \
|
||||||
brls::GenericEvent::Callback cb_##dialog = [d_##dialog](brls::View* view) \
|
brls::GenericEvent::Callback cb_##dialog = [d_##dialog](brls::View *view) { \
|
||||||
{ \
|
|
||||||
d_##dialog->close(); \
|
d_##dialog->close(); \
|
||||||
}; \
|
}; \
|
||||||
d_##dialog->addButton("Ok", cb_##dialog); \
|
d_##dialog->addButton("Ok", cb_##dialog); \
|
||||||
|
@ -20,10 +19,12 @@ using namespace brls::i18n::literals; // for _i18n
|
||||||
d_##dialog->open(); \
|
d_##dialog->open(); \
|
||||||
brls::Logger::info("Dialog: {0}", r);
|
brls::Logger::info("Dialog: {0}", r);
|
||||||
|
|
||||||
|
HostInterface::HostInterface(Host *host)
|
||||||
HostInterface::HostInterface(IO * io, Host * host, Settings * settings)
|
: host(host)
|
||||||
: io(io), host(host), settings(settings)
|
|
||||||
{
|
{
|
||||||
|
this->settings = Settings::GetInstance();
|
||||||
|
this->io = IO::GetInstance();
|
||||||
|
|
||||||
brls::ListItem *connect = new brls::ListItem("Connect");
|
brls::ListItem *connect = new brls::ListItem("Connect");
|
||||||
connect->getClickEvent()->subscribe(std::bind(&HostInterface::Connect, this, std::placeholders::_1));
|
connect->getClickEvent()->subscribe(std::bind(&HostInterface::Connect, this, std::placeholders::_1));
|
||||||
this->addView(connect);
|
this->addView(connect);
|
||||||
|
@ -37,6 +38,10 @@ HostInterface::HostInterface(IO * io, Host * host, Settings * settings)
|
||||||
"Host configuration", true);
|
"Host configuration", true);
|
||||||
this->addView(info);
|
this->addView(info);
|
||||||
|
|
||||||
|
// push opengl chiaki stream
|
||||||
|
// when the host is connected
|
||||||
|
this->host->SetEventConnectedCallback(std::bind(&HostInterface::Stream, this));
|
||||||
|
this->host->SetEventQuitCallback(std::bind(&HostInterface::CloseStream, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
HostInterface::~HostInterface()
|
HostInterface::~HostInterface()
|
||||||
|
@ -44,8 +49,11 @@ HostInterface::~HostInterface()
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostInterface::Register(IO * io, Host * host, Settings * settings, std::function<void()> success_cb)
|
void HostInterface::Register(Host *host, std::function<void()> success_cb)
|
||||||
{
|
{
|
||||||
|
Settings *settings = Settings::GetInstance();
|
||||||
|
IO *io = IO::GetInstance();
|
||||||
|
|
||||||
// user must provide psn id for registration
|
// user must provide psn id for registration
|
||||||
std::string account_id = settings->GetPSNAccountID(host);
|
std::string account_id = settings->GetPSNAccountID(host);
|
||||||
std::string online_id = settings->GetPSNOnlineID(host);
|
std::string online_id = settings->GetPSNOnlineID(host);
|
||||||
|
@ -65,8 +73,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
|
||||||
}
|
}
|
||||||
|
|
||||||
// add HostConnected function to regist_event_type_finished_success
|
// add HostConnected function to regist_event_type_finished_success
|
||||||
auto event_type_finished_success_cb = [settings, success_cb]()
|
auto event_type_finished_success_cb = [settings, success_cb]() {
|
||||||
{
|
|
||||||
// save RP keys
|
// save RP keys
|
||||||
settings->WriteFile();
|
settings->WriteFile();
|
||||||
if(success_cb != nullptr)
|
if(success_cb != nullptr)
|
||||||
|
@ -82,8 +89,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
|
||||||
};
|
};
|
||||||
host->SetRegistEventTypeFinishedSuccess(event_type_finished_success_cb);
|
host->SetRegistEventTypeFinishedSuccess(event_type_finished_success_cb);
|
||||||
|
|
||||||
auto event_type_finished_failed_cb = []()
|
auto event_type_finished_failed_cb = []() {
|
||||||
{
|
|
||||||
// unlock user inputs
|
// unlock user inputs
|
||||||
brls::Application::unblockInputs();
|
brls::Application::unblockInputs();
|
||||||
brls::Application::notify("Registration failed");
|
brls::Application::notify("Registration failed");
|
||||||
|
@ -92,8 +98,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
|
||||||
|
|
||||||
// the host is not registered yet
|
// the host is not registered yet
|
||||||
brls::Dialog *peprpc = new brls::Dialog("Please enter your PlayStation registration PIN code");
|
brls::Dialog *peprpc = new brls::Dialog("Please enter your PlayStation registration PIN code");
|
||||||
brls::GenericEvent::Callback cb_peprpc = [host, io, peprpc](brls::View* view)
|
brls::GenericEvent::Callback cb_peprpc = [host, io, peprpc](brls::View *view) {
|
||||||
{
|
|
||||||
bool pin_provided = false;
|
bool pin_provided = false;
|
||||||
char pin_input[9] = {0};
|
char pin_input[9] = {0};
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
|
@ -133,8 +138,7 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
|
||||||
void HostInterface::Register()
|
void HostInterface::Register()
|
||||||
{
|
{
|
||||||
// use Connect just after the registration to save user inputs
|
// use Connect just after the registration to save user inputs
|
||||||
HostInterface::Register(this->io, this->host,
|
HostInterface::Register(this->host, std::bind(&HostInterface::ConnectSession, this));
|
||||||
this->settings, std::bind(&HostInterface::ConnectSession, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostInterface::Wakeup(brls::View *view)
|
void HostInterface::Wakeup(brls::View *view)
|
||||||
|
@ -194,11 +198,6 @@ void HostInterface::ConnectSession()
|
||||||
// user inputs are restored with the CloseStream
|
// user inputs are restored with the CloseStream
|
||||||
brls::Application::blockInputs();
|
brls::Application::blockInputs();
|
||||||
|
|
||||||
// push opengl chiaki stream
|
|
||||||
// when the host is connected
|
|
||||||
this->io->SetEventConnectedCallback(std::bind(&HostInterface::Stream, this));
|
|
||||||
this->io->SetEventQuitCallback(std::bind(&HostInterface::CloseStream, this, std::placeholders::_1));
|
|
||||||
|
|
||||||
// connect host sesssion
|
// connect host sesssion
|
||||||
this->host->InitSession(this->io);
|
this->host->InitSession(this->io);
|
||||||
this->host->StartSession();
|
this->host->StartSession();
|
||||||
|
@ -212,10 +211,11 @@ void HostInterface::Disconnect()
|
||||||
this->host->StopSession();
|
this->host->StopSession();
|
||||||
this->connected = false;
|
this->connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->host->FiniSession();
|
this->host->FiniSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HostInterface::Stream()
|
void HostInterface::Stream()
|
||||||
{
|
{
|
||||||
this->connected = true;
|
this->connected = true;
|
||||||
// https://github.com/natinusala/borealis/issues/59
|
// https://github.com/natinusala/borealis/issues/59
|
||||||
|
@ -226,11 +226,10 @@ bool HostInterface::Stream()
|
||||||
// brls::Application::setDisplayFramerate(true);
|
// brls::Application::setDisplayFramerate(true);
|
||||||
|
|
||||||
// push raw opengl stream over borealis
|
// push raw opengl stream over borealis
|
||||||
brls::Application::pushView(new PSRemotePlay(this->io, this->host));
|
brls::Application::pushView(new PSRemotePlay(this->host));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HostInterface::CloseStream(ChiakiQuitEvent * quit)
|
void HostInterface::CloseStream(ChiakiQuitEvent *quit)
|
||||||
{
|
{
|
||||||
// session QUIT call back
|
// session QUIT call back
|
||||||
brls::Application::unblockInputs();
|
brls::Application::unblockInputs();
|
||||||
|
@ -244,14 +243,14 @@ bool HostInterface::CloseStream(ChiakiQuitEvent * quit)
|
||||||
*/
|
*/
|
||||||
brls::Application::notify(chiaki_quit_reason_string(quit->reason));
|
brls::Application::notify(chiaki_quit_reason_string(quit->reason));
|
||||||
Disconnect();
|
Disconnect();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApplication::MainApplication(DiscoveryManager * discoverymanager, IO * io)
|
MainApplication::MainApplication(DiscoveryManager *discoverymanager)
|
||||||
: discoverymanager(discoverymanager), io(io)
|
: discoverymanager(discoverymanager)
|
||||||
{
|
{
|
||||||
this->settings = Settings::GetInstance();
|
this->settings = Settings::GetInstance();
|
||||||
this->log = this->settings->GetLogger();
|
this->log = this->settings->GetLogger();
|
||||||
|
this->io = IO::GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApplication::~MainApplication()
|
MainApplication::~MainApplication()
|
||||||
|
@ -312,10 +311,9 @@ bool MainApplication::Load()
|
||||||
for(auto it = hosts->begin(); it != hosts->end(); it++)
|
for(auto it = hosts->begin(); it != hosts->end(); it++)
|
||||||
{
|
{
|
||||||
// add host to the gui only if the host is registered or discovered
|
// add host to the gui only if the host is registered or discovered
|
||||||
if(this->host_menuitems.find(&it->second) == this->host_menuitems.end()
|
if(this->host_menuitems.find(&it->second) == this->host_menuitems.end() && (it->second.HasRPkey() == true || it->second.IsDiscovered() == true))
|
||||||
&& (it->second.HasRPkey() == true || it->second.IsDiscovered() == true))
|
|
||||||
{
|
{
|
||||||
HostInterface * new_host = new HostInterface(this->io, &it->second, this->settings);
|
HostInterface *new_host = new HostInterface(&it->second);
|
||||||
this->host_menuitems[&it->second] = new_host;
|
this->host_menuitems[&it->second] = new_host;
|
||||||
// create host if udefined
|
// create host if udefined
|
||||||
BuildConfigurationMenu(new_host, &it->second);
|
BuildConfigurationMenu(new_host, &it->second);
|
||||||
|
@ -331,8 +329,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
std::string psn_account_id_string = this->settings->GetPSNAccountID(host);
|
std::string psn_account_id_string = this->settings->GetPSNAccountID(host);
|
||||||
brls::ListItem *psn_account_id = new brls::ListItem("PSN Account ID", "PS5 or PS4 v7.0 and greater (base64 account_id)");
|
brls::ListItem *psn_account_id = new brls::ListItem("PSN Account ID", "PS5 or PS4 v7.0 and greater (base64 account_id)");
|
||||||
psn_account_id->setValue(psn_account_id_string.c_str());
|
psn_account_id->setValue(psn_account_id_string.c_str());
|
||||||
auto psn_account_id_cb = [this, host, psn_account_id](brls::View * view)
|
auto psn_account_id_cb = [this, host, psn_account_id](brls::View *view) {
|
||||||
{
|
|
||||||
char account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2] = {0};
|
char account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
|
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -351,8 +348,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
std::string psn_online_id_string = this->settings->GetPSNOnlineID(host);
|
std::string psn_online_id_string = this->settings->GetPSNOnlineID(host);
|
||||||
brls::ListItem *psn_online_id = new brls::ListItem("PSN Online ID");
|
brls::ListItem *psn_online_id = new brls::ListItem("PSN Online ID");
|
||||||
psn_online_id->setValue(psn_online_id_string.c_str());
|
psn_online_id->setValue(psn_online_id_string.c_str());
|
||||||
auto psn_online_id_cb = [this, host, psn_online_id](brls::View * view)
|
auto psn_online_id_cb = [this, host, psn_online_id](brls::View *view) {
|
||||||
{
|
|
||||||
char online_id[256] = {0};
|
char online_id[256] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(online_id, sizeof(online_id));
|
bool input = this->io->ReadUserKeyboard(online_id, sizeof(online_id));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -386,8 +382,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
brls::SelectListItem *resolution = new brls::SelectListItem(
|
brls::SelectListItem *resolution = new brls::SelectListItem(
|
||||||
"Resolution", {"720p", "540p", "360p"}, value);
|
"Resolution", {"720p", "540p", "360p"}, value);
|
||||||
|
|
||||||
auto resolution_cb = [this, host](int result)
|
auto resolution_cb = [this, host](int result) {
|
||||||
{
|
|
||||||
ChiakiVideoResolutionPreset value = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
|
ChiakiVideoResolutionPreset value = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
|
@ -421,8 +416,7 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
brls::SelectListItem *fps = new brls::SelectListItem(
|
brls::SelectListItem *fps = new brls::SelectListItem(
|
||||||
"FPS", {"60", "30"}, value);
|
"FPS", {"60", "30"}, value);
|
||||||
|
|
||||||
auto fps_cb = [this, host](int result)
|
auto fps_cb = [this, host](int result) {
|
||||||
{
|
|
||||||
ChiakiVideoFPSPreset value = CHIAKI_VIDEO_FPS_PRESET_60;
|
ChiakiVideoFPSPreset value = CHIAKI_VIDEO_FPS_PRESET_60;
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
|
@ -471,7 +465,6 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
brls::ListItem *host_rp_key_type = new brls::ListItem("RP Key type");
|
brls::ListItem *host_rp_key_type = new brls::ListItem("RP Key type");
|
||||||
host_rp_key_type->setValue(host_rp_key_type_string.c_str());
|
host_rp_key_type->setValue(host_rp_key_type_string.c_str());
|
||||||
ls->addView(host_rp_key_type);
|
ls->addView(host_rp_key_type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -484,8 +477,7 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
// "Add Host configuration", true);
|
// "Add Host configuration", true);
|
||||||
|
|
||||||
brls::ListItem *display_name = new brls::ListItem("Display name");
|
brls::ListItem *display_name = new brls::ListItem("Display name");
|
||||||
auto display_name_cb = [this, display_name](brls::View * view)
|
auto display_name_cb = [this, display_name](brls::View *view) {
|
||||||
{
|
|
||||||
char name[16] = {0};
|
char name[16] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(name, sizeof(name));
|
bool input = this->io->ReadUserKeyboard(name, sizeof(name));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -500,8 +492,7 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
add_host->addView(display_name);
|
add_host->addView(display_name);
|
||||||
|
|
||||||
brls::ListItem *address = new brls::ListItem("Remote IP/name");
|
brls::ListItem *address = new brls::ListItem("Remote IP/name");
|
||||||
auto address_cb = [this, address](brls::View * view)
|
auto address_cb = [this, address](brls::View *view) {
|
||||||
{
|
|
||||||
char addr[256] = {0};
|
char addr[256] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(addr, sizeof(addr));
|
bool input = this->io->ReadUserKeyboard(addr, sizeof(addr));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -515,15 +506,13 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
address->getClickEvent()->subscribe(address_cb);
|
address->getClickEvent()->subscribe(address_cb);
|
||||||
add_host->addView(address);
|
add_host->addView(address);
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// brls::ListItem* port = new brls::ListItem("Remote session port", "tcp/udp 9295");
|
// brls::ListItem* port = new brls::ListItem("Remote session port", "tcp/udp 9295");
|
||||||
// brls::ListItem* port = new brls::ListItem("Remote stream port", "udp 9296");
|
// brls::ListItem* port = new brls::ListItem("Remote stream port", "udp 9296");
|
||||||
// brls::ListItem* port = new brls::ListItem("Remote Senkusha port", "udp 9297");
|
// brls::ListItem* port = new brls::ListItem("Remote Senkusha port", "udp 9297");
|
||||||
brls::SelectListItem *ps_version = new brls::SelectListItem("PlayStation Version",
|
brls::SelectListItem *ps_version = new brls::SelectListItem("PlayStation Version",
|
||||||
{"PS5", "PS4 > 8", "7 < PS4 < 8", "PS4 < 7"});
|
{"PS5", "PS4 > 8", "7 < PS4 < 8", "PS4 < 7"});
|
||||||
auto ps_version_cb = [this, ps_version](int result)
|
auto ps_version_cb = [this, ps_version](int result) {
|
||||||
{
|
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -548,8 +537,7 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
add_host->addView(ps_version);
|
add_host->addView(ps_version);
|
||||||
|
|
||||||
brls::ListItem *register_host = new brls::ListItem("Register");
|
brls::ListItem *register_host = new brls::ListItem("Register");
|
||||||
auto register_host_cb = [this](brls::View * view)
|
auto register_host_cb = [this](brls::View *view) {
|
||||||
{
|
|
||||||
bool err = false;
|
bool err = false;
|
||||||
if(this->remote_display_name.length() <= 0)
|
if(this->remote_display_name.length() <= 0)
|
||||||
{
|
{
|
||||||
|
@ -576,16 +564,18 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
host->SetHostAddr(this->remote_addr);
|
host->SetHostAddr(this->remote_addr);
|
||||||
host->SetChiakiTarget(this->remote_ps_version);
|
host->SetChiakiTarget(this->remote_ps_version);
|
||||||
|
|
||||||
HostInterface::Register(this->io, host, this->settings);
|
HostInterface::Register(host);
|
||||||
};
|
};
|
||||||
register_host->getClickEvent()->subscribe(register_host_cb);
|
register_host->getClickEvent()->subscribe(register_host_cb);
|
||||||
|
|
||||||
add_host->addView(register_host);
|
add_host->addView(register_host);
|
||||||
}
|
}
|
||||||
|
|
||||||
PSRemotePlay::PSRemotePlay(IO * io, Host * host)
|
PSRemotePlay::PSRemotePlay(Host *host)
|
||||||
: io(io), host(host)
|
: host(host)
|
||||||
{
|
{
|
||||||
|
this->io = IO::GetInstance();
|
||||||
|
|
||||||
// store joycon/touchpad keys
|
// store joycon/touchpad keys
|
||||||
for(int x = 0; x < CHIAKI_CONTROLLER_TOUCHES_MAX; x++)
|
for(int x = 0; x < CHIAKI_CONTROLLER_TOUCHES_MAX; x++)
|
||||||
// start touchpad as "untouched"
|
// start touchpad as "untouched"
|
||||||
|
@ -622,4 +612,3 @@ void PSRemotePlay::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned h
|
||||||
PSRemotePlay::~PSRemotePlay()
|
PSRemotePlay::~PSRemotePlay()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ static void AudioCB(int16_t * buf, size_t samples_count, void * user)
|
||||||
|
|
||||||
static void EventCB(ChiakiEvent *event, void *user)
|
static void EventCB(ChiakiEvent *event, void *user)
|
||||||
{
|
{
|
||||||
IO * io = (IO *)user;
|
Host *host = (Host *)user;
|
||||||
io->EventCB(event);
|
host->ConnectionEventCB(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RegistEventCB(ChiakiRegistEvent *event, void *user)
|
static void RegistEventCB(ChiakiRegistEvent *event, void *user)
|
||||||
|
@ -158,7 +158,7 @@ int Host::InitSession(IO * user)
|
||||||
chiaki_opus_decoder_get_sink(&this->opus_decoder, &audio_sink);
|
chiaki_opus_decoder_get_sink(&this->opus_decoder, &audio_sink);
|
||||||
chiaki_session_set_audio_sink(&(this->session), &audio_sink);
|
chiaki_session_set_audio_sink(&(this->session), &audio_sink);
|
||||||
chiaki_session_set_video_sample_cb(&(this->session), VideoCB, user);
|
chiaki_session_set_video_sample_cb(&(this->session), VideoCB, user);
|
||||||
chiaki_session_set_event_cb(&(this->session), EventCB, user);
|
chiaki_session_set_event_cb(&(this->session), EventCB, this);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +166,7 @@ int Host::FiniSession()
|
||||||
{
|
{
|
||||||
if(this->session_init)
|
if(this->session_init)
|
||||||
{
|
{
|
||||||
|
this->session_init = false;
|
||||||
chiaki_session_join(&this->session);
|
chiaki_session_join(&this->session);
|
||||||
chiaki_session_fini(&this->session);
|
chiaki_session_fini(&this->session);
|
||||||
chiaki_opus_decoder_fini(&this->opus_decoder);
|
chiaki_opus_decoder_fini(&this->opus_decoder);
|
||||||
|
@ -194,6 +195,28 @@ void Host::SendFeedbackState(ChiakiControllerState * state)
|
||||||
chiaki_session_set_controller_state(&this->session, state);
|
chiaki_session_set_controller_state(&this->session, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Host::ConnectionEventCB(ChiakiEvent *event)
|
||||||
|
{
|
||||||
|
switch(event->type)
|
||||||
|
{
|
||||||
|
case CHIAKI_EVENT_CONNECTED:
|
||||||
|
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_CONNECTED");
|
||||||
|
if(this->chiaki_event_connected_cb != nullptr)
|
||||||
|
this->chiaki_event_connected_cb();
|
||||||
|
break;
|
||||||
|
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
|
||||||
|
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_LOGIN_PIN_REQUEST");
|
||||||
|
if(this->chiaki_even_login_pin_request_cb != nullptr)
|
||||||
|
this->chiaki_even_login_pin_request_cb(event->login_pin_request.pin_incorrect);
|
||||||
|
break;
|
||||||
|
case CHIAKI_EVENT_QUIT:
|
||||||
|
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_QUIT");
|
||||||
|
if(this->chiaki_event_quit_cb != nullptr)
|
||||||
|
this->chiaki_event_quit_cb(&event->quit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Host::RegistCB(ChiakiRegistEvent *event)
|
void Host::RegistCB(ChiakiRegistEvent *event)
|
||||||
{
|
{
|
||||||
// Chiaki callback fuction
|
// Chiaki callback fuction
|
||||||
|
@ -314,6 +337,21 @@ void Host::SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist
|
||||||
this->chiaki_regist_event_type_finished_success = chiaki_regist_event_type_finished_success;
|
this->chiaki_regist_event_type_finished_success = chiaki_regist_event_type_finished_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Host::SetEventConnectedCallback(std::function<void()> chiaki_event_connected_cb)
|
||||||
|
{
|
||||||
|
this->chiaki_event_connected_cb = chiaki_event_connected_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Host::SetEventLoginPinRequestCallback(std::function<void(bool)> chiaki_even_login_pin_request_cb)
|
||||||
|
{
|
||||||
|
this->chiaki_even_login_pin_request_cb = chiaki_even_login_pin_request_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Host::SetEventQuitCallback(std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb)
|
||||||
|
{
|
||||||
|
this->chiaki_event_quit_cb = chiaki_event_quit_cb;
|
||||||
|
}
|
||||||
|
|
||||||
bool Host::IsRegistered()
|
bool Host::IsRegistered()
|
||||||
{
|
{
|
||||||
return this->registered;
|
return this->registered;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
// https://github.com/torvalds/linux/blob/41ba50b0572e90ed3d24fe4def54567e9050bc47/drivers/hid/hid-sony.c#L2742
|
// https://github.com/torvalds/linux/blob/41ba50b0572e90ed3d24fe4def54567e9050bc47/drivers/hid/hid-sony.c#L2742
|
||||||
#define DS4_TRACKPAD_MAX_X 1920
|
#define DS4_TRACKPAD_MAX_X 1920
|
||||||
|
@ -60,12 +61,23 @@ static const float vert_pos[] = {
|
||||||
0.0f, 0.0f,
|
0.0f, 0.0f,
|
||||||
0.0f, 1.0f,
|
0.0f, 1.0f,
|
||||||
1.0f, 0.0f,
|
1.0f, 0.0f,
|
||||||
1.0f, 1.0f
|
1.0f, 1.0f};
|
||||||
};
|
|
||||||
|
|
||||||
IO::IO(ChiakiLog * log)
|
IO *IO::instance = nullptr;
|
||||||
: log(log)
|
|
||||||
|
IO *IO::GetInstance()
|
||||||
{
|
{
|
||||||
|
if(instance == nullptr)
|
||||||
|
{
|
||||||
|
instance = new IO;
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
IO::IO()
|
||||||
|
{
|
||||||
|
Settings *settings = Settings::GetInstance();
|
||||||
|
this->log = settings->GetLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
IO::~IO()
|
IO::~IO()
|
||||||
|
@ -99,7 +111,11 @@ void IO::SetMesaConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_OPENGL
|
#ifdef DEBUG_OPENGL
|
||||||
#define D(x){ (x); CheckGLError(__func__, __FILE__, __LINE__); }
|
#define D(x) \
|
||||||
|
{ \
|
||||||
|
(x); \
|
||||||
|
CheckGLError(__func__, __FILE__, __LINE__); \
|
||||||
|
}
|
||||||
void IO::CheckGLError(const char *func, const char *file, int line)
|
void IO::CheckGLError(const char *func, const char *file, int line)
|
||||||
{
|
{
|
||||||
GLenum err;
|
GLenum err;
|
||||||
|
@ -115,36 +131,50 @@ void IO::CheckGLError(const char* func, const char* file, int line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DS(x){ DumpShaderError(x, __func__, __FILE__, __LINE__); }
|
#define DS(x) \
|
||||||
|
{ \
|
||||||
|
DumpShaderError(x, __func__, __FILE__, __LINE__); \
|
||||||
|
}
|
||||||
void IO::DumpShaderError(GLuint shader, const char *func, const char *file, int line)
|
void IO::DumpShaderError(GLuint shader, const char *func, const char *file, int line)
|
||||||
{
|
{
|
||||||
GLchar str[512 + 1];
|
GLchar str[512 + 1];
|
||||||
GLsizei len = 0;
|
GLsizei len = 0;
|
||||||
glGetShaderInfoLog(shader, 512, &len, str);
|
glGetShaderInfoLog(shader, 512, &len, str);
|
||||||
if (len > 512) len = 512;
|
if(len > 512)
|
||||||
|
len = 512;
|
||||||
str[len] = '\0';
|
str[len] = '\0';
|
||||||
CHIAKI_LOGE(this->log, "glGetShaderInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
CHIAKI_LOGE(this->log, "glGetShaderInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DP(x){ DumpProgramError(x, __func__, __FILE__, __LINE__); }
|
#define DP(x) \
|
||||||
|
{ \
|
||||||
|
DumpProgramError(x, __func__, __FILE__, __LINE__); \
|
||||||
|
}
|
||||||
void IO::DumpProgramError(GLuint prog, const char *func, const char *file, int line)
|
void IO::DumpProgramError(GLuint prog, const char *func, const char *file, int line)
|
||||||
{
|
{
|
||||||
GLchar str[512 + 1];
|
GLchar str[512 + 1];
|
||||||
GLsizei len = 0;
|
GLsizei len = 0;
|
||||||
glGetProgramInfoLog(prog, 512, &len, str);
|
glGetProgramInfoLog(prog, 512, &len, str);
|
||||||
if (len > 512) len = 512;
|
if(len > 512)
|
||||||
|
len = 512;
|
||||||
str[len] = '\0';
|
str[len] = '\0';
|
||||||
CHIAKI_LOGE(this->log, "glGetProgramInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
CHIAKI_LOGE(this->log, "glGetProgramInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// do nothing
|
// do nothing
|
||||||
#define D(x){ (x); }
|
#define D(x) \
|
||||||
#define DS(x){ }
|
{ \
|
||||||
#define DP(x){ }
|
(x); \
|
||||||
|
}
|
||||||
|
#define DS(x) \
|
||||||
|
{ \
|
||||||
|
}
|
||||||
|
#define DP(x) \
|
||||||
|
{ \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
bool IO::VideoCB(uint8_t *buf, size_t buf_size)
|
bool IO::VideoCB(uint8_t *buf, size_t buf_size)
|
||||||
{
|
{
|
||||||
// callback function to decode video buffer
|
// callback function to decode video buffer
|
||||||
|
@ -204,7 +234,6 @@ send_packet:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IO::InitAudioCB(unsigned int channels, unsigned int rate)
|
void IO::InitAudioCB(unsigned int channels, unsigned int rate)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec want, have, test;
|
SDL_AudioSpec want, have, test;
|
||||||
|
@ -289,33 +318,6 @@ bool IO::InitVideo(int video_width, int video_height, int screen_width, int scre
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IO::EventCB(ChiakiEvent *event)
|
|
||||||
{
|
|
||||||
switch(event->type)
|
|
||||||
{
|
|
||||||
case CHIAKI_EVENT_CONNECTED:
|
|
||||||
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_CONNECTED");
|
|
||||||
if(this->chiaki_event_connected_cb != nullptr)
|
|
||||||
this->quit = !this->chiaki_event_connected_cb();
|
|
||||||
else
|
|
||||||
this->quit = false;
|
|
||||||
break;
|
|
||||||
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
|
|
||||||
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_LOGIN_PIN_REQUEST");
|
|
||||||
if(this->chiaki_even_login_pin_request_cb != nullptr)
|
|
||||||
this->quit = !this->chiaki_even_login_pin_request_cb(event->login_pin_request.pin_incorrect);
|
|
||||||
break;
|
|
||||||
case CHIAKI_EVENT_QUIT:
|
|
||||||
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_QUIT");
|
|
||||||
if(this->chiaki_event_quit_cb != nullptr)
|
|
||||||
this->quit = !this->chiaki_event_quit_cb(&event->quit);
|
|
||||||
else
|
|
||||||
this->quit = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool IO::FreeVideo()
|
bool IO::FreeVideo()
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
@ -403,8 +405,7 @@ bool IO::ReadGameTouchScreen(ChiakiControllerState *state)
|
||||||
uint16_t y = touch.py * (DS4_TRACKPAD_MAX_Y / SWITCH_TOUCHSCREEN_MAX_Y);
|
uint16_t y = touch.py * (DS4_TRACKPAD_MAX_Y / SWITCH_TOUCHSCREEN_MAX_Y);
|
||||||
|
|
||||||
// use nintendo switch border's 5% to
|
// use nintendo switch border's 5% to
|
||||||
if(x <= (SWITCH_TOUCHSCREEN_MAX_X * 0.05) || x >= (SWITCH_TOUCHSCREEN_MAX_X * 0.95)
|
if(x <= (SWITCH_TOUCHSCREEN_MAX_X * 0.05) || x >= (SWITCH_TOUCHSCREEN_MAX_X * 0.95) || y <= (SWITCH_TOUCHSCREEN_MAX_Y * 0.05) || y >= (SWITCH_TOUCHSCREEN_MAX_Y * 0.95))
|
||||||
|| y <= (SWITCH_TOUCHSCREEN_MAX_Y * 0.05) || y >= (SWITCH_TOUCHSCREEN_MAX_Y * 0.95))
|
|
||||||
{
|
{
|
||||||
state->buttons |= CHIAKI_CONTROLLER_BUTTON_TOUCHPAD; // touchscreen
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_TOUCHPAD; // touchscreen
|
||||||
// printf("CHIAKI_CONTROLLER_BUTTON_TOUCHPAD\n");
|
// printf("CHIAKI_CONTROLLER_BUTTON_TOUCHPAD\n");
|
||||||
|
@ -479,24 +480,56 @@ bool IO::ReadGameKeys(SDL_Event *event, ChiakiControllerState *state)
|
||||||
// event->jbutton.which, event->jbutton.button);
|
// event->jbutton.which, event->jbutton.button);
|
||||||
switch(event->jbutton.button)
|
switch(event->jbutton.button)
|
||||||
{
|
{
|
||||||
case 0: state->buttons |= CHIAKI_CONTROLLER_BUTTON_MOON; break; // KEY_A
|
case 0:
|
||||||
case 1: state->buttons |= CHIAKI_CONTROLLER_BUTTON_CROSS; break; // KEY_B
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_MOON;
|
||||||
case 2: state->buttons |= CHIAKI_CONTROLLER_BUTTON_PYRAMID; break; // KEY_X
|
break; // KEY_A
|
||||||
case 3: state->buttons |= CHIAKI_CONTROLLER_BUTTON_BOX; break; // KEY_Y
|
case 1:
|
||||||
case 12: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT; break; // KEY_DLEFT
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_CROSS;
|
||||||
case 14: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT; break; // KEY_DRIGHT
|
break; // KEY_B
|
||||||
case 13: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_UP; break; // KEY_DUP
|
case 2:
|
||||||
case 15: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN; break; // KEY_DDOWN
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_PYRAMID;
|
||||||
case 6: state->buttons |= CHIAKI_CONTROLLER_BUTTON_L1; break; // KEY_L
|
break; // KEY_X
|
||||||
case 7: state->buttons |= CHIAKI_CONTROLLER_BUTTON_R1; break; // KEY_R
|
case 3:
|
||||||
case 8: state->l2_state = 0xff; break; // KEY_ZL
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_BOX;
|
||||||
case 9: state->r2_state = 0xff; break; // KEY_ZR
|
break; // KEY_Y
|
||||||
case 4: state->buttons |= CHIAKI_CONTROLLER_BUTTON_L3; break; // KEY_LSTICK
|
case 12:
|
||||||
case 5: state->buttons |= CHIAKI_CONTROLLER_BUTTON_R3; break; // KEY_RSTICK
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT;
|
||||||
case 10: state->buttons |= CHIAKI_CONTROLLER_BUTTON_OPTIONS; break; // KEY_PLUS
|
break; // KEY_DLEFT
|
||||||
|
case 14:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT;
|
||||||
|
break; // KEY_DRIGHT
|
||||||
|
case 13:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_UP;
|
||||||
|
break; // KEY_DUP
|
||||||
|
case 15:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN;
|
||||||
|
break; // KEY_DDOWN
|
||||||
|
case 6:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_L1;
|
||||||
|
break; // KEY_L
|
||||||
|
case 7:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_R1;
|
||||||
|
break; // KEY_R
|
||||||
|
case 8:
|
||||||
|
state->l2_state = 0xff;
|
||||||
|
break; // KEY_ZL
|
||||||
|
case 9:
|
||||||
|
state->r2_state = 0xff;
|
||||||
|
break; // KEY_ZR
|
||||||
|
case 4:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_L3;
|
||||||
|
break; // KEY_LSTICK
|
||||||
|
case 5:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_R3;
|
||||||
|
break; // KEY_RSTICK
|
||||||
|
case 10:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_OPTIONS;
|
||||||
|
break; // KEY_PLUS
|
||||||
// FIXME
|
// FIXME
|
||||||
// case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
// case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
||||||
case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_PS; break; // KEY_MINUS
|
case 11:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_PS;
|
||||||
|
break; // KEY_MINUS
|
||||||
default:
|
default:
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
@ -506,23 +539,55 @@ bool IO::ReadGameKeys(SDL_Event *event, ChiakiControllerState *state)
|
||||||
// event->jbutton.which, event->jbutton.button);
|
// event->jbutton.which, event->jbutton.button);
|
||||||
switch(event->jbutton.button)
|
switch(event->jbutton.button)
|
||||||
{
|
{
|
||||||
case 0: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_MOON; break; // KEY_A
|
case 0:
|
||||||
case 1: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_CROSS; break; // KEY_B
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_MOON;
|
||||||
case 2: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PYRAMID; break; // KEY_X
|
break; // KEY_A
|
||||||
case 3: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_BOX; break; // KEY_Y
|
case 1:
|
||||||
case 12: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT; break; // KEY_DLEFT
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_CROSS;
|
||||||
case 14: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT; break; // KEY_DRIGHT
|
break; // KEY_B
|
||||||
case 13: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_UP; break; // KEY_DUP
|
case 2:
|
||||||
case 15: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN; break; // KEY_DDOWN
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PYRAMID;
|
||||||
case 6: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L1; break; // KEY_L
|
break; // KEY_X
|
||||||
case 7: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R1; break; // KEY_R
|
case 3:
|
||||||
case 8: state->l2_state = 0x00; break; // KEY_ZL
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_BOX;
|
||||||
case 9: state->r2_state = 0x00; break; // KEY_ZR
|
break; // KEY_Y
|
||||||
case 4: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L3; break; // KEY_LSTICK
|
case 12:
|
||||||
case 5: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R3; break; // KEY_RSTICK
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT;
|
||||||
case 10: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_OPTIONS; break; // KEY_PLUS
|
break; // KEY_DLEFT
|
||||||
|
case 14:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT;
|
||||||
|
break; // KEY_DRIGHT
|
||||||
|
case 13:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_UP;
|
||||||
|
break; // KEY_DUP
|
||||||
|
case 15:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN;
|
||||||
|
break; // KEY_DDOWN
|
||||||
|
case 6:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L1;
|
||||||
|
break; // KEY_L
|
||||||
|
case 7:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R1;
|
||||||
|
break; // KEY_R
|
||||||
|
case 8:
|
||||||
|
state->l2_state = 0x00;
|
||||||
|
break; // KEY_ZL
|
||||||
|
case 9:
|
||||||
|
state->r2_state = 0x00;
|
||||||
|
break; // KEY_ZR
|
||||||
|
case 4:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L3;
|
||||||
|
break; // KEY_LSTICK
|
||||||
|
case 5:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R3;
|
||||||
|
break; // KEY_RSTICK
|
||||||
|
case 10:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_OPTIONS;
|
||||||
|
break; // KEY_PLUS
|
||||||
//case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
//case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
||||||
case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PS; break; // KEY_MINUS
|
case 11:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PS;
|
||||||
|
break; // KEY_MINUS
|
||||||
default:
|
default:
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
@ -798,4 +863,3 @@ bool IO::MainLoop(ChiakiControllerState * state)
|
||||||
|
|
||||||
return !this->quit;
|
return !this->quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,9 +134,8 @@ int main(int argc, char * argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// build sdl OpenGl and AV decoders graphical interface
|
// build sdl OpenGl and AV decoders graphical interface
|
||||||
IO io = IO(log); // open Input Output class
|
|
||||||
DiscoveryManager discoverymanager = DiscoveryManager();
|
DiscoveryManager discoverymanager = DiscoveryManager();
|
||||||
MainApplication app = MainApplication(&discoverymanager, &io);
|
MainApplication app = MainApplication(&discoverymanager);
|
||||||
app.Load();
|
app.Load();
|
||||||
|
|
||||||
CHIAKI_LOGI(log, "Quit applet");
|
CHIAKI_LOGI(log, "Quit applet");
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
#if defined(__SWITCH__) && !defined(CHIAKI_ENABLE_SWITCH_NXLINK)
|
#if defined(__SWITCH__)
|
||||||
// null log for switch version
|
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE ^ CHIAKI_LOG_DEBUG, chiaki_log_cb_print, NULL);
|
||||||
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
|
|
||||||
#else
|
#else
|
||||||
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
|
chiaki_log_init(&this->log, CHIAKI_LOG_ALL, chiaki_log_cb_print, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue