-
Notifications
You must be signed in to change notification settings - Fork 1
/
pibmc.py
78 lines (61 loc) · 2.33 KB
/
pibmc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import argparse
import sys
#import fakeRPiGPIO as GPIO
import RPi.GPIO as GPIO
import time
from pinbmc import PinBmc, DigitalPin
class PiPin(DigitalPin):
async def setup(self):
if self.is_valid_pin(self.pin):
if self.is_output: # input
GPIO.setup(self.pin, GPIO.IN)
else: # output
GPIO.setup(self.pin, GPIO.OUT, self.logic_level)
def get_true_logic_level(self):
return GPIO.HIGH
def get_false_logic_level(self):
return GPIO.LOW
async def write_logic_level(self):
if self.pin is not None:
GPIO.output(self.pin, self.logic_level)
raise ValueError("pin is None!")
async def read_logic_level(self, logic_level):
if self.pin is not None:
self.logic_level = GPIO.input(self.pin)
raise ValueError("pin is None!")
class PiBmc(PinBmc):
def __del__(self):
PinBmc.__del__(self)
GPIO.cleanup()
async def setup_power_status(self):
# create power status input pin
self.power_status = PiPin(self.status_pin, False,
self.initial_power_status_value, self.invert_status_pin_logic, self.loop)
await self.power_status.setup()
async def setup_power_button(self):
# create power output pin
self.power_button = PiPin(self.power_pin, True,
self.initial_power_button_value, self.invert_power_pin_logic, self.loop)
await self.power_button.setup()
async def setup_reset_button(self):
# create reset output pin
self.reset_button = PiPin(self.reset_pin, True,
self.initial_reset_button_value, self.invert_reset_pin_logic, self.loop)
await self.reset_button.setup()
def main():
parser = argparse.ArgumentParser(
prog='pibmc',
description='Raspberry Pi Baseboard Management Controller',
conflict_handler='resolve'
)
parser.add_argument('--port',
dest='port',
type=int,
default=623,
help='Port to listen on; defaults to 623')
args = parser.parse_args()
mybmc = PiBmc({}, {}, {}, port=args.port)
mybmc.listen()
if __name__ == '__main__':
sys.exit(main())