コード例 #1
0
ファイル: SenselThread.cs プロジェクト: hinike/SenselExamples
        void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_thread != null)
                {
                    // Stop and join the receiver thread.
                    _stop = true;
                    _sync.Set();
                    _thread.Join();
                    _thread = null;
                }

                if (_contacts.IsCreated)
                {
                    _contacts.Dispose();
                }
                if (_forceArray.IsCreated)
                {
                    _forceArray.Dispose();
                }
            }

            if (_device != null)
            {
                _device.Close();
                _device = null;
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            SenselDeviceList list = SenselDevice.GetDeviceList();

            Console.WriteLine("Num Devices: " + list.num_devices);
            if (list.num_devices == 0)
            {
                Console.WriteLine("No devices found.");
                Console.WriteLine("Press any key to exit.");
                while (!Console.KeyAvailable)
                {
                }
                return;
            }
            SenselDevice sensel_device = new SenselDevice();

            sensel_device.OpenDeviceByID(list.devices[0].idx);
            sensel_device.SetFrameContent(SenselDevice.FRAME_CONTENT_CONTACTS_MASK);
            sensel_device.StartScanning();

            Console.WriteLine("Press any key to exit");
            while (!Console.KeyAvailable)
            {
                sensel_device.ReadSensor();
                int num_frames = sensel_device.GetNumAvailableFrames();
                for (int f = 0; f < num_frames; f++)
                {
                    SenselFrame frame = sensel_device.GetFrame();
                    if (frame.n_contacts > 0)
                    {
                        Console.WriteLine("\nNum Contacts: " + frame.n_contacts);
                        for (int i = 0; i < frame.n_contacts; i++)
                        {
                            Console.WriteLine("Contact ID: " + frame.contacts[i].id);
                            if (frame.contacts[i].state == (int)SenselContactState.CONTACT_START)
                            {
                                sensel_device.SetLEDBrightness(frame.contacts[i].id, 100);
                            }
                            if (frame.contacts[i].state == (int)SenselContactState.CONTACT_END)
                            {
                                sensel_device.SetLEDBrightness(frame.contacts[i].id, 0);
                            }
                        }
                    }
                }
            }
            byte num_leds = sensel_device.GetNumAvailableLEDs();

            for (int i = 0; i < num_leds; i++)
            {
                sensel_device.SetLEDBrightness((byte)i, 0);
            }
            sensel_device.StopScanning();
            sensel_device.Close();
        }
コード例 #3
0
ファイル: SenselMaster.cs プロジェクト: yariza/sense
        static SenselMaster()
        {
            if (SenselDevice.GetDeviceList().num_devices > 0)
            {
                _thread = new SenselThread();
            }

        #if UNITY_EDITOR
            // To release the internal objects on script recompilation.
            UnityEditor.AssemblyReloadEvents.beforeAssemblyReload += ReleaseResources;
        #endif
        }
コード例 #4
0
        static void Main(string[] args)
        {
            SenselDeviceList list = SenselDevice.GetDeviceList();

            Console.WriteLine("Num Devices: " + list.num_devices);
            if (list.num_devices == 0)
            {
                Console.WriteLine("No devices found.");
                Console.WriteLine("Press any key to exit.");
                while (!Console.KeyAvailable)
                {
                }
                return;
            }

            SenselDevice sensel_device = new SenselDevice();

            sensel_device.OpenDeviceByID(list.devices[0].idx);
            sensel_device.SetFrameContent(SenselDevice.FRAME_CONTENT_PRESSURE_MASK);
            sensel_device.StartScanning();
            SenselSensorInfo sensor_info = sensel_device.GetSensorInfo();

            Console.WriteLine("Press any key to exit");
            while (!Console.KeyAvailable)
            {
                sensel_device.ReadSensor();
                int numFrames = sensel_device.GetNumAvailableFrames();
                for (int f = 0; f < numFrames; f++)
                {
                    SenselFrame frame       = sensel_device.GetFrame();
                    float       total_force = 0;
                    for (int i = 0; i < sensor_info.num_cols * sensor_info.num_rows; i++)
                    {
                        total_force = total_force + frame.force_array[i];
                    }
                    Console.WriteLine("Total Force: " + total_force);
                }
            }
            sensel_device.StopScanning();
            sensel_device.Close();
        }
