Skip to content

Commit

Permalink
fix: code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
StellaLupus committed Aug 10, 2024
1 parent ebce640 commit 3c8c416
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 57 deletions.
80 changes: 44 additions & 36 deletions src/ir_Electrolux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const uint16_t kElectroluxAcBitMark = 752;
const uint16_t kElectroluxAcHdrSpace = 2700;
const uint16_t kElectroluxAcOneSpace = 2149;
const uint16_t kElectroluxAcZeroSpace = 756;
const uint16_t kElectroluxAcFreq = 38000; // Hz.
const uint16_t kElectroluxAcFreq = 38000;
const uint16_t kElectroluxAcOverhead = 3;

#if SEND_ELECTROLUX_AC
Expand Down Expand Up @@ -48,10 +48,12 @@ void IRsend::sendElectroluxAc(
send_data >>= 32;
// Footer
mark(kElectroluxAcBitMark);
space(kDefaultMessageGap); // A 100% made up guess of the gap between messages.

// A 100% made up guess of the gap between messages.
space(kDefaultMessageGap);
}
}
#endif // SEND_ELECTROLUX
#endif // SEND_ELECTROLUX

#if DECODE_ELECTROLUX_AC
// Function should be safe up to 64 bits.
Expand All @@ -69,8 +71,8 @@ bool IRrecv::decodeElectroluxAc(
const uint16_t nbits,
const bool strict
) {
if (results->rawlen < 2 * nbits + kElectroluxAcOverhead - offset) // rawlen = 68, nbits = 104
return false; // Too short a message to match.
if (results->rawlen < 2 * nbits + kElectroluxAcOverhead - offset)
return false; // Too short a message to match.
if (strict && nbits != kElectroluxAcBits)
return false;

Expand All @@ -84,13 +86,15 @@ bool IRrecv::decodeElectroluxAc(

// Data Section #1
// e.g. data_result.data = 0xED000004, nbits = 32
match_result_t data_result = matchData(&(results->rawbuf[offset]), 32,
kElectroluxAcBitMark, kElectroluxAcOneSpace,
kElectroluxAcBitMark, kElectroluxAcZeroSpace);
match_result_t data_result = matchData(
&(results->rawbuf[offset]), 32,
kElectroluxAcBitMark, kElectroluxAcOneSpace,
kElectroluxAcBitMark, kElectroluxAcZeroSpace);

offset += data_result.used;
if (data_result.success == false)
return false; // Fail
data <<= 32; // Make room for the new bits of data.
return false; // Fail
data <<= 32; // Make room for the new bits of data.
data |= data_result.data;

// Footer
Expand All @@ -105,7 +109,7 @@ bool IRrecv::decodeElectroluxAc(
results->address = 0;
return true;
}
#endif // DECODE_ELECTROLUX
#endif // DECODE_ELECTROLUX

/// Class constructor
/// @param[in] pin GPIO to be used when sending.
Expand All @@ -130,7 +134,7 @@ void IRElectroluxAc::stateReset() { _.raw = 0xF3008005; }
void IRElectroluxAc::send(const uint16_t repeat) {
_irsend.sendElectroluxAc(getRaw(), kElectroluxAcBits, repeat);
}
#endif // SEND_ELECTROLUX_AC
#endif // SEND_ELECTROLUX_AC

/// Set up hardware to be able to send a message.
void IRElectroluxAc::begin() { _irsend.begin(); }
Expand All @@ -145,11 +149,15 @@ bool IRElectroluxAc::getPower() const { return _.Power; }

/// Turn on/off the fahrenheit temp mode.
/// @param[in] on The desired setting state.
void IRElectroluxAc::setTempModeFahrenheit(const bool on) { _.TempModeFahrenheit = on; }
void IRElectroluxAc::setTempModeFahrenheit(const bool on) {
_.TempModeFahrenheit = on;
}

/// Get the fahrenheit temp mode set from the internal state.
/// @return A boolean indicating the setting.
bool IRElectroluxAc::getTempModeFahrenheit() const { return _.TempModeFahrenheit; }
bool IRElectroluxAc::getTempModeFahrenheit() const {
return _.TempModeFahrenheit;
}

/// Set the temperature.
/// @param[in] degrees The temperature in celsius or fahrenheit.
Expand All @@ -162,7 +170,8 @@ void IRElectroluxAc::setTemp(const uint8_t degrees) {
uint8_t temp = max(kElectroluxAcMinTemp, degrees);
temp = min(kElectroluxAcMaxTemp, temp);
#ifndef UNIT_TEST
temp = map(temp, kElectroluxAcMinTemp, kElectroluxAcMaxTemp, kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp);
temp = map(temp, kElectroluxAcMinTemp, kElectroluxAcMaxTemp,
kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp);
#else
temp = temp * 9 / 5 + 32;
#endif
Expand All @@ -177,7 +186,8 @@ uint8_t IRElectroluxAc::getTemp() const {
return _.Temp + kElectroluxAcMinFTemp;
} else {
#ifndef UNIT_TEST
uint8_t temp = map(_.Temp + kElectroluxAcMinFTemp, kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp,
uint8_t temp = map(_.Temp + kElectroluxAcMinFTemp,
kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp,
kElectroluxAcMinTemp, kElectroluxAcMaxTemp);
#else
uint8_t temp = ((_.Temp + kElectroluxAcMinFTemp) - 32) * 5 / 9;
Expand Down Expand Up @@ -225,11 +235,11 @@ uint8_t IRElectroluxAc::getMode() const { return _.Mode; }
void IRElectroluxAc::setOnOffTimer(const uint16_t nr_of_mins) {
const uint8_t hours = std::min(
static_cast<uint8_t>(nr_of_mins / 60),
kElectroluxTimerMax
);
kElectroluxTimerMax);

// The time can be changed in sleep mode, but doesn't set the flag.
_.TimerEnabled = hours > 0;
_.Timer = std::max(kElectroluxTimerMin, hours); // Hours
_.Timer = std::max(kElectroluxTimerMin, hours); // Hours
}

/// Get the current On/Off Timer time.
Expand All @@ -250,7 +260,7 @@ bool IRElectroluxAc::getQuiet() const { return _.Quiet; }
/// Get a copy of the internal state as a valid code for this protocol.
/// @return A valid code for this protocol based on the current internal state.
uint64_t IRElectroluxAc::getRaw() {
checksum(); // Ensure correct settings before sending.
checksum(); // Ensure correct settings before sending.
return _.raw;
}

Expand All @@ -265,10 +275,10 @@ uint8_t IRElectroluxAc::calcChecksum(const uint64_t state) {
uint32_t data = GETBITS64(
state,
kElectroluxAcChecksumSize + kElectroluxAcChecksumOffset,
kElectroluxAcBits - 4
);
kElectroluxAcBits - 4);

uint8_t result = 0;
for (; data; data >>= 4) // Add each nibble together.
for (; data; data >>= 4) // Add each nibble together.
result += GETBITS8(data, 0, 4);
return (result ^ 0xF) & 0xF;
}
Expand Down Expand Up @@ -389,45 +399,43 @@ stdAc::state_t IRElectroluxAc::toCommon(const stdAc::state_t *prev) const {
/// @return The current internal state expressed as a human readable String.
String IRElectroluxAc::toString() const {
String result = "";
result.reserve(120); // Reserve some heap for the string to reduce fragging.
result.reserve(120); // Reserve heap for the string to reduce fragging.

result += addBoolToString(
_.Power,
kPowerStr,
false
);
false);

result += addModeToString(
_.Mode,
kElectroluxModeAuto,
kElectroluxModeCool,
0xFF,
kElectroluxModeDry,
kElectroluxModeFan
);
kElectroluxModeFan);

result += addTempToString(
getTemp(),
!getTempModeFahrenheit()
);
!getTempModeFahrenheit());

result += addFanToString(
_.Fan,
kElectroluxFanHigh,
kElectroluxFanLow,
kElectroluxFanAuto,
kElectroluxFanAuto,
kElectroluxFanMedium
);
kElectroluxFanMedium);

result += addBoolToString(getQuiet(), kQuietStr);

if (getPower()) {
result += irutils::addLabeledString(
irutils::minsToString(getOnOffTimer()),
kOffTimerStr
);
kOffTimerStr);
} else {
result += irutils::addLabeledString(
irutils::minsToString(getOnOffTimer()),
kOnTimerStr
);
kOnTimerStr);
}
return result;
}
Expand Down
42 changes: 21 additions & 21 deletions src/ir_Electrolux.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#endif

