refactoring

This commit is contained in:
Jakob Gegeniger committed 2026-09-09 00:43:01 +02:00
1 parent eb1c84cf05
commit 92423c52de
8 files changed
+655 -57

No files matched your search

+16 -9
View File
@@ -1,4 +1,5 @@
#include "swordMain.hpp"
#include "defines.hpp"
#include "mqttChannel.hpp"
@@ -11,7 +12,7 @@ constexpr uint8_t VersionArr[4] = {'V', 0, 8, 0};
const string Version = "V 0.8.0";
// const string Version = fmt::format("{} {}.{}.{}", VersionArr[0], VersionArr[1], VersionArr[2], VersionArr[3]);
SwordConfig SwordCfg{};
unique_ptr<SwordConfig> SwordCfg;
unique_ptr<DeviceIoState> IoStat;
OpMode Mode = OpMode::Maintanance;
@@ -40,7 +41,7 @@ int main(int argc, char* argv[]) {
CLI11_PARSE(app, argc, argv);
SeqLogger log(logUrl, logApiKey, "Sword");
SwordCfg.setVar(assetsBasePath, brocker, topic, user, password);
SwordCfg = make_unique<SwordConfig>(assetsBasePath, brocker, topic, user, password);
fmt::println("{}", app.get_description());
if (modeArg == "promo") {
@@ -79,7 +80,7 @@ int main(int argc, char* argv[]) {
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
MqttChannel mqtt(Version, SwordCfg, *IoStat, log);
MqttChannel mqtt(Version, *SwordCfg, *IoStat, log);
auto resetCall = [&]() {
log.sendEvent("Reset", "");
};
@@ -118,7 +119,8 @@ int main(int argc, char* argv[]) {
}
void processPromo(MqttChannel& mqtt, SeqLogger& log) {
auto tn = chrono::steady_clock::now();
Tick tn(1s);
Tick tsf(30min);
auto& serCmds = mqtt.getSerCommands();
while (true) {
Thread::sleep(10ms);
@@ -126,14 +128,19 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
if (IoStat->SwordPulled.isPosEdge()) {
if (!IoStat->Mute) {
log.sendEvent("Pull", "Start Audio");
MediaPlayer::playWavFile(SwordCfg.getSoundPromo());
if (tsf.tick()) {
MediaPlayer::playWavFile(SwordCfg->SoundPromo);
} else {
MediaPlayer::playWavFile(SwordCfg->SoundPromoShort);
}
fmt::println("Waiting for {}", IoStat->PromoDelay);
Thread::sleep(IoStat->PromoDelay);
fmt::println("Waiting done");
}
}
if (chrono::steady_clock::now() > (tn + 1s)) {
tn = chrono::steady_clock::now();
if (tn.tick()) {
mqtt.sendStatusMessage(Mode);
}
}
@@ -167,7 +174,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
if (IoStat->SwordPulled.isPosEdge()) {
mqtt.sendStatusMessage(Mode);
// say: You are not the one
MediaPlayer::playWavFile(SwordCfg.getSoundDeny());
MediaPlayer::playWavFile(SwordCfg->SoundDeny);
Thread::sleep(15s);
log.sendEvent("Req", "Pulled");
mqtt.sendEvent("pull");
@@ -196,7 +203,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
mqtt.sendEvent("pulled-out");
log.sendEvent("Req", "Pulled Out");
// say: You ARE the one
MediaPlayer::playWavFile(SwordCfg.getSoundAllow());
MediaPlayer::playWavFile(SwordCfg->SoundAllow);
Thread::sleep(15s);
mqtt.sendEvent("ceremonyDone");