Skip to content

Instantly share code, notes, and snippets.

@chopmann
Created November 1, 2019 07:11
Show Gist options
  • Save chopmann/d3df6b0141aa7146a9c73a420e639f5a to your computer and use it in GitHub Desktop.
Save chopmann/d3df6b0141aa7146a9c73a420e639f5a to your computer and use it in GitHub Desktop.
FeedbackNow - LoraServer Decoder
// 39 14 23 04c 4 00000000000000
// CC GG YY RRR X
// ButtonCodes
// 0x4 green, 0x8 yellow, 0xc red
function Decode(fport, bytes) {
var decoded = {}
decoded.loopStep = bytes[0] >>> 2
var greenHighBits = (bytes[0] % 4) << 8
decoded.green = (greenHighBits + bytes[1]) / 4
decoded.yellow = bytes[2]
var redLowBits = bytes[4] >>> 4
decoded.red = (bytes[3] * 16 + redLowBits) / 4
var buttonCode = (bytes[4] % 64)
if (buttonCode === 0x4) {
decoded.button = "green"
} else if (buttonCode === 0x8) {
decoded.button = "yellow"
} else if (buttonCode === 0xc) {
decoded.button = "red"
}
return decoded
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment