From e63a877ed6c376a3c85a76761a42011e99fe6b44 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 18 Dec 2017 21:04:02 +0100 Subject: [PATCH] added getRtcTime() LUA function (#5524) This allows for retrieving the UNIX timestamp kept internally. --- radio/src/lua/api_general.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index b63ee7e2e..63697c2d5 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -167,6 +167,25 @@ static int luaGetDateTime(lua_State * L) return 1; } +/*luadoc +@function getRtcTime() + +Return current RTC system date as unix timstamp (in seconds since 1. Jan 1970) + +Please note the RTC timestamp is kept internally as a 32bit integer, which will overflow +in 2038. + +@retval number Number of seconds elapsed since 1. Jan 1970 +*/ + +#if defined(RTCLOCK) +static int luaGetRtcTime(lua_State * L) +{ + lua_pushunsigned(L, g_rtcTime); + return 1; +} +#endif + static void luaPushLatLon(lua_State* L, TelemetrySensor & telemetrySensor, TelemetryItem & telemetryItem) /* result is lua table containing members ["lat"] and ["lon"] as lua_Number (doubles) in decimal degrees */ { @@ -1206,6 +1225,9 @@ static int luaGetUsage(lua_State * L) const luaL_Reg opentxLib[] = { { "getTime", luaGetTime }, { "getDateTime", luaGetDateTime }, +#if defined(RTCLOCK) + { "getRtcTime", luaGetRtcTime }, +#endif { "getVersion", luaGetVersion }, { "getGeneralSettings", luaGetGeneralSettings }, { "getValue", luaGetValue },