make possible to disable load cell, store config in proper place
This commit is contained in:
parent
4fd870e6d5
commit
d2b821c46e
|
|
@ -22,7 +22,7 @@ Das sind die verwendeten Libraries [1]:
|
|||
| https://github.com/mcci-catena/Adafruit_Sensor.git | f2af6f4 | Tue, 1 Sep 2015 15:57:59 +0200 |
|
||||
| https://github.com/mcci-catena/arduino-lmic.git | f67121c | Mon, 10 Feb 2020 10:57:04 -0500 |
|
||||
| https://github.com/mcci-catena/arduino-lorawan.git | a0577e1 | Mon, 10 Feb 2020 13:21:30 -0500 |
|
||||
| https://github.com/mcci-catena/Catena-Arduino-Platform.git | 119e90e | Mon, 10 Feb 2020 15:32:03 -0500 |
|
||||
| https://github.com/mcci-catena/Catena-Arduino-Platform.git | 85c010c | Tue, 11 Feb 2020 19:58:25 -0500 |
|
||||
| https://github.com/mcci-catena/Catena-mcciadk.git | a428006 | Sat, 21 Dec 2019 20:45:26 -0500 |
|
||||
| https://github.com/mcci-catena/MCCI_FRAM_I2C.git | f0a5ea5 | Sat, 21 Dec 2019 16:17:01 -0500 |
|
||||
| https://github.com/tatobari/Q2-HX711-Arduino-Library.git | ccda8d8 | Wed, 13 Mar 2019 12:41:44 -0300 |
|
||||
|
|
@ -30,5 +30,6 @@ Das sind die verwendeten Libraries [1]:
|
|||
| https://github.com/mcci-catena/SHT1x.git | be7042c | Tue, 20 Sep 2011 13:56:23 +1000 |
|
||||
|
||||
|
||||
|
||||
`[1]:
|
||||
[joerg@cinnamon libraries]$ for i in Adafruit_BME280_Library Adafruit_Sensor arduino-lmic arduino-lorawan Catena-Arduino-Platform Catena-mcciadk MCCI_FRAM_I2C Q2-HX711-Arduino-Library OneWire SHT1x ; do cd $i; echo "| $(git remote -v |grep fetch |awk '{print $2}' |tr '\n' ' ') | $(git log --pretty=format:'%h | %cD ' -n 1) |" ; cd ..; done`
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ void setup_platform(void)
|
|||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - Reading Calibration Config from FRAM...\n", millis());
|
||||
}
|
||||
gCatena.getFram()->getField(cFramStorage::kBme680Cal, (uint8_t *)&config_data, sizeof(config_data));
|
||||
gCatena.getFram()->getField(cFramStorage::kAppConf, (uint8_t *)&config_data, sizeof(config_data));
|
||||
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - setup_platform, this is the configuration\n", millis());
|
||||
|
|
@ -571,7 +571,7 @@ void bubbleSort(long A[], int len) {
|
|||
|
||||
long my_read_average(byte gain, byte times) {
|
||||
long res;
|
||||
int const num_scale_readings = 50; // number of instantaneous scale readings to calculate the median
|
||||
int const num_scale_readings = 25; // number of instantaneous scale readings to calculate the median
|
||||
|
||||
// we use the median, not the average, see https://community.particle.io/t/boron-gpio-provides-less-current-than-electrons-gpio/46647/13
|
||||
long readings[num_scale_readings]; // create arry to hold readings
|
||||
|
|
@ -613,14 +613,28 @@ void ReadSensors(SENSOR_data &sensor_data) {
|
|||
gCatena.SafePrintf("%010d - HX711 LoadCell is ready.\n", millis());
|
||||
}
|
||||
gCatena.poll();
|
||||
res.weight1 = (int32_t)my_read_average(32, 7);
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - Load_cell 1 weight1_current: %ld\n", millis(), res.weight1);
|
||||
if (config_data.cal_w1_0 != NOT_ATTACHED) {
|
||||
res.weight1 = (int32_t)my_read_average(32, 7);
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - Load_cell 1 weight1_current: %ld\n", millis(), res.weight1);
|
||||
}
|
||||
} else {
|
||||
res.weight1 = 0;
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - Load_cell 1 is disabled\n", millis());
|
||||
}
|
||||
}
|
||||
gCatena.poll();
|
||||
res.weight2 = (int32_t)my_read_average(128, 7);
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - Load_cell 2 weight2_current: %ld\n", millis(), res.weight2);
|
||||
if (config_data.cal_w2_0 != NOT_ATTACHED) {
|
||||
res.weight2 = (int32_t)my_read_average(128, 7);
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - Load_cell 2 weight2_current: %ld\n", millis(), res.weight2);
|
||||
}
|
||||
} else {
|
||||
res.weight2 = 0;
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - Load_cell 2 is disabled\n", millis());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -642,6 +656,10 @@ void ReadSensors(SENSOR_data &sensor_data) {
|
|||
// we set the weight to 0, as such high values are not realistic and probably a sign for bad calibration...
|
||||
weight_current32 = 0;
|
||||
}
|
||||
if (config_data.cal_w1_0 == NOT_ATTACHED || config_data.cal_w2_0 == NOT_ATTACHED) {
|
||||
// when at least one load cell is disabled, we multiply the measured weight by 2
|
||||
weight_current32 = weight_current32 * 2;
|
||||
}
|
||||
res.weight = (uint16_t)weight_current32;
|
||||
|
||||
if (fBme) {
|
||||
|
|
@ -1231,7 +1249,7 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
|
|||
|
||||
config_data.cal_w1_0 = cal_w1_0;
|
||||
config_data.cal_w2_0 = cal_w2_0;
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
lora_data_first.cal_w1_0 = config_data.cal_w1_0;
|
||||
lora_data_first.cal_w2_0 = config_data.cal_w2_0;
|
||||
}
|
||||
|
|
@ -1247,7 +1265,7 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
|
|||
config_data.cal_w2_0 = cal_w2_0;
|
||||
config_data.cal_w1_factor = cal_w1_factor;
|
||||
config_data.cal_w2_factor = cal_w2_factor;
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
|
||||
lora_data_first.cal_w1_0 = config_data.cal_w1_0;
|
||||
lora_data_first.cal_w2_0 = config_data.cal_w2_0;
|
||||
|
|
@ -1316,7 +1334,7 @@ cCommandStream::CommandStatus cmdCalibrateZeroScaleA(cCommandStream *pThis, void
|
|||
{
|
||||
setup_scales();
|
||||
config_data.cal_w1_0 = (int32_t)my_read_average(32, 10);
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
pThis->printf("{ \"msg\": \"calibrate_zero_scale_a was successful\" }\n");
|
||||
|
||||
return cCommandStream::CommandStatus::kSuccess;
|
||||
|
|
@ -1326,7 +1344,7 @@ cCommandStream::CommandStatus cmdCalibrateZeroScaleB(cCommandStream *pThis, void
|
|||
{
|
||||
setup_scales();
|
||||
config_data.cal_w2_0 = (int32_t)my_read_average(128, 10);
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
pThis->printf("{ \"msg\": \"calibrate_zero_scale_b was successful\" }\n");
|
||||
|
||||
return cCommandStream::CommandStatus::kSuccess;
|
||||
|
|
@ -1336,11 +1354,18 @@ cCommandStream::CommandStatus cmdCalibrateScaleA(cCommandStream *pThis, void *pC
|
|||
{
|
||||
String w1_gramm(argv[1]);
|
||||
long weight1;
|
||||
setup_scales();
|
||||
weight1 = my_read_average(32, 10);
|
||||
config_data.cal_w1_factor = (float)((weight1 - config_data.cal_w1_0) / w1_gramm.toFloat());
|
||||
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
if (w1_gramm.toFloat() == -1.0) {
|
||||
// scale a is not connected
|
||||
config_data.cal_w1_factor = 0.0;
|
||||
config_data.cal_w1_0 = NOT_ATTACHED;
|
||||
} else {
|
||||
setup_scales();
|
||||
weight1 = my_read_average(32, 10);
|
||||
config_data.cal_w1_factor = (float)((weight1 - config_data.cal_w1_0) / w1_gramm.toFloat());
|
||||
}
|
||||
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
|
||||
pThis->printf("{ \"msg\": \"calibrate_scale_a was successful\" }\n");
|
||||
|
||||
|
|
@ -1351,11 +1376,18 @@ cCommandStream::CommandStatus cmdCalibrateScaleB(cCommandStream *pThis, void *pC
|
|||
{
|
||||
String w2_gramm(argv[1]);
|
||||
long weight2;
|
||||
setup_scales();
|
||||
weight2 = my_read_average(128, 10);
|
||||
config_data.cal_w2_factor = (float)((weight2 - config_data.cal_w2_0) / w2_gramm.toFloat());
|
||||
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
if (w2_gramm.toFloat() == -1.0) {
|
||||
// scale a is not connected
|
||||
config_data.cal_w2_factor = 0.0;
|
||||
config_data.cal_w2_0 = NOT_ATTACHED;
|
||||
} else {
|
||||
setup_scales();
|
||||
weight2 = my_read_average(128, 10);
|
||||
config_data.cal_w2_factor = (float)((weight2 - config_data.cal_w2_0) / w2_gramm.toFloat());
|
||||
}
|
||||
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
|
||||
pThis->printf("{ \"msg\": \"calibrate_scale_b was successful\" }\n");
|
||||
|
||||
|
|
@ -1366,7 +1398,7 @@ cCommandStream::CommandStatus cmdSetDebugLevel(cCommandStream *pThis, void *pCon
|
|||
{
|
||||
String s_debug_level(argv[1]);
|
||||
config_data.debug_level = s_debug_level.toInt();
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
|
||||
pThis->printf("{ \"msg\": \"set_debug_level was successful\" }\n");
|
||||
|
||||
|
|
@ -1375,7 +1407,7 @@ cCommandStream::CommandStatus cmdSetDebugLevel(cCommandStream *pThis, void *pCon
|
|||
|
||||
cCommandStream::CommandStatus cmdGetDebugLevel(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
||||
{
|
||||
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
gCatena.getFram()->saveField(cFramStorage::kAppConf, (const uint8_t *)&config_data, sizeof(config_data));
|
||||
|
||||
pThis->printf("{ \"msg\": \"debug_level is %d\" }\n", config_data.debug_level);
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ enum {
|
|||
|
|
||||
\****************************************************************************/
|
||||
|
||||
static const int32_t fwVersion = 20200211;
|
||||
static const int32_t fwVersion = 202002129;
|
||||
|
||||
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
|
||||
static const byte MAX_VALUES_TO_SEND = 8;
|
||||
|
|
@ -65,15 +65,16 @@ static const uint8_t LORA_DATA_VERSION = 1;
|
|||
static const uint8_t LORA_DATA_VERSION_FIRST_PACKAGE = 128;
|
||||
static const uint32_t PRESSURE_OFFSET = 825;
|
||||
static const uint16_t SEND_DIFF_THRESHOLD_5GRAMS = 10; // when weight value drops by 50g, then send data
|
||||
static const long NOT_ATTACHED = -2147483648;
|
||||
|
||||
// must be 139 bytes long (size of kBme680Cal)
|
||||
// must be 64 bytes long (size of kAppConf)
|
||||
typedef struct {
|
||||
long cal_w1_0; // 4 Bytes, Wert Waegezelle 1 ohne Gewicht
|
||||
long cal_w2_0; // 4 Bytes, Wert Waegezelle 2 ohne Gewicht
|
||||
long cal_w1_0; // 4 Bytes, Wert Waegezelle 1 ohne Gewicht, LONG_MIN when not connected
|
||||
long cal_w2_0; // 4 Bytes, Wert Waegezelle 2 ohne Gewicht, LONG_MIN when not connected
|
||||
float cal_w1_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 1
|
||||
float cal_w2_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 2
|
||||
byte debug_level; // 0 => no debugging, no led, 1 => infos, no led, 2 => infos, 3 => error, 4 => highest level
|
||||
byte fill[122];
|
||||
byte fill[47];
|
||||
} __attribute__((packed)) CONFIG_data;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
Loading…
Reference in New Issue