This week’s App Hack will take a look at an API common across all webOS devices: the accelerometer. Generally, it is used to flip the screen around when the user rotates their device, but it can be used for so much more than that.
The accelerometer can be accessed by listening for two different events: orientation and acceleration. Orientation does the hard work of determining when the user has flipped their device to one of the standard orientations. It also gives you the pitch and roll relative to the current orientation. You can also set the orientation using the setWindowOrientation function. This takes a named orientation of ‘up’, ‘down’, ‘left’, ‘right’, ‘landscape’, ‘portrait’, and ‘free’. The directions like ‘up’ disable rotation and fix the device to one orientation. The ‘landscape’ mode will let the screen flip 180 degrees but always be in wide screen. The portrait mode is similar. And finally ‘free’ will let the user rotate however they choose.