diff --git a/src/knx/group_object/dpt/dpt.h b/src/knx/group_object/dpt/dpt.h index 6c24bcd..30e2c3b 100644 --- a/src/knx/group_object/dpt/dpt.h +++ b/src/knx/group_object/dpt/dpt.h @@ -3,9 +3,6 @@ #include "../group_object.h" namespace Knx { -#define DPT_Switch Dpt(1, 1) -#define DPT_Bool Dpt(1, 2) -#define DPT_Enable Dpt(1, 3) #define DPT_Ramp Dpt(1, 4) #define DPT_Alarm Dpt(1, 5) #define DPT_BinaryValue Dpt(1, 6) diff --git a/src/knx/group_object/dpt/dpt1.cpp b/src/knx/group_object/dpt/dpt1.cpp index ec3a9f1..63d8143 100644 --- a/src/knx/group_object/dpt/dpt1.cpp +++ b/src/knx/group_object/dpt/dpt1.cpp @@ -2,9 +2,12 @@ #include "dptconvert.h" -Knx::Dpt1::Dpt1() {} +Knx::Dpt1::Dpt1(unsigned short subgroup /*= 0*/) : Dpt(1, subgroup) {} -Knx::Dpt1::Dpt1(bool value) : _value(value) {} +Knx::Dpt1::Dpt1(bool value) : Dpt1() +{ + _value = value; +} Knx::Go_SizeCode Knx::Dpt1::size() const { @@ -26,7 +29,7 @@ void Knx::Dpt1::value(bool value) _value = value; } -bool Knx::Dpt1::value() +bool Knx::Dpt1::value() const { return _value; } @@ -42,3 +45,75 @@ Knx::Dpt1& Knx::Dpt1::operator=(const bool value) _value = value; return *this; } + +Knx::DPT_Switch::DPT_Switch() : Dpt1() +{ + subGroup = 1; +} + +Knx::DPT_Switch::DPT_Switch(SwitchValue value) : Dpt1(value == On) +{ + subGroup = 1; +} + +void Knx::DPT_Switch::value(SwitchValue value) +{ + Dpt1::value(value == On); +} + +Knx::DPT_Switch::SwitchValue Knx::DPT_Switch::value() const +{ + return Dpt1::value() ? On : Off; +} + +Knx::DPT_Switch::operator Knx::DPT_Switch::SwitchValue() const +{ + return value(); +} + +Knx::DPT_Switch& Knx::DPT_Switch::operator=(const Knx::DPT_Switch::SwitchValue value) +{ + Dpt1::value(value == On); + return *this; +} + +Knx::DPT_Bool::DPT_Bool() : Dpt1() +{ + subGroup = 2; +} + +Knx::DPT_Bool::DPT_Bool(bool value) : DPT_Bool() +{ + Dpt1::value(value); +} + +Knx::DPT_Enable::DPT_Enable() : Dpt1() +{ + subGroup = 3; +} + +Knx::DPT_Enable::DPT_Enable(EnableValue value) : Dpt1(value == Enable) +{ + subGroup = 3; +} + +void Knx::DPT_Enable::value(EnableValue value) +{ + Dpt1::value(value == Enable); +} + +Knx::DPT_Enable::EnableValue Knx::DPT_Enable::value() const +{ + return Dpt1::value() ? Enable : Disable; +} + +Knx::DPT_Enable::operator Knx::DPT_Enable::EnableValue() const +{ + return value(); +} + +Knx::DPT_Enable& Knx::DPT_Enable::operator=(const Knx::DPT_Enable::EnableValue value) +{ + Dpt1::value(value == Enable); + return *this; +} \ No newline at end of file diff --git a/src/knx/group_object/dpt/dpt1.h b/src/knx/group_object/dpt/dpt1.h index 9e4bbcf..4d37ffb 100644 --- a/src/knx/group_object/dpt/dpt1.h +++ b/src/knx/group_object/dpt/dpt1.h @@ -5,7 +5,7 @@ namespace Knx class Dpt1: public Dpt { public: - Dpt1(); + Dpt1(unsigned short subgroup = 0); Dpt1(bool value); Go_SizeCode size() const override; @@ -13,10 +13,49 @@ namespace Knx virtual void decode(uint8_t* data) override; void value(bool value); - bool value(); + bool value() const; operator bool() const; Dpt1& operator=(const bool value); private: bool _value; }; + + class DPT_Switch : public Dpt1 + { + public: + enum SwitchValue + { + Off, On + }; + + DPT_Switch(); + DPT_Switch(SwitchValue value); + void value(SwitchValue value); + SwitchValue value() const; + operator SwitchValue() const; + DPT_Switch& operator=(const SwitchValue value); + }; + + class DPT_Bool : public Dpt1 + { + public: + DPT_Bool(); + DPT_Bool(bool value); + }; + + class DPT_Enable : public Dpt1 + { + public: + enum EnableValue + { + Disable, Enable + }; + + DPT_Enable(); + DPT_Enable(EnableValue value); + void value(EnableValue value); + EnableValue value() const; + operator EnableValue() const; + DPT_Enable& operator=(const EnableValue value); + }; } \ No newline at end of file diff --git a/src/knx/group_object/dpt/dpt9.cpp b/src/knx/group_object/dpt/dpt9.cpp index cb1042e..cea3652 100644 --- a/src/knx/group_object/dpt/dpt9.cpp +++ b/src/knx/group_object/dpt/dpt9.cpp @@ -2,9 +2,9 @@ #include "dptconvert.h" -Knx::Dpt9::Dpt9() {} +Knx::Dpt9::Dpt9() { mainGroup = 9; } -Knx::Dpt9::Dpt9(float value) : _value(value) {} +Knx::Dpt9::Dpt9(float value) : _value(value) { mainGroup = 9; } Knx::Go_SizeCode Knx::Dpt9::size() const { @@ -29,7 +29,7 @@ void Knx::Dpt9::value(float value) _value = value; } -bool Knx::Dpt9::value() +float Knx::Dpt9::value() const { return _value; } diff --git a/src/knx/group_object/dpt/dpt9.h b/src/knx/group_object/dpt/dpt9.h index fe9eb05..6c804a2 100644 --- a/src/knx/group_object/dpt/dpt9.h +++ b/src/knx/group_object/dpt/dpt9.h @@ -13,7 +13,7 @@ namespace Knx virtual void decode(uint8_t* data) override; void value(float value); - bool value(); + float value() const; operator float() const; Dpt9& operator=(const float value); private: