-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDS2413.cpp
74 lines (56 loc) · 1.49 KB
/
DS2413.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
#include "OneWireHub.h"
#include "DS2413.h"
//#define DEBUG_DS2413
DS2413::DS2413(byte ID1, byte ID2, byte ID3, byte ID4, byte ID5, byte ID6, byte ID7): OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7){
this->AState = true; //false;
this->ALatch = false;
this->BState = false;
this->BLatch = false;
}
bool DS2413::duty(OneWireHub * hub)
{
uint8_t done = hub->recv();
uint8_t data = 0;
switch (done) {
// PIO ACCESS WRITE
case 0x5A:
data = ~hub->recv();
// Write inverse
hub->send(data);
//@@@ - ToDo event
this->ALatch = data&0x01;
this->BLatch = data&0x02;
#ifdef DEBUG_DS2413
Serial.print("DS2413 : PIO WRITE : 5A = ");
Serial.println(data, HEX);
#endif
this->ChangePIO();
break;
// PIO ACCESS READ
case 0xF5:
this->ReadState();
data = 0;
if (this->AState) data = data | 0x01;
if (!this->ALatch) data = data | 0x02;
if (this->BState) data = data | 0x04;
if (!this->BLatch) data = data | 0x08;
data = data | (~data << 4);
hub->send( data );
#ifdef DEBUG_DS2413
Serial.print("DS2413 : PIO ACCESS READ : F5 = ");
Serial.println(data, HEX);
#endif
break;
default:
#ifdef DEBUG_hint
Serial.print("DS2413=");
Serial.println(done, HEX);
#endif
break;
}
return TRUE;
}
void DS2413::ReadState(){
}
void DS2413::ChangePIO(){
}