step: GameMode
This commit is contained in:
1 parent
c1e8f2a7a4
commit
313e097a53
8 files changed
+251
-46
No files matched your search
+55
-19
@@ -8,7 +8,7 @@ using namespace std::literals::string_view_literals;
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace std;
|
||||
|
||||
const string Version = "V 0.9.0";
|
||||
const string Version = "V 0.9.1";
|
||||
|
||||
unique_ptr<SwordConfig> SwordCfg;
|
||||
unique_ptr<DeviceIoState> IoStat;
|
||||
@@ -37,7 +37,16 @@ int main(int argc, char* argv[]) {
|
||||
app.add_option("-l,--log", logUrl, "Logging Service");
|
||||
app.add_option("-k,--key", logApiKey, "Logging API Key");
|
||||
|
||||
fmt::println("## Starting Sword Station {}", Version);
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
std::ostringstream cmdline;
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
if (i > 0)
|
||||
cmdline << ' ';
|
||||
cmdline << argv[i];
|
||||
}
|
||||
fmt::println(" CallArgs {}", cmdline.str());
|
||||
|
||||
SeqLogger log(logUrl, logApiKey, appName);
|
||||
SwordCfg = make_unique<SwordConfig>(assetsBasePath, brocker, topic, user, password);
|
||||
@@ -99,11 +108,8 @@ int main(int argc, char* argv[]) {
|
||||
switch (IoStat->Mode) {
|
||||
case OpMode::Maintanance: {
|
||||
fmt::println("Running Maintanance");
|
||||
// txQueue.emplace<ResponseTxMsg>(msg->code, 0);
|
||||
Thread::sleep(500ms);
|
||||
IoStat->tick();
|
||||
// auto e = make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
// txQueue.enqueue(move(e));
|
||||
} break;
|
||||
case OpMode::PromoMode: {
|
||||
fmt::println("Running PromoMode");
|
||||
@@ -141,9 +147,9 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
log.sendEvent("Pull", "Start Audio");
|
||||
|
||||
if (tsf.tick()) {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromo);
|
||||
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo);
|
||||
} else {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromoShort);
|
||||
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromoShort);
|
||||
}
|
||||
dP.sample();
|
||||
fmt::println("Muting next for {}", IoStat->PromoDelay);
|
||||
@@ -199,7 +205,14 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto code = gameCmds.at(msg->Payload);
|
||||
auto code = GameAbortTry;
|
||||
try {
|
||||
code = gameCmds.at(msg->Payload);
|
||||
} catch (const std::exception& e) {
|
||||
fmt::println("Code not parsable {}", msg->Payload);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case GameModeCommands_e::GameStarted: {
|
||||
fmt::println("Got GameStarted");
|
||||
@@ -212,65 +225,88 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
} break;
|
||||
|
||||
case GameModeCommands_e::GameNextTryLocked: {
|
||||
bool abort = false;
|
||||
fmt::println("Got NextTryLock");
|
||||
log.sendEvent("Req", "StayLockded");
|
||||
while (true) {
|
||||
while (!abort) {
|
||||
IoStat->SwordPulled.sample();
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
// say: You are not the one
|
||||
MediaPlayer::playWavFile(SwordCfg->getNextDeny());
|
||||
Thread::sleep(5s);
|
||||
log.sendEvent("Req", "Pulled");
|
||||
mqtt.sendEvent("pull");
|
||||
MediaPlayer::playWavFileSync(SwordCfg->getNextDeny());
|
||||
log.sendEvent("Req", "Pulled");
|
||||
mqtt.sendEvent("pull-denied");
|
||||
break;
|
||||
}
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
}
|
||||
} break;
|
||||
|
||||
case GameModeCommands_e::GameNextTryRelease: {
|
||||
bool abort = false;
|
||||
fmt::println("NextTryRelease");
|
||||
log.sendEvent("Req", "UnlockSword");
|
||||
IoStat->SwordLatch.moveIn();
|
||||
while (true) {
|
||||
while (!abort) {
|
||||
IoStat->SwordEnd.sample();
|
||||
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Passive) {
|
||||
fmt::println("pulling sword");
|
||||
break;
|
||||
}
|
||||
Thread::sleep(10ms);
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
}
|
||||
while (true) {
|
||||
while (!abort) {
|
||||
IoStat->SwordEntry.sample();
|
||||
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Passive) {
|
||||
fmt::println("sword pulled");
|
||||
break;
|
||||
}
|
||||
Thread::sleep(10ms);
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
}
|
||||
if (abort) {
|
||||
break;
|
||||
}
|
||||
mqtt.sendEvent("pulled-out");
|
||||
log.sendEvent("Req", "Pulled Out");
|
||||
// say: You ARE the one
|
||||
MediaPlayer::playWavFile(SwordCfg->getNextAllow());
|
||||
Thread::sleep(5s);
|
||||
MediaPlayer::playWavFileSync(SwordCfg->getNextAllow());
|
||||
mqtt.sendEvent("ceremonyDone");
|
||||
|
||||
while (true) {
|
||||
while (!abort) {
|
||||
IoStat->SwordEntry.sample();
|
||||
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Active) {
|
||||
fmt::println("returning sword");
|
||||
break;
|
||||
}
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
}
|
||||
while (true) {
|
||||
while (!abort) {
|
||||
IoStat->SwordEnd.sample();
|
||||
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Active) {
|
||||
fmt::println("sword returned");
|
||||
break;
|
||||
}
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
}
|
||||
if (abort) {
|
||||
break;
|
||||
}
|
||||
log.sendEvent("Req", "Put Back");
|
||||
mqtt.sendEvent("put-in");
|
||||
IoStat->SwordLatch.moveOut(); // Lock
|
||||
Thread::sleep(3s);
|
||||
mqtt.sendEvent("locked");
|
||||
// mqtt.sendEvent("lock-error");
|
||||
} break;
|
||||
|
||||
default:
|
||||
// nothing to doe here
|
||||
fmt::println("oopsie");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user