-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathonoffcore.c
95 lines (71 loc) · 1.35 KB
/
onoffcore.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
/*
* onoffcore.c
*
* Created on: 28 cze 2020
* Author: watchdoge
*/
static int ctrl_target;
static int ctrl_hysteresis_up;
static int ctrl_hysteresis_down;
static int ctrl_signal;
static void (*ONcallback)(void);
static void (*OFFcallback)(void);
int onoffcore_set_target(int target)
{
ctrl_target = target;
return 0;
}
int onoffcore_set_hist_down(int hyst_down)
{
ctrl_hysteresis_down = hyst_down;
return 0;
}
int onoffcore_set_hist_up(int hyst_up)
{
ctrl_hysteresis_up = hyst_up;
return 0;
}
int onoffcore_set_signal(int signal)
{
ctrl_signal = signal;
return 0;
}
int onoffcore_set_ON_callback(void *ONcb)
{
ONcallback = ONcb;
return 0;
}
int onoffcore_set_OFF_callback(void *OFFcb)
{
OFFcallback = OFFcb;
return 0;
}
int onoffcore_read_target(void)
{
return ctrl_target;
}
int onoffcore_read_hist_down(void)
{
return ctrl_hysteresis_down;
}
int onoffcore_read_hist_up(void)
{
return ctrl_hysteresis_up;
}
int onoffcore_read_signal(void)
{
return ctrl_signal;
}
void onoffcore_run(void)
{
if (ctrl_signal < (ctrl_target - ctrl_hysteresis_down)){
if(ONcallback){
ONcallback();
}
}
else if (ctrl_signal > (ctrl_target + ctrl_hysteresis_up)) {
if (OFFcallback){
OFFcallback();
}
}
}