2020-01-17 11:43:26 +00:00
|
|
|
// This ALWAYS runs at boot
|
|
|
|
E.setFlags({pretokenise:1});
|
2020-02-04 16:17:23 +00:00
|
|
|
// Load settings...
|
2020-02-28 17:02:26 +00:00
|
|
|
var s = require('Storage').readJSON('setting.json',1)||{};
|
2020-02-04 16:17:23 +00:00
|
|
|
if (s.ble!==false) {
|
2020-02-28 14:17:22 +00:00
|
|
|
if (s.HID) { // Human interface device
|
2020-04-29 06:46:15 +00:00
|
|
|
if (s.HID=="joy") Bangle.HID = E.toUint8Array(atob("BQEJBKEBCQGhAAUJGQEpBRUAJQGVBXUBgQKVA3UBgQMFAQkwCTEVgSV/dQiVAoECwMA="));
|
2020-04-28 14:23:02 +00:00
|
|
|
else if (s.HID=="kb") Bangle.HID = E.toUint8Array(atob("BQEJBqEBBQcZ4CnnFQAlAXUBlQiBApUBdQiBAZUFdQEFCBkBKQWRApUBdQORAZUGdQgVACVzBQcZAClzgQAJBRUAJv8AdQiVArECwA=="));
|
|
|
|
else /*kbmedia*/Bangle.HID = E.toUint8Array(atob("BQEJBqEBhQIFBxngKecVACUBdQGVCIEClQF1CIEBlQV1AQUIGQEpBZEClQF1A5EBlQZ1CBUAJXMFBxkAKXOBAAkFFQAm/wB1CJUCsQLABQwJAaEBhQEVACUBdQGVAQm1gQIJtoECCbeBAgm4gQIJzYECCeKBAgnpgQIJ6oECwA=="));
|
2020-02-04 16:17:23 +00:00
|
|
|
NRF.setServices({}, {uart:true, hid:Bangle.HID});
|
|
|
|
}
|
|
|
|
}
|
2020-02-25 13:34:06 +00:00
|
|
|
if (s.blerepl===false) { // If not programmable, force terminal off Bluetooth
|
|
|
|
if (s.log) Terminal.setConsole(true); // if showing debug, force REPL onto terminal
|
2020-02-28 11:44:25 +00:00
|
|
|
else E.setConsole(null,{force:true}); // on new (2v05+) firmware we have E.setConsole which allows a 'null' console
|
2020-02-25 13:34:06 +00:00
|
|
|
} else {
|
2020-03-12 16:46:39 +00:00
|
|
|
if (s.log && !NRF.getSecurityStatus().connected) Terminal.setConsole(); // if showing debug, put REPL on terminal (until connection)
|
2020-02-25 13:34:06 +00:00
|
|
|
else Bluetooth.setConsole(true); // else if no debug, force REPL to Bluetooth
|
|
|
|
}
|
2020-03-02 17:43:56 +00:00
|
|
|
// we just reset, so BLE should be on.
|
|
|
|
// Don't disconnect if something is already connected to us
|
|
|
|
if (s.ble===false && !NRF.getSecurityStatus().connected) NRF.sleep();
|
2020-02-04 16:17:23 +00:00
|
|
|
// Set time, vibrate, beep, etc
|
|
|
|
if (!s.vibrate) Bangle.buzz=Promise.resolve;
|
2020-03-25 11:05:33 +00:00
|
|
|
if (s.beep===false) Bangle.beep=Promise.resolve;
|
|
|
|
else if (s.beep=="vib") Bangle.beep = function (time, freq) {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
if ((0|freq)<=0) freq=4000;
|
|
|
|
if ((0|time)<=0) time=200;
|
|
|
|
if (time>5000) time=5000;
|
|
|
|
analogWrite(D13,0.1,{freq:freq});
|
|
|
|
setTimeout(function() {
|
|
|
|
digitalWrite(D13,0);
|
|
|
|
resolve();
|
|
|
|
}, time);
|
|
|
|
});
|
|
|
|
};
|
2020-02-04 16:17:23 +00:00
|
|
|
Bangle.setLCDTimeout(s.timeout);
|
|
|
|
if (!s.timeout) Bangle.setLCDPower(1);
|
|
|
|
E.setTimeZone(s.timezone);
|
|
|
|
delete s;
|
2020-03-12 16:46:39 +00:00
|
|
|
// stop users doing bad things!
|
|
|
|
global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }
|
2020-03-31 14:04:51 +00:00
|
|
|
// Load *.boot.js files
|
2020-04-04 16:25:58 +00:00
|
|
|
require('Storage').list(/\.boot\.js/).map(bootFile=>{
|
2020-03-31 14:04:51 +00:00
|
|
|
eval(require('Storage').read(bootFile));
|
|
|
|
});
|