BUG Community

Welcome! Log In

JOcanto's Blog

New Python Libraries for Bug

One the greatest features of the BUG is the amazing Bug Java Framework (not an official name yet, but I hope it'll catch on), which provides: modularity, tons for services, low level interaction with modules, etc. Without doubts, Bug Java Framework is the de facto system to write applications for BUG. However, many programming languages are supported by BUG, for example python and ruby come pre-installed in R1.4.3

If you want to write python apps for BUG, the Develop with Python wiki page is a must read. The downside of using python on BUG is the number of bug-python libraries is really limited (VonHippel been the only one).

So, I decided to help the cause and put in practice my new-acquired python skills and implement a couple of libraries: BugBaseController.py and InputEventProvider.py.

BugBaseController.py , as its Java counterpart, controls the LEDs on the BUG Base; using the library is very simple:

#Import the Library import BUGBaseControl #Create a new instance of the class base = BUGBaseControl.BUGBaseControl() # Now we can turn on a LED base.setLED(BUGBaseControl.HOTKEY_LED_1) # With this method we can turn off the LED base.clearLED(BUGBaseControl.HOTKEY_LED_1) # After you're done , remember to close it base.close()

The InputProvider.py is equally simple to use:

# We need to create a class that will work as our Observer, # the class only need to have a method called update class EventViewer: def update(self, events): # events is a list of ButtonEvent passed by the InputProvider if events[0].getAction() == ButtonEvent.KEY_DOWN: print events[0].getButtonName() + " Pressed" else: print events[0].getButtonName() + " Released" #Import the Library import InputEventProvider #Create a new instance of the class evenProvider = InputEventProvider.InputEventProvider() # Attahced the EventVierw class evenProvider.attach(EventViewer()) # Start the service evenProvider.start() # After you're done , remember to close it evenProvider.close()

The complete source code can be download here. Once downloaded, you can try the code on your bug by just :

  1. Copy the files into your Bug using scp
  2. $ scp [PATH_TO_THE_FILES]/*.py root@10.10.10.10:/home/root
  3. Connect to your Bug using ssh and just type :
  4. $ python sample.py ...

Hope these libraries help you make your bug python experience a little easier.

Post Comments

Add Your Comment!

» All comments
» Comments RSS

Powered by Community Engine

Top
Login
Close
Bottom