power optimizations
This commit is contained in:
parent
9c8b63fda8
commit
14490795af
|
|
@ -9,7 +9,7 @@
|
|||
*/
|
||||
|
||||
// HX711: 0 => compile for hx711, 1 => compile for NAU7802
|
||||
#define HX711 1
|
||||
#define HX711 0
|
||||
|
||||
#include <Catena.h>
|
||||
|
||||
|
|
@ -752,10 +752,14 @@ void StartNewIteration() {
|
|||
|
||||
if (!fUsbPower) {
|
||||
DoDeepSleep(sleep_time_sec);
|
||||
os_setTimedCallback(
|
||||
&iterationJob,
|
||||
os_getTime() + sec2osticks(2),
|
||||
startNewIterationCb);
|
||||
if (! stop_iterations) {
|
||||
StartNewIteration();
|
||||
}
|
||||
|
||||
//os_setTimedCallback(
|
||||
// &iterationJob,
|
||||
// os_getTime() + sec2osticks(2),
|
||||
// startNewIterationCb);
|
||||
}
|
||||
else {
|
||||
if (config_data.debug_level > 0) {
|
||||
|
|
@ -947,7 +951,7 @@ void doSleepAlert(const bool fDeepSleep)
|
|||
|
||||
}
|
||||
// sleep and print
|
||||
if (config_data.debug_level > 2) {
|
||||
if (config_data.debug_level > 1) {
|
||||
gLed.Set(LedPattern::TwoShort);
|
||||
}
|
||||
|
||||
|
|
@ -1047,7 +1051,10 @@ void doLightSleep(osjob_t *pJob)
|
|||
{
|
||||
uint32_t interval = sec2osticks(CATCFG_GetInterval(gTxCycle));
|
||||
|
||||
|
||||
if (config_data.debug_level > 1) {
|
||||
gLed.Set(LedPattern::Sleeping);
|
||||
}
|
||||
|
||||
if (gCatena.GetOperatingFlags() &
|
||||
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fQuickLightSleep))
|
||||
|
|
@ -1055,7 +1062,6 @@ void doLightSleep(osjob_t *pJob)
|
|||
interval = 1;
|
||||
}
|
||||
|
||||
gLed.Set(LedPattern::Sleeping);
|
||||
os_setTimedCallback(
|
||||
&iterationJob,
|
||||
os_getTime() + interval,
|
||||
|
|
|
|||
|
|
@ -17,25 +17,38 @@ byte interruptPin = A0;
|
|||
bool SetupScales(byte dbg_level)
|
||||
{
|
||||
debug_level = dbg_level;
|
||||
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - SetupScales start\n", millis());
|
||||
}
|
||||
pinMode(interruptPin, INPUT);
|
||||
Wire.begin();
|
||||
|
||||
if (!myScale.begin())
|
||||
{
|
||||
Serial.println("Scale not detected. Please check wiring. Freezing...");
|
||||
gCatena.SafePrintf("Scale not detected. Please check wiring. Freezing...\n");
|
||||
return false;
|
||||
}
|
||||
Serial.println("Scale detected!");
|
||||
gCatena.SafePrintf("Scale detected!\n");
|
||||
|
||||
myScale.setIntPolarityHigh();
|
||||
delay(500);
|
||||
|
||||
myScale.clearBit(NAU7802_PGA_PWR_PGA_CAP_EN, NAU7802_PGA_PWR);
|
||||
myScale.setSampleRate(NAU7802_SPS_80);
|
||||
myScale.setLDO(NAU7802_LDO_3V3);
|
||||
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - SetupScales done\n", millis());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
long ReadScale(char channel)
|
||||
{
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - ReadScale Start\n", millis());
|
||||
}
|
||||
|
||||
uint8_t channelNumber;
|
||||
if (channel == 'B') {
|
||||
channelNumber = NAU7802_CHANNEL_1;
|
||||
|
|
@ -44,11 +57,7 @@ long ReadScale(char channel)
|
|||
}
|
||||
long startTime = millis();
|
||||
myScale.setChannel(channelNumber);
|
||||
myScale.clearBit(NAU7802_PGA_PWR_PGA_CAP_EN, NAU7802_PGA_PWR);
|
||||
myScale.setSampleRate(NAU7802_SPS_10);
|
||||
myScale.setLDO(NAU7802_LDO_2V7);
|
||||
myScale.calibrateAFE();
|
||||
//delay(500);
|
||||
|
||||
long res;
|
||||
int const num_scale_readings = SAMPLES; // number of instantaneous scale readings to calculate the median
|
||||
|
|
@ -85,15 +94,35 @@ long ReadScale(char channel)
|
|||
gCatena.SafePrintf("Duration (ms): %d\n", duration);
|
||||
}
|
||||
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - ReadScale Done\n", millis());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void PowerdownScale()
|
||||
{
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - PowerdownScale Start\n", millis());
|
||||
}
|
||||
myScale.powerDown();
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - PowerdownScale Done\n", millis());
|
||||
}
|
||||
}
|
||||
|
||||
void PowerupScale()
|
||||
{
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - PowerupScale Start\n", millis());
|
||||
}
|
||||
myScale.powerUp(); //Power up scale. This scale takes ~600ms to boot and take reading.
|
||||
|
||||
// we wait 100 ms to give it time to stabilze
|
||||
delay(100);
|
||||
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("%010d - PowerupScale Done\n", millis());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue