tiny bits of cleanup here and there

This commit is contained in:
Matthew Connelly 2018-06-11 15:18:16 +01:00
parent aed9e9541c
commit ad49956139
1 changed files with 25 additions and 8 deletions

View File

@ -1,5 +1,5 @@
class uPyConfig: class uPyConfig:
from machine import I2C, Pin from machine import Pin
class features: class features:
class connectivity: class connectivity:
wifi = False wifi = False
@ -15,27 +15,27 @@ class uPyConfig:
temperature = False temperature = False
hall_effect = False hall_effect = False
class owc: class _owc:
from onewire import OneWire from onewire import OneWire
from machine import Pin
def __init__(self, pin): def __init__(self, pin):
if pin.__class__ != self.Pin: pin=self.Pin(pin) if pin.__class__ != self.Pin: pin=self.Pin(pin)
self.bus = self.OneWire(pin) self.bus = self.OneWire(pin)
class _i2c: class _i2c:
from machine import I2C, Pin from machine import I2C
def load_handle(self): def load_handle(self):
if self.bus.__class__ == self.I2C: return
self.bus = self.I2C(scl=self.scl, sda=self.sda) self.bus = self.I2C(scl=self.scl, sda=self.sda)
self.bus.init(scl=self.scl, sda=self.sda) self.bus.init(scl=self.scl, sda=self.sda)
def __init__(self, scl, sda): def __init__(self, scl, sda):
self.scl=self.Pin(scl) if scl.__class__ != self.Pin: scl=self.Pin(scl)
self.sda=self.Pin(sda) if sda.__class__ != self.Pin: sda=self.Pin(sda)
self.scl=scl
self.sda=sda
self.load_handle() self.load_handle()
class _oled: class _oled:
from machine import Pin
addr = 0x0 addr = 0x0
rst = 0 rst = 0
rst_hold = False rst_hold = False
@ -55,11 +55,17 @@ class uPyConfig:
def __init__(self, i2c): def __init__(self, i2c):
self.i2c = 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): def __init__(self, board_defs):
self.i2c = self._i2c(board_defs['i2c_scl'], board_defs['i2c_sda']) 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_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' 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_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_capacitive' in board_defs.keys(): self.features.sensor.capacitive = True
if 'sen_temperature' in board_defs.keys(): self.features.sensor.temperature = 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 if 'sen_hall' in board_defs.keys(): self.features.sensor.hall_effect = True
@ -153,6 +159,17 @@ class esp32(uPyConfig):
'oled_height': 64, 'oled_height': 64,
'oled_width': 128, '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'): def __init__(self, variant='generic'):