Beispiel #1
0
        public void identifyPort(SerialController s)
        {
            hypercube.input._debugLog("Attempting connection to: " + s.portName);
            testSubject = s;
            testSubject.readDataAsString = true;
            timer = 0f;
            type  = serialPortType.SERIAL_WORKING;
//            sentForcedInit = false;
        }
Beispiel #2
0
        // we try to read the serial port until we get some config data.
        // once we identify the port or timeout we can discard this class
        public serialPortType update(float deltaTime)
        {
            if (testSubject == null)
            {
                return(serialPortType.SERIAL_UNKNOWN);
            }

            if (type != serialPortType.SERIAL_WORKING)
            {
                return(type);
            }

            if (timer > timeOut)
            {
                hypercube.input._debugLog("<color=#ff0000>" + testSubject.portName + " timed out.</color>");
                return(serialPortType.SERIAL_UNKNOWN);
            }


            timer += deltaTime;

            //when we first connect...
            //this will tell the chip to give us an init, even if it isn't mechanically resetting (just in case, for example on osx which does not mechanically reset the chip on connection)
//            if (!sentForcedInit && testSubject.serial.isConnected)
//            {
//#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
//              testSubject.SendSerialMessage("reping");  //OSX does not reset the serial port hardware on connect, so we need to get it to tell us again what it is.
//#endif
//                sentForcedInit = true;
//            }

            string data = testSubject.ReadSerialMessage();

            while (data != null)
            {
                hypercube.input._debugLog("IN: " + data);

                if (data.StartsWith("firmwareVersion::"))
                {
                    string[] toks = data.Split(new string[] { "::" }, System.StringSplitOptions.None);
                    firmwareVersion = dataFileDict.stringToFloat(toks[2], firmwareVersion);

                    if (toks[1] == "touchPanelsPCB")
                    {
                        type = serialPortType.SERIAL_TOUCHPANEL;
                        return(type); //don't readMessage again. let the calling method do it, now that we are done here.
                    }

                    //TODO add any other kinds of serial ports that need ID here.
                }

                data = testSubject.ReadSerialMessage();
            }

            return(type);
        }
        //we haven't found all of our ports, keep trying.
        void updateSerialComSearch(float deltaTime)
        {
            for (int i = 0; i < portSearches.Length; i++)
            {
                if (portSearches[i] == null)
                {
                    continue;
                }

                serialPortType t = portSearches[i].update(deltaTime);
                if (t == serialPortType.SERIAL_UNKNOWN) //a timeout or some other problem.  This is likely not a port related to us.
                {
                    //input._debugLog("<color=orange>Failed to connect to "+ portSearches[i].getSerialInput().portName +" </color>");
                    GameObject.Destroy(portSearches[i].getSerialInput());
                    badSerialPorts.Add(portSearches[i].getSerialInput().portName);
                    portSearches[i] = null;
                }
                else if (t == serialPortType.SERIAL_TOUCHPANEL)
                {
                    //note that the serialController is still readAsString = true here

                    input._debugLog("<color=#00ff00>Touch Panel PCB identified.</color>");
                    touchPanelFirmwareVersion = portSearches[i].firmwareVersion;

                    portSearches[i].getSerialInput().SendSerialMessage("read0");//send for the config asap.

                    //also give it to the touchpanel, this will let other methods call input.touchpanel without getting a null,
                    //but it wont receive updates until we get a calibration.
                    touchPanel = new touchScreenInputManager(portSearches[i].getSerialInput());

#if HYPERCUBE_DEV
                    castMesh cm = input._get().GetComponent <castMesh>();
                    if (cm.calibratorBasic)
                    {
                        cm.calibratorBasic.fwVersionNumber.text = "Firmware\nv" + touchPanelFirmwareVersion.ToString();
                        cm.calibratorBasic.pcbText.color        = Color.yellow; //let the dev know that we have found the pcb.
                    }
#endif

                    portSearches[i] = null; //stop checking this port for relevance.

                    Debug.Log("Hypercube: Successfully connected to Volume Touch Panel running firmware v" + touchPanelFirmwareVersion);

                    //TEMP:this version of the tools only knows how to use touchpanel serial port. we are done.
                    //if we ever need to find other ports, this should be removed so it can continue searching.
                    endPortSearch();
                }
            }
        }