예제 #1
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YProximity hwd = YProximity.FindProximity(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
예제 #2
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YProximity hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Proximity callback");
     _func.registerValueCallback(valueChangeCallback);
 }
예제 #3
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YLightSensor ir, al;
            YProximity   p;

            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")
            {
                p = YProximity.FirstProximity();
                if (p == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = p.get_module().get_serialNumber();
            }
            else
            {
                p = YProximity.FindProximity(target + ".proximity1");
            }

            if (!p.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            al = YLightSensor.FindLightSensor(target + ".lightSensor1");
            ir = YLightSensor.FindLightSensor(target + ".lightSensor2");

            while (p.isOnline())
            {
                Console.Write(" Proximity: " + p.get_currentValue().ToString());
                Console.Write(" Ambiant: " + al.get_currentValue().ToString());
                Console.Write(" IR: " + ir.get_currentValue().ToString());

                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
예제 #4
0
        public static YProximityProxy FindProximity(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YProximity      func = null;
            YProximityProxy res  = (YProximityProxy)YFunctionProxy.FindSimilarUnknownFunction("YProximityProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YProximityProxy)YFunctionProxy.FindSimilarKnownFunction("YProximityProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YProximity.FirstProximity();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YProximityProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YProximity.FindProximity(name);
                if (func.get_userData() != null)
                {
                    return((YProximityProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YProximityProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
예제 #5
0
        /**
         * <summary>
         *   Enumerates all functions of type Proximity 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>YProximity.FindProximity</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>();
            YProximity    it  = YProximity.FirstProximity();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextProximity();
            }
            return(res.ToArray());
        }
예제 #6
0
    /**
     * <summary>
     *   Retrieves a proximity sensor for a given identifier.
     * <para>
     *   The identifier can be specified using several formats:
     * </para>
     * <para>
     * </para>
     * <para>
     *   - FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionLogicalName
     * </para>
     * <para>
     * </para>
     * <para>
     *   This function does not require that the proximity sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YProximity.isOnline()</c> to test if the proximity sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a proximity sensor by logical name, no error is notified: the first instance
     *   found is returned. The search is performed first by hardware name,
     *   then by logical name.
     * </para>
     * <para>
     *   If a call to this object's is_online() method returns FALSE although
     *   you are certain that the matching device is plugged, make sure that you did
     *   call registerHub() at application initialization time.
     * </para>
     * <para>
     * </para>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the proximity sensor
     * </param>
     * <returns>
     *   a <c>YProximity</c> object allowing you to drive the proximity sensor.
     * </returns>
     */
    public static YProximity FindProximity(string func)
    {
        YProximity obj;

        lock (YAPI.globalLock) {
            obj = (YProximity)YFunction._FindFromCache("Proximity", func);
            if (obj == null)
            {
                obj = new YProximity(func);
                YFunction._AddToCache("Proximity", func, obj);
            }
        }
        return(obj);
    }
예제 #7
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YLightSensor ir, al;
                YProximity   p;

                if (Target.ToLower() == "any")
                {
                    p = YProximity.FirstProximity();
                    if (p == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await p.get_module()).get_serialNumber();
                }
                else
                {
                    p = YProximity.FindProximity(Target + ".proximity1");
                }

                al = YLightSensor.FindLightSensor(Target + ".lightSensor1");
                ir = YLightSensor.FindLightSensor(Target + ".lightSensor2");

                while (await p.isOnline())
                {
                    Write("Proximity: " + await p.get_currentValue());
                    Write("\tAmbiant: " + await al.get_currentValue());
                    WriteLine("\tIR: " + await ir.get_currentValue());
                    await YAPI.Sleep(1000);
                }

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

            YAPI.FreeAPI();
            return(0);
        }
예제 #8
0
 // perform the initial setup that may be done without a YoctoAPI object (hwd can be null)
 internal override void base_init(YFunction hwd, string instantiationName)
 {
     _func = (YProximity)hwd;
     base.base_init(hwd, instantiationName);
 }
예제 #9
0
        //--- (end of YProximity definitions)

        //--- (YProximity implementation)
        internal YProximityProxy(YProximity hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Proximity " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }