Skip to content

Commit 16769de

Browse files
authored
Merge pull request #191 from klutvott123/discard-duplicate-data-from-buffer
Discard duplicate input data for smartport
2 parents f1b8363 + 78cf386 commit 16769de

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/SCRIPTS/BF/MSP/sp.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ FPORT_REMOTE_SENSOR_ID = 0x00
55
REQUEST_FRAME_ID = 0x30
66
REPLY_FRAME_ID = 0x32
77

8+
local lastSensorId, lastFrameId, lastDataId, lastValue
9+
810
protocol.mspSend = function(payload)
911
local dataId = 0
1012
dataId = payload[1] + bit32.lshift(payload[2],8)
@@ -22,8 +24,27 @@ protocol.mspWrite = function(cmd, payload)
2224
return mspSendRequest(cmd, payload)
2325
end
2426

27+
--Discards duplicate data from lua input buffer
28+
local function smartPortTelemetryPop()
29+
local sensorId, frameId, dataId, value
30+
while true do
31+
sensorId, frameId, dataId, value = sportTelemetryPop()
32+
if sensorId == nil then
33+
return nil
34+
elseif (lastSensorId == sensorId) and (lastFrameId == frameId) and (lastDataId == dataId) and (lastValue == value) then
35+
--Keep checking
36+
else
37+
lastSensorId = sensorId
38+
lastFrameId = frameId
39+
lastDataId = dataId
40+
lastValue = value
41+
return sensorId, frameId, dataId, value
42+
end
43+
end
44+
end
45+
2546
protocol.mspPoll = function()
26-
local sensorId, frameId, dataId, value = sportTelemetryPop()
47+
local sensorId, frameId, dataId, value = smartPortTelemetryPop()
2748
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID) and frameId == REPLY_FRAME_ID then
2849
local payload = {}
2950
payload[1] = bit32.band(dataId,0xFF)

0 commit comments

Comments
 (0)