-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGpioPower.py
executable file
·68 lines (54 loc) · 1.58 KB
/
GpioPower.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
#!/usr/bin/python3
#-*- coding:utf-8 -*-
import RPi.GPIO as GPIO
sensor_pins={'air':12,'dht':35,'pcf':7}
led_pins={'green':40,'yellow':38,'red':36}
bl_pin=23
def _GPIO_Power_Regist(pins):
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup( pins , GPIO.OUT)
return
def _GPIO_Power_UnRegist(pins):
GPIO.cleanup(pins)
return
def _GPIO_Power_Set(pins, on):
if on==1:
GPIO.output( pins, GPIO.HIGH)
else :
GPIO.output( pins, GPIO.LOW )
return
#=====================================
def power_init_all():
_GPIO_Power_Regist(list(sensor_pins.values()))
_GPIO_Power_Regist(list(led_pins.values()))
#_GPIO_Power_Regist(bl_pin)
return
def power_deinit_all():
_GPIO_Power_UnRegist(list(sensor_pins.values()))
_GPIO_Power_UnRegist(list(led_pins.values()))
#_GPIO_Power_UnRegist(bl_pin)
return
def power_init_sensor():
_GPIO_Power_Regist(list(sensor_pins.values()))
return
def power_deinit_sensor():
_GPIO_Power_UnRegist(list(sensor_pins.values()))
return
def power_init_led():
_GPIO_Power_Regist(list(led_pins.values()))
return
def power_deinit_led():
_GPIO_Power_UnRegist(list(led_pins.values()))
return
def set_led_power(green, yellow, red):
_GPIO_Power_Set(led_pins['green'], green)
_GPIO_Power_Set(led_pins['yellow'], yellow)
_GPIO_Power_Set(led_pins['red'], red)
return
def set_backlight_power(on):
#_GPIO_Power_Set(bl_pin, on)
return
def set_sensor_power(on):
_GPIO_Power_Set(list(sensor_pins.values()), on)
return