Thema: 

G-Sensor Programmierung

Diskutiere G-Sensor Programmierung im Programmieren Forum im Bereich Windows Mobile 6.5 und älter; Hallo, ich habe folgende Problemstellung, ich moechte mir eine Bluetooth Fernbedienung Programmieren die mittels Bewegung und einigen wenigen Tasten funktioniert.

  1. #1

    G-Sensor Programmierung

    Hallo,
    ich habe folgende Problemstellung, ich moechte mir eine Bluetooth Fernbedienung Programmieren die mittels Bewegung und einigen wenigen Tasten funktioniert.

    Das eigentliche Problem ist nun der G-Sensor, um genauer zu sein die Daten des Sensors zu lesen, das Auswerten sollte eigentlich kein Problem sein, ist hier evt. jemand der Erfahrung hat oder einen Link empfehlen kann, SDK etc.? Bin dankbar fuer jegliche Hilfe. Programmiersprache sollte C++ sein, ungern aber moeglich waere auch C#.

    Vielen Dank schonmal im Vorraus.

  2. #2
    CSC
    CSC ist offline

    AW: G-Sensor Programmierung

    Guck mal hier:

    http://blog.enterprisemobile.com/200...-managed-code/

    Damit hab ich mal was programmiert (Visual Studio, .NET CF, C#), ging super...

  3. #3

    AW: G-Sensor Programmierung

    Ich habe den Thread verschoben, hier würdest du mehr Antworten bekommen.

    mfg
    timsah

  4. Die folgenden Benutzer danken timsah für diesen wertvollen Beitrag:

    yjeanrenaud (08.11.2009)

  5. #4

    AW: G-Sensor Programmierung

    http://scottandmichelle.net/scott/co...html?entry=784 (Englisch) ist ein Beispielprojekt in C++.


  6. #5

    AW: G-Sensor Programmierung

    Vielen dank fuer die schnelle Hilfe, hab gefunden wonach ich gesucht hab.

    Denke es werden jetzt einige lange Naechte folgen

  7. #6

    AW: G-Sensor Programmierung

    Hallo,
    ich versuche ebenfalls den G-Sensor auf einem HTC HD zu programmieren, finde bisher aber nichts dazu im .NET Compact Framework. Die bereits geposteten Links habe ich bereits gefunden, diese beziehen sich aber nur auf C#. Hat das jemand schon in VB realisiert?

  8. #7
    CSC
    CSC ist offline

    AW: G-Sensor Programmierung

    Bis auf eine leicht andere Syntax sollte das genauso funktionieren!

  9. #8

    AW: G-Sensor Programmierung

    Leicht andere Syntax? Ich weiß nicht mal, wie ich mit dem C# Code anfangen muss

  10. #9

    AW: G-Sensor Programmierung

    Das C# Projekt gibt's hier (unter source code). Das enthält Code für die verschiedenen Sensoren für HTC und Omnia.
    Da ich nur den G-Sensor für HTC Geräte brauche, habe ich die folgende Klasse erstellt:
    Code:
    using System;
    using System.Runtime.InteropServices;
    
    namespace GSensorTest
    {
        public class GSensor : IDisposable
        {
            public struct SensorData
            {
                public short TiltX;          // From -1000 to 1000, 0 is flat
                public short TiltY;          // From -1000 to 1000, 0 is flat
                public short TiltZ;          // From -1000 to 1000, 0 = Straight up, -1000 = Flat, 1000 = Upside down
                public short Unknown1;
                public int AngleY;           // From 0 to 359 degrees
                public int AngleX;           // From 0 to 359 degrees
                public int Unknown2;
            };
    
            [DllImport("HTCSensorSDK")]
            extern static IntPtr HTCSensorGetDataOutput(IntPtr handle, out SensorData sensorData);
    
            [DllImport("HTCSensorSDK")]
            extern static IntPtr HTCSensorOpen(int sensor);
    
            [DllImport("HTCSensorSDK")]
            extern static void HTCSensorClose(IntPtr handle);
    
            [DllImport("coredll", SetLastError = true)]
            extern static IntPtr CreateEvent(IntPtr eventAttributes, bool manualReset, bool intialState, string name);
    
            [DllImport("coredll", SetLastError = true)]
            extern static bool EventModify(IntPtr handle, uint func);
    
            [DllImport("coredll")]
            extern static bool CloseHandle(IntPtr handle);
    
            private IntPtr _handle;
    
            public GSensor()
            {
                _handle = HTCSensorOpen(1);
                IntPtr hEvent = CreateEvent(IntPtr.Zero, true, false, "HTC_GSENSOR_SERVICESTART");
                EventModify(hEvent, 3);
                CloseHandle(hEvent);
            }
    
            public void GetSensorData(ref SensorData data)
            {
                HTCSensorGetDataOutput(_handle, out data);
            }
    
            #region IDisposable Members
    
            public void Dispose()
            {
                if (_handle != IntPtr.Zero)
                {
                    HTCSensorClose(_handle);
                    _handle = IntPtr.Zero;
                }
                IntPtr hEvent = CreateEvent(IntPtr.Zero, true, false, "HTC_GSENSOR_SERVICESTOP");
                EventModify(hEvent, 3);
                CloseHandle(hEvent);
            }
    
            #endregion
        }
    }
    Und für VB.net gibt's diverse freie Konvertierer (z.B. C# - VB.net Konvertierer)
    Mit folgendem Resultat:

    Code:
    Imports System
    Imports System.Runtime.InteropServices
    
    Namespace GSensorTest
        Public Class GSensor
            Implements IDisposable
            Public Structure SensorData
                Public TiltX As Short
                ' From -1000 to 1000, 0 is flat
                Public TiltY As Short
                ' From -1000 to 1000, 0 is flat
                Public TiltZ As Short
                ' From -1000 to 1000, 0 = Straight up, -1000 = Flat, 1000 = Upside down
                Public Unknown1 As Short
                Public AngleY As Integer
                ' From 0 to 359 degrees
                Public AngleX As Integer
                ' From 0 to 359 degrees
                Public Unknown2 As Integer
            End Structure
            
             _ 
            Private Shared Function HTCSensorGetDataOutput(ByVal handle As IntPtr, ByRef sensorData As SensorData) As IntPtr
            End Function
            
             _ 
            Private Shared Function HTCSensorOpen(ByVal sensor As Integer) As IntPtr
            End Function
            
             _ 
            Private Shared Sub HTCSensorClose(ByVal handle As IntPtr)
            End Sub
            
             _ 
            Private Shared Function CreateEvent(ByVal eventAttributes As IntPtr, ByVal manualReset As Boolean, ByVal intialState As Boolean, ByVal name As String) As IntPtr
            End Function
            
             _ 
            Private Shared Function EventModify(ByVal handle As IntPtr, ByVal func As UInteger) As Boolean
            End Function
            
             _ 
            Private Shared Function CloseHandle(ByVal handle As IntPtr) As Boolean
            End Function
            
            Private _handle As IntPtr
            
            Public Sub New()
                _handle = HTCSensorOpen(1)
                Dim hEvent As IntPtr = CreateEvent(IntPtr.Zero, True, False, "HTC_GSENSOR_SERVICESTART")
                EventModify(hEvent, 3)
                CloseHandle(hEvent)
            End Sub
            
            Public Sub GetSensorData(ByRef data As SensorData)
                HTCSensorGetDataOutput(_handle, data)
            End Sub
            
            #Region "IDisposable Members"
            
            Public Sub Dispose()
                If _handle <> IntPtr.Zero Then
                    HTCSensorClose(_handle)
                    _handle = IntPtr.Zero
                End If
                Dim hEvent As IntPtr = CreateEvent(IntPtr.Zero, True, False, "HTC_GSENSOR_SERVICESTOP")
                EventModify(hEvent, 3)
                CloseHandle(hEvent)
            End Sub
            
            #End Region
        End Class
    End Namespace
    Da der Emulator diesen Sensor nicht hat (die entsprechende dll fehlt natürlich auch), habe ich im code so etwas wie
    Code:
    private GSensor _gSensor;
    ...
    // init
    if (File.Exists(@"\Windows\HTCSensorSDK.dll"))
    {
        _gSensor = new GSensor();
    }
    ...
    // get sensor data
    if (_gSensor != null)
    {
        GSensor.SensorData sensorData = new GSensor.SensorData();
        _gSensor.GetSensorData(ref sensorData);
    }
    ...
    // close application
    if (_gSensor != null)
    {
        _gSensor.Dispose();
    }
    Geändert (16.11.2009 um 22:14) Grund: bug fix: _gSensor != null :-)

  11. Die folgenden Benutzer danken heliosdev für diesen Beitrag: 2

    v3nom (17.11.2009), yjeanrenaud (16.11.2009)

  12. #10

    AW: G-Sensor Programmierung

    Wow, cool! Ich werde es damit mal ausprobieren! Vielen Dank!

  13. #11

    AW: G-Sensor Programmierung

    So, habe es nun endlich ausprobieren können und es funktioniert
    Vielen Dank nochmal

  14. Die folgenden Benutzer danken v3nom für diesen wertvollen Beitrag:

    yjeanrenaud (18.11.2009)

  15. #12

    AW: G-Sensor Programmierung

    Hallo,

    könntet Ihr wohl ein Beispiel zum Download bereitstellen? Irgendwie bekomme ich das nicht hin.

    Danke im Voraus!

    Gruß,
    T.u.b.e.

  16. #13

    AW: G-Sensor Programmierung

    Das ist die GSensor-API-Klasse in VB.NET, so wie ich sie gerade verwende:

    Code:
    Imports System
    Imports System.Runtime.InteropServices
    
    Public Class GSensor
        Implements IDisposable
    
        Public Structure SensorData
            Public TiltX As Short ' From -1000 to 1000, 0 is flat
            Public TiltY As Short ' From -1000 to 1000, 0 is flat
            Public TiltZ As Short ' From -1000 to 1000, 0 = Straight up, -1000 = Flat, 1000 = Upside down
            Public Unknown1 As Short
            Public AngleY As Integer ' From 0 to 359 degrees
            Public AngleX As Integer ' From 0 to 359 degrees
            Public Unknown2 As Integer
        End Structure
    
        <DllImport("HTCSensorSDK")> _
        Private Shared Function HTCSensorGetDataOutput(ByVal handle As IntPtr, ByRef sensorData As SensorData) As IntPtr
        End Function
    
        <DllImport("HTCSensorSDK")> _
        Private Shared Function HTCSensorOpen(ByVal sensor As Integer) As IntPtr
        End Function
    
        <DllImport("HTCSensorSDK")> _
        Private Shared Sub HTCSensorClose(ByVal handle As IntPtr)
        End Sub
    
        <DllImport("coredll", SetLastError:=True)> _
        Private Shared Function CreateEvent(ByVal eventAttributes As IntPtr, ByVal manualReset As Boolean, ByVal intialState As Boolean, ByVal name As String) As IntPtr
        End Function
    
        <DllImport("coredll", SetLastError:=True)> _
        Private Shared Function EventModify(ByVal handle As IntPtr, ByVal func As UInteger) As Boolean
        End Function
    
        <DllImport("coredll")> _
        Private Shared Function CloseHandle(ByVal handle As IntPtr) As Boolean
        End Function
    
        Private _handle As IntPtr
    
        Public Sub New()
            Dim hEvent As IntPtr
    
            Try
                _handle = HTCSensorOpen(1)
    
                hEvent = CreateEvent(IntPtr.Zero, True, False, "HTC_GSENSOR_SERVICESTART")
                EventModify(hEvent, 3)
                CloseHandle(hEvent)
            Catch
                MsgBox("This is not a HTC Device")
            End Try
        End Sub
    
        Public Sub GetSensorData(ByRef data As SensorData)
            If (_handle <> IntPtr.Zero) Then
                HTCSensorGetDataOutput(_handle, data)
            End If
        End Sub
    
        Public Sub Dispose() Implements System.IDisposable.Dispose
            Dim hEvent As IntPtr
    
            If (_handle <> IntPtr.Zero) Then
                HTCSensorClose(_handle)
                _handle = IntPtr.Zero
            End If
    
            hEvent = CreateEvent(IntPtr.Zero, True, False, "HTC_GSENSOR_SERVICESTOP")
            EventModify(hEvent, 3)
            CloseHandle(hEvent)
        End Sub
    End Class

  17. Die folgenden Benutzer danken v3nom für diesen wertvollen Beitrag:

    yjeanrenaud (10.02.2010)

