// link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YColorLed hwd = YColorLed.FindColorLed(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Exemple #2
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);
        }
Exemple #4
0
        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);
        }
Exemple #5
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();
        }
Exemple #6
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();
        }