コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public virtual int InitInput()
        {
            // Init Library.
            Library.Init();
            // Load config.
            m_IniReader = config;
            if (m_IniReader != null)
            {
                LoadConfig();
            }
            // Init self.
            InitSensors();
            // Open device stream.
            int ret = 0;

            #region Stream

            m_Stream = StreamFactory.GetStream(
                deviceName, deviceId, deviceAddress,
                out m_BufferSize, out m_IsDynamicStream
                );
            if (m_Stream == null)
            {
                Log.e("DeviceBase", "No such stream with \"" + deviceName + "\"");
                return(-1);
            }
            //m_Buffer=new byte[m_BufferSize];
            m_Stream.SetOnStreamOpenListener(this);
            if (m_IsDynamicStream)
            {
                m_Stream.SetOnStreamReadListener(this);
            }
            try{
                m_Stream.Open();
            }catch (System.Exception e) {
                Log.w("DeviceBase", e.ToString());
                ret = -1;
            }

            #endregion Stream

            // Init sensors.
            axes = new List <string>(); buttons = new List <string>();
            if (ret == 0)
            {
                for (int i = 0; i < m_NumSensors; ++i)
                {
                    sensors[i].StartInput();
                }
            }
            //

            // TODO

            #region Beta

            if (devices[deviceId] == null)
            {
                devices[deviceId] = this;
            }
            else
            {
                Log.w("DeviceBase", "The same id device exists!!!");
            }

            if (asVirtualController)
            {
                int hjId = GetVirtualControllerId();
                if (hjId < 0)
                {
                    Log.w("DeviceBase", "Invalid virtual controller id");
                }
                else if (VirtualController.controllers[hjId] == null)
                {
                }
                else
                {
                    Log.w("DeviceBase", "The same type HandJoystick exists!!!");
                    //return -1;
                }
                m_VirtualController = VirtualController.Instantiate
                                          (fmtJoy, axes.ToArray(), fmtJoy, buttons.ToArray(), poseName);
                VirtualController.controllers[hjId] = m_VirtualController;
            }

            #endregion Beta

            return(ret);
        }