diff --git a/examples/irremote/main.go b/examples/irremote/main.go index 38940e4..3ee1ec3 100644 --- a/examples/irremote/main.go +++ b/examples/irremote/main.go @@ -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 ( diff --git a/irremote/receiver.go b/irremote/receiver.go index 580d2f9..2ba44d4 100644 --- a/irremote/receiver.go +++ b/irremote/receiver.go @@ -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 @@ -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