klasa dla HECy (grzałka z czujnikiem dla Nettigo Air Monitor)

User avatar
malarz
Posts: 506
Joined: Wed Jan 27, 2021 4:04 pm
Been thanked: 2 times

Post

klew wrote: Mon Jan 19, 2026 7:36 pm
malarz wrote: Mon Jan 19, 2026 7:17 pm
jak rozumiem, nadpisać jednak readValuesFromDevice i zapisywać w niej stan do jakiegoś nowego boola

a jak wartość tej zmiennej wrzucać do VirtualBinary? Czegoś nie umiem/nie rozumiem i wolę się dopytać tutaj. Najchętniej bym jakiś podobny przykład obejrzał.

Przy okazji jak już temat VB ujrzał światło dzienne (pytanie do innego tematu), to czy można jakoś zapisywać historię VB w cloudzie? Czy trzeba dodać sobie dodatkowego KPOPa i tam zapisywać 0/1 aby to uzyskać?
Proponuję prowadzić dyskusję w jednym miejscu ;)

Po prostu czytaj do bool.
W swojej klasie (tej nowej) ustawiaj tego boola na vb i tyle.

Vb nie ma aktualnie historii, ale prędzej czy później będzie ona dodana
Ja bym jednak chciał tutaj o tym podyskutować. Już wiem skąd ten komentarz w tej funkcji się wziął

Code: Select all

  double getHumi() override {
    // ugly method overriding
    // it should be in readValuesFromDevice() method (it's private)
    // but this method is much shorter

    if (sht.readStatusRegister().HeaterStatus) {
      heaterChannel.set();
      SUPLA_LOG_DEBUG("HECA heater is ON");
    } else {
      heaterChannel.clear();
      SUPLA_LOG_DEBUG("HECA heater is OFF");
    }

    return humidity;
  }
jeżeli to wpiszę do nowej prywatnej readValuesFromDevice() to mam problem z wywołaniem oryginalnej funkcji z klasy dla SHT31:

Code: Select all

