From 954799eef3986f1421b493f6446be9cafe6bd78c Mon Sep 17 00:00:00 2001
From: aquaticus <1891400+aquaticus@users.noreply.github.com>
Date: Sat, 19 Aug 2023 12:29:10 +0200
Subject: [PATCH] pooling config and variable now bool (was int)
---
config.cpp | 4 ++--
config.h | 2 +-
decoder.cpp | 8 ++++++--
decoder.h | 4 ++--
main.cpp | 9 +++++----
nexus433.ini.in | 4 ++--
6 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/config.cpp b/config.cpp
index 6fbeb81..1cc6183 100644
--- a/config.cpp
+++ b/config.cpp
@@ -39,7 +39,7 @@ std::string Config::mqtt::certfile;
std::string Config::mqtt::keyfile;
std::string Config::mqtt::keypass;
-int Config::receiver::polling = 0;
+bool Config::receiver::polling = false;
string Config::receiver::chip = GPIOD_DEFAULT_DEVICE;
int Config::receiver::pin = GPIOD_DEFAULT_PIN;
int Config::receiver::resolution_us = 1;
@@ -84,7 +84,7 @@ bool Config::Load(const char *filename)
Config::mqtt::keyfile = ini.Get("mqtt", "keyfile", "");
Config::mqtt::keypass = ini.Get("mqtt", "keypass", "");
- Config::receiver::polling = ini.GetInteger("receiver", "polling", Config::receiver::polling);
+ Config::receiver::polling = ini.GetBoolean("receiver", "polling", Config::receiver::polling);
Config::receiver::chip = ini.Get("receiver", "chip", Config::receiver::chip);
Config::receiver::pin = ini.GetInteger("receiver", "pin", Config::receiver::pin);
Config::receiver::resolution_us = ini.GetInteger("receiver", "resolution_us", Config::receiver::resolution_us);
diff --git a/config.h b/config.h
index 7069c4f..2a7a5b5 100644
--- a/config.h
+++ b/config.h
@@ -47,7 +47,7 @@ class Config
struct receiver
{
- static int polling;
+ static bool polling;
static std::string chip;
static int pin;
static int resolution_us;
diff --git a/decoder.cpp b/decoder.cpp
index cbe0181..f16acb3 100644
--- a/decoder.cpp
+++ b/decoder.cpp
@@ -39,7 +39,11 @@ along with this program. If not, see .
void Decoder::Start()
{
- VERBOSE_PRINTF("Decoder resolution: %d µs; tolerance: %d µs\n", m_ResolutionUs, m_ToleranceUs);
+ if(m_Polling)
+ {
+ // Meaningful for pooling mode only
+ VERBOSE_PRINTF("Pooling mode decoder resolution: %d µs; tolerance: %d µs\n", m_ResolutionUs, m_ToleranceUs);
+ }
m_ErrorStop = false;
m_Future = std::move(m_StopFlag.get_future());
m_pThread = new std::thread([this] { this->ThreadFunc();} );
@@ -90,7 +94,7 @@ void Decoder::ThreadFunc()
void Decoder::ThreadFunc()
{
- if (1 == m_Polling)
+ if (m_Polling)
{
PollingReader();
}
diff --git a/decoder.h b/decoder.h
index bf7d5e8..bbeb8a9 100644
--- a/decoder.h
+++ b/decoder.h
@@ -37,7 +37,7 @@ class Decoder : public IDecoder
STATE_PULSE_END,
} STATES;
- Decoder(IStorage& s, gpiod_line *line, int tolerance, int precision, int polling):
+ Decoder(IStorage& s, gpiod_line *line, int tolerance, int precision, bool polling):
m_Storage(s),
m_Line(line),
m_ToleranceUs(tolerance),
@@ -82,7 +82,7 @@ class Decoder : public IDecoder
gpiod_line* m_Line;
int m_ToleranceUs; // +/- tolerance in microseconds, default 150
int m_ResolutionUs; // how long go to sleep in microseconds. Lower number (0 best) better precision but higher system load
- int m_Polling; // 1 to use polling, 0 to use events
+ bool m_Polling; // true to use polling, false to use events
std::atomic m_ErrorStop;
std::future m_Future;
};
diff --git a/main.cpp b/main.cpp
index 11ddcc1..c93c0e9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -304,8 +304,9 @@ int main(int argc, char** argv)
syslog (LOG_NOTICE, NEXUS433 " daemon started.");
}
+
// if config was specified check if file exists
- // in daemon mode path are relative to root, so better pass absolute path
+ // in daemon mode paths are relative to root, so better pass absolute path
if (config && access(config, F_OK) == -1)
{
std::cerr << "No access to configuration file " << config << std::endl;
@@ -355,9 +356,9 @@ int main(int argc, char** argv)
return -2;
}
- if (1 == Config::receiver::polling)
+ if (Config::receiver::polling)
{
- std::cout << "Decoding using polling" << std::endl;
+ std::cout << "Decoding mode: POLLING" << std::endl;
rv = gpiod_line_request_input(line, NEXUS433);
if (-1 == rv)
{
@@ -369,7 +370,7 @@ int main(int argc, char** argv)
}
else
{
- std::cout << "Decoding using events" << std::endl;
+ std::cout << "Decoding mode: EVENTS" << std::endl;
rv = gpiod_line_request_both_edges_events(line, NEXUS433);
if (-1 == rv)
{
diff --git a/nexus433.ini.in b/nexus433.ini.in
index dc68815..4b62cc0 100644
--- a/nexus433.ini.in
+++ b/nexus433.ini.in
@@ -36,8 +36,8 @@
;tolerance_us=300
; internal led device located in /sys/class/leds
; internal_led=""
-; use polling mode - avoids using gpiod events and uses more CPU
-;polling=0
+;use polling mode - avoids using gpiod events and uses more CPU
+; polling=false
[transmitter]
; timeout in seconds. If transmitter does not send any data within that period it's reported as offline