@@ -5,6 +5,8 @@ FPORT_REMOTE_SENSOR_ID = 0x00
5
5
REQUEST_FRAME_ID = 0x30
6
6
REPLY_FRAME_ID = 0x32
7
7
8
+ local lastSensorId , lastFrameId , lastDataId , lastValue
9
+
8
10
protocol .mspSend = function (payload )
9
11
local dataId = 0
10
12
dataId = payload [1 ] + bit32.lshift (payload [2 ],8 )
@@ -22,8 +24,27 @@ protocol.mspWrite = function(cmd, payload)
22
24
return mspSendRequest (cmd , payload )
23
25
end
24
26
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
+
25
46
protocol .mspPoll = function ()
26
- local sensorId , frameId , dataId , value = sportTelemetryPop ()
47
+ local sensorId , frameId , dataId , value = smartPortTelemetryPop ()
27
48
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID ) and frameId == REPLY_FRAME_ID then
28
49
local payload = {}
29
50
payload [1 ] = bit32.band (dataId ,0xFF )
0 commit comments