forked from jgyates/genmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgengpioin.py
98 lines (73 loc) · 3.44 KB
/
gengpioin.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
#------------------------------------------------------------
# FILE: gengpioin.py
# PURPOSE: genmon.py support program to allow GPIO inputs to control
# remote start, stop snd start/transfer functionality
# status LEDs
#
# AUTHOR: Jason G Yates
# DATE: 10-Apr-2016
#
# MODIFICATIONS:
#------------------------------------------------------------
import datetime, time, sys, signal, os, threading, socket
import atexit
from genmonlib import myclient, mylog
import RPi.GPIO as GPIO
# These are the GPIP pins numbers on the Raspberry PI GPIO header
# https://www.element14.com/community/servlet/JiveServlet/previewBody/73950-102-10-339300/pi3_gpio.png
INPUT_STOP = 11 # STOP GPIO 17
INPUT_START = 13 # START GPIO 27
INPUT_START_TRANSFER = 15 # START/TRANSFER GPIO 22
#---------- Signal Handler ------------------------------------------
def signal_handler(signal, frame):
GPIO.remove_event_detect(INPUT_STOP)
GPIO.remove_event_detect(INPUT_START)
GPIO.remove_event_detect(INPUT_START_TRANSFER)
GPIO.cleanup()
MyClientInterface.Close()
sys.exit(0)
#------------------- StopCallback -----------------#
def StopCallBack():
try:
MyClientInterface.ProcessMonitorCommand("generator: setremote=stop")
except Exception as e1:
log.error("Error: " + str(e1))
#------------------- StartCallBack -----------------#
def StartCallBack():
try:
MyClientInterface.ProcessMonitorCommand("generator: setremote=start")
except Exception as e1:
log.error("Error: " + str(e1))
#------------------- StartTransferCallBack -----------------#
def StartTransferCallBack():
try:
MyClientInterface.ProcessMonitorCommand("generator: setremote=starttransfer")
except Exception as e1:
log.error("Error: " + str(e1))
#------------------- Command-line interface for gengpioin -----------------#
if __name__=='__main__': # usage program.py [server_address]
address='127.0.0.1' if len(sys.argv)<2 else sys.argv[1]
try:
log = mylog.SetupLogger("client", "gengpioin.log")
# Set the signal handler
signal.signal(signal.SIGINT, signal_handler)
MyClientInterface = myclient.ClientInterface(host = address, log = log)
#setup GPIO using Board numbering
GPIO.setmode(GPIO.BOARD)
print GPIO.RPI_INFO
GPIO.setwarnings(True)
GPIO.setup(INPUT_STOP, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input, set internal pull up resistor#
GPIO.add_event_detect(INPUT_STOP, GPIO.FALLING) # detect falling edge
GPIO.add_event_callback(INPUT_STOP, callback = StopCallBack) #, bouncetime=1000)
GPIO.setup(INPUT_START, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input, set internal pull up resistor#
GPIO.add_event_detect(INPUT_START, GPIO.FALLING) # detect falling edge
GPIO.add_event_callback(INPUT_START, callback = StartCallBack) #, bouncetime=1000)
GPIO.setup(INPUT_START_TRANSFER, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input, set internal pull up resistor#
GPIO.add_event_detect(INPUT_START_TRANSFER, GPIO.FALLING) # detect falling edge
GPIO.add_event_callback(INPUT_START_TRANSFER, callback = StartTransferCallBack) #, bouncetime=1000)
while True:
time.sleep(3)
except Exception as e1:
log.error("Error: " + str(e1))
print ("Error: " + str(e1))