implement setting region through the UI/pipe

This commit is contained in:
itsmattkc
2024-06-19 11:58:02 -07:00
parent fcc2f10bef
commit 08cfaedfed
10 changed files with 76 additions and 20 deletions
+13
View File
@@ -173,6 +173,19 @@ void Backend::setButton(int button, int32_t value)
}
}
void Backend::setRegion(int region)
{
if (m_pipe) {
m_pipeMutex.lock();
writeByte(m_pipeOut, VANILLA_PIPE_IN_REGION);
int8_t regionSized = region;
write(m_pipeOut, &regionSized, sizeof(regionSized));
m_pipeMutex.unlock();
} else {
vanilla_set_region(region);
}
}
void Backend::sync(const QString &wirelessInterface, uint16_t code)
{
if (m_pipe) {
+1
View File
@@ -55,6 +55,7 @@ public slots:
void updateTouch(int x, int y);
void setButton(int button, int32_t value);
void requestIDR();
void setRegion(int region);
private:
BackendPipe *m_pipe;
+17 -9
View File
@@ -102,16 +102,18 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
m_regionComboBox = new QComboBox(settingsGroupBox);
m_regionComboBox->addItem(tr("Japan"));
m_regionComboBox->addItem(tr("North America"));
m_regionComboBox->addItem(tr("Europe"));
m_regionComboBox->addItem(tr("China (Unused)"));
m_regionComboBox->addItem(tr("South Korea (Unused)"));
m_regionComboBox->addItem(tr("Taiwan (Unused)"));
m_regionComboBox->addItem(tr("Australia (Unused)"));
m_regionComboBox->addItem(tr("Japan"), VANILLA_REGION_JAPAN);
m_regionComboBox->addItem(tr("North America"), VANILLA_REGION_AMERICA);
m_regionComboBox->addItem(tr("Europe"), VANILLA_REGION_EUROPE);
m_regionComboBox->addItem(tr("China (Unused)"), VANILLA_REGION_CHINA);
m_regionComboBox->addItem(tr("South Korea (Unused)"), VANILLA_REGION_SOUTH_KOREA);
m_regionComboBox->addItem(tr("Taiwan (Unused)"), VANILLA_REGION_TAIWAN);
m_regionComboBox->addItem(tr("Australia (Unused)"), VANILLA_REGION_AUSTRALIA);
// TODO: Should probably save this somewhere
m_regionComboBox->setCurrentIndex(1);
// TODO: Should probably save/load this from a config file
m_regionComboBox->setCurrentIndex(VANILLA_REGION_AMERICA);
connect(m_regionComboBox, &QComboBox::currentIndexChanged, this, &MainWindow::updateRegion);
configLayout->addWidget(m_regionComboBox, row, 1);
}
@@ -337,6 +339,7 @@ void MainWindow::setConnectedState(bool on)
QMetaObject::invokeMethod(m_backend, "connectToConsole", Qt::QueuedConnection, Q_ARG(QString, m_wirelessInterfaceComboBox->currentText()));
updateVolumeAxis();
updateRegion();
} else {
if (m_backend) {
m_backend->interrupt();
@@ -426,4 +429,9 @@ void MainWindow::takeScreenshot()
}
ss.save(s);
}
}
void MainWindow::updateRegion()
{
m_backend->setRegion(m_regionComboBox->currentData().toInt());
}
+2
View File
@@ -70,6 +70,8 @@ private slots:
void volumeChanged(int val);
void updateRegion();
void showInputConfigDialog();
void recordingError(int err);
+7 -11
View File
@@ -53,16 +53,11 @@ typedef struct
static_assert(offsetof(GenericPacket, generic_cmd_header) == 0x8);
static_assert(sizeof(GenericPacket) == 0x61C);
enum Region
int current_region = VANILLA_REGION_AMERICA;
void set_region(int region)
{
REGION_JAPAN = 0,
REGION_AMERICA = 1,
REGION_EUROPE = 2,
REGION_CHINA = 3,
REGION_SOUTH_KOREA = 4,
REGION_TAIWAN = 5,
REGION_AUSTRALIA = 6,
};
current_region = region;
}
typedef struct
{
@@ -265,8 +260,9 @@ void handle_generic_packet(int skt, GenericPacket *request)
EEPROM *e = (EEPROM *)&response.payload[4];
// TODO make this configurable
e->region = REGION_EUROPE;//REGION_AMERICA;//REGION_JAPAN;
print_info("Setting region to: %i", current_region);
e->region = current_region;
e->region_crc = crc16(&e->region, sizeof(e->region));
e->touchpad_calibration.new_min_x = htons(0);
+2
View File
@@ -3,4 +3,6 @@
void *listen_command(void *x);
void set_region(int region);
#endif // GAMEPAD_COMMAND_H
+6
View File
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <wpa_ctrl.h>
#include "gamepad/command.h"
#include "gamepad/gamepad.h"
#include "gamepad/input.h"
#include "gamepad/video.h"
@@ -139,4 +140,9 @@ void vanilla_retrieve_sps_pps_data(void *data, size_t *size)
memcpy(data, sps_pps_params, MIN(*size, sizeof(sps_pps_params)));
}
*size = sizeof(sps_pps_params);
}
void vanilla_set_region(int region)
{
set_region(region);
}
+20
View File
@@ -64,6 +64,17 @@ enum VanillaEvent
VANILLA_EVENT_VIBRATE
};
enum VanillaRegion
{
VANILLA_REGION_JAPAN = 0,
VANILLA_REGION_AMERICA = 1,
VANILLA_REGION_EUROPE = 2,
VANILLA_REGION_CHINA = 3,
VANILLA_REGION_SOUTH_KOREA = 4,
VANILLA_REGION_TAIWAN = 5,
VANILLA_REGION_AUSTRALIA = 6,
};
/**
* Event handler used by caller to receive events
*/
@@ -142,6 +153,15 @@ void vanilla_request_idr();
*/
void vanilla_retrieve_sps_pps_data(void *data, size_t *size);
/**
* Sets the region Vanilla should present itself to the console
*
* The gamepad is region locked and the console will complain if the gamepad doesn't match.
*
* Set to a member of the VanillaRegion enum.
*/
void vanilla_set_region(int region);
#if defined(__cplusplus)
}
#endif
+7
View File
@@ -244,6 +244,13 @@ int main()
vanilla_request_idr();
break;
}
case VANILLA_PIPE_IN_REGION:
{
int8_t region;
read(fd_in, &region, sizeof(region));
vanilla_set_region(region);
break;
}
case VANILLA_PIPE_IN_QUIT:
m_quit = 1;
break;
+1
View File
@@ -7,6 +7,7 @@
#define VANILLA_PIPE_IN_BUTTON 0x03
#define VANILLA_PIPE_IN_TOUCH 0x04
#define VANILLA_PIPE_IN_REQ_IDR 0x05
#define VANILLA_PIPE_IN_REGION 0x06
#define VANILLA_PIPE_IN_INTERRUPT 0x1E
#define VANILLA_PIPE_IN_QUIT 0x1F