forked from sblatt/Logitech-G19-Linux-Daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallpaper2.py
More file actions
executable file
·147 lines (121 loc) · 3.91 KB
/
wallpaper2.py
File metadata and controls
executable file
·147 lines (121 loc) · 3.91 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from logitech.g19 import G19
import time
import os
import random
import cv2
import ctypes
import subprocess
import signal
import sys
import thread
import random
class AUDIOPLAYER:
def __init__(self):
pass
def play(self, path):
self.audio = subprocess.Popen(['mplayer', '-msglevel','all=-1', '-novideo', '-slave', path], stderr=subprocess.PIPE)
def stop(self):
self.audio.send_signal(2)
class COLOR:
def __init__(self, lg19):
self.lg19 = lg19
def userInput(self):
inp = raw_input()
val = inp.split(' ')
if len(val) != 3:
print 'Syntax Error. Combination is "255 0 0"'
return False
for i in val:
try:
j = int(i)
except:
print 'Needs integer {}'.format(i)
return False
if j<0 or j>255:
print 'Wrong color code {}'.format(j)
return False
self.value = val
return True
def setColor(self):
self.lg19.set_bg_color(int(self.value[0]), int(self.value[1]), int(self.value[2]))
def play(self):
print 'Enter rgb color in "255 128 128" format'
while True:
if self.userInput():
self.setColor()
print '[+] Settings applied'
else:
print '[-] Changes not applied'
class VIDEOPLAYER:
def __init__(self, lg19):
self.libc = ctypes.CDLL('libc.so.6')
self.lg19 = lg19
def play(self, path):
videoFile = cv2.VideoCapture(path)
nFrames = int(videoFile.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
fps = videoFile.get(cv2.cv.CV_CAP_PROP_FPS)
frame_gap = 1/fps
uexpected_time = int(frame_gap * 1000000)
usleep = uexpected_time
for i in xrange(nFrames):
t1 = time.time()
self.libc.usleep(usleep)
try:
ret, frame = videoFile.read()
frame = cv2.resize(frame, (320, 240))
frame = cv2.transpose(frame)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2BGR565)
data = frame.flatten('C').tolist()
except:
return
self.lg19.send_frame(data)
t2 = time.time()
time_taken = t2-t1
utime_taken = int(time_taken*1000000)
uextra_time = utime_taken - uexpected_time
usleep = int(usleep - uextra_time)
if usleep < 1:
usleep = 1
class WALLPAPER:
def __init__(self, lg19):
self.lg19 = lg19
def load(self, path):
img = cv2.imread(path)
img = cv2.resize(img, (320, 240))
img = cv2.transpose(img)
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGR565)
data = img.flatten('C').tolist()
self.lg19.send_frame(data)
class ROULETTE:
def __init__(self, path=''):
self.root = path
def pick(self, include_hidden=False, extension=''):
while True:
dirs = os.listdir(self.root)
pick = random.choice(dirs)
path = os.path.join(self.root, pick)
if os.path.isfile(path) and pick.endswith(extension):
if include_hidden==True or not pick.startswith('.'):
break
return path
if __name__=="__main__":
def signal_handler(signal, frame):
print('Quitting')
audio.stop()
sys.exit(0)
video_dir = '/home/sumit/data/My Passport/multimedia/video/'
image_dir = 'wallpaper'
lg19 = G19()
audio = AUDIOPLAYER()
video = VIDEOPLAYER(lg19)
color = COLOR(lg19)
wallpaper = WALLPAPER(lg19)
thread.start_new_thread(color.play, ())
pick_video = ROULETTE(video_dir)
pick_image = ROULETTE(image_dir)
while True:
sleep = random.randint(1, 20)
path = pick_image.pick()
try: wallpaper.load(path)
except: print path
time.sleep(sleep)