3 Commits
Author SHA1 Message Date
Jakob Gegeniger 27a791c4c0 step: Consistent abort msg, live signal and last Will 2026-10-22 22:14:48 +02:00
Jakob Gegeniger dbe482655c step: version-return 2026-10-17 11:46:48 +02:00
Jakob Gegeniger b34a3a4acd fix: PullDown 2026-10-16 21:29:06 +02:00
17 changed files with 194 additions and 142 deletions

No files matched your search

+1 -3
View File
@@ -11,9 +11,7 @@
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/build/src/sword/SwordMain", "program": "${workspaceFolder}/build/src/sword/SwordMain",
"args": [ "args": [
//"test", "game", //"test",
// "promo",
"game",
"${workspaceFolder}/assets", "${workspaceFolder}/assets",
"-n", "SwordDebug", "-n", "SwordDebug",
"-b", "'mqtts://excaliburs-erben.de:8883'", "-b", "'mqtts://excaliburs-erben.de:8883'",
+1 -1
View File
@@ -1,4 +1,4 @@
; sudo nano /etc/systemd/system/SwordMain.service ; sudo nano /etc/systemd/system/Sword.service
[Unit] [Unit]
Description=Service for sword stationg Description=Service for sword stationg
After=network-online.target After=network-online.target
+15 -1
View File
@@ -29,4 +29,18 @@ sudo crontab -e
``` ```
```txt ```txt
0 3 * * * /sbin/reboot 0 3 * * * /sbin/reboot
``` 0 23 * * * /sbin/reboot
0 6 * * * /sbin/reboot
*/5 * * * * ping -c 4 8.8.8.8 > /dev/null 2>&1
```
## PowerSavings
```sh
sudo nano /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
```
```ini
[connection]
wifi.powersave = 2
```
+7 -7
View File
@@ -1,9 +1,9 @@
# Autostart applications # Autostart applications
```sh ```sh
sudo nano /etc/systemd/system/SwordMain.service sudo nano /etc/systemd/system/Sword.service
``` ```
./
```ini ```ini
[Unit] [Unit]
Description=My Raspberry Pi Application Description=My Raspberry Pi Application
@@ -14,7 +14,7 @@ Wants=network-online.target
Type=simple Type=simple
User=gustice User=gustice
WorkingDirectory=/home/pi/SwordMain WorkingDirectory=/home/pi/SwordMain
ExecStart=/home/pi/SwordMain/start.sh ExecStart=bash start.sh
Restart=on-failure Restart=on-failure
RestartSec=5 RestartSec=5
@@ -27,12 +27,12 @@ chmod +x /home/pi/SwordMain/start.sh
# Reload systemd # Reload systemd
sudo systemctl daemon-reload sudo systemctl daemon-reload
# Enable the service # Enable the service
sudo systemctl enable SwordMain.service sudo systemctl enable Sword.service
# start immediately # start immediately
sudo systemctl start SwordMain.service sudo systemctl start Sword.service
# check status # check status
sudo systemctl status SwordMain.service sudo systemctl status Sword.service
``` ```
promo $(pwd)/assets -b "mqtts://excaliburs-erben.de:8883" -t "outdoor/king-arthur/sword/" -p "awesomeexodusoutdooradventures" -u "exodususer" game $(pwd)/assets -b "mqtts://excaliburs-erben.de:8883" -t "outdoor/king-arthur/sword/" -p "awesomeexodusoutdooradventures" -u "exodususer"
+4 -1
View File
@@ -12,4 +12,7 @@ pack_sword:
cp_sword: cp_sword:
@mkdir -p deploy/sword @mkdir -p deploy/sword
@cp build/src/sword/SwordMain deploy/sword @cp build/src/sword/SwordMain deploy/sword
cpexe_toServ:
scp build/src/sword/SwordMain gustice@excaliburs-erben.de:SwordMain
Submodule platform updated: 6f6a0474cb...387735f701.
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
/home/gustice/workspace/swordStation/SwordMain \ /home/gustice/workspace/swordStation/SwordMain \
promo /home/gustice/workspace/swordStation/assets \ game /home/gustice/workspace/swordStation/assets \
-n Sword \ -n Sword \
-b mqtts://excaliburs-erben.de:8883 \ -b mqtts://excaliburs-erben.de:8883 \
-t outdoor/king-arthur/sword/ \ -t outdoor/king-arthur/sword/ \
+1 -1
View File
@@ -16,7 +16,7 @@ BROKER = "excaliburs-erben.de"
PORT = 8883 PORT = 8883
USERNAME = os.getenv("MQTT_USER", "exodususer") USERNAME = os.getenv("MQTT_USER", "exodususer")
PASSWORD = os.getenv("MQTT_PASSWORD", "awesomeexodusoutdooradventures") PASSWORD = os.getenv("MQTT_PASSWORD", "awesomeexodusoutdooradventures")
BASE_TOPIC = "outdoor/king-arthur/sword" BASE_TOPIC = "staging/outdoor/king-arthur/sword"
YELLOW = "\033[93m" YELLOW = "\033[93m"
RESET = "\033[0m" RESET = "\033[0m"
+1
View File
@@ -1,2 +1,3 @@
add_subdirectory(sword) add_subdirectory(sword)
add_subdirectory(throneBridge) add_subdirectory(throneBridge)
add_subdirectory(throne)
+1 -1
View File
@@ -42,7 +42,7 @@ class SeqLogger {
{"MessageTemplate", "[{App}]: Got {Event}; " + message}, {"MessageTemplate", "[{App}]: Got {Event}; " + message},
{"Properties", { {"Properties", {
{"App", AppName}, {"App", AppName},
{"Event", Version} {"Event", event}
}} }}
} }
})} })}
+3 -2
View File
@@ -15,6 +15,7 @@ enum ServiceCommands_e {
PlaySoundPromo, PlaySoundPromo,
PlaySoundDeny, PlaySoundDeny,
PlaySoundChosen, PlaySoundChosen,
SetMaintanence,
}; };
enum GameModeCommands_e { enum GameModeCommands_e {
@@ -22,7 +23,8 @@ enum GameModeCommands_e {
GameFinished, // The Game is finished (resume to Promo mode) GameFinished, // The Game is finished (resume to Promo mode)
GameNextTryLocked, // Lock sword on next try GameNextTryLocked, // Lock sword on next try
GameNextTryRelease, // Release sword on next try GameNextTryRelease, // Release sword on next try
GameAbortTry // Abort this try GameAbortTry, // Abort this try
GameForceAbort // Abort current state
}; };
enum OutgoingCommands_e { enum OutgoingCommands_e {
@@ -57,7 +59,6 @@ struct MqttQe {
enum class OpMode { enum class OpMode {
Undefined, // Enable in Game mode Undefined, // Enable in Game mode
Maintanance = 1, // Set Maintanance mode Maintanance = 1, // Set Maintanance mode
PromoMode, // Enable PromoMode
GamingMode, // Enable in Game mode GamingMode, // Enable in Game mode
}; };
+28 -6
View File
@@ -4,8 +4,11 @@
class MqttChannel { class MqttChannel {
public: public:
static constexpr array<const char*, 3> Modes = {"Undefined", "Maintanance", "Production"};
MqttChannel(string name, string version, SwordConfig cfg, DeviceIoState& ioStat, SeqLogger& log) MqttChannel(string name, string version, SwordConfig cfg, DeviceIoState& ioStat, SeqLogger& log)
: Config(cfg), : Version(version),
Config(cfg),
IoStat(ioStat), IoStat(ioStat),
Logger(log), Logger(log),
cfgTopic(cfg.StationPath + "cfg"), cfgTopic(cfg.StationPath + "cfg"),
@@ -15,7 +18,8 @@ class MqttChannel {
statTopic(cfg.StationPath + "stat"), statTopic(cfg.StationPath + "stat"),
resetTopic(cfg.StationPath + "reset"), resetTopic(cfg.StationPath + "reset"),
serviceCommands({ // cfg-topic serviceCommands({
// cfg-topic
{"openLock", ServiceCommands_e::SetLockOpen}, {"openLock", ServiceCommands_e::SetLockOpen},
{"closeLock", ServiceCommands_e::SetLockClose}, {"closeLock", ServiceCommands_e::SetLockClose},
{"mute", ServiceCommands_e::SetDisableSound}, {"mute", ServiceCommands_e::SetDisableSound},
@@ -23,21 +27,26 @@ class MqttChannel {
{"playSound:Promo", ServiceCommands_e::PlaySoundPromo}, {"playSound:Promo", ServiceCommands_e::PlaySoundPromo},
{"playSound:Deny", ServiceCommands_e::PlaySoundDeny}, {"playSound:Deny", ServiceCommands_e::PlaySoundDeny},
{"playSound:Chosen", ServiceCommands_e::PlaySoundChosen}, {"playSound:Chosen", ServiceCommands_e::PlaySoundChosen},
{"setMaintanance", ServiceCommands_e::SetMaintanence},
}), }),
setCommands({ // cfg-topic setCommands({
// cfg-topic
{"volume", ServiceCommands_e::SetConfigVolume}, {"volume", ServiceCommands_e::SetConfigVolume},
{"promoDelay", ServiceCommands_e::SetConfigPromoDelay}, {"promoDelay", ServiceCommands_e::SetConfigPromoDelay},
}), }),
gameCommands({ // set-topic gameCommands({
// set-topic
{"gameStarted", GameModeCommands_e::GameStarted}, {"gameStarted", GameModeCommands_e::GameStarted},
{"gameFinished", GameModeCommands_e::GameFinished}, {"gameFinished", GameModeCommands_e::GameFinished},
{"stayLocked", GameModeCommands_e::GameNextTryLocked}, {"stayLocked", GameModeCommands_e::GameNextTryLocked},
{"releaseLock", GameModeCommands_e::GameNextTryRelease}, {"releaseLock", GameModeCommands_e::GameNextTryRelease},
{"abortTry", GameModeCommands_e::GameAbortTry}, {"abortTry", GameModeCommands_e::GameAbortTry},
{"forceAbort", GameModeCommands_e::GameAbortTry},
}), }),
subTopics{{setTopic, cfgTopic, resetTopic}}, subTopics{{setTopic, cfgTopic, resetTopic}},
client(name, cfg.BrockerUrl, subTopics, client(name, cfg.BrockerUrl, subTopics,
{cfg.MqttUser, cfg.MqttPassword}) { {cfg.MqttUser, cfg.MqttPassword},
MqttClient::LastWill{eventTopic, "offline", 1, false}) {
fmt::println("MQTT: Starting task:"); fmt::println("MQTT: Starting task:");
mqttCall = [this](string topic, string payload) { mqttCall = [this](string topic, string payload) {
fmt::print("MQTT: Got T:'{}' M:'{}'\n", topic, payload); fmt::print("MQTT: Got T:'{}' M:'{}'\n", topic, payload);
@@ -57,6 +66,7 @@ class MqttChannel {
client.registerCallback(mqttCall); client.registerCallback(mqttCall);
client.send(verTopic, fmt::format("{}", version)); client.send(verTopic, fmt::format("{}", version));
client.send(eventTopic, "online");
} }
std::unique_ptr<MqttQe> tryDeque() { std::unique_ptr<MqttQe> tryDeque() {
@@ -99,6 +109,11 @@ class MqttChannel {
if (serMsg->Topic == instance.resetTopic) { if (serMsg->Topic == instance.resetTopic) {
return; return;
} }
if (serMsg->Payload == "setMaintanance") {
std::string m{Modes[static_cast<int>(instance.IoStat.Mode)]};
instance.client.send(instance.verTopic, fmt::format("{}", instance.Version));
continue;
}
auto payload = serMsg->Payload; auto payload = serMsg->Payload;
if (payload == "mute") { if (payload == "mute") {
@@ -133,6 +148,9 @@ class MqttChannel {
auto code = instance.serviceCommands.at(payload); auto code = instance.serviceCommands.at(payload);
switch (code) { switch (code) {
case ServiceCommands_e::SetLockOpen: { case ServiceCommands_e::SetLockOpen: {
if (instance.IoStat.GameRunning) {
break;
}
instance.IoStat.SwordLatch.moveIn(); instance.IoStat.SwordLatch.moveIn();
auto tE = std::chrono::steady_clock::now() + 6s; auto tE = std::chrono::steady_clock::now() + 6s;
while (std::chrono::steady_clock::now() < tE) { while (std::chrono::steady_clock::now() < tE) {
@@ -142,6 +160,9 @@ class MqttChannel {
auto currE = mon.sampleCurrent(); auto currE = mon.sampleCurrent();
} break; } break;
case ServiceCommands_e::SetLockClose: { case ServiceCommands_e::SetLockClose: {
if (instance.IoStat.GameRunning) {
break;
}
instance.IoStat.SwordLatch.moveOut(); instance.IoStat.SwordLatch.moveOut();
auto tE = std::chrono::steady_clock::now() + 6s; auto tE = std::chrono::steady_clock::now() + 6s;
while (std::chrono::steady_clock::now() < tE) { while (std::chrono::steady_clock::now() < tE) {
@@ -184,7 +205,7 @@ class MqttChannel {
void sendEvent(std::string event) { void sendEvent(std::string event) {
try { try {
auto& s = IoStat; auto& s = IoStat;
fmt::println("Sending Event: {}",event); fmt::println("Sending Event: {}", event);
client.send(eventTopic, fmt::format("{}", event)); client.send(eventTopic, fmt::format("{}", event));
} catch (const exception& exc) { } catch (const exception& exc) {
fmt::println(stderr, "\nERROR: Unable to connect to Setup bridge: {}", exc.what()); fmt::println(stderr, "\nERROR: Unable to connect to Setup bridge: {}", exc.what());
@@ -195,6 +216,7 @@ class MqttChannel {
const std::map<string, ServiceCommands_e>& getSerCommands() { return serviceCommands; } const std::map<string, ServiceCommands_e>& getSerCommands() { return serviceCommands; }
private: private:
std::string Version;
SwordConfig Config; SwordConfig Config;
Queue<MqttQe> MasterQueue; Queue<MqttQe> MasterQueue;
Queue<MqttQe> MqttQueue; Queue<MqttQe> MqttQueue;
+118 -97
View File
@@ -8,12 +8,11 @@ using namespace std::literals::string_view_literals;
using namespace std::literals::chrono_literals; using namespace std::literals::chrono_literals;
using namespace std; using namespace std;
const string Version = "V 0.9.1"; const string Version = "V 0.10.0";
unique_ptr<SwordConfig> SwordCfg; unique_ptr<SwordConfig> SwordCfg;
unique_ptr<DeviceIoState> IoStat; unique_ptr<DeviceIoState> IoStat;
void processPromo(MqttChannel& mqtt, SeqLogger& log);
void processProduction(MqttChannel& mqtt, SeqLogger& log); void processProduction(MqttChannel& mqtt, SeqLogger& log);
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@@ -22,7 +21,7 @@ int main(int argc, char* argv[]) {
string modeArg = "test"; string modeArg = "test";
string assetsBasePath = "/home/user/assets/sword"; string assetsBasePath = "/home/user/assets/sword";
string brocker = "mqtts://excaliburs-erben.de:8883"; string brocker = "mqtts://excaliburs-erben.de:8883";
string topic = "outdoor/king-arthur/sword/"; string topic = "staging/outdoor/king-arthur/sword/";
string user = "userForMqttBrocker"; string user = "userForMqttBrocker";
string password = "passwordForMqttBorcker"; string password = "passwordForMqttBorcker";
string logUrl = "log.excaliburs-erben.de"; string logUrl = "log.excaliburs-erben.de";
@@ -60,9 +59,9 @@ int main(int argc, char* argv[]) {
fmt::println(" {}", file); fmt::println(" {}", file);
} }
InputPort sbPort(SwordEntryPin, "PinSEntry"); InputPort sbPort(SwordEntryPin, "PinSEntry", pal::GpioPort::Normal, pal::GpioPort::PullDown);
InputPort sePort(SwordEndPin, "PInSEnd"); InputPort sePort(SwordEndPin, "PInSEnd", pal::GpioPort::Normal, pal::GpioPort::PullDown);
InputPort spPort(SwordPulledPin, "PInSPull"); InputPort spPort(SwordPulledPin, "PInSPull", pal::GpioPort::Normal, pal::GpioPort::PullDown);
InputPort sparePort(sparePin, "spare"); InputPort sparePort(sparePin, "spare");
OutputPort mOut1(LinMotPin1, "M1:1"); OutputPort mOut1(LinMotPin1, "M1:1");
OutputPort mOut2(LinMotPin2, "M1:2"); OutputPort mOut2(LinMotPin2, "M1:2");
@@ -82,17 +81,13 @@ int main(int argc, char* argv[]) {
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch); IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
fmt::println("{}", app.get_description()); fmt::println("{}", app.get_description());
if (modeArg == "promo") { if (modeArg == "game") {
fmt::println("starting with promo"); fmt::println("starting with game");
IoStat->Mode = OpMode::PromoMode;
} else if (modeArg == "game") {
fmt::println("starting with promo");
IoStat->Mode = OpMode::GamingMode; IoStat->Mode = OpMode::GamingMode;
} else { } else {
fmt::println("unknown {}", modeArg); fmt::println("unknown {}", modeArg);
} }
constexpr array<const char*, 4> modes = {"Undefined", "Maintanance", "PromoMode", "Production"}; log.sendBootUp(Version, MqttChannel::Modes[static_cast<int>(IoStat->Mode)]);
log.sendBootUp(Version, modes[static_cast<int>(IoStat->Mode)]);
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log); MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
auto resetCall = [&]() { auto resetCall = [&]() {
@@ -111,10 +106,6 @@ int main(int argc, char* argv[]) {
Thread::sleep(500ms); Thread::sleep(500ms);
IoStat->tick(); IoStat->tick();
} break; } break;
case OpMode::PromoMode: {
fmt::println("Running PromoMode");
processPromo(mqtt, log);
} break;
case OpMode::GamingMode: { case OpMode::GamingMode: {
fmt::println("Running GamingMode"); fmt::println("Running GamingMode");
processProduction(mqtt, log); processProduction(mqtt, log);
@@ -133,75 +124,91 @@ enum MuteState {
WaitForNextDay, WaitForNextDay,
}; };
void processPromo(MqttChannel& mqtt, SeqLogger& log) { void processPromo(MqttChannel& mqtt, SeqLogger& log) {
auto muterS = MuteState::WaitForUnmute; static Tick tmu(1min);
Tick tmu(1min); static Tick tsf(30min);
Tick tsf(30min); static Waiter dP;
Waiter dP; if (IoStat->SwordPulled.isPosEdge()) {
auto& serCmds = mqtt.getSerCommands(); if (!IoStat->Mute) {
while (true) { if (dP.tick(IoStat->PromoDelay)) {
Thread::sleep(10ms); log.sendEvent("Pull", "Start Audio");
IoStat->tick();
if (IoStat->SwordPulled.isPosEdge()) {
if (!IoStat->Mute) {
if (dP.tick(IoStat->PromoDelay)) {
log.sendEvent("Pull", "Start Audio");
if (tsf.tick()) { if (tsf.tick()) {
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo); MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo);
} else {
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromoShort);
}
dP.sample();
fmt::println("Muting next for {}", IoStat->PromoDelay);
} else { } else {
fmt::println("still muted"); MediaPlayer::playWavFileAsync(SwordCfg->SoundPromoShort);
} }
dP.sample();
fmt::println("Muting next for {}", IoStat->PromoDelay);
} else {
fmt::println("await promo delay");
} }
} }
if (tmu.tick()) { }
auto now = std::chrono::system_clock::now(); if (tmu.tick()) {
std::time_t time = std::chrono::system_clock::to_time_t(now); static auto muterS = MuteState::WaitForUnmute;
std::tm* lTime = std::localtime(&time); auto now = std::chrono::system_clock::now();
int current_hour = lTime->tm_hour; std::time_t time = std::chrono::system_clock::to_time_t(now);
std::tm* lTime = std::localtime(&time);
int current_hour = lTime->tm_hour;
switch (muterS) { switch (muterS) {
case WaitForUnmute: case WaitForUnmute:
if (current_hour >= 9) { if (current_hour >= 9) {
fmt::println("[09:00 Threshold] Unmute"); fmt::println("[09:00 Threshold] Unmute");
log.sendEvent("Unmute", "Time for unmute"); log.sendEvent("Unmute", "Time for unmute");
IoStat->Mute = false; IoStat->Mute = false;
muterS = WaitForMute; muterS = WaitForMute;
} }
break; break;
case WaitForMute: case WaitForMute:
if (current_hour >= 21) { if (current_hour >= 21) {
fmt::println("[21:00 Threshold] Mute"); fmt::println("[21:00 Threshold] Mute");
log.sendEvent("Mute", "Time for mute"); log.sendEvent("Mute", "Time for mute");
IoStat->Mute = true; IoStat->Mute = true;
muterS = WaitForNextDay; muterS = WaitForNextDay;
} }
break; break;
case WaitForNextDay: case WaitForNextDay:
if (current_hour < 1) { if (current_hour < 1) {
fmt::println("[01:00 Threshold] new day"); fmt::println("[01:00 Threshold] new day");
muterS = WaitForUnmute; muterS = WaitForUnmute;
} }
break; break;
default: default:
break; break;
}
} }
} }
} }
void processProduction(MqttChannel& mqtt, SeqLogger& log) { void processProduction(MqttChannel& mqtt, SeqLogger& log) {
auto& serCmds = mqtt.getSerCommands();
auto& gameCmds = mqtt.getGameCommands(); auto& gameCmds = mqtt.getGameCommands();
static Tick tSend(500ms);
auto sendLogIfAborted = [&log, &mqtt](bool abort) {
if (abort) {
fmt::println("..abort");
log.sendEvent("Req", "Aborted");
mqtt.sendEvent("aborted");
}
};
auto testAbortCondition = [](MqttChannel& mqtt, string cond) -> bool {
auto abortMsg = mqtt.tryDequeueFor(10ms);
return (abortMsg && abortMsg->Payload == cond);
};
auto isDone = [](decltype(std::chrono::steady_clock::now()) until) -> bool {
return std::chrono::steady_clock::now() > until;
};
while (true) { while (true) {
auto msg = mqtt.tryDequeueFor(500ms); auto msg = mqtt.tryDequeueFor(10ms);
IoStat->tick(); IoStat->tick();
if (!msg) { if (!msg) {
if (!IoStat->GameRunning) {
processPromo(mqtt, log);
}
continue; continue;
} }
@@ -217,11 +224,15 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
case GameModeCommands_e::GameStarted: { case GameModeCommands_e::GameStarted: {
fmt::println("Got GameStarted"); fmt::println("Got GameStarted");
log.sendEvent("Req", "GameStarted"); log.sendEvent("Req", "GameStarted");
IoStat->GameRunning = true;
// todo abort all running tests
} break; } break;
case GameModeCommands_e::GameFinished: { case GameModeCommands_e::GameFinished: {
fmt::println("Got GameFinished"); fmt::println("Got GameFinished");
log.sendEvent("Req", "GameFinished"); log.sendEvent("Req", "GameFinished");
IoStat->GameRunning = false;
// todo abort all running tests
} break; } break;
case GameModeCommands_e::GameNextTryLocked: { case GameModeCommands_e::GameNextTryLocked: {
@@ -234,13 +245,13 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
// say: You are not the one // say: You are not the one
mqtt.sendEvent("pull"); mqtt.sendEvent("pull");
MediaPlayer::playWavFileSync(SwordCfg->getNextDeny()); MediaPlayer::playWavFileSync(SwordCfg->getNextDeny());
log.sendEvent("Req", "Pulled"); log.sendEvent("Game", "Pulled");
mqtt.sendEvent("pull-denied"); mqtt.sendEvent("pull-denied");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "abortTry");
abort = abortMsg && abortMsg->Payload == "abortTry";
} }
sendLogIfAborted(abort);
} break; } break;
case GameModeCommands_e::GameNextTryRelease: { case GameModeCommands_e::GameNextTryRelease: {
@@ -250,53 +261,63 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
IoStat->SwordLatch.moveIn(); IoStat->SwordLatch.moveIn();
while (!abort) { while (!abort) {
IoStat->SwordEnd.sample(); IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Passive) { IoStat->SwordEntry.sample();
fmt::println("pulling sword"); if ((!IoStat->SwordEnd.isActive()) || (!IoStat->SwordEntry.isActive())) {
fmt::println("..pulling sword");
if ((!IoStat->SwordEntry.isActive()) && IoStat->SwordEnd.isActive()) {
// Unplausible state
fmt::println("!Sensor Error");
log.sendEvent("Err", "Stuck sensor");
}
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "abortTry");
abort = abortMsg && abortMsg->Payload == "abortTry";
} }
while (!abort) { while (!abort) {
IoStat->SwordEntry.sample(); IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Passive) { if (!IoStat->SwordEntry.isActive()) {
fmt::println("sword pulled"); fmt::println("..sword pulled");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "abortTry");
abort = abortMsg && abortMsg->Payload == "abortTry";
}
if (abort) {
break;
} }
sendLogIfAborted(abort);
if (abort) break;
IoStat->SwordEnd.sample(); // still stuck?
bool stuckSensor = (!IoStat->SwordEntry.isActive()) && (IoStat->SwordEnd.isActive());
mqtt.sendEvent("pulled-out"); mqtt.sendEvent("pulled-out");
log.sendEvent("Req", "Pulled Out"); log.sendEvent("Game", "Pulled Out");
// say: You ARE the one // say: You ARE the one
MediaPlayer::playWavFileSync(SwordCfg->getNextAllow()); MediaPlayer::playWavFileSync(SwordCfg->getNextAllow());
log.sendEvent("Game", "Ceremony");
mqtt.sendEvent("ceremonyDone"); mqtt.sendEvent("ceremonyDone");
while (!abort) { while (!abort) {
IoStat->SwordEntry.sample(); IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Active) { if (IoStat->SwordEntry.isActive()) {
fmt::println("returning sword"); fmt::println("..returning sword");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "forceAbort");
abort = abortMsg && abortMsg->Payload == "abortTry"; }
if (stuckSensor) {
fmt::println("..extra wait due to stuck sensor");
Thread::sleep(3s);
} }
while (!abort) { while (!abort) {
IoStat->SwordEnd.sample(); IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Active) { if (IoStat->SwordEnd.isActive()) {
fmt::println("sword returned"); fmt::println("..sword returned");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "forceAbort");
abort = abortMsg && abortMsg->Payload == "abortTry";
} }
if (abort) { sendLogIfAborted(abort);
break; if (abort) break;
}
log.sendEvent("Req", "Put Back"); log.sendEvent("Game", "Put Back");
mqtt.sendEvent("put-in"); mqtt.sendEvent("put-in");
IoStat->SwordLatch.moveOut(); // Lock IoStat->SwordLatch.moveOut(); // Lock
Thread::sleep(3s); Thread::sleep(3s);
+6 -5
View File
@@ -46,7 +46,7 @@ class LinMot {
private: private:
OutputPort& _out1; OutputPort& _out1;
OutputPort& _out2; OutputPort& _out2;
bool _locked; bool _locked{};
void set(bool val) { void set(bool val) {
_out1.write(val); _out1.write(val);
_out2.write(!val); _out2.write(!val);
@@ -64,13 +64,13 @@ class CurrMon {
float val{}; float val{};
for (size_t i = 0; i < 8; i++) { for (size_t i = 0; i < 8; i++) {
val += sampe(); val += sample();
} }
_refVal = val / 8; _refVal = val / 8;
} }
float sampleCurrent() { float sampleCurrent() {
auto val = sampe() - _refVal; auto val = sample() - _refVal;
val = val / 0.264; val = val / 0.264;
fmt::println("{:.2} A", val); fmt::println("{:.2} A", val);
return val; return val;
@@ -80,7 +80,7 @@ class CurrMon {
float _refVal{}; float _refVal{};
AdcAds1115& _adc; AdcAds1115& _adc;
float sampe() { float sample() {
float volt; float volt;
_adc.readConversionVoltage(volt); _adc.readConversionVoltage(volt);
return volt; return volt;
@@ -106,6 +106,7 @@ class DeviceIoState {
} }
OpMode Mode{OpMode::Maintanance}; OpMode Mode{OpMode::Maintanance};
bool GameRunning{};
pal::InputTransAware& SwordEntry; pal::InputTransAware& SwordEntry;
pal::InputTransAware& SwordEnd; pal::InputTransAware& SwordEnd;
pal::InputTransAware& SwordPulled; pal::InputTransAware& SwordPulled;
@@ -238,7 +239,7 @@ class MediaPlayer {
static thread playWavFileThread(const string& filePath) { static thread playWavFileThread(const string& filePath) {
if (filePath.empty()) { if (filePath.empty()) {
fmt::println(stderr, "ERROR: Empty file path"); fmt::println(stderr, "ERROR: Empty file path");
thread([](){}); thread([](){ Thread::sleep(2s); });
} }
return thread([filePath]() { return thread([filePath]() {
auto cmd = fmt::format("aplay '{}'", filePath); auto cmd = fmt::format("aplay '{}'", filePath);
+2 -2
View File
@@ -1,6 +1,6 @@
add_executable(ThroneBridgeMain throneBridgeMain.cpp) add_executable(ThroneMain throneMain.cpp)
target_link_libraries(ThroneBridgeMain target_link_libraries(ThroneMain
PkgConfig::LIBGPIOD PkgConfig::LIBGPIOD
base base
palAdapt palAdapt
+2 -8
View File
@@ -180,11 +180,8 @@ int main(int argc, char* argv[]) {
SwordCfg.setVar(assetsBasePath, brocker, topic, user, password); SwordCfg.setVar(assetsBasePath, brocker, topic, user, password);
fmt::println("{}", app.get_description()); fmt::println("{}", app.get_description());
if (modeArg == "promo") { if (modeArg == "game") {
fmt::println("starting with promo"); fmt::println("starting with game");
Mode = OpMode::PromoMode;
} else if (modeArg == "game") {
fmt::println("starting with promo");
Mode = OpMode::GamingMode; Mode = OpMode::GamingMode;
} else { } else {
fmt::println("unknown {}", modeArg); fmt::println("unknown {}", modeArg);
@@ -232,10 +229,7 @@ int main(int argc, char* argv[]) {
switch (Mode) { switch (Mode) {
case OpMode::Maintanance: { case OpMode::Maintanance: {
fmt::println("Running Maintanance"); fmt::println("Running Maintanance");
// txQueue.emplace<ResponseTxMsg>(msg->code, 0);
processMaintanence(mqtt); processMaintanence(mqtt);
// auto e = make_unique<ResponseTxMsg>(msg->code, 0);
// txQueue.enqueue(move(e));
} break; } break;
case OpMode::PromoMode: { case OpMode::PromoMode: {
fmt::println("Running PromoMode"); fmt::println("Running PromoMode");
+2 -5
View File
@@ -180,11 +180,8 @@ int main(int argc, char* argv[]) {
SwordCfg.setVar(assetsBasePath, brocker, topic, user, password); SwordCfg.setVar(assetsBasePath, brocker, topic, user, password);
fmt::println("{}", app.get_description()); fmt::println("{}", app.get_description());
if (modeArg == "promo") { if (modeArg == "game") {
fmt::println("starting with promo"); fmt::println("starting with game");
Mode = OpMode::PromoMode;
} else if (modeArg == "game") {
fmt::println("starting with promo");
Mode = OpMode::GamingMode; Mode = OpMode::GamingMode;
} else { } else {
fmt::println("unknown {}", modeArg); fmt::println("unknown {}", modeArg);