Example #1
0
 public static void Main()
 {
     OutputPort o = new OutputPort(Pins.ONBOARD_LED, false);
     var timer_onboard = new ExtendedTimer(new TimerCallback(test), o, 10, 100);
     var light = new RgbLight();
     Thread.Sleep(Timeout.Infinite);
 }
Example #2
0
 public void Rgb()
 {
     t = new Microsoft.SPOT.ExtendedTimer(new TimerCallback(OnChangeLightColor)
                                                 , null
                                                 , 0
                                                 , 100);
 }
Example #3
0
        public SpiFloorIndicator(SPI.SPI_module module, FEZ_Pin.Digital latchPin)
        {
            var config = new SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 200, module);
            spi = new SPI(config);

            latch = new OutputPort((Cpu.Pin) latchPin, true);

            CurrentFloor = 1;

            timer = new ExtendedTimer(UpdateIndicator, null, DateTime.Now,
                TimeSpan.FromTicks(25 * TimeSpan.TicksPerMillisecond));
        }
Example #4
0
 public static void Main()
 {
     DateTime localSystemTime = new DateTime(2009, 9, 19, 13, 10, 0, 0);
     Utility.SetLocalTime(localSystemTime);
     Debug.Print("It is now " + DateTime.Now);
     //alarm in 5 secs
     DateTime alarmTime = new DateTime(2009, 9, 19, 13, 10, 5, 0);
     ExtendedTimer alarmTimer = new ExtendedTimer(new TimerCallback(OnTimer),
                                                  null,
                                                  alarmTime,
                                                  TimeSpan.Zero); //one shot (or new TimeSpan(-1))
     Thread.Sleep(Timeout.Infinite); //low power consumption here
     Debug.Print("End of program. Should be never reached.");
 }
Example #5
0
 public void Start()
 {
     if(null != _timer)
         throw new ArgumentException("Cannot start an already running watchdog");
     _timer = new ExtendedTimer(TriggerReboot, null, _duration, _duration);
 }
            private void Interrupt(uint Pin, uint PinState, DateTime TimeStamp)
            {
                this.State = ( PinState == 0 ? false : true );
                this.Provider.ReportInput( TimeStamp
                                         , this.ButtonDef.Button
                                         , this.State ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown
                                         );

                if(this.ButtonDef.AutoRepeat)
                {
                    // If the button is down make sure the auto repeat timer is running
                    if(!this.State)
                    {
                        if ((this.Timer == null) && (this.Provider.RepeatDelay > 0))
                        {
                            this.Timer = new ExtendedTimer( new TimerCallback(this.OnTimer)
                                                          , null
                                                          , this.Provider.RepeatDelay
                                                          , this.Provider.RepeatPeriod
                                                          );
                        }
                    }
                    else
                        if(this.Timer != null)
                        {
                            // shut down the auto repeat timer on button up
                            this.Timer.Change(-1, -1);
                            this.Timer.Dispose();
                            this.Timer = null;
                        }
                }
            }
Example #7
0
        /// <summary>
        /// Creates a brand new name service object.
        /// Since there is only one UDP 137 port, you should use this class as singleton.
        /// </summary>
        public NameService()
        {
            foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
            {
                localIP = IPAddress.Parse(networkInterface.IPAddress).GetAddressBytes();
                localMacAddress = networkInterface.PhysicalAddress;
                break;
            }

            socket.Bind(new IPEndPoint(IPAddress.Any, BCAST_NS_PORT));
            updateTimer = new ExtendedTimer(new TimerCallback(OnUpdate), null, Timeout.Infinite, Timeout.Infinite);
            thread = new Thread(new ThreadStart(SocketThread));
            thread.Start();
            thread.Priority = ThreadPriority.AboveNormal;
            Thread.Sleep(0);
        }
Example #8
0
        /// <summary>
        /// Releases used resources.
        /// </summary>
        public void Dispose()
        {
            if (updateTimer != null)
            {
                updateTimer.Dispose();
                updateTimer = null;
            }

            // Shut down socket first, so the ReceiveFrom method in thread gets unblocked
            if (socket != null)
            {
                socket.Close();
                socket = null;
            }

            if (thread != null)
            {
                terminate = true;
                thread.Join();
                thread = null;
            }
        }
Example #9
0
 public void Start()
 {
     if (_durations.Count > 0)
     {
         TimeSpan currentDuration = (TimeSpan)_durations[_position];
         _timer = new ExtendedTimer(InternalTimerTriggered, _position, TimeSpan.Zero, currentDuration);
     }
 }