Antworten
Du betrachtest G-Sensor Programmierung im Forum Programmieren im Bereich Windows Mobile 6.5 und älter von PocketPC.ch.

G-Sensor Programmierung

Ähnliche Themen

  1. Einstieg in die Mobile Programmierung
    Von Ha_Pe im Forum Programmieren
    Antworten: 5
    Letzter Beitrag: 11.04.2008, 13:46
  2. GapiDraw Programmierung
    Von rainfle im Forum Programmieren
    Antworten: 0
    Letzter Beitrag: 02.02.2006, 08:59
  3. Antworten: 1
    Letzter Beitrag: 12.10.2004, 19:41
  4. PocketPC2003 Programmierung in C++
    Von Rico im Forum Programmieren
    Antworten: 2
    Letzter Beitrag: 21.11.2003, 22:34
  5. Programmierung am Pocket PC
    Von dekana im Forum Offtopic
    Antworten: 1
    Letzter Beitrag: 29.09.2002, 14:30

Besucher haben diese Seite mit folgenden Suchbegriffen gefunden:

Asus G Sensor

g sensor c#

vb.net g-sensor

vb.net sensor

g sensordaten vom htc auslesen mit vs8

G-Sensor c#

g sensor VB.net

C# g-sensor

HTC G sensor C#

sensor programmieren

auslesen G-sensor HTC Desire

htc sensor hd2 vb.net

htc sensor data

GSensor C#

c# g sensor

HTCSensorSDK.dl

HTCSensorOpen

htc hd2 gsensor.dll

csharp windows mobile advanced configuration tool

auswertung g sensor c# gsensorsensoren programmierenhtcsensorsdk.dll for hd2 wm 6.5wetab g sensor c#anzeige für einen sensor c#

Stichworte