forked from ezeakeal/pyBus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyBus_core.py
57 lines (46 loc) · 1.52 KB
/
pyBus_core.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
#!/usr/bin/python
import os
import sys
import time
import json
import signal
import logging
import binascii
import subprocess
from time import strftime as date
sys.path.append( './lib/' )
# Here we import the two types of drivers. The event driven driver, and the ticking driver.
import pyBus_eventDriver as pB_eDriver # For responding to signals
from pyBus_interface import *
#####################################
# GLOBALS
#####################################
DEVPATH = "/dev/ttyUSB0" # This is a default, but its always overridden. So not really a default.
IBUS = None
REGISTERED = False # This is a temporary measure until state driven behaviour is implemented
#####################################
# FUNCTIONS
# Initializes modules as required and opens files for writing
def initialize():
global IBUS, REGISTERED, DEVPATH
REGISTERED=False
# Initialize the iBus interface or wait for it to become available.
while IBUS == None:
if os.path.exists(DEVPATH):
IBUS = ibusFace(DEVPATH)
else:
logging.warning("USB interface not found at (%s). Waiting 1 seconds.", DEVPATH)
time.sleep(2)
IBUS.waitClearBus() # Wait for the iBus to clear, then send some initialization signals
pB_eDriver.init(IBUS)
# close the USB device and whatever else is required
def shutdown():
global IBUS
logging.info("Shutting down event driver")
pB_eDriver.shutDown()
if IBUS:
logging.info("Killing iBUS instance")
IBUS.close()
IBUS = None
def run():
pB_eDriver.listen()