-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeviceManager.py
More file actions
executable file
·31 lines (24 loc) · 889 Bytes
/
DeviceManager.py
File metadata and controls
executable file
·31 lines (24 loc) · 889 Bytes
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
import RPi.GPIO as GPIO
from Sonar import Sonar
from Relay import Relay
class DeviceManager:
deviceClasses = {'sonar': Sonar, 'relay': Relay}
def __init__(self, devicesConfig):
GPIO.setmode(GPIO.BCM)
self.devicesConfig = devicesConfig
self.deviceInstances = {}
for section in self.devicesConfig.sections():
deviceClassName = section.split('.')[0]
deviceName = section.split('.')[1]
deviceClass = DeviceManager.deviceClasses[deviceClassName]
args = []
for (key, val) in self.devicesConfig.items(section):
args.append(val)
instance = None
if(section == 'sonar'):
instance = deviceClass(int(args[0]), int(args[1]))
else:
instance = deviceClass(int(args[0]), int(args[1]))
self.deviceInstances[deviceName] = instance
def cleanup(self):
GPIO.cleanup()