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 lastDisplayOverride = 0;
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 display_override = false;
@ -249,7 +249,6 @@ bool fetchWeatherData() {
humidity = doc["main"]["humidity"];
pressure = doc["main"]["pressure"].as<float>() / 1000;
wind_speed = doc["wind"]["speed"].as<float>();
// Define 10 messages for each weather condition
if (mainWeather == "Clear") {
String clearMessages[] = {
"All systems nominal. Atmospheric clearance detected.",
@ -261,9 +260,14 @@ bool fetchWeatherData() {
"Clear. No interference detected. Navigation optimal.",
"Visible space clear. Proceed with standard operations.",
"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.",
"Clear and stable. No impact on external activities.",
"The sky is free of disturbances. Proceed with confidence.",
"Atmospheric conditions steady. All sensors reporting normal."
};
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(clearMessages, 10);
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(clearMessages, 15);
} else if (mainWeather == "Clouds") {
String cloudMessages[] = {
"Cloud cover detected. Light interference on visual systems.",
@ -275,9 +279,14 @@ bool fetchWeatherData() {
"Low-visibility overhead. Preparing for reduced solar input.",
"Sensors report cloud patterns. Adjusting visibility protocols.",
"Clouds forming in surrounding space. Adjusting navigational parameters.",
"Light cloud cover detected. No operational impact expected."
"Light cloud cover detected. No operational impact expected.",
"Cloud formation increasing. Visual scan in progress.",
"Partly cloudy. Visibility reduced, but no immediate danger.",
"Overcast sky. Sensors adjusting for changing light levels.",
"Increasing cloud density. Proceeding with caution on exterior tasks.",
"Cumulus clouds observed. No operational impact anticipated."
};
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(cloudMessages, 10);
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(cloudMessages, 15);
} else if (mainWeather == "Rain") {
String rainMessages[] = {
"Precipitation incoming. Shielding activated.",
@ -289,9 +298,14 @@ bool fetchWeatherData() {
"Rain detected. Traction systems engaged for slippery terrain.",
"Wet conditions approaching. Hydration protocols for external units activated.",
"Raindrops increasing. Proceed with caution on exterior surfaces.",
"Heavy rain in the vicinity. External equipment may require adjustment."
"Heavy rain in the vicinity. External equipment may require adjustment.",
"Intense rain incoming. All systems on standby for moisture management.",
"Heavy precipitation. Surface traction adjustments being made.",
"Rainfall intensifying. Navigation systems recalibrating.",
"Storm-like rain detected. Prepare for potential delays in operations.",
"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(rainMessages, 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 == "Drizzle") {
String drizzleMessages[] = {
"Light drizzle detected. Surface moisture rising, minimal impact.",
@ -303,9 +317,14 @@ bool fetchWeatherData() {
"Drizzle detected. Adjusting exterior temperature controls.",
"Light rain confirmed. Surface conditions remain stable.",
"Drizzle present. External activity unaffected.",
"Micro-droplets detected. Surface wetting minimal."
"Micro-droplets detected. Surface wetting minimal.",
"Drizzle increasing. Minimal disruption to operational efficiency.",
"Light mist falling. Preparing exterior equipment for light moisture.",
"Slight drizzle detected. Monitoring for potential buildup.",
"Traces of rain observed. Surface conditioning proceeding normally.",
"Faint drizzle. No significant effect on operational systems."
};
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(drizzleMessages, 15);
} else if (mainWeather == "Thunderstorm") {
String thunderstormMessages[] = {
"Warning: Severe storm approaching. High-voltage hazard detected.",
@ -317,9 +336,14 @@ bool fetchWeatherData() {
"Power surge imminent. Warning: high-voltage storm detected.",
"Electrical storm approaching. Brace for system disturbances.",
"Warning: Lightning detected. Secure sensitive systems immediately.",
"Severe atmospheric storm approaching. Power systems primed for protection."
"Severe atmospheric storm approaching. Power systems primed for protection.",
"Lightning detected. Power surge prevention systems activated.",
"Thunderstorm conditions intensifying. All external systems under review.",
"Severe electrical interference. Adjusting system tolerance for spikes.",
"Warning: Storm detected. Power fluctuations expected.",
"Thunderstorm alert. Lightning strike imminent. Systems on full defense."
};
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(thunderstormMessages, 10);
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(thunderstormMessages, 15);
} else if (mainWeather == "Snow") {
String snowMessages[] = {
"Cryogenic conditions detected. Snowfall in progress.",
@ -331,9 +355,14 @@ bool fetchWeatherData() {
"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."
"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, 10);
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.",
@ -345,11 +374,16 @@ bool fetchWeatherData() {
"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."
"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, 10);
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. Conditions unstable. Monitoring closely.";
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;
prevHumidity = humidity;
@ -396,7 +430,7 @@ bool fetchWeatherData() {
int scrollPos = SCREEN_WIDTH; // Global variable to keep track of the scroll position
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() {
display.clearDisplay();
@ -415,7 +449,7 @@ void displayWeatherData() {
if (!is_display_off) {
if (millis() - lastScrollTime > scrollDelay) {
// Update scroll position
scrollPos -= 6; // Move left by 1 pixel each time
scrollPos -= 5; // Move left by 1 pixel each time
lastScrollTime = millis();
@ -431,20 +465,21 @@ void displayWeatherData() {
display.print(weatherState);
// Clear the area for "Time left" display before printing
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.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.drawLine(0, 18, 127, 18, 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, 51, pressure_icon, 10, 10, WHITE);
display.drawBitmap(74, 51, wind_icon, 10, 10, WHITE);
display.drawBitmap(0, 42, temperature_icon, 10, 10, WHITE);
display.drawBitmap(74, 42, humidity_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;
for (int i = 0; i < 3; i++) {