Skip to content

Commit 8cc7b26

Browse files
committed
Testing it out.
1 parent de3d723 commit 8cc7b26

File tree

9 files changed

+611
-0
lines changed

9 files changed

+611
-0
lines changed

.idea/Arduino-IRremote.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 369 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IRelectra.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* IRelectra
3+
* Version 0.8
4+
* Copyrights 2014 Barak Weiss
5+
*
6+
* Many thanks to Chris from AnalysIR
7+
*/
8+
9+
#include "IRelectra.h"
10+
#include <stdint.h>
11+
12+
#define UNIT 1000
13+
#define NUM_BITS 34
14+
15+
IRelectra::IRelectra(IRsend* remote) : _remote(remote)
16+
{}
17+
18+
// Add bit b to array p at index i
19+
// This function is used to convert manchester encoding to MARKs and SPACEs
20+
// p is the pointer to the start of the MARK, SPACE array
21+
// i is the current index
22+
// b is the bit we want to add to the MARK, SPACE array
23+
// A zero bit is one unit MARK and one unit SPACE
24+
// a one bit is one unit SPACE and one unit MARK
25+
void IRelectra::addBit(unsigned int* p, int* i, char b)
26+
{
27+
if (((*i) & 1) == 1)
28+
{
29+
// current index is SPACE
30+
if ((b & 1) == 1)
31+
{
32+
// one is one unit low, then one unit up
33+
// since we're pointing at SPACE, we should increase it byte a unit
34+
// then add another MARK unit
35+
*(p+*i) += UNIT;
36+
(*i)++;
37+
*(p+*i) = UNIT;
38+
}
39+
if ((b & 1) == 0)
40+
{
41+
// we need a MARK unit, then SPACE unit
42+
(*i)++;
43+
*(p+*i) = UNIT;
44+
(*i)++;
45+
*(p+*i) = UNIT;
46+
}
47+
}
48+
else if (((*i) & 1) == 0)
49+
{
50+
// current index is MARK
51+
if ((b & 1) == 1)
52+
{
53+
(*i)++;
54+
*(p+*i) = UNIT;
55+
(*i)++;
56+
*(p+*i) = UNIT;
57+
}
58+
if ((b & 1) == 0)
59+
{
60+
*(p+*i) += UNIT;
61+
(*i)++;
62+
*(p+*i) = UNIT;
63+
}
64+
}
65+
66+
}
67+
68+
// Sends the specified configuration to the IR led using IRremote
69+
// 1. Get the numeric value of the configuration
70+
// 2. Convert to IRremote compatible array (MARKS and SPACES)
71+
// 3. Send to IRremote
72+
bool IRelectra::SendElectra(int power, int mode, int fan, int temperature, int swing, int sleep)
73+
{
74+
unsigned int data[200]; //~maximum size of the IR packet
75+
int i = 0;
76+
77+
// get the data representing the configuration
78+
uint64_t code = EncodeElectra(power, mode, fan, temperature, swing, sleep);
79+
80+
// The whole packet looks this:
81+
// 3 Times:
82+
// 3000 usec MARK
83+
// 3000 used SPACE
84+
// Maxchester encoding of the data, clock is ~1000usec
85+
// 4000 usec MARK
86+
for (int k = 0; k<3; k++)
87+
{
88+
data[i] = 3 * UNIT; //mark
89+
i++;
90+
data[i] = 3 * UNIT;
91+
for (int j = NUM_BITS - 1; j >= 0; j--)
92+
{
93+
addBit(data, &i, (code >> j) & 1);
94+
}
95+
i++;
96+
}
97+
data[i] = 4 * UNIT;
98+
99+
_remote->sendRaw(data, i + 1, 38);
100+
return true;
101+
}
102+
103+
// Encodes specific A/C configuration to a number that describes
104+
// That configuration has a total of 34 bits
105+
// 33: Power bit, if this bit is ON, the A/C will toggle it's power.
106+
// 32-30: Mode - Cool, heat etc.
107+
// 29-28: Fan - Low, medium etc.
108+
// 27-26: Zeros
109+
// 25: Swing On/Off
110+
// 24-23: Zeros
111+
// 22-19: Temperature, where 15 is 0000, 30 is 1111
112+
// 18: Sleep mode On/Off
113+
// 17- 2: Zeros
114+
// 1: One
115+
// 0: Zero
116+
uint64_t IRelectra::EncodeElectra(int power, int mode, int fan, int temperature, int swing, int sleep)
117+
{
118+
uint64_t num = 0;
119+
uint64_t power64 = power;
120+
uint64_t mode64 = mode;
121+
122+
num |= ((power64 & 1) << 33);
123+
124+
num |= ((mode64 & 7) << 30);
125+
126+
num |= ((fan & 3) << 28);
127+
128+
num |= ((swing & 1) << 25);
129+
130+
temperature -= 15;
131+
num |= ((temperature & 15) << 19);
132+
133+
num |= ((sleep & 1) << 18);
134+
135+
num |= 2;
136+
137+
return num;
138+
}

