Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strItems">Array of menu items.  Must be 4 strings per menu item: 1) menu ID,
        /// 2) caption, 3) action</param>
        public clsLCDMenu(string[] strItems, ILCD lcd, InterruptPort buttonUp, InterruptPort buttonDown,
                          MenuCallback getCaption, MenuGetValue getValue, MenuSetValue setValue)
        {
            int intNumItems = strItems.Length;

            if (intNumItems % 3 != 00)
            {
                throw new ApplicationException("Invalid menu array - size must be multiple of 4");
            }

            int intMenuIndex = 0; // index of item within its menu (0-based)

            for (int i = 0; i < intNumItems; i = i + 3)
            {
                int intNextMenu = -1;
                int intPrevMenu = -1;
                if (i >= 3 && strItems[i] == strItems[i - 3])
                {
                    // this isn't the first item in this menu - point to the previous item
                    intPrevMenu = intMenuIndex - 1;
                }
                if ((i + 3) < intNumItems && strItems[i] == strItems[i + 3])
                {
                    // this isn't the last item in this menu - point to the next item
                    intNextMenu = intMenuIndex + 1;
                }
                lstMenu.Add(new menuItem((byte)(i + 1), strItems[i], strItems[i + 1], intNextMenu, intPrevMenu, strItems[i + 2]));
                intMenuIndex += 1;
            }
            intMenuCount                 = lstMenu.Count;
            this.lcd                     = lcd;
            this.buttonUp                = buttonUp;
            this.buttonDown              = buttonDown;
            this.buttonUp.OnInterrupt   += new NativeEventHandler(buttonUp_OnInterrupt);
            this.buttonDown.OnInterrupt += new NativeEventHandler(buttonDown_OnInterrupt);
            lcd.SetCursorOn(true); // set block cursor
            this.menuGetCaption = getCaption;
            this.menuGetValue   = getValue;
            this.menuSetValue   = setValue;

            // display menu 1 - the Main Menu
            displayMenu("1");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strItems">Array of menu items.  Must be 4 strings per menu item: 1) menu ID,
        /// 2) caption, 3) action</param>
        public clsLCDMenu(string[] strItems, ILCD lcd, InterruptPort buttonUp, InterruptPort buttonDown, 
            MenuCallback getCaption, MenuGetValue getValue, MenuSetValue setValue)
        {
            int intNumItems = strItems.Length;

            if (intNumItems % 3 != 00)
            {
                throw new ApplicationException("Invalid menu array - size must be multiple of 4");
            }

            int intMenuIndex = 0; // index of item within its menu (0-based)
            for (int i = 0; i < intNumItems; i = i + 3)
            {
                int intNextMenu = -1;
                int intPrevMenu = -1;
                if (i >= 3 && strItems[i] == strItems[i - 3])
                {
                    // this isn't the first item in this menu - point to the previous item
                    intPrevMenu = intMenuIndex - 1;
                }
                if ((i + 3) < intNumItems && strItems[i] == strItems[i + 3])
                {
                    // this isn't the last item in this menu - point to the next item
                    intNextMenu = intMenuIndex + 1;
                }
                lstMenu.Add(new menuItem((byte)(i + 1), strItems[i], strItems[i+1], intNextMenu, intPrevMenu, strItems[i+2]));
                intMenuIndex += 1;
            }
            intMenuCount = lstMenu.Count;
            this.lcd = lcd;
            this.buttonUp = buttonUp;
            this.buttonDown = buttonDown;
            this.buttonUp.OnInterrupt +=new NativeEventHandler(buttonUp_OnInterrupt);
            this.buttonDown.OnInterrupt +=new NativeEventHandler(buttonDown_OnInterrupt);
            lcd.SetCursorOn(true); // set block cursor
            this.menuGetCaption = getCaption;
            this.menuGetValue = getValue;
            this.menuSetValue = setValue;

            // display menu 1 - the Main Menu
            displayMenu("1");
        }
Exemplo n.º 3
0
        private static void initializePins()
        {
            // initialize - will be set to actual values based on which LCD is being used
            string strUARTPort = "";
            Cpu.Pin relayPin = Pins.GPIO_NONE;

            try
            {
#if MATRIX_ORBITAL
                lcd = new clsLCD_MO(SerialPorts.COM2, 9600, 2, 16);
                strUARTPort = SerialPorts.COM1;
                relayPin = Pins.GPIO_PIN_D13;
#else
#if SPARKFUN
                lcd = new clsLCD_SF(SerialPorts.COM2, 9600, 4, 20);
                strUARTPort = SerialPorts.COM1;
                relayPin = Pins.GPIO_PIN_D13;
#else
#if MICRO_LIQUID_CRYSTAL
                lcd = new clsLCD_MLC(Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D13, Pins.GPIO_PIN_D5,
                    Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D10, Pins.GPIO_PIN_D11, Pins.GPIO_PIN_D12, 2, 8);
                strUARTPort = SerialPorts.COM2;
                relayPin = Pins.GPIO_PIN_D0;
#else
#if SPARKFUN_KIT
                // power to transistor controlling Arduino power
                arduino = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D12, false);
                arduino.Write(true); // turn on Arduino
                Thread.Sleep(2000); // give Arduino a chance to do its initialization
                lcd = new clsLCD_SFKit(SerialPorts.COM2, 9600, 2, 16);
                ((clsLCD_SFKit)lcd).Command +=new CommandEventHandler(uart_Command);
                strUARTPort = SerialPorts.COM1;
                relayPin = Pins.GPIO_PIN_D13;

#endif
#endif
#endif
#endif
            }
            catch (Exception ex)
            {
                Debug.Assert(false);
                Debug.Print("No LCD for you! " + ex.Message);
            }
            try
            {
#if !NO_UART
                // last parm should be true for UART terminal (to send user confirmation), but false for UART XBee
                uart = new clsUART(strUARTPort, 9600, 512, false);

                uart.Command += new CommandEventHandler(uart_Command);
#endif
            }
            catch (Exception ex)
            {
                Debug.Assert(false);
                Debug.Print("No UART for you! " + ex.Message);
            }
            try
            {

                buttonGreen = new InterruptPort(Pins.GPIO_PIN_D8, true, SecretLabs.NETMF.Hardware.Netduino.ResistorModes.Disabled,
                    SecretLabs.NETMF.Hardware.Netduino.InterruptModes.InterruptEdgeBoth);
                buttonRed = new InterruptPort(Pins.GPIO_PIN_D7, true, SecretLabs.NETMF.Hardware.Netduino.ResistorModes.Disabled,
                    SecretLabs.NETMF.Hardware.Netduino.InterruptModes.InterruptEdgeBoth);

                buttonGreen.OnInterrupt += new NativeEventHandler(buttonGreen_OnInterrupt);
                buttonRed.OnInterrupt += new NativeEventHandler(buttonRed_OnInterrupt);

                pot = new AnalogInput(Pins.GPIO_PIN_A0);
                temperature = new AnalogInput(Pins.GPIO_PIN_A2);
                relay = new OutputPort(relayPin, false);
                buzzer = new PWM(Pins.GPIO_PIN_D6);
            }
            catch (Exception ex)
            {
                // catch and release
                Debug.Assert(false);
                Debug.Print("Exception in initializePins: " + ex.Message);
            }
        }