Skip to content

Commit fd827e1

Browse files
committed
Sanyo88: Support the clock setting.
* Add `set/getClock()`. * Add & update unit tests. For #1503
1 parent dea547f commit fd827e1

File tree

6 files changed

+57
-17
lines changed

6 files changed

+57
-17
lines changed

src/IRac.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,11 +1811,13 @@ void IRac::sanyo(IRSanyoAc *ac,
18111811
/// @param[in] turbo Run the device in turbo/powerful mode.
18121812
/// @param[in] filter Turn on the (ion/pollen/etc) filter mode.
18131813
/// @param[in] sleep Nr. of minutes for sleep mode. -1 is Off, >= 0 is on.
1814+
/// @param[in] clock The time in Nr. of mins since midnight. < 0 is ignore.
18141815
void IRac::sanyo88(IRSanyoAc88 *ac,
18151816
const bool on, const stdAc::opmode_t mode,
18161817
const float degrees, const stdAc::fanspeed_t fan,
18171818
const stdAc::swingv_t swingv, const bool turbo,
1818-
const bool filter, const int16_t sleep) {
1819+
const bool filter, const int16_t sleep,
1820+
const int16_t clock) {
18191821
ac->begin();
18201822
ac->setPower(on);
18211823
ac->setMode(ac->convertMode(mode));
@@ -1831,7 +1833,7 @@ void IRac::sanyo88(IRSanyoAc88 *ac,
18311833
// No Clean setting available.
18321834
// No Beep setting available.
18331835
ac->setSleep(sleep >= 0); // Sleep is either on/off, so convert to boolean.
1834-
// No Clock setting available.
1836+
if (clock >= 0) ac->setClock(clock);
18351837
ac->send();
18361838
}
18371839
#endif // SEND_SANYO_AC88
@@ -2801,7 +2803,7 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) {
28012803
{
28022804
IRSanyoAc88 ac(_pin, _inverted, _modulation);
28032805
sanyo88(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv,
2804-
send.turbo, send.filter, send.sleep);
2806+
send.turbo, send.filter, send.sleep, send.clock);
28052807
break;
28062808
}
28072809
#endif // SEND_SANYO_AC88

src/IRac.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ void electra(IRElectraAc *ac,
398398
const bool on, const stdAc::opmode_t mode,
399399
const float degrees, const stdAc::fanspeed_t fan,
400400
const stdAc::swingv_t swingv, const bool turbo,
401-
const bool filter, const int16_t sleep = -1);
401+
const bool filter,
402+
const int16_t sleep = -1, const int16_t clock = -1);
402403
#endif // SEND_SANYO_AC88
403404
#if SEND_SHARP_AC
404405
void sharp(IRSharpAc *ac, const sharp_ac_remote_model_t model,

src/ir_Sanyo.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ IRSanyoAc::IRSanyoAc(const uint16_t pin, const bool inverted,
315315
const bool use_modulation)
316316
: _irsend(pin, inverted, use_modulation) { stateReset(); }
317317

318-
/// Reset the state of the remote to a known good state/sequence.
319-
/// @see https://docs.google.com/spreadsheets/d/1dYfLsnYvpjV-SgO8pdinpfuBIpSzm8Q1R5SabrLeskw/edit?ts=5f0190a5#gid=1050142776&range=A2:B2
318+
/// Reset the state of the remote to a known state/sequence.
320319
void IRSanyoAc::stateReset(void) {
321320
static const uint8_t kReset[kSanyoAcStateLength] = {
322321
0x6A, 0x6D, 0x51, 0x00, 0x10, 0x45, 0x00, 0x00, 0x33};
@@ -748,7 +747,7 @@ IRSanyoAc88::IRSanyoAc88(const uint16_t pin, const bool inverted,
748747
/// @see https://docs.google.com/spreadsheets/d/1dYfLsnYvpjV-SgO8pdinpfuBIpSzm8Q1R5SabrLeskw/edit?ts=5f0190a5#gid=1050142776&range=A2:B2
749748
void IRSanyoAc88::stateReset(void) {
750749
static const uint8_t kReset[kSanyoAc88StateLength] = {
751-
0xAA, 0x55, 0xA0, 0x16, 0x0F, 0x21, 0x01, 0x01, 0x00, 0x00, 0x10};
750+
0xAA, 0x55, 0xA0, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10};
752751
std::memcpy(_.raw, kReset, kSanyoAc88StateLength);
753752
}
754753

@@ -874,6 +873,21 @@ uint8_t IRSanyoAc88::convertFan(const stdAc::fanspeed_t speed) {
874873
}
875874
}
876875

876+
/// Get the current clock time.
877+
/// @return The time as the nr. of minutes past midnight.
878+
uint16_t IRSanyoAc88::getClock(void) const {
879+
return _.ClockHrs * 60 + _.ClockMins;
880+
}
881+
882+
/// Set the current clock time.
883+
/// @param[in] mins_since_midnight The time as nr. of minutes past midnight.
884+
void IRSanyoAc88::setClock(const uint16_t mins_since_midnight) {
885+
uint16_t mins = std::min(mins_since_midnight, (uint16_t)(23 * 60 + 59));
886+
_.ClockMins = mins % 60;
887+
_.ClockHrs = mins / 60;
888+
_.ClockSecs = 0;
889+
}
890+
877891
/// Convert a native fan speed into its stdAc equivalent.
878892
/// @param[in] spd The native setting to be converted.
879893
/// @return The stdAc equivalent of the native setting.
@@ -933,22 +947,22 @@ stdAc::state_t IRSanyoAc88::toCommon(void) const {
933947
result.filter = _.Filter;
934948
result.turbo = _.Turbo;
935949
result.sleep = _.Sleep ? 0 : -1;
950+
result.clock = getClock();
936951
// Not supported.
937952
result.swingh = stdAc::swingh_t::kOff;
938953
result.econo = false;
939954
result.light = false;
940955
result.quiet = false;
941956
result.beep = false;
942957
result.clean = false;
943-
result.clock = -1;
944958
return result;
945959
}
946960

947961
/// Convert the current internal state into a human readable string.
948962
/// @return A human readable string.
949963
String IRSanyoAc88::toString(void) const {
950964
String result = "";
951-
result.reserve(100);
965+
result.reserve(115);
952966
result += addBoolToString(getPower(), kPowerStr, false);
953967
result += addModeToString(_.Mode, kSanyoAc88Auto, kSanyoAc88Cool,
954968
kSanyoAc88Heat, kSanyoAc88Auto, kSanyoAc88Fan);
@@ -959,5 +973,6 @@ String IRSanyoAc88::toString(void) const {
959973
result += addBoolToString(_.SwingV, kSwingVStr);
960974
result += addBoolToString(_.Turbo, kTurboStr);
961975
result += addBoolToString(_.Sleep, kSleepStr);
976+
result += addLabeledString(minsToString(getClock()), kClockStr);
962977
return result;
963978
}

src/ir_Sanyo.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,13 @@ union SanyoAc88Protocol{
201201
uint8_t Filter :1;
202202
uint8_t SwingV :1;
203203
uint8_t :1;
204-
// Byte 4-9 (Timer times?)
205-
uint8_t :8;
206-
uint8_t :8;
207-
uint8_t :8;
204+
// Byte 4
205+
uint8_t ClockSecs :8; // Nr. of Seconds
206+
// Byte 5
207+
uint8_t ClockMins :8; // Nr. of Minutes
208+
// Byte 6
209+
uint8_t ClockHrs :8; // Nr. of Hours
210+
// Byte 7-9 (Timer times?)
208211
uint8_t :8;
209212
uint8_t :8;
210213
uint8_t :8;
@@ -252,6 +255,8 @@ class IRSanyoAc88 {
252255
bool getFilter(void) const;
253256
void setSwingV(const bool on);
254257
bool getSwingV(void) const;
258+
uint16_t getClock(void) const;
259+
void setClock(const uint16_t mins_since_midnight);
255260
void setRaw(const uint8_t newState[]);
256261
uint8_t* getRaw(void);
257262
static uint8_t convertMode(const stdAc::opmode_t mode);

test/IRac_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ TEST(TestIRac, Sanyo88) {
14981498
IRrecv capture(kGpioUnused);
14991499
const char expected[] =
15001500
"Power: On, Mode: 2 (Cool), Temp: 28C, Fan: 2 (Medium), Swing(V): On, "
1501-
"Turbo: On, Sleep: On";
1501+
"Turbo: On, Sleep: On, Clock: 11:40";
15021502

15031503
ac.begin();
15041504
irac.sanyo88(&ac,
@@ -1509,7 +1509,8 @@ TEST(TestIRac, Sanyo88) {
15091509
stdAc::swingv_t::kAuto, // Vertical Swing
15101510
true, // Turbo
15111511
true, // Filter
1512-
17); // Sleep
1512+
17, // Sleep
1513+
11 * 60 + 40); // Clock
15131514
ASSERT_EQ(expected, ac.toString());
15141515
ac._irsend.makeDecodeResult();
15151516
EXPECT_TRUE(capture.decode(&ac._irsend.capture));

test/ir_Sanyo_test.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ TEST(TestDecodeSanyoAc88, DecodeRealExamples) {
596596
EXPECT_FALSE(irsend.capture.repeat);
597597
EXPECT_EQ(
598598
"Power: On, Mode: 2 (Cool), Temp: 24C, Fan: 0 (Auto), Swing(V): Off, "
599-
"Turbo: Off, Sleep: Off",
599+
"Turbo: Off, Sleep: Off, Clock: 18:42",
600600
IRAcUtils::resultAcToString(&irsend.capture));
601601
}
602602

@@ -617,7 +617,7 @@ TEST(TestDecodeSanyoAc88, SyntheticSelfDecode) {
617617
EXPECT_FALSE(irsend.capture.repeat);
618618
EXPECT_EQ(
619619
"Power: On, Mode: 2 (Cool), Temp: 24C, Fan: 0 (Auto), Swing(V): Off, "
620-
"Turbo: Off, Sleep: Off",
620+
"Turbo: Off, Sleep: Off, Clock: 18:42",
621621
IRAcUtils::resultAcToString(&irsend.capture));
622622
EXPECT_EQ(
623623
"f38000d50"
@@ -804,3 +804,19 @@ TEST(TestSanyoAc88Class, OperatingMode) {
804804
ac.setMode(255);
805805
EXPECT_EQ(kSanyoAc88Auto, ac.getMode());
806806
}
807+
808+
TEST(TestSanyoAc88Class, Clock) {
809+
IRSanyoAc88 ac(kGpioUnused);
810+
ac.begin();
811+
812+
EXPECT_EQ(0, ac.getClock());
813+
814+
ac.setClock(21 * 60 + 19);
815+
EXPECT_EQ(21 * 60 + 19, ac.getClock());
816+
817+
ac.setClock(0);
818+
EXPECT_EQ(0, ac.getClock());
819+
820+
ac.setClock(25 * 60 + 61);
821+
EXPECT_EQ(23 * 60 + 59, ac.getClock());
822+
}

0 commit comments

Comments
 (0)