From efa877eba48a666403b927213d27962ed18b284a Mon Sep 17 00:00:00 2001 From: paspo Date: Sun, 18 Feb 2018 18:17:35 +0100 Subject: [PATCH] i2c bus support --- etc/openpdu/openpdu.conf | 1 + openpdu | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/etc/openpdu/openpdu.conf b/etc/openpdu/openpdu.conf index 9a7b7ac..ea44876 100644 --- a/etc/openpdu/openpdu.conf +++ b/etc/openpdu/openpdu.conf @@ -20,3 +20,4 @@ # type = i2c-out # address = 20 # channels = 8 +# bus = 1 diff --git a/openpdu b/openpdu index b584829..153a7aa 100755 --- a/openpdu +++ b/openpdu @@ -87,7 +87,7 @@ def getpower(outlet, json=False): class BoardI2COut(object): - def __init__(self, boardnum, channels=None, address=None): + def __init__(self, boardnum, channels=None, address=None, bus=None): self.boardnum = boardnum if channels is None: self.channels = 0 @@ -97,6 +97,12 @@ class BoardI2COut(object): self.address = 0x20 else: self.address = address + if bus is None: + self.bus = 1 + else: + self.bus = bus + if not glob.glob('/dev/i2c*'): + raise OSError('Cannot access I2C. Please ensure I2C is enabled') def toJSON(self): return {'boardnum':self.boardnum,'type':'i2c-out','channels':self.channels,'address':self.address} @@ -202,7 +208,8 @@ for s in configParser.sections(): elif bType=='i2c-out': channels = int(configParser.get(s, 'channels')) address = configParser.get(s, 'address') - b = BoardI2COut(boardnum=num, channels=channels, address=address) + bus = configParser.get(s, 'bus') + b = BoardI2COut(boardnum=num, channels=channels, address=address, bus=bus) _boards.append(b) if re.match('^outlet.*',s): num = int(re.sub(r'^outlet','',s))