Skip to content
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

Handle signed values #458

Merged
merged 1 commit into from
Nov 13, 2022

Conversation

klutvott123
Copy link
Member

Currently we're treating all incoming values as unsigned.
This PR adds detection of signed values by checking the fields min limit

@klutvott123 klutvott123 mentioned this pull request Nov 13, 2022
haslinghuis
haslinghuis previously approved these changes Nov 13, 2022
@@ -121,6 +121,10 @@ local function processMspReply(cmd,rx_buf)
raw_val = bit32.lshift(raw_val, (idx-1)*8)
f.value = bit32.bor(f.value, raw_val)
end
local bits = #f.vals * 8
if f.min < 0 and bit32.btest(f.value, bit32.lshift(1, bits - 1)) then
f.value = f.value - math.pow(2, bits)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f.value = f.value - math.pow(2, bits)
f.value = f.value - (2 ^ bits)

Copy link
Member Author

Choose a reason for hiding this comment

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

done. thanks 👍

@haslinghuis haslinghuis merged commit 700c8c3 into betaflight:master Nov 13, 2022
@haslinghuis haslinghuis added this to the 1.7 milestone Nov 13, 2022
@klutvott123 klutvott123 deleted the handle-signed-values branch November 17, 2022 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants