tune code

This commit is contained in:
Joerg Lehmann 2020-05-28 13:27:19 +02:00
parent b71e0c0f0c
commit 7c8a52cafe
2 changed files with 9 additions and 4 deletions

View File

@ -56,7 +56,7 @@ enum {
| |
\****************************************************************************/ \****************************************************************************/
static const int32_t fwVersion = 20200527; static const int32_t fwVersion = 20200528;
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages; static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
static const byte MAX_VALUES_TO_SEND = 8; static const byte MAX_VALUES_TO_SEND = 8;

View File

@ -96,9 +96,11 @@ long ReadScale(char channel)
long readings[num_scale_readings]; // create arry to hold readings long readings[num_scale_readings]; // create arry to hold readings
for (int i = 0; i < num_scale_readings; i++) { for (int i = 0; i < num_scale_readings; i++) {
//while (digitalRead(interruptPin) == LOW) { //while (digitalRead(interruptPin) == LOW) {
long mytimer = millis();
while (! myScale.available()) { while (! myScale.available()) {
// we set a timeout of 10 seconds for the measurement... // we set a timeout of 10 seconds for the measurement...
if ((millis() - startTime) > 10000) { if ((millis() - mytimer) > 10000) {
// Timeout reading scale...
Wire.endTransmission(true); Wire.endTransmission(true);
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("Timeout while reading scale...\n"); gCatena.SafePrintf("Timeout while reading scale...\n");
@ -107,11 +109,14 @@ long ReadScale(char channel)
} }
delay(1); delay(1);
} }
long reading = myScale.getReading(); long reading;
if (myScale.available()) {
reading = myScale.getReading();
readings[i] = reading;
}
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("Reading: %d\n", reading); gCatena.SafePrintf("Reading: %d\n", reading);
} }
readings[i] = reading; // fill the array with instantaneous readings from the scale
delay(10); delay(10);
} }