parent
39d5a466eb
commit
f61a94e32b
@ -0,0 +1,11 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
empty_i2c_component:
|
||||
id: empty_i2c_component_1
|
||||
address: 0x01 # optional
|
||||
|
||||
i2c:
|
||||
sda: 4
|
||||
scl: 5
|
||||
```
|
||||
@ -0,0 +1,25 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor, output
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
CONF_I2C_ADDR = 0x09
|
||||
|
||||
showcase_component_ns = cg.esphome_ns.namespace('showcase_component')
|
||||
ShowcaseComponent = empty_i2c_component_ns.class_('ShowcaseComponent', cg.Component, i2c.I2CDevice)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(ShowcaseComponent),
|
||||
|
||||
cv.Required(CONF_UPPER): cv.use_id(output.FloatOutput),
|
||||
cv.Required(CONF_LOWER): cv.use_id(output.FloatOutput)
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(CONF_I2C_ADDR))
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
@ -0,0 +1,24 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "showcase_component.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace showcase_component {
|
||||
|
||||
static const char *TAG = "empty_i2c_component.component";
|
||||
|
||||
void ShowcaseComponent::setup() {
|
||||
}
|
||||
|
||||
void ShowcaseComponent::loop() {
|
||||
uint8_t data = 10;
|
||||
this->read_register(0x0, &data, 0x1);
|
||||
/* ESP_LOGI(TAG, "READ value: %d", data); */
|
||||
}
|
||||
|
||||
void ShowcaseComponent::dump_config(){
|
||||
ESP_LOGCONFIG(TAG, "Empty I2C component");
|
||||
}
|
||||
|
||||
} // namespace empty_i2c_component
|
||||
} // namespace esphome
|
||||
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace showcase_component {
|
||||
|
||||
class ShowcaseComponent : public i2c::I2CDevice, public Component {
|
||||
public:
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
|
||||
void set_upper(output::FloatOutput *upper) {upper_ = upper;}
|
||||
void set_lower(output::FloatOutput *lower) {lower_ = lower;}
|
||||
|
||||
void write_state(float upper, float lower){
|
||||
this->upper_->set_level(upper);
|
||||
this->lower_->set_level(lower);
|
||||
}
|
||||
|
||||
protected:
|
||||
output::FloatOutput *upper_;
|
||||
output::FloatOutput *lower_;
|
||||
};
|
||||
|
||||
} // namespace empty_i2c_component
|
||||
} // namespace esphome
|
||||
@ -0,0 +1,25 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "empty_i2c_component.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace empty_i2c_component {
|
||||
|
||||
static const char *TAG = "empty_i2c_component.component";
|
||||
|
||||
void EmptyI2CComponent::setup() {
|
||||
}
|
||||
|
||||
void EmptyI2CComponent::loop() {
|
||||
uint8_t data = 10;
|
||||
this->read_register(0x0, &data, 0x1);
|
||||
ESP_LOGI(TAG, "READ value: %d", data);
|
||||
}
|
||||
|
||||
void EmptyI2CComponent::dump_config(){
|
||||
ESP_LOGCONFIG(TAG, "Empty I2C component");
|
||||
}
|
||||
|
||||
|
||||
} // namespace empty_i2c_component
|
||||
} // namespace esphome
|
||||
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace empty_i2c_component {
|
||||
|
||||
class EmptyI2CComponent : public i2c::I2CDevice, public Component {
|
||||
public:
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace empty_i2c_component
|
||||
} // namespace esphome
|
||||
Loading…
Reference in new issue