Skip to content

Commit 8e8e8e6

Browse files
committed
fix: set temp accuracy
fix: checksum
1 parent eec3252 commit 8e8e8e6

File tree

4 files changed

+64
-128
lines changed

4 files changed

+64
-128
lines changed

src/IRac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2873,7 +2873,7 @@ void IRac::electrolux(IRElectroluxAc *ac,
28732873
const bool quiet) {
28742874
ac->begin();
28752875
ac->stateReset();
2876-
ac->setPowerToggle(on);
2876+
ac->setPower(on);
28772877
ac->setMode(ac->convertMode(mode));
28782878
ac->setTempModeFahrenheit(!celsius);
28792879
ac->setTemp(degrees);

src/ir_Electrolux.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Brand: Electrolux, Model: Electrolux EACM EZ/N3
77

88
#include "ir_Electrolux.h"
9+
#include <Arduino.h>
910
#include <algorithm>
1011
#include "IRac.h"
1112
#include "IRrecv.h"
@@ -124,11 +125,11 @@ void IRElectroluxAc::begin(void) { _irsend.begin(); }
124125

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

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

133134
/// Turn on/off the fahrenheit temp mode.
134135
/// @param[in] on The desired setting state.
@@ -142,14 +143,15 @@ bool IRElectroluxAc::getTempModeFahrenheit(void) const { return _.TempModeFahren
142143
/// @param[in] degrees The temperature in celsius or fahrenheit.
143144
void IRElectroluxAc::setTemp(const uint8_t degrees) {
144145
if(getTempModeFahrenheit()) {
145-
uint8_t temp = std::max(kElectroluxAcMaxFTemp, degrees);
146-
temp = std::min(kElectroluxAcMinFTemp, temp);
146+
uint8_t temp = max(kElectroluxAcMinFTemp, degrees);
147+
temp = min(kElectroluxAcMaxFTemp, temp);
147148
_.Temp = (temp - kElectroluxAcMinFTemp);
148149
}
149150
else {
150-
uint8_t temp = std::max(kElectroluxAcMaxTemp, degrees);
151-
temp = std::min(kElectroluxAcMinTemp, temp);
152-
_.Temp = ((temp - kElectroluxAcMinTemp) * 1.8); //TODO: fix accuracy
151+
uint8_t temp = max(kElectroluxAcMinTemp, degrees);
152+
temp = min(kElectroluxAcMaxTemp, temp);
153+
temp = map(temp, kElectroluxAcMinTemp, kElectroluxAcMaxTemp, kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp);
154+
_.Temp = temp - kElectroluxAcMinFTemp;
153155
}
154156
}
155157

@@ -160,7 +162,8 @@ uint8_t IRElectroluxAc::getTemp(void) const {
160162
return _.Temp + kElectroluxAcMinFTemp;
161163
}
162164
else {
163-
return (_.Temp / 1.8) + kElectroluxAcMinTemp; //TODO: fix accuracy
165+
uint8_t temp = map(_.Temp + kElectroluxAcMinFTemp, kElectroluxAcMinFTemp, kElectroluxAcMaxFTemp, kElectroluxAcMinTemp, kElectroluxAcMaxTemp);
166+
return temp;
164167
}
165168
}
166169

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

@@ -325,7 +328,7 @@ stdAc::state_t IRElectroluxAc::toCommon(const stdAc::state_t *prev) const {
325328
result.power = false;
326329
}
327330
result.protocol = decode_type_t::ELETROLUX_AC;
328-
result.power = _.PowerToggle;
331+
result.power = _.Power;
329332
result.mode = toCommonMode(_.Mode);
330333
result.celsius = !getTempModeFahrenheit();
331334
result.degrees = getTemp();
@@ -351,17 +354,17 @@ stdAc::state_t IRElectroluxAc::toCommon(const stdAc::state_t *prev) const {
351354
String IRElectroluxAc::toString(void) const {
352355
String result = "";
353356
result.reserve(120); // Reserve some heap for the string to reduce fragging.
354-
result += addBoolToString(_.PowerToggle, kPowerStr, false);
357+
result += addBoolToString(_.Power, kPowerStr, false);
355358
result += addModeToString(_.Mode, kElectroluxModeAuto, kElectroluxModeCool,
356359
0xFF, kElectroluxModeDry, kElectroluxModeFan);
357-
result += addTempToString(getTemp());
360+
result += addTempToString(getTemp(), !getTempModeFahrenheit());
358361
result += addFanToString(_.Fan, kElectroluxFanHigh, kElectroluxFanLow,
359362
kElectroluxFanAuto, kElectroluxFanAuto,
360363
kElectroluxFanMedium);
361364

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

364-
if(getPowerToggle()) {
367+
if(getPower()) {
365368
result += irutils::addLabeledString(irutils::minsToString(getOnOffTimer()), kOffTimerStr);
366369
}
367370
else {
@@ -373,4 +376,10 @@ String IRElectroluxAc::toString(void) const {
373376
/// Calculate and set the checksum values for the internal state.
374377
void IRElectroluxAc::checksum(void) {
375378
_.Sum = calcChecksum(_.raw);
376-
}
379+
}
380+
381+
/// Set the requested power state of the A/C to on.
382+
void IRElectroluxAc::on(void) { setPower(true); }
383+
384+
/// Set the requested power state of the A/C to off.
385+
void IRElectroluxAc::off(void) { setPower(false); }

src/ir_Electrolux.h

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,46 @@
1515
#endif
1616
#include "IRremoteESP8266.h"
1717
#include "IRsend.h"
18+
#include "map"
1819
#ifdef UNIT_TEST
1920
#include "IRsend_test.h"
2021
#endif
2122

2223
union ElectroluxAcProtocol{
2324
uint64_t raw; // The state of the IR remote in native IR code form.
24-
struct {
25-
uint8_t PowerToggle :1;
26-
uint8_t Fan :2;
27-
uint8_t Temp :5;
28-
uint8_t Mode :3;
29-
uint8_t TimerEnable :1;
30-
uint8_t Timer :4;
31-
uint8_t Quiet :1;
32-
uint8_t :1;
33-
uint8_t TempModeFahrenheit :1;
34-
uint8_t :5;
35-
uint8_t :4;
36-
uint8_t Sum :4;
25+
// struct {
26+
// //Byte 0
27+
// uint8_t Power :1;
28+
// uint8_t Fan :2;
29+
// uint8_t Temp :5;
30+
// //Byte 1
31+
// uint8_t Mode :3;
32+
// uint8_t TimerEnable :1;
33+
// uint8_t Timer :4;
34+
// //Byte 2
35+
// uint8_t Quiet :1;
36+
// uint8_t :1;
37+
// uint8_t TempModeFahrenheit :1;
38+
// uint8_t :5;
39+
// //Byte 3
40+
// uint8_t :4;
41+
// uint8_t Sum :4;
42+
// uint64_t :0;
43+
// };
44+
struct {
45+
uint8_t Sum :4;
46+
uint8_t :4;
47+
uint8_t :5;
48+
uint8_t TempModeFahrenheit :1;
49+
uint8_t :1;
50+
uint8_t Quiet :1;
51+
uint8_t Timer :4;
52+
uint8_t TimerEnable :1;
53+
uint8_t Mode :3;
54+
uint8_t Temp :5;
55+
uint8_t Fan :2;
56+
uint8_t Power :1;
57+
uint64_t :0;
3758
};
3859
};
3960

@@ -45,7 +66,7 @@ const uint8_t kElectroluxAcMaxFTemp = 90; // 90F
4566
const uint8_t kElectroluxTimerMax = 12; // 12H
4667
const uint8_t kElectroluxTimerMin = 1; // 1H
4768
const uint64_t kElectroluxAcKnownGoodState = 0xF3008005;
48-
const uint8_t kElectroluxAcChecksumOffset = 28;
69+
const uint8_t kElectroluxAcChecksumOffset = 0;
4970
const uint8_t kElectroluxAcChecksumSize = 4;
5071

5172
// Fan
@@ -75,8 +96,10 @@ class IRElectroluxAc {
7596
int8_t calibrate(void) { return _irsend.calibrate(); }
7697
#endif // SEND_ELECTROLUX_AC
7798
void begin();
78-
void setPowerToggle(const bool on);
79-
bool getPowerToggle(void) const;
99+
void on(void);
100+
void off(void);
101+
void setPower(const bool on);
102+
bool getPower(void) const;
80103
void setTemp(const uint8_t temp);
81104
uint8_t getTemp(void) const;
82105
void setFan(const uint8_t speed);

tools/calculate_check_bytes.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)