Skip to content

Commit

Permalink
Kelon: Use uint64 to store raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
depau committed Jun 5, 2021
1 parent 15f134a commit 30566a3
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3336,7 +3336,7 @@ namespace IRAcUtils {
#if DECODE_KELON
case decode_type_t::KELON: {
IRKelonAC ac(kGpioUnused);
ac.setRaw(result->state);
ac.setRaw(result->value);
return ac.toString();
}
#endif // DECODE_KELON
Expand Down Expand Up @@ -3828,7 +3828,7 @@ namespace IRAcUtils {
#if DECODE_KELON
case decode_type_t::KELON: {
IRKelonAC ac(kGpioUnused);
ac.setRaw(decode->state);
ac.setRaw(decode->value);
*result = ac.toCommon();
break;
}
Expand Down
5 changes: 2 additions & 3 deletions src/IRremoteESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@
DECODE_AMCOR || DECODE_DAIKIN152 || DECODE_MITSUBISHI136 || \
DECODE_MITSUBISHI112 || DECODE_HITACHI_AC424 || DECODE_HITACHI_AC3 || \
DECODE_HITACHI_AC344 || DECODE_CORONA_AC || DECODE_SANYO_AC || \
DECODE_VOLTAS || DECODE_MIRAGE || DECODE_HAIER_AC176 || DECODE_KELON)
DECODE_VOLTAS || DECODE_MIRAGE || DECODE_HAIER_AC176)
// Add any DECODE to the above if it uses result->state (see kStateSizeMax)
// you might also want to add the protocol to hasACState function
#define DECODE_AC true // We need some common infrastructure for decoding A/Cs.
Expand Down Expand Up @@ -1030,8 +1030,7 @@ const uint16_t kHitachiAc424Bits = kHitachiAc424StateLength * 8;
const uint16_t kInaxBits = 24;
const uint16_t kInaxMinRepeat = kSingleRepeat;
const uint16_t kJvcBits = 16;
const uint16_t kKelonStateLength = 6;
const uint16_t kKelonBits = kKelonStateLength * 8;
const uint16_t kKelonBits = 48;
const uint16_t kKelvinatorStateLength = 16;
const uint16_t kKelvinatorBits = kKelvinatorStateLength * 8;
const uint16_t kKelvinatorDefaultRepeat = kNoRepeat;
Expand Down
10 changes: 5 additions & 5 deletions src/IRsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,11 @@ bool IRsend::send(const decode_type_t type, const uint64_t data,
sendJVC(data, nbits, min_repeat);
break;
#endif
#if SEND_KELON
case KELON:
sendKelon(data, nbits, min_repeat);
break;
#endif // SEND_KELON
#if SEND_LASERTAG
case LASERTAG:
sendLasertag(data, nbits, min_repeat);
Expand Down Expand Up @@ -1180,11 +1185,6 @@ bool IRsend::send(const decode_type_t type, const uint8_t *state,
sendHitachiAc424(state, nbytes);
break;
#endif // SEND_HITACHI_AC424
#if SEND_KELON
case KELON:
sendKelon(state, nbytes);
break;
#endif // SEND_KELON
#if SEND_KELVINATOR
case KELVINATOR:
sendKelvinator(state, nbytes);
Expand Down
4 changes: 2 additions & 2 deletions src/IRsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ class IRsend {
const uint16_t repeat = kNoRepeat);
#endif // SEND_TRUMA
#if SEND_KELON
void sendKelon(const unsigned char data[], const uint16_t nbytes = kKelonStateLength,
const uint16_t repeat = kNoRepeat);
void sendKelon(const uint64_t data, const uint16_t nbits = kKelonBits,
const uint16_t repeat = kNoRepeat);
#endif // SEND_KELON

protected:
Expand Down
1 change: 0 additions & 1 deletion src/IRutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ bool hasACState(const decode_type_t protocol) {
case HITACHI_AC3:
case HITACHI_AC344:
case HITACHI_AC424:
case KELON:
case KELVINATOR:
case MIRAGE:
case MITSUBISHI136:
Expand Down
19 changes: 9 additions & 10 deletions src/ir_Kelon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ const uint16_t kKelonFreq = 38000;

/// Send a Kelon message.
/// Status: Beta / Should be working.
/// @param[in] data The message to be sent.
/// @param[in] nbytes The number of bytes of message to be sent.
/// @param[in] data The data to be transmitted.
/// @param[in] nbits Nr. of bits of data to be sent.
/// @param[in] repeat The number of times the command is to be repeated.
void IRsend::sendKelon(const unsigned char data[], const uint16_t nbytes,
const uint16_t repeat) {
void IRsend::sendKelon(const uint64_t data, const uint16_t nbits, const uint16_t repeat) {
sendGeneric(kKelonHdrMark, kKelonHdrSpace,
kKelonBitMark, kKelonOneSpace,
kKelonBitMark, kKelonZeroSpace,
kKelonBitMark, kKelonGap,
data, nbytes, kKelonFreq, false, // LSB First.
data, nbits, kKelonFreq, false, // LSB First.
repeat, 50);
}

Expand Down Expand Up @@ -100,7 +99,7 @@ IRKelonAC::IRKelonAC(const uint16_t pin, const bool inverted, const bool use_mod

/// Reset the internals of the object to a known good state.
void IRKelonAC::stateReset() {
for (unsigned char &i : _.raw) i = 0x0;
_.raw = 0L;
_.preamble[0] = 0b10000011;
_.preamble[1] = 0b00000110;
}
Expand All @@ -110,7 +109,7 @@ void IRKelonAC::stateReset() {
/// Send the current internal state as an IR message.
/// @param[in] repeat Nr. of times the message will be repeated.
void IRKelonAC::send(const uint16_t repeat) {
_irsend.sendKelon(getRaw(), kKelonStateLength, repeat);
_irsend.sendKelon(getRaw(), kKelonBits, repeat);

// Reset toggle flags
_.PowerToggle = false;
Expand Down Expand Up @@ -319,14 +318,14 @@ bool IRKelonAC::getTimerEnabled() const {
/// Get the raw state of the object, suitable to be sent with the appropriate
/// IRsend object method.
/// @return A PTR to the internal state.
uint8_t *IRKelonAC::getRaw() {
uint64_t IRKelonAC::getRaw() const {
return _.raw;
}

/// Set the raw state of the object.
/// @param[in] new_code The raw state from the native IR message.
void IRKelonAC::setRaw(const uint8_t *new_code) {
std::memcpy(_.raw, new_code, kKelonStateLength);
void IRKelonAC::setRaw(const uint64_t new_code) {
_.raw = new_code;
}

/// Convert a standard A/C mode (stdAc::opmode_t) into it a native mode.
Expand Down
6 changes: 3 additions & 3 deletions src/ir_Kelon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "IRutils.h"

union KelonProtocol {
uint8_t raw[kKelonStateLength];
uint64_t raw;

struct {
uint8_t preamble[2];
Expand Down Expand Up @@ -124,9 +124,9 @@ class IRKelonAC {

bool getTimerEnabled() const;

uint8_t *getRaw();
uint64_t getRaw() const;

void setRaw(const uint8_t new_code[]);
void setRaw(const uint64_t new_code);

static uint8_t convertMode(stdAc::opmode_t mode);

Expand Down

0 comments on commit 30566a3

Please sign in to comment.