Archiv der Kategorie ‘Programmieren‘
Magnetic pendulum, the OpenCL way. 2009-11-23
For the last couple of days I did some effort on porting my Python implementation of a magnetic pendulum (German post here, the slides include lots of pictures) to OpenCL. It’s really cool to leverage GPU power for your own benefit.
This is an implementation of a magnetic pendulum in OpenCL. A spherical pendulum is influenced by magnets. For every point of origin the program finds the magnet the pendulum’s body will be nearest when it comes to rest (friction is taken into account). It will create an image, where every pixel (points in the --plane) is mapped to a color representing each magnet.
The problem is ideally suited for parallel computing as every initial condition can be solved independently from the others. I did a Python version some time ago that utilized Scipy. Although it was quite optimized with C code, it performed very bad. To create a map of 1600×1600 pixels, it took about 2700 minutes! Leveraging the power hidden in GPUs, I wanted to know what speed-up would be reached.
The code works quite good so far. I began coding a CPU version in C that is a lot faster than the original Python version, but even my decent GPU outperforms that by a factor of ten. The map from above can now be done in 284 seconds. That is seconds, not minutes!
Asus DH Remote: Crafting an OS X driver 2009-11-02
Some ASUS mainboards are supplied with a remote control, the „Asus DH Remote“. I’m running Mac OS X Snow Leopard on a P5W DH Deluxe, which is quite old from a technical point of view, but actually doing a good job. As often, there are only Windows drivers for the remote, but none for Linux or even OS X. For the Linux part, there is already a driver for LIRC.
When I realized that the IR receiver is a simple USB HID device, I started brewing an OS X user-space utility together that interfaces the receiver. It is merely a hack based off example code I found at the Mac Dev Center, but that got it to work in a short time.
Basically, what you get from the receiver is the message that a key on the remote was pressed or released. Using this information, the tool is using Brandon Holland’s IRKeyboardEmu to emulate HID command reports sent by an Apple Remote. This allows you to use the Asus DH Remote as a controller for FrontRow or iTunes!
It is far from being perfect, but I think it’s a good starting point for your own inventions.
Source and Universal Binary: AsusRemote-v0.1.zip
- Download and extract the archive.
- Install the binary:
# sudo cp AsusRemote /usr/local/bin/AsusRemote
# sudo chown root:wheel /usr/local/bin/AsusRemote
# sudo chmod +s /usr/local/bin/AsusRemote
Note the SUID bit for AsusRemote. It needs superuser rights to interface to IRKeyboardEmu! Else it will issue an error issuing a sysctl command.
- To be able to use the daemon right after booting OS X, you need to copy com.tinowagner.AsusRemote.plist to /Library/LaunchDaemons/:
# sudo cp com.tinowagner.AsusRemote.plist /Library/LaunchDaemons/
# sudo chown root:wheel /Library/LaunchDaemons/com.tinowagner.AsusRemote.plist
- Finally, you should download the newest binary of IRKeyboardEmu and copy it to /System/Library/Extensions. Just follow the instructions in the readme.
- After rebooting, check that the daemon is running. There should be a process called AsusRemote.
This is a hard coded part. It tries to match the keys on the Apple Remote.
- AP LAUNCH: Menu. Start FrontRow.
- + and – : Up and down arrows, Volume up/down.
- Reverse and Forward: Previous/Rewind, Next/Fast-forward
- Play/Pause: Enter, Play/Pause
There is no action assigned to the other keys.
If nothing happens after pressing a key, try running AsusRemote from command line. First kill the daemon running in the background:
# sudo killall AsusRemote
You should now see a version message. Pressing an arbitrary key on the remote should produce an output:
2009, (c) Tino Wagner <email@example.com>
Key pressed: Plus
Key released: Plus
Key pressed: Minus
Key released: Minus
Key pressed: Forward
Key released: Forward
Key pressed: Reverse
Key released: Reverse
Key: AP Launch
Key: AP Launch
Feel free to modify the code to your likes! But please drop me a note if it’s an improvement that could be useful for everybody, so I can post it here.