Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HX711-multi.h have error error: extra qualification 'HX711MULTI::' on member 'readRaw' [-fpermissive] #118

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
changes to tare, added debugEnable flag
  • Loading branch information
compugician committed Oct 19, 2016
commit 843e97de2834980385083aa7b2a75785812f0fda
34 changes: 28 additions & 6 deletions HX711-multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ HX711MULTI::HX711MULTI(int count, byte *dout, byte pd_sck, byte gain) {
DOUT = dout; //TODO - make the input of dout to the function a const, or otherwise copy the values for local storage
COUNT = count;

debugEnabled = false;

pinMode(PD_SCK, OUTPUT);
for (int i=0; i<count; i++) {
pinMode(DOUT[i], INPUT);
Expand Down Expand Up @@ -75,11 +77,11 @@ bool HX711MULTI::tare(byte times, uint16_t tolerance) {
minValues[i]=0x7FFFFFFF;
maxValues[i]=0x80000000;

OFFSETS[i]=0;
//OFFSETS[i]=0; //<--removed this line, so that a failed tare does not undo previous tare
}

for (i=0; i<times; ++i) {
read(values);
readRaw(values);
for (j=0; j<COUNT; ++j) {
if (values[j]<minValues[j]) {
minValues[j]=values[j];
Expand All @@ -94,8 +96,12 @@ bool HX711MULTI::tare(byte times, uint16_t tolerance) {
for (i=0; i<COUNT; ++i) {
if (abs(maxValues[i]-minValues[i])>tolerance) {
//one of the cells fluctuated more than the allowed tolerance, reject tare attempt;
Serial.println("Rejecting tare");
Serial.println(abs(maxValues[i]-minValues[i]));
if (debugEnabled) {
Serial.print("Rejecting tare: (");
Serial.print(i);
Serial.print(") ");
Serial.println(abs(maxValues[i]-minValues[i]));
}
return false;
}
}
Expand All @@ -110,8 +116,21 @@ bool HX711MULTI::tare(byte times, uint16_t tolerance) {
}

//reads from all cahnnels and sets the values into the passed long array pointer (which must have at least 'count' cells allocated)
//send NULL if you are only reading to toggle the line, and not to get values, such as in the case of setting gains.
//if you are only reading to toggle the line, and not to get values (such as in the case of setting gains) you can pass NULL.
void HX711MULTI::read(long *result) {

readRaw(result);

// Datasheet indicates the value is returned as a two's complement value, so 'stretch' the 24th bit to fit into 32 bits.
if (NULL!=result) {
for (int j = 0; j < COUNT; ++j) {
result[j] -= OFFSETS[j];
}
}
}


void HX711MULTI::readRaw(long *result) {
int i,j;
// wait for all the chips to become ready
while (!is_ready());
Expand Down Expand Up @@ -141,12 +160,15 @@ void HX711MULTI::read(long *result) {
} else {
result[j] &= 0x00FFFFFF; //required in lieu of re-setting the value to zero before shifting bits in.
}
result[j] -= OFFSETS[j];
}

}
}

void HX711MULTI::setDebugEnable(bool debugEnable) {
debugEnabled = debugEnable;
}

void HX711MULTI::power_down() {
digitalWrite(PD_SCK, LOW);
digitalWrite(PD_SCK, HIGH);
Expand Down
7 changes: 7 additions & 0 deletions HX711-multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class HX711MULTI
byte *DOUT; // Serial Data Output Pin
byte GAIN; // amplification factor

bool debugEnabled; //print debug messages?

long *OFFSETS; // used for tare weight
float SCALE; // used to return weight in grams, kg, ounces, whatever

Expand Down Expand Up @@ -43,6 +45,9 @@ class HX711MULTI
// waits for the chip to be ready and returns a reading
void read(long *result = NULL);

// same as read, but does not offset the values according to the tare
void HX711MULTI::readRaw(long *result = NULL);

// set the OFFSET value for tare weight
// times: how many times to read the tare value
// returns true iff the offsets have been reset for the scale during this call.
Expand All @@ -54,6 +59,8 @@ class HX711MULTI

// wakes up the chip after power down mode
void power_up();

void setDebugEnable(bool debugEnable = true);
};

#endif /* HX711_MULTI_h */