-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnkyoRI.cpp
68 lines (60 loc) · 1.46 KB
/
OnkyoRI.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//---------------------------------------------------------------------------
//
// Name: OnkyoRI.cpp
// Author: Vita Tucek
// Created: 19.1.2016
// License: MIT
// Description: Library for control Onkyo devices with RI port.
// Message is composed from header, 12 databits and footer.
//
// For timing delay() function is used. That means until send
// is completed program is blocked (max send() duration is 61ms).
//
//---------------------------------------------------------------------------
#include "Arduino.h"
#include "OnkyoRI.h"
/// send command message to device
///
/// \param command command to device
///
void OnkyoRI::send(int command)
{
writeHeader();
for(int i=0;i<12;i++)
{
bool level = command & 0x800;
command <<= 1;
writeBit(level);
}
writeFooter();
}
/// write message header
void OnkyoRI::writeHeader()
{
digitalWrite(_outputPin,HIGH);
delayMicroseconds(3000);
digitalWrite(_outputPin,LOW);
delayMicroseconds(1000);
}
/// write message bit
///
/// \param level requested bit level (0/1)
///
void OnkyoRI::writeBit(bool level)
{
digitalWrite(_outputPin,HIGH);
delayMicroseconds(1000);
digitalWrite(_outputPin,LOW);
if(level)
delayMicroseconds(2000);
else
delayMicroseconds(1000);
}
/// write message footer
void OnkyoRI::writeFooter()
{
digitalWrite(_outputPin,HIGH);
delayMicroseconds(1000);
digitalWrite(_outputPin,LOW);
delay(20);
}