예제 #1
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YColorLedCluster ledCluster;
                int color;
                ColorStr = ColorStr.ToUpper();

                if (ColorStr == "RED")
                {
                    color = 0xFF0000;
                }
                else if (ColorStr == "GREEN")
                {
                    color = 0x00FF00;
                }
                else if (ColorStr == "BLUE")
                {
                    color = 0x0000FF;
                }
                else
                {
                    color = Convert.ToInt32("0x" + ColorStr, 16);
                }

                if (Target.ToLower() == "any")
                {
                    ledCluster = YColorLedCluster.FirstColorLedCluster();
                    if (ledCluster == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    ledCluster = YColorLedCluster.FindColorLedCluster(Target + ".colorLedCluster");
                }

                if (await ledCluster.isOnline())
                {
                    //configure led cluster
                    int nb_leds = 62;
                    await ledCluster.set_activeLedCount(nb_leds);

                    await ledCluster.set_ledType(YColorLedCluster.LEDTYPE_RGB);

                    // immediate transition for fist half of leds
                    WriteLine("immediate switch to " + color.ToString("x"));
                    await ledCluster.set_rgbColor(0, nb_leds / 2, color);

                    // immediate transition for second half of leds
                    WriteLine("smooth transition to " + color.ToString("x"));
                    await ledCluster.rgb_move(nb_leds / 2, nb_leds / 2, color, 2000);
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
예제 #2
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);
        }
예제 #3
0
        static void Main(string[] args)
        {
            string           errmsg = "";
            string           target;
            YColorLedCluster ledCluster;
            string           color_str;
            int color;

            if (args.Length < 2)
            {
                usage();
            }

            target    = args[0].ToUpper();
            color_str = args[1].ToUpper();

            if (color_str == "RED")
            {
                color = 0xFF0000;
            }
            else if (color_str == "GREEN")
            {
                color = 0x00FF00;
            }
            else if (color_str == "BLUE")
            {
                color = 0x0000FF;
            }
            else
            {
                color = Convert.ToInt32("0x" + color_str, 16);
            }

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

            if (target == "ANY")
            {
                ledCluster = YColorLedCluster.FirstColorLedCluster();
                if (ledCluster == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                string hwid = target + ".colorLedCluster";
                ledCluster = YColorLedCluster.FindColorLedCluster(hwid);
            }

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

            //configure led cluster
            int nb_leds = 2;

            ledCluster.set_activeLedCount(nb_leds);
            ledCluster.set_ledType(YColorLedCluster.LEDTYPE_RGB);

            // immediate transition for fist half of leds
            ledCluster.set_rgbColor(0, nb_leds / 2, color);
            // immediate transition for second half of leds
            ledCluster.rgb_move(nb_leds / 2, nb_leds / 2, color, 2000);

            YAPI.FreeAPI();
        }