minor tweaks

This commit is contained in:
ewall
2010-09-01 20:22:10 -04:00
parent 3585cc37ea
commit 875f47a9ae
2 changed files with 83 additions and 56 deletions

8
README
View File

@@ -6,14 +6,10 @@ released under MIT License (http://www.opensource.org/licenses/mit-license.php)
-----
Description:
Instead of using your i-buddy (http://www.i-buddy.com) with MSN Messenger, why not use it to show other info?
With pybuddy, you can control your i-buddy to do any of the supported actions: change head color, blink its
heart, beat its wings, etc. Example uses are: monitoring a website traffic (404s in red, 500s beating wings,
200s in green), showing your project's continuous integration process, ...and so on.
Instead of using your i-buddy (http://www.i-buddy.com) with MSN Messenger, why not use it to show other info? With pybuddy, you can control your i-buddy to do any of the supported actions: change head color, blink its heart, beat its wings, etc. Example uses are: monitoring a website traffic (404s in red, 500s beating wings, 200s in green), showing your project's continuous integration process, ...and so on.
Dependencies:
The daemon is written in python, runs on Linux and needs python-usb. To install on Debian, use
`apt-get install python-usb`; on RedHat, `yum install pyusb`. (Or `easy_install python-usb`?)
The daemon is written in python, runs on Linux and needs python-usb. To install on Debian, use `apt-get install python-usb`; on RedHat, `yum install pyusb`. (Or `easy_install python-usb`?)
Software using pybuddy:
Beside the scripts published in the contrib directory, there is other software using pybuddy:

View File

@@ -1,17 +1,14 @@
import usb
import time
import sys
from time import sleep
################
#Configuration
################
tsleep = 0.1
## configuration
tsleep = 0.5
usbvendor = 0x1130
usbproduct = 0001
################
# IBUDDY class
################
## iBUDDY class
class BuddyDevice:
SETUP = (0x22, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00)
MESS = (0x55, 0x53, 0x42, 0x43, 0x00, 0x40, 0x02)
@@ -26,10 +23,9 @@ class BuddyDevice:
battery = 0
product = 0
def __init__(self, battery, buddy_product):
try:
self.dev=UsbDevice(0x1130, buddy_product, battery)
self.dev=UsbDevice(usbvendor, buddy_product, battery)
self.dev.open()
self.dev.handle.reset()
self.resetMessage()
@@ -39,7 +35,7 @@ class BuddyDevice:
except NoBuddyException, e:
raise NoBuddyException()
# Commands are sent as disabled bits
# commands are sent as disabled bits
def setReverseBitValue(self,num,value):
if (value==1):
temp = 0xFF - (1<<num)
@@ -97,22 +93,18 @@ class BuddyDevice:
return self.getReverseBitValue(1)
def send(self, inp):
"""
try:
self.dev.handle.controlMsg(0x21, 0x09, self.SETUP, 0x02, 0x01)
self.dev.handle.controlMsg(0x21, 0x09, self.MESS+(inp,), 0x02, 0x01)
except usb.USBError:
print "USB error!"
self.__init__(self.battery,buddy_product)
"""
#self.dev.handle.controlMsg(0x21, 0x09, self.SETUP, 0x02, 0x01)
#self.dev.handle.controlMsg(0x22, 0x09, self.SETUP, 0x02, 0x01)
self.dev.handle.controlMsg(0x21, 0x09, self.MESS+(inp,), 0x02, 0x01)
#####################
# USB class
######################
#self.dev.handle.controlMsg(0x21, 0x09, self.MESS+(inp,), 0x02, 0x01)
## USB class
class UsbDevice:
def __init__(self, vendor_id, product_id, skip):
busses = usb.busses()
@@ -142,7 +134,7 @@ class UsbDevice:
if self.handle:
self.handle = None
self.handle = self.dev.open()
#We need to detach HID interface
# we need to detach HID interface
try:
self.handle.detachKernelDriver(0)
self.handle.detachKernelDriver(1)
@@ -159,7 +151,7 @@ class NoBuddyException(Exception): pass
# MAIN program
#######################################
#Initialize device
# initialize device
print "Starting search..."
try:
buddy=BuddyDevice(0, int(usbproduct))
@@ -169,5 +161,44 @@ except NoBuddyException, e:
buddy.resetMessage()
buddy.pumpMessage()
buddy.setHeart(1)
sleep(0.5)
buddy.setHeadColor(1,0,0)
buddy.pumpMessage()
sleep(0.5)
buddy.setHeadColor(0,1,0)
buddy.pumpMessage()
sleep(0.5)
buddy.setHeadColor(0,0,1)
buddy.pumpMessage()
sleep(0.5)
buddy.flick(BuddyDevice.LEFT)
buddy.pumpMessage()
sleep(0.5)
buddy.flick(BuddyDevice.RIGHT)
buddy.pumpMessage()
sleep(0.5)
buddy.flick(BuddyDevice.LEFT)
buddy.pumpMessage()
sleep(0.5)
buddy.flick(BuddyDevice.RIGHT)
buddy.pumpMessage()
sleep(0.1)
buddy.wing(BuddyDevice.UP)
buddy.pumpMessage()
sleep(0.1)
buddy.wing(BuddyDevice.DOWN)
buddy.pumpMessage()
sleep(0.1)
buddy.wing(BuddyDevice.UP)
buddy.pumpMessage()
sleep(0.1)
buddy.wing(BuddyDevice.DOWN)
buddy.pumpMessage()
sleep(0.1)
buddy.wing(BuddyDevice.UP)
buddy.pumpMessage()
sleep(0.1)
buddy.wing(BuddyDevice.DOWN)
buddy.pumpMessage()
buddy.setHeadColor(0,0,0)
buddy.pumpMessage()