Renames the executable to lowercase and updates the corresponding dependency links in CMakeLists.txt. Introduces a version file to manage the project's version.
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#include "Heart.h"
|
|
#include <gpiod.hpp>
|
|
|
|
namespace cardio
|
|
{
|
|
Heart::Heart(const char* chipName, const unsigned int lineOffset)
|
|
: _lastBeat(std::chrono::steady_clock::now()),
|
|
chip_(std::string("/dev/") + chipName),
|
|
isOn_(false),
|
|
request_(get_line_request(chip_, lineOffset))
|
|
{
|
|
}
|
|
|
|
void Heart::beat()
|
|
{
|
|
const auto now = std::chrono::steady_clock::now();
|
|
if (const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>
|
|
(now - _lastBeat); elapsed.count() >= 500)
|
|
{
|
|
isOn_ = !isOn_;
|
|
const auto val = isOn_ ? gpiod::line::value::ACTIVE : gpiod::line::value::INACTIVE;
|
|
request_.set_value(DEFAULT_HEART_PIN, val);
|
|
_lastBeat = now;
|
|
}
|
|
}
|
|
|
|
void Heart::stop()
|
|
{
|
|
isOn_ = false;
|
|
request_.set_value(DEFAULT_HEART_PIN, gpiod::line::value::INACTIVE);
|
|
}
|
|
|
|
gpiod::line_request Heart::get_line_request(gpiod::chip& chip, const unsigned int lineOffset)
|
|
{
|
|
const auto settings = gpiod::line_settings()
|
|
.set_direction(gpiod::line::direction::OUTPUT);
|
|
|
|
return chip.prepare_request()
|
|
.add_line_settings(lineOffset, settings)
|
|
.do_request();
|
|
}
|
|
}
|