1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00
ctruLua/source/ptm.c
Firew0lf b4d025d602 Updated the sf2dlib and sftdlib; Added the gfx.color.hex() function; Added the New3DS CPU mode control.
As the color order of the sf2dlib changed, you have to change it in your code, or use the color.hex() function.
To fix the problems, just change "0xRRGGBBAA" to "0xAABBGGRR".
Also, the shader compiler changed to Picasso, so you'll need it in order to compile.
https://github.com/fincs/picasso
2015-12-09 23:14:23 +01:00

149 lines
2.9 KiB
C

/***
The `ptm` module.
@module ctr.ptm
@usage local ptm = require("ctr.ptm")
*/
#include <3ds/types.h>
#include <3ds/services/ptm.h>
#include <lua.h>
#include <lauxlib.h>
static Handle *ptmHandle;
/***
Initialize the PTM module.
@function init
*/
static int ptm_init(lua_State *L) {
ptmInit();
ptmSysmInit();
return 0;
}
/***
Disable the PTM module.
@function shutdown
*/
static int ptm_shutdown(lua_State *L) {
ptmExit();
ptmSysmExit();
return 0;
}
/***
Return the shell state.
@function getShellState
@treturn number shell state
*/
static int ptm_getShellState(lua_State *L) {
u8 out = 0;
PTMU_GetShellState(ptmHandle, &out);
lua_pushinteger(L, out);
return 1;
}
/***
Return the battery level.
@function getBatteryLevel
@treturn number battery level (`5`: fully charged; `0`: empty)
*/
static int ptm_getBatteryLevel(lua_State *L) {
u8 out = 0;
PTMU_GetBatteryLevel(ptmHandle, &out);
lua_pushinteger(L, out);
return 1;
}
/***
Return whether or not the battery is charging.
@function getBatteryChargeState
@treturn boolean `true` if the battery is charging
*/
static int ptm_getBatteryChargeState(lua_State *L) {
u8 out = 0;
PTMU_GetBatteryChargeState(ptmHandle, &out);
lua_pushboolean(L, out);
return 1;
}
/***
Return whether or not the pedometer is counting.
@function getPedometerState
@treturn boolean `true` if the pedometer is counting
*/
static int ptm_getPedometerState(lua_State *L) {
u8 out = 0;
PTMU_GetPedometerState(ptmHandle, &out);
lua_pushboolean(L, out);
return 1;
}
/***
Return the total steps taken with the system.
@function getTotalStepCount
@treturn number step count
*/
static int ptm_getTotalStepCount(lua_State *L) {
u32 steps = 0;
PTMU_GetTotalStepCount(ptmHandle, &steps);
lua_pushinteger(L, steps);
return 1;
}
/***
Setup the new 3DS CPU features (overclock, 4 cores ...)
@newonly
@function configureNew3DSCPU
@tparam boolean enable enable the New3DS CPU features
@treturn boolean `true` if everything went fine
*/
static int ptm_configureNew3DSCPU(lua_State *L) {
u8 conf = false;
if (lua_isboolean(L, 1))
conf = lua_toboolean(L, 1);
Result ret = PTMSYSM_ConfigureNew3DSCPU(conf);
if (ret) {
lua_pushboolean(L, false);
lua_pushinteger(L, ret);
return 2;
}
lua_pushboolean(L, true);
return 1;
}
static const struct luaL_Reg ptm_lib[] = {
{"init", ptm_init },
{"shutdown", ptm_shutdown },
{"getShellState", ptm_getShellState },
{"getBatteryLevel", ptm_getBatteryLevel },
{"getBatteryChargeState", ptm_getBatteryChargeState},
{"getPedometerState", ptm_getPedometerState },
{"getTotalStepCount", ptm_getTotalStepCount },
{"configureNew3DSCPU", ptm_configureNew3DSCPU },
{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);
}