-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds24x05.c
62 lines (46 loc) · 965 Bytes
/
ds24x05.c
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
#include "ds24x05.h"
struct ds2405
{
unsigned char* rom;
unsigned char state;
};
volatile struct ds2405 switches[SWITCH_COUNT];
volatile unsigned char index = 0;
char find_index(unsigned char* value);
char DS24x05_Toggle(unsigned char* rom)
{
if (!OW_Reset()) return 0;
OW_MatchROM(rom);
char i = find_index(rom);
if (i != -1){
if (switches[i].state == false){
switches[i].state = true;
}else{
switches[i].state = false;
}
}
return 1;
}
void DS24x05_Add(unsigned char* rom){
switches[index].rom = rom;
switches[index].state = false;
index++;
}
unsigned char DS24x05_GetState(unsigned char* rom){
char i = find_index(rom);
if (i != -1){
return switches[i].state;
}
return false;
}
char find_index(unsigned char* value){
unsigned char i;
for (i=0; i<SWITCH_COUNT; i++)
{
if (switches[i].rom == value)
{
return i;
}
}
return(-1);
}