From cec806bb78c0afc0deeee4b1607b2e5d34106918 Mon Sep 17 00:00:00 2001 From: Firew0lf Date: Tue, 18 Aug 2015 12:24:36 +0200 Subject: [PATCH] Added the PTM services API. Should work. --- source/ctr.c | 2 ++ source/ptm.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 source/ptm.c diff --git a/source/ctr.c b/source/ctr.c index 0b35876..b908145 100644 --- a/source/ctr.c +++ b/source/ctr.c @@ -4,6 +4,7 @@ int load_gfx_lib(lua_State *L); int load_os_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[] = { { NULL, NULL } @@ -12,6 +13,7 @@ static const struct luaL_Reg ctr_lib[] = { struct { char *name; int (*load)(lua_State *L); } ctr_libs[] = { { "gfx", load_gfx_lib }, { "news", load_news_lib }, + { "ptm", load_ptm_lib } { NULL, NULL }, }; diff --git a/source/ptm.c b/source/ptm.c new file mode 100644 index 0000000..676e1d1 --- /dev/null +++ b/source/ptm.c @@ -0,0 +1,84 @@ +#include <3ds/types.h> +#include <3ds/services/ptm.h> + +#include +#include + +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); +}