Developing widgets for chumby
See also Developing Widgets for Foo/Katamari
This page describes the development of widgets for the "Ironforge" production chumby hardware. Widgets for the Chumby are developed for Adobe Flash Lite 3.1. Flash Lite 3.1 has a feature-set based on desktop Flash Player 8.
The version of the Flash Lite Player is 3.1.5 as of November 2009.
- Flash video (FLV) encoded with ON2 and Sorenson Spark codecs
- Video, NetStream and NetConnection classes
- Internal PNG Transparent (PNG-24)
- Internal GIF Transparent
- External MP3 files
- External PNG, GIF, non-progressive JPEGs
- Bitmap caching, bitmap effects or enhancements
- Blend modes
- Non-default code pages
- Focal gradients
- Progressive JPEGs
- External GIF Transparent
- Non-round line caps and joins
Also important for developers to note is that the device's current input system is a touchscreen, meaning that mouseMove events will only occur while mouseDown (equivalent on current computers of only being able to move the mouse while holding a mouse button), which may/will have some effect on how your programs operate. For example, buttons should not be designed to have a separate 'over' state, since the Flash player can't determine when to switch in and out of that state. Instead, button over states should be the same as their 'up' state.
For efficiency's sake, Flash Lite downsamples images and embedded fonts, so avoid resizing images and small serif fonts, as detail will be lost.
While the chumby runs Flash Lite, it's actually a fairly normal Flash Player, and will run most of the content created for Flash 7, as well as a few of the newer features. It's not necessary to specifically publish for Flash Lite 2 or Flash Lite 3 in the Flash development tools unless you plan on using the features specific to Flash Lite. Most of these features are designed more for the mobile phones and thus don't apply to chumby devices.
The most common and complete development tools for Flash are those available from Adobe; however, there are several other third-party programs that will generate Flash movies. Any version of Adobe's Flash products is capable of producing widgets for chumby, not just the latest version (currently Flash CS4 Professional)
You can also use the freeware FlashDevelop.
Performance and Optimizations
The protoype chumby has a 350Mhz ARM9 processor - similar in performance to a low-end Pentium desktop. There are certain tricks and techniques that can make the difference between a sluggish movie and one that works smoothly.
- Change property values only when necessary. The very act of changing a property can result in a redraw of that object, even if the value itself hasn't changed. Be sure to check to see if changing the property is necessary before changing it - for instance, don't change the _rotation value of the hour hand of a clock if it hasn't actually moved.
- Change dynamic text only when necessary. If the text isn't actually different, don't change it.
- Reduce the size of images by playing with compression settings. Make the images as small as possible with acceptable quality.
- Reduce the size of audio by playing with compression settings. As with images, try for small size with acceptable quality.
- Simplify vector graphics. See if you can use Flash's curve simplification to reduce the number of points and curves. For static graphics, you might even be better off creating bitmaps and using them instead.
- Avoid layered translucent areas. Piling on a lot of translucency is expensive. You may be better off using PNGs with these effects already composited. If you can use masks, use them.
- Avoid gradients. Gradient fills, particularly radial gradients and gradients with translucency, are expensive. Use them sparingly.
- Avoid full-frame animation. Animation that changes large areas of the display can slow down the animation - try to keep the percentage of the screen being updated as small as possible for any given frame.
- Use tweening sparingly. Try to keep tweening to one or two small objects at a time. Don't use shape tweens unless absolutely necessary - they're extremely expensive to compute.
- Avoid processing a lot of data in a single frame. Try queuing data in an array and process one item per frame. It complicates things a little bit, but will result in smoother operation and will avoid Actionscript timeouts.
- Avoid lots of text. Lots of small text can be expensive to render. The chumby is meant to be read from a few feet away, so you really should be using large text anyway.
- Don't do too many network fetches at the same time - Flash Lite limits the number of fetches intiated on the same frame, and the total number of fetches in progress at the same time. Considering queuing fetches and intiating new fetches when the previous ones complete.
- Watch your variables. Properly declare (var variableName:Type;) and scope variables. Remove variables when no longer necessary (delete variableName;) to remove from memory.
Widgets are passed a set of properties on the _root timeline about the Chumby such as its name, the current channel, the user (you), the music source, information about the clock, and so forth. These are set by control panel before each and every widget. The current parameters can be found in the Chumby Property Dictionary page.
For a simple example using the Chumby properties, refer to the following tutorial:
Note also that widgets are occasionally loaded into other movies (typically the "virtual chumby") - that means you cannot rely on the movie's background color to be used. A widget should generally include a background graphic with the desired color or image behind all of the other graphics.
The widget has a security sandbox similar to a movie running in a browser plugin - an external source of content should have an appropriate crossdomain.xml file to expose content to the widget. For more information, please see the following Flash Player Technotes and Articles:
- External data not accessible outside a Macromedia Flash movie's domain
- Security Changes in Macromedia Flash Player 7
For help creating a crossdomain.xml file refer to this tutorial:
If you wish your widget to be compatible with "Virtual Chumby", in addition to functioning on the device itself, then you should build widgets so that they can be
loadMovie()'d into another movie at some level other than
_level0 - this means you should try to avoid adding random properties to
_global, or the built-in objects. If you wish to use
_root, then you should set
_lockroot = true on the main timeline of your widget movie.
In general, widgets should be under 100K in size in order to reduce download time and use the minimum of storage in the device itself.
Uploading a Widget
You can upload a widget to our service which you can then use on your chumby. You will need to have the SWF for your widget, and a 80x60 pixel JPEG thumbnail image which represents your widget.
- Create an account with chumby.com, if you haven't already
- Log in - you will probably be redirected to a page that offers to let you register a chumby, or a list of your current physical chumbys
- Select the "upload a widget" item from the "widgets" menu
- Fill in the information
Widgets should be under 100K in size in order to reduce download time and use the minimum of storage in the device itself.
A widget uploaded using this mechanism will show up in the widget mix configuration, and can be selected just like any other widget. However, these uploaded widgets will only be accessible from your account. If you'd like your widget to be visible to everyone, turn on the "Public" radio button on the upload page - your widget will be reviewed by a chumby employee. Important: Widgets should not play sound without user interaction. Your widget is unlikely to be shared publicly if it plays audio automatically, unless that's a user-set option that defaults to off.
Widget Configuration Dialog
Widgets on Chumby.com can have a configuration dialog used to save custom user settings. For example, a simple RSS reader widget would want to save the URL of the desired RSS feed using such a dialog. This configuration dialog is a small Flash movie which only appears on the Chumby site, it does not appear on the Chumby device.
- Configuration Flash files can be any version of Flash
- Configuration Flash files must be 320x240
- Parameters saved using the configuration dialog are automatically placed on the root timeline of the actual widget
Widget parameters that are preceded by "_private" are not copied when a widget is sent or forwarded to another user - this allows user-specific configuration that is not passed on, such as passwords or other authentication tokens.
As an author, you're limited in the duration your widget can run, a maximum of 999 seconds (around 15 minutes). It it not possible (without special permission from Chumby) to author a widget that will run an indeterminate amount of time, or forever. The user, however, does have a few simple options to choose to make a widget run "forever" - select "Forever" from the "customize" menu when they add a widget, put the widget alone in a channel, or press the "stay" button in the Control Panel.
It it possible, however, to indicate that a widget has completed its operation before it would naturally time out. Simply set the variable "_chumby_widget_done" to "true" on the main timeline of your widget movie - the Control Panel will detect that and immediately expire the widget's timer.
Several developers have argued that their widgets are so important to users that they must be allowed to run forever. As policy, we've decided to have the user make that determination, not the author.
Example Widgets, Templates, and Components
- Chumbian authored Example Widgets
- Raff's FlashDevelop Template & Mini-Components
- Raff's older Chumby Widget code
- PhotoFrame Widget w/source
- Chumby Radio Alarm Clock
- WryBread's sources
- ApoXX's Package Tracker source
- Risacher's sources
- KayakPete's WebCam source
- djchumby's MasterClock source (FlashDevelop project)
The optimal video settings for the production chumbys using Flash Lite 3 are:
- Frame rate: 12fps
- Video data rate: 220kbps
- Audio data rate: 32kbps (mono) or less
- Width: must be less than or equal to 320
- Height: must be less than or equal to 240
Avoid using the FLVPlayback component, as there are performance and untypical behavior bugs. Instead, use the Video, NetStream, and NetConnection objects. See Playing back external FLV files dynamically in the Adobe ActionScript 2.0 documentation for information on how to use these objects.
Refer to the following tutorial for the proper way to use .FLV video with the Chumby:
Some widgets, such as videos and certain games, fall in a category that's best to run in "cooperative mode", meaning they don't expire after a set time period. Instead, they run until they set the flag called _chumby_widget_done on the _root timeline. The chumby control panel continuously looks for the _chumby_widget_done flag on the _root timeline of the widget. When that variable is set to true, the control panel will advance to the next widget in the channel, even if the timeout hasn't been reached yet.
A user can set any widget to run "forever" if she chooses to, but if you develop a widget that would run better in cooperative mode, you may request that it run that way by default.
Before Chumby sets your widget to cooperative mode, it must meet some criteria. It must set the aforementioned flag in the following circumstances:
- If the widget first comes up and the user doesn't interact with it at all for 20 seconds.
- If the user already interacted, but there is a period of inactivity since the last interaction (typically 30 seconds).
- If the widget is done (video complete or game over, for example) and the user does not start another game/video within 10 seconds.
In the case of #2 above, it's possible (but not required) to bring up an overlay 5 seconds before the timeout saying something like "to stay on this widget, tap the screen."
Once you set the flag to true, don't assume the widget will necessarily stop running. For example, if it's the only one in the channel, it will stay active.
Even non-cooperative-mode widgets can set the _chumby_widget_done flag to true in order to time-out early.
To enable cooperative mode: Please contact Chumby Industries after uploading your widget.
Chumby Industries can enable email sending for certain widgets that have good reason to do so. By default, this functionality is not available to widgets. Once enabled, plain text emails can be sent to the address that Chumby has on file for the owner of the device.
The code sample below shows how the email request is sent to the server. This code snippet makes use of variables that the control panel writes to the _root timeline of each widget when it starts, such as the _root._chumby_widget_instance_id.
var baseURL:String = (_root._chumby_base_url == undefined) ? "http://www.chumby.com" : _root._chumby_base_url; var url:String = baseURL+'/xml/email/'+_root._chumby_widget_instance_id; var emailXML:XML = new XML('<email subject="The Subject">Message body goes here.</email>'); emailXML.sendAndLoad(url,response_xml);
Detecting/filtering based on GeoIP
The requests look like:
http://content.chumby.com/geoip?ip=220.127.116.11 # uses IP from param or http://content.chumby.com/geoip # uses IP of sender
The response will resemble:
<?xml version="1.0"?> <geoip ip="18.104.22.168" iso_country="US"> <ack>This product includes GeoLite data created by MaxMind, available from http://maxmind.com/</ack> <license>http://geolite.maxmind.com/download/geoip/database/LICENSE.txt</license> <link>http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip</link> </geoip>
Most Common Problems
The most common problems with widgets that seem to fail on the chumby are:
- The movie is the wrong version - Flash Lite 3 will not play Flash 9 movies.
- The movie does not have sufficient security privileges - crossdomain files may not exist on the external content servers
- The movie has the wrong dimensions - the widgets should be 320x240
In order to be accessible and operable by the ensemble of the users, the widgets MUST support characters outside of ASCII-7. Otherwise, characters like "é, ê, ñ, À, Œ, ç" will not be displayed, resulting on unreadable texts.
The solution is to use UTF-8 for encoding, and insert fonts containing commonly used characters in principal languages such as French, German, Spanish and so. The DejaVu fonts provide such support.
This affect all the widgets deployed on a chumby : RSS reader, social widgets (Facebook, Twitter, FriendFeed…), corporate widgets and so.
See the forums for initial discussion.