more fixes

This commit is contained in:
J. Nick Koston
2026-04-07 19:47:43 -10:00
parent 439c3c9cbc
commit e22ded3803
2 changed files with 11 additions and 7 deletions
@@ -69,7 +69,8 @@ class BLECharacteristicSetValueActionManager {
template<typename... Ts> class BLECharacteristicSetValueAction : public Action<Ts...> {
public:
BLECharacteristicSetValueAction(BLECharacteristic *characteristic) : parent_(characteristic) {}
TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer)
// TemplatableValue (not TemplatableFn) — also set from C++ with raw values (initializer_list, ByteBuffer)
template<typename V> void set_buffer(V buffer) { this->buffer_ = buffer; }
void set_buffer(std::initializer_list<uint8_t> buffer) { this->buffer_ = std::vector<uint8_t>(buffer); }
void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); }
void play(const Ts &...x) override {
@@ -90,6 +91,7 @@ template<typename... Ts> class BLECharacteristicSetValueAction : public Action<T
protected:
BLECharacteristic *parent_;
TemplatableValue<std::vector<uint8_t>, Ts...> buffer_{};
};
#endif // USE_ESP32_BLE_SERVER_SET_VALUE_ACTION
@@ -115,13 +117,15 @@ template<typename... Ts> class BLECharacteristicNotifyAction : public Action<Ts.
template<typename... Ts> class BLEDescriptorSetValueAction : public Action<Ts...> {
public:
BLEDescriptorSetValueAction(BLEDescriptor *descriptor) : parent_(descriptor) {}
TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer)
// TemplatableValue (not TemplatableFn) — also set from C++ with raw values (initializer_list, ByteBuffer)
template<typename V> void set_buffer(V buffer) { this->buffer_ = buffer; }
void set_buffer(std::initializer_list<uint8_t> buffer) { this->buffer_ = std::vector<uint8_t>(buffer); }
void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); }
void play(const Ts &...x) override { this->parent_->set_value(this->buffer_.value(x...)); }
protected:
BLEDescriptor *parent_;
TemplatableValue<std::vector<uint8_t>, Ts...> buffer_{};
};
#endif // USE_ESP32_BLE_SERVER_DESCRIPTOR_SET_VALUE_ACTION
+5 -5
View File
@@ -80,11 +80,11 @@ template<typename T, typename... X> class TemplatableFn {
// Forward declaration for TemplatableValue (string specialization needs it)
template<typename T, typename... X> class TemplatableValue;
/// Selects TemplatableFn (4 bytes) for non-string types, TemplatableValue (8 bytes) for std::string.
/// std::string needs TemplatableValue for const char*, __FlashStringHelper*, and PROGMEM support.
template<typename T, typename... X>
using TemplatableStorage =
std::conditional_t<std::same_as<T, std::string>, TemplatableValue<T, X...>, TemplatableFn<T, X...>>;
/// TemplatableStorage uses TemplatableValue (8 bytes) for the TEMPLATABLE_VALUE macro.
/// Many components pass raw constants to macro-generated setters from codegen, so the
/// macro must accept both raw values and function pointers. Components that want the
/// 4-byte savings can use TemplatableFn directly instead of the macro.
template<typename T, typename... X> using TemplatableStorage = TemplatableValue<T, X...>;
#define TEMPLATABLE_VALUE_(type, name) \
protected: \