Githubからこのライブラリをコンパイルして修正して、誰かが独自のスケールを作成できるようにしました。しかし、私はarduinoのためにそれをコンパイルしようとすると、私はこのエラーを取得します。Arduinoバランスライブラリエラー
Arduino: 1.6.13 (Windows 10), Board: "Arduino Nano, ATmega328"
C:\Users\user\Documents\GitHub\Q2-Balance-Arduino-Library\examples\hx711_two_cell\hx711_two_cell.ino: In function 'void loop()':
hx711_two_cell:40: error: no matching function for call to 'Q2Balance::tare(int)'
balance.tare(100); ^
C:\Users\user\Documents\GitHub\Q2-Balance-Arduino-Library\examples\hx711_two_cell\hx711_two_cell.ino:40:21: note: candidate is:
In file included from C:\Users\user\Documents\GitHub\Q2-Balance-Arduino-Library\examples\hx711_two_cell\hx711_two_cell.ino:1:0:
C:\Users\user\Documents\Arduino\libraries\Q2-Balance-Arduino-Library-master\src/Q2Balance.h:64:10: note: void Q2Balance::tare(long int, void (*)())
void tare(long milliseconds, void (*afterTared)(void));
私はこの第二の空隙引数が必要である理由として困惑している(右、関数をコールバック)
私は私がするために、この機能については変更する必要があるかわかりませんよ
#ifndef q2balance_h
#define q2balance_h
#include "Arduino.h"
#define Q2BALANCE_MARKER_COUNT 10
// #define Q2BALANCE_DEBUG
#define Q2BALANCE_UNIT_GRAM 0
#define Q2BALANCE_UNIT_POUND 1
#define Q2BALANCE_UNIT_OUNCE 2
#define Q2BALANCE_UNIT_GRAIN 3
#define Q2BALANCE_UNIT_TROY 4
#define Q2BALANCE_UNIT_PWT 5
#define Q2BALANCE_UNIT_CARAT 6
#define Q2BALANCE_UNIT_NEWTON 7
struct BalanceCalibrationStruct {
long calibrationZero;
long calibrationMV[Q2BALANCE_MARKER_COUNT];
long calibrationMeasured[Q2BALANCE_MARKER_COUNT];
float calibrationScaler[Q2BALANCE_MARKER_COUNT];
};
class Q2Balance
{
private:
BalanceCalibrationStruct _settings;
bool _tared = false;
bool _taring = false;
bool _calibrating = false;
bool _calibratingZero = false;
bool _settling = false;
long _smoothValue = 0;
long _rawValue = 0;
long _tareValue = 0;
unsigned long _settleTimeout;
long _settleMinVal = 0;
long _settleMaxVal = 0;
long _jitter = 0;
int _calibrationIndex;
void (*_afterCalibrated)(void);
void sortCalibrations();
int findCalibrationWindow(long voltage);
float calcValue(int units, long value);
public:
long TARELIMIT = 110;
long JUMPLIMIT = 200;
long SAMPLE_COUNT = 10;
bool LOGGING = false;
Q2Balance();
virtual ~Q2Balance();
bool taring();
bool tared();
bool settling();
bool calibrating();
float adjustedValue(int units);
float adjustedRawValue(int units);
long smoothValue();
long rawValue();
long jitter();
void calibrateZero(long milliseconds, void (*afterCalibrated)(void));
void calibrate(int index, long measurement, long milliseconds, void (*afterCalibrated)(void));
void measure(long measurement);
void tare(long milliseconds, void (*afterTared)(void));
long settle(long milliseconds);
BalanceCalibrationStruct getCalibration();
void setCalibration(BalanceCalibrationStruct newSettings);
void tick();
void printCalibration(int index);
void printCalibrations();
};
#endif /* q2balance_h */
とCPPファイル
#include "q2balance.h"
Q2Balance::Q2Balance(){
_settings.calibrationZero = 0;
for(int i = 0;i<Q2BALANCE_MARKER_COUNT;i++)
{
_settings.calibrationMV[i]= 0;
_settings.calibrationMeasured[i] = 0;
_settings.calibrationScaler[i] = 0;
}
}
Q2Balance::~Q2Balance(){
}
BalanceCalibrationStruct Q2Balance::getCalibration(){
BalanceCalibrationStruct newSettings;
newSettings.calibrationZero = _settings.calibrationZero;
for(int i = 0;i<Q2BALANCE_MARKER_COUNT;i++)
{
newSettings.calibrationMV[i] = _settings.calibrationMV[i];
newSettings.calibrationMeasured[i] = _settings.calibrationMeasured[i];
newSettings.calibrationScaler[i] = _settings.calibrationScaler[i];
}
return newSettings;
}
void Q2Balance::setCalibration(BalanceCalibrationStruct newSettings){
_settings.calibrationZero = newSettings.calibrationZero;
for(int i = 0;i<10;i++)
{
_settings.calibrationMV[i] = newSettings.calibrationMV[i];
_settings.calibrationMeasured[i] = newSettings.calibrationMeasured[i];
_settings.calibrationScaler[i] = newSettings.calibrationScaler[i];
}
}
void Q2Balance::tick(){
unsigned long now = millis();
if (_settling){
if (_smoothValue < _settleMinVal){
_settleMinVal = _smoothValue;
}
if (_smoothValue > _settleMaxVal){
_settleMaxVal = _smoothValue;
}
_jitter = _settleMaxVal - _settleMinVal;
if (now > _settleTimeout){
_settling = false;
} else {
return;
}
}
if(_taring){
_taring = false;
_tared = true;
_smoothValue = _rawValue;
_tareValue = _rawValue;
if (_afterCalibrated!=NULL){
(*_afterCalibrated)();
_afterCalibrated = NULL;
}
}
if (_tared && abs(_smoothValue - _tareValue) > TARELIMIT){
_tared = false;
}
if (_calibratingZero) {
_settings.calibrationZero = _smoothValue;
for(int i = 0;i<Q2BALANCE_MARKER_COUNT;i++) // Recalc calibrations if zero changed
{
if(_settings.calibrationScaler[i] != 0){
float delta = (float)(_settings.calibrationMV[i] - _settings.calibrationZero);
float scaler = (float)_settings.calibrationMeasured[i]/delta;
_settings.calibrationScaler[i] = scaler;
}
}
_calibratingZero = false;
_calibrating = false;
if (_afterCalibrated!=NULL){
(*_afterCalibrated)();
_afterCalibrated = NULL;
}
}
if (_calibrating) {
_calibrating = false;
_settings.calibrationMV[_calibrationIndex] = _smoothValue;
float delta = (float)(_smoothValue - _settings.calibrationZero);
float scaler = (float)_settings.calibrationMeasured[_calibrationIndex]/delta;
_settings.calibrationScaler[_calibrationIndex] = scaler;
if (_afterCalibrated!=NULL){
(*_afterCalibrated)();
_afterCalibrated = NULL;
}
}
}
long Q2Balance::settle(long settleTime) {
_settling = true;
_settleMinVal = _smoothValue;
_settleMaxVal = _smoothValue;
_settleTimeout = millis() + settleTime;
}
bool Q2Balance::settling(){
return _settling;
};
bool Q2Balance::calibrating(){
return _calibrating;
};
void Q2Balance::tare(long settleTime, void (*afterTared)(void)){
if (!_calibrating && !_settling){
_taring = true;
_afterCalibrated = afterTared;
settle(settleTime);
}
}
bool Q2Balance::taring(){
return _taring;
};
bool Q2Balance::tared(){
return _tared;
};
void Q2Balance::calibrateZero(long settleTime, void (*afterCalibrated)(void)){
if (!_calibrating && !_settling){
_afterCalibrated = afterCalibrated;
_calibratingZero = true;
_calibrating = true;
settle(settleTime);
}
}
void Q2Balance::calibrate(int index, long measurement, long settleTime, void (*afterCalibrated)(void)){
if (!_calibrating && !_settling){
if (index < Q2BALANCE_MARKER_COUNT){
_afterCalibrated = afterCalibrated;
_calibrating = true;
_calibrationIndex = index;
_settings.calibrationMeasured[index] = measurement;
settle(settleTime);
}
}
}
void Q2Balance::measure(long measurement){
long avg = _smoothValue;
_rawValue = measurement;
if (abs(measurement-_smoothValue) > JUMPLIMIT){ // If there is a large jump, abandon smoothing and set the value.
_smoothValue = measurement;
return;
}
avg -= avg/SAMPLE_COUNT;
avg += measurement/SAMPLE_COUNT;
_smoothValue = avg;
};
long Q2Balance::smoothValue(){
return _smoothValue;
};
long Q2Balance::rawValue(){
return _rawValue;
};
long Q2Balance::jitter(){
return _jitter;
}
float Q2Balance::calcValue(int units, long value){
if(_settings.calibrationZero == 0){
return 0; //unzeroed
}
int index = findCalibrationWindow(_smoothValue);
if (index == -1){
return 0; //uncalibrated
}
long val = _smoothValue - _tareValue;
if (_tared){
return (0);
}
float scaled = round(val * _settings.calibrationScaler[index] * 100.0)/100.0;
if (units > 0){
switch (units) {
case Q2BALANCE_UNIT_POUND:
scaled = scaled * 0.002204622;
break;
case Q2BALANCE_UNIT_OUNCE:
scaled = scaled * 0.0352734;
break;
case Q2BALANCE_UNIT_GRAIN:
scaled = scaled * 15.43;
break;
case Q2BALANCE_UNIT_TROY:
scaled = scaled * 0.032;
break;
case Q2BALANCE_UNIT_PWT:
scaled = scaled * 0.643;
break;
case Q2BALANCE_UNIT_CARAT:
scaled = scaled * 5;
break;
case Q2BALANCE_UNIT_NEWTON:
scaled = scaled * 0.009;
break;
}
}
return scaled;
}
float Q2Balance::adjustedValue(int units){
return calcValue(_smoothValue, units);
}
float Q2Balance::adjustedRawValue(int units){
return calcValue(_rawValue, units);
}
void Q2Balance::printCalibrations(){
char buffer[128];
sprintf(buffer, "ZERO %ld ",_settings.calibrationZero);
Serial.println(buffer);
for(int c=0;c<Q2BALANCE_MARKER_COUNT;c++){
printCalibration(c);
}
}
void Q2Balance::printCalibration(int index){
char buffer[128];
char str_scaler[16];
dtostrf(_settings.calibrationScaler[index], 6, 6, str_scaler);
sprintf(buffer, "IDX %dMV %ld M %ld SC %s",
index,
_settings.calibrationMV[index],
_settings.calibrationMeasured[index],
str_scaler
);
Serial.println(buffer);
}
int Q2Balance::findCalibrationWindow(long voltage){
int i,t=0;
for (i = 0; i < Q2BALANCE_MARKER_COUNT; i++)
{
if (_settings.calibrationMV[i] == 0){
break;
}
if (_settings.calibrationMV[i] >= voltage){
break;
}
t = i;
}
if (_settings.calibrationMV[t] == 0){
return -1;
}
return t;
}
:これはこれは.hファイルである をコンパイルするために取得
目的は、コールバック関数を提供することです。 –