Ejemplo 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }