From ae2bff73806ea4f0e57043b1d58160c8adda27bf Mon Sep 17 00:00:00 2001 From: HB Date: Wed, 30 Sep 2020 00:28:20 +0200 Subject: [PATCH] i2c, uart --- .../empty_i2c_component/__init__.py | 18 +++++++++++++++ .../empty_i2c_component.cpp | 23 +++++++++++++++++++ .../empty_i2c_component/empty_i2c_component.h | 18 +++++++++++++++ .../empty_uart_component/__init__.py | 18 +++++++++++++++ .../empty_uart_component.cpp | 22 ++++++++++++++++++ .../empty_uart_component.h | 18 +++++++++++++++ test_empty.yaml | 18 ++++++++++++++- 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 custom_components/empty_i2c_component/__init__.py create mode 100644 custom_components/empty_i2c_component/empty_i2c_component.cpp create mode 100644 custom_components/empty_i2c_component/empty_i2c_component.h create mode 100644 custom_components/empty_uart_component/__init__.py create mode 100644 custom_components/empty_uart_component/empty_uart_component.cpp create mode 100644 custom_components/empty_uart_component/empty_uart_component.h diff --git a/custom_components/empty_i2c_component/__init__.py b/custom_components/empty_i2c_component/__init__.py new file mode 100644 index 0000000..81c7162 --- /dev/null +++ b/custom_components/empty_i2c_component/__init__.py @@ -0,0 +1,18 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import i2c, sensor +from esphome.const import CONF_ID + +DEPENDENCIES = ['i2c'] + +empty_i2c_component_ns = cg.esphome_ns.namespace('empty_i2c_component') +EmptyI2CComponent = empty_i2c_component_ns.class_('EmptyI2CComponent', cg.Component, i2c.I2CDevice) + +CONFIG_SCHEMA = cv.Schema({ + cv.GenerateID(): cv.declare_id(EmptyI2CComponent) +}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x29)) + +def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + yield cg.register_component(var, config) + yield i2c.register_i2c_device(var, config) \ No newline at end of file diff --git a/custom_components/empty_i2c_component/empty_i2c_component.cpp b/custom_components/empty_i2c_component/empty_i2c_component.cpp new file mode 100644 index 0000000..48298d6 --- /dev/null +++ b/custom_components/empty_i2c_component/empty_i2c_component.cpp @@ -0,0 +1,23 @@ +#include "esphome/core/log.h" +#include "empty_i2c_component.h" + +namespace esphome { +namespace empty_i2c_component { + +static const char *TAG = "empty_i2c_component.component"; + +void EmptyI2CComponent::setup() { + +} + +void EmptyI2CComponent::loop() { + +} + +void EmptyI2CComponent::dump_config(){ + ESP_LOGCONFIG(TAG, "Empty i2c component"); +} + + +} // namespace empty_i2c_component +} // namespace esphome \ No newline at end of file diff --git a/custom_components/empty_i2c_component/empty_i2c_component.h b/custom_components/empty_i2c_component/empty_i2c_component.h new file mode 100644 index 0000000..92e74ac --- /dev/null +++ b/custom_components/empty_i2c_component/empty_i2c_component.h @@ -0,0 +1,18 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/i2c/i2c.h" + +namespace esphome { +namespace empty_i2c_component { + +class EmptyI2CComponent : public i2c::I2CDevice, public Component { + public: + void setup() override; + void loop() override; + void dump_config() override; +}; + + +} // namespace empty_i2c_component +} // namespace esphome \ No newline at end of file diff --git a/custom_components/empty_uart_component/__init__.py b/custom_components/empty_uart_component/__init__.py new file mode 100644 index 0000000..32cbfc3 --- /dev/null +++ b/custom_components/empty_uart_component/__init__.py @@ -0,0 +1,18 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import uart +from esphome.const import CONF_ID + +DEPENDENCIES = ['uart'] + +empty_uart_component_ns = cg.esphome_ns.namespace('empty_uart_component') +EmptyUARTComponent = empty_uart_component_ns.class_('EmptyUARTComponent', cg.Component, uart.UARTDevice) + +CONFIG_SCHEMA = cv.Schema({ + cv.GenerateID(): cv.declare_id(EmptyUARTComponent) +}).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA) + +def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + yield cg.register_component(var, config) + yield uart.register_uart_device(var, config) \ No newline at end of file diff --git a/custom_components/empty_uart_component/empty_uart_component.cpp b/custom_components/empty_uart_component/empty_uart_component.cpp new file mode 100644 index 0000000..95031b1 --- /dev/null +++ b/custom_components/empty_uart_component/empty_uart_component.cpp @@ -0,0 +1,22 @@ +#include "esphome/core/log.h" +#include "empty_uart_component.h" + +namespace esphome { +namespace empty_uart_component { + +static const char *TAG = "empty_uart_component.component"; + +void EmptyUARTComponent::setup() { + +} + +void EmptyUARTComponent::loop() { + +} + +void EmptyUARTComponent::dump_config(){ + ESP_LOGCONFIG(TAG, "Empty i2c component"); +} + +} // namespace empty_uart_component +} // namespace esphome \ No newline at end of file diff --git a/custom_components/empty_uart_component/empty_uart_component.h b/custom_components/empty_uart_component/empty_uart_component.h new file mode 100644 index 0000000..6b72372 --- /dev/null +++ b/custom_components/empty_uart_component/empty_uart_component.h @@ -0,0 +1,18 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/uart/uart.h" + +namespace esphome { +namespace empty_uart_component { + +class EmptyUARTComponent : public uart::UARTDevice, public Component { + public: + void setup() override; + void loop() override; + void dump_config() override; +}; + + +} // namespace empty_uart_component +} // namespace esphome \ No newline at end of file diff --git a/test_empty.yaml b/test_empty.yaml index 81350b3..36f9177 100644 --- a/test_empty.yaml +++ b/test_empty.yaml @@ -39,4 +39,20 @@ cover: id: empty_cover_1 empty_component: - id: empty_component_1 \ No newline at end of file + id: empty_component_1 + +i2c: + sda: 4 + scl: 5 + +empty_i2c_component: + id: empty_i2c_component_1 + address: 0x01 + +uart: + tx_pin: D0 + rx_pin: D1 + baud_rate: 9600 + +empty_uart_component: + id: empty_uart_component_1 \ No newline at end of file