Potrzebna pomoc z obiektami

User avatar
shimano73
Posts: 2174
Joined: Sun Feb 28, 2016 12:27 pm
Location: Orzesze
Been thanked: 1 time

Post

Potrzebuję pomocy ze składnią. Zrobiłem sobie nowy soft do obsługi wagi lpg w oparciu o GUI generic.
Niestety moja wiedza z programowania ma dużo braków. Stworzyłem obsługę układu hx711 dla czujników tensometrycznych.
Mam jeszcze parę pomysłu ale stanąłem przed ścianą i nie wiem co zrobić .Tak wygląda obsługa

Code: Select all

/*
 Copyright (C) AC SOFTWARE SP. Z O.O.

 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 _H711_h
#define _H711_h

 
#include "supla/sensor/thermometer.h"
#include "HX711.h"

namespace Supla {
namespace Sensor {
class H711 : public Thermometer{
 public:
  H711(int8_t DOUT, int8_t CLK, int calibration_factor, int empty) {
  _DOUT = DOUT;
  _CLK = CLK;
  _calibration_factor = calibration_factor;
  _empty = empty;
  }

  double getValue() {
		double _level = scale.get_units(10);
		actual_level = _level;
		Serial.print("Level :"); Serial.println(_level);
		Serial.print("Empty :"); Serial.println(_empty);
		_level = _level - _empty;
		_level = _level * 100 ;
		
		_level = _level / (_full - _empty) ; // wyliczanie procentu pojemności butli
		if (_level < _empty) _level = 0;
		Serial.print("Level persent :"); Serial.print(_level);Serial.println("%");
		
    return _level;
  }

  double getActual() {
	  return actual_level;
  }
  
  void onInit() {
  scale.begin(_DOUT, _CLK);
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  
  long zero_factor = scale.read_average(); //Get a baseline reading
 
  scale.set_scale(_calibration_factor);
  scale.set_offset(367493);
    channel.setNewValue(getValue());
  }

 
 protected:
  int8_t _DOUT, _CLK;
  int _calibration_factor;
  int _empty;
  double _full = 21.2;
  double actual_level;
   HX711 scale; 
 
};

};  // namespace Sensor
};  // namespace Supla

#endif


obsługa działa tak jak chciałem, tylko nie wiem jak powinna wyglądać składnia uzycia metody getAcctual() w programie głównym w arduino np

Code: Select all

	double zmienna = "co tu wstawić".getActual()

Proszę o pomoc mądre głowy :)
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie

Wezmę udział w Supla Offline Party 2024 :)
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

Wstaw tam nazwę zmiennej, która jest instancją klasy wagi.

Np:

Code: Select all

Supla:: Sensor::H711 waga(parametry, ...);

auto act = waga.getActual();
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
shimano73
Posts: 2174
Joined: Sun Feb 28, 2016 12:27 pm
Location: Orzesze
Been thanked: 1 time

Post

Prawie się udało. Program w skrócie wygląda tak :

Code: Select all


void setup() {

 new Supla::Sensor::H711(HX711_DOUT, HX711_CLK, String (ConfigManager->get(KEY_LPG_CALIBRATIONS)->getValue()).toInt(), String (ConfigManager->get(KEY_LPG_EMPTY)->getValue()).toInt());
  Supla:: Sensor::H711 waga(HX711_DOUT, HX711_CLK, String (ConfigManager->get(KEY_LPG_CALIBRATIONS)->getValue()).toInt(), String (ConfigManager->get(KEY_LPG_EMPTY)->getValue()).toInt());
  double LPG_Actual = waga.getActual();
  ...
Program się kompiluje, ale po wgraniu przez OTA się wysypał, a dziś już za późno aby ponownie rozbierać wagę :cry:
Wcześnie , dla zwiększenia ilości pamięci za komentowałem elementy których nie używam

Code: Select all


#ifndef GUI_Generic_Config_h
#define GUI_Generic_Config_h

//#define DEBUG_MODE

//#define SUPLA_RELAY
//#define SUPLA_BUTTON
//#define SUPLA_LIMIT_SWITCH
//#define SUPLA_ROLLERSHUTTER
#define SUPLA_CONFIG

//#define SUPLA_HC_SR04

// 1Wire
//#define SUPLA_DS18B20
//#define SUPLA_DHT11
//#define SUPLA_DHT22
//#define SUPLA_SI7021_SONOFF

// i2c
//#define SUPLA_BME280
//#define SUPLA_SHT30
//#define SUPLA_SI7021
// #define SUPLA_HTU21D    // 0x40 NOT SUPPORTED
// #define SUPLA_SHT71     // 0x44 AND 0x45 NOT SUPPORTED
// #define SUPLA_BH1750    // 0x23 AND 0x5C NOT SUPPORTED
// #define SUPLA_MAX44009  // A0 NOT SUPPORTED

A tu jeszcze wynik kompilacji

Code: Select all



Executable segment sizes:
IROM   : 457236          - code in flash         (default or ICACHE_FLASH_ATTR) 
IRAM   : 27436   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...) 
DATA   : 1272  )         - initialized variables (global, static) in RAM/HEAP 
RODATA : 4020  ) / 81920 - constants             (global, static) in RAM/HEAP 
BSS    : 29664 )         - zeroed variables      (global, static) in RAM/HEAP 
Szkic używa 489964 bajtów (46%) pamięci programu. Maksimum to 1044464 bajtów.
Zmienne globalne używają 34956 bajtów (42%) pamięci dynamicznej, pozostawiając 46964 bajtów dla zmiennych lokalnych. Maksimum to 81920 bajtów.

Jutro a właściwie dziś po południu podłącze się laptopem i zobaczę co tam się stało.
Nie mniej jednak prosiłbym o rzut okiem na moje wypociny
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie

Wezmę udział w Supla Offline Party 2024 :)

Return to “Pomoc”