diff --git a/source/hid.c b/source/hid.c index e9df181..a8de874 100644 --- a/source/hid.c +++ b/source/hid.c @@ -74,8 +74,72 @@ static int hid_read(lua_State *L) { 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[] = { - { "read", hid_read }, + { "read", hid_read }, + { "touch", hid_touch }, + { "circle", hid_circle }, + { "accel", hid_accel }, + { "gyro", hid_gyro }, + { "volume", hid_volume }, { NULL, NULL } }; @@ -86,4 +150,4 @@ int luaopen_hid_lib(lua_State *L) { void load_hid_lib(lua_State *L) { luaL_requiref(L, "ctr.hid", luaopen_hid_lib, false); -} \ No newline at end of file +} diff --git a/source/main.c b/source/main.c index 182ef2b..f1f419e 100644 --- a/source/main.c +++ b/source/main.c @@ -33,6 +33,10 @@ int main() { sf2d_init(); sftd_init(); //sf2d_set_3d(true); + + // Init accel/gyro + HIDUSER_EnableAccelerometer(); + HIDUSER_EnableGyroscope(); // Init Lua lua_State *L = luaL_newstate(); @@ -46,5 +50,8 @@ int main() { // Un-init (?) sftd_fini(); sf2d_fini(); + // Disable needed things + HIDUSER_DisableAccelerometer(); + HIDUSER_DisableGyroscope(); return 0; }