Thursday, 29 December 2011

Windows SDK Woes

Finally got a Windows 7 PC at work. Installing the Microsoft Platform SDK kept on failing with a not too helpful error message.

Installation of the "Microsoft Windows SDK for Windows 7" product has reported the following error: Please refer to Samples\Setup\HTML\ConfigDetails.htm document for further information.

The log file is not too helpful as it contains many errors, but most of them seem to be spurious.

It seems that if a more recent version of the "Visual C++ 2010 x86 Redistributable" (vcredist_x64.exe) is installed then the SDK install fails. The solution is to first unistall the redistributable package then install the SDK.

Since the redistributables are updated with windows update I expect that this is a common problem. MS could at least put a note on the download page for the SDK about this.

Saturday, 14 May 2011

Keyboard Cleaning

I really like my Kinesis Ergo Elan keyboard which I bought about 12 years ago. It is old enough to have a 5-pin DIN connector with PS-2 adapter, which is now plugged into a PS-2 to USB  converter. I use it at work, so it has had more than 10 years of continuous use without any real problem. However, it was starting to look a bit grotty and the escape key was a bit sticky. Then the other day some keys stopped working so I thought it was time for a good clean.

The only way to get all the muck out was a complete disassembly. Fortunately, the Kinesis keys come off fairly easily. The cause of the sticky escape key was very obvious once it was dissasembled - some sticky mess all around the contacts.  Most of the keyboard is screwed together but the function keys were held in place by plastic lugs which had been melted over the backing plate. Not a good design for easy disassembly. So it was necessary to cut of the top of the lug to take the function key assembly apart and then glue it back together.

The keys before cleaning

Something disgusting on the function keys 
Once all the keys were removed, they could be cleaned and all the grot removed from underneath them.

Key switches with keys removed. 

The keyboard cleaned up pretty nicely. The plastic is slightly yellowed and the legend on the "enter" key is slightly faded, but considering the use that this keyboard has had it is in remarkably good repair. I have just ordered the newer model (the Kinesis Advantage) for use at home, to replace the Microsoft Natural keyboard that I have been using.

The cleaned keyboard

Saturday, 16 April 2011

Agile Japan 2011

Despite the fact that the study of Japanese companies by Nonaka and Takeuchi in their seminal paper “The new new product development game”  is credited with giving the name to Scrum  I don’t see a widespread adoption of agile methods for software development in Japan. Certainly at the large IT company where I work, process heavy waterfall style development seems to be the norm. A couple of years ago, the “quality division” tried to introduce a waterfall process in order to unify the process across all projects in the company to improve “quality.” This effort demonstrated everything that was wrong about imposing heavy defined processes and fortunately our division successfully opted out.

Introducing change anywhere is hard and I struggle to improve our development process. Two of the problems that I face are that agile methods do not seem well known, at least among my colleagues, and a belief that such techniques may work in America but would not work in Japan. This made me especially happy to be able to attend Agile Japan 2011  because the keynote speaker was Linda Rising, talking about introducing change, and it was a chance for my colleagues to see that Agile is used in Japan.

The main conference was held in Tokyo but there were 10 satellite conferences held around Japan, from Okinawa to Hokkaido, including one in Sendai. Because there was a satellite conference in Osaka it was easy for me to take the whole team. Initially I was expecting just a video link to Tokyo, and this was the case for the morning session. But for the afternoon they had a local program – with parallel sessions! There seemed to be about 60 attendees in Osaka.

In the keynote from Linda Rising she discussed her favourite patterns from “Fearless Change.” I had read this book some time ago and it was a nice refresher of the patterns. I will definitely have to re-read the book again. The comment that seemed to resonate most was “Just do it!”. This presentation is now on YouTube

