From 94e6dbc9f35657fdbe1c3cb0f5a3938325dabf2d Mon Sep 17 00:00:00 2001 From: Hans Christian Olaussen <41271048+klutvott123@users.noreply.github.com> Date: Tue, 12 Nov 2019 21:47:52 +0100 Subject: [PATCH] More memory savings --- src/SCRIPTS/BF/MSP/common.lua | 7 ++----- src/SCRIPTS/BF/MSP/crsf.lua | 12 +++++------- src/SCRIPTS/BF/MSP/sp.lua | 11 +++++------ src/SCRIPTS/BF/protocols.lua | 2 +- src/SCRIPTS/BF/ui.lua | 2 +- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/SCRIPTS/BF/MSP/common.lua b/src/SCRIPTS/BF/MSP/common.lua index d50b3ba0..a18d5e3c 100644 --- a/src/SCRIPTS/BF/MSP/common.lua +++ b/src/SCRIPTS/BF/MSP/common.lua @@ -1,7 +1,6 @@ - -- Protocol version -MSP_VERSION = bit32.lshift(1,5) -MSP_STARTFLAG = bit32.lshift(1,4) +local MSP_VERSION = bit32.lshift(1,5) +local MSP_STARTFLAG = bit32.lshift(1,4) -- Sequence number for next MSP packet local mspSeq = 0 @@ -17,8 +16,6 @@ local mspTxIdx = 1 local mspTxCRC = 0 local mspTxPk = 0 -mspPendingRequest = false - function mspProcessTxQ() if (#(mspTxBuf) == 0) then return false diff --git a/src/SCRIPTS/BF/MSP/crsf.lua b/src/SCRIPTS/BF/MSP/crsf.lua index 4dccb563..700d4b87 100644 --- a/src/SCRIPTS/BF/MSP/crsf.lua +++ b/src/SCRIPTS/BF/MSP/crsf.lua @@ -1,14 +1,12 @@ - -- CRSF Devices -CRSF_ADDRESS_BETAFLIGHT = 0xC8 -CRSF_ADDRESS_RADIO_TRANSMITTER = 0xEA +local CRSF_ADDRESS_BETAFLIGHT = 0xC8 +local CRSF_ADDRESS_RADIO_TRANSMITTER = 0xEA -- CRSF Frame Types -CRSF_FRAMETYPE_MSP_REQ = 0x7A -- response request using msp sequence as command -CRSF_FRAMETYPE_MSP_RESP = 0x7B -- reply with 60 byte chunked binary -CRSF_FRAMETYPE_MSP_WRITE = 0x7C -- write with 60 byte chunked binary +local CRSF_FRAMETYPE_MSP_REQ = 0x7A -- response request using msp sequence as command +local CRSF_FRAMETYPE_MSP_RESP = 0x7B -- reply with 60 byte chunked binary +local CRSF_FRAMETYPE_MSP_WRITE = 0x7C -- write with 60 byte chunked binary crsfMspCmd = 0 -crsfMspHeader = {} protocol.mspSend = function(payload) local payloadOut = { CRSF_ADDRESS_BETAFLIGHT, CRSF_ADDRESS_RADIO_TRANSMITTER } diff --git a/src/SCRIPTS/BF/MSP/sp.lua b/src/SCRIPTS/BF/MSP/sp.lua index 5974ecd4..59d0d9c7 100644 --- a/src/SCRIPTS/BF/MSP/sp.lua +++ b/src/SCRIPTS/BF/MSP/sp.lua @@ -1,9 +1,8 @@ - -LOCAL_SENSOR_ID = 0x0D -SMARTPORT_REMOTE_SENSOR_ID = 0x1B -FPORT_REMOTE_SENSOR_ID = 0x00 -REQUEST_FRAME_ID = 0x30 -REPLY_FRAME_ID = 0x32 +local LOCAL_SENSOR_ID = 0x0D +local SMARTPORT_REMOTE_SENSOR_ID = 0x1B +local FPORT_REMOTE_SENSOR_ID = 0x00 +local REQUEST_FRAME_ID = 0x30 +local REPLY_FRAME_ID = 0x32 local lastSensorId, lastFrameId, lastDataId, lastValue diff --git a/src/SCRIPTS/BF/protocols.lua b/src/SCRIPTS/BF/protocols.lua index 01651cd4..85944515 100644 --- a/src/SCRIPTS/BF/protocols.lua +++ b/src/SCRIPTS/BF/protocols.lua @@ -26,7 +26,7 @@ local supportedProtocols = } } -function getProtocol() +local function getProtocol() if supportedProtocols.smartPort.push() then return supportedProtocols.smartPort elseif supportedProtocols.crsf.push() then diff --git a/src/SCRIPTS/BF/ui.lua b/src/SCRIPTS/BF/ui.lua index 0891da1f..a929be54 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -48,10 +48,10 @@ end local function saveSettings(new) if Page.values then + local payload = {} if Page.preSave then payload = Page.preSave(Page) else - payload = {} for i=1,(Page.outputBytes or #Page.values) do payload[i] = Page.values[i] end