Exemplo n.º 1
0
        private void TestLed_Click(object sender, EventArgs e)
        {
            YModule m;
            YLed    led;

            if (!comboBox1.Enabled)
            {
                return;
            }
            m = (YModule)comboBox1.Items[comboBox1.SelectedIndex];
            if (!m.isOnline())
            {
                return;
            }
            led = YLed.FindLed(m.get_serialNumber() + ".led");
            if (led.get_power() == YLed.POWER_OFF)
            {
                led.set_power(YLed.POWER_ON);
            }
            else
            {
                led.set_power(YLed.POWER_OFF);
            }

            refreshUI();
        }
Exemplo n.º 2
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YLed hwd = YLed.FindLed(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Exemplo n.º 3
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YLed hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Led callback");
     _func.registerValueCallback(valueChangeCallback);
 }
    /**
     * <summary>
     *   Retrieves a led for a given identifier.
     * <para>
     *   The identifier can be specified using several formats:
     * </para>
     * <para>
     * </para>
     * <para>
     *   - FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionLogicalName
     * </para>
     * <para>
     * </para>
     * <para>
     *   This function does not require that the led is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YLed.isOnline()</c> to test if the led is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a led by logical name, no error is notified: the first instance
     *   found is returned. The search is performed first by hardware name,
     *   then by logical name.
     * </para>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the led
     * </param>
     * <returns>
     *   a <c>YLed</c> object allowing you to drive the led.
     * </returns>
     */
    public static YLed FindLed(string func)
    {
        YLed obj;

        obj = (YLed)YFunction._FindFromCache("Led", func);
        if (obj == null)
        {
            obj = new YLed(func);
            YFunction._AddToCache("Led", func, obj);
        }
        return(obj);
    }
Exemplo n.º 5
0
    // --- (end of YLed implementation)

    // --- (Led functions)

    /**
     * <summary>
     *   Retrieves a led for a given identifier.
     * <para>
     *   The identifier can be specified using several formats:
     * </para>
     * <para>
     * </para>
     * <para>
     *   - FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionLogicalName
     * </para>
     * <para>
     * </para>
     * <para>
     *   This function does not require that the led is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YLed.isOnline()</c> to test if the led is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a led by logical name, no error is notified: the first instance
     *   found is returned. The search is performed first by hardware name,
     *   then by logical name.
     * </para>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the led
     * </param>
     * <returns>
     *   a <c>YLed</c> object allowing you to drive the led.
     * </returns>
     */
    public static YLed FindLed(string func)
    {
        YLed res;

        if (_LedCache.ContainsKey(func))
        {
            return((YLed)_LedCache[func]);
        }
        res = new YLed(func);
        _LedCache.Add(func, res);
        return(res);
    }
