-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDS2890.cpp
116 lines (87 loc) · 2.35 KB
/
DS2890.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "OneWireHub.h"
#include "DS2890.h"
//#define DEBUG_DS2890
DS2890::DS2890(byte ID1, byte ID2, byte ID3, byte ID4, byte ID5, byte ID6, byte ID7): OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7){
this->regs = 0;
this->potion = 0;
}
bool DS2890::duty(OneWireHub * hub)
{
uint16_t data;
uint8_t done = hub->recv();
switch (done) {
// WRITE POSITION
case 0x0F:
// get
this->potion = hub->recv();
// send
hub->send( this->potion );
#ifdef DEBUG_DS2890
Serial.print("DS2890 : WRITE POSITION: ");
Serial.println(this->potion, HEX);
#endif
break;
// WRITE CONTROL REGISTER
case 0x55:
// data
this->regs = hub->recv();
// send dara
hub->send(this->regs);
#ifdef DEBUG_DS2890
Serial.print("DS2890 : WRITE CONTROL REGISTER: ");
Serial.println(this->regs, HEX);
#endif
break;
// READ CONTROL REGISTER
case 0xAA:
// regs
hub->send( this->regs );
// send
hub->send( this->potion );
#ifdef DEBUG_DS2890
Serial.print("DS2890 : READ CONTROL REGISTER: ");
Serial.print(this->regs, HEX);
Serial.print("-");
Serial.println(this->potion, HEX);
#endif
break;
// READ POSITION
case 0xF0:
// regs
hub->send( this->regs );
// send
hub->send( this->potion );
#ifdef DEBUG_DS2890
Serial.print("DS2890 : READ POSITION: ");
Serial.print(this->regs, HEX);
Serial.print("-");
Serial.println(this->potion, HEX);
#endif
break;
// INCREMENT
case 0xC3:
if (this->potion < 0xFF) this->potion = this->potion + 1;
// send
hub->send( this->potion );
#ifdef DEBUG_DS2890
Serial.print("DS2890 : INCREMENT");
#endif
break;
// DECREMENT
case 0x99:
if (this->potion > 0x00) this->potion = this->potion - 1;
// send
hub->send( this->potion );
#ifdef DEBUG_DS2890
Serial.print("DS2890 : DECREMENT");
#endif
break;
default:
#ifdef DEBUG_hint
Serial.print("DS2890=");
Serial.println(done, HEX);
#endif
break;
}
return TRUE;
}