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

Added the "ctr.ir" library. Maybe it's working.

This commit is contained in:
Firew0lf 2015-08-20 18:33:49 +02:00
parent 155a2e9805
commit 551e8e121e
2 changed files with 93 additions and 0 deletions

View file

@ -9,6 +9,7 @@ int load_gfx_lib(lua_State *L);
int load_news_lib(lua_State *L);
int load_ptm_lib(lua_State *L);
int load_hid_lib(lua_State *L);
int load_ir_lib(lua_State *L);
static int ctr_run(lua_State *L) {
lua_pushboolean(L, aptMainLoop());
@ -35,6 +36,7 @@ struct { char *name; int (*load)(lua_State *L); } ctr_libs[] = {
{ "news", load_news_lib },
{ "ptm", load_ptm_lib },
{ "hid", load_hid_lib },
{ "ir", load_ir_lib },
{ NULL, NULL }
};

91
source/ir.c Normal file
View file

@ -0,0 +1,91 @@
#include <3ds/types.h>
#include <3ds/services/ir.h>
#include <3ds/linear.h>
#include <lualib.h>
#include <lauxlib.h>
u32 bufferSize = 0;
u32 *buffer;
static int ir_init(lua_State *L) {
u8 bitrate = luaL_checkinteger(L, 1);
bufferSize = luaL_optinteger(L, 2, 2048); //default: 2Kio
buffer = linearAlloc(bufferSize);
Result ret = IRU_Initialize(buffer, bufferSize);
if (ret) {
lua_pushboolean(L, false);
lua_pushinteger(L, ret);
return 2;
}
IRU_SetBitRate(bitrate);
lua_pushboolean(L, true);
return 1;
}
static int ir_shutdown(lua_State *L) {
IRU_Shutdown();
return 0;
}
static int ir_send(lua_State *L) {
u8 *data = (u8*)luaL_checkstring(L, 1);
u32 wait = lua_toboolean(L, 2);
IRU_SendData(data, sizeof(data), wait);
return 0;
}
static int ir_receive(lua_State *L) {
u32 size = luaL_optinteger(L, 1, bufferSize);
u32 wait = lua_toboolean(L, 2);
u8 *data = 0;
u32 *transfercount = 0;
IRU_RecvData(data, size, 0x00, transfercount, wait);
lua_pushstring(L, (const char *)data);
return 1;
}
static int ir_setBitRate(lua_State *L) {
u8 bitrate = luaL_checkinteger(L, 1);
IRU_SetBitRate(bitrate);
return 0;
}
static int ir_getBitRate(lua_State *L) {
u8 bitrate = 0;
IRU_GetBitRate(&bitrate);
lua_pushinteger(L, bitrate);
return 1;
}
static const struct luaL_Reg ir_lib[] = {
{"init", ir_init },
{"shutdown", ir_shutdown },
{"send", ir_send },
{"receive", ir_receive },
{"setBitRate", ir_setBitRate},
{"getBitRate", ir_getBitRate},
{NULL, NULL}
};
int luaopen_ir_lib(lua_State *L) {
luaL_newlib(L, ir_lib);
return 1;
}
void load_ir_lib(lua_State *L) {
luaL_requiref(L, "ctr.ir", luaopen_ir_lib, 0);
}