IRelectra.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* IRelectra
3+
* Version 0.8
4+
* Copyrights 2014 Barak Weiss
5+
*
6+
* Many thanks to Chris from AnalysIR
7+
*/
8+
9+
#ifndef IRelectra_h
10+
#define IRelectra_h
11+
12+
#include <stdint.h>
13+
14+
#include "IRremote.h"
15+
16+
#define POWER_OFF 0
17+
#define POWER_ON 1
18+
19+
#define MODE_COOL 0b001
20+
#define MODE_HEAT 0b010
21+
#define MODE_AUTO 0b011
22+
#define MODE_DRY 0b100
23+
#define MODE_FAN 0b101
24+
25+
#define FAN_LOW 0b00
26+
#define FAN_MED 0b01
27+
#define FAN_HIGH 0b10
28+
#define FAN_AUTO 0b11
29+
30+
#define SWING_OFF 0b0
31+
#define SWING_ON 0b1
32+
33+
#define SLEEP_OFF 0b0
34+
#define SLEEP_ON 0b1
35+
36+
class IRelectra
37+
{
38+
public:
39+
// Ctor, remote will be used to send the raw IR data
40+
IRelectra(IRsend* remote);
41+
42+
// Sends the specified configuration to the IR led using IRremote
43+
bool SendElectra(int power, int mode, int fan, int temperature, int swing, int sleep);
44+
45+
private:
46+
IRsend* _remote;
47+
uint64_t EncodeElectra(int power, int mode, int fan, int temperature, int swing, int sleep);
48+
void addBit(unsigned int* p, int* i, char b);
49+
};
50+
51+
#endif

irSend.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "IRremote.h"
22
#include "IRremoteInt.h"
3+
#include <wiringPi.h>
4+
35

46
//+=============================================================================
57
void IRsend::sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz)
@@ -52,11 +54,13 @@ void IRsend::space (unsigned int time)
5254
// A few hours staring at the ATmega documentation and this will all make sense.
5355
// See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details.
5456
//
57+
#define TIMER_PWM_PIN 17
5558
void IRsend::enableIROut (int khz)
5659
{
5760
// Disable the Timer2 Interrupt (which is used for receiving IR)
5861
TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt
5962

63+
wiringPiSetupSys();
6064
pinMode(TIMER_PWM_PIN, OUTPUT);
6165
digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
6266

test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "IRremote.h"
2+
#include "IRelectra.h"
3+
4+
int main()
5+
IRsend irsend(D3);
6+
IRelectra e(&irsend);
7+
e.SendElectra(POWER_OFF, MODE_COOL, FAN_LOW, 22, SWING_ON, SLEEP_OFF);
8+
9+
return 0;
10+
}

0 commit comments

Comments
 (0)