Example #10
0
        private void InternalTimerTriggered(object state)
        {
            _timer.Dispose();

            // Fire off an event.
            IntervalReachedEventArgs args = new IntervalReachedEventArgs(_position);
            OnIntervalCompleted(args);

            _position = (_position + 1) % _durations.Count;

            bool shouldTerminate = _position == 0 && !Repeat;
            if (shouldTerminate)
            {
                return;
            }

            // Set the next timer going.
            TimeSpan nextDuration = (TimeSpan)_durations[_position];
            _timer = new ExtendedTimer(InternalTimerTriggered, _position, TimeSpan.Zero, nextDuration);
        }
Example #11
0
        private static void setLightOffTimer(DateTime datAlarm)
        {
            if (tmrLightOff != null)
            {
                tmrLightOff.Dispose();
            }
            Debug.Print("setting light off timer to " + datAlarm);
            strLightOff = "- " + datAlarm.ToString("HH:mm");
            // set the timer to go off at this date, and every 24 hours after that
            tmrLightOff = new ExtendedTimer(new TimerCallback(SetLightState), false, datAlarm, new TimeSpan(1, 0, 0, 0));
            datNextOff = datAlarm;

        }
Example #12
0
        private static void setLightOnTimer(DateTime datAlarm)
        {
            if (tmrLightOn != null)
            {
                tmrLightOn.Dispose();
            }
            Debug.Print("setting light on timer to " + datAlarm);
            strLightOn = "+ " + datAlarm.ToString("HH:mm");
            // set the timer to go off at this date, and repeat forever if we aren't recalculating based on sunset
            // NOTE - MSDN says period can be set to TimeoutInfinite, but TimeSpan(-1) causes out of range exception
            TimeSpan tsRepeat = TimeSpan.MaxValue;
            if (!blnLightOnAtSunset)
            {
                // repeat timer at same time every day
                tsRepeat = new TimeSpan(1, 0, 0, 0);
            }
            tmrLightOn = new ExtendedTimer(new TimerCallback(SetLightState), true, datAlarm, tsRepeat);
            datNextOn = datAlarm;


        }
