コード例 #1
0
        public static YBuzzerProxy FindBuzzer(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YBuzzer      func = null;
            YBuzzerProxy res  = (YBuzzerProxy)YFunctionProxy.FindSimilarUnknownFunction("YBuzzerProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YBuzzerProxy)YFunctionProxy.FindSimilarKnownFunction("YBuzzerProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YBuzzer.FirstBuzzer();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YBuzzerProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YBuzzer.FindBuzzer(name);
                if (func.get_userData() != null)
                {
                    return((YBuzzerProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YBuzzerProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
コード例 #2
0
        /**
         * <summary>
         *   Enumerates all functions of type Buzzer 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>YBuzzer.FindBuzzer</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>();
            YBuzzer       it  = YBuzzer.FirstBuzzer();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextBuzzer();
            }
            return(res.ToArray());
        }
コード例 #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);
        }
コード例 #4
0
ファイル: Demo.cs プロジェクト: yoctopuce/yoctolib_uwp
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YBuzzer   buz;
                YColorLed led;
                YAnButton button1, button2;

                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();
                led     = YColorLed.FindColorLed(serial + ".colorLed");
                button1 = YAnButton.FindAnButton(serial + ".anButton1");
                button2 = YAnButton.FindAnButton(serial + ".anButton2");

                WriteLine("press a test button");

                while (await buz.isOnline())
                {
                    int  frequency, volume, color;
                    bool b1 = (await button1.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                    bool b2 = (await button2.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                    if (b1 || b2)
                    {
                        if (b1)
                        {
                            volume    = 60;
                            frequency = 1500;
                            color     = 0xff0000;
                        }
                        else
                        {
                            volume    = 30;
                            color     = 0x00ff00;
                            frequency = 750;
                        }

                        await led.resetBlinkSeq();

                        await led.addRgbMoveToBlinkSeq(color, 100);

                        await led.addRgbMoveToBlinkSeq(0, 100);

                        await led.startBlinkSeq();

                        await buz.set_volume(volume);

                        for (int i = 0; i < 5; i++)
                        {
                            // this can be done using sequence as well
                            await buz.set_frequency(frequency);

                            await buz.freqMove(2 *frequency, 250);

                            await YAPI.Sleep(250);
                        }

                        await buz.set_frequency(0);

                        await led.stopBlinkSeq();

                        await led.set_rgbColor(0);
                    }
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            string    errmsg = "";
            string    target, serial;
            YBuzzer   buz;
            YLed      led, led1, led2;
            YAnButton button1, button2;

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

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                buz = YBuzzer.FirstBuzzer();
                if (buz == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                buz = YBuzzer.FindBuzzer(target + ".buzzer");
            }

            if (!buz.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }

            serial  = buz.get_module().get_serialNumber();
            led1    = YLed.FindLed(serial + ".led1");
            led2    = YLed.FindLed(serial + ".led2");
            button1 = YAnButton.FindAnButton(serial + ".anButton1");
            button2 = YAnButton.FindAnButton(serial + ".anButton2");

            Console.WriteLine("press a test button or hit Ctrl-C");

            while (buz.isOnline())
            {
                int  frequency;
                bool b1 = (button1.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                bool b2 = (button2.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                if (b1 || b2)
                {
                    if (b1)
                    {
                        led       = led1;
                        frequency = 1500;
                    }
                    else
                    {
                        led       = led2;
                        frequency = 750;
                    }

                    led.set_power(YLed.POWER_ON);
                    led.set_luminosity(100);
                    led.set_blinking(YLed.BLINKING_PANIC);
                    for (int i = 0; i < 5; i++) // this can be done using sequence as well
                    {
                        buz.set_frequency(frequency);
                        buz.freqMove(2 * frequency, 250);
                        YAPI.Sleep(250, ref errmsg);
                    }
                    buz.set_frequency(0);
                    led.set_power(YLed.POWER_OFF);
                }
            }
            YAPI.FreeAPI();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            string    errmsg = "";
            string    target, serial;
            YBuzzer   buz;
            YColorLed led;
            YAnButton button1, button2;

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

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                buz = YBuzzer.FirstBuzzer();
                if (buz == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                buz = YBuzzer.FindBuzzer(target + ".buzzer");
            }

            if (!buz.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }

            serial  = buz.get_module().get_serialNumber();
            led     = YColorLed.FindColorLed(serial + ".colorLed");
            button1 = YAnButton.FindAnButton(serial + ".anButton1");
            button2 = YAnButton.FindAnButton(serial + ".anButton2");

            Console.WriteLine("press a test button or hit Ctrl-C");

            while (buz.isOnline())
            {
                int  frequency;
                int  color;
                int  volume;
                bool b1 = (button1.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                bool b2 = (button2.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                if (b1 || b2)
                {
                    if (b1)
                    {
                        volume    = 60;
                        frequency = 1500;
                        color     = 0xff0000;
                    }
                    else
                    {
                        volume    = 30;
                        color     = 0x00ff00;
                        frequency = 750;
                    }
                    led.resetBlinkSeq();
                    led.addRgbMoveToBlinkSeq(color, 100);
                    led.addRgbMoveToBlinkSeq(0, 100);
                    led.startBlinkSeq();
                    buz.set_volume(volume);
                    for (int i = 0; i < 5; i++)
                    {
                        // this can be done using sequence as well
                        buz.set_frequency(frequency);
                        buz.freqMove(2 * frequency, 250);
                        YAPI.Sleep(250, ref errmsg);
                    }

                    buz.set_frequency(0);
                    led.stopBlinkSeq();
                    led.set_rgbColor(0);
                }
            }

            YAPI.FreeAPI();
        }
コード例 #7
0
ファイル: Demo.cs プロジェクト: yoctopuce/yoctolib_uwp
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YBuzzer   buz;
                YLed      led, led1, led2;
                YAnButton button1, button2;

                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();
                led1    = YLed.FindLed(serial + ".led1");
                led2    = YLed.FindLed(serial + ".led2");
                button1 = YAnButton.FindAnButton(serial + ".anButton1");
                button2 = YAnButton.FindAnButton(serial + ".anButton2");

                WriteLine("press a test button");

                while (await buz.isOnline())
                {
                    int  frequency;
                    bool b1 = (await button1.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                    bool b2 = (await button2.get_isPressed() == YAnButton.ISPRESSED_TRUE);
                    if (b1 || b2)
                    {
                        if (b1)
                        {
                            led       = led1;
                            frequency = 1500;
                        }
                        else
                        {
                            led       = led2;
                            frequency = 750;
                        }

                        await led.set_power(YLed.POWER_ON);

                        await led.set_luminosity(100);

                        await led.set_blinking(YLed.BLINKING_PANIC);

                        for (int i = 0; i < 5; i++)
                        {
                            // this can be done using sequence as well
                            await buz.set_frequency(frequency);

                            await buz.freqMove(2 *frequency, 250);

                            await YAPI.Sleep(250);
                        }

                        await buz.set_frequency(0);

                        await led.set_power(YLed.POWER_OFF);
                    }
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }