Compare commits

...

84 Commits

Author SHA1 Message Date
Jesse Hills
1447536906 Merge pull request #4441 from esphome/bump-2023.2.0
2023.2.0
2023-02-15 22:33:31 +13:00
Jesse Hills
27ec517084 Remove dup line 2023-02-15 21:39:17 +13:00
Jesse Hills
ce1f034bac Bump version to 2023.2.0 2023-02-15 19:29:02 +13:00
Jesse Hills
f1f96f16e9 Merge branch 'beta' into bump-2023.2.0 2023-02-15 19:29:02 +13:00
Jesse Hills
7665e9b076 Merge pull request #4433 from esphome/bump-2023.2.0b5
2023.2.0b5
2023-02-14 14:51:00 +13:00
Jesse Hills
227d94f38d Bump version to 2023.2.0b5 2023-02-14 13:59:49 +13:00
Sergey Dudanov
b724ae9e0e Fix setting wrong traits on midea climate component (#4425)
* Fix issue3914

* Remove also default presets and modes

* Fix traits after autoconf
2023-02-14 13:59:49 +13:00
Jesse Hills
df6cc14201 Bump esphome-dashboard to 20230214.0 (#4431) 2023-02-14 13:59:49 +13:00
Jesse Hills
d981d7859d Handle uart.write in json-config endpoint (#4430) 2023-02-14 13:59:49 +13:00
Jesse Hills
0f1ec515c1 Add version api endpoint (#4429) 2023-02-14 13:59:49 +13:00
WitchKing
78e18256f7 Ledc fix (#4338) 2023-02-14 13:59:49 +13:00
Jesse Hills
4899dfe642 Merge pull request #4423 from esphome/bump-2023.2.0b4
2023.2.0b4
2023-02-13 15:17:05 +13:00
Jesse Hills
d6b6e94059 Bump version to 2023.2.0b4 2023-02-13 11:54:27 +13:00
NP v/d Spek
310355a00b Fix check for empty clipping array (#4421) 2023-02-13 11:54:26 +13:00
NP v/d Spek
8cf26d6f3c Add Clipping to displaybuffer (#4271)
* adding Clipping support to the displaybuffer
- add rect structure

* removed unused define

* add missing property for storing the clipped areas

* include log header

* Move Rect method's code to cpp file
- removed obsolete remarks

* fixed reported issues

* make Rect class methods public

* clang fix

* Remove commented code

* Renaming clipping methods

* Multiple changes:
- replaced 32766 with VALUE_NO_SET
- fixed the way *_clipping(left, top, right, bottom) is stored
- add `is_clipping();`
- make sure that all clipped region are closed after `do_update_()`
- rename de parameters for `Rect::expand();`

* remove unneeded space

* replace define with static const uint8_t

* correcting my copy paste mistake

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-02-13 11:54:26 +13:00
Patrick Collins
b15a10f905 Climate PID Autotune Logging fixes (#4136)
* pid autotune logging fixes

* fixed clang-format request

* improved and clarified logging

* changed logging not to alter the TAG

* logging now does not alter TAG. fixed clang formattting

* fixed string issues

* playing with strings to please the clang gods

* playing with strings

* Delete secrets.yaml

* Delete console-fan-autotune-test.yaml

* Update esphome/components/pid/pid_autotuner.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/pid/pid_autotuner.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/pid/pid_autotuner.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/pid/pid_autotuner.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Update esphome/components/pid/pid_autotuner.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-02-13 11:54:26 +13:00
Jesse Hills
5dcf1debd7 Merge pull request #4406 from esphome/bump-2023.2.0b3
2023.2.0b3
2023-02-09 18:04:35 +13:00
Jesse Hills
9b57e1ac1d Bump version to 2023.2.0b3 2023-02-09 17:38:54 +13:00
Jesse Hills
68683e3a50 Fix release workflow (#4405) 2023-02-09 17:38:54 +13:00
Jesse Hills
d83324c4dc Merge pull request #4404 from esphome/bump-2023.2.0b2
2023.2.0b2
2023-02-09 16:55:48 +13:00
Jesse Hills
ecde4c1d2d Bump version to 2023.2.0b2 2023-02-09 16:27:25 +13:00
Jesse Hills
bd8e470726 Bump curl version in docker (#4403) 2023-02-09 16:27:24 +13:00
Jesse Hills
4af4649e23 Merge pull request #4355 from esphome/bump-2022.12.8
2022.12.8
2023-01-27 10:04:29 +13:00
Jesse Hills
8bcddef39d Bump version to 2022.12.8 2023-01-27 09:44:41 +13:00
Franck Nijhof
4ac96ccea2 Add Home Assistant integration discovery (#4328) 2023-01-27 09:44:41 +13:00
Franck Nijhof
3c5de77ae9 Refactor NGINX configuration of Home Assistant Add-on (#4312) 2023-01-27 09:44:41 +13:00
Franck Nijhof
a2925b1d37 Migrate old-style S6 scripts to s6-rc.d (#4311) 2023-01-27 09:44:41 +13:00
Franck Nijhof
73748e9e20 Upgrades add-on base image to 6.2.0 (#4310) 2023-01-27 09:44:40 +13:00
Jesse Hills
75c9823899 Merge pull request #4350 from esphome/bump-2022.12.7
2022.12.7
2023-01-26 15:50:03 +13:00
Jesse Hills
c8c0bd3351 Bump version to 2022.12.7 2023-01-26 15:00:18 +13:00
melyux
e1cdeb7c8f Add a soft reset in setup() for bmp280 (#4329)
fixes https://github.com/esphome/issues/issues/3383
2023-01-26 15:00:17 +13:00
Alex
7f97f42552 Fix BME280 initialization before wifi setup (#4190)
fixes https://github.com/esphome/issues/issues/3530
2023-01-26 15:00:17 +13:00
Stephan Martin
aa7f3569ec rename esp32 CAN to TWAI, so it compiles again (#4334)
fixes https://github.com/esphome/issues/issues/4023
2023-01-26 15:00:17 +13:00
Denis Bodor (aka Lefinnois)
2d0a08442e fix stepper jump back with small steps (#4339) 2023-01-26 15:00:17 +13:00
Joakim Sørensen
d2380756b2 Add "content" to deploy-ha-addon-repo dispatch (#4349) 2023-01-26 15:00:17 +13:00
Jesse Hills
925e3cb6c9 Fix missing s 2023-01-23 20:34:31 +00:00
Jesse Hills
6757acba56 Merge pull request #4342 from esphome/bump-2022.12.6
2022.12.6
2023-01-24 08:58:45 +13:00
Jesse Hills
5cc91cdd95 Bump version to 2022.12.6 2023-01-24 08:30:42 +13:00
Jesse Hills
2b41886819 Move from docker manifest command to buildx with platforms (#4320) 2023-01-24 08:30:42 +13:00
Jesse Hills
72c6efd6a0 Merge pull request #4335 from esphome/bump-2022.12.5
2022.12.5
2023-01-23 09:27:18 +13:00
Jesse Hills
a1f1804112 Bump version to 2022.12.5 2023-01-23 09:06:20 +13:00
Jesse Hills
a8b1ceb4e9 Bump nano version in lint docker image (#4218) 2023-01-23 09:06:20 +13:00
Jesse Hills
4fb0f7f8c6 Merge pull request #4323 from esphome/bump-2022.12.4
2022.12.4
2023-01-21 16:17:57 +13:00
Jesse Hills
958cadeca8 Bump version to 2022.12.4 2023-01-20 18:33:09 +13:00
J. Nick Koston
00f2655f1a Always send the MTU request for BLE v3 cached connections (#4322)
closes https://github.com/esphome/esphome/pull/4321
fixes https://github.com/esphome/issues/issues/4041
fixes https://github.com/esphome/issues/issues/3951
2023-01-20 18:33:09 +13:00
Jesse Hills
074f5029eb Fix gpio pin mode for ISR pins (#4216) 2023-01-20 18:33:09 +13:00
Jesse Hills
1691976587 Merge pull request #4214 from esphome/bump-2022.12.3
2022.12.3
2022-12-20 23:34:01 +13:00
Jesse Hills
60e6b4d21e Bump version to 2022.12.3 2022-12-20 23:15:39 +13:00
Jesse Hills
5750591df2 Fix ESP32 GPIO when using INPUT PULLUP mode (#4213) 2022-12-20 23:15:39 +13:00
Jesse Hills
a75da54455 Merge pull request #4212 from esphome/bump-2022.12.2
2022.12.2
2022-12-20 11:06:34 +13:00
Jesse Hills
de7f6c3f5f Bump version to 2022.12.2 2022-12-20 10:49:36 +13:00
J. Nick Koston
4245480656 Handle zero padding anywhere in the combined adv data (#4208)
fixes https://github.com/esphome/issues/issues/3913
2022-12-20 10:49:35 +13:00
Jesse Hills
1824c8131e Fix import_full_config for adoption configs (#4197)
* Fix git raw url

* Fix setting full config query param

* Force dashboard import urls to have a branch or tag reference for full import
2022-12-20 10:49:35 +13:00
Jesse Hills
4e9606d2e0 Merge pull request #4196 from esphome/bump-2022.12.1
2022.12.1
2022-12-16 14:05:24 +13:00
Jesse Hills
78500fa933 Bump version to 2022.12.1 2022-12-16 13:36:11 +13:00
Jesse Hills
9c69b98a49 Fix i2s_audio media_player compiling for esp32-s2 (#4195) 2022-12-16 13:36:10 +13:00
Jesse Hills
e6d8ef98d3 Mark ESP32-S2 as not having Bluetooth (#4194) 2022-12-16 13:36:10 +13:00
Stefan Agner
3f1af1690b Support non-multiarch toolchains on 32-bit ARM (#4191)
fixes https://github.com/esphome/issues/issues/3904
2022-12-16 13:36:10 +13:00
Jesse Hills
84374b6b1e Merge pull request #4186 from esphome/bump-2022.12.0
2022.12.0
2022-12-14 17:06:24 +13:00
Jesse Hills
391316c9b5 Bump version to 2022.12.0 2022-12-14 16:37:39 +13:00
Jesse Hills
705c62ebd7 Merge branch 'beta' into bump-2022.12.0 2022-12-14 16:37:39 +13:00
Jesse Hills
7209dd8bae Merge pull request #4152 from esphome/bump-2022.11.5
2022.11.5
2022-12-06 13:12:57 +13:00
Jesse Hills
ab736c89bb Bump version to 2022.11.5 2022-12-06 12:52:48 +13:00
Jesse Hills
6911639617 Fix board pin alias lookup (#4147) 2022-12-06 12:52:48 +13:00
Jesse Hills
b9720d0715 Merge pull request #4130 from esphome/bump-2022.11.4
2022.11.4
2022-12-01 15:38:52 +13:00
Jesse Hills
47b3267ed4 Bump version to 2022.11.4 2022-12-01 13:47:50 +13:00
Jesse Hills
e16ba2adb5 Fix queuing scripts not compiling (#4077) 2022-12-01 13:47:50 +13:00
Nicolas Graziano
0a19b1e32c Dashboard, after login use relative url. (#4103) 2022-12-01 13:47:49 +13:00
Jesse Hills
bae9a950c0 current-based cover fix copy paste mistake (#4124) 2022-12-01 13:47:49 +13:00
Jesse Hills
72b2943332 Merge pull request #4083 from esphome/bump-2022.11.3
2022.11.3
2022-11-25 07:23:08 +13:00
Jesse Hills
4ec0ef7548 Bump version to 2022.11.3 2022-11-24 17:01:52 +13:00
Jesse Hills
25bc6761f6 Don't convert climate temperature step (#4082) 2022-11-24 17:01:52 +13:00
Brian Kaufman
81b6562c25 Fix units for refresh: never (#4048) 2022-11-24 17:01:52 +13:00
Samuel Sieb
ae74189fc2 fix missing library (#4051) 2022-11-24 17:01:51 +13:00
Jesse Hills
9e516efe10 Merge pull request #4074 from esphome/bump-2022.11.2
2022.11.2
2022-11-23 16:06:34 +13:00
Jesse Hills
366e29439e Bump version to 2022.11.2 2022-11-23 13:04:21 +13:00
J. Nick Koston
1c9c700d7f Avoid creating a new espbt::ESPBTUUID each loop when registering for notify (#4069) 2022-11-23 13:04:21 +13:00
J. Nick Koston
b2e6b9d31f Avoid 128bit uuid loop for 16/32 bit uuids (#4068) 2022-11-23 13:04:21 +13:00
Jesse Hills
7623f63846 rp2040_pwm frequency is per pair of pins (#4061) 2022-11-23 13:04:21 +13:00
Jesse Hills
2bfaf9dce3 Update web_server index (#4060) 2022-11-23 13:04:20 +13:00
Jesse Hills
5c2c1560bb Fix rp2040 pwm to use pico-sdk, not mbed (#4059) 2022-11-23 13:04:20 +13:00
Jesse Hills
f7096ab78e Merge pull request #4041 from esphome/bump-2022.11.1
2022.11.1
2022-11-17 15:40:51 +13:00
Jesse Hills
98f8feb625 Bump version to 2022.11.1 2022-11-17 13:52:15 +13:00
Jesse Hills
9944ca414e Support ADC on RP2040 (#4040) 2022-11-17 13:52:15 +13:00
14 changed files with 368 additions and 52 deletions

View File

@@ -150,6 +150,6 @@ jobs:
ref: "main",
inputs: {
version: "${{ github.event.release.tag_name }}",
content: "${{ toJSON(github.event.release.body) }}"
content: ${{ toJSON(github.event.release.body) }}
}
})

2
.gitignore vendored
View File

@@ -128,3 +128,5 @@ tests/.esphome/
sdkconfig.*
!sdkconfig.defaults
.tests/

View File

@@ -26,7 +26,7 @@ RUN \
python3-cryptography=3.3.2-1 \
iputils-ping=3:20210202-1 \
git=1:2.30.2-1 \
curl=7.74.0-1.3+deb11u3 \
curl=7.74.0-1.3+deb11u5 \
openssh-client=1:8.4p1-5+deb11u1 \
&& rm -rf \
/tmp/* \

View File

@@ -15,6 +15,84 @@ static const char *const TAG = "display";
const Color COLOR_OFF(0, 0, 0, 0);
const Color COLOR_ON(255, 255, 255, 255);
void Rect::expand(int16_t horizontal, int16_t vertical) {
if (this->is_set() && (this->w >= (-2 * horizontal)) && (this->h >= (-2 * vertical))) {
this->x = this->x - horizontal;
this->y = this->y - vertical;
this->w = this->w + (2 * horizontal);
this->h = this->h + (2 * vertical);
}
}
void Rect::extend(Rect rect) {
if (!this->is_set()) {
this->x = rect.x;
this->y = rect.y;
this->w = rect.w;
this->h = rect.h;
} else {
if (this->x > rect.x) {
this->x = rect.x;
}
if (this->y > rect.y) {
this->y = rect.y;
}
if (this->x2() < rect.x2()) {
this->w = rect.x2() - this->x;
}
if (this->y2() < rect.y2()) {
this->h = rect.y2() - this->y;
}
}
}
void Rect::shrink(Rect rect) {
if (!this->inside(rect)) {
(*this) = Rect();
} else {
if (this->x < rect.x) {
this->x = rect.x;
}
if (this->y < rect.y) {
this->y = rect.y;
}
if (this->x2() > rect.x2()) {
this->w = rect.x2() - this->x;
}
if (this->y2() > rect.y2()) {
this->h = rect.y2() - this->y;
}
}
}
bool Rect::inside(int16_t x, int16_t y, bool absolute) { // NOLINT
if (!this->is_set()) {
return true;
}
if (absolute) {
return ((x >= 0) && (x <= this->w) && (y >= 0) && (y <= this->h));
} else {
return ((x >= this->x) && (x <= this->x2()) && (y >= this->y) && (y <= this->y2()));
}
}
bool Rect::inside(Rect rect, bool absolute) {
if (!this->is_set() || !rect.is_set()) {
return true;
}
if (absolute) {
return ((rect.x <= this->w) && (rect.w >= 0) && (rect.y <= this->h) && (rect.h >= 0));
} else {
return ((rect.x <= this->x2()) && (rect.x2() >= this->x) && (rect.y <= this->y2()) && (rect.y2() >= this->y));
}
}
void Rect::info(const std::string &prefix) {
if (this->is_set()) {
ESP_LOGI(TAG, "%s [%3d,%3d,%3d,%3d]", prefix.c_str(), this->x, this->y, this->w, this->h);
} else
ESP_LOGI(TAG, "%s ** IS NOT SET **", prefix.c_str());
}
void DisplayBuffer::init_internal_(uint32_t buffer_length) {
ExternalRAMAllocator<uint8_t> allocator(ExternalRAMAllocator<uint8_t>::ALLOW_FAILURE);
this->buffer_ = allocator.allocate(buffer_length);
@@ -24,6 +102,7 @@ void DisplayBuffer::init_internal_(uint32_t buffer_length) {
}
this->clear();
}
void DisplayBuffer::fill(Color color) { this->filled_rectangle(0, 0, this->get_width(), this->get_height(), color); }
void DisplayBuffer::clear() { this->fill(COLOR_OFF); }
int DisplayBuffer::get_width() {
@@ -50,6 +129,9 @@ int DisplayBuffer::get_height() {
}
void DisplayBuffer::set_rotation(DisplayRotation rotation) { this->rotation_ = rotation; }
void HOT DisplayBuffer::draw_pixel_at(int x, int y, Color color) {
if (!this->get_clipping().inside(x, y))
return; // NOLINT
switch (this->rotation_) {
case DISPLAY_ROTATION_0_DEGREES:
break;
@@ -368,6 +450,10 @@ void DisplayBuffer::do_update_() {
} else if (this->writer_.has_value()) {
(*this->writer_)(*this);
}
// remove all not ended clipping regions
while (is_clipping()) {
end_clipping();
}
}
void DisplayOnPageChangeTrigger::process(DisplayPage *from, DisplayPage *to) {
if ((this->from_ == nullptr || this->from_ == from) && (this->to_ == nullptr || this->to_ == to))
@@ -392,6 +478,41 @@ void DisplayBuffer::strftime(int x, int y, Font *font, const char *format, time:
}
#endif
void DisplayBuffer::start_clipping(Rect rect) {
if (!this->clipping_rectangle_.empty()) {
Rect r = this->clipping_rectangle_.back();
rect.shrink(r);
}
this->clipping_rectangle_.push_back(rect);
}
void DisplayBuffer::end_clipping() {
if (this->clipping_rectangle_.empty()) {
ESP_LOGE(TAG, "clear: Clipping is not set.");
} else {
this->clipping_rectangle_.pop_back();
}
}
void DisplayBuffer::extend_clipping(Rect add_rect) {
if (this->clipping_rectangle_.empty()) {
ESP_LOGE(TAG, "add: Clipping is not set.");
} else {
this->clipping_rectangle_.back().extend(add_rect);
}
}
void DisplayBuffer::shrink_clipping(Rect add_rect) {
if (this->clipping_rectangle_.empty()) {
ESP_LOGE(TAG, "add: Clipping is not set.");
} else {
this->clipping_rectangle_.back().shrink(add_rect);
}
}
Rect DisplayBuffer::get_clipping() {
if (this->clipping_rectangle_.empty()) {
return Rect();
} else {
return this->clipping_rectangle_.back();
}
}
bool Glyph::get_pixel(int x, int y) const {
const int x_data = x - this->glyph_data_->offset_x;
const int y_data = y - this->glyph_data_->offset_y;

View File

@@ -4,7 +4,6 @@
#include "esphome/core/defines.h"
#include "esphome/core/automation.h"
#include "display_color_utils.h"
#include <cstdarg>
#include <vector>
@@ -100,6 +99,32 @@ enum DisplayRotation {
DISPLAY_ROTATION_270_DEGREES = 270,
};
static const int16_t VALUE_NO_SET = 32766;
class Rect {
public:
int16_t x; ///< X coordinate of corner
int16_t y; ///< Y coordinate of corner
int16_t w; ///< Width of region
int16_t h; ///< Height of region
Rect() : x(VALUE_NO_SET), y(VALUE_NO_SET), w(VALUE_NO_SET), h(VALUE_NO_SET) {} // NOLINT
inline Rect(int16_t x, int16_t y, int16_t w, int16_t h) ALWAYS_INLINE : x(x), y(y), w(w), h(h) {}
inline int16_t x2() { return this->x + this->w; }; ///< X coordinate of corner
inline int16_t y2() { return this->y + this->h; }; ///< Y coordinate of corner
inline bool is_set() ALWAYS_INLINE { return (this->h != VALUE_NO_SET) && (this->w != VALUE_NO_SET); }
void expand(int16_t horizontal, int16_t vertical);
void extend(Rect rect);
void shrink(Rect rect);
bool inside(Rect rect, bool absolute = false);
bool inside(int16_t x, int16_t y, bool absolute = false);
void info(const std::string &prefix = "rect info:");
};
class Font;
class Image;
class DisplayBuffer;
@@ -126,6 +151,7 @@ class DisplayBuffer {
int get_width();
/// Get the height of the image in pixels with rotation applied.
int get_height();
/// Set a single pixel at the specified coordinates to the given color.
void draw_pixel_at(int x, int y, Color color = COLOR_ON);
@@ -374,6 +400,49 @@ class DisplayBuffer {
*/
virtual DisplayType get_display_type() = 0;
/** Set the clipping rectangle for further drawing
*
* @param[in] rect: Pointer to Rect for clipping (or NULL for entire screen)
*
* return true if success, false if error
*/
void start_clipping(Rect rect);
void start_clipping(int16_t left, int16_t top, int16_t right, int16_t bottom) {
start_clipping(Rect(left, top, right - left, bottom - top));
};
/** Add a rectangular region to the invalidation region
* - This is usually called when an element has been modified
*
* @param[in] rect: Rectangle to add to the invalidation region
*/
void extend_clipping(Rect rect);
void extend_clipping(int16_t left, int16_t top, int16_t right, int16_t bottom) {
this->extend_clipping(Rect(left, top, right - left, bottom - top));
};
/** substract a rectangular region to the invalidation region
* - This is usually called when an element has been modified
*
* @param[in] rect: Rectangle to add to the invalidation region
*/
void shrink_clipping(Rect rect);
void shrink_clipping(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) {
this->shrink_clipping(Rect(left, top, right - left, bottom - top));
};
/** Reset the invalidation region
*/
void end_clipping();
/** Get the current the clipping rectangle
*
* return rect for active clipping region
*/
Rect get_clipping();
bool is_clipping() const { return !this->clipping_rectangle_.empty(); }
protected:
void vprintf_(int x, int y, Font *font, Color color, TextAlign align, const char *format, va_list arg);
@@ -390,6 +459,7 @@ class DisplayBuffer {
DisplayPage *previous_page_{nullptr};
std::vector<DisplayOnPageChangeTrigger *> on_page_change_triggers_;
bool auto_clear_enabled_{true};
std::vector<Rect> clipping_rectangle_;
};
class DisplayPage {

View File

@@ -12,6 +12,8 @@ CONF_BLE_ID = "ble_id"
NO_BLUTOOTH_VARIANTS = [const.VARIANT_ESP32S2]
NO_BLUTOOTH_VARIANTS = [const.VARIANT_ESP32S2]
esp32_ble_ns = cg.esphome_ns.namespace("esp32_ble")
ESP32BLE = esp32_ble_ns.class_("ESP32BLE", cg.Component)

View File

@@ -8,6 +8,20 @@
#endif
#include <driver/ledc.h>
#define CLOCK_FREQUENCY 80e6f
#ifdef USE_ARDUINO
#ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK
#undef CLOCK_FREQUENCY
// starting with ESP32 Arduino 2.0.2, the 40MHz crystal is used as clock by default if supported
#define CLOCK_FREQUENCY 40e6f
#endif
#else
#define DEFAULT_CLK LEDC_USE_APB_CLK
#endif
static const uint8_t SETUP_ATTEMPT_COUNT_MAX = 5;
namespace esphome {
namespace ledc {
@@ -26,11 +40,11 @@ inline ledc_mode_t get_speed_mode(uint8_t) { return LEDC_LOW_SPEED_MODE; }
#endif
#endif
float ledc_max_frequency_for_bit_depth(uint8_t bit_depth) { return 80e6f / float(1 << bit_depth); }
float ledc_max_frequency_for_bit_depth(uint8_t bit_depth) { return CLOCK_FREQUENCY / float(1 << bit_depth); }
float ledc_min_frequency_for_bit_depth(uint8_t bit_depth, bool low_frequency) {
const float max_div_num = ((1 << MAX_RES_BITS) - 1) / (low_frequency ? 32.0f : 256.0f);
return 80e6f / (max_div_num * float(1 << bit_depth));
return CLOCK_FREQUENCY / (max_div_num * float(1 << bit_depth));
}
optional<uint8_t> ledc_bit_depth_for_frequency(float frequency) {
@@ -46,6 +60,38 @@ optional<uint8_t> ledc_bit_depth_for_frequency(float frequency) {
return {};
}
#ifdef USE_ESP_IDF
esp_err_t configure_timer_frequency(ledc_mode_t speed_mode, ledc_timer_t timer_num, ledc_channel_t chan_num,
uint8_t channel, uint8_t &bit_depth, float frequency) {
bit_depth = *ledc_bit_depth_for_frequency(frequency);
if (bit_depth < 1) {
ESP_LOGE(TAG, "Frequency %f can't be achieved with any bit depth", frequency);
}
ledc_timer_config_t timer_conf{};
timer_conf.speed_mode = speed_mode;
timer_conf.duty_resolution = static_cast<ledc_timer_bit_t>(bit_depth);
timer_conf.timer_num = timer_num;
timer_conf.freq_hz = (uint32_t) frequency;
timer_conf.clk_cfg = DEFAULT_CLK;
// Configure the time with fallback in case of error
int attempt_count_max = SETUP_ATTEMPT_COUNT_MAX;
esp_err_t init_result = ESP_FAIL;
while (attempt_count_max > 0 && init_result != ESP_OK) {
init_result = ledc_timer_config(&timer_conf);
if (init_result != ESP_OK) {
ESP_LOGW(TAG, "Unable to initialize timer with frequency %.1f and bit depth of %u", frequency, bit_depth);
// try again with a lower bit depth
timer_conf.duty_resolution = static_cast<ledc_timer_bit_t>(--bit_depth);
}
attempt_count_max--;
}
return init_result;
}
#endif
void LEDCOutput::write_state(float state) {
if (!initialized_) {
ESP_LOGW(TAG, "LEDC output hasn't been initialized yet!");
@@ -61,6 +107,7 @@ void LEDCOutput::write_state(float state) {
auto duty = static_cast<uint32_t>(duty_rounded);
#ifdef USE_ARDUINO
ESP_LOGV(TAG, "Setting duty: %u on channel %u", duty, this->channel_);
ledcWrite(this->channel_, duty);
#endif
#ifdef USE_ESP_IDF
@@ -72,6 +119,7 @@ void LEDCOutput::write_state(float state) {
}
void LEDCOutput::setup() {
ESP_LOGV(TAG, "Entering setup...");
#ifdef USE_ARDUINO
this->update_frequency(this->frequency_);
this->turn_off();
@@ -83,19 +131,16 @@ void LEDCOutput::setup() {
auto timer_num = static_cast<ledc_timer_t>((channel_ % 8) / 2);
auto chan_num = static_cast<ledc_channel_t>(channel_ % 8);
bit_depth_ = *ledc_bit_depth_for_frequency(frequency_);
if (bit_depth_ < 1) {
ESP_LOGW(TAG, "Frequency %f can't be achieved with any bit depth", frequency_);
this->status_set_warning();
esp_err_t timer_init_result =
configure_timer_frequency(speed_mode, timer_num, chan_num, this->channel_, this->bit_depth_, this->frequency_);
if (timer_init_result != ESP_OK) {
ESP_LOGE(TAG, "Frequency %f can't be achieved with computed bit depth %u", this->frequency_, this->bit_depth_);
this->status_set_error();
return;
}
ledc_timer_config_t timer_conf{};
timer_conf.speed_mode = speed_mode;
timer_conf.duty_resolution = static_cast<ledc_timer_bit_t>(bit_depth_);
timer_conf.timer_num = timer_num;
timer_conf.freq_hz = (uint32_t) frequency_;
timer_conf.clk_cfg = LEDC_AUTO_CLK;
ledc_timer_config(&timer_conf);
ESP_LOGV(TAG, "Configured frequency %f with a bit depth of %u bits", this->frequency_, this->bit_depth_);
ledc_channel_config_t chan_conf{};
chan_conf.gpio_num = pin_->get_pin();
@@ -107,6 +152,7 @@ void LEDCOutput::setup() {
chan_conf.hpoint = 0;
ledc_channel_config(&chan_conf);
initialized_ = true;
this->status_clear_error();
#endif
}
@@ -114,36 +160,80 @@ void LEDCOutput::dump_config() {
ESP_LOGCONFIG(TAG, "LEDC Output:");
LOG_PIN(" Pin ", this->pin_);
ESP_LOGCONFIG(TAG, " LEDC Channel: %u", this->channel_);
ESP_LOGCONFIG(TAG, " Frequency: %.1f Hz", this->frequency_);
ESP_LOGCONFIG(TAG, " PWM Frequency: %.1f Hz", this->frequency_);
ESP_LOGCONFIG(TAG, " Bit depth: %u", this->bit_depth_);
ESP_LOGV(TAG, " Max frequency for bit depth: %f", ledc_max_frequency_for_bit_depth(this->bit_depth_));
ESP_LOGV(TAG, " Min frequency for bit depth: %f",
ledc_min_frequency_for_bit_depth(this->bit_depth_, (this->frequency_ < 100)));
ESP_LOGV(TAG, " Max frequency for bit depth-1: %f", ledc_max_frequency_for_bit_depth(this->bit_depth_ - 1));
ESP_LOGV(TAG, " Min frequency for bit depth-1: %f",
ledc_min_frequency_for_bit_depth(this->bit_depth_ - 1, (this->frequency_ < 100)));
ESP_LOGV(TAG, " Max frequency for bit depth+1: %f", ledc_max_frequency_for_bit_depth(this->bit_depth_ + 1));
ESP_LOGV(TAG, " Min frequency for bit depth+1: %f",
ledc_min_frequency_for_bit_depth(this->bit_depth_ + 1, (this->frequency_ < 100)));
ESP_LOGV(TAG, " Max res bits: %d", MAX_RES_BITS);
ESP_LOGV(TAG, " Clock frequency: %f", CLOCK_FREQUENCY);
}
void LEDCOutput::update_frequency(float frequency) {
auto bit_depth_opt = ledc_bit_depth_for_frequency(frequency);
if (!bit_depth_opt.has_value()) {
ESP_LOGW(TAG, "Frequency %f can't be achieved with any bit depth", frequency);
this->status_set_warning();
ESP_LOGE(TAG, "Frequency %f can't be achieved with any bit depth", this->frequency_);
this->status_set_error();
}
this->bit_depth_ = bit_depth_opt.value_or(8);
this->frequency_ = frequency;
#ifdef USE_ARDUINO
ledcSetup(this->channel_, frequency, this->bit_depth_);
initialized_ = true;
ESP_LOGV(TAG, "Using Arduino API - Trying to define channel, frequency and bit depth...");
u_int32_t configured_frequency = 0;
// Configure LEDC channel, frequency and bit depth with fallback
int attempt_count_max = SETUP_ATTEMPT_COUNT_MAX;
while (attempt_count_max > 0 && configured_frequency == 0) {
ESP_LOGV(TAG, "Trying initialize channel %u with frequency %.1f and bit depth of %u...", this->channel_,
this->frequency_, this->bit_depth_);
configured_frequency = ledcSetup(this->channel_, frequency, this->bit_depth_);
if (configured_frequency != 0) {
initialized_ = true;
this->status_clear_error();
ESP_LOGV(TAG, "Configured frequency: %u with bit depth: %u", configured_frequency, this->bit_depth_);
} else {
ESP_LOGW(TAG, "Unable to initialize channel %u with frequency %.1f and bit depth of %u", this->channel_,
this->frequency_, this->bit_depth_);
// try again with a lower bit depth
this->bit_depth_--;
}
attempt_count_max--;
}
if (configured_frequency == 0) {
ESP_LOGE(TAG, "Permanently failed to initialize channel %u with frequency %.1f and bit depth of %u", this->channel_,
this->frequency_, this->bit_depth_);
this->status_set_error();
return;
}
#endif // USE_ARDUINO
#ifdef USE_ESP_IDF
if (!initialized_) {
ESP_LOGW(TAG, "LEDC output hasn't been initialized yet!");
return;
}
auto speed_mode = get_speed_mode(channel_);
auto timer_num = static_cast<ledc_timer_t>((channel_ % 8) / 2);
auto chan_num = static_cast<ledc_channel_t>(channel_ % 8);
ledc_timer_config_t timer_conf{};
timer_conf.speed_mode = speed_mode;
timer_conf.duty_resolution = static_cast<ledc_timer_bit_t>(bit_depth_);
timer_conf.timer_num = timer_num;
timer_conf.freq_hz = (uint32_t) frequency_;
timer_conf.clk_cfg = LEDC_AUTO_CLK;
ledc_timer_config(&timer_conf);
esp_err_t timer_init_result =
configure_timer_frequency(speed_mode, timer_num, chan_num, this->channel_, this->bit_depth_, this->frequency_);
if (timer_init_result != ESP_OK) {
ESP_LOGE(TAG, "Frequency %f can't be achieved with computed bit depth %u", this->frequency_, this->bit_depth_);
this->status_set_error();
return;
}
this->status_clear_error();
#endif
// re-apply duty
this->write_state(this->duty_);

View File

@@ -84,18 +84,18 @@ ClimateTraits AirConditioner::traits() {
traits.set_supported_custom_presets(this->supported_custom_presets_);
traits.set_supported_custom_fan_modes(this->supported_custom_fan_modes_);
/* + MINIMAL SET OF CAPABILITIES */
traits.add_supported_mode(ClimateMode::CLIMATE_MODE_OFF);
traits.add_supported_mode(ClimateMode::CLIMATE_MODE_FAN_ONLY);
traits.add_supported_fan_mode(ClimateFanMode::CLIMATE_FAN_AUTO);
traits.add_supported_fan_mode(ClimateFanMode::CLIMATE_FAN_LOW);
traits.add_supported_fan_mode(ClimateFanMode::CLIMATE_FAN_MEDIUM);
traits.add_supported_fan_mode(ClimateFanMode::CLIMATE_FAN_HIGH);
traits.add_supported_swing_mode(ClimateSwingMode::CLIMATE_SWING_OFF);
traits.add_supported_swing_mode(ClimateSwingMode::CLIMATE_SWING_VERTICAL);
traits.add_supported_preset(ClimatePreset::CLIMATE_PRESET_NONE);
traits.add_supported_preset(ClimatePreset::CLIMATE_PRESET_SLEEP);
if (this->base_.getAutoconfStatus() == dudanov::midea::AUTOCONF_OK)
Converters::to_climate_traits(traits, this->base_.getCapabilities());
if (!traits.get_supported_modes().empty())
traits.add_supported_mode(ClimateMode::CLIMATE_MODE_OFF);
if (!traits.get_supported_swing_modes().empty())
traits.add_supported_swing_mode(ClimateSwingMode::CLIMATE_SWING_OFF);
if (!traits.get_supported_presets().empty())
traits.add_supported_preset(ClimatePreset::CLIMATE_PRESET_NONE);
return traits;
}

View File

@@ -1,6 +1,10 @@
#include "pid_autotuner.h"
#include "esphome/core/log.h"
#ifndef M_PI
#define M_PI 3.1415926535897932384626433
#endif
namespace esphome {
namespace pid {
@@ -73,7 +77,7 @@ PIDAutotuner::PIDAutotuneResult PIDAutotuner::update(float setpoint, float proce
}
if (!std::isnan(this->setpoint_) && this->setpoint_ != setpoint) {
ESP_LOGW(TAG, "Setpoint changed during autotune! The result will not be accurate!");
ESP_LOGW(TAG, "%s: Setpoint changed during autotune! The result will not be accurate!", this->id_.c_str());
}
this->setpoint_ = setpoint;
@@ -87,7 +91,7 @@ PIDAutotuner::PIDAutotuneResult PIDAutotuner::update(float setpoint, float proce
if (!this->frequency_detector_.has_enough_data() || !this->amplitude_detector_.has_enough_data()) {
// not enough data for calculation yet
ESP_LOGV(TAG, " Not enough data yet for aututuner");
ESP_LOGV(TAG, "%s: Not enough data yet for autotuner", this->id_.c_str());
return res;
}
@@ -97,12 +101,13 @@ PIDAutotuner::PIDAutotuneResult PIDAutotuner::update(float setpoint, float proce
// The frequency/amplitude is not fully accurate yet, try to wait
// until the fault clears, or terminate after a while anyway
if (zc_symmetrical) {
ESP_LOGVV(TAG, " ZC is not symmetrical");
ESP_LOGVV(TAG, "%s: ZC is not symmetrical", this->id_.c_str());
}
if (amplitude_convergent) {
ESP_LOGVV(TAG, " Amplitude is not convergent");
ESP_LOGVV(TAG, "%s: Amplitude is not convergent", this->id_.c_str());
}
uint32_t phase = this->relay_function_.phase_count;
ESP_LOGVV(TAG, "%s: >", this->id_.c_str());
ESP_LOGVV(TAG, " Phase %u, enough=%u", phase, enough_data_phase_);
if (this->enough_data_phase_ == 0) {
@@ -116,7 +121,7 @@ PIDAutotuner::PIDAutotuneResult PIDAutotuner::update(float setpoint, float proce
}
}
ESP_LOGI(TAG, "PID Autotune finished!");
ESP_LOGI(TAG, "%s: PID Autotune finished!", this->id_.c_str());
float osc_ampl = this->amplitude_detector_.get_mean_oscillation_amplitude();
float d = (this->relay_function_.output_positive - this->relay_function_.output_negative) / 2.0f;
@@ -131,12 +136,12 @@ PIDAutotuner::PIDAutotuneResult PIDAutotuner::update(float setpoint, float proce
return res;
}
void PIDAutotuner::dump_config() {
ESP_LOGI(TAG, "PID Autotune:");
if (this->state_ == AUTOTUNE_SUCCEEDED) {
ESP_LOGI(TAG, "%s: PID Autotune:", this->id_.c_str());
ESP_LOGI(TAG, " State: Succeeded!");
bool has_issue = false;
if (!this->amplitude_detector_.is_amplitude_convergent()) {
ESP_LOGW(TAG, " Could not reliable determine oscillation amplitude, PID parameters may be inaccurate!");
ESP_LOGW(TAG, " Could not reliably determine oscillation amplitude, PID parameters may be inaccurate!");
ESP_LOGW(TAG, " Please make sure you eliminate all outside influences on the measured temperature.");
has_issue = true;
}
@@ -173,10 +178,12 @@ void PIDAutotuner::dump_config() {
print_rule_("Pessen Integral PID", 0.7f, 1.75f, 0.105f);
print_rule_("Some Overshoot PID", 0.333f, 0.667f, 0.111f);
print_rule_("No Overshoot PID", 0.2f, 0.4f, 0.0625f);
ESP_LOGI(TAG, "%s: Autotune completed", this->id_.c_str());
}
if (this->state_ == AUTOTUNE_RUNNING) {
ESP_LOGI(TAG, " Autotune is still running!");
ESP_LOGD(TAG, "%s: PID Autotune:", this->id_.c_str());
ESP_LOGD(TAG, " Autotune is still running!");
ESP_LOGD(TAG, " Status: Trying to reach %.2f °C", setpoint_ - relay_function_.current_target_error());
ESP_LOGD(TAG, " Stats so far:");
ESP_LOGD(TAG, " Phases: %u", relay_function_.phase_count);
@@ -221,7 +228,6 @@ float PIDAutotuner::RelayFunction::update(float error) {
float output = state == RELAY_FUNCTION_POSITIVE ? output_positive : output_negative;
if (change) {
this->phase_count++;
ESP_LOGV(TAG, "Autotune: Turning output to %.1f%%", output * 100);
}
return output;
@@ -245,10 +251,8 @@ void PIDAutotuner::OscillationFrequencyDetector::update(uint32_t now, float erro
if (had_crossing) {
// Had crossing above hysteresis threshold, record
ESP_LOGV(TAG, "Autotune: Detected Zero-Cross at %u", now);
if (this->last_zerocross != 0) {
uint32_t dt = now - this->last_zerocross;
ESP_LOGV(TAG, " dt: %u", dt);
this->zerocrossing_intervals.push_back(dt);
}
this->last_zerocross = now;
@@ -297,13 +301,11 @@ void PIDAutotuner::OscillationAmplitudeDetector::update(float error,
// The positive error peak must have been in previous segment (180° shifted)
// record phase_max
this->phase_maxs.push_back(phase_max);
ESP_LOGV(TAG, "Autotune: Phase Max: %f", phase_max);
} else if (last_relay_state == RelayFunction::RELAY_FUNCTION_NEGATIVE) {
// Transitioned from negative error to positive error.
// The negative error peak must have been in previous segment (180° shifted)
// record phase_min
this->phase_mins.push_back(phase_min);
ESP_LOGV(TAG, "Autotune: Phase Min: %f", phase_min);
}
// reset phase values for next phase
this->phase_min = error;

View File

@@ -31,6 +31,8 @@ class PIDAutotuner {
void dump_config();
void set_autotuner_id(std::string id) { this->id_ = std::move(id); }
void set_noiseband(float noiseband) {
relay_function_.noiseband = noiseband;
// ZC detector uses 1/4 the noiseband of relay function (noise suppression)
@@ -106,6 +108,7 @@ class PIDAutotuner {
} state_ = AUTOTUNE_RUNNING;
float ku_;
float pu_;
std::string id_;
};
} // namespace pid

View File

@@ -130,9 +130,6 @@ void PIDClimate::update_pid_() {
// keep autotuner instance so that subsequent dump_configs will print the long result message.
} else {
value = res.output;
if (mode != climate::CLIMATE_MODE_HEAT_COOL) {
ESP_LOGW(TAG, "For PID autotuner you need to set AUTO (also called heat/cool) mode!");
}
}
}
}
@@ -151,10 +148,24 @@ void PIDClimate::start_autotune(std::unique_ptr<PIDAutotuner> &&autotune) {
float min_value = this->supports_cool_() ? -1.0f : 0.0f;
float max_value = this->supports_heat_() ? 1.0f : 0.0f;
this->autotuner_->config(min_value, max_value);
this->autotuner_->set_autotuner_id(this->get_object_id());
ESP_LOGI(TAG,
"%s: Autotune has started. This can take a long time depending on the "
"responsiveness of your system. Your system "
"output will be altered to deliberately oscillate above and below the setpoint multiple times. "
"Until your sensor provides a reading, the autotuner may display \'nan\'",
this->get_object_id().c_str());
this->set_interval("autotune-progress", 10000, [this]() {
if (this->autotuner_ != nullptr && !this->autotuner_->is_finished())
this->autotuner_->dump_config();
});
if (mode != climate::CLIMATE_MODE_HEAT_COOL) {
ESP_LOGW(TAG, "%s: !!! For PID autotuner you need to set AUTO (also called heat/cool) mode!",
this->get_object_id().c_str());
}
}
void PIDClimate::reset_integral_term() { this->controller_.reset_accumulated_integral(); }

View File

@@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2023.2.0b1"
__version__ = "2023.2.0"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"

View File

@@ -545,6 +545,14 @@ class DownloadBinaryRequestHandler(BaseHandler):
self.finish()
class EsphomeVersionHandler(BaseHandler):
@authenticated
def get(self):
self.set_header("Content-Type", "application/json")
self.write(json.dumps({"version": const.__version__}))
self.finish()
def _list_dashboard_entries():
files = settings.list_yaml_files()
return [DashboardEntry(file) for file in files]
@@ -1000,8 +1008,14 @@ class SafeLoaderIgnoreUnknown(yaml.SafeLoader):
def ignore_unknown(self, node):
return f"{node.tag} {node.value}"
def construct_yaml_binary(self, node) -> str:
return super().construct_yaml_binary(node).decode("ascii")
SafeLoaderIgnoreUnknown.add_constructor(None, SafeLoaderIgnoreUnknown.ignore_unknown)
SafeLoaderIgnoreUnknown.add_constructor(
"tag:yaml.org,2002:binary", SafeLoaderIgnoreUnknown.construct_yaml_binary
)
class JsonConfigRequestHandler(BaseHandler):
@@ -1135,6 +1149,7 @@ def make_app(debug=get_bool_env(ENV_DEV)):
(f"{rel}rename", EsphomeRenameHandler),
(f"{rel}prometheus-sd", PrometheusServiceDiscoveryHandler),
(f"{rel}boards/([a-z0-9]+)", BoardsRequestHandler),
(f"{rel}version", EsphomeVersionHandler),
],
**app_settings,
)

View File

@@ -9,7 +9,7 @@ pyserial==3.5
platformio==6.1.5 # When updating platformio, also update Dockerfile
esptool==4.4
click==8.1.3
esphome-dashboard==20230120.0
esphome-dashboard==20230214.0
aioesphomeapi==13.1.0
zeroconf==0.47.1