only one HX711, rename load cell names
This commit is contained in:
parent
bac960c897
commit
c9875123f4
|
|
@ -94,12 +94,12 @@ void setTxCycleTime(unsigned txCycle, unsigned txCount);
|
||||||
cCommandStream::CommandFn cmdHello;
|
cCommandStream::CommandFn cmdHello;
|
||||||
cCommandStream::CommandFn cmdGetCalibrationSettings;
|
cCommandStream::CommandFn cmdGetCalibrationSettings;
|
||||||
cCommandStream::CommandFn cmdGetSensorReadings;
|
cCommandStream::CommandFn cmdGetSensorReadings;
|
||||||
cCommandStream::CommandFn cmdGetScale1;
|
cCommandStream::CommandFn cmdGetScaleA;
|
||||||
cCommandStream::CommandFn cmdGetScale2;
|
cCommandStream::CommandFn cmdGetScaleB;
|
||||||
cCommandStream::CommandFn cmdCalibrateZeroScale1;
|
cCommandStream::CommandFn cmdCalibrateZeroScaleA;
|
||||||
cCommandStream::CommandFn cmdCalibrateZeroScale2;
|
cCommandStream::CommandFn cmdCalibrateZeroScaleB;
|
||||||
cCommandStream::CommandFn cmdCalibrateScale1;
|
cCommandStream::CommandFn cmdCalibrateScaleA;
|
||||||
cCommandStream::CommandFn cmdCalibrateScale2;
|
cCommandStream::CommandFn cmdCalibrateScaleB;
|
||||||
|
|
||||||
// the individual commmands are put in this table
|
// the individual commmands are put in this table
|
||||||
static const cCommandStream::cEntry sMyExtraCommmands[] =
|
static const cCommandStream::cEntry sMyExtraCommmands[] =
|
||||||
|
|
@ -107,10 +107,10 @@ static const cCommandStream::cEntry sMyExtraCommmands[] =
|
||||||
{ "hello", cmdHello },
|
{ "hello", cmdHello },
|
||||||
{ "get_calibration_settings", cmdGetCalibrationSettings },
|
{ "get_calibration_settings", cmdGetCalibrationSettings },
|
||||||
{ "get_sensor_readings", cmdGetSensorReadings },
|
{ "get_sensor_readings", cmdGetSensorReadings },
|
||||||
{ "calibrate_zero_scale1", cmdCalibrateZeroScale1 },
|
{ "calibrate_zero_scale_a", cmdCalibrateZeroScaleA },
|
||||||
{ "calibrate_zero_scale2", cmdCalibrateZeroScale2 },
|
{ "calibrate_zero_scale_b", cmdCalibrateZeroScaleB },
|
||||||
{ "calibrate_scale1", cmdCalibrateScale1 },
|
{ "calibrate_scale_a", cmdCalibrateScaleA },
|
||||||
{ "calibrate_scale2", cmdCalibrateScale2 },
|
{ "calibrate_scale_b", cmdCalibrateScaleB },
|
||||||
// other commands go here....
|
// other commands go here....
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -225,8 +225,7 @@ Catena_Mx25v8035f gFlash;
|
||||||
bool fFlash;
|
bool fFlash;
|
||||||
|
|
||||||
// Scales
|
// Scales
|
||||||
HX711 LoadCell_1;
|
HX711 LoadCell;
|
||||||
HX711 LoadCell_2;
|
|
||||||
|
|
||||||
// USB power
|
// USB power
|
||||||
bool fUsbPower;
|
bool fUsbPower;
|
||||||
|
|
@ -395,23 +394,14 @@ void setup_scales(void)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
gCatena.SafePrintf("Setup Scale 1...\n");
|
gCatena.SafePrintf("Setup Scale 1...\n");
|
||||||
#endif
|
#endif
|
||||||
LoadCell_1.begin(A1, A0);
|
LoadCell.begin(A1, A0);
|
||||||
|
|
||||||
if (!(LoadCell_1.wait_ready_timeout(1000))) {
|
if (!(LoadCell.wait_ready_timeout(1000))) {
|
||||||
gCatena.SafePrintf("Scale 1 not ready.\n");
|
gCatena.SafePrintf("Scale not ready.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
gCatena.SafePrintf("Setup Scale 2...\n");
|
gCatena.SafePrintf("Setup Scale is complete\n");
|
||||||
#endif
|
|
||||||
LoadCell_2.begin(D12, A2);
|
|
||||||
|
|
||||||
if (!(LoadCell_2.wait_ready_timeout(1000))) {
|
|
||||||
gCatena.SafePrintf("Scale 2 not ready.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gCatena.SafePrintf("Setup Scales is complete\n");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -635,26 +625,19 @@ void ReadSensors(bool firstTime, bool readOnly)
|
||||||
setup_scales();
|
setup_scales();
|
||||||
|
|
||||||
// Read Scales
|
// Read Scales
|
||||||
if (LoadCell_1.is_ready()) {
|
if (LoadCell.is_ready()) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("HX711 LoadCell_1 is ready.");
|
Serial.println("HX711 LoadCell is ready.");
|
||||||
#endif
|
#endif
|
||||||
long w1 = LoadCell_1.read_average(5);
|
LoadCell.set_gain(128);
|
||||||
|
long w1 = LoadCell.read_average(5);
|
||||||
weight1_current = (int32_t)w1;
|
weight1_current = (int32_t)w1;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
gCatena.SafePrintf("Load_cell 1 output val: %ld\n", w1);
|
gCatena.SafePrintf("Load_cell 1 output val: %ld\n", w1);
|
||||||
gCatena.SafePrintf("Load_cell 1 weight1_current: %ld\n", weight1_current);
|
gCatena.SafePrintf("Load_cell 1 weight1_current: %ld\n", weight1_current);
|
||||||
#endif
|
#endif
|
||||||
}
|
LoadCell.set_gain(32);
|
||||||
else {
|
long w2 = LoadCell.read_average(5);
|
||||||
Serial.println("HX711 LoadCell_1 not ready.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LoadCell_2.is_ready()) {
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println("HX711 LoadCell_2 is ready.");
|
|
||||||
#endif
|
|
||||||
long w2 = LoadCell_2.read_average(5);
|
|
||||||
weight2_current = (int32_t)w2;
|
weight2_current = (int32_t)w2;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
gCatena.SafePrintf("Load_cell 2 output val: %ld\n", w2);
|
gCatena.SafePrintf("Load_cell 2 output val: %ld\n", w2);
|
||||||
|
|
@ -662,7 +645,7 @@ void ReadSensors(bool firstTime, bool readOnly)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println("HX711 LoadCell_2 not ready.");
|
Serial.println("HX711 LoadCell not ready.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable Power
|
// Disable Power
|
||||||
|
|
@ -955,29 +938,29 @@ cCommandStream::CommandStatus cmdGetScale2(cCommandStream *pThis, void *pContext
|
||||||
return cCommandStream::CommandStatus::kSuccess;
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
cCommandStream::CommandStatus cmdCalibrateZeroScale1(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
cCommandStream::CommandStatus cmdCalibrateZeroScaleA(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
||||||
{
|
{
|
||||||
ReadSensors(false, true);
|
ReadSensors(false, true);
|
||||||
config_data.cal_w1_0 = last_sensor_reading.weight1;
|
config_data.cal_w1_0 = last_sensor_reading.weight1;
|
||||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||||
|
|
||||||
pThis->printf("{ \"msg\": \"calibrate_zero_scale1 was successful\" }\n");
|
pThis->printf("{ \"msg\": \"calibrate_zero_scale_a was successful\" }\n");
|
||||||
|
|
||||||
return cCommandStream::CommandStatus::kSuccess;
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
cCommandStream::CommandStatus cmdCalibrateZeroScale2(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
cCommandStream::CommandStatus cmdCalibrateZeroScaleB(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
||||||
{
|
{
|
||||||
ReadSensors(false, true);
|
ReadSensors(false, true);
|
||||||
config_data.cal_w2_0 = last_sensor_reading.weight2;
|
config_data.cal_w2_0 = last_sensor_reading.weight2;
|
||||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||||
|
|
||||||
pThis->printf("{ \"msg\": \"calibrate_zero_scale2 was successful\" }\n");
|
pThis->printf("{ \"msg\": \"calibrate_zero_scale_b was successful\" }\n");
|
||||||
|
|
||||||
return cCommandStream::CommandStatus::kSuccess;
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
cCommandStream::CommandStatus cmdCalibrateScale1(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
cCommandStream::CommandStatus cmdCalibrateScaleA(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
||||||
{
|
{
|
||||||
ReadSensors(false, true);
|
ReadSensors(false, true);
|
||||||
|
|
||||||
|
|
@ -992,12 +975,12 @@ cCommandStream::CommandStatus cmdCalibrateScale1(cCommandStream *pThis, void *pC
|
||||||
gCatena.SafePrintf("w1_gramm (float): %d\n", (int)w1_gramm.toFloat());
|
gCatena.SafePrintf("w1_gramm (float): %d\n", (int)w1_gramm.toFloat());
|
||||||
gCatena.SafePrintf("config_data.cal_w1_factor: %d\n", (int)config_data.cal_w1_factor);
|
gCatena.SafePrintf("config_data.cal_w1_factor: %d\n", (int)config_data.cal_w1_factor);
|
||||||
|
|
||||||
pThis->printf("{ \"msg\": \"calibrate_scale1 was successful\" }\n");
|
pThis->printf("{ \"msg\": \"calibrate_scale_a was successful\" }\n");
|
||||||
|
|
||||||
return cCommandStream::CommandStatus::kSuccess;
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
cCommandStream::CommandStatus cmdCalibrateScale2(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
cCommandStream::CommandStatus cmdCalibrateScaleB(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
||||||
{
|
{
|
||||||
ReadSensors(false, true);
|
ReadSensors(false, true);
|
||||||
|
|
||||||
|
|
@ -1006,7 +989,7 @@ cCommandStream::CommandStatus cmdCalibrateScale2(cCommandStream *pThis, void *pC
|
||||||
|
|
||||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||||
|
|
||||||
pThis->printf("{ \"msg\": \"calibrate_scale2 was successful\" }\n");
|
pThis->printf("{ \"msg\": \"calibrate_scale_b was successful\" }\n");
|
||||||
|
|
||||||
return cCommandStream::CommandStatus::kSuccess;
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue