-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpi.py
57 lines (48 loc) · 2.09 KB
/
pi.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
# *****BatteryMonitor main file batteries.py*****
# Copyright (C) 2014 Simon Richard Matthews
# Project loaction https://github.com/simat/BatteryMonitor
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#!/usr/bin/python
import RPi.GPIO as gpio
import threading
from time import sleep
from time import time
class Rawdat():
"""class for using the raspberry Pi for IO"""
savedinvertermap ={}
def __init__(self,InterfacesInUse):
self.gpio=gpio
self.gpio.setmode(self.gpio.BOARD)
self.gpio.setup(11, self.gpio.OUT, initial = 1)
self.gpio.setup(13, self.gpio.OUT, initial = 0)
def getdata(self):
print (self.gpio.input(11),self.gpio.input(13))
def backgroundswapinv(self,on,off):
print(on,off)
self.gpio.output(on,1)
sleep(20) # wait for second inverter to power up and syncronise
self.gpio.output(off,0)
def swapinverter(self,on,off):
"""turns on inverter controlled by Pi pin number if on arg and turns off
inverter controlled by Pi pin number in off arg"""
threading.Thread(target=self.backgroundswapinv,args=(self,on,off)).start()
def allinvon(self,batdata,pins):
""" turn on inverters in pins list, save current inverter map"""
batdata.pip.timeoverload=time()
for pin in pins:
self.savedinvertermap[pin]=self.gpio.input(pin)
self.gpio.output(pin,1)
def restoreinverters(self):
""" restore saved invertermap"""
for pin in self.savedinvertermap:
self.gpio.output(pin,self.savedinvertermap[pin])