Esempio n. 1
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YQuadratureDecoder hwd = YQuadratureDecoder.FindQuadratureDecoder(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Esempio n. 2
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YQuadratureDecoder hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering QuadratureDecoder callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Esempio n. 3
0
        public static YQuadratureDecoderProxy FindQuadratureDecoder(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YQuadratureDecoder      func = null;
            YQuadratureDecoderProxy res  = (YQuadratureDecoderProxy)YFunctionProxy.FindSimilarUnknownFunction("YQuadratureDecoderProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YQuadratureDecoderProxy)YFunctionProxy.FindSimilarKnownFunction("YQuadratureDecoderProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YQuadratureDecoder.FirstQuadratureDecoder();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YQuadratureDecoderProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YQuadratureDecoder.FindQuadratureDecoder(name);
                if (func.get_userData() != null)
                {
                    return((YQuadratureDecoderProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YQuadratureDecoderProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Esempio n. 4
0
        /**
         * <summary>
         *   Enumerates all functions of type QuadratureDecoder 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>YQuadratureDecoder.FindQuadratureDecoder</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>();
            YQuadratureDecoder it  = YQuadratureDecoder.FirstQuadratureDecoder();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextQuadratureDecoder();
            }
            return(res.ToArray());
        }
Esempio n. 5
0
    /**
     * <summary>
     *   Retrieves a quadrature decoder 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 quadrature decoder is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YQuadratureDecoder.isOnline()</c> to test if the quadrature decoder is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a quadrature decoder 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>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the quadrature decoder
     * </param>
     * <returns>
     *   a <c>YQuadratureDecoder</c> object allowing you to drive the quadrature decoder.
     * </returns>
     */
    public static YQuadratureDecoder FindQuadratureDecoder(string func)
    {
        YQuadratureDecoder obj;

        obj = (YQuadratureDecoder)YFunction._FindFromCache("QuadratureDecoder", func);
        if (obj == null)
        {
            obj = new YQuadratureDecoder(func);
            YFunction._AddToCache("QuadratureDecoder", func, obj);
        }
        return(obj);
    }
Esempio n. 6
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YBuzzer            buz;
                YColorLedCluster   leds;
                YQuadratureDecoder qd;
                YAnButton          button;

                if (Target.ToLower() == "any")
                {
                    buz = YBuzzer.FirstBuzzer();
                    if (buz == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    buz = YBuzzer.FindBuzzer(Target + ".buzzer");
                }

                if (!await buz.isOnline())
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                    return(-1);
                }

                string serial = await(await buz.get_module()).get_serialNumber();
                leds   = YColorLedCluster.FindColorLedCluster(serial + ".colorLedCluster");
                button = YAnButton.FindAnButton(serial + ".anButton1");
                qd     = YQuadratureDecoder.FindQuadratureDecoder(serial + ".quadratureDecoder1");

                if ((!await button.isOnline()) || (!await qd.isOnline()))
                {
                    WriteLine("Make sure the Yocto-MaxiBuzzer is configured with at least one anButton and one quadrature Decoder");
                    return(-1);
                }

                WriteLine("press a test button, or turn the encoder or hit Ctrl-C");
                int lastPos = (int)await qd.get_currentValue();

                await buz.set_volume(75);

                while (await button.isOnline())
                {
                    if ((await button.get_isPressed() == YAnButton.ISPRESSED_TRUE) &&
                        (lastPos != 0))
                    {
                        lastPos = 0;
                        await qd.set_currentValue(0);

                        await buz.playNotes("'E32 C8");

                        await leds.set_rgbColor(0, 1, 0x000000);
                    }
                    else
                    {
                        int p = (int)await qd.get_currentValue();

                        if (lastPos != p)
                        {
                            lastPos = p;
                            await buz.pulse(notefreq(p), 500);

                            await leds.set_hslColor(0, 1, 0x00FF7f | (p % 255) << 16);
                        }
                    }
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Esempio n. 7
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 = (YQuadratureDecoder)hwd;
     base.base_init(hwd, instantiationName);
 }
Esempio n. 8
0
        //--- (end of YQuadratureDecoder definitions)

        //--- (YQuadratureDecoder implementation)
        internal YQuadratureDecoderProxy(YQuadratureDecoder hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("QuadratureDecoder " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }