|
24 | 24 |
|
25 | 25 | #include <math.h>
|
26 | 26 | #include <Arduino.h>
|
27 |
| -#include "CloudColoredLight.h" |
| 27 | +#include "../../ArduinoCloudProperty.h" |
28 | 28 |
|
29 | 29 | /******************************************************************************
|
30 | 30 | CLASS DECLARATION
|
31 | 31 | ******************************************************************************/
|
| 32 | +class DimmeredLight { |
| 33 | + public: |
| 34 | + bool swi; |
| 35 | + float bri; |
| 36 | + DimmeredLight(bool swi, float bri): swi(swi), bri(bri) { |
| 37 | + } |
| 38 | + |
| 39 | + bool operator==(DimmeredLight & aLight) { |
| 40 | + return aLight.swi == swi && aLight.bri == bri; |
| 41 | + } |
| 42 | + |
| 43 | + bool operator!=(DimmeredLight & aLight) { |
| 44 | + return !(operator==(aLight)); |
| 45 | + } |
| 46 | + |
| 47 | +}; |
32 | 48 |
|
33 |
| -class CloudDimmeredLight : public CloudColoredLight { |
| 49 | +class CloudDimmeredLight : public ArduinoCloudProperty { |
34 | 50 | private:
|
| 51 | + DimmeredLight _value, |
| 52 | + _cloud_value; |
| 53 | + |
35 | 54 | public:
|
36 |
| - float getBrightness() { |
37 |
| - return _value.bri; |
| 55 | + CloudDimmeredLight() : _value(false, 0), _cloud_value(false, 0) {} |
| 56 | + CloudDimmeredLight(bool swi, float brightness) : _value(swi, brightness), _cloud_value(swi, brightness) {} |
| 57 | + |
| 58 | + virtual bool isDifferentFromCloud() { |
| 59 | + |
| 60 | + return _value != _cloud_value; |
| 61 | + } |
| 62 | + |
| 63 | + CloudDimmeredLight& operator=(DimmeredLight aLight) { |
| 64 | + _value.swi = aLight.swi; |
| 65 | + _value.bri = aLight.bri; |
| 66 | + updateLocalTimestamp(); |
| 67 | + return *this; |
| 68 | + } |
| 69 | + |
| 70 | + DimmeredLight getCloudValue() { |
| 71 | + return _cloud_value; |
38 | 72 | }
|
39 |
| - bool getSwitch() { |
40 |
| - return _value.swi; |
| 73 | + |
| 74 | + DimmeredLight getValue() { |
| 75 | + return _value; |
| 76 | + } |
| 77 | + |
| 78 | + virtual void fromCloudToLocal() { |
| 79 | + _value = _cloud_value; |
| 80 | + } |
| 81 | + virtual void fromLocalToCloud() { |
| 82 | + _cloud_value = _value; |
| 83 | + } |
| 84 | + |
| 85 | + virtual void appendAttributesToCloud() { |
| 86 | + appendAttribute(_value.swi); |
| 87 | + // To allow visualization through color widget |
| 88 | + // Start |
| 89 | + float hue = 0; |
| 90 | + float sat = 0; |
| 91 | + appendAttributeReal(hue, getAttributeName(".hue", '.'), encoder); |
| 92 | + appendAttributeReal(sat, getAttributeName(".sat", '.'), encoder); |
| 93 | + if (_value.swi) { |
| 94 | + appendAttribute(_value.bri); |
| 95 | + } else { |
| 96 | + float bri = 0; |
| 97 | + appendAttributeReal(bri, getAttributeName(".bri", '.'), encoder); |
| 98 | + } |
| 99 | + // should be only: |
| 100 | + // appendAttribute(_value.bri); |
| 101 | + // end |
41 | 102 | }
|
42 | 103 |
|
43 | 104 | virtual void setAttributesFromCloud() {
|
|
0 commit comments