Logitech MX Revolution mouse in Linux

Posted by Chris Sat, 27 Dec 2008 17:17:00 GMT

Just got the Logitech MX Revolution mouse for Christmas, and I have to say I’m impressed. It’s a solid mouse with good weight and good button placement, my only small complaint is that the thumb wheel is a little to far forward, but I just shift my hand when I need to. The mouse has something like 13 buttons, all of which, so far, are usable in Linux.

The biggest first problem that I ran into was that, by default, the mouse treats clicking the scroll wheel as the toggle for switching between click-by-click scroll mode and free-scroll mode. In linux this just doesn’t work. After googling around, I came across this blog entry that describes how to get things working a bit.

For the most part, setting up the mouse in OpenSuSE 11 was as easy as adding a new definition into /etc/X11/xorg.conf that looks like this:

Section "InputDevice"
    Driver       "evdev"
    Identifier   "Mouse[3]"
    Option       "Device" "/dev/input/event9"
EndSection

The Device line can be found by doing cat /proc/bus/input/devices and looking for the entry with the “Name” Logitech USB Receiver and a “Handlers” line that starts with “mouse2”. The “event” label after “mouse2” will indicate which even device the mouse is on, in my case the entry looks like this:

I: Bus=0003 Vendor=046d Product=c525 Version=0111
N: Name="Logitech USB Receiver"
P: Phys=usb-0000:00:1d.1-1/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/input/input12
U: Uniq=
H: Handlers=mouse2 event9
B: EV=17
B: KEY=ffff0000 0 0 0 0 0 0 0 0
B: REL=143
B: MSC=10

So I specified /dev/input/event9 as the device. After getting that set up, most of the buttons work as expected, with the exception of the thumbwheel, which I’m still working on.

The tricky part is changing the behavior of the scroll wheel so that clicking it doesn’t toggle between click and smooth scrolling. To do this you can use a small program that I found at this url. It’s called revoco, and at the time of this writing version 0.5 was the latest version. I’ve mirrored the latest version here in case the original site goes down.

Inside the tarball is a single C source file and some instructions. You just need to unpack the tarball and run make to compile to an executable, which you can execute with the --help flag to get some instructions. I set my mousewheel scroll-style to be “auto” with the following command:

sudo ./revoco auto=8,8

This sets the wheel to normally be in click-by-click scroll mode, but then if you scroll quickly it automatically switches over to free-scroll mode until you stop the wheel, at which point it changes back to click-by-click. You have to run this command as root (hence the sudo) and you can play around with the values after auto to fit your style, higher numbers mean you have to scroll faster to trigger the switch over.

I’ve been happy with it so far, and will probably post some more info if I figure out a good use for the thumbwheel.

Resetting the iPhone background after jailbreaking

Posted by Chris Fri, 22 Aug 2008 19:04:00 GMT

Just a quick HOWTO: If you’ve just jailbroken your iphone and find that you can’t change you background anymore, simply remove the file:

/var/mobile/Library/LockBackground.jpg

either via SSH-ing in or using the Terminal app. Then re-set it using the Settings app and you should be all set.

Redmine: First Impressions

Posted by Chris Tue, 03 Jun 2008 20:38:00 GMT

Current I have a project (using Ruby on Rails) that I’ve been working on off and on for a few months and another project that I’m considering starting with a friend. Both of them are non-trivial, and I’m already accumulating quite a few files in source control for the one I’ve been working on. I really wanted a nice clean app for tracking project tasks and ideas and my first thought was just a wiki, but I quickly came to the conclusion that just a wiki wasn’t really what I wanted. Then I found Redmine.

Redmine is a project management app written in Ruby on Rails, it’s got a lot of features that I’ve just started exploring. For each project you set up you get the following resources: a “task” list (bugs and features, etc), a document store, a wiki, a calendar, gantt chart generation, time tracking (tied to tasks I think) and version control integration (I’ve only played with subversion so far). It’s all presented in a really clean interface, and so far seems to have a lot of the features I’ve seen in other pieces of software like bugzilla, jira, confluence.

Installation was very easy on my Dreamhost server, I basically followed their instructions which included untarring, creating the database and running a few Rake targets and I was up and running. I got my first user, project and task created in roughly 20 minutes.

You can find the project at www.redmine.org

Unit testing Hibernate DAOs with dbUnit

Posted by Chris Tue, 08 Apr 2008 16:51:00 GMT

For the longest time our unit test suite had lots of DAO unit tests that, in some cases, were using dbUnit already, but were connecting to an actual Oracle database while running. They were also automatically loading up the Spring DAO context (all of the DAOs) and all of the Hibernate mapping files for the whole project. This resulted in test cases that took roughly 20 seconds to run, which was way to long for a unit test to run.

