Add files via upload

This commit is contained in:
SeByDocKy 2024-11-06 20:05:06 +01:00 committed by GitHub
parent c0b0a8ca28
commit e861026f62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 15 additions and 7 deletions

View File

@ -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]))

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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_;