step: less noise

This commit is contained in:
Jakob Gegeniger committed 2026-11-03 00:37:12 +01:00
1 parent 2617407d18
commit 4fe0599988
5 files changed
+47 -28

No files matched your search

Submodule platform updated: dd23ecf4a7...b74f37d999.
+32 -1
View File
@@ -17,6 +17,7 @@ class MqttChannel {
eventTopic(cfg.StationPath + "event"), eventTopic(cfg.StationPath + "event"),
statTopic(cfg.StationPath + "stat"), statTopic(cfg.StationPath + "stat"),
resetTopic(cfg.StationPath + "reset"), resetTopic(cfg.StationPath + "reset"),
sendTimeout(std::chrono::seconds{10}),
serviceCommands({ serviceCommands({
// cfg-topic // cfg-topic
@@ -99,7 +100,7 @@ class MqttChannel {
static void runMasterService(Thread::Context& ctx, MqttChannel& instance, function<void()> resetCall) { static void runMasterService(Thread::Context& ctx, MqttChannel& instance, function<void()> resetCall) {
while (true) { while (true) {
auto serMsg = instance.MasterQueue.tryDequeueFor(500ms); auto serMsg = instance.MasterQueue.tryDequeueFor(50ms);
// only resetTopic and cfgTopic arrive here // only resetTopic and cfgTopic arrive here
instance.sendStatusMessage(); instance.sendStatusMessage();
if (!serMsg) { if (!serMsg) {
@@ -174,9 +175,34 @@ class MqttChannel {
resetCall(); resetCall();
} }
union IoState {
uint32_t raw{};
struct {
uint32_t mode : 2;
uint32_t mute : 1;
uint32_t sS : 1;
uint32_t sE : 1;
uint32_t sP : 1;
uint32_t lE : 1;
uint32_t v : 3;
uint32_t pD : 4;
} state;
};
void sendStatusMessage() { void sendStatusMessage() {
try { try {
auto& s = IoStat; auto& s = IoStat;
IoState ss;
ss.state.mode = (int)IoStat.Mode;
ss.state.mute = s.Mute;
ss.state.sS = s.SwordEntry.get();
ss.state.sE = s.SwordEnd.get();
ss.state.sP = s.SwordPulled.get();
ss.state.lE = s.SwordLatch.isLocked();
ss.state.v = s.Volume;
ss.state.pD = s.PromoDelay.count();
if ((ss.raw != lastState.raw) || sendTimeout.tick()) {
client.send(statTopic, fmt::format("M:{},snd:{},sS:{},sE:{},sP:{},lE:{},v:{},pD:{}", client.send(statTopic, fmt::format("M:{},snd:{},sS:{},sE:{},sP:{},lE:{},v:{},pD:{}",
(int)IoStat.Mode, (int)IoStat.Mode,
!s.Mute, !s.Mute,
@@ -186,6 +212,9 @@ class MqttChannel {
s.SwordLatch.isLocked(), s.SwordLatch.isLocked(),
s.Volume, s.Volume,
s.PromoDelay)); s.PromoDelay));
sendTimeout.reset();
}
lastState.raw = ss.raw;
} 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());
} }
@@ -217,6 +246,8 @@ class MqttChannel {
const string eventTopic; const string eventTopic;
const string statTopic; const string statTopic;
const string resetTopic; const string resetTopic;
IoState lastState{};
Tick sendTimeout;
const std::map<string, GameModeCommands_e> gameCommands; const std::map<string, GameModeCommands_e> gameCommands;
const std::map<string, ServiceCommands_e> serviceCommands; const std::map<string, ServiceCommands_e> serviceCommands;
+14 -12
View File
@@ -8,7 +8,7 @@ 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.10.0"; const string Version = "V 0.10.1";
unique_ptr<SwordConfig> SwordCfg; unique_ptr<SwordConfig> SwordCfg;
unique_ptr<DeviceIoState> IoStat; unique_ptr<DeviceIoState> IoStat;
@@ -47,6 +47,15 @@ int main(int argc, char* argv[]) {
fmt::println("## Starting Sword Station {}", Version); fmt::println("## Starting Sword Station {}", Version);
OpMode mode{OpMode::Maintanance};
fmt::println("{}", app.get_description());
if (modeArg == "game") {
fmt::println("starting with game");
mode = OpMode::GamingMode;
} else {
fmt::println("unknown {}", modeArg);
}
CLI11_PARSE(app, argc, argv); CLI11_PARSE(app, argc, argv);
std::ostringstream cmdline; std::ostringstream cmdline;
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
@@ -78,14 +87,14 @@ int main(int argc, char* argv[]) {
InputTransAware SwordEnd(sePort); InputTransAware SwordEnd(sePort);
InputTransAware SwordPulled(spPort); InputTransAware SwordPulled(spPort);
log.sendBootUp(Version, MqttChannel::Modes[static_cast<int>(IoStat->Mode)]); log.sendBootUp(Version, MqttChannel::Modes[static_cast<int>(mode)]);
ICurrentMon* pMon = nullptr; ICurrentMon* pMon = nullptr;
try { try {
static I2cMaster i2cDev(II2cMaster::ClockRate::_400k); static I2cMaster i2cDev(II2cMaster::ClockRate::_400k);
static AdcAds1115 adc(i2cDev, AdcAds1115::I2CAddress::Gnd); static AdcAds1115 adc(i2cDev, AdcAds1115::I2CAddress::Gnd);
// Check if the ADC is connected // Check if the ADC is connected
if (!adc.isConnected()) { if (!adc.isConnected()) {
fmt::println("Failed to connect ot Sensor {}", modeArg); fmt::println("Failed to connect ot Sensor");
} }
static CurrMon mon(adc); static CurrMon mon(adc);
pMon = &mon; pMon = &mon;
@@ -98,14 +107,7 @@ int main(int argc, char* argv[]) {
} }
LinMot SwordLatch(mOut1, mOut2, *pMon, saveFile); LinMot SwordLatch(mOut1, mOut2, *pMon, saveFile);
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch); IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
IoStat->Mode = mode;
fmt::println("{}", app.get_description());
if (modeArg == "game") {
fmt::println("starting with game");
IoStat->Mode = OpMode::GamingMode;
} else {
fmt::println("unknown {}", modeArg);
}
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log); MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
auto resetCall = [&]() { auto resetCall = [&]() {
@@ -148,7 +150,7 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
if (IoStat->SwordPulled.isPosEdge()) { if (IoStat->SwordPulled.isPosEdge()) {
if (!IoStat->Mute) { if (!IoStat->Mute) {
if (dP.tick(IoStat->PromoDelay)) { if (dP.tick(IoStat->PromoDelay)) {
log.sendEvent("Pull", "Start Audio"); log.sendEvent("Promo-Pull", "Start Audio");
if (tsf.tick()) { if (tsf.tick()) {
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo); MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo);
-7
View File
@@ -279,7 +279,6 @@ void processMaintanence(MqttChannel& mqtt) {
} }
} }
IoStat->tick(); IoStat->tick();
mqtt.sendStatusMessage(Mode);
} }
} }
@@ -304,7 +303,6 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
} }
if (chrono::steady_clock::now() > (tn + 1s)) { if (chrono::steady_clock::now() > (tn + 1s)) {
tn = chrono::steady_clock::now(); tn = chrono::steady_clock::now();
mqtt.sendStatusMessage(Mode);
} }
} }
} }
@@ -341,7 +339,6 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
while (true) { while (true) {
IoStat->SwordPulled.sample(); IoStat->SwordPulled.sample();
if (IoStat->SwordPulled.isPosEdge()) { if (IoStat->SwordPulled.isPosEdge()) {
mqtt.sendStatusMessage(Mode);
// say: You are not the one // say: You are not the one
MediaPlayer::playWavFile(SwordCfg.getSoundDeny()); MediaPlayer::playWavFile(SwordCfg.getSoundDeny());
Thread::sleep(15s); Thread::sleep(15s);
@@ -358,14 +355,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
while (true) { while (true) {
IoStat->SwordEnd.sample(); IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.isNegEdge()) { if (IoStat->SwordEnd.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }
while (true) { while (true) {
IoStat->SwordEntry.sample(); IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.isNegEdge()) { if (IoStat->SwordEntry.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }
@@ -379,14 +374,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
while (true) { while (true) {
IoStat->SwordEnd.sample(); IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.isNegEdge()) { if (IoStat->SwordEnd.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }
while (true) { while (true) {
IoStat->SwordEntry.sample(); IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.isNegEdge()) { if (IoStat->SwordEntry.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }
-7
View File
@@ -282,7 +282,6 @@ void processMaintanence(MqttChannel& mqtt) {
} }
} }
IoStat->tick(); IoStat->tick();
mqtt.sendStatusMessage(Mode);
} }
} }
@@ -307,7 +306,6 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
} }
if (chrono::steady_clock::now() > (tn + 1s)) { if (chrono::steady_clock::now() > (tn + 1s)) {
tn = chrono::steady_clock::now(); tn = chrono::steady_clock::now();
mqtt.sendStatusMessage(Mode);
} }
} }
} }
@@ -344,7 +342,6 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
while (true) { while (true) {
IoStat->SwordPulled.sample(); IoStat->SwordPulled.sample();
if (IoStat->SwordPulled.isPosEdge()) { if (IoStat->SwordPulled.isPosEdge()) {
mqtt.sendStatusMessage(Mode);
// say: You are not the one // say: You are not the one
MediaPlayer::playWavFile(SwordCfg.getSoundDeny()); MediaPlayer::playWavFile(SwordCfg.getSoundDeny());
Thread::sleep(15s); Thread::sleep(15s);
@@ -361,14 +358,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
while (true) { while (true) {
IoStat->SwordEnd.sample(); IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.isNegEdge()) { if (IoStat->SwordEnd.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }
while (true) { while (true) {
IoStat->SwordEntry.sample(); IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.isNegEdge()) { if (IoStat->SwordEntry.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }
@@ -382,14 +377,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
while (true) { while (true) {
IoStat->SwordEnd.sample(); IoStat->SwordEnd.sample();
if (IoStat->SwordEnd.isNegEdge()) { if (IoStat->SwordEnd.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }
while (true) { while (true) {
IoStat->SwordEntry.sample(); IoStat->SwordEntry.sample();
if (IoStat->SwordEntry.isNegEdge()) { if (IoStat->SwordEntry.isNegEdge()) {
mqtt.sendStatusMessage(Mode);
break; break;
} }
} }