Initial hatctl state
This commit is contained in:
parent
20f42926b4
commit
1500cc4352
4 changed files with 1100 additions and 0 deletions
15
projects/hatctl/BUILD
Normal file
15
projects/hatctl/BUILD
Normal file
|
@ -0,0 +1,15 @@
|
|||
py_project(
|
||||
name = "lib"
|
||||
)
|
||||
|
||||
zapp_binary(
|
||||
name = "hatctl",
|
||||
main = "src/python/hatctl/__main__.py",
|
||||
imports = [
|
||||
"src/python",
|
||||
],
|
||||
deps = [
|
||||
":lib",
|
||||
py_requirement("click"),
|
||||
],
|
||||
)
|
10
projects/hatctl/README.md
Normal file
10
projects/hatctl/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# hatctl
|
||||
|
||||
A fork of [clusterctl](https://github.com/burtyb/clusterhat-image/blob/master/files/usr/sbin/clusterctrl) which serves to fix innumerable packaging problems.
|
||||
|
||||
## license
|
||||
|
||||
This software is published under the MIT License
|
||||
|
||||
Copyright (c) 2018 Chris Burton (8086 consultancy)
|
||||
Copyright (c) 2021 Reid McKenzie
|
1010
projects/hatctl/src/python/hatctl/__main__.py
Normal file
1010
projects/hatctl/src/python/hatctl/__main__.py
Normal file
File diff suppressed because it is too large
Load diff
65
projects/hatctl/src/python/hatctl/xra1200.py
Normal file
65
projects/hatctl/src/python/hatctl/xra1200.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
import smbus
|
||||
|
||||
|
||||
# Registers
|
||||
# Direction
|
||||
IN = 0x00
|
||||
OUT = 0x01
|
||||
DIR = 0x03
|
||||
PUR = 0x04
|
||||
|
||||
INPUT = 1
|
||||
OUTPUT = 0
|
||||
|
||||
|
||||
class Xra1200:
|
||||
bus = -1
|
||||
address = -1
|
||||
port = -1
|
||||
|
||||
def __init__(self, bus=0, address=0x39, port=0, dir="Null"):
|
||||
self.bus = smbus.SMBus(bus)
|
||||
self.address = address
|
||||
self.port = port
|
||||
if dir == 1:
|
||||
self.set_input()
|
||||
elif dir == 0:
|
||||
self.set_output()
|
||||
|
||||
def set_dir(self, dir):
|
||||
self.bus.write_byte_data(self.address, DIR, dir)
|
||||
|
||||
def get_dir(self):
|
||||
return self.bus.read_byte_data(self.address, DIR)
|
||||
|
||||
def set_pur(self, pur):
|
||||
self.bus.write_byte_data(self.address, PUR, pur)
|
||||
|
||||
def get_pur(self):
|
||||
try:
|
||||
reg = self.bus.read_byte_data(self.address, PUR)
|
||||
except IOError as err:
|
||||
return -1
|
||||
return reg
|
||||
|
||||
def set_input(self):
|
||||
state = self.bus.read_byte_data(self.address, DIR)
|
||||
self.bus.write_byte_data(self.address, DIR, state | 1 << self.port)
|
||||
|
||||
def write_byte(self, data):
|
||||
self.bus.write_byte_data(self.address, OUT, data)
|
||||
|
||||
def read_byte(self):
|
||||
return self.bus.read_byte_data(self.address, IN)
|
||||
|
||||
def on(self):
|
||||
state = self.bus.read_byte_data(self.address, OUT)
|
||||
self.bus.write_byte_data(self.address, OUT, state | 1 << self.port)
|
||||
|
||||
def off(self):
|
||||
state = self.bus.read_byte_data(self.address, OUT)
|
||||
self.bus.write_byte_data(self.address, OUT, state & (255 - (1 << self.port)))
|
||||
|
||||
def get(self):
|
||||
state = self.bus.read_byte_data(self.address, IN)
|
||||
return (state >> self.port) & 1
|
Loading…
Reference in a new issue