In order to try to make them run faster, and be more self contained, we have modified the tests so that they no longer rely on the Spring context and loading all the hibernate mapping files. We have also moved to use HSQLDB, which HIbernate supports, an in-memory SQL database implemented in Java. Initial tests are positive, with many of the tests that previously took 15-20 seconds taking 3-4 seconds to run.

In order to do this, I had to switch from using a Spring-configured hibernate environment to a hand-configured hibernate environment that allows the test classes to define the hibernate mapping files to use. The important steps in doing this were to create a Hibernate Configuration object and define all of the HSQLDB/Hibernate related configuration for the tests and set up some automatic loading of test data via dbUnit.

Hibernate Configuration was pretty simple, and looks like this in my parent class setUp() method:

Configuration config = new Configuration().
setProperty("hibernate.dialect","org.hibernate.dialect.HSQLDialect").
setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver").
setProperty("hibernate.connection.url","jdbc:hsqldb:mem:nwawebres").
setProperty("hibernate.connection.username", "sa").
setProperty("hibernate.connection.password", "").
setProperty("hibernate.connection.pool_size", "1").
setProperty("hibernate.connection.autocommit", "true").
setProperty("hibernate.current_session_context_class", "thread").
setProperty("hibernate.show_sql", "true").
setProperty("hibernate.cglib.use_reflection_optimizer", "false").
setProperty("hibernate.hbm2ddl.auto", "create-drop");

This sets up Hibernate to use an in-memory HSQLDB that is re-initialized for every test run and has tables automatically created based on the specified Hibernate mapping files. In order to specify the hibernate mapping files, I created an abstract method that returns a list of strings, then I do the following:

Iterator i = getHibernateMappingFiles().iterator();
while(i.hasNext()) {
    String file = (String) i.next();
    System.out.println("Adding mapping file: " + file);
    InputStream input = getClass().getResourceAsStream(file);
    if(input == null) {
        input = getClass().getClassLoader().getResourceAsStream(file);
    }
    config.addInputStream(input);
}

After the hibernate mapping files are specified. I then have code that initialized the new database with base data based on the test class (See below for explanation of getDatabaseConnection() and getDatasetXmlLocation()):

_sessionFactory = config.buildSessionFactory();
_hibernateTemplate = new HibernateTemplate(_sessionFactory);
_hibernateTemplate.afterPropertiesSet();

Session session = _sessionFactory.openSession();
session.beginTransaction();
DatabaseConnection dbconn = getDatabaseConnection(session.connection());
try {
    String xml = getDatasetXmlLocation();
    InputStream input = getClass().getResourceAsStream(xml);
    IDataSet dataSet = new XmlDataSet(input);
    DatabaseOperation.INSERT.execute(dbconn, dataSet);
}
catch (DataSetException ex) {
    System.out.println("Data not loaded " + ex.getClass().getName() + ", due to DataSetException");
    System.out.println("Message: " + ex.getMessage());
    // catch it. If there is no dataset avaible, exit graciously!
} catch (DatabaseUnitException e) {
    System.out.println("Data not loaded" + e.getMessage() + ", due to Database Unit Exception");
    // catch it. If there is no dataset avaible, exit graciously!
}
finally {
    session.close();
}

This method uses two other methods: getDatabaseConnection() and getDatasetXmlLocation():

protected String getDatasetXmlLocation() {
    int idx = getClass().getName().lastIndexOf(".");
    return getClass().getName().substring(idx + 1) + ".xml";
}

And:

protected DatabaseConnection getDatabaseConnection(
        Connection connection) {
    DatabaseConnection dbconn =  new DatabaseConnection(connection);
    DatabaseConfig config = dbconn.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
    return dbconn;
}

This method can be used by child classes to get a database connection for verifying data in the database via dbUnit, like so:

QueryDataSet ds = new QueryDataSet(conn);
ds.addTable("CATALOG", "SELECT * FROM CATALOG WHERE id = " + catagoryId);
ITable table = ds.getTable("CATALOG");
...
Number id = (Number) table.getValue(0, "ID");
assertEquals("Wrong id", id.longValue(), cat.getId());

After most of this goes in a parent class, child test classes just need to implement get getHibernateMappingFiles() method and define a setUp() method that creates the test DAO class and injects the _hibernateTemplate member variable from the parent class into the DAO.

Skype 2.0 For Linux in OpenSuSE 10.3

Posted by Chris Tue, 01 Apr 2008 04:35:00 GMT

I finally got around to trying out the new Skype 2.0 release for linux. I had tried the beta a few months ago with almost no luck, so I had kind of put it off for a while.

