diff --git a/src/knx/group_object/dpt/dpt.h b/src/knx/group_object/dpt/dpt.h index c87fb49..0e8fb5f 100644 --- a/src/knx/group_object/dpt/dpt.h +++ b/src/knx/group_object/dpt/dpt.h @@ -330,4 +330,37 @@ namespace Knx */ virtual bool decode(uint8_t* data) = 0; }; + + template class DPT: public Dpt + { + public: + DPT() {}; + DPT(T value) + { + _value = value; + } + + virtual void value(T value) + { + _value = value; + } + + T value() const + { + return _value; + } + + operator T() const + { + return _value; + } + + DPT& operator=(const T value) + { + _value = value; + return *this; + } + private: + T _value; + }; } \ No newline at end of file diff --git a/src/knx/group_object/dpt/dpt1.cpp b/src/knx/group_object/dpt/dpt1.cpp index 24d21b5..cc4e8e4 100644 --- a/src/knx/group_object/dpt/dpt1.cpp +++ b/src/knx/group_object/dpt/dpt1.cpp @@ -2,13 +2,6 @@ #include "dptconvert.h" -Knx::Dpt1::Dpt1() {} - -Knx::Dpt1::Dpt1(bool value) -{ - this->value(value); -} - Knx::Go_SizeCode Knx::Dpt1::size() const { return Go_1_Bit; @@ -16,32 +9,11 @@ Knx::Go_SizeCode Knx::Dpt1::size() const void Knx::Dpt1::encode(uint8_t* data) const { - bitToPayload(data, 7, _value); + bitToPayload(data, 7, value()); } bool Knx::Dpt1::decode(uint8_t* data) { - _value = bitFromPayload(data, 7); + value(bitFromPayload(data, 7)); return true; } - -void Knx::Dpt1::value(bool value) -{ - _value = value; -} - -bool Knx::Dpt1::value() const -{ - return _value; -} - -Knx::Dpt1::operator bool() const -{ - return _value; -} - -Knx::Dpt1& Knx::Dpt1::operator=(const bool value) -{ - _value = value; - return *this; -} diff --git a/src/knx/group_object/dpt/dpt1.h b/src/knx/group_object/dpt/dpt1.h index 817b7f1..e15f7bf 100644 --- a/src/knx/group_object/dpt/dpt1.h +++ b/src/knx/group_object/dpt/dpt1.h @@ -2,22 +2,12 @@ #include "dpt.h" namespace Knx { - class Dpt1: public Dpt + class Dpt1: public DPT { public: - Dpt1(); - Dpt1(bool value); Go_SizeCode size() const override; - void encode(uint8_t* data) const override; bool decode(uint8_t* data) override; - - void value(bool value); - bool value() const; - operator bool() const; - Dpt1& operator=(const bool value); - private: - bool _value; }; template class DPT1 : public Dpt1 diff --git a/src/knx/group_object/dpt/dpt2.h b/src/knx/group_object/dpt/dpt2.h index a9a6f28..74bf41b 100644 --- a/src/knx/group_object/dpt/dpt2.h +++ b/src/knx/group_object/dpt/dpt2.h @@ -9,7 +9,7 @@ namespace Knx { NoControl, Control }; - template class DPT2: public Dpt + template class DPT2: public DPT { public: Go_SizeCode size() const override @@ -26,7 +26,7 @@ namespace Knx } bitToPayload(data, 6, true); - bitToPayload(data, 7, ((int)_value) == 1); + bitToPayload(data, 7, ((int)DPT::value()) == 1); } bool decode(uint8_t* data) override @@ -41,7 +41,7 @@ namespace Knx bool v = bitFromPayload(data, 7); - _value = v ? (T)1 : (T)0; + value(v ? (T)1 : (T)0); return true; } @@ -55,16 +55,6 @@ namespace Knx return _control; } - void value(T value) - { - _value = value; - } - - T value() const - { - return _value; - } - private: ControlValue _control; T _value; diff --git a/src/knx/group_object/dpt/dpt4.cpp b/src/knx/group_object/dpt/dpt4.cpp index c7bc861..8e94b50 100644 --- a/src/knx/group_object/dpt/dpt4.cpp +++ b/src/knx/group_object/dpt/dpt4.cpp @@ -2,13 +2,6 @@ #include "dptconvert.h" -Knx::Dpt4::Dpt4() {} - -Knx::Dpt4::Dpt4(char value) -{ - _value = value; -} - Knx::Go_SizeCode Knx::Dpt4::size() const { return Go_1_Octet; @@ -16,36 +9,15 @@ Knx::Go_SizeCode Knx::Dpt4::size() const void Knx::Dpt4::encode(uint8_t* data) const { - unsigned8ToPayload(data, 0, _value, 0xFF); + unsigned8ToPayload(data, 0, value(), 0xFF); } bool Knx::Dpt4::decode(uint8_t* data) { - _value = signed8FromPayload(data, 0); + value(signed8FromPayload(data, 0)); return true; } -void Knx::Dpt4::value(char value) -{ - _value = value; -} - -char Knx::Dpt4::value() const -{ - return _value; -} - -Knx::Dpt4::operator char() const -{ - return _value; -} - -Knx::Dpt4& Knx::Dpt4::operator=(const char value) -{ - _value = value; - return *this; -} - bool Knx::DPT_Char_ASCII::decode(uint8_t* data) { Dpt4::value(signed8FromPayload(data, 0) & 0x7F); diff --git a/src/knx/group_object/dpt/dpt4.h b/src/knx/group_object/dpt/dpt4.h index 739fe36..b46a6e1 100644 --- a/src/knx/group_object/dpt/dpt4.h +++ b/src/knx/group_object/dpt/dpt4.h @@ -2,22 +2,13 @@ #include "dpt.h" namespace Knx { - class Dpt4: public Dpt + class Dpt4: public DPT { public: - Dpt4(); - Dpt4(char value); Go_SizeCode size() const override; void encode(uint8_t* data) const override; bool decode(uint8_t* data) override; - - virtual void value(char value); - char value() const; - operator char() const; - Dpt4& operator=(const char value); - private: - char _value; }; class DPT_Char_ASCII: public Dpt4