-
Notifications
You must be signed in to change notification settings - Fork 1
/
CEC_Device.cpp
82 lines (71 loc) · 1.73 KB
/
CEC_Device.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "CEC_Device.h"
#include <Arduino.h>
CEC_Device::CEC_Device(int physicalAddress, int in_line, int out_line)
: CEC_LogicalDevice(physicalAddress)
, _isrTriggered(false)
, _lastLineState2(true)
, _in_line(in_line)
, _out_line(out_line)
{
}
void CEC_Device::Initialize(CEC_DEVICE_TYPE type)
{
pinMode(_out_line, OUTPUT);
pinMode( _in_line, INPUT);
digitalWrite(_out_line, LOW);
delay(200);
CEC_LogicalDevice::Initialize(type);
}
void CEC_Device::OnReady()
{
// This is called after the logical address has been
// allocated
DbgPrint("Device ready\n");
}
void CEC_Device::OnReceive(int source, int dest, unsigned char* buffer, int count)
{
// This is called when a frame is received. To transmit
// a frame call TransmitFrame. To receive all frames, even
// those not addressed to this device, set Promiscuous to true.
DbgPrint("Packet received at %ld: %02d -> %02d: %02X", millis(), source, dest, ((source&0x0f)<<4)|(dest&0x0f));
for (int i = 0; i < count; i++)
DbgPrint(":%02X", buffer[i]);
DbgPrint("\n");
}
bool CEC_Device::LineState()
{
int state = digitalRead(_in_line);
return state == LOW;
}
void CEC_Device::SetLineState(bool state)
{
digitalWrite(_out_line, state?LOW:HIGH);
// give enough time for the line to settle before sampling
// it
delayMicroseconds(50);
_lastLineState2 = LineState();
}
void CEC_Device::SignalIRQ()
{
// This is called when the line has changed state
_isrTriggered = true;
}
bool CEC_Device::IsISRTriggered()
{
if (_isrTriggered)
{
_isrTriggered = false;
return true;
}
return false;
}
void CEC_Device::Run()
{
bool state = LineState();
if (_lastLineState2 != state)
{
_lastLineState2 = state;
SignalIRQ();
}
CEC_LogicalDevice::Run();
}