summaryrefslogtreecommitdiffstats
path: root/usr.sbin/apmd/apmdlex.l
diff options
context:
space:
mode:
authornsayer <nsayer@FreeBSD.org>2001-05-15 05:13:45 +0000
committernsayer <nsayer@FreeBSD.org>2001-05-15 05:13:45 +0000
commitb5081db59bef2818c352f77a726f2d105b638847 (patch)
tree6a2076a6d6331e348a9a0f5a870a063402e0babd /usr.sbin/apmd/apmdlex.l
parent2bdf180df8cc9444b255a01377516bec3cd373bd (diff)
downloadFreeBSD-src-b5081db59bef2818c352f77a726f2d105b638847.zip
FreeBSD-src-b5081db59bef2818c352f77a726f2d105b638847.tar.gz
Add battery state monitoring to apmd.
The new syntax available in the config file is: apm_battery [0-9]+(%|[Mm) (dis|)charging { ... } The stuff in the braces is the same as the existing case. nn% checks for a certain percentage of life remaining and nnM checks for a cerain number of minutes remaining. Specifying "discharge" means that you're interested in knowing when the battery reaches a certain level while AC power is off, "charging" the opposite. The man page needs to be updated. The code can be fooled. If you SIGHUP the daemon and the battery level matches a rule it will be performed once per SIGHUP. If the battery level matches a rule and you repeatedly apply and take away AC power, the rule will be run once per occurance. This, however, is a feature. :-) The code also only runs when select() times out, so getting APM events more often than the timeout interval will result in the rules not being run. These are things that remain to be overcome.
Diffstat (limited to 'usr.sbin/apmd/apmdlex.l')
-rw-r--r--usr.sbin/apmd/apmdlex.l13
1 files changed, 13 insertions, 0 deletions
diff --git a/usr.sbin/apmd/apmdlex.l b/usr.sbin/apmd/apmdlex.l
index 34598bb..0e5cff3 100644
--- a/usr.sbin/apmd/apmdlex.l
+++ b/usr.sbin/apmd/apmdlex.l
@@ -74,6 +74,19 @@ int first_time;
<TOP>STANDBYRESUME { yylval.ev = EVENT_STANDBYRESUME; return EVENT; }
<TOP>CAPABILITIESCHANGE { yylval.ev = EVENT_CAPABILITIESCHANGE; return EVENT; }
+<TOP>apm_battery { return APMBATT; }
+
+<TOP>charging { return BATTCHARGE; }
+<TOP>discharging { return BATTDISCHARGE; }
+<TOP>[0-9]+% {
+ yylval.i = atoi(yytext);
+ return BATTPERCENT;
+ }
+<TOP>[0-9]+[Mm] {
+ yylval.i = -atoi(yytext);
+ return BATTTIME;
+ }
+
<TOP>exec { return EXECCMD; }
<TOP>reject { return REJECTCMD; }
OpenPOWER on IntegriCloud