Ejemplo n.º 1
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YTilt          anytilt, tilt1, tilt2;
                YCompass       compass;
                YAccelerometer accel;
                YGyro          gyro;

                if (Target.ToLower() == "any")
                {
                    anytilt = YTilt.FirstTilt();
                    if (anytilt == null)
                    {
                        WriteLine("No module connected (check USB cable)");
                        return(-1);
                    }
                }
                else
                {
                    anytilt = YTilt.FindTilt(Target + ".tilt1");
                }

                string serial = await(await anytilt.get_module()).get_serialNumber();
                tilt1   = YTilt.FindTilt(serial + ".tilt1");
                tilt2   = YTilt.FindTilt(serial + ".tilt2");
                compass = YCompass.FindCompass(serial + ".compass");
                accel   = YAccelerometer.FindAccelerometer(serial + ".accelerometer");
                gyro    = YGyro.FindGyro(serial + ".gyro");
                int count = 0;

                while (await tilt1.isOnline())
                {
                    if (count++ % 10 == 0)
                    {
                        WriteLine("tilt1   tilt2   compass   acc   gyro");
                    }
                    Write(await tilt1.get_currentValue() + "\t");
                    Write(await tilt2.get_currentValue() + "\t");
                    Write(await compass.get_currentValue() + "\t");
                    Write(await accel.get_currentValue() + "\t");
                    WriteLine("" + await gyro.get_currentValue());
                    await YAPI.Sleep(250);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
        public static YTiltProxy FindTilt(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YTilt      func = null;
            YTiltProxy res  = (YTiltProxy)YFunctionProxy.FindSimilarUnknownFunction("YTiltProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YTiltProxy)YFunctionProxy.FindSimilarKnownFunction("YTiltProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YTilt.FirstTilt();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YTiltProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YTilt.FindTilt(name);
                if (func.get_userData() != null)
                {
                    return((YTiltProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YTiltProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
        /**
         * <summary>
         *   Enumerates all functions of type Tilt available on the devices
         *   currently reachable by the library, and returns their unique hardware ID.
         * <para>
         *   Each of these IDs can be provided as argument to the method
         *   <c>YTilt.FindTilt</c> to obtain an object that can control the
         *   corresponding device.
         * </para>
         * </summary>
         * <returns>
         *   an array of strings, each string containing the unique hardwareId
         *   of a device function currently connected.
         * </returns>
         */
        public static new string[] GetSimilarFunctions()
        {
            List <string> res = new List <string>();
            YTilt         it  = YTilt.FirstTilt();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextTilt();
            }
            return(res.ToArray());
        }
Ejemplo n.º 4
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YTilt anytilt, tilt1, tilt2, tilt3;

                if (Target.ToLower() == "any")
                {
                    anytilt = YTilt.FirstTilt();
                    if (anytilt == null)
                    {
                        WriteLine("No module connected (check USB cable)");
                        return(-1);
                    }
                }
                else
                {
                    anytilt = YTilt.FindTilt(Target + ".tilt1");
                }

                string serial = await(await anytilt.get_module()).get_serialNumber();
                tilt1 = YTilt.FindTilt(serial + ".tilt1");
                tilt2 = YTilt.FindTilt(serial + ".tilt2");
                tilt3 = YTilt.FindTilt(serial + ".tilt3");
                int count = 0;

                while (await tilt1.isOnline())
                {
                    if (count++ % 10 == 0)
                    {
                        WriteLine("tilt1   tilt2   tilt3");
                    }
                    Write(await tilt1.get_currentValue() + "\t");
                    Write(await tilt2.get_currentValue() + "\t");
                    WriteLine("" + await tilt3.get_currentValue());
                    await YAPI.Sleep(250);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YTilt          anytilt, tilt1, tilt2;
            YCompass       compass;
            YAccelerometer accelerometer;
            YGyro          gyro;

            if (args.Length < 1)
            {
                usage();
            }
            target = args[0].ToUpper();

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                anytilt = YTilt.FirstTilt();
                if (anytilt == null)
                {
                    Console.WriteLine("No module connected (check USB cable)");
                    Environment.Exit(0);
                }
            }
            else
            {
                anytilt = YTilt.FindTilt(target + ".tilt1");
                if (!anytilt.isOnline())
                {
                    Console.WriteLine("Module not connected");
                    Console.WriteLine("check identification and USB cable");
                    Environment.Exit(0);
                }
            }

            string serial = anytilt.get_module().get_serialNumber();

            tilt1         = YTilt.FindTilt(serial + ".tilt1");
            tilt2         = YTilt.FindTilt(serial + ".tilt2");
            compass       = YCompass.FindCompass(serial + ".compass");
            accelerometer = YAccelerometer.FindAccelerometer(serial + ".accelerometer");
            gyro          = YGyro.FindGyro(serial + ".gyro");
            int count = 0;

            if (!tilt1.isOnline())
            {
                Console.WriteLine("device disconnected");
                Environment.Exit(0);
            }

            while (tilt1.isOnline())
            {
                if (count % 10 == 0)
                {
                    Console.WriteLine("tilt1   tilt2   compass   acc   gyro");
                }

                Console.Write(tilt1.get_currentValue().ToString() + "\t");
                Console.Write(tilt2.get_currentValue().ToString() + "\t");
                Console.Write(compass.get_currentValue().ToString() + "\t");
                Console.Write(accelerometer.get_currentValue().ToString() + "\t");
                Console.WriteLine(gyro.get_currentValue().ToString());

                YAPI.Sleep(250, ref errmsg);
            }
            YAPI.FreeAPI();
        }