From 9fdf31e28b3bfb081d9df95bbf3843e11842e2f2 Mon Sep 17 00:00:00 2001 From: Sumit Date: Sat, 21 Oct 2017 15:31:56 +0530 Subject: [PATCH 1/4] Fixed overflow byte error and ubuntu usb support --- logitech/g19.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/logitech/g19.py b/logitech/g19.py index 2e9f1b2..bbdf9ae 100644 --- a/logitech/g19.py +++ b/logitech/g19.py @@ -63,7 +63,7 @@ def convert_image_to_frame(filename): for y in range(240): r, g, b = access[x, y] val = G19.rgb_to_uint16(r, g, b) - data.append(val >> 8) + data.append((val >> 8) & 0xff) data.append(val & 0xff) return data @@ -87,7 +87,7 @@ def convert_text_to_image(text): for y in range(240): r, g, b = access[x, y] val = G19.rgb_to_uint16(r, g, b) - data.append(val >> 8) + data.append((val >> 8) & 0xff) data.append(val & 0xff) return data @@ -125,7 +125,7 @@ def fill_display_with_color(self, r, g, b): # saved in little-endian, because USB is little-endian value = self.rgb_to_uint16(r, g, b) valueH = value & 0xff - valueL = value >> 8 + valueL = (value >> 8) & 0xff frame = [valueL, valueH] * (320 * 240) self.send_frame(frame) @@ -350,8 +350,8 @@ def set_display_colorful(self): data.append(0) for x in range(320): for y in range(240): - data[2*(x*240+y)] = self.rgb_to_uint16( - 255 * x / 320, 255 * (320 - x) / 320, 255 * y / 240) >> 8 + data[2*(x*240+y)] = (self.rgb_to_uint16( + 255 * x / 320, 255 * (320 - x) / 320, 255 * y / 240) >> 8) & 0xff data[2*(x*240+y)+1] = self.rgb_to_uint16( 255 * x / 320, 255 * (320 - x) / 320, 255 * y / 240) & 0xff self.send_frame(data) @@ -417,7 +417,7 @@ def __init__(self, resetOnStart=False): self.handleIfMM = self.__kbd_device.open() config = self.__lcd_device.configurations[0] iface0 = config.interfaces[0][0] - iface1 = config.interfaces[1][0] + iface1 = config.interfaces[0][1] try: self.handleIfMM.setConfiguration(1) @@ -461,4 +461,4 @@ def main(): lg19.stop_event_handling() if __name__ == '__main__': - main() \ No newline at end of file + main() From 791115e3870c851779cae75d3c88decfffa5fbc8 Mon Sep 17 00:00:00 2001 From: Sumit Date: Sat, 28 Oct 2017 09:12:17 +0530 Subject: [PATCH 2/4] Project reboot --- readme.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/readme.txt b/readme.txt index 0a82338..7e5a5b9 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,6 @@ -************IMPORTANT****************** - -I stoped working on this project as I'm now involved in an even better project for the Logitech G19: - -http://g19linux.sourceforge.net/ - -If you want to continue this deamon, feel free to do so, or just join us at sourceforge! +I am working on it just to make it work with my keyboard. +Using python here instead of other codes is primarily for fun and learning. +I am not trying to make it high-end fully functional driver, rather something fun to play with. *************************************** From 238ee20a0ad764ff0eb141b39c11f87366af552a Mon Sep 17 00:00:00 2001 From: Sumit Date: Sat, 28 Oct 2017 09:13:38 +0530 Subject: [PATCH 3/4] Video player for G19 play videos --- video.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 video.py diff --git a/video.py b/video.py new file mode 100644 index 0000000..6382a48 --- /dev/null +++ b/video.py @@ -0,0 +1,94 @@ +from logitech.g19 import G19 +import time +import os +import random +import cv2 +import ctypes +import subprocess +import signal +import sys + +class AUDIOPLAYER: + def __init__(self): + pass + + def play(self, path): + self.audio = subprocess.Popen(['mplayer', '-msglevel','all=-1', '-novideo', path], stderr=subprocess.PIPE) + + def stop(self): + self.audio.send_signal(2) + + +class VIDEOPLAYER: + def __init__(self): + self.libc = ctypes.CDLL('libc.so.6') + self.lg19 = G19() + + + 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 + + while (videoFile.isOpened()): + 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: + pass + 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 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(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) + + root = '/home/sumit/data/My Passport/multimedia/video/' + audio = AUDIOPLAYER() + video = VIDEOPLAYER() + lottery = ROULETTE(root) + + + while True: + path = lottery.pick() + + try: + print '[>] {}'.format(path) + audio.play(path) + video.play(path) + except: + print '[*] {}'.format(path) + audio.stop() + time.sleep(10) From a722977449e826c53d3fc3bc07144bb1d3345383 Mon Sep 17 00:00:00 2001 From: Sumit Date: Sun, 29 Oct 2017 13:07:57 +0530 Subject: [PATCH 4/4] Updated color changing and wallpaper --- video.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/video.py b/video.py index 6382a48..e0d721c 100644 --- a/video.py +++ b/video.py @@ -7,22 +7,57 @@ 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', path], stderr=subprocess.PIPE) + 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): + def __init__(self, lg19): self.libc = ctypes.CDLL('libc.so.6') - self.lg19 = G19() + self.lg19 = lg19 def play(self, path): @@ -33,7 +68,7 @@ def play(self, path): uexpected_time = int(frame_gap * 1000000) usleep = uexpected_time - while (videoFile.isOpened()): + for i in xrange(nFrames): t1 = time.time() self.libc.usleep(usleep) try: @@ -43,7 +78,7 @@ def play(self, path): frame = cv2.cvtColor(frame, cv2.COLOR_BGR2BGR565) data = frame.flatten('C').tolist() except: - pass + return self.lg19.send_frame(data) t2 = time.time() time_taken = t2-t1 @@ -54,6 +89,13 @@ def play(self, path): 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 @@ -62,7 +104,7 @@ def pick(self, include_hidden=False, extension=''): while True: dirs = os.listdir(self.root) pick = random.choice(dirs) - path = os.path.join(root, pick) + 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 @@ -75,14 +117,27 @@ def signal_handler(signal, frame): audio.stop() sys.exit(0) - root = '/home/sumit/data/My Passport/multimedia/video/' + video_dir = '../multimedia/video/' + image_dir = 'wallpaper' + lg19 = G19() audio = AUDIOPLAYER() - video = VIDEOPLAYER() - lottery = ROULETTE(root) + 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: - path = lottery.pick() + for i in range(5): + path = pick_image.pick() + try: wallpaper.load(path) + except: print path + time.sleep(5) + + path = pick_video.pick() try: print '[>] {}'.format(path) @@ -91,4 +146,3 @@ def signal_handler(signal, frame): except: print '[*] {}'.format(path) audio.stop() - time.sleep(10)