-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filter_Controller.ino.orig
273 lines (249 loc) · 7.77 KB
/
Filter_Controller.ino.orig
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
272
//<File !Start!>
//<App !Start!>
// FILE: [Filter_Controller.ino]
// Created by GUIslice Builder version: [0.17.b11]
//
// GUIslice Builder Generated File
//
// For the latest guides, updates and support view:
// https://github.com/ImpulseAdventure/GUIslice
//
//<App !End!>
//<File !End!>
// ------------------------------------------------
// Headers to include
// ------------------------------------------------
#include <Arduino.h>
#include <EEPROM.h>
#include "Filter_Controller_GSLC.h"
// ------------------------------------------------
// Program Globals
// ------------------------------------------------
uint8_t on_time_global;
uint8_t gap_time_global;
uint8_t play_status_global;
uint8_t relay=22;
bool gap_timer_started = false;
bool box=false;
bool on_t_flag=false;
bool gap_t_flag=true;
bool relay_text_updated=false;
char acTxt[4];
unsigned long int t1, t2;
void on_time() {
uint8_t on_time_l = gslc_ElemXSpinnerGetCounter(&m_gui, &m_sXSpinner1);
//Serial.println("On Time: " + String(on_time_l));
on_time_global = on_time_l;
EEPROM.update(0, on_time_l);
}
void gap_time() {
uint8_t gap_time_l = gslc_ElemXSpinnerGetCounter(&m_gui, &m_sXSpinner2);
//Serial.println("Gap Time: " + String(gap_time_l));
gap_time_global=gap_time_l;
EEPROM.update(1, gap_time_l);
}
void start_switch() {
if (gslc_ElemXTogglebtnGetState(&m_gui, m_pElemToggle1)) {
//Serial.println("turned on");
play_status_global = 1;
EEPROM.update(2, 1);
}
else
{
//Serial.println("turned off");
play_status_global = 0;
EEPROM.update(2, 0);
}
}
// Save some element references for direct access
//<Save_References !Start!>
gslc_tsElemRef* m_pElemProgress1 = NULL;
gslc_tsElemRef* m_pElemSpinner1 = NULL;
gslc_tsElemRef* m_pElemSpinner2 = NULL;
gslc_tsElemRef* m_pElemToggle1 = NULL;
gslc_tsElemRef* relay_text = NULL;
//<Save_References !End!>
// Define debug message function
static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); else Serial.write(ch); return 0; }
// ------------------------------------------------
// Callback Methods
// ------------------------------------------------
// Common Button callback
bool CbBtnCommon(void* pvGui,void *pvElemRef,gslc_teTouch eTouch,int16_t nX,int16_t nY)
{
// Typecast the parameters to match the GUI and element types
gslc_tsGui* pGui = (gslc_tsGui*)(pvGui);
gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
gslc_tsElem* pElem = gslc_GetElemFromRef(pGui,pElemRef);
if ( eTouch == GSLC_TOUCH_UP_IN ) {
// From the element's ID we can determine which button was pressed.
switch (pElem->nId) {
//<Button Enums !Start!>
case E_ELEM_TOGGLE1:
// TODO Add code for Toggle button ON/OFF state
start_switch();
break;
//<Button Enums !End!>
default:
break;
}
}
return true;
}
//<Checkbox Callback !Start!>
//<Checkbox Callback !End!>
//<Keypad Callback !Start!>
//<Keypad Callback !End!>
//<Spinner Callback !Start!>
//<Spinner Callback !End!>
//<Listbox Callback !Start!>
//<Listbox Callback !End!>
//<Checkbox Callback !Start!>
//<Checkbox Callback !End!>
//<Keypad Callback !Start!>
//<Keypad Callback !End!>
// Spinner Input Ready callback
bool CbSpinner(void* pvGui, void *pvElemRef, int16_t nState, void* pvData)
{
gslc_tsGui* pGui = (gslc_tsGui*)pvGui;
gslc_tsElemRef* pElemRef = (gslc_tsElemRef*)(pvElemRef);
gslc_tsElem* pElem = gslc_GetElemFromRef(pGui,pElemRef);
// NOTE: pvData is NULL
if (nState == XSPINNER_CB_STATE_UPDATE) {
// From the element's ID we can determine which input field is ready.
switch (pElem->nId) {
//<Spinner Enums !Start!>
case E_ELEM_SPINNER1:
//TODO- Add Spinner handling code
// using gslc_ElemXSpinnerGetCounter(&m_gui, &m_sXSpinner1);
on_time();
break;
case E_ELEM_SPINNER2:
//TODO- Add Spinner handling code
// using gslc_ElemXSpinnerGetCounter(&m_gui, &m_sXSpinner2);
gap_time();
break;
//<Spinner Enums !End!>
default:
break;
}
}
}
//<Listbox Callback !Start!>
//<Listbox Callback !End!>
//<Draw Callback !Start!>
//<Draw Callback !End!>
//<Slider Callback !Start!>
//<Slider Callback !End!>
//<Tick Callback !Start!>
//<Tick Callback !End!>
void setup()
{
// ------------------------------------------------
// Initialize
// ------------------------------------------------
Serial.begin(9600);
// Wait for USB Serial
//delay(1000); // NOTE: Some devices require a delay after Serial.begin() before serial port can be used
on_time_global = EEPROM.read(0);
gap_time_global = EEPROM.read(1);
play_status_global = EEPROM.read(2);
//set pins 22 to 39 as outputs
for (int i = 22; i < 40; i++) {
pinMode(i, OUTPUT);
}
// set all pins to LOW
for (int i = 22; i < 40; i++) {
digitalWrite(i, LOW);
}
gslc_InitDebug(&DebugOut);
// ------------------------------------------------
// Create graphic elements
// ------------------------------------------------
InitGUIslice_gen();
gslc_ElemXSpinnerSetCounter(&m_gui, &m_sXSpinner1, on_time_global);
gslc_ElemXSpinnerSetCounter(&m_gui, &m_sXSpinner2, gap_time_global);
if (play_status_global==1)
gslc_ElemXTogglebtnSetState(&m_gui, m_pElemToggle1, true);
else
gslc_ElemXTogglebtnSetState(&m_gui, m_pElemToggle1, false);
int relay_readable = map (relay, 22, 39, 1, 18);
snprintf(acTxt, 4, "%u", relay_readable);
gslc_ElemSetTxtStr(&m_gui,relay_text,acTxt);
t1 = millis();
t2 = millis();
}
// -----------------------------------
// Main event loop
// -----------------------------------
void loop()
{
// ------------------------------------------------
// Update GUI Elements
// ------------------------------------------------
//TODO - Add update code for any text, gauges, or sliders
// ------------------------------------------------
// Periodically call GUIslice update function
// ------------------------------------------------
gslc_Update(&m_gui);
if(play_status_global)
{
if(millis() - t1 > (on_time_global*1000))
{
digitalWrite(relay, LOW);
//Serial.println("Relay: " + String(relay) + " OFF");
float progress_percent = (millis() - t2);
progress_percent = progress_percent/ (gap_time_global*1000);
progress_percent=progress_percent*100;
//Serial.println("Progress: " + String(progress_percent) + "%");
gslc_ElemXProgressSetVal(&m_gui,m_pElemProgress1, int16_t(100-progress_percent));
}
else{
t2 = millis();
digitalWrite(relay, HIGH);
//Serial.println("Relay: " + String(relay) + " ON");
float progress_percent = (millis() - t1);
progress_percent = progress_percent/ (on_time_global*1000);
progress_percent=progress_percent*100;
//Serial.println("Progress: " + String(progress_percent) + "%");
gslc_ElemXProgressSetVal(&m_gui,m_pElemProgress1, int16_t(progress_percent));
}
if(millis() - t2 > (gap_time_global*1000))
{
t1 = millis();
relay++;
relay_text_updated = true;
if(relay > 39)
{
relay = 22;
}
}
if (relay_text_updated)
{
relay_text_updated = false;
int relay_readable = map (relay, 22, 39, 1, 18);
//Serial.println("Relay: " + String(relay_readable));
snprintf(acTxt, 4, "%u", relay_readable);
gslc_ElemSetTxtStr(&m_gui,relay_text,acTxt);
}
if(led_status_t.isExpired())
{
if(box==false)
{
gslc_ElemXCheckboxSetState(&m_gui, m_status, true);
box = true;
}
else
{
gslc_ElemXCheckboxSetState(&m_gui, m_status, false);
box = false;
}
led_status_t.repeat();
}
}
else
{
digitalWrite(relay, LOW);
gslc_ElemXCheckboxSetState(&m_gui, m_status, false);
}
}