sensor/budka: drobnosti z review před zveřejněním
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
513b77a8a8
commit
d288425ebf
2 files changed
+22
-8
No files matched your search
@@ -75,9 +75,13 @@ void BudkaLinkSensorManager::handleLine() {
|
|||||||
else if (!strcmp(k, "h")) dst = &h;
|
else if (!strcmp(k, "h")) dst = &h;
|
||||||
else if (!strcmp(k, "p")) dst = &p;
|
else if (!strcmp(k, "p")) dst = &p;
|
||||||
else if (!strcmp(k, "mot")) {
|
else if (!strcmp(k, "mot")) {
|
||||||
mot = strtoul(v, NULL, 10);
|
char* end;
|
||||||
mot_valid = true;
|
unsigned long m = strtoul(v, &end, 10);
|
||||||
mot_at = now;
|
if (end != v) {
|
||||||
|
mot = m;
|
||||||
|
mot_valid = true;
|
||||||
|
mot_at = now;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Meter fields: v<k> i<k> w<k> wh<k>, k = 1..BUDKA_LINK_METERS.
|
// Meter fields: v<k> i<k> w<k> wh<k>, k = 1..BUDKA_LINK_METERS.
|
||||||
size_t kl = strlen(k);
|
size_t kl = strlen(k);
|
||||||
@@ -90,8 +94,12 @@ void BudkaLinkSensorManager::handleLine() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dst) {
|
if (dst) {
|
||||||
dst->v = strtof(v, NULL);
|
char* end;
|
||||||
dst->at = now;
|
float f = strtof(v, &end);
|
||||||
|
if (end != v) { // "v1=" with no number is not a reading
|
||||||
|
dst->v = f;
|
||||||
|
dst->at = now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_line_ms = now;
|
last_line_ms = now;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// The budka sends one NMEA-style line every ~30 s (firmware/main/mc_link.h in
|
// The budka sends one NMEA-style line every ~30 s (firmware/main/mc_link.h in
|
||||||
// the chytra-budka repo):
|
// the chytra-budka repo):
|
||||||
//
|
//
|
||||||
// CB1 id=fbfe18 t=21.4 h=63 p=1013.2 v1=5.04 i1=0.221 w1=1.11 wh1=310.75
|
// CB1 id=0a1b2c t=21.4 h=63 p=1013.2 v1=5.04 i1=0.221 w1=1.11 wh1=310.75
|
||||||
// v2=4.96 i2=0.090 w2=0.45 wh2=111.70 mot=3 up=1234*5A\r\n (one line)
|
// v2=4.96 i2=0.090 w2=0.45 wh2=111.70 mot=3 up=1234*5A\r\n (one line)
|
||||||
//
|
//
|
||||||
// Meters are numbered 1..BUDKA_LINK_METERS in id order on the budka. The box's
|
// Meters are numbered 1..BUDKA_LINK_METERS in id order on the budka. The box's
|
||||||
@@ -24,6 +24,10 @@
|
|||||||
|
|
||||||
#include "EnvironmentSensorManager.h"
|
#include "EnvironmentSensorManager.h"
|
||||||
|
|
||||||
|
#if ENV_INCLUDE_GPS
|
||||||
|
#error "BudkaLinkSensorManager uses Serial1, which the GPS code also claims"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef BUDKA_LINK_BAUD
|
#ifndef BUDKA_LINK_BAUD
|
||||||
#define BUDKA_LINK_BAUD 115200
|
#define BUDKA_LINK_BAUD 115200
|
||||||
#endif
|
#endif
|
||||||
@@ -40,8 +44,10 @@ public:
|
|||||||
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
|
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
// Last motion count and the time it last increased (0 = never), so the
|
// Cumulative PIR count as last reported by the budka (hasMotion() = the
|
||||||
// app can raise an alert on new motion.
|
// budka has a PIR and sent a count), and millis() of the last valid line
|
||||||
|
// (0 = none yet) — enough for an app to alert on new motion or a silent
|
||||||
|
// budka.
|
||||||
bool hasMotion() const { return mot_valid; }
|
bool hasMotion() const { return mot_valid; }
|
||||||
uint32_t motionCount() const { return mot; }
|
uint32_t motionCount() const { return mot; }
|
||||||
unsigned long lastLineMillis() const { return last_line_ms; }
|
unsigned long lastLineMillis() const { return last_line_ms; }
|
||||||
|
|||||||
Reference in new issue
Block a user