Skip to content

Commit

Permalink
Sanyo88: Support the clock setting.
Browse files Browse the repository at this point in the history
* Add `set/getClock()`.
* Add & update unit tests.

For #1503
  • Loading branch information
crankyoldgit committed Aug 10, 2021
1 parent dea547f commit fd827e1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,11 +1811,13 @@ void IRac::sanyo(IRSanyoAc *ac,
/// @param[in] turbo Run the device in turbo/powerful mode.
/// @param[in] filter Turn on the (ion/pollen/etc) filter mode.
/// @param[in] sleep Nr. of minutes for sleep mode. -1 is Off, >= 0 is on.
/// @param[in] clock The time in Nr. of mins since midnight. < 0 is ignore.
void IRac::sanyo88(IRSanyoAc88 *ac,
const bool on, const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv, const bool turbo,
const bool filter, const int16_t sleep) {
const bool filter, const int16_t sleep,
const int16_t clock) {
ac->begin();
ac->setPower(on);
ac->setMode(ac->convertMode(mode));
Expand All @@ -1831,7 +1833,7 @@ void IRac::sanyo88(IRSanyoAc88 *ac,
// No Clean setting available.
// No Beep setting available.
ac->setSleep(sleep >= 0); // Sleep is either on/off, so convert to boolean.
// No Clock setting available.
if (clock >= 0) ac->setClock(clock);
ac->send();
}
#endif // SEND_SANYO_AC88
Expand Down Expand Up @@ -2801,7 +2803,7 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) {
{
IRSanyoAc88 ac(_pin, _inverted, _modulation);
sanyo88(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv,
send.turbo, send.filter, send.sleep);
send.turbo, send.filter, send.sleep, send.clock);
break;
}
#endif // SEND_SANYO_AC88
Expand Down
3 changes: 2 additions & 1 deletion src/IRac.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ void electra(IRElectraAc *ac,
const bool on, const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv, const bool turbo,
const bool filter, const int16_t sleep = -1);
const bool filter,
const int16_t sleep = -1, const int16_t clock = -1);
#endif // SEND_SANYO_AC88
#if SEND_SHARP_AC
void sharp(IRSharpAc *ac, const sharp_ac_remote_model_t model,
Expand Down
25 changes: 20 additions & 5 deletions src/ir_Sanyo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ IRSanyoAc::IRSanyoAc(const uint16_t pin, const bool inverted,
const bool use_modulation)
: _irsend(pin, inverted, use_modulation) { stateReset(); }

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

Expand Down Expand Up @@ -874,6 +873,21 @@ uint8_t IRSanyoAc88::convertFan(const stdAc::fanspeed_t speed) {
}
}

/// Get the current clock time.
/// @return The time as the nr. of minutes past midnight.
uint16_t IRSanyoAc88::getClock(void) const {
return _.ClockHrs * 60 + _.ClockMins;
}

/// Set the current clock time.
/// @param[in] mins_since_midnight The time as nr. of minutes past midnight.
void IRSanyoAc88::setClock(const uint16_t mins_since_midnight) {
uint16_t mins = std::min(mins_since_midnight, (uint16_t)(23 * 60 + 59));
_.ClockMins = mins % 60;
_.ClockHrs = mins / 60;
_.ClockSecs = 0;
}

/// Convert a native fan speed into its stdAc equivalent.
/// @param[in] spd The native setting to be converted.
/// @return The stdAc equivalent of the native setting.
Expand Down Expand Up @@ -933,22 +947,22 @@ stdAc::state_t IRSanyoAc88::toCommon(void) const {
result.filter = _.Filter;
result.turbo = _.Turbo;
result.sleep = _.Sleep ? 0 : -1;
result.clock = getClock();
// Not supported.
result.swingh = stdAc::swingh_t::kOff;
result.econo = false;
result.light = false;
result.quiet = false;
result.beep = false;
result.clean = false;
result.clock = -1;
return result;
}

