refactor code
This commit is contained in:
parent
a97afbf36c
commit
3d03d0b52d
|
|
@ -235,7 +235,7 @@ bool fUsbPower;
|
|||
// have we printed the sleep info?
|
||||
bool g_fPrintedSleeping = false;
|
||||
|
||||
// the job that's used to synchronize us with the LMIC code
|
||||
// tFhe job that's used to synchronize us with the LMIC code
|
||||
static osjob_t sensorJob;
|
||||
void sensorJob_cb(osjob_t* pJob);
|
||||
|
||||
|
|
@ -365,6 +365,9 @@ void setup_platform(void)
|
|||
gCatena.SafePrintf("**** no platform, check provisioning ****\n");
|
||||
flags = 0;
|
||||
}
|
||||
// Because of Alarms on Swisscom Network
|
||||
LMIC_setDrTxpow(DR_SF10, 14);
|
||||
LMIC_setAdrMode(1);
|
||||
}
|
||||
|
||||
void setup_bme280(void)
|
||||
|
|
@ -378,8 +381,11 @@ void setup_bme280(void)
|
|||
}
|
||||
}
|
||||
|
||||
void setup_scales(void)
|
||||
bool setup_scales(void)
|
||||
{
|
||||
bool res;
|
||||
res = true;
|
||||
|
||||
#ifdef DEBUG
|
||||
gCatena.SafePrintf("Setup Scales...\n");
|
||||
#endif
|
||||
|
|
@ -398,13 +404,16 @@ void setup_scales(void)
|
|||
#endif
|
||||
LoadCell.begin(A1, A0);
|
||||
|
||||
if (!(LoadCell.wait_ready_timeout(1000))) {
|
||||
gCatena.SafePrintf("Scale not ready.\n");
|
||||
if (!(LoadCell.wait_ready_timeout(2000))) {
|
||||
gCatena.SafePrintf("Scale not ready after Init.\n");
|
||||
res = false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
gCatena.SafePrintf("Setup Scale is complete\n");
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void setup_flash(void)
|
||||
|
|
@ -592,30 +601,6 @@ void ReadSensors(bool firstTime, bool readOnly)
|
|||
int32_t weight_current32;
|
||||
uint16_t weight_current;
|
||||
|
||||
if (fBme) {
|
||||
/* warm up the BME280 by discarding a measurement */
|
||||
(void)gBME280.readTemperature();
|
||||
|
||||
Adafruit_BME280::Measurements m = gBME280.readTemperaturePressureHumidity();
|
||||
// temperature is 2 bytes from -0x80.00 to +0x7F.FF degrees C
|
||||
// pressure is 2 bytes, hPa * 10.
|
||||
// humidity is one byte, where 0 == 0/256 and 0xFF == 255/256.
|
||||
#ifdef DEBUG
|
||||
gCatena.SafePrintf(
|
||||
"BME280: T: %d P: %d RH: %d\n",
|
||||
(int)m.Temperature,
|
||||
(int)m.Pressure,
|
||||
(int)m.Humidity);
|
||||
#endif
|
||||
temp_current = (int16_t)((m.Temperature) * 10);
|
||||
humidity_current = (uint8_t)m.Humidity;
|
||||
pressure_current = (uint8_t)((m.Pressure / 100) - PRESSURE_OFFSET);
|
||||
#ifdef DEBUG
|
||||
gCatena.SafePrintf("pressure_current: %d\n", pressure_current);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// vBat
|
||||
float vBat = gCatena.ReadVbat();
|
||||
#ifdef DEBUG
|
||||
|
|
@ -633,7 +618,8 @@ void ReadSensors(bool firstTime, bool readOnly)
|
|||
setup_scales();
|
||||
|
||||
// Read Scales
|
||||
if (LoadCell.is_ready()) {
|
||||
//if (LoadCell.is_ready()) {
|
||||
if (setup_scales()) {
|
||||
#ifdef DEBUG
|
||||
Serial.println("HX711 LoadCell is ready.");
|
||||
#endif
|
||||
|
|
@ -668,6 +654,29 @@ void ReadSensors(bool firstTime, bool readOnly)
|
|||
}
|
||||
weight_current = (uint16_t)weight_current32;
|
||||
|
||||
if (fBme) {
|
||||
/* warm up the BME280 by discarding a measurement */
|
||||
(void)gBME280.readTemperature();
|
||||
|
||||
Adafruit_BME280::Measurements m = gBME280.readTemperaturePressureHumidity();
|
||||
// temperature is 2 bytes from -0x80.00 to +0x7F.FF degrees C
|
||||
// pressure is 2 bytes, hPa * 10.
|
||||
// humidity is one byte, where 0 == 0/256 and 0xFF == 255/256.
|
||||
#ifdef DEBUG
|
||||
gCatena.SafePrintf(
|
||||
"BME280: T: %d P: %d RH: %d\n",
|
||||
(int)m.Temperature,
|
||||
(int)m.Pressure,
|
||||
(int)m.Humidity);
|
||||
#endif
|
||||
temp_current = (int16_t)((m.Temperature) * 10);
|
||||
humidity_current = (uint8_t)m.Humidity;
|
||||
pressure_current = (uint8_t)((m.Pressure / 100) - PRESSURE_OFFSET);
|
||||
#ifdef DEBUG
|
||||
gCatena.SafePrintf("pressure_current: %d\n", pressure_current);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (not(readOnly)) {
|
||||
|
||||
if (firstTime) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue