mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 10:44:13 +01:00
Merge remote-tracking branch 'upstream/dev' into gsm
This commit is contained in:
commit
6d1a18b2fa
32 changed files with 205 additions and 59 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -397,7 +397,7 @@ jobs:
|
||||||
file: ${{ fromJson(needs.list-components.outputs.components) }}
|
file: ${{ fromJson(needs.list-components.outputs.components) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: sudo apt-get install libsodium-dev libsdl2-dev
|
run: sudo apt-get install libsdl2-dev
|
||||||
|
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.7
|
uses: actions/checkout@v4.1.7
|
||||||
|
@ -451,7 +451,7 @@ jobs:
|
||||||
run: echo ${{ matrix.components }}
|
run: echo ${{ matrix.components }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: sudo apt-get install libsodium-dev libsdl2-dev
|
run: sudo apt-get install libsdl2-dev
|
||||||
|
|
||||||
- name: Check out code from GitHub
|
- name: Check out code from GitHub
|
||||||
uses: actions/checkout@v4.1.7
|
uses: actions/checkout@v4.1.7
|
||||||
|
|
|
@ -155,7 +155,7 @@ async def to_code(config):
|
||||||
decoded = base64.b64decode(encryption_config[CONF_KEY])
|
decoded = base64.b64decode(encryption_config[CONF_KEY])
|
||||||
cg.add(var.set_noise_psk(list(decoded)))
|
cg.add(var.set_noise_psk(list(decoded)))
|
||||||
cg.add_define("USE_API_NOISE")
|
cg.add_define("USE_API_NOISE")
|
||||||
cg.add_library("esphome/noise-c", "0.1.4")
|
cg.add_library("esphome/noise-c", "0.1.6")
|
||||||
else:
|
else:
|
||||||
cg.add_define("USE_API_PLAINTEXT")
|
cg.add_define("USE_API_PLAINTEXT")
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "e131.h"
|
#include "e131.h"
|
||||||
|
#ifdef USE_NETWORK
|
||||||
#include "e131_addressable_light_effect.h"
|
#include "e131_addressable_light_effect.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
|
@ -118,3 +119,4 @@ bool E131Component::process_(int universe, const E131Packet &packet) {
|
||||||
|
|
||||||
} // namespace e131
|
} // namespace e131
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
#ifdef USE_NETWORK
|
||||||
#include "esphome/components/socket/socket.h"
|
#include "esphome/components/socket/socket.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
|
||||||
|
@ -53,3 +54,4 @@ class E131Component : public esphome::Component {
|
||||||
|
|
||||||
} // namespace e131
|
} // namespace e131
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "e131_addressable_light_effect.h"
|
#include "e131_addressable_light_effect.h"
|
||||||
#include "e131.h"
|
#include "e131.h"
|
||||||
|
#ifdef USE_NETWORK
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
@ -90,3 +91,4 @@ bool E131AddressableLightEffect::process_(int universe, const E131Packet &packet
|
||||||
|
|
||||||
} // namespace e131
|
} // namespace e131
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/components/light/addressable_light_effect.h"
|
#include "esphome/components/light/addressable_light_effect.h"
|
||||||
|
#ifdef USE_NETWORK
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace e131 {
|
namespace e131 {
|
||||||
|
|
||||||
|
@ -42,3 +42,4 @@ class E131AddressableLightEffect : public light::AddressableLightEffect {
|
||||||
|
|
||||||
} // namespace e131
|
} // namespace e131
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "e131.h"
|
#include "e131.h"
|
||||||
|
#ifdef USE_NETWORK
|
||||||
#include "esphome/components/network/ip_address.h"
|
#include "esphome/components/network/ip_address.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include "esphome/core/util.h"
|
#include "esphome/core/util.h"
|
||||||
|
@ -137,3 +138,4 @@ bool E131Component::packet_(const std::vector<uint8_t> &data, int &universe, E13
|
||||||
|
|
||||||
} // namespace e131
|
} // namespace e131
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "ota_esphome.h"
|
#include "ota_esphome.h"
|
||||||
|
#ifdef USE_OTA
|
||||||
#include "esphome/components/md5/md5.h"
|
#include "esphome/components/md5/md5.h"
|
||||||
#include "esphome/components/network/util.h"
|
#include "esphome/components/network/util.h"
|
||||||
#include "esphome/components/ota/ota_backend.h"
|
#include "esphome/components/ota/ota_backend.h"
|
||||||
|
@ -410,3 +410,4 @@ float ESPHomeOTAComponent::get_setup_priority() const { return setup_priority::A
|
||||||
uint16_t ESPHomeOTAComponent::get_port() const { return this->port_; }
|
uint16_t ESPHomeOTAComponent::get_port() const { return this->port_; }
|
||||||
void ESPHomeOTAComponent::set_port(uint16_t port) { this->port_ = port; }
|
void ESPHomeOTAComponent::set_port(uint16_t port) { this->port_ = port; }
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
|
#ifdef USE_OTA
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
#include "esphome/components/ota/ota_backend.h"
|
#include "esphome/components/ota/ota_backend.h"
|
||||||
|
@ -41,3 +42,4 @@ class ESPHomeOTAComponent : public ota::OTAComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
|
CONF_MAC_ADDRESS,
|
||||||
KEY_CORE,
|
KEY_CORE,
|
||||||
KEY_FRAMEWORK_VERSION,
|
KEY_FRAMEWORK_VERSION,
|
||||||
KEY_TARGET_FRAMEWORK,
|
KEY_TARGET_FRAMEWORK,
|
||||||
KEY_TARGET_PLATFORM,
|
KEY_TARGET_PLATFORM,
|
||||||
PLATFORM_HOST,
|
PLATFORM_HOST,
|
||||||
CONF_MAC_ADDRESS,
|
|
||||||
)
|
)
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
from esphome.helpers import IS_MACOS
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
import esphome.codegen as cg
|
|
||||||
|
|
||||||
from .const import KEY_HOST
|
from .const import KEY_HOST
|
||||||
|
|
||||||
|
@ -42,8 +41,5 @@ async def to_code(config):
|
||||||
cg.add_build_flag("-DUSE_HOST")
|
cg.add_build_flag("-DUSE_HOST")
|
||||||
cg.add_define("USE_ESPHOME_HOST_MAC_ADDRESS", config[CONF_MAC_ADDRESS].parts)
|
cg.add_define("USE_ESPHOME_HOST_MAC_ADDRESS", config[CONF_MAC_ADDRESS].parts)
|
||||||
cg.add_build_flag("-std=c++17")
|
cg.add_build_flag("-std=c++17")
|
||||||
cg.add_build_flag("-lsodium")
|
|
||||||
if IS_MACOS:
|
|
||||||
cg.add_build_flag("-L/opt/homebrew/lib")
|
|
||||||
cg.add_define("ESPHOME_BOARD", "host")
|
cg.add_define("ESPHOME_BOARD", "host")
|
||||||
cg.add_platformio_option("platform", "platformio/native")
|
cg.add_platformio_option("platform", "platformio/native")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "improv_serial_component.h"
|
#include "improv_serial_component.h"
|
||||||
|
#ifdef USE_WIFI
|
||||||
#include "esphome/core/application.h"
|
#include "esphome/core/application.h"
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
|
@ -313,3 +313,4 @@ ImprovSerialComponent *global_improv_serial_component = // NOLINT(cppcoreguidel
|
||||||
|
|
||||||
} // namespace improv_serial
|
} // namespace improv_serial
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
|
#ifdef USE_WIFI
|
||||||
#include <improv.h>
|
#include <improv.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -78,3 +78,4 @@ extern ImprovSerialComponent
|
||||||
|
|
||||||
} // namespace improv_serial
|
} // namespace improv_serial
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "esphome/components/number/number.h"
|
#include "esphome/components/number/number.h"
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
@ -11,7 +13,7 @@ namespace lvgl {
|
||||||
class LVGLNumber : public number::Number {
|
class LVGLNumber : public number::Number {
|
||||||
public:
|
public:
|
||||||
void set_control_lambda(std::function<void(float)> control_lambda) {
|
void set_control_lambda(std::function<void(float)> control_lambda) {
|
||||||
this->control_lambda_ = control_lambda;
|
this->control_lambda_ = std::move(control_lambda);
|
||||||
if (this->initial_state_.has_value()) {
|
if (this->initial_state_.has_value()) {
|
||||||
this->control_lambda_(this->initial_state_.value());
|
this->control_lambda_(this->initial_state_.value());
|
||||||
this->initial_state_.reset();
|
this->initial_state_.reset();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "esphome/components/select/select.h"
|
#include "esphome/components/select/select.h"
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
@ -28,7 +30,7 @@ static std::vector<std::string> split_string(const std::string &str) {
|
||||||
class LVGLSelect : public select::Select {
|
class LVGLSelect : public select::Select {
|
||||||
public:
|
public:
|
||||||
void set_control_lambda(std::function<void(size_t)> lambda) {
|
void set_control_lambda(std::function<void(size_t)> lambda) {
|
||||||
this->control_lambda_ = lambda;
|
this->control_lambda_ = std::move(lambda);
|
||||||
if (this->initial_state_.has_value()) {
|
if (this->initial_state_.has_value()) {
|
||||||
this->control(this->initial_state_.value());
|
this->control(this->initial_state_.value());
|
||||||
this->initial_state_.reset();
|
this->initial_state_.reset();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "esphome/components/switch/switch.h"
|
#include "esphome/components/switch/switch.h"
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
@ -11,7 +13,7 @@ namespace lvgl {
|
||||||
class LVGLSwitch : public switch_::Switch {
|
class LVGLSwitch : public switch_::Switch {
|
||||||
public:
|
public:
|
||||||
void set_control_lambda(std::function<void(bool)> state_lambda) {
|
void set_control_lambda(std::function<void(bool)> state_lambda) {
|
||||||
this->state_lambda_ = state_lambda;
|
this->state_lambda_ = std::move(state_lambda);
|
||||||
if (this->initial_state_.has_value()) {
|
if (this->initial_state_.has_value()) {
|
||||||
this->state_lambda_(this->initial_state_.value());
|
this->state_lambda_(this->initial_state_.value());
|
||||||
this->initial_state_.reset();
|
this->initial_state_.reset();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "esphome/components/text/text.h"
|
#include "esphome/components/text/text.h"
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
@ -11,7 +13,7 @@ namespace lvgl {
|
||||||
class LVGLText : public text::Text {
|
class LVGLText : public text::Text {
|
||||||
public:
|
public:
|
||||||
void set_control_lambda(std::function<void(const std::string)> control_lambda) {
|
void set_control_lambda(std::function<void(const std::string)> control_lambda) {
|
||||||
this->control_lambda_ = control_lambda;
|
this->control_lambda_ = std::move(control_lambda);
|
||||||
if (this->initial_state_.has_value()) {
|
if (this->initial_state_.has_value()) {
|
||||||
this->control_lambda_(this->initial_state_.value());
|
this->control_lambda_(this->initial_state_.value());
|
||||||
this->initial_state_.reset();
|
this->initial_state_.reset();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "prometheus_handler.h"
|
#include "prometheus_handler.h"
|
||||||
|
#ifdef USE_NETWORK
|
||||||
#include "esphome/core/application.h"
|
#include "esphome/core/application.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
@ -350,3 +351,4 @@ void PrometheusHandler::lock_row_(AsyncResponseStream *stream, lock::Lock *obj)
|
||||||
|
|
||||||
} // namespace prometheus
|
} // namespace prometheus
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
#ifdef USE_NETWORK
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
@ -117,3 +118,4 @@ class PrometheusHandler : public AsyncWebHandler, public Component {
|
||||||
|
|
||||||
} // namespace prometheus
|
} // namespace prometheus
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -29,6 +29,13 @@ inline double deg2rad(double degrees) {
|
||||||
void Rtttl::dump_config() { ESP_LOGCONFIG(TAG, "Rtttl"); }
|
void Rtttl::dump_config() { ESP_LOGCONFIG(TAG, "Rtttl"); }
|
||||||
|
|
||||||
void Rtttl::play(std::string rtttl) {
|
void Rtttl::play(std::string rtttl) {
|
||||||
|
if (this->state_ != State::STATE_STOPPED && this->state_ != State::STATE_STOPPING) {
|
||||||
|
int pos = this->rtttl_.find(':');
|
||||||
|
auto name = this->rtttl_.substr(0, pos);
|
||||||
|
ESP_LOGW(TAG, "RTTL Component is already playing: %s", name.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->rtttl_ = std::move(rtttl);
|
this->rtttl_ = std::move(rtttl);
|
||||||
|
|
||||||
this->default_duration_ = 4;
|
this->default_duration_ = 4;
|
||||||
|
@ -98,13 +105,20 @@ void Rtttl::play(std::string rtttl) {
|
||||||
this->note_duration_ = 1;
|
this->note_duration_ = 1;
|
||||||
|
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
|
if (this->speaker_ != nullptr) {
|
||||||
|
this->set_state_(State::STATE_INIT);
|
||||||
this->samples_sent_ = 0;
|
this->samples_sent_ = 0;
|
||||||
this->samples_count_ = 0;
|
this->samples_count_ = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
|
if (this->output_ != nullptr) {
|
||||||
|
this->set_state_(State::STATE_RUNNING);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rtttl::stop() {
|
void Rtttl::stop() {
|
||||||
this->note_duration_ = 0;
|
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
if (this->output_ != nullptr) {
|
if (this->output_ != nullptr) {
|
||||||
this->output_->set_level(0.0);
|
this->output_->set_level(0.0);
|
||||||
|
@ -117,16 +131,35 @@ void Rtttl::stop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
this->note_duration_ = 0;
|
||||||
|
this->set_state_(STATE_STOPPING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rtttl::loop() {
|
void Rtttl::loop() {
|
||||||
if (this->note_duration_ == 0)
|
if (this->note_duration_ == 0 || this->state_ == State::STATE_STOPPED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
if (this->speaker_ != nullptr) {
|
if (this->speaker_ != nullptr) {
|
||||||
|
if (this->state_ == State::STATE_STOPPING) {
|
||||||
|
if (this->speaker_->is_stopped()) {
|
||||||
|
this->set_state_(State::STATE_STOPPED);
|
||||||
|
}
|
||||||
|
} else if (this->state_ == State::STATE_INIT) {
|
||||||
|
if (this->speaker_->is_stopped()) {
|
||||||
|
this->speaker_->start();
|
||||||
|
this->set_state_(State::STATE_STARTING);
|
||||||
|
}
|
||||||
|
} else if (this->state_ == State::STATE_STARTING) {
|
||||||
|
if (this->speaker_->is_running()) {
|
||||||
|
this->set_state_(State::STATE_RUNNING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this->speaker_->is_running()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this->samples_sent_ != this->samples_count_) {
|
if (this->samples_sent_ != this->samples_count_) {
|
||||||
SpeakerSample sample[SAMPLE_BUFFER_SIZE + 1];
|
SpeakerSample sample[SAMPLE_BUFFER_SIZE + 2];
|
||||||
int x = 0;
|
int x = 0;
|
||||||
double rem = 0.0;
|
double rem = 0.0;
|
||||||
|
|
||||||
|
@ -136,7 +169,7 @@ void Rtttl::loop() {
|
||||||
if (this->samples_per_wave_ != 0 && this->samples_sent_ >= this->samples_gap_) { // Play note//
|
if (this->samples_per_wave_ != 0 && this->samples_sent_ >= this->samples_gap_) { // Play note//
|
||||||
rem = ((this->samples_sent_ << 10) % this->samples_per_wave_) * (360.0 / this->samples_per_wave_);
|
rem = ((this->samples_sent_ << 10) % this->samples_per_wave_) * (360.0 / this->samples_per_wave_);
|
||||||
|
|
||||||
int16_t val = (49152 * this->gain_) * sin(deg2rad(rem));
|
int16_t val = (127 * this->gain_) * sin(deg2rad(rem)); // 16bit = 49152
|
||||||
|
|
||||||
sample[x].left = val;
|
sample[x].left = val;
|
||||||
sample[x].right = val;
|
sample[x].right = val;
|
||||||
|
@ -153,9 +186,9 @@ void Rtttl::loop() {
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
int send = this->speaker_->play((uint8_t *) (&sample), x * 4);
|
int send = this->speaker_->play((uint8_t *) (&sample), x * 2);
|
||||||
if (send != x * 4) {
|
if (send != x * 4) {
|
||||||
this->samples_sent_ -= (x - (send / 4));
|
this->samples_sent_ -= (x - (send / 2));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -167,14 +200,7 @@ void Rtttl::loop() {
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
if (!this->rtttl_[position_]) {
|
if (!this->rtttl_[position_]) {
|
||||||
this->note_duration_ = 0;
|
this->finish_();
|
||||||
#ifdef USE_OUTPUT
|
|
||||||
if (this->output_ != nullptr) {
|
|
||||||
this->output_->set_level(0.0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
ESP_LOGD(TAG, "Playback finished");
|
|
||||||
this->on_finished_playback_callback_.call();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +239,7 @@ void Rtttl::loop() {
|
||||||
case 'a':
|
case 'a':
|
||||||
note = 10;
|
note = 10;
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
case 'b':
|
case 'b':
|
||||||
note = 12;
|
note = 12;
|
||||||
break;
|
break;
|
||||||
|
@ -238,14 +265,21 @@ void Rtttl::loop() {
|
||||||
uint8_t scale = get_integer_();
|
uint8_t scale = get_integer_();
|
||||||
if (scale == 0)
|
if (scale == 0)
|
||||||
scale = this->default_octave_;
|
scale = this->default_octave_;
|
||||||
|
|
||||||
|
if (scale < 4 || scale > 7) {
|
||||||
|
ESP_LOGE(TAG, "Octave out of valid range. Should be between 4 and 7. (Octave: %d)", scale);
|
||||||
|
this->finish_();
|
||||||
|
return;
|
||||||
|
}
|
||||||
bool need_note_gap = false;
|
bool need_note_gap = false;
|
||||||
|
|
||||||
// Now play the note
|
// Now play the note
|
||||||
if (note) {
|
if (note) {
|
||||||
auto note_index = (scale - 4) * 12 + note;
|
auto note_index = (scale - 4) * 12 + note;
|
||||||
if (note_index < 0 || note_index >= (int) sizeof(NOTES)) {
|
if (note_index < 0 || note_index >= (int) sizeof(NOTES)) {
|
||||||
ESP_LOGE(TAG, "Note out of valid range");
|
ESP_LOGE(TAG, "Note out of valid range (note: %d, scale: %d, index: %d, max: %d)", note, scale, note_index,
|
||||||
this->note_duration_ = 0;
|
(int) sizeof(NOTES));
|
||||||
|
this->finish_();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto freq = NOTES[note_index];
|
auto freq = NOTES[note_index];
|
||||||
|
@ -285,14 +319,17 @@ void Rtttl::loop() {
|
||||||
this->samples_gap_ = (this->sample_rate_ * DOUBLE_NOTE_GAP_MS) / 1600; //(ms);
|
this->samples_gap_ = (this->sample_rate_ * DOUBLE_NOTE_GAP_MS) / 1600; //(ms);
|
||||||
}
|
}
|
||||||
if (this->output_freq_ != 0) {
|
if (this->output_freq_ != 0) {
|
||||||
|
// make sure there is enough samples to add a full last sinus.
|
||||||
|
|
||||||
|
uint16_t samples_wish = this->samples_count_;
|
||||||
this->samples_per_wave_ = (this->sample_rate_ << 10) / this->output_freq_;
|
this->samples_per_wave_ = (this->sample_rate_ << 10) / this->output_freq_;
|
||||||
|
|
||||||
// make sure there is enough samples to add a full last sinus.
|
|
||||||
uint16_t division = ((this->samples_count_ << 10) / this->samples_per_wave_) + 1;
|
uint16_t division = ((this->samples_count_ << 10) / this->samples_per_wave_) + 1;
|
||||||
uint16_t x = this->samples_count_;
|
|
||||||
this->samples_count_ = (division * this->samples_per_wave_);
|
this->samples_count_ = (division * this->samples_per_wave_);
|
||||||
ESP_LOGD(TAG, "play time old: %d div: %d new: %d %d", x, division, this->samples_count_, this->samples_per_wave_);
|
|
||||||
this->samples_count_ = this->samples_count_ >> 10;
|
this->samples_count_ = this->samples_count_ >> 10;
|
||||||
|
ESP_LOGVV(TAG, "- Calc play time: wish: %d gets: %d (div: %d spw: %d)", samples_wish, this->samples_count_,
|
||||||
|
division, this->samples_per_wave_);
|
||||||
}
|
}
|
||||||
// Convert from frequency in Hz to high and low samples in fixed point
|
// Convert from frequency in Hz to high and low samples in fixed point
|
||||||
}
|
}
|
||||||
|
@ -301,5 +338,53 @@ void Rtttl::loop() {
|
||||||
this->last_note_ = millis();
|
this->last_note_ = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Rtttl::finish_() {
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
|
if (this->output_ != nullptr) {
|
||||||
|
this->output_->set_level(0.0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_SPEAKER
|
||||||
|
if (this->speaker_ != nullptr) {
|
||||||
|
SpeakerSample sample[2];
|
||||||
|
sample[0].left = 0;
|
||||||
|
sample[0].right = 0;
|
||||||
|
sample[1].left = 0;
|
||||||
|
sample[1].right = 0;
|
||||||
|
this->speaker_->play((uint8_t *) (&sample), 8);
|
||||||
|
|
||||||
|
this->speaker_->finish();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
this->set_state_(State::STATE_STOPPING);
|
||||||
|
this->note_duration_ = 0;
|
||||||
|
this->on_finished_playback_callback_.call();
|
||||||
|
ESP_LOGD(TAG, "Playback finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
static const LogString *state_to_string(State state) {
|
||||||
|
switch (state) {
|
||||||
|
case STATE_STOPPED:
|
||||||
|
return LOG_STR("STATE_STOPPED");
|
||||||
|
case STATE_STARTING:
|
||||||
|
return LOG_STR("STATE_STARTING");
|
||||||
|
case STATE_RUNNING:
|
||||||
|
return LOG_STR("STATE_RUNNING");
|
||||||
|
case STATE_STOPPING:
|
||||||
|
return LOG_STR("STATE_STOPPING");
|
||||||
|
case STATE_INIT:
|
||||||
|
return LOG_STR("STATE_INIT");
|
||||||
|
default:
|
||||||
|
return LOG_STR("UNKNOWN");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void Rtttl::set_state_(State state) {
|
||||||
|
State old_state = this->state_;
|
||||||
|
this->state_ = state;
|
||||||
|
ESP_LOGD(TAG, "State changed from %s to %s", LOG_STR_ARG(state_to_string(old_state)),
|
||||||
|
LOG_STR_ARG(state_to_string(state)));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace rtttl
|
} // namespace rtttl
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -14,12 +14,20 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace rtttl {
|
namespace rtttl {
|
||||||
|
|
||||||
|
enum State : uint8_t {
|
||||||
|
STATE_STOPPED = 0,
|
||||||
|
STATE_INIT,
|
||||||
|
STATE_STARTING,
|
||||||
|
STATE_RUNNING,
|
||||||
|
STATE_STOPPING,
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
static const size_t SAMPLE_BUFFER_SIZE = 512;
|
static const size_t SAMPLE_BUFFER_SIZE = 2048;
|
||||||
|
|
||||||
struct SpeakerSample {
|
struct SpeakerSample {
|
||||||
int16_t left{0};
|
int8_t left{0};
|
||||||
int16_t right{0};
|
int8_t right{0};
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -42,7 +50,7 @@ class Rtttl : public Component {
|
||||||
void stop();
|
void stop();
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
|
||||||
bool is_playing() { return this->note_duration_ != 0; }
|
bool is_playing() { return this->state_ != State::STATE_STOPPED; }
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
void add_on_finished_playback_callback(std::function<void()> callback) {
|
void add_on_finished_playback_callback(std::function<void()> callback) {
|
||||||
|
@ -57,6 +65,8 @@ class Rtttl : public Component {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
void finish_();
|
||||||
|
void set_state_(State state);
|
||||||
|
|
||||||
std::string rtttl_{""};
|
std::string rtttl_{""};
|
||||||
size_t position_{0};
|
size_t position_{0};
|
||||||
|
@ -68,13 +78,12 @@ class Rtttl : public Component {
|
||||||
|
|
||||||
uint32_t output_freq_;
|
uint32_t output_freq_;
|
||||||
float gain_{0.6f};
|
float gain_{0.6f};
|
||||||
|
State state_{State::STATE_STOPPED};
|
||||||
|
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
output::FloatOutput *output_;
|
output::FloatOutput *output_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void play_output_();
|
|
||||||
|
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
speaker::Speaker *speaker_{nullptr};
|
speaker::Speaker *speaker_{nullptr};
|
||||||
int sample_rate_{16000};
|
int sample_rate_{16000};
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
import re
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
import re
|
||||||
|
|
||||||
|
from esphome import automation
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
from esphome.components import time
|
||||||
|
from esphome.components.esp32 import CORE, add_idf_sdkconfig_option
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ID,
|
|
||||||
CONF_TIME_ID,
|
|
||||||
CONF_ADDRESS,
|
CONF_ADDRESS,
|
||||||
|
CONF_ID,
|
||||||
CONF_REBOOT_TIMEOUT,
|
CONF_REBOOT_TIMEOUT,
|
||||||
|
CONF_TIME_ID,
|
||||||
KEY_CORE,
|
KEY_CORE,
|
||||||
KEY_FRAMEWORK_VERSION,
|
KEY_FRAMEWORK_VERSION,
|
||||||
)
|
)
|
||||||
from esphome.components.esp32 import CORE, add_idf_sdkconfig_option
|
|
||||||
from esphome.components import time
|
|
||||||
from esphome.core import TimePeriod
|
from esphome.core import TimePeriod
|
||||||
from esphome import automation
|
|
||||||
|
|
||||||
CONF_NETMASK = "netmask"
|
CONF_NETMASK = "netmask"
|
||||||
CONF_PRIVATE_KEY = "private_key"
|
CONF_PRIVATE_KEY = "private_key"
|
||||||
|
@ -91,6 +92,8 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
|
||||||
|
cg.add_define("USE_WIREGUARD")
|
||||||
|
|
||||||
cg.add(var.set_address(str(config[CONF_ADDRESS])))
|
cg.add(var.set_address(str(config[CONF_ADDRESS])))
|
||||||
cg.add(var.set_netmask(str(config[CONF_NETMASK])))
|
cg.add(var.set_netmask(str(config[CONF_NETMASK])))
|
||||||
cg.add(var.set_private_key(config[CONF_PRIVATE_KEY]))
|
cg.add(var.set_private_key(config[CONF_PRIVATE_KEY]))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "wireguard.h"
|
#include "wireguard.h"
|
||||||
|
#ifdef USE_WIREGUARD
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -289,3 +289,4 @@ std::string mask_key(const std::string &key) { return (key.substr(0, 5) + "[...]
|
||||||
|
|
||||||
} // namespace wireguard
|
} // namespace wireguard
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
#ifdef USE_WIREGUARD
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
@ -170,3 +171,4 @@ template<typename... Ts> class WireguardDisableAction : public Action<Ts...>, pu
|
||||||
|
|
||||||
} // namespace wireguard
|
} // namespace wireguard
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#define USE_VALVE
|
#define USE_VALVE
|
||||||
#define USE_WIFI
|
#define USE_WIFI
|
||||||
#define USE_WIFI_AP
|
#define USE_WIFI_AP
|
||||||
|
#define USE_WIREGUARD
|
||||||
|
|
||||||
// Arduino-specific feature flags
|
// Arduino-specific feature flags
|
||||||
#ifdef USE_ARDUINO
|
#ifdef USE_ARDUINO
|
||||||
|
|
|
@ -11,10 +11,6 @@ esphome:
|
||||||
message: Button was pressed
|
message: Button was pressed
|
||||||
- homeassistant.tag_scanned: pulse
|
- homeassistant.tag_scanned: pulse
|
||||||
|
|
||||||
wifi:
|
|
||||||
ssid: MySSID
|
|
||||||
password: password1
|
|
||||||
|
|
||||||
api:
|
api:
|
||||||
port: 8000
|
port: 8000
|
||||||
password: pwd
|
password: pwd
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
<<: !include common.yaml
|
<<: !include common.yaml
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: MySSID
|
||||||
|
password: password1
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
<<: !include common.yaml
|
<<: !include common.yaml
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: MySSID
|
||||||
|
password: password1
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
<<: !include common.yaml
|
<<: !include common.yaml
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: MySSID
|
||||||
|
password: password1
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
<<: !include common.yaml
|
<<: !include common.yaml
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: MySSID
|
||||||
|
password: password1
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
<<: !include common.yaml
|
<<: !include common.yaml
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: MySSID
|
||||||
|
password: password1
|
||||||
|
|
3
tests/components/api/test.host.yaml
Normal file
3
tests/components/api/test.host.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<<: !include common.yaml
|
||||||
|
|
||||||
|
network:
|
|
@ -1 +1,5 @@
|
||||||
<<: !include common.yaml
|
<<: !include common.yaml
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: MySSID
|
||||||
|
password: password1
|
||||||
|
|
Loading…
Reference in a new issue