-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialCommands.cpp
More file actions
127 lines (121 loc) · 5.41 KB
/
Copy pathserialCommands.cpp
File metadata and controls
127 lines (121 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "serialCommands.h"
#include <WiFi.h>
#include <ezTime.h>
#include "ClockLogic.h" // backlightLevel, worldZones, manualBrightnessUntil
#include "genericBaseProject.h" // BACKLIGHT_PIN
#include "holidayService.h" // public holiday status
#include "marketHolidays.h" // holiday calendar status / refresh
#include "weatherService.h" // weatherAgeMinutes, weatherInvalidate
void handleSerialCommands()
{
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
command.trim();
command.toUpperCase();
if (command.startsWith("BRIGHTNESS ")) {
// Extract brightness value from command (e.g., "BRIGHTNESS 128")
int spaceIndex = command.indexOf(' ');
if (spaceIndex > 0) {
String valueStr = command.substring(spaceIndex + 1);
int newBrightness = valueStr.toInt();
if (newBrightness >= 5 && newBrightness <= 255) {
backlightLevel = newBrightness;
analogWrite(BACKLIGHT_PIN, backlightLevel);
// Respect this manual setting before auto-brightness resumes
manualBrightnessUntil = millis() + MANUAL_BRIGHTNESS_HOLD_MS;
// Persist so the level survives a reboot
projectConfig.brightness = backlightLevel;
projectConfig.saveConfigFile();
Log.print("Brightness set to: ");
Log.println(backlightLevel);
} else {
Log.println("Error: Brightness must be between 5 and 255");
}
} else {
Log.println("Error: Usage: BRIGHTNESS <value>");
}
}
else if (command == "SYNC") {
Log.println("Forcing NTP time synchronization...");
// Force immediate sync by calling updateNTP manually
if (waitForSync(10)) { // Wait up to 10 seconds for sync
Log.println("Time sync successful!");
Log.println("UTC: " + UTC.dateTime());
Log.println("Santa Clara: " + worldZones[0].tz.dateTime());
} else {
Log.println("Time sync failed or timed out");
}
}
else if (command == "WIFI" || command == "IP") {
Log.println("=== WiFi Information ===");
Log.print("SSID: ");
Log.println(WiFi.SSID());
Log.print("IP Address: ");
Log.println(WiFi.localIP());
Log.print("Gateway: ");
Log.println(WiFi.gatewayIP());
Log.print("Subnet: ");
Log.println(WiFi.subnetMask());
Log.print("DNS: ");
Log.println(WiFi.dnsIP());
Log.print("Signal Strength (RSSI): ");
Log.print(WiFi.RSSI());
Log.println(" dBm");
Log.print("MAC Address: ");
Log.println(WiFi.macAddress());
Log.print("Connection Status: ");
if (WiFi.status() == WL_CONNECTED) {
Log.println("Connected");
} else {
Log.println("Disconnected");
}
}
else if (command == "LDR") {
printLdrStatus();
}
else if (command == "WEATHER") {
long age = weatherAgeMinutes();
Log.println(age < 0 ? "No weather data yet."
: "Weather data is " + String(age) + " min old.");
weatherInvalidate();
Log.println("Cache invalidated - the background task refetches within seconds.");
}
else if (command == "HOLIDAYS") {
printMarketHolidaysStatus();
marketHolidaysForceRefresh();
printPublicHolidaysStatus();
}
else if (command == "HELP" || command == "?") {
Log.println("=== Available Commands ===");
Log.println("BRIGHTNESS <5-255> - Set display brightness");
Log.println("SYNC - Force NTP time synchronization");
Log.println("WIFI or IP - Show WiFi connection info");
Log.println("LDR - Show ambient light sensor state");
Log.println("WEATHER - Force a weather refetch");
Log.println("HOLIDAYS - Show/refresh market holiday calendars");
Log.println("HELP or ? - Show this help message");
}
else if (command.length() > 0) {
Log.println("Unknown command. Type HELP for available commands.");
}
}
}
void showStartupCommands()
{
Log.println();
Log.println("=== World Clock Ready ===");
Log.println("Serial commands available:");
Log.println("- BRIGHTNESS <5-255> : Set display brightness");
Log.println("- SYNC : Force time synchronization");
Log.println("- WIFI or IP : Show network information");
Log.println("- LDR : Show ambient light sensor state");
Log.println("- WEATHER : Force a weather refetch");
Log.println("- HELP or ? : Show command help");
Log.println("Type any command and press Enter");
Log.println();
Log.println("Touch screen controls:");
Log.println("- Tap CENTER of clock : Open settings (timezones, formats, status)");
Log.println("- Tap LEFT third : Decrease brightness");
Log.println("- Tap RIGHT third : Increase brightness");
Log.println();
}