LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

User inactivity detection

Hello all,

I need to turn off the power to a big-ass amplifier if the user forgets to turn it off himself. I'm trying to find the best way to do this (*).

 

The way I've done it is put a timer with the required duration, and at the begining of the panel callback (before the switch) I do a SetCtrlAttribute(... ATTR_INTERVAL, Duration), this way the timer is continuously reset unless the user stops doing anything.

 

The drawback is that any action (including any mouse move) will call SetCtrlAttribute many many times, which is suboptimal.

 

Any other way to do this ?

 

(*) Oviously the correct (tm) way to do this is in hardware, as you never know if the program might crash, the PC power go off, etc. But it's not an amplifier that goes "KaBoom!" if left on, so a software solution is acceptable.

0 Kudos
Message 1 of 4
(3,006 Views)

Since normally a panel callback handles only a limited subset of all possible events, you could exit before the timer reset in the other cases. I'm thinking to something like this:

 

int CVICALLBACK panelCallback (int panel, int event, void *callbackData,
		int eventData1, int eventData2)
{
	switch (event) {
		case EVENT_GOT_FOCUS:
		case EVENT_LOST_FOCUS:
		case EVENT_KEYPRESS:
		case EVENT_CLOSE:
			// Handled events: break to proceed in the function
			break;
		default:
			// Exit for unhandled events
			return 0;
	}

	// Reset activity detection timer
	SetCtrlAttribute (... ATTR_INTERVAL, Duration);

	// Handle events starting from here
	doSomething ();

	return 0;
}

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 4
(2,999 Views)

If I correctly understand you are controlling an amplyfier and running some kind of data acquisition. have access to the amplyfier driver and tha data recorded. Your goal is to switch off the sustem if the user leaves it on for longer than a threshold. 

In real life data aquisition may go on for really long time even without the user doing anything. Asking for presding a button periodically is also a bad idea. The user may be out for a coffee and you ruin the experiment. I, as a graying User would nit revommend you these tricks. 

The approach I like is to set up each measurement properly at the beginning including the lenght of data collection period with an option to shut diwn the amokyfier. Than during the run you show the timer approaching the end of the experiment. When the countdown end the system acts as requested. You may add a runtime option to extend the countdown. This way you ate not annoying the user and still csn switch off the system automatically. 

0 Kudos
Message 3 of 4
(2,966 Views)

I plan on putting a time limit constant somewhere hidden in the program parameters, but yes, putting a visible timer countdown is probably a good idea. Those measurement sessions last normally only a few seconds (and can be repeated), so an 'auto-off' time limit need not be too long.

Message 4 of 4
(2,936 Views)