Skip to content

Commit

Permalink
X12S : give internal GPS access to LUA (#5610)
Browse files Browse the repository at this point in the history
* Initial test

* Tested version

* Cosmetics
  • Loading branch information
3djc authored and kilrah committed Jan 8, 2018
1 parent bf29ebc commit 45d1755
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion radio/src/lua/api_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1232,6 +1262,7 @@ const luaL_Reg opentxLib[] = {
{ "getGeneralSettings", luaGetGeneralSettings },
{ "getValue", luaGetValue },
{ "getRAS", luaGetRAS },
{ "getTxGPS", luaGetTxGPS },
{ "getFieldInfo", luaGetFieldInfo },
{ "getFlightMode", luaGetFlightMode },
{ "playFile", luaPlayFile },
Expand Down

0 comments on commit 45d1755

Please sign in to comment.