mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 02:58:11 +01:00
commit
b914d6e305
12 changed files with 79 additions and 29 deletions
|
@ -32,8 +32,8 @@ static const int32_t SOC_ADC_RTC_MAX_BITWIDTH = 12;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const int32_t ADC_MAX = (1 << SOC_ADC_RTC_MAX_BITWIDTH) - 1; // 4095 (12 bit) or 8191 (13 bit)
|
static const int ADC_MAX = (1 << SOC_ADC_RTC_MAX_BITWIDTH) - 1; // 4095 (12 bit) or 8191 (13 bit)
|
||||||
static const int32_t ADC_HALF = (1 << SOC_ADC_RTC_MAX_BITWIDTH) >> 1; // 2048 (12 bit) or 4096 (13 bit)
|
static const int ADC_HALF = (1 << SOC_ADC_RTC_MAX_BITWIDTH) >> 1; // 2048 (12 bit) or 4096 (13 bit)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_RP2040
|
#ifdef USE_RP2040
|
||||||
|
@ -59,7 +59,7 @@ extern "C"
|
||||||
}
|
}
|
||||||
|
|
||||||
// load characteristics for each attenuation
|
// load characteristics for each attenuation
|
||||||
for (int32_t i = 0; i < (int32_t) ADC_ATTEN_MAX; i++) {
|
for (int32_t i = 0; i <= ADC_ATTEN_DB_11; i++) {
|
||||||
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
||||||
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
||||||
1100, // default vref
|
1100, // default vref
|
||||||
|
@ -157,7 +157,7 @@ float ADCSensor::sample() {
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
float ADCSensor::sample() {
|
float ADCSensor::sample() {
|
||||||
if (!autorange_) {
|
if (!autorange_) {
|
||||||
int32_t raw = -1;
|
int raw = -1;
|
||||||
if (channel1_ != ADC1_CHANNEL_MAX) {
|
if (channel1_ != ADC1_CHANNEL_MAX) {
|
||||||
raw = adc1_get_raw(channel1_);
|
raw = adc1_get_raw(channel1_);
|
||||||
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
||||||
|
@ -174,7 +174,7 @@ float ADCSensor::sample() {
|
||||||
return mv / 1000.0f;
|
return mv / 1000.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raw11 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
int raw11 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
||||||
|
|
||||||
if (channel1_ != ADC1_CHANNEL_MAX) {
|
if (channel1_ != ADC1_CHANNEL_MAX) {
|
||||||
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_11);
|
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_11);
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
|
||||||
adc1_channel_t channel1_{ADC1_CHANNEL_MAX};
|
adc1_channel_t channel1_{ADC1_CHANNEL_MAX};
|
||||||
adc2_channel_t channel2_{ADC2_CHANNEL_MAX};
|
adc2_channel_t channel2_{ADC2_CHANNEL_MAX};
|
||||||
bool autorange_{false};
|
bool autorange_{false};
|
||||||
esp_adc_cal_characteristics_t cal_characteristics_[(int32_t) ADC_ATTEN_MAX] = {};
|
esp_adc_cal_characteristics_t cal_characteristics_[ADC_ATTEN_MAX] = {};
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.Optional(CONF_IBEACON_MINOR): cv.uint16_t,
|
cv.Optional(CONF_IBEACON_MINOR): cv.uint16_t,
|
||||||
cv.Optional(CONF_IBEACON_UUID): cv.uuid,
|
cv.Optional(CONF_IBEACON_UUID): cv.uuid,
|
||||||
cv.Optional(CONF_MIN_RSSI): cv.All(
|
cv.Optional(CONF_MIN_RSSI): cv.All(
|
||||||
cv.decibel, cv.int_range(min=-90, max=-30)
|
cv.decibel, cv.int_range(min=-100, max=-30)
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -51,7 +51,7 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
|
||||||
this->found_ = false;
|
this->found_ = false;
|
||||||
}
|
}
|
||||||
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override {
|
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override {
|
||||||
if (this->check_minimum_rssi_ && this->minimum_rssi_ <= device.get_rssi()) {
|
if (this->check_minimum_rssi_ && this->minimum_rssi_ > device.get_rssi()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (this->match_by_) {
|
switch (this->match_by_) {
|
||||||
|
|
|
@ -263,6 +263,7 @@ async def to_code(config):
|
||||||
# Match arduino CONFIG_BTU_TASK_STACK_SIZE
|
# Match arduino CONFIG_BTU_TASK_STACK_SIZE
|
||||||
# https://github.com/espressif/arduino-esp32/blob/fd72cf46ad6fc1a6de99c1d83ba8eba17d80a4ee/tools/sdk/esp32/sdkconfig#L1866
|
# https://github.com/espressif/arduino-esp32/blob/fd72cf46ad6fc1a6de99c1d83ba8eba17d80a4ee/tools/sdk/esp32/sdkconfig#L1866
|
||||||
add_idf_sdkconfig_option("CONFIG_BTU_TASK_STACK_SIZE", 8192)
|
add_idf_sdkconfig_option("CONFIG_BTU_TASK_STACK_SIZE", 8192)
|
||||||
|
add_idf_sdkconfig_option("CONFIG_BT_ACL_CONNECTIONS", 9)
|
||||||
|
|
||||||
cg.add_define("USE_OTA_STATE_CALLBACK") # To be notified when an OTA update starts
|
cg.add_define("USE_OTA_STATE_CALLBACK") # To be notified when an OTA update starts
|
||||||
cg.add_define("USE_ESP32_BLE_CLIENT")
|
cg.add_define("USE_ESP32_BLE_CLIENT")
|
||||||
|
|
|
@ -12,7 +12,7 @@ void HomeassistantSensor::setup() {
|
||||||
this->entity_id_, this->attribute_, [this](const std::string &state) {
|
this->entity_id_, this->attribute_, [this](const std::string &state) {
|
||||||
auto val = parse_number<float>(state);
|
auto val = parse_number<float>(state);
|
||||||
if (!val.has_value()) {
|
if (!val.has_value()) {
|
||||||
ESP_LOGW(TAG, "Can't convert '%s' to number!", state.c_str());
|
ESP_LOGW(TAG, "'%s': Can't convert '%s' to number!", this->entity_id_.c_str(), state.c_str());
|
||||||
this->publish_state(NAN);
|
this->publish_state(NAN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ void TemplateSwitch::write_state(bool state) {
|
||||||
void TemplateSwitch::set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
|
void TemplateSwitch::set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
|
||||||
bool TemplateSwitch::assumed_state() { return this->assumed_state_; }
|
bool TemplateSwitch::assumed_state() { return this->assumed_state_; }
|
||||||
void TemplateSwitch::set_state_lambda(std::function<optional<bool>()> &&f) { this->f_ = f; }
|
void TemplateSwitch::set_state_lambda(std::function<optional<bool>()> &&f) { this->f_ = f; }
|
||||||
float TemplateSwitch::get_setup_priority() const { return setup_priority::HARDWARE; }
|
float TemplateSwitch::get_setup_priority() const { return setup_priority::HARDWARE - 2.0f; }
|
||||||
Trigger<> *TemplateSwitch::get_turn_on_trigger() const { return this->turn_on_trigger_; }
|
Trigger<> *TemplateSwitch::get_turn_on_trigger() const { return this->turn_on_trigger_; }
|
||||||
Trigger<> *TemplateSwitch::get_turn_off_trigger() const { return this->turn_off_trigger_; }
|
Trigger<> *TemplateSwitch::get_turn_off_trigger() const { return this->turn_off_trigger_; }
|
||||||
void TemplateSwitch::setup() {
|
void TemplateSwitch::setup() {
|
||||||
|
|
|
@ -1492,11 +1492,10 @@ void WaveshareEPaper7P5InV2alt::initialize() {
|
||||||
this->command(0x01);
|
this->command(0x01);
|
||||||
|
|
||||||
// 1-0=11: internal power
|
// 1-0=11: internal power
|
||||||
this->data(0x17);
|
this->data(0x07);
|
||||||
|
|
||||||
this->data(0x17); // VGH&VGL
|
this->data(0x17); // VGH&VGL
|
||||||
this->data(0x3F); // VSH
|
this->data(0x3F); // VSH
|
||||||
this->data(0x3F); // VSL
|
this->data(0x26); // VSL
|
||||||
this->data(0x11); // VSHR
|
this->data(0x11); // VSHR
|
||||||
|
|
||||||
// VCOM DC Setting
|
// VCOM DC Setting
|
||||||
|
@ -1510,10 +1509,6 @@ void WaveshareEPaper7P5InV2alt::initialize() {
|
||||||
this->data(0x2F);
|
this->data(0x2F);
|
||||||
this->data(0x17);
|
this->data(0x17);
|
||||||
|
|
||||||
// OSC Setting
|
|
||||||
this->command(0x30);
|
|
||||||
this->data(0x06); // 2-0=100: N=4 ; 5-3=111: M=7 ; 3C=50Hz 3A=100HZ
|
|
||||||
|
|
||||||
// POWER ON
|
// POWER ON
|
||||||
this->command(0x04);
|
this->command(0x04);
|
||||||
|
|
||||||
|
@ -1535,7 +1530,7 @@ void WaveshareEPaper7P5InV2alt::initialize() {
|
||||||
// COMMAND VCOM AND DATA INTERVAL SETTING
|
// COMMAND VCOM AND DATA INTERVAL SETTING
|
||||||
this->command(0x50);
|
this->command(0x50);
|
||||||
this->data(0x10);
|
this->data(0x10);
|
||||||
this->data(0x07);
|
this->data(0x00);
|
||||||
// COMMAND TCON SETTING
|
// COMMAND TCON SETTING
|
||||||
this->command(0x60);
|
this->command(0x60);
|
||||||
this->data(0x22);
|
this->data(0x22);
|
||||||
|
|
|
@ -569,6 +569,8 @@ const char *get_disconnect_reason_str(uint8_t reason) {
|
||||||
return "Handshake Failed";
|
return "Handshake Failed";
|
||||||
case WIFI_REASON_CONNECTION_FAIL:
|
case WIFI_REASON_CONNECTION_FAIL:
|
||||||
return "Connection Failed";
|
return "Connection Failed";
|
||||||
|
case WIFI_REASON_ROAMING:
|
||||||
|
return "Station Roaming";
|
||||||
case WIFI_REASON_UNSPECIFIED:
|
case WIFI_REASON_UNSPECIFIED:
|
||||||
default:
|
default:
|
||||||
return "Unspecified";
|
return "Unspecified";
|
||||||
|
@ -631,7 +633,9 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
||||||
if (it.reason == WIFI_REASON_NO_AP_FOUND) {
|
if (it.reason == WIFI_REASON_NO_AP_FOUND) {
|
||||||
ESP_LOGW(TAG, "Event: Disconnected ssid='%s' reason='Probe Request Unsuccessful'", buf);
|
ESP_LOGW(TAG, "Event: Disconnected ssid='%s' reason='Probe Request Unsuccessful'", buf);
|
||||||
s_sta_connect_not_found = true;
|
s_sta_connect_not_found = true;
|
||||||
|
} else if (it.reason == WIFI_REASON_ROAMING) {
|
||||||
|
ESP_LOGI(TAG, "Event: Disconnected ssid='%s' reason='Station Roaming'", buf);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "Event: Disconnected ssid='%s' bssid=" LOG_SECRET("%s") " reason='%s'", buf,
|
ESP_LOGW(TAG, "Event: Disconnected ssid='%s' bssid=" LOG_SECRET("%s") " reason='%s'", buf,
|
||||||
format_mac_addr(it.bssid).c_str(), get_disconnect_reason_str(it.reason));
|
format_mac_addr(it.bssid).c_str(), get_disconnect_reason_str(it.reason));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2023.7.0"
|
__version__ = "2023.7.1"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|
|
@ -25,6 +25,7 @@ import tornado.ioloop
|
||||||
import tornado.iostream
|
import tornado.iostream
|
||||||
import tornado.netutil
|
import tornado.netutil
|
||||||
import tornado.process
|
import tornado.process
|
||||||
|
import tornado.queues
|
||||||
import tornado.web
|
import tornado.web
|
||||||
import tornado.websocket
|
import tornado.websocket
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -202,7 +203,11 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||||
def __init__(self, application, request, **kwargs):
|
def __init__(self, application, request, **kwargs):
|
||||||
super().__init__(application, request, **kwargs)
|
super().__init__(application, request, **kwargs)
|
||||||
self._proc = None
|
self._proc = None
|
||||||
|
self._queue = None
|
||||||
self._is_closed = False
|
self._is_closed = False
|
||||||
|
# Windows doesn't support non-blocking pipes,
|
||||||
|
# use Popen() with a reading thread instead
|
||||||
|
self._use_popen = os.name == "nt"
|
||||||
|
|
||||||
@authenticated
|
@authenticated
|
||||||
def on_message(self, message):
|
def on_message(self, message):
|
||||||
|
@ -224,13 +229,28 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||||
return
|
return
|
||||||
command = self.build_command(json_message)
|
command = self.build_command(json_message)
|
||||||
_LOGGER.info("Running command '%s'", " ".join(shlex_quote(x) for x in command))
|
_LOGGER.info("Running command '%s'", " ".join(shlex_quote(x) for x in command))
|
||||||
self._proc = tornado.process.Subprocess(
|
|
||||||
command,
|
if self._use_popen:
|
||||||
stdout=tornado.process.Subprocess.STREAM,
|
self._queue = tornado.queues.Queue()
|
||||||
stderr=subprocess.STDOUT,
|
# pylint: disable=consider-using-with
|
||||||
stdin=tornado.process.Subprocess.STREAM,
|
self._proc = subprocess.Popen(
|
||||||
)
|
command,
|
||||||
self._proc.set_exit_callback(self._proc_on_exit)
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
)
|
||||||
|
stdout_thread = threading.Thread(target=self._stdout_thread)
|
||||||
|
stdout_thread.daemon = True
|
||||||
|
stdout_thread.start()
|
||||||
|
else:
|
||||||
|
self._proc = tornado.process.Subprocess(
|
||||||
|
command,
|
||||||
|
stdout=tornado.process.Subprocess.STREAM,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
stdin=tornado.process.Subprocess.STREAM,
|
||||||
|
)
|
||||||
|
self._proc.set_exit_callback(self._proc_on_exit)
|
||||||
|
|
||||||
tornado.ioloop.IOLoop.current().spawn_callback(self._redirect_stdout)
|
tornado.ioloop.IOLoop.current().spawn_callback(self._redirect_stdout)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -252,7 +272,13 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
data = yield self._proc.stdout.read_until_regex(reg)
|
if self._use_popen:
|
||||||
|
data = yield self._queue.get()
|
||||||
|
if data is None:
|
||||||
|
self._proc_on_exit(self._proc.poll())
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
data = yield self._proc.stdout.read_until_regex(reg)
|
||||||
except tornado.iostream.StreamClosedError:
|
except tornado.iostream.StreamClosedError:
|
||||||
break
|
break
|
||||||
data = codecs.decode(data, "utf8", "replace")
|
data = codecs.decode(data, "utf8", "replace")
|
||||||
|
@ -260,6 +286,19 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||||
_LOGGER.debug("> stdout: %s", data)
|
_LOGGER.debug("> stdout: %s", data)
|
||||||
self.write_message({"event": "line", "data": data})
|
self.write_message({"event": "line", "data": data})
|
||||||
|
|
||||||
|
def _stdout_thread(self):
|
||||||
|
if not self._use_popen:
|
||||||
|
return
|
||||||
|
while True:
|
||||||
|
data = self._proc.stdout.readline()
|
||||||
|
if data:
|
||||||
|
data = data.replace(b"\r", b"")
|
||||||
|
self._queue.put_nowait(data)
|
||||||
|
if self._proc.poll() is not None:
|
||||||
|
break
|
||||||
|
self._proc.wait(1.0)
|
||||||
|
self._queue.put_nowait(None)
|
||||||
|
|
||||||
def _proc_on_exit(self, returncode):
|
def _proc_on_exit(self, returncode):
|
||||||
if not self._is_closed:
|
if not self._is_closed:
|
||||||
# Check if the proc was not forcibly closed
|
# Check if the proc was not forcibly closed
|
||||||
|
@ -270,7 +309,10 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
|
||||||
# Check if proc exists (if 'start' has been run)
|
# Check if proc exists (if 'start' has been run)
|
||||||
if self.is_process_active:
|
if self.is_process_active:
|
||||||
_LOGGER.debug("Terminating process")
|
_LOGGER.debug("Terminating process")
|
||||||
self._proc.proc.terminate()
|
if self._use_popen:
|
||||||
|
self._proc.terminate()
|
||||||
|
else:
|
||||||
|
self._proc.proc.terminate()
|
||||||
# Shutdown proc on WS close
|
# Shutdown proc on WS close
|
||||||
self._is_closed = True
|
self._is_closed = True
|
||||||
|
|
||||||
|
|
|
@ -31,3 +31,11 @@ logger:
|
||||||
http_request:
|
http_request:
|
||||||
useragent: esphome/tagreader
|
useragent: esphome/tagreader
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: adc
|
||||||
|
id: adc_sensor_p4
|
||||||
|
name: ADC pin 4
|
||||||
|
pin: 4
|
||||||
|
attenuation: 11db
|
||||||
|
update_interval: 1s
|
||||||
|
|
Loading…
Reference in a new issue