Example #13
0
        static void setValueFromMenu(string menuCode, Int16 intValue)
        {

            if (menuCode == "BYE")
            {
                // menu has been closed, so hook up our events again

                // update temperature every 30 seconds
                timerTemperature = new Timer(new TimerCallback(displayTemperature), null, 0, 30000);
                // update time every second
                timerTime = new Timer(new TimerCallback(displayTime), null, 1000, 1000);

                // tell the program to ignore the next button release event, since its still the "exit menu" click
                blnButtonHeld = true; 
                buttonGreen.OnInterrupt += new NativeEventHandler(buttonGreen_OnInterrupt);
                buttonRed.OnInterrupt += new NativeEventHandler(buttonRed_OnInterrupt);
            }
            else if (menuCode == "_SUNSET")
            {
                if (datSunset == DateTime.MinValue)
                {
                    // try calculating sunset
                    calculateSunriseAndSunset(DateTime.Now);                    
                }
                // set light to turn on 15 minutes before sunset
                DateTime datLightOn = datSunset.AddMinutes(-15);
                setLightTime(datLightOn.ToString("HH:mm"), true);
                SaveSettingToEEPROM(ADDR_LIGHTON_HOUR, 254); // 254 means sunset
                SaveSettingToEEPROM(ADDR_LIGHTON_MIN, 254);
            }
            else if (menuCode == "_SUNRISE")
            {
                if (datSunrise == DateTime.MinValue)
                {
                    // try calculating sunset
                    calculateSunriseAndSunset(DateTime.Now);
                }
                // set light to turn off 15 minutes after sunrise
                DateTime datLightOff = datSunrise.AddMinutes(15);
                setLightTime(datLightOff.ToString("HH:mm"), false);
                SaveSettingToEEPROM(ADDR_LIGHTOFF_HOUR, 254); // 254 means sunrise
                SaveSettingToEEPROM(ADDR_LIGHTOFF_MIN, 254);
            }
            else if (menuCode == "_CELCIUS")
            {
                // display temperature in celcius
                blnFahr = false;
                // recalc temperature so that it is displayed in right format in menu
                calcTemperature();
                SaveSettingToEEPROM(ADDR_TEMP_FORMAT, 2); // 2 means Celcius
            }
            else if (menuCode == "_FAHR")
            {
                blnFahr = true;
                // recalc temperature so that it is displayed in right format in menu
                calcTemperature();
                SaveSettingToEEPROM(ADDR_TEMP_FORMAT, 1); // 1 means Fahrenheit
            }
            else if (menuCode == "_BACKLITE")
            {
                // toggle backlight
                blnBacklight = !blnBacklight;
                lcd.SetBacklight(blnBacklight);
                // not saved permanently to EEPROM
            }
            else if (menuCode == "_NOLITE")
            {
                // disable timers
                datNextOn = DateTime.MinValue;
                datNextOff = DateTime.MinValue;
                tmrLightOn.Dispose();
                tmrLightOn = null;
                tmrLightOff.Dispose();
                tmrLightOff = null;
            }
                // DAW - 5/23/11 - added Daylight Savings Time setting
            else if (menuCode == "_DST")
            {
                // toggle DST
                blnUseDaylightSavingsTime = !blnUseDaylightSavingsTime;
                calculateSunriseAndSunset(DateTime.Now);
                if (blnUseDaylightSavingsTime)
                {
                    SaveSettingToEEPROM(ADDR_DST, 2);
                }
                else
                {
                    SaveSettingToEEPROM(ADDR_DST, 1);
                }
            }  else
            {
                string[] strParts = menuCode.Split(new char[] { '`' });
                // first part is probably UD_, but we actually only care about the format code
                DateTime date = DateTime.Now;
                string strTime;
                switch (strParts[1])
                {
                    case "yy":
                        Utility.SetLocalTime(new DateTime(2000 + intValue, date.Month, date.Day, date.Hour, date.Minute, date.Second));
                        checkTimers();
                        SaveSettingToEEPROM(ADDR_YEAR, (byte)intValue);
                        break;
                    case "MM":
                        Utility.SetLocalTime(new DateTime(date.Year, intValue, date.Day, date.Hour, date.Minute, date.Second));
                        checkTimers();
                        SaveSettingToEEPROM(ADDR_MONTH, (byte)intValue);
                        break;
                    case "dd":
                        Utility.SetLocalTime(new DateTime(date.Year, date.Month, intValue, date.Hour, date.Minute, date.Second));
                        checkTimers();
                        SaveSettingToEEPROM(ADDR_DAY, (byte)intValue);
                        break;
                    case "HH":
                        Utility.SetLocalTime(new DateTime(date.Year, date.Month, date.Day, intValue, date.Minute, date.Second));
                        checkTimers();
                        break;
                    case "mm":
                        Utility.SetLocalTime(new DateTime(date.Year, date.Month, date.Day, date.Hour, intValue, date.Second));
                        checkTimers();
                        break;
                    case "HH+":
                        strTime = Int_ToZeroPrefixedString(intValue, 2) + datNextOn.ToString(":mm");
                        setLightTime(strTime, true);
                        SaveSettingToEEPROM(ADDR_LIGHTON_HOUR, (byte)(intValue + 1)); // add 1, since 0 value means not saved
                        break;
                    case "mm+":
                        strTime = datNextOn.ToString("HH:") + Int_ToZeroPrefixedString(intValue, 2);
                        setLightTime(strTime, true);
                        SaveSettingToEEPROM(ADDR_LIGHTON_MIN, (byte)(intValue + 1)); // add 1, since 0 value means not saved
                        break;
                    case "HH-":
                        strTime = Int_ToZeroPrefixedString(intValue, 2) + datNextOff.ToString(":mm");
                        setLightTime(strTime, false);
                        SaveSettingToEEPROM(ADDR_LIGHTOFF_HOUR, (byte)(intValue + 1)); // add 1, since 0 value means not saved
                        break;
                    case "mm-":
                        strTime = datNextOff.ToString("HH:") + Int_ToZeroPrefixedString(intValue, 2);
                        setLightTime(strTime, false);
                        SaveSettingToEEPROM(ADDR_LIGHTOFF_MIN, (byte)(intValue + 1)); // add 1, since 0 value means not saved
                        break;
                    case "BR":
                        // LCD brightness
                        bytBrightness = (byte)intValue;
                        lcd.SetBrightness(bytBrightness);
                        blnManualBrightness = true; // ignore pot setting
                        if (intValue < 255)
                            intValue += 1; // add 1, since 0 value means not saved
                        SaveSettingToEEPROM(ADDR_LCD_BRITE, (byte)(intValue)); 
                        break;
                    default:
                        Debug.Print("unknown format code in setValueForMenu: " + menuCode);
                        break;
                }
            }
            
        }