Skip to content

Commit fb1fbc7

Browse files
committed
Make power down a direct function to call without any begin
1 parent cfc6338 commit fb1fbc7

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

src/examples/low_power/low_power.ino

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void setup() {
6969
// In powerSave(), after the LTE modem is sleeping, we also put the
7070
// CPU to sleep. When the time period is over, the CPU is woken at the same
7171
// time as the LTE modem is woken up.
72+
7273
LowPower.configurePeriodicPowerSave(
7374
PowerSaveModePeriodMultiplier::THIRTY_SECONDS, 2);
7475

@@ -93,5 +94,5 @@ void loop() {
9394

9495
// Do work ...
9596
Log.info("Doing work...");
96-
delay(5000);
97+
delay(10000);
9798
}

src/low_power.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ static volatile bool ring_line_activity = false;
7575
static volatile bool modem_is_in_power_save = false;
7676
static volatile bool pit_triggered = false;
7777

78-
static uint32_t power_down_time = 0;
79-
8078
static bool retrieved_period = false;
8179
static uint32_t period = 0;
8280
static uint32_t period_requested = 0;
@@ -323,10 +321,6 @@ static void powerUpPeripherals(void) {
323321
}
324322
}
325323

326-
void LowPowerClass::configurePowerDown(const uint32_t power_down_seconds) {
327-
power_down_time = power_down_seconds;
328-
}
329-
330324
bool LowPowerClass::configurePeriodicPowerSave(
331325
const PowerSaveModePeriodMultiplier power_save_mode_period_multiplier,
332326
const uint8_t power_save_mode_period_value) {
@@ -438,7 +432,7 @@ void LowPowerClass::powerSave(void) {
438432
powerUpPeripherals();
439433
}
440434

441-
void LowPowerClass::powerDown(void) {
435+
void LowPowerClass::powerDown(const uint32_t power_down_time_seconds) {
442436

443437
const unsigned long start_time_ms = millis();
444438

@@ -449,8 +443,10 @@ void LowPowerClass::powerDown(void) {
449443
enablePIT();
450444

451445
uint32_t remaining_time_seconds =
452-
period - (uint32_t)(((millis() - start_time_ms) / 1000.0f));
446+
power_down_time_seconds -
447+
(uint32_t)(((millis() - start_time_ms) / 1000.0f));
453448

449+
// TODO: There is some external interrupt causing the avr to wake
454450
while (remaining_time_seconds > 0) {
455451

456452
sleep_cpu();

src/low_power.h

+8-14
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ class LowPowerClass {
3737
return instance;
3838
}
3939

40-
/**
41-
* @brief configures the time spent in power down for both modem and CPU.
42-
*
43-
* @param power_down_seconds Time the LTE modem and CPU will be powered down
44-
* when calling #powerDown().
45-
*/
46-
void configurePowerDown(const uint32_t power_down_seconds);
47-
4840
/**
4941
* @brief Used to configure power save mode for the LTE modem. The total
5042
* power save time period for the LTE modem will be
@@ -71,12 +63,6 @@ class LowPowerClass {
7163
const PowerSaveModePeriodMultiplier power_save_mode_period_multiplier,
7264
const uint8_t power_save_mode_period_value);
7365

74-
/**
75-
* @brief Will power down both CPU and LTE modem. All active connections on
76-
* the modem will be terminated.
77-
*/
78-
void powerDown(void);
79-
8066
/**
8167
* @brief Will attempt to put the modem in power save and then power down
8268
* the MCU for the time configured in configurePeriodicPowerSave(). Note
@@ -86,6 +72,14 @@ class LowPowerClass {
8672
* sleep time.
8773
*/
8874
void powerSave(void);
75+
76+
/**
77+
* @brief Will power down both CPU and LTE modem. All active connections on
78+
* the modem will be terminated.
79+
*
80+
* @power_down_time_seconds Seconds to remain powered down.
81+
*/
82+
void powerDown(const uint32_t power_down_time_seconds);
8983
};
9084

9185
extern LowPowerClass LowPower;

src/lte.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void LteClass::begin(void) {
137137
}
138138

139139
void LteClass::end(void) {
140+
SequansController.unregisterCallback(CEREG_CALLBACK);
140141
SequansController.retryCommand(AT_COMMAND_DISCONNECT);
141142
SequansController.end();
142143
}

0 commit comments

Comments
 (0)