-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.cpp
179 lines (165 loc) · 5.77 KB
/
user.cpp
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
#include "global.h"
#include "user_pages.h"
#include <Bounce2.h>
Bounce debouncer = Bounce(); // Instantiate a Bounce object
byte VentilationInActual;
byte VentilationOutActual;
byte VentilationMode = MODE_COM;
boolean Refresh = false; // For Main Loop, to refresh things like GPIO / WS2812
unsigned long upTime = 0; // Seconds since start of ESP8266
void userInit() {
// user init code here
server.on( "/", userPage);
server.on( "/filldynamicdata", filldynamicdata);
server.on ( "/set", set_active_values );
server.on ( "/get", get_active_values );
// server.on( "/style.css", sendCSS);
pinMode(LED_BUILTIN, OUTPUT);
analogWrite(LED_BUILTIN, 220);
}
void userLoop() {
// user code here
yield();
// Button press
debouncer.update();
// Call code if Bounce fell (transition from HIGH to LOW) :
if ( debouncer.fell() ) {
VentilationMode++;
if (VentilationMode > 2) {
VentilationMode = 0;
}
Refresh = true;
Serial.println("BUTTON pressed");
Serial.print("VentilationMode changed to: ");
Serial.println(VentilationMode);
}
if (Refresh)
{
Refresh = false;
Serial.println("Refreshing values");
Serial.println(VentilationMode);
switch (VentilationMode) {
case MODE_MIN:
// set air volume
VentilationInActual = config.userConfig.VentilationInMin;
VentilationOutActual = config.userConfig.VentilationOutMin;
analogWriteFreq(1);
/*
// set LED color
StatusLED.R = 255; // R
StatusLED.G = 255; // G
StatusLED.B = 0; // B
*/
// display text
//lcdMiddleLine = "MINIMUM";
break;
case MODE_COM:
// set air volume
VentilationInActual = config.userConfig.VentilationInCom;
VentilationOutActual = config.userConfig.VentilationOutCom;
analogWriteFreq(4);
/*
// set LED color
StatusLED.R = 0; // R
StatusLED.G = 255; // G
StatusLED.B = 0; // B
*/
// display text
//lcdMiddleLine = "MINIMUM";
break;
case MODE_MAX:
// set air volume
VentilationInActual = config.userConfig.VentilationInMax;
VentilationOutActual = config.userConfig.VentilationOutMax;
analogWriteFreq(10);
/*
// set LED color
StatusLED.R = 255; // R
StatusLED.G = 0; // G
StatusLED.B = 0; // B
*/
// display text
//lcdMiddleLine = "MINIMUM";
break;
case MODE_EXT:
// set air volume
//pwmZuluftRate = 5;
//pwmAbluftRate = 5;
analogWriteFreq(20);
/*
// set LED color
StatusLED.R = 0; // R
StatusLED.G = 0; // G
StatusLED.B = 255; // B
*/
// display text
//lcdMiddleLine = "EXTERNAL CONTROL";
break;
default:
// Use comfort settings as above
VentilationMode = MODE_COM;
}
// set output PWM
analogWrite(VentilationInPin, 205 + ((1024 - 205) / 100) * VentilationInActual);
analogWrite(VentilationOutPin, 205 + ((1024 - 205) / 100) * VentilationOutActual);
Serial.print("ZuluftRate: ");
Serial.print(VentilationInActual);
Serial.print("\t");
Serial.print("Zuluft PWM value: ");
Serial.println(205 + ((1024 - 205) / 100) * VentilationInActual);
Serial.print("AbluftRate: ");
Serial.print(VentilationOutActual);
Serial.print("\t");
Serial.print("Abluft PWM value: ");
Serial.println(205 + (1024 - 205) / 100 * VentilationOutActual);
yield();
// Set LED
//strip.SetPixelColor(1, StatusLED.R, StatusLED.G, StatusLED.B);
//strip.Show();
///Serial.println("Refreshing...");
//Serial.printf("FreeMem:%d %d:%d:%d %d.%d.%d \n",ESP.getFreeHeap() , DateTime.hour,DateTime.minute, DateTime.second, DateTime.year, DateTime.month, DateTime.day);
}
}
// config
void userInitConfig() {
config.userConfig.AutoTurnOff = false;
config.userConfig.AutoTurnOn = false;
config.userConfig.TurnOffHour = 0;
config.userConfig.TurnOffMinute = 0;
config.userConfig.TurnOnHour = 0;
config.userConfig.TurnOnMinute = 0;
config.userConfig.VentilationInMin = 5;
config.userConfig.VentilationInCom = 60;
config.userConfig.VentilationInMax = 100;
config.userConfig.VentilationOutMin = 5;
config.userConfig.VentilationOutCom = 60;
config.userConfig.VentilationOutMax = 100;
}
void userLoadConfig(JsonObject& json) {
config.daylight = json["AutoTurnOff"] == 1 ? true : false;
config.daylight = json["AutoTurnOn"] == 1 ? true : false;
config.ntpUpdatePeriod = json["TurnOffHour"];
config.ntpUpdatePeriod = json["TurnOffMinute"];
config.ntpUpdatePeriod = json["TurnOnHour"];
config.ntpUpdatePeriod = json["TurnOnMinute"];
config.ntpUpdatePeriod = json["VentilationInMin"];
config.ntpUpdatePeriod = json["VentilationInCom"];
config.ntpUpdatePeriod = json["VentilationInMax"];
config.ntpUpdatePeriod = json["VentilationOutMin"];
config.ntpUpdatePeriod = json["VentilationOutCom"];
config.ntpUpdatePeriod = json["VentilationOutMax"];
}
void userSaveConfig(JsonObject& json) {
json["AutoTurnOff"] = config.userConfig.AutoTurnOff;
json["AutoTurnOnTurnOff"] = config.userConfig.AutoTurnOn;
json["TurnOffHour"] = config.userConfig.TurnOffHour;
json["TurnOffMinute"] = config.userConfig.TurnOffMinute;
json["TurnOnHour"] = config.userConfig.TurnOnHour;
json["TurnOnMinute"] = config.userConfig.TurnOnMinute;
json["VentilationInMin"] = config.userConfig.VentilationInMin;
json["VentilationInCom"] = config.userConfig.VentilationInCom;
json["VentilationInMax"] = config.userConfig.VentilationInMax;
json["VentilationOutMin"] = config.userConfig.VentilationOutMin;
json["VentilationOutCom"] = config.userConfig.VentilationOutCom;
json["VentilationOutMax"] = config.userConfig.VentilationOutMax;
}