Files
jimmyandClaude Opus 5.5 24dd5ffb15 feat: ESP-NOW link, beat sync and control messages in the C++ driver
- espnow_link, ctrl_msg and beat_sync: the reliable link, envelopes and
  beat-synced timing.
- ctrl_msg: accept an envelope with the trailing save byte.
- patterns_frame() and espnow_link_poll() split out of their tasks, so the
  WebAssembly simulator can drive one frame and one link pass from a timer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:32:36 +13:00

62 lines
2.1 KiB
C

/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <cstddef>
#include "cJSON.h"
#include "esp_err.h"
#include "patterns.h"
// Flash holds about 50 presets (the nvs partition is 24 KB); 48 leaves room for garbage collection
#define PRESETS_MAX 48
/** @brief Load the saved presets and the startup name from NVS. Call after NVS is initialised. */
esp_err_t presets_init(void);
/** @brief Add the default presets whose names are not in the list yet. Returns how many were added. */
int presets_add_defaults(void);
/** @brief Number of presets. */
size_t presets_count(void);
/** @brief Preset at index i (0 <= i < presets_count()). */
const preset_t *presets_at(size_t i);
/** @brief Create a preset, or update the one with the same name. ESP_ERR_NO_MEM when full. */
esp_err_t presets_save(const preset_t *preset);
/** @brief Saves refused since boot: store full, or flash write failed. */
uint32_t presets_dropped(void);
/** @brief Put the presets in this order. Names not given keep their place at the end. */
esp_err_t presets_set_order(const char *const *names, size_t n);
/** @brief Delete a preset by name. Clears the startup name if it was that preset. */
esp_err_t presets_delete(const char *name);
/** @brief Select a preset: crossfades in and restarts its pattern. ESP_ERR_NOT_FOUND if no such name. */
esp_err_t presets_select(const char *name);
/** @brief Name of the last preset selected since boot, or "". */
const char *presets_selected(void);
/** @brief Set the preset applied at boot. An empty name clears it. */
esp_err_t presets_set_startup(const char *name);
/** @brief Name of the startup preset, or "". */
const char *presets_startup(void);
/** @brief Apply the startup preset, if one is set and still exists. */
void presets_apply_startup(void);
/** @brief A preset as JSON, with the MicroPython field names. The caller frees it with cJSON_Delete. */
cJSON *preset_to_json(const preset_t *p);
/**
* @brief Apply the fields present in JSON onto p; missing fields keep their value.
* @return false if a field is malformed (an unknown pattern name, for example).
*/
bool preset_from_json(const cJSON *o, preset_t *p);