Difference between revisions of "Developing Widgets for Chumby: Sensor Access"

From Chumby Wiki
Jump to: navigation, search
(Accelerometer)
 
Line 84: Line 84:
  
 
Note that the value of G varies depending upon your location - the above equation represents an average.
 
Note that the value of G varies depending upon your location - the above equation represents an average.
 +
 +
[http://www.adobe.com/devnet/devices/articles/chumby_development_06.html Adobe Developer Connection - Developing widgets for Chumby with Flash Lite 3] provides detailed information on using the values returned by the accelerometer. The author, Phillip Kerman, also offers an accelerometer class for easier access.
  
 
==Bend Sensor==
 
==Bend Sensor==

Latest revision as of 15:28, 6 June 2008

See ChumbyNative - AS2 file for ASnative calls accessing various chumby facilities

Flash Access to Sensors

The Chumby Flash Player has some ASnative calls to access the various sensors

NOTE: These are very likely to change in future releases - use at your own peril.

NOTE: If you are compiling your widgets in AS2, you will have to change the syntax of the ASnative calls in order to compile without errors:

_bend = ["ASnative"](5,14)();         // this will return a value
_accelerometer = ["ASnative"](5,60);  // this will return a function object


Touchscreen

Normally, the touchscreen is calibrated by the user using the Control Panel, however, raw coordinates are available.

_rawX = ASnative(5,10); // get the last raw touchscreen X coordinate
_rawY = ASnative(5,11); // get the last raw touchscreen Y coordinate
trace('x:'+_rawX()+', y:'+_rawY());

Display

This allows you to dim or turn off the display, perhaps for power reasons.

_getLCDMute = ASnative(5,19); // get the value of the LCD "mute"
_setLCDMute = ASnative(5,20); // set the value of the LCD "mute"
trace(_getLCDMute());
_setLCDMute(1);

There are three possible values:

_setLCDMute(0); // full on
_setLCDMute(1); // dim
_setLCDMute(2); // full off

Speaker

This cuts off audio to the built in speakers, but still allows audio through the headphone jack.

_getSpeakerMute = ASnative(5,17);
_setSpeakerMute = ASnative(5,18);
trace(_getSpeakerMute());
_setSpeakerMute(1);

There is a system daemon that does this automatically, so you'd have to kill that in you want to control this yourself.

Microphone

A microphone has been added, replacing the light sensor found in the alpha prototypes.

Code to come.

DC Power

This tells you whether the device is connected to the DC power adaptor, or if it's running on the 9V battery. The battery is not designed to operate the chumby, but rather to keep alive a small secondary processor. The chumby itself will power down - it should power up again based on the next set alarm, or can be restarted with the power switch when the AC power has been restored.

_dcPower = ASnative(5,16);
trace(_dcPower());

Accelerometer

The force values are read-only, and range 0-4095, with zero point (no force) at 2048, and a range of approximately -5 to +5 G. The "current" values are the instantaneous value of the sensor, the "avg" values are a running average of the last couple of readings (which will be somewhat smoother), and the "impact" values represent a change in force above a certain threshold. The "impactTime" can be use to detect when the impact occured. The "impactHints" value is used internally by the driver for housekeeping and is currently undocumented.

 _accelerometer = ['ASnative'](5,60);

Somewhere in your code.

 version = _accelerometer(0);
 timestamp = _accelerometer(1);
 currentX = _accelerometer(2);
 currentY = _accelerometer(3);
 currentZ = _accelerometer(4);
 avgX = _accelerometer(5);
 avgY = _accelerometer(6);
 avgZ = _accelerometer(7);
 impactX = _accelerometer(8);
 impactY = _accelerometer(9);
 impactZ = _accelerometer(10);
 impactTime = _accelerometer(11);
 impactHints = _accelerometer(12);

A quick way to convert a component to a multiple of G would be:

gValue = rawValue*0.0024489559928062587-5;

Note that the value of G varies depending upon your location - the above equation represents an average.

Adobe Developer Connection - Developing widgets for Chumby with Flash Lite 3 provides detailed information on using the values returned by the accelerometer. The author, Phillip Kerman, also offers an accelerometer class for easier access.

Bend Sensor

This is the switch sensor on the top of the chumby device

_bent = ASnative(5,25); // get the "bent" flag (0/1)
trace(_bent());