step: less noise
This commit is contained in:
1 parent
2617407d18
commit
4fe0599988
5 files changed
+56
-37
No files matched your search
+1
-1
Submodule platform updated: dd23ecf4a7...b74f37d999.
+41
-10
@@ -17,6 +17,7 @@ class MqttChannel {
|
||||
eventTopic(cfg.StationPath + "event"),
|
||||
statTopic(cfg.StationPath + "stat"),
|
||||
resetTopic(cfg.StationPath + "reset"),
|
||||
sendTimeout(std::chrono::seconds{10}),
|
||||
|
||||
serviceCommands({
|
||||
// cfg-topic
|
||||
@@ -99,7 +100,7 @@ class MqttChannel {
|
||||
|
||||
static void runMasterService(Thread::Context& ctx, MqttChannel& instance, function<void()> resetCall) {
|
||||
while (true) {
|
||||
auto serMsg = instance.MasterQueue.tryDequeueFor(500ms);
|
||||
auto serMsg = instance.MasterQueue.tryDequeueFor(50ms);
|
||||
// only resetTopic and cfgTopic arrive here
|
||||
instance.sendStatusMessage();
|
||||
if (!serMsg) {
|
||||
@@ -174,18 +175,46 @@ class MqttChannel {
|
||||
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() {
|
||||
try {
|
||||
auto& s = IoStat;
|
||||
client.send(statTopic, fmt::format("M:{},snd:{},sS:{},sE:{},sP:{},lE:{},v:{},pD:{}",
|
||||
(int)IoStat.Mode,
|
||||
!s.Mute,
|
||||
s.SwordEntry.get(),
|
||||
s.SwordEnd.get(),
|
||||
s.SwordPulled.get(),
|
||||
s.SwordLatch.isLocked(),
|
||||
s.Volume,
|
||||
s.PromoDelay));
|
||||
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:{}",
|
||||
(int)IoStat.Mode,
|
||||
!s.Mute,
|
||||
s.SwordEntry.get(),
|
||||
s.SwordEnd.get(),
|
||||
s.SwordPulled.get(),
|
||||
s.SwordLatch.isLocked(),
|
||||
s.Volume,
|
||||
s.PromoDelay));
|
||||
sendTimeout.reset();
|
||||
}
|
||||
lastState.raw = ss.raw;
|
||||
} catch (const exception& exc) {
|
||||
fmt::println(stderr, "\nERROR: Unable to connect to Setup bridge: {}", exc.what());
|
||||
}
|
||||
@@ -217,6 +246,8 @@ class MqttChannel {
|
||||
const string eventTopic;
|
||||
const string statTopic;
|
||||
const string resetTopic;
|
||||
IoState lastState{};
|
||||
Tick sendTimeout;
|
||||
|
||||
const std::map<string, GameModeCommands_e> gameCommands;
|
||||
const std::map<string, ServiceCommands_e> serviceCommands;
|
||||
|
||||
+14
-12
@@ -8,7 +8,7 @@ using namespace std::literals::string_view_literals;
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace std;
|
||||
|
||||
const string Version = "V 0.10.0";
|
||||
const string Version = "V 0.10.1";
|
||||
|
||||
unique_ptr<SwordConfig> SwordCfg;
|
||||
unique_ptr<DeviceIoState> IoStat;
|
||||
@@ -47,6 +47,15 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
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);
|
||||
std::ostringstream cmdline;
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
@@ -78,14 +87,14 @@ int main(int argc, char* argv[]) {
|
||||
InputTransAware SwordEnd(sePort);
|
||||
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;
|
||||
try {
|
||||
static I2cMaster i2cDev(II2cMaster::ClockRate::_400k);
|
||||
static AdcAds1115 adc(i2cDev, AdcAds1115::I2CAddress::Gnd);
|
||||
// Check if the ADC is connected
|
||||
if (!adc.isConnected()) {
|
||||
fmt::println("Failed to connect ot Sensor {}", modeArg);
|
||||
fmt::println("Failed to connect ot Sensor");
|
||||
}
|
||||
static CurrMon mon(adc);
|
||||
pMon = &mon;
|
||||
@@ -98,14 +107,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
LinMot SwordLatch(mOut1, mOut2, *pMon, saveFile);
|
||||
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
|
||||
|
||||
fmt::println("{}", app.get_description());
|
||||
if (modeArg == "game") {
|
||||
fmt::println("starting with game");
|
||||
IoStat->Mode = OpMode::GamingMode;
|
||||
} else {
|
||||
fmt::println("unknown {}", modeArg);
|
||||
}
|
||||
IoStat->Mode = mode;
|
||||
|
||||
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
|
||||
auto resetCall = [&]() {
|
||||
@@ -148,7 +150,7 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
if (!IoStat->Mute) {
|
||||
if (dP.tick(IoStat->PromoDelay)) {
|
||||
log.sendEvent("Pull", "Start Audio");
|
||||
log.sendEvent("Promo-Pull", "Start Audio");
|
||||
|
||||
if (tsf.tick()) {
|
||||
MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo);
|
||||
|
||||
@@ -279,7 +279,6 @@ void processMaintanence(MqttChannel& mqtt) {
|
||||
}
|
||||
}
|
||||
IoStat->tick();
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +303,6 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
}
|
||||
if (chrono::steady_clock::now() > (tn + 1s)) {
|
||||
tn = chrono::steady_clock::now();
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,7 +339,6 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
while (true) {
|
||||
IoStat->SwordPulled.sample();
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
// say: You are not the one
|
||||
MediaPlayer::playWavFile(SwordCfg.getSoundDeny());
|
||||
Thread::sleep(15s);
|
||||
@@ -358,14 +355,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
while (true) {
|
||||
IoStat->SwordEnd.sample();
|
||||
if (IoStat->SwordEnd.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
IoStat->SwordEntry.sample();
|
||||
if (IoStat->SwordEntry.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -379,14 +374,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
while (true) {
|
||||
IoStat->SwordEnd.sample();
|
||||
if (IoStat->SwordEnd.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
IoStat->SwordEntry.sample();
|
||||
if (IoStat->SwordEntry.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +282,6 @@ void processMaintanence(MqttChannel& mqtt) {
|
||||
}
|
||||
}
|
||||
IoStat->tick();
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +306,6 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
}
|
||||
if (chrono::steady_clock::now() > (tn + 1s)) {
|
||||
tn = chrono::steady_clock::now();
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,7 +342,6 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
while (true) {
|
||||
IoStat->SwordPulled.sample();
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
// say: You are not the one
|
||||
MediaPlayer::playWavFile(SwordCfg.getSoundDeny());
|
||||
Thread::sleep(15s);
|
||||
@@ -361,14 +358,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
while (true) {
|
||||
IoStat->SwordEnd.sample();
|
||||
if (IoStat->SwordEnd.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
IoStat->SwordEntry.sample();
|
||||
if (IoStat->SwordEntry.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -382,14 +377,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
while (true) {
|
||||
IoStat->SwordEnd.sample();
|
||||
if (IoStat->SwordEnd.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
IoStat->SwordEntry.sample();
|
||||
if (IoStat->SwordEntry.isNegEdge()) {
|
||||
mqtt.sendStatusMessage(Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user