In file included from C:\Users\malarz\Documents\Arduino\NAM\NAM.ino:64:
C:\Users\malarz\Documents\Arduino\NAM\heca.h: In member function 'void Supla::Sensor::HECA::readValuesFromDevice()':
C:\Users\malarz\Documents\Arduino\NAM\heca.h:55:32: error: 'void Supla::Sensor::SHT3x::readValuesFromDevice()' is private within this context
   55 |     SHT3x::readValuesFromDevice();
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from C:\Users\malarz\Documents\Arduino\NAM\NAM.ino:63:
c:\Users\malarz\Documents\Arduino\libraries\SuplaDevice\src/supla/sensor/sht3x.h:53:8: note: declared private here
   53 |   void readValuesFromDevice() {
      |        ^~~~~~~~~~~~~~~~~~~~
exit status 1

Compilation error: 'void Supla::Sensor::SHT3x::readValuesFromDevice()' is private within this context
bo jest prywatna i w dziedziconej klasie nie jest dostępna. Musiałbym więc w rzeczywistości jej zawartość przepisać do funkcji w podklasie. Można też dodać jakąś formę obsługi tej funkcjonalności SHT31 do klasy ogólnej (supla-defice/src/supla/sensor/sht3x.h), ale to jest chyba na tyle rzadkie jej zastosowanie, że to się mija z celem (pod koniec napiszę jeszcze co trzeba by tam dodać).

I ponawiam pytanie dot.
W swojej klasie (tej nowej) ustawiaj tego boola na vb i tyle.
Jak mam ustawiać tego boola na vb (moja klasa nie dziedziczy po VB a po SHT31)

Innym rozwiązaniem jest oczywiście dodanie do klasy SHT31 funkcji:
1. zwracającej sht.readStatusRegister().HeaterStatus
2. wywołującej sht.writeAlertHigh
3. wywołującej sht.writeAlertLow
4. wywołującej sht.clearAll
i zbudowanie nowej klasy na bazie VB albo z parametrem wskazującym na obiekt SHT31, albo tworzącym sobie własny obiekt klasy SHT31, z którego tę nową funkcję . Być może to ostatnie miałeś na myśli. Ale w tym przypadku jak pisałem, nie wydaje mi się aby to miało większy sens.
Próbuję przerobić pomysły na działające projekty w ArduinoIDE.
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Ta metoda read... jest już cyklicznie wywoływana. Nie musisz jej jeszcze raz uruchamiać.

Vb po prostu zostaw jako member Twojej nowej klasy (tak jak teraz chyba jest)
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
malarz
Posts: 506
Joined: Wed Jan 27, 2021 4:04 pm
Been thanked: 2 times

Post

klew wrote: Wed Jan 21, 2026 10:19 pm Ta metoda read... jest już cyklicznie wywoływana. Nie musisz jej jeszcze raz uruchamiać.

Vb po prostu zostaw jako member Twojej nowej klasy (tak jak teraz chyba jest)
Czyli coś takiego będzie działać poprawnie?

Code: Select all

/*
   Copyright (C) malarz

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   */

#ifndef SRC_SUPLA_SENSOR_HECA_H_
#define SRC_SUPLA_SENSOR_HECA_H_

#include <supla/sensor/SHT3x.h>
#include <supla/control/virtual_relay.h>
#include <supla/sensor/virtual_binary.h>

namespace Supla {
namespace Sensor {
class HECA : public Supla::Sensor::SHT3x {
 public:
  explicit HECA(int8_t humOn = 63, int8_t humOff = 60, int8_t address = 0x44) : SHT3x(address) {
    humiOn = humOn;
    humiOff = humOff;

    channel.setInitialCaption("HECA temp&humi");

    heaterChannel.setDefaultFunction(SUPLA_CHANNELFNC_BINARY_SENSOR);
    heaterChannel.setInitialCaption("HECA heater");
    heaterChannel.getChannel()->setDefaultIcon(2);
    heaterChannel.clear();
  }

  void onInit() override {
    SHT3x::onInit();

    // set hight humidity alert and dummy hight temperature alert
    sht.writeAlertHigh(120, 119, humiOn, humiOff);
    // set dummy low alert
    sht.writeAlertLow(5, -5, 0, 1);
    // reset all registers for proper operation of alerts
    sht.clearAll();
  }

 private:
  void readValuesFromDevice() {
// to jednak wydaje mi się potrzebne, choć @klew chyba pisze inaczej
//    SHT3x::readValuesFromDevice();

    if (sht.readStatusRegister().HeaterStatus) {
      heaterOn = true;
      heaterChannel.set();
      SUPLA_LOG_DEBUG("HECA heater is ON");
    } else {
      heaterOn = false;
      heaterChannel.clear();
      SUPLA_LOG_DEBUG("HECA heater is OFF");
    }
  }

 protected:
  int8_t humiOn = 63;
  int8_t humiOff = 60;
  bool heaterOn = false;
  Supla::Sensor::VirtualBinary heaterChannel;
};

}  // namespace Sensor
}  // namespace Supla

#endif  // SRC_SUPLA_SENSOR_HECA_H_
Czy o takiego boola Ci chodziło jak dodałem powyżej "heaterOn". I jak go powiązać ze stanem VB?
Próbuję przerobić pomysły na działające projekty w ArduinoIDE.
User avatar
malarz
Posts: 506
Joined: Wed Jan 27, 2021 4:04 pm
Been thanked: 2 times

Post

Dzięki za marge. Przeczytałem jeszcze raz dyskusję z GH i teraz widzę, gdzie źle cię zrozumiałem. W każdym razie chyba Cię przekonałem w viewtopic.php?p=226075#p226075 :)
Próbuję przerobić pomysły na działające projekty w ArduinoIDE.
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

malarz wrote: Wed Jan 28, 2026 8:24 pm Dzięki za marge. Przeczytałem jeszcze raz dyskusję z GH i teraz widzę, gdzie źle cię zrozumiałem. W każdym razie chyba Cię przekonałem w viewtopic.php?p=226075#p226075 :)
:)
Najlepsze suple dla Twojego domu :mrgreen:

Return to “Pomoc”