mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Add MCP47A1 DAC output (#3014)
This commit is contained in:
parent
84a830195f
commit
ea1be8e7bf
6 changed files with 69 additions and 0 deletions
|
@ -96,6 +96,7 @@ esphome/components/mcp23x08_base/* @jesserockz
|
|||
esphome/components/mcp23x17_base/* @jesserockz
|
||||
esphome/components/mcp23xxx_base/* @jesserockz
|
||||
esphome/components/mcp2515/* @danielschramm @mvturnho
|
||||
esphome/components/mcp47a1/* @jesserockz
|
||||
esphome/components/mcp9808/* @k7hpn
|
||||
esphome/components/md5/* @esphome/core
|
||||
esphome/components/mdns/* @esphome/core
|
||||
|
|
0
esphome/components/mcp47a1/__init__.py
Normal file
0
esphome/components/mcp47a1/__init__.py
Normal file
21
esphome/components/mcp47a1/mcp47a1.cpp
Normal file
21
esphome/components/mcp47a1/mcp47a1.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "mcp47a1.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace mcp47a1 {
|
||||
|
||||
static const char *const TAG = "mcp47a1";
|
||||
|
||||
void MCP47A1::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "MCP47A1 Output:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
}
|
||||
|
||||
void MCP47A1::write_state(float state) {
|
||||
const uint8_t value = remap(state, 0.0f, 1.0f, 63, 0);
|
||||
this->write_byte(0, value);
|
||||
}
|
||||
|
||||
} // namespace mcp47a1
|
||||
} // namespace esphome
|
17
esphome/components/mcp47a1/mcp47a1.h
Normal file
17
esphome/components/mcp47a1/mcp47a1.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace mcp47a1 {
|
||||
|
||||
class MCP47A1 : public Component, public output::FloatOutput, public i2c::I2CDevice {
|
||||
public:
|
||||
void dump_config() override;
|
||||
void write_state(float state) override;
|
||||
};
|
||||
|
||||
} // namespace mcp47a1
|
||||
} // namespace esphome
|
27
esphome/components/mcp47a1/output.py
Normal file
27
esphome/components/mcp47a1/output.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import output, i2c
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
CODEOWNERS = ["@jesserockz"]
|
||||
DEPENDENCIES = ["i2c"]
|
||||
|
||||
mcp47a1_ns = cg.esphome_ns.namespace("mcp47a1")
|
||||
MCP47A1 = mcp47a1_ns.class_("MCP47A1", output.FloatOutput, cg.Component, i2c.I2CDevice)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
output.FLOAT_OUTPUT_SCHEMA.extend(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.declare_id(MCP47A1),
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(i2c.i2c_device_schema(0x2E))
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
await output.register_output(var, config)
|
|
@ -72,6 +72,9 @@ output:
|
|||
channel: 0
|
||||
max_power: 0.8
|
||||
|
||||
- platform: mcp47a1
|
||||
id: output_mcp47a1
|
||||
|
||||
demo:
|
||||
|
||||
esp32_ble:
|
||||
|
|
Loading…
Reference in a new issue