mirror of
https://github.com/esphome/esphome.git
synced 2026-11-16 01:55:59 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1edffa1813 | ||
|
|
07bbad4061 | ||
|
|
1cd99ce6d6 | ||
|
|
91db9d86d0 |
No files matched your search
@@ -96,7 +96,7 @@ void AHT10Component::read_data_() {
|
||||
this->restart_read_();
|
||||
return;
|
||||
}
|
||||
if (data[1] == 0x0 && data[2] == 0x0 && high_nibble(data[3]) == 0x0) {
|
||||
if (data[1] == 0x0 && data[2] == 0x0 && (data[3] >> 4) == 0x0) {
|
||||
// Invalid humidity (0x0)
|
||||
if (this->humidity_sensor_ == nullptr) {
|
||||
ESP_LOGV(TAG, "Invalid humidity (reading not required)");
|
||||
@@ -110,7 +110,7 @@ void AHT10Component::read_data_() {
|
||||
if (this->read_count_ > 1) {
|
||||
ESP_LOGD(TAG, "Success at %ums", (unsigned) (millis() - this->start_time_));
|
||||
}
|
||||
uint32_t raw_temperature = encode_uint24(low_nibble(data[3]), data[4], data[5]);
|
||||
uint32_t raw_temperature = encode_uint24(data[3] & 0xF, data[4], data[5]);
|
||||
uint32_t raw_humidity = encode_uint24(data[1], data[2], data[3]) >> 4;
|
||||
|
||||
PUBLISH_STATE(this->temperature_sensor_, ((200.0f * static_cast<float>(raw_temperature)) / AHT10_DIVISOR) - 50.0f);
|
||||
|
||||
@@ -62,9 +62,9 @@ bool AM2315C::reset_register_(uint8_t reg) {
|
||||
|
||||
bool AM2315C::convert_(uint8_t *data, float &humidity, float &temperature) {
|
||||
uint32_t raw;
|
||||
raw = encode_uint24(data[1], data[2], data[3]) >> 4;
|
||||
raw = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
|
||||
humidity = raw * 9.5367431640625e-5;
|
||||
raw = encode_uint24(low_nibble(data[3]), data[4], data[5]);
|
||||
raw = encode_uint24(data[3] & 0x0F, data[4], data[5]);
|
||||
temperature = raw * 1.9073486328125e-4 - 50;
|
||||
return crc8(data, 6, 0xFF, 0x31, true) == data[6];
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ void AXS15231Touchscreen::update_touches() {
|
||||
this->status_clear_warning();
|
||||
if (data[0] != 0 || data[1] == 0) // no touches
|
||||
return;
|
||||
uint16_t x = encode_uint16(low_nibble(data[2]), data[3]);
|
||||
uint16_t y = encode_uint16(low_nibble(data[4]), data[5]);
|
||||
uint16_t x = encode_uint16(data[2] & 0xF, data[3]);
|
||||
uint16_t y = encode_uint16(data[4] & 0xF, data[5]);
|
||||
this->add_raw_touch_position_(0, x, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,10 +114,10 @@ void BME280Component::setup() {
|
||||
this->calibration_.h1 = read_u8_(BME280_REGISTER_DIG_H1);
|
||||
this->calibration_.h2 = read_s16_le_(BME280_REGISTER_DIG_H2);
|
||||
this->calibration_.h3 = read_u8_(BME280_REGISTER_DIG_H3);
|
||||
this->calibration_.h4 = sign_extend<12>(
|
||||
encode_uint12(read_u8_(BME280_REGISTER_DIG_H4), low_nibble(read_u8_(BME280_REGISTER_DIG_H4 + 1))));
|
||||
this->calibration_.h5 = sign_extend<12>(
|
||||
encode_uint12(read_u8_(BME280_REGISTER_DIG_H5 + 1), high_nibble(read_u8_(BME280_REGISTER_DIG_H5))));
|
||||
this->calibration_.h4 =
|
||||
sign_extend<12>(read_u8_(BME280_REGISTER_DIG_H4) << 4 | (read_u8_(BME280_REGISTER_DIG_H4 + 1) & 0x0F));
|
||||
this->calibration_.h5 =
|
||||
sign_extend<12>(read_u8_(BME280_REGISTER_DIG_H5 + 1) << 4 | (read_u8_(BME280_REGISTER_DIG_H5) >> 4));
|
||||
this->calibration_.h6 = read_u8_(BME280_REGISTER_DIG_H6);
|
||||
|
||||
uint8_t humid_control_val = 0;
|
||||
|
||||
@@ -70,9 +70,8 @@ bool BME680Component::setup_registers_() {
|
||||
this->calibration_.t2 = encode_value_le<int16_t>(&coeff1[1]);
|
||||
this->calibration_.t3 = coeff1[3];
|
||||
|
||||
// H1 and H2 are 12-bit values sharing byte 1: its low nibble ends H1, its high nibble ends H2
|
||||
this->calibration_.h1 = encode_uint12(coeff2[2], low_nibble(coeff2[1]));
|
||||
this->calibration_.h2 = encode_uint12(coeff2[0], high_nibble(coeff2[1]));
|
||||
this->calibration_.h1 = coeff2[2] << 4 | (coeff2[1] & 0x0F);
|
||||
this->calibration_.h2 = encode_uint16(coeff2[0], coeff2[1]) >> 4;
|
||||
this->calibration_.h3 = coeff2[3];
|
||||
this->calibration_.h4 = coeff2[4];
|
||||
this->calibration_.h5 = coeff2[5];
|
||||
@@ -244,7 +243,7 @@ void BME680Component::read_data_() {
|
||||
uint32_t raw_pressure = encode_uint24(data[2], data[3], data[4]) >> 4;
|
||||
uint32_t raw_humidity = encode_uint16(data[8], data[9]);
|
||||
uint16_t raw_gas = encode_uint16(data[13], data[14]) >> 6;
|
||||
uint8_t gas_range = low_nibble(data[14]);
|
||||
uint8_t gas_range = data[14] & 0x0F;
|
||||
|
||||
float temperature = this->calc_temperature_(raw_temperature);
|
||||
float pressure = this->calc_pressure_(raw_pressure);
|
||||
|
||||
@@ -68,7 +68,7 @@ void CST3240Touchscreen::update_touches() {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t count = low_nibble(data[cstxxx::FINGER_COUNT_IDX]);
|
||||
const uint8_t count = data[cstxxx::FINGER_COUNT_IDX] & 0x0F;
|
||||
if (count <= CST3240_MAX_TOUCHES) {
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
auto touch = cstxxx::decode_touch(data, i);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "cst328_touchscreen.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::cst328 {
|
||||
@@ -100,7 +99,7 @@ void CST328Touchscreen::update_touches() {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t touch_cnt = low_nibble(touch_data[CST_REG_FINGER_COUNT_IDX]);
|
||||
uint8_t touch_cnt = touch_data[CST_REG_FINGER_COUNT_IDX] & 0x0F;
|
||||
if (touch_cnt == 0 || touch_cnt > CST328_TOUCH_MAX_POINTS) {
|
||||
this->update_button_state_(false);
|
||||
} else {
|
||||
|
||||
@@ -68,8 +68,8 @@ void CST816Touchscreen::update_touches() {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t x = encode_uint16(low_nibble(data[REG_XPOS_HIGH]), data[REG_XPOS_LOW]);
|
||||
uint16_t y = encode_uint16(low_nibble(data[REG_YPOS_HIGH]), data[REG_YPOS_LOW]);
|
||||
uint16_t x = encode_uint16(data[REG_XPOS_HIGH] & 0xF, data[REG_XPOS_LOW]);
|
||||
uint16_t y = encode_uint16(data[REG_YPOS_HIGH] & 0xF, data[REG_YPOS_LOW]);
|
||||
ESP_LOGV(TAG, "Read touch %d/%d", x, y);
|
||||
this->add_raw_touch_position_(0, x, y);
|
||||
}
|
||||
|
||||
@@ -37,18 +37,11 @@ struct TouchRecord {
|
||||
uint8_t z;
|
||||
};
|
||||
|
||||
/// Decodes record `index` of a touch report. Each record is 5 bytes:
|
||||
/// [id:4 | event:4] [x 11..4] [y 11..4] [x 3..0 | y 3..0] [z].
|
||||
/// The first record is followed by 2 extra bytes, so later records start 2 bytes further on.
|
||||
/// Decodes record `index` of a touch report.
|
||||
inline TouchRecord decode_touch(const uint8_t *report, uint8_t index) {
|
||||
const uint8_t *r = report + index * 5 + (index == 0 ? 0 : 2);
|
||||
return {
|
||||
.id = high_nibble(r[0]),
|
||||
.event = low_nibble(r[0]),
|
||||
.x = encode_uint12(r[1], high_nibble(r[3])),
|
||||
.y = encode_uint12(r[2], low_nibble(r[3])),
|
||||
.z = r[4],
|
||||
};
|
||||
return {static_cast<uint8_t>(r[0] >> 4), static_cast<uint8_t>(r[0] & 0x0F),
|
||||
static_cast<uint16_t>(r[1] << 4 | r[3] >> 4), static_cast<uint16_t>(r[2] << 4 | (r[3] & 0x0F)), r[4]};
|
||||
}
|
||||
|
||||
class CSTTouchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import logger
|
||||
from esphome.components.nrf52.framework import include_west_project
|
||||
from esphome.components.zephyr import zephyr_add_prj_conf
|
||||
from esphome.config_helpers import filter_source_files_from_platform
|
||||
import esphome.config_validation as cv
|
||||
@@ -53,6 +52,9 @@ CONFIG_SCHEMA = cv.All(
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
if CORE.using_zephyr:
|
||||
# Imported here so configs for other platforms do not load the nrf52 package
|
||||
from esphome.components.nrf52.framework import include_west_project
|
||||
|
||||
zephyr_add_prj_conf("HWINFO", True)
|
||||
# gdb thread support
|
||||
zephyr_add_prj_conf("DEBUG_THREAD_INFO", True)
|
||||
|
||||
@@ -35,12 +35,12 @@ void EKTF2232Touchscreen::setup() {
|
||||
if (err == i2c::ERROR_OK) {
|
||||
err = this->read(received, 4);
|
||||
if (err == i2c::ERROR_OK) {
|
||||
this->x_raw_max_ = encode_uint16(high_nibble(received[3]), received[2]);
|
||||
this->x_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
|
||||
err = this->write(GET_Y_RES, 4);
|
||||
if (err == i2c::ERROR_OK) {
|
||||
err = this->read(received, 4);
|
||||
if (err == i2c::ERROR_OK) {
|
||||
this->y_raw_max_ = encode_uint16(high_nibble(received[3]), received[2]);
|
||||
this->y_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,9 +74,8 @@ void EKTF2232Touchscreen::update_touches() {
|
||||
|
||||
for (int i = 0; i < touch_count; i++) {
|
||||
uint8_t *d = raw + 1 + (i * 3);
|
||||
// d[0] holds the top 4 bits of X (high nibble) and of Y (low nibble)
|
||||
x_raw = encode_uint16(high_nibble(d[0]), d[1]);
|
||||
y_raw = encode_uint16(low_nibble(d[0]), d[2]);
|
||||
x_raw = (d[0] & 0xF0) << 4 | d[1];
|
||||
y_raw = (d[0] & 0x0F) << 8 | d[2];
|
||||
this->add_raw_touch_position_(i, x_raw, y_raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ from esphome.const import (
|
||||
from esphome.core import CORE, EsphomeError, HexInt
|
||||
from esphome.core.config import BOARD_MAX_LENGTH
|
||||
from esphome.coroutine import CoroPriority, coroutine_with_priority
|
||||
from esphome.espidf import sbom
|
||||
from esphome.espidf.component import IDFComponent, generate_idf_components
|
||||
import esphome.final_validate as fv
|
||||
from esphome.helpers import copy_file_if_changed, rmtree, write_file_if_changed
|
||||
@@ -4033,6 +4032,9 @@ def copy_files():
|
||||
CORE.relative_build_path("version.txt"),
|
||||
__version__,
|
||||
)
|
||||
# Imported here: sbom loads git and urllib helpers that config validation does not need
|
||||
from esphome.espidf import sbom
|
||||
|
||||
sbom.write_manifests()
|
||||
|
||||
# Remote extra build files are fetched into the shared download cache in
|
||||
|
||||
@@ -69,8 +69,8 @@ void FT5x06Touchscreen::update_touches() {
|
||||
for (uint8_t i = 0; i != touch_cnt; i++) {
|
||||
uint8_t status = data[i][0] >> 6;
|
||||
uint8_t id = data[i][2] >> 3;
|
||||
uint16_t x = encode_uint16(low_nibble(data[i][0]), data[i][1]);
|
||||
uint16_t y = encode_uint16(low_nibble(data[i][2]), data[i][3]);
|
||||
uint16_t x = encode_uint16(data[i][0] & 0x0F, data[i][1]);
|
||||
uint16_t y = encode_uint16(data[i][2] & 0xF, data[i][3]);
|
||||
|
||||
ESP_LOGV(TAG, "Read %X status, id: %d, pos %d/%d", status, id, x, y);
|
||||
if (status == 0 || status == 2) {
|
||||
|
||||
@@ -90,31 +90,31 @@ void FT63X6Touchscreen::update_touches() {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FT63X6Touchscreen::read_touch_number_() { return low_nibble(this->read_byte_(FT63X6_ADDR_TD_STATUS)); }
|
||||
uint8_t FT63X6Touchscreen::read_touch_number_() { return this->read_byte_(FT63X6_ADDR_TD_STATUS) & 0x0F; }
|
||||
// Touch 1 functions
|
||||
uint16_t FT63X6Touchscreen::read_touch_x_(uint8_t touch) {
|
||||
uint8_t read_buf[2];
|
||||
read_buf[0] = this->read_byte_(FT63X6_ADDR_TOUCH1_X + (touch * 6));
|
||||
read_buf[1] = this->read_byte_(FT63X6_ADDR_TOUCH1_X + 1 + (touch * 6));
|
||||
return encode_uint16(low_nibble(read_buf[0]), read_buf[1]);
|
||||
return encode_uint16(read_buf[0] & 0x0f, read_buf[1]);
|
||||
}
|
||||
uint16_t FT63X6Touchscreen::read_touch_y_(uint8_t touch) {
|
||||
uint8_t read_buf[2];
|
||||
read_buf[0] = this->read_byte_(FT63X6_ADDR_TOUCH1_Y + (touch * 6));
|
||||
read_buf[1] = this->read_byte_(FT63X6_ADDR_TOUCH1_Y + 1 + (touch * 6));
|
||||
return encode_uint16(low_nibble(read_buf[0]), read_buf[1]);
|
||||
return encode_uint16(read_buf[0] & 0x0f, read_buf[1]);
|
||||
}
|
||||
uint8_t FT63X6Touchscreen::read_touch_event_(uint8_t touch) {
|
||||
return this->read_byte_(FT63X6_ADDR_TOUCH1_X + (touch * 6)) >> 6;
|
||||
}
|
||||
uint8_t FT63X6Touchscreen::read_touch_id_(uint8_t touch) {
|
||||
return high_nibble(this->read_byte_(FT63X6_ADDR_TOUCH1_ID + (touch * 6)));
|
||||
return this->read_byte_(FT63X6_ADDR_TOUCH1_ID + (touch * 6)) >> 4;
|
||||
}
|
||||
uint8_t FT63X6Touchscreen::read_touch_weight_(uint8_t touch) {
|
||||
return this->read_byte_(FT63X6_ADDR_TOUCH1_WEIGHT + (touch * 6));
|
||||
}
|
||||
uint8_t FT63X6Touchscreen::read_touch_misc_(uint8_t touch) {
|
||||
return high_nibble(this->read_byte_(FT63X6_ADDR_TOUCH1_MISC + (touch * 6)));
|
||||
return this->read_byte_(FT63X6_ADDR_TOUCH1_MISC + (touch * 6)) >> 4;
|
||||
}
|
||||
|
||||
uint8_t FT63X6Touchscreen::read_byte_(uint8_t addr) {
|
||||
|
||||
@@ -347,26 +347,23 @@ bool FUSB302B::read_message_(PdMsg &msg, bool &is_sop) {
|
||||
bool FUSB302B::send_message(const PdMsg &msg) {
|
||||
// Register address, then the TX tokens; written in one transfer without the copy write_register() makes
|
||||
uint8_t buf[1 + 4 + 1 + 2 + PD_MAX_NUM_DATA_OBJECTS * 4 + 4];
|
||||
size_t len = 0;
|
||||
uint8_t *p = buf;
|
||||
|
||||
buf[len++] = FUSB_FIFOS;
|
||||
buf[len++] = FUSB_TX_TOKEN_SYNC1;
|
||||
buf[len++] = FUSB_TX_TOKEN_SYNC1;
|
||||
buf[len++] = FUSB_TX_TOKEN_SYNC1;
|
||||
buf[len++] = FUSB_TX_TOKEN_SYNC2;
|
||||
buf[len++] = FUSB_TX_TOKEN_PACKSYM | (msg.num_of_obj * 4 + 2);
|
||||
put_le16(buf + len, msg.get_coded_header());
|
||||
len += 2;
|
||||
for (uint8_t i = 0; i < msg.num_of_obj; i++) {
|
||||
put_le32(buf + len, msg.data_objects[i]);
|
||||
len += 4;
|
||||
}
|
||||
buf[len++] = FUSB_TX_TOKEN_JAM_CRC;
|
||||
buf[len++] = FUSB_TX_TOKEN_EOP;
|
||||
buf[len++] = FUSB_TX_TOKEN_TXOFF;
|
||||
buf[len++] = FUSB_TX_TOKEN_TXON;
|
||||
*p++ = FUSB_FIFOS;
|
||||
*p++ = FUSB_TX_TOKEN_SYNC1;
|
||||
*p++ = FUSB_TX_TOKEN_SYNC1;
|
||||
*p++ = FUSB_TX_TOKEN_SYNC1;
|
||||
*p++ = FUSB_TX_TOKEN_SYNC2;
|
||||
*p++ = FUSB_TX_TOKEN_PACKSYM | (msg.num_of_obj * 4 + 2);
|
||||
p = put_le16(p, msg.get_coded_header());
|
||||
for (uint8_t i = 0; i < msg.num_of_obj; i++)
|
||||
p = put_le32(p, msg.data_objects[i]);
|
||||
*p++ = FUSB_TX_TOKEN_JAM_CRC;
|
||||
*p++ = FUSB_TX_TOKEN_EOP;
|
||||
*p++ = FUSB_TX_TOKEN_TXOFF;
|
||||
*p++ = FUSB_TX_TOKEN_TXON;
|
||||
|
||||
i2c::ErrorCode err = this->write(buf, len);
|
||||
i2c::ErrorCode err = this->write(buf, p - buf);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
ESP_LOGW(TAG, "Sending message type %u failed (error %d)", msg.type, static_cast<int>(err));
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "gsl3670_touchscreen.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome::gsl3670 {
|
||||
|
||||
@@ -67,11 +66,10 @@ void GSL3670Touchscreen::update_touches() {
|
||||
|
||||
// Build gsl_touch_info exactly as the Seeed driver does
|
||||
for (uint8_t j = 0; j != finger_num; j++) {
|
||||
// Record: y_lo, y_hi, x_lo, then the id (high nibble) and the top 4 bits of X (low nibble)
|
||||
const uint8_t *record = &buf[(j + 1) * 4];
|
||||
auto x = encode_uint16(low_nibble(record[3]), record[2]);
|
||||
auto y = encode_uint16(record[1], record[0]);
|
||||
auto id = high_nibble(record[3]);
|
||||
// buf[(j+1)*4 + 0..3]: byte0=y_lo, byte1=y_hi, byte2=x_lo, byte3=id|x_hi
|
||||
auto x = (uint16_t) (((buf[(j + 1) * 4 + 3] & 0x0f) << 8) | buf[(j + 1) * 4 + 2]);
|
||||
auto y = (uint16_t) ((buf[(j + 1) * 4 + 1] << 8) | buf[(j + 1) * 4 + 0]);
|
||||
auto id = (buf[(j + 1) * 4 + 3] >> 4) & 0x0f;
|
||||
ESP_LOGV(TAG, "Touch id=%u, x=%u y=%u", id, x, y);
|
||||
if (x <= 8192 && y <= 8192)
|
||||
this->add_raw_touch_position_(id, x, y);
|
||||
|
||||
@@ -62,7 +62,7 @@ void LilygoT547Touchscreen::update_touches() {
|
||||
return;
|
||||
}
|
||||
|
||||
point = low_nibble(buffer[5]);
|
||||
point = buffer[5] & 0xF;
|
||||
if (point > 2) {
|
||||
ESP_LOGW(TAG, "Invalid touch point count: %d", point);
|
||||
point = 2;
|
||||
@@ -88,11 +88,9 @@ void LilygoT547Touchscreen::update_touches() {
|
||||
|
||||
uint16_t id, x_raw, y_raw;
|
||||
for (uint8_t i = 0; i < point; i++) {
|
||||
const uint8_t *record = buffer + i * 5;
|
||||
id = high_nibble(record[0]);
|
||||
// The low 4 bits of Y and X share byte 3
|
||||
y_raw = encode_uint12(record[1], high_nibble(record[3]));
|
||||
x_raw = encode_uint12(record[2], low_nibble(record[3]));
|
||||
id = (buffer[i * 5] >> 4) & 0x0F;
|
||||
y_raw = (uint16_t) ((buffer[i * 5 + 1] << 4) | ((buffer[i * 5 + 3] >> 4) & 0x0F));
|
||||
x_raw = (uint16_t) ((buffer[i * 5 + 2] << 4) | (buffer[i * 5 + 3] & 0x0F));
|
||||
this->add_raw_touch_position_(id, x_raw, y_raw);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "max44009.h"
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome::max44009 {
|
||||
@@ -81,8 +80,8 @@ float MAX44009Sensor::read_illuminance_() {
|
||||
}
|
||||
|
||||
float MAX44009Sensor::convert_to_lux_(uint8_t data_high, uint8_t data_low) {
|
||||
uint8_t exponent = high_nibble(data_high);
|
||||
uint32_t mantissa = (low_nibble(data_high) << 4) | low_nibble(data_low);
|
||||
uint8_t exponent = data_high >> 4;
|
||||
uint32_t mantissa = ((data_high & 0x0F) << 4) + (data_low & 0x0F);
|
||||
return ((0x0001 << exponent) * 0.045) * mantissa;
|
||||
}
|
||||
|
||||
|
||||
@@ -291,25 +291,21 @@ bool ShellyDimmer::send_command_(uint8_t cmd, const uint8_t *const payload, uint
|
||||
}
|
||||
|
||||
size_t ShellyDimmer::frame_command_(uint8_t *data, uint8_t cmd, const uint8_t *const payload, size_t len) {
|
||||
size_t pos = 0;
|
||||
|
||||
// Generate a frame.
|
||||
data[0] = SHELLY_DIMMER_PROTO_START_BYTE;
|
||||
data[1] = ++this->seq_;
|
||||
data[2] = cmd;
|
||||
data[3] = len;
|
||||
pos += 4;
|
||||
uint8_t *p = data;
|
||||
*p++ = SHELLY_DIMMER_PROTO_START_BYTE;
|
||||
*p++ = ++this->seq_;
|
||||
*p++ = cmd;
|
||||
*p++ = len;
|
||||
|
||||
if (payload != nullptr) {
|
||||
std::memcpy(data + 4, payload, len);
|
||||
pos += len;
|
||||
std::memcpy(p, payload, len);
|
||||
p += len;
|
||||
}
|
||||
|
||||
// Calculate checksum for the payload.
|
||||
put_be16(data + pos, shelly_dimmer_checksum(data + 1, 3 + len));
|
||||
pos += 2;
|
||||
data[pos++] = SHELLY_DIMMER_PROTO_END_BYTE;
|
||||
return pos;
|
||||
// Checksum over the sequence, command, length and payload bytes
|
||||
p = put_be16(p, shelly_dimmer_checksum(data + 1, 3 + len));
|
||||
*p++ = SHELLY_DIMMER_PROTO_END_BYTE;
|
||||
return p - data;
|
||||
}
|
||||
|
||||
int ShellyDimmer::handle_byte_(uint8_t c) {
|
||||
|
||||
@@ -176,8 +176,8 @@ bool SPD2010Touchscreen::read_data_() {
|
||||
// Zero strength marks a released contact.
|
||||
if (contact[4] == 0)
|
||||
continue;
|
||||
const uint16_t x = encode_uint16(high_nibble(contact[3]), contact[1]);
|
||||
const uint16_t y = encode_uint16(low_nibble(contact[3]), contact[2]);
|
||||
const uint16_t x = ((contact[3] & 0xF0u) << 4u) | contact[1];
|
||||
const uint16_t y = ((contact[3] & 0x0Fu) << 8u) | contact[2];
|
||||
this->add_raw_touch_position_(contact[0], x, y, contact[4]);
|
||||
}
|
||||
this->status_clear_warning();
|
||||
|
||||
+1
-11
@@ -1155,16 +1155,6 @@ bool random_bytes(uint8_t *data, size_t len);
|
||||
/// @name Bit manipulation
|
||||
///@{
|
||||
|
||||
/// The high 4 bits of a byte, e.g. high_nibble(0xA5) == 0xA.
|
||||
constexpr uint8_t high_nibble(uint8_t byte) { return byte >> 4; }
|
||||
/// The low 4 bits of a byte, e.g. low_nibble(0xA5) == 0x5.
|
||||
constexpr uint8_t low_nibble(uint8_t byte) { return byte & 0x0F; }
|
||||
|
||||
/// Encode a 12-bit value from its high 8 and low 4 bits, e.g. encode_uint12(0x12, 0x3) == 0x123.
|
||||
/// Bits above the low 4 of \p low_bits are ignored.
|
||||
constexpr uint16_t encode_uint12(uint8_t high_bits, uint8_t low_bits) {
|
||||
return (static_cast<uint16_t>(high_bits) << 4) | low_nibble(low_bits);
|
||||
}
|
||||
/// Encode a 16-bit value given the most and least significant byte.
|
||||
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb) {
|
||||
return (static_cast<uint16_t>(msb) << 8) | (static_cast<uint16_t>(lsb));
|
||||
@@ -1267,7 +1257,7 @@ constexpr uint8_t *put_le32(uint8_t *dst, uint32_t value) {
|
||||
}
|
||||
|
||||
/// Decode a two-digit packed BCD byte (tens in the high nibble) to its value, e.g. 0x59 to 59.
|
||||
constexpr uint8_t bcd_to_uint8(uint8_t bcd) { return high_nibble(bcd) * 10 + low_nibble(bcd); }
|
||||
constexpr uint8_t bcd_to_uint8(uint8_t bcd) { return (bcd >> 4) * 10 + (bcd & 0x0F); }
|
||||
/// Encode a value from 0 to 99 as a two-digit packed BCD byte, e.g. 59 to 0x59.
|
||||
constexpr uint8_t uint8_to_bcd(uint8_t value) { return ((value / 10) << 4) | (value % 10); }
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ from pathlib import Path
|
||||
import re
|
||||
from typing import Any, NamedTuple
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import url2pathname
|
||||
|
||||
from esphome import loader, yaml_util
|
||||
from esphome.components.external_components import ExternalSource, get_sources
|
||||
@@ -201,6 +200,8 @@ def _esphome_vcs() -> _Source | None:
|
||||
if commit:
|
||||
return _Source(strip_url_credentials(url), commit)
|
||||
if "dir_info" in info and url.startswith("file:"):
|
||||
from urllib.request import url2pathname
|
||||
|
||||
# An editable or local install may be a fork or a patched clone
|
||||
if (
|
||||
source := _checkout_vcs(Path(url2pathname(urlparse(url).path)))
|
||||
|
||||
@@ -17,7 +17,6 @@ import threading
|
||||
import time
|
||||
from typing import IO, TYPE_CHECKING
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import url2pathname
|
||||
|
||||
from esphome.helpers import ProgressBar, get_usable_cpu_count, rmtree
|
||||
from esphome.net_retry import (
|
||||
@@ -1363,6 +1362,9 @@ def local_path_from_url(url: str) -> Path:
|
||||
Handles ``file:///home/me/x`` and ``file:///C:/x`` (no host), ``file://localhost/x``
|
||||
and ``file://server/share/x`` (a UNC path).
|
||||
"""
|
||||
# urllib.request loads http.client and the email parser, which config validation does not need
|
||||
from urllib.request import url2pathname
|
||||
|
||||
from esphome.core import EsphomeError
|
||||
|
||||
try:
|
||||
|
||||
@@ -26,7 +26,6 @@ from pathlib import Path, PurePosixPath
|
||||
import re
|
||||
from typing import Any
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
from urllib.request import url2pathname
|
||||
|
||||
from esphome import git
|
||||
from esphome.core import CORE, EsphomeError, Library
|
||||
@@ -961,6 +960,8 @@ def _node_key(
|
||||
f"{scheme}:// library URL '{repository}' must be an absolute "
|
||||
f"directory path, e.g. {scheme}:///path/to/lib"
|
||||
)
|
||||
from urllib.request import url2pathname
|
||||
|
||||
path = url2pathname(url_path)
|
||||
return (name or PurePosixPath(url_path).name), "local", (path, None)
|
||||
key = str(split_result.path).strip("/").removesuffix(".git")
|
||||
|
||||
@@ -55,26 +55,6 @@ TEST(HelpersTest, Ilog10RoundTripMatchesLog10) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(HelpersTest, Nibbles) {
|
||||
EXPECT_EQ(high_nibble(0xA5), 0xA);
|
||||
EXPECT_EQ(low_nibble(0xA5), 0x5);
|
||||
EXPECT_EQ(high_nibble(0x0F), 0x0);
|
||||
EXPECT_EQ(low_nibble(0xF0), 0x0);
|
||||
static_assert(high_nibble(0xFF) == 0xF && low_nibble(0xFF) == 0xF, "usable in constant expressions");
|
||||
}
|
||||
|
||||
TEST(HelpersTest, EncodeUint12) {
|
||||
EXPECT_EQ(encode_uint12(0x12, 0x3), 0x123);
|
||||
EXPECT_EQ(encode_uint12(0xFF, 0xF), 0xFFF);
|
||||
EXPECT_EQ(encode_uint12(0x00, 0x0), 0x000);
|
||||
EXPECT_EQ(encode_uint12(0x12, 0xA3), 0x123);
|
||||
// A touch record byte packing the low nibbles of X (high) and Y (low)
|
||||
const uint8_t shared = 0x5C;
|
||||
EXPECT_EQ(encode_uint12(0x34, high_nibble(shared)), 0x345);
|
||||
EXPECT_EQ(encode_uint12(0x67, low_nibble(shared)), 0x67C);
|
||||
static_assert(encode_uint12(0xAB, 0xC) == 0xABC, "usable in constant expressions");
|
||||
}
|
||||
|
||||
TEST(HelpersTest, SignExtend) {
|
||||
EXPECT_EQ(sign_extend<24>(0x000000), 0);
|
||||
EXPECT_EQ(sign_extend<24>(0x7FFFFF), 8388607);
|
||||
|
||||
Reference in new issue
Block a user