Significant Sensor API Changes in leJOS 1.0.0 alpha5

I should say something about the changes to the
sensor API in 1.0.0alpha5 (released Monday), since they will probably affect existing
programs. The main difference is that a sensor
now has a type (e.g. light or touch) and a mode
(e.g. raw, boolean or percentage). These are set
with setTypeAndMode, preferably with values from
SensorConstants. The kinds of values that
readValue returns (i.e. canonical values) depend
on the type and mode. The readPercentage method
was removed. Also, SensorListener has only one
method, which is called only when the canonical
value changes.

The Sensor API that was brought over from TinyVM
was inadequate for advanced use, as some of the
feedback I've recevied indicates, e.g.: Peter
Dekkers was the first to send me some code and a
proposal to have a more object oriented Sensor
API with classes such as LightSensor,
TouchSensor, etc. He also suggested that Button and Sensor should have a common ancestor,
InputDevice. Ryan Vander Bijl also talked about
a similar object oriented approach. Sren Hilmer
sent some code, explaining an approach to only
get desired events in SensorListener's with only
one notification method (using masks). Recently, David Edwards noticed that TinyVM couldn't handle
rotation sensors. Not only is there a bug in the
API, but there is no way to reset the previous sensor value (which can now be done with setPreviousValue).

The object oriented approach, i.e. making Sensor
abstract and inheriting various sensor classes,
was appealing. I was already starting to code it, but I desisted due to several pragmatic reasons. Consider, for example, what it would be like to have two Sensor instances with different modes
and types.

You will also notice a performance increase in the Sensor API. The low-level (native) method readSensorValue can be executed about 2500 times per second in a for loop. Also, sensor events are now dispatched by a single thread, which
was also optimized. So code that relies on SensorListener's will also benefit.


Posted by Jose Solorzano 2000-10-26

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks