diff --git a/examples/IRrecvDumpV2/IRrecvDumpV2.ino b/examples/IRrecvDumpV2/IRrecvDumpV2.ino index 24281677d..d0520ec1a 100644 --- a/examples/IRrecvDumpV2/IRrecvDumpV2.ino +++ b/examples/IRrecvDumpV2/IRrecvDumpV2.ino @@ -42,7 +42,7 @@ #ifdef ARDUINO_ESP32C3_DEV const uint16_t kRecvPin = 10; // 14 on a ESP32-C3 causes a boot loop. #else // ARDUINO_ESP32C3_DEV -const uint16_t kRecvPin = 14; +const uint16_t kRecvPin = 4; #endif // ARDUINO_ESP32C3_DEV // The Serial connection baud rate. diff --git a/examples/TurnOnMidea/TurnOnMidea.ino b/examples/TurnOnMidea/TurnOnMidea.ino new file mode 100644 index 000000000..cdd3e41ff --- /dev/null +++ b/examples/TurnOnMidea/TurnOnMidea.ino @@ -0,0 +1,67 @@ +/* Copyright 2017, 2018 David Conran +* +* An IR LED circuit *MUST* be connected to the ESP8266 on a pin +* as specified by kIrLed below. +* +* TL;DR: The IR LED needs to be driven by a transistor for a good result. +* +* Suggested circuit: +* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending +* +* Common mistakes & tips: +* * Don't just connect the IR LED directly to the pin, it won't +* have enough current to drive the IR LED effectively. +* * Make sure you have the IR LED polarity correct. +* See: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity +* * Typical digital camera/phones can be used to see if the IR LED is flashed. +* Replace the IR LED with a normal LED if you don't have a digital camera +* when debugging. +* * Avoid using the following pins unless you really know what you are doing: +* * Pin 0/D3: Can interfere with the boot/program mode & support circuits. +* * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will interfere. +* * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere. +* * ESP-01 modules are tricky. We suggest you use a module with more GPIOs +* for your first time. e.g. ESP-12 etc. +*/ +#include +#include +#include +#include + +const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2). +IRMideaAC ac(kIrLed); // Set the GPIO used for sending messages. + +void printState() { + // Display the settings. + Serial.println("Mitsubishi A/C remote is in the following state:"); + Serial.printf(" %s\n", ac.toString().c_str()); + // Display the encoded IR sequence. + unsigned char* ir_code = ac.getRaw(); + Serial.print("IR Code: 0x"); + for (uint8_t i = 0; i < kMitsubishiACStateLength; i++) + Serial.printf("%02X", ir_code[i]); + Serial.println(); +} + +void setup() { + ac.begin(); + Serial.begin(115200); + delay(200); + + Serial.println("Default state of the remote."); + printState(); + Serial.println("Setting desired state for A/C."); + ac.on(); + ac.setMode(kMideaACFan); + ac.setBeep(false); +} + +void loop() { + // Now send the IR signal. +#if SEND_MITSUBISHI_AC + Serial.println("Sending IR command to A/C ..."); + ac.send(); +#endif // SEND_MITSUBISHI_AC + printState(); + delay(5000); +} diff --git a/examples/TurnOnMidea/platformio.ini b/examples/TurnOnMidea/platformio.ini new file mode 100644 index 000000000..6bda1bb71 --- /dev/null +++ b/examples/TurnOnMidea/platformio.ini @@ -0,0 +1,18 @@ +[platformio] +src_dir = . + +[env] +lib_extra_dirs = ../../ +lib_ldf_mode = deep+ +lib_ignore = examples +framework = arduino +monitor_speed = 115200 +build_flags = ; -D_IR_LOCALE_=en-AU + +[env:nodemcuv2] +platform = espressif8266 +board = nodemcuv2 + +[env:esp32dev] +platform = espressif32 +board = esp32dev diff --git a/platformio.ini b/platformio.ini index 76c2f3b40..3155bd5c0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,12 +11,6 @@ platform = espressif8266 build_flags = ; -D_IR_LOCALE_=en-AU monitor_speed = 115200 -[env:nodemcuv2] -board = nodemcuv2 - -[env:d1_mini] -board = d1_mini - [env:esp32dev] platform = espressif32 board = esp32dev diff --git a/src/IRutils.cpp b/src/IRutils.cpp index d8cabaff4..b616116fd 100644 --- a/src/IRutils.cpp +++ b/src/IRutils.cpp @@ -794,6 +794,21 @@ namespace irutils { return result + ')'; } + /// Create a String of human output for the beep bit. + /// @param[in] beep Is beep bit set ? + /// @return The resulting String. + String addBeepToString(const bool beep) { + String result = ""; + if (beep) { + result.reserve(10); + result += ", Beep: On"; + } else { + result.reserve(11); + result += ", Beep: Off"; + } + return result; + } + /// Create a String of the 3-letter day of the week from a numerical day of /// the week. e.g. "Day: 1 (Mon)" /// @param[in] day_of_week A numerical version of the sequential day of the diff --git a/src/IRutils.h b/src/IRutils.h index 8c94df228..15cb04d83 100644 --- a/src/IRutils.h +++ b/src/IRutils.h @@ -88,6 +88,7 @@ namespace irutils { const uint8_t low, const uint8_t lowest, const uint8_t off, const uint8_t swing, const uint8_t breeze, const uint8_t circulate); + String addBeepToString(const bool beep = true); String addDayToString(const uint8_t day_of_week, const int8_t offset = 0, const bool precomma = true); String addTimerModeToString(const uint8_t timerType, const uint8_t noTimer, diff --git a/src/ir_Midea.cpp b/src/ir_Midea.cpp index 80acfcda3..24f949a36 100644 --- a/src/ir_Midea.cpp +++ b/src/ir_Midea.cpp @@ -496,6 +496,14 @@ bool IRMideaAC::getQuiet(void) const { return _Quiet; } +bool IRMideaAC::getBeep(void) const { + return _.BeepDisable; +} + +void IRMideaAC::setBeep(const bool on) { + _.BeepDisable = on; +} + /// Calculate the checksum for a given state. /// @param[in] state The value to calc the checksum of. /// @return The calculated checksum value. @@ -740,6 +748,8 @@ String IRMideaAC::toString(void) { result += addToggleToString(getLightToggle(), kLightStr); result += addToggleToString(getCleanToggle(), kCleanStr); result += addToggleToString(get8CHeatToggle(), k8CHeatStr); + result += irutils::addBeepToString(getBeep()); + return result; } diff --git a/src/ir_Midea.h b/src/ir_Midea.h index e44055e79..053095834 100644 --- a/src/ir_Midea.h +++ b/src/ir_Midea.h @@ -234,6 +234,8 @@ class IRMideaAC { void setQuiet(const bool on); void setQuiet(const bool on, const bool prev); bool getQuiet(void) const; + bool getBeep(void) const; + void setBeep(const bool on); uint8_t getType(void) const; bool isOnTimerEnabled(void) const; uint16_t getOnTimer(void) const; diff --git a/test/Makefile b/test/Makefile index 8c0a33da4..282a6df48 100644 --- a/test/Makefile +++ b/test/Makefile @@ -25,10 +25,10 @@ INCLUDES = -I$(USER_DIR) -I. # Flags passed to the preprocessor. # Set Google Test's header directory as a system directory, such that # the compiler doesn't generate warnings in Google Test headers. -CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include -DUNIT_TEST -D_IR_LOCALE_=en-AU +CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include -DUNIT_TEST -D_IR_LOCALE_=en-AU # Flags passed to the C++ compiler. -CXXFLAGS += -g -Wall -Wextra -Werror -pthread -std=gnu++11 +CXXFLAGS += -g -Wall -Wextra -Werror -pthread -std=gnu++11 -Wno-parentheses -Wno-unused-const-variable -Wno-deprecated-declarations -Wno-literal-conversion # Google Test libraries GTEST_LIBS = gtest.a gtest_main.a gmock.a gmock_main.a diff --git a/test/ir_Midea_test.cpp b/test/ir_Midea_test.cpp index 0660f8afc..104bb7185 100644 --- a/test/ir_Midea_test.cpp +++ b/test/ir_Midea_test.cpp @@ -252,6 +252,25 @@ TEST(TestMideaACClass, Power) { EXPECT_EQ(0xA1026FFFFFE2, midea.getRaw()); } +// Tests for controlling the beep state. +TEST(TestMideaACClass, Beep) { + IRMideaAC midea(0); + midea.begin(); + + midea.setRaw(0xA1026FFFFFE2); // Power off. + + midea.on(); + midea.setBeep(true); + EXPECT_TRUE(midea.getBeep()); + + EXPECT_EQ(0xA1826FFFFF62, midea.getRaw()); + + midea.setBeep(false); + EXPECT_FALSE(midea.getBeep()); + EXPECT_EQ(0xA1026FFFFFE2, midea.getRaw()); +} + + // Tests for the various Checksum routines. TEST(TestMideaACClass, Checksums) { IRMideaAC midea(0);