Handle denials of power appropriately

This commit is contained in:
2025-02-12 22:59:13 +01:00
parent 21f7d9ae8a
commit c130026f00
19 changed files with 126 additions and 47 deletions

View File

@@ -45,12 +45,16 @@ void nodeTimeAdjustedCallback(int32_t offset) {
void vTaskUpdate(void *pvParameters) {
for (;;) {
Power::waitForCurrentAllowance(
PowerParameters::PowerConsumers::WIFI,
PowerParameters::CurrentConsumptions::CURRENT_WIFI_PEAK +
PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE,
MESH_MAX_EXECUTION_DELAY_MS, NULL);
mesh.update();
if (Power::waitForCurrentAllowance(
PowerParameters::PowerConsumers::WIFI,
PowerParameters::CurrentConsumptions::CURRENT_WIFI_PEAK +
PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE,
MESH_MAX_EXECUTION_DELAY_MS, NULL)) {
mesh.update();
} else {
ESP_LOGW(TAG, "Skipping mesh update after not being granted power");
}
Power::waitForCurrentAllowance(
PowerParameters::PowerConsumers::WIFI,
PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE,
@@ -73,10 +77,13 @@ void Communication::begin(void) {
mesh.setDebugMsgTypes(
ERROR |
STARTUP); // set before init() so that you can see startup messages
Power::waitForCurrentAllowance(
PowerParameters::PowerConsumers::WIFI,
PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE,
MESH_MAX_EXECUTION_DELAY_MS, NULL);
if (!Power::waitForCurrentAllowance(
PowerParameters::PowerConsumers::WIFI,
PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE,
MESH_MAX_EXECUTION_DELAY_MS, NULL)) {
ESP_LOGE(TAG, "Failed to get power for mesh initialization");
throw "Failed to get power for mesh initialization";
}
mesh.init(MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT);
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);

View File

@@ -1,18 +1,17 @@
#ifndef Communication_h
#define Communication_h
#include <stdint.h>
#include "../power/Power.h"
#include <Arduino.h>
#include <painlessMesh.h>
#include "../power/Power.h"
#include <stdint.h>
#define MESH_PREFIX "DEZIBOT_MESH"
#define MESH_PASSWORD "somethingSneaky"
#define MESH_PORT 5555
#define MESH_MAX_EXECUTION_DELAY_MS 10
#define TAG "Communication"
class Communication{
public: