Posted by & filed under Hardware, Programming, Projects, Python.

So I got one of these Cheap Chinese HID RGB LEDs the other day. The include software only interfaced with Outlook, sigh. Oh well, lets start poking around.

I found that the drive is for an HID (Human Interface Device) device so I opened python and grabbed pywinusb, which includes a HID helper class.

So again looking at the driver, I found that the vendor-id was 0x1294. This number 4278190081 for the report… I don’t remember how I found it…

But after finding out those two values I started throwing bits at it. I sent 0x0001 and to my surprise, the envlope started glowing green. There are 8 settings, and the mapping is as follows:

  • 0 – off
  • 1 – green
  • 2 – red
  • 3 – blu
  • 4 – teal
  • 5 – yelloish-green
  • 6 – purple
  • 7 – white(ish)

Bam… Disco Party In My Room

import time,random
import pywinusb.hid as hid

def get_device():
    all_devices = hid.HidDeviceFilter(vendor_id = 0x1294).get_devices()
    if len(all_devices)==0:
        print "Can't find target device"
    else:       
        return all_devices[0]
    return null    
    
def set_color(device,color):
    for report in device.find_output_reports():
        if 4278190081 in report:
            report[4278190081] =  [color,0,0,0,0]
            report.send()
                
if __name__ == '__main__':
    try:
        d = get_device()
        d.open()
        
        set_color(d,0)
        color = 0
        
        while True:
            nucolor = color                     # windows has a bad random,
            while color is nucolor:             # i saw a ten streak of 6's
                nucolor = random.randint(1, 7)  # so this forces it to change
            color = nucolor
            print color
            set_color(d,color)

            time.sleep(1)
        
    finally:
        d.close()

    exit()

Ok, Lets now grab my Reddit Inbox.

I quickly found the reddit_api python module, now called PRAW (Python Reddit API Wrapper), but it didn’t quite do what I wanted. [*Disclaimer: This might not be true with newer versions of PRAW]
So I forked it.
My changes include a direct way to access reddits unread message end-point.

With that in hand, we can build a script to check our unread messages.

#configure your details here
user = "" #reddit username
password = "" #reddit password
delay = 60*5 #delay in seconds between checking mail


#dont you dare look down past here!!!

import time
import pywinusb.hid as hid
import reddit

def get_device():
	all_devices = hid.HidDeviceFilter(vendor_id = 0x1294).get_devices()
	if len(all_devices)==0:
		print "Can't find target device"		
	else:		
		return all_devices[0]
	return null
	
	
def set_color(device,color):
	for report in device.find_output_reports():
		if 4278190081 in report:
			report[4278190081] =  [color,0,0,0,0] 
			report.send() 				

				
if __name__ == '__main__':	
	try:
		d = get_device()
		d.open()
		
		set_color(d,0)
		r = reddit.Reddit(user_agent="redmail")
		r.login(user=user,password=password)
		inbox = r.get_inbox()
		
		while True:			
			new = inbox.get_new_messages(force=True)
			if len(new) > 0:
				set_color(d,2)
			else:
				set_color(d,0)				
				
			time.sleep(delay)
		
	finally:
		d.close()

	exit()

And done, Reddit orangered’s on my desk.

The Github project: https://github.com/willwharton/redmail

Posted by & filed under Android, Java, Programming, Projects.

Redwall before it had a name, it started as a project with some pretty strange requirements. I wanted to build something on android with social-esque features, but I didn’t want to pay for lots of servers to handle massive amounts traffic. In fact, I didn’t want to spend any money or time after I built it. I wanted it to just work.

Use the force Luke

There are a few options for handling accounts. You could go with Facebook, Twitter, GitHub even. But one other website really got me thinking, Reddit. Reddit has a json (and xml) api that’s fairly straight forward and easy to use. Reddis api provides a mechanism for submitting, rating, and moderating content.

I came up with the idea of using Reddit and imgur.com to build a social wallpaper app. Complete with Archives, Rating, Comments, and Moderation. There are a lot of features missing, but for this project/experiment it didn’t really matter. I was satisfied with what I could achieve with Reddit’s free api.

Redwall was born!

All of the social features come from the reddit api. All the content in the app is feed via r/redwall. In more detail, it only lists imgur.com links from r/redwall.

There is no registration required to browse the wallpaper selection from the app (or even r/redwall for that matter,) which allows new users, the kind that just want to consume from the community a direct pass to the wallpapers. On the other hand, users must have a reddit account to submit to the gallery. And you can only submit from the Reddit, not from the app. But I don’t care. It works pretty well (their are definitely spots of code I need to update. Downloading in background, size filters, etc…). The source code is available on Github if you are interested in helping.

Best of all is I don’t pay a dime for the features that Reddit provides.

Where to grab Redwall

Redwall on Github: https://github.com/willwharton/redwallandroid
Redwall on Play: https://play.google.com/store/apps/details?id=com.kudzu.android.redwall
Redwall Pro on Play: https://play.google.com/store/apps/details?id=com.kudzu.android.redwall.pro

Redwall Android Market QR

Redwall Android Market QR

Redwall PRO Android Market QR

Redwall PRO Android Market QR