This commit is contained in:
Jakob Gegeniger committed 2026-10-28 21:19:56 +01:00
1 parent 855ffe5915
commit e7a9e0316e
3 files changed
+26 -10

No files matched your search

Submodule platform updated: 387735f701...dd23ecf4a7.
+14 -5
View File
@@ -78,15 +78,25 @@ int main(int argc, char* argv[]) {
InputTransAware SwordEnd(sePort);
InputTransAware SwordPulled(spPort);
I2cMaster i2cDev(II2cMaster::ClockRate::_400k);
AdcAds1115 adc(i2cDev, AdcAds1115::I2CAddress::Gnd);
log.sendBootUp(Version, MqttChannel::Modes[static_cast<int>(IoStat->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);
}
CurrMon mon(adc);
LinMot SwordLatch(mOut1, mOut2, mon, saveFile);
static CurrMon mon(adc);
pMon = &mon;
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
log.sendEvent("HW-Err", "Failed to init II2-Hardware");
static ICurrentMon fakeMon;
pMon = &fakeMon;
}
LinMot SwordLatch(mOut1, mOut2, *pMon, saveFile);
IoStat = make_unique<DeviceIoState>(SwordEntry, SwordEnd, SwordPulled, SwordLatch);
fmt::println("{}", app.get_description());
@@ -96,7 +106,6 @@ int main(int argc, char* argv[]) {
} else {
fmt::println("unknown {}", modeArg);
}
log.sendBootUp(Version, MqttChannel::Modes[static_cast<int>(IoStat->Mode)]);
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
auto resetCall = [&]() {
+11 -4
View File
@@ -33,7 +33,14 @@
#include "textUtils.hpp"
#include "thread.hpp"
class CurrMon {
class ICurrentMon {
public:
virtual float sampleCurrent() {
return 0;
}
};
class CurrMon : public ICurrentMon {
// https://www.monolithicpower.com/en/documentview/productdocument/index/version/2/document_type/Datasheet/lang/EN/sku/MCS1802/document_id/5066/
public:
CurrMon(AdcAds1115& adc)
@@ -48,7 +55,7 @@ class CurrMon {
_refVal = val / 8;
}
float sampleCurrent() {
float sampleCurrent() override {
auto val = sample() - _refVal;
val = val / 0.264;
// fmt::println("{:.2} A", val);
@@ -70,7 +77,7 @@ class LinMot {
public:
using SaveCall = void (*)(string, vector<float>);
LinMot(OutputPort& o1, OutputPort& o2, CurrMon& mon, SaveCall call)
LinMot(OutputPort& o1, OutputPort& o2, ICurrentMon& mon, SaveCall call)
: _out1(o1),
_out2(o2),
_mon(mon),
@@ -92,7 +99,7 @@ class LinMot {
private:
OutputPort& _out1;
OutputPort& _out2;
CurrMon& _mon;
ICurrentMon& _mon;
SaveCall _saveCb;
const float FinThresh = 0.020;
const float AbortThresh = 0.050;