Skip to content

Commit

Permalink
Midea: make beep configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
fmck3516 committed Sep 21, 2024
1 parent ce0a65e commit e4e7d43
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/IRrecvDumpV2/IRrecvDumpV2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
67 changes: 67 additions & 0 deletions examples/TurnOnMidea/TurnOnMidea.ino
Original file line number Diff line number Diff line change
@@ -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 <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Midea.h>

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);
}
18 changes: 18 additions & 0 deletions examples/TurnOnMidea/platformio.ini
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions src/IRutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/IRutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/ir_Midea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/ir_Midea.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/ir_Midea_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e4e7d43

Please sign in to comment.