Package com.gluonhq.attach.magnetometer
Interface MagnetometerService
- All Known Implementing Classes:
AndroidMagnetometerService
,DummyMagnetometerService
,IOSMagnetometerService
,MobileMagnetometerService
public interface MagnetometerService
A magnetometer measures the ambient geomagnetic field for all three physical axes (x, y and z).
The service gets started by calling either start()
or
start(Parameters)
, and can be stopped
at any time by calling stop()
.
The MagnetometerService provides a read-only reading property
that is updated at regular intervals by the underlying platform implementation. A user of the
MagnetometerService can listen to changes of the magnetic field, by registering a
ChangeListener
to the
reading property
.
Example
MagnetometerService.create().ifPresent(service -> {
service.start();
MagnetometerReading reading = service.getReading();
System.out.printf("Magnetic field: %.4f, %.4f, %.4f. Magnitude: %.4f",
reading.getX(), reading.getY(), reading.getZ(), reading.getMagnitude());
});
Android Configuration: none
iOS Configuration: none
- Since:
- 3.0.0
-
Property Summary
TypePropertyDescriptionjavafx.beans.property.ReadOnlyObjectProperty<MagnetometerReading>
A frequently-updated reading from the magnetometer. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Parameters
Default frequency is 10 Hz (10 samples per second). -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<MagnetometerService>
create()
Returns an instance ofMagnetometerService
.Returns a single reading from the magnetometer.javafx.beans.property.ReadOnlyObjectProperty<MagnetometerReading>
A frequently-updated reading from the magnetometer.void
start()
Starts the service withDEFAULT_PARAMETERS
.void
start
(Parameters parameters) Starts the service with given parameters.void
stop()
Stops the service.
-
Property Details
-
reading
javafx.beans.property.ReadOnlyObjectProperty<MagnetometerReading> readingPropertyA frequently-updated reading from the magnetometer.- See Also:
-
-
Field Details
-
DEFAULT_PARAMETERS
Default frequency is 10 Hz (10 samples per second).
-
-
Method Details
-
create
Returns an instance ofMagnetometerService
.- Returns:
- An instance of
MagnetometerService
.
-
getReading
MagnetometerReading getReading()Returns a single reading from the magnetometer.- Returns:
- the current magnetometer reading
-
readingProperty
javafx.beans.property.ReadOnlyObjectProperty<MagnetometerReading> readingProperty()A frequently-updated reading from the magnetometer.- See Also:
-
start
void start()Starts the service withDEFAULT_PARAMETERS
.- Since:
- 4.0.10
-
start
Starts the service with given parameters.- Parameters:
parameters
- Parameters for configuring the service- Since:
- 4.0.10
-
stop
void stop()Stops the service.- Since:
- 4.0.10
-