Files
powerpods/main/cmd/cmd_client_info.c
T
skrueckenandCursor 7f28a48a10 Add runtime UV protection toggle and treat near-zero sense as external power.
Per-pod NVS enable (default off) via UART/ESP-NOW/dashboard, and skip UV latch when LiPo ADC reads ~0 mV so USB/external supply still boots.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-01 22:51:17 +01:00

65 lines
2.1 KiB
C

#include "client_registry.h"
#include "cmd_client_info.h"
#include "esp_log.h"
#include "pb_encode.h"
#include "uart_cmd.h"
static const char *TAG = "[CLIENT_INFO]";
static bool encode_clients_list(pb_ostream_t *stream, const pb_field_t *field,
void *const *arg) {
(void)arg;
size_t count = client_registry_count();
for (size_t i = 0; i < count; i++) {
const client_info_t *client = client_registry_at(i);
if (client == NULL) {
continue;
}
uart_cmd_bytes_t mac = {.data = client->mac, .len = CLIENT_MAC_LEN};
alox_ClientInfo proto = alox_ClientInfo_init_zero;
proto.id = client->id;
proto.available = client->available;
proto.used = client->used;
proto.last_ping = client_registry_ms_since(client->last_ping_at);
proto.last_success_ping =
client_registry_ms_since(client->last_success_ping_at);
proto.version = client->version;
proto.accel_stream_enabled = client->accel_stream_enabled;
proto.tap_notify_single = client->tap_notify_single;
proto.tap_notify_double = client->tap_notify_double;
proto.tap_notify_triple = client->tap_notify_triple;
proto.uv_protection_enabled = client->uv_protection_enabled;
proto.mac.funcs.encode = uart_cmd_encode_bytes;
proto.mac.arg = &mac;
if (!pb_encode_tag_for_field(stream, field)) {
return false;
}
if (!pb_encode_submessage(stream, alox_ClientInfo_fields, &proto)) {
return false;
}
}
return true;
}
static void handle_client_info(const uint8_t *data, size_t len) {
(void)data;
(void)len;
alox_UartMessage response;
uart_cmd_init_response(&response, alox_MessageType_CLIENT_INFO,
alox_UartMessage_client_info_response_tag);
response.payload.client_info_response.clients.funcs.encode = encode_clients_list;
response.payload.client_info_response.clients.arg = NULL;
ESP_LOGI(TAG, "sending %u clients", (unsigned)client_registry_count());
uart_cmd_send(&response, TAG);
}
void cmd_client_info_register(void) {
uart_cmd_register(alox_MessageType_CLIENT_INFO, handle_client_info);
}