Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of Toshiba Remote Control B #2093

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/IRtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ IRTEXT_CONST_STRING(kTimerActiveDaysStr, D_STR_TIMER_ACTIVE_DAYS);
///< "TimerActiveDays"
IRTEXT_CONST_STRING(kKeyStr, D_STR_KEY); ///< "Key"
IRTEXT_CONST_STRING(kValueStr, D_STR_VALUE); ///< "Value"
///< "Remote Control Types"
IRTEXT_CONST_STRING(kRemoteControlType, D_STR_REMOTECONTROLTYPE); ///<
///< "Remote Control Type"
IRTEXT_CONST_STRING(kToshibaRemoteControlTypeA, D_STR_TOSHIBAREMOTETYPEA);
///< "A"
IRTEXT_CONST_STRING(kToshibaRemoteControlTypeB, D_STR_TOSHIBAREMOTETYPEB);
///< "B"

// Separators & Punctuation
const char kTimeSep = D_CHR_TIME_SEP; ///< ':'
Expand Down
3 changes: 3 additions & 0 deletions src/IRtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ extern IRTEXT_CONST_PTR(kUpStr);
extern IRTEXT_CONST_PTR(kUpperStr);
extern IRTEXT_CONST_PTR(kUpperMiddleStr);
extern IRTEXT_CONST_PTR(kValueStr);
extern IRTEXT_CONST_PTR(kRemoteControlType);
extern IRTEXT_CONST_PTR(kToshibaRemoteControlTypeA);
extern IRTEXT_CONST_PTR(kToshibaRemoteControlTypeB);
extern IRTEXT_CONST_PTR(kV9014557AStr);
extern IRTEXT_CONST_PTR(kV9014557BStr);
extern IRTEXT_CONST_PTR(kVaneStr);
Expand Down
31 changes: 29 additions & 2 deletions src/ir_Toshiba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ void IRToshibaAC::send(const uint16_t repeat) {
uint16_t IRToshibaAC::getInternalStateLength(const uint8_t state[],
const uint16_t size) {
if (size < kToshibaAcLengthByte) return 0;
return std::min((uint16_t)(state[kToshibaAcLengthByte] + kToshibaAcMinLength),
kToshibaACStateLengthLong);
// Fix: Extract the last 4 bits instead
return std::min((uint16_t)((state[kToshibaAcLengthByte] & 0xF)
+ kToshibaAcMinLength), kToshibaACStateLengthLong);
}

/// Get the length of the current internal state per the protocol structure.
Expand Down Expand Up @@ -490,9 +491,35 @@ String IRToshibaAC::toString(void) const {
result += addBoolToString(getEcono(), kEconoStr);
result += addBoolToString(getFilter(), kFilterStr);
}
switch (getRemoteControl()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is addModelString helpers

case kToshibaAcRemoteB:
result += addLabeledString(kToshibaRemoteControlTypeB,
kRemoteControlType);
break;
default:
result += addLabeledString(kToshibaRemoteControlTypeA,
kRemoteControlType);
break;
}
return result;
}

void IRToshibaAC::setRemoteControl(const uint8_t remote_type) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use model, as example see

void IRVoltas::setModel(const voltas_ac_remote_model_t model) {

switch (remote_type) {
case kToshibaAcRemoteA:
case kToshibaAcRemoteB:
_.Remote = remote_type;
break;
default:
_.Remote = kToshibaAcRemoteA;
break;
}
}

uint8_t IRToshibaAC::getRemoteControl() const {
return _.Remote;
}

#if DECODE_TOSHIBA_AC
/// Decode the supplied Toshiba A/C message.
/// Status: STABLE / Working.
Expand Down
11 changes: 10 additions & 1 deletion src/ir_Toshiba.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ union ToshibaProtocol{
///< 1 (56 bit message)
///< 3 (72 bit message)
///< 4 (80 bit message)
uint8_t Length :8;
uint8_t Length :4;
// Toshiba remote type
// 0 - Remote control A
// 1 - Remote control B
uint8_t Remote :4;
// Byte[3] - The bit-inverted value of the "length" byte.
uint8_t :8;
// Byte[4]
Expand Down Expand Up @@ -111,6 +115,9 @@ const uint8_t kToshibaAcFanMax = 5; // 0b101
const uint8_t kToshibaAcTurboOn = 1; // 0b01
const uint8_t kToshibaAcEconoOn = 3; // 0b11

const uint8_t kToshibaAcRemoteA = 0; // 0b0000
const uint8_t kToshibaAcRemoteB = 1; // 0b0001

// Legacy defines. (Deprecated)
#define TOSHIBA_AC_AUTO kToshibaAcAuto
#define TOSHIBA_AC_COOL kToshibaAcCool
Expand Down Expand Up @@ -140,6 +147,8 @@ class IRToshibaAC {
void begin(void);
void on(void);
void off(void);
void setRemoteControl(const uint8_t remote_type);
uint8_t getRemoteControl() const;
void setPower(const bool on);
bool getPower(void) const;
void setTemp(const uint8_t degrees);
Expand Down
9 changes: 9 additions & 0 deletions src/locale/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,15 @@ D_STR_INDIRECT " " D_STR_MODE
#ifndef D_STR_VALUE
#define D_STR_VALUE "Value"
#endif // D_STR_VALUE
#ifndef D_STR_REMOTECONTROLTYPE
#define D_STR_REMOTECONTROLTYPE "Remote Control Type"
#endif // D_STR_REMOTECONTROLTYPE
#ifndef D_STR_TOSHIBAREMOTETYPEA
#define D_STR_TOSHIBAREMOTETYPEA "A"
#endif // D_STR_TOSHIBAREMOTETYPEA
#ifndef D_STR_TOSHIBAREMOTETYPEB
#define D_STR_TOSHIBAREMOTETYPEB "B"
#endif // D_STR_TOSHIBAREMOTETYPEB

// Compound words/phrases/descriptions from pre-defined words.
// Note: Obviously these need to be defined *after* their component words.
Expand Down
24 changes: 12 additions & 12 deletions test/ir_Toshiba_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,21 @@ TEST(TestToshibaACClass, HumanReadableOutput) {

ac.setRaw(initial_state);
EXPECT_EQ("Temp: 17C, Power: On, Mode: 0 (Auto), Fan: 0 (Auto), "
"Turbo: Off, Econo: Off, Filter: Off",
"Turbo: Off, Econo: Off, Filter: Off, Remote Control Type: A",
ac.toString());
ac.setRaw(modified_state);
EXPECT_EQ("Temp: 17C, Power: On, Mode: 1 (Cool), Fan: 5 (High), "
"Turbo: Off, Econo: Off, Filter: Off",
"Turbo: Off, Econo: Off, Filter: Off, Remote Control Type: A",
ac.toString());
ac.setTemp(25);
ac.setFan(3);
ac.setMode(kToshibaAcDry);
EXPECT_EQ("Temp: 25C, Power: On, Mode: 2 (Dry), Fan: 3 (Medium), "
"Turbo: Off, Econo: Off, Filter: Off",
"Turbo: Off, Econo: Off, Filter: Off, Remote Control Type: A",
ac.toString());
ac.off();
EXPECT_EQ("Temp: 25C, Power: Off, Fan: 3 (Medium), Turbo: Off, Econo: Off, "
"Filter: Off",
"Filter: Off, Remote Control Type: A",
ac.toString());
}

Expand Down Expand Up @@ -380,7 +380,7 @@ TEST(TestDecodeToshibaAC, SyntheticExample) {
EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits);
EXPECT_EQ(
"Temp: 17C, Power: On, Mode: 0 (Auto), Fan: 0 (Auto), Turbo: Off, "
"Econo: Off, Filter: Off",
"Econo: Off, Filter: Off, Remote Control Type: A",
IRAcUtils::resultAcToString(&irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p));
Expand Down Expand Up @@ -628,7 +628,7 @@ TEST(TestDecodeToshibaAC, RealLongExample) {
EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits);
EXPECT_EQ(
"Temp: 22C, Power: On, Mode: 0 (Auto), Fan: 0 (Auto), Turbo: On, "
"Econo: Off, Filter: Off",
"Econo: Off, Filter: Off, Remote Control Type: A",
IRAcUtils::resultAcToString(&irsend.capture));
}

Expand Down Expand Up @@ -718,7 +718,7 @@ TEST(TestDecodeToshibaAC, RealShortExample) {
EXPECT_EQ(kToshibaACBitsShort, irsend.capture.bits);
EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits);
EXPECT_EQ(
"Temp: 17C, Swing(V): 0 (Step)",
"Temp: 17C, Swing(V): 0 (Step), Remote Control Type: A",
IRAcUtils::resultAcToString(&irsend.capture));
}

Expand All @@ -733,7 +733,7 @@ TEST(TestToshibaACClass, ConstructLongState) {
ac.setEcono(true);
EXPECT_EQ(
"Temp: 29C, Power: On, Mode: 2 (Dry), Fan: 2 (UNKNOWN), "
"Turbo: Off, Econo: On, Filter: Off",
"Turbo: Off, Econo: On, Filter: Off, Remote Control Type: A",
ac.toString());
EXPECT_EQ(kToshibaACStateLengthLong, ac.getStateLength());
const uint8_t expectedState[kToshibaACStateLengthLong] = {
Expand Down Expand Up @@ -784,7 +784,7 @@ TEST(TestDecodeToshibaAC, RealExample_WHUB03NJ) {
EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits);
EXPECT_EQ(
"Temp: 20C, Power: Off, Fan: 0 (Auto), Turbo: Off, Econo: Off, "
"Filter: Off",
"Filter: Off, Remote Control Type: A",
IRAcUtils::resultAcToString(&irsend.capture));
}

Expand All @@ -805,7 +805,7 @@ TEST(TestToshibaACClass, SwingCodes) {
ac.setSwing(kToshibaAcSwingOn);

EXPECT_EQ(
"Temp: 17C, Swing(V): 1 (On)",
"Temp: 17C, Swing(V): 1 (On), Remote Control Type: A",
ac.toString());
EXPECT_EQ(kToshibaACStateLengthShort, ac.getStateLength());
const uint8_t swingOnState[kToshibaACStateLengthShort] = {
Expand All @@ -815,7 +815,7 @@ TEST(TestToshibaACClass, SwingCodes) {

ac.setSwing(kToshibaAcSwingOff);
EXPECT_EQ(
"Temp: 17C, Swing(V): 2 (Off)",
"Temp: 17C, Swing(V): 2 (Off), Remote Control Type: A",
ac.toString());
EXPECT_EQ(kToshibaACStateLengthShort, ac.getStateLength());
const uint8_t swingOffState[kToshibaACStateLengthShort] = {
Expand All @@ -828,7 +828,7 @@ TEST(TestToshibaACClass, SwingCodes) {
ac.setRaw(swingToggleState, kToshibaACStateLengthShort);
EXPECT_EQ(kToshibaAcSwingToggle, ac.getSwing());
EXPECT_EQ(
"Temp: 17C, Swing(V): 4 (Toggle)",
"Temp: 17C, Swing(V): 4 (Toggle), Remote Control Type: A",
ac.toString());
}

Expand Down
Loading