Ik beweeg in alle richtingen, de waardes blijven 0Ik neem aan dat je je toestel dan wel aan het bewegen bent (of elke keer in een andere stand houdt).?
Het is een sensor die in het toestel gebouwd zit, en ik vindt er van alles over op internet.Maar hoe kom je aan die OrientationSensor1.
Is dat niet gewoon een willekeurige sensor?
Helaas krijg ik er geen enkele waarde uit op deze na:
Label1.Text := FloatToStr( OrientationSensor1.Sensor.UpdateInterval ); //Geeft de waarde 1000 (1000 ms ?)
Ik heb geen idee wat voor soort variable ik uit kan lezen:Wat is de waarde van TSensorType in die OrientationSensor1?
Label1.Text := OrientationSensor1.Sensor.SensorType;
Label1.Text := FloatToStr( OrientationSensor1.Sensor.SensorType );
Label1.Text := IntToStr( OrientationSensor1.Sensor.SensorType );
Al deze regels (telkens één regel geprobeerd) geven fout meldingen.
Label1.Text := IntToStr( ord(OrientationSensor1.Sensor.SensorType) );
?
Misschien is de SensorType ook een property in de ObjectInspector.
Dan zie je direct welke waarde die heeft.
Hij moet op Compas3D gezet worden.
En heb je OrientationSensor1.Sensor.Start; gedaan
Probeer de code van hier eens:
http://stackoverflow.com/questions/2...r-data-in-memo
Vooral die LocationSensor1.Sensor.AvailableProperties uitlezen na de OrientationSensor1.Sensor.Start;
Last edited by rvk; 15-Sep-16 at 17:49.
Nee dat had ik niet gedaan, dus heb dat nu meteen gedaan. Helaas het probleem blijft.En heb je OrientationSensor1.Sensor.Start; gedaan
Ik lees onderaan iets over een Bug in XE8, het zal toch zeker niet weer zo zijnProbeer de code van hier eens:
http://stackoverflow.com/questions/2...r-data-in-memo
Mogen ga ik met deze code bezig, moet nu gaan werken...
Als ik die code opneem in mijn code dan krijg ik van alle kanten fout meldingen.
Daarom ben ik maar eens een nieuw project begonnen.
Na opstart krijg ik:Code:unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Sensors, System.Sensors.Components, FMX.StdCtrls, FMX.Controls.Presentation; type TForm1 = class(TForm) OrientationSensor1: TOrientationSensor; Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.FormActivate(Sender: TObject); begin OrientationSensor1.Active := True; Sleep(1000); // 1Sec. wachten OrientationSensor1.Sensor.Start; Sleep(1000); // 1Sec. wachten if OrientationSensor1.Sensor.Started then Label1.Text := 'Gestart'; end; procedure TForm1.Button1Click(Sender: TObject); begin Label1.Text := IntToStr( ord(OrientationSensor1.Sensor.SensorType) ); Label2.Text := FloatToStr( OrientationSensor1.Sensor.HeadingX ); Label3.Text := FloatToStr( OrientationSensor1.Sensor.HeadingY ); Label4.Text := FloatToStr( OrientationSensor1.Sensor.HeadingZ ); end; end.
Gestart
en als ik op Button1 druk:
2
0
0
0
================================================== =======================
Dit heb ik er nu van gemaakt, klopt het zo ?:
Ik heb alleen de eerste voorbeeld code gebruikt, dus mogelijk moet ik nog iets wijzigen waarover verder op die site gesproken wordt...Code:unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Sensors, System.Sensors.Components, FMX.StdCtrls, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo; //, TypInfo; //------------------------- type TOrientationSensorAccessor = class(TCustomOrientationSensor); TLocationSensorAccessor = class(TCustomLocationSensor); //------------------------- type TForm1 = class(TForm) OrientationSensor1: TOrientationSensor; Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Button2: TButton; Memo1: TMemo; LocationSensor1: TLocationSensor; procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation //---------------- uses TypInfo; //---------------- {$R *.fmx} procedure TForm1.FormActivate(Sender: TObject); begin OrientationSensor1.Active := True; Sleep(1000); // 1Sec. wachten OrientationSensor1.Sensor.Start; Sleep(1000); // 1Sec. wachten if OrientationSensor1.Sensor.Started then Label1.Text := 'Gestart'; end; procedure TForm1.Button1Click(Sender: TObject); begin Label1.Text := IntToStr( ord(OrientationSensor1.Sensor.SensorType) ); Label2.Text := FloatToStr( OrientationSensor1.Sensor.HeadingX ); Label3.Text := FloatToStr( OrientationSensor1.Sensor.HeadingY ); Label4.Text := FloatToStr( OrientationSensor1.Sensor.HeadingZ ); end; procedure TForm1.Button2Click(Sender: TObject); var p_location: TCustomLocationSensor.TProperty; p_orientation: TCustomOrientationSensor.TProperty; n, v: string; begin Memo1.Lines.Clear; if Assigned(OrientationSensor1.Sensor) then begin if not OrientationSensor1.Sensor.Started then OrientationSensor1.Sensor.Start; // Error (only in XE8): Incompatible types 'TCustomLocationSensor.TProperty' and 'TCustomOrientationSensor.TProperty' // In XE7 it works. for p_orientation in OrientationSensor1.Sensor.AvailableProperties do begin n := 'OrientationSensor.'+GetEnumName(TypeInfo(TCustomOrientationSensor.TProperty), integer(p_orientation)) ; v := FloatToStr(TOrientationSensorAccessor(OrientationSensor1.Sensor).GetDoubleProperty(p_orientation)); Memo1.Lines.Values[n] := v; end; end; // if Assigned(LocationSensor1.Sensor) then // begin // if not LocationSensor1.Sensor.Started then LocationSensor1.Sensor.Start; // for p_location in LocationSensor1.Sensor.AvailableProperties do // begin // n := 'LocationSensor.'+GetEnumName(TypeInfo(TCustomLocationSensor.TProperty), integer(p_location)) ; // v := FloatToStr(TLocationSensorAccessor(LocationSensor1.Sensor).GetDoubleProperty(p_location)); // Memo1.Lines.Values[n] := v; // end; // end; end; end.
Met deze (huidige) code krijg ik helaas nog steeds 3 keer de waarde "0".
Last edited by MMSoft; 16-Sep-16 at 10:30.
Ik heb zelf geen FMX dus kan je niet helpen de code erin te zetten.
Maar ik mis hier wel het "kiezen" van de juiste Sensor.
Volgens mij moet de OrientationSensor1 een event OnSensorChoosing hebben.
Daarin moet je controleren of de sensor de juiste property heeft die je wilt hebben en dan moet je ChoseSensorIndex zetten.
Voeg dit eens toe als OnSensorChoosing:
Delphi Code:
procedure TForm1.OrientationSensor1SensorChoosing(Sender: TObject; const Sensors: TSensorArray; var ChoseSensorIndex: Integer); var I, Found: Integer; begin Found := -1; for I := 0 to High(Sensors) do begin // deze zou voor de TiltX zijn // if TCustomOrientationSensor.TProperty.TiltX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then // Found := I; if TCustomOrientationSensor.TProperty.HeadingX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then Found := I; end; if Found < 0 then begin Found := 0; ShowMessage('Compass not available'); end; ChoseSensorIndex := Found; end;
Ik weet niet of je de HeadingXYZ nodig hebt of de TiltXYZ maar probeer ze allebei maar eens.
Tevens weet ik niet zeker wat voor waarde HeadingX terug geeft.
Dat zijn volgens mij MicroTeslas dus die moet je dan converteren.
Je zou ook eens kunnen kijken wat de waarde van MagHeading is.
SensorType = 2Code:for I := 0 to High(Sensors) do begin //deze zou voor de TiltX zijn //if TCustomOrientationSensor.TProperty.TiltX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then // Found := I; if TCustomOrientationSensor.TProperty.HeadingX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then Found := I; end;
HeadingX = 0
TiltX = NAN
MagHeading = NAN
----------------------
SensorType = 5Code:for I := 0 to High(Sensors) do begin //deze zou voor de TiltX zijn if TCustomOrientationSensor.TProperty.TiltX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then Found := I; // if TCustomOrientationSensor.TProperty.HeadingX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then // Found := I; end;
HeadingX = NAN
TiltX = 0
MagHeading = NAN
----------------------
SensorType = 5Code:for I := 0 to High(Sensors) do begin //deze zou voor de TiltX zijn if TCustomOrientationSensor.TProperty.TiltX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then Found := I; if TCustomOrientationSensor.TProperty.HeadingX in TCustomOrientationSensor(Sensors[I]).AvailableProperties then Found := I; end;
HeadingX = NAN
TiltX = 0
MagHeading = NAN
-------------------------------------------------------------------------------
De melding 'Compass not available' heb ik Geen enkele keer gezien.
Deze code heeft er dus invloed op, maar ik krijg of NAN of de waarde 0, dus nog steeds geen bruikbare data
Volgende poging:
Delphi Code:
procedure TForm1.OrientationSensor1Choosing(Sender: TObject; const Sensors: TSensorArray; var ChoseSensorIndex: Integer); var I : integer; begin for I := 0 to Length(Sensors) - 1 do if (Sensors[I] as TCustomOrientationSensor).SensorType = TOrientationSensorType.Compass3D then begin ChoseSensorIndex := I; Break; end; end;
OrientationSensor1.Active := True;
// wat geeft OrientationSensor1.Sensor.CompMagHeading;
Ik denk dat "OrientationSensor1Choosing" moet zijn "OrientationSensor1SensorChoosing", want de eerste geeft een foutmelding.Code:procedure TForm1.OrientationSensor1SensorChoosing(Sender: TObject; const Sensors: TSensorArray; var ChoseSensorIndex: Integer); //procedure TForm1.OrientationSensor1Choosing(Sender: TObject; // const Sensors: TSensorArray; var ChoseSensorIndex: Integer); var I : integer; begin for I := 0 to Length(Sensors) - 1 do if (Sensors[I] as TCustomOrientationSensor).SensorType = TOrientationSensorType.Compass3D then begin ChoseSensorIndex := I; Break; end; end;
Dit even voor de zekerheid voordat ik iets anders doe dan je bedoeld.
Dit geeft NAN, ook nadat ik de GSM in alle richtingen bewogen heb.Code:OrientationSensor1.Active := True; Label1.Text := FloatToStr( OrientationSensor1.Sensor.CompMagHeading );
Ja, het moet OrientationSensor1SensorChoosing zijn.
Niet vergeten dit als Event aan de OrientationSensor1 te hangen !!!
De OnSensorChoosing event wordt uitgevoerd om de juiste sensor in de OrientationSensor1 te kiezen.
Ik begrijp niet waarom je NAN zou krijgen. Ik neem aan dat je wel een compass in je toestel hebt zitten.
Misschien zou je eens wat code kunnen gebruiken op
https://theroadtodelphi.com/2012/09/...monkey-part-1/
Maar je werkt op een Android, toch?
Je zou dit eens kunnen proberen...
(maar dan i.p.v. een WriteLn() de tekst in een Memo1.Lines.Add() stoppen)
Delphi Code:
var LManager : TSensorManager; LSensors : TSensorArray; LSensor : TCustomSensor; LLocationSensor : TCustomLocationSensor; begin LManager := TSensorManager.Current; LManager.Activate; try LSensors := LManager.GetSensorsByCategory(TSensorCategory.Location); for LSensor in LSensors do begin Writeln(Format('Description : %s', [LSensor.Description])); Writeln(Format('Manufacturer : %s', [LSensor.Manufacturer])); Writeln(Format('Model : %s', [LSensor.Model])); Writeln(Format('Serial No : %s', [LSensor.SerialNo])); Writeln(Format('State : %s', [GetEnumName(TypeInfo(TSensorState),integer(LSensor.State))])); Writeln(Format('TimeStamp : %s', [DatetoStr(LSensor.TimeStamp)])); Writeln(Format('Unique ID : %s', [LSensor.UniqueID])); LLocationSensor:=LSensor as TCustomLocationSensor; LLocationSensor.Start; try Writeln(Format('Sensor Type : %s', [GetEnumName(TypeInfo(TLocationSensorType),integer(LLocationSensor.SensorType))])); Writeln(Format('Authorized : %s', [GetEnumName(TypeInfo(TAuthorizationType),integer(LLocationSensor.Authorized))])); Writeln(Format('Accuracy : %n', [LLocationSensor.Accuracy])); Writeln(Format('Distance : %n', [LLocationSensor.Distance])); Writeln(Format('Power Consumption : %s', [GetEnumName(TypeInfo(TPowerConsumption),integer(LLocationSensor.PowerConsumption))])); Writeln(Format('Location Change : %s', [GetEnumName(TypeInfo(TLocationChangeType),integer(LLocationSensor.LocationChange))])); if TCustomLocationSensor.TProperty.Latitude in LLocationSensor.AvailableProperties then Writeln(Format('Latitude : %n', [LLocationSensor.Latitude])); if TCustomLocationSensor.TProperty.Longitude in LLocationSensor.AvailableProperties then Writeln(Format('Longitude : %n', [LLocationSensor.Longitude])); if TCustomLocationSensor.TProperty.ErrorRadius in LLocationSensor.AvailableProperties then Writeln(Format('Error Radius : %n', [LLocationSensor.ErrorRadius])); if TCustomLocationSensor.TProperty.Altitude in LLocationSensor.AvailableProperties then Writeln(Format('Altitude : %n', [LLocationSensor.Altitude])); if TCustomLocationSensor.TProperty.Speed in LLocationSensor.AvailableProperties then Writeln(Format('Speed : %n', [LLocationSensor.Speed])); if TCustomLocationSensor.TProperty.TrueHeading in LLocationSensor.AvailableProperties then Writeln(Format('True Heading : %n', [LLocationSensor.TrueHeading])); if TCustomLocationSensor.TProperty.MagneticHeading in LLocationSensor.AvailableProperties then Writeln(Format('Magnetic Heading : %n', [LLocationSensor.MagneticHeading])); if TCustomLocationSensor.TProperty.Address1 in LLocationSensor.AvailableProperties then Writeln(Format('Address1 : %s', [LLocationSensor.Address1])); if TCustomLocationSensor.TProperty.Address2 in LLocationSensor.AvailableProperties then Writeln(Format('Address2 : %s', [LLocationSensor.Address2])); if TCustomLocationSensor.TProperty.City in LLocationSensor.AvailableProperties then Writeln(Format('City : %s', [LLocationSensor.City])); if TCustomLocationSensor.TProperty.StateProvince in LLocationSensor.AvailableProperties then Writeln(Format('State/Province : %s', [LLocationSensor.StateProvince])); if TCustomLocationSensor.TProperty.PostalCode in LLocationSensor.AvailableProperties then Writeln(Format('Postal Code : %s', [LLocationSensor.PostalCode])); if TCustomLocationSensor.TProperty.CountryRegion in LLocationSensor.AvailableProperties then Writeln(Format('Country Region : %s', [LLocationSensor.CountryRegion])); finally LLocationSensor.Stop; end; Writeln; end; finally LManager.Deactivate; end; end;
Deze is vanaf het begin al gekoppeld als een Events.Niet vergeten dit als Event aan de OrientationSensor1 te hangen !!!
Als ik een orginele Compass App installeer dan werkt die App wel.Ik neem aan dat je wel een compass in je toestel hebt zitten
Het is een Samsung Galaxy S2, GT-I8260
Tevens heb ik een Samsung Galaxy S4, GT-I9505, maar daar werkt het ook niet op.
Op deze S4 werkt een orginele Compass App ook niet, dus deze heeft blijkbaar ook geen OrientationSensor.
Maar op de S2 zou het toch moeten werken ?
KloptMaar je werkt op een Android, toch?
Dat geeft dit:Je zou dit eens kunnen proberen...
Last edited by MMSoft; 20-Sep-16 at 20:05.
Geeft ie maar één sensor resultaat? Hij zou er veel meer moeten geven waaronder een compass.
Je kunt niet naar beneden scrollen in die memo?
Nee, er staat niet meer in de Memo.
Hierbij de volledige code:
Code:unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Sensors, System.Sensors.Components, FMX.StdCtrls, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo; //, TypInfo; //------------------------- type TOrientationSensorAccessor = class(TCustomOrientationSensor); TLocationSensorAccessor = class(TCustomLocationSensor); //------------------------- type TForm1 = class(TForm) OrientationSensor1: TOrientationSensor; Button1: TButton; Memo1: TMemo; LocationSensor1: TLocationSensor; MotionSensor1: TMotionSensor; procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure OrientationSensor1SensorChoosing(Sender: TObject; const Sensors: TSensorArray; var ChoseSensorIndex: Integer); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation //---------------- uses TypInfo; //---------------- {$R *.fmx} procedure TForm1.FormActivate(Sender: TObject); begin LocationSensor1.Active := True; OrientationSensor1.Active := True; MotionSensor1.Active := True; end; procedure TForm1.OrientationSensor1SensorChoosing(Sender: TObject; const Sensors: TSensorArray; var ChoseSensorIndex: Integer); var I : integer; begin for I := 0 to Length(Sensors) - 1 do if (Sensors[I] as TCustomOrientationSensor).SensorType = TOrientationSensorType.Compass3D then begin ChoseSensorIndex := I; Break; end; end; procedure TForm1.Button1Click(Sender: TObject); var LManager : TSensorManager; LSensors : TSensorArray; LSensor : TCustomSensor; LLocationSensor : TCustomLocationSensor; begin LManager := TSensorManager.Current; LManager.Activate; try LSensors := LManager.GetSensorsByCategory(TSensorCategory.Location); for LSensor in LSensors do begin Memo1.Lines.Add( Format('Description : %s', [LSensor.Description])) ; Memo1.Lines.Add( Format('Manufacturer : %s', [LSensor.Manufacturer])); Memo1.Lines.Add( Format('Model : %s', [LSensor.Model])); Memo1.Lines.Add( Format('Serial No : %s', [LSensor.SerialNo])); Memo1.Lines.Add( Format('State : %s', [GetEnumName(TypeInfo(TSensorState),integer(LSensor.State))])); Memo1.Lines.Add( Format('TimeStamp : %s', [DatetoStr(LSensor.TimeStamp)])); Memo1.Lines.Add( Format('Unique ID : %s', [LSensor.UniqueID])); LLocationSensor:=LSensor as TCustomLocationSensor; LLocationSensor.Start; try Memo1.Lines.Add( Format('Sensor Type : %s', [GetEnumName(TypeInfo(TLocationSensorType),integer(LLocationSensor.SensorType))])); Memo1.Lines.Add( Format('Authorized : %s', [GetEnumName(TypeInfo(TAuthorizationType),integer(LLocationSensor.Authorized))])); Memo1.Lines.Add( Format('Accuracy : %n', [LLocationSensor.Accuracy])); Memo1.Lines.Add( Format('Distance : %n', [LLocationSensor.Distance])); Memo1.Lines.Add( Format('Power Consumption : %s', [GetEnumName(TypeInfo(TPowerConsumption),integer(LLocationSensor.PowerConsumption))])); Memo1.Lines.Add( Format('Location Change : %s', [GetEnumName(TypeInfo(TLocationChangeType),integer(LLocationSensor.LocationChange))])); if TCustomLocationSensor.TProperty.Latitude in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Latitude : %n', [LLocationSensor.Latitude])); if TCustomLocationSensor.TProperty.Longitude in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Longitude : %n', [LLocationSensor.Longitude])); if TCustomLocationSensor.TProperty.ErrorRadius in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Error Radius : %n', [LLocationSensor.ErrorRadius])); if TCustomLocationSensor.TProperty.Altitude in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Altitude : %n', [LLocationSensor.Altitude])); if TCustomLocationSensor.TProperty.Speed in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Speed : %n', [LLocationSensor.Speed])); if TCustomLocationSensor.TProperty.TrueHeading in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('True Heading : %n', [LLocationSensor.TrueHeading])); if TCustomLocationSensor.TProperty.MagneticHeading in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Magnetic Heading : %n', [LLocationSensor.MagneticHeading])); if TCustomLocationSensor.TProperty.Address1 in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Address1 : %s', [LLocationSensor.Address1])); if TCustomLocationSensor.TProperty.Address2 in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Address2 : %s', [LLocationSensor.Address2])); if TCustomLocationSensor.TProperty.City in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('City : %s', [LLocationSensor.City])); if TCustomLocationSensor.TProperty.StateProvince in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('State/Province : %s', [LLocationSensor.StateProvince])); if TCustomLocationSensor.TProperty.PostalCode in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Postal Code : %s', [LLocationSensor.PostalCode])); if TCustomLocationSensor.TProperty.CountryRegion in LLocationSensor.AvailableProperties then Memo1.Lines.Add( Format('Country Region : %s', [LLocationSensor.CountryRegion])); finally LLocationSensor.Stop; end; Memo1.Lines.Add( ' ' ); end; finally LManager.Deactivate; end; end; end.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks