コード例 #1
0
 private void EndTone(object state)
 {
     _noteTimer.Dispose();
     _noteTimer = null;
     BrainPad.Buzzer.Stop();
     _firmata.SendSysex((byte)ExtendedMessageCommand.ActionCompleted, new[] { _toneWaitId0, _toneWaitId1 });
 }
コード例 #2
0
ファイル: Watchdog.cs プロジェクト: pwalke/Pourcast
 public void Start()
 {
     if (null != _timer)
     {
         throw new ArgumentException("Cannot start an already running watchdog");
     }
     _timer = new ExtendedTimer(TriggerReboot, null, _duration, _duration);
 }
コード例 #3
0
 public void Start()
 {
     if (_durations.Count > 0)
     {
         TimeSpan currentDuration = (TimeSpan)_durations[_position];
         _timer = new ExtendedTimer(InternalTimerTriggered, _position, TimeSpan.Zero, currentDuration);
     }
 }
コード例 #4
0
        public static void Main()
        {
            Utility.SetLocalTime(new DateTime(2019, 3, 13, 23, 59, 30));

            TimerCallback TC = new TimerCallback(BlinkLed);

            ExtendedTimer eTimer = new ExtendedTimer(TC, null, ExtendedTimer.TimeEvents.Second);

            while (true)
            {
            }
        }
コード例 #5
0
        /// <summary>
        /// Constructor: initializes the Ping class
        /// </summary>
        /// <param name="pin">which pin the sensor is connected to</param>
        /// <param name="period">time between pulses in millisec, minimum of 1000</param>
        /// <param name="enabled">if true, start pinging immediately, otherwise wait for enable</param>
        public ParallaxPing(Cpu.Pin pin, int period, bool enabled)
        {
            _port = new TristatePort(pin, false, false, ResistorModes.Disabled);

            // Initially set as disabled.
            _timer = new ExtendedTimer(TakeMeasurement, null, Timeout.Infinite, period);

            // Store the current period
            Period = period;

            // Set the enabled state
            Enabled = enabled;
        }
コード例 #6
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);
        }
コード例 #7
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.");
        }
コード例 #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;
            }
        }
コード例 #9
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);
        }
コード例 #10
0
        // duration is expressed in eighth notes at 120 beats/min
        private void PlayTone(int tone, int duration)
        {
            if (_noteTimer != null)
            {
                // A new note kills the previous one
                _noteTimer.Dispose();
                _noteTimer = null;
                BrainPad.Buzzer.Stop();
                _firmata.SendSysex((byte)ExtendedMessageCommand.ActionCompleted, new[] { _toneWaitId0, _toneWaitId1 });
            }

            if (tone < _notes.Length)
            {
                if (tone != 0) // a tone of 0 is a rest - we don't play anything, we just wait it out
                {
                    BrainPad.Buzzer.PlayFrequency(_notes[tone]);
                }
                _noteTimer = new ExtendedTimer(
                    EndTone,
                    null,
                    250 * duration,
                    System.Threading.Timeout.Infinite);
            }
        }
コード例 #11
0
ファイル: StatusLed.cs プロジェクト: josemotta/Netduino
 public StatusLed(Cpu.Pin pin)
 {
     _port  = new OutputPort(pin, false);
     _timer = new ExtendedTimer(OnTimeout, null, 0, 0);
 }
コード例 #12
0
        //Initialize timer and logger.
        public override void Init()
        {
            if (!InitSystem())
                return;

            try
            {
                string[] locationArray = location.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                numOfTimers = locationArray.Length;
                L.Log(LogType.FILE, LogLevel.DEBUG, "numOfTimers is " + numOfTimers);

                //ExtendedTimer timer1;

                for (int i = 0; i < numOfTimers; i++)
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, "locationArray[i] is " + locationArray[i]);
                    if (timerArr[i] == null)
                    {
                        timerArr[i] = new ExtendedTimer(i, locationArray[i]);
                        timerArr[i].AutoReset = false;
                        timerArr[i].Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
                        timerArr[i].Interval = timer_interval;
                        timerArr[i].Enabled = true;
                        System.Threading.Thread.Sleep(timer_interval / numOfTimers);
                    }
                    //globalLastPositionArr[i] = "0-0";
                }
            }
            catch (Exception)
            {
                L.Log(LogType.FILE, LogLevel.ERROR, "Error on initializing timers");
                return;
            }
        }