Describe interfaces with PROGMEM descriptor rows; drop the switch tables

AlexaInterfaces.h/.cpp hold one row per interface in program memory (28: namespace,
version, property names, flags, type), each row and string an object of its own, so
the linker keeps only the rows a sketch names. addCapability(AlexaInterfaceType) is
an always-inline switch that folds to one row; a type without a row is refused with
an error. The Event handler gets its type from the capabilities of the device.
Versions follow the interface pages (EndpointHealth 3.1, ThermostatController 3.2),
HumiditySensor is new, the two withdrawn interfaces and AlexaInterfaceUtils are gone.
Display category names are in flash. The discovery objects of the five examples are
unchanged: 14 new host tests compare them with what the previous commit announced.
basicLight on a D1 mini: static RAM 34,508 -> 30,788, flash 338,533 -> 330,509;
it links two rows, EndpointHealth and PowerController. Host tests: 47 -> 61.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
David 2026-09-28 19:04:14 +00:00
parent d534f23f27
commit 8b11cc2394
13 changed files with 909 additions and 777 deletions

View file

@ -0,0 +1,41 @@
// The part of Arduino.h that AlexaDevice, AlexaInterface and AlexaLog use, for the host tests (pio test -e native):
// String, Print and Serial. The program-memory helpers come from src/AlexaCompat.h. A board never sees this file.
#ifndef ALEX2ESP_HOST_ARDUINO_H
#define ALEX2ESP_HOST_ARDUINO_H
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include "AlexaCompat.h"
class String : public std::string
{
public:
String() {}
String(const char *text) : std::string(text != nullptr ? text : "") {}
String(const std::string &text) : std::string(text) {}
bool isEmpty() const { return empty(); }
};
class Print
{
public:
virtual ~Print() {}
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
size_t print(const char *text) { return write(reinterpret_cast<const uint8_t *>(text), strlen(text)); }
size_t println(const char *text) { return print(text) + print("\r\n"); }
};
class HostSerial : public Print
{
public:
size_t write(const uint8_t *buffer, size_t size) override { return fwrite(buffer, 1, size, stdout); }
};
inline HostSerial Serial;
#endif // ALEX2ESP_HOST_ARDUINO_H