Ejemplo n.º 1
0
async def esp8266_pin_to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    num = config[CONF_NUMBER]
    cg.add(var.set_pin(num))
    cg.add(var.set_inverted(config[CONF_INVERTED]))
    cg.add(var.set_flags(pins.gpio_flags_expr(config[CONF_MODE])))
    return var
Ejemplo n.º 2
0
async def esp8266_pin_to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    num = config[CONF_NUMBER]
    mode = config[CONF_MODE]
    cg.add(var.set_pin(num))
    cg.add(var.set_inverted(config[CONF_INVERTED]))
    cg.add(var.set_flags(pins.gpio_flags_expr(mode)))
    if num < 16:
        initial_state: PinInitialState = CORE.data[KEY_ESP8266][
            KEY_PIN_INITIAL_STATES][num]
        if mode[CONF_INPUT]:
            if mode[CONF_PULLDOWN]:
                initial_state.mode = cg.global_ns.INPUT_PULLDOWN_16
            elif mode[CONF_PULLUP]:
                initial_state.mode = cg.global_ns.INPUT_PULLUP
            else:
                initial_state.mode = cg.global_ns.INPUT
        elif mode[CONF_OUTPUT]:
            if mode[CONF_OPEN_DRAIN]:
                initial_state.mode = cg.global_ns.OUTPUT_OPEN_DRAIN
            else:
                initial_state.mode = cg.global_ns.OUTPUT
            initial_state.level = int(config[CONF_INVERTED])

    return var
Ejemplo n.º 3
0
async def sx1509_pin_to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    parent = await cg.get_variable(config[CONF_SX1509])
    cg.add(var.set_parent(parent))

    num = config[CONF_NUMBER]
    cg.add(var.set_pin(num))
    cg.add(var.set_inverted(config[CONF_INVERTED]))
    cg.add(var.set_flags(pins.gpio_flags_expr(config[CONF_MODE])))
    return var
Ejemplo n.º 4
0
async def esp32_pin_to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    num = config[CONF_NUMBER]
    if CORE.using_esp_idf:
        cg.add(var.set_pin(getattr(gpio_num_t, f"GPIO_NUM_{num}")))
    else:
        cg.add(var.set_pin(num))
    cg.add(var.set_inverted(config[CONF_INVERTED]))
    if CONF_DRIVE_STRENGTH in config:
        cg.add(var.set_drive_strength(config[CONF_DRIVE_STRENGTH]))
    cg.add(var.set_flags(pins.gpio_flags_expr(config[CONF_MODE])))
    return var
Ejemplo n.º 5
0
async def mcp23xxx_pin_to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    parent = await cg.get_variable(config[CONF_MCP23XXX])

    cg.add(var.set_parent(parent))

    num = config[CONF_NUMBER]
    cg.add(var.set_pin(num))
    cg.add(var.set_inverted(config[CONF_INVERTED]))
    cg.add(var.set_flags(pins.gpio_flags_expr(config[CONF_MODE])))
    cg.add(var.set_interrupt_mode(config[CONF_INTERRUPT]))
    return var