public static YAnButtonProxy FindAnButton(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YAnButton      func = null;
            YAnButtonProxy res  = (YAnButtonProxy)YFunctionProxy.FindSimilarUnknownFunction("YAnButtonProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YAnButtonProxy)YFunctionProxy.FindSimilarKnownFunction("YAnButtonProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YAnButton.FirstAnButton();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YAnButtonProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YAnButton.FindAnButton(name);
                if (func.get_userData() != null)
                {
                    return((YAnButtonProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YAnButtonProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
        static void blueCallback(YAnButton button, String calibratedValue)
        {
            // calculate the blue component by scaling the calibratedValue
            // from 0..1000 to 0..255
            uint value = uint.Parse(calibratedValue);
            byte blue  = (byte)((value * 255 / 1000) & 0xff);
            // we used the userData to get the pointer to the instance of ColorMixer
            ColorMixer mixer = (ColorMixer)button.get_userData();

            // update the color
            mixer.changeBlue(blue);
        }