JS 实现休眠

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u010531676/article/details/78926544

注:以下内容仅供学术讨论,如果拿代码去做坏事,后果自负。

在找JS休眠例子时,找了一会都没找出的。有说用Narrative JavaScript ,但没深究。

我在他的例子上进行改进,主要使用setTimeout()函数。

以下例子就以休眠后自动发送弹幕为例(我是肯定不会打广告的):

console窗口:

var i =0;
function reRun(){
    setTimeout("myRefresh("+i+")",1000);
i++;
}
function myRefresh(obj){
$(".room-chat-texta").val("这是第"+obj+"次");
    $(".room-chat-send").trigger("click");
reRun();
}
reRun();


很简单,就是函数间互调,调用间隔1秒。

我对前端不是很了解,欢迎各位指点迷津。

展开阅读全文

6410 休眠唤醒实现小结

05-04

前一段时间调试了6410的休眠和唤醒,一直没有时间自己总结一下,下面把具体的实现贴出来,供大家参考,又不对的地方,请帮忙纠正,谢谢。rn1,在/driver/char中修改Makefile,添加以下语句:rnrnobj-$(CONFIG_APM_EMULATION) += apm-emulation.ornrn2,在/driver/char中修改Kconfig,添加以下语句:rnrnconfig APM_EMULATIONrn bool "S3C64XX Power Management support"rn helprn Power Management of Linux Arm for S3C64XX supportrnrn3,进入menuconfig界面,执行以下操作:rnrn选中选项“Power management options --->” rnrn内部选为:“[*] Power Management support rn [ ] Power Management Debug Supportrn [*] Suspend to RAM and standby rn <*> Advanced Power Management Emulation ”rnrn4,修改文件/driver/char/apm-emulation.c,将函数apm_ioctl改为以下代码,实现rtc定时唤醒功能:rnrn/*rn * apm_ioctl - handle APM ioctlrn *rn * APM_IOC_SUSPENDrn * This IOCTL is overloaded, and performs two functions. It is used to:rn * - initiate a suspendrn * - acknowledge a suspend read from /dev/apm_bios.rn * Only when everyone who has opened /dev/apm_bios with write permissionrn * has acknowledge does the actual suspend happen.rn */rnstatic intrnapm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)rnrn struct apm_user *as = filp->private_data;rn int err = -EINVAL;rnrn if (!as->suser || !as->writer)rn return -EPERM;rnrn switch (cmd) rn case APM_IOC_SUSPEND:rn mutex_lock(&state_lock);rnrn as->suspend_result = -EINTR;rnrn /* added by byc for test */rn printk(KERN_INFO "\nioctl of suspend is entered!\n");rn printk(KERN_INFO "\nsuspend_state is %d %s\n", as->suspend_state, as->suspend_state);rn /* end */rnrn switch (as->suspend_state) rn case SUSPEND_READ:rn /*rn * If we read a suspend command from /dev/apm_bios,rn * then the corresponding APM_IOC_SUSPEND ioctl isrn * interpreted as an acknowledge.rn */rn as->suspend_state = SUSPEND_ACKED;rn atomic_dec(&suspend_acks_pending);rn mutex_unlock(&state_lock);rnrn /*rn * suspend_acks_pending changed, the notifier needs torn * be woken up for thisrn */rn wake_up(&apm_suspend_waitqueue);rnrn /*rn * Wait for the suspend/resume to complete. If therern * are pending acknowledges, we wait here for them.rn */rn freezer_do_not_count();rnrn wait_event(apm_suspend_waitqueue,rn as->suspend_state == SUSPEND_DONE);rnrn /*rn * Since we are waiting until the suspend is done, thern * try_to_freeze() in freezer_count() will not triggerrn */rn freezer_count();rn break;rn case SUSPEND_ACKTO:rn as->suspend_result = -ETIMEDOUT;rn mutex_unlock(&state_lock);rn break;rn default:rn as->suspend_state = SUSPEND_WAIT;rn mutex_unlock(&state_lock);rnrn /*rn * Otherwise it is a request to suspend the system.rn * Just invoke pm_suspend(), we'll handle it fromrn * there via the notifier.rn */rn /* added by byc for test */rn static void __iomem *base_addr_pwrcfg;rn static void __iomem *base_addr_rtccon;rnrn printk(KERN_INFO "\nsystem is suspended\n");rnrn base_addr_pwrcfg = ioremap(0x7E00F804, 0x04);rn base_addr_rtccon = ioremap(0x7E005050, 0x04);rn rn printk(KERN_INFO " pwrcfg value is: %x\n", readl(base_addr_pwrcfg));rn printk(KERN_INFO " rtccon value is: %x\n", readl(base_addr_rtccon));rn rn writel(readl(base_addr_pwrcfg) & 0xfffffbff, base_addr_pwrcfg);rn writel(readl(base_addr_rtccon) | 0x47, base_addr_rtccon); rnrn printk(KERN_INFO " pwrcfg value is: %x\n", readl(base_addr_pwrcfg));rn printk(KERN_INFO " rtccon value is: %x\n", readl(base_addr_rtccon)); rn /* end */rnrn as->suspend_result = pm_suspend(PM_SUSPEND_MEM);rn rn /* added by byc for test */rn //platform_driver_register(&sdhci_s3c_driver);rn /* end */rn mutex_lock(&state_lock);rn err = as->suspend_result;rn as->suspend_state = SUSPEND_NONE;rn mutex_unlock(&state_lock);rn break;rn rnrn return err;rn 论坛

