From Clomosy Docs

In Clomosy, a sensor is used in the context of mobile application development to detect the orientation of the device. The 'FormOrientationSensorType' property determines which type of sensor the mobile form will use to track the device's orientation.

For example, if the 'FormOrientationSensorType' property is set to "ostTilt," it will track the tilt of the device.

This property allows applications to track the position of the device, enabling operations like screen rotation. This is particularly important for games, map applications, and other mobile applications.

Feature Use of Definition
FormOrientationSensorType MyForm.FormOrientationSensorType = ostTilt; It determines which type of sensor will be used to track the device's orientation.
ostTilt MyForm.FormOrientationSensorType = ostTilt; Specifies the amount the device tilts around an axis.
ostHeading MyForm.FormOrientationSensorType = ostHeading; Specifies the angle of the device towards north.
Active MyForm.FormOrientationSensor.Active = True; Sensor usage is activated.

Compass Sensor (ostHeading)

"ostHeading" stands for "Orientation Sensor Heading." This term specifies the direction a device is facing. It indicates which way the device is oriented.

For example, in a compass application, the ostHeading value may represent the angle at which the device is pointing towards the north direction. This indicates how much the device has turned relative to the north.

In summary, ostHeading provides information about the device's orientation and which direction it is facing. This is particularly useful for applications that need to track the device's heading, such as compass or navigation applications.

You should write the following commands to obtain the X, Y, and Z position sensors.

Use of:

currentXHeading = MyForm.FormOrientationSensor.Sensor.HeadingX;
currentYHeading = MyForm.FormOrientationSensor.Sensor.HeadingY;
currentZHeading = MyForm.FormOrientationSensor.Sensor.HeadingZ;

Example

var
  MyForm: TCLForm;
  CompassImg,DirectionImg: TClProImage;
  GetTimer: TClTimer;
  CompassXLabel,CompassYLabel,CompassZLabel : TclLabel;

void GetCompass;
var
  currentYHeading,currentXHeading,currentZHeading: Double;
  rotationAngle: Double;
{
  if (not MyForm.FormOrientationSensor.Sensor == nil)
  {
    currentYHeading = MyForm.FormOrientationSensor.Sensor.HeadingY;
    currentXHeading = MyForm.FormOrientationSensor.Sensor.HeadingX;
    currentZHeading = MyForm.FormOrientationSensor.Sensor.HeadingZ;
    
    CompassXLabel.Text = 'X : '+FloatToStr(Abs(currentXHeading));
    CompassYLabel.Text = 'Y : '+FloatToStr(Abs(currentYHeading));
    CompassZLabel.Text = 'Z : '+FloatToStr(Abs(currentZHeading));
  }
  CompassImg.RotationAngle = currentYHeading;
}

{
  MyForm = TCLForm.Create(Self);
  
  MyForm.SetFormBGImage('https://clomosy.com/demos/compassbg.png');
  CompassXLabel = MyForm.AddNewLabel(MyForm,'CompassXLabel','--');
  CompassXLabel.Align = alBottom;
  CompassXLabel.Margins.Bottom= 30; 
  CompassXLabel.Height = 50;
  CompassXLabel.Width = 150;
  
  CompassYLabel = MyForm.AddNewLabel(MyForm,'CompassYLabel','--');
  CompassYLabel.Align = alBottom;
  CompassYLabel.Margins.Bottom= 20; 
  CompassYLabel.Height = 50;
  CompassYLabel.Width = 150;
  
  CompassZLabel = MyForm.AddNewLabel(MyForm,'CompassZLabel','--');
  CompassZLabel.Align = alBottom;
  CompassZLabel.Margins.Bottom= 10; 
  CompassZLabel.Height = 50;
  CompassZLabel.Width = 150;
  
  CompassImg = MyForm.AddNewProImage(MyForm,'CompassImg');
  CompassImg.Align = AlCenter;
  CompassImg.Height = 350;
  CompassImg.Width = 350;
  CompassImg.clProSettings.PictureSource = 'https://clomosy.com/demos/compass2.png';
  CompassImg.clProSettings.PictureAutoFit = True;
  CompassImg.SetclProSettings(CompassImg.clProSettings);
  
  DirectionImg = MyForm.AddNewProImage(MyForm,'DirectionImg');
  DirectionImg.Align = AlCenter;
  DirectionImg.Height = 350;
  DirectionImg.Width = 350;
  DirectionImg.Margins.Right = 28;
  DirectionImg.Margins.Bottom = 100;
  DirectionImg.clProSettings.PictureSource = 'https://clomosy.com/demos/compass_arrow2.png';
  DirectionImg.clProSettings.PictureAutoFit = True;
  DirectionImg.SetclProSettings(DirectionImg.clProSettings);
  
  MyForm.FormOrientationSensorType = ostHeading;
  MyForm.FormOrientationSensor.Active = True;
  
  If (Clomosy.PlatformIsMobile)
  {   
  GetTimer = MyForm.AddNewTimer(MyForm, 'GetTimer', 500);
  GetTimer.Enabled = True;
  MyForm.AddNewEvent(GetTimer, tbeOnTimer, 'GetCompass'); 
  } else ShowMessage('To use the feature, log in from your mobile device.');
  MyForm.Run;
}

