Move blinds to esp-idf
- can always revert - better dhcp support
This commit is contained in:
+27
-5
@@ -5,11 +5,17 @@ esphome:
|
||||
|
||||
project:
|
||||
name: dasfoo.blinds
|
||||
version: "3.0"
|
||||
version: "4.0"
|
||||
|
||||
libraries:
|
||||
- SPI
|
||||
- lsatan/SmartRC-CC1101-Driver-Lib
|
||||
on_boot:
|
||||
priority: -100.0 # Everything is initialized.
|
||||
# Use remote_transmitter component instead of digitalWrite in somfy.cpp.
|
||||
then:
|
||||
- lambda: 'id(transceiver)->begin_tx();'
|
||||
|
||||
esp32:
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
packages:
|
||||
device_base: !include templates/esp32-poe.yaml
|
||||
@@ -17,13 +23,29 @@ packages:
|
||||
external_components:
|
||||
# Path is relative to the main YAML file, not this device_base template!
|
||||
- source: components
|
||||
- source: github://pr#6300
|
||||
components:
|
||||
- cc1101
|
||||
|
||||
spi:
|
||||
clk_pin: 14
|
||||
miso_pin: 16
|
||||
mosi_pin: 15
|
||||
|
||||
cc1101:
|
||||
id: transceiver
|
||||
cs_pin: 13
|
||||
tuner:
|
||||
frequency: 433340
|
||||
|
||||
cover:
|
||||
- name: "Office window"
|
||||
remote_id_offset: 0
|
||||
<<: &somfy_cover
|
||||
platform: somfy
|
||||
rf_pin: 4
|
||||
rf_pin:
|
||||
number: 4
|
||||
allow_other_uses: true
|
||||
# Can be retrieved from MQTT server. Take the key with lowest integer value
|
||||
# from /$board/rolling_code/ path.
|
||||
remote_id_base: !secret somfy_remote_id_base
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
|
||||
#ifndef cc1101_h
|
||||
#define cc1101_h
|
||||
|
||||
static bool cc1101_initialized = false;
|
||||
|
||||
static void cc1101_Init() {
|
||||
if (!cc1101_initialized) {
|
||||
ELECHOUSE_cc1101.addSpiPin(14, 16, 15, 13, 0);
|
||||
ELECHOUSE_cc1101.setModul(0);
|
||||
ELECHOUSE_cc1101.Init();
|
||||
ELECHOUSE_cc1101.setPA(7);
|
||||
ELECHOUSE_cc1101.setMHZ(433.34);
|
||||
ELECHOUSE_cc1101.SetTx();
|
||||
}
|
||||
cc1101_initialized = true;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,8 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import cover, mqtt
|
||||
from esphome.const import CONF_ID
|
||||
from esphome.components import cover
|
||||
from esphome import pins
|
||||
from esphome.const import CONF_ID, CONF_ALLOW_OTHER_USES
|
||||
|
||||
DEPENDENCIES = ["mqtt"]
|
||||
AUTO_LOAD = ["mqtt"]
|
||||
@@ -16,7 +17,7 @@ CONF_REMOTE_ID_OFFSET = "remote_id_offset"
|
||||
CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(SomfyRTSCover),
|
||||
cv.Required(CONF_RF_PIN): cv.uint8_t,
|
||||
cv.Required(CONF_RF_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Required(CONF_REMOTE_ID_BASE): cv.uint32_t,
|
||||
cv.Required(CONF_REMOTE_ID_OFFSET): cv.uint32_t,
|
||||
}
|
||||
@@ -27,7 +28,8 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await cover.register_cover(var, config)
|
||||
|
||||
cg.add(var.set_rf_pin(config[CONF_RF_PIN]))
|
||||
rf_pin = await cg.gpio_pin_expression(config[CONF_RF_PIN])
|
||||
cg.add(var.set_rf_pin(rf_pin))
|
||||
cg.add(var.set_remote_id(
|
||||
config[CONF_REMOTE_ID_BASE] + config[CONF_REMOTE_ID_OFFSET]
|
||||
))
|
||||
|
||||
+21
-16
@@ -1,6 +1,5 @@
|
||||
#include "somfy.h"
|
||||
|
||||
#include "cc1101.h"
|
||||
#include "esphome/components/mqtt/mqtt_client.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
@@ -18,7 +17,7 @@ static const int RF_SYMBOL = 640;
|
||||
|
||||
void SomfyRTSCover::dump_config() {
|
||||
LOG_COVER("", "Somfy RTS Cover", this);
|
||||
ESP_LOGCONFIG(TAG, " RF Pin: %d", this->rf_pin_);
|
||||
LOG_PIN(" RF Pin", this->rf_pin_);
|
||||
ESP_LOGCONFIG(TAG, " Remote ID: %d", this->remote_id_);
|
||||
if (this->rolling_code_) {
|
||||
ESP_LOGCONFIG(TAG, " Rolling Code: %d", this->rolling_code_);
|
||||
@@ -39,9 +38,10 @@ cover::CoverTraits SomfyRTSCover::get_traits() {
|
||||
}
|
||||
|
||||
void SomfyRTSCover::setup() {
|
||||
pinMode(rf_pin_, OUTPUT);
|
||||
digitalWrite(rf_pin_, LOW);
|
||||
cc1101_Init();
|
||||
if (rf_pin_ != nullptr) {
|
||||
rf_pin_->setup();
|
||||
rf_pin_->digital_write(false);
|
||||
}
|
||||
|
||||
rolling_code_pref_ =
|
||||
global_preferences->make_preference<int>(this->get_object_id_hash());
|
||||
@@ -87,6 +87,11 @@ void SomfyRTSCover::control(const cover::CoverCall &call) {
|
||||
}
|
||||
|
||||
void SomfyRTSCover::send(uint8_t command) {
|
||||
if (rf_pin_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Sender GPIO pin is not set");
|
||||
return;
|
||||
}
|
||||
|
||||
if (rolling_code_ == 0) {
|
||||
ESP_LOGE(TAG,
|
||||
"Remote #%d was requested to run command %d, but has not "
|
||||
@@ -125,25 +130,25 @@ void SomfyRTSCover::send(uint8_t command) {
|
||||
}
|
||||
|
||||
// Wake-up pulse & silence.
|
||||
digitalWrite(rf_pin_, HIGH);
|
||||
rf_pin_->digital_write(true);
|
||||
delayMicroseconds(9415);
|
||||
digitalWrite(rf_pin_, LOW);
|
||||
rf_pin_->digital_write(false);
|
||||
delayMicroseconds(89565);
|
||||
|
||||
for (int repeat = 0; repeat < 3; ++repeat) {
|
||||
// Hardware sync.
|
||||
uint8_t sync = repeat == 0 ? 2 : 7;
|
||||
for (uint8_t i = 0; i < sync; i++) {
|
||||
digitalWrite(rf_pin_, HIGH);
|
||||
rf_pin_->digital_write(true);
|
||||
delayMicroseconds(4 * RF_SYMBOL);
|
||||
digitalWrite(rf_pin_, LOW);
|
||||
rf_pin_->digital_write(false);
|
||||
delayMicroseconds(4 * RF_SYMBOL);
|
||||
}
|
||||
|
||||
// Software sync.
|
||||
digitalWrite(rf_pin_, HIGH);
|
||||
rf_pin_->digital_write(true);
|
||||
delayMicroseconds(4550);
|
||||
digitalWrite(rf_pin_, LOW);
|
||||
rf_pin_->digital_write(false);
|
||||
delayMicroseconds(RF_SYMBOL);
|
||||
|
||||
// Data: bits are sent one by one.
|
||||
@@ -152,20 +157,20 @@ void SomfyRTSCover::send(uint8_t command) {
|
||||
for (signed char bit = 7; bit >= 0; --bit) {
|
||||
uint8_t value = (frame[octet] >> bit) & 1;
|
||||
if (value == 1) {
|
||||
digitalWrite(rf_pin_, LOW);
|
||||
rf_pin_->digital_write(false);
|
||||
delayMicroseconds(RF_SYMBOL);
|
||||
digitalWrite(rf_pin_, HIGH);
|
||||
rf_pin_->digital_write(true);
|
||||
delayMicroseconds(RF_SYMBOL);
|
||||
} else {
|
||||
digitalWrite(rf_pin_, HIGH);
|
||||
rf_pin_->digital_write(true);
|
||||
delayMicroseconds(RF_SYMBOL);
|
||||
digitalWrite(rf_pin_, LOW);
|
||||
rf_pin_->digital_write(false);
|
||||
delayMicroseconds(RF_SYMBOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
digitalWrite(rf_pin_, LOW);
|
||||
rf_pin_->digital_write(false);
|
||||
// Inter-frame silence.
|
||||
delayMicroseconds(30415);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace somfy {
|
||||
|
||||
class SomfyRTSCover : public cover::Cover, public Component {
|
||||
public:
|
||||
void set_rf_pin(uint8_t rf_pin) { this->rf_pin_ = rf_pin; }
|
||||
void set_rf_pin(GPIOPin *rf_pin) { this->rf_pin_ = rf_pin; }
|
||||
void set_remote_id(uint32_t remote_id) { this->remote_id_ = remote_id; }
|
||||
|
||||
cover::CoverTraits get_traits() override;
|
||||
@@ -31,11 +31,11 @@ class SomfyRTSCover : public cover::Cover, public Component {
|
||||
*/
|
||||
void send(uint8_t command);
|
||||
|
||||
uint8_t rf_pin_;
|
||||
uint32_t remote_id_;
|
||||
uint32_t rolling_code_;
|
||||
std::string mqtt_topic_prefix_;
|
||||
ESPPreferenceObject rolling_code_pref_;
|
||||
GPIOPin *rf_pin_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace somfy
|
||||
|
||||
Reference in New Issue
Block a user