forked from OSCSYS/fermtroller
/
FermTroller.pde
271 lines (216 loc) · 6.93 KB
/
FermTroller.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#define BUILD 2
/*
Copyright (C) 2009, 2010 Matt Reba, Jeremiah Dillingham
This file is part of FermTroller.
FermTroller 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.
FermTroller 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 FermTroller. If not, see <http://www.gnu.org/licenses/>.
FermTroller - 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
*/
/*
Compiled on Arduino-0022 (http://arduino.cc/en/Main/Software)
With Sanguino Software "Sanguino-0018r2_1_4.zip" (http://code.google.com/p/sanguino/downloads/list)
Using the following libraries:
PID v0.6 (Beta 6) (http://www.arduino.cc/playground/Code/PIDLibrary)
OneWire 2.0 (http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip)
Encoder by CodeRage ()
FastPin and modified LiquidCrystal with FastPin by CodeRage (http://www.brewtroller.com/forum/showthread.php?t=626)
*/
//*****************************************************************************************************************************
// BEGIN CODE
//*****************************************************************************************************************************
#include <avr/pgmspace.h>
#include <PID_Beta6.h>
#include <pin.h>
#include <menu.h>
#include "Config.h"
#include "Enum.h"
#include "HWProfile.h"
#include "PVOut.h"
#include "UI_LCD.h"
void(* softReset) (void) = 0;
//**********************************************************************************
// Compile Time Logic
//**********************************************************************************
#ifndef NUM_ZONES
#define NUM_ZONES PVOUT_COUNT
#endif
#define NUM_VLVCFGS NUM_ZONES * 2 + 1 //Per zone Heat and Cool + Global Alarm
#ifdef USEMETRIC
#define SETPOINT_MULT 50
#define SETPOINT_DIV 2
#else
#define SETPOINT_MULT 100
#define SETPOINT_DIV 1
#endif
#if COM_SERIAL0 == BTNIC || defined BTNIC_EMBEDDED
#define BTNIC_PROTOCOL
#endif
#if defined BTPD_SUPPORT || defined UI_LCD_I2C || defined TS_ONEWIRE_I2C || defined BTNIC_EMBEDDED
#define USE_I2C
#endif
#ifdef USE_I2C
#include <Wire.h>
#endif
//**********************************************************************************
// Globals
//**********************************************************************************
#ifdef DIGITAL_INPUTS
pin digInPin[6];
#endif
#ifdef HEARTBEAT
pin hbPin;
#endif
//8-byte Temperature Sensor Address for each zone
byte tSensor[NUM_ZONES][8];
int temp[NUM_ZONES];
//Create the appropriate 'LCD' object for the hardware configuration (4-Bit GPIO, I2C)
#if defined UI_LCD_4BIT
#include <LiquidCrystalFP.h>
#ifndef UI_DISPLAY_SETUP
LCD4Bit LCD(LCD_RS_PIN, LCD_ENABLE_PIN, LCD_DATA4_PIN, LCD_DATA5_PIN, LCD_DATA6_PIN, LCD_DATA7_PIN);
#else
LCD4Bit LCD(LCD_RS_PIN, LCD_ENABLE_PIN, LCD_DATA4_PIN, LCD_DATA5_PIN, LCD_DATA6_PIN, LCD_DATA7_PIN, LCD_BRIGHT_PIN, LCD_CONTRAST_PIN);
#endif
#elif defined UI_LCD_I2C
LCDI2C LCD(UI_LCD_I2CADDR);
#endif
//Valve Variables
unsigned long vlvConfig[NUM_VLVCFGS], actHeats, actCools;
boolean buzzStatus;
byte alarmStatus[NUM_ZONES];
unsigned long coolTime[NUM_ZONES];
byte coolMinOn[NUM_ZONES], coolMinOff[NUM_ZONES]; //Minimum On/Off time for coolOutput in minutes
//Create the appropriate 'Valves' object for the hardware configuration (GPIO, MUX, MODBUS)
#if defined PVOUT_TYPE_GPIO
#define PVOUT
PVOutGPIO Valves(PVOUT_COUNT);
#elif defined PVOUT_TYPE_MUX
#define PVOUT
PVOutMUX Valves(
MUX_LATCH_PIN,
MUX_DATA_PIN,
MUX_CLOCK_PIN,
MUX_ENABLE_PIN,
MUX_ENABLE_LOGIC
);
#elif defined PVOUT_TYPE_MODBUS
#define PVOUT
PVOutMODBUS Valves();
#endif
//Shared buffers
char buf[20];
//Output Globals
double setpoint[NUM_ZONES];
byte hysteresis[NUM_ZONES];
byte alarmThresh[NUM_ZONES];
//Full Cool -100, Idle 0, Full Heat 100
int zonePwr[NUM_ZONES];
//Log Globals
boolean logData = LOG_INITSTATUS;
const char BT[] PROGMEM = "FermTroller";
const char BTVER[] PROGMEM = "2.1";
//Log Strings
const char LOGCMD[] PROGMEM = "CMD";
const char LOGDEBUG[] PROGMEM = "DEBUG";
const char LOGSYS[] PROGMEM = "SYS";
const char LOGCFG[] PROGMEM = "CFG";
const char LOGDATA[] PROGMEM = "DATA";
//**********************************************************************************
// Setup
//**********************************************************************************
void setup() {
#ifdef USE_I2C
Wire.begin(BT_I2C_ADDR);
#endif
//Log initialization (Log.pde)
comInit();
pinInit();
#ifdef PVOUT
#if defined PVOUT_TYPE_GPIO
#if PVOUT_COUNT >= 1
Valves.setup(0, VALVE1_PIN);
#endif
#if PVOUT_COUNT >= 2
Valves.setup(1, VALVE2_PIN);
#endif
#if PVOUT_COUNT >= 3
Valves.setup(2, VALVE3_PIN);
#endif
#if PVOUT_COUNT >= 4
Valves.setup(3, VALVE4_PIN);
#endif
#if PVOUT_COUNT >= 5
Valves.setup(4, VALVE5_PIN);
#endif
#if PVOUT_COUNT >= 6
Valves.setup(5, VALVE6_PIN);
#endif
#if PVOUT_COUNT >= 7
Valves.setup(6, VALVE7_PIN);
#endif
#if PVOUT_COUNT >= 8
Valves.setup(7, VALVE8_PIN);
#endif
#if PVOUT_COUNT >= 9
Valves.setup(8, VALVE9_PIN);
#endif
#if PVOUT_COUNT >= 10
Valves.setup(9, VALVEA_PIN);
#endif
#if PVOUT_COUNT >= 11
Valves.setup(10, VALVEB_PIN);
#endif
#if PVOUT_COUNT >= 12
Valves.setup(11, VALVEC_PIN);
#endif
#if PVOUT_COUNT >= 13
Valves.setup(12, VALVED_PIN);
#endif
#if PVOUT_COUNT >= 14
Valves.setup(13, VALVEE_PIN);
#endif
#if PVOUT_COUNT >= 15
Valves.setup(14, VALVEF_PIN);
#endif
#if PVOUT_COUNT >= 16
Valves.setup(15, VALVEG_PIN);
#endif
#endif
Valves.init();
#endif
tempInit();
//Check for cfgVersion variable and update EEPROM if necessary (EEPROM.pde)
checkConfig();
//Load global variable values stored in EEPROM (EEPROM.pde)
loadSetup();
//User Interface Initialization (UI.pde)
//Moving this to last of setup() to allow time for I2CLCD to initialize
#ifndef NOUI
uiInit();
#endif
splashScreen();
screenInit(0);
unlockUI();
}
//**********************************************************************************
// Loop
//**********************************************************************************
void loop() {
//User Interface Processing (UI.pde)
#ifndef NOUI
uiCore();
#endif
//Core FermTroller process code (FermCore.pde)
fermCore();
}