Add 2 macro to activate or deactivate LOG messages through DEBUG variable

To activate DEBUG message do : #define DEBUG 1
This commit is contained in:
Memiks 2021-04-10 15:15:38 +09:00
parent 0773d6a437
commit 056717fe8f
5 changed files with 36 additions and 28 deletions

View File

@ -6,6 +6,14 @@
#include <Arduino.h>
#if defined(DEBUG) && (DEBUG > 0)
#define LOG(...) Serial.print(__VA_ARGS__)
#define LOGLN(...) Serial.println(__VA_ARGS__)
#else
#define LOG(...)
#define LOGLN(...)
#endif
#ifdef ESP8266
#include <IRsend.h> // From IRremoteESP8266 library
#include <stdint.h>

View File

@ -292,7 +292,7 @@ void MitsubishiHeatpumpIR::sendMitsubishi(IRSender& IR, uint8_t powerMode, uint8
// Set the temperature on the template message
if (temperature == 10) {
Serial.println(F("Temp=10 maintenance mode"));
LOGLN(F("Temp=10 maintenance mode"));
MitsubishiTemplate[7] = 0x00; // Maintenance mode
MitsubishiTemplate[15] = 0x20; // This seems to be set to 0x20 on maintenance mode
} else {
@ -329,7 +329,7 @@ void MitsubishiHeatpumpIR::sendMitsubishi(IRSender& IR, uint8_t powerMode, uint8
#ifdef IR_SEND_TIME
if (_mitsubishiModel == MITSUBISHI_KJ) {
#ifdef DEBUG
Serial.printf("Send time %02d:%02d day %d --> %x\n", sendHour, sendMinute, sendWeekday, (sendHour * 60 + sendMinute)/10);
LOGf("Send time %02d:%02d day %d --> %x\n", sendHour, sendMinute, sendWeekday, (sendHour * 60 + sendMinute)/10);
#endif
MitsubishiTemplate[10] = (uint8_t)((sendHour * 60 + sendMinute)/10);
// Sunday is start if week , value 1
@ -337,7 +337,7 @@ void MitsubishiHeatpumpIR::sendMitsubishi(IRSender& IR, uint8_t powerMode, uint8
}
else {
#ifdef DEBUG
Serial.printf("Send time %02d:%02d --> %x\n", sendHour, sendMinute, (sendHour * 60 + sendMinute)/6);
LOGf("Send time %02d:%02d --> %x\n", sendHour, sendMinute, (sendHour * 60 + sendMinute)/6);
#endif
MitsubishiTemplate[10] = (uint8_t)((sendHour * 60 + sendMinute)/6);
}
@ -351,7 +351,7 @@ void MitsubishiHeatpumpIR::sendMitsubishi(IRSender& IR, uint8_t powerMode, uint8
sprintf_P(pbyte, PSTR("[%02d]=%02x "), i, (int) MitsubishiTemplate[i]);
strcat(IRPacket, pbyte);
}
Serial.println(IRPacket);
LOGLN(IRPacket);
#else
// Calculate the checksum
for (int i=0; i<17; i++) {

View File

@ -422,21 +422,21 @@ void MitsubishiHeavyZMPHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint
/* ZMP model has no horizontal swing
*/
Serial.println("Calling sendHeavy from ZMP with");
Serial.print(F("PowerMode: "));
Serial.println(powerMode);
Serial.print(F("OperatingMode: "));
Serial.println(operatingMode);
Serial.print(F("FanSpeed: "));
Serial.println(fanSpeed);
Serial.print(F("Temperature: "));
Serial.println(temperature);
Serial.print(F("swingV: "));
Serial.println(swingV);
Serial.print(F("swingH: "));
Serial.println(swingH);
Serial.print(F("cleanMode: "));
Serial.println(cleanMode);
LOGLN("Calling sendHeavy from ZMP with");
LOG(F("PowerMode: "));
LOGLN(powerMode);
LOG(F("OperatingMode: "));
LOGLN(operatingMode);
LOG(F("FanSpeed: "));
LOGLN(fanSpeed);
LOG(F("Temperature: "));
LOGLN(temperature);
LOG(F("swingV: "));
LOGLN(swingV);
LOG(F("swingH: "));
LOGLN(swingH);
LOG(F("cleanMode: "));
LOGLN(cleanMode);
sendMitsubishiHeavy(IR, powerMode, operatingMode, fanSpeed, temperature, swingV, swingH, cleanMode);
}
@ -553,10 +553,10 @@ void MitsubishiHeavyZMPHeatpumpIR::sendMitsubishiHeavy(IRSender& IR, uint8_t pow
// Data
for (uint8_t i=0; i<sizeof(MitsubishiHeavyZMPTemplate); i++) {
Serial.print(F("Byte "));
Serial.print(i);
Serial.print(F(": "));
Serial.println(MitsubishiHeavyZMPTemplate[i]);
LOG(F("Byte "));
LOG(i);
LOG(F(": "));
LOGLN(MitsubishiHeavyZMPTemplate[i]);
IR.sendIRbyte(MitsubishiHeavyZMPTemplate[i], MITSUBISHI_HEAVY_BIT_MARK, MITSUBISHI_HEAVY_ZERO_SPACE, MITSUBISHI_HEAVY_ONE_SPACE);
}

View File

@ -131,10 +131,10 @@ void MitsubishiMSCHeatpumpIR::sendMitsubishiMSC(IRSender& IR, uint8_t powerMode,
for (int i=0; i<templateSize; i++) {
checksum += MitsubishiTemplate[i];
sprintf_P(pbyte, PSTR(",%02x"),(int) MitsubishiTemplate[i]);
Serial.print(pbyte);
LOG(pbyte);
}
Serial.println("");
LOGLN("");
#endif
// 38 kHz PWM frequency

View File

@ -128,8 +128,8 @@ void PanasonicCKPHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t op
// Note that the argument to 'timer.after' has to be explicitly cast into 'long'
panasonicCancelTimer = timer.after(2L*60L*1000L, sendPanasonicCKPCancelTimer);
Serial.print(F("'Timer cancel' timer ID: "));
Serial.println(panasonicCancelTimer);
LOG(F("'Timer cancel' timer ID: "));
LOGLN(panasonicCancelTimer);
*/
}
@ -255,7 +255,7 @@ void PanasonicCKPHeatpumpIR::sendPanasonicCKPOnOffTimerCancel(IRSender& IR, bool
// Send the Panasonic CKP timer cancel
void PanasonicCKPHeatpumpIR::sendPanasonicCKPCancelTimer(IRSender& IR)
{
Serial.println(F("Sending Panasonic CKP timer cancel"));
LOGLN(F("Sending Panasonic CKP timer cancel"));
sendPanasonicCKPOnOffTimerCancel(IR, false, true);
}