Archive for the 'Code' Category

Extreme Feedback Device – The Cruise Control Lights

Steve on Jul 19th 2010

My Arduino based Cruise Control build indicator lights have been up and running for a couple of months now and so far so good.  It’s time to post the source code for the Arduino sketch and the Java app that runs on the machine that the build lights are connected to.

First, here’s a very short video of a successful build.  While a build is in progress, all 3 lights turn on, and at the end of the build, you get either solid red or solid green (hopefully), depending upon success!

The lights are connected via USB to a machine that sits nearby.  On that machine runs a Java program that attaches to the USB serial port and sends commands to the Arduino sketch to turn any of the 3 coloured lights on or off.  The sketch is very simple with no clever logic at all.  All it does is read the serial port and based on the value of 3 bytes, turns the lights on or off.  All the logic is contained in the Java program.

The Java program running on the attached PC connects to a Cruise Control server using the JMX protocol and waits for status updates for a given project.  These status updates occur when builds are started, and when they end.  There are also various informational properties that can be obtained from the build server, such as what time the last successful build was.  With this information, the lights can be set to show green for a good build less than 2 days old, amber for a build less than 4 days old but older than 2 days, and red for a build that’s older than 4 days (or a failed build).

I won’t go into a long post detailing the code now.  It’s a single Java source file with everything in (including the Arduino sketch in the comments), with a section for the command line handling, the JMX connection and the serial port code.  It uses the RXTX serial I/O library, so if you want to compile and run it, you’ll need to download that first.  I’m happy to answer any questions about the code, and of course, it’s free for you to do whatever you like with (WTFPL).  There’s not a lot of documentation specific to the Cruise Control JMX interface, but if you read through the actual Cruise Control source at sourceforge, you get a pretty good idea of all the properties available.   The methods to get the properties and the JMX events are fairly standard and the details from Sun here (PDF)  helped too.

CruiseControl/Arduino Lights Source Code

http://sam.zoy.org/wtfpl/

Filed in Code,Software | No responses yet

Liang-Barsky Polygon Clipping Example

Steve on Nov 8th 2009

According to site stats, my Sky Diver article is one of the popular ones so far, and in particular, people seem to hit it after searching for Liang-Barsky clipping. Since I’ve not had any comments or contacts relating to the code I posted, I don’t know if it’s what people are expecting or not. However, I do know that it’s not immediately usable without some thought, and I’ve wanted to provide a complete example for a while.

So, here it is. I’ve taken the Liang-Barsky polygon clip code I posted, and worked it into an example Java Applet, which you can hopefully see below if you have Java enabled in your browser. The code has only been changed to remove it’s fixed point nature (no more ‘<< 8′ to confuse things), and I’ve added a framework around it that calls the clip method, so you can hopefully see what’s going on.

I’ve not written up a complete tutorial on how the clipping works, like I said before, for that you need to read Computer Graphics, Principles and Practice by Foley, Van Dam, et. al. or search the internet for tutorials like this good one at Skytopia.

Here’s the applet for you to play with.  Click on the image below to load and start it, then use the arrow keys to adjust the clip boundaries.

Note that I’ve used a little bit of Javascript to start the applet with a click on the image so that the full Java environment isn’t loaded every time this post is shown. You need Java and Javascript enabled for it all to work.

Full source code can be downloaded here.

Hope it’s useful.

Filed in Code | No responses yet