Exemplo n.º 6
0
        public static YLedProxy FindLed(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YLed      func = null;
            YLedProxy res  = (YLedProxy)YFunctionProxy.FindSimilarUnknownFunction("YLedProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YLedProxy)YFunctionProxy.FindSimilarKnownFunction("YLedProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YLed.FirstLed();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YLedProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YLed.FindLed(name);
                if (func.get_userData() != null)
                {
                    return((YLedProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YLedProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Exemplo n.º 7
0
        /**
         * <summary>
         *   Enumerates all functions of type Led 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>YLed.FindLed</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>();
            YLed          it  = YLed.FirstLed();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextLed();
            }
            return(res.ToArray());
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;
            YLed   led;
            string on_off;

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

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

            if (target == "ANY")
            {
                led = YLed.FirstLed();
                if (led == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                led = YLed.FindLed(target + ".led");
            }

            if (led.isOnline())
            {
                if (on_off == "ON")
                {
                    led.set_power(YLed.POWER_ON);
                }
                else
                {
                    led.set_power(YLed.POWER_OFF);
                }
            }
            else
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
            }
            YAPI.FreeAPI();
        }
Exemplo n.º 9
0
        private void refreshUI()
        {
            int     index = 4;
            YModule m;
            YLed    led;

            if (comboBox1.Enabled)
            {
                //TestLed.Click -= TestLed_Click;


                index = 0;
                m     = (YModule)comboBox1.Items[comboBox1.SelectedIndex];
                led   = YLed.FindLed(m.get_serialNumber() + ".led");
                if (led.isOnline())
                {
                    if (led.get_power() == YLed.POWER_ON)
                    {
                        index           = index | 1;
                        TestLed.Checked = true;
                    }
                    else
                    {
                        TestLed.Checked = false;
                    }
                    if (m.get_beacon() == YModule.BEACON_ON)
                    {
                        index          = index | 2;
                        Beacon.Checked = true;
                    }
                    else
                    {
                        Beacon.Checked = false;
                    }
                }
            }

            switch (index)
            {
            case 0: pictureBox1.Image = Properties.Resources.poc; break;

            case 1: pictureBox1.Image = Properties.Resources.pocg; break;

            case 2: pictureBox1.Image = Properties.Resources.pocb; break;

            case 3: pictureBox1.Image = Properties.Resources.pocbg; break;

            case 4: pictureBox1.Image = Properties.Resources.nopoc; break;
            }
        }
Exemplo n.º 10
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YLed led;
                if (Target.ToLower() == "any")
                {
                    led = YLed.FirstLed();
                    if (led == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    led = YLed.FindLed(Target + ".led");
                }

                if (await led.isOnline())
                {
                    if (OnOff.ToUpper() == "ON")
                    {
                        await led.set_power(YLed.POWER_ON);
                    }
                    else
                    {
                        await led.set_power(YLed.POWER_OFF);
                    }
                }
                else
                {
                    WriteLine("Module not connected (check identification and USB cable)");
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Exemplo n.º 11
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();
        }
Exemplo n.º 12
0
 /**
  * <summary>
  *   Retrieves a led for a given identifier.
  * <para>
  *   The identifier can be specified using several formats:
  * </para>
  * <para>
  * </para>
  * <para>
  *   - FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionLogicalName
  * </para>
  * <para>
  * </para>
  * <para>
  *   This function does not require that the led is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YLed.isOnline()</c> to test if the led is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a led by logical name, no error is notified: the first instance
  *   found is returned. The search is performed first by hardware name,
  *   then by logical name.
  * </para>
  * </summary>
  * <param name="func">
  *   a string that uniquely characterizes the led
  * </param>
  * <returns>
  *   a <c>YLed</c> object allowing you to drive the led.
  * </returns>
  */
 public static YLed FindLed(string func)
 {
     YLed obj;
     obj = (YLed) YFunction._FindFromCache("Led", func);
     if (obj == null) {
         obj = new YLed(func);
         YFunction._AddToCache("Led", func, obj);
     }
     return obj;
 }
Exemplo n.º 13
0
 // --- (end of YLed implementation)
 // --- (Led functions)
 /**
    * <summary>
    *   Retrieves a led for a given identifier.
    * <para>
    *   The identifier can be specified using several formats:
    * </para>
    * <para>
    * </para>
    * <para>
    *   - FunctionLogicalName
    * </para>
    * <para>
    *   - ModuleSerialNumber.FunctionIdentifier
    * </para>
    * <para>
    *   - ModuleSerialNumber.FunctionLogicalName
    * </para>
    * <para>
    *   - ModuleLogicalName.FunctionIdentifier
    * </para>
    * <para>
    *   - ModuleLogicalName.FunctionLogicalName
    * </para>
    * <para>
    * </para>
    * <para>
    *   This function does not require that the led is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YLed.isOnline()</c> to test if the led is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a led by logical name, no error is notified: the first instance
    *   found is returned. The search is performed first by hardware name,
    *   then by logical name.
    * </para>
    * </summary>
    * <param name="func">
    *   a string that uniquely characterizes the led
    * </param>
    * <returns>
    *   a <c>YLed</c> object allowing you to drive the led.
    * </returns>
    */
 public static YLed FindLed(string func)
 {
     YLed res;
     if (_LedCache.ContainsKey(func))
       return (YLed)_LedCache[func];
     res = new YLed(func);
     _LedCache.Add(func, res);
     return res;
 }
Exemplo n.º 14
0
 // perform the initial setup that may be done without a YoctoAPI object (hwd can be null)
 internal override void base_init(YFunction hwd, string instantiationName)
 {
     _func = (YLed)hwd;
     base.base_init(hwd, instantiationName);
 }
Exemplo n.º 15
0
        //--- (end of YLed definitions)

        //--- (YLed implementation)
        internal YLedProxy(YLed hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Led " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
Exemplo n.º 16
0
        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);
        }