Skip to content

Commit

Permalink
sns: namespace, fix init function(s)
Browse files Browse the repository at this point in the history
One namespace for sensor functions and types.
Fix discrepancy between topic and indexed topic funcs.
Energy types fixes, make sure we use known ratios.

Sensor fixes, moving certain pin settings and defaults into the sensor
classes, using those in the actual sensor init code.
Energy is still within the sensor module, pending version bump before moving.
  • Loading branch information
mcspr committed Jul 20, 2022
1 parent 91eb010 commit b366d77
Show file tree
Hide file tree
Showing 26 changed files with 2,685 additions and 2,480 deletions.
16 changes: 8 additions & 8 deletions code/espurna/config/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
#endif

#ifndef DIGITAL1_DEFAULT_STATE
#define DIGITAL1_DEFAULT_STATE 1
#define DIGITAL1_DEFAULT_STATE HIGH
#endif

#ifndef DIGITAL2_PIN
Expand All @@ -310,7 +310,7 @@
#endif

#ifndef DIGITAL2_DEFAULT_STATE
#define DIGITAL2_DEFAULT_STATE 1
#define DIGITAL2_DEFAULT_STATE HIGH
#endif

#ifndef DIGITAL3_PIN
Expand All @@ -322,7 +322,7 @@
#endif

#ifndef DIGITAL3_DEFAULT_STATE
#define DIGITAL3_DEFAULT_STATE 1
#define DIGITAL3_DEFAULT_STATE HIGH
#endif

#ifndef DIGITAL4_PIN
Expand All @@ -334,7 +334,7 @@
#endif

#ifndef DIGITAL4_DEFAULT_STATE
#define DIGITAL4_DEFAULT_STATE 1
#define DIGITAL4_DEFAULT_STATE HIGH
#endif

#ifndef DIGITAL5_PIN
Expand All @@ -346,7 +346,7 @@
#endif

#ifndef DIGITAL5_DEFAULT_STATE
#define DIGITAL5_DEFAULT_STATE 1
#define DIGITAL5_DEFAULT_STATE HIGH
#endif

#ifndef DIGITAL6_PIN
Expand All @@ -358,7 +358,7 @@
#endif

#ifndef DIGITAL6_DEFAULT_STATE
#define DIGITAL6_DEFAULT_STATE 1
#define DIGITAL6_DEFAULT_STATE HIGH
#endif

#ifndef DIGITAL7_PIN
Expand All @@ -370,7 +370,7 @@
#endif

#ifndef DIGITAL7_DEFAULT_STATE
#define DIGITAL7_DEFAULT_STATE 1
#define DIGITAL7_DEFAULT_STATE HIGH
#endif

#ifndef DIGITAL8_PIN
Expand All @@ -382,7 +382,7 @@
#endif

#ifndef DIGITAL8_DEFAULT_STATE
#define DIGITAL8_DEFAULT_STATE 1
#define DIGITAL8_DEFAULT_STATE HIGH
#endif

//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions code/espurna/domoticz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void send() {
namespace sensor {
namespace {

void send(unsigned char index, const ::sensor::Value& value) {
void send(unsigned char index, const espurna::sensor::Value& value) {
if (!enabled()) {
return;
}
Expand Down Expand Up @@ -541,7 +541,7 @@ void setup() {
} // namespace espurna

#if SENSOR_SUPPORT
void domoticzSendMagnitude(unsigned char index, const sensor::Value& value) {
void domoticzSendMagnitude(unsigned char index, const espurna::sensor::Value& value) {
espurna::domoticz::sensor::send(index, value);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/domoticz.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Copyright (C) 2019-2021 by Maxim Prokhorov <prokhorov dot max at outlook dot com

#include "sensor.h"

void domoticzSendMagnitude(unsigned char, const sensor::Value&);
void domoticzSendMagnitude(unsigned char, const espurna::sensor::Value&);
void domoticzSetup();
bool domoticzEnabled();
4 changes: 2 additions & 2 deletions code/espurna/homeassistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ class SensorDiscovery : public Discovery {
json[F("uniq_id")] = uniqueId();

json[F("name")] = _ctx.name() + ' ' + name() + ' ' + localId();
json[F("stat_t")] = mqttTopic(magnitudeTopicIndex(_index), false);
json[F("stat_t")] = mqttTopic(magnitudeTopic(_index), false);
json[F("unit_of_meas")] = magnitudeUnits(_index);

json.printTo(_message);
Expand All @@ -667,7 +667,7 @@ class SensorDiscovery : public Discovery {

const String& name() {
if (!_name.length()) {
_name = magnitudeTopic(magnitudeType(_index));
_name = magnitudeTypeTopic(magnitudeType(_index));
}

return _name;
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/influxdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void _idbConfigure() {
if (_idb_enabled && !_idb_client) _idbInitClient();
}

void _idbSendSensor(const sensor::Value& value) {
void _idbSendSensor(const espurna::sensor::Value& value) {
idbSend(magnitudeTopic(value.type).c_str(), value.index, value.repr.c_str());
}

Expand Down
8 changes: 4 additions & 4 deletions code/espurna/rfm69.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ void _rfm69CleanNodes(size_t max) {
size_t id { 0 };
rfm69::settings::foreachMapping([&](rfm69::Mapping&&) {
if (id < max) {
++id;
return true;
return false;
}

return false;
++id;
return true;
});

while (id < max) {
while (id < rfm69::build::maxTopics()) {
delSetting({"rfm69Node", id});
delSetting({"rfm69Key", id});
delSetting({"rfm69Topic", id});
Expand Down
4 changes: 2 additions & 2 deletions code/espurna/rpnrules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,8 @@ void init(rpn_context& context) {
#if SENSOR_SUPPORT
namespace sensor {

void updateVariables(const ::sensor::Value& value) {
static_assert(sizeof(decltype(value.value)) == sizeof(rpn_float), "");
void updateVariables(const espurna::sensor::Value& value) {
static_assert(std::is_same<decltype(value.value), rpn_float>::value, "");

auto topic = value.topic;
topic.remove('/');
Expand Down
Loading

0 comments on commit b366d77

Please sign in to comment.