/// Convert the current internal state into a human readable string.
/// @return A human readable string.
String IRSanyoAc88::toString(void) const {
String result = "";
result.reserve(100);
result.reserve(115);
result += addBoolToString(getPower(), kPowerStr, false);
result += addModeToString(_.Mode, kSanyoAc88Auto, kSanyoAc88Cool,
kSanyoAc88Heat, kSanyoAc88Auto, kSanyoAc88Fan);
Expand All @@ -959,5 +973,6 @@ String IRSanyoAc88::toString(void) const {
result += addBoolToString(_.SwingV, kSwingVStr);
result += addBoolToString(_.Turbo, kTurboStr);
result += addBoolToString(_.Sleep, kSleepStr);
result += addLabeledString(minsToString(getClock()), kClockStr);
return result;
}
13 changes: 9 additions & 4 deletions src/ir_Sanyo.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@ union SanyoAc88Protocol{
uint8_t Filter :1;
uint8_t SwingV :1;
uint8_t :1;
// Byte 4-9 (Timer times?)
uint8_t :8;
uint8_t :8;
uint8_t :8;
// Byte 4
uint8_t ClockSecs :8; // Nr. of Seconds
// Byte 5
uint8_t ClockMins :8; // Nr. of Minutes
// Byte 6
uint8_t ClockHrs :8; // Nr. of Hours
// Byte 7-9 (Timer times?)
uint8_t :8;
uint8_t :8;
uint8_t :8;
Expand Down Expand Up @@ -252,6 +255,8 @@ class IRSanyoAc88 {
bool getFilter(void) const;
void setSwingV(const bool on);
bool getSwingV(void) const;
uint16_t getClock(void) const;
void setClock(const uint16_t mins_since_midnight);
void setRaw(const uint8_t newState[]);
uint8_t* getRaw(void);
static uint8_t convertMode(const stdAc::opmode_t mode);
Expand Down
5 changes: 3 additions & 2 deletions test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ TEST(TestIRac, Sanyo88) {
IRrecv capture(kGpioUnused);
const char expected[] =
"Power: On, Mode: 2 (Cool), Temp: 28C, Fan: 2 (Medium), Swing(V): On, "
"Turbo: On, Sleep: On";
"Turbo: On, Sleep: On, Clock: 11:40";

ac.begin();
irac.sanyo88(&ac,
Expand All @@ -1509,7 +1509,8 @@ TEST(TestIRac, Sanyo88) {
stdAc::swingv_t::kAuto, // Vertical Swing
true, // Turbo
true, // Filter
17); // Sleep
17, // Sleep
11 * 60 + 40); // Clock
ASSERT_EQ(expected, ac.toString());
ac._irsend.makeDecodeResult();
EXPECT_TRUE(capture.decode(&ac._irsend.capture));
Expand Down
20 changes: 18 additions & 2 deletions test/ir_Sanyo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ TEST(TestDecodeSanyoAc88, DecodeRealExamples) {
EXPECT_FALSE(irsend.capture.repeat);
EXPECT_EQ(
"Power: On, Mode: 2 (Cool), Temp: 24C, Fan: 0 (Auto), Swing(V): Off, "
"Turbo: Off, Sleep: Off",
"Turbo: Off, Sleep: Off, Clock: 18:42",
IRAcUtils::resultAcToString(&irsend.capture));
}

Expand All @@ -617,7 +617,7 @@ TEST(TestDecodeSanyoAc88, SyntheticSelfDecode) {
EXPECT_FALSE(irsend.capture.repeat);
EXPECT_EQ(
"Power: On, Mode: 2 (Cool), Temp: 24C, Fan: 0 (Auto), Swing(V): Off, "
"Turbo: Off, Sleep: Off",
"Turbo: Off, Sleep: Off, Clock: 18:42",
IRAcUtils::resultAcToString(&irsend.capture));
EXPECT_EQ(
"f38000d50"
Expand Down Expand Up @@ -804,3 +804,19 @@ TEST(TestSanyoAc88Class, OperatingMode) {
ac.setMode(255);
EXPECT_EQ(kSanyoAc88Auto, ac.getMode());
}

TEST(TestSanyoAc88Class, Clock) {
IRSanyoAc88 ac(kGpioUnused);
ac.begin();

EXPECT_EQ(0, ac.getClock());

ac.setClock(21 * 60 + 19);
EXPECT_EQ(21 * 60 + 19, ac.getClock());

ac.setClock(0);
EXPECT_EQ(0, ac.getClock());

ac.setClock(25 * 60 + 61);
EXPECT_EQ(23 * 60 + 59, ac.getClock());
}

0 comments on commit fd827e1

Please sign in to comment.