-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialCommands.cpp
More file actions
151 lines (145 loc) · 6.79 KB
/
Copy pathserialCommands.cpp
File metadata and controls
151 lines (145 loc) · 6.79 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "serialCommands.h"
#include <WiFi.h>
#include <ezTime.h>
#include "brightness.h"
#include "ClockLogic.h" // backlightLevel, worldZones, markManualBrightness
#include "factoryReset.h" // factoryReset - FACTORYRESET command
#include "genericBaseProject.h" // currentNtpServer - SYNC command
#include "holidayService.h" // public holiday status
#include "logShipper.h" // remote log push status
#include "marketHolidays.h" // holiday calendar status / refresh
#include "uiPages.h" // openTouchCalibration - CALTOUCH command
#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 >= BRIGHTNESS_MIN && newBrightness <= BRIGHTNESS_MAX) {
backlightLevel = newBrightness;
setBacklight(backlightLevel);
// Respect this manual setting before auto-brightness resumes
markManualBrightness();
// 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 " + String(BRIGHTNESS_RANGE_TEXT));
}
} else {
Log.println("Error: Usage: BRIGHTNESS <value>");
}
}
else if (command == "SYNC") {
// Query the current NTP server directly. (waitForSync() can't be
// used as the check here: it returns true whenever the clock is
// merely set - which since the build-time seeding it always is -
// without proving the server answered.)
Log.println("Forcing NTP time synchronization (server: " +
String(currentNtpServer()) + ")...");
time_t t;
unsigned long measuredAt;
if (queryNTP(currentNtpServer(), t, measuredAt)) {
UTC.setTime(t, millis() - measuredAt);
Log.println("Time sync successful!");
Log.println("UTC: " + UTC.dateTime());
Log.println("Santa Clara: " + worldZones[0].tz.dateTime());
} else {
Log.println("Time sync failed: " + errorString());
}
}
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 == "LOGSHIP") {
logShipperPrintStatus(Log);
}
else if (command == "CALTOUCH") {
openTouchCalibration(); // no-op log on boards that need none
}
else if (command == "FACTORYRESET") {
Log.println("Factory reset: erasing all settings and WiFi credentials...");
factoryReset(); // wipes NVS + SPIFFS and reboots - does not return
}
else if (command == "HELP" || command == "?") {
Log.println("=== Available Commands ===");
Log.println("BRIGHTNESS <" + String(BRIGHTNESS_RANGE_TEXT) + "> - 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("LOGSHIP - Show remote log shipping status");
Log.println("CALTOUCH - Open the touch calibration screen");
Log.println("FACTORYRESET - Erase all settings + WiFi creds, then reboot");
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 <" + String(BRIGHTNESS_RANGE_TEXT) + "> : 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();
}