Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed long delay bug and minor doc improvements.

- Delays longer than 16383us were unreliable, due to a quirk/bug in
  Arduino's delayMicroseconds.

- Some parameters that were meant to hold kHz values were named "hz", so
  renamed them to "khz".

- The meaning of sendRaw's buf parameter wasn't obvious to me, so I
  added a comment explaining it.
  • Loading branch information...
commit 026866b2ddfd58414c8680f427cd8367f9a2cc32 1 parent 3f70ad2
@xenomachina authored
Showing with 20 additions and 5 deletions.
  1. +19 −4 IRremote.cpp
  2. +1 −1  IRremote.h
View
23 IRremote.cpp
@@ -105,9 +105,11 @@ void IRsend::sendSony(unsigned long data, int nbits) {
}
}
-void IRsend::sendRaw(unsigned int buf[], int len, int hz)
+// buf is alternating mark and space durations (in microseconds), starting with
+// a mark at index 0.
+void IRsend::sendRaw(unsigned int buf[], int len, int khz)
{
- enableIROut(hz);
+ enableIROut(khz);
for (int i = 0; i < len; i++) {
if (i & 1) {
space(buf[i]);
@@ -221,11 +223,24 @@ void IRsend::sendJVC(unsigned long data, int nbits, int repeat)
mark(JVC_BIT_MARK);
space(0);
}
+
+// This works around a deficiency in Arduino's delayMicroseconds where it
+// is unreliable for values over 16383.
+static void delayMicrosecondsCorrectly(int micros) {
+ if (micros > 16383) {
+ int millis = micros - (micros % 16000);
+ micros -= millis;
+ millis /= 1000;
+ delay(millis);
+ }
+ delayMicroseconds(micros);
+}
+
void IRsend::mark(int time) {
// Sends an IR mark for the specified number of microseconds.
// The mark output is modulated at the PWM frequency.
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
- delayMicroseconds(time);
+ delayMicrosecondsCorrectly(time);
}
/* Leave pin off for time (given in microseconds) */
@@ -233,7 +248,7 @@ 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.
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
- delayMicroseconds(time);
+ delayMicrosecondsCorrectly(time);
}
void IRsend::enableIROut(int khz) {
View
2  IRremote.h
@@ -92,7 +92,7 @@ class IRsend
// Neither Sanyo nor Mitsubishi send is implemented yet
// void sendSanyo(unsigned long data, int nbits);
// void sendMitsubishi(unsigned long data, int nbits);
- void sendRaw(unsigned int buf[], int len, int hz);
+ void sendRaw(unsigned int buf[], int len, int khz);
void sendRC5(unsigned long data, int nbits);
void sendRC6(unsigned long data, int nbits);
void sendDISH(unsigned long data, int nbits);
Please sign in to comment.
Something went wrong with that request. Please try again.