mirror of
https://github.com/esphome/esphome.git
synced 2025-09-28 08:02:23 +01:00
cond
This commit is contained in:
@@ -488,6 +488,7 @@ async def to_code_descriptor(descriptor_conf, char_var):
|
|||||||
cg.add(desc_var.set_value(value))
|
cg.add(desc_var.set_value(value))
|
||||||
if CONF_ON_WRITE in descriptor_conf:
|
if CONF_ON_WRITE in descriptor_conf:
|
||||||
on_write_conf = descriptor_conf[CONF_ON_WRITE]
|
on_write_conf = descriptor_conf[CONF_ON_WRITE]
|
||||||
|
cg.add_define("USE_ESP32_BLE_SERVER_DESCRIPTOR_ON_WRITE")
|
||||||
await automation.build_automation(
|
await automation.build_automation(
|
||||||
BLETriggers_ns.create_descriptor_on_write_trigger(desc_var),
|
BLETriggers_ns.create_descriptor_on_write_trigger(desc_var),
|
||||||
[(cg.std_vector.template(cg.uint8), "x"), (cg.uint16, "id")],
|
[(cg.std_vector.template(cg.uint8), "x"), (cg.uint16, "id")],
|
||||||
@@ -505,6 +506,7 @@ async def to_code_characteristic(service_var, char_conf):
|
|||||||
)
|
)
|
||||||
if CONF_ON_WRITE in char_conf:
|
if CONF_ON_WRITE in char_conf:
|
||||||
on_write_conf = char_conf[CONF_ON_WRITE]
|
on_write_conf = char_conf[CONF_ON_WRITE]
|
||||||
|
cg.add_define("USE_ESP32_BLE_SERVER_CHARACTERISTIC_ON_WRITE")
|
||||||
await automation.build_automation(
|
await automation.build_automation(
|
||||||
BLETriggers_ns.create_characteristic_on_write_trigger(char_var),
|
BLETriggers_ns.create_characteristic_on_write_trigger(char_var),
|
||||||
[(cg.std_vector.template(cg.uint8), "x"), (cg.uint16, "id")],
|
[(cg.std_vector.template(cg.uint8), "x"), (cg.uint16, "id")],
|
||||||
@@ -560,12 +562,14 @@ async def to_code(config):
|
|||||||
else:
|
else:
|
||||||
cg.add(var.enqueue_start_service(service_var))
|
cg.add(var.enqueue_start_service(service_var))
|
||||||
if CONF_ON_CONNECT in config:
|
if CONF_ON_CONNECT in config:
|
||||||
|
cg.add_define("USE_ESP32_BLE_SERVER_ON_CONNECT")
|
||||||
await automation.build_automation(
|
await automation.build_automation(
|
||||||
BLETriggers_ns.create_server_on_connect_trigger(var),
|
BLETriggers_ns.create_server_on_connect_trigger(var),
|
||||||
[(cg.uint16, "id")],
|
[(cg.uint16, "id")],
|
||||||
config[CONF_ON_CONNECT],
|
config[CONF_ON_CONNECT],
|
||||||
)
|
)
|
||||||
if CONF_ON_DISCONNECT in config:
|
if CONF_ON_DISCONNECT in config:
|
||||||
|
cg.add_define("USE_ESP32_BLE_SERVER_ON_DISCONNECT")
|
||||||
await automation.build_automation(
|
await automation.build_automation(
|
||||||
BLETriggers_ns.create_server_on_disconnect_trigger(var),
|
BLETriggers_ns.create_server_on_disconnect_trigger(var),
|
||||||
[(cg.uint16, "id")],
|
[(cg.uint16, "id")],
|
||||||
@@ -594,6 +598,7 @@ async def ble_server_characteristic_set_value(config, action_id, template_arg, a
|
|||||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
value = await parse_value(config[CONF_VALUE], args)
|
value = await parse_value(config[CONF_VALUE], args)
|
||||||
cg.add(var.set_buffer(value))
|
cg.add(var.set_buffer(value))
|
||||||
|
cg.add_define("USE_ESP32_BLE_SERVER_SET_VALUE_ACTION")
|
||||||
return var
|
return var
|
||||||
|
|
||||||
|
|
||||||
@@ -612,6 +617,7 @@ async def ble_server_descriptor_set_value(config, action_id, template_arg, args)
|
|||||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
value = await parse_value(config[CONF_VALUE], args)
|
value = await parse_value(config[CONF_VALUE], args)
|
||||||
cg.add(var.set_buffer(value))
|
cg.add(var.set_buffer(value))
|
||||||
|
cg.add_define("USE_ESP32_BLE_SERVER_DESCRIPTOR_SET_VALUE_ACTION")
|
||||||
return var
|
return var
|
||||||
|
|
||||||
|
|
||||||
@@ -629,4 +635,5 @@ async def ble_server_descriptor_set_value(config, action_id, template_arg, args)
|
|||||||
)
|
)
|
||||||
async def ble_server_characteristic_notify(config, action_id, template_arg, args):
|
async def ble_server_characteristic_notify(config, action_id, template_arg, args):
|
||||||
paren = await cg.get_variable(config[CONF_ID])
|
paren = await cg.get_variable(config[CONF_ID])
|
||||||
|
cg.add_define("USE_ESP32_BLE_SERVER_NOTIFY_ACTION")
|
||||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
|
@@ -9,6 +9,7 @@ namespace esp32_ble_server_automations {
|
|||||||
|
|
||||||
using namespace esp32_ble;
|
using namespace esp32_ble;
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_CHARACTERISTIC_ON_WRITE
|
||||||
Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_characteristic_on_write_trigger(
|
Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_characteristic_on_write_trigger(
|
||||||
BLECharacteristic *characteristic) {
|
BLECharacteristic *characteristic) {
|
||||||
Trigger<std::vector<uint8_t>, uint16_t> *on_write_trigger = // NOLINT(cppcoreguidelines-owning-memory)
|
Trigger<std::vector<uint8_t>, uint16_t> *on_write_trigger = // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
@@ -18,7 +19,9 @@ Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_characteristic_on_w
|
|||||||
[on_write_trigger](const std::vector<uint8_t> &data, uint16_t id) { on_write_trigger->trigger(data, id); });
|
[on_write_trigger](const std::vector<uint8_t> &data, uint16_t id) { on_write_trigger->trigger(data, id); });
|
||||||
return on_write_trigger;
|
return on_write_trigger;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_DESCRIPTOR_ON_WRITE
|
||||||
Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_descriptor_on_write_trigger(BLEDescriptor *descriptor) {
|
Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_descriptor_on_write_trigger(BLEDescriptor *descriptor) {
|
||||||
Trigger<std::vector<uint8_t>, uint16_t> *on_write_trigger = // NOLINT(cppcoreguidelines-owning-memory)
|
Trigger<std::vector<uint8_t>, uint16_t> *on_write_trigger = // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
new Trigger<std::vector<uint8_t>, uint16_t>();
|
new Trigger<std::vector<uint8_t>, uint16_t>();
|
||||||
@@ -27,21 +30,27 @@ Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_descriptor_on_write
|
|||||||
[on_write_trigger](const std::vector<uint8_t> &data, uint16_t id) { on_write_trigger->trigger(data, id); });
|
[on_write_trigger](const std::vector<uint8_t> &data, uint16_t id) { on_write_trigger->trigger(data, id); });
|
||||||
return on_write_trigger;
|
return on_write_trigger;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_ON_CONNECT
|
||||||
Trigger<uint16_t> *BLETriggers::create_server_on_connect_trigger(BLEServer *server) {
|
Trigger<uint16_t> *BLETriggers::create_server_on_connect_trigger(BLEServer *server) {
|
||||||
Trigger<uint16_t> *on_connect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
|
Trigger<uint16_t> *on_connect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
server->on(BLEServerEvt::EmptyEvt::ON_CONNECT,
|
server->on(BLEServerEvt::EmptyEvt::ON_CONNECT,
|
||||||
[on_connect_trigger](uint16_t conn_id) { on_connect_trigger->trigger(conn_id); });
|
[on_connect_trigger](uint16_t conn_id) { on_connect_trigger->trigger(conn_id); });
|
||||||
return on_connect_trigger;
|
return on_connect_trigger;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_ON_DISCONNECT
|
||||||
Trigger<uint16_t> *BLETriggers::create_server_on_disconnect_trigger(BLEServer *server) {
|
Trigger<uint16_t> *BLETriggers::create_server_on_disconnect_trigger(BLEServer *server) {
|
||||||
Trigger<uint16_t> *on_disconnect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
|
Trigger<uint16_t> *on_disconnect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
server->on(BLEServerEvt::EmptyEvt::ON_DISCONNECT,
|
server->on(BLEServerEvt::EmptyEvt::ON_DISCONNECT,
|
||||||
[on_disconnect_trigger](uint16_t conn_id) { on_disconnect_trigger->trigger(conn_id); });
|
[on_disconnect_trigger](uint16_t conn_id) { on_disconnect_trigger->trigger(conn_id); });
|
||||||
return on_disconnect_trigger;
|
return on_disconnect_trigger;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_SET_VALUE_ACTION
|
||||||
void BLECharacteristicSetValueActionManager::set_listener(BLECharacteristic *characteristic,
|
void BLECharacteristicSetValueActionManager::set_listener(BLECharacteristic *characteristic,
|
||||||
EventEmitterListenerID listener_id,
|
EventEmitterListenerID listener_id,
|
||||||
const std::function<void()> &pre_notify_listener) {
|
const std::function<void()> &pre_notify_listener) {
|
||||||
@@ -90,6 +99,7 @@ void BLECharacteristicSetValueActionManager::remove_listener_(BLECharacteristic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace esp32_ble_server_automations
|
} // namespace esp32_ble_server_automations
|
||||||
} // namespace esp32_ble_server
|
} // namespace esp32_ble_server
|
||||||
|
@@ -25,13 +25,22 @@ static constexpr EventEmitterListenerID INVALID_LISTENER_ID = 0;
|
|||||||
|
|
||||||
class BLETriggers {
|
class BLETriggers {
|
||||||
public:
|
public:
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_CHARACTERISTIC_ON_WRITE
|
||||||
static Trigger<std::vector<uint8_t>, uint16_t> *create_characteristic_on_write_trigger(
|
static Trigger<std::vector<uint8_t>, uint16_t> *create_characteristic_on_write_trigger(
|
||||||
BLECharacteristic *characteristic);
|
BLECharacteristic *characteristic);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_DESCRIPTOR_ON_WRITE
|
||||||
static Trigger<std::vector<uint8_t>, uint16_t> *create_descriptor_on_write_trigger(BLEDescriptor *descriptor);
|
static Trigger<std::vector<uint8_t>, uint16_t> *create_descriptor_on_write_trigger(BLEDescriptor *descriptor);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_ON_CONNECT
|
||||||
static Trigger<uint16_t> *create_server_on_connect_trigger(BLEServer *server);
|
static Trigger<uint16_t> *create_server_on_connect_trigger(BLEServer *server);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_ON_DISCONNECT
|
||||||
static Trigger<uint16_t> *create_server_on_disconnect_trigger(BLEServer *server);
|
static Trigger<uint16_t> *create_server_on_disconnect_trigger(BLEServer *server);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_SET_VALUE_ACTION
|
||||||
enum BLECharacteristicSetValueActionEvt {
|
enum BLECharacteristicSetValueActionEvt {
|
||||||
PRE_NOTIFY,
|
PRE_NOTIFY,
|
||||||
};
|
};
|
||||||
@@ -97,13 +106,17 @@ template<typename... Ts> class BLECharacteristicSetValueAction : public Action<T
|
|||||||
BLECharacteristic *parent_;
|
BLECharacteristic *parent_;
|
||||||
EventEmitterListenerID listener_id_;
|
EventEmitterListenerID listener_id_;
|
||||||
};
|
};
|
||||||
|
#endif // USE_ESP32_BLE_SERVER_SET_VALUE_ACTION
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_NOTIFY_ACTION
|
||||||
template<typename... Ts> class BLECharacteristicNotifyAction : public Action<Ts...> {
|
template<typename... Ts> class BLECharacteristicNotifyAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
BLECharacteristicNotifyAction(BLECharacteristic *characteristic) : parent_(characteristic) {}
|
BLECharacteristicNotifyAction(BLECharacteristic *characteristic) : parent_(characteristic) {}
|
||||||
void play(Ts... x) override {
|
void play(Ts... x) override {
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_SET_VALUE_ACTION
|
||||||
// Call the pre-notify event
|
// Call the pre-notify event
|
||||||
BLECharacteristicSetValueActionManager::get_instance()->emit_pre_notify(this->parent_);
|
BLECharacteristicSetValueActionManager::get_instance()->emit_pre_notify(this->parent_);
|
||||||
|
#endif
|
||||||
// Notify the characteristic
|
// Notify the characteristic
|
||||||
this->parent_->notify();
|
this->parent_->notify();
|
||||||
}
|
}
|
||||||
@@ -111,7 +124,9 @@ template<typename... Ts> class BLECharacteristicNotifyAction : public Action<Ts.
|
|||||||
protected:
|
protected:
|
||||||
BLECharacteristic *parent_;
|
BLECharacteristic *parent_;
|
||||||
};
|
};
|
||||||
|
#endif // USE_ESP32_BLE_SERVER_NOTIFY_ACTION
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_BLE_SERVER_DESCRIPTOR_SET_VALUE_ACTION
|
||||||
template<typename... Ts> class BLEDescriptorSetValueAction : public Action<Ts...> {
|
template<typename... Ts> class BLEDescriptorSetValueAction : public Action<Ts...> {
|
||||||
public:
|
public:
|
||||||
BLEDescriptorSetValueAction(BLEDescriptor *descriptor) : parent_(descriptor) {}
|
BLEDescriptorSetValueAction(BLEDescriptor *descriptor) : parent_(descriptor) {}
|
||||||
@@ -122,6 +137,7 @@ template<typename... Ts> class BLEDescriptorSetValueAction : public Action<Ts...
|
|||||||
protected:
|
protected:
|
||||||
BLEDescriptor *parent_;
|
BLEDescriptor *parent_;
|
||||||
};
|
};
|
||||||
|
#endif // USE_ESP32_BLE_SERVER_DESCRIPTOR_SET_VALUE_ACTION
|
||||||
|
|
||||||
} // namespace esp32_ble_server_automations
|
} // namespace esp32_ble_server_automations
|
||||||
} // namespace esp32_ble_server
|
} // namespace esp32_ble_server
|
||||||
|
@@ -160,6 +160,14 @@
|
|||||||
#define USE_ESP32_BLE_SERVER
|
#define USE_ESP32_BLE_SERVER
|
||||||
#define USE_ESP32_BLE_UUID
|
#define USE_ESP32_BLE_UUID
|
||||||
#define USE_ESP32_BLE_ADVERTISING
|
#define USE_ESP32_BLE_ADVERTISING
|
||||||
|
// BLE Server automations - conditionally compiled
|
||||||
|
#define USE_ESP32_BLE_SERVER_SET_VALUE_ACTION
|
||||||
|
#define USE_ESP32_BLE_SERVER_DESCRIPTOR_SET_VALUE_ACTION
|
||||||
|
#define USE_ESP32_BLE_SERVER_NOTIFY_ACTION
|
||||||
|
#define USE_ESP32_BLE_SERVER_CHARACTERISTIC_ON_WRITE
|
||||||
|
#define USE_ESP32_BLE_SERVER_DESCRIPTOR_ON_WRITE
|
||||||
|
#define USE_ESP32_BLE_SERVER_ON_CONNECT
|
||||||
|
#define USE_ESP32_BLE_SERVER_ON_DISCONNECT
|
||||||
#define USE_ESP32_CAMERA_JPEG_ENCODER
|
#define USE_ESP32_CAMERA_JPEG_ENCODER
|
||||||
#define USE_I2C
|
#define USE_I2C
|
||||||
#define USE_IMPROV
|
#define USE_IMPROV
|
||||||
|
Reference in New Issue
Block a user