int main(int argc, char *argv[]) { XScreenSaverInfo *info = XScreenSaverAllocInfo(); Display *display = XOpenDisplay(NULL); //empty argument means to use $DISPLAY variable unsigned long int time_idle; int time_pws = 10*60*1000; // time to wait to go in power save (10 minutes) if(fork() == 0) { while(1) { time_idle = get_idle(info,display,0); // get idle time in milliseconds printf("%lu ms\n", time_idle); if (time_idle < time_pws ) { sleep((time_pws - time_idle)/1000 + 5); // add 5 seconds of delay to prevent very little difference } else { // GO IN POWER SAVE MODE printf("GO IN POWER SAVE %lu ms\n", time_idle); set_powersave(1); setpriority(PRIO_PROCESS, 0, -15); // change priority to low while (time_idle >= time_pws ) { // check until we have to exit from the power saving mode sleep(5); time_idle = get_idle(info,display,1); } setpriority(PRIO_PROCESS, 0, 0); // change priority to normal // EXIT FROM POWER SAVE MODE printf("EXIT FROM POWER SAVE %lu ms\n", time_idle); set_powersave(0); } } } return 0; }
void TPool::run ( TPool::TJob * job, void * ptr, const bool del ) { if ( job == NULL ) return; #if THR_SEQUENTIAL == 1 job->run( ptr ); if ( del ) delete job; #else TPoolThr * thr = get_idle(); job->lock(); thr->run_job( job, ptr, del ); #endif }
static int idle_init(lua_State *L) { ev_idle *w = get_idle(L, 1); ev_idle_init(w, watcher_cb); return 0; }
RES_CODE usb_remote_hid_t::scan_hid(uint32_t port_indx, USBSubClassCode subcls, USBProtocolCode proto) { RES_CODE res; // select EPT_0 and device address ep0_hnd->mode.as_bytes[0] = EPT_0; // RX pipe ep0_hnd->mode.as_bytes[1] = EPT_0; // TX pipe res = hdc_init(port_indx); if(res == RES_OK) { epi_hnd->mode0 = ep0_hnd->mode0; // device hub port // TRACE Device descriptor TRACELN("HID: dev found %x:%x", dev_descriptor.idVendor, dev_descriptor.idProduct); trace_usb_descriptor(&dev_descriptor.as_generic); if(dev_descriptor.bDeviceClass == INTERFACE_DEFINED_CLASS) { //loop the configurations for(uint32_t cfg_indx=0; cfg_indx<dev_descriptor.bNumConfigurations; cfg_indx++) { res = get_config_descriptor(cfg_indx); if(res != RES_OK) break; // TRACE Configuration descriptor(s) trace_usb_descriptor(&config_descriptor->as_generic); //loop the interfaces for(uint32_t iface_indx=0; iface_indx<config_descriptor->bNumInterfaces; iface_indx++) { pid = usb_get_interface(config_descriptor, iface_indx); if(pid && pid->bDeviceClass == HID_DEVICE_CLASS && pid->bDeviceSubClass == subcls && pid->bDeviceProtocol == proto) { // set the configuration // set_configuration(0); res = set_configuration(config_descriptor->bConfigurationValue); if(res == RES_OK) { epi_hnd->mode.as_bytes[0] = EPT_0; epi_hnd->mode.as_bytes[1] = EPT_0; for(int i=0; i<pid->bNumEndpoints && i<2; i++) { USBEndpointDescriptor* ped; ped = usb_get_enpoint(config_descriptor, i); if(ped && ped->bmAttributes == ENDPOINT_TYPE_INTERRUPT) { if( ped->bEndpointAddress & 0x80 ) { if(epi_hnd->mode.as_bytes[0] == EPT_0) { epi_hnd->mode.as_bytes[0] = ped->bEndpointAddress & 0x7F; epi_hnd->mode.as_ushort[1] = ep0_hnd->mode.as_ushort[1]; //drv_state_cnt usb_svc_configendpoint(epi_hnd, &ped->as_generic); } } else { if(epi_hnd->mode.as_bytes[1] == EPT_0) { epi_hnd->mode.as_bytes[1] = ped->bEndpointAddress ; epi_hnd->mode.as_ushort[1] = ep0_hnd->mode.as_ushort[1]; //drv_state_cnt usb_svc_configendpoint(epi_hnd, &ped->as_generic); } } } } hid_idle = 255; get_idle(HID_REPORT_ALL); return RES_OK; } } } } } } if(res == RES_OK) res = RES_ERROR; return res; }