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

Added the PTM services API. Should work.

This commit is contained in:
Firew0lf 2015-08-18 12:24:36 +02:00
parent 8f42c4f7ab
commit cec806bb78
2 changed files with 86 additions and 0 deletions

View file

@ -4,6 +4,7 @@
int load_gfx_lib(lua_State *L); int load_gfx_lib(lua_State *L);
int load_os_lib(lua_State *L); int load_os_lib(lua_State *L);
int load_news_lib(lua_State *L); int load_news_lib(lua_State *L);
int load_ptm_lib(lua_State *L);
static const struct luaL_Reg ctr_lib[] = { static const struct luaL_Reg ctr_lib[] = {
{ NULL, NULL } { NULL, NULL }
@ -12,6 +13,7 @@ static const struct luaL_Reg ctr_lib[] = {
struct { char *name; int (*load)(lua_State *L); } ctr_libs[] = { struct { char *name; int (*load)(lua_State *L); } ctr_libs[] = {
{ "gfx", load_gfx_lib }, { "gfx", load_gfx_lib },
{ "news", load_news_lib }, { "news", load_news_lib },
{ "ptm", load_ptm_lib }
{ NULL, NULL }, { NULL, NULL },
}; };

84
source/ptm.c Normal file
View file

@ -0,0 +1,84 @@
#include <3ds/types.h>
#include <3ds/services/ptm.h>
#include <lua.h>
#include <lauxlib.h>
static Handle ptmHandle;
static int ptm_init(lua_State *L) {
ptmInit();
return 0;
}
static int ptm_shutdown(lua_State *L) {
ptmExit();
return 0;
}
static int ptm_getShellState(lua_State *L) {
u8 *out = 0;
PTMU_GetShellState(ptmHandle, out);
lua_pushintegrer(L, (lua_Integrer)out);
return 1;
}
static int ptm_getBatteryLevel(lua_State *L) {
u8 *out = 0;
PTMU_GetBatteryLevel(ptmHandle, out);
lua_pushintegrer(L, (lua_Integrer)out);
return 1;
}
static int ptm_getBatteryChargeState(lua_State *L) {
u8 *out = 0;
PTMU_GetBatteryChargeState(ptmHandle, out);
lua_pushintegrer(L, (lua_Integrer)out);
return 1;
}
static int ptm_getPedometerState(lua_State *L) {
u8 *out = 0;
PTMU_GetPedometerState(ptmHandle, out);
lua_pushintegrer(L, (lua_Integrer)out);
return 1;
}
static int ptm_getTotalStepCount(lua_State *L) {
u32 *steps = 0;
PTMU_GetTotalStepCount(ptmHandle, steps);
lua_pushintegrer(L, (lua_Integrer)steps);
return 1;
}
static const struct luaL_Reg ptm_lib[] = {
{"init", ptm_init },
{"shutdown", ptm_shutdown },
{"getShellState", ptm_getShellState },
{"getBatteryLevel", ptm_getBatteryLevel },
{"getBatteryChargeState", ptm_getBatteryChargeState},
{"getPedometer", ptm_getPedometer },
{"getTotalStepCount", ptm_getTotalStepCount },
{NULL, NULL}
}
int luaopen_ptm_lib(lua_State *L) {
luaL_newlib(L, ptm_lib);
return 1;
}
void load_ptm_lib(lua_State *L) {
luaL_requiref(L, "ctr.ptm", luaopen_ptm_lib, 0);
}