ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Mobile specific functions / Sensor functions
  • Use conditions
  • Device orientation: definitions
  • Stop detection
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
SensorDetectChangeOrientation (Function)
In french: CapteurDétecteChangementOrientation
Allows you to be notified when the orientation of the device changes on any one of its 3 axes.
Example
// Détection des changements d'orientation sur plusieurs axes
SensorDetectChangeOrientation(DetectionOrientation, snrAzimuth + snrPitch + snrRoll)
// Procédure appelée par la fonction CapteurDétecteChangementOrientation
PROCÉDURE DetectionOrientation(nAzimut is int, nPitch is int, nRoll is int)
IF nAzimut = 0 OR nAzimut = 360 THEN
ToastDisplay("L'appareil est orienté vers le Nord.")
END
 
// Arrêt de la détection des changements d'orientation:
SensorEnd()
Syntax
<Result> = SensorDetectChangeOrientation(<WLanguage procedure> [, <Orientation> [, <Frequency> [, <Threshold>]]])
<Result>: Boolean
  • True if the detection was triggered,
  • False otherwise.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure ("callback") called when the device changes orientation. This procedure has the following format:
PROCEDURE <Nom de la procédure> (<Azimut>, <Pitch>, <Roll>)
where:
  • <Azimuth> is an integer corresponding to the angle between the direction of the magnetic North and the direction of the longitudinal axis (Y) of the device,
  • <Pitch> is an integer corresponding to the rotation angle of the device around the horizontal axis (X)
  • <Roll> is an integer corresponding to the rotation angle of the device around the longitudinal axis (Y).
The parameters of this procedure are optional. There is no need to pass parameters to this procedure. Indeed, these parameters are automatically filled during each call providing that the corresponding type of orientation is specified in <Orientation>. Otherwise, these parameters are set to 0.
If the name of the procedure corresponds to an empty string (""), the notifications for change of orientation corresponding to <Orientation> will not be sent anymore.
<Orientation>: Optional Integer constant (or combination of constants)
Type of orientation change that must be noted:
snrAzimuthNotification when the orientation changes around the vertical axis (Z).
snrPitchNotification when the orientation changes around the horizontal axis (X).
snrRollNotification when the orientation changes around the longitudinal axis (Y).

By default, a notification will be sent when the orientation changes on any one of the three axes (equivalent to snrAzimuth + snrPitch + snrRoll).
<Frequency>: Optional Integer constant
Frequency according to which the notifications for changes of orientation must be sent:
snrFrequencyGameNotification frequency required when using SensorDetectChangeOrientation in a game.
snrFrequencyNormal
(Default value)
Standard frequency of notification.
snrFrequencyQuickFast frequency of notification.

iPhone/iPad This parameter is ignored. The frequency is the same, regardless of the specified constant.
<Threshold>: Optional integer
Threshold for tolerance in changing (in degrees). The notifications will be sent for the changes of orientation greater than this threshold.
No threshold will be fixed if this parameter is not specified: the notifications will be sent for each change of orientation (equivalent to a threshold set to 0).
Remarks

Use conditions

  • This function cannot be used in the emulator or in the simulator. In both cases, the result of the function will always be set to False.
  • The detection of orientation changes uses the accelerometer sensor found on the device. No detection of orientation changes will be performed if this sensor is not found on the device. The sensitivity of the detection depends on the quality of the sensor in the device.
  • Only the last call to SensorDetectChangeOrientation is taken into account. Indeed, there can only be one detection at a time. To perform a detection according to multiple axes, you must combine the orientations.

Device orientation: definitions

The change of orientation can be specified according to the three following dimensions:
  • Azimuth: Direction of the device in relation to the magnetic North around the vertical axis (Z). This direction is expressed in degrees (from 0 to 360 degrees). In this case, 0 or 360 corresponds to the North, 90 corresponds to the East, 180 corresponds to the South and 270 corresponds to the West.
  • Pitch: Rotation of the device around the horizontal axis (X). This rotation is expressed in degrees (from -180 to 180). Its value is set to 0 degree when the device lies down flat with the screen pointing to the ceiling, -90 degrees when the device stands still with the top of the device pointing to the ceiling, 90 degrees when the device stands still with the top of the device pointing to the ground and -180/180 degrees when the device lies down flat with the screen pointing to the ground.
  • Roll: Rotation of the device around the longitudinal axis (Y). This rotation is expressed in degrees (from -90 to 90). Its value is set to 0 degree when the device lies down flat with the screen pointing to the ceiling, -90 degrees when the screen is oriented to the left and 90 degrees when the screen is oriented to the right.
Origin of the orientation
System of coordinates (considering that the device lies down flat, the screen directed to the ceiling):
  • The origin is found in the lower-left corner of the screen.
  • The X-axis represents the horizontal axis and it points to the right of the screen.
  • The Y-axis represents the longitudinal axis and it points to the top of the screen.
  • The Z-axis represents the vertical axis and it points outside the front of the screen.

Stop detection

We advise you to stop detecting the changes of orientation when no longer required in order to save the battery of the device. To do so, <WLanguage procedure> must correspond to an empty string ("").
SensorEnd is used to stop all the current detections.
Related Examples:
WM System Cross-platform examples (WINDEV Mobile): WM System
[ + ] This application is an example of some of the features of WINDEV Mobile available for Android/iOS.
The following system functions are used:
- NFC
- Multimedia control
- Brightness
- Volume
- Wi-Fi
- Bluetooth
- Toast
- Compass
- Accelerometer
- Camera control
- LED
- Vibration
- Notifications
- Drawing functions
- Internet
Component: WDJS.DLL
See also
Minimum version required
  • Version 16
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/23/2023

Send a report | Local help