The first presentation in Osaka in the afternoon was by Kawabata Mitsuyoshi of Agileware  talking about the 5 eXtreme Programing values. The most interesting part of this presentation for me was the specific difficulties of doing agile in Japan. XP values face to face communication but often when you want to discuss an issue the response is “I will send an email” or “let’s discuss it later.” This is something I have noticed myself with developers using email to “communicate” with someone a few meters away. I doubt that this problem is unique to Japan though.

The second session I attended in the afternoon was a workshop by Tarumoto Tetsuya  on  Usability Testing and more specifically DIY usability testing when you can’t afford or wait for a professionally run usability test. This included a very interesting description of the usability testing for the Suica  contactless smart card used for JR railways in Tokyo.

To demonstrate how to run a test, asking the users what they are thinking rather than asking them their opinion of the software being tested the workshop included a Kanji game. Unfortunately this was completely impossible for me, lacking the many years of hard study of Kanji which all Japanese have at school.

Overall the conference was very well run, had some interesting presentations and I definitely hope that there will be an Agile Japan 2012 and that I will be able to go.

Saturday, 9 April 2011

3D rotation about an arbitrary axis

I often need to do some geometric calculations involving rotation of a vector about an axis. However, not often enough to have the matrices for the rotation to hand. The calculation is not particulary difficult and is described in many places, but last time I needed this I found a very good write up by Glenn Murray:

Not only is this an easy to follow description, it also has the final rotation matrices which makes it very easy to code.

Tuesday, 5 April 2011

Printing from QtCreator

Why are the printing functions from most IDEs so bad? OK so I have not really compared the printing function in many IDEs, but the ones that I have used hardly offer any control over the printing at all and print in a large font.  I do like to read through listings on paper and to make notes on the listing  when trying to understand code or planning some modifications. But, I don't like priniting out pages and pages just to get a single function.

For whole files, I have been using a2ps. It can print multiple pages per sheet, supports two sided printing and produces readable listings with a small font. However, prinitng selected text was more difficult.

Now, QtCreator has support for external tools so I can print both whole files and selected text from within QtCreator but using a2ps. To print a file I just configured an external tool with the command line:
/usr/bin/a2ps --tabsize=4 --sides=tumble --medium=a4 -f8 -Ec++  --center-title=${CurrentProject:FilePath} -g -d "%{CurrentDocument:FilePath}"

To print a selection is similar, but instead of specifying the file as an argument, %{CurrentDocument:Selection} is specified as the input to the tool as shown below.

Sunday, 3 April 2011

Hard Choices

The Hard Choices board game from the Software Engineering Institute is a game designed to teach the effect of technical debt in software development. Players choose between taking a shortcut or taking the "long way" and gathering more tools. Shortcuts incur a -1 movement penalty on subsequent turns unless one turn is spent "refactoring."

An interesting suggestion from the Facilitator's guide is to play multiple rounds, keeping the shortcut and tools cards from the previous round. This simulates a second release where shortcuts from the first round will continue to slow development.

I want to play this with my development team but I am not sure how well the will take to playing a dice game in the office. The discussion following the game is likely to be the most important part.

The game itself is provided as a PDF download to print out. Just printing it out seemed a bit too simple so I printed it on some ink jet films and stuck the board on a piece of poystyrene board and the tool cards onto some thick card.

Saturday, 19 March 2011

A monitor for Cruise Control

I have wanted to build a monitor for our Cruise Control build server ever since I heard about the use of lava lamps to report the build status. The “easy” way seems to be to use an X10 automation system but unfortunately I have not been able to find that for sale in Japan. (It probably conflicts with local radio licensing laws. )

Our builds have been staying broken for tool long. The email notification  does not seem to encourage the fixing of the build. We definately needed something more obvious to show the build status. So when I recently found that there was a 4-way USB relay board available at a fairly reasonable price from Elefine I decided to build my own monitor. The hard part is controlling the power from the computer and the relay board takes care of that. Once I got the board all I needed to do was put it in a case and create some driver software to control it.

