-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauxiliary.py
More file actions
44 lines (34 loc) · 1.27 KB
/
auxiliary.py
File metadata and controls
44 lines (34 loc) · 1.27 KB
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
#!/usr/bin/env python
# Auxiliary functions, such as releasing GPIO
#-------------------------------------------------------------------------------
#### Imports ####
import time
import RPi.GPIO as gpio
#### Objects ####
#-------------------------------------------------------------------------------
class AuxiliaryHelp(object):
# Make sure there is only one instance of AuxiliaryHelp
_instances=[]
# Initialize the object
def __init__(self):
if ( len(self._instances)>1 ):
print("ERROR: One instance of AuxiliaryHelp is running already.")
exit(1)
self._instances.append(self)
#-------------------------------------------------------------------------------
#clean up GPIO
def cleanup (self):
gpio.cleanup()
#-------------------------------------------------------------------------------
#write a value to a log file
def writetofile (self,label,value):
logfile = 'logfile.txt'
mystring = label+': '+str(value)+'\n'
try:
f=open(logfile, 'a')
f.write(mystring)
print('Wrote the following to '+logfile+':\n'+label+': '+str(value)+'\n')
f.close()
except IOError:
print("cannot find file: " + logfile)
exit()