At first I tried the RPM that was packaged for OpenSuSE 10.3, but didn’t have any luck with it. I’m not sure if it was something I had done by using Smart and some online repositories to mess up my package configuration, but it kept complaining that some 32bit compat libraries for QT4 hadn’t been installed, even though I think they were.

Eventually I just made sure all the libqt4-*-32bit RPMS were installed (via Smart) and then used the dynamically linked tarball version of Skype (from their downloads page).

At first everything was going well except video, then I noticed in their readme that they point out that you need to have the most recent version of the gspcav drivers (webcam drivers for linux), which OpenSuSE 10.3 doesn’t have. I think the version available with the online repositories is something like gspcav 1.00.12 and you need version 1.00.20 (as of when I am writing this). This is the version that was release on 12 Dec 2007. Using the OpenSuSE Build Service I found a pre-compiled version of the gspcav-kmp-default package that matched the latest kernel for OpenSuSE 10.3, and after getting that installed video worked like a charm. I haven’t made a call that uses the video yet, but I was able to get it working in the Skype configuration test window, so I have pretty high hopes.

Unit Testing only public methods is bad 1

Posted by Chris Thu, 27 Mar 2008 19:51:00 GMT

I think I’ve had the argument about testing only the public interface for a class multiple times now, probably at multiple jobs, and I’ve never really gotten a good answer about it. My point of view is that only testing the public interface is the wrong way to go about unit testing.

The way I see it, unit testing should test “units”, and in the case of software that translates in my head to “units of work”. Public interface methods are not “unit of work” from the point of view of the person writing or maintaining the software (the person writing the unit tests). Public interface methods may the “units of work” for a QA tester or an integration tester, but they are not for the author of the code.

From experience, taking the approach of testing the public interface for a class often leads to very difficult to maintain unit tests. Very often, public interface methods will utilize several logic branches and several “helper” methods that are often private or protected. They can often deal with complex and deeply nested datastructures. These factors can lead to unit tests can become very difficult to set up, give a false sense of coverage because they don’t exercise all logical paths, or are hard to maintain because the setup is so unwieldy.

The alternative is breaking your code up into the most atomic units that make sense and then testing these individually. This means testing all of the private and protected methods and not just the public interface. The difficulty in this arises when trying to determine how to write the tests for your public methods. The public methods still accomplish the same data processing regardless of how you refactor your code or write your tests for the “helper” methods, and testing the smaller methods doesn’t remove logical complexity from the system as a whole.

At this point in time, the only thing I can think of is the suggestion to make sure that no single method is responsible for too much decision making. Maybe the best practice is to attempt to have a system where a single method tries to only use a single layer of a datastructure to make it’s decision, and leaves other decisions to other methods. This way you can construct a test for a method by only providing a single layer of the datastructure, which should hopefully limit the amount to setup you need to do. I’m still working on this.

Using the Smart package manager with OpenSuSE 10.3

Posted by Chris Wed, 13 Feb 2008 02:25:00 GMT

I’ve been using OpenSuSE for years, and regular SuSE before then. They’ve always been RPM based, which leaves a lot to be desired, and their tool Yast2 for managing software installation has some drawbacks that I can never quite get over.

With that said, it’s really easy to get Smart up and running to do your software management. Smart is a package manager that can manage the RPM system in OpenSuSE and will read from online YaST2 (and other types) repositories. Smart reminds me a lot of Apt, the commands are very similar and it accomplishes the same results pretty much.

If you’re running OpenSuSE, you can get smart from the online build service found at http://software.opensuse.org. You will need to get at least the following two packages:

  1. Smart
  2. rpm-python

After those are installed (using rpm -Uvh smart...rpm rpm-python...rpm), you can issue the command smart update.

The initial update process will read the current repositories you may have set up with YaST2 and imports them automatically. After the update process is complete, there are a couple basic command you’ll use most often:

  • smart search: search takes a search string and will search the repositories for packages that match, returning the package names and descriptions
  • smart install: install takes a list of package names to install. Install will also calculate any dependencies and install those as well, prompting you with a complete list before actually installing
  • smart update: Updates the local package information with the latest from your online repositories
  • smart upgrade: Does a full system upgrade, looking for any newer versions of packages you already have installed, it will prompt you with the complete list and ask for confirmation before continuing
  • smart remove: Removes a package and it’s dependencies, will prompt you with a complete list of packages before it continues

Smart is a great tool for doing software management on OpenSuSE, and in my experience much faster than YaST2.

Animation technique finally

Posted by Chris Fri, 08 Feb 2008 19:36:00 GMT

I ended up taking a slightly different approach to my animation last night. It basically consists of a couple different parts.

The first part was modifying the PositionableItem class to contain a few more pieces of information:

  1. Target Position (publicly settable)
  2. Original Position (internal, set as a copy of the current position when the Target Position is set)

