This commit is contained in:
Jakob Gegeniger committed 2026-10-13 22:10:06 +02:00
1 parent e7393389b8
commit c1e8f2a7a4
4 files changed
+121 -60

No files matched your search

+46 -49
View File
@@ -12,7 +12,6 @@ const string Version = "V 0.9.0";
unique_ptr<SwordConfig> SwordCfg;
unique_ptr<DeviceIoState> IoStat;
OpMode Mode = OpMode::Maintanance;
void processPromo(MqttChannel& mqtt, SeqLogger& log);
void processProduction(MqttChannel& mqtt, SeqLogger& log);
@@ -42,30 +41,15 @@ int main(int argc, char* argv[]) {
SeqLogger log(logUrl, logApiKey, appName);
SwordCfg = make_unique<SwordConfig>(assetsBasePath, brocker, topic, user, password);
fmt::println("{}", app.get_description());
if (modeArg == "promo") {
fmt::println("starting with promo");
Mode = OpMode::PromoMode;
} else if (modeArg == "game") {
fmt::println("starting with promo");
Mode = OpMode::GamingMode;
} else {
fmt::println("unknown {}", modeArg);
}
constexpr array<const char*, 4> modes = {"Undefined", "Maintanance", "PromoMode", "Production"};
log.sendBootUp(Version, modes[static_cast<int>(Mode)]);
auto itrHandler = [&]() {
TriggeredInput itr(26, "PItr");
while (true) {
cout << "Await next interrupt\n";
if (itr.await()) {
cout << "Interrupt Event\n";
}
{
fmt::println("Win files found: {}", SwordCfg->getSoundsAllow().size());
for (const auto& file : SwordCfg->getSoundsAllow()) {
fmt::println(" {}", file);
}
};
thread interruptThread(itrHandler);
fmt::println("Lose files found: {}", SwordCfg->getSoundsDeny().size());
for (const auto& file : SwordCfg->getSoundsDeny())
fmt::println(" {}", file);
}
InputPort sbPort(SwordEntryPin, "PinSEntry");
InputPort sePort(SwordEndPin, "PInSEnd");
@@ -88,6 +72,19 @@ int main(int argc, char* argv[]) {
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
fmt::println("{}", app.get_description());
if (modeArg == "promo") {
fmt::println("starting with promo");
IoStat->Mode = OpMode::PromoMode;
} else if (modeArg == "game") {
fmt::println("starting with promo");
IoStat->Mode = OpMode::GamingMode;
} else {
fmt::println("unknown {}", modeArg);
}
constexpr array<const char*, 4> modes = {"Undefined", "Maintanance", "PromoMode", "Production"};
log.sendBootUp(Version, modes[static_cast<int>(IoStat->Mode)]);
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
auto resetCall = [&]() {
log.sendEvent("Reset", "");
@@ -99,13 +96,12 @@ int main(int argc, char* argv[]) {
SwordLatch.moveOut();
fmt::println("Running App");
while (true) {
switch (Mode) {
switch (IoStat->Mode) {
case OpMode::Maintanance: {
fmt::println("Running Maintanance");
// txQueue.emplace<ResponseTxMsg>(msg->code, 0);
Thread::sleep(500ms);
IoStat->tick();
mqtt.sendStatusMessage(Mode);
// auto e = make_unique<ResponseTxMsg>(msg->code, 0);
// txQueue.enqueue(move(e));
} break;
@@ -122,7 +118,6 @@ int main(int argc, char* argv[]) {
break;
}
}
interruptThread.join();
return EXIT_SUCCESS;
}
@@ -134,7 +129,6 @@ enum MuteState {
void processPromo(MqttChannel& mqtt, SeqLogger& log) {
auto muterS = MuteState::WaitForUnmute;
Tick tmu(1min);
Tick tn(1s);
Tick tsf(30min);
Waiter dP;
auto& serCmds = mqtt.getSerCommands();
@@ -158,9 +152,6 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
}
}
}
if (tn.tick()) {
mqtt.sendStatusMessage(Mode);
}
if (tmu.tick()) {
auto now = std::chrono::system_clock::now();
std::time_t time = std::chrono::system_clock::to_time_t(now);
@@ -202,7 +193,8 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
auto& serCmds = mqtt.getSerCommands();
auto& gameCmds = mqtt.getGameCommands();
while (true) {
auto msg = mqtt.tryDeque();
auto msg = mqtt.tryDequeueFor(500ms);
IoStat->tick();
if (!msg) {
continue;
}
@@ -212,11 +204,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
case GameModeCommands_e::GameStarted: {
fmt::println("Got GameStarted");
log.sendEvent("Req", "GameStarted");
}
} break;
case GameModeCommands_e::GameFinished: {
fmt::println("Got GameFinished");
log.sendEvent("Req", "GameFinished");
}
} break;
case GameModeCommands_e::GameNextTryLocked: {
fmt::println("Got NextTryLock");
@@ -224,12 +217,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
while (true) {
IoStat->SwordPulled.sample();
if (IoStat->SwordPulled.isPosEdge()) {
mqtt.sendStatusMessage(Mode);
// say: You are not the one
MediaPlayer::playWavFile(SwordCfg->SoundDeny);
Thread::sleep(15s);
MediaPlayer::playWavFile(SwordCfg->getNextDeny());
Thread::sleep(5s);
log.sendEvent("Req", "Pulled");
mqtt.sendEvent("pull");
break;
}
}
} break;
@@ -240,36 +233,38 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
IoStat->SwordLatch.moveIn();
while (true) {
IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Passive) {
fmt::println("pulling sword");
break;
}
Thread::sleep(10ms);
}
while (true) {
IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Passive) {
fmt::println("sword pulled");
break;
}
Thread::sleep(10ms);
}
mqtt.sendEvent("pulled-out");
log.sendEvent("Req", "Pulled Out");
// say: You ARE the one
MediaPlayer::playWavFile(SwordCfg->SoundAllow);
Thread::sleep(15s);
MediaPlayer::playWavFile(SwordCfg->getNextAllow());
Thread::sleep(5s);
mqtt.sendEvent("ceremonyDone");
while (true) {
IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Active) {
fmt::println("returning sword");
break;
}
}
while (true) {
IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Active) {
fmt::println("sword returned");
break;
}
}
@@ -279,3 +274,5 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
}
}
}
// todo send state in background