-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DelonghiAc: Add basic send/decode support.
* sendDelonghiAc() & decodeDelonhiAc() * Unit tests for the above. * Tests include real-world data For #1096
- Loading branch information
1 parent
4b88574
commit 5ff9e50
Showing
13 changed files
with
289 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2020 David Conran | ||
|
||
#include "ir_Delonghi.h" | ||
#include "IRrecv.h" | ||
#include "IRsend.h" | ||
|
||
// Delonghi based protocol. | ||
|
||
|
||
const uint16_t kDelonghiAcHdrMark = 8984; | ||
const uint16_t kDelonghiAcBitMark = 572; | ||
const uint16_t kDelonghiAcHdrSpace = 4200; | ||
const uint16_t kDelonghiAcOneSpace = 1558; | ||
const uint16_t kDelonghiAcZeroSpace = 510; | ||
const uint32_t kDelonghiAcGap = kDefaultMessageGap; // A totally made-up guess. | ||
const uint16_t kDelonghiAcFreq = 38000; // Hz. (Guess: most common frequency.) | ||
const uint16_t kDelonghiAcOverhead = 3; | ||
|
||
|
||
#if SEND_DELONGHI_AC | ||
// Send an Delonghi AC formatted message. | ||
// | ||
// Args: | ||
// data: The message to be sent. | ||
// nbits: The number of bits of the message to be sent. | ||
// Typically kDelonghiAcBits. | ||
// repeat: The number of times the command is to be repeated. | ||
// | ||
// Status: Alpha / Yet to be tested on a real device. | ||
// | ||
// Ref: | ||
// https://github.com/crankyoldgit/IRremoteESP8266/issues/1096 | ||
void IRsend::sendDelonghiAc(const uint64_t data, const uint16_t nbits, | ||
const uint16_t repeat) { | ||
sendGeneric(kDelonghiAcHdrMark, kDelonghiAcHdrSpace, | ||
kDelonghiAcBitMark, kDelonghiAcOneSpace, | ||
kDelonghiAcBitMark, kDelonghiAcZeroSpace, | ||
kDelonghiAcBitMark, kDelonghiAcGap, | ||
data, nbits, kDelonghiAcFreq, false, // LSB First. | ||
repeat, kDutyDefault); | ||
} | ||
#endif // SEND_DELONGHI_AC | ||
|
||
#if DECODE_DELONGHI_AC | ||
// Decode the supplied DELONGHI_AC message. | ||
// | ||
// Args: | ||
// results: Ptr to the data to decode and where to store the decode result. | ||
// offset: The starting index to use when attempting to decode the raw data. | ||
// Typically/Defaults to kStartOffset. | ||
// nbits: The number of data bits to expect. Typically kDelonghiAcBits. | ||
// strict: Flag indicating if we should perform strict matching. | ||
// Returns: | ||
// boolean: True if it can decode it, false if it can't. | ||
// | ||
// Status: BETA / Appears to be working. | ||
// | ||
// Ref: | ||
// https://github.com/crankyoldgit/IRremoteESP8266/issues/1096 | ||
bool IRrecv::decodeDelonghiAc(decode_results *results, uint16_t offset, | ||
const uint16_t nbits, const bool strict) { | ||
if (results->rawlen < 2 * nbits + kDelonghiAcOverhead - offset) | ||
return false; // Too short a message to match. | ||
if (strict && nbits != kDelonghiAcBits) | ||
return false; | ||
|
||
uint64_t data = 0; | ||
|
||
// Header + Data + Footer | ||
if (!matchGeneric(results->rawbuf + offset, &data, | ||
results->rawlen - offset, nbits, | ||
kDelonghiAcHdrMark, kDelonghiAcHdrSpace, | ||
kDelonghiAcBitMark, kDelonghiAcOneSpace, | ||
kDelonghiAcBitMark, kDelonghiAcZeroSpace, | ||
kDelonghiAcBitMark, kDelonghiAcGap, true, | ||
_tolerance, kMarkExcess, false)) return false; | ||
|
||
// Compliance | ||
// TODO(crankyoldgit): Enable this when written. | ||
// if (strict && !IRDelonghiAc::validChecksum(data)) return false; | ||
|
||
// Success | ||
results->decode_type = decode_type_t::DELONGHI_AC; | ||
results->bits = nbits; | ||
results->value = data; | ||
results->command = 0; | ||
results->address = 0; | ||
return true; | ||
} | ||
#endif // DECODE_DELONGHI_AC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Delonghi A/C | ||
// | ||
// Copyright 2020 David Conran | ||
|
||
#ifndef IR_DELONGHI_H_ | ||
#define IR_DELONGHI_H_ | ||
|
||
#define __STDC_LIMIT_MACROS | ||
#include <stdint.h> | ||
#ifndef UNIT_TEST | ||
#include <Arduino.h> | ||
#endif | ||
#include "IRremoteESP8266.h" | ||
#include "IRsend.h" | ||
#ifdef UNIT_TEST | ||
#include "IRsend_test.h" | ||
#endif | ||
|
||
// Supports: | ||
// Brand: Delonghi, Model: PAC A95 | ||
|
||
// Ref: | ||
// https://github.com/crankyoldgit/IRremoteESP8266/issues/1096 | ||
|
||
// Kudos: | ||
// TheMaxxz: For the breakdown and mapping of the bit values. | ||
|
||
// Constants | ||
|
||
// Classes | ||
class IRDelonghiAc { | ||
public: | ||
explicit IRDelonghiAc(const uint16_t pin, const bool inverted = false, | ||
const bool use_modulation = true); | ||
|
||
void stateReset(); | ||
#if SEND_DELONGHI_AC | ||
void send(const uint16_t repeat = kDelonghiAcDefaultRepeat); | ||
int8_t calibrate(void) { return _irsend.calibrate(); } | ||
#endif // SEND_DELONGHI_AC | ||
void begin(); | ||
static uint8_t calcChecksum(const uint64_t state); | ||
static bool validChecksum(const uint64_t state); | ||
void setPower(const bool state); | ||
bool getPower(); | ||
void on(); | ||
void off(); | ||
void setTemp(const uint8_t temp); | ||
uint8_t getTemp(); | ||
void setFan(const uint8_t speed); | ||
uint8_t getFan(); | ||
void setMode(const uint8_t mode); | ||
uint8_t getMode(); | ||
uint64_t getRaw(); | ||
void setRaw(const uint64_t state); | ||
uint8_t convertMode(const stdAc::opmode_t mode); | ||
uint8_t convertFan(const stdAc::fanspeed_t speed); | ||
static stdAc::opmode_t toCommonMode(const uint8_t mode); | ||
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed); | ||
stdAc::state_t toCommon(void); | ||
String toString(); | ||
#ifndef UNIT_TEST | ||
|
||
private: | ||
IRsend _irsend; | ||
#else | ||
IRsendTest _irsend; | ||
#endif | ||
uint64_t remote_state; // The state of the IR remote. | ||
void checksum(void); | ||
}; | ||
#endif // IR_DELONGHI_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.