Browse Source

tuya: send channel value directly

mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
012c3818a5
2 changed files with 3 additions and 12 deletions
  1. +1
    -1
      code/espurna/light.h
  2. +2
    -11
      code/espurna/tuya.cpp

+ 1
- 1
code/espurna/light.h View File

@ -75,7 +75,7 @@ class LightProvider {
public: public:
virtual void update() = 0; virtual void update() = 0;
virtual void state(bool) = 0; virtual void state(bool) = 0;
virtual void channel(unsigned char ch, double value) = 0;
virtual void channel(unsigned char ch, float value) = 0;
}; };
struct LightTransition { struct LightTransition {


+ 2
- 11
code/espurna/tuya.cpp View File

@ -139,7 +139,7 @@ namespace tuya {
} }
} }
void channel(unsigned char channel, double value) override {
void channel(unsigned char channel, float value) override {
// XXX: can't handle channel values when OFF, and will turn the lights ON // XXX: can't handle channel values when OFF, and will turn the lights ON
if (!_last_state) { if (!_last_state) {
return; return;
@ -150,18 +150,9 @@ namespace tuya {
return; return;
} }
auto rounded = static_cast<unsigned int>(value);
// input dimmer channel value when lights are OFF is 16 // input dimmer channel value when lights are OFF is 16
// for the same reason as above, don't send OFF values // for the same reason as above, don't send OFF values
constexpr unsigned int Low { 16u };
constexpr unsigned int High { 255u };
rounded = std::clamp(rounded, Low, High);
if (rounded == 16u) {
return;
}
send(entry->dp_id, rounded);
send(entry->dp_id, static_cast<unsigned int>(value));
} }
private: private:


Loading…
Cancel
Save