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

                YColorLed led1;
                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")
                {
                    led1 = YColorLed.FirstColorLed();
                    if (led1 == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    led1 = YColorLed.FindColorLed(Target + ".colorLed1");
                }

                if (await led1.isOnline())
                {
                    WriteLine("smooth transition to " + color.ToString("x"));
                    await led1.rgbMove(color, 1000);
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }
            YAPI.FreeAPI();
            return(0);
        }
        public static YColorLedProxy FindColorLed(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YColorLed      func = null;
            YColorLedProxy res  = (YColorLedProxy)YFunctionProxy.FindSimilarUnknownFunction("YColorLedProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YColorLedProxy)YFunctionProxy.FindSimilarKnownFunction("YColorLedProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YColorLed.FirstColorLed();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YColorLedProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YColorLed.FindColorLed(name);
                if (func.get_userData() != null)
                {
                    return((YColorLedProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YColorLedProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
        /**
         * <summary>
         *   Enumerates all functions of type ColorLed 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>YColorLed.FindColorLed</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>();
            YColorLed     it  = YColorLed.FirstColorLed();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextColorLed();
            }
            return(res.ToArray());
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            string errmsg = "";

            YColorLed led;


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


            led = YColorLed.FirstColorLed();
            if (led == null)
            {
                Console.WriteLine("no color led found (check USB cable)");
                Environment.Exit(0);
            }

            led.resetBlinkSeq();                      // cleans the sequence
            led.addRgbMoveToBlinkSeq(0x00FF00, 500);  // move to green in 500 ms
            led.addRgbMoveToBlinkSeq(0x000000, 0);    // switch to black instantaneously
            led.addRgbMoveToBlinkSeq(0x000000, 250);  // stays black for 250ms
            led.addRgbMoveToBlinkSeq(0x0000FF, 0);    // switch to blue instantaneously
            led.addRgbMoveToBlinkSeq(0x0000FF, 100);  // stays blue for 100ms
            led.addRgbMoveToBlinkSeq(0x000000, 0);    // switch to black instantaneously
            led.addRgbMoveToBlinkSeq(0x000000, 250);  // stays black for 250ms
            led.addRgbMoveToBlinkSeq(0xFF0000, 0);    // switch to red instantaneously
            led.addRgbMoveToBlinkSeq(0xFF0000, 100);  // stays red for 100ms
            led.addRgbMoveToBlinkSeq(0x000000, 0);    // switch to black instantaneously
            led.addRgbMoveToBlinkSeq(0x000000, 1000); // stays black for 1s
            led.startBlinkSeq();                      // starts sequence
            Console.WriteLine("done");
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            string    errmsg = "";
            string    target;
            YColorLed led1;
            YColorLed led2;
            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")
            {
                led1 = YColorLed.FirstColorLed();
                if (led1 == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }

                led2 = led1.nextColorLed();
            }
            else
            {
                led1 = YColorLed.FindColorLed(target + ".colorLed1");
                led2 = YColorLed.FindColorLed(target + ".colorLed2");
            }

            if (led1.isOnline())
            {
                led1.set_rgbColor(color);  // immediate switch
                led2.rgbMove(color, 1000); // smooth transition
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Beispiel #6
0
        static int Main(string[] args)
        {
            string errmsg = "";
            int    i;
            int    nbled = 0;

            Console.WriteLine("Yoctopuce Library v" + YAPI.GetAPIVersion());
            Console.WriteLine("ColorMixer");
            if (args.Length < 1)
            {
                Console.WriteLine("usage: demo [usb | ip_address]");
                return(1);
            }

            for (i = 0; i < args.Length; i++)
            {
                // Setup the API to use local USB devices
                if (YAPI.RegisterHub(args[i], ref errmsg) != YAPI.SUCCESS)
                {
                    Console.WriteLine("Unable to get acces to devices on " + args[i]);
                    Console.WriteLine("error: " + errmsg);
                    return(1);
                }
            }

            // create our ColorMixer Object
            ColorMixer mixer = new ColorMixer();

            // get our pointer on our 3 knob
            // we use will reference the 3 knob by the logical name
            // that we have configured using the VirtualHub
            YAnButton knobRed   = YAnButton.FindAnButton("Red");
            YAnButton knobGreen = YAnButton.FindAnButton("Green");
            YAnButton knobBlue  = YAnButton.FindAnButton("Blue");

            // register these 3 knob to the mixer
            mixer.assignRedButton(knobRed);
            mixer.assignGreenButton(knobGreen);
            mixer.assignBlueButton(knobBlue);

            // display a warning if we miss a knob
            if (!knobRed.isOnline())
            {
                Console.WriteLine("Warning: knob \"" + knobRed + "\" is not connected");
            }
            if (!knobGreen.isOnline())
            {
                Console.WriteLine("Warning: knob \"" + knobGreen + "\" is not connected");
            }
            if (!knobBlue.isOnline())
            {
                Console.WriteLine("Warning: knob \"" + knobBlue + "\" is not connected");
            }

            // register all led that is connected to our "network"
            YColorLed led = YColorLed.FirstColorLed();

            while (led != null)
            {
                mixer.addLED(led);
                nbled++;
                led = led.nextColorLed();
            }
            Console.WriteLine(nbled + " Color Led detected", nbled);
            // never hanling loop that will..
            while (true)
            {
                // ... handle all event durring 5000ms without using lots of CPU ...
                YAPI.Sleep(1000, ref errmsg);
                // ... and check for device plug/unplug
                YAPI.UpdateDeviceList(ref errmsg);
            }
        }