ecos: added mode and duration to switch

Dieser Commit ist enthalten in:
Reinder Feenstra 2021-12-26 10:13:45 +01:00
Ursprung b6e0fe3959
Commit be63db9378
3 geänderte Dateien mit 27 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -60,6 +60,7 @@ struct Option
{ {
static constexpr std::string_view addr = "addr"; static constexpr std::string_view addr = "addr";
static constexpr std::string_view dir = "dir"; static constexpr std::string_view dir = "dir";
static constexpr std::string_view duration = "duration";
static constexpr std::string_view go = "go"; static constexpr std::string_view go = "go";
static constexpr std::string_view info = "info"; static constexpr std::string_view info = "info";
static constexpr std::string_view mode = "mode"; static constexpr std::string_view mode = "mode";

Datei anzeigen

@ -27,7 +27,7 @@
namespace ECoS { namespace ECoS {
const std::initializer_list<std::string_view> Switch::options = {Option::addr, Option::protocol, Option::state, Option::mode}; const std::initializer_list<std::string_view> Switch::options = {Option::addr, Option::protocol, Option::state, Option::mode, Option::duration};
static bool fromString(std::string_view text, Switch::Protocol& protocol) static bool fromString(std::string_view text, Switch::Protocol& protocol)
{ {
@ -40,6 +40,17 @@ static bool fromString(std::string_view text, Switch::Protocol& protocol)
return true; return true;
} }
static bool fromString(std::string_view text, Switch::Mode& mode)
{
if(text == "SWITCH")
mode = Switch::Mode::Switch;
else if(text == "PULSE")
mode = Switch::Mode::Pulse;
else
return false;
return true;
}
Switch::Switch(Kernel& kernel, uint16_t id) Switch::Switch(Kernel& kernel, uint16_t id)
: Object(kernel, id) : Object(kernel, id)
{ {
@ -57,7 +68,9 @@ Switch::Switch(Kernel& kernel, const Line& data)
if(auto state = values.find(Option::state); state != values.end()) if(auto state = values.find(Option::state); state != values.end())
{} {}
if(auto mode = values.find(Option::mode); mode != values.end()) if(auto mode = values.find(Option::mode); mode != values.end())
{} fromString(mode->second, m_mode);
if(auto duration = values.find(Option::duration); duration != values.end())
fromChars(duration->second, m_duration);
} }
bool Switch::receiveReply(const Reply& reply) bool Switch::receiveReply(const Reply& reply)

Datei anzeigen

@ -41,9 +41,18 @@ class Switch final : public Object
MM = 2, MM = 2,
}; };
enum class Mode
{
Unknown = 0,
Switch = 1,
Pulse = 2,
};
private: private:
uint16_t m_address = 0; uint16_t m_address = 0;
Protocol m_protocol = Protocol::Unknown; Protocol m_protocol = Protocol::Unknown;
Mode m_mode = Mode::Unknown;
uint16_t m_duration = 0;
public: public:
static const std::initializer_list<std::string_view> options; static const std::initializer_list<std::string_view> options;
@ -56,6 +65,8 @@ class Switch final : public Object
uint16_t address() const { return m_address; } uint16_t address() const { return m_address; }
Protocol protocol() const { return m_protocol; } Protocol protocol() const { return m_protocol; }
Mode mode() const { return m_mode; }
uint16_t duration() const { return m_duration; }
}; };
} }