示例#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
        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();
        }