forked from pburakov/hack_week_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
44 lines (35 loc) · 1.13 KB
/
utils.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
import netifaces as ni
import time
from config import SWITCH
with open('/sys/class/gpio/export', 'w') as gpio_export:
gpio_export.write("%d\n" % SWITCH)
with open('/sys/class/gpio/gpio%d/direction' % SWITCH, 'w') as gpio_direction:
gpio_direction.write('in\n')
def reset_onboard_led():
# Disable green onboard LED to indicate progress in headless run
led_trigger = open('/sys/class/leds/led0/trigger', 'w')
led_trigger.write('gpio')
led_trigger.close()
def blink_onboard_led():
led = open('/sys/class/leds/led0/brightness', 'w')
led.write('1')
led.close()
time.sleep(0.05)
led = open('/sys/class/leds/led0/brightness', 'w')
led.write('0')
led.close()
def read_test_switch():
switch = open('/sys/class/gpio/gpio%d/value' % SWITCH, 'r')
statusStr = switch.read().strip()
switch.close()
status = int(statusStr)
return status >= 1
def get_serial_pixel(x, y, size_y):
if x & 1 == 1:
i = (x + 1) * size_y - y - 1
else:
i = x * size_y + y
return i
def get_ip_address(ifname):
ni.ifaddresses(ifname)
return ni.ifaddresses(ifname)[ni.AF_INET][0]['addr']