Skip to content

Commit

Permalink
Fix irremote reporting incorrect NEC addresses and command codes (#422)
Browse files Browse the repository at this point in the history
Change from reading MSB->LSB to LSB->MSB
Fixes #422
  • Loading branch information
neildavis authored and deadprogram committed Jul 13, 2022
1 parent 3edd8e4 commit 13c4335
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
36 changes: 18 additions & 18 deletions examples/irremote/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ import (
)

var irCmdButtons = map[uint16]string{
0xA2: "POWER",
0xE2: "FUNC/STOP",
0x62: "VOL+",
0x22: "FAST BACK",
0x02: "PAUSE",
0xC2: "FAST FORWARD",
0xE0: "DOWN",
0xA8: "VOL-",
0x90: "UP",
0x98: "EQ",
0xB0: "ST/REPT",
0x68: "0",
0x30: "1",
0x45: "POWER",
0x47: "FUNC/STOP",
0x46: "VOL+",
0x44: "FAST BACK",
0x40: "PAUSE",
0x43: "FAST FORWARD",
0x07: "DOWN",
0x15: "VOL-",
0x09: "UP",
0x19: "EQ",
0x0D: "ST/REPT",
0x16: "0",
0x0C: "1",
0x18: "2",
0x7A: "3",
0x10: "4",
0x38: "5",
0x5E: "3",
0x08: "4",
0x1C: "5",
0x5A: "6",
0x42: "7",
0x4A: "8",
0x52: "9",
0x52: "8",
0x4A: "9",
}

var (
Expand Down
10 changes: 5 additions & 5 deletions irremote/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (ir *ReceiverDevice) pinChange(pin machine.Pin) {
ir.resetStateMachine()
} else {
// 562.5µs OR 1687.5µs space detected
mask := uint32((1 << (31 - ir.bitIndex)))
mask := uint32(1 << ir.bitIndex)
if duration > time.Microsecond*1000 {
// 1687.5µs space detected (logic 1) - Set bit
ir.data.Code |= mask
Expand Down Expand Up @@ -201,16 +201,16 @@ const (

func (ir *ReceiverDevice) decode() irDecodeError {
// Decode cmd and inverse cmd and perform validation check
cmd := uint8((ir.data.Code & 0xff00) >> 8)
invCmd := uint8(ir.data.Code & 0xff)
cmd := uint8((ir.data.Code & 0x00ff0000) >> 16)
invCmd := uint8((ir.data.Code & 0xff000000) >> 24)
if cmd != ^invCmd {
// Validation failure. cmd and inverse cmd do not match
return irDecodeErrorInverseCheckFail
}
// cmd validation pass, decode address
ir.data.Command = uint16(cmd)
addrLow := uint8((ir.data.Code & 0xff000000) >> 24)
addrHigh := uint8((ir.data.Code & 0x00ff0000) >> 16)
addrLow := uint8(ir.data.Code & 0xff)
addrHigh := uint8((ir.data.Code & 0xff00) >> 8)
if addrHigh == ^addrLow {
// addrHigh is inverse of addrLow. This is not a valid 16-bit address in extended NEC coding
// since it is indistinguishable from 8-bit address with inverse validation. Use the 8-bit address
Expand Down

0 comments on commit 13c4335

Please sign in to comment.