示例#1
0
        void ReceiverThread()
        {
            _device.StartScanning();

            while (true)
            {
                // Wait for a kick from the main thread.
                _sync.WaitOne();

                if (_stop)
                {
                    break;
                }

                // Read the sensor.
                // This may block the thread for serial communication.
                _device.ReadSensor();

                // Retrieve the received frame data.
                if (_frame == null)
                {
                    _frame = _device.GetFrame();
                }
                else
                {
                    lock (_frame) _device.GetFrame();
                }
            }

            _device.StopScanning();
        }
示例#2
0
        void ReceiverThread()
        {
            _device.StartScanning();

            while (true)
            {
                // Wait for a kick from the main thread.
                // We set one-second timeout to keep connection while pausing
                // (It'll be automatically disconnected from the device when
                // there is no access for a certain period).
                _sync.WaitOne(1000);

                if (_stop)
                {
                    break;
                }

                // Read the sensor.
                // This may block the thread for serial communication.
                _device.ReadSensor();

                // Retrieve the received frame data.
                if (_frame == null)
                {
                    _frame = _device.GetFrame();
                }
                else
                {
                    lock (_frame) _device.GetFrame();
                }
            }

            _device.StopScanning();
        }
示例#3
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();
        }
示例#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();
        }