Delphi下自动休眠与关机的实现

06-06

为了省电和减少硬件的损坏几率,在暂时不使用电脑时,可将电脑设为省电模式,即休眠模式。在这种模式下,显示器和硬rn盘会关闭。要关机但有任务正在运行时,可以设置定时关机。下面介绍了当鼠标、键盘在一定时间内无操作时,系统就转为休眠或待机 及定时关机的实现方法。rn以下是 核心 等 系统下实现关机、休NT (WinXP/2000/2003 )眠的代码。rn( 获取键盘、鼠标的空闲时间1)rnfunction LastInput: DWord;rnvarrnLInput: TLastInputInfo;rnbeginrnLInput.cbSize := SizeOf(TLastInputInfo);rn( )rnGetLastInputInfo(LInput);rnResult := GetTickCount - LInput.dwTime;rnend;rn(取得系统操作权限2)rnrnunction SetPrivilege(sPrivilegeName: string; bEnabled: Boolean): Boolean;rnfrnvarrnTPPrev,TP: TTokenPrivileges; Token: THandle; dwRetLen: DWord;rnbeginrnResult := False;rnOpenProcessToken (GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES orrnTOKEN_QUERY,Token);rnTP.PrivilegeCount := 1;rnif( LookupPrivilegeValue(Nil,PChar(sPrivilegeName),TP.Privileges[ 0 ].LUID ))rnthenrnbeginrnif(bEnabled) thenrnTP.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLEDrnelsernTP.Privileges[ 0 ].Attributes := 0;rndwRetLen := 0;rnResult := AdjustTokenPrivileges (Token,False,TP,SizeOf ( TPPrev ),TPPrev,rndwRetLen);rnend;rnCloseHandle(Token );rnend;rn(实现休眠操作3)rnprocedure TForm1.SleepClick(Sender: TObject);rnbeginrn鼠标键盘已经有 秒没有使用rnself.Caption := Format('rn%d ', [(LastInput)divrn1000]);rnif (LastInput)div 1000=strtoint(edit1.text)*60 thenrnbeginrn获取操作权限!rnSetPrivilege('SeShutdownPrivilege', True );//rnSetSystemPowerState(true,true);rnend;rnend;rn( 实现关机操作4)rnfunction WinExitNT(iFlags: Integer ): Boolean;rnbeginrnResult := True;rnif (SetPrivilege('SeShutdownPrivilege',True)) thenrnbeginrnif(not ExitWindowsEx(iFlags,0))then Result := False;rnSetPrivilege('SeShutdownPrivilege',False)rnendrnelsernResult := False;rnend;rn关 机 时 调 用 方 法 :rnWinExitNT (EWX_FORCE +rn。rnEWX_POWEROFF) 论坛

没有更多推荐了,返回首页