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()
orstart(Parameters)
, and can be stopped at any time by callingstop()
.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 aChangeListener
to thereading 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
-
-
Field Summary
Fields Modifier and Type Field Description static Parameters
DEFAULT_PARAMETERS
Default frequency is 10 Hz (10 samples per second).
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static java.util.Optional<MagnetometerService>
create()
Returns an instance ofMagnetometerService
.MagnetometerReading
getReading()
Returns a single reading from the magnetometer.javafx.beans.property.ReadOnlyObjectProperty<MagnetometerReading>
readingProperty()
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.
-
-
-
Field Detail
-
DEFAULT_PARAMETERS
static final Parameters DEFAULT_PARAMETERS
Default frequency is 10 Hz (10 samples per second).
-
-
Method Detail
-
create
static java.util.Optional<MagnetometerService> 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.- Returns:
- A property containing a frequently-updated magnetometer reading.
-
start
void start()
Starts the service withDEFAULT_PARAMETERS
.- Since:
- 4.0.10
-
start
void start(Parameters parameters)
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
-
-