Example #1
0
        public static void Main()
        {
            ////////////////////////////////////////////////////////
            // BEGIN  Computer variables
            ////////////////////////////////////////////////////////

            Utility.SetLocalTime(new DateTime(2011, 01, 01, 12, 0, 0, 0));

            // Blink board LED
            bool blinkLEDState = false;

            // test blink led
            OutputPort blinkLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, blinkLEDState);

            // Sensor port
            InterruptPort IntSensorButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di1, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            // add an interrupt handler to the pin
            IntSensorButton.OnInterrupt += new NativeEventHandler(IntSensorButton_OnInterrupt);

            // Switch displey on/off port
            InterruptPort IntDisplayOnOffButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di2, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            // add an interrupt handler to the pin
            IntDisplayOnOffButton.OnInterrupt += new NativeEventHandler(IntDisplayOnOffButton_OnInterrupt);

            FEZ_Shields.KeypadLCD.Initialize();
            bikeData.IsDisplayOn = true;

            DisplayController display = new DisplayController(bikeData);

            /////////////////////////////////////////////////////////
            // END  Computer variables
            /////////////////////////////////////////////////////////

            // Main loop
            while (true)
            {
                //                          |0123456789012345
                //                         0|99 km/h 99:99:99
                //                         1|99.999 km  99:99
                //             Edit 1        Wheel size: 999>
                //             Edit 2        Time: 99:99:99 >

                // Reset speedometer
                if (display.CanEditLine())
                {
                    bikeData.lastDisplayUsed = DateTime.Now;
                }
                else
                {
                    TimeSpan lastDisplayUsedSpan = DateTime.Now - bikeData.lastDisplayUsed;
                    if (lastDisplayUsedSpan.Seconds > 5)
                    {
                        bikeData.lastSpeedCheck = DateTime.MinValue;
                        bikeData.CurrentSpeed   = 0;
                        bikeData.IsDisplayOn    = false;
                    }
                }

                // Reset trip timer
                TimeSpan lastTripCheckSpan = DateTime.Now - bikeData.lastTripCheck;
                if (lastTripCheckSpan.Minutes > 30)
                {
                    bikeData.IsStartTripSet = false;
                    bikeData.StartTrip      = DateTime.MinValue;
                }

                // Sleep for 500 milliseconds
                Thread.Sleep(500);

                display.DisplayLines();

                FEZ_Shields.KeypadLCD.Keys KeyPressed = FEZ_Shields.KeypadLCD.GetKey();
                if (KeyPressed != FEZ_Shields.KeypadLCD.Keys.None)
                {
                    if (!bikeData.IsDisplayOn)
                    {
                        bikeData.IsDisplayOn = true;
                    }
                    else
                    {
                        display.ProcessKey(KeyPressed);
                    }
                }

                // toggle LED state
                blinkLEDState = !blinkLEDState;
                blinkLED.Write(blinkLEDState);
            }
        }