New Samsung Omnia code

Jun 3, 2009 at 7:47 AM
Edited Jun 5, 2009 at 7:24 AM


I've downloaded the Samsung 1.1 SDK and updated SamsungGSensor.cs according to the new API. With this new code, your program won't crash after the display turns off...

Maybe Koush can update the sensorapi as I don't have access to it.

Tested on Samsung Omnia i900

UPDATE (2009/06/05): I've updated the code...

Remember: You need the SamsungMobileSDK_1.dll in the same directory of your exe file or in your \Windows folder... You'll find the dll in the Samsung Innovative Windows Mobile SDK 1.1



using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Microsoft.WindowsCE.Forms;

namespace Sensors
    class SamsungGSensor : GSensorBase
        public struct Vector
            public float x;
            public float y;
            public float z;

        /*public struct Capabilities
            public uint callbackPeriod; // in milliseconds

        public enum SmiResultCode
            Success = 0x00000000,
            Unknown = 0x00000001,
            DeviceNotFound = 0x00000002,
            DeviceDisabled = 0x00000003,
            PermissionDenied = 0x00000004,
            InvalidParameter = 0x00000005,
            CannotActivateServer = 0x00000006,

            HapticsInvalidHandle = 0x10020000,
            HapticsOutOfHandles = 0x10020001,

            LedColorNotSupported = 0x10030000


        /*public struct SdkVersion
            public uint major;
            public uint minor;
            public uint patch;

        public delegate void EventHandler(Vector v);

        public const string SamsungMobileSDKDllName = "SamsungMobileSDK_1.dll";

        //[DllImport(SamsungMobileSDKDllName, EntryPoint = "SmiGetSdkVersion")]
        //private static extern IntPtr SmiGetSdkVersion(ref SdkVersion version);

        [DllImport(SamsungMobileSDKDllName, EntryPoint = "SmiAccelerometerGetVector")]
        private static extern SmiResultCode GetVector(ref Vector accel);

        /*[DllImport(SamsungMobileSDKDllName, EntryPoint = "SmiAccelerometerGetCapabilities")]
        private static extern SmiResultCode GetCapabilities(ref Capabilities cap);

        [DllImport(SamsungMobileSDKDllName, EntryPoint = "SmiAccelerometerRegisterHandler")]
        private static extern SmiResultCode RegisterHandler(uint period, EventHandler handler);

        [DllImport(SamsungMobileSDKDllName, EntryPoint = "SmiAccelerometerUnregisterHandler")]
        private static extern SmiResultCode UnregisterHandler();*/

        public static SamsungGSensor Create()
            Vector vec = new Vector();
            if (GetVector(ref vec) != SmiResultCode.Success)
                throw new Exception("No Omnia G-Sensor found");
            return new SamsungGSensor();

        private SamsungGSensor()

        #region IGSensor Members

        public override GVector GetGVector()
            Vector newVec = new Vector();
            GetVector(ref newVec);
            GVector ret = new GVector();
            ret.X = newVec.x;
            ret.Y = newVec.y;
            ret.Z = -newVec.z;
            //double samsungScaleFactor = 1.0 / 1000.0 * 9.8 * 3.3793103448275862068965517241379;
            double samsungScaleFactor = 7.8;
            return ret.Scale(samsungScaleFactor);



        #region IDisposable Members

        protected override void Dispose(bool disposing)

Jun 16, 2009 at 1:08 AM

Hello ageye, were all Omnias crashing because of this? Or does this affect only to particular ROMs or particual hardwares?

Jun 16, 2009 at 6:08 AM

Good question - I don't know, but I think so...