forked from christianlykke9/Beomote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Beomote.h
53 lines (39 loc) · 1007 Bytes
/
Beomote.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef _BEOMOTE_H
#define _BEOMOTE_H
#include "Commands.h"
#include <Arduino.h>
#include <avr/io.h>
#include <avr/interrupt.h>
// Common divisors for 3125 = 1, 5, 25, 125, 625, 3125
#define TICK 625
// Defining the Bang & Olufsen commands
#define BEO_ZERO (3125 / TICK)
#define BEO_SAME (6250 / TICK)
#define BEO_ONE (9375 / TICK)
#define BEO_STOP (12500 / TICK)
#define BEO_START (15625 / TICK)
typedef struct {
boolean link;
beo_address address;
beo_command command;
} BeoCommand;
class Beomote {
public:
void initialize(int pin);
int receive(BeoCommand &cmd);
// This method is only to be called by the interrupt service routine
void timerISR();
private:
int irPin;
int lastState;
int lastBeoBit;
boolean irReceived;
boolean link;
unsigned char address;
unsigned char command;
int timer;
int index;
void reset();
};
extern Beomote Beo;
#endif