MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / setPowerSaving

Method setPowerSaving

lib/hal/HalPowerManager.cpp:28–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28void HalPowerManager::setPowerSaving(bool enabled) {
29 if (normalFreq <= 0) {
30 return; // invalid state
31 }
32
33 auto wifiMode = WiFi.getMode();
34 if (wifiMode != WIFI_MODE_NULL) {
35 // Wifi is active, force disabling power saving
36 enabled = false;
37 }
38
39 // Note: We don't use mutex here to avoid too much overhead,
40 // it's not very important if we read a slightly stale value for currentLockMode
41 const LockMode mode = currentLockMode;
42
43 if (mode == None && enabled && !isLowPower) {
44 LOG_DBG("PWR", "Going to low-power mode");
45 if (!setCpuFrequencyMhz(LOW_POWER_FREQ)) {
46 LOG_DBG("PWR", "Failed to set CPU frequency = %d MHz", LOW_POWER_FREQ);
47 return;
48 }
49 isLowPower = true;
50
51 } else if ((!enabled || mode != None) && isLowPower) {
52 LOG_DBG("PWR", "Restoring normal CPU frequency");
53 if (!setCpuFrequencyMhz(normalFreq)) {
54 LOG_DBG("PWR", "Failed to set CPU frequency = %d MHz", normalFreq);
55 return;
56 }
57 isLowPower = false;
58 }
59
60 // Otherwise, no change needed
61}
62
63void HalPowerManager::startDeepSleep(HalGPIO& gpio) const {
64 // Ensure that the power button has been released to avoid immediately turning back on if you're holding it

Callers 2

LockMethod · 0.80
loopFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected