LED3 still missing SUNSIM still missing
This commit is contained in:
299
ui/ui.ino
299
ui/ui.ino
@@ -43,14 +43,20 @@ int led1_pwm_pin = 26;
|
||||
int led2_pwm_channel = 2;
|
||||
int led2_pwm_pin = 27;
|
||||
|
||||
//Variabke PWM LED2
|
||||
int led3_pwm_channel = 2;
|
||||
int led3_pwm_pin = 13;
|
||||
|
||||
char led1cycle[5] = "led1";
|
||||
char led2cycle[5] = "led2";
|
||||
char led3cycle[5] = "led3";
|
||||
char fancycle[4] = "fan";
|
||||
|
||||
//Variable zum Speichern des Status des Schalters
|
||||
bool fan_active = false;
|
||||
bool led1active = false;
|
||||
bool led2active = false;
|
||||
bool led3active = false;
|
||||
|
||||
/* Ändern Sie dies auf die Auflösung Ihres Bildschirms */
|
||||
static const uint16_t screenWidth = 320;
|
||||
@@ -115,10 +121,11 @@ void switchEventHandler(lv_event_t * e)
|
||||
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
||||
char * user_data = (char*)lv_event_get_user_data(e);
|
||||
|
||||
int light_off_duty_cycle = 1024;
|
||||
int light_off_duty_cycle = 1023;
|
||||
int fan_duty_cycle;
|
||||
int led1_duty_cycle;
|
||||
int led2_duty_cycle;
|
||||
int led3_duty_cycle;
|
||||
bool veggie = preferences.getBool("veggie");
|
||||
bool flower = preferences.getBool("flowering");
|
||||
|
||||
@@ -156,6 +163,22 @@ void switchEventHandler(lv_event_t * e)
|
||||
turnOff(led2_pwm_pin, light_off_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent);
|
||||
}
|
||||
}
|
||||
if(obj == ui_light2switch)
|
||||
{
|
||||
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
||||
{
|
||||
preferences.begin("g_phase", true);
|
||||
led3_duty_cycle = preferences.getInt(user_data, 860);
|
||||
preferences.end();
|
||||
led3active = true;
|
||||
turnOn(led3_pwm_pin, led2_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent);
|
||||
}
|
||||
else
|
||||
{
|
||||
led2active = false;
|
||||
turnOff(led2_pwm_pin, light_off_duty_cycle, ui_light2statuslbl, ui_lbllightstatus, ui_light2percent);
|
||||
}
|
||||
}
|
||||
if(obj == ui_switchfanstatus)
|
||||
{
|
||||
if (lv_obj_has_state(obj, LV_STATE_CHECKED))
|
||||
@@ -314,7 +337,7 @@ static void dimmDownBtnEventHandler(lv_event_t * e)
|
||||
{
|
||||
preferences.begin("g_phase", false);
|
||||
led2_duty_cycle += preferences.getInt(user_data);
|
||||
if (led2_duty_cycle >= 860) led2_duty_cycle = 860;
|
||||
if (led2_duty_cycle >= 920) led2_duty_cycle = 860;
|
||||
preferences.putInt(user_data, led2_duty_cycle);
|
||||
preferences.end();
|
||||
dimm(led2_pwm_pin, led2_duty_cycle, ui_light2percent);
|
||||
@@ -586,16 +609,18 @@ void setup ()
|
||||
|
||||
WiFi.disconnect();
|
||||
|
||||
// bool status;
|
||||
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);
|
||||
// }
|
||||
// default settings
|
||||
// (you can also pass in a Wire library object like &Wire2)
|
||||
status = bme.begin(0x76);
|
||||
if (!status)
|
||||
{
|
||||
lv_label_set_text(ui_lblhum, "NA");
|
||||
lv_label_set_text(ui_fanhum, "NA");
|
||||
lv_label_set_text(ui_lbltemp, "NA");
|
||||
lv_label_set_text(ui_fantemp, "NA");
|
||||
}
|
||||
}
|
||||
void loopC2(void* pvParameters)
|
||||
{
|
||||
@@ -630,7 +655,7 @@ void loop ()
|
||||
if (currentMillis - lastUpdate >= updateInterval)
|
||||
{
|
||||
printTime();
|
||||
// printValues();
|
||||
printValues();
|
||||
lastUpdate = currentMillis;
|
||||
}
|
||||
|
||||
@@ -670,7 +695,6 @@ void saveModeSettings(lv_event_t * e)
|
||||
{
|
||||
preferences.putInt("veggie_start_h", start_hour);
|
||||
preferences.putInt("veggie_start_m", start_min);
|
||||
preferences.putInt("veggie_end_h", end_hour);
|
||||
preferences.putInt("veggie_end_m", end_min);
|
||||
if (lv_obj_has_state(ui_sunsetcheck, LV_STATE_CHECKED))
|
||||
{
|
||||
@@ -809,7 +833,7 @@ void setGrowModeLbl(lv_event_t * e)
|
||||
start_h = "flower_start_h";
|
||||
start_m = "flower_start_m";
|
||||
end_h = "flower_end_h";
|
||||
end_m = "flower_end_h";
|
||||
end_m = "flower_end_m";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -817,7 +841,7 @@ void setGrowModeLbl(lv_event_t * e)
|
||||
start_h = "veggie_start_h";
|
||||
start_m = "veggie_start_m";
|
||||
end_h = "veggie_end_h";
|
||||
end_m = "veggie_end_h";
|
||||
end_m = "veggie_end_m";
|
||||
}
|
||||
|
||||
int s_hour = preferences.getInt(start_h);
|
||||
@@ -884,101 +908,128 @@ void growMode()
|
||||
end_h = preferences.getInt("flower_end_h");
|
||||
end_m = preferences.getInt("flower_end_m");
|
||||
sim_sun = preferences.getBool("fl_sun");
|
||||
Serial.println("###################");
|
||||
}
|
||||
preferences.end();
|
||||
|
||||
time_t diff_start = getDiffTime(start_h, start_m);
|
||||
time_t diff_end = getDiffTime(end_h, end_m);
|
||||
…
|
||||
Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S");
|
||||
|
||||
if (diff_start < 0 && diff_end > 0)
|
||||
|
||||
|
||||
if (!lights)
|
||||
{
|
||||
Serial.println("Diffstart < 0 && Diffstart > Diffend");
|
||||
if(sim_sun)
|
||||
{
|
||||
Serial.println("LIGHTS ARE OFF");
|
||||
Serial.println("SIMSUN TRUE");
|
||||
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;
|
||||
sunrise = true;
|
||||
updateSimMode = (5 * 60 * 1000) / (sim_duty_cycle - led1_pref);
|
||||
Serial.println(updateSimMode);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
modeOn();
|
||||
if (diff_start > diff_end)
|
||||
{
|
||||
targettime.tm_mday += 1;
|
||||
}
|
||||
|
||||
diff_time = getDiffTime(end_h, end_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
Serial.println(updateVeggieMode);
|
||||
Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println("###################");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Serial.println("TRUE");
|
||||
if(sim_sun)
|
||||
{
|
||||
Serial.println("SIMSUN TRUE");
|
||||
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;
|
||||
sunrise = true;
|
||||
updateSimMode = (5 * 60 * 1000) / (sim_duty_cycle - led1_pref);
|
||||
Serial.println(updateSimMode);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
modeOn();
|
||||
// targettime.tm_mday += 1;
|
||||
diff_time = getDiffTime(end_h, end_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Serial.println("FALSE");
|
||||
diff_time = getDiffTime(start_h, start_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
|
||||
modeOff();
|
||||
else if (diff_start < 0 && diff_start < diff_end)
|
||||
{
|
||||
Serial.println("Diffstart < 0 && Diffstart < Diffend");
|
||||
targettime.tm_mday += 1;
|
||||
diff_time = getDiffTime(start_h, start_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
|
||||
modeOff();
|
||||
|
||||
Serial.print("UPDATE LIGHTS ON: ");
|
||||
Serial.print(updateVeggieMode);
|
||||
Serial.println("###################");
|
||||
Serial.print("UPDATE LIGHTS ON: ");
|
||||
Serial.println(updateVeggieMode);
|
||||
Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println("###################");
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else if (diff_start < 0 && diff_start > diff_end)
|
||||
{
|
||||
Serial.println("Diffstart < 0 && Diffstart > Diffend");
|
||||
targettime.tm_mday += 1;
|
||||
diff_time = getDiffTime(end_h, end_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
|
||||
modeOn();
|
||||
|
||||
Serial.print("UPDATE LIGHTS ON: ");
|
||||
Serial.println(updateVeggieMode);
|
||||
Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println("###################");
|
||||
|
||||
|
||||
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");
|
||||
if (diff_time < 0)
|
||||
{
|
||||
if(sim_sun)
|
||||
{
|
||||
diff_time = getDiffTime(start_h, start_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
sim_duty_cycle = 860;
|
||||
sunset = true;
|
||||
updateSimMode = (60 * 60 * 1000) / (sim_duty_cycle - led1_pref);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
modeOff();
|
||||
diff_time = getDiffTime(end_h, end_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
modeOn();
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
Serial.print("UPDATE LIGHTS OFF: ");
|
||||
Serial.print(updateVeggieMode);
|
||||
Serial.println("###################");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (diff_start > 0 && diff_end < 0)
|
||||
{
|
||||
Serial.println("Diffstart > 0 && Diffstart < Diffend");
|
||||
|
||||
diff_time = getDiffTime(start_h, start_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
|
||||
modeOff();
|
||||
|
||||
Serial.print("UPDATE LIGHTS ON: ");
|
||||
Serial.println(updateVeggieMode);
|
||||
Serial.println(&timeinfo, "Realtime: %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_start > diff_end)
|
||||
{
|
||||
Serial.println("Diffstart > 0 && Diffstart > Diffend");
|
||||
|
||||
diff_time = getDiffTime(end_h, end_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
|
||||
modeOn();
|
||||
|
||||
Serial.print("UPDATE LIGHTS ON: ");
|
||||
Serial.println(updateVeggieMode);
|
||||
Serial.println(&timeinfo, "Realtime: %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_start < diff_end)
|
||||
{
|
||||
Serial.println("Diffstart > 0 && Diffstart < Diffend");
|
||||
|
||||
diff_time = getDiffTime(start_h, start_m);
|
||||
updateVeggieMode = (diff_time * 1000) + 1000;
|
||||
|
||||
modeOff();
|
||||
|
||||
Serial.print("UPDATE LIGHTS ON: ");
|
||||
Serial.println(updateVeggieMode);
|
||||
Serial.println(&timeinfo, "Realtime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println(&targettime, "Targettime: %A, %B %d %Y %H:%M:%S");
|
||||
Serial.println("###################");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
preferences.end();
|
||||
@@ -1010,36 +1061,14 @@ 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(" %");
|
||||
|
||||
// Serial.println();
|
||||
// }
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user