コード例 #5
0
        void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_rawInput != null)
                {
                    UnityEngine.Object.Destroy(_rawInput);
                }

                if (_filteredInput != null)
                {
                    UnityEngine.Object.Destroy(_filteredInput);
                }

                if (_filter != null)
                {
                    UnityEngine.Object.Destroy(_filter);
                }

                if (_totalInput != null)
                {
                    UnityEngine.Object.Destroy(_totalInput);
                }

                for (var i = 0; i < kLevelCount; i++)
                {
                    if (_pyramid[i] != null)
                    {
                        UnityEngine.Object.Destroy(_pyramid[i]);
                    }
                }
            }

            if (_device != null)
            {
                _device.Close();
                _device = null;
            }
        }
コード例 #6
0
        public SenselThread()
        {
            // Check if a device is available.
            var deviceList = SenselDevice.GetDeviceList();

            if (deviceList.num_devices == 0)
            {
                throw new System.IO.IOException("Sensel device not found.");
            }

            // Open the found device.
            _device = new SenselDevice();
            _device.OpenDeviceByID(deviceList.devices[0].idx);
            _device.SetFrameContent(
                SenselDevice.FRAME_CONTENT_CONTACTS_MASK |
                SenselDevice.FRAME_CONTENT_PRESSURE_MASK |
                SenselDevice.FRAME_CONTENT_ACCEL_MASK
                );

            _sensorInfo = _device.GetSensorInfo();

            // Allocate the force array.
            _forceArray = new NativeArray <float>(
                _sensorInfo.num_cols * _sensorInfo.num_rows,
                Allocator.Persistent
                );

            // Allocate the contact array.
            _contacts = new NativeArray <SenselContact>(
                _sensorInfo.max_contacts, Allocator.Persistent
                );

            // Start the receiver thread.
            _thread = new Thread(ReceiverThread);
            _sync   = new AutoResetEvent(false);
            _thread.Start();
        }
コード例 #7
0
        public ForceMap()
        {
            var deviceList = SenselDevice.GetDeviceList();

            if (deviceList.num_devices == 0)
            {
                throw new System.IO.IOException("Sensel device not found.");
            }

            _device = new SenselDevice();
            _device.OpenDeviceByID(deviceList.devices[0].idx);
            _device.SetFrameContent(SenselDevice.FRAME_CONTENT_PRESSURE_MASK);

            _filter = new Material(Shader.Find("Hidden/Sensel/Filters"));

            var info = _device.GetSensorInfo();

            _rawInput          = new Texture2D(info.num_cols, info.num_rows, TextureFormat.RFloat, false);
            _rawInput.wrapMode = TextureWrapMode.Clamp;

            _filteredInput          = new RenderTexture(kMapWidth, kMapHeight, 0, RenderTextureFormat.RHalf);
            _filteredInput.wrapMode = TextureWrapMode.Clamp;

            var tw = kMapWidth;
            var th = kMapHeight;

            for (var i = 0; i < kLevelCount; i++)
            {
                tw                  /= 2;
                th                  /= 2;
                _pyramid[i]          = new RenderTexture(tw, th, 0, RenderTextureFormat.RHalf);
                _pyramid[i].wrapMode = TextureWrapMode.Clamp;
            }

            _totalInput = new RenderTexture(1, 1, 0, RenderTextureFormat.RHalf);
        }
コード例 #8
0
        static void Main(string[] args)
        {
            SenselDeviceList list = SenselDevice.GetDeviceList();

            Console.WriteLine("Num Devices: " + list.num_devices);
            if (list.num_devices != 0)
            {
                SenselDevice sensel_device = new SenselDevice();
                sensel_device.OpenDeviceByID(list.devices[0].idx);
                SenselSensorInfo   sensor_info = sensel_device.GetSensorInfo();
                SenselFirmwareInfo fw_info     = sensel_device.GetFirmwareInfo();
                Console.WriteLine("Sensel Device: " + System.Text.Encoding.Default.GetString(list.devices[0].serial_num));
                Console.WriteLine("Firmware Version: " + fw_info.fw_version_major + "." + fw_info.fw_version_minor + "." + fw_info.fw_version_build);
                Console.WriteLine("Width: " + sensor_info.width + "mm");
                Console.WriteLine("Height: " + sensor_info.height + "mm");
                Console.WriteLine("Cols: " + sensor_info.num_cols);
                Console.WriteLine("Rows: " + sensor_info.num_rows);
                sensel_device.Close();
            }
            Console.WriteLine("Press any key to exit.");
            while (!Console.KeyAvailable)
            {
            }
        }