-
Notifications
You must be signed in to change notification settings - Fork 2
/
switch.py
executable file
·57 lines (47 loc) · 1.57 KB
/
switch.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/python2.7
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import time
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.FT232H as FT232H
def switch(mode):
# FT232H.use_FT232H()
ft232h = FT232H.FT232H()
ft232h.setup(8, GPIO.IN)
ft232h.setup(9, GPIO.OUT)
ft232h.output(9, GPIO.HIGH)
ft232h.setup(10, GPIO.OUT)
ft232h.output(10, GPIO.LOW)
if mode == "toggle":
do_toggle(ft232h)
else:
do_clear(ft232h)
if mode == "run":
do_toggle(ft232h)
def do_toggle(ft232h):
ft232h.output(9, GPIO.LOW)
time.sleep(0.1)
ft232h.output(9, GPIO.HIGH)
def do_clear(ft232h):
ft232h.output(10, GPIO.HIGH)
time.sleep(0.1)
ft232h.output(10, GPIO.LOW)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Control the USB switcher.")
parser.add_argument("mode", choices=["toggle", "run", "debug"],
default="toggle", nargs='?',
help="what mode the USB switcher should be placed into")
args = parser.parse_args()
switch(args.mode)