mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 15:04:54 +01:00
renamed transmit_cc1101 to transmit_rc_switch_raw_cc1101 to better reflect what it does, and begin_tx/end_tx can be used for the rest of the transmit_* actions
This commit is contained in:
parent
c3d27326f2
commit
eeeb5dd256
10 changed files with 47 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome import automation, pins
|
||||
from esphome.automation import maybe_simple_id
|
||||
from esphome.components import sensor
|
||||
from esphome.components import spi
|
||||
from esphome.components import remote_base
|
||||
|
@ -74,6 +75,24 @@ async def to_code(config):
|
|||
cg.add(var.set_config_lqi_sensor(lqi))
|
||||
|
||||
|
||||
BeginTxAction = ns.class_("BeginTxAction", automation.Action)
|
||||
EndTxAction = ns.class_("EndTxAction", automation.Action)
|
||||
|
||||
CC1101_ACTION_SCHEMA = maybe_simple_id(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(CC1101),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@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
|
||||
|
||||
|
||||
CC1101RawAction = ns.class_("CC1101RawAction", remote_base.RCSwitchRawAction)
|
||||
|
||||
CC1101_TRANSMIT_SCHEMA = (
|
||||
|
@ -88,8 +107,8 @@ CC1101_TRANSMIT_SCHEMA = (
|
|||
)
|
||||
|
||||
|
||||
@remote_base.register_action("cc1101", CC1101RawAction, CC1101_TRANSMIT_SCHEMA)
|
||||
async def cc1101_action(var, config, args):
|
||||
@remote_base.register_action("rc_switch_raw_cc1101", CC1101RawAction, CC1101_TRANSMIT_SCHEMA)
|
||||
async def rc_switch_raw_cc1101_action(var, config, args):
|
||||
proto = await cg.templatable(
|
||||
config[CONF_PROTOCOL],
|
||||
args,
|
||||
|
|
|
@ -6,11 +6,13 @@
|
|||
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 a single pin instead of GD0O and GD02 (gdo0 is an optional parameter). If assigned,
|
||||
the pin direction will be reversed for the transfers.
|
||||
On ESP8266, you can use a single pin instead of GD0O and GD02 (gdo0 is an optional parameter). If assigned, the pin
|
||||
direction will be reversed for the transfers.
|
||||
|
||||
On ESP32, this will not work, you must connect two separate pins. TX to GDO0, RX to GDO2.
|
||||
If only TX works, they are probably switched.
|
||||
On ESP32, this will not work, you must connect two separate pins. TX to GDO0, RX to GDO2. If only TX works, they are
|
||||
probably switched.
|
||||
|
||||
Transfers, except transmit_rc_switch_raw_cc1101, must be surrounded with cc1101.begin_tx and cc1101.end_tx.
|
||||
|
||||
The source code is a mashup of the following github projects with some special esphome sauce:
|
||||
|
||||
|
@ -593,14 +595,14 @@ void CC1101::set_rxbw_(uint32_t bw) {
|
|||
}
|
||||
|
||||
void CC1101::set_tx_() {
|
||||
ESP_LOGI(TAG, "CC1101 set_tx");
|
||||
ESP_LOGD(TAG, "CC1101 set_tx");
|
||||
this->send_cmd_(CC1101_SIDLE);
|
||||
this->send_cmd_(CC1101_STX);
|
||||
this->trxstate_ = 1;
|
||||
}
|
||||
|
||||
void CC1101::set_rx_() {
|
||||
ESP_LOGI(TAG, "CC1101 set_rx");
|
||||
ESP_LOGD(TAG, "CC1101 set_rx");
|
||||
this->send_cmd_(CC1101_SIDLE);
|
||||
this->send_cmd_(CC1101_SRX);
|
||||
this->trxstate_ = 2;
|
||||
|
|
|
@ -90,6 +90,16 @@ class CC1101 : public PollingComponent,
|
|||
void end_tx();
|
||||
};
|
||||
|
||||
template<typename... Ts> class BeginTxAction : public Action<Ts...>, public Parented<CC1101> {
|
||||
public:
|
||||
void play(Ts... x) override { this->parent_->begin_tx(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class EndTxAction : public Action<Ts...>, public Parented<CC1101> {
|
||||
public:
|
||||
void play(Ts... x) override { this->parent_->end_tx(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class CC1101RawAction : public remote_base::RCSwitchRawAction<Ts...>, public Parented<CC1101> {
|
||||
protected:
|
||||
void play(Ts... x) override {
|
||||
|
|
|
@ -51,7 +51,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
- remote_transmitter.transmit_rc_switch_raw_cc1101:
|
||||
transmitter_id: realtx
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
|
|
|
@ -51,7 +51,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
- remote_transmitter.transmit_rc_switch_raw_cc1101:
|
||||
transmitter_id: realtx
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
|
|
|
@ -43,7 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
- remote_transmitter.transmit_rc_switch_raw_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
|
|
@ -43,7 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
- remote_transmitter.transmit_rc_switch_raw_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
|
|
@ -43,7 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
- remote_transmitter.transmit_rc_switch_raw_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
|
|
@ -43,7 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
- remote_transmitter.transmit_rc_switch_raw_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
|
|
@ -50,7 +50,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
- remote_transmitter.transmit_rc_switch_raw_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
|
Loading…
Reference in a new issue