return to OCLUG Web Site
A Django site.
March 12, 2013

Michael P. Soulier
msoulier
But I Digress
» Joysticks on Mac OS X in Flightgear

I like flight simulators. I've played all of the good ones, Flightgear is an open-source flight simulator that isn't bad, and is steadily getting better with every release. While it is available to run on Mac, there's no way to calibrate the Joystick due to a lack of caring on Apple's part.

But, Flightgear is hackable. The joystick file is just a set of XML bindings, those bindings can run code, so using coefficients to the input and controlling the output, in theory I can calibrate the settings myself. So, I did:

<?xml version="1.0"?>

<PropertyList>
    <axis n="0">
        <desc>Aileron</desc>
        <binding>
            <command>nasal</command>
            <script>
                var value = cmdarg().getNode("setting").getValue();
                if (abs(value) &lt; 0.05) {
                    value = 0;
                }
                else {
                    value -= 0.15;
                    value *= 1.5;
                }
                setprop("/controls/flight/aileron", value);
            </script>
        </binding>
    </axis>
    <axis n="1">
        <desc>Elevator</desc>
        <binding>
            <command>nasal</command>
            <script>
                var value = cmdarg().getNode("setting").getValue();
                if (abs(value) &lt; 0.05) {
                    value = 0;
                }
                else {
                    value -= 0.1;
                    value *= -1.5;
                }
                setprop("/controls/flight/elevator", value);
            </script>
        </binding>
    </axis>
    <axis n="2">
        <desc>Rudder</desc>
        <binding>
            <command>nasal</command>
            <script>
                var value = cmdarg().getNode("setting").getValue();
                if (abs(value) &lt; 0.05) {
                    value = 0;
                }
                else {
                    value *= 1.5;
                }
                setprop("/controls/flight/rudder", value);
            </script>
        </binding>
    </axis>
    <axis n="3">
        <desc>Throttle</desc>
        <binding>
            <command>nasal</command>
            <script>
                var value = cmdarg().getNode("setting").getValue();
                value -= 0.5;
                value *= -1.5;
                setprop("/controls/engines/engine/throttle", value);
            </script>
        </binding>
    </axis>

<axis n="4">
    <desc>View Direction</desc>
    <direction>left</direction>
    <low>
    <repeatable>true</repeatable>
    <binding>
        <command>nasal</command>
        <script>view.panViewDir(1)</script>
    </binding>
    </low>
    <high>
    <repeatable>true</repeatable>
    <binding>
        <command>nasal</command>
        <script>view.panViewDir(-1)</script>
    </binding>
    </high>
    <dead-band type="double">0</dead-band>
    <binding>
    <factor type="double">-1</factor>
    </binding>
</axis>
<axis n="5">
    <desc>View Elevation</desc>
    <direction>upward</direction>
    <low>
    <repeatable>true</repeatable>
    <binding>
        <command>nasal</command>
        <script>view.panViewPitch(1)</script>
    </binding>
    </low>
    <high>
    <repeatable>true</repeatable>
    <binding>
        <command>nasal</command>
        <script>view.panViewPitch(-1)</script>
    </binding>
    </high>
    <dead-band type="double">0</dead-band>
    <binding>
    <factor type="double">-1</factor>
    </binding>
</axis>
<button>
    <desc>Brakes</desc>
    <binding>
    <command>nasal</command>
    <script>controls.applyBrakes(1)</script>
    </binding>
    <mod-up>
    <binding>
        <command>nasal</command>
        <script>controls.applyBrakes(0)</script>
    </binding>
    </mod-up>
</button>
<button n="3">
    <desc>Flaps Up</desc>
    <repeatable>false</repeatable>
    <binding>
    <command>nasal</command>
    <script>controls.flapsDown(-1)</script>
    </binding>
    <mod-up>
    <binding>
        <command>nasal</command>
        <script>controls.flapsDown(0)</script>
    </binding>
    </mod-up>
</button>
<button n="4">
    <desc>Flaps Down</desc>
    <repeatable>false</repeatable>
    <binding>
    <command>nasal</command>
    <script>controls.flapsDown(1)</script>
    </binding>
    <mod-up>
    <binding>
        <command>nasal</command>
        <script>controls.flapsDown(0)</script>
    </binding>
    </mod-up>
</button>
<button n="1">
    <desc>Elevator Trim Forward</desc>
    <repeatable>true</repeatable>
    <binding>
    <command>nasal</command>
    <script>controls.elevatorTrim(0.75)</script>
    </binding>
</button>
<button n="2">
    <desc>Elevator Trim Backward</desc>
    <repeatable>true</repeatable>
    <binding>
    <command>nasal</command>
    <script>controls.elevatorTrim(-0.75)</script>
    </binding>
</button>
<name type="string">WingMan Extreme Digital 3D</name>
</PropertyList>

Right now, the calibration is good, but the controls are really jerky and overly sensitive. I'll have to see if I can smooth them out. But, they work.

December 9, 2012

Michael P. Soulier
msoulier
But I Digress
» Brewing a better UNIX

Being a Linux user, I'm used to a fairly standard set of tools on my command-line. On OS X, it's essentially BSD UNIX underneath, which I have had some experience with thanks to FreeBSD. The environment is very similar, but not identical, and on FreeBSD, you quickly find yourself using the ports system to install new packages that have been ported to FreeBSD from places like Linux.

It took about five minutes of FreeBSD use for me to go install bash, wget, vim, imagemagick, and a host of other packages. There's a lot already installed with OS X, but a few key things or me were definitely missing. I pulled vim from MacVim, but then I had to look for somewhere to get everything else I needed.

Being UNIX, I had several choices:

  1. Grab the source and build it myself.
  2. Install MacPorts and build it from there.
  3. Install Homebrew and build it from there.

