Skip to content

Fix double events (#245) #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2019
Merged

Fix double events (#245) #251

merged 2 commits into from
Oct 10, 2019

Conversation

raphaelcoeffic
Copy link
Member

@raphaelcoeffic raphaelcoeffic commented Oct 9, 2019

This fix should be quite harmless and works for me on X9D+ simulator.

The following patch has been used to be able to test with the simu:

diff --git a/src/SCRIPTS/BF/MSP/common.lua b/src/SCRIPTS/BF/MSP/common.lua
index 21c2257..173ac91 100644
--- a/src/SCRIPTS/BF/MSP/common.lua
+++ b/src/SCRIPTS/BF/MSP/common.lua
@@ -136,3 +136,7 @@ function mspPollReply()
     end
     return nil
 end
+
+function mspSetRxReq(cmd)
+    mspRxReq = cmd
+end
diff --git a/src/SCRIPTS/BF/MSP/simu.lua b/src/SCRIPTS/BF/MSP/simu.lua
new file mode 100644
index 0000000..7befa3a
--- /dev/null
+++ b/src/SCRIPTS/BF/MSP/simu.lua
@@ -0,0 +1,23 @@
+
+local lastCmd
+
+protocol.mspRead = function(cmd)
+    lastCmd = cmd
+    return true
+end
+
+protocol.mspWrite = function(cmd, payload)
+    return true
+end
+
+protocol.mspPoll = function()
+    -- TODO: return fake payload for the lastCmd
+   if lastCmd == 112 then
+      mspSetRxReq(lastCmd)
+      lastCmd = 0
+      return { 100, 100, 100,
+               100, 100, 100,
+               100, 100, 100 }
+   end
+   return nil
+end
diff --git a/src/SCRIPTS/BF/protocols.lua b/src/SCRIPTS/BF/protocols.lua
index 01651cd..5e3d37d 100644
--- a/src/SCRIPTS/BF/protocols.lua
+++ b/src/SCRIPTS/BF/protocols.lua
@@ -23,11 +23,24 @@ local supportedProtocols =
         maxRxBufferSize = 58,
         saveMaxRetries  = 2,
         saveTimeout     = 150
+    },
+    simu =
+    {
+        transport       = SCRIPT_HOME.."/MSP/simu.lua",
+        rssi            = function() return getValue("RSSI") end,
+        exitFunc        = function() return 0 end,
+        stateSensor     = "Tmp1",
+        saveMaxRetries  = 2,
+        saveTimeout     = 500
     }
 }
 
 function getProtocol()
-    if supportedProtocols.smartPort.push() then
+    local ver, rad, maj, min, rev = getVersion()
+
+    if string.find(rad, "-simu") then
+        return supportedProtocols.simu
+    elseif supportedProtocols.smartPort.push() then
         return supportedProtocols.smartPort
     elseif supportedProtocols.crsf.push() then
         return supportedProtocols.crsf
diff --git a/src/SCRIPTS/BF/radios.lua b/src/SCRIPTS/BF/radios.lua
index f4516ac..30dba77 100644
--- a/src/SCRIPTS/BF/radios.lua
+++ b/src/SCRIPTS/BF/radios.lua
@@ -52,7 +52,7 @@ local supportedRadios =
 }
 
 local ver, rad, maj, min, rev = getVersion()
-local radio = supportedRadios[rad]
+local radio = supportedRadios[string.gsub(rad, "-simu", "")]
 
 if not radio then
     error("Radio not supported: "..rad)

Fixes #245.

@raphaelcoeffic
Copy link
Member Author

By the way, due to the latest .gitattributes, I had no choice but to commit the files with the fixed line endings. git forced me...

Copy link
Member

@mikeller mikeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed to fix the(+) bug on X9D+.

Sorry about the line endings. I copied the unified .gitattributes across all repositories, but forgot to git pull on them before pushing the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

opentx 2.3 number jumping back to another value
2 participants