forked from crankyoldgit/IRremoteESP8266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 99131ec
Showing
11 changed files
with
1,327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Contributors of this project | ||
Sofar only [me] (https://github.com/markszabo/), but feel free to join :) | ||
|
||
## Contributors of the original project (https://github.com/shirriff/Arduino-IRremote/) | ||
These are the active contributors of this project that you may contact if there is anything you need help with or if you have suggestions. | ||
|
||
- [z3t0](https://github.com/z3t0) : Active Contributor and currently also the main contributor. | ||
* Email: zetoslab@gmail.com | ||
* Skype: polarised16 | ||
- [shirriff](https://github.com/shirriff) : Owner of repository and creator of library. | ||
- [Informatic](https://github.com/Informatic) : Active contributor | ||
- [fmeschia](https://github.com/fmeschia) : Active contributor | ||
- [PaulStoffregen](https://github.com/paulstroffregen) : Active contributor | ||
- [crash7](https://github.com/crash7) : Active contributor | ||
- [Neco777](https://github.com/neco777) : Active contributor | ||
|
||
Note: This list is being updated constantly so please let [z3t0](https://github.com/z3t0) know if you have been missed. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,371 @@ | ||
/* | ||
* IRremote | ||
* Version 0.11 August, 2009 | ||
* Copyright 2009 Ken Shirriff | ||
* For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html | ||
* | ||
* Modified by Paul Stoffregen <paul@pjrc.com> to support other boards and timers | ||
* Modified by Mitra Ardron <mitra@mitra.biz> | ||
* Added Sanyo and Mitsubishi controllers | ||
* Modified Sony to spot the repeat codes that some Sony's send | ||
* | ||
* Interrupt code based on NECIRrcv by Joe Knapp | ||
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 | ||
* Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ | ||
* | ||
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) | ||
* LG added by Darryl Smith (based on the JVC protocol) | ||
* Whynter A/C ARC-110WD added by Francesco Meschia | ||
*/ | ||
|
||
#include "IRremoteESP8266.h" | ||
#include "IRremoteInt.h" | ||
|
||
// These versions of MATCH, MATCH_MARK, and MATCH_SPACE are only for debugging. | ||
// To use them, set DEBUG in IRremoteInt.h | ||
// Normally macros are used for efficiency | ||
#ifdef DEBUG | ||
int MATCH(int measured, int desired) { | ||
Serial.print("Testing: "); | ||
Serial.print(TICKS_LOW(desired), DEC); | ||
Serial.print(" <= "); | ||
Serial.print(measured, DEC); | ||
Serial.print(" <= "); | ||
Serial.println(TICKS_HIGH(desired), DEC); | ||
return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired); | ||
} | ||
|
||
int MATCH_MARK(int measured_ticks, int desired_us) { | ||
Serial.print("Testing mark "); | ||
Serial.print(measured_ticks * USECPERTICK, DEC); | ||
Serial.print(" vs "); | ||
Serial.print(desired_us, DEC); | ||
Serial.print(": "); | ||
Serial.print(TICKS_LOW(desired_us + MARK_EXCESS), DEC); | ||
Serial.print(" <= "); | ||
Serial.print(measured_ticks, DEC); | ||
Serial.print(" <= "); | ||
Serial.println(TICKS_HIGH(desired_us + MARK_EXCESS), DEC); | ||
return measured_ticks >= TICKS_LOW(desired_us + MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us + MARK_EXCESS); | ||
} | ||
|
||
int MATCH_SPACE(int measured_ticks, int desired_us) { | ||
Serial.print("Testing space "); | ||
Serial.print(measured_ticks * USECPERTICK, DEC); | ||
Serial.print(" vs "); | ||
Serial.print(desired_us, DEC); | ||
Serial.print(": "); | ||
Serial.print(TICKS_LOW(desired_us - MARK_EXCESS), DEC); | ||
Serial.print(" <= "); | ||
Serial.print(measured_ticks, DEC); | ||
Serial.print(" <= "); | ||
Serial.println(TICKS_HIGH(desired_us - MARK_EXCESS), DEC); | ||
return measured_ticks >= TICKS_LOW(desired_us - MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS); | ||
} | ||
#else | ||
int MATCH(int measured, int desired) {return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired);} | ||
int MATCH_MARK(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us + MARK_EXCESS));} | ||
int MATCH_SPACE(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us - MARK_EXCESS));} | ||
// Debugging versions are in IRremote.cpp | ||
#endif | ||
|
||
IRsend::IRsend(int IRsendPin) | ||
{ | ||
IRpin = IRsendPin; | ||
} | ||
|
||
void IRsend::begin() | ||
{ | ||
pinMode(IRpin, OUTPUT); | ||
} | ||
|
||
void IRsend::sendNEC(unsigned long data, int nbits) | ||
{ | ||
enableIROut(38); | ||
mark(NEC_HDR_MARK); | ||
space(NEC_HDR_SPACE); | ||
for (int i = 0; i < nbits; i++) { | ||
if (data & TOPBIT) { | ||
mark(NEC_BIT_MARK); | ||
space(NEC_ONE_SPACE); | ||
} | ||
else { | ||
mark(NEC_BIT_MARK); | ||
space(NEC_ZERO_SPACE); | ||
} | ||
data <<= 1; | ||
} | ||
mark(NEC_BIT_MARK); | ||
space(0); | ||
} | ||
|
||
void IRsend::sendWhynter(unsigned long data, int nbits) { | ||
enableIROut(38); | ||
mark(WHYNTER_ZERO_MARK); | ||
space(WHYNTER_ZERO_SPACE); | ||
mark(WHYNTER_HDR_MARK); | ||
space(WHYNTER_HDR_SPACE); | ||
for (int i = 0; i < nbits; i++) { | ||
if (data & TOPBIT) { | ||
mark(WHYNTER_ONE_MARK); | ||
space(WHYNTER_ONE_SPACE); | ||
} | ||
else { | ||
mark(WHYNTER_ZERO_MARK); | ||
space(WHYNTER_ZERO_SPACE); | ||
} | ||
data <<= 1; | ||
} | ||
mark(WHYNTER_ZERO_MARK); | ||
space(WHYNTER_ZERO_SPACE); | ||
} | ||
|
||
void IRsend::sendSony(unsigned long data, int nbits) { | ||
enableIROut(40); | ||
mark(SONY_HDR_MARK); | ||
space(SONY_HDR_SPACE); | ||
data = data << (32 - nbits); | ||
for (int i = 0; i < nbits; i++) { | ||
if (data & TOPBIT) { | ||
mark(SONY_ONE_MARK); | ||
space(SONY_HDR_SPACE); | ||
} | ||
else { | ||
mark(SONY_ZERO_MARK); | ||
space(SONY_HDR_SPACE); | ||
} | ||
data <<= 1; | ||
} | ||
} | ||
|
||
void IRsend::sendRaw(unsigned int buf[], int len, int hz) | ||
{ | ||
enableIROut(hz); | ||
for (int i = 0; i < len; i++) { | ||
if (i & 1) { | ||
space(buf[i]); | ||
} | ||
else { | ||
mark(buf[i]); | ||
} | ||
} | ||
space(0); // Just to be sure | ||
} | ||
|
||
// Note: first bit must be a one (start bit) | ||
void IRsend::sendRC5(unsigned long data, int nbits) | ||
{ | ||
enableIROut(36); | ||
data = data << (32 - nbits); | ||
mark(RC5_T1); // First start bit | ||
space(RC5_T1); // Second start bit | ||
mark(RC5_T1); // Second start bit | ||
for (int i = 0; i < nbits; i++) { | ||
if (data & TOPBIT) { | ||
space(RC5_T1); // 1 is space, then mark | ||
mark(RC5_T1); | ||
} | ||
else { | ||
mark(RC5_T1); | ||
space(RC5_T1); | ||
} | ||
data <<= 1; | ||
} | ||
space(0); // Turn off at end | ||
} | ||
|
||
// Caller needs to take care of flipping the toggle bit | ||
void IRsend::sendRC6(unsigned long data, int nbits) | ||
{ | ||
enableIROut(36); | ||
data = data << (32 - nbits); | ||
mark(RC6_HDR_MARK); | ||
space(RC6_HDR_SPACE); | ||
mark(RC6_T1); // start bit | ||
space(RC6_T1); | ||
int t; | ||
for (int i = 0; i < nbits; i++) { | ||
if (i == 3) { | ||
// double-wide trailer bit | ||
t = 2 * RC6_T1; | ||
} | ||
else { | ||
t = RC6_T1; | ||
} | ||
if (data & TOPBIT) { | ||
mark(t); | ||
space(t); | ||
} | ||
else { | ||
space(t); | ||
mark(t); | ||
} | ||
|
||
data <<= 1; | ||
} | ||
space(0); // Turn off at end | ||
} | ||
void IRsend::sendPanasonic(unsigned int address, unsigned long data) { | ||
enableIROut(35); | ||
mark(PANASONIC_HDR_MARK); | ||
space(PANASONIC_HDR_SPACE); | ||
|
||
for(int i=0;i<16;i++) | ||
{ | ||
mark(PANASONIC_BIT_MARK); | ||
if (address & 0x8000) { | ||
space(PANASONIC_ONE_SPACE); | ||
} else { | ||
space(PANASONIC_ZERO_SPACE); | ||
} | ||
address <<= 1; | ||
} | ||
for (int i=0; i < 32; i++) { | ||
mark(PANASONIC_BIT_MARK); | ||
if (data & TOPBIT) { | ||
space(PANASONIC_ONE_SPACE); | ||
} else { | ||
space(PANASONIC_ZERO_SPACE); | ||
} | ||
data <<= 1; | ||
} | ||
mark(PANASONIC_BIT_MARK); | ||
space(0); | ||
} | ||
void IRsend::sendJVC(unsigned long data, int nbits, int repeat) | ||
{ | ||
enableIROut(38); | ||
data = data << (32 - nbits); | ||
if (!repeat){ | ||
mark(JVC_HDR_MARK); | ||
space(JVC_HDR_SPACE); | ||
} | ||
for (int i = 0; i < nbits; i++) { | ||
if (data & TOPBIT) { | ||
mark(JVC_BIT_MARK); | ||
space(JVC_ONE_SPACE); | ||
} | ||
else { | ||
mark(JVC_BIT_MARK); | ||
space(JVC_ZERO_SPACE); | ||
} | ||
data <<= 1; | ||
} | ||
mark(JVC_BIT_MARK); | ||
space(0); | ||
} | ||
|
||
void IRsend::sendSAMSUNG(unsigned long data, int nbits) | ||
{ | ||
enableIROut(38); | ||
mark(SAMSUNG_HDR_MARK); | ||
space(SAMSUNG_HDR_SPACE); | ||
for (int i = 0; i < nbits; i++) { | ||
if (data & TOPBIT) { | ||
mark(SAMSUNG_BIT_MARK); | ||
space(SAMSUNG_ONE_SPACE); | ||
} | ||
else { | ||
mark(SAMSUNG_BIT_MARK); | ||
space(SAMSUNG_ZERO_SPACE); | ||
} | ||
data <<= 1; | ||
} | ||
mark(SAMSUNG_BIT_MARK); | ||
space(0); | ||
} | ||
|
||
void IRsend::mark(int time) { | ||
// Sends an IR mark for the specified number of microseconds. | ||
// The mark output is modulated at the PWM frequency. | ||
long beginning = micros(); | ||
while(micros() - beginning < time){ | ||
digitalWrite(IRpin, HIGH); | ||
delayMicroseconds(halfPeriodicTime); | ||
digitalWrite(IRpin, LOW); | ||
delayMicroseconds(halfPeriodicTime); //38 kHz -> T = 26.31 microsec (periodic time), half of it is 13 | ||
} | ||
} | ||
|
||
/* Leave pin off for time (given in microseconds) */ | ||
void IRsend::space(int time) { | ||
// Sends an IR space for the specified number of microseconds. | ||
// A space is no output, so the PWM output is disabled. | ||
digitalWrite(IRpin, LOW); | ||
if (time > 0) delayMicroseconds(time); | ||
} | ||
|
||
void IRsend::enableIROut(int khz) { | ||
// Enables IR output. The khz value controls the modulation frequency in kilohertz. | ||
halfPeriodicTime = 500/khz; // T = 1/f but we need T/2 in microsecond and f is in kHz | ||
} | ||
|
||
|
||
/* Sharp and DISH support by Todd Treece ( http://unionbridge.org/design/ircommand ) | ||
The Dish send function needs to be repeated 4 times, and the Sharp function | ||
has the necessary repeat built in because of the need to invert the signal. | ||
Sharp protocol documentation: | ||
http://www.sbprojects.com/knowledge/ir/sharp.htm | ||
Here are the LIRC files that I found that seem to match the remote codes | ||
from the oscilloscope: | ||
Sharp LCD TV: | ||
http://lirc.sourceforge.net/remotes/sharp/GA538WJSA | ||
DISH NETWORK (echostar 301): | ||
http://lirc.sourceforge.net/remotes/echostar/301_501_3100_5100_58xx_59xx | ||
For the DISH codes, only send the last for characters of the hex. | ||
i.e. use 0x1C10 instead of 0x0000000000001C10 which is listed in the | ||
linked LIRC file. | ||
*/ | ||
|
||
void IRsend::sendSharpRaw(unsigned long data, int nbits) { | ||
enableIROut(38); | ||
|
||
// Sending codes in bursts of 3 (normal, inverted, normal) makes transmission | ||
// much more reliable. That's the exact behaviour of CD-S6470 remote control. | ||
for (int n = 0; n < 3; n++) { | ||
for (int i = 1 << (nbits-1); i > 0; i>>=1) { | ||
if (data & i) { | ||
mark(SHARP_BIT_MARK); | ||
space(SHARP_ONE_SPACE); | ||
} | ||
else { | ||
mark(SHARP_BIT_MARK); | ||
space(SHARP_ZERO_SPACE); | ||
} | ||
} | ||
|
||
mark(SHARP_BIT_MARK); | ||
space(SHARP_ZERO_SPACE); | ||
delay(40); | ||
|
||
data = data ^ SHARP_TOGGLE_MASK; | ||
} | ||
} | ||
|
||
// Sharp send compatible with data obtained through decodeSharp | ||
void IRsend::sendSharp(unsigned int address, unsigned int command) { | ||
sendSharpRaw((address << 10) | (command << 2) | 2, 15); | ||
} | ||
|
||
void IRsend::sendDISH(unsigned long data, int nbits) { | ||
enableIROut(56); | ||
mark(DISH_HDR_MARK); | ||
space(DISH_HDR_SPACE); | ||
for (int i = 0; i < nbits; i++) { | ||
if (data & DISH_TOP_BIT) { | ||
mark(DISH_BIT_MARK); | ||
space(DISH_ONE_SPACE); | ||
} | ||
else { | ||
mark(DISH_BIT_MARK); | ||
space(DISH_ZERO_SPACE); | ||
} | ||
data <<= 1; | ||
} | ||
} |
Oops, something went wrong.