Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // home app
- var middleBut;
- var topBut_on;
- var topBut_off;
- var nextAttent;
- var btState = false;
- var voltLast = analogRead(30);
- var voltNow = voltLast;
- var lcdOnStamp;
- var loopy;
- if (NRF.getSecurityStatus().connected)
- btState = true;
- var colorMode = {
- "normal" : 0b111111000000000000,
- "charging" : 0b000000111111000000,
- "bluetooth" : 0b000000111111111111
- };
- Bangle.on('lcdPower',function(on) {
- if (on) {
- setTimeout(installWatches,3000);
- lcdOnStamp = Date.now();
- onActivateAndInit();
- } else {
- uninstallWatches();
- }
- });
- function uninstallWatches() {
- clearWatch(middleBut);
- clearWatch(topBut_on);
- clearWatch(topBut_off);
- clearInterval(loopy);
- }
- function getBatteryAccurate(){
- v = analogRead(30);
- const vlo = 0.50366211;
- const vhi = 0.63476562;
- pc = (v-vlo)*100/(vhi-vlo);
- if (pc>100) pc=100;
- if (pc<0) pc=0;
- return pc;
- }
- function updateColor() {
- g.setFont("6x8",3);
- g.setFontAlign(0, 0, 0);
- if ( btState ) g.setColor(colorMode.bluetooth);
- else if (Bangle.isCharging()) g.setColor(colorMode.charging);
- else g.setColor(colorMode.normal);
- }
- function writeScreenText() {
- updateColor();
- g.drawString(" " + getBatteryAccurate().toFixed(2) + "%",120,120,true);
- // var m = process.memory();
- // g.drawString(" " + (m.usage*100/m.total).toFixed(2) + "%",120,160,true);
- g.drawString(voltNow.toFixed(8),120,200,true);
- }
- function installWatches() {
- var triggeredLongPress = false;
- var btn1_state = false;
- middleBut = setWatch(()=>{
- Bangle.showLauncher();
- },BTN2,{repeat:false,edge:"falling"});
- var hold_cbk = null;
- topBut_off = setWatch( () => {
- btn1_state = false;
- clearTimeout(hold_cbk);
- if (!triggeredLongPress) Bangle.setLCDPower(false);
- else
- triggeredLongPress = false;
- },BTN1, {repeat:true,edge:"falling"});
- topBut_on = setWatch((o) => {
- btn1_state = true;
- hold_cbk = setTimeout(() => {
- if ( btn1_state ) {
- triggeredLongPress = true;
- btState = !btState;
- if ( btState ) {
- // beep when bt is on
- Bangle.beep(1000,4000);
- NRF.wake();
- Bluetooth.setConsole(true);
- }
- else {
- Bangle.buzz(1000,1);
- E.setConsole(null,{force:true});
- NRF.sleep();
- }
- writeScreenText();
- }
- },5000);
- }, BTN1, {repeat:true,edge:"rising"});
- }
- function displayScreen() {
- Bangle.drawWidgets();
- writeScreenText();
- }
- function attention() {
- Bangle.buzz(1000,1).then( ()=>
- setTimeout(()=>Bangle.buzz(1000,1),1000));
- nextAttent = E.hwRand()/2147483647;
- nextAttent = 85000*60 + 10000*60 *nextAttent;
- setTimeout(attention,nextAttent);
- }
- function onActivateAndInit() {
- g.clear(false);
- displayScreen();
- setTimeout(() => {
- voltNow = analogRead(30);
- voltageLast = voltNow;
- writeScreenText();
- },1000);
- loopy = setInterval(() => {
- updateColor();
- var num = (((Date.now() - lcdOnStamp)/1000) | 0);
- var second = '' + num;
- if ( second.length > ('' + (num-1)).length ) {
- // force redraw screen
- g.clear(false);
- displayScreen();
- }
- g.drawString(second,120,80,true);
- },500);
- }
- global.WIDGETS={};
- require("gbridge.wid.js");
- require("widbt.wid.js");
- nextAttent = E.hwRand()/2147483647;
- nextAttent = 85000*60 + 10000*60 *nextAttent;
- setTimeout(attention,nextAttent);
- onActivateAndInit();
- installWatches();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement