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
