Lua: CAN receive integration? callback? #3320

This commit is contained in:
rusefillc 2021-10-24 00:18:28 -04:00
parent add98ca5ed
commit 71fd316f70
1 changed files with 33 additions and 0 deletions

View File

@ -340,6 +340,34 @@ static int lua_setFuelMult(lua_State* l) {
}
#endif // EFI_UNIT_TEST
struct LuaCanReciever;
// linked list of all CAN receivers
static LuaCanReciever *list;
struct LuaCanReciever {
LuaCanReciever *next;
~LuaCanReciever() {
LuaCanReciever *current, *tmp;
// find self in list and remove self
LL_FOREACH_SAFE(list, current, tmp)
{
if (current == this) {
LL_DELETE(list, current);
}
}
}
LuaCanReciever() {
LL_PREPEND(list, this);
}
};
struct LuaSensor : public StoredValueSensor {
LuaSensor() : LuaSensor("Invalid") { }
@ -372,6 +400,11 @@ void configureRusefiLuaHooks(lua_State* l) {
.fun("reset", static_cast<void (Timer::*)() >(&Timer::reset ))
.fun("getElapsedSeconds", static_cast<float(Timer::*)()const>(&Timer::getElapsedSeconds));
LuaClass<LuaCanReciever> luaCanReciever(l, "CanReciever");
luaCanReciever
.ctor()
;
LuaClass<LuaSensor> luaSensor(l, "Sensor");
luaSensor
.ctor<const char*>()