mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2026-01-03 03:52:54 +00:00
Merge pull request #198 from pcoughlin/master
update custom_delay function
This commit is contained in:
@@ -253,7 +253,7 @@ class IRsend
|
|||||||
public:
|
public:
|
||||||
IRsend () { }
|
IRsend () { }
|
||||||
|
|
||||||
void custom_delay_ms (unsigned int time);
|
void custom_delay_usec (unsigned long uSecs);
|
||||||
void enableIROut (int khz) ;
|
void enableIROut (int khz) ;
|
||||||
void mark (int usec) ;
|
void mark (int usec) ;
|
||||||
void space (int usec) ;
|
void space (int usec) ;
|
||||||
|
|||||||
26
irSend.cpp
26
irSend.cpp
@@ -22,7 +22,7 @@ void IRsend::sendRaw (unsigned int buf[], unsigned char len, unsigned char hz
|
|||||||
void IRsend::mark (int time)
|
void IRsend::mark (int time)
|
||||||
{
|
{
|
||||||
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
|
TIMER_ENABLE_PWM; // Enable pin 3 PWM output
|
||||||
if (time > 0) custom_delay_ms(time);
|
if (time > 0) custom_delay_usec(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
//+=============================================================================
|
//+=============================================================================
|
||||||
@@ -33,7 +33,7 @@ void IRsend::mark (int time)
|
|||||||
void IRsend::space (int time)
|
void IRsend::space (int time)
|
||||||
{
|
{
|
||||||
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
|
TIMER_DISABLE_PWM; // Disable pin 3 PWM output
|
||||||
if (time > 0) IRsend::custom_delay_ms(time);
|
if (time > 0) IRsend::custom_delay_usec(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,14 +71,16 @@ void IRsend::enableIROut (int khz)
|
|||||||
//+=============================================================================
|
//+=============================================================================
|
||||||
// Custom delay function that circumvents Arduino's delayMicroseconds limit
|
// Custom delay function that circumvents Arduino's delayMicroseconds limit
|
||||||
|
|
||||||
void IRsend::custom_delay_ms(unsigned int time) {
|
void IRsend::custom_delay_usec(unsigned long uSecs) {
|
||||||
if (time)
|
if (uSecs > 4) {
|
||||||
{
|
unsigned long start = micros();
|
||||||
if (time > 16000)
|
unsigned long endMicros = start + uSecs - 4;
|
||||||
{
|
if (endMicros < start) { // Check if overflow
|
||||||
delayMicroseconds(time % 1000);
|
while ( micros() > start ) {} // wait until overflow
|
||||||
delay(time / 1000);
|
}
|
||||||
}
|
while ( micros() < endMicros ) {} // normal wait
|
||||||
else delayMicroseconds(time);
|
} else {
|
||||||
}
|
__asm__("nop\n\t"); // must have or compiler optimizes out
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user