currentMeas
This commit is contained in:
1 parent
f93a8aaabd
commit
d2b8e1de3c
9 files changed
+92
-27
No files matched your search
+25
-14
@@ -8,9 +8,7 @@ using namespace std::literals::string_view_literals;
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace std;
|
||||
|
||||
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]);
|
||||
const string Version = "V 0.9.0";
|
||||
|
||||
unique_ptr<SwordConfig> SwordCfg;
|
||||
unique_ptr<DeviceIoState> IoStat;
|
||||
@@ -21,6 +19,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
CLI::App app{"Sword Firmware"};
|
||||
string appName = "SwordDebug";
|
||||
string modeArg = "test";
|
||||
string assetsBasePath = "/home/user/assets/sword";
|
||||
string brocker = "mqtts://nerdyssey.de:8883";
|
||||
@@ -31,6 +30,7 @@ int main(int argc, char* argv[]) {
|
||||
string logApiKey = "uYpJC6WyZAbFK2MUgwNH";
|
||||
app.add_option("startmode", modeArg, "Startup mode")->required();
|
||||
app.add_option("basepath", assetsBasePath, "Base bath for assets")->required();
|
||||
app.add_option("-n,--name", appName, "Name of App");
|
||||
app.add_option("-b,--brocker", brocker, "MQTT Topic URL");
|
||||
app.add_option("-t,--topic", topic, "MQTT Topic");
|
||||
app.add_option("-p,--passwd", password, "MQTT Brocker password");
|
||||
@@ -40,7 +40,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
SeqLogger log(logUrl, logApiKey, "Sword");
|
||||
SeqLogger log(logUrl, logApiKey, appName);
|
||||
SwordCfg = make_unique<SwordConfig>(assetsBasePath, brocker, topic, user, password);
|
||||
|
||||
fmt::println("{}", app.get_description());
|
||||
@@ -78,15 +78,23 @@ int main(int argc, char* argv[]) {
|
||||
InputTransAware SwordPulled(spPort);
|
||||
LinMot SwordLatch(mOut1, mOut2);
|
||||
|
||||
I2cMaster i2cDev(II2cMaster::ClockRate::_400k);
|
||||
AdcAds1115 adc(i2cDev, AdcAds1115::I2CAddress::Gnd);
|
||||
// Check if the ADC is connected
|
||||
if (!adc.isConnected()) {
|
||||
fmt::println("Failed to connect ot Sensor {}", modeArg);
|
||||
}
|
||||
CurrMon mon(adc);
|
||||
|
||||
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
|
||||
|
||||
MqttChannel mqtt(Version, *SwordCfg, *IoStat, log);
|
||||
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
|
||||
auto resetCall = [&]() {
|
||||
log.sendEvent("Reset", "");
|
||||
};
|
||||
|
||||
mqtt.flushInput();
|
||||
static auto conTask = Thread::createExplicit("MqttTask", MqttChannel::runMasterService, ref(mqtt), resetCall);
|
||||
static auto conTask = Thread::createExplicit("MqttTask", MqttChannel::runMasterService, ref(mqtt), resetCall, ref(mon));
|
||||
|
||||
SwordLatch.moveOut();
|
||||
fmt::println("Running App");
|
||||
@@ -128,23 +136,26 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) {
|
||||
Tick tmu(1min);
|
||||
Tick tn(1s);
|
||||
Tick tsf(30min);
|
||||
Waiter dP;
|
||||
auto& serCmds = mqtt.getSerCommands();
|
||||
while (true) {
|
||||
Thread::sleep(10ms);
|
||||
IoStat->tick();
|
||||
if (IoStat->SwordPulled.isPosEdge()) {
|
||||
if (!IoStat->Mute) {
|
||||
log.sendEvent("Pull", "Start Audio");
|
||||
if (dP.tick(IoStat->PromoDelay)) {
|
||||
log.sendEvent("Pull", "Start Audio");
|
||||
|
||||
if (tsf.tick()) {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromo);
|
||||
if (tsf.tick()) {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromo);
|
||||
} else {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromoShort);
|
||||
}
|
||||
dP.sample();
|
||||
fmt::println("Muting next for {}", IoStat->PromoDelay);
|
||||
} else {
|
||||
MediaPlayer::playWavFile(SwordCfg->SoundPromoShort);
|
||||
fmt::println("still muted");
|
||||
}
|
||||
|
||||
fmt::println("Waiting for {}", IoStat->PromoDelay);
|
||||
Thread::sleep(IoStat->PromoDelay);
|
||||
fmt::println("Waiting done");
|
||||
}
|
||||
}
|
||||
if (tn.tick()) {
|
||||
|
||||
Reference in new issue
Block a user