예제 #1
0
        /// <summary>
        /// Creates an array of new <see cref="MulticolorLED"/> objects, one for each hardware module that is physically connected to the specified socket.
        /// </summary>
        /// <param name="socketNumber">The socket to get the objects for.</param>
        /// <returns>An array of <see cref="MulticolorLED"/> objects.</returns>
        /// <remarks>
        /// <para>
        ///  Use this method to retrieve an array of newly instantiated objects that correspond to the hardware modules that are physically connected to the specified socket.
        ///  When using this method, keep in mind the following points:
        /// </para>
        /// <list type="bullet">
        ///  <item>
        ///   This method creates new objects. If you have already created objects associated with socket <paramref name="socketNumber"/>, this method will fail.
        ///  </item>
        ///  <item>This method should only be called once. Subsequent calls to this method will fail.</item>
        /// </list>
        /// <para>
        ///  This method is useful when you don't know the number of modules that are connected to the specified socket, or when that number can vary.
        ///  By calling this method, you can obtain the proper number of object references, in the correct order. The object returned in the first index
        ///  of the array (index 0) corresponds to the hardware module that is first on the chain (that is, closest to the main board), the second index
        ///  of the array (index 1) corresponds to the hardware module that is second on the chain, and so on.
        /// </para>
        /// <para>
        ///  If you create objects associated with socket <paramref name="socketNumber"/> before calling this method, or call this method more than once, this method
        ///  will fail because module objects have already been assigned their positons on the chain.
        /// </para>
        /// </remarks>
        public static MulticolorLED[] GetAll(int socketNumber)
        {
            int chainLength;

            try
            {
                chainLength = GetLengthOfChain(socketNumber);
                if (chainLength == 0)
                {
                    return(new MulticolorLED[0]);
                }
            }
            catch (Exception e)
            {
                // no nodes on chain?
                throw new Socket.InvalidSocketException("Cannot initialize DaisyLink on socket " + socketNumber, e);
            }

            MulticolorLED[] ret = new MulticolorLED[chainLength];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = new MulticolorLED(socketNumber);
            }
            return(ret);
        }
예제 #2
0
 /// <summary>
 /// Raises the <see cref="AnimationFinished"/> event.
 /// </summary>
 /// <param name="sender">The <see cref="MulticolorLED"/> that raised the event.</param>
 protected virtual void OnAnimationFinishedEvent(MulticolorLED sender)
 {
     if (onAnimationFinished == null)
     {
         onAnimationFinished = new AnimationFinishedEventHandler(OnAnimationFinishedEvent);
     }
     if (Program.CheckAndInvoke(AnimationFinished, onAnimationFinished, sender))
     {
         AnimationFinished(sender);
     }
 }
예제 #3
0
        private void OnAnimationFinished(MulticolorLED sender, EventArgs e)
        {
            if (this.onAnimationFinished == null)
            {
                this.onAnimationFinished = this.OnAnimationFinished;
            }

            if (Program.CheckAndInvoke(this.AnimationFinished, this.onAnimationFinished, sender, e))
            {
                this.AnimationFinished(sender, e);
            }
        }
예제 #4
0
        /// <summary>Returns an array of MulticolorLEDs for each hardware module that is physically connected to the specified socket.</summary>
        /// <param name="socketNumber">The socket to get the objects for.</param>
        /// <returns>The array of MulticolorLEDs.</returns>
        public static MulticolorLED[] GetAll(int socketNumber)
        {
            int chainLength = DaisyLinkModule.GetLengthOfChain(socketNumber);

            if (chainLength == 0)
            {
                return(new MulticolorLED[0]);
            }

            MulticolorLED[] leds = new MulticolorLED[chainLength];
            for (int i = 0; i < leds.Length; i++)
            {
                leds[i] = new MulticolorLED(socketNumber);
            }

            return(leds);
        }
예제 #5
0
        /// <summary>
        /// constructor, gets all peripherals needed for the UI
        /// </summary>
        /// <param name="inputFinished">an EventHandler which will be called when the input in a round is completed successfully</param>
        public GameView(MasterMind masterMind, Gadgeteer.Modules.Module.DisplayModule display, Gadgeteer.Modules.GHIElectronics.Joystick joystick, 
            Gadgeteer.Modules.GHIElectronics.MulticolorLED led, EventHandler inputFinished)
        {
            this.masterMind = masterMind;

            //store Gadgeteer device references for later use
            this.display = display;
            this.joystick = joystick;
            this.led = led;

            //event handler which will be invoked when the user finished his input..we just pass this to the current ColorCodeInput
            this.inputFinished = inputFinished;

            //start with the first round!
            display.SimpleGraphics.Clear();
            display.SimpleGraphics.DisplayText("Mastermind - good luck!", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.White, CODE_X_POS, WELCOME_Y_POS);
            createColorCodeInput(0);
        }