esphome 2025.9.3__py3-none-any.whl → 2025.10.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esphome/__main__.py +94 -31
- esphome/address_cache.py +142 -0
- esphome/automation.py +130 -32
- esphome/build_gen/platformio.py +1 -3
- esphome/codegen.py +1 -0
- esphome/components/animation/animation.cpp +2 -2
- esphome/components/api/__init__.py +166 -3
- esphome/components/api/api_connection.cpp +84 -41
- esphome/components/api/api_connection.h +22 -16
- esphome/components/api/api_frame_helper.cpp +33 -19
- esphome/components/api/api_frame_helper.h +19 -4
- esphome/components/api/api_frame_helper_noise.cpp +41 -53
- esphome/components/api/api_frame_helper_noise.h +1 -1
- esphome/components/api/api_frame_helper_plaintext.cpp +22 -31
- esphome/components/api/api_frame_helper_plaintext.h +1 -1
- esphome/components/api/api_pb2.cpp +189 -15
- esphome/components/api/api_pb2.h +132 -20
- esphome/components/api/api_pb2_dump.cpp +97 -9
- esphome/components/api/api_pb2_service.cpp +118 -160
- esphome/components/api/api_pb2_service.h +31 -3
- esphome/components/api/api_server.cpp +68 -10
- esphome/components/api/api_server.h +32 -4
- esphome/components/api/custom_api_device.h +8 -8
- esphome/components/api/homeassistant_service.h +123 -6
- esphome/components/api/proto.h +6 -2
- esphome/components/api/user_services.h +2 -2
- esphome/components/as7341/sensor.py +1 -1
- esphome/components/audio/__init__.py +1 -1
- esphome/components/audio/audio.cpp +1 -1
- esphome/components/audio/audio_decoder.cpp +9 -9
- esphome/components/bl0906/bl0906.cpp +2 -2
- esphome/components/bl0942/bl0942.cpp +2 -2
- esphome/components/ble_client/__init__.py +1 -1
- esphome/components/bluetooth_proxy/__init__.py +4 -30
- esphome/components/bluetooth_proxy/bluetooth_connection.cpp +11 -4
- esphome/components/bluetooth_proxy/bluetooth_connection.h +2 -2
- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +2 -2
- esphome/components/camera_encoder/__init__.py +2 -4
- esphome/components/camera_encoder/esp32_camera_jpeg_encoder.cpp +4 -2
- esphome/components/camera_encoder/esp32_camera_jpeg_encoder.h +3 -1
- esphome/components/canbus/canbus.cpp +7 -5
- esphome/components/canbus/canbus.h +7 -7
- esphome/components/captive_portal/__init__.py +18 -1
- esphome/components/captive_portal/captive_portal.cpp +40 -46
- esphome/components/captive_portal/captive_portal.h +20 -22
- esphome/components/captive_portal/dns_server_esp32_idf.cpp +205 -0
- esphome/components/captive_portal/dns_server_esp32_idf.h +27 -0
- esphome/components/ccs811/ccs811.cpp +1 -1
- esphome/components/climate/climate.cpp +10 -7
- esphome/components/cm1106/cm1106.cpp +1 -1
- esphome/components/copy/lock/copy_lock.cpp +1 -1
- esphome/components/cover/cover.cpp +1 -0
- esphome/components/daikin_arc/daikin_arc.cpp +19 -12
- esphome/components/dashboard_import/dashboard_import.cpp +1 -1
- esphome/components/dashboard_import/dashboard_import.h +1 -1
- esphome/components/deep_sleep/__init__.py +9 -2
- esphome/components/deep_sleep/deep_sleep_component.h +11 -9
- esphome/components/deep_sleep/deep_sleep_esp32.cpp +51 -27
- esphome/components/ektf2232/touchscreen/__init__.py +8 -5
- esphome/components/ektf2232/touchscreen/ektf2232.cpp +4 -4
- esphome/components/ektf2232/touchscreen/ektf2232.h +2 -2
- esphome/components/epaper_spi/__init__.py +1 -0
- esphome/components/epaper_spi/display.py +80 -0
- esphome/components/epaper_spi/epaper_spi.cpp +227 -0
- esphome/components/epaper_spi/epaper_spi.h +93 -0
- esphome/components/epaper_spi/epaper_spi_model_7p3in_spectra_e6.cpp +42 -0
- esphome/components/epaper_spi/epaper_spi_model_7p3in_spectra_e6.h +45 -0
- esphome/components/epaper_spi/epaper_spi_spectra_e6.cpp +135 -0
- esphome/components/epaper_spi/epaper_spi_spectra_e6.h +23 -0
- esphome/components/es7210/es7210.cpp +3 -3
- esphome/components/esp32/__init__.py +256 -340
- esphome/components/esp32/boards.py +81 -0
- esphome/components/esp32/preferences.cpp +23 -17
- esphome/components/esp32_ble/__init__.py +167 -44
- esphome/components/esp32_ble/ble.cpp +47 -3
- esphome/components/esp32_ble/ble.h +18 -0
- esphome/components/esp32_ble/ble_advertising.cpp +7 -3
- esphome/components/esp32_ble/ble_advertising.h +4 -0
- esphome/components/esp32_ble/ble_uuid.cpp +16 -42
- esphome/components/esp32_ble_beacon/__init__.py +3 -4
- esphome/components/esp32_ble_beacon/esp32_ble_beacon.cpp +0 -4
- esphome/components/esp32_ble_client/ble_client_base.cpp +14 -12
- esphome/components/esp32_ble_server/__init__.py +28 -14
- esphome/components/esp32_ble_server/ble_characteristic.cpp +67 -57
- esphome/components/esp32_ble_server/ble_characteristic.h +27 -16
- esphome/components/esp32_ble_server/ble_descriptor.cpp +4 -3
- esphome/components/esp32_ble_server/ble_descriptor.h +13 -9
- esphome/components/esp32_ble_server/ble_server.cpp +59 -24
- esphome/components/esp32_ble_server/ble_server.h +38 -20
- esphome/components/esp32_ble_server/ble_server_automations.cpp +49 -33
- esphome/components/esp32_ble_server/ble_server_automations.h +39 -24
- esphome/components/esp32_ble_tracker/__init__.py +25 -80
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +2 -8
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +0 -3
- esphome/components/esp32_camera/__init__.py +1 -3
- esphome/components/esp32_can/esp32_can.cpp +22 -4
- esphome/components/esp32_can/esp32_can.h +3 -0
- esphome/components/esp32_hosted/__init__.py +2 -1
- esphome/components/esp32_improv/esp32_improv_component.cpp +135 -65
- esphome/components/esp32_improv/esp32_improv_component.h +7 -1
- esphome/components/esp32_rmt_led_strip/led_strip.cpp +1 -1
- esphome/components/esp8266/__init__.py +3 -3
- esphome/components/esphome/ota/__init__.py +21 -2
- esphome/components/esphome/ota/ota_esphome.cpp +456 -146
- esphome/components/esphome/ota/ota_esphome.h +49 -2
- esphome/components/ethernet/__init__.py +39 -22
- esphome/components/ethernet/ethernet_component.cpp +28 -5
- esphome/components/ethernet/ethernet_component.h +5 -1
- esphome/components/external_components/__init__.py +8 -6
- esphome/components/fingerprint_grow/fingerprint_grow.cpp +1 -1
- esphome/components/fingerprint_grow/fingerprint_grow.h +2 -1
- esphome/components/font/__init__.py +5 -5
- esphome/components/graph/graph.cpp +1 -1
- esphome/components/graphical_display_menu/graphical_display_menu.cpp +3 -2
- esphome/components/haier/hon_climate.cpp +2 -2
- esphome/components/haier/hon_climate.h +1 -1
- esphome/components/hdc1080/hdc1080.cpp +42 -34
- esphome/components/hdc1080/hdc1080.h +1 -3
- esphome/components/homeassistant/number/homeassistant_number.cpp +2 -2
- esphome/components/homeassistant/switch/homeassistant_switch.cpp +2 -2
- esphome/components/http_request/__init__.py +3 -3
- esphome/components/htu21d/htu21d.cpp +13 -18
- esphome/components/htu21d/htu21d.h +1 -1
- esphome/components/i2s_audio/__init__.py +1 -2
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +1 -1
- esphome/components/ili9xxx/ili9xxx_display.cpp +2 -2
- esphome/components/improv_serial/improv_serial_component.cpp +12 -15
- esphome/components/improv_serial/improv_serial_component.h +6 -8
- esphome/components/json/json_util.cpp +42 -44
- esphome/components/json/json_util.h +57 -0
- esphome/components/kamstrup_kmp/kamstrup_kmp.cpp +2 -2
- esphome/components/key_collector/key_collector.h +4 -4
- esphome/components/libretiny/__init__.py +6 -6
- esphome/components/libretiny/preferences.cpp +23 -16
- esphome/components/light/light_call.cpp +98 -120
- esphome/components/light/light_call.h +17 -7
- esphome/components/lm75b/__init__.py +0 -0
- esphome/components/lm75b/lm75b.cpp +39 -0
- esphome/components/lm75b/lm75b.h +19 -0
- esphome/components/lm75b/sensor.py +34 -0
- esphome/components/lock/lock.h +12 -6
- esphome/components/logger/__init__.py +15 -27
- esphome/components/logger/logger.cpp +10 -20
- esphome/components/logger/logger.h +105 -62
- esphome/components/logger/logger_esp32.cpp +0 -48
- esphome/components/logger/logger_zephyr.cpp +2 -3
- esphome/components/logger/select/logger_level_select.cpp +6 -7
- esphome/components/logger/select/logger_level_select.h +7 -0
- esphome/components/ltr501/ltr501.cpp +7 -6
- esphome/components/ltr_als_ps/ltr_als_ps.cpp +7 -6
- esphome/components/matrix_keypad/matrix_keypad.h +4 -4
- esphome/components/max7219digit/max7219digit.cpp +1 -1
- esphome/components/mcp23xxx_base/mcp23xxx_base.h +3 -3
- esphome/components/mcp2515/mcp2515.cpp +31 -3
- esphome/components/mcp2515/mcp2515_defs.h +3 -1
- esphome/components/md5/md5.cpp +0 -26
- esphome/components/md5/md5.h +10 -20
- esphome/components/mdns/__init__.py +93 -19
- esphome/components/mdns/mdns_component.cpp +57 -94
- esphome/components/mdns/mdns_component.h +35 -11
- esphome/components/mdns/mdns_esp32.cpp +7 -13
- esphome/components/mdns/mdns_esp8266.cpp +7 -7
- esphome/components/mdns/mdns_libretiny.cpp +3 -4
- esphome/components/mdns/mdns_rp2040.cpp +3 -4
- esphome/components/mipi/__init__.py +1 -5
- esphome/components/mipi_spi/display.py +24 -8
- esphome/components/mipi_spi/mipi_spi.h +3 -3
- esphome/components/mixer/speaker/mixer_speaker.cpp +3 -3
- esphome/components/mmc5603/mmc5603.cpp +3 -3
- esphome/components/modbus/modbus.cpp +27 -13
- esphome/components/modbus/modbus.h +5 -3
- esphome/components/modbus/modbus_definitions.h +86 -0
- esphome/components/modbus_controller/__init__.py +29 -1
- esphome/components/modbus_controller/const.py +4 -0
- esphome/components/modbus_controller/modbus_controller.cpp +38 -13
- esphome/components/modbus_controller/modbus_controller.h +18 -29
- esphome/components/mpr121/mpr121.cpp +41 -42
- esphome/components/mpr121/mpr121.h +0 -1
- esphome/components/nau7802/nau7802.cpp +2 -2
- esphome/components/network/__init__.py +7 -3
- esphome/components/nextion/display.py +4 -4
- esphome/components/nextion/nextion.cpp +8 -8
- esphome/components/number/__init__.py +2 -0
- esphome/components/number/number_call.cpp +23 -12
- esphome/components/number/number_call.h +5 -0
- esphome/components/online_image/bmp_image.cpp +2 -1
- esphome/components/online_image/jpeg_image.cpp +4 -2
- esphome/components/opentherm/opentherm.cpp +5 -5
- esphome/components/opentherm/opentherm.h +3 -3
- esphome/components/openthread/openthread.cpp +11 -10
- esphome/components/openthread/openthread.h +0 -1
- esphome/components/ota/ota_backend.h +1 -0
- esphome/components/packages/__init__.py +10 -8
- esphome/components/packet_transport/packet_transport.cpp +2 -0
- esphome/components/pid/pid_controller.cpp +1 -1
- esphome/components/prometheus/prometheus_handler.cpp +239 -239
- esphome/components/psram/__init__.py +30 -28
- esphome/components/qmc5883l/qmc5883l.cpp +15 -0
- esphome/components/qmc5883l/qmc5883l.h +3 -0
- esphome/components/qmc5883l/sensor.py +31 -12
- esphome/components/remote_base/gobox_protocol.cpp +3 -3
- esphome/components/remote_receiver/__init__.py +14 -2
- esphome/components/remote_receiver/{remote_receiver_esp8266.cpp → remote_receiver.cpp} +2 -2
- esphome/components/remote_receiver/remote_receiver.h +4 -0
- esphome/components/remote_receiver/remote_receiver_esp32.cpp +18 -1
- esphome/components/remote_transmitter/__init__.py +2 -2
- esphome/components/remote_transmitter/remote_transmitter.cpp +103 -0
- esphome/components/rp2040/__init__.py +11 -11
- esphome/components/rtttl/rtttl.cpp +2 -2
- esphome/components/scd30/sensor.py +1 -1
- esphome/components/script/__init__.py +1 -1
- esphome/components/script/script.h +7 -7
- esphome/components/select/select.cpp +5 -4
- esphome/components/select/select_call.cpp +1 -1
- esphome/components/sensirion_common/i2c_sensirion.cpp +2 -1
- esphome/components/sensor/__init__.py +2 -0
- esphome/components/sha256/__init__.py +22 -0
- esphome/components/sha256/sha256.cpp +116 -0
- esphome/components/sha256/sha256.h +60 -0
- esphome/components/socket/lwip_raw_tcp_impl.cpp +34 -6
- esphome/components/sonoff_d1/sonoff_d1.cpp +1 -1
- esphome/components/spi/__init__.py +0 -3
- esphome/components/split_buffer/__init__.py +5 -0
- esphome/components/split_buffer/split_buffer.cpp +133 -0
- esphome/components/split_buffer/split_buffer.h +40 -0
- esphome/components/sps30/sps30.cpp +14 -10
- esphome/components/sps30/sps30.h +2 -0
- esphome/components/st7567_i2c/st7567_i2c.cpp +3 -1
- esphome/components/st7789v/st7789v.cpp +3 -2
- esphome/components/statsd/statsd.cpp +1 -1
- esphome/components/substitutions/__init__.py +3 -1
- esphome/components/substitutions/jinja.py +13 -3
- esphome/components/sx126x/__init__.py +16 -0
- esphome/components/sx126x/sx126x.cpp +15 -1
- esphome/components/sx126x/sx126x.h +9 -1
- esphome/components/sx126x/sx126x_reg.h +2 -0
- esphome/components/text_sensor/text_sensor.cpp +16 -0
- esphome/components/text_sensor/text_sensor.h +3 -10
- esphome/components/tormatic/tormatic_cover.cpp +1 -1
- esphome/components/tuya/select/tuya_select.cpp +1 -1
- esphome/components/tuya/tuya.cpp +29 -4
- esphome/components/uart/__init__.py +37 -27
- esphome/components/uart/uart.h +6 -0
- esphome/components/uart/uart_component.cpp +8 -0
- esphome/components/uart/uart_component.h +28 -0
- esphome/components/uart/uart_component_esp_idf.cpp +64 -10
- esphome/components/uart/uart_component_esp_idf.h +5 -2
- esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp +1 -1
- esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +1 -1
- esphome/components/uponor_smatrix/uponor_smatrix.cpp +3 -3
- esphome/components/usb_host/__init__.py +12 -2
- esphome/components/usb_host/usb_host.h +89 -14
- esphome/components/usb_host/usb_host_client.cpp +157 -22
- esphome/components/usb_host/usb_host_component.cpp +1 -1
- esphome/components/usb_uart/__init__.py +0 -1
- esphome/components/usb_uart/ch34x.cpp +4 -4
- esphome/components/usb_uart/cp210x.cpp +3 -3
- esphome/components/usb_uart/usb_uart.cpp +88 -32
- esphome/components/usb_uart/usb_uart.h +30 -6
- esphome/components/valve/valve.cpp +1 -0
- esphome/components/veml7700/veml7700.cpp +7 -6
- esphome/components/version/version_text_sensor.cpp +2 -1
- esphome/components/voice_assistant/voice_assistant.cpp +3 -2
- esphome/components/waveshare_epaper/waveshare_epaper.cpp +4 -4
- esphome/components/web_server/list_entities.cpp +3 -4
- esphome/components/web_server/list_entities.h +8 -10
- esphome/components/web_server/ota/__init__.py +1 -1
- esphome/components/web_server/ota/ota_web_server.cpp +9 -3
- esphome/components/web_server/web_server.cpp +509 -404
- esphome/components/web_server/web_server.h +5 -6
- esphome/components/web_server/web_server_v1.cpp +21 -19
- esphome/components/web_server_base/__init__.py +5 -2
- esphome/components/web_server_base/web_server_base.h +27 -7
- esphome/components/web_server_idf/__init__.py +1 -1
- esphome/components/web_server_idf/multipart.cpp +2 -2
- esphome/components/web_server_idf/multipart.h +2 -2
- esphome/components/web_server_idf/utils.cpp +2 -2
- esphome/components/web_server_idf/utils.h +2 -2
- esphome/components/web_server_idf/web_server_idf.cpp +118 -26
- esphome/components/web_server_idf/web_server_idf.h +12 -10
- esphome/components/wifi/__init__.py +13 -11
- esphome/components/wifi/wifi_component.cpp +74 -56
- esphome/components/wifi/wifi_component.h +4 -4
- esphome/components/wifi/wifi_component_esp8266.cpp +1 -1
- esphome/components/wifi/wifi_component_esp_idf.cpp +24 -4
- esphome/components/wireguard/__init__.py +1 -1
- esphome/components/wts01/__init__.py +0 -0
- esphome/components/wts01/sensor.py +41 -0
- esphome/components/wts01/wts01.cpp +91 -0
- esphome/components/wts01/wts01.h +27 -0
- esphome/components/zephyr/__init__.py +5 -5
- esphome/components/zwave_proxy/__init__.py +43 -0
- esphome/components/zwave_proxy/zwave_proxy.cpp +346 -0
- esphome/components/zwave_proxy/zwave_proxy.h +93 -0
- esphome/config.py +79 -24
- esphome/config_validation.py +13 -15
- esphome/const.py +9 -2
- esphome/core/__init__.py +33 -22
- esphome/core/component.cpp +28 -18
- esphome/core/component_iterator.h +2 -1
- esphome/core/config.py +15 -15
- esphome/core/defines.h +21 -0
- esphome/core/entity_helpers.py +9 -6
- esphome/core/hash_base.h +56 -0
- esphome/core/helpers.cpp +19 -3
- esphome/core/helpers.h +26 -0
- esphome/core/scheduler.cpp +5 -21
- esphome/core/scheduler.h +19 -8
- esphome/core/string_ref.h +1 -1
- esphome/core/time.cpp +5 -5
- esphome/cpp_generator.py +4 -29
- esphome/dashboard/const.py +21 -4
- esphome/dashboard/core.py +10 -8
- esphome/dashboard/dns.py +15 -0
- esphome/dashboard/entries.py +15 -21
- esphome/dashboard/models.py +76 -0
- esphome/dashboard/settings.py +7 -7
- esphome/dashboard/status/mdns.py +46 -2
- esphome/dashboard/web_server.py +367 -93
- esphome/espota2.py +112 -32
- esphome/external_files.py +6 -7
- esphome/git.py +8 -0
- esphome/helpers.py +124 -77
- esphome/loader.py +8 -9
- esphome/pins.py +2 -2
- esphome/platformio_api.py +56 -18
- esphome/storage_json.py +26 -21
- esphome/types.py +30 -2
- esphome/util.py +32 -16
- esphome/vscode.py +8 -8
- esphome/wizard.py +10 -10
- esphome/writer.py +50 -15
- esphome/yaml_util.py +37 -31
- esphome/zeroconf.py +12 -3
- {esphome-2025.9.3.dist-info → esphome-2025.10.0b2.dist-info}/METADATA +12 -12
- {esphome-2025.9.3.dist-info → esphome-2025.10.0b2.dist-info}/RECORD +340 -320
- esphome/components/event_emitter/__init__.py +0 -5
- esphome/components/event_emitter/event_emitter.cpp +0 -14
- esphome/components/event_emitter/event_emitter.h +0 -63
- esphome/components/remote_receiver/remote_receiver_libretiny.cpp +0 -125
- esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +0 -107
- esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +0 -110
- esphome/components/uart/uart_component_esp32_arduino.cpp +0 -214
- esphome/components/uart/uart_component_esp32_arduino.h +0 -60
- esphome/components/wifi/wifi_component_esp32_arduino.cpp +0 -860
- esphome/core/string_ref.cpp +0 -12
- esphome/dashboard/util/file.py +0 -63
- {esphome-2025.9.3.dist-info → esphome-2025.10.0b2.dist-info}/WHEEL +0 -0
- {esphome-2025.9.3.dist-info → esphome-2025.10.0b2.dist-info}/entry_points.txt +0 -0
- {esphome-2025.9.3.dist-info → esphome-2025.10.0b2.dist-info}/licenses/LICENSE +0 -0
- {esphome-2025.9.3.dist-info → esphome-2025.10.0b2.dist-info}/top_level.txt +0 -0
@@ -1,14 +0,0 @@
|
|
1
|
-
#include "event_emitter.h"
|
2
|
-
|
3
|
-
namespace esphome {
|
4
|
-
namespace event_emitter {
|
5
|
-
|
6
|
-
static const char *const TAG = "event_emitter";
|
7
|
-
|
8
|
-
void raise_event_emitter_full_error() {
|
9
|
-
ESP_LOGE(TAG, "EventEmitter has reached the maximum number of listeners for event");
|
10
|
-
ESP_LOGW(TAG, "Removing listener to make space for new listener");
|
11
|
-
}
|
12
|
-
|
13
|
-
} // namespace event_emitter
|
14
|
-
} // namespace esphome
|
@@ -1,63 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
#include <unordered_map>
|
3
|
-
#include <vector>
|
4
|
-
#include <functional>
|
5
|
-
#include <limits>
|
6
|
-
|
7
|
-
#include "esphome/core/log.h"
|
8
|
-
|
9
|
-
namespace esphome {
|
10
|
-
namespace event_emitter {
|
11
|
-
|
12
|
-
using EventEmitterListenerID = uint32_t;
|
13
|
-
void raise_event_emitter_full_error();
|
14
|
-
|
15
|
-
// EventEmitter class that can emit events with a specific name (it is highly recommended to use an enum class for this)
|
16
|
-
// and a list of arguments. Supports multiple listeners for each event.
|
17
|
-
template<typename EvtType, typename... Args> class EventEmitter {
|
18
|
-
public:
|
19
|
-
EventEmitterListenerID on(EvtType event, std::function<void(Args...)> listener) {
|
20
|
-
EventEmitterListenerID listener_id = get_next_id_(event);
|
21
|
-
listeners_[event][listener_id] = listener;
|
22
|
-
return listener_id;
|
23
|
-
}
|
24
|
-
|
25
|
-
void off(EvtType event, EventEmitterListenerID id) {
|
26
|
-
if (listeners_.count(event) == 0)
|
27
|
-
return;
|
28
|
-
listeners_[event].erase(id);
|
29
|
-
}
|
30
|
-
|
31
|
-
protected:
|
32
|
-
void emit_(EvtType event, Args... args) {
|
33
|
-
if (listeners_.count(event) == 0)
|
34
|
-
return;
|
35
|
-
for (const auto &listener : listeners_[event]) {
|
36
|
-
listener.second(args...);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
EventEmitterListenerID get_next_id_(EvtType event) {
|
41
|
-
// Check if the map is full
|
42
|
-
if (listeners_[event].size() == std::numeric_limits<EventEmitterListenerID>::max()) {
|
43
|
-
// Raise an error if the map is full
|
44
|
-
raise_event_emitter_full_error();
|
45
|
-
off(event, 0);
|
46
|
-
return 0;
|
47
|
-
}
|
48
|
-
// Get the next ID for the given event.
|
49
|
-
EventEmitterListenerID next_id = (current_id_ + 1) % std::numeric_limits<EventEmitterListenerID>::max();
|
50
|
-
while (listeners_[event].count(next_id) > 0) {
|
51
|
-
next_id = (next_id + 1) % std::numeric_limits<EventEmitterListenerID>::max();
|
52
|
-
}
|
53
|
-
current_id_ = next_id;
|
54
|
-
return current_id_;
|
55
|
-
}
|
56
|
-
|
57
|
-
private:
|
58
|
-
std::unordered_map<EvtType, std::unordered_map<EventEmitterListenerID, std::function<void(Args...)>>> listeners_;
|
59
|
-
EventEmitterListenerID current_id_ = 0;
|
60
|
-
};
|
61
|
-
|
62
|
-
} // namespace event_emitter
|
63
|
-
} // namespace esphome
|
@@ -1,125 +0,0 @@
|
|
1
|
-
#include "remote_receiver.h"
|
2
|
-
#include "esphome/core/hal.h"
|
3
|
-
#include "esphome/core/helpers.h"
|
4
|
-
#include "esphome/core/log.h"
|
5
|
-
|
6
|
-
#ifdef USE_LIBRETINY
|
7
|
-
|
8
|
-
namespace esphome {
|
9
|
-
namespace remote_receiver {
|
10
|
-
|
11
|
-
static const char *const TAG = "remote_receiver.libretiny";
|
12
|
-
|
13
|
-
void IRAM_ATTR HOT RemoteReceiverComponentStore::gpio_intr(RemoteReceiverComponentStore *arg) {
|
14
|
-
const uint32_t now = micros();
|
15
|
-
// If the lhs is 1 (rising edge) we should write to an uneven index and vice versa
|
16
|
-
const uint32_t next = (arg->buffer_write_at + 1) % arg->buffer_size;
|
17
|
-
const bool level = arg->pin.digital_read();
|
18
|
-
if (level != next % 2)
|
19
|
-
return;
|
20
|
-
|
21
|
-
// If next is buffer_read, we have hit an overflow
|
22
|
-
if (next == arg->buffer_read_at)
|
23
|
-
return;
|
24
|
-
|
25
|
-
const uint32_t last_change = arg->buffer[arg->buffer_write_at];
|
26
|
-
const uint32_t time_since_change = now - last_change;
|
27
|
-
if (time_since_change <= arg->filter_us)
|
28
|
-
return;
|
29
|
-
|
30
|
-
arg->buffer[arg->buffer_write_at = next] = now;
|
31
|
-
}
|
32
|
-
|
33
|
-
void RemoteReceiverComponent::setup() {
|
34
|
-
this->pin_->setup();
|
35
|
-
auto &s = this->store_;
|
36
|
-
s.filter_us = this->filter_us_;
|
37
|
-
s.pin = this->pin_->to_isr();
|
38
|
-
s.buffer_size = this->buffer_size_;
|
39
|
-
|
40
|
-
this->high_freq_.start();
|
41
|
-
if (s.buffer_size % 2 != 0) {
|
42
|
-
// Make sure divisible by two. This way, we know that every 0bxxx0 index is a space and every 0bxxx1 index is a mark
|
43
|
-
s.buffer_size++;
|
44
|
-
}
|
45
|
-
|
46
|
-
s.buffer = new uint32_t[s.buffer_size];
|
47
|
-
void *buf = (void *) s.buffer;
|
48
|
-
memset(buf, 0, s.buffer_size * sizeof(uint32_t));
|
49
|
-
|
50
|
-
// First index is a space.
|
51
|
-
if (this->pin_->digital_read()) {
|
52
|
-
s.buffer_write_at = s.buffer_read_at = 1;
|
53
|
-
} else {
|
54
|
-
s.buffer_write_at = s.buffer_read_at = 0;
|
55
|
-
}
|
56
|
-
this->pin_->attach_interrupt(RemoteReceiverComponentStore::gpio_intr, &this->store_, gpio::INTERRUPT_ANY_EDGE);
|
57
|
-
}
|
58
|
-
void RemoteReceiverComponent::dump_config() {
|
59
|
-
ESP_LOGCONFIG(TAG, "Remote Receiver:");
|
60
|
-
LOG_PIN(" Pin: ", this->pin_);
|
61
|
-
if (this->pin_->digital_read()) {
|
62
|
-
ESP_LOGW(TAG, "Remote Receiver Signal starts with a HIGH value. Usually this means you have to "
|
63
|
-
"invert the signal using 'inverted: True' in the pin schema!");
|
64
|
-
}
|
65
|
-
ESP_LOGCONFIG(TAG,
|
66
|
-
" Buffer Size: %u\n"
|
67
|
-
" Tolerance: %u%s\n"
|
68
|
-
" Filter out pulses shorter than: %u us\n"
|
69
|
-
" Signal is done after %u us of no changes",
|
70
|
-
this->buffer_size_, this->tolerance_,
|
71
|
-
(this->tolerance_mode_ == remote_base::TOLERANCE_MODE_TIME) ? " us" : "%", this->filter_us_,
|
72
|
-
this->idle_us_);
|
73
|
-
}
|
74
|
-
|
75
|
-
void RemoteReceiverComponent::loop() {
|
76
|
-
auto &s = this->store_;
|
77
|
-
|
78
|
-
// copy write at to local variables, as it's volatile
|
79
|
-
const uint32_t write_at = s.buffer_write_at;
|
80
|
-
const uint32_t dist = (s.buffer_size + write_at - s.buffer_read_at) % s.buffer_size;
|
81
|
-
// signals must at least one rising and one leading edge
|
82
|
-
if (dist <= 1)
|
83
|
-
return;
|
84
|
-
const uint32_t now = micros();
|
85
|
-
if (now - s.buffer[write_at] < this->idle_us_) {
|
86
|
-
// The last change was fewer than the configured idle time ago.
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
|
90
|
-
ESP_LOGVV(TAG, "read_at=%u write_at=%u dist=%u now=%u end=%u", s.buffer_read_at, write_at, dist, now,
|
91
|
-
s.buffer[write_at]);
|
92
|
-
|
93
|
-
// Skip first value, it's from the previous idle level
|
94
|
-
s.buffer_read_at = (s.buffer_read_at + 1) % s.buffer_size;
|
95
|
-
uint32_t prev = s.buffer_read_at;
|
96
|
-
s.buffer_read_at = (s.buffer_read_at + 1) % s.buffer_size;
|
97
|
-
const uint32_t reserve_size = 1 + (s.buffer_size + write_at - s.buffer_read_at) % s.buffer_size;
|
98
|
-
this->temp_.clear();
|
99
|
-
this->temp_.reserve(reserve_size);
|
100
|
-
int32_t multiplier = s.buffer_read_at % 2 == 0 ? 1 : -1;
|
101
|
-
|
102
|
-
for (uint32_t i = 0; prev != write_at; i++) {
|
103
|
-
int32_t delta = s.buffer[s.buffer_read_at] - s.buffer[prev];
|
104
|
-
if (uint32_t(delta) >= this->idle_us_) {
|
105
|
-
// already found a space longer than idle. There must have been two pulses
|
106
|
-
break;
|
107
|
-
}
|
108
|
-
|
109
|
-
ESP_LOGVV(TAG, " i=%u buffer[%u]=%u - buffer[%u]=%u -> %d", i, s.buffer_read_at, s.buffer[s.buffer_read_at], prev,
|
110
|
-
s.buffer[prev], multiplier * delta);
|
111
|
-
this->temp_.push_back(multiplier * delta);
|
112
|
-
prev = s.buffer_read_at;
|
113
|
-
s.buffer_read_at = (s.buffer_read_at + 1) % s.buffer_size;
|
114
|
-
multiplier *= -1;
|
115
|
-
}
|
116
|
-
s.buffer_read_at = (s.buffer_size + s.buffer_read_at - 1) % s.buffer_size;
|
117
|
-
this->temp_.push_back(this->idle_us_ * multiplier);
|
118
|
-
|
119
|
-
this->call_listeners_dumpers_();
|
120
|
-
}
|
121
|
-
|
122
|
-
} // namespace remote_receiver
|
123
|
-
} // namespace esphome
|
124
|
-
|
125
|
-
#endif
|
@@ -1,107 +0,0 @@
|
|
1
|
-
#include "remote_transmitter.h"
|
2
|
-
#include "esphome/core/log.h"
|
3
|
-
#include "esphome/core/application.h"
|
4
|
-
|
5
|
-
#ifdef USE_ESP8266
|
6
|
-
|
7
|
-
namespace esphome {
|
8
|
-
namespace remote_transmitter {
|
9
|
-
|
10
|
-
static const char *const TAG = "remote_transmitter";
|
11
|
-
|
12
|
-
void RemoteTransmitterComponent::setup() {
|
13
|
-
this->pin_->setup();
|
14
|
-
this->pin_->digital_write(false);
|
15
|
-
}
|
16
|
-
|
17
|
-
void RemoteTransmitterComponent::dump_config() {
|
18
|
-
ESP_LOGCONFIG(TAG,
|
19
|
-
"Remote Transmitter:\n"
|
20
|
-
" Carrier Duty: %u%%",
|
21
|
-
this->carrier_duty_percent_);
|
22
|
-
LOG_PIN(" Pin: ", this->pin_);
|
23
|
-
}
|
24
|
-
|
25
|
-
void RemoteTransmitterComponent::calculate_on_off_time_(uint32_t carrier_frequency, uint32_t *on_time_period,
|
26
|
-
uint32_t *off_time_period) {
|
27
|
-
if (carrier_frequency == 0) {
|
28
|
-
*on_time_period = 0;
|
29
|
-
*off_time_period = 0;
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
uint32_t period = (1000000UL + carrier_frequency / 2) / carrier_frequency; // round(1000000/freq)
|
33
|
-
period = std::max(uint32_t(1), period);
|
34
|
-
*on_time_period = (period * this->carrier_duty_percent_) / 100;
|
35
|
-
*off_time_period = period - *on_time_period;
|
36
|
-
}
|
37
|
-
|
38
|
-
void RemoteTransmitterComponent::await_target_time_() {
|
39
|
-
const uint32_t current_time = micros();
|
40
|
-
if (this->target_time_ == 0) {
|
41
|
-
this->target_time_ = current_time;
|
42
|
-
} else if ((int32_t) (this->target_time_ - current_time) > 0) {
|
43
|
-
delayMicroseconds(this->target_time_ - current_time);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
void RemoteTransmitterComponent::mark_(uint32_t on_time, uint32_t off_time, uint32_t usec) {
|
48
|
-
this->await_target_time_();
|
49
|
-
this->pin_->digital_write(true);
|
50
|
-
|
51
|
-
const uint32_t target = this->target_time_ + usec;
|
52
|
-
if (this->carrier_duty_percent_ < 100 && (on_time > 0 || off_time > 0)) {
|
53
|
-
while (true) { // Modulate with carrier frequency
|
54
|
-
this->target_time_ += on_time;
|
55
|
-
if ((int32_t) (this->target_time_ - target) >= 0)
|
56
|
-
break;
|
57
|
-
this->await_target_time_();
|
58
|
-
this->pin_->digital_write(false);
|
59
|
-
|
60
|
-
this->target_time_ += off_time;
|
61
|
-
if ((int32_t) (this->target_time_ - target) >= 0)
|
62
|
-
break;
|
63
|
-
this->await_target_time_();
|
64
|
-
this->pin_->digital_write(true);
|
65
|
-
}
|
66
|
-
}
|
67
|
-
this->target_time_ = target;
|
68
|
-
}
|
69
|
-
|
70
|
-
void RemoteTransmitterComponent::space_(uint32_t usec) {
|
71
|
-
this->await_target_time_();
|
72
|
-
this->pin_->digital_write(false);
|
73
|
-
this->target_time_ += usec;
|
74
|
-
}
|
75
|
-
|
76
|
-
void RemoteTransmitterComponent::digital_write(bool value) { this->pin_->digital_write(value); }
|
77
|
-
|
78
|
-
void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t send_wait) {
|
79
|
-
ESP_LOGD(TAG, "Sending remote code");
|
80
|
-
uint32_t on_time, off_time;
|
81
|
-
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
82
|
-
this->target_time_ = 0;
|
83
|
-
this->transmit_trigger_->trigger();
|
84
|
-
for (uint32_t i = 0; i < send_times; i++) {
|
85
|
-
for (int32_t item : this->temp_.get_data()) {
|
86
|
-
if (item > 0) {
|
87
|
-
const auto length = uint32_t(item);
|
88
|
-
this->mark_(on_time, off_time, length);
|
89
|
-
} else {
|
90
|
-
const auto length = uint32_t(-item);
|
91
|
-
this->space_(length);
|
92
|
-
}
|
93
|
-
App.feed_wdt();
|
94
|
-
}
|
95
|
-
this->await_target_time_(); // wait for duration of last pulse
|
96
|
-
this->pin_->digital_write(false);
|
97
|
-
|
98
|
-
if (i + 1 < send_times)
|
99
|
-
this->target_time_ += send_wait;
|
100
|
-
}
|
101
|
-
this->complete_trigger_->trigger();
|
102
|
-
}
|
103
|
-
|
104
|
-
} // namespace remote_transmitter
|
105
|
-
} // namespace esphome
|
106
|
-
|
107
|
-
#endif
|
@@ -1,110 +0,0 @@
|
|
1
|
-
#include "remote_transmitter.h"
|
2
|
-
#include "esphome/core/log.h"
|
3
|
-
#include "esphome/core/application.h"
|
4
|
-
|
5
|
-
#ifdef USE_LIBRETINY
|
6
|
-
|
7
|
-
namespace esphome {
|
8
|
-
namespace remote_transmitter {
|
9
|
-
|
10
|
-
static const char *const TAG = "remote_transmitter";
|
11
|
-
|
12
|
-
void RemoteTransmitterComponent::setup() {
|
13
|
-
this->pin_->setup();
|
14
|
-
this->pin_->digital_write(false);
|
15
|
-
}
|
16
|
-
|
17
|
-
void RemoteTransmitterComponent::dump_config() {
|
18
|
-
ESP_LOGCONFIG(TAG,
|
19
|
-
"Remote Transmitter:\n"
|
20
|
-
" Carrier Duty: %u%%",
|
21
|
-
this->carrier_duty_percent_);
|
22
|
-
LOG_PIN(" Pin: ", this->pin_);
|
23
|
-
}
|
24
|
-
|
25
|
-
void RemoteTransmitterComponent::calculate_on_off_time_(uint32_t carrier_frequency, uint32_t *on_time_period,
|
26
|
-
uint32_t *off_time_period) {
|
27
|
-
if (carrier_frequency == 0) {
|
28
|
-
*on_time_period = 0;
|
29
|
-
*off_time_period = 0;
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
uint32_t period = (1000000UL + carrier_frequency / 2) / carrier_frequency; // round(1000000/freq)
|
33
|
-
period = std::max(uint32_t(1), period);
|
34
|
-
*on_time_period = (period * this->carrier_duty_percent_) / 100;
|
35
|
-
*off_time_period = period - *on_time_period;
|
36
|
-
}
|
37
|
-
|
38
|
-
void RemoteTransmitterComponent::await_target_time_() {
|
39
|
-
const uint32_t current_time = micros();
|
40
|
-
if (this->target_time_ == 0) {
|
41
|
-
this->target_time_ = current_time;
|
42
|
-
} else {
|
43
|
-
while ((int32_t) (this->target_time_ - micros()) > 0) {
|
44
|
-
// busy loop that ensures micros is constantly called
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
void RemoteTransmitterComponent::mark_(uint32_t on_time, uint32_t off_time, uint32_t usec) {
|
50
|
-
this->await_target_time_();
|
51
|
-
this->pin_->digital_write(true);
|
52
|
-
|
53
|
-
const uint32_t target = this->target_time_ + usec;
|
54
|
-
if (this->carrier_duty_percent_ < 100 && (on_time > 0 || off_time > 0)) {
|
55
|
-
while (true) { // Modulate with carrier frequency
|
56
|
-
this->target_time_ += on_time;
|
57
|
-
if ((int32_t) (this->target_time_ - target) >= 0)
|
58
|
-
break;
|
59
|
-
this->await_target_time_();
|
60
|
-
this->pin_->digital_write(false);
|
61
|
-
|
62
|
-
this->target_time_ += off_time;
|
63
|
-
if ((int32_t) (this->target_time_ - target) >= 0)
|
64
|
-
break;
|
65
|
-
this->await_target_time_();
|
66
|
-
this->pin_->digital_write(true);
|
67
|
-
}
|
68
|
-
}
|
69
|
-
this->target_time_ = target;
|
70
|
-
}
|
71
|
-
|
72
|
-
void RemoteTransmitterComponent::space_(uint32_t usec) {
|
73
|
-
this->await_target_time_();
|
74
|
-
this->pin_->digital_write(false);
|
75
|
-
this->target_time_ += usec;
|
76
|
-
}
|
77
|
-
|
78
|
-
void RemoteTransmitterComponent::digital_write(bool value) { this->pin_->digital_write(value); }
|
79
|
-
|
80
|
-
void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t send_wait) {
|
81
|
-
ESP_LOGD(TAG, "Sending remote code");
|
82
|
-
uint32_t on_time, off_time;
|
83
|
-
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
84
|
-
this->target_time_ = 0;
|
85
|
-
this->transmit_trigger_->trigger();
|
86
|
-
for (uint32_t i = 0; i < send_times; i++) {
|
87
|
-
InterruptLock lock;
|
88
|
-
for (int32_t item : this->temp_.get_data()) {
|
89
|
-
if (item > 0) {
|
90
|
-
const auto length = uint32_t(item);
|
91
|
-
this->mark_(on_time, off_time, length);
|
92
|
-
} else {
|
93
|
-
const auto length = uint32_t(-item);
|
94
|
-
this->space_(length);
|
95
|
-
}
|
96
|
-
App.feed_wdt();
|
97
|
-
}
|
98
|
-
this->await_target_time_(); // wait for duration of last pulse
|
99
|
-
this->pin_->digital_write(false);
|
100
|
-
|
101
|
-
if (i + 1 < send_times)
|
102
|
-
this->target_time_ += send_wait;
|
103
|
-
}
|
104
|
-
this->complete_trigger_->trigger();
|
105
|
-
}
|
106
|
-
|
107
|
-
} // namespace remote_transmitter
|
108
|
-
} // namespace esphome
|
109
|
-
|
110
|
-
#endif
|
@@ -1,214 +0,0 @@
|
|
1
|
-
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
2
|
-
#include "uart_component_esp32_arduino.h"
|
3
|
-
#include "esphome/core/application.h"
|
4
|
-
#include "esphome/core/defines.h"
|
5
|
-
#include "esphome/core/helpers.h"
|
6
|
-
#include "esphome/core/log.h"
|
7
|
-
|
8
|
-
#ifdef USE_LOGGER
|
9
|
-
#include "esphome/components/logger/logger.h"
|
10
|
-
#endif
|
11
|
-
|
12
|
-
namespace esphome {
|
13
|
-
namespace uart {
|
14
|
-
static const char *const TAG = "uart.arduino_esp32";
|
15
|
-
|
16
|
-
static const uint32_t UART_PARITY_EVEN = 0 << 0;
|
17
|
-
static const uint32_t UART_PARITY_ODD = 1 << 0;
|
18
|
-
static const uint32_t UART_PARITY_ENABLE = 1 << 1;
|
19
|
-
static const uint32_t UART_NB_BIT_5 = 0 << 2;
|
20
|
-
static const uint32_t UART_NB_BIT_6 = 1 << 2;
|
21
|
-
static const uint32_t UART_NB_BIT_7 = 2 << 2;
|
22
|
-
static const uint32_t UART_NB_BIT_8 = 3 << 2;
|
23
|
-
static const uint32_t UART_NB_STOP_BIT_1 = 1 << 4;
|
24
|
-
static const uint32_t UART_NB_STOP_BIT_2 = 3 << 4;
|
25
|
-
static const uint32_t UART_TICK_APB_CLOCK = 1 << 27;
|
26
|
-
|
27
|
-
uint32_t ESP32ArduinoUARTComponent::get_config() {
|
28
|
-
uint32_t config = 0;
|
29
|
-
|
30
|
-
/*
|
31
|
-
* All bits numbers below come from
|
32
|
-
* framework-arduinoespressif32/cores/esp32/esp32-hal-uart.h
|
33
|
-
* And more specifically conf0 union in uart_dev_t.
|
34
|
-
*
|
35
|
-
* Below is bit used from conf0 union.
|
36
|
-
* <name>:<bits position> <values>
|
37
|
-
* parity:0 0:even 1:odd
|
38
|
-
* parity_en:1 Set this bit to enable uart parity check.
|
39
|
-
* bit_num:2-4 0:5bits 1:6bits 2:7bits 3:8bits
|
40
|
-
* stop_bit_num:4-6 stop bit. 1:1bit 2:1.5bits 3:2bits
|
41
|
-
* tick_ref_always_on:27 select the clock.1:apb clock:ref_tick
|
42
|
-
*/
|
43
|
-
|
44
|
-
if (this->parity_ == UART_CONFIG_PARITY_EVEN) {
|
45
|
-
config |= UART_PARITY_EVEN | UART_PARITY_ENABLE;
|
46
|
-
} else if (this->parity_ == UART_CONFIG_PARITY_ODD) {
|
47
|
-
config |= UART_PARITY_ODD | UART_PARITY_ENABLE;
|
48
|
-
}
|
49
|
-
|
50
|
-
switch (this->data_bits_) {
|
51
|
-
case 5:
|
52
|
-
config |= UART_NB_BIT_5;
|
53
|
-
break;
|
54
|
-
case 6:
|
55
|
-
config |= UART_NB_BIT_6;
|
56
|
-
break;
|
57
|
-
case 7:
|
58
|
-
config |= UART_NB_BIT_7;
|
59
|
-
break;
|
60
|
-
case 8:
|
61
|
-
config |= UART_NB_BIT_8;
|
62
|
-
break;
|
63
|
-
}
|
64
|
-
|
65
|
-
if (this->stop_bits_ == 1) {
|
66
|
-
config |= UART_NB_STOP_BIT_1;
|
67
|
-
} else {
|
68
|
-
config |= UART_NB_STOP_BIT_2;
|
69
|
-
}
|
70
|
-
|
71
|
-
config |= UART_TICK_APB_CLOCK;
|
72
|
-
|
73
|
-
return config;
|
74
|
-
}
|
75
|
-
|
76
|
-
void ESP32ArduinoUARTComponent::setup() {
|
77
|
-
// Use Arduino HardwareSerial UARTs if all used pins match the ones
|
78
|
-
// preconfigured by the platform. For example if RX disabled but TX pin
|
79
|
-
// is 1 we still want to use Serial.
|
80
|
-
bool is_default_tx, is_default_rx;
|
81
|
-
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
82
|
-
is_default_tx = tx_pin_ == nullptr || tx_pin_->get_pin() == 21;
|
83
|
-
is_default_rx = rx_pin_ == nullptr || rx_pin_->get_pin() == 20;
|
84
|
-
#else
|
85
|
-
is_default_tx = tx_pin_ == nullptr || tx_pin_->get_pin() == 1;
|
86
|
-
is_default_rx = rx_pin_ == nullptr || rx_pin_->get_pin() == 3;
|
87
|
-
#endif
|
88
|
-
static uint8_t next_uart_num = 0;
|
89
|
-
if (is_default_tx && is_default_rx && next_uart_num == 0) {
|
90
|
-
#if ARDUINO_USB_CDC_ON_BOOT
|
91
|
-
this->hw_serial_ = &Serial0;
|
92
|
-
#else
|
93
|
-
this->hw_serial_ = &Serial;
|
94
|
-
#endif
|
95
|
-
next_uart_num++;
|
96
|
-
} else {
|
97
|
-
#ifdef USE_LOGGER
|
98
|
-
bool logger_uses_hardware_uart = true;
|
99
|
-
|
100
|
-
#ifdef USE_LOGGER_USB_CDC
|
101
|
-
if (logger::global_logger->get_uart() == logger::UART_SELECTION_USB_CDC) {
|
102
|
-
// this is not a hardware UART, ignore it
|
103
|
-
logger_uses_hardware_uart = false;
|
104
|
-
}
|
105
|
-
#endif // USE_LOGGER_USB_CDC
|
106
|
-
|
107
|
-
#ifdef USE_LOGGER_USB_SERIAL_JTAG
|
108
|
-
if (logger::global_logger->get_uart() == logger::UART_SELECTION_USB_SERIAL_JTAG) {
|
109
|
-
// this is not a hardware UART, ignore it
|
110
|
-
logger_uses_hardware_uart = false;
|
111
|
-
}
|
112
|
-
#endif // USE_LOGGER_USB_SERIAL_JTAG
|
113
|
-
|
114
|
-
if (logger_uses_hardware_uart && logger::global_logger->get_baud_rate() > 0 &&
|
115
|
-
logger::global_logger->get_uart() == next_uart_num) {
|
116
|
-
next_uart_num++;
|
117
|
-
}
|
118
|
-
#endif // USE_LOGGER
|
119
|
-
|
120
|
-
if (next_uart_num >= SOC_UART_NUM) {
|
121
|
-
ESP_LOGW(TAG, "Maximum number of UART components created already.");
|
122
|
-
this->mark_failed();
|
123
|
-
return;
|
124
|
-
}
|
125
|
-
|
126
|
-
this->number_ = next_uart_num;
|
127
|
-
this->hw_serial_ = new HardwareSerial(next_uart_num++); // NOLINT(cppcoreguidelines-owning-memory)
|
128
|
-
}
|
129
|
-
|
130
|
-
this->load_settings(false);
|
131
|
-
}
|
132
|
-
|
133
|
-
void ESP32ArduinoUARTComponent::load_settings(bool dump_config) {
|
134
|
-
int8_t tx = this->tx_pin_ != nullptr ? this->tx_pin_->get_pin() : -1;
|
135
|
-
int8_t rx = this->rx_pin_ != nullptr ? this->rx_pin_->get_pin() : -1;
|
136
|
-
bool invert = false;
|
137
|
-
if (tx_pin_ != nullptr && tx_pin_->is_inverted())
|
138
|
-
invert = true;
|
139
|
-
if (rx_pin_ != nullptr && rx_pin_->is_inverted())
|
140
|
-
invert = true;
|
141
|
-
this->hw_serial_->setRxBufferSize(this->rx_buffer_size_);
|
142
|
-
this->hw_serial_->begin(this->baud_rate_, get_config(), rx, tx, invert);
|
143
|
-
if (dump_config) {
|
144
|
-
ESP_LOGCONFIG(TAG, "UART %u was reloaded.", this->number_);
|
145
|
-
this->dump_config();
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
void ESP32ArduinoUARTComponent::dump_config() {
|
150
|
-
ESP_LOGCONFIG(TAG, "UART Bus %d:", this->number_);
|
151
|
-
LOG_PIN(" TX Pin: ", tx_pin_);
|
152
|
-
LOG_PIN(" RX Pin: ", rx_pin_);
|
153
|
-
if (this->rx_pin_ != nullptr) {
|
154
|
-
ESP_LOGCONFIG(TAG, " RX Buffer Size: %u", this->rx_buffer_size_);
|
155
|
-
}
|
156
|
-
ESP_LOGCONFIG(TAG,
|
157
|
-
" Baud Rate: %u baud\n"
|
158
|
-
" Data Bits: %u\n"
|
159
|
-
" Parity: %s\n"
|
160
|
-
" Stop bits: %u",
|
161
|
-
this->baud_rate_, this->data_bits_, LOG_STR_ARG(parity_to_str(this->parity_)), this->stop_bits_);
|
162
|
-
this->check_logger_conflict();
|
163
|
-
}
|
164
|
-
|
165
|
-
void ESP32ArduinoUARTComponent::write_array(const uint8_t *data, size_t len) {
|
166
|
-
this->hw_serial_->write(data, len);
|
167
|
-
#ifdef USE_UART_DEBUGGER
|
168
|
-
for (size_t i = 0; i < len; i++) {
|
169
|
-
this->debug_callback_.call(UART_DIRECTION_TX, data[i]);
|
170
|
-
}
|
171
|
-
#endif
|
172
|
-
}
|
173
|
-
|
174
|
-
bool ESP32ArduinoUARTComponent::peek_byte(uint8_t *data) {
|
175
|
-
if (!this->check_read_timeout_())
|
176
|
-
return false;
|
177
|
-
*data = this->hw_serial_->peek();
|
178
|
-
return true;
|
179
|
-
}
|
180
|
-
|
181
|
-
bool ESP32ArduinoUARTComponent::read_array(uint8_t *data, size_t len) {
|
182
|
-
if (!this->check_read_timeout_(len))
|
183
|
-
return false;
|
184
|
-
this->hw_serial_->readBytes(data, len);
|
185
|
-
#ifdef USE_UART_DEBUGGER
|
186
|
-
for (size_t i = 0; i < len; i++) {
|
187
|
-
this->debug_callback_.call(UART_DIRECTION_RX, data[i]);
|
188
|
-
}
|
189
|
-
#endif
|
190
|
-
return true;
|
191
|
-
}
|
192
|
-
|
193
|
-
int ESP32ArduinoUARTComponent::available() { return this->hw_serial_->available(); }
|
194
|
-
void ESP32ArduinoUARTComponent::flush() {
|
195
|
-
ESP_LOGVV(TAG, " Flushing");
|
196
|
-
this->hw_serial_->flush();
|
197
|
-
}
|
198
|
-
|
199
|
-
void ESP32ArduinoUARTComponent::check_logger_conflict() {
|
200
|
-
#ifdef USE_LOGGER
|
201
|
-
if (this->hw_serial_ == nullptr || logger::global_logger->get_baud_rate() == 0) {
|
202
|
-
return;
|
203
|
-
}
|
204
|
-
|
205
|
-
if (this->hw_serial_ == logger::global_logger->get_hw_serial()) {
|
206
|
-
ESP_LOGW(TAG, " You're using the same serial port for logging and the UART component. Please "
|
207
|
-
"disable logging over the serial port by setting logger->baud_rate to 0.");
|
208
|
-
}
|
209
|
-
#endif
|
210
|
-
}
|
211
|
-
|
212
|
-
} // namespace uart
|
213
|
-
} // namespace esphome
|
214
|
-
#endif // USE_ESP32_FRAMEWORK_ARDUINO
|
@@ -1,60 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
4
|
-
|
5
|
-
#include <driver/uart.h>
|
6
|
-
#include <HardwareSerial.h>
|
7
|
-
#include <vector>
|
8
|
-
#include "esphome/core/component.h"
|
9
|
-
#include "esphome/core/hal.h"
|
10
|
-
#include "esphome/core/log.h"
|
11
|
-
#include "uart_component.h"
|
12
|
-
|
13
|
-
namespace esphome {
|
14
|
-
namespace uart {
|
15
|
-
|
16
|
-
class ESP32ArduinoUARTComponent : public UARTComponent, public Component {
|
17
|
-
public:
|
18
|
-
void setup() override;
|
19
|
-
void dump_config() override;
|
20
|
-
float get_setup_priority() const override { return setup_priority::BUS; }
|
21
|
-
|
22
|
-
void write_array(const uint8_t *data, size_t len) override;
|
23
|
-
|
24
|
-
bool peek_byte(uint8_t *data) override;
|
25
|
-
bool read_array(uint8_t *data, size_t len) override;
|
26
|
-
|
27
|
-
int available() override;
|
28
|
-
void flush() override;
|
29
|
-
|
30
|
-
uint32_t get_config();
|
31
|
-
|
32
|
-
HardwareSerial *get_hw_serial() { return this->hw_serial_; }
|
33
|
-
uint8_t get_hw_serial_number() { return this->number_; }
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Load the UART with the current settings.
|
37
|
-
* @param dump_config (Optional, default `true`): True for displaying new settings or
|
38
|
-
* false to change it quitely
|
39
|
-
*
|
40
|
-
* Example:
|
41
|
-
* ```cpp
|
42
|
-
* id(uart1).load_settings();
|
43
|
-
* ```
|
44
|
-
*
|
45
|
-
* This will load the current UART interface with the latest settings (baud_rate, parity, etc).
|
46
|
-
*/
|
47
|
-
void load_settings(bool dump_config) override;
|
48
|
-
void load_settings() override { this->load_settings(true); }
|
49
|
-
|
50
|
-
protected:
|
51
|
-
void check_logger_conflict() override;
|
52
|
-
|
53
|
-
HardwareSerial *hw_serial_{nullptr};
|
54
|
-
uint8_t number_{0};
|
55
|
-
};
|
56
|
-
|
57
|
-
} // namespace uart
|
58
|
-
} // namespace esphome
|
59
|
-
|
60
|
-
#endif // USE_ESP32_FRAMEWORK_ARDUINO
|