fixes for pull request

This commit is contained in:
Gábor Poczkodi 2024-02-28 13:04:14 +01:00
parent de08d4a07c
commit aecc34ecb2
12 changed files with 65 additions and 66 deletions

View file

@ -1 +1 @@
CODEOWNERS = ["@gabest11"]
CODEOWNERS = ["@gabest11"]

View file

@ -2,7 +2,7 @@
https://github.com/gabest11/esphome-cc1101
This is a CC1101 transceiver component that works with esphome's remote_transmitter/remote_receiver.
It can be compiled with Arduino and esp-idf framework and should support any esphome compatible board through the SPI Bus.
On ESP8266, you can use the same pin for GDO and GD2 (it is an optional parameter).
@ -65,20 +65,20 @@ CC1101::CC1101()
this->m4RxBw_ = 0;
this->trxstate_ = 0;
this->clb_[0][0] = 24;
this->clb_[0][0] = 24;
this->clb_[0][1] = 28;
this->clb_[1][0] = 31;
this->clb_[1][0] = 31;
this->clb_[1][1] = 38;
this->clb_[2][0] = 65;
this->clb_[2][0] = 65;
this->clb_[2][1] = 76;
this->clb_[3][0] = 77;
this->clb_[3][0] = 77;
this->clb_[3][1] = 79;
}
void CC1101::set_config_gdo0(InternalGPIOPin* pin)
{
gdo0_ = pin;
gdo0_ = pin;
if(gdo2_ == NULL) gdo2_ = pin;
}
@ -222,7 +222,7 @@ bool CC1101::reset()
//this->disable();
this->cs_->digital_write(false);
delayMicroseconds(41);
this->send_cmd(CC1101_SRES);
ESP_LOGD(TAG, "Issued CC1101 reset sequence.");
@ -292,7 +292,7 @@ void CC1101::write_register_burst(uint8_t reg, uint8_t* buffer, size_t length)
bool CC1101::send_data(const uint8_t* data, size_t length)
{
uint8_t buffer[length];
memcpy(buffer, data, lenght);
this->send_cmd(CC1101_SIDLE);
@ -338,7 +338,7 @@ void CC1101::set_mode(bool s)
this->write_register(CC1101_MDMCFG3, 0x93);
this->write_register(CC1101_MDMCFG4, 7 + this->m4RxBw_);
}
this->set_modulation(this->modulation_);
}
@ -550,7 +550,7 @@ void CC1101::set_frequency(uint32_t f)
this->write_register(CC1101_TEST0, 0x09);
uint8_t s = this->read_status_register(CC1101_FSCAL2);
if(s < 32)
{
this->write_register(CC1101_FSCAL2, s + 32);
@ -562,7 +562,7 @@ void CC1101::set_frequency(uint32_t f)
void CC1101::set_clb(uint8_t b, uint8_t s, uint8_t e)
{
if(b < 4)
if(b < 4)
{
this->clb_[b][0] = s;
this->clb_[b][1] = e;

View file

@ -7,7 +7,7 @@
namespace esphome {
namespace cc1101 {
class CC1101
class CC1101
: public sensor::Sensor,
public PollingComponent,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1KHZ>

View file

@ -107,4 +107,4 @@ static const uint32_t CC1101_MARCSTATE_TX_END = 0x14;
static const uint32_t CC1101_MARCSTATE_RXTX_SWITCH = 0x15;
}
}
}

View file

@ -9,19 +9,19 @@ from esphome.const import (
UNIT_EMPTY,
UNIT_DECIBEL_MILLIWATT,
DEVICE_CLASS_SIGNAL_STRENGTH,
STATE_CLASS_MEASUREMENT
STATE_CLASS_MEASUREMENT,
)
CODEOWNERS = ["@gabest11", "@dbuezas", "@nistvan86", "@LSatan"]
DEPENDENCIES = ["spi"]
CONF_GDO0 = "gdo0"
CONF_GDO2 = "gdo2"
CONF_BANDWIDTH = "bandwidth"
CONF_FREQUENCY = "frequency"
CONF_RSSI = "rssi"
CONF_LQI = "lqi"
CONF_CC1101_GDO0 = "gdo0"
CONF_CC1101_GDO2 = "gdo2"
CONF_CC1101_BANDWIDTH = "bandwidth"
CONF_CC1101_FREQUENCY = "frequency"
CONF_CC1101_RSSI = "rssi"
CONF_CC1101_LQI = "lqi"
cc1101_ns = cg.esphome_ns.namespace("cc1101")
CC1101 = cc1101_ns.class_("CC1101", sensor.Sensor, cg.PollingComponent, spi.SPIDevice)
@ -33,19 +33,19 @@ CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(CC1101),
cv.Required(CONF_GDO0): pins.gpio_output_pin_schema,
cv.Optional(CONF_GDO2): pins.gpio_input_pin_schema,
cv.Optional(CONF_BANDWIDTH, default=200): cv.uint32_t,
cv.Optional(CONF_FREQUENCY, default=433920): cv.uint32_t,
cv.Optional(CONF_RSSI): sensor.sensor_schema(
unit_of_measurement = UNIT_DECIBEL_MILLIWATT,
accuracy_decimals = 0,
device_class = DEVICE_CLASS_SIGNAL_STRENGTH,
state_class = STATE_CLASS_MEASUREMENT,
cv.Required(CONF_CC1101_GDO0): pins.gpio_output_pin_schema,
cv.Optional(CONF_CC1101_GDO2): pins.gpio_input_pin_schema,
cv.Optional(CONF_CC1101_BANDWIDTH, default=200): cv.uint32_t,
cv.Optional(CONF_CC1101_FREQUENCY, default=433920): cv.uint32_t,
cv.Optional(CONF_CC1101_RSSI): sensor.sensor_schema(
unit_of_measurement=UNIT_DECIBEL_MILLIWATT,
accuracy_decimals=0,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_LQI): sensor.sensor_schema(
unit_of_measurement = UNIT_EMPTY,
accuracy_decimals = 0,
cv.Optional(CONF_CC1101_LQI): sensor.sensor_schema(
unit_of_measurement=UNIT_EMPTY,
accuracy_decimals=0,
state_class = STATE_CLASS_MEASUREMENT,
),
}
@ -62,28 +62,27 @@ CC1101_ACTION_SCHEMA = maybe_simple_id(
@automation.register_action("cc1101.begin_tx", BeginTxAction, CC1101_ACTION_SCHEMA)
@automation.register_action("cc1101.end_tx", EndTxAction, CC1101_ACTION_SCHEMA)
async def cc1101_action_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
return var
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await spi.register_spi_device(var, config)
gdo0 = await cg.gpio_pin_expression(config[CONF_GDO0])
gdo0 = await cg.gpio_pin_expression(config[CONF_CC1101_GDO0])
cg.add(var.set_config_gdo0(gdo0))
if CONF_GDO2 in config:
gdo2 = await cg.gpio_pin_expression(config[CONF_GDO2])
if CONF_CC1101_GDO2 in config:
gdo2 = await cg.gpio_pin_expression(config[CONF_CC1101_GDO2])
cg.add(var.set_config_gdo2(gdo2))
cg.add(var.set_config_bandwidth(config[CONF_BANDWIDTH]))
cg.add(var.set_config_frequency(config[CONF_FREQUENCY]))
if CONF_RSSI in config:
rssi = await sensor.new_sensor(config[CONF_RSSI])
cg.add(var.set_config_bandwidth(config[CONF_CC1101_BANDWIDTH]))
cg.add(var.set_config_frequency(config[CONF_CC1101_FREQUENCY]))
if CONF_CC1101_RSSI in config:
rssi = await sensor.new_sensor(config[CONF_CC1101_RSSI])
cg.add(var.set_config_rssi_sensor(rssi))
if CONF_LQI in config:
lqi = await sensor.new_sensor(config[CONF_LQI])
if CONF_CC1101_LQI in config:
lqi = await sensor.new_sensor(config[CONF_CC1101_LQI])
cg.add(var.set_config_lqi_sensor(lqi))

View file

@ -60,9 +60,9 @@ button:
code: '0111000110010011110110010100011111110001001011110111'
protocol:
pulse_length: 434
sync: [1,6]
zero: [1,2]
one: [2,1]
sync: [1, 6]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 10

View file

@ -60,9 +60,9 @@ button:
code: '0111000110010011110110010100011111110001001011110111'
protocol:
pulse_length: 434
sync: [1,6]
zero: [1,2]
one: [2,1]
sync: [1, 6]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 10

View file

@ -51,9 +51,9 @@ button:
code: '0111000110010011110110010100011111110001001011110111'
protocol:
pulse_length: 434
sync: [1,6]
zero: [1,2]
one: [2,1]
sync: [1, 6]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 10

View file

@ -51,9 +51,9 @@ button:
code: '0111000110010011110110010100011111110001001011110111'
protocol:
pulse_length: 434
sync: [1,6]
zero: [1,2]
one: [2,1]
sync: [1, 6]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 10

View file

@ -51,9 +51,9 @@ button:
code: '0111000110010011110110010100011111110001001011110111'
protocol:
pulse_length: 434
sync: [1,6]
zero: [1,2]
one: [2,1]
sync: [1, 6]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 10

View file

@ -51,9 +51,9 @@ button:
code: '0111000110010011110110010100011111110001001011110111'
protocol:
pulse_length: 434
sync: [1,6]
zero: [1,2]
one: [2,1]
sync: [1, 6]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 10

View file

@ -51,9 +51,9 @@ button:
code: '0111000110010011110110010100011111110001001011110111'
protocol:
pulse_length: 434
sync: [1,6]
zero: [1,2]
one: [2,1]
sync: [1, 6]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 10