Move blinds to esp-idf
- can always revert - better dhcp support
This commit is contained in:
@@ -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