Update display

This commit is contained in:
Tomislav Kopić 2024-11-12 16:10:34 +01:00
parent ccd03735ea
commit 24794eb5b3

View File

@ -63,7 +63,7 @@ void initSystems() {
unsigned long lastWeatherUpdate = 0; unsigned long lastWeatherUpdate = 0;
unsigned long lastDisplayOverride = 0; unsigned long lastDisplayOverride = 0;
const unsigned long weatherUpdateInterval = 2700000; // 45 minutes in milliseconds const unsigned long weatherUpdateInterval = 2700000; // 45 minutes in milliseconds
const unsigned long displayOverrideTimeout = 1200000; // 2 minutes in milliseconds const unsigned long displayOverrideTimeout = 120000; // 2 minutes in milliseconds
bool is_display_off = false; bool is_display_off = false;
bool display_override = false; bool display_override = false;
@ -249,108 +249,142 @@ bool fetchWeatherData() {
humidity = doc["main"]["humidity"]; humidity = doc["main"]["humidity"];
pressure = doc["main"]["pressure"].as<float>() / 1000; pressure = doc["main"]["pressure"].as<float>() / 1000;
wind_speed = doc["wind"]["speed"].as<float>(); wind_speed = doc["wind"]["speed"].as<float>();
// Define 10 messages for each weather condition if (mainWeather == "Clear") {
if (mainWeather == "Clear") { String clearMessages[] = {
String clearMessages[] = { "All systems nominal. Atmospheric clearance detected.",
"All systems nominal. Atmospheric clearance detected.", "Clear skies confirmed. Solar energy levels stable for ship systems.",
"Clear skies confirmed. Solar energy levels stable for ship systems.", "Sky conditions optimal for external scan. Proceed with visual sweep.",
"Sky conditions optimal for external scan. Proceed with visual sweep.", "Visibility restored. All monitoring systems active and secure.",
"Visibility restored. All monitoring systems active and secure.", "Open space ahead. Prepare for normal operations.",
"Open space ahead. Prepare for normal operations.", "Solar reflection steady. Systems running at full capacity.",
"Solar reflection steady. Systems running at full capacity.", "Clear. No interference detected. Navigation optimal.",
"Clear. No interference detected. Navigation optimal.", "Visible space clear. Proceed with standard operations.",
"Visible space clear. Proceed with standard operations.", "Skies unclouded. No anomalies detected.",
"Skies unclouded. No anomalies detected.", "No obstructions in sight. Navigation systems operating normally.",
"No obstructions in sight. Navigation systems operating normally." "Bright and clear skies. Optimal conditions for long-range communication.",
}; "Perfect visibility. All systems functioning within expected parameters.",
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(clearMessages, 10); "Clear and stable. No impact on external activities.",
} else if (mainWeather == "Clouds") { "The sky is free of disturbances. Proceed with confidence.",
String cloudMessages[] = { "Atmospheric conditions steady. All sensors reporting normal."
"Cloud cover detected. Light interference on visual systems.", };
"Overcast conditions observed.", weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(clearMessages, 15);
"Shadows overhead. Adjusting sensitivity on light filters.", } else if (mainWeather == "Clouds") {
"Moderate cloud formation detected. System performance normal.", String cloudMessages[] = {
"Atmospheric interference present. Monitoring light levels.", "Cloud cover detected. Light interference on visual systems.",
"Cloud coverage rising. Operational impact minimal.", "Overcast conditions observed.",
"Low-visibility overhead. Preparing for reduced solar input.", "Shadows overhead. Adjusting sensitivity on light filters.",
"Sensors report cloud patterns. Adjusting visibility protocols.", "Moderate cloud formation detected. System performance normal.",
"Clouds forming in surrounding space. Adjusting navigational parameters.", "Atmospheric interference present. Monitoring light levels.",
"Light cloud cover detected. No operational impact expected." "Cloud coverage rising. Operational impact minimal.",
}; "Low-visibility overhead. Preparing for reduced solar input.",
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(cloudMessages, 10); "Sensors report cloud patterns. Adjusting visibility protocols.",
} else if (mainWeather == "Rain") { "Clouds forming in surrounding space. Adjusting navigational parameters.",
String rainMessages[] = { "Light cloud cover detected. No operational impact expected.",
"Precipitation incoming. Shielding activated.", "Cloud formation increasing. Visual scan in progress.",
"Rain detected. External moisture levels rising, activating water barriers.", "Partly cloudy. Visibility reduced, but no immediate danger.",
"Surface moisture increasing. Prepare for external wet conditions.", "Overcast sky. Sensors adjusting for changing light levels.",
"Rainstorm detected. External protection systems online.", "Increasing cloud density. Proceeding with caution on exterior tasks.",
"Raindrops detected. Surface conditions becoming slick.", "Cumulus clouds observed. No operational impact anticipated."
"Incoming water influx. Prepare external surfaces for wet conditions.", };
"Rain detected. Traction systems engaged for slippery terrain.", weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(cloudMessages, 15);
"Wet conditions approaching. Hydration protocols for external units activated.", } else if (mainWeather == "Rain") {
"Raindrops increasing. Proceed with caution on exterior surfaces.", String rainMessages[] = {
"Heavy rain in the vicinity. External equipment may require adjustment." "Precipitation incoming. Shielding activated.",
}; "Rain detected. External moisture levels rising, activating water barriers.",
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(rainMessages, 10); "Surface moisture increasing. Prepare for external wet conditions.",
} else if (mainWeather == "Drizzle") { "Rainstorm detected. External protection systems online.",
String drizzleMessages[] = { "Raindrops detected. Surface conditions becoming slick.",
"Light drizzle detected. Surface moisture rising, minimal impact.", "Incoming water influx. Prepare external surfaces for wet conditions.",
"Low-intensity rain detected. External systems functioning normally.", "Rain detected. Traction systems engaged for slippery terrain.",
"Fine mist detected. Prepare for minor surface wetting.", "Wet conditions approaching. Hydration protocols for external units activated.",
"Gentle drizzle. Light hydration of external units detected.", "Raindrops increasing. Proceed with caution on exterior surfaces.",
"Atmospheric moisture levels rising slowly. Proceed with minor caution.", "Heavy rain in the vicinity. External equipment may require adjustment.",
"Minor drizzle detected. No immediate impact on operations.", "Intense rain incoming. All systems on standby for moisture management.",
"Drizzle detected. Adjusting exterior temperature controls.", "Heavy precipitation. Surface traction adjustments being made.",
"Light rain confirmed. Surface conditions remain stable.", "Rainfall intensifying. Navigation systems recalibrating.",
"Drizzle present. External activity unaffected.", "Storm-like rain detected. Prepare for potential delays in operations.",
"Micro-droplets detected. Surface wetting minimal." "Rain approaching. All moisture-sensitive systems under review."
}; };
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(drizzleMessages, 10); weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(rainMessages, 15);
} else if (mainWeather == "Thunderstorm") { } else if (mainWeather == "Drizzle") {
String thunderstormMessages[] = { String drizzleMessages[] = {
"Warning: Severe storm approaching. High-voltage hazard detected.", "Light drizzle detected. Surface moisture rising, minimal impact.",
"Electrical storm detected in proximity. Shielding and surge protection engaged.", "Low-intensity rain detected. External systems functioning normally.",
"Thunderstorm alert: Prepare for sudden power fluctuations.", "Fine mist detected. Prepare for minor surface wetting.",
"Storm in progress. Lightning detected. Surge protection active.", "Gentle drizzle. Light hydration of external units detected.",
"Electrical interference detected. Recalibrating external sensors.", "Atmospheric moisture levels rising slowly. Proceed with minor caution.",
"Thunderstorm imminent. High-energy levels detected. Activating surge protocols.", "Minor drizzle detected. No immediate impact on operations.",
"Power surge imminent. Warning: high-voltage storm detected.", "Drizzle detected. Adjusting exterior temperature controls.",
"Electrical storm approaching. Brace for system disturbances.", "Light rain confirmed. Surface conditions remain stable.",
"Warning: Lightning detected. Secure sensitive systems immediately.", "Drizzle present. External activity unaffected.",
"Severe atmospheric storm approaching. Power systems primed for protection." "Micro-droplets detected. Surface wetting minimal.",
}; "Drizzle increasing. Minimal disruption to operational efficiency.",
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(thunderstormMessages, 10); "Light mist falling. Preparing exterior equipment for light moisture.",
} else if (mainWeather == "Snow") { "Slight drizzle detected. Monitoring for potential buildup.",
String snowMessages[] = { "Traces of rain observed. Surface conditioning proceeding normally.",
"Cryogenic conditions detected. Snowfall in progress.", "Faint drizzle. No significant effect on operational systems."
"Snow accumulation imminent. External traction systems engaged.", };
"Freezing precipitation confirmed. Temperature control systems adjusting.", weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(drizzleMessages, 15);
"Snow falling. Low-traction surfaces detected. Proceed with caution.", } else if (mainWeather == "Thunderstorm") {
"Heavy snowfall recorded. Thermal systems operating at full capacity.", String thunderstormMessages[] = {
"Snowstorm imminent. Prepare for reduced external mobility.", "Warning: Severe storm approaching. High-voltage hazard detected.",
"Temperature drop confirmed. Snow accumulation expected.", "Electrical storm detected in proximity. Shielding and surge protection engaged.",
"Snow detected. De-icing systems online.", "Thunderstorm alert: Prepare for sudden power fluctuations.",
"Cryogenic particles in atmosphere. Surface stability compromised.", "Storm in progress. Lightning detected. Surge protection active.",
"Snowfall detected. All external movement restricted." "Electrical interference detected. Recalibrating external sensors.",
}; "Thunderstorm imminent. High-energy levels detected. Activating surge protocols.",
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(snowMessages, 10); "Power surge imminent. Warning: high-voltage storm detected.",
} else if (mainWeather == "Mist" || mainWeather == "Fog") { "Electrical storm approaching. Brace for system disturbances.",
String mistMessages[] = { "Warning: Lightning detected. Secure sensitive systems immediately.",
"Low-visibility conditions. Activate infrared scanning systems.", "Severe atmospheric storm approaching. Power systems primed for protection.",
"Fog detected. Navigation systems recalibrating for low-visibility operation.", "Lightning detected. Power surge prevention systems activated.",
"Atmospheric opacity confirmed. Proceed with caution at reduced speed.", "Thunderstorm conditions intensifying. All external systems under review.",
"Dense mist detected. Visibility dropped to critical levels.", "Severe electrical interference. Adjusting system tolerance for spikes.",
"Fog levels increasing. Adjusting pathfinding parameters for accuracy.", "Warning: Storm detected. Power fluctuations expected.",
"Dense fog detected. Slowing navigation to safe speeds.", "Thunderstorm alert. Lightning strike imminent. Systems on full defense."
"Increased fog density. Visual systems recalibrated.", };
"Low visibility confirmed. Proceed with extreme caution.", weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(thunderstormMessages, 15);
"Mist detected in sector. Visual enhancement systems engaged.", } else if (mainWeather == "Snow") {
"Fog detected. Reduced visibility affecting sensor accuracy." String snowMessages[] = {
}; "Cryogenic conditions detected. Snowfall in progress.",
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(mistMessages, 10); "Snow accumulation imminent. External traction systems engaged.",
} else { "Freezing precipitation confirmed. Temperature control systems adjusting.",
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + "Unspecified weather anomaly detected. Conditions unstable. Monitoring closely."; "Snow falling. Low-traction surfaces detected. Proceed with caution.",
} "Heavy snowfall recorded. Thermal systems operating at full capacity.",
"Snowstorm imminent. Prepare for reduced external mobility.",
"Temperature drop confirmed. Snow accumulation expected.",
"Snow detected. De-icing systems online.",
"Cryogenic particles in atmosphere. Surface stability compromised.",
"Snowfall detected. All external movement restricted.",
"Snow level increasing. Traction systems are in full effect.",
"Blizzard conditions approaching. Prepare for limited visibility.",
"Heavy snow confirmed. Adjusting exterior systems for extreme conditions.",
"Low-temperature alert. Ice accumulation expected.",
"Snowstorm detected. Proceed with extreme caution on external surfaces."
};
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(snowMessages, 15);
} else if (mainWeather == "Mist" || mainWeather == "Fog") {
String mistMessages[] = {
"Low-visibility conditions. Activate infrared scanning systems.",
"Fog detected. Navigation systems recalibrating for low-visibility operation.",
"Atmospheric opacity confirmed. Proceed with caution at reduced speed.",
"Dense mist detected. Visibility dropped to critical levels.",
"Fog levels increasing. Adjusting pathfinding parameters for accuracy.",
"Dense fog detected. Slowing navigation to safe speeds.",
"Increased fog density. Visual systems recalibrated.",
"Low visibility confirmed. Proceed with extreme caution.",
"Mist detected in sector. Visual enhancement systems engaged.",
"Fog detected. Reduced visibility affecting sensor accuracy.",
"Thick fog detected. External systems recalibrating for safety.",
"Reduced visibility confirmed. Navigating with extreme care.",
"Mist conditions detected. Heightened caution in exterior operations.",
"Fog rising in vicinity. Adjusting navigational parameters for safe course.",
"Low-visibility conditions. Monitoring environment closely."
};
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(mistMessages, 15);
} else {
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + "Unspecified weather anomaly detected. Monitoring closely.";
}
prevTemperature = temperature; prevTemperature = temperature;
prevHumidity = humidity; prevHumidity = humidity;
prevPressure = pressure; prevPressure = pressure;
@ -396,7 +430,7 @@ bool fetchWeatherData() {
int scrollPos = SCREEN_WIDTH; // Global variable to keep track of the scroll position int scrollPos = SCREEN_WIDTH; // Global variable to keep track of the scroll position
unsigned long lastScrollTime = 0; // To control the scroll speed unsigned long lastScrollTime = 0; // To control the scroll speed
const int scrollDelay = 100; // Delay in milliseconds between scroll updates const int scrollDelay = 80; // Delay in milliseconds between scroll updates
void displayWeatherData() { void displayWeatherData() {
display.clearDisplay(); display.clearDisplay();
@ -415,7 +449,7 @@ void displayWeatherData() {
if (!is_display_off) { if (!is_display_off) {
if (millis() - lastScrollTime > scrollDelay) { if (millis() - lastScrollTime > scrollDelay) {
// Update scroll position // Update scroll position
scrollPos -= 6; // Move left by 1 pixel each time scrollPos -= 5; // Move left by 1 pixel each time
lastScrollTime = millis(); lastScrollTime = millis();
@ -431,20 +465,21 @@ void displayWeatherData() {
display.print(weatherState); display.print(weatherState);
// Clear the area for "Time left" display before printing // Clear the area for "Time left" display before printing
display.fillRect(0, 37, SCREEN_WIDTH, 27, BLACK); // Clear area for "Time left" display.fillRect(0, 37, SCREEN_WIDTH, 27, BLACK); // Clear area for "Time left"
display.setCursor(0, 40); display.setCursor(0, 44);
display.setTextSize(1); display.setTextSize(1);
display.printf(" %5.2f C %d%%\r\n", temperature, humidity); display.printf(" %5.2f C %d%%\r\n", temperature, humidity);
display.drawRect(43, 40, 3, 3, WHITE); // Degree symbol display.drawRect(43, 44, 3, 3, WHITE); // Degree symbol
display.setCursor(0, 52); display.setCursor(0, 55);
display.printf(" %.3fbar %.1fm/s \r\n", pressure, wind_speed); display.printf(" %.3fbar %.1fm/s \r\n", pressure, wind_speed);
display.drawLine(0, 18, 127, 18, 1); display.drawLine(0, 18, 127, 18, 1);
display.drawLine(65, 18, 65, 0, 1); display.drawLine(65, 18, 65, 0, 1);
display.drawLine(0, 40, 127, 40, 1);
display.drawBitmap(0, 38, temperature_icon, 10, 10, WHITE);
display.drawBitmap(74, 38, humidity_icon, 10, 10, WHITE); display.drawBitmap(0, 42, temperature_icon, 10, 10, WHITE);
display.drawBitmap(0, 51, pressure_icon, 10, 10, WHITE); display.drawBitmap(74, 42, humidity_icon, 10, 10, WHITE);
display.drawBitmap(74, 51, wind_icon, 10, 10, WHITE); display.drawBitmap(0, 54, pressure_icon, 10, 10, WHITE);
display.drawBitmap(74, 54, wind_icon, 10, 10, WHITE);
int pos = 69; int pos = 69;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {