Skip to content

Commit

Permalink
pooling config and variable now bool (was int)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquaticus committed Aug 19, 2023
1 parent 9f42d41 commit 954799e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

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();} );
Expand Down Expand Up @@ -90,7 +94,7 @@ void Decoder::ThreadFunc()

void Decoder::ThreadFunc()
{
if (1 == m_Polling)
if (m_Polling)
{
PollingReader();
}
Expand Down
4 changes: 2 additions & 2 deletions decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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<bool> m_ErrorStop;
std::future<void> m_Future;
};
9 changes: 5 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions nexus433.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 954799e

Please sign in to comment.