IRremote
ir_Sharp_alt.cpp
Go to the documentation of this file.
1 //-*- mode: C; c-basic-offset: 8; tab-width: 8; indent-tabs-mode: t; -*-
2 #include "IRremote.h"
3 
4 //==============================================================================
5 // SSSS H H AAA RRRR PPPP AAA L TTTTT
6 // S H H A A R R P P A A L T
7 // SSS HHHHH AAAAA RRRR PPPP AAAAA L T
8 // S H H A A R R P A A L T
9 // SSSS H H A A R R P A A LLLLL T
10 //==============================================================================
11 
12 // This is an alternative protocol to that in ir_Sharp.cpp. It was tested with
13 // the original Sharp GA538WJSA remote control. LIRC file with codes for this
14 // remote control: http://lirc.sourceforge.net/remotes/sharp/GA538WJSA
15 //
16 // Author: Sergiy Kolesnikov
17 //
18 
19 #define SHARP_ALT_RAWLEN 32
20 #define SHARP_ALT_ADDRESS_BITS 5
21 #define SHARP_ALT_COMMAND_BITS 8
22 #define SHARP_ALT_BIT_MARK 150
23 #define SHARP_ALT_SEND_BIT_MARK 300
24 #define SHARP_ALT_ONE_SPACE 1750
25 #define SHARP_ALT_ZERO_SPACE 700
26 #define SHARP_ALT_RPT_SPACE 50000
27 #define SHARP_ALT_SEND_RPT_SPACE 44000
28 #define SHARP_ALT_TOGGLE_MASK 0x3FF
29 #define SHARP_ALT_SEND_INVERT_MASK 0x7FE0
30 
31 //+=============================================================================
32 #if SEND_SHARP_ALT
33 void IRsend::sendSharpAltRaw(unsigned long data, int nbits) {
34  enableIROut(38);
35 
36  for (int n = 0; n < 3; n++) {
37  unsigned long mask = B1;
38  for (int i = 0; i < nbits; i++) {
39  if (data & mask) {
42  } else {
45  }
46  mask <<= 1;
47  }
50  data = data ^ SHARP_ALT_SEND_INVERT_MASK;
51  }
52 }
53 
54 void IRsend::sendSharpAlt(unsigned int address, unsigned long command) {
55  unsigned long data = 1; // The expansion and the check bits (01).
56  data = (data << SHARP_ALT_COMMAND_BITS) | command;
57  data = (data << SHARP_ALT_ADDRESS_BITS) | address;
58 
59  // (+2) is for the expansion and the check bits.
61 }
62 #endif
63 
64 //+=============================================================================
65 #if DECODE_SHARP_ALT
66 bool IRrecv::decodeSharpAlt(decode_results *results) {
67 
68  // Check we have enough data.
70  return false;
71 
72  // Check stop mark.
74  return false;
75 
76  // Check the "check bit." If this bit is not 0 than it is an inverted
77  // frame, which we ignore.
79  return false;
80 
81  // Check for repeat.
82  static boolean is_first_repeat = true;
83  long initial_space = ((long) results->rawbuf[0]) * USECPERTICK;
84  if (initial_space <= SHARP_ALT_RPT_SPACE) {
85  if (!is_first_repeat) {
86  results->bits = 0;
87  results->value = REPEAT;
88  results->decode_type = SHARP;
89  return true;
90  } else {
91 
92  // Ignore the first repeat that always comes after the
93  // inverted frame (even if the button was pressed only
94  // once).
95  is_first_repeat = false;
96  return false;
97  }
98  }
99 
100  // Decode bits. SHARP_ALT_RAWLEN-6 because index starts with 0 (-1) and we
101  // omit the timings for the stop mark (-1), the check bit (-2), and the
102  // expansion bit (-2).
103  uint16_t bits = 0;
104  for (int i = SHARP_ALT_RAWLEN - 6; i > 1; i -= 2) {
105  if (MATCH_SPACE(results->rawbuf[i], SHARP_ALT_ONE_SPACE)) {
106  bits = (bits << 1) | 1;
107  } else if (MATCH_SPACE(results->rawbuf[i], SHARP_ALT_ZERO_SPACE)) {
108  bits = (bits << 1) | 0;
109  } else {
110  return false;
111  }
112  }
113 
115  results->address = (bits & (1 << (SHARP_ALT_ADDRESS_BITS))) - 1;
116  results->value = bits >> SHARP_ALT_ADDRESS_BITS; // command
117  results->decode_type = SHARP_ALT;
118  is_first_repeat = true;
119  return true;
120 }
121 #endif
SHARP_ALT_ZERO_SPACE
#define SHARP_ALT_ZERO_SPACE
Definition: ir_Sharp_alt.cpp:25
SHARP_ALT_ONE_SPACE
#define SHARP_ALT_ONE_SPACE
Definition: ir_Sharp_alt.cpp:24
decode_results
Results returned from the decoder.
Definition: IRremote.h:174
decode_results::bits
int bits
Number of bits in decoded value.
Definition: IRremote.h:179
decode_results::address
unsigned int address
Used by Panasonic & Sharp [16-bits].
Definition: IRremote.h:177
decode_results::rawbuf
volatile unsigned int * rawbuf
Raw intervals in 50uS ticks.
Definition: IRremote.h:180
IRsend::mark
void mark(unsigned int usec)
Definition: irSend.cpp:69
IRsend::enableIROut
void enableIROut(int khz)
Definition: irSend.cpp:127
SHARP_ALT_BIT_MARK
#define SHARP_ALT_BIT_MARK
Definition: ir_Sharp_alt.cpp:22
decode_results::decode_type
decode_type_t decode_type
UNKNOWN, NEC, SONY, RC5, ...
Definition: IRremote.h:176
SHARP_ALT_RAWLEN
#define SHARP_ALT_RAWLEN
Definition: ir_Sharp_alt.cpp:19
MATCH_SPACE
int MATCH_SPACE(int measured_ticks, int desired_us)
Definition: IRremote.cpp:89
IRsend::sendSharpAlt
void sendSharpAlt(unsigned int address, unsigned long command)
Definition: ir_Sharp_alt.cpp:54
irparams
volatile irparams_t irparams
Allow all parts of the code access to the ISR data NB.
USECPERTICK
#define USECPERTICK
Definition: IRremoteBoardDefs.h:166
SHARP_ALT
@ SHARP_ALT
Definition: IRremote.h:129
SHARP
@ SHARP
Definition: IRremote.h:128
SHARP_ALT_SEND_RPT_SPACE
#define SHARP_ALT_SEND_RPT_SPACE
Definition: ir_Sharp_alt.cpp:27
SHARP_ALT_SEND_INVERT_MASK
#define SHARP_ALT_SEND_INVERT_MASK
Definition: ir_Sharp_alt.cpp:29
SHARP_ALT_ADDRESS_BITS
#define SHARP_ALT_ADDRESS_BITS
Definition: ir_Sharp_alt.cpp:20
IRremote.h
Public API to the library.
IRsend::space
void space(unsigned int usec)
Definition: irSend.cpp:103
REPEAT
#define REPEAT
Decoded value for NEC when a repeat code is received.
Definition: IRremote.h:188
decode_results::value
unsigned long value
Decoded value [max 32-bits].
Definition: IRremote.h:178
MATCH_MARK
int MATCH_MARK(int measured_ticks, int desired_us)
Definition: IRremote.cpp:63
SHARP_ALT_SEND_BIT_MARK
#define SHARP_ALT_SEND_BIT_MARK
Definition: ir_Sharp_alt.cpp:23
SHARP_ALT_COMMAND_BITS
#define SHARP_ALT_COMMAND_BITS
Definition: ir_Sharp_alt.cpp:21
IRsend::sendSharpAltRaw
void sendSharpAltRaw(unsigned long data, int nbits)
Definition: ir_Sharp_alt.cpp:33
SHARP_ALT_RPT_SPACE
#define SHARP_ALT_RPT_SPACE
Definition: ir_Sharp_alt.cpp:26
irparams_t::rawlen
unsigned int rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:45