-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDS2433.cpp
93 lines (73 loc) · 2.03 KB
/
DS2433.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
#include "OneWireHub.h"
#include "DS2433.h"
#define DEBUG_DS2433
DS2433::DS2433(byte ID1, byte ID2, byte ID3, byte ID4, byte ID5, byte ID6, byte ID7): OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7){
for (int i=0;i<sizeof(this->memory);i++)
this->memory[i] = 0xFF;
}
bool DS2433::duty(OneWireHub * hub)
{
uint16_t memory_address;
uint8_t mem_offset;
uint8_t b;
uint16_t crc;
uint8_t done = hub->recv();
switch (done) {
// WRITE SCRATCHPAD COMMAND
case 0x0F:
// Adr1
b = hub->recv();
((uint8_t*)&memory_address)[0] = b;
// Adr2
b = hub->recv();
((uint8_t*)&memory_address)[1] = b;
for (int i=0;i<32;i++){
hub->send(this->memory[memory_address+i]);
if (hub->errno) break;
}
#ifdef DEBUG_DS2433
Serial.print("DS2433 : WRITE SCRATCHPAD COMMAND : ");
Serial.println(memory_address, HEX);
#endif
break;
// READ SCRATCHPAD COMMAND
case 0xAA:
// Adr1
b = hub->recv();
((uint8_t*)&memory_address)[0] = b;
// Adr2
b = hub->recv();
((uint8_t*)&memory_address)[1] = b;
// Offset
mem_offset = hub->recv();
#ifdef DEBUG_DS2433
Serial.print("DS2433 : READ SCRATCHPAD COMMAND : ");
Serial.print(memory_address, HEX);
Serial.print(",");
Serial.println(mem_offset, HEX);
#endif
break;
// READ MEMORY
case 0xF0:
// Adr1
b = hub->recv();
((uint8_t*)&memory_address)[0] = b;
// Adr2
b = hub->recv();
((uint8_t*)&memory_address)[1] = b;
// data
for (int i=0;i<32;i++)
hub->send(this->memory[memory_address+i]);
#ifdef DEBUG_DS2433
Serial.print("DS2433 : READ MEMORY : ");
Serial.println(memory_address, HEX);
#endif
break;
default:
#ifdef DEBUG_hint
Serial.print("DS2433=");
Serial.println(done, HEX);
#endif
break;
}
}