@@ -5,6 +5,8 @@ FPORT_REMOTE_SENSOR_ID = 0x00
55REQUEST_FRAME_ID = 0x30
66REPLY_FRAME_ID = 0x32
77
8+ local lastSensorId , lastFrameId , lastDataId , lastValue
9+
810protocol .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 )
2325end
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+
2546protocol .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