PlotSource is an abstract class. This means that it is not intended for direct use but exists as a parent for sub-classes. It is also defining the interface for children with the
data() operations (a UML term encompassing methods).
The CLUE board has many sensors and inputs which can be used as data sources for plotting. The data output from all of these sensors and analogue input(s) are ultimately represented by either one number or a list of numbers per sample read. This commonality suggests they can be represented by a single class providing the interface to the rest of the program. The per-sensor code can be implemented in a sub-class derived from a base class using inheritance. UML diagrams depict inheritance with an unfilled, triangular arrow head.
The sub-classes are listed below with their name together with with any processing performed, the number of values returned by
data() and the units for values:
AccelerometerPlotSource- none - 3 values - ms-2.
ColorPlotSource- discard data from clear sensor leaving red, green and blue values - 3 values - integer.
GyroPlotSource- none - 3 values - degrees per second (dps).
HumidityPlotSource- none - 1 value - percentage.
IlluminatedColorPlotSource- only pass a single value from sensor selected at instantiation - 1 value - integer.
MagnetometerPlotSource- none - 3 values - uT.
PinPlotSource- converted to voltage - 1 value per pin, maximum of 3 - V.
PressurePlotSource- optionally converted to inches of mercury - 1 value - hPa or inHg.
ProximityPlotSource- none - 1 value - integer.
TemperaturePlotSource- optionally converted to Fahrenheit - 1 value - degrees Celsius or Fahrenheit.
VolumePlotSource- conversion to decibel scale - 1 value - dB.
The colour sensor here is actually represented by two classes. There are different ways to design the illuminated vs the non-illuminated colour plot source.
- The variation in behaviour can be achieved with conditional logic inside a single class. The selection of the desired behaviour can be achieved in many ways:
- creation of two objects with the variety passed as a parameter as the object is constructed;
- a single object with additional methods extending the interface;
- a single object with an optional parameter to the existing
- Increased use of inheritance with two or three classes, e.g.
IlluminatedColorPlotSourcecould be derived from
ColorPlotSourceand optionally a
NonIlluminatedColorPlotSourcecould be created.
- Two classes derived from
The final option was the one chosen with the
IlluminatedColorPlotSource using the
stop() methods to turn on the CLUE's pair of bright, white, forward-facing LEDs for the duration of the illuminated plotting. The sensor's gain is also set a little higher.