Each physical device is controlled by a single instance of the respective class, accessed through the interfaces listed above. The single instance of the Sun SPOT class creates and manages access to the device driver singletons. The singletons are created only as required.
For example, to get access to the
Iled theLed = Spot.getInstance().getGreenLed();
To turn the LED on and off:
theLed.setOn();
theLed.setOff();
Persistent properties
The sections Manifest and resources and Library manifest properties explain how to define
An 8k byte area of flash is reserved for persistent System properties that can be read and written from SPOT applications and by using ant commands on the host. All properties have a String key and a String value.
We distinguish between
Accessing properties from SPOT applications
To obtain the value of a System property do:
System.getProperty(<propName>);
This call returns null if the property has not been defined. All system properties, including user- defined properties, can be accessed this way.
To set the value of a
Spot.getInstance().setPersistentProperty(<propName>, <propValue>);
A property can be erased by setting its value to null. Setting or erasing a persistent property takes about 250ms. If you wish to set several properties at once, you can optimise performance like this:
Properties propsToWrite = new Properties(); propsToWrite.setProperty("key1", "value1");
…
propsToWrite.setProperty("key99", "value99"); Spot.getInstance().setPersistentProperties(propsToWrite);
You can also get the value of a
Spot.getInstance().getPersistentProperty(<propName>);
This call is much slower to execute than System.getProperty, because it
26