WatchIdleTimer: nnn (feature request)

nnCron and nnCron LITE discussion

WatchIdleTimer: nnn (feature request)

Postby LuckMan212 » Sun, 10 Jul 2005, 01:15

Hello,

well I have really been struggling to make a pair of tasks to handle my speaker muting. It is proving to be impossible with the current tools available.

The closest I am able to come is these tasks:
Code: Select all
#( idle_mute
Rule: IDLE: 1800 MIXER-STATE 0<> AND VK_CAPITAL KEY-TOGGLED? 0= AND
Action:
   MIXER-MUTE
   FILE-CREATE: "mute.sem"
)#

#( idle_unmute
WatchProcStop: "*.scr"
Rule: FILE-EXIST: "mute.sem"
Action:
   FILE-DELETE: "mute.sem"
   MIXER-UNMUTE
)#


This *ALMOST* works. The problem is, it seems that when the monitor goes to sleep (DPMS) that Windows shuts down the currently running screensaver (.scr). So the volume gets un-muted at that time, instead of when the user returns to their workstation.

What would REALLY be great is if nnCron had another "Watch*" function such as "WatchIdleTimer" (it can be in seconds or in ticks) that could trap immediately such events as they occur.

I can think of a million reasons that this could be useful. This would really work perfect!! Some examples:

Code: Select all
#( idle_mute1
WatchIdleTimer: 1800 >   \ 30+ minutes
Rule: FILE-EXISTS: "mute.sem" 0=
Action:
   MIXER-MUTE
   FILE-CREATE: "mute.sem"
)#

#( idle_unmute1
WatchIdleTimer: 10 <
Rule: FILE-EXISTS: "mute.sem"
Action:
   FILE-DELETE: "mute.sem"
   MIXER-UNMUTE
)#


this will run Prime95 (mersenne project) only during idle times:
Code: Select all
#( prime95
WatchIdleTimer: 1800 >
Rule: PROC-EXIST: "PRIME95.EXE" 0=
Action:
   START-APP "C:\Prime95\PRIME95.EXE"
   BEGIN %GetIdleTime% 60000 > WHILE
      PAUSE 5000
   REPEAT
   KILL: "PRIME95.EXE"
)#


there are probably a lot of reasons it would be nice to be able to trigger a task to execute immediately after a user returns to work.
what do you think, would it be possible to add this feature? :o
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby VK » Tue, 19 Jul 2005, 18:12

There is no need to implement such a word. You can use endless loop to check IDLE time at intervals that are shorter than a minute. The examples are in nnCron FAQ (as I have told you).

Here is a special example for you:

Code: Select all
<%
InitIdleHook
%>
#( test_watchidle
\ one instance of this task at a time:
SingleInstance
Action:
\ endless loop:
BEGIN TRUE WHILE
\ if IDLE time is greater than 5 seconds
GetIdleTime 5000 >
    IF
    \ do smth useful (BEEP as an example)
    BEEP: 500 500
    \ the loop will repeat every 3 seconds
    PAUSE: 3000
    THEN
REPEAT
)#


Of course, you can change the time to check IDLE time every second, 500 ms, or even 10 ms if you need this.
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17

Postby LuckMan212 » Tue, 19 Jul 2005, 18:20

well that's OK solution but nasty side effect is nnCron takes 100% CPU while it is inside such a loop, this is not good for me.

well if it is not possible, thats OK but If more elegant solution can be made in a future version that would be nice.

thank you :)
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Tue, 19 Jul 2005, 20:41

please, give me an exact example of a task, which loads the CPU. I'm pretty sure you have just used extremely short pause...
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Tue, 19 Jul 2005, 20:46

I used the exact same example task that you gave above. :?
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Tue, 19 Jul 2005, 21:04

I will look into it.

BTW, there is a shorter version of the same task:
Code: Select all
#( test_watchidle1
\ one instance of this task at a time:
SingleInstance
Action:
\ endless loop:
BEGIN TRUE WHILE
\ if IDLE time is greater than 5 seconds
IDLE: 5
    IF
    \ do smth useful (BEEP as an example)
    BEEP: 500 500
    \ the loop will repeat every 3 seconds
    PAUSE: 3000
    THEN
REPEAT
)#
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby VK » Wed, 20 Jul 2005, 10:07

You know - there is a quick and easy solution for this problem: just move the 'PAUSE' to the beginning of the loop:

Code: Select all
#( test_watchidle1
\ one instance of this task at a time:
SingleInstance
Action:
\ endless loop:
BEGIN TRUE WHILE
\ the loop will repeat every 3 seconds
PAUSE: 3000
\ if IDLE time is greater than 5 seconds
IDLE: 5
    IF
        \ do smth useful (BEEP as an example)
        BEEP: 500 500
    THEN
REPEAT
)#
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17


Return to nnCron forum (English)

Who is online

Users browsing this forum: No registered users and 2 guests

cron