fix: PullDown
This commit is contained in:
1 parent
313e097a53
commit
b34a3a4acd
15 files changed
+101
-108
No files matched your search
Vendored
+1
-3
@@ -11,9 +11,7 @@
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/src/sword/SwordMain",
|
||||
"args": [
|
||||
//"test",
|
||||
// "promo",
|
||||
"game",
|
||||
"game", //"test",
|
||||
"${workspaceFolder}/assets",
|
||||
"-n", "SwordDebug",
|
||||
"-b", "'mqtts://excaliburs-erben.de:8883'",
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
; sudo nano /etc/systemd/system/SwordMain.service
|
||||
; sudo nano /etc/systemd/system/Sword.service
|
||||
[Unit]
|
||||
Description=Service for sword stationg
|
||||
After=network-online.target
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Autostart applications
|
||||
|
||||
```sh
|
||||
sudo nano /etc/systemd/system/SwordMain.service
|
||||
sudo nano /etc/systemd/system/Sword.service
|
||||
```
|
||||
|
||||
./
|
||||
```ini
|
||||
[Unit]
|
||||
Description=My Raspberry Pi Application
|
||||
@@ -14,7 +14,7 @@ Wants=network-online.target
|
||||
Type=simple
|
||||
User=gustice
|
||||
WorkingDirectory=/home/pi/SwordMain
|
||||
ExecStart=/home/pi/SwordMain/start.sh
|
||||
ExecStart=bash start.sh
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
@@ -27,12 +27,12 @@ chmod +x /home/pi/SwordMain/start.sh
|
||||
# Reload systemd
|
||||
sudo systemctl daemon-reload
|
||||
# Enable the service
|
||||
sudo systemctl enable SwordMain.service
|
||||
sudo systemctl enable Sword.service
|
||||
# start immediately
|
||||
sudo systemctl start SwordMain.service
|
||||
sudo systemctl start Sword.service
|
||||
# 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"
|
||||
+1
-1
Submodule platform updated: 6f6a0474cb...b998471c3f.
+1
-1
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
/home/gustice/workspace/swordStation/SwordMain \
|
||||
promo /home/gustice/workspace/swordStation/assets \
|
||||
game /home/gustice/workspace/swordStation/assets \
|
||||
-n Sword \
|
||||
-b mqtts://excaliburs-erben.de:8883 \
|
||||
-t outdoor/king-arthur/sword/ \
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ BROKER = "excaliburs-erben.de"
|
||||
PORT = 8883
|
||||
USERNAME = os.getenv("MQTT_USER", "exodususer")
|
||||
PASSWORD = os.getenv("MQTT_PASSWORD", "awesomeexodusoutdooradventures")
|
||||
BASE_TOPIC = "outdoor/king-arthur/sword"
|
||||
BASE_TOPIC = "staging/outdoor/king-arthur/sword"
|
||||
|
||||
YELLOW = "\033[93m"
|
||||
RESET = "\033[0m"
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
add_subdirectory(sword)
|
||||
add_subdirectory(throneBridge)
|
||||
add_subdirectory(throne)
|
||||
@@ -42,7 +42,7 @@ class SeqLogger {
|
||||
{"MessageTemplate", "[{App}]: Got {Event}; " + message},
|
||||
{"Properties", {
|
||||
{"App", AppName},
|
||||
{"Event", Version}
|
||||
{"Event", event}
|
||||
}}
|
||||
}
|
||||
})}
|
||||
|
||||
@@ -57,7 +57,6 @@ struct MqttQe {
|
||||
enum class OpMode {
|
||||
Undefined, // Enable in Game mode
|
||||
Maintanance = 1, // Set Maintanance mode
|
||||
PromoMode, // Enable PromoMode
|
||||
GamingMode, // Enable in Game mode
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ class MqttChannel {
|
||||
statTopic(cfg.StationPath + "stat"),
|
||||
resetTopic(cfg.StationPath + "reset"),
|
||||
|
||||
serviceCommands({ // cfg-topic
|
||||
serviceCommands({
|
||||
// cfg-topic
|
||||
{"openLock", ServiceCommands_e::SetLockOpen},
|
||||
{"closeLock", ServiceCommands_e::SetLockClose},
|
||||
{"mute", ServiceCommands_e::SetDisableSound},
|
||||
@@ -24,11 +25,13 @@ class MqttChannel {
|
||||
{"playSound:Deny", ServiceCommands_e::PlaySoundDeny},
|
||||
{"playSound:Chosen", ServiceCommands_e::PlaySoundChosen},
|
||||
}),
|
||||
setCommands({ // cfg-topic
|
||||
setCommands({
|
||||
// cfg-topic
|
||||
{"volume", ServiceCommands_e::SetConfigVolume},
|
||||
{"promoDelay", ServiceCommands_e::SetConfigPromoDelay},
|
||||
}),
|
||||
gameCommands({ // set-topic
|
||||
gameCommands({
|
||||
// set-topic
|
||||
{"gameStarted", GameModeCommands_e::GameStarted},
|
||||
{"gameFinished", GameModeCommands_e::GameFinished},
|
||||
{"stayLocked", GameModeCommands_e::GameNextTryLocked},
|
||||
@@ -133,6 +136,9 @@ class MqttChannel {
|
||||
auto code = instance.serviceCommands.at(payload);
|
||||
switch (code) {
|
||||
case ServiceCommands_e::SetLockOpen: {
|
||||
if (instance.IoStat.GameRunning) {
|
||||
break;
|
||||
}
|
||||
instance.IoStat.SwordLatch.moveIn();
|
||||
auto tE = std::chrono::steady_clock::now() + 6s;
|
||||
while (std::chrono::steady_clock::now() < tE) {
|
||||
@@ -142,6 +148,9 @@ class MqttChannel {
|
||||
auto currE = mon.sampleCurrent();
|
||||
} break;
|
||||
case ServiceCommands_e::SetLockClose: {
|
||||
if (instance.IoStat.GameRunning) {
|
||||
break;
|
||||
}
|
||||
instance.IoStat.SwordLatch.moveOut();
|
||||
auto tE = std::chrono::steady_clock::now() + 6s;
|
||||
while (std::chrono::steady_clock::now() < tE) {
|
||||
@@ -184,7 +193,7 @@ class MqttChannel {
|
||||
void sendEvent(std::string event) {
|
||||
try {
|
||||
auto& s = IoStat;
|
||||
fmt::println("Sending Event: {}",event);
|
||||
fmt::println("Sending Event: {}", event);
|
||||
client.send(eventTopic, fmt::format("{}", event));
|
||||
} catch (const exception& exc) {
|
||||
fmt::println(stderr, "\nERROR: Unable to connect to Setup bridge: {}", exc.what());
|
||||
|
||||
+62
-68
@@ -8,12 +8,11 @@ using namespace std::literals::string_view_literals;
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace std;
|
||||
|
||||
const string Version = "V 0.9.1";
|
||||
const string Version = "V 0.9.2";
|
||||
|
||||
unique_ptr<SwordConfig> SwordCfg;
|
||||
unique_ptr<DeviceIoState> IoStat;
|
||||
|
||||
void processPromo(MqttChannel& mqtt, SeqLogger& log);
|
||||
void processProduction(MqttChannel& mqtt, SeqLogger& log);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -22,7 +21,7 @@ int main(int argc, char* argv[]) {
|
||||
string modeArg = "test";
|
||||
string assetsBasePath = "/home/user/assets/sword";
|
||||
string brocker = "mqtts://excaliburs-erben.de:8883";
|
||||
string topic = "outdoor/king-arthur/sword/";
|
||||
string topic = "staging/outdoor/king-arthur/sword/";
|
||||
string user = "userForMqttBrocker";
|
||||
string password = "passwordForMqttBorcker";
|
||||
string logUrl = "log.excaliburs-erben.de";
|
||||
@@ -60,9 +59,9 @@ int main(int argc, char* argv[]) {
|
||||
fmt::println(" {}", file);
|
||||
}
|
||||
|
||||
InputPort sbPort(SwordEntryPin, "PinSEntry");
|
||||
InputPort sePort(SwordEndPin, "PInSEnd");
|
||||
InputPort spPort(SwordPulledPin, "PInSPull");
|
||||
InputPort sbPort(SwordEntryPin, "PinSEntry", pal::GpioPort::Normal, pal::GpioPort::PullDown);
|
||||
InputPort sePort(SwordEndPin, "PInSEnd", pal::GpioPort::Normal, pal::GpioPort::PullDown);
|
||||
InputPort spPort(SwordPulledPin, "PInSPull", pal::GpioPort::Normal, pal::GpioPort::PullDown);
|
||||
InputPort sparePort(sparePin, "spare");
|
||||
OutputPort mOut1(LinMotPin1, "M1:1");
|
||||
OutputPort mOut2(LinMotPin2, "M1:2");
|
||||
@@ -82,11 +81,8 @@ 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");
|
||||
if (modeArg == "game") {
|
||||
fmt::println("starting with game");
|
||||
IoStat->Mode = OpMode::GamingMode;
|
||||
} else {
|
||||
fmt::println("unknown {}", modeArg);
|
||||
@@ -111,10 +107,6 @@ int main(int argc, char* argv[]) {
|
||||
Thread::sleep(500ms);
|
||||
IoStat->tick();
|
||||
} break;
|
||||
case OpMode::PromoMode: {
|
||||
fmt::println("Running PromoMode");
|
||||
processPromo(mqtt, log);
|
||||
} break;
|
||||
case OpMode::GamingMode: {
|
||||
fmt::println("Running GamingMode");
|
||||
processProduction(mqtt, log);
|
||||
@@ -133,75 +125,74 @@ enum MuteState {
|
||||
WaitForNextDay,
|
||||
};
|
||||
void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
auto muterS = MuteState::WaitForUnmute;
|
||||
Tick tmu(1min);
|
||||
Tick tsf(30min);
|
||||
Waiter dP;
|
||||
auto& serCmds = mqtt.getSerCommands();
|
||||
while (true) {
|
||||
Thread::sleep(10ms);
|
||||
IoStat->tick();
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
if (!IoStat->Mute) {
|
||||
if (dP.tick(IoStat->PromoDelay)) {
|
||||
log.sendEvent("Pull", "Start Audio");
|
||||
static Tick tmu(1min);
|
||||
static Tick tsf(30min);
|
||||
static Waiter dP;
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
if (!IoStat->Mute) {
|
||||
if (dP.tick(IoStat->PromoDelay)) {
|
||||
log.sendEvent("Pull", "Start Audio");
|
||||
|
||||
if (tsf.tick()) {
|
||||
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo);
|
||||
} else {
|
||||
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromoShort);
|
||||
}
|
||||
dP.sample();
|
||||
fmt::println("Muting next for {}", IoStat->PromoDelay);
|
||||
if (tsf.tick()) {
|
||||
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo);
|
||||
} 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();
|
||||
std::time_t time = std::chrono::system_clock::to_time_t(now);
|
||||
std::tm* lTime = std::localtime(&time);
|
||||
int current_hour = lTime->tm_hour;
|
||||
}
|
||||
if (tmu.tick()) {
|
||||
static auto muterS = MuteState::WaitForUnmute;
|
||||
auto now = std::chrono::system_clock::now();
|
||||
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) {
|
||||
case WaitForUnmute:
|
||||
if (current_hour >= 9) {
|
||||
fmt::println("[09:00 Threshold] Unmute");
|
||||
log.sendEvent("Unmute", "Time for unmute");
|
||||
IoStat->Mute = false;
|
||||
muterS = WaitForMute;
|
||||
}
|
||||
break;
|
||||
case WaitForMute:
|
||||
if (current_hour >= 21) {
|
||||
fmt::println("[21:00 Threshold] Mute");
|
||||
log.sendEvent("Mute", "Time for mute");
|
||||
IoStat->Mute = true;
|
||||
muterS = WaitForNextDay;
|
||||
}
|
||||
break;
|
||||
case WaitForNextDay:
|
||||
if (current_hour < 1) {
|
||||
fmt::println("[01:00 Threshold] new day");
|
||||
muterS = WaitForUnmute;
|
||||
}
|
||||
break;
|
||||
switch (muterS) {
|
||||
case WaitForUnmute:
|
||||
if (current_hour >= 9) {
|
||||
fmt::println("[09:00 Threshold] Unmute");
|
||||
log.sendEvent("Unmute", "Time for unmute");
|
||||
IoStat->Mute = false;
|
||||
muterS = WaitForMute;
|
||||
}
|
||||
break;
|
||||
case WaitForMute:
|
||||
if (current_hour >= 21) {
|
||||
fmt::println("[21:00 Threshold] Mute");
|
||||
log.sendEvent("Mute", "Time for mute");
|
||||
IoStat->Mute = true;
|
||||
muterS = WaitForNextDay;
|
||||
}
|
||||
break;
|
||||
case WaitForNextDay:
|
||||
if (current_hour < 1) {
|
||||
fmt::println("[01:00 Threshold] new day");
|
||||
muterS = WaitForUnmute;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
auto& serCmds = mqtt.getSerCommands();
|
||||
auto& gameCmds = mqtt.getGameCommands();
|
||||
static Tick tSend(500ms);
|
||||
|
||||
while (true) {
|
||||
auto msg = mqtt.tryDequeueFor(500ms);
|
||||
auto msg = mqtt.tryDequeueFor(10ms);
|
||||
IoStat->tick();
|
||||
if (!msg) {
|
||||
if (!IoStat->GameRunning) {
|
||||
processPromo(mqtt, log);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -217,11 +208,13 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
case GameModeCommands_e::GameStarted: {
|
||||
fmt::println("Got GameStarted");
|
||||
log.sendEvent("Req", "GameStarted");
|
||||
IoStat->GameRunning = true;
|
||||
} break;
|
||||
|
||||
case GameModeCommands_e::GameFinished: {
|
||||
fmt::println("Got GameFinished");
|
||||
log.sendEvent("Req", "GameFinished");
|
||||
IoStat->GameRunning = false;
|
||||
} break;
|
||||
|
||||
case GameModeCommands_e::GameNextTryLocked: {
|
||||
@@ -273,6 +266,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
log.sendEvent("Req", "Pulled Out");
|
||||
// say: You ARE the one
|
||||
MediaPlayer::playWavFileSync(SwordCfg->getNextAllow());
|
||||
log.sendEvent("Req", "Ceremony");
|
||||
mqtt.sendEvent("ceremonyDone");
|
||||
|
||||
while (!abort) {
|
||||
|
||||
@@ -46,7 +46,7 @@ class LinMot {
|
||||
private:
|
||||
OutputPort& _out1;
|
||||
OutputPort& _out2;
|
||||
bool _locked;
|
||||
bool _locked{};
|
||||
void set(bool val) {
|
||||
_out1.write(val);
|
||||
_out2.write(!val);
|
||||
@@ -64,13 +64,13 @@ class CurrMon {
|
||||
|
||||
float val{};
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
val += sampe();
|
||||
val += sample();
|
||||
}
|
||||
_refVal = val / 8;
|
||||
}
|
||||
|
||||
float sampleCurrent() {
|
||||
auto val = sampe() - _refVal;
|
||||
auto val = sample() - _refVal;
|
||||
val = val / 0.264;
|
||||
fmt::println("{:.2} A", val);
|
||||
return val;
|
||||
@@ -80,7 +80,7 @@ class CurrMon {
|
||||
float _refVal{};
|
||||
AdcAds1115& _adc;
|
||||
|
||||
float sampe() {
|
||||
float sample() {
|
||||
float volt;
|
||||
_adc.readConversionVoltage(volt);
|
||||
return volt;
|
||||
@@ -106,6 +106,7 @@ class DeviceIoState {
|
||||
}
|
||||
|
||||
OpMode Mode{OpMode::Maintanance};
|
||||
bool GameRunning{};
|
||||
pal::InputTransAware& SwordEntry;
|
||||
pal::InputTransAware& SwordEnd;
|
||||
pal::InputTransAware& SwordPulled;
|
||||
@@ -238,7 +239,7 @@ class MediaPlayer {
|
||||
static thread playWavFileThread(const string& filePath) {
|
||||
if (filePath.empty()) {
|
||||
fmt::println(stderr, "ERROR: Empty file path");
|
||||
thread([](){});
|
||||
thread([](){ Thread::sleep(2s); });
|
||||
}
|
||||
return thread([filePath]() {
|
||||
auto cmd = fmt::format("aplay '{}'", filePath);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
add_executable(ThroneBridgeMain throneBridgeMain.cpp)
|
||||
add_executable(ThroneMain throneMain.cpp)
|
||||
|
||||
target_link_libraries(ThroneBridgeMain
|
||||
target_link_libraries(ThroneMain
|
||||
PkgConfig::LIBGPIOD
|
||||
base
|
||||
palAdapt
|
||||
|
||||
@@ -180,11 +180,8 @@ int main(int argc, char* argv[]) {
|
||||
SwordCfg.setVar(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");
|
||||
if (modeArg == "game") {
|
||||
fmt::println("starting with game");
|
||||
Mode = OpMode::GamingMode;
|
||||
} else {
|
||||
fmt::println("unknown {}", modeArg);
|
||||
@@ -232,10 +229,7 @@ int main(int argc, char* argv[]) {
|
||||
switch (Mode) {
|
||||
case OpMode::Maintanance: {
|
||||
fmt::println("Running Maintanance");
|
||||
// txQueue.emplace<ResponseTxMsg>(msg->code, 0);
|
||||
processMaintanence(mqtt);
|
||||
// auto e = make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
// txQueue.enqueue(move(e));
|
||||
} break;
|
||||
case OpMode::PromoMode: {
|
||||
fmt::println("Running PromoMode");
|
||||
|
||||
@@ -180,11 +180,8 @@ int main(int argc, char* argv[]) {
|
||||
SwordCfg.setVar(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");
|
||||
if (modeArg == "game") {
|
||||
fmt::println("starting with game");
|
||||
Mode = OpMode::GamingMode;
|
||||
} else {
|
||||
fmt::println("unknown {}", modeArg);
|
||||
|
||||
Reference in new issue
Block a user