Fitting the board into a box and wiring it up was fairly simple. Unfortunately the USB port on the relay board is flush with the edge of the circuit board. This means that a fairly large hole is needed in the case to take the USB plug which looks a bit messy. 

For the lamps I decided not to use lava lamps because they will have to sit on the desk in the office and they tend to run very hot.  Instead I have adapted a small globe light, taking out the normal bulb and replacing it with two separate lights, one red and one green.

For the software I had already made a cruise control monitor plugin for QtCreator so I had most of the code already. All that was needed was to add code to switch the relays on and off depending on the build status. I tried to use the DLL which is provided by emx for the relay board but that did not work well – causing the program to crash on exit. So instead the code uses their command line utility for controlling the board.

Saturday, 5 February 2011

Using the 3DConnexion mouse with a Qt Application

This note describes my experiences getting a 3D mouse to work in a Qt application on Windows.

The 3DConnexion 3D mouse is a 6-DOF controller often used for CAD and engineering applications. 3DConnexion provide an SDK for windows which provides integration with MFC applications but not for Qt.

RAWINPUT support for Qt

The recommended method of supporting the 3DConnexion 3D mouse is to use Windows RAWINPUT message to receive the data from the mouse and then process those message to get the motion data.

There are 2 problems here

  • Qt has no native support for RAWINPUT - it is a windows only system and Qt has no corresponding Qt events for the 3D mouse
  • The "out-of-the-box" version of Qt does not forward RAWINPUT messages as they are received - at least up to Qt 4.6.2. On windows 7 Qt4.7.1 seemed to work with no modification.

The Raw Input API provides a "stable and robust way for applications to accept raw input from any HID, including the keyboard and mouse." [msdn] This enables the application to get the actual data sent by the HID device without any processing being done by windows first.

The application first registers to receive Raw Input from a particular device type, then when that device has data the application receives a WM_INPUT message in its event queue and the queue status flag QS_RAWINPUT is set. The application can then retrieve the data using the Raw Input API.

Raw Input was added in Windows XP, so is not available in Windows 2000
(Which is important -- see below.)

Raw Input and Qt

The problem with Qt (at least in 4.6.2) is that the version from the installer does not process Raw Input messages correctly. The way of collecting these the Raw Input messages is to set an event filter on the QApplication which gets the native windows messages. These can then be processed by the application using the Windows Raw Input API. However, the WM_INPUT messages are not being received by window/event filter the until some other event such as a mouse or timer event occurrs. Moving the 3D mouse causes no events to be received by the event filter but then if the normal mouse is moved (or key pressed etc)
all(?) the 3D mouse events arrive.

The problem can be traced to QEventDispatcherWin32?, which maps the windows messages onto Qt Events. Specifically, the line

   MsgWaitForMultipleObjectsEX(nCount, pHandles, INFINITE, QS_ALLINPUT,MWMO_ALERTABLE);

in the processEvents function of QEventDispatcherWin32. This is blocking and not waking on WM_INPUT events.

The windows documentation for this notes that QS_ALLINPUT, which includes QS_INPUT, “does not include QS_RAWINPUT in Windows2000.” Therefore, the problem is that the binary Qt installer is built to work on all windows platforms, so during the compile _WIN32_WINNT is defined to something less
that WinXP? (0×501) so that raw-input messages are not handled.

The fix is to re-compile Qt passing -D _WIN32_WINNT=0×501 to configure so that the WM_INPUT messages are correctly passed to the event filter when the 3D mouse is moved.

So this is not really a Qt bug, but rather that Qt is compiled for an "earlier" Windows platform which does not support Raw Input.

Sample Code for Qt and the 3D Mouse

I updated the 3DConennexion code for MFC to work with Qt. It uses an event filter to pick up the raw windows events then extracts the 3D Mouse information. This is then available as a Qt signal.

The zip file below contains a very simple application which displays the motion data in a window. This was tested with Qt 4.7.1.