Alex2ESP/test/host_arduino/Arduino.h
David 7afc4346e8 AlexaCapability: instance, asset and text names, configuration, action and state mappings, nonControllable
AlexaCapability replaces the header-only AlexaInterface as what a device holds: 116 bytes with fixed places for
3 names, 4 action mappings and 2 state mappings, no std::vector or std::string. AlexaInterface and AlexaActions
stay as 1.x names; the five examples compile unchanged and announce the same bytes.
addCapability(row, instance) adds several capabilities of one generic controller. An instanced interface without
an instance or a name, an instance or semantics on an interface that takes none, and a full store are refused
with an ERROR line that says what to change.
PlaybackController and WakeOnLANController announce "properties": {} (AIF_EMPTY_PROPERTIES).
basicLight on a D1 mini: static RAM 30,788 -> 30,672 B, flash 330,509 -> 332,541 B; host tests 61 -> 77.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-28 19:33:57 +00:00

41 lines
1.2 KiB
C++

// The part of Arduino.h that AlexaDevice, AlexaCapability 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