Ejemplo n.º 1
0
static int lua_ea(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_EnableAccelerometer();
	return 0;
}
Ejemplo n.º 2
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;
	
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
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;
	
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
    (void) argc, (void) argv;

    Result res = MAKERESULT(RL_SUCCESS, RS_SUCCESS, 0, RD_SUCCESS);

    gfxInitDefault();

    PrintConsole top;
    consoleInit(GFX_TOP, &top);

    util_debug_init();
    consoleSelect(&top);

    if (R_FAILED(res = acInit())) {
        util_presult("acInit failed", res);
        goto ac_failure;
    }

    u32 wifi = 0;
    if (R_FAILED(res = ACU_GetWifiStatus(&wifi))) {
        util_presult("ACU_GetWifiStatus failed", res);
        fprintf(stderr, "Did you enable Wifi?\n");
        goto wifi_check_failure;
    }
    if (!wifi) {
        fprintf(stderr, "Wifi disabled.\n");
        goto wifi_check_failure;
    }

    if ((sock_ctx = memalign(SOCU_BUFSZ, SOCU_ALIGN)) == NULL) {
        util_perror("Allocating SOC buffer");
        res = MAKERESULT(
            RL_PERMANENT, RS_OUTOFRESOURCE, RM_SOC, RD_OUT_OF_MEMORY);
        goto soc_alloc_failure;
    }

    if (R_FAILED(res = socInit(sock_ctx, SOCU_BUFSZ))) {
        util_presult("socInit failed", res);
        goto soc_failure;
    }

    if (R_FAILED(res = hidInit())) {
        util_presult("hidInit failed", res);
        goto hid_failure;
    }
    if (R_FAILED(res = HIDUSER_EnableAccelerometer())) {
        util_presult("Failed to enable accelerometer", res);
        goto accel_failure;
    }

    if (R_FAILED(res = ctrollerInit())) {
        fprintf(stderr, "Do you have a valid IP in\n '" CFG_FILE "'?");
        goto failure;
    }

    bool isHomebrew = envIsHomebrew();
    printf("Press %s to exit.\n", isHomebrew ? EXIT_DESC : "HOME");
    fflush(stdout);

    while (aptMainLoop()) {

        if (isHomebrew) {
            if (hidKeysHeld() == EXIT_KEYS) {
                res = RL_SUCCESS;
                break;
            }
        }

        if (ctrollerSendHIDInfo()) {
            util_perror("Sending HID info");
            fflush(stderr);
            for (int i = 3; i > 0; i--) {
                util_debug_printf("\rRetrying in %ds... ", i);
                svcSleepThread(1000000000L);
            }
            util_debug_printf("\rRetrying now.\x1b[K\n");
        }

        gspWaitForVBlank();

        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    puts("Exiting...");
failure:
    HIDUSER_DisableAccelerometer();
accel_failure:
    hidExit();
hid_failure:
    socExit();
soc_failure:
    free(sock_ctx);
soc_alloc_failure:
wifi_check_failure:
    acExit();
ac_failure:
    if (R_FAILED(res)) {
        util_hang(res);
    }
    gfxExit();
    return res;
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: yuriks/mgba
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();
}