Well, I've done source installs, I've done ports out of FreeBSD, so I figured I'd see how Homebrew works. Basically, it makes /usr/local owned by the user that installs it, which on OS X is me, as an administrative user (like a Windows power user). From there you can double-check that everything is set up properly by running:

brew doctor

It will pick up permission problems, issues with your PATH environment variable, warn you about packages that were built but not symlinked into /usr/local properly, etc. Then it's not much different than using apt-get on Debian, except that the packages are building when they install, they're not pre-built binaries. So wget was just:

brew update
brew install wget

Since then I've installed some essentials, and non-essentials if I include freeciv. Lets see, I have:

msoulier@merlin:~$ brew list
c-ares      git         lame        lua     sdl_mixer
cracklib    glib        libevent    lynx    tmux
feh         gmp         libffi      mutt    tokyo-cabinet
flac        gnupg       libgcrypt   nettle  unrar
fontconfig  gnuplot     libgpg-error p11-kit wget
freeciv     gnutls      libmikmod   pcre    xz
freetype    imagemagick libogg      pkg-config
gd          imlib2      libpng      readline
gettext     irssi       libtasn1    sdl
giblib      jpeg        libvorbis   sdl_image

Rather nicely, the packages are all installed under /usr/local/Cellar/, and symlinked into the right places so they show up in my path, and for building. As I really hate installing from source, because you never know what you have installed or how to uninstall it, or what you'll break if you upgrade it, I like this.

I do find that other packages mess with those careful permissions, so I keep running brew doctor so I know about the issues. I also noticed, thanks to a coworker, that the Perl community has done something similar for install Perl modules called Perlbrew. I'm going to look into that soon, as honestly, it's about damn time. Managing personal Perl modules sucks, has always sucked, and now thanks to Perlbrew will hopefully suck no longer. But I digress, more on that in another post.

I give Homebrew an A. An A+ would be a command to fix permissions problems without my help, and maybe there is one, these things elude me at times. I highly recommend it if you're trying to complete your *nix environment on OS X.

November 25, 2012

Michael P. Soulier
msoulier
But I Digress
» Tweeting on OS X

For some time my desktop has been an older, underpowered Linux box, so using services like Twitter via the website has been painful, as loaded with heavy javascript that would consume my CPU's limited resources.

So, like any Python programmer would do, I wrote my own client. Well, lets be honest, the hard work was done by the tweepy library, I'm just using it. I call it Twit, and I've been using it to post for some time now, lightweight from the command-line. I also keep one running, polling my account for new posts, and notifying me when there are new posts and pulling them down.

My notifications come in many forms, depending on the command-line options. I can just watch them show up in text in the shell, I can use xosd to display notifications on your X11 desktop, It can use libnotify in Gnome to display temporary notifications that drop down in the corner of the screen.

As I'm now playing with an OS X desktop, libnotify isn't supported. I could use xosd along with XQuartz, but I'd prefer more native integration with OS X, as it does have a notification system, via AppKit. Python is preinstalled on OS X, and the AppKit module is included. I found a great example of how to use it online, which made this much, much simpler, so thanks there.

I used it like so:

def notify_appkit(status, options):
    """Thanks to
    https://github.com/albertz/music-player/blob/master/notifications.py
    for how to do this."""
    global notifCenter
    if not notifCenter:
        import AppKit
        notifCenter = \
            AppKit.NSUserNotificationCenter.defaultUserNotificationCenter()
        appDelegate = AppKit.NSApplication.sharedApplication().delegate()
        notifCenter.setDelegate_(appDelegate)

    notif = AppKit.NSUserNotification.alloc().init()
    title = "Tweet by %s" % status.user.name
    notif.setTitle_(title)
    notif.setInformativeText_(status.text)
    notifCenter.deliverNotification_(notif)

Now, this does cause a little icon on the dock to jump up and down, so I'll need to look into that, and how to open the browser to twitter or the embedded link when the notification is clicked on, but it's a good start.

November 16, 2012

Michael P. Soulier
msoulier
But I Digress
» Ok, nobody panic, there's a fruit on my screen

I've needed a new desktop for a while now. As I'm primarily a Unix user, I typically buy a cheap PC and put Linux on it. This involves doing a bunch of research into available hardware to make sure that everything is going to work, like accelerated graphics for any games I'd like to play, supported network drivers, etc. Over the years it's gotten easier and easier to get Linux working on a box, but sometimes I still have to work to get something working.

The end result is a working Linux workstation that I can use for work, and my basic computing needs, often involving fighting with the fact that noone wants to support it or any software that I'm using. That part does get old year after year.

For example, I bought a Kobo ages ago, and I had to use a Windows box to run the Kobo desktop software, to patch its firmware and put books on it. Later I found out that I could just copy .epub books into it like a flash drive, which is awesome by the way Kobo, but you get the idea. For my iPod shuffle, I copy mp3s onto it and run the rebuild_db Python script to update the db on the iPod. There are workarounds for these issues, but sometimes it's nice to just plug something in and have it work. And fighting with my devices isn't as much fun as it used to be. I'm too damn busy.

So, based the recommendations of various friends and colleagues, I decided to take the plunge with my new desktop, and try a Mac Mini from Apple, running Mac OS X 10.8, "Mountain Lion". I figured that it's a lot better supported in commercial software land, while being BSD Unix underneath, so maybe it's the best of both worlds.

http://www.but-i-digress.ca/static/images/apple-logo1.jpg

I need to customize the crap out of it, and get used to the interface and keybindings, and do a lot of reading. I hope to post my experiences here, so stay tuned if you're interested.

Sure, I could have just thrown Linux on another box, and maybe I still will, but I've done that. I felt like doing something new.