mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Use borealis keyboard for the nintendo switch
This commit is contained in:
parent
1ee23e0fa2
commit
0af3ae27d4
7 changed files with 98 additions and 163 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 205e97ab45922fa7f5c9fa6a85d5d686cd50b669
|
Subproject commit cbdc1b65314d1eeb2799deae5cf6f113d6d67b46
|
|
@ -50,10 +50,6 @@ class MainApplication
|
||||||
IO *io;
|
IO *io;
|
||||||
brls::TabFrame *rootFrame;
|
brls::TabFrame *rootFrame;
|
||||||
std::map<Host *, HostInterface *> host_menuitems;
|
std::map<Host *, HostInterface *> host_menuitems;
|
||||||
// add_host local settings
|
|
||||||
std::string remote_display_name = "";
|
|
||||||
std::string remote_addr = "";
|
|
||||||
ChiakiTarget remote_ps_version = CHIAKI_TARGET_PS5_1;
|
|
||||||
|
|
||||||
bool BuildConfigurationMenu(brls::List *, Host *host = nullptr);
|
bool BuildConfigurationMenu(brls::List *, Host *host = nullptr);
|
||||||
void BuildAddHostConfigurationMenu(brls::List *);
|
void BuildAddHostConfigurationMenu(brls::List *);
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Host
|
||||||
public:
|
public:
|
||||||
Host(std::string host_name);
|
Host(std::string host_name);
|
||||||
~Host();
|
~Host();
|
||||||
int Register(std::string pin);
|
int Register(int pin);
|
||||||
int Wakeup();
|
int Wakeup();
|
||||||
int InitSession(IO *);
|
int InitSession(IO *);
|
||||||
int FiniSession();
|
int FiniSession();
|
||||||
|
|
|
@ -102,7 +102,6 @@ class IO
|
||||||
bool FreeVideo();
|
bool FreeVideo();
|
||||||
bool InitJoystick();
|
bool InitJoystick();
|
||||||
bool FreeJoystick();
|
bool FreeJoystick();
|
||||||
bool ReadUserKeyboard(char *buffer, size_t buffer_size);
|
|
||||||
bool MainLoop(ChiakiControllerState *state);
|
bool MainLoop(ChiakiControllerState *state);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -97,42 +97,31 @@ void HostInterface::Register(Host *host, std::function<void()> success_cb)
|
||||||
host->SetRegistEventTypeFinishedFailed(event_type_finished_failed_cb);
|
host->SetRegistEventTypeFinishedFailed(event_type_finished_failed_cb);
|
||||||
|
|
||||||
// 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");
|
// use callback to ensure that the message is showed on screen
|
||||||
brls::GenericEvent::Callback cb_peprpc = [host, io, peprpc](brls::View *view) {
|
// before the Swkbd
|
||||||
bool pin_provided = false;
|
auto pin_input_cb = [host](int pin) {
|
||||||
char pin_input[9] = { 0 };
|
// prevent users form messing with the gui
|
||||||
std::string error_message;
|
brls::Application::blockInputs();
|
||||||
|
int ret = host->Register(pin);
|
||||||
// use callback to ensure that the message is showed on screen
|
if(ret != HOST_REGISTER_OK)
|
||||||
// before the the ReadUserKeyboard
|
|
||||||
peprpc->close();
|
|
||||||
|
|
||||||
pin_provided = io->ReadUserKeyboard(pin_input, sizeof(pin_input));
|
|
||||||
if(pin_provided)
|
|
||||||
{
|
{
|
||||||
// prevent users form messing with the gui
|
switch(ret)
|
||||||
brls::Application::blockInputs();
|
|
||||||
int ret = host->Register(pin_input);
|
|
||||||
if(ret != HOST_REGISTER_OK)
|
|
||||||
{
|
{
|
||||||
switch(ret)
|
// account not configured
|
||||||
{
|
case HOST_REGISTER_ERROR_SETTING_PSNACCOUNTID:
|
||||||
// account not configured
|
brls::Application::notify("No PSN Account ID provided");
|
||||||
case HOST_REGISTER_ERROR_SETTING_PSNACCOUNTID:
|
brls::Application::unblockInputs();
|
||||||
brls::Application::notify("No PSN Account ID provided");
|
break;
|
||||||
brls::Application::unblockInputs();
|
case HOST_REGISTER_ERROR_SETTING_PSNONLINEID:
|
||||||
break;
|
brls::Application::notify("No PSN Online ID provided");
|
||||||
case HOST_REGISTER_ERROR_SETTING_PSNONLINEID:
|
brls::Application::unblockInputs();
|
||||||
brls::Application::notify("No PSN Online ID provided");
|
break;
|
||||||
brls::Application::unblockInputs();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
peprpc->addButton("Ok", cb_peprpc);
|
// the pin is 8 digit
|
||||||
peprpc->setCancelable(false);
|
bool success = brls::Swkbd::openForNumber(pin_input_cb,
|
||||||
peprpc->open();
|
"Please enter your PlayStation registration PIN code", "8 digits without spaces", 8, "", "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostInterface::Register()
|
void HostInterface::Register()
|
||||||
|
@ -327,39 +316,36 @@ bool MainApplication::Load()
|
||||||
bool MainApplication::BuildConfigurationMenu(brls::List *ls, Host *host)
|
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::InputListItem *psn_account_id = new brls::InputListItem("PSN Account ID", psn_account_id_string,
|
||||||
psn_account_id->setValue(psn_account_id_string.c_str());
|
"Account ID in base64 format", "PS5 or PS4 v7.0 and greater", CHIAKI_PSN_ACCOUNT_ID_SIZE * 2,
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_SPACE |
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_AT |
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_PERCENT |
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_BACKSLASH);
|
||||||
|
|
||||||
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 };
|
// retrieve, push and save setting
|
||||||
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
|
this->settings->SetPSNAccountID(host, psn_account_id->getValue());
|
||||||
if(input)
|
// write on disk
|
||||||
{
|
this->settings->WriteFile();
|
||||||
// update gui
|
|
||||||
psn_account_id->setValue(account_id);
|
|
||||||
// push in setting
|
|
||||||
this->settings->SetPSNAccountID(host, account_id);
|
|
||||||
// write on disk
|
|
||||||
this->settings->WriteFile();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
psn_account_id->getClickEvent()->subscribe(psn_account_id_cb);
|
psn_account_id->getClickEvent()->subscribe(psn_account_id_cb);
|
||||||
ls->addView(psn_account_id);
|
ls->addView(psn_account_id);
|
||||||
|
|
||||||
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::InputListItem *psn_online_id = new brls::InputListItem("PSN Online ID",
|
||||||
psn_online_id->setValue(psn_online_id_string.c_str());
|
psn_online_id_string, "", "", 16,
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_SPACE |
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_AT |
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_PERCENT |
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_FORWSLASH |
|
||||||
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_BACKSLASH);
|
||||||
|
|
||||||
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 };
|
// retrieve, push and save setting
|
||||||
bool input = this->io->ReadUserKeyboard(online_id, sizeof(online_id));
|
this->settings->SetPSNOnlineID(host, psn_online_id->getValue());
|
||||||
if(input)
|
// write on disk
|
||||||
{
|
this->settings->WriteFile();
|
||||||
// update gui
|
|
||||||
psn_online_id->setValue(online_id);
|
|
||||||
// push in setting
|
|
||||||
this->settings->SetPSNOnlineID(host, online_id);
|
|
||||||
// write on disk
|
|
||||||
this->settings->WriteFile();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
psn_online_id->getClickEvent()->subscribe(psn_online_id_cb);
|
psn_online_id->getClickEvent()->subscribe(psn_online_id_cb);
|
||||||
ls->addView(psn_online_id);
|
ls->addView(psn_online_id);
|
||||||
|
@ -465,34 +451,24 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List *add_host)
|
||||||
// brls::Label* add_host_label = new brls::Label(brls::LabelStyle::REGULAR,
|
// brls::Label* add_host_label = new brls::Label(brls::LabelStyle::REGULAR,
|
||||||
// "Add Host configuration", true);
|
// "Add Host configuration", true);
|
||||||
|
|
||||||
brls::ListItem *display_name = new brls::ListItem("Display name");
|
brls::InputListItem *display_name = new brls::InputListItem("Display name",
|
||||||
auto display_name_cb = [this, display_name](brls::View *view) {
|
"default", "configuration name", "", 16,
|
||||||
char name[16] = { 0 };
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_SPACE |
|
||||||
bool input = this->io->ReadUserKeyboard(name, sizeof(name));
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_AT |
|
||||||
if(input)
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_PERCENT |
|
||||||
{
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_FORWSLASH |
|
||||||
// update gui
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_BACKSLASH);
|
||||||
display_name->setValue(name);
|
|
||||||
// set internal value
|
|
||||||
this->remote_display_name = name;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
display_name->getClickEvent()->subscribe(display_name_cb);
|
|
||||||
add_host->addView(display_name);
|
add_host->addView(display_name);
|
||||||
|
|
||||||
brls::ListItem *address = new brls::ListItem("Remote IP/name");
|
brls::InputListItem *address = new brls::InputListItem("Remote IP/name",
|
||||||
auto address_cb = [this, address](brls::View *view) {
|
"", "IP address or fqdn", "", 255,
|
||||||
char addr[256] = { 0 };
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_SPACE |
|
||||||
bool input = this->io->ReadUserKeyboard(addr, sizeof(addr));
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_AT |
|
||||||
if(input)
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_PERCENT |
|
||||||
{
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_FORWSLASH |
|
||||||
// update gui
|
brls::KeyboardKeyDisableBitmask::KEYBOARD_DISABLE_BACKSLASH);
|
||||||
address->setValue(addr);
|
|
||||||
// set internal value
|
|
||||||
this->remote_addr = addr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
address->getClickEvent()->subscribe(address_cb);
|
|
||||||
add_host->addView(address);
|
add_host->addView(address);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -501,46 +477,48 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List *add_host)
|
||||||
// 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) {
|
|
||||||
switch(result)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
// ps5 v1
|
|
||||||
this->remote_ps_version = CHIAKI_TARGET_PS5_1;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
// ps4 v8
|
|
||||||
this->remote_ps_version = CHIAKI_TARGET_PS4_10;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
// ps4 v7
|
|
||||||
this->remote_ps_version = CHIAKI_TARGET_PS4_9;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
// ps4 v6
|
|
||||||
this->remote_ps_version = CHIAKI_TARGET_PS4_8;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ps_version->getValueSelectedEvent()->subscribe(ps_version_cb);
|
|
||||||
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, display_name, address, ps_version](brls::View *view) {
|
||||||
bool err = false;
|
bool err = false;
|
||||||
if(this->remote_display_name.length() <= 0)
|
std::string dn = display_name->getValue();
|
||||||
|
std::string addr = address->getValue();
|
||||||
|
ChiakiTarget version = CHIAKI_TARGET_PS4_UNKNOWN;
|
||||||
|
|
||||||
|
switch(ps_version->getSelectedValue())
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
// ps5 v1
|
||||||
|
version = CHIAKI_TARGET_PS5_1;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
// ps4 v8
|
||||||
|
version = CHIAKI_TARGET_PS4_10;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// ps4 v7
|
||||||
|
version = CHIAKI_TARGET_PS4_9;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// ps4 v6
|
||||||
|
version = CHIAKI_TARGET_PS4_8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dn.length() <= 0)
|
||||||
{
|
{
|
||||||
brls::Application::notify("No Display name defined");
|
brls::Application::notify("No Display name defined");
|
||||||
err = true;
|
err = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->remote_addr.length() <= 0)
|
if(addr.length() <= 0)
|
||||||
{
|
{
|
||||||
brls::Application::notify("No Remote address provided");
|
brls::Application::notify("No Remote address provided");
|
||||||
err = true;
|
err = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->remote_ps_version < 0)
|
if(version <= CHIAKI_TARGET_PS4_UNKNOWN)
|
||||||
{
|
{
|
||||||
brls::Application::notify("No PlayStation Version provided");
|
brls::Application::notify("No PlayStation Version provided");
|
||||||
err = true;
|
err = true;
|
||||||
|
@ -549,10 +527,9 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List *add_host)
|
||||||
if(err)
|
if(err)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Host *host = this->settings->GetOrCreateHost(&this->remote_display_name);
|
Host *host = this->settings->GetOrCreateHost(&dn);
|
||||||
host->SetHostAddr(this->remote_addr);
|
host->SetHostAddr(addr);
|
||||||
host->SetChiakiTarget(this->remote_ps_version);
|
host->SetChiakiTarget(version);
|
||||||
|
|
||||||
HostInterface::Register(host);
|
HostInterface::Register(host);
|
||||||
};
|
};
|
||||||
register_host->getClickEvent()->subscribe(register_host_cb);
|
register_host->getClickEvent()->subscribe(register_host_cb);
|
||||||
|
|
|
@ -72,7 +72,7 @@ int Host::Wakeup()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Host::Register(std::string pin)
|
int Host::Register(int pin)
|
||||||
{
|
{
|
||||||
// use pin and accont_id to negociate secrets for session
|
// use pin and accont_id to negociate secrets for session
|
||||||
//
|
//
|
||||||
|
@ -103,7 +103,7 @@ int Host::Register(std::string pin)
|
||||||
if(online_id.length() > 0)
|
if(online_id.length() > 0)
|
||||||
{
|
{
|
||||||
regist_info.psn_online_id = this->psn_online_id.c_str();
|
regist_info.psn_online_id = this->psn_online_id.c_str();
|
||||||
// regist_info.psn_account_id = {0};
|
// regist_info.psn_account_id = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -117,16 +117,15 @@ int Host::Register(std::string pin)
|
||||||
throw Exception("Undefined PS4 system version (please run discover first)");
|
throw Exception("Undefined PS4 system version (please run discover first)");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->regist_info.pin = atoi(pin.c_str());
|
|
||||||
this->regist_info.host = this->host_addr.c_str();
|
this->regist_info.host = this->host_addr.c_str();
|
||||||
this->regist_info.broadcast = false;
|
this->regist_info.broadcast = false;
|
||||||
|
|
||||||
if(this->target >= CHIAKI_TARGET_PS4_9)
|
if(this->target >= CHIAKI_TARGET_PS4_9)
|
||||||
CHIAKI_LOGI(this->log, "Registering to host `%s` `%s` with PSN AccountID `%s` pin `%s`",
|
CHIAKI_LOGI(this->log, "Registering to host `%s` `%s` with PSN AccountID `%s` pin `%d`",
|
||||||
this->host_name.c_str(), this->host_addr.c_str(), account_id.c_str(), pin.c_str());
|
this->host_name.c_str(), this->host_addr.c_str(), account_id.c_str(), pin);
|
||||||
else
|
else
|
||||||
CHIAKI_LOGI(this->log, "Registering to host `%s` `%s` with PSN OnlineID `%s` pin `%s`",
|
CHIAKI_LOGI(this->log, "Registering to host `%s` `%s` with PSN OnlineID `%s` pin `%d`",
|
||||||
this->host_name.c_str(), this->host_addr.c_str(), online_id.c_str(), pin.c_str());
|
this->host_name.c_str(), this->host_addr.c_str(), online_id.c_str(), pin);
|
||||||
|
|
||||||
chiaki_regist_start(&this->regist, this->log, &this->regist_info, RegistEventCB, this);
|
chiaki_regist_start(&this->regist, this->log, &this->regist_info, RegistEventCB, this);
|
||||||
return HOST_REGISTER_OK;
|
return HOST_REGISTER_OK;
|
||||||
|
|
|
@ -345,42 +345,6 @@ bool IO::FreeVideo()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IO::ReadUserKeyboard(char *buffer, size_t buffer_size)
|
|
||||||
{
|
|
||||||
#ifndef __SWITCH__
|
|
||||||
// use cin to get user input from linux
|
|
||||||
std::cin.getline(buffer, buffer_size);
|
|
||||||
CHIAKI_LOGI(this->log, "Got user input: %s\n", buffer);
|
|
||||||
#else
|
|
||||||
// https://kvadevack.se/post/nintendo-switch-virtual-keyboard/
|
|
||||||
SwkbdConfig kbd;
|
|
||||||
Result rc = swkbdCreate(&kbd, 0);
|
|
||||||
|
|
||||||
if(R_SUCCEEDED(rc))
|
|
||||||
{
|
|
||||||
swkbdConfigMakePresetDefault(&kbd);
|
|
||||||
rc = swkbdShow(&kbd, buffer, buffer_size);
|
|
||||||
|
|
||||||
if(R_SUCCEEDED(rc))
|
|
||||||
{
|
|
||||||
CHIAKI_LOGI(this->log, "Got user input: %s\n", buffer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CHIAKI_LOGE(this->log, "swkbdShow() error: %u\n", rc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
swkbdClose(&kbd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CHIAKI_LOGE(this->log, "swkbdCreate() error: %u\n", rc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IO::ReadGameTouchScreen(ChiakiControllerState *state)
|
bool IO::ReadGameTouchScreen(ChiakiControllerState *state)
|
||||||
{
|
{
|
||||||
#ifdef __SWITCH__
|
#ifdef __SWITCH__
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue