1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Added all the other hid functions

This commit is contained in:
Firew0lf 2015-08-18 18:42:56 +02:00
parent d21906c684
commit 12a315b738
2 changed files with 73 additions and 2 deletions

View file

@ -74,8 +74,72 @@ static int hid_read(lua_State *L) {
return 1; return 1;
} }
static int hid_touch(lua_State *L) {
hidScanInput();
touchPosition pos;
hidTouchRead(&pos);
lua_pushinteger(L, (lua_Integer)pos.px);
lua_pushinteger(L, (lua_Integer)pos.py);
return 2;
}
static int hid_circle(lua_State *L) {
hidScanInput();
circlePosition pos;
hidCircleRead(&pos);
lua_pushinteger(L, (lua_Integer)pos.dx);
lua_pushinteger(L, (lua_Integer)pos.dy);
return 2;
}
static int hid_accel(lua_State *L) {
hidScanInput();
accelVector pos;
hidAccelRead(&pos);
lua_pushinteger(L, (lua_Integer)pos.x);
lua_pushinteger(L, (lua_Integer)pos.y);
lua_pushinteger(L, (lua_Integer)pos.z);
return 3;
}
static int hid_gyro(lua_State *L) {
hidScanInput();
angularRate pos;
hidGyroRead(&pos);
lua_pushinteger(L, (lua_Integer)pos.x);
lua_pushinteger(L, (lua_Integer)pos.y);
lua_pushinteger(L, (lua_Integer)pos.z);
return 3;
}
static int hid_volume(lua_State *L) {
u8 volume = 0;
HIDUSER_GetSoundVolume(&volume);
lua_pushinteger(L, (lua_Integer)volume);
return 1;
}
static const struct luaL_Reg hid_lib[] = { static const struct luaL_Reg hid_lib[] = {
{ "read", hid_read }, { "read", hid_read },
{ "touch", hid_touch },
{ "circle", hid_circle },
{ "accel", hid_accel },
{ "gyro", hid_gyro },
{ "volume", hid_volume },
{ NULL, NULL } { NULL, NULL }
}; };

View file

@ -34,6 +34,10 @@ int main() {
sftd_init(); sftd_init();
//sf2d_set_3d(true); //sf2d_set_3d(true);
// Init accel/gyro
HIDUSER_EnableAccelerometer();
HIDUSER_EnableGyroscope();
// Init Lua // Init Lua
lua_State *L = luaL_newstate(); lua_State *L = luaL_newstate();
if (L == NULL) error("memory allocation error while creating a new Lua state"); if (L == NULL) error("memory allocation error while creating a new Lua state");
@ -46,5 +50,8 @@ int main() {
// Un-init (?) // Un-init (?)
sftd_fini(); sftd_fini();
sf2d_fini(); sf2d_fini();
// Disable needed things
HIDUSER_DisableAccelerometer();
HIDUSER_DisableGyroscope();
return 0; return 0;
} }