From ad49956139cf06d733697b46c3d39763e3366ee1 Mon Sep 17 00:00:00 2001 From: Matthew Connelly Date: Mon, 11 Jun 2018 15:18:16 +0100 Subject: [PATCH] tiny bits of cleanup here and there --- uPyConfig.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/uPyConfig.py b/uPyConfig.py index 2e7b313..9057e1e 100644 --- a/uPyConfig.py +++ b/uPyConfig.py @@ -1,5 +1,5 @@ class uPyConfig: - from machine import I2C, Pin + from machine import Pin class features: class connectivity: wifi = False @@ -15,27 +15,27 @@ class uPyConfig: temperature = False hall_effect = False - class owc: + class _owc: from onewire import OneWire - from machine import Pin def __init__(self, pin): if pin.__class__ != self.Pin: pin=self.Pin(pin) self.bus = self.OneWire(pin) class _i2c: - from machine import I2C, Pin - + from machine import I2C def load_handle(self): + if self.bus.__class__ == self.I2C: return self.bus = self.I2C(scl=self.scl, sda=self.sda) self.bus.init(scl=self.scl, sda=self.sda) def __init__(self, scl, sda): - self.scl=self.Pin(scl) - self.sda=self.Pin(sda) + if scl.__class__ != self.Pin: scl=self.Pin(scl) + if sda.__class__ != self.Pin: sda=self.Pin(sda) + self.scl=scl + self.sda=sda self.load_handle() class _oled: - from machine import Pin addr = 0x0 rst = 0 rst_hold = False @@ -55,11 +55,17 @@ class uPyConfig: def __init__(self, i2c): self.i2c = i2c + def onewire_init(self, pin, glob=True): + if glob: self.owc = self._owc(pin) + else: return self._owc(pin) + return self.owc + def __init__(self, board_defs): self.i2c = self._i2c(board_defs['i2c_scl'], board_defs['i2c_sda']) if 'has_wifi' in board_defs.keys(): self.features.connectivity.wifi = True if 'has_bluetooth' in board_defs.keys(): self.features.connectivity.bluetooth = True if 'has_bluetooth_le' in board_defs.keys(): self.features.connectivity.bluetooth_le = True + if 'has_lora' in board_defs.keys(): self.features.connectivity.lora = True if 'sen_capacitive' in board_defs.keys(): self.features.sensor.capacitive = True if 'sen_temperature' in board_defs.keys(): self.features.sensor.temperature = True if 'sen_hall' in board_defs.keys(): self.features.sensor.hall_effect = True @@ -153,6 +159,17 @@ class esp32(uPyConfig): 'oled_height': 64, 'oled_width': 128, }, + 'ttgo-1': { + 'has_oled': True, + 'oled_height': 64, + 'oled_width': 128, + }, + 'ttgo-2': { + 'has_oled': True, + 'oled_height': 64, + 'oled_width': 128, + 'has_lora': True, + } } def __init__(self, variant='generic'):