bolar_1 date 2026-7-1 d:/proc

This commit is contained in:
2026-11-27 17:44:38 +08:00
commit 0dbdfa57bc
890 changed files with 325428 additions and 0 deletions

38
main/button_config.h Normal file
View File

@@ -0,0 +1,38 @@
#pragma once
#include <string>
// ADR-004 Phase 2 — button multi-click action map, decoupled from hard-coded
// logic. Only clicks 3 and 4 are configurable; clicks 1 / 2 / long-press are
// hard-coded as safety rails (single-click chat, double-click WiFi config,
// long-press shutdown) and never touched by server config.
//
// Server pushes via hello:
// button_map: { "3": "friend_mode", "4": "network_switch" }
// Firmware caches into NVS namespace "btn_cfg" (keys c3, c4) so device works
// offline after first successful session. Unknown actions fall back to the
// legacy hard-coded default (same as pre-refactor behavior).
namespace button_config {
// Called from WebSocketProtocol hello parser. Writes NVS.
// Only keys "3" / "4" are honored. Unknown actions or invalid values are
// rejected (logged and not written) so server mistakes can't break the
// device.
void UpdateFromHello(const char* action_for_3, const char* action_for_4);
// Resolve the action name for a given click count.
// Priority: NVS value → legacy default → empty.
// count=3 legacy default = "friend_mode"
// count=4 legacy default = "network_switch"
// Other counts always return empty (caller should skip).
std::string GetAction(int count);
// Execute an action by name. Unknown action name is logged and ignored.
// Known actions:
// "friend_mode" — enter BLE friend pairing (same as legacy 3-click)
// "network_switch" — restart into the other network (same as legacy 4-click)
// "nothing" — explicit no-op (for parents who want to disable a slot)
void Execute(const std::string& action);
} // namespace button_config