diff --git a/README.md b/README.md new file mode 100644 index 0000000..fe3368f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# G19_basic diff --git a/Verdana.ttf b/Verdana.ttf old mode 100644 new mode 100755 diff --git a/license.txt b/license.txt old mode 100644 new mode 100755 diff --git a/logitech/__init__.py b/logitech/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/__init__.py b/logitech/applets/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_bg_light/__init__.py b/logitech/applets/simple_bg_light/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_bg_light/simple_bg_light.py b/logitech/applets/simple_bg_light/simple_bg_light.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_clock/__init__.py b/logitech/applets/simple_clock/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_clock/simple_clock.py b/logitech/applets/simple_clock/simple_clock.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_display_brightness/__init__.py b/logitech/applets/simple_display_brightness/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_display_brightness/simple_display_brightness.py b/logitech/applets/simple_display_brightness/simple_display_brightness.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_slideshow/__init__.py b/logitech/applets/simple_slideshow/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_slideshow/simple_slideshow.py b/logitech/applets/simple_slideshow/simple_slideshow.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_timer/__init__.py b/logitech/applets/simple_timer/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/simple_timer/simple_timer.py b/logitech/applets/simple_timer/simple_timer.py old mode 100644 new mode 100755 diff --git a/logitech/applets/xplanet/__init__.py b/logitech/applets/xplanet/__init__.py old mode 100644 new mode 100755 diff --git a/logitech/applets/xplanet/xplanet.py b/logitech/applets/xplanet/xplanet.py old mode 100644 new mode 100755 diff --git a/logitech/g19.py b/logitech/g19.py old mode 100644 new mode 100755 index 2e9f1b2..0bd2f7c --- a/logitech/g19.py +++ b/logitech/g19.py @@ -416,8 +416,9 @@ def __init__(self, resetOnStart=False): self.handleIf1 = self.__lcd_device.open() self.handleIfMM = self.__kbd_device.open() config = self.__lcd_device.configurations[0] + #print len(config.interfaces[0]) iface0 = config.interfaces[0][0] - iface1 = config.interfaces[1][0] + iface1 = config.interfaces[0][1] try: self.handleIfMM.setConfiguration(1) @@ -461,4 +462,4 @@ def main(): lg19.stop_event_handling() if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/logitech/g19_config.py b/logitech/g19_config.py old mode 100644 new mode 100755 diff --git a/logitech/g19_keys.py b/logitech/g19_keys.py old mode 100644 new mode 100755 diff --git a/logitech/g19_mapper.py b/logitech/g19_mapper.py old mode 100644 new mode 100755 diff --git a/logitech/g19_menu.py b/logitech/g19_menu.py old mode 100644 new mode 100755 diff --git a/logitech/g19_qt.py b/logitech/g19_qt.py old mode 100644 new mode 100755 diff --git a/logitech/g19_receivers.py b/logitech/g19_receivers.py old mode 100644 new mode 100755 diff --git a/logitech/runnable.py b/logitech/runnable.py old mode 100644 new mode 100755 diff --git a/readme.txt b/readme.txt old mode 100644 new mode 100755 diff --git a/videos.py b/videos.py new file mode 100755 index 0000000..cf0dc7a --- /dev/null +++ b/videos.py @@ -0,0 +1,149 @@ +from logitech.g19 import G19 +import time +import os +import random +import cv2 +import ctypes +import subprocess +import signal +import sys +import thread + +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.CAP_PROP_FRAME_COUNT)) + fps = videoFile.get(cv2.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): + self.lg19.load_image(path) + +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/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: + for i in range(0): + path = pick_image.pick() + try: wallpaper.load(path) + except: print path + time.sleep(5) + + path = pick_video.pick() + + try: + print '[>] {}'.format(path) + audio.play(path) + video.play(path) + except: + print '[*] {}'.format(path) + audio.stop() + diff --git a/wallpaper.py b/wallpaper.py new file mode 100755 index 0000000..def2d87 --- /dev/null +++ b/wallpaper.py @@ -0,0 +1,66 @@ +from logitech.g19 import G19 +import os +import random +import time +import thread + +class WALLPAPER: + def __init__(self, lg19): + self.imgPath = 'wallpaper' + self.timeout = 60 + self.lg19 = lg19 + + def reloadImages(self): + self.files = os.listdir(self.imgPath) + random.shuffle(self.files,random.random) + + def changeImages(self): + for image in self.files: + self.lg19.load_image(os.path.join(self.imgPath, image)) + time.sleep(self.timeout) + + def play(self): + while True: + self.reloadImages() + self.changeImages() + +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 255 255"' + return False + for i in val: + try: + j = int(i) + except: + print 'Needs integer %s' % (i) + return False + if j<0 or j>255: + print 'Wrong value for color %d' % (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 color in "255 0 0" format' + while True: + if self.userInput(): + self.setColor() + print '[+] Settings applied' + else: + print '[-] Changes not applied' + +if __name__=="__main__": + lg19 = G19() + wp = WALLPAPER(lg19) + thread.start_new_thread(wp.play, ()) + cl = COLOR(lg19) + cl.play() diff --git a/wallpaper/9.jpg b/wallpaper/9.jpg new file mode 100755 index 0000000..d349ead Binary files /dev/null and b/wallpaper/9.jpg differ diff --git a/wallpaper2.py b/wallpaper2.py new file mode 100755 index 0000000..805ca25 --- /dev/null +++ b/wallpaper2.py @@ -0,0 +1,147 @@ +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) + + +