def to_code(config): for clk in gpio_output_pin_expression(config[CONF_CLK_PIN]): yield rhs = App.init_spi(clk) spi = Pvariable(config[CONF_ID], rhs) if CONF_MISO_PIN in config: for miso in gpio_input_pin_expression(config[CONF_MISO_PIN]): yield add(spi.set_miso(miso)) if CONF_MOSI_PIN in config: for mosi in gpio_input_pin_expression(config[CONF_MOSI_PIN]): yield add(spi.set_mosi(mosi)) setup_component(spi, config)
def to_code(config): for dout_pin in gpio_input_pin_expression(config[CONF_DOUT_PIN]): yield for sck_pin in gpio_input_pin_expression(config[CONF_CLK_PIN]): yield rhs = App.make_hx711_sensor(config[CONF_NAME], dout_pin, sck_pin, config.get(CONF_UPDATE_INTERVAL)) hx711 = Pvariable(config[CONF_ID], rhs) if CONF_GAIN in config: add(hx711.set_gain(GAINS[config[CONF_GAIN]])) sensor.setup_sensor(hx711, config) setup_component(hx711, config)
def to_code(config): rhs = App.make_deep_sleep_component() deep_sleep = Pvariable(config[CONF_ID], rhs) if CONF_SLEEP_DURATION in config: add(deep_sleep.set_sleep_duration(config[CONF_SLEEP_DURATION])) if CONF_WAKEUP_PIN in config: for pin in gpio_input_pin_expression(config[CONF_WAKEUP_PIN]): yield add(deep_sleep.set_wakeup_pin(pin)) if CONF_WAKEUP_PIN_MODE in config: add( deep_sleep.set_wakeup_pin_mode( WAKEUP_PIN_MODES[config[CONF_WAKEUP_PIN_MODE]])) if CONF_RUN_DURATION in config: add(deep_sleep.set_run_duration(config[CONF_RUN_DURATION])) if CONF_ESP32_EXT1_WAKEUP in config: conf = config[CONF_ESP32_EXT1_WAKEUP] mask = 0 for pin in conf[CONF_PINS]: mask |= 1 << pin[CONF_NUMBER] struct = StructInitializer( Ext1Wakeup, ('mask', mask), ('wakeup_mode', EXT1_WAKEUP_MODES[conf[CONF_MODE]])) add(deep_sleep.set_ext1_wakeup(struct)) setup_component(deep_sleep, config)
def to_code(config): pin = None for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin) gpio = Pvariable(config[CONF_ID], rhs) binary_sensor.setup_binary_sensor(gpio, config) setup_component(gpio, config)
def to_code(config): for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_duty_cycle_sensor(config[CONF_NAME], pin, config.get(CONF_UPDATE_INTERVAL)) duty = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(duty, config) setup_component(duty, config)
def to_code(config): for pin_a in gpio_input_pin_expression(config[CONF_PIN_A]): yield for pin_b in gpio_input_pin_expression(config[CONF_PIN_B]): yield rhs = App.make_rotary_encoder_sensor(config[CONF_NAME], pin_a, pin_b) encoder = Pvariable(config[CONF_ID], rhs) if CONF_PIN_RESET in config: for pin_i in gpio_input_pin_expression(config[CONF_PIN_RESET]): yield add(encoder.set_reset_pin(pin_i)) if CONF_RESOLUTION in config: resolution = RESOLUTIONS[config[CONF_RESOLUTION]] add(encoder.set_resolution(resolution)) sensor.setup_sensor(encoder, config) setup_component(encoder, config)
def to_code(config): for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_pulse_counter_sensor(config[CONF_NAME], pin, config.get(CONF_UPDATE_INTERVAL)) pcnt = Pvariable(config[CONF_ID], rhs) if CONF_COUNT_MODE in config: rising_edge = COUNT_MODES[config[CONF_COUNT_MODE][CONF_RISING_EDGE]] falling_edge = COUNT_MODES[config[CONF_COUNT_MODE][CONF_FALLING_EDGE]] add(pcnt.set_edge_mode(rising_edge, falling_edge)) if CONF_INTERNAL_FILTER in config: add(pcnt.set_filter_us(config[CONF_INTERNAL_FILTER])) sensor.setup_sensor(pcnt, config) setup_component(pcnt, config)
def to_code(config): for trigger in gpio_output_pin_expression(config[CONF_TRIGGER_PIN]): yield for echo in gpio_input_pin_expression(config[CONF_ECHO_PIN]): yield rhs = App.make_ultrasonic_sensor(config[CONF_NAME], trigger, echo, config.get(CONF_UPDATE_INTERVAL)) ultrasonic = Pvariable(config[CONF_ID], rhs) if CONF_TIMEOUT_TIME in config: add(ultrasonic.set_timeout_us(config[CONF_TIMEOUT_TIME])) elif CONF_TIMEOUT_METER in config: add(ultrasonic.set_timeout_m(config[CONF_TIMEOUT_METER])) sensor.setup_sensor(ultrasonic, config) setup_component(ultrasonic, config)
def to_code(config): for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_remote_receiver_component(pin) receiver = Pvariable(config[CONF_ID], rhs) for dumper in config[CONF_DUMP]: add(receiver.add_dumper(DUMPERS[dumper].new())) if CONF_TOLERANCE in config: add(receiver.set_tolerance(config[CONF_TOLERANCE])) if CONF_BUFFER_SIZE in config: add(receiver.set_buffer_size(config[CONF_BUFFER_SIZE])) if CONF_FILTER in config: add(receiver.set_filter_us(config[CONF_FILTER])) if CONF_IDLE in config: add(receiver.set_idle_us(config[CONF_IDLE])) setup_component(receiver, config)
def to_code(config): for spi_ in get_variable(config[CONF_SPI_ID]): yield for cs in gpio_output_pin_expression(config[CONF_CS_PIN]): yield for dc in gpio_output_pin_expression(config[CONF_DC_PIN]): yield model_type, model = MODELS[config[CONF_MODEL]] if model_type == 'a': rhs = App.make_waveshare_epaper_type_a(spi_, cs, dc, model) epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaperTypeA) elif model_type == 'b': rhs = App.make_waveshare_epaper_type_b(spi_, cs, dc, model) epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaper) else: raise NotImplementedError() if CONF_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')], return_type=void): yield add(epaper.set_writer(lambda_)) if CONF_RESET_PIN in config: for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]): yield add(epaper.set_reset_pin(reset)) if CONF_BUSY_PIN in config: for reset in gpio_input_pin_expression(config[CONF_BUSY_PIN]): yield add(epaper.set_busy_pin(reset)) if CONF_FULL_UPDATE_EVERY in config: add(epaper.set_full_update_every(config[CONF_FULL_UPDATE_EVERY])) display.setup_display(epaper, config) setup_component(epaper, config)