Then I added a step(percent) method that calculates a new position based on the current position, the original position, the target position and the percent specified.

After that, my animation logic consists of setting target positions, and then looping for a specified time. During each loop the step(percent) method is called on each object and then each object is drawn. I already had code in place to draw an image based on it’s position information, so it was pretty easy.

I loop for 250ms, sleeping for 5ms after each loop, which keeps my CPU usage low.

It works great. :)

Initial OpenGL Drawing and Animation

Posted by Chris Thu, 07 Feb 2008 20:35:00 GMT

Before I started this little project I didn’t know any OpenGL, and really didn’t have any animation/graphics experience. Primarily I’ve been relying on Google to get me around, but there are some things I’m still struggling with and may just have to figure out on my own.

The first thing I’ve run into is how to approach drawing in a reusable way. OpenGL provides very primitive commands for drawing, and they are all oriented around drawing one frame at a time. The approach I’m settled at as of last night is to create a decorator class that will decorate my domain objects with location information, I’ve called it PositionedItem. It looks like this:

class PositionedItem
  attr_accessor :x, :y, :z, :x_rotation, :y_rotation, :z_rotation
  def initialize(other_obj)
    @decorated_object = other_obj
    @x = 0
    @y = 0
    @z = 0
    @x_rotation = 0
    @y_rotation = 0
    @z_rotation = 0
  end

  def set_position(x, y, z, x_rotation, y_rotation, z_rotation)
    @x = x
    @y = y
    @z = z
    @x_rotation = x_rotation
    @y_rotation = y_rotation
    @z_rotation = z_rotation
  end

  def method_missing(method, *args, &block)
    @decorated_object.send(method, *args, &block)
  end
end

This allows me to take a pure data-class (like a “Picture” class in the code I’m currently working on) and wrap it with position information that my drawing class can use.

In my main drawing method I am currently drawing a few quads on the screen with a texture in them (from my Picture class), there is a main picture and some side pictures. At the beginning of the drawing method, I set the positions of the objects that are going to be drawn (a subset of the entire collection of objects) and then call a draw method for each picture, this method knows how to draw a single positioned item based on it’s position data.

One thing that this approach doesn’t do right now is allow for more complex, position relative items. Each drawing method call does the following steps:

  1. Push the current Transformation matrix
  2. Draw a single quad with a texture
  3. Pop the transformation matrix

This means that right now I can only draw quads and it’s always relative to the original location, not relative to the last quad that was drawn.

As for animation, I still don’t really have that figured out. I do have goals though:

  1. It has to be time-based, not frame count based
  2. It has to be some kind of keyframe animation, I want to define the start and end positions and calculate all of the inbetween steps
  3. it has to be smooth

I think my approach is going to be having animation methods for each type of animation I want to do in my drawing class. Right now I want to animate choosing the next and previous pictures, so I’m going to have a animate_select_next and an animate_select_previous method. So far, I haven’t written any code, but I think the method is going to look something like this (complete pseudocode btw):

start_time = now_time
target_time = start_time + 500ms
save_object_start_positions
define_target_positions
while( now_time < target_time)
  percent_complete = (now_time - start_time) / (target_time - start_time)
  objects.each do |obj|
    new_position = (target_position - saved_start_position) * percent_complete
    set_newposition
    draw obj
  end
  sleep 5ms
end

I might be able to keep this generic enough to use it for all my animation, and just define the target positions when I call the method.

In the meantime, I need to find good sources on how to do simple keyframe animation and drawing loop techniques in OpenGL, because I’m really just trying to figure it out on my own at this point in time.

Ruby + SDL + OpenGL 2

Posted by Chris Thu, 31 Jan 2008 08:27:00 GMT

I started playing around with Ruby, rubysdl and ruby-opengl tonight. I’m not really sure where the last 6 hours went…

In six hours I went from knowing almost no OpenGL, a basic understanding of Ruby, and absolutely nothing about SDL to having a full screen OpenGL app written in Ruby that shows the JPGs in the current directory in a coverlow-esque manner that you can flip through with the left and right arrow keys. I’m amazed. The whole thing is only like 200ish lines long, and I’ll attach it so if anyone finds it while looking up how to do OpenGL stuff in Ruby you can maybe benefit from my hours of digging through random documentation and websites. It’s really strange, but the only actual OpenGL/GLU documentation I could find was in PDF form…that’s nuts.

Sometime after I get some sleep I’ll try to write up some tutorials.

Edit: So, I can’t figure out how to attach things right now, I’ll get it up later.

Edit: Here’s a link to download: Source

Edit: Here’s a link to look at it online: Online Source

Older posts: 1 2