Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions src/SCRIPTS/BF/background.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,35 @@ local function run_bg()
-- assuming when sensor value higher than 0 there is an telemetry connection
-- only send datetime one time after telemetry connection became available
-- or when connection is restored after e.g. lipo refresh
local now = getDateTime()
local year = now.year;

values = {}
values[1] = bit32.band(year, 0xFF)
year = bit32.rshift(year, 8)
values[2] = bit32.band(year, 0xFF)
values[3] = now.mon
values[4] = now.day
values[5] = now.hour
values[6] = now.min
values[7] = now.sec
if API_VERSION < 1.041 then
-- format: year (16) / month (8) / day (8) / hour (8) / min (8) / sec (8)
local now = getDateTime()
local year = now.year;

values = {}
values[1] = bit32.band(year, 0xFF)
year = bit32.rshift(year, 8)
values[2] = bit32.band(year, 0xFF)
values[3] = now.mon
values[4] = now.day
values[5] = now.hour
values[6] = now.min
values[7] = now.sec
else
-- format: seconds after the epoch (32) / milliseconds (16)
local now = getRtcTime()

values = {}

for i = 1, 4 do
values[i] = bit32.band(now, 0xFF)
now = bit32.rshift(now, 8)
end

values[5] = 0 -- we don't have milliseconds
values[6] = 0
end

-- send msp message
protocol.mspWrite(MSP_SET_RTC, values)
Expand Down
9 changes: 9 additions & 0 deletions src/SCRIPTS/TELEMETRY/bf.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
SCRIPT_HOME = "/SCRIPTS/BF"

-- Change this to match the API version of the firmware you are using
-- (you can have multiple copies of this script with different values
-- for API_VERSION, and select different versions for different models
-- on your TX)
-- Version mapping:
-- 1.041: Betaflight 4.0 and newer
-- <1.041: Betaflight 3.5 and older
API_VERSION = 1.040

protocol = assert(loadScript(SCRIPT_HOME.."/protocols.lua"))()
radio = assert(loadScript(SCRIPT_HOME.."/radios.lua"))()

Expand Down