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

No files matched your search

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