static int lua_eg(lua_State *L) { int argc = lua_gettop(L); #ifndef SKIP_ERROR_HANDLING if (argc != 0) return luaL_error(L, "wrong number of arguments."); #endif HIDUSER_EnableGyroscope(); return 0; }
int joystickGetAxes(lua_State *L) { love_joystick *self = luaobj_checkudata(L, 1, CLASS_TYPE); int numAxesCheck = lua_gettop(L); for (int i = 2; i <= numAxesCheck; i++) { int axisId = luaL_checkinteger(L, i); if( axisId < 5 ) { // Circle Axes circlePosition circleData; hidCircleRead(&circleData); if( axisId == 1 ) lua_pushinteger(L, circleData.dx); if( axisId == 2 ) lua_pushinteger(L, circleData.dy); circlePosition cStickData; irrstCstickRead(&cStickData); if( axisId == 3 ) lua_pushinteger(L, cStickData.dx); if( axisId == 4 ) lua_pushinteger(L, cStickData.dy); } else if( axisId < 8 ) { // Gyro Axes HIDUSER_EnableGyroscope(); angularRate gyroData; hidGyroRead(&gyroData); if( axisId == 5 ) lua_pushinteger(L, gyroData.x); if( axisId == 6 ) lua_pushinteger(L, gyroData.y); if( axisId == 7 ) lua_pushinteger(L, gyroData.z); } else if ( axisId < 11 ) { // Accelloremeter Axes HIDUSER_EnableAccelerometer(); accelVector accelData; hidAccelRead(&accelData); if( axisId == 8 ) lua_pushinteger(L, accelData.x); if( axisId == 9 ) lua_pushinteger(L, accelData.y); if( axisId == 10 ) lua_pushinteger(L, accelData.z); } else { luaError(L, "AxisId out of bounds"); } } return numAxesCheck-1; }
void Sensor::setEnabled(Type sensor, bool enabled) { #ifndef EMULATION if (sensor == Sensor::Gyroscope && enabled != m_gyro_enabled) { m_gyro_enabled = enabled; if (enabled) HIDUSER_EnableGyroscope(); else HIDUSER_DisableGyroscope(); } else if (sensor == Sensor::Accelerometer && enabled != m_accel_enabled) { m_accel_enabled = enabled; if (enabled) HIDUSER_EnableAccelerometer(); else HIDUSER_DisableAccelerometer(); } #endif }
int joystickGetAxis(lua_State *L) { love_joystick *self = luaobj_checkudata(L, 1, CLASS_TYPE); int axisId = luaL_checkinteger(L, 2); if( axisId < 3 ) { // Circle Axes circlePosition circleData; hidCircleRead(&circleData); if( axisId == 1 ) lua_pushinteger(L, circleData.dx); if( axisId == 2 ) lua_pushinteger(L, circleData.dy); } else if( axisId < 6 ) { // Gyro Axes HIDUSER_EnableGyroscope(); angularRate gyroData; hidGyroRead(&gyroData); if( axisId == 3 ) lua_pushinteger(L, gyroData.x); if( axisId == 4 ) lua_pushinteger(L, gyroData.y); if( axisId == 5 ) lua_pushinteger(L, gyroData.z); } else if ( axisId < 9 ) { // Accelloremeter Axes HIDUSER_EnableAccelerometer(); accelVector accelData; hidAccelRead(&accelData); if( axisId == 6 ) lua_pushinteger(L, accelData.x); if( axisId == 7 ) lua_pushinteger(L, accelData.y); if( axisId == 8 ) lua_pushinteger(L, accelData.z); } else { luaError(L, "AxisId out of bounds"); } return 1; }
int main(int argc, char **argv){ // Initialize services gfxInitDefault(); //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one consoleInit(GFX_TOP, NULL); int alevel=0, glevel = 0; //print GyroscopeRawToDpsCoefficient float gyroCoef; HIDUSER_GetGyroscopeRawToDpsCoefficient_(&gyroCoef); printf("\x1b[0;0HGyroCoef:%f", gyroCoef); //print GyroscopeLowCalibrateParam u8 Calibrate[20]; HIDUSER_GetGyroscopeLowCalibrateParam(Calibrate); for(int i = 0; i<3; ++i){ printf("\x1b[%d;0HGyroCalibrate(%d):", i+1, i+1); for(int j = 0; j<6; ++j){ printf("%02X ", Calibrate[i*6+j]); } } printf("\x1b[13;0HPad:\n"); printf("A:call EnableGyroscope\n"); printf("B:call DisableGyroscope\n"); printf("X:call EnableAccelerometer\n"); printf("Y:call DisableAccelerometer\n"); Result result=0; while(aptMainLoop()){ hidScanInput(); u32 kDown = hidKeysDown(); if(kDown & KEY_START) break; // break in order to return to hbmenu if(kDown & KEY_A){ ++glevel; result=HIDUSER_EnableGyroscope(); } if(kDown & KEY_B){ --glevel; result = HIDUSER_DisableGyroscope(); } if(kDown & KEY_X){ ++alevel; result = HIDUSER_EnableAccelerometer(); } if(kDown & KEY_Y){ --alevel; result = HIDUSER_DisableAccelerometer(); } //Read gyro data myAngularRate gyro; hidGyroRead((angularRate*)&gyro); printf("\x1b[5;0Hgyro(level=%3d)%6d;%6d;%6d",glevel, gyro.x, gyro.y, gyro.z); //Read raw gyro data gyro = *(myAngularRate*)&hidSharedMem[86+6]; printf("\x1b[6;0Hgyro(raw )%6d;%6d;%6d", gyro.x, gyro.y, gyro.z); //Read accel data accelVector vector; hidAccelRead(&vector); printf("\x1b[7;0Hacce(level=%3d)%6d;%6d;%6d",alevel, vector.x, vector.y, vector.z); //Read raw accel vector = *(accelVector*)&hidSharedMem[66+6]; printf("\x1b[8;0Hacce(raw )%6d;%6d;%6d", vector.x, vector.y, vector.z); //test if gyro and accel events are activated printf("\x1b[9;0Hgyro event: %s", hidTryWaitForEvent(HIDEVENT_Gyro, 10000000) ? "true " : "false"); printf("\x1b[10;0Hacce event: %s", hidTryWaitForEvent(HIDEVENT_Accel, 10000000)?"true ":"false"); //print the last result of enable/disable gyroscope/accelerometer call printf("\x1b[11;0Henable/disable call result=%08lX", result); // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); //Wait for VBlank gspWaitForVBlank(); } // Exit services gfxExit(); return 0; }
static void _setup(struct GBAGUIRunner* runner) { struct GBAOptions opts = { .useBios = true, .logLevel = 0, .idleOptimization = IDLE_LOOP_DETECT }; GBAConfigLoadDefaults(&runner->context.config, &opts); runner->context.gba->logHandler = GBA3DSLog; runner->context.gba->rotationSource = &rotation.d; if (hasSound) { runner->context.gba->stream = &stream; } GBAVideoSoftwareRendererCreate(&renderer); renderer.outputBuffer = linearAlloc(256 * VIDEO_VERTICAL_PIXELS * 2); renderer.outputBufferStride = 256; runner->context.renderer = &renderer.d; GBAAudioResizeBuffer(&runner->context.gba->audio, AUDIO_SAMPLES); } static void _gameLoaded(struct GBAGUIRunner* runner) { if (runner->context.gba->memory.hw.devices & HW_TILT) { HIDUSER_EnableAccelerometer(); } if (runner->context.gba->memory.hw.devices & HW_GYRO) { HIDUSER_EnableGyroscope(); } #if RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF double ratio = GBAAudioCalculateRatio(1, 60, 1); blip_set_rates(runner->context.gba->audio.left, GBA_ARM7TDMI_FREQUENCY, 0x8000 * ratio); blip_set_rates(runner->context.gba->audio.right, GBA_ARM7TDMI_FREQUENCY, 0x8000 * ratio); #endif if (hasSound) { memset(audioLeft, 0, AUDIO_SAMPLES * sizeof(int16_t)); memset(audioRight, 0, AUDIO_SAMPLES * sizeof(int16_t)); } } static void _gameUnloaded(struct GBAGUIRunner* runner) { if (hasSound) { CSND_SetPlayState(8, 0); CSND_SetPlayState(9, 0); csndExecCmds(false); } if (runner->context.gba->memory.hw.devices & HW_TILT) { HIDUSER_DisableAccelerometer(); } if (runner->context.gba->memory.hw.devices & HW_GYRO) { HIDUSER_DisableGyroscope(); } } static void _drawFrame(struct GBAGUIRunner* runner, bool faded) { GX_SetDisplayTransfer(0, renderer.outputBuffer, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), tex->data, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), 0x000002202); GSPGPU_FlushDataCache(0, tex->data, 256 * VIDEO_VERTICAL_PIXELS * 2); #if RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF if (!hasSound) { blip_clear(runner->context.gba->audio.left); blip_clear(runner->context.gba->audio.right); } #endif gspWaitForPPF(); _drawStart(); sf2d_draw_texture_scale_blend(tex, 40, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0)); _drawEnd(); }