def __init__(self, config): self.i2c = bus.MCU_I2C_from_config(config, default_addr=0x60) scale = config.getfloat('scale', 1., above=0.) # Configure registers for i, name in enumerate('abcd'): val = config.getfloat('channel_%s' % (name,), None, minval=0., maxval=scale) if val is not None: self.set_dac(i, int(val * 4095. / scale + .5))
def __init__(self, config): self.i2c = bus.MCU_I2C_from_config(config) scale = config.getfloat('scale', 1., above=0.) # Configure registers self.set_register(0x04, 0xff) self.set_register(0x0a, 0xff) for i in range(4): val = config.getfloat('wiper_%d' % (i, ), None, minval=0., maxval=scale) if val is not None: val = int(val * 255. / scale + .5) self.set_register(WiperRegisters[i], val)
def __init__(self, config): self.i2c = bus.MCU_I2C_from_config(config) i2c_addr = self.i2c.get_i2c_address() if i2c_addr < 44 or i2c_addr > 47: raise config.error("mcp4451 address must be between 44 and 47") scale = config.getfloat('scale', 1., above=0.) # Configure registers self.set_register(0x04, 0xff) self.set_register(0x0a, 0xff) for i in range(4): val = config.getfloat('wiper_%d' % (i,), None, minval=0., maxval=scale) if val is not None: val = int(val * 255. / scale + .5) self.set_register(WiperRegisters[i], val)
def __init__(self, config): self.printer = config.get_printer() self.name = config.get_name().split()[-1] self.hal.get_reactor().= self.printer.get_reactor() self.i2c = bus.MCU_I2C_from_config(config, default_addr=BME280_CHIP_ADDR, default_speed=100000) self.os_temp = config.getint('bme280_oversample_temp', 2) self.os_hum = config.getint('bme280_oversample_hum', 2) self.os_pres = config.getint('bme280_oversample_pressure', 2) self.temp = self.pressure = self.humidity = self.t_fine = 0. self.max_sample_time = \ (1.25 + (2.3 * self.os_temp) + ((2.3 * self.os_pres) + .575) + ((2.3 * self.os_hum) + .575)) / 1000 self.dig = None self.sample_timer = self.hal.get_reactor().register_timer(self._sample_bme280) self.printer.add_object("bme280 " + self.name, self) self.printer.event_register_handler("klippy:ready", self.handle_ready)
def __init__(self, config): self.printer = config.get_printer() self.name = config.get_name().split()[-1] self.reactor = self.printer.get_reactor() self.i2c = bus.MCU_I2C_from_config(config, default_addr=HTU21D_I2C_ADDR, default_speed=100000) self.hold_master_mode = config.getboolean('htu21d_hold_master', False) self.resolution = config.get('htu21d_resolution', 'TEMP12_HUM08') self.report_time = config.getint('htu21d_report_time', 30, minval=5) if self.resolution not in HTU21D_RESOLUTIONS: raise config.error("Invalid HTU21D Resolution. Valid are %s" % '|'.join(HTU21D_RESOLUTIONS.keys())) self.deviceId = config.get('sensor_type') self.temp = self.humidity = 0. self.sample_timer = self.reactor.register_timer(self._sample_htu21d) self.printer.add_object("htu21d " + self.name, self) self.printer.register_event_handler("klippy:ready", self.handle_ready)
def __init__(self, config): self.printer = config.get_printer() self.reactor = self.printer.get_reactor() self.i2c = bus.MCU_I2C_from_config(config, default_addr=CHIP_ADDR, default_speed=400000) self.mcu = self.i2c.get_mcu() self.oid = self.mcu.create_oid() self.get_i2c_oid = self.i2c.get_oid self.get_command_queue = self.i2c.get_command_queue self.get_mcu = self.i2c.get_mcu self.pat9125_write_verify_cmd = None self.last_query_time = 0. self.write_verify_response = None self.write_verify_request = None self.write_verify_timer = self.reactor.register_timer( self._write_verify_request_event)
def __init__(self, config): self._printer = config.get_printer() self._name = config.get_name().split()[1] self._i2c = bus.MCU_I2C_from_config(config, default_speed=400000) self._ppins = self._printer.lookup_object("pins") self._ppins.register_chip("sx1509_" + self._name, self) self._mcu = self._i2c.get_mcu() self._mcu.register_config_callback(self._build_config) self._oid = self._i2c.get_oid() self._last_clock = 0 # Set up registers default values self.reg_dict = { REG_DIR: 0xFFFF, REG_DATA: 0, REG_PULLUP: 0, REG_PULLDOWN: 0, REG_INPUT_DISABLE: 0, REG_ANALOG_DRIVER_ENABLE: 0 } self.reg_i_on_dict = {reg: 0 for reg in REG_I_ON}