forked from OpenPDU/openpdu
preliminary I2C support
This commit is contained in:
parent
efa877eba4
commit
4da032952a
2
APKBUILD
2
APKBUILD
@ -7,7 +7,7 @@ pkgdesc="OpenPDU project - main binary"
|
||||
url="https://github.com/openpdu/openpdu"
|
||||
arch="noarch"
|
||||
license="GPL2"
|
||||
depends="python py-argh apk-cron"
|
||||
depends="python py-argh apk-cron i2c-tools"
|
||||
makedepends=""
|
||||
install="openpdu.post-install"
|
||||
subpackages=""
|
||||
|
34
openpdu
34
openpdu
@ -4,7 +4,9 @@ import os
|
||||
import sys
|
||||
import argh
|
||||
from argh import arg
|
||||
from subprocess import call
|
||||
import re
|
||||
import glob
|
||||
import ConfigParser
|
||||
import json as JSON
|
||||
|
||||
@ -30,6 +32,14 @@ def boards(json=False):
|
||||
b += board.toSTR()
|
||||
return '\nBoards:\n' + b
|
||||
|
||||
|
||||
def initboards():
|
||||
'initialize boards'
|
||||
for board in _boards:
|
||||
board.init()
|
||||
return
|
||||
|
||||
|
||||
@arg('-j', '--json', help="output in json")
|
||||
def outlets(json=False):
|
||||
'dump outlets configuration'
|
||||
@ -85,7 +95,7 @@ def getpower(outlet, json=False):
|
||||
|
||||
|
||||
|
||||
|
||||
# MCP23008
|
||||
class BoardI2COut(object):
|
||||
def __init__(self, boardnum, channels=None, address=None, bus=None):
|
||||
self.boardnum = boardnum
|
||||
@ -111,10 +121,19 @@ class BoardI2COut(object):
|
||||
return ' Board %s\n Type: i2c-out\n Channels: %s\n Address: %s\n\n' % (self.boardnum,self.channels,self.address)
|
||||
|
||||
def setpower(self, channel, power):
|
||||
return
|
||||
d = self.getpower(channel)
|
||||
mask = 1 << channel
|
||||
d &= ~mask
|
||||
if power:
|
||||
d |= mask
|
||||
#i2cset -y 1 0x20 0x09 0xFF
|
||||
return os.popen("/usr/sbin/i2cset -y %s %s 0x09 0x%s" % (self.bus, self.address, format(d, '02x'))).read()
|
||||
|
||||
def getpower(self, channel):
|
||||
return False
|
||||
return os.popen("/usr/sbin/i2cget -y %s %s 0x09" % (self.bus, self.address)).read()
|
||||
|
||||
def init(self):
|
||||
call(["/usr/sbin/i2cset", "-y", self.bus, self.address, "0x00", "0x00"])
|
||||
|
||||
|
||||
class BoardGpioOut(object):
|
||||
@ -151,6 +170,13 @@ class BoardGpioOut(object):
|
||||
f = open(fn,'r')
|
||||
return int(f.read()) == 0
|
||||
|
||||
def init(self):
|
||||
for gpio in self.gpios:
|
||||
open('/sys/class/gpio/export','w').write(str(gpio))
|
||||
fn = '/sys/class/gpio/gpio%s/direction' % gpio
|
||||
open(fn,'w').write('out')
|
||||
return
|
||||
|
||||
|
||||
class Outlet(object):
|
||||
def __init__(self, outletnum, boardnum, channel):
|
||||
@ -221,7 +247,7 @@ for s in configParser.sections():
|
||||
_outlets.append(o)
|
||||
|
||||
parser = argh.ArghParser()
|
||||
parser.add_commands([setpower, getpower, outlets, boards, version])
|
||||
parser.add_commands([setpower, getpower, outlets, boards, initboards, version])
|
||||
|
||||
# dispatching:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user