From f93a8aaabd4fff86013e67c07fc2bfbeb1625d02 Mon Sep 17 00:00:00 2001 From: Jakob Gegeniger Date: Wed, 9 Sep 2026 23:21:48 +0200 Subject: [PATCH] new featres --- .gitignore | 3 ++- doc/setup.md | 9 +++++++++ makefile | 19 ++++++------------- scripts/run.sh | 9 +++++++++ scripts/test.sh | 9 +++++++++ src/sword/swordMain.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 scripts/run.sh create mode 100644 scripts/test.sh diff --git a/.gitignore b/.gitignore index 5b79a54..548c5a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ -.cache/ \ No newline at end of file +.cache/ +deploy/ \ No newline at end of file diff --git a/doc/setup.md b/doc/setup.md index cea2678..c4c86ed 100644 --- a/doc/setup.md +++ b/doc/setup.md @@ -21,3 +21,12 @@ amixer sset Master 10%- apt install -y libpaho-mqttpp-dev + +## Reboot + +```sh +sudo crontab -e +``` +```txt +0 3 * * * /sbin/reboot +``` \ No newline at end of file diff --git a/makefile b/makefile index 3200b60..7472b88 100644 --- a/makefile +++ b/makefile @@ -2,16 +2,9 @@ build: cmake -B build -S . cmake --build build --target SwordMain -run: - build/src/SwordMain promo ./assets -b "mqtts://nerdyssey.de:8883" -t "outdoor/king-arthur/sword/" -p "awesomeexodusoutdooradventures" -u "exodususer" -l "log.nerdyssey.de" -k "uYpJC6WyZAbFK2MUgwNH" - -test: - build/src/SwordMain promo ./assets -b "mqtts://nerdyssey.de:8883" -t "staging/outdoor/king-arthur/sword/" -p "awesomeexodusoutdooradventures" -u "exodususer" -l "log.nerdyssey.de" -k "uYpJC6WyZAbFK2MUgwNH" - -# deploy: -# cp build/src/SwordMain . -# tar -cfz swordMain.tar.gz assets SwordMain -# curl --user your_username:your_access_token --upload-file ./swordMain.tar.gz git.nerdyssey.de/exodus/burg-stett-king-arth-sword/0.5.0/swordMain.tar.gz - -# download: -# curl -O https://gitea.example.com/api/packages/my_organization/generic/my-app/1.0.0/my-app-linux-amd64.tar.gz \ No newline at end of file +pack_sword: + @mkdir -p deploy/sword + @cp build/src/sword/SwordMain deploy/sword + @cp -r assets deploy/sword + @cd deploy && tar -czvf swordMain.tar.gz sword + @echo .. extract with "tar -xzvf" diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100644 index 0000000..a54e7fb --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash +/home/gustice/workspace/swordStation/SwordMain \ + promo /home/gustice/workspace/swordStation/assets \ + -b mqtts://nerdyssey.de:8883 \ + -t outdoor/king-arthur/sword/ \ + -p awesomeexodusoutdooradventures \ + -u exodususer \ + -l "log.nerdyssey.de" \ + -k "uYpJC6WyZAbFK2MUgwNH" \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100644 index 0000000..db5c9e5 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +/home/gustice/workspace/swordStation/SwordMain \ + test /home/gustice/workspace/swordStation/assets \ + -b mqtts://nerdyssey.de:8883 \ + -t staging/outdoor/king-arthur/sword/ \ + -p awesomeexodusoutdooradventures \ + -u exodususer \ + -l "log.nerdyssey.de" \ + -k "uYpJC6WyZAbFK2MUgwNH" \ No newline at end of file diff --git a/src/sword/swordMain.cpp b/src/sword/swordMain.cpp index b2434fe..ba05737 100644 --- a/src/sword/swordMain.cpp +++ b/src/sword/swordMain.cpp @@ -118,7 +118,14 @@ int main(int argc, char* argv[]) { return EXIT_SUCCESS; } +enum MuteState { + WaitForUnmute, + WaitForMute, + WaitForNextDay, +}; void processPromo(MqttChannel& mqtt, SeqLogger& log) { + auto muterS = MuteState::WaitForUnmute; + Tick tmu(1min); Tick tn(1s); Tick tsf(30min); auto& serCmds = mqtt.getSerCommands(); @@ -143,6 +150,40 @@ 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); + 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; + + default: + break; + } + } } }