|
|
|
@@ -16,12 +16,11 @@ Preferences preferences;
|
|
|
|
const char* ntp = "fritz.box";
|
|
|
|
const char* ntp = "fritz.box";
|
|
|
|
const int gmt_offset_sec = 3600;
|
|
|
|
const int gmt_offset_sec = 3600;
|
|
|
|
const int daylight_offset_sec = 7200;
|
|
|
|
const int daylight_offset_sec = 7200;
|
|
|
|
ESP32Time rtc(3600);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Variablen für PWM
|
|
|
|
//Variablen für PWM
|
|
|
|
int pwm_freq = 5000;
|
|
|
|
int pwm_freq = 5000;
|
|
|
|
int pwm_resolution = 8;
|
|
|
|
int pwm_resolution = 10;
|
|
|
|
int pwm_light_resolution = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Variablen PWM fan
|
|
|
|
//Variablen PWM fan
|
|
|
|
int fan_pwm_channel = 0;
|
|
|
|
int fan_pwm_channel = 0;
|
|
|
|
@@ -39,21 +38,14 @@ char led1cycle[5] = "led1";
|
|
|
|
char led2cycle[5] = "led2";
|
|
|
|
char led2cycle[5] = "led2";
|
|
|
|
char fancycle[4] = "fan";
|
|
|
|
char fancycle[4] = "fan";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Variable zum Speichern des Status des Schalters
|
|
|
|
//Variable zum Speichern des Status des Schalters
|
|
|
|
bool fan_active = false;
|
|
|
|
bool fan_active = false;
|
|
|
|
bool led1active = false;
|
|
|
|
bool led1active = false;
|
|
|
|
bool led2active = false;
|
|
|
|
bool led2active = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Ändern Sie dies auf die Auflösung Ihres Bildschirms */
|
|
|
|
/* Ändern Sie dies auf die Auflösung Ihres Bildschirms */
|
|
|
|
static const uint16_t screenWidth = 320;
|
|
|
|
static const uint16_t screenWidth = 320;
|
|
|
|
static const uint16_t screenHeight = 240;
|
|
|
|
static const uint16_t screenHeight = 240;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum { SCREENBUFFER_SIZE_PIXELS = screenWidth * screenHeight / 10 };
|
|
|
|
enum { SCREENBUFFER_SIZE_PIXELS = screenWidth * screenHeight / 10 };
|
|
|
|
static lv_color_t buf [SCREENBUFFER_SIZE_PIXELS];
|
|
|
|
static lv_color_t buf [SCREENBUFFER_SIZE_PIXELS];
|
|
|
|
|
|
|
|
|
|
|
|
@@ -68,9 +60,10 @@ void my_print(const char * buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//WIFI
|
|
|
|
void scanWifi(lv_event_t * e)
|
|
|
|
void scanWifi(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
lv_dropdown_clear_options(ui_wifinetlist);
|
|
|
|
lv_dropdown_clear_options(ui_wifinetlist);
|
|
|
|
int n = WiFi.scanNetworks();
|
|
|
|
int n = WiFi.scanNetworks();
|
|
|
|
if (n == 0)
|
|
|
|
if (n == 0)
|
|
|
|
@@ -80,8 +73,6 @@ void scanWifi(lv_event_t * e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n; ++i)
|
|
|
|
for (int i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_dropdown_add_option(ui_wifinetlist, WiFi.SSID(i).c_str(), i);
|
|
|
|
lv_dropdown_add_option(ui_wifinetlist, WiFi.SSID(i).c_str(), i);
|
|
|
|
@@ -94,48 +85,40 @@ void setWifi(lv_event_t * e)
|
|
|
|
char ssid[32];
|
|
|
|
char ssid[32];
|
|
|
|
lv_dropdown_get_selected_str(ui_wifinetlist, ssid, sizeof(ssid));
|
|
|
|
lv_dropdown_get_selected_str(ui_wifinetlist, ssid, sizeof(ssid));
|
|
|
|
const char * pw = (const char*)lv_textarea_get_text(ui_wifipw);
|
|
|
|
const char * pw = (const char*)lv_textarea_get_text(ui_wifipw);
|
|
|
|
Serial.println(ssid);
|
|
|
|
|
|
|
|
Serial.println(pw);
|
|
|
|
|
|
|
|
WiFi.begin(ssid, pw);
|
|
|
|
WiFi.begin(ssid, pw);
|
|
|
|
int8_t counter;
|
|
|
|
int8_t counter;
|
|
|
|
while (WiFi.status() != WL_CONNECTED && counter != 10)
|
|
|
|
while (WiFi.status() != WL_CONNECTED && counter != 21)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_label_set_text(ui_wifistatus, "Connecting...");
|
|
|
|
lv_label_set_text(ui_wifistatus, "Connecting...");
|
|
|
|
// Serial.println("AHHHHHH die Schleife");
|
|
|
|
|
|
|
|
delay(500);
|
|
|
|
delay(500);
|
|
|
|
++counter;
|
|
|
|
++counter;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lv_label_set_text(ui_wifistatus, "Connected");
|
|
|
|
lv_label_set_text(ui_wifistatus, "Connected");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preferences.begin("wifi", false);
|
|
|
|
preferences.begin("wifi", false);
|
|
|
|
preferences.putString("ssid", ssid);
|
|
|
|
preferences.putString("ssid", ssid);
|
|
|
|
preferences.putString("pw", pw);
|
|
|
|
preferences.putString("pw", pw);
|
|
|
|
preferences.end();
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FAN AND LIGHT CONTROL
|
|
|
|
void switchEventHandler(lv_event_t * e)
|
|
|
|
void switchEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
|
|
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
|
|
|
char * user_data = (char*)lv_event_get_user_data(e);
|
|
|
|
char * user_data = (char*)lv_event_get_user_data(e);
|
|
|
|
preferences.begin("dutycycles", false);
|
|
|
|
|
|
|
|
int light_off_duty_cycle = 1024;
|
|
|
|
int light_off_duty_cycle = 1024;
|
|
|
|
int fan_duty_cycle;
|
|
|
|
int fan_duty_cycle;
|
|
|
|
int led1_duty_cycle;
|
|
|
|
int led1_duty_cycle;
|
|
|
|
int led2_duty_cycle;
|
|
|
|
int led2_duty_cycle;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(obj == ui_light1switch)
|
|
|
|
if(obj == ui_light1switch)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
|
|
|
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", true);
|
|
|
|
led1_duty_cycle = preferences.getInt(user_data, 860);
|
|
|
|
led1_duty_cycle = preferences.getInt(user_data, 860);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
led1active = true;
|
|
|
|
led1active = true;
|
|
|
|
|
|
|
|
|
|
|
|
turnOn(led1_pwm_pin, led1_duty_cycle, ui_light1statuslbl, ui_lbllightstatus, ui_light1percent);
|
|
|
|
turnOn(led1_pwm_pin, led1_duty_cycle, ui_light1statuslbl, ui_lbllightstatus, ui_light1percent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@@ -148,7 +131,9 @@ void switchEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
|
|
|
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", true);
|
|
|
|
led2_duty_cycle = preferences.getInt(user_data, 860);
|
|
|
|
led2_duty_cycle = preferences.getInt(user_data, 860);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
led2active = true;
|
|
|
|
led2active = true;
|
|
|
|
turnOn(led2_pwm_pin, led2_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent);
|
|
|
|
turnOn(led2_pwm_pin, led2_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -162,8 +147,11 @@ void switchEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
|
|
|
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fan_duty_cycle = preferences.getInt(user_data, 76);
|
|
|
|
preferences.begin("g_phase", true);
|
|
|
|
|
|
|
|
fan_duty_cycle = preferences.getInt(user_data, 310);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
fan_active = true;
|
|
|
|
fan_active = true;
|
|
|
|
|
|
|
|
|
|
|
|
turnOn(fan_pwm_pin, fan_duty_cycle, ui_lblfanstatus, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
turnOn(fan_pwm_pin, fan_duty_cycle, ui_lblfanstatus, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@@ -173,7 +161,6 @@ void switchEventHandler(lv_event_t * e)
|
|
|
|
turnOff(fan_pwm_pin, off_duty_cycle, ui_lblfanstatus, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
turnOff(fan_pwm_pin, off_duty_cycle, ui_lblfanstatus, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void turnOn(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmainlbl, lv_obj_t * percent)
|
|
|
|
void turnOn(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmainlbl, lv_obj_t * percent)
|
|
|
|
@@ -182,21 +169,28 @@ void turnOn(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmain
|
|
|
|
int percentage;
|
|
|
|
int percentage;
|
|
|
|
if (statusmainlbl == ui_lblfanspeed)
|
|
|
|
if (statusmainlbl == ui_lblfanspeed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
percentage = round((duty_cycle * 100.0) / 255.0);
|
|
|
|
percentage = round((duty_cycle * 100.0) / 1024.0);
|
|
|
|
lv_label_set_text_fmt(statusmainlbl, "%d%%", percentage);
|
|
|
|
lv_label_set_text_fmt(statusmainlbl, "%d%%", percentage);
|
|
|
|
lv_label_set_text_fmt(percent, "%d%%", percentage);
|
|
|
|
lv_label_set_text_fmt(percent, "%d%%", percentage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
percentage = round(100 - (duty_cycle * 100.0) / 1024.0);
|
|
|
|
percentage = round(100 - (duty_cycle * 100.0) / 1024.0);
|
|
|
|
lv_label_set_text(statusmainlbl, "ON");
|
|
|
|
lv_label_set_text(statusmainlbl, "ON");
|
|
|
|
lv_label_set_text_fmt(percent, "%d%%", percentage);
|
|
|
|
lv_label_set_text_fmt(percent, "%d%%", percentage);
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
|
|
|
|
preferences.putBool("light", true);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lv_label_set_text(statuslbl, "ON");
|
|
|
|
lv_label_set_text(statuslbl, "ON");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void turnOff(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmainlbl, lv_obj_t * percent)
|
|
|
|
void turnOff(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmainlbl, lv_obj_t * percent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
ledcWrite(pin, duty_cycle);
|
|
|
|
ledcWrite(pin, duty_cycle);
|
|
|
|
if (statusmainlbl == ui_lblfanspeed) lv_label_set_text(statusmainlbl, "0%");
|
|
|
|
if (statusmainlbl == ui_lblfanspeed) lv_label_set_text(statusmainlbl, "0%");
|
|
|
|
lv_label_set_text(statuslbl, "OFF");
|
|
|
|
lv_label_set_text(statuslbl, "OFF");
|
|
|
|
@@ -204,16 +198,24 @@ void turnOff(int pin, int duty_cycle, lv_obj_t * statuslbl, lv_obj_t * statusmai
|
|
|
|
|
|
|
|
|
|
|
|
if (led1active == false && led2active == false)
|
|
|
|
if (led1active == false && led2active == false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
|
|
|
|
preferences.putBool("light", false);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
lv_label_set_text(statusmainlbl, "OFF");
|
|
|
|
lv_label_set_text(statusmainlbl, "OFF");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dimm(int pin, int duty_cycle, lv_obj_t * percent, lv_obj_t * percent2 = NULL)
|
|
|
|
void dimm(int pin, int duty_cycle, lv_obj_t * percent, lv_obj_t * percent2 = NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int percentage = 0;
|
|
|
|
int percentage = 0;
|
|
|
|
ledcWrite(pin, duty_cycle);
|
|
|
|
ledcWrite(pin, duty_cycle);
|
|
|
|
if (percent == ui_lblfanspeed)
|
|
|
|
if (percent == ui_lblfanspeed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
percentage = round((duty_cycle * 100.0) / 255.0);
|
|
|
|
percentage = round((duty_cycle * 100.0) / 1024.0);
|
|
|
|
lv_label_set_text_fmt(percent2, "%d%%", percentage);
|
|
|
|
lv_label_set_text_fmt(percent2, "%d%%", percentage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@@ -226,33 +228,35 @@ void dimm(int pin, int duty_cycle, lv_obj_t * percent, lv_obj_t * percent2 = NUL
|
|
|
|
|
|
|
|
|
|
|
|
static void dimmUpBtnEventHandler(lv_event_t * e)
|
|
|
|
static void dimmUpBtnEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int fan_duty_cycle = 3;
|
|
|
|
int fan_duty_cycle = 10;
|
|
|
|
int led1_duty_cycle = -10;
|
|
|
|
int led1_duty_cycle = -10;
|
|
|
|
int led2_duty_cycle = -10;
|
|
|
|
int led2_duty_cycle = -10;
|
|
|
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
|
|
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
|
|
|
char* user_data = (char*)lv_event_get_user_data(e);
|
|
|
|
char* user_data = (char*)lv_event_get_user_data(e);
|
|
|
|
preferences.begin("dutycycles", false);
|
|
|
|
|
|
|
|
Serial.println(user_data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (obj == ui_light1up)
|
|
|
|
if (obj == ui_light1up)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (led1active)
|
|
|
|
if (led1active)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
led1_duty_cycle += preferences.getInt(user_data, 860);
|
|
|
|
led1_duty_cycle += preferences.getInt(user_data, 860);
|
|
|
|
if (led1_duty_cycle <= 0) led1_duty_cycle = 0;
|
|
|
|
if (led1_duty_cycle <= 0) led1_duty_cycle = 0;
|
|
|
|
Serial.println(led1_duty_cycle);
|
|
|
|
|
|
|
|
preferences.putInt(user_data, led1_duty_cycle);
|
|
|
|
preferences.putInt(user_data, led1_duty_cycle);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
dimm(led1_pwm_pin, led1_duty_cycle, ui_light1percent);
|
|
|
|
dimm(led1_pwm_pin, led1_duty_cycle, ui_light1percent);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (obj == ui_light2up)
|
|
|
|
if (obj == ui_light2up)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (led2active)
|
|
|
|
if (led2active)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
led2_duty_cycle += preferences.getInt(user_data, 860);
|
|
|
|
led2_duty_cycle += preferences.getInt(user_data, 860);
|
|
|
|
if (led2_duty_cycle <= 0) led2_duty_cycle = 0;
|
|
|
|
if (led2_duty_cycle <= 0) led2_duty_cycle = 0;
|
|
|
|
Serial.println(led2_duty_cycle);
|
|
|
|
|
|
|
|
preferences.putInt(user_data, led2_duty_cycle);
|
|
|
|
preferences.putInt(user_data, led2_duty_cycle);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
dimm(led2_pwm_pin, led2_duty_cycle, ui_light2percent);
|
|
|
|
dimm(led2_pwm_pin, led2_duty_cycle, ui_light2percent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -260,33 +264,34 @@ static void dimmUpBtnEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (fan_active)
|
|
|
|
if (fan_active)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
fan_duty_cycle += preferences.getInt(user_data, 76);
|
|
|
|
fan_duty_cycle += preferences.getInt(user_data, 76);
|
|
|
|
if (fan_duty_cycle >= 255) fan_duty_cycle = 255;
|
|
|
|
if (fan_duty_cycle >= 1024) fan_duty_cycle = 1024;
|
|
|
|
Serial.println(fan_duty_cycle);
|
|
|
|
|
|
|
|
preferences.putInt(user_data, fan_duty_cycle);
|
|
|
|
preferences.putInt(user_data, fan_duty_cycle);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
dimm(fan_pwm_pin, fan_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
dimm(fan_pwm_pin, fan_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void dimmDownBtnEventHandler(lv_event_t * e)
|
|
|
|
static void dimmDownBtnEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
|
|
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
|
|
|
char* user_data = (char*)lv_event_get_user_data(e);
|
|
|
|
char* user_data = (char*)lv_event_get_user_data(e);
|
|
|
|
int fan_duty_cycle = -3;
|
|
|
|
int fan_duty_cycle = -10;
|
|
|
|
int led1_duty_cycle = 10;
|
|
|
|
int led1_duty_cycle = 10;
|
|
|
|
int led2_duty_cycle = 10;
|
|
|
|
int led2_duty_cycle = 10;
|
|
|
|
preferences.begin("dutycycles", false);
|
|
|
|
|
|
|
|
Serial.println(user_data);
|
|
|
|
|
|
|
|
if (obj == ui_light1down)
|
|
|
|
if (obj == ui_light1down)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (led1active)
|
|
|
|
if (led1active)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
led1_duty_cycle += preferences.getInt(user_data);
|
|
|
|
led1_duty_cycle += preferences.getInt(user_data);
|
|
|
|
if (led1_duty_cycle >= 860) led1_duty_cycle = 860;
|
|
|
|
if (led1_duty_cycle >= 860) led1_duty_cycle = 860;
|
|
|
|
Serial.println(led1_duty_cycle);
|
|
|
|
|
|
|
|
preferences.putInt(user_data, led1_duty_cycle);
|
|
|
|
preferences.putInt(user_data, led1_duty_cycle);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
dimm(led1_pwm_pin, led1_duty_cycle, ui_light1percent);
|
|
|
|
dimm(led1_pwm_pin, led1_duty_cycle, ui_light1percent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -294,10 +299,11 @@ static void dimmDownBtnEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (led2active)
|
|
|
|
if (led2active)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
led2_duty_cycle += preferences.getInt(user_data);
|
|
|
|
led2_duty_cycle += preferences.getInt(user_data);
|
|
|
|
if (led2_duty_cycle >= 860) led2_duty_cycle = 860;
|
|
|
|
if (led2_duty_cycle >= 860) led2_duty_cycle = 860;
|
|
|
|
Serial.println(led2_duty_cycle);
|
|
|
|
|
|
|
|
preferences.putInt(user_data, led2_duty_cycle);
|
|
|
|
preferences.putInt(user_data, led2_duty_cycle);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
dimm(led2_pwm_pin, led2_duty_cycle, ui_light2percent);
|
|
|
|
dimm(led2_pwm_pin, led2_duty_cycle, ui_light2percent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -305,13 +311,14 @@ static void dimmDownBtnEventHandler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (fan_active)
|
|
|
|
if (fan_active)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
fan_duty_cycle += preferences.getInt(user_data);
|
|
|
|
fan_duty_cycle += preferences.getInt(user_data);
|
|
|
|
if (fan_duty_cycle <= 64) fan_duty_cycle = 64;
|
|
|
|
if (fan_duty_cycle <= 310) fan_duty_cycle = 310;
|
|
|
|
preferences.putInt(user_data, fan_duty_cycle);
|
|
|
|
preferences.putInt(user_data, fan_duty_cycle);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
dimm(fan_pwm_pin, fan_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
dimm(fan_pwm_pin, fan_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -354,7 +361,6 @@ void my_touchpad_read (lv_indev_t * indev_driver, lv_indev_data_t * data)
|
|
|
|
if (data->point.x < 0) data->point.x = 0;
|
|
|
|
if (data->point.x < 0) data->point.x = 0;
|
|
|
|
if (data->point.y < 0) data->point.y = 0;
|
|
|
|
if (data->point.y < 0) data->point.y = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Debugging-Ausgaben
|
|
|
|
// Debugging-Ausgaben
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Serial.print("Touch X: ");
|
|
|
|
Serial.print("Touch X: ");
|
|
|
|
@@ -368,7 +374,23 @@ void my_touchpad_read (lv_indev_t * indev_driver, lv_indev_data_t * data)
|
|
|
|
/* Tick-Funktion für LVGL interne Timings */
|
|
|
|
/* Tick-Funktion für LVGL interne Timings */
|
|
|
|
static uint32_t my_tick_get_cb (void) { return millis(); }
|
|
|
|
static uint32_t my_tick_get_cb (void) { return millis(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Setup Preferences
|
|
|
|
|
|
|
|
void initPreferences()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("wifi", false);
|
|
|
|
|
|
|
|
preferences.putString("ssid", "MeinZuhause");
|
|
|
|
|
|
|
|
preferences.putString("pw", "D4n1e7Y4s3m1nUnd7ey7a");
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
|
|
|
|
preferences.putBool("light", false);
|
|
|
|
|
|
|
|
preferences.putInt(led1cycle, 860);
|
|
|
|
|
|
|
|
preferences.putInt(led2cycle, 860);
|
|
|
|
|
|
|
|
preferences.putInt(fancycle, 510);
|
|
|
|
|
|
|
|
preferences.putBool("veggie", false);
|
|
|
|
|
|
|
|
preferences.putBool("flowering", false);
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -378,8 +400,9 @@ struct tm targettime = {0};
|
|
|
|
time_t realtime;
|
|
|
|
time_t realtime;
|
|
|
|
time_t target_sec;
|
|
|
|
time_t target_sec;
|
|
|
|
time_t endtime;
|
|
|
|
time_t endtime;
|
|
|
|
|
|
|
|
time_t diff_time;
|
|
|
|
|
|
|
|
int updateVeggieMode = 5000;
|
|
|
|
|
|
|
|
bool startup;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -388,15 +411,13 @@ void setup ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Serial.begin( 115200 ); /* Vorbereitung für mögliches serielles Debugging */
|
|
|
|
Serial.begin( 115200 ); /* Vorbereitung für mögliches serielles Debugging */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//INIT NEEDED PREFERENCES FILES
|
|
|
|
|
|
|
|
// initPreferences();
|
|
|
|
|
|
|
|
|
|
|
|
String LVGL_Arduino = "Hello Arduino! ";
|
|
|
|
String LVGL_Arduino = "Hello Arduino! ";
|
|
|
|
LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
|
|
|
|
LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println( LVGL_Arduino );
|
|
|
|
Serial.println( LVGL_Arduino );
|
|
|
|
Serial.println( "I am LVGL_Arduino" );
|
|
|
|
Serial.println( "I am LVGL_Arduino" );
|
|
|
|
|
|
|
|
|
|
|
|
lv_init();
|
|
|
|
lv_init();
|
|
|
|
|
|
|
|
|
|
|
|
#if LV_USE_LOG != 0
|
|
|
|
#if LV_USE_LOG != 0
|
|
|
|
@@ -411,16 +432,13 @@ void setup ()
|
|
|
|
tft.setTouch(calData);
|
|
|
|
tft.setTouch(calData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PWM-Kanal konfigurieren
|
|
|
|
// PWM-Kanal konfigurieren
|
|
|
|
ledcAttachChannel(fan_pwm_pin, pwm_freq, pwm_resolution, fan_pwm_channel);
|
|
|
|
ledcAttachChannel(fan_pwm_pin, pwm_freq, pwm_resolution, fan_pwm_channel);
|
|
|
|
ledcAttachChannel(led1_pwm_pin, pwm_freq, pwm_light_resolution, led1_pwm_channel);
|
|
|
|
ledcAttachChannel(led1_pwm_pin, pwm_freq, pwm_resolution, led1_pwm_channel);
|
|
|
|
ledcAttachChannel(led2_pwm_pin, pwm_freq, pwm_light_resolution, led2_pwm_channel);
|
|
|
|
ledcAttachChannel(led2_pwm_pin, pwm_freq, pwm_resolution, led2_pwm_channel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Standardmäßig den Lüfter auf 0% Duty Cycle setzen
|
|
|
|
|
|
|
|
ledcWrite(fan_pwm_pin, 76);
|
|
|
|
|
|
|
|
ledcWrite(led1_pwm_pin, 255);
|
|
|
|
|
|
|
|
ledcWrite(led2_pwm_pin, 255);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static lv_disp_t* disp;
|
|
|
|
static lv_disp_t* disp;
|
|
|
|
disp = lv_display_create( screenWidth, screenHeight );
|
|
|
|
disp = lv_display_create( screenWidth, screenHeight );
|
|
|
|
@@ -431,16 +449,10 @@ void setup ()
|
|
|
|
indev = lv_indev_create();
|
|
|
|
indev = lv_indev_create();
|
|
|
|
lv_indev_set_type( indev, LV_INDEV_TYPE_POINTER );
|
|
|
|
lv_indev_set_type( indev, LV_INDEV_TYPE_POINTER );
|
|
|
|
lv_indev_set_read_cb( indev, my_touchpad_read );
|
|
|
|
lv_indev_set_read_cb( indev, my_touchpad_read );
|
|
|
|
|
|
|
|
|
|
|
|
lv_tick_set_cb( my_tick_get_cb );
|
|
|
|
lv_tick_set_cb( my_tick_get_cb );
|
|
|
|
|
|
|
|
|
|
|
|
ui_init();
|
|
|
|
ui_init();
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println( "Setup abgeschlossen" );
|
|
|
|
Serial.println( "Setup abgeschlossen" );
|
|
|
|
|
|
|
|
|
|
|
|
// DHT11-Sensor initialisieren
|
|
|
|
|
|
|
|
// dht.begin();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Verknüpfung Funktionen UI
|
|
|
|
// Verknüpfung Funktionen UI
|
|
|
|
lv_obj_add_event_cb(ui_switchfanstatus, switchEventHandler, LV_EVENT_VALUE_CHANGED, fancycle); // Verknüpfen des Switches
|
|
|
|
lv_obj_add_event_cb(ui_switchfanstatus, switchEventHandler, LV_EVENT_VALUE_CHANGED, fancycle); // Verknüpfen des Switches
|
|
|
|
lv_obj_add_event_cb(ui_btnfanup, dimmUpBtnEventHandler, LV_EVENT_CLICKED, fancycle); // Up-Button
|
|
|
|
lv_obj_add_event_cb(ui_btnfanup, dimmUpBtnEventHandler, LV_EVENT_CLICKED, fancycle); // Up-Button
|
|
|
|
@@ -455,7 +467,6 @@ void setup ()
|
|
|
|
lv_obj_add_event_cb(ui_wifikeyboard, setWifi, LV_EVENT_READY, NULL);
|
|
|
|
lv_obj_add_event_cb(ui_wifikeyboard, setWifi, LV_EVENT_READY, NULL);
|
|
|
|
lv_obj_add_event_cb(ui_savemode, saveModeSettings, LV_EVENT_CLICKED, NULL);
|
|
|
|
lv_obj_add_event_cb(ui_savemode, saveModeSettings, LV_EVENT_CLICKED, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setze initial den Lüfter auf "Off" und den Schalter auf unchecked
|
|
|
|
// Setze initial den Lüfter auf "Off" und den Schalter auf unchecked
|
|
|
|
lv_label_set_text(ui_lblfanstatus, "OFF");
|
|
|
|
lv_label_set_text(ui_lblfanstatus, "OFF");
|
|
|
|
lv_label_set_text(ui_lblfanfanspeed, "0%");
|
|
|
|
lv_label_set_text(ui_lblfanfanspeed, "0%");
|
|
|
|
@@ -467,8 +478,12 @@ void setup ()
|
|
|
|
//Speichern der var von DutyCycle led1, led2, fan
|
|
|
|
//Speichern der var von DutyCycle led1, led2, fan
|
|
|
|
lv_dropdown_clear_options(ui_wifinetlist);
|
|
|
|
lv_dropdown_clear_options(ui_wifinetlist);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Standardmäßig den Lüfter auf 50% Duty Cycle setzen
|
|
|
|
|
|
|
|
lv_obj_add_state(ui_switchfanstatus, LV_STATE_CHECKED);
|
|
|
|
|
|
|
|
lv_obj_send_event(ui_switchfanstatus, LV_EVENT_VALUE_CHANGED, fancycle);
|
|
|
|
|
|
|
|
|
|
|
|
preferences.begin("wifi", false);
|
|
|
|
//Setup Wifi
|
|
|
|
|
|
|
|
preferences.begin("wifi", true);
|
|
|
|
String ssid = preferences.getString("ssid", "");
|
|
|
|
String ssid = preferences.getString("ssid", "");
|
|
|
|
String pw = preferences.getString("pw", "");
|
|
|
|
String pw = preferences.getString("pw", "");
|
|
|
|
int8_t counter = 0;
|
|
|
|
int8_t counter = 0;
|
|
|
|
@@ -493,149 +508,73 @@ void setup ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
preferences.end();
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
|
|
|
|
int target_h;
|
|
|
|
//Test GrowProgram
|
|
|
|
int target_m;
|
|
|
|
|
|
|
|
bool lights;
|
|
|
|
preferences.begin("g_phase", true);
|
|
|
|
preferences.begin("g_phase", false);
|
|
|
|
bool light_status = preferences.getBool("light_status", false);
|
|
|
|
|
|
|
|
int led1 = preferences.getInt(led1cycle, 860);
|
|
|
|
|
|
|
|
int led2 = preferences.getInt(led2cycle, 860);
|
|
|
|
|
|
|
|
|
|
|
|
bool veggie = preferences.getBool("veggie");
|
|
|
|
bool veggie = preferences.getBool("veggie");
|
|
|
|
bool flowering = preferences.getBool("flowering");
|
|
|
|
bool flowering = preferences.getBool("flowering");
|
|
|
|
bool veggie_lights_on = preferences.getBool("veggie_on");
|
|
|
|
|
|
|
|
bool veggie_lights_off = preferences.getBool("veggie_off");
|
|
|
|
|
|
|
|
bool flower_lights_on = preferences.getBool("flower_on");
|
|
|
|
|
|
|
|
bool flower_lights_off = preferences.getBool("flower_off");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (veggie)
|
|
|
|
if (veggie)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_dropdown_set_selected(ui_growmode, 1);
|
|
|
|
lv_dropdown_set_selected(ui_growmode, 1);
|
|
|
|
if (veggie_lights_off)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
target_h = preferences.getInt("veggie_start_h");
|
|
|
|
|
|
|
|
target_m = preferences.getInt("veggie_start_m");
|
|
|
|
|
|
|
|
lights = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
target_h = preferences.getInt("veggie_end_h");
|
|
|
|
|
|
|
|
target_m = preferences.getInt("veggie_end_m");
|
|
|
|
|
|
|
|
lights = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (flowering)
|
|
|
|
else if (flowering)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_dropdown_set_selected(ui_growmode, 2);
|
|
|
|
lv_dropdown_set_selected(ui_growmode, 2);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_dropdown_set_selected(ui_growmode, 0);
|
|
|
|
lv_dropdown_set_selected(ui_growmode, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int start_flower_h = preferences.getInt("flower_start_h");
|
|
|
|
|
|
|
|
int start_flower_m = preferences.getInt("flower_start_m");
|
|
|
|
|
|
|
|
int end_flower_h = preferences.getInt("flower_end_h");
|
|
|
|
|
|
|
|
int end_flower_m = preferences.getInt("flower_end_m");
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
Serial.println("VON SETUP");
|
|
|
|
|
|
|
|
Serial.print("MODUS VEGGIE: ");
|
|
|
|
|
|
|
|
Serial.println(veggie);
|
|
|
|
|
|
|
|
Serial.print("MODUS FLOWERING: ");
|
|
|
|
|
|
|
|
Serial.println(flowering);
|
|
|
|
|
|
|
|
Serial.print("LICHTSTATUS: ");
|
|
|
|
Serial.print("Starttime Flower: ");
|
|
|
|
Serial.println(light_status);
|
|
|
|
Serial.print(start_flower_h);
|
|
|
|
Serial.print("LED1: ");
|
|
|
|
Serial.print(":");
|
|
|
|
Serial.println(led1);
|
|
|
|
Serial.println(start_flower_m);
|
|
|
|
Serial.print("LED2: ");
|
|
|
|
Serial.print("Endtime: ");
|
|
|
|
Serial.println(led2);
|
|
|
|
Serial.print(end_flower_h);
|
|
|
|
|
|
|
|
Serial.print(":");
|
|
|
|
|
|
|
|
Serial.println(end_flower_m);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configTime(gmt_offset_sec, daylight_offset_sec, ntp);
|
|
|
|
configTime(gmt_offset_sec, daylight_offset_sec, ntp);
|
|
|
|
|
|
|
|
printTime();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!getLocalTime(&timeinfo))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("Failed to obtain time");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realtime = mktime(&timeinfo);
|
|
|
|
|
|
|
|
targettime = timeinfo;
|
|
|
|
targettime = timeinfo;
|
|
|
|
targettime.tm_hour = target_h;
|
|
|
|
|
|
|
|
targettime.tm_min = target_m;
|
|
|
|
|
|
|
|
targettime.tm_sec = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
target_sec = mktime(&targettime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (realtime >= target_sec)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println(&timeinfo, "Testtime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println(&targettime, "Testtime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startup = true;
|
|
|
|
lv_obj_add_event_cb(ui_growmode, setMode, LV_EVENT_VALUE_CHANGED, NULL);
|
|
|
|
lv_obj_add_event_cb(ui_growmode, setMode, LV_EVENT_VALUE_CHANGED, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
WiFi.disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop ()
|
|
|
|
void loop ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lv_timer_handler(); /* Lässt die GUI ihre Arbeit verrichten */
|
|
|
|
lv_timer_handler(); /* Lässt die GUI ihre Arbeit verrichten */
|
|
|
|
|
|
|
|
static unsigned int lastUpdate = 0;
|
|
|
|
|
|
|
|
static unsigned int lastUpdate2 = 0;
|
|
|
|
|
|
|
|
const unsigned int updateInterval = 1000; //60 sekunden
|
|
|
|
static unsigned long lastUpdate = 0;
|
|
|
|
|
|
|
|
const unsigned long updateInterval = 60000; //60 sekunden
|
|
|
|
|
|
|
|
static unsigned long lastUpdate2 = 0;
|
|
|
|
|
|
|
|
const unsigned long updateInterval2 = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned long currentMillis = millis();
|
|
|
|
unsigned long currentMillis = millis();
|
|
|
|
|
|
|
|
|
|
|
|
if (currentMillis - lastUpdate2 >= updateInterval2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printTime();
|
|
|
|
|
|
|
|
realtime = mktime(&timeinfo);
|
|
|
|
|
|
|
|
//onTime();
|
|
|
|
|
|
|
|
lastUpdate2 = currentMillis;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentMillis - lastUpdate >= updateInterval)
|
|
|
|
if (currentMillis - lastUpdate >= updateInterval)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// if (realtime >= testtime2)
|
|
|
|
printTime();
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
lastUpdate = currentMillis;
|
|
|
|
lastUpdate = currentMillis;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentMillis - lastUpdate2 >= updateVeggieMode)
|
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Serial.print("UPDATE LOOP: ");
|
|
|
|
|
|
|
|
Serial.println(updateVeggieMode);
|
|
|
|
void onTime()
|
|
|
|
growMode();
|
|
|
|
{
|
|
|
|
lastUpdate2 = currentMillis;
|
|
|
|
// testtime.tm_min += 5;
|
|
|
|
}
|
|
|
|
// int seconds = 60 * 5;
|
|
|
|
|
|
|
|
// testtime2 = mktime(&testtime);
|
|
|
|
|
|
|
|
// testtime2 += seconds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// struct tm * test = gmtime(&testtime2);
|
|
|
|
|
|
|
|
// Serial.println(test, "Test: ,%A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void saveModeSettings(lv_event_t * e)
|
|
|
|
void saveModeSettings(lv_event_t * e)
|
|
|
|
@@ -648,8 +587,8 @@ void saveModeSettings(lv_event_t * e)
|
|
|
|
|
|
|
|
|
|
|
|
lv_dropdown_get_selected_str(ui_setmode, mode, sizeof(mode));
|
|
|
|
lv_dropdown_get_selected_str(ui_setmode, mode, sizeof(mode));
|
|
|
|
lv_roller_get_selected_str(ui_starthour, start_h, sizeof(start_h));
|
|
|
|
lv_roller_get_selected_str(ui_starthour, start_h, sizeof(start_h));
|
|
|
|
lv_roller_get_selected_str(ui_startmin, start_m, sizeof(start_h));
|
|
|
|
|
|
|
|
lv_roller_get_selected_str(ui_endhour, end_h, sizeof(end_h));
|
|
|
|
lv_roller_get_selected_str(ui_endhour, end_h, sizeof(end_h));
|
|
|
|
|
|
|
|
lv_roller_get_selected_str(ui_startmin, start_m, sizeof(start_h));
|
|
|
|
lv_roller_get_selected_str(ui_endmin, end_m, sizeof(end_h));
|
|
|
|
lv_roller_get_selected_str(ui_endmin, end_m, sizeof(end_h));
|
|
|
|
|
|
|
|
|
|
|
|
int start_hour = atoi(start_h);
|
|
|
|
int start_hour = atoi(start_h);
|
|
|
|
@@ -689,31 +628,216 @@ void setMode(lv_event_t * e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
preferences.putBool("veggie", true);
|
|
|
|
preferences.putBool("veggie", true);
|
|
|
|
preferences.putBool("flowering", false);
|
|
|
|
preferences.putBool("flowering", false);
|
|
|
|
|
|
|
|
targettime = timeinfo;
|
|
|
|
|
|
|
|
growMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
preferences.putBool("veggie", false);
|
|
|
|
preferences.putBool("veggie", false);
|
|
|
|
preferences.putBool("flowering", true);
|
|
|
|
preferences.putBool("flowering", true);
|
|
|
|
|
|
|
|
targettime = timeinfo;
|
|
|
|
|
|
|
|
growMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
preferences.end();
|
|
|
|
preferences.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void modeOn()
|
|
|
|
|
|
|
|
|
|
|
|
void veggie()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
lv_obj_add_state(ui_light1switch, LV_STATE_CHECKED);
|
|
|
|
|
|
|
|
lv_obj_add_state(ui_light2switch, LV_STATE_CHECKED);
|
|
|
|
|
|
|
|
lv_obj_send_event(ui_light1switch, LV_EVENT_VALUE_CHANGED, led1cycle);
|
|
|
|
|
|
|
|
lv_obj_send_event(ui_light2switch, LV_EVENT_VALUE_CHANGED, led2cycle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void modeOff()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lv_obj_remove_state(ui_light1switch, LV_STATE_CHECKED);
|
|
|
|
|
|
|
|
lv_obj_remove_state(ui_light2switch, LV_STATE_CHECKED);
|
|
|
|
|
|
|
|
lv_obj_send_event(ui_light1switch, LV_EVENT_VALUE_CHANGED, led1cycle);
|
|
|
|
|
|
|
|
lv_obj_send_event(ui_light2switch, LV_EVENT_VALUE_CHANGED, led2cycle);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void growMode()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("GROWMODE");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preferences.begin("g_phase", true);
|
|
|
|
|
|
|
|
bool lights = preferences.getBool("light");
|
|
|
|
|
|
|
|
bool veggie_state = preferences.getBool("veggie");
|
|
|
|
|
|
|
|
bool flower_state = preferences.getBool("flowering");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("Veggie: ");
|
|
|
|
|
|
|
|
Serial.println(veggie_state);
|
|
|
|
|
|
|
|
Serial.print("Flowering: ");
|
|
|
|
|
|
|
|
Serial.println(flower_state);
|
|
|
|
|
|
|
|
Serial.print("Status Licht:");
|
|
|
|
|
|
|
|
Serial.println(lights);
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
if (veggie_state || flower_state)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
preferences.begin("g_phase", true);
|
|
|
|
|
|
|
|
Serial.println("IF VEGGIE OR FLOWER ACTIVE");
|
|
|
|
|
|
|
|
int start_h;
|
|
|
|
|
|
|
|
int start_m;
|
|
|
|
|
|
|
|
int end_h;
|
|
|
|
|
|
|
|
int end_m;
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
if (veggie_state)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("IF VEGGIE");
|
|
|
|
|
|
|
|
start_h = preferences.getInt("veggie_start_h");
|
|
|
|
|
|
|
|
start_m = preferences.getInt("veggie_start_m");
|
|
|
|
|
|
|
|
end_h = preferences.getInt("veggie_end_h");
|
|
|
|
|
|
|
|
end_m = preferences.getInt("veggie_end_m");
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("IF FLOWER");
|
|
|
|
|
|
|
|
start_h = preferences.getInt("flower_start_h");
|
|
|
|
|
|
|
|
start_m = preferences.getInt("flower_start_m");
|
|
|
|
|
|
|
|
end_h = preferences.getInt("flower_end_h");
|
|
|
|
|
|
|
|
end_m = preferences.getInt("flower_end_m");
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time_t diff_start = getDiffTime(start_h, start_m);
|
|
|
|
|
|
|
|
time_t diff_end = getDiffTime(end_h, end_m);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (diff_start < 0 && diff_end < 0 && diff_start < diff_end)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("IF DIFFS KLEINER THEN 0");
|
|
|
|
|
|
|
|
Serial.println("DIFFSTART IST KLEINER");
|
|
|
|
|
|
|
|
modeOff();
|
|
|
|
|
|
|
|
targettime.tm_mday += 1;
|
|
|
|
|
|
|
|
diff_start = getDiffTime(start_h, start_m);
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_start * 1000) + 1000;
|
|
|
|
|
|
|
|
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
Serial.println(diff_start);
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (diff_start < 0 && diff_end < 0 && diff_start > diff_end)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("IF DIFFS KLEINER THEN 0");
|
|
|
|
|
|
|
|
Serial.println("DIFFSTART IST GRÖßER");
|
|
|
|
|
|
|
|
modeOn();
|
|
|
|
|
|
|
|
targettime.tm_mday += 1;
|
|
|
|
|
|
|
|
diff_end = getDiffTime(end_h, end_m);
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_end *1000) + 1000;
|
|
|
|
|
|
|
|
Serial.println(diff_end);
|
|
|
|
|
|
|
|
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (diff_start > 0 && diff_end > 0 && diff_start > diff_end)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("IF DIFFS GRÖßER THEN 0");
|
|
|
|
|
|
|
|
Serial.println("DIFFSTART IST GRÖßER");
|
|
|
|
|
|
|
|
Serial.print("DIFF START: ");
|
|
|
|
|
|
|
|
Serial.println(diff_start);
|
|
|
|
|
|
|
|
Serial.print("DIFF END: ");
|
|
|
|
|
|
|
|
Serial.println(diff_end);
|
|
|
|
|
|
|
|
modeOn();
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_end* 1000) + 1000;
|
|
|
|
|
|
|
|
Serial.println(updateVeggieMode);
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (diff_start > 0 && diff_end > 0 && diff_start < diff_end)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("IF DIFFS GRÖßER THEN 0");
|
|
|
|
|
|
|
|
Serial.println("DIFFSTART IST KLEINER");
|
|
|
|
|
|
|
|
Serial.print("DIFF START: ");
|
|
|
|
|
|
|
|
Serial.println(diff_start);
|
|
|
|
|
|
|
|
Serial.print("DIFF END: ");
|
|
|
|
|
|
|
|
Serial.println(diff_end);
|
|
|
|
|
|
|
|
modeOff();
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_start* 1000) + 1000;
|
|
|
|
|
|
|
|
Serial.println(updateVeggieMode);
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (lights)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("LIGHTS ARE ON");
|
|
|
|
|
|
|
|
diff_time = getDiffTime(end_h, end_m);
|
|
|
|
|
|
|
|
Serial.println(diff_time);
|
|
|
|
|
|
|
|
Serial.println(&timeinfo, "Testtime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
Serial.println(&targettime, "Testtime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (diff_time < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
modeOff();
|
|
|
|
|
|
|
|
diff_time = getDiffTime(start_h, start_m);
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_time * 1000) + 1000;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_time * 1000) + 1000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modeOn();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("UPDATE LIGHTS ON: ");
|
|
|
|
|
|
|
|
Serial.print(updateVeggieMode);
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println("LIGHTS OFF: ");
|
|
|
|
|
|
|
|
diff_time = getDiffTime(start_h, start_m);
|
|
|
|
|
|
|
|
Serial.println(diff_time);
|
|
|
|
|
|
|
|
Serial.println(&timeinfo, "Testtime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
Serial.println(&targettime, "Testtime: %A, %B %d %Y %H:%M:%S");
|
|
|
|
|
|
|
|
if (diff_time < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
modeOn();
|
|
|
|
|
|
|
|
diff_time = getDiffTime(end_h, end_m);
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_time * 1000) + 1000;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modeOff();
|
|
|
|
|
|
|
|
updateVeggieMode = (diff_time * 1000) + 1000;
|
|
|
|
|
|
|
|
Serial.print("UPDATE LIGHTS OFF: ");
|
|
|
|
|
|
|
|
Serial.print(updateVeggieMode);
|
|
|
|
|
|
|
|
Serial.println("###################");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
preferences.end();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void flowering()
|
|
|
|
time_t getDiffTime(int time_h, int time_m)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
targettime.tm_hour = time_h;
|
|
|
|
|
|
|
|
targettime.tm_min = time_m;
|
|
|
|
|
|
|
|
targettime.tm_sec = 0;
|
|
|
|
|
|
|
|
target_sec = mktime(&targettime);
|
|
|
|
|
|
|
|
realtime = mktime(&timeinfo);
|
|
|
|
|
|
|
|
diff_time = difftime(target_sec, realtime);
|
|
|
|
|
|
|
|
return diff_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void printTime()
|
|
|
|
void printTime()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct tm timeinfo;
|
|
|
|
|
|
|
|
if(!getLocalTime(&timeinfo))
|
|
|
|
if(!getLocalTime(&timeinfo))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Serial.println("Failed to obtain time");
|
|
|
|
Serial.println("Failed to obtain time");
|
|
|
|
|