refactoring
This commit is contained in:
1 parent
eb1c84cf05
commit
92423c52de
8 files changed
+655
-57
No files matched your search
+11
-11
@@ -8,12 +8,12 @@ class MqttChannel {
|
||||
: Config(cfg),
|
||||
IoStat(ioStat),
|
||||
Logger(log),
|
||||
runTopic(cfg.getStationPath() + "run"),
|
||||
cfgTopic(cfg.getStationPath() + "cfg"),
|
||||
verTopic(cfg.getStationPath() + "ver"),
|
||||
eventTopic(cfg.getStationPath() + "event"),
|
||||
statTopic(cfg.getStationPath() + "stat"),
|
||||
resetTopic(cfg.getStationPath() + "reset"),
|
||||
runTopic(cfg.StationPath + "run"),
|
||||
cfgTopic(cfg.StationPath + "cfg"),
|
||||
verTopic(cfg.StationPath + "ver"),
|
||||
eventTopic(cfg.StationPath + "event"),
|
||||
statTopic(cfg.StationPath + "stat"),
|
||||
resetTopic(cfg.StationPath + "reset"),
|
||||
|
||||
gameCommands({
|
||||
{"gameStarted", GameModeCommands_e::GameStarted},
|
||||
@@ -36,9 +36,9 @@ class MqttChannel {
|
||||
}),
|
||||
subTopics{{runTopic, cfgTopic, resetTopic}},
|
||||
client("Sword",
|
||||
cfg.getBrockerUrl(),
|
||||
cfg.BrockerUrl,
|
||||
subTopics,
|
||||
{cfg.getMqttUser(), cfg.getMqttPassword()}) {
|
||||
{cfg.MqttUser, cfg.MqttPassword}) {
|
||||
fmt::println("MQTT: Starting task:");
|
||||
mqttCall = [this](string topic, string payload) {
|
||||
if (topic == resetTopic ||
|
||||
@@ -134,13 +134,13 @@ class MqttChannel {
|
||||
instance.IoStat.SwordLatch.moveOut();
|
||||
} break;
|
||||
case ServiceCommands_e::PlaySoundPromo: {
|
||||
MediaPlayer::playWavFile(instance.Config.getSoundPromo());
|
||||
MediaPlayer::playWavFile(instance.Config.SoundPromo);
|
||||
} break;
|
||||
case ServiceCommands_e::PlaySoundDeny: {
|
||||
MediaPlayer::playWavFile(instance.Config.getSoundDeny());
|
||||
MediaPlayer::playWavFile(instance.Config.SoundDeny);
|
||||
} break;
|
||||
case ServiceCommands_e::PlaySoundChosen: {
|
||||
MediaPlayer::playWavFile(instance.Config.getSoundAllow());
|
||||
MediaPlayer::playWavFile(instance.Config.SoundAllow);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-9
@@ -1,4 +1,5 @@
|
||||
#include "swordMain.hpp"
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "mqttChannel.hpp"
|
||||
|
||||
@@ -11,7 +12,7 @@ constexpr uint8_t VersionArr[4] = {'V', 0, 8, 0};
|
||||
const string Version = "V 0.8.0";
|
||||
// const string Version = fmt::format("{} {}.{}.{}", VersionArr[0], VersionArr[1], VersionArr[2], VersionArr[3]);
|
||||
|
||||
SwordConfig SwordCfg{};
|
||||
unique_ptr<SwordConfig> SwordCfg;
|
||||
unique_ptr<DeviceIoState> IoStat;
|
||||
OpMode Mode = OpMode::Maintanance;
|
||||
|
||||
@@ -40,7 +41,7 @@ int main(int argc, char* argv[]) {
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
SeqLogger log(logUrl, logApiKey, "Sword");
|
||||
SwordCfg.setVar(assetsBasePath, brocker, topic, user, password);
|
||||
SwordCfg = make_unique<SwordConfig>(assetsBasePath, brocker, topic, user, password);
|
||||
|
||||
fmt::println("{}", app.get_description());
|
||||
if (modeArg == "promo") {
|
||||
@@ -79,7 +80,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
|
||||
|
||||
MqttChannel mqtt(Version, SwordCfg, *IoStat, log);
|
||||
MqttChannel mqtt(Version, *SwordCfg, *IoStat, log);
|
||||
auto resetCall = [&]() {
|
||||
log.sendEvent("Reset", "");
|
||||
};
|
||||
@@ -118,7 +119,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
auto tn = chrono::steady_clock::now();
|
||||
Tick tn(1s);
|
||||
Tick tsf(30min);
|
||||
auto& serCmds = mqtt.getSerCommands();
|
||||
while (true) {
|
||||
Thread::sleep(10ms);
|
||||
@@ -126,14 +128,19 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
if (!IoStat->Mute) {
|
||||
log.sendEvent("Pull", "Start Audio");
|
||||
MediaPlayer::playWavFile(SwordCfg.getSoundPromo());
|
||||
|
||||
if (tsf.tick()) {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromo);
|
||||
} else {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromoShort);
|
||||
}
|
||||
|
||||
fmt::println("Waiting for {}", IoStat->PromoDelay);
|
||||
Thread::sleep(IoStat->PromoDelay);
|
||||
fmt::println("Waiting done");
|
||||
}
|
||||
}
|
||||
if (chrono::steady_clock::now() > (tn + 1s)) {
|
||||
tn = chrono::steady_clock::now();
|
||||
if (tn.tick()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +174,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
// say: You are not the one
|
||||
MediaPlayer::playWavFile(SwordCfg.getSoundDeny());
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundDeny);
|
||||
Thread::sleep(15s);
|
||||
log.sendEvent("Req", "Pulled");
|
||||
mqtt.sendEvent("pull");
|
||||
@@ -196,7 +203,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
mqtt.sendEvent("pulled-out");
|
||||
log.sendEvent("Req", "Pulled Out");
|
||||
// say: You ARE the one
|
||||
MediaPlayer::playWavFile(SwordCfg.getSoundAllow());
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundAllow);
|
||||
Thread::sleep(15s);
|
||||
mqtt.sendEvent("ceremonyDone");
|
||||
|
||||
|
||||
+21
-36
@@ -28,7 +28,6 @@
|
||||
#include "textUtils.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
|
||||
class LinMot {
|
||||
public:
|
||||
LinMot(OutputPort& o1, OutputPort& o2)
|
||||
@@ -79,45 +78,31 @@ class DeviceIoState {
|
||||
bool Mute{false};
|
||||
};
|
||||
|
||||
class SwordConfig {
|
||||
public:
|
||||
std::string getSoundPromo() { return soundPromo; }
|
||||
std::string getSoundDeny() { return soundDeny; }
|
||||
std::string getSoundAllow() { return soundAllow; }
|
||||
std::string getBrockerUrl() { return brockerUrl; }
|
||||
std::string getMqttUser() { return mqttUser; }
|
||||
std::string getMqttPassword() { return mqttPassword; }
|
||||
std::string getStationPath() { return stationPath; }
|
||||
|
||||
void setVar(std::string base,
|
||||
struct SwordConfig {
|
||||
SwordConfig(std::string base,
|
||||
std::string brocker, std::string topic,
|
||||
std::string user, std::string passwd) {
|
||||
if (wasSet) {
|
||||
return;
|
||||
}
|
||||
soundPromo = base + soundPromo;
|
||||
soundDeny = base + soundDeny;
|
||||
soundAllow = base + soundAllow;
|
||||
std::string user, std::string passwd)
|
||||
: AssetBase(base),
|
||||
SoundPromo{base + "/promo.wav"},
|
||||
SoundPromoShort{base + "/promoShort.wav"},
|
||||
SoundDeny{base + "/deny.wav"},
|
||||
SoundAllow{base + "/allow.wav"},
|
||||
BrockerUrl(brocker),
|
||||
StationPath(topic),
|
||||
MqttUser(user),
|
||||
MqttPassword(passwd) {}
|
||||
|
||||
brockerUrl = brocker;
|
||||
stationPath = topic;
|
||||
mqttUser = user;
|
||||
mqttPassword = passwd;
|
||||
wasSet = true;
|
||||
}
|
||||
const std::string AssetBase;
|
||||
|
||||
private:
|
||||
bool wasSet{};
|
||||
std::string assetBase{};
|
||||
std::string soundPromo{"/promo.wav"};
|
||||
std::string soundPromoShort{"/promoShort.wav"};
|
||||
std::string soundDeny{"/deny.wav"};
|
||||
std::string soundAllow{"/allow.wav"};
|
||||
const std::string SoundPromo;
|
||||
const std::string SoundPromoShort;
|
||||
const std::string SoundDeny;
|
||||
const std::string SoundAllow;
|
||||
|
||||
std::string brockerUrl;
|
||||
std::string mqttUser;
|
||||
std::string mqttPassword;
|
||||
std::string stationPath;
|
||||
const std::string BrockerUrl;
|
||||
const std::string StationPath;
|
||||
const std::string MqttUser;
|
||||
const std::string MqttPassword;
|
||||
};
|
||||
|
||||
class MediaPlayer {
|
||||
|
||||
Reference in new issue
Block a user