Switch: Rotation support

This commit is contained in:
Vicki Pfau 2018-09-30 14:05:06 -07:00
parent b192330166
commit 1247dec1ba
2 changed files with 41 additions and 0 deletions

View File

@ -103,6 +103,7 @@ Features:
- Libretro: Add Game Boy cheat support
- Qt: Separate fast forward volume control (fixes mgba.io/i/846, mgba.io/i/1143)
- Switch: Rumble support
- Switch: Rotation support
Bugfixes:
- PSP2: Fix audio crackling after fast forward
- PSP2: Fix audio crackling when buffer is full

View File

@ -81,6 +81,7 @@ static struct mSwitchRumble {
int down;
HidVibrationValue value;
} rumble;
static struct mRotationSource rotation = {0};
static int audioBufferActive;
static struct GBAStereoSample audioBuffer[N_BUFFERS][SAMPLES] __attribute__((__aligned__(0x1000)));
static AudioOutBuffer audoutBuffer[N_BUFFERS];
@ -235,6 +236,7 @@ static void _setup(struct mGUIRunner* runner) {
runner->core->setVideoBuffer(runner->core, frameBuffer, 256);
runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d);
runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation);
runner->core->setAVStream(runner->core, &stream);
}
@ -403,6 +405,27 @@ void _setRumble(struct mRumble* rumble, int enable) {
}
}
int32_t _readTiltX(struct mRotationSource* source) {
UNUSED(source);
SixAxisSensorValues sixaxis;
hidSixAxisSensorValuesRead(&sixaxis, CONTROLLER_P1_AUTO, 1);
return sixaxis.accelerometer.x * 3e8f;
}
int32_t _readTiltY(struct mRotationSource* source) {
UNUSED(source);
SixAxisSensorValues sixaxis;
hidSixAxisSensorValuesRead(&sixaxis, CONTROLLER_P1_AUTO, 1);
return sixaxis.accelerometer.y * -3e8f;
}
int32_t _readGyroZ(struct mRotationSource* source) {
UNUSED(source);
SixAxisSensorValues sixaxis;
hidSixAxisSensorValuesRead(&sixaxis, CONTROLLER_P1_AUTO, 1);
return sixaxis.gyroscope.z * 1.1e9f;
}
static int _batteryState(void) {
u32 charge;
int state = 0;
@ -509,6 +532,18 @@ int main(int argc, char* argv[]) {
hidInitializeVibrationDevices(&vibrationDeviceHandles[0], 2, CONTROLLER_HANDHELD, TYPE_HANDHELD | TYPE_JOYCON_PAIR);
hidInitializeVibrationDevices(&vibrationDeviceHandles[2], 2, CONTROLLER_PLAYER_1, TYPE_HANDHELD | TYPE_JOYCON_PAIR);
u32 handles[4];
hidGetSixAxisSensorHandles(&handles[0], 2, CONTROLLER_PLAYER_1, TYPE_JOYCON_PAIR);
hidGetSixAxisSensorHandles(&handles[2], 1, CONTROLLER_PLAYER_1, TYPE_PROCONTROLLER);
hidGetSixAxisSensorHandles(&handles[3], 1, CONTROLLER_HANDHELD, TYPE_HANDHELD);
hidStartSixAxisSensor(handles[0]);
hidStartSixAxisSensor(handles[1]);
hidStartSixAxisSensor(handles[2]);
hidStartSixAxisSensor(handles[3]);
rotation.readTiltX = _readTiltX;
rotation.readTiltY = _readTiltY;
rotation.readGyroZ = _readGyroZ;
stream.videoDimensionsChanged = NULL;
stream.postVideoFrame = NULL;
stream.postAudioFrame = NULL;
@ -648,6 +683,11 @@ int main(int argc, char* argv[]) {
glDeleteProgram(program);
glDeleteVertexArrays(1, &vao);
hidStopSixAxisSensor(handles[0]);
hidStopSixAxisSensor(handles[1]);
hidStopSixAxisSensor(handles[2]);
hidStopSixAxisSensor(handles[3]);
psmExit();
audoutExit();
deinitEgl();