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:
parent
d21906c684
commit
12a315b738
2 changed files with 73 additions and 2 deletions
68
source/hid.c
68
source/hid.c
|
|
@ -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 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -86,4 +150,4 @@ int luaopen_hid_lib(lua_State *L) {
|
||||||
|
|
||||||
void load_hid_lib(lua_State *L) {
|
void load_hid_lib(lua_State *L) {
|
||||||
luaL_requiref(L, "ctr.hid", luaopen_hid_lib, false);
|
luaL_requiref(L, "ctr.hid", luaopen_hid_lib, false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ int main() {
|
||||||
sf2d_init();
|
sf2d_init();
|
||||||
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();
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue