This commit is contained in:
2025-02-28 14:30:08 +01:00
parent ea0f514c2b
commit ae617cade4
38 changed files with 4040 additions and 96 deletions

152
ui/ui.ino
View File

@@ -7,6 +7,10 @@
#include <WiFi.h>
#include <ESP32Time.h>
#include "time.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
TaskHandle_t Task1;
Preferences preferences;
@@ -14,6 +18,10 @@ Preferences preferences;
// #define DHTTYPE DHT11 // DHT 11
// DHT dht(DHTPIN, DHTTYPE);
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
const char* ntp = "fritz.box";
const int gmt_offset_sec = 3600;
const int daylight_offset_sec = 7200;
@@ -153,7 +161,7 @@ void switchEventHandler(lv_event_t * e)
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
{
preferences.begin("g_phase", true);
fan_duty_cycle = preferences.getInt(user_data, 310);
fan_duty_cycle = preferences.getInt(user_data, 0);
preferences.end();
fan_active = true;
@@ -270,7 +278,7 @@ static void dimmUpBtnEventHandler(lv_event_t * e)
if (fan_active)
{
preferences.begin("g_phase", false);
fan_duty_cycle += preferences.getInt(user_data, 76);
fan_duty_cycle += preferences.getInt(user_data, 0);
if (fan_duty_cycle >= 1024) fan_duty_cycle = 1024;
preferences.putInt(user_data, fan_duty_cycle);
preferences.end();
@@ -318,7 +326,7 @@ static void dimmDownBtnEventHandler(lv_event_t * e)
{
preferences.begin("g_phase", false);
fan_duty_cycle += preferences.getInt(user_data);
if (fan_duty_cycle <= 310) fan_duty_cycle = 310;
if (fan_duty_cycle <= 0) fan_duty_cycle = 0;
preferences.putInt(user_data, fan_duty_cycle);
preferences.end();
dimm(fan_pwm_pin, fan_duty_cycle, ui_lblfanspeed, ui_lblfanfanspeed);
@@ -577,6 +585,17 @@ void setup ()
0);
WiFi.disconnect();
// bool status;
// // default settings
// // (you can also pass in a Wire library object like &Wire2)
// status = bme.begin(0x76);
// if (!status)
// {
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
// while (1);
// }
}
void loopC2(void* pvParameters)
{
@@ -611,6 +630,7 @@ void loop ()
if (currentMillis - lastUpdate >= updateInterval)
{
printTime();
// printValues();
lastUpdate = currentMillis;
}
@@ -880,8 +900,8 @@ void growMode()
Serial.println(&timeinfo, "Testtime: %A, %B %d %Y %H:%M:%S");
Serial.println(&targettime, "Testtime: %A, %B %d %Y %H:%M:%S");
// if (diff_start < 0 && diff_start > diff_end)
if (diff_start < 0)
if (diff_start < 0 && diff_start > diff_end)
// if (diff_start < 0)
{
Serial.println("TRUE");
if(sim_sun)
@@ -900,7 +920,7 @@ void growMode()
else
{
modeOn();
targettime.tm_mday += 1;
// targettime.tm_mday += 1;
diff_time = getDiffTime(end_h, end_m);
updateVeggieMode = (diff_time * 1000) + 1000;
}
@@ -922,7 +942,10 @@ void growMode()
}
}
else
{
{
Serial.println("LIGHTS ARE ON: ");
Serial.println(&timeinfo, "Testtime: %A, %B %d %Y %H:%M:%S");
Serial.println(&targettime, "Testtime: %A, %B %d %Y %H:%M:%S");
@@ -987,93 +1010,36 @@ void printTime()
// void printValues() {
// char hum[20];
// char temp[20];
// sprintf(hum, "%.0f%%",bme.readHumidity());
// sprintf(temp, "%.0f%%",bme.readTemperature());
// lv_label_set_text(ui_lblhum, hum);
// lv_label_set_text(ui_fanhum, hum);
// lv_label_set_text(ui_lbltemp, temp);
// lv_label_set_text(ui_fantemp, temp);
// Serial.print("Temperature = ");
// Serial.print();
// Serial.println(" *C");
// Convert temperature to Fahrenheit
/*Serial.print("Temperature = ");
Serial.print(1.8 * bme.readTemperature() + 32);
Serial.println(" *F");*/
// Serial.print("Pressure = ");
// Serial.print(bme.readPressure() / 100.0F);
// Serial.println(" hPa");
// Serial.print("Approx. Altitude = ");
// Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
// Serial.println(" m");
// Serial.print("Humidity = ");
// Serial.print(bme.readHumidity());
// Serial.println(" %");
// 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");
// if(sim_sun)
// {
// diff_time = getDiffTime(end_h, end_m);
// updateVeggieMode = (diff_time * 1000) + 1000;
// lv_obj_add_state(ui_light1switch, LV_STATE_CHECKED);
// lv_obj_add_state(ui_light2switch, LV_STATE_CHECKED);
// sim_duty_cycle = 860;
// turnOn(led1_pwm_pin, sim_duty_cycle, ui_light1statuslbl, ui_lbllightstatus, ui_light1percent);
// turnOn(led2_pwm_pin, sim_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent);
// sunrise = true;
// updateSimMode = (60 * 60 * 1000) / (sim_duty_cycle - led1);
// }
// else
// {
// 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
// {
// }
// Serial.println();
// }