diff --git a/src/ir_JVC.cpp b/src/ir_JVC.cpp index 0efc51b59..5a4017ec5 100644 --- a/src/ir_JVC.cpp +++ b/src/ir_JVC.cpp @@ -69,7 +69,11 @@ void IRsend::sendJVC(uint64_t data, uint16_t nbits, uint16_t repeat) { data, nbits, 38, true, 0, // Repeats are handles elsewhere. 33); // Wait till the end of the repeat time window before we send another code. - space(std::max(JVC_RPT_LENGTH - JVC_MIN_GAP - usecs.elapsed(), 0U)); + uint32_t elapsed = usecs.elapsed(); + // Avoid potential unsigned integer underflow. + // e.g. when elapsed > JVC_RPT_LENGTH. + if (elapsed < JVC_RPT_LENGTH) + space(JVC_RPT_LENGTH - elapsed); usecs.reset(); } } diff --git a/src/ir_Whynter.cpp b/src/ir_Whynter.cpp index 17489f4f6..2306343b6 100644 --- a/src/ir_Whynter.cpp +++ b/src/ir_Whynter.cpp @@ -4,7 +4,6 @@ #include #include "IRrecv.h" #include "IRsend.h" -#include "IRtimer.h" #include "IRutils.h" // W W H H Y Y N N TTTTT EEEEE RRRRR @@ -54,10 +53,8 @@ void IRsend::sendWhynter(uint64_t data, uint16_t nbits, uint16_t repeat) { // Set IR carrier frequency enableIROut(38); - IRtimer usecTimer = IRtimer(); for (uint16_t i = 0; i <= repeat; i++) { - usecTimer.reset(); // (Pre-)Header mark(WHYNTER_BIT_MARK); space(WHYNTER_ZERO_SPACE); @@ -65,10 +62,10 @@ void IRsend::sendWhynter(uint64_t data, uint16_t nbits, uint16_t repeat) { WHYNTER_BIT_MARK, WHYNTER_ONE_SPACE, WHYNTER_BIT_MARK, WHYNTER_ZERO_SPACE, WHYNTER_BIT_MARK, WHYNTER_MIN_GAP, + WHYNTER_MIN_COMMAND_LENGTH - (WHYNTER_BIT_MARK + + WHYNTER_ZERO_SPACE), data, nbits, 38, true, 0, // Repeats are already handled. 50); - space(std::max(WHYNTER_MIN_COMMAND_LENGTH - WHYNTER_MIN_GAP - - usecTimer.elapsed(), 0U)); } } #endif diff --git a/test/ir_JVC_test.cpp b/test/ir_JVC_test.cpp index 0826b2268..de7d9224e 100644 --- a/test/ir_JVC_test.cpp +++ b/test/ir_JVC_test.cpp @@ -17,7 +17,7 @@ TEST(TestSendJVC, SendDataOnly) { "m8400s4200" "m525s1725m525s1725m525s525m525s525m525s525m525s525m525s1725m525s525" "m525s1725m525s525m525s1725m525s1725m525s1725m525s525m525s525m525s525" - "m525s60000", irsend.outputStr()); + "m525s70875", irsend.outputStr()); } // Test sending with different repeats. @@ -31,22 +31,22 @@ TEST(TestSendJVC, SendWithRepeats) { "m8400s4200" "m525s1725m525s1725m525s525m525s525m525s525m525s525m525s1725m525s525" "m525s1725m525s525m525s1725m525s1725m525s1725m525s525m525s525m525s525" - "m525s60000" + "m525s70875" "m525s1725m525s1725m525s525m525s525m525s525m525s525m525s1725m525s525" "m525s1725m525s525m525s1725m525s1725m525s1725m525s525m525s525m525s525" - "m525s60000", irsend.outputStr()); + "m525s70875", irsend.outputStr()); irsend.sendJVC(0xC2B8, JVC_BITS, 2); // 2 repeats. EXPECT_EQ( "m8400s4200" "m525s1725m525s1725m525s525m525s525m525s525m525s525m525s1725m525s525" "m525s1725m525s525m525s1725m525s1725m525s1725m525s525m525s525m525s525" - "m525s60000" + "m525s70875" "m525s1725m525s1725m525s525m525s525m525s525m525s525m525s1725m525s525" "m525s1725m525s525m525s1725m525s1725m525s1725m525s525m525s525m525s525" - "m525s60000" + "m525s70875" "m525s1725m525s1725m525s525m525s525m525s525m525s525m525s1725m525s525" "m525s1725m525s525m525s1725m525s1725m525s1725m525s525m525s525m525s525" - "m525s60000", irsend.outputStr()); + "m525s70875", irsend.outputStr()); } // Test sending an atypical data size. @@ -59,7 +59,7 @@ TEST(TestSendJVC, SendUsualSize) { EXPECT_EQ( "m8400s4200" "m525s525m525s525m525s525m525s525m525s525m525s525m525s525m525s525" - "m525s60000", irsend.outputStr()); + "m525s70875", irsend.outputStr()); irsend.reset(); irsend.sendJVC(0x1234567890ABCDEF, 64); @@ -73,7 +73,7 @@ TEST(TestSendJVC, SendUsualSize) { "m525s1725m525s525m525s1725m525s525m525s1725m525s525m525s1725m525s1725" "m525s1725m525s1725m525s525m525s525m525s1725m525s1725m525s525m525s1725" "m525s1725m525s1725m525s1725m525s525m525s1725m525s1725m525s1725m525s1725" - "m525s60000", irsend.outputStr()); + "m525s70875", irsend.outputStr()); } // Tests for encodeJVC(). diff --git a/test/ir_Whynter_test.cpp b/test/ir_Whynter_test.cpp index 4978bb6f5..72dc86e83 100644 --- a/test/ir_Whynter_test.cpp +++ b/test/ir_Whynter_test.cpp @@ -19,7 +19,7 @@ TEST(TestSendWhynter, SendDataOnly) { "m750s750m750s750m750s750m750s750m750s750m750s750m750s750m750s750" "m750s750m750s750m750s750m750s750m750s750m750s750m750s750m750s750" "m750s750m750s750m750s750m750s750m750s750m750s750m750s750m750s750" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); irsend.reset(); irsend.sendWhynter(0xFFFFFFFF); @@ -29,7 +29,7 @@ TEST(TestSendWhynter, SendDataOnly) { "m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150" "m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150" "m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150m750s2150" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); irsend.reset(); irsend.sendWhynter(0x87654321); @@ -39,7 +39,7 @@ TEST(TestSendWhynter, SendDataOnly) { "m750s750m750s2150m750s2150m750s750m750s750m750s2150m750s750m750s2150" "m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150" "m750s750m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); } // Test sending with different repeats. @@ -55,7 +55,7 @@ TEST(TestSendWhynter, SendWithRepeats) { "m750s750m750s2150m750s2150m750s750m750s750m750s2150m750s750m750s2150" "m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150" "m750s750m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); irsend.reset(); irsend.sendWhynter(0x87654321, WHYNTER_BITS, 1); // 1 repeat. @@ -65,13 +65,13 @@ TEST(TestSendWhynter, SendWithRepeats) { "m750s750m750s2150m750s2150m750s750m750s750m750s2150m750s750m750s2150" "m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150" "m750s750m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150" - "m750s108000" + "m750s106500" "m750s750m2850s2850" "m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150m750s2150" "m750s750m750s2150m750s2150m750s750m750s750m750s2150m750s750m750s2150" "m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150" "m750s750m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); irsend.sendWhynter(0x87654321, WHYNTER_BITS, 2); // 2 repeats. EXPECT_EQ( "m750s750m2850s2850" @@ -79,19 +79,19 @@ TEST(TestSendWhynter, SendWithRepeats) { "m750s750m750s2150m750s2150m750s750m750s750m750s2150m750s750m750s2150" "m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150" "m750s750m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150" - "m750s108000" + "m750s106500" "m750s750m2850s2850" "m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150m750s2150" "m750s750m750s2150m750s2150m750s750m750s750m750s2150m750s750m750s2150" "m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150" "m750s750m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150" - "m750s108000" + "m750s106500" "m750s750m2850s2850" "m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150m750s2150" "m750s750m750s2150m750s2150m750s750m750s750m750s2150m750s750m750s2150" "m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150m750s2150" "m750s750m750s750m750s2150m750s750m750s750m750s750m750s750m750s2150" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); } // Test sending an atypical data size. @@ -104,7 +104,7 @@ TEST(TestSendWhynter, SendUnusualSize) { EXPECT_EQ( "m750s750m2850s2850" "m750s750m750s750m750s750m750s750m750s750m750s750m750s750m750s750" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); irsend.reset(); irsend.sendWhynter(0x1234567890ABCDEF, 64); @@ -118,7 +118,7 @@ TEST(TestSendWhynter, SendUnusualSize) { "m750s2150m750s750m750s2150m750s750m750s2150m750s750m750s2150m750s2150" "m750s2150m750s2150m750s750m750s750m750s2150m750s2150m750s750m750s2150" "m750s2150m750s2150m750s2150m750s750m750s2150m750s2150m750s2150m750s2150" - "m750s108000", irsend.outputStr()); + "m750s106500", irsend.outputStr()); } // Tests for decodeWhynter().