mirror of
https://github.com/esphome/esphome.git
synced 2025-10-29 22:24:26 +00:00
Cleanup dashboard JS (#491)
* Cleanup dashboard JS * Add vscode * Save start_mark/end_mark * Updates * Updates * Remove need for cv.nameable It's a bit hacky but removes so much bloat from integrations * Add enum helper * Document APIs, and Improvements * Fixes * Fixes * Update PULL_REQUEST_TEMPLATE.md * Updates * Updates * Updates
This commit is contained in:
@@ -11,7 +11,7 @@ I2CDevice = i2c_ns.class_('I2CDevice')
|
||||
|
||||
MULTI_CONF = True
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(I2CComponent),
|
||||
cv.GenerateID(): cv.declare_id(I2CComponent),
|
||||
cv.Optional(CONF_SDA, default='SDA'): pins.input_pin,
|
||||
cv.Optional(CONF_SCL, default='SCL'): pins.input_pin,
|
||||
cv.Optional(CONF_FREQUENCY, default='50kHz'):
|
||||
@@ -21,17 +21,26 @@ CONFIG_SCHEMA = cv.Schema({
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID], config[CONF_SDA], config[CONF_SCL],
|
||||
int(config[CONF_FREQUENCY]), config[CONF_SCAN])
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
|
||||
cg.add(var.set_sda_pin(config[CONF_SDA]))
|
||||
cg.add(var.set_scl_pin(config[CONF_SCL]))
|
||||
cg.add(var.set_frequency(int(config[CONF_FREQUENCY])))
|
||||
cg.add(var.set_scan(config[CONF_SCAN]))
|
||||
cg.add_library('Wire', None)
|
||||
cg.add_global(i2c_ns.using)
|
||||
|
||||
|
||||
def i2c_device_schema(default_address):
|
||||
"""Create a schema for a i2c device.
|
||||
|
||||
:param default_address: The default address of the i2c device, can be None to represent
|
||||
a required option.
|
||||
:return: The i2c device schema, `extend` this in your config schema.
|
||||
"""
|
||||
schema = {
|
||||
cv.GenerateID(CONF_I2C_ID): cv.use_variable_id(I2CComponent),
|
||||
cv.GenerateID(CONF_I2C_ID): cv.use_id(I2CComponent),
|
||||
}
|
||||
if default_address is None:
|
||||
schema[cv.Required(CONF_ADDRESS)] = cv.i2c_address
|
||||
@@ -42,6 +51,12 @@ def i2c_device_schema(default_address):
|
||||
|
||||
@coroutine
|
||||
def register_i2c_device(var, config):
|
||||
"""Register an i2c device with the given config.
|
||||
|
||||
Sets the i2c bus to use and the i2c address.
|
||||
|
||||
This is a coroutine, you need to await it with a 'yield' expression!
|
||||
"""
|
||||
parent = yield cg.get_variable(config[CONF_I2C_ID])
|
||||
cg.add(var.set_i2c_parent(parent))
|
||||
cg.add(var.set_i2c_address(config[CONF_ADDRESS]))
|
||||
|
||||
@@ -8,8 +8,7 @@ namespace i2c {
|
||||
|
||||
static const char *TAG = "i2c";
|
||||
|
||||
I2CComponent::I2CComponent(uint8_t sda_pin, uint8_t scl_pin, uint32_t frequency, bool scan)
|
||||
: sda_pin_(sda_pin), scl_pin_(scl_pin), frequency_(frequency), scan_(scan) {
|
||||
I2CComponent::I2CComponent() {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (next_i2c_bus_num_ == 0)
|
||||
this->wire_ = &Wire;
|
||||
|
||||
@@ -25,7 +25,11 @@ namespace i2c {
|
||||
*/
|
||||
class I2CComponent : public Component {
|
||||
public:
|
||||
I2CComponent(uint8_t sda_pin, uint8_t scl_pin, uint32_t frequency, bool scan);
|
||||
I2CComponent();
|
||||
void set_sda_pin(uint8_t sda_pin) { sda_pin_ = sda_pin; }
|
||||
void set_scl_pin(uint8_t scl_pin) { scl_pin_ = scl_pin; }
|
||||
void set_frequency(uint32_t frequency) { frequency_ = frequency; }
|
||||
void set_scan(bool scan) { scan_ = scan; }
|
||||
|
||||
/** Read len amount of bytes from a register into data. Optionally with a conversion time after
|
||||
* writing the register value to the bus.
|
||||
|
||||
Reference in New Issue
Block a user