union ElectroluxAcProtocol {
uint64_t raw; // The state of the IR remote in native IR code form.
uint64_t raw; // The state of the IR remote in native IR code form.
struct {
uint8_t Sum: 4;
uint8_t : 4;
Expand All @@ -39,30 +39,30 @@ union ElectroluxAcProtocol {
};

// Constants
const uint8_t kElectroluxAcMinTemp = 16; // 16C
const uint8_t kElectroluxAcMaxTemp = 32; // 32C
const uint8_t kElectroluxAcMinFTemp = 60; // 60F
const uint8_t kElectroluxAcMaxFTemp = 90; // 90F
const uint8_t kElectroluxTimerMax = 12; // 12H
const uint8_t kElectroluxTimerMin = 1; // 1H
const uint8_t kElectroluxAcMinTemp = 16; // 16C
const uint8_t kElectroluxAcMaxTemp = 32; // 32C
const uint8_t kElectroluxAcMinFTemp = 60; // 60F
const uint8_t kElectroluxAcMaxFTemp = 90; // 90F
const uint8_t kElectroluxTimerMax = 12; // 12H
const uint8_t kElectroluxTimerMin = 1; // 1H
const uint64_t kElectroluxAcKnownGoodState = 0xF3008005;
const uint8_t kElectroluxAcChecksumOffset = 0;
const uint8_t kElectroluxAcChecksumSize = 4;

// Fan
const uint8_t kElectroluxFanLow = 2; // 0b11
const uint8_t kElectroluxFanMedium = 1; // 0b01
const uint8_t kElectroluxFanHigh = 0; // 0b00
const uint8_t kElectroluxFanAuto = 3; // 0b11
const uint8_t kElectroluxFanLow = 2; // 0b11
const uint8_t kElectroluxFanMedium = 1; // 0b01
const uint8_t kElectroluxFanHigh = 0; // 0b00
const uint8_t kElectroluxFanAuto = 3; // 0b11

// Modes
const uint8_t kElectroluxModeCool = 0; // 0b000
const uint8_t kElectroluxModeDry = 1; // 0b001
const uint8_t kElectroluxModeFan = 2; // 0b010
const uint8_t kElectroluxModeAuto = 4; // 0b100
const uint8_t kElectroluxModeCool = 0; // 0b000
const uint8_t kElectroluxModeDry = 1; // 0b001
const uint8_t kElectroluxModeFan = 2; // 0b010
const uint8_t kElectroluxModeAuto = 4; // 0b100

class IRElectroluxAc {
public:
public:
explicit IRElectroluxAc(uint16_t pin, bool inverted = false,
bool use_modulation = true);

Expand All @@ -75,7 +75,7 @@ class IRElectroluxAc {
/// @note This will produce a 65ms IR signal pulse at 38kHz.
/// Only ever needs to be run once per object instantiation, if at all.
int8_t calibrate() { return _irsend.calibrate(); }
#endif // SEND_ELECTROLUX_AC
#endif // SEND_ELECTROLUX_AC
void begin();

void on();
Expand Down Expand Up @@ -132,16 +132,16 @@ class IRElectroluxAc {

#ifndef UNIT_TEST

private:
IRsend _irsend; ///< Instance of the IR send class
private:
IRsend _irsend; ///< Instance of the IR send class
#else // UNIT_TEST
/// @cond IGNORE
IRsendTest _irsend; ///< Instance of the testing IR send class
IRsendTest _irsend; ///< Instance of the testing IR send class
/// @endcond
#endif // UNIT_TEST
ElectroluxAcProtocol _{};

void checksum();
};

#endif // IR_ELECTROLUX_AC_H_
#endif // IR_ELECTROLUX_AC_H_

0 comments on commit 3c8c416

Please sign in to comment.