From e861026f62ac673beec14278c408c58142623f3e Mon Sep 17 00:00:00 2001 From: SeByDocKy Date: Wed, 6 Nov 2024 20:05:06 +0100 Subject: [PATCH] Add files via upload --- esphome/components/gp8403/__init__.py | 8 +++++--- esphome/components/gp8403/gp8403.cpp | 1 + esphome/components/gp8403/gp8403.h | 6 +++++- esphome/components/gp8403/output/gp8403_output.cpp | 3 ++- esphome/components/gp8403/output/gp8403_output.h | 4 ++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/esphome/components/gp8403/__init__.py b/esphome/components/gp8403/__init__.py index a7a2b46f58..9792e02dcc 100644 --- a/esphome/components/gp8403/__init__.py +++ b/esphome/components/gp8403/__init__.py @@ -4,7 +4,7 @@ import esphome.codegen as cg from esphome.components import i2c from esphome.const import CONF_ID, CONF_VOLTAGE -CODEOWNERS = ["@jesserockz"] +CODEOWNERS = ["@jesserockz","@sebydocky"] DEPENDENCIES = ["i2c"] MULTI_CONF = True @@ -14,6 +14,8 @@ GP8403 = gp8403_ns.class_("GP8403", cg.Component, i2c.I2CDevice) GP8403Voltage = gp8403_ns.enum("GP8403Voltage") CONF_GP8403_ID = "gp8403_id" +CONF_GP8403 = "gp8403" +CONF_GP8413 = "gp8413" VOLTAGES = { "5V": GP8403Voltage.GP8403_VOLTAGE_5V, @@ -24,6 +26,7 @@ CONFIG_SCHEMA = ( cv.Schema( { cv.GenerateID(): cv.declare_id(GP8403), + cv.Optional(CONF_GP8413, default=False): cv.boolean, cv.Required(CONF_VOLTAGE): cv.enum(VOLTAGES, upper=True), } ) @@ -31,10 +34,9 @@ CONFIG_SCHEMA = ( .extend(i2c.i2c_device_schema(0x58)) ) - async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await i2c.register_i2c_device(var, config) - + cg.add(var.set_gp8413(config[CONF_GP8413])) cg.add(var.set_voltage(config[CONF_VOLTAGE])) diff --git a/esphome/components/gp8403/gp8403.cpp b/esphome/components/gp8403/gp8403.cpp index 7a08a18a8f..c4e19c4d56 100644 --- a/esphome/components/gp8403/gp8403.cpp +++ b/esphome/components/gp8403/gp8403.cpp @@ -14,6 +14,7 @@ void GP8403::setup() { this->write_register(RANGE_REGISTER, (uint8_t *) (&this-> void GP8403::dump_config() { ESP_LOGCONFIG(TAG, "GP8403:"); ESP_LOGCONFIG(TAG, " Voltage: %dV", this->voltage_ == GP8403_VOLTAGE_5V ? 5 : 10); + ESP_LOGCONFIG(TAG, " Is GP8413 ?: %s", YESNO(this->gp8413_)); LOG_I2C_DEVICE(this); } diff --git a/esphome/components/gp8403/gp8403.h b/esphome/components/gp8403/gp8403.h index 65182ef301..51a6ce1c05 100644 --- a/esphome/components/gp8403/gp8403.h +++ b/esphome/components/gp8403/gp8403.h @@ -16,11 +16,15 @@ class GP8403 : public Component, public i2c::I2CDevice { void setup() override; void dump_config() override; float get_setup_priority() const override { return setup_priority::DATA; } - + void set_gp8413(bool gp8413) { gp8413_ = gp8413; } void set_voltage(gp8403::GP8403Voltage voltage) { this->voltage_ = voltage; } + bool gp8413_; protected: GP8403Voltage voltage_; + //bool gp8413_; + + }; } // namespace gp8403 diff --git a/esphome/components/gp8403/output/gp8403_output.cpp b/esphome/components/gp8403/output/gp8403_output.cpp index ff73bb4627..dfc37517e7 100644 --- a/esphome/components/gp8403/output/gp8403_output.cpp +++ b/esphome/components/gp8403/output/gp8403_output.cpp @@ -15,7 +15,8 @@ void GP8403Output::dump_config() { } void GP8403Output::write_state(float state) { - uint16_t value = ((uint16_t) (state * 4095)) << 4; + uint16_t value = (this->parent_->gp8413_) ? ( (uint16_t) (32767 * state) << 1) : (((uint16_t) (4095 * state)) << 4); + ESP_LOGV(TAG, "Calculated DAC value: %u", value); i2c::ErrorCode err = this->parent_->write_register(OUTPUT_REGISTER + (2 * this->channel_), (uint8_t *) &value, 2); if (err != i2c::ERROR_OK) { ESP_LOGE(TAG, "Error writing to GP8403, code %d", err); diff --git a/esphome/components/gp8403/output/gp8403_output.h b/esphome/components/gp8403/output/gp8403_output.h index 71e5efb1cb..39dee71c5c 100644 --- a/esphome/components/gp8403/output/gp8403_output.h +++ b/esphome/components/gp8403/output/gp8403_output.h @@ -12,10 +12,10 @@ class GP8403Output : public Component, public output::FloatOutput, public Parent public: void dump_config() override; float get_setup_priority() const override { return setup_priority::DATA - 1; } - void set_channel(uint8_t channel) { this->channel_ = channel; } - void write_state(float state) override; + // bool get_gp8413() {return this->parent_->gp8413_ ;} + protected: uint8_t channel_;