In article <slrnfv42pe.k7i.jim@[EMAIL PROTECTED]
>,
Jim <jim@[EMAIL PROTECTED]
> wrote:
> On 2008-04-01, Gregory Weston <uce@[EMAIL PROTECTED]
> wrote:
> >
> >> In my ongoing attempt to learn Cocoa my next wee project is going to
be a
> >> 'is the internet up?' type app. Basically it will send a single ping
> >> packet
> >> to three addresses once every n-seconds (say 120) and *****s the
results.
> >>
> >> That part isn't a problem.
> >>
> >> As part of the results I want a graphic of a fla****ng LED. Red for
> >> 'Internet
> >> is down', green for 'Internet is up'. My question is this: how do I
make
> >> it
> >> flash? The method I'm considering is to have an NSTimer that fires
every 2
> >> seconds and calls a method that toggles the graphic between whatever
two
> >> of
> >> the three graphics are appropriate - RedLED on, GreenLED on, LED off.
> >>
> >> Or is there a better way?
> >
> > That'll work fine.
>
> Thank you. Good to know that I'm starting to think in the right lines.
>
> Out of interest - and this is purely a hypothetical question - how would
I
> have two timers, both firing at 2 second inteveals but separeted by a
> second?
>
> I realise that timers aren't _very_ precise, hence the question may be
> nonsense. I'm just curious.
You wouldn't. What you would do depends on what you're really trying to
accomplish.
If you really wanted to work with multiple timers you'd probably issue
two calls to the Carbon routine InstallEventLoopTimer() with the second
argument for each set to put them appropriately out of phase with each
other. But if you're looking, for example, to have a timer firing every
two seconds to set the LED image to "off" and another firing every 2
seconds (but offset by 1 second from the first) to set it to either red
or green on, I'd say you should really just have a single timer that
fires every second and sets it appropriate based on both the current
state and the external is-it-up flag.


|