forked from OSCSYS/brewtroller
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Events.pde
114 lines (95 loc) · 3.58 KB
/
Events.pde
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
/*
Copyright (C) 2009, 2010 Matt Reba, Jeremiah Dillingham
This file is part of BrewTroller.
BrewTroller 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.
BrewTroller 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 for more details.
You should have received a copy of the GNU General Public License
along with BrewTroller. If not, see <http://www.gnu.org/licenses/>.
BrewTroller - Open Source Brewing Computer
Software Lead: Matt Reba (matt_AT_brewtroller_DOT_com)
Hardware Lead: Jeremiah Dillingham (jeremiah_AT_brewtroller_DOT_com)
Documentation, Forums and more information available at http://www.brewtroller.com
*/
void eventHandler(byte eventID, int eventParam) {
//Global Event handler
//EVENT_STEPINIT: Nothing to do here (Pass to UI handler below)
//EVENT_STEPEXIT: Nothing to do here (Pass to UI handler below)
if (eventID == EVENT_SETPOINT) {
//Setpoint Change (Update AutoValve Logic)
byte avProfile = vesselAV(eventParam);
byte vlvHeat = vesselVLVHeat(eventParam);
byte vlvIdle = vesselVLVIdle(eventParam);
if (setpoint[eventParam]) autoValve[avProfile] = 1;
else {
autoValve[avProfile] = 0;
if (vlvConfigIsActive(vlvIdle)) bitClear(actProfiles, vlvIdle);
if (vlvConfigIsActive(vlvHeat)) bitClear(actProfiles, vlvHeat);
}
}
#ifndef NOUI
//Pass Event Info to UI Event Handler
uiEvent(eventID, eventParam);
#endif
//Pass Event Info to Com Event Handler
comEvent(eventID, eventParam);
}
#ifdef DIGITAL_INPUTS
void triggerSetup() {
//If EEPROM is not initialized skip trigger init
if (checkConfig()) return;
//For each logical trigger type see what the assigned trigger pin is (if any)
for (byte i = 0; i < NUM_TRIGGERS; i++) {
if (TriggerPin[i] != NULL) TriggerPin[i]->detachPCInt();
if (getTriggerPin(i)) {
TriggerPin[i] = &digInPin[getTriggerPin(i) - 1];
if (i == TRIGGER_ESTOP) TriggerPin[i]->attachPCInt(CHANGE, eStopISR);
else if (i == TRIGGER_SPARGEMAX) TriggerPin[i]->attachPCInt(RISING, spargeMaxISR);
else if (i == TRIGGER_HLTMIN) TriggerPin[i]->attachPCInt(FALLING, hltMinISR);
else if (i == TRIGGER_MASHMIN) TriggerPin[i]->attachPCInt(FALLING, mashMinISR);
else if (i == TRIGGER_KETTLEMIN) TriggerPin[i]->attachPCInt(FALLING, kettleMinISR);
}
}
}
void eStopISR() {
//Either clear E-Stop condition if e-Stop trigger goes high
//or perform E-Stop actions on trigger low
if (TriggerPin[TRIGGER_ESTOP]->get()) estop = 0;
else {
estop = 1;
setAlarm(1);
processHeatOutputs();
#ifdef PVOUT
updateValves();
#endif
updateTimers();
}
}
void spargeMaxISR() {
bitClear(actProfiles, VLV_SPARGEIN);
}
void hltMinISR() {
heatPin[VS_HLT].set(LOW);
heatStatus[VS_HLT] = 0;
bitClear(actProfiles, VLV_HLTHEAT);
}
void mashMinISR() {
heatPin[VS_MASH].set(LOW);
heatStatus[VS_MASH] = 0;
bitClear(actProfiles, VLV_MASHHEAT);
#ifdef DIRECT_FIRED_RIMS
heatPin[VS_STEAM].set(LOW);
heatStatus[VS_STEAM] = 0;
#endif
}
void kettleMinISR() {
heatPin[VS_KETTLE].set(LOW);
heatStatus[VS_KETTLE] = 0;
bitClear(actProfiles, VLV_KETTLEHEAT);
}
#endif