-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to a more modern implementation
- Loading branch information
Showing
2 changed files
with
211 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,102 @@ | ||
/* | ||
* IRelectra | ||
* Version 0.8 | ||
* Copyrights 2014 Barak Weiss | ||
* Copyrights 2016 Barak Weiss | ||
* | ||
* Many thanks to Chris from AnalysIR | ||
*/ | ||
|
||
#ifndef IRelectra_h | ||
#define IRelectra_h | ||
|
||
#include <stdint.h> | ||
|
||
#include "IRremote.h" | ||
|
||
#define POWER_OFF 0 | ||
#define POWER_ON 1 | ||
|
||
#define MODE_COOL 0b001 | ||
#define MODE_HEAT 0b010 | ||
#define MODE_AUTO 0b011 | ||
#define MODE_DRY 0b100 | ||
#define MODE_FAN 0b101 | ||
|
||
#define FAN_LOW 0b00 | ||
#define FAN_MED 0b01 | ||
#define FAN_HIGH 0b10 | ||
#define FAN_AUTO 0b11 | ||
#include <stdint.h> | ||
#include <vector> | ||
|
||
#define SWING_OFF 0b0 | ||
#define SWING_ON 0b1 | ||
typedef enum IRElectraMode { | ||
IRElectraModeCool = 0b001, | ||
IRElectraModeHeat = 0b010, | ||
IRElectraModeAuto = 0b011, | ||
IRElectraModeDry = 0b100, | ||
IRElectraModeFan = 0b101 | ||
} IRElectraMode; | ||
|
||
#define SLEEP_OFF 0b0 | ||
#define SLEEP_ON 0b1 | ||
typedef enum IRElectraFan { | ||
IRElectraFanLow = 0b00, | ||
IRElectraFanMedium = 0b01, | ||
IRElectraFanHigh = 0b10, | ||
IRElectraFanAuto = 0b11 | ||
} IRElectraFan; | ||
|
||
class IRelectra | ||
{ | ||
public: | ||
// Ctor, remote will be used to send the raw IR data | ||
// Initialize | ||
IRelectra(IRsend* remote); | ||
|
||
// Sends the specified configuration to the IR led using IRremote | ||
bool SendElectra(int power, int mode, int fan, int temperature, int swing, int sleep); | ||
// Send an IR packet with the given parameters. | ||
bool sendElectra(bool power, IRElectraMode mode, IRElectraFan fan, int temperature, bool swing, bool sleep); | ||
|
||
private: | ||
IRsend* _remote; | ||
uint64_t EncodeElectra(int power, int mode, int fan, int temperature, int swing, int sleep); | ||
void addBit(unsigned int* p, int* i, char b); | ||
|
||
// Encodes specific A/C configuration to a number that describes | ||
uint64_t encodeElectra(bool power, IRElectraMode mode, IRElectraFan fan, int temperature, bool swing, bool sleep); | ||
|
||
// Create the entire MARK-SPACE array containing the entire packet to send to the A/C | ||
std::vector<unsigned int> generateSignal(uint64_t code); | ||
}; | ||
|
||
// Class to create MARK-SPACE array. An IR code is a digital signal, which | ||
// means it's made out of 0's (space) and 1's (mark). This class helps | ||
// create these kinds of signals. It has the ability to add marks and spaces | ||
// at any time, and to add single bit using Manchester code to the signal. | ||
// Once you added enough data to the array use the data() methods to get | ||
// the raw data. Make sure that the first think you add to the array is | ||
// at least one mark. | ||
class MarkSpaceArray | ||
{ | ||
public: | ||
// Initialize the array with a specific unit length. This is the clock used | ||
// in the Manchester code. | ||
MarkSpaceArray(uint16_t unitLengthInUsec); | ||
|
||
// Add a number of time units with mark. | ||
void addMark(uint16_t units); | ||
|
||
// Add a number of time units with space. | ||
void addSpace(uint16_t units); | ||
|
||
// Encodes the bit with IEEE 802.3 Manchester coding and adds it to the array | ||
// A zero bit is one unit MARK and one unit SPACE | ||
// a one bit is one unit SPACE and one unit MARK | ||
void addBitWithManchesterCode(uint8_t bit); | ||
|
||
// Encodes a given number of bits from the given number bit by bit with | ||
// IEEE 802.3 Manchester coding and adds it to the array. MSB first. | ||
void addNumberWithManchesterCode(uint64_t bit, uint8_t numberOfBits); | ||
|
||
// Array containing timing for marks and spaces, starts with marks. | ||
const std::vector<unsigned int> data(); | ||
|
||
private: | ||
// Add more time units to the current state. For example, if the array | ||
// looks like this: { 1*UNIT, 1*UNIT } (equal to calling addMark(1) | ||
// followed by addSpace(1), the current state is SPACE (currentState()==0) | ||
// calling this function will change the array to { 1*UNIT, 2*UNIT }. | ||
void addUnitsToCurrentState(uint16_t units); | ||
|
||
// Add more time to the other state. For example, if the array | ||
// looks like this: { 1*UNIT, 1*UNIT } (equal to calling addMark(1) | ||
// followed by addSpace(1), the current state is SPACE (currentState()==0) | ||
// calling this function will change the array to { 1*UNIT, 1*UNIT, 1*UNIT } | ||
void addUnitsToNextState(uint16_t units); | ||
|
||
// Returns 1 for mark, 0 for space. | ||
uint8_t currentState(); | ||
|
||
uint16_t _unitLength; | ||
std::vector<unsigned int> _data; | ||
}; | ||
|
||
#endif |