Start with implementing subdpts

This commit is contained in:
Thomas Kunze 2024-09-12 23:13:30 +02:00
parent 60b414bab2
commit c77490ad62
5 changed files with 123 additions and 12 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
};
}

View File

@ -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;
}

View File

@ -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: