Skip to content

Commit

Permalink
Power saving repeater
Browse files Browse the repository at this point in the history
  • Loading branch information
thebentern committed Oct 5, 2023
1 parent 7f039a6 commit 303016b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,10 @@ void setup()

readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time)

gps = GPS::createGps();
if (config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER) {
gps = GPS::createGps();
}

if (gps) {
gpsStatus->observe(&gps->newStatus);
} else {
Expand Down Expand Up @@ -738,6 +741,10 @@ void setup()
powerFSMthread = new PowerFSMThread();

setCPUFast(false); // 80MHz is fine for our slow peripherals
// Power saving Repeaters turn pretty much everything off except the radio and CPU
if (config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER && config.power.is_power_saving) {
setCpuLowPower();
}
}

uint32_t rebootAtMsec; // If not zero we will reboot at this time (used to reboot shortly after the update completes)
Expand Down
29 changes: 29 additions & 0 deletions src/platform/nrf52/main-nrf52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,33 @@ void clearBonds()
nrf52Bluetooth->setup();
}
nrf52Bluetooth->clearBonds();
}

void setCpuLowPower()
{
LOG_DEBUG("Setting CPU to LOW power\n");
// This may cause crashes as debug messages continue to flow.
Serial.end();

#ifdef PIN_SERIAL_RX1
Serial1.end();
#endif
setBluetoothEnable(false);

#ifdef RAK4630
#ifdef PIN_3V3_EN
digitalWrite(PIN_3V3_EN, LOW);
#endif
#ifndef USE_EINK
// RAK-12039 set pin for Air quality sensor
digitalWrite(AQ_SET_PIN, LOW);
#endif
#endif
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
}

void setCpuHighPower()
{
LOG_DEBUG("Setting CPU to HIGH power\n");
sd_power_mode_set(NRF_POWER_MODE_CONSTLAT);
}
6 changes: 5 additions & 1 deletion src/target_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
// Enable/disable bluetooth.
void setBluetoothEnable(bool on);

void getMacAddr(uint8_t *dmac);
void getMacAddr(uint8_t *dmac);

void setCpuHighPower();

void setCpuLowPower();

0 comments on commit 303016b

Please sign in to comment.