Skip to content

Commit 61ff23c

Browse files
committed
Apply ESP32 dashboard design treatment
1 parent e504573 commit 61ff23c

15 files changed

Lines changed: 2603 additions & 1103 deletions

File tree

src/Config.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,41 @@ namespace SQM
9595
}
9696
return false;
9797
}
98+
99+
bool isTimeSourceEnabled(const Config &cfg, TimeSource source)
100+
{
101+
return source == TimeSource::NTP ? cfg.ntp.enabled : cfg.gps.enabled;
102+
}
103+
104+
void normalizeTimeSources(Config &cfg)
105+
{
106+
if (!cfg.ntp.enabled && !cfg.gps.enabled)
107+
{
108+
return;
109+
}
110+
111+
if (!isTimeSourceEnabled(cfg, cfg.primaryTimeSource))
112+
{
113+
cfg.primaryTimeSource = cfg.ntp.enabled ? TimeSource::NTP : TimeSource::GPS;
114+
}
115+
116+
if (!isTimeSourceEnabled(cfg, cfg.secondaryTimeSource))
117+
{
118+
cfg.secondaryTimeSource = cfg.gps.enabled && cfg.primaryTimeSource != TimeSource::GPS
119+
? TimeSource::GPS
120+
: TimeSource::NTP;
121+
}
122+
123+
if (cfg.ntp.enabled && cfg.gps.enabled && cfg.primaryTimeSource == cfg.secondaryTimeSource)
124+
{
125+
cfg.secondaryTimeSource = cfg.primaryTimeSource == TimeSource::NTP ? TimeSource::GPS : TimeSource::NTP;
126+
}
127+
128+
if (!cfg.ntp.enabled || !cfg.gps.enabled)
129+
{
130+
cfg.secondaryTimeSource = cfg.primaryTimeSource;
131+
}
132+
}
98133
} // namespace
99134

100135
std::optional<Config> Config::load()
@@ -352,6 +387,26 @@ namespace SQM
352387
return setError(error, "Secondary time source is invalid");
353388
}
354389

390+
if (!ntp.enabled && !gps.enabled)
391+
{
392+
return setError(error, "At least one time source must be enabled");
393+
}
394+
395+
if (!isTimeSourceEnabled(*this, primaryTimeSource))
396+
{
397+
return setError(error, "Primary time source is disabled");
398+
}
399+
400+
if (ntp.enabled && gps.enabled && !isTimeSourceEnabled(*this, secondaryTimeSource))
401+
{
402+
return setError(error, "Secondary time source is disabled");
403+
}
404+
405+
if (ntp.enabled && gps.enabled && primaryTimeSource == secondaryTimeSource)
406+
{
407+
return setError(error, "Time sources must be different when both NTP and GPS are enabled");
408+
}
409+
355410
if (wifi.reconnectDelayMs == 0 || wifi.maxReconnectDelayMs == 0 ||
356411
wifi.reconnectDelayMs > 86400000 || wifi.maxReconnectDelayMs > 86400000 ||
357412
wifi.reconnectDelayMs > wifi.maxReconnectDelayMs)
@@ -615,6 +670,8 @@ namespace SQM
615670
cfg.sensor.i2cFrequency = sensor["i2cFrequency"] | 100000;
616671
}
617672

673+
normalizeTimeSources(cfg);
674+
618675
std::string validationError;
619676
if (!cfg.validate(&validationError))
620677
{

src/WebServer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace SQM
2222
{
2323
namespace
2424
{
25+
constexpr size_t CONFIG_JSON_BUFFER_SIZE = 4096;
26+
2527
esp_timer_handle_t restartTimer = nullptr;
2628

2729
void restartTimerCallback(void *)
@@ -415,7 +417,8 @@ namespace SQM
415417
{
416418
request->send(500, "application/json", createErrorJson("Failed to save configuration").c_str());
417419
}
418-
});
420+
},
421+
CONFIG_JSON_BUFFER_SIZE);
419422
configHandler->setMethod(HTTP_POST | HTTP_PUT);
420423
server.addHandler(configHandler);
421424

web/src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Dashboard from './components/Dashboard';
66
import Settings from './components/Settings';
77
import System from './components/System';
88
import Updates from './components/Updates';
9+
import NotFound from './components/NotFound';
910

1011
const isDemo = import.meta.env.VITE_DEMO_MODE === 'true';
1112

@@ -36,6 +37,9 @@ const App: FunctionalComponent = () => (
3637
<Layout path="/updates">
3738
<Updates />
3839
</Layout>
40+
<Layout default>
41+
<NotFound />
42+
</Layout>
3943
</Router>
4044
);
4145

25.4 KB
Binary file not shown.
11.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)