Skip to content

Commit

Permalink
fix: set temp accuracy
Browse files Browse the repository at this point in the history
fix: checksum
  • Loading branch information
StellaLupus committed Aug 10, 2024
1 parent eec3252 commit 68aff0f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 130 deletions.
2 changes: 1 addition & 1 deletion src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,7 @@ void IRac::electrolux(IRElectroluxAc *ac,
const bool quiet) {
ac->begin();
ac->stateReset();
ac->setPowerToggle(on);
ac->setPower(on);
ac->setMode(ac->convertMode(mode));
ac->setTempModeFahrenheit(!celsius);
ac->setTemp(degrees);
Expand Down
42 changes: 25 additions & 17 deletions src/ir_Electrolux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Brand: Electrolux, Model: Electrolux EACM EZ/N3

#include "ir_Electrolux.h"
#include <Arduino.h>
#include <algorithm>
#include "IRac.h"
#include "IRrecv.h"
Expand Down Expand Up @@ -36,8 +37,7 @@ void IRsend::sendElectroluxAc(const uint64_t data, const uint16_t nbits, const u
// Header
mark(kElectroluxAcHdrMark);
space(kElectroluxAcHdrSpace);
// Data Section #1
// e.g. data = 0xED000004, nbits = 32
// Data Section
sendData(kElectroluxAcBitMark, kElectroluxAcOneSpace, kElectroluxAcBitMark, kElectroluxAcZeroSpace, send_data, 32, true);
send_data >>= 32;
// Footer
Expand Down Expand Up @@ -124,11 +124,11 @@ void IRElectroluxAc::begin(void) { _irsend.begin(); }

/// Turn on/off the Power Airwell setting.
/// @param[in] on The desired setting state.
void IRElectroluxAc::setPowerToggle(const bool on) { _.PowerToggle = on; }
void IRElectroluxAc::setPower(const bool on) { _.Power = on; }

/// Get the power toggle setting from the internal state.
/// @return A boolean indicating the setting.
bool IRElectroluxAc::getPowerToggle(void) const { return _.PowerToggle; }
bool IRElectroluxAc::getPower(void) const { return _.Power; }

/// Turn on/off the fahrenheit temp mode.
/// @param[in] on The desired setting state.
Expand All @@ -142,14 +142,15 @@ bool IRElectroluxAc::getTempModeFahrenheit(void) const { return _.TempModeFahren
/// @param[in] degrees The temperature in celsius or fahrenheit.
void IRElectroluxAc::setTemp(const uint8_t degrees) {
if(getTempModeFahrenheit()) {
uint8_t temp = std::max(kElectroluxAcMaxFTemp, degrees);
temp = std::min(kElectroluxAcMinFTemp, temp);
uint8_t temp = max(kElectroluxAcMinFTemp, degrees);
temp = min(kElectroluxAcMaxFTemp, temp);
_.Temp = (temp - kElectroluxAcMinFTemp);
}
else {
uint8_t temp = std::max(kElectroluxAcMaxTemp, degrees);
temp = std::min(kElectroluxAcMinTemp, temp);
_.Temp = ((temp - kElectroluxAcMinTemp) * 1.8); //TODO: fix accuracy
uint8_t temp = max(kElectroluxAcMinTemp, degrees);
temp = min(kElectroluxAcMaxTemp, temp);
temp = map(temp, kElectroluxAcMinTemp, kElectroluxAcMaxTemp, kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp);
_.Temp = temp - kElectroluxAcMinFTemp;
}
}

Expand All @@ -160,7 +161,8 @@ uint8_t IRElectroluxAc::getTemp(void) const {
return _.Temp + kElectroluxAcMinFTemp;
}
else {
return (_.Temp / 1.8) + kElectroluxAcMinTemp; //TODO: fix accuracy
uint8_t temp = map(_.Temp + kElectroluxAcMinFTemp, kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp, kElectroluxAcMinTemp, kElectroluxAcMaxTemp);
return temp;
}
}

Expand Down Expand Up @@ -239,10 +241,10 @@ void IRElectroluxAc::setRaw(const uint64_t state) { _.raw = state; }
/// @param[in] state The value to calc the checksum of.
/// @return The 4-bit checksum stored in a uint_8.
uint8_t IRElectroluxAc::calcChecksum(const uint64_t state) {
uint32_t data = GETBITS32(state, 0, kElectroluxAcBits - 4);
uint32_t data = GETBITS64(state, kElectroluxAcChecksumSize + kElectroluxAcChecksumOffset, kElectroluxAcBits - 4);
uint8_t result = 0;
for (; data; data >>= 4) // Add each nibble together.
result += GETBITS32(data, 0, 4);
result += GETBITS8(data, 0, 4);
return (result ^ 0xF) & 0xF;
}

Expand Down Expand Up @@ -325,7 +327,7 @@ stdAc::state_t IRElectroluxAc::toCommon(const stdAc::state_t *prev) const {
result.power = false;
}
result.protocol = decode_type_t::ELETROLUX_AC;
result.power = _.PowerToggle;
result.power = _.Power;
result.mode = toCommonMode(_.Mode);
result.celsius = !getTempModeFahrenheit();
result.degrees = getTemp();
Expand All @@ -351,17 +353,17 @@ stdAc::state_t IRElectroluxAc::toCommon(const stdAc::state_t *prev) const {
String IRElectroluxAc::toString(void) const {
String result = "";
result.reserve(120); // Reserve some heap for the string to reduce fragging.
result += addBoolToString(_.PowerToggle, kPowerStr, false);
result += addBoolToString(_.Power, kPowerStr, false);
result += addModeToString(_.Mode, kElectroluxModeAuto, kElectroluxModeCool,
0xFF, kElectroluxModeDry, kElectroluxModeFan);
result += addTempToString(getTemp());
result += addTempToString(getTemp(), !getTempModeFahrenheit());
result += addFanToString(_.Fan, kElectroluxFanHigh, kElectroluxFanLow,
kElectroluxFanAuto, kElectroluxFanAuto,
kElectroluxFanMedium);

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

if(getPowerToggle()) {
if(getPower()) {
result += irutils::addLabeledString(irutils::minsToString(getOnOffTimer()), kOffTimerStr);
}
else {
Expand All @@ -373,4 +375,10 @@ String IRElectroluxAc::toString(void) const {
/// Calculate and set the checksum values for the internal state.
void IRElectroluxAc::checksum(void) {
_.Sum = calcChecksum(_.raw);
}
}

/// Set the requested power state of the A/C to on.
void IRElectroluxAc::on(void) { setPower(true); }

/// Set the requested power state of the A/C to off.
void IRElectroluxAc::off(void) { setPower(false); }
36 changes: 20 additions & 16 deletions src/ir_Electrolux.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
#endif
#include "IRremoteESP8266.h"
#include "IRsend.h"
#include "map"
#ifdef UNIT_TEST
#include "IRsend_test.h"
#endif

union ElectroluxAcProtocol{
uint64_t raw; // The state of the IR remote in native IR code form.
struct {
uint8_t PowerToggle :1;
uint8_t Fan :2;
uint8_t Temp :5;
uint8_t Mode :3;
uint8_t TimerEnable :1;
uint8_t Timer :4;
uint8_t Quiet :1;
uint8_t :1;
uint8_t TempModeFahrenheit :1;
uint8_t :5;
uint8_t :4;
uint8_t Sum :4;
struct {
uint8_t Sum :4;
uint8_t :4;
uint8_t :5;
uint8_t TempModeFahrenheit :1;
uint8_t :1;
uint8_t Quiet :1;
uint8_t Timer :4;
uint8_t TimerEnable :1;
uint8_t Mode :3;
uint8_t Temp :5;
uint8_t Fan :2;
uint8_t Power :1;
uint64_t :0;
};
};

Expand All @@ -45,7 +47,7 @@ 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 = 28;
const uint8_t kElectroluxAcChecksumOffset = 0;
const uint8_t kElectroluxAcChecksumSize = 4;

// Fan
Expand Down Expand Up @@ -75,8 +77,10 @@ class IRElectroluxAc {
int8_t calibrate(void) { return _irsend.calibrate(); }
#endif // SEND_ELECTROLUX_AC
void begin();
void setPowerToggle(const bool on);
bool getPowerToggle(void) const;
void on(void);
void off(void);
void setPower(const bool on);
bool getPower(void) const;
void setTemp(const uint8_t temp);
uint8_t getTemp(void) const;
void setFan(const uint8_t speed);
Expand Down
96 changes: 0 additions & 96 deletions tools/calculate_check_bytes.py

This file was deleted.

0 comments on commit 68aff0f

Please sign in to comment.