diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 109f89a867..8784c04074 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -34,17 +34,8 @@ static int lua_readpin(lua_State* l) { return 1; } -static int lua_getAuxAnalog(lua_State* l) { - auto sensorIndex = luaL_checkinteger(l, 1); - - lua_pushnumber(l, sensorIndex); - return 1; -} - -static int lua_getSensor(lua_State* l) { - auto sensorIndex = luaL_checkinteger(l, 1); - - auto result = Sensor::get(static_cast(sensorIndex)); +static int getSensor(lua_State* l, SensorType type) { + auto result = Sensor::get(type); if (result) { // return value if valid @@ -57,6 +48,20 @@ static int lua_getSensor(lua_State* l) { return 1; } +static int lua_getAuxAnalog(lua_State* l) { + auto sensorIndex = luaL_checkinteger(l, 1); + + auto type = static_cast(sensorIndex + static_cast(SensorType::Aux1)); + + return getSensor(l, type); +} + +static int lua_getSensor(lua_State* l) { + auto sensorIndex = luaL_checkinteger(l, 1); + + return getSensor(l, static_cast(sensorIndex)); +} + static int lua_getSensorRaw(lua_State* l) { auto sensorIndex = luaL_checkinteger(l, 1);