コード例 #1
0
        public static void deviceListHandler(IntPtr cbr, UInt64 session, UInt16 eventID, U64Array sourceList)
        {
            UInt64[] sources = sourceList.array;
            //log("Received sourceList packet");
            if (sources.Length == 0)
            {
                //log("Empty sources list received");
                // no gloves found, reset the values
                if (Apollo.sourceList.Count > 0)
                {
                    log("No gloves connected, cleared gloveList");
                    Apollo.sourceList.Clear();
                    // Apollo state machine will automatically stop streaming if a new glove is found, so this is safe
                }
            }
            else
            {
                // check if new gloves are found
                foreach (var source in sources)
                {
                    // make sure the glove is not alread in the list
                    if (!Apollo.sourceList.ContainsKey(source))
                    {
                        log("New glove connected: " + source);
                        // a new glove is connected, only setup the state, fill in the info later
                        Apollo.sourceList.Add(source, new GloveInfo(GloveState.GLOVE_1_GET_INFO));
                    }
                }

                // check if each glove in my list is still known to Apollo
                foreach (var gloveId in Apollo.sourceList.Keys)
                {
                    // check if a glove in the Apollo list is known in the current sources
                    bool inList = false;
                    foreach (var source in sources)
                    {
                        if (source == gloveId)
                        {
                            inList = true;
                        }
                    }

                    if (!inList)
                    {
                        // A glove is disconnected
                        log("A glove is disconnected: " + gloveId);
                        Apollo.sourceList.Remove(gloveId);
                        // Apollo state machine will automatically stop streaming if a new glove is found, so this is safe
                    }
                }
            }
        }
コード例 #2
0
        // Checks all the gloves status and handles their connection with Apollo
        private static void setupGloves()
        {
            foreach (var glove in sourceList)
            {
                // generate a random eventID and prepare the variables
                var eventId    = randomEventId;
                var gloveId    = glove.Key;
                var endpointID = glove.Value.endpointID;

                switch (glove.Value.state)
                {
                case GloveState.GLOVE_0_DISCONNECTED:
                    log(gloveId + ": Unused state, should not happen");
                    break;

                case GloveState.GLOVE_1_GET_INFO:
                    log(gloveId + ": GET_INFO: " + eventId);
                    // request the information about this source to identify it
                    sendPacket(ApolloSDK.generateGetSourceInfo(_session, gloveId, eventId));

                    // create the event
                    eventList.Add(eventId, new eventData(EventType.GLOVE_IDENTIFY, gloveId));
                    break;

                case GloveState.GLOVE_2_FILTER_GESTURE:
                    if (!_usePinchFilter)
                    {
                        sourceList[gloveId].state = GloveState.GLOVE_3_FILTER_CONVERT;
                        log(gloveId + ": SKIPPED FILTER GESTURE: " + eventId);
                        break;
                    }
                    log(gloveId + ": SETUP FILTER GESTURE: " + eventId);

                    // prepare the arguments for the gesture filter
                    var gestureArray = new ApolloGestureArray(new apollo_gesture_t[] { apollo_gesture_t.GESTURE_INDEX_PINCH });
                    // create a filter handle for the packet generation
                    var gestureFilterHandle = ApolloSDK.generateGestureFilter(_session, gestureArray.numGestures, gestureArray.gestures, 0, 1);

                    // create the unmanaged sources/filters lists
                    var gestureSources = new U64Array(endpointID);
                    var gestureFilters = new U64Array(gestureFilterHandle);
                    // Add the filters in Apollo
                    sendPacket(ApolloSDK.generateAddFilters(_session, gestureSources.pointer, gestureSources.size, gestureFilters.pointer, gestureFilters.size, eventId));

                    // create an event
                    eventList.Add(eventId, new eventData(EventType.GLOVE_ADD_FILTER_GESTURE, gloveId));

                    _filterGestureAttempts++;
                    // Skip this fase if it was not able to setup the filter
                    if (_filterGestureAttempts >= 3)
                    {
                        sourceList[gloveId].state = GloveState.GLOVE_3_FILTER_CONVERT;
                    }
                    break;

                case GloveState.GLOVE_3_FILTER_CONVERT:
                    log(gloveId + ": SETUP FILTER CONVERT: " + eventId);
                    // create a filter handle for the packet generation
                    var convertFilterHandle = ApolloSDK.generateMeshMappingFilter(_session, getUE4MannequinMeshConfig());

                    // create the unmanaged sources/filters lists
                    var convertSources = new U64Array(endpointID);
                    var convertFilters = new U64Array(convertFilterHandle);

                    // Add the filters in Apollo
                    sendPacket(ApolloSDK.generateAddFilters(_session, convertSources.pointer, convertSources.size, convertFilters.pointer, convertFilters.size, eventId));

                    // create an event
                    eventList.Add(eventId, new eventData(EventType.GLOVE_ADD_FILTER_CONVERT, gloveId));
                    break;

                case GloveState.GLOVE_4_ADD_TO_STREAM:
                    // add this glove to the stream
                    // create a packet with one gloveId and send the packet out

                    //var glovesList = new U64Array(new ulong[] { endpointID, gloveId });
                    var glovesList = new U64Array(endpointID);
                    sendPacket(ApolloSDK.generateAddStreams(_session, glovesList.pointer, glovesList.size, eventId));

                    // create an event in the list
                    eventList.Add(eventId, new eventData(EventType.GLOVE_ADD_STREAM, gloveId));

                    log(gloveId + ": ADD_TO_STREAM: " + eventId + " | endpointID: " + endpointID);
                    break;

                case GloveState.GLOVE_5_SET_STREAM_DATA:
                    // enable the data-stream for this glove
                    // create and send the packet
                    sendPacket(ApolloSDK.generateSetStreamData(_session, endpointID, true, eventId));

                    // create an event in the list
                    eventList.Add(eventId, new eventData(EventType.GLOVE_SET_STREAM_DATA, gloveId));

                    log(gloveId + ": SET_STREAM_DATA: " + eventId + " | endpointID: " + endpointID);
                    break;

                case GloveState.GLOVE_6_SET_STREAM_RAW:
                    // enable the raw-stream for this glove
                    // create and send the packet
                    sendPacket(ApolloSDK.generateSetStreamRaw(_session, endpointID, true, eventId));

                    // create an event in the list
                    eventList.Add(eventId, new eventData(EventType.GLOVE_SET_STREAM_RAW, gloveId));

                    log(gloveId + ": SET_STREAM_RAW: " + eventId + " | endpointID: " + endpointID);
                    break;

                case GloveState.GLOVE_7_SETUP:
                    log(gloveId + ": SETUP");
                    // glove is completely setup, don't do anything
                    break;

                default:
                    log("Unknow state '" + glove.Value.state + "' for source: " + glove.Key);
                    break;
                }
            }
        }
コード例 #3
0
        public static void dongleIdListHandler(IntPtr cbr, UInt64 session, UInt16 eventID, U64Array dongleList)
        {
            UInt64[] dongles = dongleList.array;

            if (dongles.Length == 0)
            {
                warning("No dongles found, please insert one");
                // no dongles found, reset the values
                dongleId = 0;
            }
            else if (dongles.Length == 1)
            {
                // if the new dongle ID is not already known
                if (dongleId != dongles[0])
                {
                    // safe the first (and only) dongle id
                    log("New dongle discovered: " + dongles[0]);
                    dongleId = dongles[0];
                }
            }
            else
            {
                warning("More then 1 dongle connected, please make sure you have only one dongle connected to your PC");
                // more then one dongle found, don't know which one to pick so reset the dongleId
                dongleId = 0;
            }
        }