Technical comments on the Chumby [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Mon 2008-04-28 10:49
Technical comments on the Chumby

For any interested geeks in the audience, here's some more technical detail on the Chumby and my use of it as a high-tech alarm clock.

The Chumby is essentially a small ARM Linux device, with a touchscreen, speakers, two USB ports on the back, built-in wi-fi, and a couple of sillier peripherals such as a ‘squeeze sensor’ and an accelerometer. The latter two are unimpressive: when I tried the accelerometer I had to shake the thing really quite hard before it would register at all, and the squeeze sensor is just a microswitch at the top of the flexible leather case which they fondly hope will be triggered by most squeezing actions, but in fact the only way to reliably trigger it is to feel for the actual microswitch under the cover and press it.

So my first problem (well, my first after finding a UK power supply for the thing, which turned out not to be too hard) was to get it talking to my entirely wired Ethernet. I had googled up some plausible-looking instructions which involved filling one of its USB ports with a USB Ethernet dongle, and filling the other with a USB pen-drive containing an appropriate startup script to cause it to use said dongle in preference to its in-built wi-fi. Unfortunately, the instructions didn't work: it was able to send packets, but not receive them. It turns out, according to a forum post from a Chumby developer, that this is because a subsequent release of the Chumby firmware broke that mode of use. Apparently accidentally, and they claim they'll have it fixed in the next firmware release, but at least for the moment my Chumby is a wi-fi only device. Hence, my temporary solution has been to borrow a wireless access point from [livejournal.com profile] senji. (Rather to my surprise: I'd expected nobody would have one they weren't actually using, so I'd have to resort to spending money).

I had been able to write the bulk of my alarm clock program ahead of time, because the Chumby provides a custom Flash player and is mostly geared to running graphical applications with that; nearly all of its graphical interface is written in Flash, as far as I can tell. So I downloaded some dodgy free Flash authoring tools, hastily taught myself enough ActionScript to get by, and was able to write a working clock program in advance by testing it in a web browser; when the Chumby arrived I only needed extremely minor tweaks before it was basically working on that too.

(I found Flash pretty irritating to write. The other alternative would be to figure out how the Chumby's Flash player talks to the various hardware, and write my alarm clock as a native ARM Linux application instead of in Flash. But I'd vaguely prefer to have it in Flash for the moment, because that makes it easier for other Chumby owners to use it once I've got it finished enough to publish.)

In its standard running mode, the Chumby expects to download a collection of Flash ‘widgets’ from its home website (you can upload your own easily), and then it provides a convenient control-panel interface to switch between them. So I was vaguely hoping that I'd be able to have it run my alarm clock widget most of the time, but be able to switch to other modes on occasion.

However, there turned out to be a show-stopping problem with that: the display backlight is very bright in its default mode, and really needs to be in dimmed mode for use in a darkened bedroom. The Flash player does provide a hacky custom API for accessing Chumby-specific features like the LCD dimmer control, but that API isn't available to widgets it downloads from the web, on security grounds! This is clearly barmy: it's not a bad idea in principle to prevent web-downloaded widgets from altering your Chumby's systemwide settings, but it is thoroughly silly to consider the LCD brightness to be a systemwide setting. Rather, the LCD brightness should be considered part of the display, and widgets can control how they are displayed. In other words, any widget should be free to set its own brightness, and the setting should only last until you switch to a different widget.

The solution to this turns out to be not to run your widget as a web download. Instead, the Flash file for the widget goes on a pen drive, with (again) one of those startup scripts to activate it. Stick that in the Chumby, and when it boots up it will now be a single-function device running only my alarm clock (and an NTP client). Which is basically what I wanted, so fair enough; but it is faintly annoying that I can't also make use of all its other whizzy features if I ever happen to want them. (Or rather, I can, but only by pulling out the pen drive and rebooting.)

The final problem is the as yet unexplained glitches while playing sound. Yesterday I thought this was a frequency problem: the sound seemed higher-pitched than it should have been, and had big gaps in it, so my guess was that one piece of code was feeding sound at the correct rate to another piece of code which was playing it at twice the correct rate, leading to big gaps when the latter ran out of data and had to wait for the next block. However, after double-checking what the pitch should have been, I now no longer believe this, and my next guess is that it's a mixing confusion caused by the fact that my program is trying to start playing each alarm beep over the top of the remains of the previous one. So this evening I plan to try redesigning the alarm mechanism so that it's never playing more than one piece of sound data at a time, and see if that helps.

(I'm not helped in all this by the fact that the free Flash authoring software appears not to get sound quite right when writing out Flash files: testing on a web browser, the first second and a bit of any sound I try to play is chopped off, and I haven't yet worked out whether the same amount is lost on the Chumby. Bah.)

LinkReply
[personal profile] pm215Mon 2008-04-28 10:04
finding a UK power supply for the thing

So does it successfully recover if there's a power cut in the middle of the night?

Link Reply to this | Thread
[personal profile] simontMon 2008-04-28 10:11
It should reboot fine and go back into running my alarm clock program, but at present it'll end up back in "confirm alarm" state and hence not go off the next morning, unless of course I happen to wake up in the middle of the night in which case I'll notice.

That's just a fault in my software, though, namely that making it store persistent state is still on the to-do list :-)
Link Reply to this | Parent
[personal profile] simontTue 2008-04-29 10:16
Hmm. In fact, annoyingly, no: the Chumby does not automatically power itself back on when mains power returns after an outage, and apparently can't be persuaded to by any means short of a JTAG cable.
Link Reply to this | Parent
[identity profile] kaet.livejournal.comMon 2008-04-28 11:41
Which flash tools did you use. A couple of years ago I managed to get a vaguely sensible (make-driven) development using MSTAC (for actionscript) and Swfmill (for resources). But it was all a bit less than ideal.
Link Reply to this | Thread
[personal profile] simontMon 2008-04-28 12:25
Concidentally enough, MTASC and swfmill :-)

Indeed, it is all a bit less than ideal. MTASC has annoyed me by having completely broken type checking – I eventually ripped out all of the type suffixes from my variable declarations and reverted to effectively unchecked Javascript, because that was the only way I could find to prevent it from misidentifying my variables as types other than the ones I had explicitly declared for them. Also it seems to object if I declare a variable in an inner scope with the same name as one in an outer scope; a warning in case I'd done it by accident would be fine, but disallowing it completely is inexcusable for a compiler one of whose major boasts is that it gets local-variable scoping right where Adobe gets it wrong. And swfmill is currently under suspicion as the cause of my embedded sound files not playing correctly.

I am half tempted to borrow someone's copy of the approved Adobe authoring software, or go round to their house and use it briefly, just to confirm whether or not the sound problem really is related to my tool choice.
Link Reply to this | Parent | Thread
[identity profile] kaet.livejournal.comMon 2008-04-28 12:50
I actually had access to the Adobe tools when I worked on my stuff, but found them so incredibly bug-ridden and painful to use that I had better luck with the open source tools. At least with a text-based tool you can revert, diff, etc and so track down a bug reasonably reliably to work around. :)

Yes, I had the problems with types, too, and didn't use them, but I assumed that I didn't understand the type system (I didn't really want to learn too much about these things, so happily dismissed things as "whacky nonsense, I don't want to get involved with").

I've looked at a fair number of flash apps "under the hood" and they all seem to be a horrible mess of workarounds, abandoned, unused blind alleys, etc. So I'm pretty confident it's an artefact of the provided environments, :(.
Link Reply to this | Parent | Thread
[personal profile] simontMon 2008-04-28 13:01
At least with a text-based tool you can revert, diff, etc

Indeed. I certainly wouldn't want to switch to using the Adobe tools, even if I had a free copy of them, because I much prefer all my source files being in easily source-controllable text. At most I might want to track down and fix the bug in swfmill, if it does turn out to be one.

but I assumed that I didn't understand the type system

I suppose it's possible that there's something I don't understand about the type system and MTASC is getting it right, but I doubt it. If I declare a variable as var x : Object and the compiler subsequently rejects a reference to x.foo (having put the foo property in myself) on the grounds that type String doesn't have that property, and if I haven't declared any other variable in the entire program with the same name, then any type system which makes that error message justifiable is one I don't want to understand!

and they all seem to be a horrible mess of workarounds, abandoned, unused blind alleys, etc. So I'm pretty confident it's an artefact of the provided environments

As far as I can easily tell, the end-product Flash format itself is a horrible mess of abandoned or unused blind alleys and multiple non-interchangeable half-overlapping ways to achieve the same thing. It's more confusingly non-orthogonal than a street map of central Cambridge. So I wouldn't have a hard time believing that the awfulness of the available development environments was in turn an artefact of the target platform...
Link Reply to this | Parent | Thread
[identity profile] cartesiandaemon.livejournal.comMon 2008-04-28 15:50
FWIW when I was experimenting with my flash game, I ended up with a swf file which #included a text file with all of the actionscript script, and hence could process the text file in a normal source control way -- I don't know if that's relevant for you.
Link Reply to this | Parent | Thread
[personal profile] simontMon 2008-04-28 15:58
That'd manage most of the convenience, certainly, but in my current setup I also get to manage the media resources (fonts, sounds, images or movies if I had any) in a text-based (XML-based, in fact) way; it's all diffable. Unless it should turn out that there is really no practical way to sort out my sound issues other than using the Adobe tools, "pay a load of money for software which manages to do nearly as well" doesn't have that indefinable air of a good deal about it for me :-)
Link Reply to this | Parent | Thread
[identity profile] cartesiandaemon.livejournal.comTue 2008-04-29 13:46
Oh, totally, I'd agree with that conclusion. Just that they didn't have the specific (and possibly most glaring) flaw of not letting you source control actionscript.
Link Reply to this | Parent
[personal profile] simontTue 2008-04-29 09:34
Aha. I said yesterday that swfmill was under suspicion for being the cause of my sound problems: well, last night I found it guilty.

It turns out that when you embed an MP3 in a Flash file, there's some header information stored alongside it as part of the Flash format giving things like bits per sample, samples per second, mono or stereo. Of course the MP3 itself contains this information too. Now swfmill, it turns out, hardwires the Flash header to the settings it thought were most likely to occur in practice (16-bit stereo 44100Hz), and has a comment in the code saying "TODO: really we should be reading this out of the MP3". But my alarm sound MP3 happened to be in mono, so the Flash and MP3 headers disagreed, which was the source of the problem.

It turns out, naturally, that the Adobe Flash player believes the header in the MP3 itself, whereas the Chumby one at least half believes the header in the Flash, which is why the sound worked fine when I tested in a web browser but failed on the Chumby. *sigh*

I couldn't even be bothered to fix swfmill, in the end; I just regenerated my alarm sound in the approved format :-)
Link Reply to this | Parent
[identity profile] bryon8467.livejournal.comWed 2008-05-07 18:23
Nice userpic!
Link Reply to this
navigation
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]