Show/Hide Toolbars

Android Applications

Navigation: Delphi Libraries

Mobile Sensor Utilities

Scroll Prev Top Next More

As a general rule I tend to choose not to use non visual components. It made sense therefore to wrap all sensors in an object library which encapsulates the stuff I needed to learn and also to allow "Dummy" sensors to enable the exercise of code on Windows even when the Windows computer does not support the sensor.

 

Object TIsSensorManager

 

Initially used just to interrogate the device and list the sensor functions supported. Later expanded to act as a global registry of all sensor objects in the event of a reset. This functionality may not be required.

 

Object TIsTimedEventSensor  

 

An abstract base object to contain common functionality so that all sensors operated the same way - a callback when data was ready. Later changes to handle the global sensor manager registration. All sensors of a type (Eg Location) are discovered and handled. While most mobiles only have one sensor of each type that is not assumed. This object also allows the dummy sensors to be created in windows using TDummyWindowsLocationSensor and TDummyWindowsMotionSensor. For those sensors that do not initiate a sensor event the Timer queries the sensor values  in the descendent object (GetValues) and in turn will call an OnChange event.

 

Objects TIsOrientationSensor and TIsMotionSensor

 

Customizations of TIsTimedEventSensor to expose appropriate properties, The list will/should be added to to accommodate other sensors. Mostly just coding to interrogate different types and properties.

 

Object TIsLocationSensor

 

My initial attempt at accessing a sensor without the non visual component. All potential location values are collected from sensors and stored as private values (eg. FStateProvince) but are not exposed as properties as I was mainly interested in GPS functions and Android Device do not support these values. If multiple sensors happen to provide the same property the object will store the last one to report via an OnChange event. The object contains functions to try to manipulate and rationalize the data reported and converting TLocationCoord2D references to  the record type RNavigateLongLat from Navigation Utilities.

 

In addition to providing the actual GPS values reported by the sensor the object provide glitch removal, smoothing and (for stationary devices) averages.

 

When averages are activated an OnBeforeAverageReset event and reset are actioned when the device is moved. If a motion sensor object is allocated to the location object that can flag movement then movement of the device will reset an average session. A parameter MetersToTriggerLocationChange (default 10m) can also be set to indicate movement but this is set to at least 100 meters if a Motion Sensor is present. The reset can also be triggered by the completion of AverageResetLimit (Default 10) GPS samples without change.