Initial hatctl state

This commit is contained in:
Reid 'arrdem' McKenzie 2021-10-11 21:22:49 -06:00
parent 20f42926b4
commit 1500cc4352
4 changed files with 1100 additions and 0 deletions

15
projects/hatctl/BUILD Normal file
View 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
View 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

File diff suppressed because it is too large Load diff

View 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