power optimizations
This commit is contained in:
parent
9c8b63fda8
commit
14490795af
|
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// HX711: 0 => compile for hx711, 1 => compile for NAU7802
|
// HX711: 0 => compile for hx711, 1 => compile for NAU7802
|
||||||
#define HX711 1
|
#define HX711 0
|
||||||
|
|
||||||
#include <Catena.h>
|
#include <Catena.h>
|
||||||
|
|
||||||
|
|
@ -752,10 +752,14 @@ void StartNewIteration() {
|
||||||
|
|
||||||
if (!fUsbPower) {
|
if (!fUsbPower) {
|
||||||
DoDeepSleep(sleep_time_sec);
|
DoDeepSleep(sleep_time_sec);
|
||||||
os_setTimedCallback(
|
if (! stop_iterations) {
|
||||||
&iterationJob,
|
StartNewIteration();
|
||||||
os_getTime() + sec2osticks(2),
|
}
|
||||||
startNewIterationCb);
|
|
||||||
|
//os_setTimedCallback(
|
||||||
|
// &iterationJob,
|
||||||
|
// os_getTime() + sec2osticks(2),
|
||||||
|
// startNewIterationCb);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (config_data.debug_level > 0) {
|
if (config_data.debug_level > 0) {
|
||||||
|
|
@ -947,7 +951,7 @@ void doSleepAlert(const bool fDeepSleep)
|
||||||
|
|
||||||
}
|
}
|
||||||
// sleep and print
|
// sleep and print
|
||||||
if (config_data.debug_level > 2) {
|
if (config_data.debug_level > 1) {
|
||||||
gLed.Set(LedPattern::TwoShort);
|
gLed.Set(LedPattern::TwoShort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1047,7 +1051,10 @@ void doLightSleep(osjob_t *pJob)
|
||||||
{
|
{
|
||||||
uint32_t interval = sec2osticks(CATCFG_GetInterval(gTxCycle));
|
uint32_t interval = sec2osticks(CATCFG_GetInterval(gTxCycle));
|
||||||
|
|
||||||
|
|
||||||
|
if (config_data.debug_level > 1) {
|
||||||
gLed.Set(LedPattern::Sleeping);
|
gLed.Set(LedPattern::Sleeping);
|
||||||
|
}
|
||||||
|
|
||||||
if (gCatena.GetOperatingFlags() &
|
if (gCatena.GetOperatingFlags() &
|
||||||
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fQuickLightSleep))
|
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fQuickLightSleep))
|
||||||
|
|
@ -1055,7 +1062,6 @@ void doLightSleep(osjob_t *pJob)
|
||||||
interval = 1;
|
interval = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gLed.Set(LedPattern::Sleeping);
|
|
||||||
os_setTimedCallback(
|
os_setTimedCallback(
|
||||||
&iterationJob,
|
&iterationJob,
|
||||||
os_getTime() + interval,
|
os_getTime() + interval,
|
||||||
|
|
|
||||||
|
|
@ -17,25 +17,38 @@ byte interruptPin = A0;
|
||||||
bool SetupScales(byte dbg_level)
|
bool SetupScales(byte dbg_level)
|
||||||
{
|
{
|
||||||
debug_level = dbg_level;
|
debug_level = dbg_level;
|
||||||
|
if (debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("%010d - SetupScales start\n", millis());
|
||||||
|
}
|
||||||
pinMode(interruptPin, INPUT);
|
pinMode(interruptPin, INPUT);
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
if (!myScale.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;
|
return false;
|
||||||
}
|
}
|
||||||
Serial.println("Scale detected!");
|
gCatena.SafePrintf("Scale detected!\n");
|
||||||
|
|
||||||
myScale.setIntPolarityHigh();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ReadScale(char channel)
|
long ReadScale(char channel)
|
||||||
{
|
{
|
||||||
|
if (debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("%010d - ReadScale Start\n", millis());
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t channelNumber;
|
uint8_t channelNumber;
|
||||||
if (channel == 'B') {
|
if (channel == 'B') {
|
||||||
channelNumber = NAU7802_CHANNEL_1;
|
channelNumber = NAU7802_CHANNEL_1;
|
||||||
|
|
@ -44,11 +57,7 @@ long ReadScale(char channel)
|
||||||
}
|
}
|
||||||
long startTime = millis();
|
long startTime = millis();
|
||||||
myScale.setChannel(channelNumber);
|
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();
|
myScale.calibrateAFE();
|
||||||
//delay(500);
|
|
||||||
|
|
||||||
long res;
|
long res;
|
||||||
int const num_scale_readings = SAMPLES; // number of instantaneous scale readings to calculate the median
|
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);
|
gCatena.SafePrintf("Duration (ms): %d\n", duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("%010d - ReadScale Done\n", millis());
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerdownScale()
|
void PowerdownScale()
|
||||||
{
|
{
|
||||||
|
if (debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("%010d - PowerdownScale Start\n", millis());
|
||||||
|
}
|
||||||
myScale.powerDown();
|
myScale.powerDown();
|
||||||
|
if (debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("%010d - PowerdownScale Done\n", millis());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerupScale()
|
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.
|
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