forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide an easy way to run code at boot time espruino#163
- Loading branch information
1 parent
dd0e3c8
commit e2247b2
Showing
6 changed files
with
36 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// check for alarms | ||
(function() { | ||
var alarms = require('Storage').readJSON('alarm.json',1)||[]; | ||
var time = new Date(); | ||
var active = alarms.filter(a=>a.on&&(a.last!=time.getDate())); | ||
if (active.length) { | ||
active = active.sort((a,b)=>a.hr-b.hr); | ||
var hr = time.getHours()+(time.getMinutes()/60)+(time.getSeconds()/3600); | ||
if (!require('Storage').read("alarm.js")) { | ||
console.log("No alarm app!"); | ||
require('Storage').write('alarm.json',"[]") | ||
} else { | ||
var t = 3600000*(active[0].hr-hr); | ||
if (t<1000) t=1000; | ||
/* execute alarm at the correct time. We avoid execing immediately | ||
since this code will get called AGAIN when alarm.js is loaded. alarm.js | ||
will then clearInterval() to get rid of this call so it can proceed | ||
normally. */ | ||
setTimeout(function() { | ||
load("alarm.js"); | ||
},t); | ||
} | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters