forked from M-o-a-T/owslave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moat_count.c
112 lines (95 loc) · 2.01 KB
/
moat_count.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
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
/*
* Copyright © 2014-2015, Matthias Urlichs <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License (included; see the file LICENSE)
* for more details.
*/
/* This code implements reading port pins via 1wire.
*/
#include <string.h> // memset
#include "moat_internal.h"
#include "dev_data.h"
#include "debug.h"
#include "onewire.h"
#include "count.h"
#include "timer.h"
#ifdef N_COUNT
#define BLEN N_COUNT*sizeof(t->count)
uint8_t read_count_len(uint8_t chan)
{
count_t *t;
if(chan)
return sizeof(t->count);
else
return BLEN;
}
void read_count(uint8_t chan, uint8_t *buf)
{
count_t *t;
if (chan) { // one COUNT: send value
if (chan > N_COUNT)
next_idle('p');
t = &counts[chan-1];
cli();
#if COUNT_SIZE >= 4
*buf++ = t->count>>24;
#endif
#if COUNT_SIZE >= 3
*buf++ = t->count>>16;
#endif
#if COUNT_SIZE >= 2
*buf++ = t->count>>8;
#endif
*buf++ = t->count;
t->flags &=~ CF_IS_ALERT;
sei();
} else { // all COUNTs
uint8_t i;
t = counts;
for(i=0;i<N_COUNT;i++,t++) {
cli();
#if COUNT_SIZE >= 4
*buf++ = t->count>>24;
#endif
#if COUNT_SIZE >= 3
*buf++ = t->count>>16;
#endif
#if COUNT_SIZE >= 2
*buf++ = t->count>>8;
#endif
*buf++ = t->count;
sei();
}
}
}
#ifdef CONDITIONAL_SEARCH
char alert_count_check(void)
{
return (count_changed_cache+7)>>3;
}
void alert_count_fill(uint8_t *buf)
{
uint8_t i;
count_t *t = counts;
uint8_t m=1;
memset(buf,0,(N_COUNT+7)>>3);
for(i=0;i < N_COUNT; i++,t++) {
if (!m) {
m = 1;
buf++;
}
if (t->flags & CF_IS_ALERT)
*buf |= m;
m <<= 1;
}
}
#endif // conditional
#endif