mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
commit
cb6e314336
12 changed files with 136 additions and 55 deletions
|
@ -37,10 +37,14 @@ void BP1658CJ::loop() {
|
||||||
uint8_t data[12];
|
uint8_t data[12];
|
||||||
if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
||||||
this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
|
this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
|
||||||
// Off / Sleep
|
|
||||||
data[0] = BP1658CJ_MODEL_ID + BP1658CJ_ADDR_STANDBY;
|
|
||||||
for (int i = 1; i < 12; i++)
|
for (int i = 1; i < 12; i++)
|
||||||
data[i] = 0;
|
data[i] = 0;
|
||||||
|
|
||||||
|
// First turn all channels off
|
||||||
|
data[0] = BP1658CJ_MODEL_ID + BP1658CJ_ADDR_START_5CH;
|
||||||
|
this->write_buffer_(data, 12);
|
||||||
|
// Then sleep
|
||||||
|
data[0] = BP1658CJ_MODEL_ID + BP1658CJ_ADDR_STANDBY;
|
||||||
this->write_buffer_(data, 12);
|
this->write_buffer_(data, 12);
|
||||||
} else if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
} else if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
||||||
(this->pwm_amounts_[3] > 0 || this->pwm_amounts_[4] > 0)) {
|
(this->pwm_amounts_[3] > 0 || this->pwm_amounts_[4] > 0)) {
|
||||||
|
|
|
@ -17,12 +17,16 @@ static const uint8_t BP5758D_ADDR_START_2CH = 0b00100000;
|
||||||
static const uint8_t BP5758D_ADDR_START_5CH = 0b00110000;
|
static const uint8_t BP5758D_ADDR_START_5CH = 0b00110000;
|
||||||
static const uint8_t BP5758D_ALL_DATA_CHANNEL_ENABLEMENT = 0b00011111;
|
static const uint8_t BP5758D_ALL_DATA_CHANNEL_ENABLEMENT = 0b00011111;
|
||||||
|
|
||||||
|
static const uint8_t BP5758D_DELAY = 2;
|
||||||
|
|
||||||
void BP5758D::setup() {
|
void BP5758D::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Setting up BP5758D Output Component...");
|
ESP_LOGCONFIG(TAG, "Setting up BP5758D Output Component...");
|
||||||
this->data_pin_->setup();
|
this->data_pin_->setup();
|
||||||
this->data_pin_->digital_write(false);
|
this->data_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
this->clock_pin_->setup();
|
this->clock_pin_->setup();
|
||||||
this->clock_pin_->digital_write(false);
|
this->clock_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
this->channel_current_.resize(5, 0);
|
this->channel_current_.resize(5, 0);
|
||||||
this->pwm_amounts_.resize(5, 0);
|
this->pwm_amounts_.resize(5, 0);
|
||||||
}
|
}
|
||||||
|
@ -39,11 +43,11 @@ void BP5758D::loop() {
|
||||||
uint8_t data[17];
|
uint8_t data[17];
|
||||||
if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
||||||
this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
|
this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
|
||||||
for (int i = 1; i < 16; i++)
|
for (int i = 1; i < 17; i++)
|
||||||
data[i] = 0;
|
data[i] = 0;
|
||||||
|
|
||||||
// First turn all channels off
|
// First turn all channels off
|
||||||
data[0] = BP5758D_MODEL_ID + BP5758D_ADDR_START_3CH;
|
data[0] = BP5758D_MODEL_ID + BP5758D_ADDR_START_5CH;
|
||||||
this->write_buffer_(data, 17);
|
this->write_buffer_(data, 17);
|
||||||
// Then sleep
|
// Then sleep
|
||||||
data[0] = BP5758D_MODEL_ID + BP5758D_ADDR_STANDBY;
|
data[0] = BP5758D_MODEL_ID + BP5758D_ADDR_STANDBY;
|
||||||
|
@ -123,28 +127,42 @@ void BP5758D::set_channel_value_(uint8_t channel, uint16_t value) {
|
||||||
void BP5758D::set_channel_current_(uint8_t channel, uint8_t current) { this->channel_current_[channel] = current; }
|
void BP5758D::set_channel_current_(uint8_t channel, uint8_t current) { this->channel_current_[channel] = current; }
|
||||||
|
|
||||||
void BP5758D::write_bit_(bool value) {
|
void BP5758D::write_bit_(bool value) {
|
||||||
this->clock_pin_->digital_write(false);
|
|
||||||
this->data_pin_->digital_write(value);
|
this->data_pin_->digital_write(value);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
this->clock_pin_->digital_write(true);
|
this->clock_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
|
this->clock_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BP5758D::write_byte_(uint8_t data) {
|
void BP5758D::write_byte_(uint8_t data) {
|
||||||
for (uint8_t mask = 0x80; mask; mask >>= 1) {
|
for (uint8_t mask = 0x80; mask; mask >>= 1) {
|
||||||
this->write_bit_(data & mask);
|
this->write_bit_(data & mask);
|
||||||
}
|
}
|
||||||
this->clock_pin_->digital_write(false);
|
|
||||||
this->data_pin_->digital_write(true);
|
// ack bit
|
||||||
|
this->data_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||||
this->clock_pin_->digital_write(true);
|
this->clock_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
|
this->clock_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
|
this->data_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BP5758D::write_buffer_(uint8_t *buffer, uint8_t size) {
|
void BP5758D::write_buffer_(uint8_t *buffer, uint8_t size) {
|
||||||
this->data_pin_->digital_write(false);
|
this->data_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
|
this->clock_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < size; i++) {
|
for (uint32_t i = 0; i < size; i++) {
|
||||||
this->write_byte_(buffer[i]);
|
this->write_byte_(buffer[i]);
|
||||||
}
|
}
|
||||||
this->clock_pin_->digital_write(false);
|
|
||||||
this->clock_pin_->digital_write(true);
|
this->clock_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
this->data_pin_->digital_write(true);
|
this->data_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(BP5758D_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace bp5758d
|
} // namespace bp5758d
|
||||||
|
|
|
@ -90,6 +90,8 @@ void BLEService::stop() {
|
||||||
ESP_LOGE(TAG, "esp_ble_gatts_stop_service failed: %d", err);
|
ESP_LOGE(TAG, "esp_ble_gatts_stop_service failed: %d", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
esp32_ble::global_ble->get_advertising()->remove_service_uuid(this->uuid_);
|
||||||
|
esp32_ble::global_ble->get_advertising()->start();
|
||||||
this->running_state_ = STOPPING;
|
this->running_state_ = STOPPING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
|
|
||||||
|
#include <esp_bt_defs.h>
|
||||||
#include <esp_gap_ble_api.h>
|
#include <esp_gap_ble_api.h>
|
||||||
#include <esp_gatt_defs.h>
|
#include <esp_gatt_defs.h>
|
||||||
#include <esp_gattc_api.h>
|
#include <esp_gattc_api.h>
|
||||||
#include <esp_gatts_api.h>
|
#include <esp_gatts_api.h>
|
||||||
#include <esp_bt_defs.h>
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace esp32_ble_server {
|
namespace esp32_ble_server {
|
||||||
|
|
|
@ -4,7 +4,7 @@ from esphome.components import binary_sensor, output, esp32_ble_server
|
||||||
from esphome.const import CONF_ID
|
from esphome.const import CONF_ID
|
||||||
|
|
||||||
|
|
||||||
AUTO_LOAD = ["binary_sensor", "output", "esp32_ble_server"]
|
AUTO_LOAD = ["esp32_ble_server"]
|
||||||
CODEOWNERS = ["@jesserockz"]
|
CODEOWNERS = ["@jesserockz"]
|
||||||
CONFLICTS_WITH = ["esp32_ble_beacon"]
|
CONFLICTS_WITH = ["esp32_ble_beacon"]
|
||||||
DEPENDENCIES = ["wifi", "esp32"]
|
DEPENDENCIES = ["wifi", "esp32"]
|
||||||
|
|
|
@ -18,6 +18,17 @@ ESP32ImprovComponent::ESP32ImprovComponent() { global_improv_component = this; }
|
||||||
void ESP32ImprovComponent::setup() {
|
void ESP32ImprovComponent::setup() {
|
||||||
this->service_ = global_ble_server->create_service(improv::SERVICE_UUID, true);
|
this->service_ = global_ble_server->create_service(improv::SERVICE_UUID, true);
|
||||||
this->setup_characteristics();
|
this->setup_characteristics();
|
||||||
|
|
||||||
|
#ifdef USE_BINARY_SENSOR
|
||||||
|
if (this->authorizer_ != nullptr) {
|
||||||
|
this->authorizer_->add_on_state_callback([this](bool state) {
|
||||||
|
if (state) {
|
||||||
|
this->authorized_start_ = millis();
|
||||||
|
this->identify_start_ = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP32ImprovComponent::setup_characteristics() {
|
void ESP32ImprovComponent::setup_characteristics() {
|
||||||
|
@ -50,8 +61,10 @@ void ESP32ImprovComponent::setup_characteristics() {
|
||||||
BLEDescriptor *capabilities_descriptor = new BLE2902();
|
BLEDescriptor *capabilities_descriptor = new BLE2902();
|
||||||
this->capabilities_->add_descriptor(capabilities_descriptor);
|
this->capabilities_->add_descriptor(capabilities_descriptor);
|
||||||
uint8_t capabilities = 0x00;
|
uint8_t capabilities = 0x00;
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
if (this->status_indicator_ != nullptr)
|
if (this->status_indicator_ != nullptr)
|
||||||
capabilities |= improv::CAPABILITY_IDENTIFY;
|
capabilities |= improv::CAPABILITY_IDENTIFY;
|
||||||
|
#endif
|
||||||
this->capabilities_->set_value(capabilities);
|
this->capabilities_->set_value(capabilities);
|
||||||
this->setup_complete_ = true;
|
this->setup_complete_ = true;
|
||||||
}
|
}
|
||||||
|
@ -63,8 +76,7 @@ void ESP32ImprovComponent::loop() {
|
||||||
|
|
||||||
switch (this->state_) {
|
switch (this->state_) {
|
||||||
case improv::STATE_STOPPED:
|
case improv::STATE_STOPPED:
|
||||||
if (this->status_indicator_ != nullptr)
|
this->set_status_indicator_state_(false);
|
||||||
this->status_indicator_->turn_off();
|
|
||||||
|
|
||||||
if (this->service_->is_created() && this->should_start_ && this->setup_complete_) {
|
if (this->service_->is_created() && this->should_start_ && this->setup_complete_) {
|
||||||
if (this->service_->is_running()) {
|
if (this->service_->is_running()) {
|
||||||
|
@ -80,14 +92,17 @@ void ESP32ImprovComponent::loop() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case improv::STATE_AWAITING_AUTHORIZATION: {
|
case improv::STATE_AWAITING_AUTHORIZATION: {
|
||||||
if (this->authorizer_ == nullptr || this->authorizer_->state) {
|
#ifdef USE_BINARY_SENSOR
|
||||||
|
if (this->authorizer_ == nullptr ||
|
||||||
|
(this->authorized_start_ != 0 && ((now - this->authorized_start_) < this->authorized_duration_))) {
|
||||||
this->set_state_(improv::STATE_AUTHORIZED);
|
this->set_state_(improv::STATE_AUTHORIZED);
|
||||||
this->authorized_start_ = now;
|
} else
|
||||||
} else {
|
#else
|
||||||
if (this->status_indicator_ != nullptr) {
|
this->set_state_(improv::STATE_AUTHORIZED);
|
||||||
|
#endif
|
||||||
|
{
|
||||||
if (!this->check_identify_())
|
if (!this->check_identify_())
|
||||||
this->status_indicator_->turn_on();
|
this->set_status_indicator_state_(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -99,25 +114,13 @@ void ESP32ImprovComponent::loop() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->status_indicator_ != nullptr) {
|
|
||||||
if (!this->check_identify_()) {
|
if (!this->check_identify_()) {
|
||||||
if ((now % 1000) < 500) {
|
this->set_status_indicator_state_((now % 1000) < 500);
|
||||||
this->status_indicator_->turn_on();
|
|
||||||
} else {
|
|
||||||
this->status_indicator_->turn_off();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case improv::STATE_PROVISIONING: {
|
case improv::STATE_PROVISIONING: {
|
||||||
if (this->status_indicator_ != nullptr) {
|
this->set_status_indicator_state_((now % 200) < 100);
|
||||||
if ((now % 200) < 100) {
|
|
||||||
this->status_indicator_->turn_on();
|
|
||||||
} else {
|
|
||||||
this->status_indicator_->turn_off();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wifi::global_wifi_component->is_connected()) {
|
if (wifi::global_wifi_component->is_connected()) {
|
||||||
wifi::global_wifi_component->save_wifi_sta(this->connecting_sta_.get_ssid(),
|
wifi::global_wifi_component->save_wifi_sta(this->connecting_sta_.get_ssid(),
|
||||||
this->connecting_sta_.get_password());
|
this->connecting_sta_.get_password());
|
||||||
|
@ -142,13 +145,27 @@ void ESP32ImprovComponent::loop() {
|
||||||
}
|
}
|
||||||
case improv::STATE_PROVISIONED: {
|
case improv::STATE_PROVISIONED: {
|
||||||
this->incoming_data_.clear();
|
this->incoming_data_.clear();
|
||||||
if (this->status_indicator_ != nullptr)
|
this->set_status_indicator_state_(false);
|
||||||
this->status_indicator_->turn_off();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP32ImprovComponent::set_status_indicator_state_(bool state) {
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
|
if (this->status_indicator_ == nullptr)
|
||||||
|
return;
|
||||||
|
if (this->status_indicator_state_ == state)
|
||||||
|
return;
|
||||||
|
this->status_indicator_state_ = state;
|
||||||
|
if (state) {
|
||||||
|
this->status_indicator_->turn_on();
|
||||||
|
} else {
|
||||||
|
this->status_indicator_->turn_off();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool ESP32ImprovComponent::check_identify_() {
|
bool ESP32ImprovComponent::check_identify_() {
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
|
||||||
|
@ -156,11 +173,7 @@ bool ESP32ImprovComponent::check_identify_() {
|
||||||
|
|
||||||
if (identify) {
|
if (identify) {
|
||||||
uint32_t time = now % 1000;
|
uint32_t time = now % 1000;
|
||||||
if (time < 600 && time % 200 < 100) {
|
this->set_status_indicator_state_(time < 600 && time % 200 < 100);
|
||||||
this->status_indicator_->turn_on();
|
|
||||||
} else {
|
|
||||||
this->status_indicator_->turn_off();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return identify;
|
return identify;
|
||||||
}
|
}
|
||||||
|
@ -213,8 +226,12 @@ float ESP32ImprovComponent::get_setup_priority() const { return setup_priority::
|
||||||
|
|
||||||
void ESP32ImprovComponent::dump_config() {
|
void ESP32ImprovComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "ESP32 Improv:");
|
ESP_LOGCONFIG(TAG, "ESP32 Improv:");
|
||||||
|
#ifdef USE_BINARY_SENSOR
|
||||||
LOG_BINARY_SENSOR(" ", "Authorizer", this->authorizer_);
|
LOG_BINARY_SENSOR(" ", "Authorizer", this->authorizer_);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
ESP_LOGCONFIG(TAG, " Status Indicator: '%s'", YESNO(this->status_indicator_ != nullptr));
|
ESP_LOGCONFIG(TAG, " Status Indicator: '%s'", YESNO(this->status_indicator_ != nullptr));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP32ImprovComponent::process_incoming_data_() {
|
void ESP32ImprovComponent::process_incoming_data_() {
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
|
||||||
#include "esphome/components/esp32_ble_server/ble_characteristic.h"
|
|
||||||
#include "esphome/components/esp32_ble_server/ble_server.h"
|
|
||||||
#include "esphome/components/output/binary_output.h"
|
|
||||||
#include "esphome/components/wifi/wifi_component.h"
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
|
|
||||||
|
#include "esphome/components/esp32_ble_server/ble_characteristic.h"
|
||||||
|
#include "esphome/components/esp32_ble_server/ble_server.h"
|
||||||
|
#include "esphome/components/wifi/wifi_component.h"
|
||||||
|
|
||||||
|
#ifdef USE_BINARY_SENSOR
|
||||||
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
|
#include "esphome/components/output/binary_output.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
|
@ -34,8 +42,12 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
|
||||||
void stop() override;
|
void stop() override;
|
||||||
bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
|
bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
|
||||||
|
|
||||||
|
#ifdef USE_BINARY_SENSOR
|
||||||
void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
|
void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
|
||||||
|
#endif
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
|
void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
|
||||||
|
#endif
|
||||||
void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
|
void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
|
||||||
void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
|
void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
|
||||||
|
|
||||||
|
@ -58,12 +70,19 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
|
||||||
BLECharacteristic *rpc_response_;
|
BLECharacteristic *rpc_response_;
|
||||||
BLECharacteristic *capabilities_;
|
BLECharacteristic *capabilities_;
|
||||||
|
|
||||||
|
#ifdef USE_BINARY_SENSOR
|
||||||
binary_sensor::BinarySensor *authorizer_{nullptr};
|
binary_sensor::BinarySensor *authorizer_{nullptr};
|
||||||
|
#endif
|
||||||
|
#ifdef USE_OUTPUT
|
||||||
output::BinaryOutput *status_indicator_{nullptr};
|
output::BinaryOutput *status_indicator_{nullptr};
|
||||||
|
#endif
|
||||||
|
|
||||||
improv::State state_{improv::STATE_STOPPED};
|
improv::State state_{improv::STATE_STOPPED};
|
||||||
improv::Error error_state_{improv::ERROR_NONE};
|
improv::Error error_state_{improv::ERROR_NONE};
|
||||||
|
|
||||||
|
bool status_indicator_state_{false};
|
||||||
|
void set_status_indicator_state_(bool state);
|
||||||
|
|
||||||
void set_state_(improv::State state);
|
void set_state_(improv::State state);
|
||||||
void set_error_(improv::Error error);
|
void set_error_(improv::Error error);
|
||||||
void send_response_(std::vector<uint8_t> &response);
|
void send_response_(std::vector<uint8_t> &response);
|
||||||
|
|
|
@ -76,7 +76,7 @@ void HTU21DComponent::update() {
|
||||||
if (this->humidity_ != nullptr)
|
if (this->humidity_ != nullptr)
|
||||||
this->humidity_->publish_state(humidity);
|
this->humidity_->publish_state(humidity);
|
||||||
if (this->heater_ != nullptr)
|
if (this->heater_ != nullptr)
|
||||||
this->heater_->publish_state(humidity);
|
this->heater_->publish_state(heater_level);
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,4 +106,5 @@ async def output_set_level_to_code(config, action_id, template_arg, args):
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
cg.add_define("USE_OUTPUT")
|
||||||
cg.add_global(output_ns.using)
|
cg.add_global(output_ns.using)
|
||||||
|
|
|
@ -11,6 +11,8 @@ static const uint8_t SM10BIT_ADDR_START_3CH = 0x8;
|
||||||
static const uint8_t SM10BIT_ADDR_START_2CH = 0x10;
|
static const uint8_t SM10BIT_ADDR_START_2CH = 0x10;
|
||||||
static const uint8_t SM10BIT_ADDR_START_5CH = 0x18;
|
static const uint8_t SM10BIT_ADDR_START_5CH = 0x18;
|
||||||
|
|
||||||
|
static const uint8_t SM10BIT_DELAY = 2;
|
||||||
|
|
||||||
// Power current values
|
// Power current values
|
||||||
// HEX | Binary | RGB level | White level | Config value
|
// HEX | Binary | RGB level | White level | Config value
|
||||||
// 0x0 | 0000 | RGB 10mA | CW 5mA | 0
|
// 0x0 | 0000 | RGB 10mA | CW 5mA | 0
|
||||||
|
@ -37,10 +39,13 @@ void Sm10BitBase::loop() {
|
||||||
uint8_t data[12];
|
uint8_t data[12];
|
||||||
if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
||||||
this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
|
this->pwm_amounts_[3] == 0 && this->pwm_amounts_[4] == 0) {
|
||||||
// Off / Sleep
|
|
||||||
data[0] = this->model_id_ + SM10BIT_ADDR_STANDBY;
|
|
||||||
for (int i = 1; i < 12; i++)
|
for (int i = 1; i < 12; i++)
|
||||||
data[i] = 0;
|
data[i] = 0;
|
||||||
|
// First turn all channels off
|
||||||
|
data[0] = this->model_id_ + SM10BIT_ADDR_START_5CH;
|
||||||
|
this->write_buffer_(data, 12);
|
||||||
|
// Then sleep
|
||||||
|
data[0] = this->model_id_ + SM10BIT_ADDR_STANDBY;
|
||||||
this->write_buffer_(data, 12);
|
this->write_buffer_(data, 12);
|
||||||
} else if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
} else if (this->pwm_amounts_[0] == 0 && this->pwm_amounts_[1] == 0 && this->pwm_amounts_[2] == 0 &&
|
||||||
(this->pwm_amounts_[3] > 0 || this->pwm_amounts_[4] > 0)) {
|
(this->pwm_amounts_[3] > 0 || this->pwm_amounts_[4] > 0)) {
|
||||||
|
@ -84,28 +89,42 @@ void Sm10BitBase::set_channel_value_(uint8_t channel, uint16_t value) {
|
||||||
this->pwm_amounts_[channel] = value;
|
this->pwm_amounts_[channel] = value;
|
||||||
}
|
}
|
||||||
void Sm10BitBase::write_bit_(bool value) {
|
void Sm10BitBase::write_bit_(bool value) {
|
||||||
this->clock_pin_->digital_write(false);
|
|
||||||
this->data_pin_->digital_write(value);
|
this->data_pin_->digital_write(value);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
this->clock_pin_->digital_write(true);
|
this->clock_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
|
this->clock_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sm10BitBase::write_byte_(uint8_t data) {
|
void Sm10BitBase::write_byte_(uint8_t data) {
|
||||||
for (uint8_t mask = 0x80; mask; mask >>= 1) {
|
for (uint8_t mask = 0x80; mask; mask >>= 1) {
|
||||||
this->write_bit_(data & mask);
|
this->write_bit_(data & mask);
|
||||||
}
|
}
|
||||||
this->clock_pin_->digital_write(false);
|
|
||||||
this->data_pin_->digital_write(true);
|
// ack bit
|
||||||
|
this->data_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||||
this->clock_pin_->digital_write(true);
|
this->clock_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
|
this->clock_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
|
this->data_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sm10BitBase::write_buffer_(uint8_t *buffer, uint8_t size) {
|
void Sm10BitBase::write_buffer_(uint8_t *buffer, uint8_t size) {
|
||||||
this->data_pin_->digital_write(false);
|
this->data_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
|
this->clock_pin_->digital_write(false);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < size; i++) {
|
for (uint32_t i = 0; i < size; i++) {
|
||||||
this->write_byte_(buffer[i]);
|
this->write_byte_(buffer[i]);
|
||||||
}
|
}
|
||||||
this->clock_pin_->digital_write(false);
|
|
||||||
this->clock_pin_->digital_write(true);
|
this->clock_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
this->data_pin_->digital_write(true);
|
this->data_pin_->digital_write(true);
|
||||||
|
delayMicroseconds(SM10BIT_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sm10bit_base
|
} // namespace sm10bit_base
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2023.10.0b1"
|
__version__ = "2023.10.0b2"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#define USE_OTA
|
#define USE_OTA
|
||||||
#define USE_OTA_PASSWORD
|
#define USE_OTA_PASSWORD
|
||||||
#define USE_OTA_STATE_CALLBACK
|
#define USE_OTA_STATE_CALLBACK
|
||||||
|
#define USE_OUTPUT
|
||||||
#define USE_POWER_SUPPLY
|
#define USE_POWER_SUPPLY
|
||||||
#define USE_QR_CODE
|
#define USE_QR_CODE
|
||||||
#define USE_SELECT
|
#define USE_SELECT
|
||||||
|
|
Loading…
Reference in a new issue