Пример #1
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;
	
}
Пример #2
0
static int lua_gyro(lua_State *L)
{
	int argc = lua_gettop(L);
	#ifndef SKIP_ERROR_HANDLING
       if (argc != 0) return luaL_error(L, "wrong number of arguments.");
	#endif
	angularRate cpos;
	hidGyroRead(&cpos);
	lua_pushnumber(L, cpos.x);
	lua_pushnumber(L, cpos.y);
	lua_pushnumber(L, cpos.z);
    return 3;
}
Пример #3
0
int hidCollectData(struct hidInfo *info)
{
    info->keys.up   = hidKeysUp();
    info->keys.down = hidKeysDown();
    info->keys.held = hidKeysHeld();

    hidTouchRead(&info->touchscreen);
    hidCircleRead(&info->circlepad);
    hidGyroRead(&info->gyro);
    hidCstickRead(&info->cstick);

    return 0;
}
Пример #4
0
void Sensor::update()
{
	#ifndef EMULATION
	if(m_gyro_enabled) {
		angularRate gyro;
		hidGyroRead(&gyro);
		m_gyro = Vector3f{gyro.x/100.f, gyro.y/100.f, gyro.z/100.f};
	}
	if(m_accel_enabled) {
		accelVector accel;
		hidAccelRead(&accel);
		m_accel = {accel.x/100.f, accel.y/100.f, accel.z/100.f};
	}
	#endif
}
Пример #5
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;
	
}
Пример #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;
}