Switch: Rotation support
Vicki Pfau vi@endrift.com
Sun, 30 Sep 2018 14:05:06 -0700
2 files changed,
41 insertions(+),
0 deletions(-)
M
CHANGES
→
CHANGES
@@ -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
M
src/platform/switch/main.c
→
src/platform/switch/main.c
@@ -81,6 +81,7 @@ int up;
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 @@ _mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_R, GBA_KEY_R);
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 @@ ++sr->down;
} } +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;@@ -508,6 +531,18 @@ rumble.value.freq_low = 120.0;
rumble.value.freq_high = 180.0; 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;@@ -647,6 +682,11 @@ glDeleteTextures(1, &tex);
glDeleteBuffers(1, &vbo); glDeleteProgram(program); glDeleteVertexArrays(1, &vao); + + hidStopSixAxisSensor(handles[0]); + hidStopSixAxisSensor(handles[1]); + hidStopSixAxisSensor(handles[2]); + hidStopSixAxisSensor(handles[3]); psmExit(); audoutExit();