Balance Sensor (ostTilt)

"ostTilt" is the abbreviation for "Orientation Sensor Tilt." This term indicates the inclination or tilt of a device. It specifies how much the device is tilted around an axis.

For example, ostTilt can be used to determine the angle at which a device is inclined. This indicates how much the device is tilted in the horizontal plane.

You should write the following commands to obtain the X, Y, and Z position sensors.

Use of:

 currentXTilt = MyForm.FormOrientationSensor.Sensor.TiltX;
 currentYTilt = MyForm.FormOrientationSensor.Sensor.TiltY;
 currentZTilt = MyForm.FormOrientationSensor.Sensor.TiltZ;

Example

var
  MyForm: TCLForm;
  CompassImg: TClProImage;
  GetTimer: TClTimer;
  TiltXLabel,TiltYLabel,TiltZLabel : TclLabel;

void GetTilt;
var
  currentYTilt,currentXTilt,currentZTilt: Double;
  rotationAngle: Double;
{
  if (not MyForm.FormOrientationSensor.Sensor==nil)
  {
    currentXTilt = MyForm.FormOrientationSensor.Sensor.TiltX;
    currentYTilt = MyForm.FormOrientationSensor.Sensor.TiltY;
    currentZTilt = MyForm.FormOrientationSensor.Sensor.TiltZ;
    
    TiltXLabel.Text = 'X : '+FloatToStr(currentXTilt);
    TiltYLabel.Text = 'Y : '+FloatToStr(currentYTilt);
    TiltZLabel.Text = 'Z : '+FloatToStr(currentZTilt);
  }
  CompassImg.RotationAngle = currentXTilt;
}

{
  MyForm = TCLForm.Create(Self);
  
  MyForm.SetFormBGImage('https://clomosy.com/demos/compassbg.png');
  TiltXLabel = MyForm.AddNewLabel(MyForm,'TiltXLabel','--');
  TiltXLabel.Align = alBottom;
  TiltXLabel.Margins.Bottom= 30; 
  TiltXLabel.Height = 50;
  TiltXLabel.Width = 150;
  
  TiltYLabel = MyForm.AddNewLabel(MyForm,'TiltYLabel','--');
  TiltYLabel.Align = alBottom;
  TiltYLabel.Margins.Bottom= 20; 
  TiltYLabel.Height = 50;
  TiltYLabel.Width = 150;
  
  TiltZLabel = MyForm.AddNewLabel(MyForm,'TiltZLabel','--');
  TiltZLabel.Align = alBottom;
  TiltZLabel.Margins.Bottom= 10; 
  TiltZLabel.Height = 50;
  TiltZLabel.Width = 150;
  
  CompassImg = MyForm.AddNewProImage(MyForm,'CompassImg');
  CompassImg.Align = AlCenter;
  CompassImg.Height = 350;
  CompassImg.Width = 350;
  CompassImg.clProSettings.PictureSource = 'https://clomosy.com/demos/balance.png';
  CompassImg.clProSettings.PictureAutoFit = True;
  CompassImg.SetclProSettings(CompassImg.clProSettings);
  
  MyForm.FormOrientationSensorType = ostTilt;
  MyForm.FormOrientationSensor.Active = True;
  If(Clomosy.PlatformIsMobile)
  { 
    GetTimer = MyForm.AddNewTimer(MyForm, 'GetTimer', 500); 
    GetTimer.Enabled = True;
    MyForm.AddNewEvent(GetTimer, tbeOnTimer, 'GetTilt');
  } else ShowMessage('To use the feature, log in from your mobile device.');
  MyForm.Run;
}

See Also