From 45d1755e196476ec78c2b1bdd0ce8ef3b487149f Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 8 Jan 2018 15:12:28 +0100 Subject: [PATCH] X12S : give internal GPS access to LUA (#5610) * Initial test * Tested version * Cosmetics --- radio/src/lua/api_general.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index c7996bdaf..d5ec4a9b2 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -181,7 +181,7 @@ in 2038. #if defined(RTCLOCK) static int luaGetRtcTime(lua_State * L) { - lua_pushunsigned(L, g_rtcTime); + lua_pushunsigned(L, g_rtcTime); return 1; } #endif @@ -649,6 +649,36 @@ static int luaGetRAS(lua_State * L) return 1; } +/*luadoc +@function getTxGPS() + +Return the internal GPS position or nil if no valid hardware found + +@retval table representing the current radio position + * `lat` (number) internal GPS latitude, positive is North + * `lon` (number) internal GPS longitude, positive is East + * 'numsat' (number) current number of sats locked in by the GPS sensor + * 'fix' (boolean) fix status + +@status current Introduced in 2.2.2 +*/ +static int luaGetTxGPS(lua_State * L) +{ +#if defined(INTERNAL_GPS) + lua_createtable(L, 0, 4); + lua_pushtablenumber(L, "lat", gpsData.latitude * 0.000001); + lua_pushtablenumber(L, "lon", gpsData.longitude * 0.000001); + lua_pushtablenumber(L, "numsat", gpsData.numSat); + if (gpsData.fix) + lua_pushtableboolean(L, "fix", true); + else + lua_pushtableboolean(L, "fix", false); +#else + lua_pushnil(L); +#endif + return 1; +} + /*luadoc @function getFlightMode(mode) @@ -1232,6 +1262,7 @@ const luaL_Reg opentxLib[] = { { "getGeneralSettings", luaGetGeneralSettings }, { "getValue", luaGetValue }, { "getRAS", luaGetRAS }, + { "getTxGPS", luaGetTxGPS }, { "getFieldInfo", luaGetFieldInfo }, { "getFlightMode", luaGetFlightMode }, { "playFile", luaPlayFile },