diff --git a/.eslintignore b/.eslintignore index fcbea07f9..4af79d129 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,5 @@ apps/banglerun/rollup.config.js apps/schoolCalendar/fullcalendar/main.js apps/authentiwatch/qr_packed.js apps/qrcode/qr-scanner.umd.min.js +apps/gipy/pkg/gpconv.js *.test.js diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index a3469e7bb..7c0cfca3a 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -22,9 +22,6 @@ jobs: - name: Install typescript dependencies working-directory: ./typescript run: npm ci - - name: Build types - working-directory: ./typescript - run: npm run build:types - name: Build all TS apps and widgets working-directory: ./typescript run: npm run build diff --git a/.gitignore b/.gitignore index a9398e871..7687a770a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ tests/Layout/testresult.bmp apps.local.json _site .jekyll-cache +.owncloudsync.log +Desktop.ini +.sync_*.db* +*.swp diff --git a/.gitmodules b/.gitmodules index fd6663d2a..c2c1104c2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "EspruinoAppLoaderCore"] path = core url = https://github.com/espruino/EspruinoAppLoaderCore.git +[submodule "webtools"] + path = webtools + url = https://github.com/espruino/EspruinoWebTools.git diff --git a/README.md b/README.md index ea485da86..fed13a358 100644 --- a/README.md +++ b/README.md @@ -255,8 +255,11 @@ and which gives information about the app for the Launcher. // 'app' - an application // 'clock' - a clock - required for clocks to automatically start // 'widget' - a widget + // 'module' - this provides a module that can be used with 'require'. + // 'provides_modules' should be used if type:module is specified // 'bootloader' - an app that at startup (app.boot.js) but doesn't have a launcher entry for 'app.js' // 'settings' - apps that appear in Settings->Apps (with appname.settings.js) but that have no 'app.js' + // 'clkinfo' - Provides a 'myapp.clkinfo.js' file that can be used to display info in clocks - see modules/clock_info.js // 'RAM' - code that runs and doesn't upload anything to storage // 'launch' - replacement 'Launcher' // 'textinput' - provides a 'textinput' library that allows text to be input on the Bangle @@ -266,10 +269,24 @@ and which gives information about the app for the Launcher. // 'locale' - provides 'locale' library for language-specific date/distance/etc // (a version of 'locale' is included in the firmware) "tags": "", // comma separated tag list for searching + // common types are: + // 'clock' - it's a clock + // 'widget' - it is (or provides) a widget + // 'outdoors' - useful for outdoor activities + // 'tool' - a useful utility (timer, calculator, etc) + // 'game' - a game + // 'bluetooth' - uses Bluetooth LE + // 'system' - used by the system + // 'clkinfo' - provides or uses clock_info module for data on your clock face (see modules/clock_info.js) "supports": ["BANGLEJS2"], // List of device IDs supported, either BANGLEJS or BANGLEJS2 "dependencies" : { "notify":"type" } // optional, app 'types' we depend on (see "type" above) "dependencies" : { "messages":"app" } // optional, depend on a specific app ID // for instance this will use notify/notifyfs is they exist, or will pull in 'notify' + "dependencies" : { "messageicons":"module" } // optional, depend on a specific library to be used with 'require' - see provides_modules + "dependencies" : { "message":"widget" } // optional, depend on a specific type of widget - see provides_widgets + "provides_modules" : ["messageicons"] // optional, this app provides a module that can be used with 'require' + "provides_widgets" : ["battery"] // optional, this app provides a type of widget - 'alarm/battery/bluetooth/pedometer/message' + "default" : true, // set if an app is the default implementer of something (a widget/module/etc) "readme": "README.md", // if supplied, a link to a markdown-style text file // that contains more information about this app (usage, etc) // A 'Read more...' link will be added under the app @@ -324,7 +341,7 @@ and which gives information about the app for the Launcher. ``` * name, icon and description present the app in the app loader. -* tags is used for grouping apps in the library, separate multiple entries by comma. Known tags are `tool`, `system`, `clock`, `game`, `sound`, `gps`, `widget`, `launcher` or empty. +* tags is used for grouping apps in the library, separate multiple entries by comma. Known tags are `tool`, `system`, `clock`, `game`, `sound`, `gps`, `widget`, `launcher`, `bluetooth` or empty. * storage is used to identify the app files and how to handle them * data is used to clean up files when the app is uninstalled @@ -454,7 +471,10 @@ It should also add `myappid.json` to `data`, to make sure it is cleaned up when ## Modules You can include any of [Espruino's modules](https://www.espruino.com/Modules) as -normal with `require("modulename")`. If you want to develop your own module for your +normal with `require("modulename")`. To include [Bangle's modules](modules) for use in the Web +IDE, [upload the modules to internal storage](modules#upload-the-module-to-the-bangles-internal-storage) +or [change the IDE's search path](modules#change-the-web-ide-search-path-to-include-banglejs-modules). +If you want to develop your own module for your app(s) then you can do that too. Just add the module into the `modules` folder then you can use it from your app as normal. diff --git a/android.html b/android.html index 93999008f..8a70a46e9 100644 --- a/android.html +++ b/android.html @@ -170,10 +170,10 @@ - + + - diff --git a/apps/7x7dotsclock/7x7dotsclock.app.js b/apps/7x7dotsclock/7x7dotsclock.app.js index aa174b2d2..aa6672a4f 100644 --- a/apps/7x7dotsclock/7x7dotsclock.app.js +++ b/apps/7x7dotsclock/7x7dotsclock.app.js @@ -149,11 +149,11 @@ function drawHSeg(x1,y1,x2,y2,Num,Color,Size) { if (Color == "fg") { g.setColor(g.theme.fg); } else { - g.setColor(mColor[0],mColor[1],mColor[2]); + g.setColor(mColor[0],mColor[1],mColor[2]); } g.fillCircle(x1+Dx+(i-1)*(x2-x1)/7,y1+Dy+(j-1)*(y2-y1)/7,Size); } else { - g.setColor(bColor[0],bColor[1],bColor[2]); + g.setColor(bColor[0],bColor[1],bColor[2]); g.fillCircle(x1+Dx+(i-1)*(x2-x1)/7,y1+Dy+(j-1)*(y2-y1)/7,1); } } @@ -166,7 +166,7 @@ function drawSSeg(x1,y1,x2,y2,Num,Color,Size) { for (let j = 1; j < 8; j++) { if (Font[Num][j-1][i-1] == 1) { if (Color == "fg") { - g.setColor(sColor[0],sColor[1],sColor[2]); + g.setColor(sColor[0],sColor[1],sColor[2]); } else { g.setColor(g.theme.fg); //g.setColor(0.7,0.7,0.7); @@ -253,8 +253,8 @@ function actions(v){ if(BTN1.read() === true) { print("BTN pressed"); Bangle.showLauncher(); - } - + } + if(v==-1){ print("up swipe event"); if(settings.swupApp != "") load(settings.swupApp); @@ -269,7 +269,7 @@ function actions(v){ } // Get Messages status -var messages = require("Storage").readJSON("messages.json",1)||[]; +var messages_installed = require("Storage").read("messages") !== undefined; //var BTconnected = NRF.getSecurityStatus().connected; //NRF.on('connect',BTconnected = NRF.getSecurityStatus().connected); @@ -289,27 +289,27 @@ function drawWidgeds() { g.setColor((g.getBPP()>8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); else g.setColor(g.theme.dark ? "#666" : "#999"); - g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="),x1Bt,y1Bt); + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="),x1Bt,y1Bt); + - //Battery //print(E.getBattery()); //print(Bangle.isCharging()); - + var x1B = 130; var y1B = 2; var x2B = x1B + 20; var y2B = y1B + 15; - + g.setColor(g.theme.bg); g.clearRect(x1B,y1B,x2B,y2B); - + g.setColor(g.theme.fg); g.drawRect(x1B,y1B,x2B,y2B); g.fillRect(x1B,y1B,x1B+(E.getBattery()*(x2B-x1B)/100),y2B); g.fillRect(x2B,y1B+(y2B-y1B)/2-3,x2B+4,y1B+(y2B-y1B)/2+3); - + //Messages @@ -318,25 +318,25 @@ function drawWidgeds() { var x2M = x1M + 25; var y2M = y2B; - if (messages.some(m=>m.new)) { + if (messages_installed && require("messages").status() == "new") { g.setColor(g.theme.fg); g.fillRect(x1M,y1M,x2M,y2M); g.setColor(g.theme.bg); g.drawLine(x1M,y1M,x1M+(x2M-x1M)/2,y1M+(y2M-y1M)/2); g.drawLine(x1M+(x2M-x1M)/2,y1M+(y2M-y1M)/2,x2M,y1M); } - + var strDow = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; var d = new Date(); var dow = d.getDay(),day = d.getDate(), month = d.getMonth() + 1, year = d.getFullYear(); print(strDow[dow] + ' ' + day + '.' + month + ' ' + year); - + g.setColor(g.theme.fg); g.setFontAlign(-1, -1,0); g.setFont("Vector", 20); g.drawString(strDow[dow] + ' ' + day, 0, 0, true); - + } @@ -354,7 +354,7 @@ function SetFull(on) { } else { Ys = 30; Bangle.setUI("updown",actions); - Bangle.on('swipe', function(direction) { + Bangle.on('swipe', function(direction) { switch (direction) { case 1: print("swipe left event"); @@ -362,7 +362,7 @@ function SetFull(on) { print(settings.swleftApp); break; case -1: - print("swipe right event"); + print("swipe right event"); if(settings.swrightApp != "") load(settings.swrightApp); print(settings.swrightApp); break; @@ -374,7 +374,7 @@ function SetFull(on) { SegH = (Ye-Ys)/2; Dy = SegH/16; - + draw(); if (on != true) { diff --git a/apps/7x7dotsclock/ChangeLog b/apps/7x7dotsclock/ChangeLog index d2c98a472..5e8e48b0b 100644 --- a/apps/7x7dotsclock/ChangeLog +++ b/apps/7x7dotsclock/ChangeLog @@ -1,2 +1,3 @@ 0.01: Initial version for upload -0.02: better theme support, configurable colors, small improvements +0.02: Better theme support, configurable colors, small improvements +0.03: Use `messages` library to check for new messages \ No newline at end of file diff --git a/apps/7x7dotsclock/metadata.json b/apps/7x7dotsclock/metadata.json index 41f0836d3..ba1996544 100644 --- a/apps/7x7dotsclock/metadata.json +++ b/apps/7x7dotsclock/metadata.json @@ -1,7 +1,7 @@ { "id": "7x7dotsclock", "name": "7x7 Dots Clock", "shortName":"7x7 Dots Clock", - "version":"0.02", + "version":"0.03", "description": "A clock with a big 7x7 dots Font", "icon": "dotsfontclock.png", "tags": "clock", diff --git a/apps/90sclk/ChangeLog b/apps/90sclk/ChangeLog index feb008f5f..057d6ff73 100644 --- a/apps/90sclk/ChangeLog +++ b/apps/90sclk/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! -0.02: Fullscreen settings. \ No newline at end of file +0.02: Fullscreen settings. +0.03: Tell clock widgets to hide. diff --git a/apps/90sclk/app.js b/apps/90sclk/app.js index 6babbfec2..351c235e0 100644 --- a/apps/90sclk/app.js +++ b/apps/90sclk/app.js @@ -115,6 +115,9 @@ function draw() { } } +// Show launcher when middle button pressed +Bangle.setUI("clock"); + Bangle.loadWidgets(); // Clear the screen once, at startup @@ -140,5 +143,3 @@ Bangle.on('lock', function(isLocked) { }); -// Show launcher when middle button pressed -Bangle.setUI("clock"); diff --git a/apps/90sclk/metadata.json b/apps/90sclk/metadata.json index fb2824a6f..59b627427 100644 --- a/apps/90sclk/metadata.json +++ b/apps/90sclk/metadata.json @@ -1,7 +1,7 @@ { "id": "90sclk", "name": "90s Clock", - "version": "0.02", + "version": "0.03", "description": "A 90s style watch-face", "readme": "README.md", "icon": "app.png", diff --git a/apps/UI4swatch/Changelog b/apps/UI4swatch/ChangeLog similarity index 100% rename from apps/UI4swatch/Changelog rename to apps/UI4swatch/ChangeLog diff --git a/apps/a_dndtoggle/ChangeLog b/apps/a_dndtoggle/ChangeLog new file mode 100644 index 000000000..ec66c5568 --- /dev/null +++ b/apps/a_dndtoggle/ChangeLog @@ -0,0 +1 @@ +0.01: Initial version diff --git a/apps/a_dndtoggle/README.md b/apps/a_dndtoggle/README.md new file mode 100644 index 000000000..bd0981c5b --- /dev/null +++ b/apps/a_dndtoggle/README.md @@ -0,0 +1,13 @@ +# a_dndtoggle - Toggle Quiet Mode of the watch + +When Quiet mode is off, just start this app to set quiet mode. Start it again to turn off quiet mode. +Work in progress. + +#ToDo +Settings page, current status indicator. + +## Creator + +Hank - contact at http://forum.espruino.com + + diff --git a/apps/a_dndtoggle/a_dndtoggle.app.js b/apps/a_dndtoggle/a_dndtoggle.app.js new file mode 100644 index 000000000..c0b968f2c --- /dev/null +++ b/apps/a_dndtoggle/a_dndtoggle.app.js @@ -0,0 +1,43 @@ + +const modeNames = [/*LANG*/"Noisy", /*LANG*/"Alarms", /*LANG*/"Silent"]; +let bSettings = require('Storage').readJSON('setting.json',true)||{}; +let current = 0|bSettings.quiet; +//0 off +//1 alarms +//2 silent + +console.log("old: " + current); + +switch (current) { + case 0: + bSettings.quiet = 2; + Bangle.buzz(); + setTimeout('Bangle.buzz();',500); + break; + case 1: + bSettings.quiet = 0; + Bangle.buzz(); + break; + case 2: + bSettings.quiet = 0; + Bangle.buzz(); + break; + default: + bSettings.quiet = 0; + Bangle.buzz(); +} + +console.log("new: " + bSettings.quiet); + +E.showMessage(modeNames[current] + " -> " + modeNames[bSettings.quiet]); +setTimeout('exitApp();', 2000); + + +function exitApp(){ + +require("Storage").writeJSON("setting.json", bSettings); +// reload clocks with new theme, otherwise just wait for user to switch apps + +load() + +} \ No newline at end of file diff --git a/apps/a_dndtoggle/a_dndtoggle.png b/apps/a_dndtoggle/a_dndtoggle.png new file mode 100644 index 000000000..4c8b74c0c Binary files /dev/null and b/apps/a_dndtoggle/a_dndtoggle.png differ diff --git a/apps/a_dndtoggle/app-icon.js b/apps/a_dndtoggle/app-icon.js new file mode 100644 index 000000000..0b08cc65b --- /dev/null +++ b/apps/a_dndtoggle/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwJC/AAl/Agf/AAUAgIFDwEHAofgh/g/0Ag/wj+AnwVB/EegEfEIN4nkAh+AgE8vgVBAoV4Aoce/EAgfADQIFcjwpFHYIFCnxBFJopZBn5ZCMopxFPoqJFSowA/gA=")) \ No newline at end of file diff --git a/apps/a_dndtoggle/metadata.json b/apps/a_dndtoggle/metadata.json new file mode 100644 index 000000000..f5ae9cc31 --- /dev/null +++ b/apps/a_dndtoggle/metadata.json @@ -0,0 +1,16 @@ +{ + "id": "a_dndtoggle", + "name": "a_dndtoggle - Toggle Quiet Mode of the watch", + "shortName": "A_DND Toggle", + "version": "0.01", + "description": "Toggle Quiet Mode of the watch just by starting this app.", + "icon": "a_dndtoggle.png", + "type": "app", + "tags": "tool", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"a_dndtoggle.app.js","url":"a_dndtoggle.app.js"}, + {"name":"a_dndtoggle.img","url":"app-icon.js","evaluate":true} + ], + "readme": "README.md" +} diff --git a/apps/about/ChangeLog b/apps/about/ChangeLog index f5638fdd2..e236e4b34 100644 --- a/apps/about/ChangeLog +++ b/apps/about/ChangeLog @@ -10,3 +10,5 @@ 0.10: Added separate Bangle.js 2 file with Bangle.js 2 kickstarter pixels (as of 28 Oct 2021) 0.11: Bangle.js2: New pixels, btn1 to exit 0.12: Actual pixels as of 29th Nov 2021 +0.13: Bangle.js 2: Use setUI to add software back button +0.14: Add automatic translation of more strings diff --git a/apps/about/app-bangle1.js b/apps/about/app-bangle1.js index 28a292376..dd94c1e84 100644 --- a/apps/about/app-bangle1.js +++ b/apps/about/app-bangle1.js @@ -11,8 +11,8 @@ g.drawString("BANGLEJS.COM",120,y-4); } else { y=-(4+h); // small screen, start right at top } -g.drawString("Powered by Espruino",0,y+=4+h); -g.drawString("Version "+ENV.VERSION,0,y+=h); +g.drawString(/*LANG*/"Powered by Espruino",0,y+=4+h); +g.drawString(/*LANG*/"Version "+ENV.VERSION,0,y+=h); g.drawString("Commit "+ENV.GIT_COMMIT,0,y+=h); function getVersion(name,file) { var j = s.readJSON(file,1); @@ -24,9 +24,9 @@ getVersion("Launcher","launch.info"); getVersion("Settings","setting.info"); y+=h; -g.drawString(MEM.total+" JS Variables available",0,y+=h); -g.drawString("Storage: "+(require("Storage").getFree()>>10)+"k free",0,y+=h); -if (ENV.STORAGE) g.drawString(" "+(ENV.STORAGE>>10)+"k total",0,y+=h); +g.drawString(MEM.total+/*LANG*/" JS Variables available",0,y+=h); +g.drawString("Storage: "+(require("Storage").getFree()>>10)+/*LANG*/"k free",0,y+=h); +if (ENV.STORAGE) g.drawString(" "+(ENV.STORAGE>>10)+/*LANG*/"k total",0,y+=h); if (ENV.SPIFLASH) g.drawString("SPI Flash: "+(ENV.SPIFLASH>>10)+"k",0,y+=h); g.setFontAlign(0,-1); g.flip(); diff --git a/apps/about/app-bangle2.js b/apps/about/app-bangle2.js index 978d36193..ccffd183f 100644 --- a/apps/about/app-bangle2.js +++ b/apps/about/app-bangle2.js @@ -10,7 +10,7 @@ var img = atob("sIwDkm2S66DYwA2AAAAAHAHGSRxJEkAAgmGGBxDIADIdAFJIbAHF9HP00kBUC6Dt var imgHeight = g.imageMetrics(img).height; var imgScroll = Math.floor(Math.random()*imgHeight); -g.reset().setFont("6x15").setFontAlign(0,0); +g.clear(1).setFont("6x15").setFontAlign(0,0); g.drawString(ENV.VERSION + " " + NRF.getAddress(), g.getWidth()/2, 171); g.drawImage(img,0,24); @@ -35,17 +35,17 @@ function drawInfo() { g.setFont("4x6").setFontAlign(0,0).drawString("BANGLEJS.COM",W-30,56); var h=8, y = 24-h; g.setFont("6x8").setFontAlign(-1,-1); - g.drawString("Powered by Espruino",0,y+=4+h); - g.drawString("Version "+ENV.VERSION,0,y+=h); + g.drawString(/*LANG*/"Powered by Espruino",0,y+=4+h); + g.drawString(/*LANG*/"Version "+ENV.VERSION,0,y+=h); g.drawString("Commit "+ENV.GIT_COMMIT,0,y+=h); getVersion("Bootloader","boot.info"); getVersion("Launcher","launch.info"); getVersion("Settings","setting.info"); - g.drawString(MEM.total+" JS Vars",0,y+=h); - g.drawString("Storage: "+(require("Storage").getFree()>>10)+"k free",0,y+=h); - if (ENV.STORAGE) g.drawString(" "+(ENV.STORAGE>>10)+"k total",0,y+=h); + g.drawString(MEM.total+/*LANG*/" JS Vars",0,y+=h); + g.drawString("Storage: "+(require("Storage").getFree()>>10)+/*LANG*/"k free",0,y+=h); + if (ENV.STORAGE) g.drawString(" "+(ENV.STORAGE>>10)+/*LANG*/"k total",0,y+=h); if (ENV.SPIFLASH) g.drawString("SPI Flash: "+(ENV.SPIFLASH>>10)+"k",0,y+=h); imageTop = y+h; imgScroll = imgHeight-imageTop; @@ -69,4 +69,7 @@ function drawImage() { // TODO: a nice little animation before setTimeout(drawInfo, 1000); -setWatch(_=>load(), BTN1); +Bangle.setUI({ + mode : "custom", + back : load +}); diff --git a/apps/about/metadata.json b/apps/about/metadata.json index 6c22bdc56..52cd37b7d 100644 --- a/apps/about/metadata.json +++ b/apps/about/metadata.json @@ -1,7 +1,7 @@ { "id": "about", "name": "About", - "version": "0.12", + "version": "0.14", "description": "Bangle.js About page - showing software version, stats, and a collaborative mural from the Bangle.js KickStarter backers", "icon": "app.png", "tags": "tool,system", diff --git a/apps/accellog/ChangeLog b/apps/accellog/ChangeLog index 80981fe27..94241c7a7 100644 --- a/apps/accellog/ChangeLog +++ b/apps/accellog/ChangeLog @@ -2,3 +2,4 @@ 0.02: Use the new multiplatform 'Layout' library 0.03: Exit as first menu option, dont show decimal places for seconds 0.04: Localisation, change Exit->Back to allow back-arrow to appear on 2v13 firmware +0.05: Add max G values during recording, record actual G values and magnitude to CSV diff --git a/apps/accellog/app.js b/apps/accellog/app.js index f4c1b3c5a..147f7503f 100644 --- a/apps/accellog/app.js +++ b/apps/accellog/app.js @@ -1,5 +1,6 @@ var fileNumber = 0; var MAXLOGS = 9; +var logRawData = false; function getFileName(n) { return "accellog."+n+".csv"; @@ -24,6 +25,11 @@ function showMenu() { /*LANG*/"View Logs" : function() { viewLogs(); }, + /*LANG*/"Log raw data" : { + value : logRawData, + format : v => v?/*LANG*/"Yes":/*LANG*/"No", + onchange : v => { logRawData=v; } + }, }; E.showMenu(menu); } @@ -78,6 +84,7 @@ function viewLogs() { } function startRecord(force) { + var stopped = false; if (!force) { // check for existing file var f = require("Storage").open(getFileName(fileNumber), "r"); @@ -92,39 +99,101 @@ function startRecord(force) { var Layout = require("Layout"); var layout = new Layout({ type: "v", c: [ - {type:"txt", font:"6x8", label:/*LANG*/"Samples", pad:2}, - {type:"txt", id:"samples", font:"6x8:2", label:" - ", pad:5, bgCol:g.theme.bg}, - {type:"txt", font:"6x8", label:/*LANG*/"Time", pad:2}, - {type:"txt", id:"time", font:"6x8:2", label:" - ", pad:5, bgCol:g.theme.bg}, - {type:"txt", font:"6x8:2", label:/*LANG*/"RECORDING", bgCol:"#f00", pad:5, fillx:1}, - ] - },{btns:[ // Buttons... - {label:/*LANG*/"STOP", cb:()=>{ - Bangle.removeListener('accel', accelHandler); - showMenu(); + { type: "h", c: [ + { type: "v", c: [ + {type:"txt", font:"6x8", label:/*LANG*/"Samples", pad:2}, + {type:"txt", id:"samples", font:"6x8:2", label:" - ", pad:5, bgCol:g.theme.bg}, + ]}, + { type: "v", c: [ + {type:"txt", font:"6x8", label:/*LANG*/"Time", pad:2}, + {type:"txt", id:"time", font:"6x8:2", label:" - ", pad:5, bgCol:g.theme.bg}, + ]}, + ]}, + { type: "h", c: [ + { type: "v", c: [ + {type:"txt", font:"6x8", label:/*LANG*/"Max X", pad:2}, + {type:"txt", id:"maxX", font:"6x8", label:" - ", pad:5, bgCol:g.theme.bg}, + ]}, + { type: "v", c: [ + {type:"txt", font:"6x8", label:/*LANG*/"Max Y", pad:2}, + {type:"txt", id:"maxY", font:"6x8", label:" - ", pad:5, bgCol:g.theme.bg}, + ]}, + { type: "v", c: [ + {type:"txt", font:"6x8", label:/*LANG*/"Max Z", pad:2}, + {type:"txt", id:"maxZ", font:"6x8", label:" - ", pad:5, bgCol:g.theme.bg}, + ]}, + ]}, + {type:"txt", font:"6x8", label:/*LANG*/"Max G", pad:2}, + {type:"txt", id:"maxMag", font:"6x8:4", label:" - ", pad:5, bgCol:g.theme.bg}, + {type:"txt", id:"state", font:"6x8:2", label:/*LANG*/"RECORDING", bgCol:"#f00", pad:5, fillx:1}, + ]}, + { + btns:[ // Buttons... + {id: "btnStop", label:/*LANG*/"STOP", cb:()=>{ + if (stopped) { + showMenu(); + } + else { + Bangle.removeListener('accel', accelHandler); + layout.state.label = /*LANG*/"STOPPED"; + layout.state.bgCol = /*LANG*/"#0f0"; + stopped = true; + layout.render(); + } }} ]}); layout.render(); // now start writing var f = require("Storage").open(getFileName(fileNumber), "w"); - f.write("Time (ms),X,Y,Z\n"); + f.write("Time (ms),X,Y,Z,Total\n"); var start = getTime(); var sampleCount = 0; + var maxMag = 0; + var maxX = 0; + var maxY = 0; + var maxZ = 0; function accelHandler(accel) { var t = getTime()-start; - f.write([ - t*1000, - accel.x*8192, - accel.y*8192, - accel.z*8192].map(n=>Math.round(n)).join(",")+"\n"); + if (logRawData) { + f.write([ + t*1000, + accel.x*8192, + accel.y*8192, + accel.z*8192, + accel.mag*8192, + ].map(n=>Math.round(n)).join(",")+"\n"); + } else { + f.write([ + Math.round(t*1000), + accel.x, + accel.y, + accel.z, + accel.mag, + ].join(",")+"\n"); + } + if (accel.mag > maxMag) { + maxMag = accel.mag.toFixed(2); + } + if (accel.x > maxX) { + maxX = accel.x.toFixed(2); + } + if (accel.y > maxY) { + maxY = accel.y.toFixed(2); + } + if (accel.z > maxZ) { + maxZ = accel.z.toFixed(2); + } sampleCount++; layout.samples.label = sampleCount; layout.time.label = Math.round(t)+"s"; - layout.render(layout.samples); - layout.render(layout.time); + layout.maxX.label = maxX; + layout.maxY.label = maxY; + layout.maxZ.label = maxZ; + layout.maxMag.label = maxMag; + layout.render(); } Bangle.setPollInterval(80); // 12.5 Hz - the default diff --git a/apps/accellog/metadata.json b/apps/accellog/metadata.json index fdf6cf320..903c57903 100644 --- a/apps/accellog/metadata.json +++ b/apps/accellog/metadata.json @@ -2,7 +2,7 @@ "id": "accellog", "name": "Acceleration Logger", "shortName": "Accel Log", - "version": "0.04", + "version": "0.05", "description": "Logs XYZ acceleration data to a CSV file that can be downloaded to your PC", "icon": "app.png", "tags": "outdoor", diff --git a/apps/activepedom/README.md b/apps/activepedom/README.md index ac32a1dd6..06ad280ee 100644 --- a/apps/activepedom/README.md +++ b/apps/activepedom/README.md @@ -1,6 +1,11 @@ # Active Pedometer + Pedometer that filters out arm movement and displays a step goal progress. +**Note:** Since creation of this app, Bangle.js's step counting algorithm has +improved significantly - and as a result the algorithm in this app (which + runs *on top* of Bangle.js's algorithm) may no longer be accurate. + I changed the step counting algorithm completely. Now every step is counted when in status 'active', if the time difference between two steps is not too short or too long. To get in 'active' mode, you have to reach the step threshold before the active timer runs out. @@ -9,6 +14,7 @@ When you reach the step threshold, the steps needed to reach the threshold are c Steps are saved to a datafile every 5 minutes. You can watch a graph using the app. ## Screenshots + * 600 steps ![](600.png) @@ -70,4 +76,4 @@ Steps are saved to a datafile every 5 minutes. You can watch a graph using the a ## Requests -If you have any feature requests, please post in this forum thread: http://forum.espruino.com/conversations/345754/ \ No newline at end of file +If you have any feature requests, please post in this forum thread: http://forum.espruino.com/conversations/345754/ diff --git a/apps/activepedom/metadata.json b/apps/activepedom/metadata.json index 4deb7006d..81bafb573 100644 --- a/apps/activepedom/metadata.json +++ b/apps/activepedom/metadata.json @@ -3,7 +3,7 @@ "name": "Active Pedometer", "shortName": "Active Pedometer", "version": "0.09", - "description": "Pedometer that filters out arm movement and displays a step goal progress. Steps are saved to a daily file and can be viewed as graph.", + "description": "(NOT RECOMMENDED) Pedometer that filters out arm movement and displays a step goal progress. Steps are saved to a daily file and can be viewed as graph. The `Health` app now provides step logging and graphs.", "icon": "app.png", "tags": "outdoors,widget", "supports": ["BANGLEJS"], diff --git a/apps/activityreminder/ChangeLog b/apps/activityreminder/ChangeLog index 37820dce6..3811425ac 100644 --- a/apps/activityreminder/ChangeLog +++ b/apps/activityreminder/ChangeLog @@ -6,3 +6,5 @@ 0.06: Add a temperature threshold to detect (and not alert) if the BJS isn't worn. Better support for the peoples using the app at night 0.07: Fix bug on the cutting edge firmware 0.08: Use default Bangle formatter for booleans +0.09: New app screen (instead of showing settings or the alert) and some optimisations +0.10: Add software back button via setUI diff --git a/apps/activityreminder/alert.js b/apps/activityreminder/alert.js new file mode 100644 index 000000000..96a9b76c4 --- /dev/null +++ b/apps/activityreminder/alert.js @@ -0,0 +1,37 @@ +(function () { + // load variable before defining functions cause it can trigger a ReferenceError + const activityreminder = require("activityreminder"); + const storage = require("Storage"); + let activityreminder_data = activityreminder.loadData(); + + function run() { + E.showPrompt("Inactivity detected", { + title: "Activity reminder", + buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 } + }).then(function (v) { + if (v == 1) { + activityreminder_data.okDate = new Date(); + } + if (v == 2) { + activityreminder_data.dismissDate = new Date(); + } + if (v == 3) { + activityreminder_data.pauseDate = new Date(); + } + activityreminder.saveData(activityreminder_data); + load(); + }); + + // Obey system quiet mode: + if (!(storage.readJSON('setting.json', 1) || {}).quiet) { + Bangle.buzz(400); + } + setTimeout(load, 20000); + } + + g.clear(); + Bangle.loadWidgets(); + Bangle.drawWidgets(); + run(); + +})(); \ No newline at end of file diff --git a/apps/activityreminder/app.js b/apps/activityreminder/app.js index c2b626fb3..81e10d8dd 100644 --- a/apps/activityreminder/app.js +++ b/apps/activityreminder/app.js @@ -1,46 +1,58 @@ (function () { - // load variable before defining functions cause it can trigger a ReferenceError - const activityreminder = require("activityreminder"); - const storage = require("Storage"); - const activityreminder_settings = activityreminder.loadSettings(); - let activityreminder_data = activityreminder.loadData(); + // load variable before defining functions cause it can trigger a ReferenceError + const activityreminder = require("activityreminder"); + let activityreminder_data = activityreminder.loadData(); + let W = g.getWidth(); + // let H = g.getHeight(); - function drawAlert() { - E.showPrompt("Inactivity detected", { - title: "Activity reminder", - buttons: { "Ok": 1, "Dismiss": 2, "Pause": 3 } - }).then(function (v) { - if (v == 1) { - activityreminder_data.okDate = new Date(); - } - if (v == 2) { - activityreminder_data.dismissDate = new Date(); - } - if (v == 3) { - activityreminder_data.pauseDate = new Date(); - } - activityreminder.saveData(activityreminder_data); - load(); - }); - - // Obey system quiet mode: - if (!(storage.readJSON('setting.json', 1) || {}).quiet) { - Bangle.buzz(400); - } - setTimeout(load, 20000); - } - - function run() { - if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) { - drawAlert(); - } else { - eval(storage.read("activityreminder.settings.js"))(() => load()); - } - } + function getHoursMins(date){ + var h = date.getHours(); + var m = date.getMinutes(); + return (""+h).substr(-2) + ":" + ("0"+m).substr(-2); + } + function drawData(name, value, y){ + g.drawString(name, 10, y); + g.drawString(value, 100, y); + } + + function drawInfo() { + var h=18, y = h; + g.setColor(g.theme.fg); + g.setFont("Vector",h).setFontAlign(-1,-1); + + // Header + g.drawLine(0,25,W,25); + g.drawLine(0,26,W,26); + + g.drawString("Current Cycle", 10, y+=h); + drawData("Start", getHoursMins(activityreminder_data.stepsDate), y+=h); + drawData("Steps", getCurrentSteps(), y+=h); + + /* + g.drawString("Button Press", 10, y+=h*2); + drawData("Ok", getHoursMins(activityreminder_data.okDate), y+=h); + drawData("Dismiss", getHoursMins(activityreminder_data.dismissDate), y+=h); + drawData("Pause", getHoursMins(activityreminder_data.pauseDate), y+=h); + */ + } + + function getCurrentSteps(){ + let health = Bangle.getHealthStatus("day"); + return health.steps - activityreminder_data.stepsOnDate; + } + + function run() { g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); - run(); - -})(); \ No newline at end of file + drawInfo(); + Bangle.setUI({ + mode : "custom", + back : load + }) + } + + run(); + +})(); diff --git a/apps/activityreminder/boot.js b/apps/activityreminder/boot.js index f97cf274d..5a11d73b8 100644 --- a/apps/activityreminder/boot.js +++ b/apps/activityreminder/boot.js @@ -1,70 +1,81 @@ (function () { - // load variable before defining functions cause it can trigger a ReferenceError - const activityreminder = require("activityreminder"); - const activityreminder_settings = activityreminder.loadSettings(); - let activityreminder_data = activityreminder.loadData(); - - if (activityreminder_data.firstLoad) { - activityreminder_data.firstLoad = false; + // load variable before defining functions cause it can trigger a ReferenceError + const activityreminder = require("activityreminder"); + const activityreminder_settings = activityreminder.loadSettings(); + let activityreminder_data = activityreminder.loadData(); + + if (activityreminder_data.firstLoad) { + activityreminder_data.firstLoad = false; + activityreminder.saveData(activityreminder_data); + } + + function run() { + if (isNotWorn()) return; + let now = new Date(); + let h = now.getHours(); + + if (isDuringAlertHours(h)) { + let health = Bangle.getHealthStatus("day"); + if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed + || health.steps < activityreminder_data.stepsOnDate) { // new day or reboot of the watch + activityreminder_data.stepsOnDate = health.steps; + activityreminder_data.stepsDate = now; activityreminder.saveData(activityreminder_data); - } - - function run() { - if (isNotWorn()) return; - let now = new Date(); - let h = now.getHours(); - - if (isDuringAlertHours(h)) { - let health = Bangle.getHealthStatus("day"); - if (health.steps - activityreminder_data.stepsOnDate >= activityreminder_settings.minSteps // more steps made than needed - || health.steps < activityreminder_data.stepsOnDate) { // new day or reboot of the watch - activityreminder_data.stepsOnDate = health.steps; - activityreminder_data.stepsDate = now; - activityreminder.saveData(activityreminder_data); - /* todo in a futur release - Add settimer to trigger like 30 secs after going in this part cause the person have been walking - (pass some argument to run() to handle long walks and not triggering so often) - */ - } - - if (activityreminder.mustAlert(activityreminder_data, activityreminder_settings)) { - load('activityreminder.app.js'); - } - } - - } - - function isNotWorn() { - return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature()); - } - - function isDuringAlertHours(h) { - if (activityreminder_settings.startHour < activityreminder_settings.endHour) { // not passing through midnight - return (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour); - } else { // passing through midnight - return (h >= activityreminder_settings.startHour || h < activityreminder_settings.endHour); - } - } - - Bangle.on('midnight', function () { - /* - Usefull trick to have the app working smothly for people using it at night - */ - let now = new Date(); - let h = now.getHours(); - if (activityreminder_settings.enabled && isDuringAlertHours(h)) { - // updating only the steps and keeping the original stepsDate on purpose - activityreminder_data.stepsOnDate = 0; - activityreminder.saveData(activityreminder_data); - } - }); - - - if (activityreminder_settings.enabled) { - setInterval(run, 60000); /* todo in a futur release - increase setInterval time to something that is still sensible (5 mins ?) - when we added a settimer + Add settimer to trigger like 30 secs after going in this part cause the person have been walking + (pass some argument to run() to handle long walks and not triggering so often) */ + } + + if (mustAlert(now)) { + load('activityreminder.alert.js'); + } } + + } + + function isNotWorn() { + return (Bangle.isCharging() || activityreminder_settings.tempThreshold >= E.getTemperature()); + } + + function isDuringAlertHours(h) { + if (activityreminder_settings.startHour < activityreminder_settings.endHour) { // not passing through midnight + return (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour); + } else { // passing through midnight + return (h >= activityreminder_settings.startHour || h < activityreminder_settings.endHour); + } + } + + function mustAlert(now) { + if ((now - activityreminder_data.stepsDate) / 60000 > activityreminder_settings.maxInnactivityMin) { // inactivity detected + if ((now - activityreminder_data.okDate) / 60000 > 3 && // last alert anwsered with ok was more than 3 min ago + (now - activityreminder_data.dismissDate) / 60000 > activityreminder_settings.dismissDelayMin && // last alert was more than dismissDelayMin ago + (now - activityreminder_data.pauseDate) / 60000 > activityreminder_settings.pauseDelayMin) { // last alert was more than pauseDelayMin ago + return true; + } + } + return false; + } + + Bangle.on('midnight', function () { + /* + Usefull trick to have the app working smothly for people using it at night + */ + let now = new Date(); + let h = now.getHours(); + if (activityreminder_settings.enabled && isDuringAlertHours(h)) { + // updating only the steps and keeping the original stepsDate on purpose + activityreminder_data.stepsOnDate = 0; + activityreminder.saveData(activityreminder_data); + } + }); + + + if (activityreminder_settings.enabled) { + setInterval(run, 60000); + /* todo in a futur release + increase setInterval time to something that is still sensible (5 mins ?) + when we added a settimer + */ + } })(); diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index 704d35641..a5c35190c 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -1,56 +1,44 @@ exports.loadSettings = function () { - return Object.assign({ - enabled: true, - startHour: 9, - endHour: 20, - maxInnactivityMin: 30, - dismissDelayMin: 15, - pauseDelayMin: 120, - minSteps: 50, - tempThreshold: 27 - }, require("Storage").readJSON("activityreminder.s.json", true) || {}); + return Object.assign({ + enabled: true, + startHour: 9, + endHour: 20, + maxInnactivityMin: 30, + dismissDelayMin: 15, + pauseDelayMin: 120, + minSteps: 50, + tempThreshold: 27 + }, require("Storage").readJSON("activityreminder.s.json", true) || {}); }; exports.writeSettings = function (settings) { - require("Storage").writeJSON("activityreminder.s.json", settings); + require("Storage").writeJSON("activityreminder.s.json", settings); }; exports.saveData = function (data) { - require("Storage").writeJSON("activityreminder.data.json", data); + require("Storage").writeJSON("activityreminder.data.json", data); }; exports.loadData = function () { - let health = Bangle.getHealthStatus("day"); - let data = Object.assign({ - firstLoad: true, - stepsDate: new Date(), - stepsOnDate: health.steps, - okDate: new Date(1970), - dismissDate: new Date(1970), - pauseDate: new Date(1970), - }, + let health = Bangle.getHealthStatus("day"); + let data = Object.assign({ + firstLoad: true, + stepsDate: new Date(), + stepsOnDate: health.steps, + okDate: new Date(1970), + dismissDate: new Date(1970), + pauseDate: new Date(1970), + }, require("Storage").readJSON("activityreminder.data.json") || {}); - if(typeof(data.stepsDate) == "string") - data.stepsDate = new Date(data.stepsDate); - if(typeof(data.okDate) == "string") - data.okDate = new Date(data.okDate); - if(typeof(data.dismissDate) == "string") - data.dismissDate = new Date(data.dismissDate); - if(typeof(data.pauseDate) == "string") - data.pauseDate = new Date(data.pauseDate); + if (typeof (data.stepsDate) == "string") + data.stepsDate = new Date(data.stepsDate); + if (typeof (data.okDate) == "string") + data.okDate = new Date(data.okDate); + if (typeof (data.dismissDate) == "string") + data.dismissDate = new Date(data.dismissDate); + if (typeof (data.pauseDate) == "string") + data.pauseDate = new Date(data.pauseDate); - return data; + return data; }; - -exports.mustAlert = function(activityreminder_data, activityreminder_settings) { - let now = new Date(); - if ((now - activityreminder_data.stepsDate) / 60000 > activityreminder_settings.maxInnactivityMin) { // inactivity detected - if ((now - activityreminder_data.okDate) / 60000 > 3 && // last alert anwsered with ok was more than 3 min ago - (now - activityreminder_data.dismissDate) / 60000 > activityreminder_settings.dismissDelayMin && // last alert was more than dismissDelayMin ago - (now - activityreminder_data.pauseDate) / 60000 > activityreminder_settings.pauseDelayMin) { // last alert was more than pauseDelayMin ago - return true; - } - } - return false; -} \ No newline at end of file diff --git a/apps/activityreminder/metadata.json b/apps/activityreminder/metadata.json index 75ebf80b2..a7fb0c487 100644 --- a/apps/activityreminder/metadata.json +++ b/apps/activityreminder/metadata.json @@ -3,7 +3,7 @@ "name": "Activity Reminder", "shortName":"Activity Reminder", "description": "A reminder to take short walks for the ones with a sedentary lifestyle", - "version":"0.08", + "version":"0.10", "icon": "app.png", "type": "app", "tags": "tool,activity", @@ -13,11 +13,12 @@ {"name": "activityreminder.app.js", "url":"app.js"}, {"name": "activityreminder.boot.js", "url": "boot.js"}, {"name": "activityreminder.settings.js", "url": "settings.js"}, + {"name": "activityreminder.alert.js", "url": "alert.js"}, {"name": "activityreminder", "url": "lib.js"}, {"name": "activityreminder.img", "url": "app-icon.js", "evaluate": true} ], "data": [ {"name": "activityreminder.s.json"}, - {"name": "activityreminder.data.json"} + {"name": "activityreminder.data.json", "storageFile": true} ] } diff --git a/apps/activityreminder/settings.js b/apps/activityreminder/settings.js index de490b796..051c0dcd8 100644 --- a/apps/activityreminder/settings.js +++ b/apps/activityreminder/settings.js @@ -1,80 +1,86 @@ (function (back) { - // Load settings - const activityreminder = require("activityreminder"); - let settings = activityreminder.loadSettings(); + // Load settings + const activityreminder = require("activityreminder"); + let settings = activityreminder.loadSettings(); - // Show the menu - E.showMenu({ - "": { "title": "Activity Reminder" }, - "< Back": () => back(), - 'Enable': { - value: settings.enabled, - onchange: v => { - settings.enabled = v; - activityreminder.writeSettings(settings); - } - }, - 'Start hour': { - value: settings.startHour, - min: 0, max: 24, - onchange: v => { - settings.startHour = v; - activityreminder.writeSettings(settings); - } - }, - 'End hour': { - value: settings.endHour, - min: 0, max: 24, - onchange: v => { - settings.endHour = v; - activityreminder.writeSettings(settings); - } - }, - 'Max inactivity': { - value: settings.maxInnactivityMin, - min: 15, max: 120, - onchange: v => { - settings.maxInnactivityMin = v; - activityreminder.writeSettings(settings); - }, - format: x => x + "m" - }, - 'Dismiss delay': { - value: settings.dismissDelayMin, - min: 5, max: 60, - onchange: v => { - settings.dismissDelayMin = v; - activityreminder.writeSettings(settings); - }, - format: x => x + "m" - }, - 'Pause delay': { - value: settings.pauseDelayMin, - min: 30, max: 240, step: 5, - onchange: v => { - settings.pauseDelayMin = v; - activityreminder.writeSettings(settings); - }, - format: x => { - return x + "m"; - } - }, - 'Min steps': { - value: settings.minSteps, - min: 10, max: 500, step: 10, - onchange: v => { - settings.minSteps = v; - activityreminder.writeSettings(settings); - } - }, - 'Temp Threshold': { - value: settings.tempThreshold, - min: 20, max: 40, step: 0.5, - format: v => v + "°C", - onchange: v => { - settings.tempThreshold = v; - activityreminder.writeSettings(settings); - } + function getMainMenu(){ + var mainMenu = { + "": { "title": "Activity Reminder" }, + "< Back": () => back(), + 'Enable': { + value: settings.enabled, + onchange: v => { + settings.enabled = v; + activityreminder.writeSettings(settings); } - }); + }, + 'Start hour': { + value: settings.startHour, + min: 0, max: 24, + onchange: v => { + settings.startHour = v; + activityreminder.writeSettings(settings); + } + }, + 'End hour': { + value: settings.endHour, + min: 0, max: 24, + onchange: v => { + settings.endHour = v; + activityreminder.writeSettings(settings); + } + }, + 'Max inactivity': { + value: settings.maxInnactivityMin, + min: 15, max: 120, + onchange: v => { + settings.maxInnactivityMin = v; + activityreminder.writeSettings(settings); + }, + format: x => x + "m" + }, + 'Dismiss delay': { + value: settings.dismissDelayMin, + min: 5, max: 60, + onchange: v => { + settings.dismissDelayMin = v; + activityreminder.writeSettings(settings); + }, + format: x => x + "m" + }, + 'Pause delay': { + value: settings.pauseDelayMin, + min: 30, max: 240, step: 5, + onchange: v => { + settings.pauseDelayMin = v; + activityreminder.writeSettings(settings); + }, + format: x => { + return x + "m"; + } + }, + 'Min steps': { + value: settings.minSteps, + min: 10, max: 500, step: 10, + onchange: v => { + settings.minSteps = v; + activityreminder.writeSettings(settings); + } + }, + 'Temp Threshold': { + value: settings.tempThreshold, + min: 20, max: 40, step: 0.5, + format: v => v + "°C", + onchange: v => { + settings.tempThreshold = v; + activityreminder.writeSettings(settings); + } + } + }; + + return mainMenu; + } + + // Show the menu + E.showMenu(getMainMenu()); }) diff --git a/apps/advcasio/ChangeLog b/apps/advcasio/ChangeLog index 7de176672..fd37c324e 100644 --- a/apps/advcasio/ChangeLog +++ b/apps/advcasio/ChangeLog @@ -1 +1,4 @@ 0.01: AdvCasio first version +0.02: Remove un-needed fonts to improve memory usage +0.03: Tell clock widgets to hide. +0.04: Swipe down to see widgets, step counter now just uses getHealthStatus diff --git a/apps/advcasio/app.js b/apps/advcasio/app.js index 8c27b7823..9d246b7ef 100644 --- a/apps/advcasio/app.js +++ b/apps/advcasio/app.js @@ -1,306 +1,160 @@ const storage = require('Storage'); require("Font6x12").add(Graphics); -require("Font6x8").add(Graphics); require("Font8x12").add(Graphics); require("Font7x11Numeric7Seg").add(Graphics); function bigThenSmall(big, small, x, y) { - g.setFont("7x11Numeric7Seg", 2); - g.drawString(big, x, y); - x += g.stringWidth(big); - g.setFont("8x12"); - g.drawString(small, x, y); + g.setFont("7x11Numeric7Seg", 2); + g.drawString(big, x, y); + x += g.stringWidth(big); + g.setFont("8x12"); + g.drawString(small, x, y); } -function getClockBg() { - return require("heatshrink").decompress(atob("icVgf/ABv8v4DBx4CB+PH8F+nAGB48fwEHBwXjxwqBuPH//+nAGBBwIjCAwI2D/wGBgIyDI4QGDwAGBHYX/4AGBn4UFEYQpCEYYpCAAMfMhP4FIgABwJ8OEBIA==")); -} - - -// sun, cloud, rain, thunder -var iconsWeather = [ - require("heatshrink").decompress(atob("i8Ugf/ACcfA434BA/AAwsAv0/8F/BAcDwEHHIpECFI3wn4GC/gOC+PAGoXggEH/+ODQgXBGQv/wAbBBAnguEACIn4gfxI4JXFwJmG/kPBA3jSynw")), require("heatshrink").decompress(atob("i0Ugf/AEXggIGE/0A/kPBAmBCIN/A4Y8CgAICwEHBYoUE/ACCj4sDn4CBC4YyDwBrDCgYA3A")), require("heatshrink").decompress(atob("h8Rgf/AAuBAgf8h4FDCwM/AgPA/gFC/0HgEBBQPwnEfDoWAg4jC/gOCAoQmBAQXjFIV//8f//4IQP4j/+gAIB4EcHII4CAoI+DLQJXF/AA==")), require("heatshrink").decompress(atob("h0Pgf/AA8fAYX+g4EC8EBAgXADAeAgAECgAOC/wrCDQIOBBYfwgAaC/kAn4EB/EAv4aDHAeBIg38")) -]; - - function getBackgroundImage() { - return require("heatshrink").decompress(atob("2GwghC/AH4A/AH4AMl////wAwURiQECgUzmcxBQQCBiYUBBARW+LAcCAgcPBYgFBkAIFG7kQiAKIiIKBgISOAAJBD//zKQfxK4vyAoMQCgn/ERBhBBYR5BAwR1DB4Y2DgYPCGIQRCCQcP+EfGJI0FEgRSCGAQCCX4JXCkAhDn4lI+HyK4YWBFIPzJYJXHAIMSK4cwJ4I3CAYMzA4cfcRMBdwytBK4i6FK4IUCMgYAEGIITBK4cCaAPwgJXB+fzK4sAgYtCK5EfA4pXR+AmBaIZYCK6KcCAwSjDEYXx/8vK5QRCK4kPK6cDkJREBIMBfgIrDK5svUAIQBAwIaCK4w+DK4YGBK7IaBboIuCK4gFCJwYBBiBCCCgQhHHYgGDgArBK5IGDAYMgJ4Xwn53BGgLVDmBXKAAinDLpJXCAAYhHR4YODn/wJIPyTYZXDE4RXD+ECNILIDAIPwj4xIAAYNCR4fyVIYLFA4KEBBAglKAGUCmcykEAiMQBIURBYM/BgIUEgcz+bTKAH4A/AH4A/AHP/AGY1d+BWCh5X/LCpW1K74fgG/5X/AH5X/K9Bg/K63wK/5XWgBX/K6pWBK/5XU+BWBh5J/K6auCK/5XTVwRfFAH5XOKwRX/K6auDh5I/K6SuDWP5XSVwYADWX6vXK/5XQWQpW/K6auDJP5XWV35XT+Cu/K7Ku/K65H/K6hW/K7EPI35XWIv5XWAH5X/K/4A/K/5X/K/4A/K9cAAH4A/AFzz/AHRX/K/5X/AH5X/K/5X/AH5X/K/4A/K/5X/K/4A/K/5X/K/4A/K/5X/AH5X/K/5X/AH5X/K/5X/AH5X/K/4A/K/5X/K/4A/K/5X/K/4A/K/5X/AH5X/K/5X/AH5X/K/5X/AH5X/K/4A/K/5X/K/4A/K/5X/K/4A/K/5X/AH5X/K/5X/AH5X/K/5X/AH5X/K/4A/K/5X/K/4A/K/5X/K/4A/K/5X/AH5X/K/5X/AH5X/K/40VAH4A/AFzLb+EPDm4AdK/5X/K+PwgEAHy5X9HgMAK/5XXH6xX/H65X/K/5X/K98AK7sAgBX3DjBWFO644DSTHwGzJXED4RXaDoLqcK7weWDIQcXK8I6YK77KXK4o8DPbY6ZK7qvDDy6vdR7JXDh60EDyw5BAIRXYSwjMbAgIhUDwJZCHwJX0GwjRWNwIAEHSwBCDSpXFH4pXzDS5XIEARXVSYbQEDaYzCK+6vcKaxXNDypX9HwQkbHS40COSpXKK2A6CHgRXcPIhX0SwpXYVuQ6EgBX/K644YODBXkSDJX/K/5X/DtRX6gA3YOkRWbLDZX4KwYA/AG8F5vdABncKH4AGhpRJAYXNAgPAKP4AF5vMJwoDBAQIKE6BR/AAvc5vO9wAB7oCB9veAoPcAoPcK+kwh8AgcA98An//gH/+sD//wCISgBJ4IABAYpaC9vdK4UP/9AAQNQr/zgHwEYNQFYQAh+EP+FegH+A4QBCMQIKBAAPNK4yxBA4RXCV4YZBE4IjChwCDmApCK8VdmHggHgFYf0SQJXE5nMK4anCAoYHC5pXCaQJXBop+BqAGEK7f/AAQeEKwQrBqCtDAILjBCQfNK4JTCAYZXF7qvD//gV4S2DgEFFIYAECgIACMC8PKoIBB8n1K4ivF5vc5xOCWYZbBAYavHU4RXCr4pEAEMDfoNQGoMEgEwYQPwAoIBBAAPM5ipC7oDCVIIAE7hXCD4SdBiEP+gGBgihCFYIAz5pXBAAnN7oIB7nc5gOBK4QA/K4pNCWgSpCBInNK/4AGhncKIStC7gCBA4QAC4BR/AAysCABZW/AHwA=")); + return require("heatshrink").decompress(atob("2GwwkGIf4AfgMRkUiiIHCiMRiAMDAwYCCBAYVDAHMv/4ACkBIBAgPxBgM/BYXyAoICBCowA5gRADKQUDKAYMCmYCBiBXBCo4A5J4MxiMSKQUf+YBBBgSiBgc/kBXBBAMyCoK2CK/btCiUhfAJLCkBkDiMQgBXDCoUvNAJX+AAU/+MB/8wAQIAC+cQK5hoDgIEBBIQFEAYIPHBIgBBAQQIDBwZXSKIMxgJaBgEjmZYCmBXLgLBBkkAgUhiMxBIM0iMSCoMRkZECkQJEichBINDiETAgISBiQTDK6MvJAXzVIQrBBYMCK5E/K4kwGIJXFgdAMgQQBiYiCDgU0HQSlCgMikIEBEAMTDYJXQ+UikYDBj6nCAAMTWoJ6BK4oVEK4c0oQ+BK4MjAgMDJoJXHNYJXHBwa0BohcDY4QAKgJQE+LzBNwJVBkQMEkBXBCoyvFJAVAKISaBiMiHQRIDkVBoSyCK5CvBAgavNDAJAC+cQn5DCgSpBl4MDgBXBgCsBCoYoMLAKREgIKDBJIdKK5oA/AH4A/AH4A/ADUBIH4APiAFEi1mAGUADrkRKwUGK2ZXes1gK2xXfD8A3/K/4AWgxX/ACtga2AwIHLkAgCwvJw6RcDgIABK+w4cK/I4dsEGP5BXtSAQ6BV/5XSG4RX/K6Y3fK+42CK/5XTGwcGK/5XSVwY5cK+o1DAAayYsAhDsCv4K7BTBK4YeYK7CyFVzJXFFIpXtVwYiYK/rmZKYYDDELJXXG4YiaK/Y0aKgQAEK+gkdKt5XGKzqv5GTpX6ETlgK4xWrKTyxKVthXmAGRX/K/5X/AH5X/K/4gBAH4A/AFz/uAH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AHNggEGHfEAgAEHKyQXVK0qTCAggbUK+6SDAApzXK/5BRDYZX3KxBBSYqxXngyvaV25XEd4ZCSsAcBAoRZ2dQZXBLwgaQCIYeCAGirCS4YGCDSJXCC6ZaodYICBZzSw4S4I+XDgSv4K4rzCK/47RAQTMaWHI9YV3TscV3aVagByBK3SwCSqyt8AAQ+XK/4A/AH4A/AH4A3gAA/AH4AuZbdggwc3ADpX/K/5XxsEAgA+XK/o8BgBX/K64/WK/4/XK/5X/K/5XvgBX/K64cYHrw4CSTFggCuXK4oDCEQJXYDS6ScDgg4CPKyRCAAZX0HAgBDK+LlYK4oeBAwZ9aK+lgAoQGBgyvzDIIDBK66sCG4JXYCwIBDK7ADCK+xZCHwJXzGoQ8BK7DpBAAaSXSgRXZO4okCK+IaXV4oABEILSWSYjRCHSo3BDSxXEAAIcBAISvyKawcIAYIGCK/4cUH4YlaHS0AHgI1XOg5YBPrY6WHgRXfAGRXDHzBX8VoJX/K68ADjRX6sBX/K/5X/K8wdcK/UAG7B0iKzZYbK/BWDAH4A/hWpzWhIf4ASgOpzIAB0EAhhH/AB8ZzGJ1WazMA4pH/AB+pxOZxOpzVMqA2ugUzmcgD7cKVYOqzGqpnRFw8ykchK8kviEBmQFBgMiFocSCAcSkUQAgMikRsHhWqxOq0Ut4mqBw0DC4IxBD4wpBHAQMCA4cCGJIAFj8hDIQuBkMTCwU/AYQJBiUxFoPxiIVDK4kyxUz4cxl+KK5MfDQXyD4UCmMSmAEBAQQHDgMTmIxHAAqpBmaqCFwMDEYZRBgEjCQQBB+USK5E/ns/0Uzwc6K48ykYkCK4IfCc4I4CK4QHEBAYAMiICBmYuDmQEBh8iAgRXCLISvJO4MqwcklEiK5CADV4oaBV4oHEK6Eve4JNCbwRfCiMTFoMDkMRSAJXCD49azWp0UqzWayJXIQwcAO4cCkMCFIJOCA4XxK6KPBkR6DTwYyBAwYPEAggfFzORpWK1OZyAOHJ4QfERAUSEgQxIIIgAr1URWIOZzOgGtwAhgMZzWq1OaIv4ASKgOqzTkvAEmq1WgFtQA==")); } +function getRocketSequences() { + return { + 1: require("heatshrink").decompress(atob("qFGwkCkQAiiEBEkUgKQhPhE8ogCE8YhCiQoEE7pKEPIgncTQ4neEwpQCPoh1eJYYwCJ7QmHKAh1hZIpOjPAUBJ0ZQCTzEhExZ1lPAZ1kKDQmOJ65O2E65OPOy5O2E64mPOyxO/J2wnPJyx2QJ35O/J2khE0p2POq52PEy4nOiQnlOrEhiSfMJrEggQnLJzB1CPBQmZkInMEzBQDPBImbPBR1ZEoRMCZYImhgQgEE0BzFKAgmaDwLDFKAbqdYQwHBOrcgDgLBFJrsiiRNGYbpLBY4Ymhd4omkkUhE0pQEEwUBJjrHBd4QmCdzoiBDwYrCPLyZHF4QnagQeCE8UgJwYniJwgnIOzwfFO0wJCJzMQE4gyFEzR2FBQombkInDQI4AakAnBTYS+ZE5BMDE0LEES7YnLE0R3FAEQA=")), + 2: require("heatshrink").decompress(atob("qFGwkCkQAikMAgIliKYon/AA0gEAQniEwIhCAgYndEIjqBE8CaGKogmgKAp1fKAgncExBQBBQR1gKAp7BJ0IndExR4CE0idaOpYnbExqeYJxxPYEx0BJ0x2XExx2XJ20QE6xONJi5OPGwJOlBwLFkLoLFlBwJOkOwJOlE4JOkTjBOOE/52Pdi5OPEy7FnE5wmXE5xOZT5gmYEoMiiB1lgR4KTLAkDPBJ1WIAYDDKA4mWJwchDwYEDTjQiDJQh4GYLAhHFosSJy6OCTIxaEEywbBKYwjEEzMgUQxQFBogAURwZOGOjTKJdTYnOEryfHE0JQEfIpQgYQMAgJLeAgrtfTI4ndgSaFE4h0bdQkSZQpOfEAgIBO0AnEdrh2FJAb1EdbInEBIpObOwhOEEzYnFXzZ2HE4QlhE4QlDFMKcDYooniO0QnDT0YnCE0ciA")), + 3: require("heatshrink").decompress(atob("qFGwkEogAjiMUEkVAKYgnhPYolgOQIniOYZ4FOcLqBE8CaGKojpgKAomhEYUQE7gmHKAIxCE0QkCPYR1gZIgnZExR4CJ0idmE7ZONYzImNgEUJ0p3YJRh2ZJJwnXOpQhBdkpaETsMEGQhOhE7jFLUYpOfTzgmKE4hOiE4hOigEUJ0rvCEywnPEqx2OTjBOOE7ImOTsqeZE5zFYoJOmT5kBJzEAih4LdK5mBAQInKOqoYDEgR4JEypHDEYbxJOq5ABdgZ7CEzZOEJQgnGihOYEIzJFTionCKYxWGEy9ADAYnGUIYmWog/EdBFAEy7KIKAwnjKwLqWE5pMeT48CVQpQfgMjKEtEiAnfEQJQCgJSCTcB6FJzkEdYcUE8FAdQghDOzonKTjh2EZAidcDoInHJzodBOwx/BE8JxcOwsAOwQmhJgSXDObwnFEwUUO0LFGE8aeiE4YmiokQE0tE")), + 4: require("heatshrink").decompress(atob("qFGwkCkQAjiMSEkRTFE/4AGkMAgQCBE8MgEIYEDE7whDdQIngTQxVEE0ChFTjxQFE7jnFKAgxCOsBQFZgJ1gE7wmKPAROkTrTEHGAwnYiBHJFAaeXOoyXBEQZPac5AsFgJOhAoh2XJwwnFKoROdE4J9GJzwnIiQmVkInPAC0QE5AJFE64mHY5DFdE4SBEYr5JDJ0hKDJ0jCZJxoACgInmKLAmOTq5OOEy5OPTsxOYE5wmXO5wlYkAnMOqshiRNCgR4LOC8CkJCCEzxHDAgYnJOqpAEDoZ4HEyodDEQpQHdCsQOwwFHEyzoCPYzJGEy0gEwaZGA4acVEQSjHKAomXkQYEYAwlZeRKYDE8gjCYa7zJEwcCkImfKAb4FAD0hdTh4LgRSBOcR0CJz0gYYrrgN4QnEYrxOEE4bEeiAnGF4J2idL6VDE8ohBE0gnFE0J0BE4QGBiROgdIQABgJ2hJoTtjYgZSEE8ScgE4omikUQTcQADA=")), + 5: require("heatshrink").decompress(atob("qFGwkCkQAikMAgIliKYonhiAnjkEATIIniEwIhCAgYndEIhQFYUZVEE0BQFOr5QEeQQmiKAL1DOr5QEE7ROCDgZVEAoInZDwchFQQoDPAJOdEQYrBdrZFDOYwncEJDsDVIpOXgJxEE4pObEAgGFgJOaE48BaIhOZJ5ZObY5ROcE441CE6xOGPAwtCJzpGCJ0hHDkI1DJzwoEJzInLFg52dUo5O/J35OzE54mWOx4mXJxx1XE54mXkUhExkSJzCfMOrAlBPBiZXgQDBAQQmgJgh4JOqoYEFYwmaDoZzEFgh1YDgkiiAFEKAroXJJAGFiQmVkCNDTIz5EJy57HKAomXkQYEJoqaYeRadEJrAnJEQUAgJPiAoYmeT4cCkAnBE0BKCJkT1EkDCeJYYiDOkLDFFL5wBE4guCPDhEBEwQiDY70CkInDiQnCJzkhOwhKDdzp2Idb4nEE0B0Bdo4niE0J0CeYhOhgESUYYnidsgnEE0KeCE0gnDE0ciA")), + 6: require("heatshrink").decompress(atob("qFGwkCkQA/ABEgKQZPhEwgABEsAoGJkBxBE8JKEAowAbJIhQEgLDiPooAdKA4ncTZAndSwhQEFoInaJQkSKAwlZdgwnfSgYADE4h1ZDwInlcggnIOzAdCE8i7EY5J3XDgYhGd4pOZEI52bSYwGCOAJ2bYIodEOzZOFFAjFcEwwAIE6xOHABBO/J34ndEyx2PJ00BJ00SJ0p1XE54mXOxxO/J5wmYgQnMOrB2BPBgkWiJ1CPBbBYAYR4KiTAXRwIrFTjgZDJYZ4IEyoiEIwrDcEJJQFOqwiBDARxFFwgmXkAYDEogsBF4QmXEQJ7GUYYkBEzDKJAgYmdEQbKFEzonEKYgngJwgmfZggmjKQghgiBRGkBzeTgUikJRgc47LDErTnDEAkQJzkCJwYnEJzonEJIaddOwhJEJzgdBE4hYEJzieJADgnEE0KUCXzoAGkJLEiB2hOgQDBT0TsDT0YmlE4YmjkQ=")), + 7: require("heatshrink").decompress(atob("qFGwkCkQAhkIpBiQlhkBSEJ8InlEIIoFE7whEE8pQFE7giBJQoneI4MCTYhQDE7YdCYYondEQYnEPwZ1bE5BQCJzonHkR2ZEAkBE4pNBE7zHFYrYhFUgonaXAQeEEwruZEYcgiROHJ7AfDAwxOeAAURiAmHE65HIOzwmOJ35OPE6xOPO35O/J35O/J1gnPEyx2PEy5OOOq5OnE5xOYO5omZgJQMJrQnLiQnagR4JOq5nCDgZ1fEYRLDE5DoZkUQNoZ4GOrJKGAoomXOw7lCAwYmYDgJSEAAUBA4QDBJzB6FOQrDXJwTJFdLjJKE9jDYZRAmkKAwmhKAgmiKAYmBkApdJIgjCKYIncOQYvJYTovGE84lagR2DE4xOakBOEgJXFOjYnEJAbtdOwggEkAmbDgInDE0B0BE4QgcE5AkiXYbpCOLonGYo4nhPMYnCUEgnBY0kiA==")), + 8: require("heatshrink").decompress(atob("qFGwkCkQA/ABBSEJ8MgE4kBEsBPFE7xMCOIJ3hOYgFEE7rCGE70gE4pQBiAndYQwjBUohOZD4ZQFE7YkBE5AICYbZ2GE7sggJRCAA8iYzZOITroALE7EhExh4CAC0QExpPXOponZExx2XJ24nWdh52XdhzF/Yu5O/J35O0E55OXOx5O/J2omXE5x1XO54mYgQnMJrR4LOrciiAmiJgR4KEzIjDPBAlYiAiEeI51YkEBE4J5CD4KceTQQcBJgRQFdTZDCJIjDcNIqhGdTQmCkByFTTInDKgoAEE7ZEEJwhPdE1R1FE0InEE0R3DEwTGcDwomEE7hKFPYqafE8ROCE5DJbE5B/IEqh2ED4gnCJrMCJwgnEiB2bE4qeFEzUggQmIBQLEaEQImHLIImaE4YfcOw4lEFMLECS7onJO8wmkE4QljAAIA==")), + }; +} +let rocketSequence = 1; +let settings = storage.readJSON("cassioWatch.settings.json", true) || {}; +let rocketSpeed = settings.rocketSpeed || 700; +delete settings; // schedule a draw for the next minute let rocketInterval; var drawTimeout; function queueDraw() { - if (drawTimeout) clearTimeout(drawTimeout); - drawTimeout = setTimeout(function() { - drawTimeout = undefined; - draw(); - }, 60000 - (Date.now() % 60000)); + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); } function clearIntervals() { - if (rocketInterval) clearInterval(rocketInterval); - rocketInterval = undefined; - if (drawTimeout) clearTimeout(drawTimeout); - drawTimeout = undefined; + if (rocketInterval) clearInterval(rocketInterval); + rocketInterval = undefined; + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; } -//////////////////////////////////////////// -// TIMER FUNC -// -var timer_time = 0; -var alreadyListenTouch = false; -function initTouchTimer () { - if (alreadyListenTouch) return; - alreadyListenTouch = true; - - Bangle.on('swipe', function(dirX,dirY) { - if (canTouch === false) return; - var njson = getDataJson(); - if (!njson) return; - - if (dirX === -1) { - timer_time = 0; - delete njson.timer; - setDataJson(njson); - } - else if (dirX === 1) { - var now = new Date().getTime(); - njson.timer = now + (timer_time * 1000 * 60); - Bangle.setLocked(true); - setDataJson(njson); - Bangle.buzz(200, 0); - timer_time = 0; - } - else if (dirY === -1) { - if (canTouch === false || njson.timer) return; - timer_time = timer_time + 5; - } - else if (dirY === 1) { - if (canTouch === false || njson.timer) return; - timer_time = timer_time - 5; - } - draw(); - }); -} -setTimeout(() => { - initTouchTimer (); -}); - -function getTimerTime() { - // if timer_time !== -1, take it - if (timer_time !== 0) { - return timer_time + "m"; - } else { - // else, show diff between njsontime and now - var njson = getDataJson(); - if (!njson) return false; - var now = new Date().getTime(); - var diff = Math.round((njson.timer - now) / (1000 * 60)); - //console.log(123, njson, diff, now, njson.timer - now); - if (diff > 0) return diff + "m"; - else if (njson.timer) { - Bangle.buzz(1000, 1); - console.log("END OF TIMER"); - delete njson.timer; - setDataJson(njson); - return false; - } else { - return false; - } - // if diff is <0, delete timer from json - } -} -function drawTimer() { - //g.drawString(getTimerTime(), 100, 100); - g.setFont("8x12", 2); - var t = 97; - var l = 105; - var time = getTimerTime(); - if (time || timer_time !== 0) g.drawString(time, l+5, t+0); - if (time && timer_time === 0) g.drawImage(getClockBg(), l-20, t+2, { scale: 1 }); -} - - -//////////////////////////////////////////// -// DATA READING -// -function getDataJson(){ - var res = {"tasks":"", "weather":[]}; - try { - res = storage.readJSON('advcasio.data.json'); - } catch(ex) { - return res; - } - return res; -} -function setDataJson(resJson){ - try { - res = storage.writeJSON('advcasio.data.json', resJson); - } catch(ex) { - return res; - } - return res; -} -var dataJson = getDataJson(); - -//////////////////////////////////////////// -// WEATHER! -// -function drawWeather(arr) { - g.setFont("6x8", 1); - var p = {l: 8, tText: 40, tIcon:20, decal:25}; - var today = new Date().getTime(); - var yesterday = today - (1000 * 60 * 60 * 24); - var testday = today + (1000 * 60 * 60 * 24 * 2); - //12h auj > 12h hier qui est sup a 0h auj - //23h59 hier est sup a 0h auj - var j = 0; - for(var i = 0; i yesterday && j < 4) { - g.drawString(arr[i][0], p.l + p.decal*j + 4, p.tText); - g.drawImage(iconsWeather[arr[i][1]], p.l + p.decal*j, p.tIcon, { scale: 1 }); - j++ - } - } -} - - -//////////////////////////////////////////// -// DRAWING FUNCS -// -function drawTasks(str) { - g.setFont("6x8", 1); - var t = 57; - var l = 0; - g.drawString(str, l+5, t+0); -} - -function drawSteps() { - g.setFont("8x12", 2); - var t = 132; - var l = 150; - g.drawString(getSteps(), l+5, t+0); -} - - function drawClock() { - g.setFont("7x11Numeric7Seg", 3); - g.clearRect(80, 57, 170, 96); - g.setColor(255, 255, 255); - var l = 77; - var t = 57; - var w = 170; - var h = 116; - g.drawRect(l, t, w, h); - g.fillRect(l, t, w, h); - g.setColor(0, 0, 0); - g.drawString(require("locale").time(new Date(), 1), 76, 60); - - // day - //g.setFont("8x12", 1); - //g.setFont("9x18", 1); - //g.drawString(require("locale").dow(new Date(), 2).toUpperCase(), 25, 136); - g.setFont("8x12", 2); - g.drawString(require("locale").dow(new Date(), 2), 18, 130); - - // month - g.setFont("8x12"); - g.drawString(require("locale").month(new Date(), 2).toUpperCase(), 80, 127); - - // day nb - g.setFont("8x12", 2); - const time = new Date().getDate(); - g.drawString(time < 10 ? "0" + time : time, 78, 137); + g.setFont("7x11Numeric7Seg", 3); + g.clearRect(80, 57, 170, 96); + g.setColor(0, 255, 255); + g.drawRect(80, 57, 170, 96); + g.fillRect(80, 57, 170, 96); + g.setColor(0, 0, 0); + g.drawString(require("locale").time(new Date(), 1), 70, 60); + g.setFont("8x12", 2); + g.drawString(require("locale").dow(new Date(), 2).toUpperCase(), 18, 130); + g.setFont("8x12"); + g.drawString(require("locale").month(new Date(), 2).toUpperCase(), 80, 126); + g.setFont("8x12", 2); + const time = new Date().getDate(); + g.drawString(time < 10 ? "0" + time : time, 78, 137); } function drawBattery() { - bigThenSmall(E.getBattery(), "%", 140, 23); + bigThenSmall(E.getBattery(), "%", 135, 21); } +function drawRocket() { + let Rocket = getRocketSequences(); + g.clearRect(5, 62, 63, 115); + g.setColor(0, 255, 255); + g.drawRect(5, 62, 63, 115); + g.fillRect(5, 62, 63, 115); + g.drawImage(Rocket[rocketSequence], 5, 65, { scale: 0.7 }); + g.setColor(0, 0, 0); + rocketSequence = rocketSequence + 1; + if(rocketSequence > 8) rocketSequence = 1; +} + +function getTemperature(){ + try { + var weatherJson = storage.readJSON('weather.json'); + var weather = weatherJson.weather; + return Math.round(weather.temp-273.15); + + } catch(ex) { + print(ex) + return "?" + } +} function getSteps() { - var steps = 0; - try{ - if (WIDGETS.wpedom !== undefined) { - steps = WIDGETS.wpedom.getSteps(); - } else if (WIDGETS.activepedom !== undefined) { - steps = WIDGETS.activepedom.getSteps(); - } else { - steps = Bangle.getHealthStatus("day").steps; - } - } catch(ex) { - // In case we failed, we can only show 0 steps. - return "? k"; - } - - steps = Math.round(steps/1000); - return steps + "k"; + var steps = Bangle.getHealthStatus("day").steps; + steps = Math.round(steps/1000); + return steps + "k"; } - function draw() { - - queueDraw(); + queueDraw(); - g.reset(); - g.clear(); - g.setColor(255, 255, 255); - g.fillRect(0, 0, g.getWidth(), g.getHeight()); - let background = getBackgroundImage(); - g.drawImage(background, 0, 0, { scale: 1 }); - - - g.setColor(0, 0, 0); - g.setFont("6x12"); - if(dataJson && dataJson.weather) drawWeather(dataJson.weather); - if(dataJson && dataJson.tasks) drawTasks(dataJson.tasks); - + g.clear(1); + g.setColor(0, 255, 255); + g.fillRect(0, 0, g.getWidth(), g.getHeight()); + let background = getBackgroundImage(); + g.drawImage(background, 0, 0, { scale: 1 }); + g.setColor(0, 0, 0); + g.setFont("6x12"); + g.drawString("Launching Process", 30, 20); + g.setFont("8x12"); + g.drawString("ACTIVATE", 40, 35); - g.setFontAlign(0,-1); - g.setFont("8x12", 2); + g.setFontAlign(0,-1); + g.setFont("8x12", 2); + g.drawString(getTemperature(), 155, 132); + g.drawString(Math.round(Bangle.getHealthStatus("last").bpm), 109, 98); + g.drawString(getSteps(), 158, 98); - drawSteps(); - g.setFontAlign(-1,-1); - drawClock(); - drawBattery(); - drawTimer(); - // Hide widgets - for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} + g.setFontAlign(-1,-1); + drawClock(); + drawRocket(); + drawBattery(); + + // Hide widgets + for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} } -// save batt power, does not seem to work although... -var canTouch = true; Bangle.on("lcdPower", (on) => { - if (on) { - draw(); - } else { - canTouch = false; - clearIntervals(); - } + if (on) { + draw(); + } else { + clearIntervals(); + } }); Bangle.on("lock", (locked) => { - clearIntervals(); - draw(); - if (!locked) { - canTouch = true; - } else { - canTouch = false; - } + clearIntervals(); + draw(); + if (!locked) { + rocketInterval = setInterval(drawRocket, rocketSpeed); + } }); +Bangle.setUI("clock"); // Load widgets, but don't show them Bangle.loadWidgets(); -Bangle.setUI("clock"); - -g.reset(); -g.clear(); +require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe +g.clear(1); draw(); diff --git a/apps/advcasio/metadata.json b/apps/advcasio/metadata.json index 0f0c75c07..25dc1243a 100644 --- a/apps/advcasio/metadata.json +++ b/apps/advcasio/metadata.json @@ -1,7 +1,7 @@ { "id": "advcasio", "name": "Advanced Casio Clock", "shortName":"advcasio", - "version":"0.01", + "version":"0.04", "description": "An over-engineered clock inspired by Casio watches. It has a 4 days weather, a timer using swipe and a scratchpad. Can be updated using a dedicated webapp.", "icon": "app.png", "tags": "clock", @@ -12,7 +12,7 @@ { "url": "screenshot-clock-3.jpg" }, { "url": "screenshot-webapp.jpg" } ], - "supports" : ["BANGLEJS", "BANGLEJS2"], + "supports" : ["BANGLEJS", "BANGLEJS2"], "readme": "README.md", "allow_emulator":true, "storage": [ diff --git a/apps/agenda/ChangeLog b/apps/agenda/ChangeLog index 56dfffa0d..77e11c92e 100644 --- a/apps/agenda/ChangeLog +++ b/apps/agenda/ChangeLog @@ -1 +1,11 @@ 0.01: Basic agenda with events from GB +0.02: Added settings page to force calendar sync +0.03: Disable past events display from settings +0.04: Added awareness of allDay field +0.05: Displaying calendar colour and name +0.06: Added clkinfo for clocks. +0.07: Clkinfo improvements. +0.08: Fix error in clkinfo (didn't require Storage & locale) + Fix clkinfo icon +0.09: Ensure Agenda supplies an image for clkinfo items +0.10: Update clock_info to avoid a redraw diff --git a/apps/agenda/README.md b/apps/agenda/README.md index a546e0a89..1a0ec9264 100644 --- a/apps/agenda/README.md +++ b/apps/agenda/README.md @@ -1,3 +1,30 @@ # Agenda -Basic agenda reading the events synchronised from GadgetBridge +Basic agenda reading the events synchronised from GadgetBridge. + +### Functionalities + +* List all events in the next week (or whatever is synchronized) +* Optionally view past events (until GB removes them) +* Show start time and location of the events in the list +* Show the colour of the calendar in the list +* Display description, location and calendar name after tapping on events + +### Troubleshooting + +For the events sync to work, GadgetBridge needs to have the calendar permission and calendar sync should be enabled in the devices settings (gear sign in GB, also check the blacklisted calendars there, if events are missing). +Keep in mind that GadgetBridge won't synchronize all events on your calendar, just the ones in a time window of 7 days (you don't want your watch to explode), ideally every day old events get deleted since they appear out of such window. + +#### Force Sync + +If for any reason events still cannot sync or some are missing, you can try any of the following (just one, you normally don't need to do this): +1. from GB open the burger menu (side), tap debug and set time. +2. from the bangle, open settings > apps > agenda > Force calendar sync, then select not to delete the local events (this is equivalent to option 1). +3. do like option 2 but delete events, GB will synchronize a fresh database instead of patching the old one (good in case you somehow cannot get rid of older events) + +After any of the options, you may need to disconnect/force close Gadgetbridge before reconnecting and let it sync (give it some time for that too), restart the agenda app on the bangle after a while to see the changes. + +### Report a bug + +You can easily open an issue in the espruino repo, but I won't be notified and it might take time. +If you want a (hopefully) quicker response, just report [on my fork](https://github.com/glemco/BangleApps). diff --git a/apps/agenda/agenda.clkinfo.js b/apps/agenda/agenda.clkinfo.js new file mode 100644 index 000000000..7c89446a2 --- /dev/null +++ b/apps/agenda/agenda.clkinfo.js @@ -0,0 +1,29 @@ +(function() { + var agendaItems = { + name: "Agenda", + img: atob("GBiBAAAAAAAAAADGMA///w///wf//wAAAA///w///w///w///x///h///h///j///D///X//+f//8wAABwAADw///w///wf//gAAAA=="), + items: [] + }; + var locale = require("locale"); + var now = new Date(); + var agenda = require("Storage").readJSON("android.calendar.json") + .filter(ev=>ev.timestamp + ev.durationInSeconds > now/1000) + .sort((a,b)=>a.timestamp - b.timestamp); + + agenda.forEach((entry, i) => { + + var title = entry.title.slice(0,12); + var date = new Date(entry.timestamp*1000); + var dateStr = locale.date(date).replace(/\d\d\d\d/,""); + dateStr += entry.durationInSeconds < 86400 ? "/ " + locale.time(date,1) : ""; + + agendaItems.items.push({ + name: "Agenda "+i, + get: () => ({ text: title + "\n" + dateStr, img: agendaItems.img }), + show: function() {}, + hide: function () {} + }); + }); + + return agendaItems; +}) diff --git a/apps/agenda/agenda.js b/apps/agenda/agenda.js index f39e31c75..9cffe0265 100644 --- a/apps/agenda/agenda.js +++ b/apps/agenda/agenda.js @@ -6,6 +6,8 @@ title, description, location, + color:int, + calName, allDay: bool, } */ @@ -24,19 +26,23 @@ var fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4"; //FIXME maybe write the end from GB already? Not durationInSeconds here (or do while receiving?) var CALENDAR = require("Storage").readJSON("android.calendar.json",true)||[]; +var settings = require("Storage").readJSON("agenda.settings.json",true)||{}; -CALENDAR=CALENDAR.sort((a,b)=>a.timestamp - b.timestamp) +CALENDAR=CALENDAR.sort((a,b)=>a.timestamp - b.timestamp); function getDate(timestamp) { return new Date(timestamp*1000); } -function formatDateLong(date, includeDay) { - if(includeDay) - return Locale.date(date)+" "+Locale.time(date,1); - return Locale.time(date,1); +function formatDateLong(date, includeDay, allDay) { + let shortTime = Locale.time(date,1)+Locale.meridian(date); + if(allDay) shortTime = ""; + if(includeDay || allDay) + return Locale.date(date)+" "+shortTime; + return shortTime; } -function formatDateShort(date) { - return Locale.date(date).replace(/\d\d\d\d/,"")+Locale.time(date,1); +function formatDateShort(date, allDay) { + return Locale.date(date).replace(/\d\d\d\d/,"")+(allDay? + "" : Locale.time(date,1)+Locale.meridian(date)); } var lines = []; @@ -45,7 +51,7 @@ function showEvent(ev) { if(!ev) return; g.setFont(bodyFont); //var lines = []; - if (ev.title) lines = g.wrapString(ev.title, g.getWidth()-10) + if (ev.title) lines = g.wrapString(ev.title, g.getWidth()-10); var titleCnt = lines.length; var start = getDate(ev.timestamp); var end = getDate((+ev.timestamp) + (+ev.durationInSeconds)); @@ -53,22 +59,24 @@ function showEvent(ev) { if (titleCnt) lines.push(""); // add blank line after title if(start.getDay() == end.getDay() && start.getMonth() == end.getMonth()) includeDay = false; - if(includeDay) { + if(includeDay || ev.allDay) { lines = lines.concat( /*LANG*/"Start:", - g.wrapString(formatDateLong(start, includeDay), g.getWidth()-10), + g.wrapString(formatDateLong(start, includeDay, ev.allDay), g.getWidth()-10), /*LANG*/"End:", - g.wrapString(formatDateLong(end, includeDay), g.getWidth()-10)); + g.wrapString(formatDateLong(end, includeDay, ev.allDay), g.getWidth()-10)); } else { lines = lines.concat( g.wrapString(Locale.date(start), g.getWidth()-10), - g.wrapString(/*LANG*/"Start"+": "+formatDateLong(start, includeDay), g.getWidth()-10), - g.wrapString(/*LANG*/"End"+": "+formatDateLong(end, includeDay), g.getWidth()-10)); + g.wrapString(/*LANG*/"Start"+": "+formatDateLong(start, includeDay, ev.allDay), g.getWidth()-10), + g.wrapString(/*LANG*/"End"+": "+formatDateLong(end, includeDay, ev.allDay), g.getWidth()-10)); } if(ev.location) lines = lines.concat(/*LANG*/"Location"+": ", g.wrapString(ev.location, g.getWidth()-10)); if(ev.description) lines = lines.concat("",g.wrapString(ev.description, g.getWidth()-10)); + if(ev.calName) + lines = lines.concat(/*LANG*/"Calendar"+": ", g.wrapString(ev.calName, g.getWidth()-10)); lines = lines.concat(["",/*LANG*/"< Back"]); E.showScroller({ h : g.getFontHeight(), // height of each menu item in pixels @@ -89,6 +97,12 @@ function showEvent(ev) { } function showList() { + //it might take time for GB to delete old events, decide whether to show them grayed out or hide entirely + if(!settings.pastEvents) { + let now = new Date(); + //TODO add threshold here? + CALENDAR = CALENDAR.filter(ev=>ev.timestamp + ev.durationInSeconds > now/1000); + } if(CALENDAR.length == 0) { E.showMessage("No events"); return; @@ -101,24 +115,21 @@ function showList() { g.setColor(g.theme.fg); g.clearRect(r.x,r.y,r.x+r.w, r.y+r.h); if (!ev) return; - var isPast = ev.timestamp + ev.durationInSeconds < (new Date())/1000; + var isPast = false; var x = r.x+2, title = ev.title; - var body = formatDateShort(getDate(ev.timestamp))+"\n"+ev.location; - var m = ev.title+"\n"+ev.location, longBody=false; + var body = formatDateShort(getDate(ev.timestamp),ev.allDay)+"\n"+(ev.location?ev.location:/*LANG*/"No location"); + if(settings.pastEvents) isPast = ev.timestamp + ev.durationInSeconds < (new Date())/1000; if (title) g.setFontAlign(-1,-1).setFont(fontBig) - .setColor(isPast ? "#888" : g.theme.fg).drawString(title, x,r.y+2); + .setColor(isPast ? "#888" : g.theme.fg).drawString(title, x+4,r.y+2); if (body) { g.setFontAlign(-1,-1).setFont(fontMedium).setColor(isPast ? "#888" : g.theme.fg); - var l = g.wrapString(body, r.w-(x+14)); - if (l.length>3) { - l = l.slice(0,3); - l[l.length-1]+="..."; - } - longBody = l.length>2; - g.drawString(l.join("\n"), x+10,r.y+20); + g.drawString(body, x+10,r.y+20); } - //if (!longBody && msg.src) g.setFontAlign(1,1).setFont("6x8").drawString(msg.src, r.x+r.w-2, r.y+r.h-2); g.setColor("#888").fillRect(r.x,r.y+r.h-1,r.x+r.w-1,r.y+r.h-1); // dividing line between items + if(ev.color) { + g.setColor("#"+(0x1000000+Number(ev.color)).toString(16).padStart(6,"0")); + g.fillRect(r.x,r.y+4,r.x+3, r.y+r.h-4); + } }, select : idx => showEvent(CALENDAR[idx]), back : () => load() diff --git a/apps/agenda/metadata.json b/apps/agenda/metadata.json index ce8438686..8253b36bc 100644 --- a/apps/agenda/metadata.json +++ b/apps/agenda/metadata.json @@ -1,17 +1,19 @@ { "id": "agenda", "name": "Agenda", - "version": "0.02", + "version": "0.10", "description": "Simple agenda", "icon": "agenda.png", "screenshots": [{"url":"screenshot_agenda_overview.png"}, {"url":"screenshot_agenda_event1.png"}, {"url":"screenshot_agenda_event2.png"}], - "tags": "agenda", + "tags": "agenda,clkinfo", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "allow_emulator": true, "storage": [ {"name":"agenda.app.js","url":"agenda.js"}, {"name":"agenda.settings.js","url":"settings.js"}, + {"name":"agenda.clkinfo.js","url":"agenda.clkinfo.js"}, {"name":"agenda.img","url":"agenda-icon.js","evaluate":true} - ] + ], + "data": [{"name":"agenda.settings.json"}] } diff --git a/apps/agenda/settings.js b/apps/agenda/settings.js index fe9dab2d8..4220fcb63 100644 --- a/apps/agenda/settings.js +++ b/apps/agenda/settings.js @@ -3,6 +3,10 @@ Bluetooth.println(""); Bluetooth.println(JSON.stringify(message)); } + var settings = require("Storage").readJSON("agenda.settings.json",1)||{}; + function updateSettings() { + require("Storage").writeJSON("agenda.settings.json", settings); + } var CALENDAR = require("Storage").readJSON("android.calendar.json",true)||[]; var mainmenu = { "" : { "title" : "Agenda" }, @@ -32,6 +36,13 @@ E.showAlert(/*LANG*/"You are not connected").then(()=>E.showMenu(mainmenu)); } }, + /*LANG*/"Show past events" : { + value : !!settings.pastEvents, + onchange: v => { + settings.pastEvents = v; + updateSettings(); + } + }, }; E.showMenu(mainmenu); }) diff --git a/apps/agpsdata/ChangeLog b/apps/agpsdata/ChangeLog index c17eac852..8ada244d7 100644 --- a/apps/agpsdata/ChangeLog +++ b/apps/agpsdata/ChangeLog @@ -1 +1,5 @@ 0.01: First, proof of concept +0.02: Load AGPS data on app start and automatically in background +0.03: Do not load AGPS data on boot + Increase minimum interval to 6 hours +0.04: Write AGPS data chunks with delay to improve reliability diff --git a/apps/agpsdata/README.md b/apps/agpsdata/README.md index 93cc94259..57bb055a1 100644 --- a/apps/agpsdata/README.md +++ b/apps/agpsdata/README.md @@ -1,18 +1,19 @@ # A-GPS Data -Load assisted GPS data directly to the watch using the new http requests on Android GadgetBridge. +Load assisted GPS (A-GPS) data directly to your Bangle.js using the new http requests on Android GadgetBridge. + +Will download A-GPS data in background (if enabled in settings). + +The GNSS type can be configured in the settings. Make sure: * your GadgetBridge version supports http requests * turn on internet access in GadgetBridge settings -Currently proof of concept on Bangle2 only. Will eventually add a widget for automatic download. - -![](screenshot.png) -![](screenshot2.png) -![](screenshot3.png) -![](screenshot4.png) -![](screenshot5.png) +Currently proof of concept on Bangle.js 2 only. ## Creator [@pidajo](https://github.com/pidajo) + +## Contributor +[@myxor](https://github.com/myxor) diff --git a/apps/agpsdata/app.js b/apps/agpsdata/app.js index 825eda273..4a6d2ba5c 100644 --- a/apps/agpsdata/app.js +++ b/apps/agpsdata/app.js @@ -1,125 +1,54 @@ -var _GB = global.GB; -var counter = 0; - -function GB(msg) { - console.log(msg); - if (msg.t == "http") { - display("Received", "(" + msg.resp.length + ") Touch to apply", () => { - display("Apply data..", ""); - setTimeout(() => { - if (setAGPS(msg.resp)) { - display("Success", "Touch for restart", httpTest); - } - else { - display("Error", "Touch for restart", httpTest); - } - }, 1); - }); - } - if (_GB) { - _GB(msg); - } -} - -function setAGPS(data) { - var js = jsFromBase64(data); - console.log(js); - try { - eval(js); - return true; - } - catch(e) { - console.log("Error:", e); - } - return false; -} - -function jsFromBase64(b64) { - var bin = atob(b64); - var chunkSize = 128; - var js = "Bangle.setGPSPower(1);\n"; // turn GPS on - var gnss_select="1"; - js += `Serial1.println("${CASIC_CHECKSUM("$PCAS04,"+gnss_select)}")\n`; // set GNSS mode - // What about: - // NAV-TIMEUTC (0x01 0x10) - // NAV-PV (0x01 0x03) - // or AGPS.zip uses AID-INI (0x0B 0x01) - - for (var i=0;i { - display("Request...", "Touch for restart", httpTest); - if (Bluetooth.println) { - console.log("On device"); - Bluetooth.println(JSON.stringify({t:"info", msg:"HTTP Request"})); - Bluetooth.println(JSON.stringify({t:"http", url:"https://www.espruino.com/agps/casic.base64"})); - } - else { - console.log("Testing on Emulator"); - setTimeout(() => { - GB({t:"http", resp:testData}); - }, 1); - } - }); -} - -var nextStep = null; - -Bangle.on("touch", () => { - if (nextStep) { - nextStep(); - } -}); - -httpTest(); - // Show launcher when middle button pressed // Load widgets Bangle.loadWidgets(); Bangle.drawWidgets(); +let waiting = false; -/* -require("Storage").write("httptest.info",{ - "id":"httptest", - "name":"Http Test", - "src":"httptest.js", - "icon":"wristlight.img" -}); -*/ +function start() { + g.reset(); + g.clear(); + waiting = false; + display("Retry?", "touch to retry"); + Bangle.on("touch", () => { updateAgps(); }); +} -var testData = "QUdOU1MgZGF0YSBmcm9tIENBU0lDLgpEYXRhTGVuZ3RoOiAyNTk4LgpMaW1pdGF0aW9uOiAzLzEwMDAuCrrOSAAIB7YdxSr+Sg2h8NYlBux1jiUgQbrXgJk/KJvFZVv8pP//uy3i/PH6rv9EMQH6SwBfAOxepgDsXgAAlCULALv/AAtCAAAAAQMAALQ7kly6zkgACAdBzVam9HANoXGycgoqGmnG5X9h3mKrWicvBKhXAp7//+00U/9j/jP/SDHM/Vn/JADrXqYA614AAF6d6v8DAADaEAAAAAIDAADKmrVTus5IAAgHTUirJrjvDKHJDjACcmXJJ+8Lv6rw5LQnl4OChUCt//9XKG3/+u6ZE84ZQuwDAMf/7F6mAOxeAADa0Pb/mP8ABDUAAAADAwAA4pBeVLrOSAAIB5291DTIzAyhJGfzAJ7pCIcIUQMgcfEoJ2TIjrHkqv//YjDTCKj/wRPdGIz/8/9NAOxepgDsXgAAl9/6/yQAAPbhAAAABAMAAIJ7sXC6zkgACAeKKDOgmwEOocKrFwP8Jmgqq4lOQ1VtLSfEi8yDVqn//5MskP6E7WQRPxzv6vv/0//sXqYA7F4AAM4w/f/0/wDoJwAAAAUDAABcUW5Hus5IAAgHu+Va48nxDaFaw0UBkVc73Y3FB+HFmDgoUWIPW+Ck//+iLcf9X/t5/ikzgPrT/wgA7F6mAOxeAAADVgsAiQAACB0AAAAGAwAAvsu9zbrOSAAIB0OVp/7+JQ2hFANPCF+F6KOOMwe9/nC5JsX0CtthqP//WzhzADr/dgqbIRj/nwDj/+xepgDsXgAAP4oKAPv/AOg4AAAABwMAAM4qVwS6zkgACAey9J9b+zwOofLIzwObDg0HLdEmMOA3PydWaUQvr6b//0wxwf/7EJ8K/yLREhkANADsXqYA7F4AALug/f/y/wALLAAAAAgDAACs6Ue+us5IAAgHm7NJLLhaDKEumRQBAFtVTExfuke3AeEmNg9cr2Cq//92MTIJm/63FCkXPv4gABgA616mAOteAACQQfX/HgAAAzUAAAAJAwAAfmebX7rOSAAIB9fgVnnchw2hNlTrAyWnJ5rnBMWFV9GyJzPfZYV8rf//Oyh2AA3xmhLdGtXu/f/Z/+xepgDsXgAA8gXx/37/AAU/AAAACgMAAPbBtfm6zkgACAc+F7Ct97wMoVEVPQCJJG1yeakXMm80PSet+BBd+aH//5AzPf2J+uX97jG7+fj/DgDsXqYA7F4AAGqE//8WAADufQIAAAsDAADELmhius5IAAgHW3g6rwRJDqFpPmYEPf8lNRy9lKO/IX8nJPRjCLOt//90Lir7QQcEGFYUTAguAA4A7F6mAOxeAADrZfj/zP8A5SsAAAAMAwAA/vB8ZbrOSAAIB1mVSsfiXw2hUX8RA60JSyUgLkEgC910JykTq7Usqv//8S9rBw//HhIpGyT/+v8fAOxepgDsXgAAitgKAD4AAOcpAAAADQMAAPoqnZW6zkgACAcCLzz8Q1ANocBvBQFuUWqAxVSgoRjR0SaS5AkH3qr//7cx3vlcB2AYPROjCOr/vf/sXqYA7F4AAA5Y/P/7/wDvGwMAAA4DAABMXoD/us5IAAgH+RiyseCLDKGnOjkHATiXLOud6AnbGuclr2roqg2l///FNxcHi/0hFLoW4fyj/10A7F6mAOxeAAANRf7/GgAA6TQAAAAPAwAAOjJsarrOSAAIB1/+xFM3Xg2hVDKBBg6Tsx25u5hYROV9J/QyJQmLrf//zC1e+7QGxRfmFOAHhf+s/+xepgDsXgAAaE/v/+j/AOonAAAAEAMAAAb9ka66zkgACAc74z4AUZEMofLN6wbbUEjD/w54MWPC3SfOFa4yQ6f//4wtrwH5EOwKOCRTFLz/UP/sXqYA7F4AAOaAFAApAADoOQAAABEDAAC+xoUHus5IAAgH1yXSbYfZDaFOrzwBIM5keona3uYD8JYnC6ekWw+l//8JMC/9ivsaAGEwM/ssAN//7F6mAOxeAAAymwQAof8A7l8AAAASAwAA9kus4rrOSAAIB/9znedCsA2h5VDBBLdHG1Uw8P6P93bRJw5UgTR9qf//LS1BAj0TAwkqJioWBABHAOxepgDsXgAAD54FACwAAN6xAAAAEwMAAEboQta6zkgACAdVJvSzetsMoRclcgKU4/OAvUl5A73wdCYbpBB/P6X//08yQ/4N7voNgx5160gAFwDsXqYA7F4AADa+EADk/wDuLwAAABQDAADyTPBuus5IAAgHhpZXHJnuDaGfsmkMbSLS2QeTnDZBLR8ntwGPV8mj//+SM6n8rftj/EUyZfw7AaX/7F6mAOxeAAAvSQUAAAAA6j4AAAAVAwAAVC23P7rOSAAIB8FSSGuHmw2hXoTeBoU+tLS9TdsrYGopJ+h3h7O9p///mjEIB3X/GhN5GXP/c//V/+xepgDsXgAASREJADgAAO4rAAAAFgMAAMqlmN26zkgACAeGsPJwF8ENoU2cJwHhxiN62PG7uVyKfydPWVyEG6z//8spSgCQ8NkRnxsl7sr/EQDsXqYA7F4AAI0S///u/wDudQEAABcDAABUYe3ous5IAAgHtHJyvWVdDaFr1mwGwPVWIZcaxOQXwAwmeHqW1+Sh//+PPnAAQgAOCxwhof8sAGwA7F6mAOxeAAAhMQcAtf8ABjsAAAAYAwAAsOXsgbrOSAAIB4nxObhoSQ2hOjBcBf2n5ijflOaX/Iz8JpPiNAUTrP//ajEL++oEchfzE9AFSgDT/+tepgDrXgAAohMLACkAAAweAAAAGQMAAFrje3e6zkgACAexAdJ/MyYOoeXvjwPazb0PcXcXfIVaNCZ2mjMDkqn//z02W/qPBMcW7BM7BcX/6//sXqYA7F4AABv4BgAVAAAPIgAAABoDAACqA6wGus5IAAgHxYz/b8dNDaH6/WQF3AILHLKDgTJ+VponRocZMKSm//8bLycAMRANDG8i/RHR/2wA7F6mAOxeAAArEwcAHAAABEgAAQAbAwAA0hkH57rOSAAIB5HXkJcOjA2h8B4kAebzvl2gmkU1K1TzJ86wODP6qP//0CzCAM4OmQrkI1UR7f/n/+xepgDsXgAAcs/u/9//AOplAAAAHQMAAGqvKTa6zkgACAekogIGh+8NoYBTBQMDtQeTiKQ4u0KYHiYkF4HbzaT//7A80v9N/gQLmSC4/icA6v/sXqYA7F4AAB2V7v/2/wAIGQAAAB4DAACQRQ0Tus5IAAgHUsOCUJ71DaHkPFgFdJcpEDguP6ldR+UmgbrM2+6m//9vOPT/S/7vC1sh6/49AJH/7F6mAOxeAAAQCfr/8/8A4wwAAAAfAwAA7IYNqLrOSAAIByZDZIfa4AyhxlEVA9QtFKN+R+1NPIIIJ8xm1q8Qqv//djDzB9H+pBNQGGj+rv++/+xepgDsXgAA3f/6/67/AAFUAAAAIAMAAJSG0BW6zhQACAWVGZOmAAAAAPr///8SEpCmiQcDAD4zLlK6zhAACAZIDf33DwP+/jYK//gDAAAAoBoC9g=="; +function updateAgps() { + g.reset(); + g.clear(); + if (!waiting) { + waiting = true; + display("Updating A-GPS...", "takes ~ 10 seconds"); + require("agpsdata").pull(function() { + waiting = false; + display("A-GPS updated.", "touch to close"); + Bangle.on("touch", () => { load(); }); + }, + function(error) { + waiting = false; + E.showAlert(error, "Error") + .then(() => { start(); }); + }); + } else { + display("Waiting..."); + } +} +updateAgps(); diff --git a/apps/agpsdata/boot.js b/apps/agpsdata/boot.js new file mode 100644 index 000000000..2b1e6819c --- /dev/null +++ b/apps/agpsdata/boot.js @@ -0,0 +1,26 @@ +(function() { + let waiting = false; + let settings = require("Storage").readJSON("agpsdata.settings.json", 1) || { + enabled: true, + refresh: 1440 + }; + + if (settings.refresh == undefined) settings.refresh = 1440; + + function successCallback(){ + waiting = false; + } + + function errorCallback(){ + waiting = false; + } + + if (settings.enabled) { + setInterval(() => { + if (!waiting && NRF.getSecurityStatus().connected){ + waiting = true; + require("agpsdata").pull(successCallback, errorCallback); + } + }, settings.refresh * 1000 * 60); + } +})(); diff --git a/apps/agpsdata/default.json b/apps/agpsdata/default.json new file mode 100644 index 000000000..0b6e0cecf --- /dev/null +++ b/apps/agpsdata/default.json @@ -0,0 +1 @@ +{"enabled":true,"refresh":1440,"gnsstype":1} diff --git a/apps/agpsdata/lib.js b/apps/agpsdata/lib.js new file mode 100644 index 000000000..34608a5c6 --- /dev/null +++ b/apps/agpsdata/lib.js @@ -0,0 +1,93 @@ +function readSettings() { + settings = Object.assign( + require('Storage').readJSON("agpsdata.default.json", true) || {}, + require('Storage').readJSON(FILE, true) || {}); +} + +var FILE = "agpsdata.settings.json"; +var settings; +readSettings(); + +function setAGPS(b64) { + return new Promise(function(resolve, reject) { + var initCommands = "Bangle.setGPSPower(1);\n"; // turn GPS on + const gnsstype = settings.gnsstype || 1; // default GPS + initCommands += `Serial1.println("${CASIC_CHECKSUM("$PCAS04," + gnsstype)}")\n`; // set GNSS mode + // What about: + // NAV-TIMEUTC (0x01 0x10) + // NAV-PV (0x01 0x03) + // or AGPS.zip uses AID-INI (0x0B 0x01) + + eval(initCommands); + + try { + writeChunks(atob(b64), resolve); + } catch (e) { + console.log("error:", e); + reject(); + } + }); +} + +var chunkI = 0; +function writeChunks(bin, resolve) { + return new Promise(function(resolve2) { + const chunkSize = 128; + setTimeout(function() { + if (chunkI < bin.length) { + var chunk = bin.substr(chunkI, chunkSize); + js = `Serial1.write(atob("${btoa(chunk)}"))\n`; + eval(js); + + chunkI += chunkSize; + writeChunks(bin, resolve); + } else { + if (resolve) + resolve(); // call outer resolve + } + }, 200); + }); +} + +function CASIC_CHECKSUM(cmd) { + var cs = 0; + for (var i = 1; i < cmd.length; i++) + cs = cs ^ cmd.charCodeAt(i); + return cmd + "*" + cs.toString(16).toUpperCase().padStart(2, '0'); +} + +function updateLastUpdate() { + const file = "agpsdata.json"; + let data = require("Storage").readJSON(file, 1) || {}; + data.lastUpdate = Math.round(Date.now()); + require("Storage").writeJSON(file, data); +} + +exports.pull = function(successCallback, failureCallback) { + const uri = "https://www.espruino.com/agps/casic.base64"; + if (Bangle.http) { + Bangle.http(uri, {timeout : 10000}) + .then(event => { + setAGPS(event.resp) + .then(r => { + updateLastUpdate(); + if (successCallback) + successCallback(); + }) + .catch((e) => { + console.log("error", e); + if (failureCallback) + failureCallback(e); + }); + }) + .catch((e) => { + console.log("error", e); + if (failureCallback) + failureCallback(e); + }); + } else { + console.log("error: No http method found"); + if (failureCallback) + failureCallback(/*LANG*/ "No http method"); + } +}; diff --git a/apps/agpsdata/metadata.json b/apps/agpsdata/metadata.json index af51f3a10..203a00f72 100644 --- a/apps/agpsdata/metadata.json +++ b/apps/agpsdata/metadata.json @@ -1,16 +1,24 @@ { "id": "agpsdata", - "name": "A-GPS Data", - "shortName":"AGPS Data", + "name": "A-GPS Data Downloader App", + "shortName":"A-GPS Data", "icon": "agpsdata.png", - "version":"0.01", - "description": "Download assisted GPS data directly to watch", - "tags": "assisted,gps,agps,http", + "version":"0.04", + "description": "Once installed, this app allows you to download assisted GPS (A-GPS) data directly to your Bangle.js **via Gadgetbridge on an Android phone** when you run the app. If you just want to upload the latest AGPS data from this app loader, please use the `Assisted GPS Update (AGPS)` app.", + "tags": "boot,tool,assisted,gps,agps,http", "allow_emulator":true, "supports": ["BANGLEJS2"], "readme":"README.md", - "screenshots" : [ { "url":"screenshot.png" }, { "url":"screenshot2.png" }, { "url":"screenshot3.png" }, { "url":"screenshot4.png" }, { "url":"screenshot5.png" } ], + "screenshots" : [ { "url":"screenshot.png" }, { "url":"screenshot2.png" } ], "storage": [ {"name":"agpsdata.app.js","url":"app.js"}, - {"name":"agpsdata.img","url":"agpsdata-icon.js","evaluate":true} + {"name":"agpsdata.img","url":"agpsdata-icon.js","evaluate":true}, + {"name":"agpsdata.default.json","url":"default.json"}, + {"name":"agpsdata.boot.js","url":"boot.js"}, + {"name":"agpsdata","url":"lib.js"}, + {"name":"agpsdata.settings.js","url":"settings.js"} + ], + "data": [ + {"name": "agpsdata.json"}, + {"name": "agpsdata.settings.json"} ] } diff --git a/apps/agpsdata/screenshot.png b/apps/agpsdata/screenshot.png index fae53ba85..1fcb2d8ee 100644 Binary files a/apps/agpsdata/screenshot.png and b/apps/agpsdata/screenshot.png differ diff --git a/apps/agpsdata/screenshot2.png b/apps/agpsdata/screenshot2.png index 7cdba1487..7c546e4b5 100644 Binary files a/apps/agpsdata/screenshot2.png and b/apps/agpsdata/screenshot2.png differ diff --git a/apps/agpsdata/screenshot3.png b/apps/agpsdata/screenshot3.png deleted file mode 100644 index be152ba28..000000000 Binary files a/apps/agpsdata/screenshot3.png and /dev/null differ diff --git a/apps/agpsdata/screenshot4.png b/apps/agpsdata/screenshot4.png deleted file mode 100644 index 305a166d0..000000000 Binary files a/apps/agpsdata/screenshot4.png and /dev/null differ diff --git a/apps/agpsdata/screenshot5.png b/apps/agpsdata/screenshot5.png deleted file mode 100644 index 6468a1872..000000000 Binary files a/apps/agpsdata/screenshot5.png and /dev/null differ diff --git a/apps/agpsdata/settings.js b/apps/agpsdata/settings.js new file mode 100644 index 000000000..64fa25330 --- /dev/null +++ b/apps/agpsdata/settings.js @@ -0,0 +1,71 @@ +(function(back) { +function writeSettings(key, value) { + var s = Object.assign( + require('Storage').readJSON(settingsDefaultFile, true) || {}, + require('Storage').readJSON(settingsFile, true) || {}); + s[key] = value; + require('Storage').writeJSON(settingsFile, s); + readSettings(); +} + +function readSettings() { + settings = Object.assign( + require('Storage').readJSON(settingsDefaultFile, true) || {}, + require('Storage').readJSON(settingsFile, true) || {}); +} + +var settingsFile = "agpsdata.settings.json"; +var settingsDefaultFile = "agpsdata.default.json"; + +var settings; +readSettings(); + +const gnsstypes = [ + "", "GPS", "BDS", "GPS+BDS", "GLONASS", "GPS+GLONASS", "BDS+GLONASS", + "GPS+BDS+GLON." +]; + +function buildMainMenu() { + var mainmenu = { + '' : {'title' : 'AGPS download'}, + '< Back' : back, + "Enabled" : { + value : !!settings.enabled, + onchange : v => { writeSettings("enabled", v); } + }, + "Refresh every" : { + value : settings.refresh / 60, + min : 6, + max : 168, + step : 1, + format : v => v + "h", + onchange : v => { writeSettings("refresh", Math.round(v * 60)); } + }, + "GNSS type" : { + value : settings.gnsstype, + min : 1, + max : 7, + step : 1, + format : v => gnsstypes[v], + onchange : x => writeSettings('gnsstype', x) + }, + "Force refresh" : () => { + E.showMessage("Loading A-GPS data"); + require("agpsdata") + .pull( + function() { + E.showAlert("Success").then( + () => { E.showMenu(buildMainMenu()); }); + }, + function(error) { + E.showAlert(error, "Error") + .then(() => { E.showMenu(buildMainMenu()); }); + }); + } + }; + + return mainmenu; +} + +E.showMenu(buildMainMenu()); +}); diff --git a/apps/aiclock/ChangeLog b/apps/aiclock/ChangeLog new file mode 100644 index 000000000..fb5aed3e3 --- /dev/null +++ b/apps/aiclock/ChangeLog @@ -0,0 +1,5 @@ +0.01: New app! +0.02: Design improvements and fixes. +0.03: Indicate battery level through line occurrence. +0.04: Use widget_utils module. +0.05: Support for clkinfo. \ No newline at end of file diff --git a/apps/aiclock/README.md b/apps/aiclock/README.md new file mode 100644 index 000000000..31dd5aa29 --- /dev/null +++ b/apps/aiclock/README.md @@ -0,0 +1,25 @@ +# AI Clock +This clock was designed by stable diffusion ([paper](https://arxiv.org/abs/2112.10752)) using the following prompt: + +`A rectangle banglejs watchface` + + +The original output of stable diffusion is shown here: + +![](orig.png) + +My implementation is shown below. Note that horizontal lines occur randomly, but the +probability is correlated with the battery level. So if your screen contains only +a few lines its time to charge your bangle again ;) Also note that the upper text +implementes the clkinfo module and can be configured via touch left/right/up/down. +Touch at the center to trigger the selected action. + +![](impl.png) + + +# Thanks to +The great open-source community: I used an open-source diffusion model (https://github.com/CompVis/stable-diffusion) +to generate a watch face for the open-source smartwatch BangleJs. + +## Creator +- [David Peer](https://github.com/peerdavid). \ No newline at end of file diff --git a/apps/aiclock/aiclock.app.js b/apps/aiclock/aiclock.app.js new file mode 100644 index 000000000..b5bb30b9d --- /dev/null +++ b/apps/aiclock/aiclock.app.js @@ -0,0 +1,437 @@ +/************************************************ + * AI Clock + */ + const storage = require('Storage'); + const clock_info = require("clock_info"); + + + + /************************************************ + * Assets + */ +require("Font7x11Numeric7Seg").add(Graphics); +Graphics.prototype.setFontGochiHand = function(scale) { + // Actual height 27 (29 - 3) + this.setFontCustom( + atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAA8AAAAADwAAAAAPAAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfgAAAA/+AAAB//4AAH///gAH///gAAf//AAAB/+AAAAH8AAAAAAAAAAAAAAAAAAAAH8AAAAB/8AAAAP/4AAAB//wAAAPx/AAAB8B+AAAHgD4AAA+AHgAADwAeAAAPAB4AAA8AHgAAD4AeAAAPgB4AAAeAPgAAB8A8AAAH4HwAAAP/+AAAAf/wAAAA/+AAAAB/wAAAAB8AAAAAAAAAAADgAAAAAfAAAAAB4AAAAAPAAAAAB8AAAAAHgAAAAA8AAAAADwAAAAAf4AAAAB//8AAAD//4AAAH//gAAAD/+AAAAAHwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4AHgAAHgA+AAA/AD4AAD4AfgAAfAD+AAB4Af4AAHgD/gAAeAfeAAB4D54AAHw/HgAAf/4fAAA//B8AAD/4DwAAH+APAAAHgA8AAAAADwAAAAAOAAAAAAAAABgAAAAAPAAAAAB8AAAAAHwAYAAAeAD4AAD4APwAAPA4fgAA8Hw+AADwfB4AAPh4HwAA+HgPAAB/+A8AAH/4DwAAP/weAAAf/j4AAAc//gAAAB/8AAAAD/gAAAAD8AAAAAAAAAAAAAAAAAADAAAAAA+AAAAAP4AAAAB/wAAAAP/AAAAD+8AAAAfzwAAAf8HAAAB/gcAAAH/hwAAAf//gAAA//+AAAAf//gAAAP//gAAAD/+AAAAB/4AAAAH/AAAAAeAAAAAAgAAAAAAAAAAAAcAAAB8H8AAAP4f4AAA/x/wAAD/H/gAAf+A+AAB74B4AAHnwHgAAefAfAAB58A8AAHj4DwAAePgPAAB4fA8AAHh+HgAAeD8+AAB4P/4AAHgf/AAAeA/4AAAAA+AAAAAAAAAAAAAAAAAAHgAAAAD/wAAAA//gAAAH//AAAA//+AAAD4H8AAAfA/wAAB4D/AAAHgP+AAAeB54AAB4HngAAHweeAAAfB54AAA4HngAAAAeeAAAAB/4AAAAH/AAAAAP4AAAAAfAAADwAAAAAPAAAAAA8HgAAADweAAAAPB4AAAA8HgAAADweAAAAPh4AAAA+HgAAAB4eAAAAHx4AAAAf//8AAA///wAAD//+AAAH//4AAAAeAAAAAB4AAAAAHgAAAAAeAAAAAB4AAAAAHgAAAAAAAAAAAAAAAAAAD+AAAA+f+AAAH//8AAA///wAAH/4fgAAePgeAAB4+B4AAHj4HwAAePgPAAB4+A8AAHz4DwAAfngeAAA//B4AAD/+HgAAH//8AAAP//wAAAAf+AAAAA/wAAAAAYAAAAAAAAAAA/gAAAAH/AAAAA/8AAAAD34AAAAeHgAAAB4eAAAAHh4AAAA8HgAAADweAAAAPDwAAAA8PAAAADx4AAAAPvgAAAAf///AAB///8AAH///wAAP///AAA/wA4AABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOA4AAAA8DwAAADwPAAAAPA8AAAAYBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='), + 46, + atob("DQoXEBQVExUUFRYUDQ=="), + 40+(scale<<8)+(1<<16) + ); + return this; +} + +/************************************************ + * Set some important constants such as width, height and center + */ +var W = g.getWidth(),R=W/2; +var H = g.getHeight(); +var cx = W/2; +var cy = H/2; +var drawTimeout; +var lock_input = false; + + +/************************************************ + * SETTINGS + */ +const SETTINGS_FILE = "aiclock.setting.json"; +let settings = { + menuPosX: 0, + menuPosY: 0, +}; +let saved_settings = storage.readJSON(SETTINGS_FILE, 1) || settings; +for (const key in saved_settings) { + settings[key] = saved_settings[key] +} + + +/************************************************ + * Menu + */ +function getDate(){ + var date = new Date(); + return ("0"+date.getDate()).substr(-2) + "/" + ("0"+(date.getMonth()+1)).substr(-2) +} + + +// Custom clockItems menu - therefore, its added here and not in a clkinfo.js file. +var clockItems = { + name: getDate(), + img: null, + items: [ + { name: "Week", + get: () => ({ text: "Week " + weekOfYear(), img: null}), + show: function() { clockItems.items[0].emit("redraw"); }, + hide: function () {} + }, + ] + }; + +function weekOfYear() { + var date = new Date(); + date.setHours(0, 0, 0, 0); + // Thursday in current week decides the year. + date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); + // January 4 is always in week 1. + var week1 = new Date(date.getFullYear(), 0, 4); + // Adjust to Thursday in week 1 and count number of weeks from date to week1. + return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 + - 3 + (week1.getDay() + 6) % 7) / 7); +} + + + +// Load menu +var menu = clock_info.load(); +menu = menu.concat(clockItems); + + + // Ensure that our settings are still in range (e.g. app uninstall). Otherwise reset the position it. + if(settings.menuPosX >= menu.length || settings.menuPosY > menu[settings.menuPosX].items.length ){ + settings.menuPosX = 0; + settings.menuPosY = 0; + } + + // Set draw functions for each item + menu.forEach((menuItm, x) => { + menuItm.items.forEach((item, y) => { + function drawItem() { + // For the clock, we have a special case, as we don't wanna redraw + // immediately when something changes. Instead, we update data each minute + // to save some battery etc. Therefore, we hide (and disable the listener) + // immedeately after redraw... + item.hide(); + + // After drawing the item, we enable inputs again... + lock_input = false; + + var info = item.get(); + drawMenuItem(info.text, info.img); + } + + item.on('redraw', drawItem); + }) + }); + + + function canRunMenuItem(){ + if(settings.menuPosY == 0){ + return false; + } + + var menuEntry = menu[settings.menuPosX]; + var item = menuEntry.items[settings.menuPosY-1]; + return item.run !== undefined; + } + + + function runMenuItem(){ + if(settings.menuPosY == 0){ + return; + } + + var menuEntry = menu[settings.menuPosX]; + var item = menuEntry.items[settings.menuPosY-1]; + try{ + var ret = item.run(); + if(ret){ + Bangle.buzz(300, 0.6); + } + } catch (ex) { + // Simply ignore it... + } + } + + +/* + * Based on the great multi clock from https://github.com/jeffmer/BangleApps/ + */ +Graphics.prototype.drawRotRect = function(w, r1, r2, angle) { + angle = angle % 360; + var w2=w/2, h=r2-r1, theta=angle*Math.PI/180; + return this.fillPoly(this.transformVertices([-w2,0,-w2,-h,w2,-h,w2,0], + {x:cx+r1*Math.sin(theta),y:cy-r1*Math.cos(theta),rotate:theta})); +}; + + +function drawBackground() { + g.setFontAlign(0,0); + g.setColor(g.theme.fg); + + var bat = E.getBattery() / 100.0; + var y = 0; + while(y < H){ + // Show less lines in case of small battery level. + if(Math.random() > bat){ + y += 5; + continue; + } + + y += 3 + Math.floor(Math.random() * 10); + g.drawLine(0, y, W, y); + g.drawLine(0, y+1, W, y+1); + g.drawLine(0, y+2, W, y+2); + y += 2; + } +} + + +function drawCircle(isLocked){ + g.setColor(g.theme.fg); + g.fillCircle(cx, cy, 12); + + var c = isLocked ? "#f00" : g.theme.bg; + g.setColor(c); + g.fillCircle(cx, cy, 6); +} + +function toAngle(a){ + if (a < 0){ + return 360 + a; + } + + if(a > 360) { + return 360 - a; + } + + return a +} + + +function drawMenuItem(text, image){ + if(text == null){ + drawTime(); + return + } + // image = atob("GBiBAAD+AAH+AAH+AAH+AAH/AAOHAAYBgAwAwBgwYBgwYBgwIBAwOBAwOBgYIBgMYBgAYAwAwAYBgAOHAAH/AAH+AAH+AAH+AAD+AA=="); + + text = String(text); + + g.reset().setBgColor("#fff").setColor("#000"); + g.setFontAlign(0,0); + g.setFont("Vector", 20); + + var imgWidth = image == null ? 0 : 24; + var strWidth = g.stringWidth(text); + var strHeight = text.split('\n').length > 1 ? 40 : Math.max(24, imgWidth+2); + var w = imgWidth + strWidth; + + g.clearRect(cx-w/2-8, 40-strHeight/2-1, cx+w/2+4, 40+strHeight/2) + + // Draw right line as designed by stable diffusion + g.drawLine(cx+w/2+5, 40-strHeight/2-1, cx+w/2+5, 40+strHeight/2); + g.drawLine(cx+w/2+6, 40-strHeight/2-1, cx+w/2+6, 40+strHeight/2); + g.drawLine(cx+w/2+7, 40-strHeight/2-1, cx+w/2+7, 40+strHeight/2); + + // And finally the text + g.drawString(text, cx+imgWidth/2, 42); + g.drawString(text, cx+1+imgWidth/2, 41); + + if(image != null) { + var scale = image.width ? imgWidth / image.width : 1; + g.drawImage(image, W/2 + -strWidth/2-4 - parseInt(imgWidth/2), 41-12, {scale: scale}); + } + + drawTime(); +} + + +function drawTime(){ + // Draw digital time first + drawDigits(); + + // And now the analog time + var drawHourHand = g.drawRotRect.bind(g,8,12,R-38); + var drawMinuteHand = g.drawRotRect.bind(g,6,12,R-12 ); + + g.setFontAlign(0,0); + + // Compute angles + var date = new Date(); + var m = parseInt(date.getMinutes() * 360 / 60); + var h = date.getHours(); + h = h > 12 ? h-12 : h; + h += date.getMinutes()/60.0; + h = parseInt(h*360/12); + + // Draw minute and hour fg + g.setColor(g.theme.fg); + drawHourHand(h); + drawMinuteHand(m); +} + + +function drawDigits(){ + var date = new Date(); + + g.setFontAlign(0,0); + g.setFont("7x11Numeric7Seg",3); + + var text = ("0"+date.getHours()).substr(-2) + ":" + ("0"+date.getMinutes()).substr(-2); //Bangle.getHealthStatus("day").steps; + var w = g.stringWidth(text); + g.setColor(g.theme.bg); + g.fillRect(cx-w/2-4, 120, cx+w/2+4, 140+20); + + // Draw right line as designed by stable diffusion + g.setColor(g.theme.fg); + g.drawLine(cx+w/2+5, 120, cx+w/2+5, 140+20); + g.drawLine(cx+w/2+6, 120, cx+w/2+6, 140+20); + g.drawLine(cx+w/2+7, 120, cx+w/2+7, 140+20); + + // And the 7set text + g.setColor("#BBB"); + g.drawString("88:88", cx, 140); + g.drawString("88:88", cx+1, 140); + g.drawString("88:88", cx, 141); + + g.setColor(g.theme.fg); + g.drawString(text, cx, 140); + g.drawString(text, cx+1, 140); + g.drawString(text, cx, 141); +} + + +function drawDate(){ + var menuEntry = menu[settings.menuPosX]; + + // The first entry is the overview... + if(settings.menuPosY == 0){ + drawMenuItem(menuEntry.name, menuEntry.img); + return; + } + + // Draw item if needed + lock_input = true; + var item = menuEntry.items[settings.menuPosY-1]; + item.show(); +} + + + + + +function draw(){ + // Queue draw in one minute + queueDraw(); + + g.reset(); + g.clearRect(0, 0, g.getWidth(), g.getHeight()); + g.setColor(1,1,1); + + drawBackground(); + drawDate(); + drawCircle(Bangle.isLocked()); +} + + +/* + * Listeners + */ +Bangle.on('lcdPower',on=>{ + if (on) { + draw(true); + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); + +Bangle.on('lock', function(isLocked) { + drawCircle(isLocked); +}); + +Bangle.on('touch', function(btn, e){ + var left = parseInt(g.getWidth() * 0.22); + var right = g.getWidth() - left; + var upper = parseInt(g.getHeight() * 0.22); + var lower = g.getHeight() - upper; + + var is_upper = e.y < upper; + var is_lower = e.y > lower; + var is_left = e.x < left && !is_upper && !is_lower; + var is_right = e.x > right && !is_upper && !is_lower; + var is_center = !is_upper && !is_lower && !is_left && !is_right; + + if(lock_input){ + return; + } + + if(is_lower){ + Bangle.buzz(40, 0.6); + settings.menuPosY = (settings.menuPosY+1) % (menu[settings.menuPosX].items.length+1); + + draw(); + } + + if(is_upper){ + Bangle.buzz(40, 0.6); + settings.menuPosY = settings.menuPosY-1; + settings.menuPosY = settings.menuPosY < 0 ? menu[settings.menuPosX].items.length : settings.menuPosY; + + draw(); + } + + if(is_right){ + Bangle.buzz(40, 0.6); + settings.menuPosX = (settings.menuPosX+1) % menu.length; + settings.menuPosY = 0; + draw(); + } + + if(is_left){ + Bangle.buzz(40, 0.6); + settings.menuPosY = 0; + settings.menuPosX = settings.menuPosX-1; + settings.menuPosX = settings.menuPosX < 0 ? menu.length-1 : settings.menuPosX; + draw(); + } + + if(is_center){ + if(canRunMenuItem()){ + runMenuItem(); + } + } +}); + + +E.on("kill", function(){ + try{ + storage.write(SETTINGS_FILE, settings); + } catch(ex){ + // If this fails, we still kill the app... + } +}); + + +/* + * Some helpers + */ +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +} + + +/* + * Lets start widgets, listen for btn etc. + */ +// Show launcher when middle button pressed +Bangle.setUI("clock"); +Bangle.loadWidgets(); +/* + * we are not drawing the widgets as we are taking over the whole screen + * so we will blank out the draw() functions of each widget and change the + * area to the top bar doesn't get cleared. + */ +require('widget_utils').hide(); + +// Clear the screen once, at startup and draw clock +g.setTheme({bg:"#fff",fg:"#000",dark:false}).clear(); +draw(); + +// After drawing the watch face, we can draw the widgets +// Bangle.drawWidgets(); diff --git a/apps/aiclock/aiclock.icon.js b/apps/aiclock/aiclock.icon.js new file mode 100644 index 000000000..0033b3848 --- /dev/null +++ b/apps/aiclock/aiclock.icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwgP/ACfAEZU/ECZELIKhSR/+PAoWAv4FDhk/x/ggP+j0fx/AgP8n8PCIX8CwIFC/F/w4FBgP4gEHC4QFE//w//DC4QFB8YFC+P/8IdCAoYdBAoPxDoQAd+CiKh4dQwDhfAA4A=")) \ No newline at end of file diff --git a/apps/aiclock/aiclock.png b/apps/aiclock/aiclock.png new file mode 100644 index 000000000..104261254 Binary files /dev/null and b/apps/aiclock/aiclock.png differ diff --git a/apps/aiclock/impl.png b/apps/aiclock/impl.png new file mode 100644 index 000000000..8a9e43e2d Binary files /dev/null and b/apps/aiclock/impl.png differ diff --git a/apps/aiclock/impl_2.png b/apps/aiclock/impl_2.png new file mode 100644 index 000000000..be3519a4b Binary files /dev/null and b/apps/aiclock/impl_2.png differ diff --git a/apps/aiclock/impl_3.png b/apps/aiclock/impl_3.png new file mode 100644 index 000000000..c2a036d14 Binary files /dev/null and b/apps/aiclock/impl_3.png differ diff --git a/apps/aiclock/metadata.json b/apps/aiclock/metadata.json new file mode 100644 index 000000000..1dcda427f --- /dev/null +++ b/apps/aiclock/metadata.json @@ -0,0 +1,22 @@ +{ + "id": "aiclock", + "name": "AI Clock", + "shortName":"AI Clock", + "icon": "aiclock.png", + "version":"0.05", + "readme": "README.md", + "supports": ["BANGLEJS2"], + "description": "A watch face that was designed by an AI (stable diffusion) and implemented by a human.", + "type": "clock", + "tags": "clock", + "screenshots": [ + {"url":"orig.png"}, + {"url":"impl.png"}, + {"url":"impl_2.png"}, + {"url":"impl_3.png"} + ], + "storage": [ + {"name":"aiclock.app.js","url":"aiclock.app.js"}, + {"name":"aiclock.img","url":"aiclock.icon.js","evaluate":true} + ] +} diff --git a/apps/aiclock/orig.png b/apps/aiclock/orig.png new file mode 100644 index 000000000..009826454 Binary files /dev/null and b/apps/aiclock/orig.png differ diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index 0ac863909..9994d33d9 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -33,4 +33,7 @@ 0.31: Add seconds to timers 0.32: Fix wrong hidden filter Add option for auto-delete a timer after it expires - +0.33: Allow hiding timers&alarms +0.34: Add "Confirm" option to alarm/timer edit menus +0.35: Add automatic translation of more strings +0.36: alarm widget moved out of app diff --git a/apps/alarm/app.js b/apps/alarm/app.js index bc0b2cf0e..1414c0b90 100644 --- a/apps/alarm/app.js +++ b/apps/alarm/app.js @@ -124,7 +124,16 @@ function showEditAlarmMenu(selectedAlarm, alarmIndex) { value: alarm.as, onchange: v => alarm.as = v }, - /*LANG*/"Cancel": () => showMainMenu() + /*LANG*/"Hidden": { + value: alarm.hidden || false, + onchange: v => alarm.hidden = v + }, + /*LANG*/"Cancel": () => showMainMenu(), + /*LANG*/"Confirm": () => { + prepareAlarmForSave(alarm, alarmIndex, time); + saveAndReload(); + showMainMenu(); + } }; if (!isNew) { @@ -174,7 +183,7 @@ function decodeDOW(alarm) { .map((day, index) => alarm.dow & (1 << (index + firstDayOfWeek)) ? day : "_") .join("") .toLowerCase() - : "Once" + : /*LANG*/"Once" } function showEditRepeatMenu(repeat, dow, dowChangeCallback) { @@ -284,8 +293,17 @@ function showEditTimerMenu(selectedTimer, timerIndex) { value: timer.del, onchange: v => timer.del = v }, + /*LANG*/"Hidden": { + value: timer.hidden || false, + onchange: v => timer.hidden = v + }, /*LANG*/"Vibrate": require("buzz_menu").pattern(timer.vibrate, v => timer.vibrate = v), - /*LANG*/"Cancel": () => showMainMenu() + /*LANG*/"Cancel": () => showMainMenu(), + /*LANG*/"Confirm": () => { + prepareTimerForSave(timer, timerIndex, time); + saveAndReload(); + showMainMenu(); + } }; if (!isNew) { diff --git a/apps/alarm/metadata.json b/apps/alarm/metadata.json index b2d25b77c..dbf090774 100644 --- a/apps/alarm/metadata.json +++ b/apps/alarm/metadata.json @@ -2,17 +2,16 @@ "id": "alarm", "name": "Alarms & Timers", "shortName": "Alarms", - "version": "0.32", + "version": "0.36", "description": "Set alarms and timers on your Bangle", "icon": "app.png", - "tags": "tool,alarm,widget", + "tags": "tool,alarm", "supports": [ "BANGLEJS", "BANGLEJS2" ], "readme": "README.md", - "dependencies": { "scheduler":"type" }, + "dependencies": { "scheduler":"type", "alarm":"widget" }, "storage": [ { "name": "alarm.app.js", "url": "app.js" }, - { "name": "alarm.img", "url": "app-icon.js", "evaluate": true }, - { "name": "alarm.wid.js", "url": "widget.js" } + { "name": "alarm.img", "url": "app-icon.js", "evaluate": true } ], "screenshots": [ { "url": "screenshot-1.png" }, diff --git a/apps/alpinenav/ChangeLog b/apps/alpinenav/ChangeLog new file mode 100644 index 000000000..b3d1e0874 --- /dev/null +++ b/apps/alpinenav/ChangeLog @@ -0,0 +1,2 @@ +0.01: New App! +0.02: Added adjustment for Bangle.js magnetometer heading fix diff --git a/apps/alpinenav/app.js b/apps/alpinenav/app.js index 29eeab0c9..7cffc39c3 100644 --- a/apps/alpinenav/app.js +++ b/apps/alpinenav/app.js @@ -224,7 +224,7 @@ Bangle.on('mag', function (m) { if (isNaN(m.heading)) compass_heading = "---"; else - compass_heading = 360 - Math.round(m.heading); + compass_heading = Math.round(m.heading); current_colour = g.getColor(); g.reset(); g.setColor(background_colour); diff --git a/apps/alpinenav/metadata.json b/apps/alpinenav/metadata.json index dcb56e912..c5a0e0611 100644 --- a/apps/alpinenav/metadata.json +++ b/apps/alpinenav/metadata.json @@ -1,7 +1,7 @@ { "id": "alpinenav", "name": "Alpine Nav", - "version": "0.01", + "version": "0.02", "description": "App that performs GPS monitoring to track and display position relative to a given origin in realtime", "icon": "app-icon.png", "tags": "outdoors,gps", diff --git a/apps/android/ChangeLog b/apps/android/ChangeLog index ee927c752..86dbdb649 100644 --- a/apps/android/ChangeLog +++ b/apps/android/ChangeLog @@ -9,4 +9,12 @@ 0.08: Handling of alarms 0.09: Alarm vibration, repeat, and auto-snooze now handled by sched 0.10: Fix SMS bug -0.11: Use default Bangle formatter for booleans +0.12: Use default Bangle formatter for booleans +0.13: Added Bangle.http function (see Readme file for more info) +0.14: Fix timeout of http function not being cleaned up +0.15: Allow method/body/headers to be specified for `http` (needs Gadgetbridge 0.68.0b or later) +0.16: Bangle.http now fails immediately if there is no Bluetooth connection (fix #2152) +0.17: Now kick off Calendar sync as soon as connected to Gadgetbridge +0.18: Use new message library + If connected to Gadgetbridge, allow GPS forwarding from phone (Gadgetbridge code still not merged) +0.19: Add automatic translation for a couple of strings. diff --git a/apps/android/README.md b/apps/android/README.md index c10718aac..c76e6e528 100644 --- a/apps/android/README.md +++ b/apps/android/README.md @@ -20,6 +20,8 @@ It contains: of Gadgetbridge - making your phone make noise so you can find it. * `Keep Msgs` - default is `Off`. When Gadgetbridge disconnects, should Bangle.js keep any messages it has received, or should it delete them? +* `Overwrite GPS` - when GPS is requested by an app, this doesn't use Bangle.js's GPS +but instead asks Gadgetbridge on the phone to use the phone's GPS * `Messages` - launches the messages app, showing a list of messages ## How it works @@ -32,6 +34,25 @@ Responses are sent back to Gadgetbridge simply as one line of JSON. More info on message formats on http://www.espruino.com/Gadgetbridge +## Functions provided + +The boot code also provides some useful functions: + +* `Bangle.messageResponse = function(msg,response)` - send a yes/no response to a message. `msg` is a message object, and `response` is a boolean. +* `Bangle.musicControl = function(cmd)` - control music, cmd = `play/pause/next/previous/volumeup/volumedown` +* `Bangle.http = function(url,options)` - make an HTTPS request to a URL and return a promise with the data. Requires the [internet enabled `Bangle.js Gadgetbridge` app](http://www.espruino.com/Gadgetbridge#http-requests). `options` can contain: + * `id` - a custom (string) ID + * `timeout` - a timeout for the request in milliseconds (default 30000ms) + * `xpath` an xPath query to run on the request (but right now the URL requested must be XML - HTML is rarely XML compliant) + +eg: + +``` +Bangle.http("https://pur3.co.uk/hello.txt").then(data=>{ + console.log("Got ",data); +}); +``` + ## Testing Bangle.js can only hold one connection open at a time, so it's hard to see diff --git a/apps/android/boot.js b/apps/android/boot.js index 9cdc019a6..e1e5b028b 100644 --- a/apps/android/boot.js +++ b/apps/android/boot.js @@ -57,7 +57,7 @@ t:event.cmd=="incoming"?"add":"remove", id:"call", src:"Phone", positive:true, negative:true, - title:event.name||"Call", body:"Incoming call\n"+event.number}); + title:event.name||/*LANG*/"Call", body:/*LANG*/"Incoming call\n"+event.number}); require("messages").pushMessage(event); }, "alarm" : function() { @@ -91,10 +91,6 @@ sched.reload(); }, //TODO perhaps move those in a library (like messages), used also for viewing events? - //simple package with events all together - "calendarevents" : function() { - require("Storage").writeJSON("android.calendar.json", event.events); - }, //add and remove events based on activity on phone (pebble-like) "calendar" : function() { var cal = require("Storage").readJSON("android.calendar.json",true); @@ -109,7 +105,7 @@ "calendar-" : function() { var cal = require("Storage").readJSON("android.calendar.json",true); //if any of those happen we are out of sync! - if (!cal || !Array.isArray(cal)) return; + if (!cal || !Array.isArray(cal)) cal = []; cal = cal.filter(e=>e.id!=event.id); require("Storage").writeJSON("android.calendar.json", cal); }, @@ -118,15 +114,74 @@ var cal = require("Storage").readJSON("android.calendar.json",true); if (!cal || !Array.isArray(cal)) cal = []; gbSend({t:"force_calendar_sync", ids: cal.map(e=>e.id)}); + }, + "http":function() { + //get the promise and call the promise resolve + if (Bangle.httpRequest === undefined) return; + var request=Bangle.httpRequest[event.id]; + if (request === undefined) return; //already timedout or wrong id + delete Bangle.httpRequest[event.id]; + clearTimeout(request.t); //t = timeout variable + if(event.err!==undefined) //if is error + request.j(event.err); //r = reJect function + else + request.r(event); //r = resolve function + }, + "gps": function() { + const settings = require("Storage").readJSON("android.settings.json",1)||{}; + if (!settings.overwriteGps) return; + delete event.t; + event.satellites = NaN; + event.course = NaN; + event.fix = 1; + Bangle.emit('gps', event); + }, + "is_gps_active": function() { + gbSend({ t: "gps_power", status: Bangle._PWR && Bangle._PWR.GPS && Bangle._PWR.GPS.length>0 }); } }; var h = HANDLERS[event.t]; if (h) h(); else console.log("GB Unknown",event); }; + // HTTP request handling - see the readme + // options = {id,timeout,xpath} + Bangle.http = (url,options)=>{ + options = options||{}; + if (!NRF.getSecurityStatus().connected) + return Promise.reject(/*LANG*/"Not connected to Bluetooth"); + if (Bangle.httpRequest === undefined) + Bangle.httpRequest={}; + if (options.id === undefined) { + // try and create a unique ID + do { + options.id = Math.random().toString().substr(2); + } while( Bangle.httpRequest[options.id]!==undefined); + } + //send the request + var req = {t: "http", url:url, id:options.id}; + if (options.xpath) req.xpath = options.xpath; + if (options.method) req.method = options.method; + if (options.body) req.body = options.body; + if (options.headers) req.headers = options.headers; + gbSend(req); + //create the promise + var promise = new Promise(function(resolve,reject) { + //save the resolve function in the dictionary and create a timeout (30 seconds default) + Bangle.httpRequest[options.id]={r:resolve,j:reject,t:setTimeout(()=>{ + //if after "timeoutMillisec" it still hasn't answered -> reject + delete Bangle.httpRequest[options.id]; + reject("Timeout"); + },options.timeout||30000)}; + }); + return promise; + } // Battery monitor function sendBattery() { gbSend({ t: "status", bat: E.getBattery(), chg: Bangle.isCharging()?1:0 }); } - NRF.on("connect", () => setTimeout(sendBattery, 2000)); + NRF.on("connect", () => setTimeout(function() { + sendBattery(); + GB({t:"force_calendar_sync_start"}); // send a list of our calendar entries to start off the sync process + }, 2000)); Bangle.on("charging", sendBattery); if (!settings.keep) NRF.on("disconnect", () => require("messages").clearAll()); // remove all messages on disconnect @@ -146,6 +201,30 @@ if (isFinite(msg.id)) return gbSend({ t: "notify", n:response?"OPEN":"DISMISS", id: msg.id }); // error/warn here? }; + // GPS overwrite logic + if (settings.overwriteGps) { // if the overwrite option is set../ + // Save current logic + const originalSetGpsPower = Bangle.setGPSPower; + // Replace set GPS power logic to suppress activation of gps (and instead request it from the phone) + Bangle.setGPSPower = (isOn, appID) => { + // if not connected, use old logic + if (!NRF.getSecurityStatus().connected) return originalSetGpsPower(isOn, appID); + // Emulate old GPS power logic + if (!Bangle._PWR) Bangle._PWR={}; + if (!Bangle._PWR.GPS) Bangle._PWR.GPS=[]; + if (!appID) appID="?"; + if (isOn && !Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.push(appID); + if (!isOn && Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.splice(Bangle._PWR.GPS.indexOf(appID),1); + let pwr = Bangle._PWR.GPS.length>0; + gbSend({ t: "gps_power", status: pwr }); + return pwr; + } + // Replace check if the GPS is on to check the _PWR variable + Bangle.isGPSOn = () => { + return Bangle._PWR && Bangle._PWR.GPS && Bangle._PWR.GPS.length>0; + } + } + // remove settings object so it's not taking up RAM delete settings; })(); diff --git a/apps/android/metadata.json b/apps/android/metadata.json index ec8b8b0fe..d5a45edb7 100644 --- a/apps/android/metadata.json +++ b/apps/android/metadata.json @@ -2,11 +2,11 @@ "id": "android", "name": "Android Integration", "shortName": "Android", - "version": "0.12", + "version": "0.19", "description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.", "icon": "app.png", "tags": "tool,system,messages,notifications,gadgetbridge", - "dependencies": {"messages":"app"}, + "dependencies": {"messages":"module"}, "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "storage": [ diff --git a/apps/android/settings.js b/apps/android/settings.js index c7c34a76f..3e04e0f9d 100644 --- a/apps/android/settings.js +++ b/apps/android/settings.js @@ -1,4 +1,7 @@ (function(back) { + + + function gb(j) { Bluetooth.println(JSON.stringify(j)); } @@ -23,7 +26,17 @@ updateSettings(); } }, - /*LANG*/"Messages" : ()=>load("messages.app.js"), + /*LANG*/"Overwrite GPS" : { + value : !!settings.overwriteGps, + onchange: newValue => { + if (newValue) { + Bangle.setGPSPower(false, 'android'); + } + settings.overwriteGps = newValue; + updateSettings(); + } + }, + /*LANG*/"Messages" : ()=>require("message").openGUI(), }; E.showMenu(mainmenu); }) diff --git a/apps/animclk/ChangeLog b/apps/animclk/ChangeLog index 348448c34..76d15bdb1 100644 --- a/apps/animclk/ChangeLog +++ b/apps/animclk/ChangeLog @@ -1,3 +1,5 @@ 0.01: New App! 0.02: Fix bug if image clock wasn't installed 0.03: Update to use setUI +0.04: Tell clock widgets to hide. Move loadWidgets() so it only runs on +startup and not on every draw. diff --git a/apps/animclk/app.js b/apps/animclk/app.js index 4bf63daf6..bdc399fbe 100644 --- a/apps/animclk/app.js +++ b/apps/animclk/app.js @@ -87,7 +87,6 @@ if (g.drawImages) { draw(); var secondInterval = setInterval(draw,100); // load widgets - Bangle.loadWidgets(); Bangle.drawWidgets(); // Stop when LCD goes off Bangle.on('lcdPower',on=>{ @@ -104,3 +103,5 @@ if (g.drawImages) { } // Show launcher when button pressed Bangle.setUI("clock"); + +Bangle.loadWidgets(); diff --git a/apps/animclk/metadata.json b/apps/animclk/metadata.json index 31dfe453f..0b426a37d 100644 --- a/apps/animclk/metadata.json +++ b/apps/animclk/metadata.json @@ -2,7 +2,7 @@ "id": "animclk", "name": "Animated Clock", "shortName": "Anim Clock", - "version": "0.03", + "version": "0.04", "description": "An animated clock face using Mark Ferrari's amazing 8 bit game art and palette cycling: http://www.markferrari.com/art/8bit-game-art", "icon": "app.png", "type": "clock", diff --git a/apps/antonclk/ChangeLog b/apps/antonclk/ChangeLog index f7e95b5fa..4ef0cee75 100644 --- a/apps/antonclk/ChangeLog +++ b/apps/antonclk/ChangeLog @@ -10,4 +10,7 @@ week is buffered until date or timezone changes 0.07: align default settings with app.js (otherwise the initial displayed settings will be confusing to users) 0.08: fixed calendar weeknumber not shortened to two digits -0.09: Use default Bangle formatter for booleans \ No newline at end of file +0.09: Use default Bangle formatter for booleans +0.10: Use Bangle.setUI({remove:...}) to allow loading the launcher without a full reset on 2v16 +0.11: Moved enhanced Anton clock to 'Anton Clock Plus' and stripped this clock back down to make it faster for new users (270ms -> 170ms) + Modified to avoid leaving functions defined when using setUI({remove:...}) diff --git a/apps/antonclk/app.js b/apps/antonclk/app.js index 4b1e71bda..528866588 100644 --- a/apps/antonclk/app.js +++ b/apps/antonclk/app.js @@ -1,230 +1,45 @@ // Clock with large digits using the "Anton" bold font - -const SETTINGSFILE = "antonclk.json"; - Graphics.prototype.setFontAnton = function(scale) { // Actual height 69 (68 - 0) g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAA/gAAAAAAAAAAP/gAAAAAAAAAH//gAAAAAAAAB///gAAAAAAAAf///gAAAAAAAP////gAAAAAAD/////gAAAAAA//////gAAAAAP//////gAAAAH///////gAAAB////////gAAAf////////gAAP/////////gAD//////////AA//////////gAA/////////4AAA////////+AAAA////////gAAAA///////wAAAAA//////8AAAAAA//////AAAAAAA/////gAAAAAAA////4AAAAAAAA///+AAAAAAAAA///gAAAAAAAAA//wAAAAAAAAAA/8AAAAAAAAAAA/AAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////AAAAAB///////8AAAAH////////AAAAf////////wAAA/////////4AAB/////////8AAD/////////+AAH//////////AAP//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wA//8AAAAAB//4A//wAAAAAAf/4A//gAAAAAAP/4A//gAAAAAAP/4A//gAAAAAAP/4A//wAAAAAAf/4A///////////4Af//////////wAf//////////wAf//////////wAf//////////wAP//////////gAP//////////gAH//////////AAH//////////AAD/////////+AAB/////////8AAA/////////4AAAP////////gAAAD///////+AAAAAf//////4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/gAAAAAAAAAAP/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/AAAAAAAAAAA//AAAAAAAAAAA/+AAAAAAAAAAB/8AAAAAAAAAAD//////////gAH//////////gAP//////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/4AAAAB/gAAD//4AAAAf/gAAP//4AAAB//gAA///4AAAH//gAB///4AAAf//gAD///4AAA///gAH///4AAD///gAP///4AAH///gAP///4AAP///gAf///4AAf///gAf///4AB////gAf///4AD////gA////4AH////gA////4Af////gA////4A/////gA//wAAB/////gA//gAAH/////gA//gAAP/////gA//gAA///8//gA//gAD///w//gA//wA////g//gA////////A//gA///////8A//gA///////4A//gAf//////wA//gAf//////gA//gAf/////+AA//gAP/////8AA//gAP/////4AA//gAH/////gAA//gAD/////AAA//gAB////8AAA//gAA////wAAA//gAAP///AAAA//gAAD//8AAAA//gAAAP+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB/+AAAAAD/wAAB//8AAAAP/wAAB///AAAA//wAAB///wAAB//wAAB///4AAD//wAAB///8AAH//wAAB///+AAP//wAAB///+AAP//wAAB////AAf//wAAB////AAf//wAAB////gAf//wAAB////gA///wAAB////gA///wAAB////gA///w//AAf//wA//4A//AAA//wA//gA//AAAf/wA//gB//gAAf/wA//gB//gAAf/wA//gD//wAA//wA//wH//8AB//wA///////////gA///////////gA///////////gA///////////gAf//////////AAf//////////AAP//////////AAP/////////+AAH/////////8AAH///+/////4AAD///+f////wAAA///8P////gAAAf//4H///+AAAAH//gB///wAAAAAP4AAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAA//wAAAAAAAAAP//wAAAAAAAAB///wAAAAAAAAf///wAAAAAAAH////wAAAAAAA/////wAAAAAAP/////wAAAAAB//////wAAAAAf//////wAAAAH///////wAAAA////////wAAAP////////wAAA///////H/wAAA//////wH/wAAA/////8AH/wAAA/////AAH/wAAA////gAAH/wAAA///4AAAH/wAAA//+AAAAH/wAAA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAH/4AAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB//8AAA/////+B///AAA/////+B///wAA/////+B///4AA/////+B///8AA/////+B///8AA/////+B///+AA/////+B////AA/////+B////AA/////+B////AA/////+B////gA/////+B////gA/////+B////gA/////+A////gA//gP/gAAB//wA//gf/AAAA//wA//gf/AAAAf/wA//g//AAAAf/wA//g//AAAA//wA//g//gAAA//wA//g//+AAP//wA//g////////gA//g////////gA//g////////gA//g////////gA//g////////AA//gf///////AA//gf//////+AA//gP//////+AA//gH//////8AA//gD//////4AA//gB//////wAA//gA//////AAAAAAAH////8AAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////gAAAAB///////+AAAAH////////gAAAf////////4AAB/////////8AAD/////////+AAH//////////AAH//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wAf//////////4A//wAD/4AAf/4A//gAH/wAAP/4A//gAH/wAAP/4A//gAP/wAAP/4A//gAP/4AAf/4A//wAP/+AD//4A///wP//////4Af//4P//////wAf//4P//////wAf//4P//////wAf//4P//////wAP//4P//////gAP//4H//////gAH//4H//////AAH//4D/////+AAD//4D/////8AAB//4B/////4AAA//4A/////wAAAP/4AP////AAAAB/4AD///4AAAAAAAAAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//AAAAAAAAAAA//gAAAAAAAAAA//gAAAAAAAAAA//gAAAAAAADgA//gAAAAAAP/gA//gAAAAAH//gA//gAAAAB///gA//gAAAAP///gA//gAAAD////gA//gAAAf////gA//gAAB/////gA//gAAP/////gA//gAB//////gA//gAH//////gA//gA///////gA//gD///////gA//gf///////gA//h////////gA//n////////gA//////////gAA/////////AAAA////////wAAAA///////4AAAAA///////AAAAAA//////4AAAAAA//////AAAAAAA/////4AAAAAAA/////AAAAAAAA////8AAAAAAAA////gAAAAAAAA///+AAAAAAAAA///4AAAAAAAAA///AAAAAAAAAA//4AAAAAAAAAA/+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//gB///wAAAAP//4H///+AAAA///8P////gAAB///+f////4AAD///+/////8AAH/////////+AAH//////////AAP//////////gAP//////////gAf//////////gAf//////////wAf//////////wAf//////////wA///////////wA//4D//wAB//4A//wB//gAA//4A//gA//gAAf/4A//gA//AAAf/4A//gA//gAAf/4A//wB//gAA//4A///P//8AH//4Af//////////wAf//////////wAf//////////wAf//////////wAf//////////gAP//////////gAP//////////AAH//////////AAD/////////+AAD///+/////8AAB///8f////wAAAf//4P////AAAAH//wD///8AAAAA/+AAf//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//gAAAAAAAAB///+AA/+AAAAP////gA//wAAAf////wA//4AAB/////4A//8AAD/////8A//+AAD/////+A///AAH/////+A///AAP//////A///gAP//////A///gAf//////A///wAf//////A///wAf//////A///wAf//////A///wA///////AB//4A//4AD//AAP/4A//gAB//AAP/4A//gAA//AAP/4A//gAA/+AAP/4A//gAB/8AAP/4A//wAB/8AAf/4Af//////////wAf//////////wAf//////////wAf//////////wAf//////////wAP//////////gAP//////////gAH//////////AAH/////////+AAD/////////8AAB/////////4AAAf////////wAAAP////////AAAAB///////4AAAAAD/////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/AAB/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="), 46, atob("EiAnGicnJycnJycnEw=="), 78 + (scale << 8) + (1 << 16)); }; -Graphics.prototype.setFontAntonSmall = function(scale) { - // Actual height 53 (52 - 0) - g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAAAAAAAAAAAAAMAAAAAAAAD8AAAAAAAA/8AAAAAAAf/8AAAAAAH//8AAAAAB///8AAAAA////8AAAAP////8AAAD/////8AAB//////8AAf//////8AH///////4A///////+AA///////AAA//////wAAA/////8AAAA////+AAAAA////gAAAAA///4AAAAAA//8AAAAAAA//AAAAAAAA/wAAAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/////wAAA//////8AAB//////+AAH///////gAH///////gAP///////wAf///////4Af///////4A////////8A////////8A////////8A//AAAAD/8A/8AAAAA/8A/8AAAAA/8A/8AAAAA/8A/+AAAAB/8A////////8A////////8A////////8Af///////4Af///////4AP///////wAP///////wAH///////gAD///////AAA//////8AAAP/////wAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAA/4AAAAAAAA/4AAAAAAAB/wAAAAAAAB/wAAAAAAAD/wAAAAAAAD/gAAAAAAAH///////8AP///////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/4AAAP8AA//4AAA/8AB//4AAH/8AH//4AAP/8AP//4AA//8AP//4AB//8Af//4AD//8Af//4AP//8A///4Af//8A///4A///8A///4D///8A//AAH///8A/8AAP///8A/8AA//+/8A/8AD//8/8A/+Af//w/8A//////g/8A/////+A/8A/////8A/8Af////4A/8Af////wA/8AP////AA/8AP///+AA/8AH///8AA/8AD///wAA/8AA///AAA/8AAP/4AAA/8AAAAAAAAAAAAAAAAAAAAAAH4AAf/gAAA/4AAf/8AAD/4AAf//AAH/4AAf//gAP/4AAf//wAP/4AAf//wAf/4AAf//4Af/4AAf//4A//4AAf//8A//4AAf//8A//4AAP//8A//A/8AB/8A/8A/8AA/8A/8B/8AA/8A/8B/8AA/8A/+D//AB/8A////////8A////////8A////////8Af///////4Af///////4Af///////wAP///////gAH//9////gAD//4///+AAB//wf//4AAAP/AH//gAAAAAAAAAAAAAAAAAAAAAAAAAAAH/wAAAAAAB//wAAAAAAP//wAAAAAD///wAAAAA////wAAAAH////wAAAB/////wAAAf/////wAAD//////wAA///////wAA/////h/wAA////wB/wAA///8AB/wAA///AAB/wAA//gAAB/wAA////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8AAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAAAAAAAAAAAAAAAAAAAAAP/4AA////4P/+AA////4P//AA////4P//gA////4P//wA////4P//wA////4P//4A////4P//4A////4P//8A////4P//8A////4P//8A/8H/AAB/8A/8H+AAA/8A/8P+AAA/8A/8P+AAA/8A/8P/gAD/8A/8P/////8A/8P/////8A/8P/////8A/8P/////4A/8H/////4A/8H/////wA/8D/////wA/8B/////gA/8A////+AA/8AP///4AAAAAB///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////wAAAf/////8AAB///////AAH///////gAP///////wAP///////wAf///////4Af///////4A////////8A////////8A////////8A/+AH/AB/8A/8AP+AA/8A/4Af+AA/8A/8Af+AA/8A/8Af/gH/8A//4f////8A//4f////8A//4f////8Af/4f////4Af/4f////4AP/4P////wAP/4P////gAH/4H////AAD/4D///+AAB/4B///4AAAP4AP//gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/8AAAAAAAA/8AAAAAAAA/8AAAAAB8A/8AAAAB/8A/8AAAAf/8A/8AAAH//8A/8AAA///8A/8AAH///8A/8AA////8A/8AD////8A/8Af////8A/8B/////8A/8P/////8A/8//////8A////////AA///////AAA//////gAAA/////4AAAA/////AAAAA////4AAAAA////AAAAAA///8AAAAAA///gAAAAAA//+AAAAAAA//wAAAAAAA/+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/gD//gAAA//4P//8AAD//8f///AAH//+////gAH///////wAP///////4AP///////8Af///////8Af///////+Af///////+A////////+A//B//AB/+A/+A/+AA/+A/8Af+AA/+A/+Af+AA/+A//A//AB/+A////////+Af///////+Af///////+Af///////8Af///////8AP///////4AH///////4AH//+////wAD//+////AAA//4P//+AAAP/gH//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//gAfgAAA///8A/8AAB///+A//AAH////A//gAH////g//wAP////g//wAf////w//4Af////w//4A/////w//8A/////w//8A/////w//8A//gP/wA/8A/8AD/wA/8A/8AD/wAf8A/8AD/gA/8A/+AH/AB/8A////////8A////////8A////////8Af///////4Af///////4Af///////wAP///////wAH///////gAD//////+AAA//////4AAAP/////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="), 46, atob("DhgeFB4eHh4eHh4eDw=="), 60 + (scale << 8) + (1 << 16)); -}; +{ // must be inside our own scope here so that when we are unloaded everything disappears + // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global +let drawTimeout; -// variables defined from settings -var secondsMode; -var secondsColoured; -var secondsWithColon; -var dateOnMain; -var dateOnSecs; -var weekDay; -var calWeek; -var upperCase; -var vectorFont; +// Actually draw the watch face +let draw = function() { + var x = g.getWidth() / 2; + var y = g.getHeight() / 2; + g.reset().clearRect(Bangle.appRect); // clear whole background (w/o widgets) + var date = new Date(); + var timeStr = require("locale").time(date, 1); // Hour and minute + g.setFontAlign(0, 0).setFont("Anton").drawString(timeStr, x, y); + // Show date and day of week + var dateStr = require("locale").date(date, 0).toUpperCase()+"\n"+ + require("locale").dow(date, 0).toUpperCase(); + g.setFontAlign(0, 0).setFont("6x8", 2).drawString(dateStr, x, y+48); -// dynamic variables -var drawTimeout; -var queueMillis = 1000; -var secondsScreen = true; - -var isBangle1 = (process.env.HWVERSION == 1); - -//For development purposes -/* -require('Storage').writeJSON(SETTINGSFILE, { - secondsMode: "Unlocked", // "Never", "Unlocked", "Always" - secondsColoured: true, - secondsWithColon: true, - dateOnMain: "Long", // "Short", "Long", "ISO8601" - dateOnSecs: "Year", // "No", "Year", "Weekday", LEGACY: true/false - weekDay: true, - calWeek: true, - upperCase: true, - vectorFont: true, -}); -*/ - -// OR (also for development purposes) -/* -require('Storage').erase(SETTINGSFILE); -*/ - -// Load settings -function loadSettings() { - // Helper function default setting - function def (value, def) {return value !== undefined ? value : def;} - - var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; - secondsMode = def(settings.secondsMode, "Never"); - secondsColoured = def(settings.secondsColoured, true); - secondsWithColon = def(settings.secondsWithColon, true); - dateOnMain = def(settings.dateOnMain, "Long"); - dateOnSecs = def(settings.dateOnSecs, "Year"); - weekDay = def(settings.weekDay, true); - calWeek = def(settings.calWeek, false); - upperCase = def(settings.upperCase, true); - vectorFont = def(settings.vectorFont, false); - - // Legacy - if (dateOnSecs === true) - dateOnSecs = "Year"; - if (dateOnSecs === false) - dateOnSecs = "No"; -} - -// schedule a draw for the next second or minute -function queueDraw() { + // queue next draw if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = setTimeout(function() { drawTimeout = undefined; draw(); - }, queueMillis - (Date.now() % queueMillis)); -} + }, 60000 - (Date.now() % 60000)); +}; -function updateState() { - if (Bangle.isLCDOn()) { - if ((secondsMode === "Unlocked" && !Bangle.isLocked()) || secondsMode === "Always") { - secondsScreen = true; - queueMillis = 1000; - } else { - secondsScreen = false; - queueMillis = 60000; - } - draw(); // draw immediately, queue redraw - } else { // stop draw timer +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = undefined; - } -} - -function isoStr(date) { - return date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2); -} - -var calWeekBuffer = [false,false,false]; //buffer tz, date, week no (once calculated until other tz or date is requested) -function ISO8601calWeek(date) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480 - dateNoTime = date; dateNoTime.setHours(0,0,0,0); - if (calWeekBuffer[0] === date.getTimezoneOffset() && calWeekBuffer[1] === dateNoTime) return calWeekBuffer[2]; - calWeekBuffer[0] = date.getTimezoneOffset(); - calWeekBuffer[1] = dateNoTime; - var tdt = new Date(date.valueOf()); - var dayn = (date.getDay() + 6) % 7; - tdt.setDate(tdt.getDate() - dayn + 3); - var firstThursday = tdt.valueOf(); - tdt.setMonth(0, 1); - if (tdt.getDay() !== 4) { - tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7); - } - calWeekBuffer[2] = 1 + Math.ceil((firstThursday - tdt) / 604800000); - return calWeekBuffer[2]; -} - -function doColor() { - return !isBangle1 && !Bangle.isLocked() && secondsColoured; -} - -// Actually draw the watch face -function draw() { - var x = g.getWidth() / 2; - var y = g.getHeight() / 2 - (secondsMode !== "Never" ? 24 : (vectorFont ? 12 : 0)); - g.reset(); - /* This is to mark the widget areas during development. - g.setColor("#888") - .fillRect(0, 0, g.getWidth(), 23) - .fillRect(0, g.getHeight() - 23, g.getWidth(), g.getHeight()).reset(); - /* */ - g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24); // clear whole background (w/o widgets) - var date = new Date(); // Actually the current date, this one is shown - var timeStr = require("locale").time(date, 1); // Hour and minute - g.setFontAlign(0, 0).setFont("Anton").drawString(timeStr, x, y); // draw time - if (secondsScreen) { - y += 65; - var secStr = (secondsWithColon ? ":" : "") + ("0" + date.getSeconds()).slice(-2); - if (doColor()) - g.setColor(0, 0, 1); - g.setFont("AntonSmall"); - if (dateOnSecs !== "No") { // A bit of a complex drawing with seconds on the right and date on the left - g.setFontAlign(1, 0).drawString(secStr, g.getWidth() - (isBangle1 ? 32 : 2), y); // seconds - y -= (vectorFont ? 15 : 13); - x = g.getWidth() / 4 + (isBangle1 ? 12 : 4) + (secondsWithColon ? 0 : g.stringWidth(":") / 2); - var dateStr2 = (dateOnMain === "ISO8601" ? isoStr(date) : require("locale").date(date, 1)); - var year; - var md; - var yearfirst; - if (dateStr2.match(/\d\d\d\d$/)) { // formatted date ends with year - year = (dateOnSecs === "Year" ? dateStr2.slice(-4) : require("locale").dow(date, 1)); - md = dateStr2.slice(0, -4); - if (!md.endsWith(".")) // keep separator before the year only if it is a dot (31.12. but 31/12) - md = md.slice(0, -1); - yearfirst = false; - } else { // formatted date begins with year - if (!dateStr2.match(/^\d\d\d\d/)) // if year position cannot be detected... - dateStr2 = isoStr(date); // ...use ISO date format instead - year = (dateOnSecs === "Year" ? dateStr2.slice(0, 4) : require("locale").dow(date, 1)); - md = dateStr2.slice(5); // never keep separator directly after year - yearfirst = true; - } - if (dateOnSecs === "Weekday" && upperCase) - year = year.toUpperCase(); - g.setFontAlign(0, 0); - if (vectorFont) - g.setFont("Vector", 24); - else - g.setFont("6x8", 2); - if (doColor()) - g.setColor(1, 0, 0); - g.drawString(md, x, (yearfirst ? y + (vectorFont ? 26 : 16) : y)); - g.drawString(year, x, (yearfirst ? y : y + (vectorFont ? 26 : 16))); - } else { - g.setFontAlign(0, 0).drawString(secStr, x, y); // Just the seconds centered - } - } else { // No seconds screen: Show date and optionally day of week - y += (vectorFont ? 50 : (secondsMode !== "Never") ? 52 : 40); - var dateStr = (dateOnMain === "ISO8601" ? isoStr(date) : require("locale").date(date, (dateOnMain === "Long" ? 0 : 1))); - if (upperCase) - dateStr = dateStr.toUpperCase(); - g.setFontAlign(0, 0); - if (vectorFont) - g.setFont("Vector", 24); - else - g.setFont("6x8", 2); - g.drawString(dateStr, x, y); - if (calWeek || weekDay) { - var dowcwStr = ""; - if (calWeek) - dowcwStr = " #" + ("0" + ISO8601calWeek(date)).slice(-2); - if (weekDay) - dowcwStr = require("locale").dow(date, calWeek ? 1 : 0) + dowcwStr; //weekDay e.g. Monday or weekDayShort # e.g. Mon #01 - else //week #01 - dowcwStr = /*LANG*/"week" + dowcwStr; - if (upperCase) - dowcwStr = dowcwStr.toUpperCase(); - g.drawString(dowcwStr, x, y + (vectorFont ? 26 : 16)); - } - } - - // queue next draw - queueDraw(); -} - -// Init the settings of the app -loadSettings(); -// Clear the screen once, at startup -g.clear(); -// Set dynamic state and perform initial drawing -updateState(); -// Register hooks for LCD on/off event and screen lock on/off event -Bangle.on('lcdPower', on => { - updateState(); -}); -Bangle.on('lock', on => { - updateState(); -}); -// Show launcher when middle button pressed -Bangle.setUI("clock"); + delete Graphics.prototype.setFontAnton; + }}); // Load widgets Bangle.loadWidgets(); -Bangle.drawWidgets(); - -// end of file \ No newline at end of file +draw(); +setTimeout(Bangle.drawWidgets,0); +} diff --git a/apps/antonclk/app.png b/apps/antonclk/app.png index a38093c5f..bb764d2a1 100644 Binary files a/apps/antonclk/app.png and b/apps/antonclk/app.png differ diff --git a/apps/antonclk/metadata.json b/apps/antonclk/metadata.json index 16bdf3aa8..b8242f11a 100644 --- a/apps/antonclk/metadata.json +++ b/apps/antonclk/metadata.json @@ -1,9 +1,8 @@ { "id": "antonclk", "name": "Anton Clock", - "version": "0.09", - "description": "A clock using the bold Anton font, optionally showing seconds and date in ISO-8601 format.", - "readme":"README.md", + "version": "0.11", + "description": "A simple clock using the bold Anton font. See `Anton Clock Plus` for an enhanced version", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], "type": "clock", @@ -12,8 +11,6 @@ "allow_emulator": true, "storage": [ {"name":"antonclk.app.js","url":"app.js"}, - {"name":"antonclk.settings.js","url":"settings.js"}, {"name":"antonclk.img","url":"app-icon.js","evaluate":true} - ], - "data": [{"name":"antonclk.json"}] + ] } diff --git a/apps/antonclk/screenshot.png b/apps/antonclk/screenshot.png index e949b8a24..9b38e90d5 100644 Binary files a/apps/antonclk/screenshot.png and b/apps/antonclk/screenshot.png differ diff --git a/apps/antonclkplus/ChangeLog b/apps/antonclkplus/ChangeLog new file mode 100644 index 000000000..3b0a3d8b8 --- /dev/null +++ b/apps/antonclkplus/ChangeLog @@ -0,0 +1,15 @@ +0.01: New App! +0.02: Load widgets after setUI so widclk knows when to hide +0.03: Clock now shows day of week under date. +0.04: Clock can optionally show seconds, date optionally in ISO-8601 format, weekdays and uppercase configurable, too. +0.05: Clock can optionally show ISO-8601 calendar weeknumber (default: Off) + when weekday name "Off": week #: + when weekday name "On": weekday name is cut at 6th position and .# is added +0.06: fixes #1271 - wrong settings name + when weekday name and calendar weeknumber are on then display is # + week is buffered until date or timezone changes +0.07: align default settings with app.js (otherwise the initial displayed settings will be confusing to users) +0.08: fixed calendar weeknumber not shortened to two digits +0.09: Use default Bangle formatter for booleans +0.10: Use Bangle.setUI({remove:...}) to allow loading the launcher without a full reset on 2v16 + Modified to avoid leaving functions defined when using setUI({remove:...}) diff --git a/apps/antonclk/README.md b/apps/antonclkplus/README.md similarity index 87% rename from apps/antonclk/README.md rename to apps/antonclkplus/README.md index 28a38f5fd..25b478dd9 100644 --- a/apps/antonclk/README.md +++ b/apps/antonclkplus/README.md @@ -1,6 +1,6 @@ -# Anton Clock - Large font digital watch with seconds and date +# Anton Clock Plus - Large font digital watch with seconds and date -Anton clock uses the "Anton" bold font to show the time in a clear, easily readable manner. On the Bangle.js 2, the time can be read easily even if the screen is locked and unlit. +Anton Clock Plus uses the "Anton" bold font to show the time in a clear, easily readable manner. On the Bangle.js 2, the time can be read easily even if the screen is locked and unlit. ## Features @@ -16,16 +16,16 @@ The basic time representation only shows hours and minutes of the current time. ## Usage -Install Anton clock through the Bangle.js app loader. -Configure it through the default Bangle.js configuration mechanism +* Install Anton Clock Plus through the Bangle.js app loader. +* Configure it through the default Bangle.js configuration mechanism (Settings app, "Apps" menu, "Anton clock" submenu). -If you like it, make it your default watch face +* If you like it, make it your default watch face (Settings app, "System" menu, "Clock" submenu, select "Anton clock"). ## Configuration -Anton clock is configured by the standard settings mechanism of Bangle.js's operating system: -Open the "Settings" app, then the "Apps" submenu and below it the "Anton clock" menu. +Anton Clock is configured by the standard settings mechanism of Bangle.js's operating system: +Open the `Settings` app, then the `Apps` submenu and below it the `Anton Clock+` menu. You configure Anton clock through several "on/off" switches in two menus. ### The main menu diff --git a/apps/antonclkplus/app-icon.js b/apps/antonclkplus/app-icon.js new file mode 100644 index 000000000..0c3aeb210 --- /dev/null +++ b/apps/antonclkplus/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwgf/AH4At/l/Aofgh4DB+EAj4REQoM/AgP4AoeACIoLCg4FB4AFDCIwLCgAROgYIB8EBAoUH/gVBCIxQBCKYHBCJp9DI4ICBLJYRCn4RQEYMOR5ARDIgIRMYQZZBgARGZwZBDCKQrCgEDR5AdBUIQRJDoLXFCJD7J/xrICIQFCn4RH/4LDAoTaCCI4Ar/LLDCBfypMkCgMkyV/CJOSCIOf5IRGFwOfCJNP//JnmT588z/+pM/BYIRCk4RC/88+f/n4RCngRCz1JCIf5/nzGoQRIHwXPCIPJI4f8CJHJGQJKCCI59LCI5ZCCJ/+v/kBoM/+V/HIJrHBYJWB/JKB5x9JEYP8AQKdBpwRL841Dp41KZoTxBHYTXBWY77PCKKhJ/4/CcgMkXoQAiA=")) diff --git a/apps/antonclkplus/app.js b/apps/antonclkplus/app.js new file mode 100644 index 000000000..409d7d487 --- /dev/null +++ b/apps/antonclkplus/app.js @@ -0,0 +1,238 @@ +// Clock with large digits using the "Anton" bold font +Graphics.prototype.setFontAnton = function(scale) { + // Actual height 69 (68 - 0) + g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAA/gAAAAAAAAAAP/gAAAAAAAAAH//gAAAAAAAAB///gAAAAAAAAf///gAAAAAAAP////gAAAAAAD/////gAAAAAA//////gAAAAAP//////gAAAAH///////gAAAB////////gAAAf////////gAAP/////////gAD//////////AA//////////gAA/////////4AAA////////+AAAA////////gAAAA///////wAAAAA//////8AAAAAA//////AAAAAAA/////gAAAAAAA////4AAAAAAAA///+AAAAAAAAA///gAAAAAAAAA//wAAAAAAAAAA/8AAAAAAAAAAA/AAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////AAAAAB///////8AAAAH////////AAAAf////////wAAA/////////4AAB/////////8AAD/////////+AAH//////////AAP//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wA//8AAAAAB//4A//wAAAAAAf/4A//gAAAAAAP/4A//gAAAAAAP/4A//gAAAAAAP/4A//wAAAAAAf/4A///////////4Af//////////wAf//////////wAf//////////wAf//////////wAP//////////gAP//////////gAH//////////AAH//////////AAD/////////+AAB/////////8AAA/////////4AAAP////////gAAAD///////+AAAAAf//////4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/gAAAAAAAAAAP/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/AAAAAAAAAAA//AAAAAAAAAAA/+AAAAAAAAAAB/8AAAAAAAAAAD//////////gAH//////////gAP//////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/4AAAAB/gAAD//4AAAAf/gAAP//4AAAB//gAA///4AAAH//gAB///4AAAf//gAD///4AAA///gAH///4AAD///gAP///4AAH///gAP///4AAP///gAf///4AAf///gAf///4AB////gAf///4AD////gA////4AH////gA////4Af////gA////4A/////gA//wAAB/////gA//gAAH/////gA//gAAP/////gA//gAA///8//gA//gAD///w//gA//wA////g//gA////////A//gA///////8A//gA///////4A//gAf//////wA//gAf//////gA//gAf/////+AA//gAP/////8AA//gAP/////4AA//gAH/////gAA//gAD/////AAA//gAB////8AAA//gAA////wAAA//gAAP///AAAA//gAAD//8AAAA//gAAAP+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB/+AAAAAD/wAAB//8AAAAP/wAAB///AAAA//wAAB///wAAB//wAAB///4AAD//wAAB///8AAH//wAAB///+AAP//wAAB///+AAP//wAAB////AAf//wAAB////AAf//wAAB////gAf//wAAB////gA///wAAB////gA///wAAB////gA///w//AAf//wA//4A//AAA//wA//gA//AAAf/wA//gB//gAAf/wA//gB//gAAf/wA//gD//wAA//wA//wH//8AB//wA///////////gA///////////gA///////////gA///////////gAf//////////AAf//////////AAP//////////AAP/////////+AAH/////////8AAH///+/////4AAD///+f////wAAA///8P////gAAAf//4H///+AAAAH//gB///wAAAAAP4AAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAA//wAAAAAAAAAP//wAAAAAAAAB///wAAAAAAAAf///wAAAAAAAH////wAAAAAAA/////wAAAAAAP/////wAAAAAB//////wAAAAAf//////wAAAAH///////wAAAA////////wAAAP////////wAAA///////H/wAAA//////wH/wAAA/////8AH/wAAA/////AAH/wAAA////gAAH/wAAA///4AAAH/wAAA//+AAAAH/wAAA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAH/4AAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB//8AAA/////+B///AAA/////+B///wAA/////+B///4AA/////+B///8AA/////+B///8AA/////+B///+AA/////+B////AA/////+B////AA/////+B////AA/////+B////gA/////+B////gA/////+B////gA/////+A////gA//gP/gAAB//wA//gf/AAAA//wA//gf/AAAAf/wA//g//AAAAf/wA//g//AAAA//wA//g//gAAA//wA//g//+AAP//wA//g////////gA//g////////gA//g////////gA//g////////gA//g////////AA//gf///////AA//gf//////+AA//gP//////+AA//gH//////8AA//gD//////4AA//gB//////wAA//gA//////AAAAAAAH////8AAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////gAAAAB///////+AAAAH////////gAAAf////////4AAB/////////8AAD/////////+AAH//////////AAH//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wAf//////////4A//wAD/4AAf/4A//gAH/wAAP/4A//gAH/wAAP/4A//gAP/wAAP/4A//gAP/4AAf/4A//wAP/+AD//4A///wP//////4Af//4P//////wAf//4P//////wAf//4P//////wAf//4P//////wAP//4P//////gAP//4H//////gAH//4H//////AAH//4D/////+AAD//4D/////8AAB//4B/////4AAA//4A/////wAAAP/4AP////AAAAB/4AD///4AAAAAAAAAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//AAAAAAAAAAA//gAAAAAAAAAA//gAAAAAAAAAA//gAAAAAAADgA//gAAAAAAP/gA//gAAAAAH//gA//gAAAAB///gA//gAAAAP///gA//gAAAD////gA//gAAAf////gA//gAAB/////gA//gAAP/////gA//gAB//////gA//gAH//////gA//gA///////gA//gD///////gA//gf///////gA//h////////gA//n////////gA//////////gAA/////////AAAA////////wAAAA///////4AAAAA///////AAAAAA//////4AAAAAA//////AAAAAAA/////4AAAAAAA/////AAAAAAAA////8AAAAAAAA////gAAAAAAAA///+AAAAAAAAA///4AAAAAAAAA///AAAAAAAAAA//4AAAAAAAAAA/+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//gB///wAAAAP//4H///+AAAA///8P////gAAB///+f////4AAD///+/////8AAH/////////+AAH//////////AAP//////////gAP//////////gAf//////////gAf//////////wAf//////////wAf//////////wA///////////wA//4D//wAB//4A//wB//gAA//4A//gA//gAAf/4A//gA//AAAf/4A//gA//gAAf/4A//wB//gAA//4A///P//8AH//4Af//////////wAf//////////wAf//////////wAf//////////wAf//////////gAP//////////gAP//////////AAH//////////AAD/////////+AAD///+/////8AAB///8f////wAAAf//4P////AAAAH//wD///8AAAAA/+AAf//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//gAAAAAAAAB///+AA/+AAAAP////gA//wAAAf////wA//4AAB/////4A//8AAD/////8A//+AAD/////+A///AAH/////+A///AAP//////A///gAP//////A///gAf//////A///wAf//////A///wAf//////A///wAf//////A///wA///////AB//4A//4AD//AAP/4A//gAB//AAP/4A//gAA//AAP/4A//gAA/+AAP/4A//gAB/8AAP/4A//wAB/8AAf/4Af//////////wAf//////////wAf//////////wAf//////////wAf//////////wAP//////////gAP//////////gAH//////////AAH/////////+AAD/////////8AAB/////////4AAAf////////wAAAP////////AAAAB///////4AAAAAD/////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/AAB/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="), 46, atob("EiAnGicnJycnJycnEw=="), 78 + (scale << 8) + (1 << 16)); +}; + +Graphics.prototype.setFontAntonSmall = function(scale) { + // Actual height 53 (52 - 0) + g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAf8AAAAAAAAAAAAAAAAAAAAMAAAAAAAAD8AAAAAAAA/8AAAAAAAf/8AAAAAAH//8AAAAAB///8AAAAA////8AAAAP////8AAAD/////8AAB//////8AAf//////8AH///////4A///////+AA///////AAA//////wAAA/////8AAAA////+AAAAA////gAAAAA///4AAAAAA//8AAAAAAA//AAAAAAAA/wAAAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/////wAAA//////8AAB//////+AAH///////gAH///////gAP///////wAf///////4Af///////4A////////8A////////8A////////8A//AAAAD/8A/8AAAAA/8A/8AAAAA/8A/8AAAAA/8A/+AAAAB/8A////////8A////////8A////////8Af///////4Af///////4AP///////wAP///////wAH///////gAD///////AAA//////8AAAP/////wAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAA/4AAAAAAAA/4AAAAAAAB/wAAAAAAAB/wAAAAAAAD/wAAAAAAAD/gAAAAAAAH///////8AP///////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/4AAAP8AA//4AAA/8AB//4AAH/8AH//4AAP/8AP//4AA//8AP//4AB//8Af//4AD//8Af//4AP//8A///4Af//8A///4A///8A///4D///8A//AAH///8A/8AAP///8A/8AA//+/8A/8AD//8/8A/+Af//w/8A//////g/8A/////+A/8A/////8A/8Af////4A/8Af////wA/8AP////AA/8AP///+AA/8AH///8AA/8AD///wAA/8AA///AAA/8AAP/4AAA/8AAAAAAAAAAAAAAAAAAAAAAH4AAf/gAAA/4AAf/8AAD/4AAf//AAH/4AAf//gAP/4AAf//wAP/4AAf//wAf/4AAf//4Af/4AAf//4A//4AAf//8A//4AAf//8A//4AAP//8A//A/8AB/8A/8A/8AA/8A/8B/8AA/8A/8B/8AA/8A/+D//AB/8A////////8A////////8A////////8Af///////4Af///////4Af///////wAP///////gAH//9////gAD//4///+AAB//wf//4AAAP/AH//gAAAAAAAAAAAAAAAAAAAAAAAAAAAH/wAAAAAAB//wAAAAAAP//wAAAAAD///wAAAAA////wAAAAH////wAAAB/////wAAAf/////wAAD//////wAA///////wAA/////h/wAA////wB/wAA///8AB/wAA///AAB/wAA//gAAB/wAA////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8A////////8AAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAAAAAAAAAAAAAAAAAAAAAP/4AA////4P/+AA////4P//AA////4P//gA////4P//wA////4P//wA////4P//4A////4P//4A////4P//8A////4P//8A////4P//8A/8H/AAB/8A/8H+AAA/8A/8P+AAA/8A/8P+AAA/8A/8P/gAD/8A/8P/////8A/8P/////8A/8P/////8A/8P/////4A/8H/////4A/8H/////wA/8D/////wA/8B/////gA/8A////+AA/8AP///4AAAAAB///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////wAAAf/////8AAB///////AAH///////gAP///////wAP///////wAf///////4Af///////4A////////8A////////8A////////8A/+AH/AB/8A/8AP+AA/8A/4Af+AA/8A/8Af+AA/8A/8Af/gH/8A//4f////8A//4f////8A//4f////8Af/4f////4Af/4f////4AP/4P////wAP/4P////gAH/4H////AAD/4D///+AAB/4B///4AAAP4AP//gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/8AAAAAAAA/8AAAAAAAA/8AAAAAB8A/8AAAAB/8A/8AAAAf/8A/8AAAH//8A/8AAA///8A/8AAH///8A/8AA////8A/8AD////8A/8Af////8A/8B/////8A/8P/////8A/8//////8A////////AA///////AAA//////gAAA/////4AAAA/////AAAAA////4AAAAA////AAAAAA///8AAAAAA///gAAAAAA//+AAAAAAA//wAAAAAAA/+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/gD//gAAA//4P//8AAD//8f///AAH//+////gAH///////wAP///////4AP///////8Af///////8Af///////+Af///////+A////////+A//B//AB/+A/+A/+AA/+A/8Af+AA/+A/+Af+AA/+A//A//AB/+A////////+Af///////+Af///////+Af///////8Af///////8AP///////4AH///////4AH//+////wAD//+////AAA//4P//+AAAP/gH//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//gAfgAAA///8A/8AAB///+A//AAH////A//gAH////g//wAP////g//wAf////w//4Af////w//4A/////w//8A/////w//8A/////w//8A//gP/wA/8A/8AD/wA/8A/8AD/wAf8A/8AD/gA/8A/+AH/AB/8A////////8A////////8A////////8Af///////4Af///////4Af///////wAP///////wAH///////gAD//////+AAA//////4AAAP/////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAP+AA/4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="), 46, atob("DhgeFB4eHh4eHh4eDw=="), 60 + (scale << 8) + (1 << 16)); +}; + +{ // must be inside our own scope here so that when we are unloaded everything disappears + // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global + +const SETTINGSFILE = "antonclk.json"; +const isBangle1 = (process.env.HWVERSION == 1); + +// variables defined from settings +let secondsMode; +let secondsColoured; +let secondsWithColon; +let dateOnMain; +let dateOnSecs; +let weekDay; +let calWeek; +let upperCase; +let vectorFont; + +// dynamic variables +let drawTimeout; +let queueMillis = 1000; +let secondsScreen = true; + + + +//For development purposes +/* +require('Storage').writeJSON(SETTINGSFILE, { + secondsMode: "Unlocked", // "Never", "Unlocked", "Always" + secondsColoured: true, + secondsWithColon: true, + dateOnMain: "Long", // "Short", "Long", "ISO8601" + dateOnSecs: "Year", // "No", "Year", "Weekday", LEGACY: true/false + weekDay: true, + calWeek: true, + upperCase: true, + vectorFont: true, +}); +*/ + +// OR (also for development purposes) +/* +require('Storage').erase(SETTINGSFILE); +*/ + +// Load settings +let loadSettings = function() { + // Helper function default setting + function def (value, def) {return value !== undefined ? value : def;} + + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; + secondsMode = def(settings.secondsMode, "Never"); + secondsColoured = def(settings.secondsColoured, true); + secondsWithColon = def(settings.secondsWithColon, true); + dateOnMain = def(settings.dateOnMain, "Long"); + dateOnSecs = def(settings.dateOnSecs, "Year"); + weekDay = def(settings.weekDay, true); + calWeek = def(settings.calWeek, false); + upperCase = def(settings.upperCase, true); + vectorFont = def(settings.vectorFont, false); + + // Legacy + if (dateOnSecs === true) + dateOnSecs = "Year"; + if (dateOnSecs === false) + dateOnSecs = "No"; +} + +// schedule a draw for the next second or minute +let queueDraw = function() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, queueMillis - (Date.now() % queueMillis)); +} + +let updateState = function() { + if (Bangle.isLCDOn()) { + if ((secondsMode === "Unlocked" && !Bangle.isLocked()) || secondsMode === "Always") { + secondsScreen = true; + queueMillis = 1000; + } else { + secondsScreen = false; + queueMillis = 60000; + } + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +} + +let isoStr = function(date) { + return date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2); +} + +let calWeekBuffer = [false,false,false]; //buffer tz, date, week no (once calculated until other tz or date is requested) +let ISO8601calWeek = function(date) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480 + dateNoTime = date; dateNoTime.setHours(0,0,0,0); + if (calWeekBuffer[0] === date.getTimezoneOffset() && calWeekBuffer[1] === dateNoTime) return calWeekBuffer[2]; + calWeekBuffer[0] = date.getTimezoneOffset(); + calWeekBuffer[1] = dateNoTime; + var tdt = new Date(date.valueOf()); + var dayn = (date.getDay() + 6) % 7; + tdt.setDate(tdt.getDate() - dayn + 3); + var firstThursday = tdt.valueOf(); + tdt.setMonth(0, 1); + if (tdt.getDay() !== 4) { + tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7); + } + calWeekBuffer[2] = 1 + Math.ceil((firstThursday - tdt) / 604800000); + return calWeekBuffer[2]; +} + +let doColor = function() { + return !isBangle1 && !Bangle.isLocked() && secondsColoured; +} + +// Actually draw the watch face +let draw = function() { + var x = g.getWidth() / 2; + var y = g.getHeight() / 2 - (secondsMode !== "Never" ? 24 : (vectorFont ? 12 : 0)); + g.reset(); + /* This is to mark the widget areas during development. + g.setColor("#888") + .fillRect(0, 0, g.getWidth(), 23) + .fillRect(0, g.getHeight() - 23, g.getWidth(), g.getHeight()).reset(); + /* */ + g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24); // clear whole background (w/o widgets) + var date = new Date(); // Actually the current date, this one is shown + var timeStr = require("locale").time(date, 1); // Hour and minute + g.setFontAlign(0, 0).setFont("Anton").drawString(timeStr, x, y); // draw time + if (secondsScreen) { + y += 65; + var secStr = (secondsWithColon ? ":" : "") + ("0" + date.getSeconds()).slice(-2); + if (doColor()) + g.setColor(0, 0, 1); + g.setFont("AntonSmall"); + if (dateOnSecs !== "No") { // A bit of a complex drawing with seconds on the right and date on the left + g.setFontAlign(1, 0).drawString(secStr, g.getWidth() - (isBangle1 ? 32 : 2), y); // seconds + y -= (vectorFont ? 15 : 13); + x = g.getWidth() / 4 + (isBangle1 ? 12 : 4) + (secondsWithColon ? 0 : g.stringWidth(":") / 2); + var dateStr2 = (dateOnMain === "ISO8601" ? isoStr(date) : require("locale").date(date, 1)); + var year; + var md; + var yearfirst; + if (dateStr2.match(/\d\d\d\d$/)) { // formatted date ends with year + year = (dateOnSecs === "Year" ? dateStr2.slice(-4) : require("locale").dow(date, 1)); + md = dateStr2.slice(0, -4); + if (!md.endsWith(".")) // keep separator before the year only if it is a dot (31.12. but 31/12) + md = md.slice(0, -1); + yearfirst = false; + } else { // formatted date begins with year + if (!dateStr2.match(/^\d\d\d\d/)) // if year position cannot be detected... + dateStr2 = isoStr(date); // ...use ISO date format instead + year = (dateOnSecs === "Year" ? dateStr2.slice(0, 4) : require("locale").dow(date, 1)); + md = dateStr2.slice(5); // never keep separator directly after year + yearfirst = true; + } + if (dateOnSecs === "Weekday" && upperCase) + year = year.toUpperCase(); + g.setFontAlign(0, 0); + if (vectorFont) + g.setFont("Vector", 24); + else + g.setFont("6x8", 2); + if (doColor()) + g.setColor(1, 0, 0); + g.drawString(md, x, (yearfirst ? y + (vectorFont ? 26 : 16) : y)); + g.drawString(year, x, (yearfirst ? y : y + (vectorFont ? 26 : 16))); + } else { + g.setFontAlign(0, 0).drawString(secStr, x, y); // Just the seconds centered + } + } else { // No seconds screen: Show date and optionally day of week + y += (vectorFont ? 50 : (secondsMode !== "Never") ? 52 : 40); + var dateStr = (dateOnMain === "ISO8601" ? isoStr(date) : require("locale").date(date, (dateOnMain === "Long" ? 0 : 1))); + if (upperCase) + dateStr = dateStr.toUpperCase(); + g.setFontAlign(0, 0); + if (vectorFont) + g.setFont("Vector", 24); + else + g.setFont("6x8", 2); + g.drawString(dateStr, x, y); + if (calWeek || weekDay) { + var dowcwStr = ""; + if (calWeek) + dowcwStr = " #" + ("0" + ISO8601calWeek(date)).slice(-2); + if (weekDay) + dowcwStr = require("locale").dow(date, calWeek ? 1 : 0) + dowcwStr; //weekDay e.g. Monday or weekDayShort # e.g. Mon #01 + else //week #01 + dowcwStr = /*LANG*/"week" + dowcwStr; + if (upperCase) + dowcwStr = dowcwStr.toUpperCase(); + g.drawString(dowcwStr, x, y + (vectorFont ? 26 : 16)); + } + } + + // queue next draw + queueDraw(); +} + +// Init the settings of the app +loadSettings(); +// Clear the screen once, at startup +g.clear(); +// Set dynamic state and perform initial drawing +updateState(); +// Register hooks for LCD on/off event and screen lock on/off event +Bangle.on('lcdPower', updateState); +Bangle.on('lock', updateState); +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app + Bangle.removeListener('lcdPower', updateState); + Bangle.removeListener('lock', updateState); + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFontAnton; + delete Graphics.prototype.setFontAntonSmall; + }}); +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); +} diff --git a/apps/antonclkplus/app.png b/apps/antonclkplus/app.png new file mode 100644 index 000000000..a38093c5f Binary files /dev/null and b/apps/antonclkplus/app.png differ diff --git a/apps/antonclkplus/metadata.json b/apps/antonclkplus/metadata.json new file mode 100644 index 000000000..05c59a4fb --- /dev/null +++ b/apps/antonclkplus/metadata.json @@ -0,0 +1,20 @@ +{ + "id": "antonclkplus", + "name": "Anton Clock Plus", + "shortName": "Anton Clock+", + "version": "0.10", + "description": "A clock using the bold Anton font, optionally showing seconds and date in ISO-8601 format.", + "readme":"README.md", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock", + "supports": ["BANGLEJS","BANGLEJS2"], + "allow_emulator": true, + "storage": [ + {"name":"antonclkplus.app.js","url":"app.js"}, + {"name":"antonclkplus.settings.js","url":"settings.js"}, + {"name":"antonclkplus.img","url":"app-icon.js","evaluate":true} + ], + "data": [{"name":"antonclkplus.json"}] +} diff --git a/apps/antonclkplus/screenshot.png b/apps/antonclkplus/screenshot.png new file mode 100644 index 000000000..e949b8a24 Binary files /dev/null and b/apps/antonclkplus/screenshot.png differ diff --git a/apps/antonclk/settings.js b/apps/antonclkplus/settings.js similarity index 100% rename from apps/antonclk/settings.js rename to apps/antonclkplus/settings.js diff --git a/apps/aptsciclk/metadata.json b/apps/aptsciclk/metadata.json index c450d926e..77e40f843 100644 --- a/apps/aptsciclk/metadata.json +++ b/apps/aptsciclk/metadata.json @@ -5,6 +5,7 @@ "version": "0.08", "description": "A clock based on the portal series", "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], "type": "clock", "tags": "clock", "supports": ["BANGLEJS2"], diff --git a/apps/aptsciclk/screenshot.png b/apps/aptsciclk/screenshot.png new file mode 100644 index 000000000..4803e4b13 Binary files /dev/null and b/apps/aptsciclk/screenshot.png differ diff --git a/apps/assistedgps/metadata.json b/apps/assistedgps/metadata.json index 1dbc42c87..4c91dcd35 100644 --- a/apps/assistedgps/metadata.json +++ b/apps/assistedgps/metadata.json @@ -1,11 +1,12 @@ { "id": "assistedgps", - "name": "Assisted GPS Update (AGPS)", + "name": "Assisted GPS Updater (AGPS)", "version": "0.03", - "description": "Downloads assisted GPS (AGPS) data to Bangle.js 1 or 2 for faster GPS startup and more accurate fixes. **No app will be installed**, this just uploads new data to the GPS chip.", + "description": "Downloads assisted GPS (AGPS) data to Bangle.js for faster GPS startup and more accurate fixes. **No app will be installed**, this just uploads new data to the GPS chip.", + "sortorder": -1, "icon": "app.png", "type": "RAM", - "tags": "tool,outdoors,agps", + "tags": "tool,outdoors,agps,gps,a-gps", "supports": ["BANGLEJS","BANGLEJS2"], "custom": "custom.html", "customConnect": true, diff --git a/apps/astral/ChangeLog b/apps/astral/ChangeLog index a51c96760..747e5ac2e 100644 --- a/apps/astral/ChangeLog +++ b/apps/astral/ChangeLog @@ -1,3 +1,5 @@ 0.01: Create astral clock app 0.02: Fixed Whirlpool galaxy RA/DA, larger compass display, fixed moonphase overlapping battery widget 0.03: Update to use Bangle.setUI instead of setWatch +0.04: Tell clock widgets to hide. +0.05: Added adjustment for Bangle.js magnetometer heading fix diff --git a/apps/astral/app.js b/apps/astral/app.js index c445463f2..a435ca9e3 100644 --- a/apps/astral/app.js +++ b/apps/astral/app.js @@ -767,6 +767,24 @@ function draw() { g.clear(); current_moonphase = getMoonPhase(); +Bangle.setUI("clockupdown", btn => { + if (btn==0) { + if (!processing) { + if (!modeswitch) { + modeswitch = true; + if (mode == "planetary") mode = "extras"; + else mode = "planetary"; + } + else + modeswitch = false; + } + } else { + if (!processing) + ready_to_compute = true; + } +}); + + // Load widgets Bangle.loadWidgets(); Bangle.drawWidgets(); @@ -799,23 +817,6 @@ Bangle.setGPSPower(1); // Show launcher when button pressed Bangle.setClockMode(); -Bangle.setUI("clockupdown", btn => { - if (btn==0) { - if (!processing) { - if (!modeswitch) { - modeswitch = true; - if (mode == "planetary") mode = "extras"; - else mode = "planetary"; - } - else - modeswitch = false; - } - } else { - if (!processing) - ready_to_compute = true; - } -}); - setWatch(function () { if (!astral_settings.astral_default) { colours_switched = true; @@ -833,7 +834,7 @@ Bangle.on('mag', function (m) { if (isNaN(m.heading)) compass_heading = "---"; else - compass_heading = 360 - Math.round(m.heading); + compass_heading = Math.round(m.heading); // g.setColor("#000000"); // g.fillRect(160, 10, 160, 20); g.setColor(display_colour); diff --git a/apps/astral/metadata.json b/apps/astral/metadata.json index 3317092db..647066a13 100644 --- a/apps/astral/metadata.json +++ b/apps/astral/metadata.json @@ -1,7 +1,7 @@ { "id": "astral", "name": "Astral Clock", - "version": "0.03", + "version": "0.05", "description": "Clock that calculates and displays Alt Az positions of all planets, Sun as well as several other astronomy targets (customizable) and current Moon phase. Coordinates are calculated by GPS & time and onscreen compass assists orienting. See Readme before using.", "icon": "app-icon.png", "type": "clock", diff --git a/apps/astrocalc/ChangeLog b/apps/astrocalc/ChangeLog index 60ef5da0a..11b2d7177 100644 --- a/apps/astrocalc/ChangeLog +++ b/apps/astrocalc/ChangeLog @@ -1,2 +1,4 @@ 0.01: Create astrocalc app 0.02: Store last GPS lock, can be used instead of waiting for new GPS on start +0.03: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps +0.04: Compatibility with Bangle.js 2, get location from My Location diff --git a/apps/astrocalc/astrocalc-app.js b/apps/astrocalc/astrocalc-app.js index 4e7aa0b40..6629842cf 100644 --- a/apps/astrocalc/astrocalc-app.js +++ b/apps/astrocalc/astrocalc-app.js @@ -9,10 +9,9 @@ * Calculate the Sun and Moon positions based on watch GPS and display graphically */ -const SunCalc = require("suncalc.js"); +const SunCalc = require("suncalc"); // from modules folder const storage = require("Storage"); -const LAST_GPS_FILE = "astrocalc.gps.json"; -let lastGPS = (storage.readJSON(LAST_GPS_FILE, 1) || null); +const BANGLEJS2 = process.env.HWVERSION == 2; // check for bangle 2 function drawMoon(phase, x, y) { const moonImgFiles = [ @@ -73,7 +72,7 @@ function drawTitle(key) { */ function drawPoint(angle, radius, color) { const pRad = Math.PI / 180; - const faceWidth = 80; // watch face radius + const faceWidth = g.getWidth()/3; // watch face radius const centerPx = g.getWidth() / 2; const a = angle * pRad; @@ -141,6 +140,7 @@ function drawData(title, obj, startX, startY) { function drawMoonPositionPage(gps, title) { const pos = SunCalc.getMoonPosition(new Date(), gps.lat, gps.lon); + const moonColor = g.theme.dark ? {r: 1, g: 1, b: 1} : {r: 0, g: 0, b: 0}; const pageData = { Azimuth: pos.azimuth.toFixed(2), @@ -150,59 +150,61 @@ function drawMoonPositionPage(gps, title) { }; const azimuthDegrees = parseInt(pos.azimuth * 180 / Math.PI); - drawData(title, pageData, null, 80); + drawData(title, pageData, null, g.getHeight()/2 - Object.keys(pageData).length/2*20); drawPoints(); - drawPoint(azimuthDegrees, 8, {r: 1, g: 1, b: 1}); + drawPoint(azimuthDegrees, 8, moonColor); let m = setWatch(() => { let m = moonIndexPageMenu(gps); - }, BTN3, {repeat: false, edge: "falling"}); + }, BANGLEJS2 ? BTN : BTN3, {repeat: false, edge: "falling"}); } function drawMoonIlluminationPage(gps, title) { const phaseNames = [ - "New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous", - "Full Moon", "Waning Gibbous", "Last Quater", "Waning Crescent", + /*LANG*/"New Moon", /*LANG*/"Waxing Crescent", /*LANG*/"First Quarter", /*LANG*/"Waxing Gibbous", + /*LANG*/"Full Moon", /*LANG*/"Waning Gibbous", /*LANG*/"Last Quater", /*LANG*/"Waning Crescent", ]; const phase = SunCalc.getMoonIllumination(new Date()); + const phaseIdx = Math.round(phase.phase*8); const pageData = { - Phase: phaseNames[phase.phase], + Phase: phaseNames[phaseIdx], }; drawData(title, pageData, null, 35); - drawMoon(phase.phase, g.getWidth() / 2, g.getHeight() / 2); + drawMoon(phaseIdx, g.getWidth() / 2, g.getHeight() / 2); let m = setWatch(() => { let m = moonIndexPageMenu(gps); - }, BTN3, {repease: false, edge: "falling"}); + }, BANGLEJS2 ? BTN : BTN3, {repease: false, edge: "falling"}); } function drawMoonTimesPage(gps, title) { const times = SunCalc.getMoonTimes(new Date(), gps.lat, gps.lon); + const moonColor = g.theme.dark ? {r: 1, g: 1, b: 1} : {r: 0, g: 0, b: 0}; const pageData = { Rise: dateToTimeString(times.rise), Set: dateToTimeString(times.set), }; - drawData(title, pageData, null, 105); + drawData(title, pageData, null, g.getHeight()/2 - Object.keys(pageData).length/2*20 + 5); drawPoints(); // Draw the moon rise position const risePos = SunCalc.getMoonPosition(times.rise, gps.lat, gps.lon); const riseAzimuthDegrees = parseInt(risePos.azimuth * 180 / Math.PI); - drawPoint(riseAzimuthDegrees, 8, {r: 1, g: 1, b: 1}); + drawPoint(riseAzimuthDegrees, 8, moonColor); // Draw the moon set position const setPos = SunCalc.getMoonPosition(times.set, gps.lat, gps.lon); const setAzimuthDegrees = parseInt(setPos.azimuth * 180 / Math.PI); - drawPoint(setAzimuthDegrees, 8, {r: 1, g: 1, b: 1}); + drawPoint(setAzimuthDegrees, 8, moonColor); let m = setWatch(() => { let m = moonIndexPageMenu(gps); - }, BTN3, {repease: false, edge: "falling"}); + }, BANGLEJS2 ? BTN : BTN3, {repease: false, edge: "falling"}); } function drawSunShowPage(gps, key, date) { @@ -224,7 +226,7 @@ function drawSunShowPage(gps, key, date) { Degrees: azimuthDegrees }; - drawData(key, pageData, null, 85); + drawData(key, pageData, null, g.getHeight()/2 - Object.keys(pageData).length/2*20 + 5); drawPoints(); @@ -233,7 +235,7 @@ function drawSunShowPage(gps, key, date) { m = setWatch(() => { m = sunIndexPageMenu(gps); - }, BTN3, {repeat: false, edge: "falling"}); + }, BANGLEJS2 ? BTN : BTN3, {repeat: false, edge: "falling"}); return null; } @@ -273,15 +275,15 @@ function moonIndexPageMenu(gps) { }, "Times": () => { m = E.showMenu(); - drawMoonTimesPage(gps, "Times"); + drawMoonTimesPage(gps, /*LANG*/"Times"); }, "Position": () => { m = E.showMenu(); - drawMoonPositionPage(gps, "Position"); + drawMoonPositionPage(gps, /*LANG*/"Position"); }, "Illumination": () => { m = E.showMenu(); - drawMoonIlluminationPage(gps, "Illumination"); + drawMoonIlluminationPage(gps, /*LANG*/"Illumination"); }, "< Back": () => m = indexPageMenu(gps), }; @@ -292,15 +294,15 @@ function moonIndexPageMenu(gps) { function indexPageMenu(gps) { const menu = { "": { - "title": "Select", + "title": /*LANG*/"Select", }, - "Sun": () => { + /*LANG*/"Sun": () => { m = sunIndexPageMenu(gps); }, - "Moon": () => { + /*LANG*/"Moon": () => { m = moonIndexPageMenu(gps); }, - "< Exit": () => { load(); } + "< Back": () => { load(); } }; return E.showMenu(menu); @@ -310,79 +312,10 @@ function getCenterStringX(str) { return (g.getWidth() - g.stringWidth(str)) / 2; } -/** - * GPS wait page, shows GPS locating animation until it gets a lock, then moves to the Sun page - */ -function drawGPSWaitPage() { - const img = require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AW43GF1wwsFwYwqFwowoFw4wmFxIwdE5YAPF/4vM5nN6YAE5vMF8YtHGIgvhFpQxKF7AuOGA4vXFyAwGF63MFyIABF6xeWMC4UDLwvNGpAJG5gwSdhIIDRBLyWCIgcJHAgJJDoouQF4vMQoICBBJoeGFx6GGACIfHL6YvaX6gvZeCIdFc4gAFXogvGFxgwFDwovQCAguOGAnMMBxeG5guTGAggGGAwNKFySREcA3N5vM5gDBdpQvXEY4AKXqovGGCKbFF7AwPZQwvZGJgtGF7vGdQItG5gSIF7gASF/44WEzgwRF0wwHF1AwFF1QwDF1gvwAH4A/AFAA==")); - const str1 = "Astrocalc v0.02"; - const str2 = "Locating GPS"; - const str3 = "Please wait..."; - - g.clear(); - g.drawImage(img, 100, 50); - g.setFont("6x8", 1); - g.drawString(str1, getCenterStringX(str1), 105); - g.drawString(str2, getCenterStringX(str2), 140); - g.drawString(str3, getCenterStringX(str3), 155); - - if (lastGPS) { - lastGPS = JSON.parse(lastGPS); - lastGPS.time = new Date(); - - const str4 = "Press Button 3 to use last GPS"; - g.setColor("#d32e29"); - g.fillRect(0, 190, g.getWidth(), 215); - g.setColor("#ffffff"); - g.drawString(str4, getCenterStringX(str4), 200); - - setWatch(() => { - clearWatch(); - Bangle.setGPSPower(0); - m = indexPageMenu(lastGPS); - }, BTN3, {repeat: false}); - } - - g.flip(); - - const DEBUG = false; - if (DEBUG) { - clearWatch(); - - const gps = { - "lat": 56.45783133333, - "lon": -3.02188583333, - "alt": 75.3, - "speed": 0.070376, - "course": NaN, - "time":new Date(), - "satellites": 4, - "fix": 1 - }; - - m = indexPageMenu(gps); - - return; - } - - Bangle.on('GPS', (gps) => { - if (gps.fix === 0) return; - clearWatch(); - - if (isNaN(gps.course)) gps.course = 0; - require("Storage").writeJSON(LAST_GPS_FILE, JSON.stringify(gps)); - Bangle.setGPSPower(0); - Bangle.buzz(); - Bangle.setLCDPower(true); - - m = indexPageMenu(gps); - }); -} - function init() { - Bangle.setGPSPower(1); - drawGPSWaitPage(); + let location = require("Storage").readJSON("mylocation.json",1)||{"lat":51.5072,"lon":0.1276,"location":"London"}; + indexPageMenu(location); } let m; -init(); \ No newline at end of file +init(); diff --git a/apps/astrocalc/metadata.json b/apps/astrocalc/metadata.json index 384c7fa1e..653c097da 100644 --- a/apps/astrocalc/metadata.json +++ b/apps/astrocalc/metadata.json @@ -1,15 +1,15 @@ { "id": "astrocalc", "name": "Astrocalc", - "version": "0.02", - "description": "Calculates interesting information on the sun and moon cycles for the current day based on your location.", + "version": "0.04", + "description": "Calculates interesting information on the sun like sunset and sunrise and moon cycles for the current day based on your location from MyLocation app", "icon": "astrocalc.png", - "tags": "app,sun,moon,cycles,tool,outdoors", - "supports": ["BANGLEJS"], + "tags": "app,sun,moon,cycles,tool", + "supports": ["BANGLEJS", "BANGLEJS2"], "allow_emulator": true, + "dependencies": {"mylocation":"app"}, "storage": [ {"name":"astrocalc.app.js","url":"astrocalc-app.js"}, - {"name":"suncalc.js","url":"suncalc.js"}, {"name":"astrocalc.img","url":"astrocalc-icon.js","evaluate":true}, {"name":"first-quarter.img","url":"first-quarter-icon.js","evaluate":true}, {"name":"last-quarter.img","url":"last-quarter-icon.js","evaluate":true}, diff --git a/apps/astrocalc/suncalc.js b/apps/astrocalc/suncalc.js deleted file mode 100644 index e2beaedca..000000000 --- a/apps/astrocalc/suncalc.js +++ /dev/null @@ -1,328 +0,0 @@ -/* - (c) 2011-2015, Vladimir Agafonkin - SunCalc is a JavaScript library for calculating sun/moon position and light phases. - https://github.com/mourner/suncalc -*/ - -(function () { 'use strict'; - - // shortcuts for easier to read formulas - - var PI = Math.PI, - sin = Math.sin, - cos = Math.cos, - tan = Math.tan, - asin = Math.asin, - atan = Math.atan2, - acos = Math.acos, - rad = PI / 180; - - // sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas - - - // date/time constants and conversions - - var dayMs = 1000 * 60 * 60 * 24, - J1970 = 2440588, - J2000 = 2451545; - - function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; } - function fromJulian(j) { return (j + 0.5 - J1970) * dayMs; } - function toDays(date) { return toJulian(date) - J2000; } - - - // general calculations for position - - var e = rad * 23.4397; // obliquity of the Earth - - function rightAscension(l, b) { return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)); } - function declination(l, b) { return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)); } - - function azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); } - function altitude(H, phi, dec) { return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); } - - function siderealTime(d, lw) { return rad * (280.16 + 360.9856235 * d) - lw; } - - function astroRefraction(h) { - if (h < 0) // the following formula works for positive altitudes only. - h = 0; // if h = -0.08901179 a div/0 would occur. - - // formula 16.4 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - // 1.02 / tan(h + 10.26 / (h + 5.10)) h in degrees, result in arc minutes -> converted to rad: - return 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179)); - } - - // general sun calculations - - function solarMeanAnomaly(d) { return rad * (357.5291 + 0.98560028 * d); } - - function eclipticLongitude(M) { - - var C = rad * (1.9148 * sin(M) + 0.02 * sin(2 * M) + 0.0003 * sin(3 * M)), // equation of center - P = rad * 102.9372; // perihelion of the Earth - - return M + C + P + PI; - } - - function sunCoords(d) { - - var M = solarMeanAnomaly(d), - L = eclipticLongitude(M); - - return { - dec: declination(L, 0), - ra: rightAscension(L, 0) - }; - } - - - var SunCalc = {}; - - - // calculates sun position for a given date and latitude/longitude - - SunCalc.getPosition = function (date, lat, lng) { - - var lw = rad * -lng, - phi = rad * lat, - d = toDays(date), - - c = sunCoords(d), - H = siderealTime(d, lw) - c.ra; - - return { - azimuth: azimuth(H, phi, c.dec), - altitude: altitude(H, phi, c.dec) - }; - }; - - - // sun times configuration (angle, morning name, evening name) - - var times = SunCalc.times = [ - [-0.833, 'sunrise', 'sunset' ], - [ -0.3, 'sunriseEnd', 'sunsetStart' ], - [ -6, 'dawn', 'dusk' ], - [ -12, 'nauticalDawn', 'nauticalDusk'], - [ -18, 'nightEnd', 'night' ], - [ 6, 'goldenHourEnd', 'goldenHour' ] - ]; - - // adds a custom time to the times config - - SunCalc.addTime = function (angle, riseName, setName) { - times.push([angle, riseName, setName]); - }; - - - // calculations for sun times - - var J0 = 0.0009; - - function julianCycle(d, lw) { return Math.round(d - J0 - lw / (2 * PI)); } - - function approxTransit(Ht, lw, n) { return J0 + (Ht + lw) / (2 * PI) + n; } - function solarTransitJ(ds, M, L) { return J2000 + ds + 0.0053 * sin(M) - 0.0069 * sin(2 * L); } - - function hourAngle(h, phi, d) { return acos((sin(h) - sin(phi) * sin(d)) / (cos(phi) * cos(d))); } - function observerAngle(height) { return -2.076 * Math.sqrt(height) / 60; } - - // returns set time for the given sun altitude - function getSetJ(h, lw, phi, dec, n, M, L) { - - var w = hourAngle(h, phi, dec), - a = approxTransit(w, lw, n); - return solarTransitJ(a, M, L); - } - - - // calculates sun times for a given date, latitude/longitude, and, optionally, - // the observer height (in meters) relative to the horizon - - SunCalc.getTimes = function (date, lat, lng, height) { - - height = height || 0; - - var lw = rad * -lng, - phi = rad * lat, - - dh = observerAngle(height), - - d = toDays(date), - n = julianCycle(d, lw), - ds = approxTransit(0, lw, n), - - M = solarMeanAnomaly(ds), - L = eclipticLongitude(M), - dec = declination(L, 0), - - Jnoon = solarTransitJ(ds, M, L), - - i, len, time, h0, Jset, Jrise; - - - var result = { - solarNoon: new Date(fromJulian(Jnoon)), - nadir: new Date(fromJulian(Jnoon - 0.5)) - }; - - for (i = 0, len = times.length; i < len; i += 1) { - time = times[i]; - h0 = (time[0] + dh) * rad; - - Jset = getSetJ(h0, lw, phi, dec, n, M, L); - Jrise = Jnoon - (Jset - Jnoon); - - result[time[1]] = new Date(fromJulian(Jrise) - (dayMs / 2)); - result[time[2]] = new Date(fromJulian(Jset) + (dayMs / 2)); - } - - return result; - }; - - - // moon calculations, based on http://aa.quae.nl/en/reken/hemelpositie.html formulas - - function moonCoords(d) { // geocentric ecliptic coordinates of the moon - - var L = rad * (218.316 + 13.176396 * d), // ecliptic longitude - M = rad * (134.963 + 13.064993 * d), // mean anomaly - F = rad * (93.272 + 13.229350 * d), // mean distance - - l = L + rad * 6.289 * sin(M), // longitude - b = rad * 5.128 * sin(F), // latitude - dt = 385001 - 20905 * cos(M); // distance to the moon in km - - return { - ra: rightAscension(l, b), - dec: declination(l, b), - dist: dt - }; - } - - SunCalc.getMoonPosition = function (date, lat, lng) { - - var lw = rad * -lng, - phi = rad * lat, - d = toDays(date), - - c = moonCoords(d), - H = siderealTime(d, lw) - c.ra, - h = altitude(H, phi, c.dec), - // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H)); - - h = h + astroRefraction(h); // altitude correction for refraction - - return { - azimuth: azimuth(H, phi, c.dec), - altitude: h, - distance: c.dist, - parallacticAngle: pa - }; - }; - - - // calculations for illumination parameters of the moon, - // based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mphase.pro formulas and - // Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. - - // Function updated from gist: https://gist.github.com/endel/dfe6bb2fbe679781948c - - SunCalc.getMoonIllumination = function (date) { - let month = date.getMonth(); - let year = date.getFullYear(); - let day = date.getDate(); - - let c = 0; - let e = 0; - let jd = 0; - let b = 0; - - if (month < 3) { - year--; - month += 12; - } - - ++month; - c = 365.25 * year; - e = 30.6 * month; - jd = c + e + day - 694039.09; // jd is total days elapsed - jd /= 29.5305882; // divide by the moon cycle - b = parseInt(jd); // int(jd) -> b, take integer part of jd - jd -= b; // subtract integer part to leave fractional part of original jd - b = Math.round(jd * 8); // scale fraction from 0-8 and round - - if (b >= 8) b = 0; // 0 and 8 are the same so turn 8 into 0 - - return {phase: b}; - }; - - - function hoursLater(date, h) { - return new Date(date.valueOf() + h * dayMs / 24); - } - - // calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article - - SunCalc.getMoonTimes = function (date, lat, lng, inUTC) { - var t = date; - if (inUTC) t.setUTCHours(0, 0, 0, 0); - else t.setHours(0, 0, 0, 0); - - var hc = 0.133 * rad, - h0 = SunCalc.getMoonPosition(t, lat, lng).altitude - hc, - h1, h2, rise, set, a, b, xe, ye, d, roots, x1, x2, dx; - - // go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set) - for (var i = 1; i <= 24; i += 2) { - h1 = SunCalc.getMoonPosition(hoursLater(t, i), lat, lng).altitude - hc; - h2 = SunCalc.getMoonPosition(hoursLater(t, i + 1), lat, lng).altitude - hc; - - a = (h0 + h2) / 2 - h1; - b = (h2 - h0) / 2; - xe = -b / (2 * a); - ye = (a * xe + b) * xe + h1; - d = b * b - 4 * a * h1; - roots = 0; - - if (d >= 0) { - dx = Math.sqrt(d) / (Math.abs(a) * 2); - x1 = xe - dx; - x2 = xe + dx; - if (Math.abs(x1) <= 1) roots++; - if (Math.abs(x2) <= 1) roots++; - if (x1 < -1) x1 = x2; - } - - if (roots === 1) { - if (h0 < 0) rise = i + x1; - else set = i + x1; - - } else if (roots === 2) { - rise = i + (ye < 0 ? x2 : x1); - set = i + (ye < 0 ? x1 : x2); - } - - if (rise && set) break; - - h0 = h2; - } - - var result = {}; - - if (rise) result.rise = hoursLater(t, rise); - if (set) result.set = hoursLater(t, set); - - if (!rise && !set) result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true; - - return result; - }; - - - // export as Node module / AMD module / browser variable - if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = SunCalc; - else if (typeof define === 'function' && define.amd) define(SunCalc); - else global.SunCalc = SunCalc; - -}()); diff --git a/apps/banglexercise/ChangeLog b/apps/banglexercise/ChangeLog index 5f1d3bd7d..6cf589541 100644 --- a/apps/banglexercise/ChangeLog +++ b/apps/banglexercise/ChangeLog @@ -2,3 +2,4 @@ 0.02: Add sit ups Add more feedback to the user about the exercises Clean up code +0.03: Add software back button on main menu diff --git a/apps/banglexercise/app.js b/apps/banglexercise/app.js index bc6e35f07..9659ee81f 100644 --- a/apps/banglexercise/app.js +++ b/apps/banglexercise/app.js @@ -71,7 +71,8 @@ function showMainMenu() { let menu; menu = { "": { - title: "BanglExercise" + title: "BanglExercise", + back: load } }; @@ -381,4 +382,5 @@ Bangle.on('HRM', function(hrm) { }); g.clear(1); +Bangle.loadWidgets(); showMainMenu(); diff --git a/apps/banglexercise/metadata.json b/apps/banglexercise/metadata.json index 9bb93f112..f4ce1894b 100644 --- a/apps/banglexercise/metadata.json +++ b/apps/banglexercise/metadata.json @@ -1,7 +1,7 @@ { "id": "banglexercise", "name": "BanglExercise", "shortName":"BanglExercise", - "version":"0.02", + "version":"0.03", "description": "Can automatically track exercises while wearing the Bangle.js watch.", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], diff --git a/apps/barclock/ChangeLog b/apps/barclock/ChangeLog index ba44ecef8..88f4eaf00 100644 --- a/apps/barclock/ChangeLog +++ b/apps/barclock/ChangeLog @@ -12,3 +12,5 @@ 0.12: Add settings to hide date,widgets 0.13: Add font setting 0.14: Use ClockFace_menu.addItems +0.15: Add Power saving option +0.16: Support Fast Loading diff --git a/apps/barclock/README.md b/apps/barclock/README.md index ff66a5cbb..28572e37c 100644 --- a/apps/barclock/README.md +++ b/apps/barclock/README.md @@ -7,4 +7,5 @@ A simple digital clock showing seconds as a horizontal bar. ## Settings * `Show date`: display date at the bottom of screen -* `Font`: choose between bitmap or vector fonts \ No newline at end of file +* `Font`: choose between bitmap or vector fonts +* `Power saving`: (Bangle.js 2 only) don't draw the seconds bar while the watch is locked \ No newline at end of file diff --git a/apps/barclock/clock-bar.js b/apps/barclock/clock-bar.js index 61ce07dfb..f2499189b 100644 --- a/apps/barclock/clock-bar.js +++ b/apps/barclock/clock-bar.js @@ -1,105 +1,128 @@ /* jshint esversion: 6 */ -/** - * A simple digital clock showing seconds as a bar - **/ +{ + /** + * A simple digital clock showing seconds as a bar + **/ // Check settings for what type our clock should be -let locale = require("locale"); -{ // add some more info to locale - let date = new Date(); - date.setFullYear(1111); - date.setMonth(1, 3); // februari: months are zero-indexed - const localized = locale.date(date, true); - locale.dayFirst = /3.*2/.test(localized); - locale.hasMeridian = (locale.meridian(date)!==""); -} - -function renderBar(l) { - if (!this.fraction) { - // zero-size fillRect stills draws one line of pixels, we don't want that - return; + let locale = require("locale"); + { // add some more info to locale + let date = new Date(); + date.setFullYear(1111); + date.setMonth(1, 3); // februari: months are zero-indexed + const localized = locale.date(date, true); + locale.dayFirst = /3.*2/.test(localized); + locale.hasMeridian = (locale.meridian(date)!==""); } - const width = this.fraction*l.w; - g.fillRect(l.x, l.y, l.x+width-1, l.y+l.height-1); -} - -function timeText(date) { - if (!clock.is12Hour) { - return locale.time(date, true); + let barW = 0, prevX = 0; + const renderBar = function (l) { + "ram"; + if (l) prevX = 0; // called from Layout: drawing area was cleared + else l = clock.layout.bar; + let x2 = l.x+barW; + if (clock.powerSave && Bangle.isLocked()) x2 = 0; // hide bar + if (x2===prevX) return; // nothing to do + if (x2===0) x2--; // don't leave 1px line + if (x212) { - date12.setHours(hours-12); + + const timeText = function(date) { + if (!clock.is12Hour) { + return locale.time(date, true); + } + const date12 = new Date(date.getTime()); + const hours = date12.getHours(); + if (hours===0) { + date12.setHours(12); + } else if (hours>12) { + date12.setHours(hours-12); + } + return locale.time(date12, true); } - return locale.time(date12, true); -} -function ampmText(date) { - return (clock.is12Hour && locale.hasMeridian) ? locale.meridian(date) : ""; -} -function dateText(date) { - const dayName = locale.dow(date, true), - month = locale.month(date, true), - day = date.getDate(); - const dayMonth = locale.dayFirst ? `${day} ${month}` : `${month} ${day}`; - return `${dayName} ${dayMonth}`; -} + const ampmText = date => (clock.is12Hour && locale.hasMeridian) ? locale.meridian(date) : ""; + const dateText = date => { + const dayName = locale.dow(date, true), + month = locale.month(date, true), + day = date.getDate(); + const dayMonth = locale.dayFirst ? `${day} ${month}` : `${month} ${day}`; + return `${dayName} ${dayMonth}`; + }; - -const ClockFace = require("ClockFace"), - clock = new ClockFace({ - precision:1, - settingsFile:'barclock.settings.json', - init: function() { - const Layout = require("Layout"); - this.layout = new Layout({ - type: "v", c: [ - { - type: "h", c: [ - {id: "time", label: "88:88", type: "txt", font: "6x8:5", col:g.theme.fg, bgCol: g.theme.bg}, // updated below - {id: "ampm", label: " ", type: "txt", font: "6x8:2", col:g.theme.fg, bgCol: g.theme.bg}, - ], - }, - {id: "bar", type: "custom", fraction: 0, fillx: 1, height: 6, col: g.theme.fg2, render: renderBar}, - this.showDate ? {height: 40} : {}, - this.showDate ? {id: "date", type: "txt", font: "10%", valign: 1} : {}, - ], - }, {lazy: true}); - // adjustments based on screen size and whether we display am/pm - let thickness; // bar thickness, same as time font "pixel block" size - if (this.is12Hour && locale.hasMeridian) { - // Maximum font size = ( - ) / (5chars * 6px) - thickness = Math.floor((Bangle.appRect.w-24)/(5*6)); - } else { - this.layout.ampm.label = ""; - thickness = Math.floor(Bangle.appRect.w/(5*6)); - } - this.layout.bar.height = thickness+1; - if (this.font===1) { // vector - const B2 = process.env.HWVERSION>1; + const ClockFace = require("ClockFace"), + clock = new ClockFace({ + precision: 1, + settingsFile: "barclock.settings.json", + init: function() { + const Layout = require("Layout"); + this.layout = new Layout({ + type: "v", c: [ + { + type: "h", c: [ + {id: "time", label: "88:88", type: "txt", font: "6x8:5", col: g.theme.fg, bgCol: g.theme.bg}, // updated below + {id: "ampm", label: " ", type: "txt", font: "6x8:2", col: g.theme.fg, bgCol: g.theme.bg}, + ], + }, + {id: "bar", type: "custom", fillx: 1, height: 6, col: g.theme.fg2, render: renderBar}, + this.showDate ? {height: 40} : {}, + this.showDate ? {id: "date", type: "txt", font: "10%", valign: 1} : {}, + ], + }, {lazy: true}); + // adjustments based on screen size and whether we display am/pm + let thickness; // bar thickness, same as time font "pixel block" size if (this.is12Hour && locale.hasMeridian) { - this.layout.time.font = "Vector:"+(B2 ? 50 : 60); - this.layout.ampm.font = "Vector:"+(B2 ? 20 : 40); + // Maximum font size = ( - ) / (5chars * 6px) + thickness = Math.floor((Bangle.appRect.w-24)/(5*6)); } else { - this.layout.time.font = "Vector:"+(B2 ? 60 : 80); + this.layout.ampm.label = ""; + thickness = Math.floor(Bangle.appRect.w/(5*6)); } - } else { - this.layout.time.font = "6x8:"+thickness; - } - this.layout.update(); - }, - update: function(date, c) { - if (c.m) this.layout.time.label = timeText(date); - if (c.h) this.layout.ampm.label = ampmText(date); - if (c.d && this.showDate) this.layout.date.label = dateText(date); - const SECONDS_PER_MINUTE = 60; - if (c.s) this.layout.bar.fraction = date.getSeconds()/SECONDS_PER_MINUTE; - this.layout.render(); - }, - resume: function() { - this.layout.forgetLazyState(); - }, - }); -clock.start(); + let bar = this.layout.bar; + bar.height = thickness+1; + if (this.font===1) { // vector + const B2 = process.env.HWVERSION>1; + if (this.is12Hour && locale.hasMeridian) { + this.layout.time.font = "Vector:"+(B2 ? 50 : 60); + this.layout.ampm.font = "Vector:"+(B2 ? 20 : 40); + } else { + this.layout.time.font = "Vector:"+(B2 ? 60 : 80); + } + } else { + this.layout.time.font = "6x8:"+thickness; + } + this.layout.update(); + bar.y2 = bar.y+bar.height-1; + }, + update: function(date, c) { + "ram"; + if (c.m) this.layout.time.label = timeText(date); + if (c.h) this.layout.ampm.label = ampmText(date); + if (c.d && this.showDate) this.layout.date.label = dateText(date); + if (c.m) this.layout.render(); + if (c.s) { + barW = Math.round(date.getSeconds()/60*this.layout.bar.w); + renderBar(); + } + }, + resume: function() { + prevX = 0; // force redraw of bar + this.layout.forgetLazyState(); + }, + remove: function() { + if (this.onLock) Bangle.removeListener("lock", this.onLock); + }, + }); + + // power saving: only update once a minute while locked, hide bar + if (clock.powerSave) { + clock.onLock = lock => { + clock.precision = lock ? 60 : 1; + clock.tick(); + renderBar(); // hide/redraw bar right away + } + Bangle.on("lock", clock.onLock); + } + + clock.start(); +} \ No newline at end of file diff --git a/apps/barclock/metadata.json b/apps/barclock/metadata.json index 0c227dc52..785c228b0 100644 --- a/apps/barclock/metadata.json +++ b/apps/barclock/metadata.json @@ -1,7 +1,7 @@ { "id": "barclock", "name": "Bar Clock", - "version": "0.14", + "version": "0.16", "description": "A simple digital clock showing seconds as a bar", "icon": "clock-bar.png", "screenshots": [{"url":"screenshot.png"},{"url":"screenshot_pm.png"}], diff --git a/apps/barclock/settings.js b/apps/barclock/settings.js index dfe25581c..7b88b7021 100644 --- a/apps/barclock/settings.js +++ b/apps/barclock/settings.js @@ -17,10 +17,14 @@ onchange: v => save("font", v), }, }; - require("ClockFace_menu").addItems(menu, save, { + let items = { showDate: s.showDate, loadWidgets: s.loadWidgets, - }); - + }; + // Power saving for Bangle.js 1 doesn't make sense (no updates while screen is off anyway) + if (process.env.HWVERSION>1) { + items.powerSave = s.powerSave; + } + require("ClockFace_menu").addItems(menu, save, items); E.showMenu(menu); }); diff --git a/apps/barcode/ChangeLog b/apps/barcode/ChangeLog index 4f99f15ac..7ab5d8587 100644 --- a/apps/barcode/ChangeLog +++ b/apps/barcode/ChangeLog @@ -7,3 +7,4 @@ 0.07: Step count resets at midnight 0.08: Step count stored in memory to survive reloads. Now shows step count daily and since last reboot. 0.09: NOW it really should reset daily (instead of every other day...) +0.10: Tell clock widgets to hide. diff --git a/apps/barcode/barcode.app.js b/apps/barcode/barcode.app.js index 89419f33c..0d9df78d5 100644 --- a/apps/barcode/barcode.app.js +++ b/apps/barcode/barcode.app.js @@ -416,13 +416,13 @@ var layout = new Layout( { // Clear the screen once, at startup g.clear(); +Bangle.setUI("clock"); Bangle.loadWidgets(); Bangle.drawWidgets(); -Bangle.setUI("clock"); layout.render(); Bangle.on('lock', function(locked) { if(!locked) { layout.render(); } -}); \ No newline at end of file +}); diff --git a/apps/barcode/metadata.json b/apps/barcode/metadata.json index cef267b2b..3f6bf06e6 100644 --- a/apps/barcode/metadata.json +++ b/apps/barcode/metadata.json @@ -2,7 +2,7 @@ "name": "Barcode clock", "shortName":"Barcode clock", "icon": "barcode.icon.png", - "version":"0.09", + "version":"0.10", "description": "EAN-8 compatible barcode clock.", "tags": "barcode,ean,ean-8,watchface,clock,clockface", "type": "clock", diff --git a/apps/barometer/ChangeLog b/apps/barometer/ChangeLog index de3a5cb96..b429dda17 100644 --- a/apps/barometer/ChangeLog +++ b/apps/barometer/ChangeLog @@ -1,3 +1,4 @@ 0.01: Display pressure as number and hand 0.02: Use theme color 0.03: workaround for some firmwares that return 'undefined' for first call to barometer +0.04: Update every second, go back with short button press diff --git a/apps/barometer/app.js b/apps/barometer/app.js index 77d4c974f..7e793af4f 100644 --- a/apps/barometer/app.js +++ b/apps/barometer/app.js @@ -59,6 +59,7 @@ function drawTicks(){ function drawScaleLabels(){ g.setColor(g.theme.fg); g.setFont("Vector",12); + g.setFontAlign(-1,-1); let label = MIN; for (let i=0;i <= NUMBER_OF_LABELS; i++){ @@ -103,22 +104,29 @@ function drawIcons() { } g.setBgColor(g.theme.bg); -g.clear(); - -drawTicks(); -drawScaleLabels(); -drawIcons(); try { function baroHandler(data) { - if (data===undefined) // workaround for https://github.com/espruino/BangleApps/issues/1429 - setTimeout(() => Bangle.getPressure().then(baroHandler), 500); - else + g.clear(); + + drawTicks(); + drawScaleLabels(); + drawIcons(); + if (data!==undefined) { drawHand(Math.round(data.pressure)); + } } Bangle.getPressure().then(baroHandler); + setInterval(() => Bangle.getPressure().then(baroHandler), 1000); } catch(e) { - print(e.message); - print("barometer not supporter, show a demo value"); + if (e !== undefined) { + print(e.message); + } + print("barometer not supported, show a demo value"); drawHand(MIN); } + +Bangle.setUI({ + mode : "custom", + back : function() {load();} +}); diff --git a/apps/barometer/metadata.json b/apps/barometer/metadata.json index a385f2be2..767fa630b 100644 --- a/apps/barometer/metadata.json +++ b/apps/barometer/metadata.json @@ -1,7 +1,7 @@ { "id": "barometer", "name": "Barometer", "shortName":"Barometer", - "version":"0.03", + "version":"0.04", "description": "A simple barometer that displays the current air pressure", "icon": "barometer.png", "tags": "tool,outdoors", diff --git a/apps/barwatch/ChangeLog b/apps/barwatch/ChangeLog new file mode 100644 index 000000000..7f837e50e --- /dev/null +++ b/apps/barwatch/ChangeLog @@ -0,0 +1 @@ +0.01: First version diff --git a/apps/barwatch/README.md b/apps/barwatch/README.md new file mode 100644 index 000000000..c37caa6e4 --- /dev/null +++ b/apps/barwatch/README.md @@ -0,0 +1,5 @@ +# BarWatch - an experimental watch + +For too long the watches have shown the time with digits or hands. No more! +With this stylish watch the time is represented by bars. Up to 24 as the day goes by. +Practical? Not really, but a different look! \ No newline at end of file diff --git a/apps/barwatch/app-icon.js b/apps/barwatch/app-icon.js new file mode 100644 index 000000000..82416ee28 --- /dev/null +++ b/apps/barwatch/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("l0uwkE/4A/AH4A/AB0gicQmUB+EPgEigExh8gj8A+ECAgMQn4WCgcACyotWC34W/C34W/CycACw0wgYWFBYIWCAAc/+YGHCAgNFACkxl8hGYwAMLYUvCykQC34WycoIW/C34W0gAWTmUjkUzkbmSAFY=")) \ No newline at end of file diff --git a/apps/barwatch/app.js b/apps/barwatch/app.js new file mode 100644 index 000000000..e0ed15ce6 --- /dev/null +++ b/apps/barwatch/app.js @@ -0,0 +1,76 @@ +// timeout used to update every minute +var drawTimeout; + +// schedule a draw for the next minute +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +} + + +function draw() { + g.reset(); + + if(g.theme.dark){ + g.setColor(1,1,1); + }else{ + g.setColor(0,0,0); + } + + // work out how to display the current time + var d = new Date(); + var h = d.getHours(), m = d.getMinutes(); + + // hour bars + var bx_offset = 10, by_offset = 35; + var b_width = 8, b_height = 60; + var b_space = 5; + + for(var i=0; i 11){ + by_offset = 105; + } + var iter = i % 12; + //console.log(iter); + g.fillRect(bx_offset+(b_width*(iter+1))+(b_space*iter), + by_offset, + bx_offset+(b_width*iter)+(b_space*iter), + by_offset+b_height); + } + + // minute bar + if(h > 11){ + by_offset = 105; + } + var m_bar = h % 12; + if(m != 0){ + g.fillRect(bx_offset+(b_width*(m_bar+1))+(b_space*m_bar), + by_offset+b_height-m, + bx_offset+(b_width*m_bar)+(b_space*m_bar), + by_offset+b_height); + } + + // queue draw in one minute + queueDraw(); +} + +// Clear the screen once, at startup +g.clear(); +// draw immediately at first +draw(); +// Stop updates when LCD is off, restart when on +Bangle.on('lcdPower',on=>{ + if (on) { + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); + +Bangle.setUI("clock"); +Bangle.loadWidgets(); +Bangle.drawWidgets(); diff --git a/apps/barwatch/app.png b/apps/barwatch/app.png new file mode 100644 index 000000000..134de9424 Binary files /dev/null and b/apps/barwatch/app.png differ diff --git a/apps/barwatch/metadata.json b/apps/barwatch/metadata.json new file mode 100644 index 000000000..adcd44107 --- /dev/null +++ b/apps/barwatch/metadata.json @@ -0,0 +1,18 @@ +{ + "id": "barwatch", + "name": "BarWatch", + "shortName":"BarWatch", + "version":"0.01", + "description": "A watch that displays the time using bars. One bar for each hour.", + "readme": "README.md", + "icon": "screenshot.png", + "tags": "clock", + "type": "clock", + "allow_emulator":true, + "screenshots" : [ { "url": "screenshot.png" } ], + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"barwatch.app.js","url":"app.js"}, + {"name":"barwatch.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/barwatch/screenshot.png b/apps/barwatch/screenshot.png new file mode 100644 index 000000000..305138252 Binary files /dev/null and b/apps/barwatch/screenshot.png differ diff --git a/apps/batclock/ChangeLog b/apps/batclock/ChangeLog index e6e21b146..2a2d91b74 100644 --- a/apps/batclock/ChangeLog +++ b/apps/batclock/ChangeLog @@ -1,2 +1,3 @@ 0.01: App Created! 0.02: Update to use Bangle.setUI instead of setWatch +0.03: Tell clock widgets to hide. diff --git a/apps/batclock/bat-clock.app.js b/apps/batclock/bat-clock.app.js index 31b8f5b9b..dc649160f 100644 --- a/apps/batclock/bat-clock.app.js +++ b/apps/batclock/bat-clock.app.js @@ -249,6 +249,9 @@ g.clear(); g.setColor(0, 0.5, 0).drawImage(bg_crack); g.setColor(1, 1, 1).drawImage(batman); +// Show launcher when button pressed +Bangle.setUI("clock"); + Bangle.loadWidgets(); Bangle.drawWidgets(); @@ -256,5 +259,3 @@ Bangle.drawWidgets(); timeInterval = setInterval(showTime, 1000); showTime(); -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/batclock/metadata.json b/apps/batclock/metadata.json index 8aa115780..e6520cb90 100644 --- a/apps/batclock/metadata.json +++ b/apps/batclock/metadata.json @@ -2,7 +2,7 @@ "id": "batclock", "name": "Bat Clock", "shortName": "Bat Clock", - "version": "0.02", + "version": "0.03", "description": "Morphing Clock, with an awesome \"The Dark Knight\" themed logo.", "icon": "bat-clock.png", "screenshots": [{"url":"screenshot.png"}], diff --git a/apps/bclock/ChangeLog b/apps/bclock/ChangeLog index 5b2cf598c..79c198431 100644 --- a/apps/bclock/ChangeLog +++ b/apps/bclock/ChangeLog @@ -1,2 +1,3 @@ 0.02: Modified for use with new bootloader and firmware 0.03: Update to use Bangle.setUI instead of setWatch +0.04: Tell clock widgets to hide. diff --git a/apps/bclock/clock-binary.js b/apps/bclock/clock-binary.js index fdf945ee6..c08a7abe6 100644 --- a/apps/bclock/clock-binary.js +++ b/apps/bclock/clock-binary.js @@ -100,10 +100,12 @@ Bangle.on('lcdPower', on => { if (on) drawClock(); }); +// Show launcher when button pressed +Bangle.setUI("clock"); + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); setInterval(() => { drawClock(); }, 1000); drawClock(); -// Show launcher when button pressed -Bangle.setUI("clock"); + diff --git a/apps/bclock/metadata.json b/apps/bclock/metadata.json index 94219a30b..c6a24d89f 100644 --- a/apps/bclock/metadata.json +++ b/apps/bclock/metadata.json @@ -1,7 +1,7 @@ { "id": "bclock", "name": "Binary Clock", - "version": "0.03", + "version": "0.04", "description": "A simple binary clock watch face", "icon": "clock-binary.png", "type": "clock", diff --git a/apps/beer/ChangeLog b/apps/beer/ChangeLog new file mode 100644 index 000000000..21ec45242 --- /dev/null +++ b/apps/beer/ChangeLog @@ -0,0 +1,3 @@ +0.01: New App! +0.02: Added adjustment for Bangle.js magnetometer heading fix + Bangle.js 2 compatibility diff --git a/apps/beer/app-icon.js b/apps/beer/app-icon.js index c700b3bd2..734985cb5 100644 --- a/apps/beer/app-icon.js +++ b/apps/beer/app-icon.js @@ -1 +1 @@ -require("heatshrink").decompress(atob("mEwghC/AB0O/4AG8AXNgYXHmAXl94XH+AXNn4XH/wXW+YX/C6oWHAAIXN7sz9vdAAoXN9sznvuAAXf/vuC53jC4Xd7wXQ93jn3u9vv9vt7wXT/4tBAgIXQ7wvCC4PgC5sO6czIQJfBC6PumaPDC6wwCC50NYAJcBVgIDBCxrAFbgYXP7yoDF6TADL4YXPVAIXCRyAXC7wXW9zwBC6cNC9zABC4gWQC653CR4fQC6x3TF6gXXI4M9d6wAEC9EN73dAAZfQgczAAkwC/4XXAH4")) +require("heatshrink").decompress(atob("mEw4cA///wH9/++1P+u3//3/qv/gv+KHkJkmABxcBBwNJkmQCJYOByQCCCBUCCItJkARQkgQHggLBku25IRDJQ4LCtu27Mt2RKJCInbAQIRLpYROglt24OB6wSC7dwLQ4LB9u2EgfbsARJ8u2mwRO+u3CNJtHCJFpCINALJoRCpCiGBoMSdQcpegIRGyaPB+QRDkARIyQRBc4YRKyet23iCJxHB6QRBzOJCJ+dCJY1CpfMGphrCp2YNZlL54CBEZgLBAQoRBiTFFCNMvmQRPndiEcJHEyQQECJMpAYIRQyARQwAROI4IAGB4wCBNAoRmhIRHCA4A/AAo")) diff --git a/apps/beer/custom.html b/apps/beer/custom.html index a357ab378..f0895f93f 100644 --- a/apps/beer/custom.html +++ b/apps/beer/custom.html @@ -127,6 +127,8 @@ var img_nofix = require("heatshrink").decompress(atob("mUyxH+ACYhJDygtYGsqLVF8u02gziGBoyhQ5gwDGRozRGCQydGCgybGCwyZC5gAaGPQwnGRAwpGQ4xwGFYyFDKsrlYxYDCsBmUyg4yXLyUsFwMyq1WAgUsNCRjUmVXroAEq8yMbcllkskwCEkplDmQwDq0sC54xEHQ9RqQAGqIwCFgOBAASYBSgMBltRAA0sgJsOGJeBxAAGwMrgIXIloxOJYNSvl8CwIDCqMBlYxNC4wxQDIOCwVYDIIDBGJ9YwV8rADBwRJCSqAVCAYaVMC4oxCPYYxQSo4xMSpIxPY4T5HY54XIMbIxKgwXKfKjhEllWGJNWlgXJGLNXruCGI+CrtXGKP+GJB9HMZ6VO/wxJcI8lfJclfKAxKfJEAGJIXLGKSvBWYQZCMZbfEqTHBGJYyFfIo1DGJ4tDGJQwCGJB9IMZyVNGIYyEfJQxPfJgwEMgoZJgAxMltRAA0tGJQyEksslkmAQklGINXxDTBFwIDCq8rC4YACC4gwJMowAJldWAAwwBABowIGJ4AYGJIymGBQylGBgyjGBwyhGCAzeF6YycGCwzYF7IzVF7o1PDqYA==")); var img_fix = require("heatshrink").decompress(atob("mUyxH+ACYhJDygtYGsqLVF94zaDYkq6wAOlQyYJo2A63VAAIoC2m0GI16My5/H5/V64ABGQIwBGQ+rTKwWHkhiBGIYwDGQ3VZioVIqoiBGAJhEGRFPGSYTIYwQxCGA4yFqodJGKeqSgQwJGQmkGKQSJfAYwLGQfPDxQwRgHVfAi/EAA4xLGQwRLYwb5BABoxQCBcA43G5wABAgIAMEBgxQ0QxB54xB5gAG4xgBBYOiGJ4PMGInPGIhcCGIt4EJoxPvHM5oxBGAnO6xrCGoXMqgxdpwxD5qQFL4QADlQxdgAhBGILIDMYoADEBwwPgCHBfQzHDAAb4NACTIIAA74OACLIIMo7GOACQoBZAoHBHQPNA4QwggGiZBA5B54HBY0DIKMYtUGMMqFYLIGY4jGhZAr6FAAYwiZAgxIY0TIFfQgADvAfR/zISGJTGR/wxRkj6CGJBiSGKL6DGP4xOGSKVDGAwxRGAQxU5oxcGR75DGJEkGCYxPlXM5vPGA/MlQxUGR1OGIL4I5lOGCgyOqgxBShHMqgwVGJt4GJd4GKwyMvHG5vGABAxMGBQyM1mtABWsGC4yLGBYABGDAyKGKwwQGZKVUF6b/OABowWGbAvZGaovdGp4dTA")); +var W = g.getWidth(), H = g.getHeight(); + // https://github.com/Leaflet/Leaflet/blob/master/src/geo/projection/Projection.SphericalMercator.js function project(latlong) { var d = Math.PI / 180, @@ -170,32 +172,30 @@ Bangle.on('GPS', function(f) { Bangle.on('mag', function(m) { if (!Bangle.isLCDOn()) return; - var headingrad = m.heading*Math.PI/180; // in radians + var headingrad = (360-m.heading)*Math.PI/180; // in radians if (!isFinite(headingrad)) headingrad=0; if (nearest) - g.drawImage(img_fix,120,120,{ + g.drawImage(img_fix,W/2,H/2,{ rotate: (Math.PI/2)+headingrad-nearestangle, scale:3, }); else - g.drawImage(img_nofix,120,120,{ + g.drawImage(img_nofix,W/2,H/2,{ rotate: headingrad, scale:2, }); - g.clearRect(60,0,180,24); - g.setFontAlign(0,0); - g.setFont("6x8"); + g.clearRect(0,0,W,24).setFontAlign(0,0).setFont("6x8"); if (fix.fix) { - g.drawString(nearest ? nearest.name : "---",120,4); + g.drawString(nearest ? nearest.name : "---",W/2,4); g.setFont("6x8",2); - g.drawString(nearest ? Math.round(nearestdist)+"m" : "---",120,16); + g.drawString(nearest ? Math.round(nearestdist)+"m" : "---",W/2,16); } else { - g.drawString(fix.satellites+" satellites",120,4); + g.drawString(fix.satellites+" satellites",W/2,4); } }); Bangle.setCompassPower(1); Bangle.setGPSPower(1); -g.clear();`; +g.setColor("#fff").setBgColor("#000").clear();`; sendCustomizedApp({ storage:[ diff --git a/apps/beer/metadata.json b/apps/beer/metadata.json index cf69aee90..3a2421bd1 100644 --- a/apps/beer/metadata.json +++ b/apps/beer/metadata.json @@ -1,11 +1,11 @@ { "id": "beer", "name": "Beer Compass", - "version": "0.01", + "version": "0.02", "description": "Uploads all the pubs in an area onto your watch, so it can always point you at the nearest one", "icon": "app.png", "tags": "", - "supports": ["BANGLEJS"], + "supports": ["BANGLEJS","BANGLEJS2"], "custom": "custom.html", "storage": [ {"name":"beer.app.js"}, diff --git a/apps/bigdclock/ChangeLog b/apps/bigdclock/ChangeLog index 09cc978fb..c92d139bb 100644 --- a/apps/bigdclock/ChangeLog +++ b/apps/bigdclock/ChangeLog @@ -3,3 +3,5 @@ 0.03: Internationalisation; bug fix - battery icon responds promptly to charging state 0.04: bug fix 0.05: proper fix for the race condition in queueDraw() +0.06: Tell clock widgets to hide. +0.07: Better battery graphic - now has green, yellow and red sections; battery status reflected in the bar across the middle of the screen; current battery state checked only once every 15 minutes, leading to longer-lasting battery charge diff --git a/apps/bigdclock/bigdclock.app.js b/apps/bigdclock/bigdclock.app.js index c013c6188..a8e2b38df 100644 --- a/apps/bigdclock/bigdclock.app.js +++ b/apps/bigdclock/bigdclock.app.js @@ -11,6 +11,8 @@ Graphics.prototype.setFontOpenSans = function(scale) { }; var drawTimeout; +var lastBattCheck = 0; +var width = 0; function queueDraw(millis_now) { if (drawTimeout) clearTimeout(drawTimeout); @@ -24,12 +26,15 @@ function draw() { var date = new Date(); var h = date.getHours(), m = date.getMinutes(); - var d = date.getDate(), - w = date.getDay(); // d=1..31; w=0..6 - const level = E.getBattery(); - const width = level + (level/2); + var d = date.getDate(); var is12Hour = (require("Storage").readJSON("setting.json", 1) || {})["12hour"]; - var dows = require("date_utils").dows(0,1); + var dow = require("date_utils").dows(0,1)[date.getDay()]; + + if ((date.getTime() >= lastBattCheck + 15*60000) || Bangle.isCharging()) { + lastBattcheck = date.getTime(); + width = E.getBattery(); + width += width/2; + } g.reset(); g.clear(); @@ -47,24 +52,35 @@ function draw() { g.drawString(d, g.getWidth() -6, 98); g.setFont('Vector', 52); g.setFontAlign(-1, -1); - g.drawString(dows[w].slice(0,2).toUpperCase(), 6, 103); + g.drawString(dow.slice(0,2).toUpperCase(), 6, 103); g.fillRect(9,159,166,171); g.fillRect(167,163,170,167); if (Bangle.isCharging()) { g.setColor(1,1,0); - } else if (level > 40) { - g.setColor(0,1,0); + g.fillRect(12,162,12+width,168); } else { g.setColor(1,0,0); + g.fillRect(12,162,57,168); + g.setColor(1,1,0); + g.fillRect(58,162,72,168); + g.setColor(0,1,0); + g.fillRect(73,162,162,168); } - g.fillRect(12,162,12+width,168); - if (level < 100) { + if (width < 150) { g.setColor(g.theme.bg); g.fillRect(12+width+1,162,162,168); } - g.setColor(0, 1, 0); + if (Bangle.isCharging()) { + g.setColor(1,1,0); + } else if (width <= 45) { + g.setColor(1,0,0); + } else if (width <= 60) { + g.setColor(1,1,0); + } else { + g.setColor(0, 1, 0); + } g.fillRect(0, 90, g.getWidth(), 94); // widget redraw @@ -85,7 +101,8 @@ Bangle.on('charging', (charging) => { draw(); }); +Bangle.setUI("clock"); + Bangle.loadWidgets(); draw(); -Bangle.setUI("clock"); diff --git a/apps/bigdclock/metadata.json b/apps/bigdclock/metadata.json index 7359bcf20..30352ca1a 100644 --- a/apps/bigdclock/metadata.json +++ b/apps/bigdclock/metadata.json @@ -1,7 +1,7 @@ { "id": "bigdclock", "name": "Big digit clock containing just the essentials", "shortName":"Big digit clk", - "version":"0.05", + "version":"0.07", "description": "A clock containing just the essentials, made as easy to read as possible for those of us that need glasses. It contains the time, the day-of-week, the day-of-month, and the current battery state-of-charge.", "icon": "bigdclock.png", "type": "clock", diff --git a/apps/bigdclock/screenshot.png b/apps/bigdclock/screenshot.png index 8a12b266e..acac53ea9 100644 Binary files a/apps/bigdclock/screenshot.png and b/apps/bigdclock/screenshot.png differ diff --git a/apps/binclock/ChangeLog b/apps/binclock/ChangeLog index dc4ed8308..7c31cc0d3 100644 --- a/apps/binclock/ChangeLog +++ b/apps/binclock/ChangeLog @@ -1,3 +1,4 @@ 0.01: New App! 0.02: Fixed bug where screen didn't clear so incorrect time displayed. 0.03: Update to use Bangle.setUI instead of setWatch +0.04: Tell clock widgets to hide. diff --git a/apps/binclock/app.js b/apps/binclock/app.js index f8cbe8dd5..d9c74e6ce 100644 --- a/apps/binclock/app.js +++ b/apps/binclock/app.js @@ -164,9 +164,6 @@ Bangle.on('lcdPower',on=>{ draw(); // draw immediately } }); -// Load widgets -Bangle.loadWidgets(); -Bangle.drawWidgets(); // Show launcher when button pressed Bangle.setUI("clockupdown", btn=>{ if (btn!=1) return; @@ -176,3 +173,6 @@ Bangle.setUI("clockupdown", btn=>{ displayTime = 0; } }); +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); diff --git a/apps/binclock/metadata.json b/apps/binclock/metadata.json index d17045868..2ca2755a6 100644 --- a/apps/binclock/metadata.json +++ b/apps/binclock/metadata.json @@ -2,7 +2,7 @@ "id": "binclock", "name": "Binary Clock", "shortName": "Binary Clock", - "version": "0.03", + "version": "0.04", "description": "A binary clock with hours and minutes. BTN1 toggles a digital clock.", "icon": "app.png", "type": "clock", diff --git a/apps/binwatch/ChangeLog b/apps/binwatch/ChangeLog index 1e54f489c..e355155b3 100644 --- a/apps/binwatch/ChangeLog +++ b/apps/binwatch/ChangeLog @@ -2,3 +2,5 @@ 0.02: first running version for BangleJs2 0.03: corrected icon, added screen shot, extended description 0.04: corrected format of background image (raw binary) +0.05: move setUI() up before draw() as to not have a false positive 'sanity +check' when building on github. diff --git a/apps/binwatch/app.js b/apps/binwatch/app.js index 28d7a06a5..153bebb32 100644 --- a/apps/binwatch/app.js +++ b/apps/binwatch/app.js @@ -334,6 +334,7 @@ function setRuntimeValues(resolution) { var hour = 0, minute = 1, second = 50; var batVLevel = 20; +Bangle.setUI("clock"); function draw() { var d = new Date(); @@ -371,7 +372,6 @@ function draw() { } // Show launcher when button pressed -Bangle.setUI("clock"); setRuntimeValues(g.getWidth()); g.reset().clear(); Bangle.loadWidgets(); diff --git a/apps/binwatch/metadata.json b/apps/binwatch/metadata.json index 0b5fb2c72..0b4dbc697 100644 --- a/apps/binwatch/metadata.json +++ b/apps/binwatch/metadata.json @@ -3,7 +3,7 @@ "shortName":"BinWatch", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], - "version":"0.04", + "version":"0.05", "supports": ["BANGLEJS2"], "readme": "README.md", "allow_emulator":true, diff --git a/apps/blobclk/ChangeLog b/apps/blobclk/ChangeLog index 9c4ef5b7b..193eb5024 100644 --- a/apps/blobclk/ChangeLog +++ b/apps/blobclk/ChangeLog @@ -5,3 +5,4 @@ 0.04: Modified to account for changes in the behavior of Graphics.fillPoly 0.05: Slight increase to draw speed after LCD on 0.06: Update to use Bangle.setUI instead of setWatch, allow themes and different size screens +0.07: Tell clock widgets to hide. diff --git a/apps/blobclk/clock-blob.js b/apps/blobclk/clock-blob.js index c84b8a1e6..d23e18ff9 100644 --- a/apps/blobclk/clock-blob.js +++ b/apps/blobclk/clock-blob.js @@ -99,6 +99,10 @@ function startTimers() { Bangle.drawWidgets(); intervalRef = setInterval(redraw,1000); } + +// Show launcher when button pressed +Bangle.setUI("clock"); + Bangle.loadWidgets(); startTimers(); Bangle.on('lcdPower',function(on) { @@ -108,5 +112,3 @@ Bangle.on('lcdPower',function(on) { clearTimers(); } }); -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/blobclk/metadata.json b/apps/blobclk/metadata.json index 85d7deabe..3ae8de222 100644 --- a/apps/blobclk/metadata.json +++ b/apps/blobclk/metadata.json @@ -2,7 +2,7 @@ "id": "blobclk", "name": "Large Digit Blob Clock", "shortName": "Blob Clock", - "version": "0.06", + "version": "0.07", "description": "A clock with big digits", "icon": "clock-blob.png", "type": "clock", diff --git a/apps/boldclk/ChangeLog b/apps/boldclk/ChangeLog index 30ac31c61..0c6e8cb52 100644 --- a/apps/boldclk/ChangeLog +++ b/apps/boldclk/ChangeLog @@ -3,3 +3,4 @@ 0.04: Work with themes, smaller screens 0.05: Adjust hand lengths to be within 'tick' points 0.06: Removed "wake LCD on face-up"-feature: A watch-face should not set things like "wake LCD on face-up". +0.07: Tell clock widgets to hide. diff --git a/apps/boldclk/bold_clock.js b/apps/boldclk/bold_clock.js index 9d3ea0756..763530a32 100644 --- a/apps/boldclk/bold_clock.js +++ b/apps/boldclk/bold_clock.js @@ -130,9 +130,10 @@ Bangle.on('lcdPower', (on) => { } }); +// Show launcher when button pressed +Bangle.setUI("clock"); + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); startTimers(); -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/boldclk/metadata.json b/apps/boldclk/metadata.json index cf961347d..086203142 100644 --- a/apps/boldclk/metadata.json +++ b/apps/boldclk/metadata.json @@ -1,7 +1,7 @@ { "id": "boldclk", "name": "Bold Clock", - "version": "0.06", + "version": "0.07", "description": "Simple, readable and practical clock", "icon": "bold_clock.png", "screenshots": [{"url":"screenshot_bold.png"}], diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index a43ecf86e..780d9cc7d 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -52,3 +52,15 @@ 0.46: Fix no clock found error on Bangle.js 2 0.47: Add polyfill for setUI with an object as an argument (fix regression for 2v12 devices after Layout module changed) 0.48: Workaround for BTHRM issues on Bangle.js 1 (write .boot files in chunks) +0.49: Store first found clock as a setting to speed up further boots +0.50: Allow setting of screen rotation + Remove support for 2v11 and earlier firmware +0.51: Remove patches for 2v10 firmware (BEEPSET and setUI) + Add patch to ensure that compass heading is corrected on pre-2v15.68 firmware + Ensure clock is only fast-loaded if it doesn't contain widgets +0.52: Ensure heading patch for pre-2v15.68 firmware applies to getCompass +0.53: Add polyfills for pre-2v15.135 firmware for Bangle.load and Bangle.showClock +0.54: Fix for invalid version comparison in polyfill +0.55: Add toLocalISOString polyfill for pre-2v15 firmwares + Only add boot info comments if settings.bootDebug was set + If settings.bootDebug is set, output timing for each section of .boot0 diff --git a/apps/boot/bootloader.js b/apps/boot/bootloader.js index 45e271f30..6e6466f48 100644 --- a/apps/boot/bootloader.js +++ b/apps/boot/bootloader.js @@ -1,8 +1,13 @@ // This runs after a 'fresh' boot -var clockApp=(require("Storage").readJSON("setting.json",1)||{}).clock; -if (clockApp) clockApp = require("Storage").read(clockApp); -if (!clockApp) { - clockApp = require("Storage").list(/\.info$/) +var s = require("Storage").readJSON("setting.json",1)||{}; +/* If were being called from JS code in order to load the clock quickly (eg from a launcher) +and the clock in question doesn't have widgets, force a normal 'load' as this will then +reset everything and remove the widgets. */ +if (global.__FILE__ && !s.clockHasWidgets) {load();throw "Clock has no widgets, can't fast load";} +// Otherwise continue to try and load the clock +var _clkApp = require("Storage").read(s.clock); +if (!_clkApp) { + _clkApp = require("Storage").list(/\.info$/) .map(file => { const app = require("Storage").readJSON(file,1); if (app && app.type == "clock") { @@ -11,9 +16,14 @@ if (!clockApp) { }) .filter(x=>x) .sort((a, b) => a.sortorder - b.sortorder)[0]; - if (clockApp) - clockApp = require("Storage").read(clockApp.src); + if (_clkApp){ + s.clock = _clkApp.src; + _clkApp = require("Storage").read(_clkApp.src); + s.clockHasWidgets = _clkApp.includes("Bangle.loadWidgets"); + require("Storage").writeJSON("setting.json", s); + } } -if (!clockApp) clockApp=`E.showMessage("No Clock Found");setWatch(()=>{Bangle.showLauncher();}, global.BTN2||BTN, {repeat:false,edge:"falling"});`; -eval(clockApp); -delete clockApp; +delete s; +if (!_clkApp) _clkApp=`E.showMessage("No Clock Found");setWatch(()=>{Bangle.showLauncher();}, global.BTN2||BTN, {repeat:false,edge:"falling"});`; +eval(_clkApp); +delete _clkApp; diff --git a/apps/boot/bootupdate.js b/apps/boot/bootupdate.js index 4cb3c52e4..112dfeba8 100644 --- a/apps/boot/bootupdate.js +++ b/apps/boot/bootupdate.js @@ -1,15 +1,22 @@ /* This rewrites boot0.js based on current settings. If settings changed then it recalculates, but this avoids us doing a whole bunch of reconfiguration most of the time. */ +{ // execute in our own scope so we don't have to free variables... E.showMessage(/*LANG*/"Updating boot0..."); -var s = require('Storage').readJSON('setting.json',1)||{}; -var BANGLEJS2 = process.env.HWVERSION==2; // Is Bangle.js 2 -var boot = "", bootPost = ""; +let s = require('Storage').readJSON('setting.json',1)||{}; +const BANGLEJS2 = process.env.HWVERSION==2; // Is Bangle.js 2 +const FWVERSION = parseFloat(process.env.VERSION.replace("v","").replace(/\.(\d\d)$/,".0$1")); +const DEBUG = s.bootDebug; // we can set this to enable debugging output in boot0 +let boot = "", bootPost = ""; +if (DEBUG) { + boot += "var _tm=Date.now()\n"; + bootPost += "delete _tm;"; +} if (require('Storage').hash) { // new in 2v11 - helps ensure files haven't changed - var CRC = E.CRC32(require('Storage').read('setting.json'))+require('Storage').hash(/\.boot\.js/)+E.CRC32(process.env.GIT_COMMIT); + let CRC = E.CRC32(require('Storage').read('setting.json'))+require('Storage').hash(/\.boot\.js/)+E.CRC32(process.env.GIT_COMMIT); boot += `if (E.CRC32(require('Storage').read('setting.json'))+require('Storage').hash(/\\.boot\\.js/)+E.CRC32(process.env.GIT_COMMIT)!=${CRC})`; } else { - var CRC = E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\.boot\.js/))+E.CRC32(process.env.GIT_COMMIT); + let CRC = E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\.boot\.js/))+E.CRC32(process.env.GIT_COMMIT); boot += `if (E.CRC32(require('Storage').read('setting.json'))+E.CRC32(require('Storage').list(/\\.boot\\.js/))+E.CRC32(process.env.GIT_COMMIT)!=${CRC})`; } boot += ` { eval(require('Storage').read('bootupdate.js')); throw "Storage Updated!"}\n`; @@ -62,23 +69,6 @@ if (s.ble===false) boot += `if (!NRF.getSecurityStatus().connected) NRF.sleep(); if (s.timeout!==undefined) boot += `Bangle.setLCDTimeout(${s.timeout});\n`; if (!s.timeout) boot += `Bangle.setLCDPower(1);\n`; boot += `E.setTimeZone(${s.timezone});`; -// Set vibrate, beep, etc IF on older firmwares -if (!Bangle.F_BEEPSET) { - if (!s.vibrate) boot += `Bangle.buzz=Promise.resolve;\n` - if (s.beep===false) boot += `Bangle.beep=Promise.resolve;\n` - else if (s.beep=="vib" && !BANGLEJS2) boot += `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); - }); - };\n`; -} // Draw out of memory errors onto the screen boot += `E.on('errorFlag', function(errorFlags) { g.reset(1).setColor("#ff0000").setFont("6x8").setFontAlign(0,1).drawString(errorFlags,g.getWidth()/2,g.getHeight()-1).flip(); @@ -92,82 +82,37 @@ if (s.options) boot+=`Bangle.setOptions(${E.toJS(s.options)});\n`; if (s.brightness && s.brightness!=1) boot+=`Bangle.setLCDBrightness(${s.brightness});\n`; if (s.passkey!==undefined && s.passkey.length==6) boot+=`NRF.setSecurity({passkey:${E.toJS(s.passkey.toString())}, mitm:1, display:1});\n`; if (s.whitelist) boot+=`NRF.on('connect', function(addr) { if (!(require('Storage').readJSON('setting.json',1)||{}).whitelist.includes(addr)) NRF.disconnect(); });\n`; -// Pre-2v10 firmwares without a theme/setUI -delete g.theme; // deleting stops us getting confused by our own decl. builtins can't be deleted -if (!g.theme) { - boot += `g.theme={fg:-1,bg:0,fg2:-1,bg2:7,fgH:-1,bgH:0x02F7,dark:true};\n`; -} -try { - Bangle.setUI({}); // In 2v12.xx we added the option for mode to be an object - for 2v12 and earlier, add a fix if it fails with an object supplied -} catch(e) { - boot += `Bangle._setUI = Bangle.setUI; -Bangle.setUI=function(mode, cb) { - if (Bangle.uiRemove) { - Bangle.uiRemove(); - delete Bangle.uiRemove; - } - if ("object"==typeof mode) { - // TODO: handle mode.back? - mode = mode.mode; - } - Bangle._setUI(mode, cb); -};\n`; -} -delete E.showScroller; // deleting stops us getting confused by our own decl. builtins can't be deleted -if (!E.showScroller) { // added in 2v11 - this is a limited functionality polyfill - boot += `E.showScroller = (function(a){function n(){g.reset();b>=l+c&&(c=1+b-l);bm||m>=a.c)break;var f=24+d*a.h;a.draw(m,{x:0,y:f,w:h,h:a.h});d+c==b&&g.setColor(g.theme.fg).drawRect(0,f,h-1,f+a.h-1).drawRect(1,f+1,h-2,f+a.h-2)}g.setColor(c?g.theme.fg:g.theme.bg);g.fillPoly([e,6,e-14,20,e+14,20]);g.setColor(a.c>l+c?g.theme.fg:g.theme.bg);g.fillPoly([e,k-7,e-14,k-21,e+14,k-21])}if(!a)return Bangle.setUI();var b=0,c=0,h=g.getWidth(), -k=g.getHeight(),e=h/2,l=Math.floor((k-48)/a.h);g.reset().clearRect(0,24,h-1,k-1);n();Bangle.setUI("updown",d=>{d?(b+=d,0>b&&(b=a.c-1),b>=a.c&&(b=0),n()):a.select(b)})});\n`; -} -delete g.imageMetrics; // deleting stops us getting confused by our own decl. builtins can't be deleted -if (!g.imageMetrics) { // added in 2v11 - this is a limited functionality polyfill - boot += `Graphics.prototype.imageMetrics=function(src) { - if (src[0]) return {width:src[0],height:src[1]}; - else if ('object'==typeof src) return { - width:("width" in src) ? src.width : src.getWidth(), - height:("height" in src) ? src.height : src.getHeight()}; - var im = E.toString(src); - return {width:im.charCodeAt(0), height:im.charCodeAt(1)}; -};\n`; -} -delete g.stringMetrics; // deleting stops us getting confused by our own decl. builtins can't be deleted -if (!g.stringMetrics) { // added in 2v11 - this is a limited functionality polyfill - boot += `Graphics.prototype.stringMetrics=function(txt) { - txt = txt.toString().split("\\n"); - return {width:Math.max.apply(null,txt.map(x=>g.stringWidth(x))), height:this.getFontHeight()*txt.length}; -};\n`; -} -delete g.wrapString; // deleting stops us getting confused by our own decl. builtins can't be deleted -if (!g.wrapString) { // added in 2v11 - this is a limited functionality polyfill - boot += `Graphics.prototype.wrapString=function(str, maxWidth) { - var lines = []; - for (var unwrappedLine of str.split("\\n")) { - var words = unwrappedLine.split(" "); - var line = words.shift(); - for (var word of words) { - if (g.stringWidth(line + " " + word) > maxWidth) { - lines.push(line); - line = word; - } else { - line += " " + word; - } - } - lines.push(line); - } - return lines; -};\n`; -} -delete Bangle.appRect; // deleting stops us getting confused by our own decl. builtins can't be deleted -if (!Bangle.appRect) { // added in 2v11 - polyfill for older firmwares - boot += `Bangle.appRect = ((y,w,h)=>({x:0,y:0,w:w,h:h,x2:w-1,y2:h-1}))(g.getWidth(),g.getHeight()); - (lw=>{ Bangle.loadWidgets = () => { lw(); Bangle.appRect = ((y,w,h)=>({x:0,y:y,w:w,h:h-y,x2:w-1,y2:h-(1+h)}))(global.WIDGETS?24:0,g.getWidth(),g.getHeight()); }; })(Bangle.loadWidgets);\n`; -} +if (s.rotate) boot+=`g.setRotation(${s.rotate&3},${s.rotate>>2});\n` // screen rotation +// ================================================== FIXING OLDER FIRMWARES +if (FWVERSION<215.068) // 2v15.68 and before had compass heading inverted. + boot += `Bangle.on('mag',e=>{if(!isNaN(e.heading))e.heading=360-e.heading;}); +Bangle.getCompass=(c=>(()=>{e=c();if(!isNaN(e.heading))e.heading=360-e.heading;return e;}))(Bangle.getCompass);`; +// deleting stops us getting confused by our own decl. builtins can't be deleted +// this is a polyfill without fastloading capability +delete Bangle.showClock; +if (!Bangle.showClock) boot += `Bangle.showClock = ()=>{load(".bootcde")};\n`; +delete Bangle.load; +if (!Bangle.load) boot += `Bangle.load = load;\n`; +let date = new Date(); +delete date.toLocalISOString; // toLocalISOString was only introduced in 2v15 +if (!date.toLocalISOString) boot += `Date.prototype.toLocalISOString = function() { + var o = this.getTimezoneOffset(); + var d = new Date(this.getTime() - o*60000); + var sign = o>0?"-":"+"; + o = Math.abs(o); + return d.toISOString().slice(0,-1)+sign+Math.floor(o/60).toString().padStart(2,0)+(o%60).toString().padStart(2,0); +};\n`; + +// show timings +if (DEBUG) boot += `print(".boot0",0|(Date.now()-_tm),"ms");_tm=Date.now();\n` +// ================================================== BOOT.JS // Append *.boot.js files // These could change bleServices/bleServiceOptions if needed -var bootFiles = require('Storage').list(/\.boot\.js$/).sort((a,b)=>{ - var getPriority = /.*\.(\d+)\.boot\.js$/; - var aPriority = a.match(getPriority); - var bPriority = b.match(getPriority); +let bootFiles = require('Storage').list(/\.boot\.js$/).sort((a,b)=>{ + let getPriority = /.*\.(\d+)\.boot\.js$/; + let aPriority = a.match(getPriority); + let bPriority = b.match(getPriority); if (aPriority && bPriority){ return parseInt(aPriority[1]) - parseInt(bPriority[1]); } else if (aPriority && !bPriority){ @@ -178,14 +123,16 @@ var bootFiles = require('Storage').list(/\.boot\.js$/).sort((a,b)=>{ return a==b ? 0 : (a>b ? 1 : -1); }); // precalculate file size -var fileSize = boot.length + bootPost.length; +let fileSize = boot.length + bootPost.length; bootFiles.forEach(bootFile=>{ // match the size of data we're adding below in bootFiles.forEach - fileSize += 2+bootFile.length+1+require('Storage').read(bootFile).length+2; + if (DEBUG) fileSize += 2+bootFile.length+1; // `//${bootFile}\n` comment + fileSize += require('Storage').read(bootFile).length+2; // boot code plus ";\n" + if (DEBUG) fileSize += 48+E.toJS(bootFile).length; // `print(${E.toJS(bootFile)},0|(Date.now()-_tm),"ms");_tm=Date.now();\n` }); // write file in chunks (so as not to use up all RAM) require('Storage').write('.boot0',boot,0,fileSize); -var fileOffset = boot.length; +let fileOffset = boot.length; bootFiles.forEach(bootFile=>{ // we add a semicolon so if the file is wrapped in (function(){ ... }() // with no semicolon we don't end up with (function(){ ... }()(function(){ ... }() @@ -194,16 +141,18 @@ bootFiles.forEach(bootFile=>{ // "//"+bootFile+"\n"+require('Storage').read(bootFile)+";\n"; // but we need to do this without ever loading everything into RAM as some // boot files seem to be getting pretty big now. - require('Storage').write('.boot0',"//"+bootFile+"\n",fileOffset); - fileOffset+=2+bootFile.length+1; - var bf = require('Storage').read(bootFile); + if (DEBUG) { + require('Storage').write('.boot0',`//${bootFile}\n`,fileOffset); + fileOffset+=2+bootFile.length+1; + } + let bf = require('Storage').read(bootFile); // we can't just write 'bf' in one go because at least in 2v13 and earlier // Espruino wants to read the whole file into RAM first, and on Bangle.js 1 // it can be too big (especially BTHRM). - var bflen = bf.length; - var bfoffset = 0; + let bflen = bf.length; + let bfoffset = 0; while (bflen) { - var bfchunk = Math.min(bflen, 2048); + let bfchunk = Math.min(bflen, 2048); require('Storage').write('.boot0',bf.substr(bfoffset, bfchunk),fileOffset); fileOffset+=bfchunk; bfoffset+=bfchunk; @@ -211,15 +160,14 @@ bootFiles.forEach(bootFile=>{ } require('Storage').write('.boot0',";\n",fileOffset); fileOffset+=2; + if (DEBUG) { + require('Storage').write('.boot0',`print(${E.toJS(bootFile)},0|(Date.now()-_tm),"ms");_tm=Date.now();\n`,fileOffset); + fileOffset += 48+E.toJS(bootFile).length + } }); require('Storage').write('.boot0',bootPost,fileOffset); - -delete boot; -delete bootPost; -delete bootFiles; -delete fileSize; -delete fileOffset; E.showMessage(/*LANG*/"Reloading..."); -eval(require('Storage').read('.boot0')); +} // .bootcde should be run automatically after if required, since // we normally get called automatically from '.boot0' +eval(require('Storage').read('.boot0')); diff --git a/apps/boot/metadata.json b/apps/boot/metadata.json index 62adc4db1..455563a16 100644 --- a/apps/boot/metadata.json +++ b/apps/boot/metadata.json @@ -1,7 +1,7 @@ { "id": "boot", "name": "Bootloader", - "version": "0.48", + "version": "0.55", "description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings", "icon": "bootloader.png", "type": "bootloader", diff --git a/apps/bowserWF/ChangeLog b/apps/bowserWF/ChangeLog new file mode 100644 index 000000000..dd2b05fb3 --- /dev/null +++ b/apps/bowserWF/ChangeLog @@ -0,0 +1,3 @@ +... +0.02: First update with ChangeLog Added +0.03: updated watch face to use the ClockFace library diff --git a/apps/bowserWF/app.js b/apps/bowserWF/app.js index e53d945cc..956c43602 100644 --- a/apps/bowserWF/app.js +++ b/apps/bowserWF/app.js @@ -1,102 +1,233 @@ var sprite = { - width : 47, height : 47, bpp : 3, - transparent : 1, - buffer : require("heatshrink").decompress(atob("kmSpICFn/+BAwCImV//VICJuT//SogRMpmT/2SCJtSyQDB/4RMymRkmX/gRLygDC3/piVhCJElAYf/pNIkgRIlIDCl/6pVBkIRIGwWJEYPypMJCI9KGwQRBLANIPRI2CGoPkyVCBwmeyVLTYNJom8yImBz4gEqV/6Vf+g2BPwf/IIq8C/+kyVRkgDBp/5CIX/+mkz/+y/9BIOf0v6///5LdCz+kCIOk34RBYQMSp5XBGQVk/pNBAQP/9IyBxGSv4yCk/1OIK8EC4QgEpM/JgJ+EGoIRBTApQCEYvplLOFXIIdBO4SqBeQJABGoeTDQMlk5WCAAPSYQLgEz4aBlM/9IgB/7CCcAvP/QsBiVfUwOJBgUiCIcmpAVCy/+pMAKwMkRgIRCp6VBAwW6qVOgmSgPkwgRDv53E6WSuEkyEPRgmf2VJv5HBl2SgAKBwEJRgnJiVKp/Sr/0y/yBQOQv56DKwVSv2STwO/DgWD/BADmaDByRoBYoQRCgFCCIf/+jgDNwOUAwMg/kSPQbODX4IJBAwUH8B6DsmRl5oBl7OBklMyV+gBoDycSxMpiVLZwS8EAQeYyjaByR6BBIJBDAQnEIgbFCogOFRgQDBr//I4L0EAQsxAYP//5WCGQ6MCAAKbCpKYEAQiMB//kIQOUyf+CJF/CIIEBTYOfcgQRHBQv/CJKnBpP8GRTCDJIPkGRQCB5I3C/n/EZUgA")) + width: 47, + height: 47, + bpp: 3, + transparent: 1, + buffer: require("heatshrink").decompress( + atob( + "kmSpICFn/+BAwCImV//VICJuT//SogRMpmT/2SCJtSyQDB/4RMymRkmX/gRLygDC3/piVhCJElAYf/pNIkgRIlIDCl/6pVBkIRIGwWJEYPypMJCI9KGwQRBLANIPRI2CGoPkyVCBwmeyVLTYNJom8yImBz4gEqV/6Vf+g2BPwf/IIq8C/+kyVRkgDBp/5CIX/+mkz/+y/9BIOf0v6///5LdCz+kCIOk34RBYQMSp5XBGQVk/pNBAQP/9IyBxGSv4yCk/1OIK8EC4QgEpM/JgJ+EGoIRBTApQCEYvplLOFXIIdBO4SqBeQJABGoeTDQMlk5WCAAPSYQLgEz4aBlM/9IgB/7CCcAvP/QsBiVfUwOJBgUiCIcmpAVCy/+pMAKwMkRgIRCp6VBAwW6qVOgmSgPkwgRDv53E6WSuEkyEPRgmf2VJv5HBl2SgAKBwEJRgnJiVKp/Sr/0y/yBQOQv56DKwVSv2STwO/DgWD/BADmaDByRoBYoQRCgFCCIf/+jgDNwOUAwMg/kSPQbODX4IJBAwUH8B6DsmRl5oBl7OBklMyV+gBoDycSxMpiVLZwS8EAQeYyjaByR6BBIJBDAQnEIgbFCogOFRgQDBr//I4L0EAQsxAYP//5WCGQ6MCAAKbCpKYEAQiMB//kIQOUyf+CJF/CIIEBTYOfcgQRHBQv/CJKnBpP8GRTCDJIPkGRQCB5I3C/n/EZUgA" + ) + ), }; const boxes = { - width : 122, height : 56, bpp : 3, - transparent : 1, - buffer : require("heatshrink").decompress(atob("kmZkmSpICPwgDBmQUQAQMJAYNkFiOSiQDB5JESAYQsSpADByYsSyBZBydt23bAR+wgFJkwUQAQNggGSposR23AgMkzZESwECpM2IiUAgmSFiW2gDlBFiVsgDlBFiXYgDNBL4MDWZy2FgEGWZy2FgENWZy2EL4MbWZpTBWwZfBXJpTCWwZiCWZpTBWwZiCWZsbWwhiCWZpWCWwTORWwgXRWwgXRWwZESWwZESWwZESWwYXRWwgXRW362/W362/W362/W362/W362/W362/W362/W362/W362/W362/WwuAgazOWwsAgyzOWwsAhqzOWwhfBjazNKYK2DL4K5NKYS2DMQSzNKYK2DMQSzNja2EMQSzNKwS2CZyK2EC6K2EC6K2DIiS2DIiS2DIiUAFoMAAFTkBFtckyAtrLgWSpICnLIIsqyVAgAsqpIA=")) + width: 122, + height: 56, + bpp: 3, + transparent: 1, + buffer: require("heatshrink").decompress( + atob( + "kmZkmSpICPwgDBmQUQAQMJAYNkFiOSiQDB5JESAYQsSpADByYsSyBZBydt23bAR+wgFJkwUQAQNggGSposR23AgMkzZESwECpM2IiUAgmSFiW2gDlBFiVsgDlBFiXYgDNBL4MDWZy2FgEGWZy2FgENWZy2EL4MbWZpTBWwZfBXJpTCWwZiCWZpTBWwZiCWZsbWwhiCWZpWCWwTORWwgXRWwgXRWwZESWwZESWwZESWwYXRWwgXRW362/W362/W362/W362/W362/W362/W362/W362/W362/W362/WwuAgazOWwsAgyzOWwsAhqzOWwhfBjazNKYK2DL4K5NKYS2DMQSzNKYK2DMQSzNja2EMQSzNKwS2CZyK2EC6K2EC6K2DIiS2DIiS2DIiUAFoMAAFTkBFtckyAtrLgWSpICnLIIsqyVAgAsqpIA=" + ) + ), }; const background = { - width : 176, height : 176, bpp : 3, - transparent : 5, - buffer : require("heatshrink").decompress(atob("kmSpIC/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/ATWAgEAIP1///8iRB8gf/AAOCIPdIIARBBoJB/+E4IP4ABghB9v4CB8BB5g/92//9pB7wP/97FEIO9IgDACAAn8iVBIOlHH4xBDnA+wyY9IAAmB/BB//5B/IOQ/OAARBup5B/yV/IP5B/IP5BRt5B7/wDC7aD8/w+B+3bBgP7IP5B7HYNt23/AQPfIPX/9oCC24IDINwCBIRAAHIOACBHI3+g4EC/l/4BByAQkA//wpED//4gGAhJB3pMAgQFBgEBH3AC/AX4C/AX4C/AX4C/AX4C/AUOAgBB/v//ghB9gf///gH3UgiVIIAJBBwRB5j+CIIf8uBB5//wIIXb//+hJB6o/92/7v5B7/0/97GCIPYAG4MgIP/BjkSIP34/hB//5B/AAQ+0IP5B/IP5BN7ZB97///wCBIPX93yAB2wCB+5B5tv//dt24CB35B5v/+n/t+P/I4PH8ESIO38gFA/+CgH/+EIgiD3gACCPoMAgQ+2AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/ASVIgAACgRB/IPY8GkAHBiRB/IPBLKgJB/IP5B/AQUAkmQghB/IP2AgEAyVAiRB/IP5BBpMAIP5B/IIUkgBB/IP5BpoAsBgJBOgEEIIoIBIP5BlyE27dt2EEIJ4CBBAlIgRBgpEAhu2IIO24ESQwxB/IJQhGkEJIL8GHwQCDgOweQpB/IKMkwAKJILVgAofYeQhBzsEAIKICLoESILmBQARBBtuwgZB3kA4B4ENIgJBcpMAIMYCDIOcAgEbHYgCGsEJkhEBE6cBIP5BZfYQ+JIIkDsEBIP5BVyEAIKtAHxgCDwBEBINk2IKCGCIKmSpECIP5BUkEBHyACD2BBUFoMJIP5BSpEbHyQCDIP5BXkmAIP5B/AQcAbKJB/ILH/AAP8hM/AgWSv4KCAAP+gmfAoXJk4ME//gpIEC8mTBgvwkgEC+QRDAAX4gVPAgP5kgsCLwWQh/kMIUf5LuFg4jBAoMBKAJ5EwF/AoUA/yFFoE/CI6RDgY+BCIQsDIP5B/IP5B/IP5B/IJ/AIJfghJBKv0EIJcAIJfwIP5BMhMAAAMEz5BGgmABoVJII9IBgUkII8kBgUSII8CoAMBhJB/IIsQoMAYoP/AAP4YpAMC/+BII9/BgXAYpAMC8DFIBgXwIIcCIP6DCgkQh/kCIRBIbQcBIJAFCgBBICI5BE/IRDFgQA=")) + width: 176, + height: 176, + bpp: 3, + transparent: 5, + buffer: require("heatshrink").decompress( + atob( + "kmSpIC/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/ATWAgEAIP1///8iRB8gf/AAOCIPdIIARBBoJB/+E4IP4ABghB9v4CB8BB5g/92//9pB7wP/97FEIO9IgDACAAn8iVBIOlHH4xBDnA+wyY9IAAmB/BB//5B/IOQ/OAARBup5B/yV/IP5B/IP5BRt5B7/wDC7aD8/w+B+3bBgP7IP5B7HYNt23/AQPfIPX/9oCC24IDINwCBIRAAHIOACBHI3+g4EC/l/4BByAQkA//wpED//4gGAhJB3pMAgQFBgEBH3AC/AX4C/AX4C/AX4C/AX4C/AUOAgBB/v//ghB9gf///gH3UgiVIIAJBBwRB5j+CIIf8uBB5//wIIXb//+hJB6o/92/7v5B7/0/97GCIPYAG4MgIP/BjkSIP34/hB//5B/AAQ+0IP5B/IP5BN7ZB97///wCBIPX93yAB2wCB+5B5tv//dt24CB35B5v/+n/t+P/I4PH8ESIO38gFA/+CgH/+EIgiD3gACCPoMAgQ+2AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/AX4C/ASVIgAACgRB/IPY8GkAHBiRB/IPBLKgJB/IP5B/AQUAkmQghB/IP2AgEAyVAiRB/IP5BBpMAIP5B/IIUkgBB/IP5BpoAsBgJBOgEEIIoIBIP5BlyE27dt2EEIJ4CBBAlIgRBgpEAhu2IIO24ESQwxB/IJQhGkEJIL8GHwQCDgOweQpB/IKMkwAKJILVgAofYeQhBzsEAIKICLoESILmBQARBBtuwgZB3kA4B4ENIgJBcpMAIMYCDIOcAgEbHYgCGsEJkhEBE6cBIP5BZfYQ+JIIkDsEBIP5BVyEAIKtAHxgCDwBEBINk2IKCGCIKmSpECIP5BUkEBHyACD2BBUFoMJIP5BSpEbHyQCDIP5BXkmAIP5B/AQcAbKJB/ILH/AAP8hM/AgWSv4KCAAP+gmfAoXJk4ME//gpIEC8mTBgvwkgEC+QRDAAX4gVPAgP5kgsCLwWQh/kMIUf5LuFg4jBAoMBKAJ5EwF/AoUA/yFFoE/CI6RDgY+BCIQsDIP5B/IP5B/IP5B/IJ/AIJfghJBKv0EIJcAIJfwIP5BMhMAAAMEz5BGgmABoVJII9IBgUkII8kBgUSII8CoAMBhJB/IIsQoMAYoP/AAP4YpAMC/+BII9/BgXAYpAMC8DFIBgXwIIcCIP6DCgkQh/kCIRBIbQcBIJAFCgBBICI5BE/IRDFgQA=" + ) + ), }; numbersDims = { - width: 20, - height: 44 + width: 20, + height: 44, }; -const numbers = [ - require("heatshrink").decompress(atob("ikswcBkmSpIC/ARGQKYQIDAwUEBxMAAQNAgECpMgAQMkB4IOIAQQLCgEQBwQaBgEBB1oCBBwYCCiRWDCIRWEO5wOHAX4CnA=")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/ARNIKYIIEwEAggOKNIQODyAHCBxQsWB3TUFgMgA4sSBwzU/AVA=")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/AQ8gKggIBAwkCBw+QCIQLCgIRCDQcQBwwyDDwUSCgVAAwIOBEwI7EpI7FBw4FDghZGHwgOEF4Y+CEYQ+DBxQADNAIAFNAIOFa/4CoA=")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/AQ8gKosSAwsBBw4aCoEAgQjEBoIpEBwtIBoIUEwEAggUDBwwyDDoWQA4ZWHhIIEJQoOCgI+EBwMQEAYOJO4oLBO4oRDJQrX/AU4")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/ARNIKgQIDwAGBgQOJNQYOCyAHDBxEggB6BBwYDBiVABxIjBCIIODF4YOEAAkBV40QBwxiDNAosEB0IC/AUg")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/AQ5UFkmQAwkCBxIdGCIIIDBxAsTgAaEkEASooOBiQOVJQgOBiBKDBxMSJQwRBLIgRCBwjX/AVA=")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/ARGQKgYICAwcCBxADBiQdDkEANYoOGEAYyEHYoOIHYqfFBxIdDBAMQFgZHCBysSFgwRBO46GFa/4CnA")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/AQ5VGiAGFgIOIDQUgBwUCEYQOJGQYNBHAlADQgOHwEAggUDpANBCgYpBBwmQAwJiGhIjDB1gC/AU4A=")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/AQ8gKYYICAwcEBxGQgAaDgVJgACBDQQOJgB6CBwcAiQODHa4AEhIRBpAHDiARBwAGCgIgCFIYOCFIYOHiQrEJQxlCBwzX/AVAA=")), - require("heatshrink").decompress(atob("ikswcBkmSpIC/AQ8gKggIBAwkCBw+QCIQLCgIRCDQcQBzkSTAsBHYoOIL4gOCMooOENAYOCoA4EBwoqDgiGGF4gOEa/4CoA=")), +const numbers = [ + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/ARGQKYQIDAwUEBxMAAQNAgECpMgAQMkB4IOIAQQLCgEQBwQaBgEBB1oCBBwYCCiRWDCIRWEO5wOHAX4CnA=" + ) + ), + require("heatshrink").decompress( + atob("ikswcBkmSpIC/ARNIKYIIEwEAggOKNIQODyAHCBxQsWB3TUFgMgA4sSBwzU/AVA=") + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/AQ8gKggIBAwkCBw+QCIQLCgIRCDQcQBwwyDDwUSCgVAAwIOBEwI7EpI7FBw4FDghZGHwgOEF4Y+CEYQ+DBxQADNAIAFNAIOFa/4CoA=" + ) + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/AQ8gKosSAwsBBw4aCoEAgQjEBoIpEBwtIBoIUEwEAggUDBwwyDDoWQA4ZWHhIIEJQoOCgI+EBwMQEAYOJO4oLBO4oRDJQrX/AU4" + ) + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/ARNIKgQIDwAGBgQOJNQYOCyAHDBxEggB6BBwYDBiVABxIjBCIIODF4YOEAAkBV40QBwxiDNAosEB0IC/AUg" + ) + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/AQ5UFkmQAwkCBxIdGCIIIDBxAsTgAaEkEASooOBiQOVJQgOBiBKDBxMSJQwRBLIgRCBwjX/AVA=" + ) + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/ARGQKgYICAwcCBxADBiQdDkEANYoOGEAYyEHYoOIHYqfFBxIdDBAMQFgZHCBysSFgwRBO46GFa/4CnA" + ) + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/AQ5VGiAGFgIOIDQUgBwUCEYQOJGQYNBHAlADQgOHwEAggUDpANBCgYpBBwmQAwJiGhIjDB1gC/AU4A=" + ) + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/AQ8gKYYICAwcEBxGQgAaDgVJgACBDQQOJgB6CBwcAiQODHa4AEhIRBpAHDiARBwAGCgIgCFIYOCFIYOHiQrEJQxlCBwzX/AVAA=" + ) + ), + require("heatshrink").decompress( + atob( + "ikswcBkmSpIC/AQ8gKggIBAwkCBw+QCIQLCgIRCDQcQBzkSTAsBHYoOIL4gOCMooOENAYOCoA4EBwoqDgiGGF4gOEa/4CoA=" + ) + ), ]; -digitPositions = [ // relative to the box - {x:13, y:6}, {x:32, y:6}, - {x:74, y:6}, {x:93, y:6}, +digitPositions = [ + // relative to the box + { x: 13, y: 6 }, + { x: 32, y: 6 }, + { x: 74, y: 6 }, + { x: 93, y: 6 }, ]; -var drawTimeout; const animation_duration = 1; // seconds -const animation_steps = 20; +const animation_steps = 20; const jump_height = 45; // top coordinate of the jump const seconds_per_minute = 60; -function draw() { - const now = new Date(); - g.drawImage(background, 0, 0); - var boxTL_x = 27; var boxTL_y = 29; - var sprite_TL_x = 72; var sprite_TL_y = 161 - sprite.height; - const seconds = now.getSeconds()%seconds_per_minute + now.getMilliseconds()/1000; - const hours = now.getHours(); - const minutes = now.getMinutes(); - - var time_advance = seconds / animation_duration; - - if (time_advance < 0.5) { - sprite_TL_y += (jump_height - sprite_TL_y) * time_advance * 2; - } else if (time_advance < 1) { - sprite_TL_y = jump_height + (sprite_TL_y-jump_height) * (time_advance-0.5) * 2; - } - const box_penetration = boxTL_y + boxes.height - sprite_TL_y; - if (box_penetration > 0) { - boxTL_y -= box_penetration; - } - g.drawImage(boxes, boxTL_x, boxTL_y); - g.drawImage(numbers[(hours / 10) >> 0], boxTL_x+digitPositions[0].x, boxTL_y+digitPositions[0].y); - g.drawImage(numbers[(hours % 10) >> 0], boxTL_x+digitPositions[1].x, boxTL_y+digitPositions[1].y); - g.drawImage(numbers[(minutes / 10) >> 0], boxTL_x+digitPositions[2].x, boxTL_y+digitPositions[2].y); - g.drawImage(numbers[(minutes % 10) >> 0], boxTL_x+digitPositions[3].x, boxTL_y+digitPositions[3].y); - g.drawImage(sprite, sprite_TL_x, sprite_TL_y); - Bangle.drawWidgets(); - - const timeout = time_advance <= 1? - animation_duration / animation_steps - : (seconds_per_minute - seconds); - setTimeout( _=>{ - drawTimeout = undefined; - draw(); - }, timeout * 1000); -} +const ClockFace = require("ClockFace"); +const clock = new ClockFace({ + precision: 60, // just once a minute -// Clear the screen once, at startup -g.setTheme({bg:"#00f",fg:"#fff",dark:true}).clear(); + init: function() { + // Clear the screen once, at startup + g.setTheme({ bg: "#00f", fg: "#fff", dark: true }).clear(); -Bangle.on('lcdPower',on=>{ - if (on) { - draw(); // draw immediately, queue redraw - } else { // stop draw timer - if (drawTimeout) { - clearTimeout(drawTimeout); - } - drawTimeout = undefined; - } + this.drawing = true; + + this.simpleDraw = function(now) { + var boxTL_x = 27; + var boxTL_y = 29; + var sprite_TL_x = 72; + var sprite_TL_y = 161 - sprite.height; + const seconds = + (now.getSeconds() % seconds_per_minute) + now.getMilliseconds() / 1000; + const hours = + this.is12Hour && now.getHours() > 12 + ? now.getHours() - 12 + : now.getHours(); + + const minutes = now.getMinutes(); + + g.drawImage(boxes, boxTL_x, boxTL_y); + g.drawImage( + numbers[(hours / 10) >> 0], + boxTL_x + digitPositions[0].x, + boxTL_y + digitPositions[0].y + ); + g.drawImage( + numbers[hours % 10 >> 0], + boxTL_x + digitPositions[1].x, + boxTL_y + digitPositions[1].y + ); + g.drawImage( + numbers[(minutes / 10) >> 0], + boxTL_x + digitPositions[2].x, + boxTL_y + digitPositions[2].y + ); + g.drawImage( + numbers[minutes % 10 >> 0], + boxTL_x + digitPositions[3].x, + boxTL_y + digitPositions[3].y + ); + }; + }, + + pause: function() { + this.drawing = false; + }, + + resume: function() { + this.drawing = true; + }, + + draw: function(now) { + if (!this.drawing) { + this.simpleDraw(now); + return; + } + g.drawImage(background, 0, 0); + var boxTL_x = 27; + var boxTL_y = 29; + var sprite_TL_x = 72; + var sprite_TL_y = 161 - sprite.height; + const seconds = + (now.getSeconds() % seconds_per_minute) + now.getMilliseconds() / 1000; + const hours = + this.is12Hour && now.getHours() > 12 + ? now.getHours() - 12 + : now.getHours(); + + const minutes = now.getMinutes(); + + var time_advance = seconds / animation_duration; + + if (time_advance < 0.5) { + sprite_TL_y += (jump_height - sprite_TL_y) * time_advance * 2; + } else if (time_advance < 1) { + sprite_TL_y = + jump_height + (sprite_TL_y - jump_height) * (time_advance - 0.5) * 2; + } + const box_penetration = boxTL_y + boxes.height - sprite_TL_y; + if (box_penetration > 0) { + boxTL_y -= box_penetration; + } + g.drawImage(boxes, boxTL_x, boxTL_y); + g.drawImage( + numbers[(hours / 10) >> 0], + boxTL_x + digitPositions[0].x, + boxTL_y + digitPositions[0].y + ); + g.drawImage( + numbers[hours % 10 >> 0], + boxTL_x + digitPositions[1].x, + boxTL_y + digitPositions[1].y + ); + g.drawImage( + numbers[(minutes / 10) >> 0], + boxTL_x + digitPositions[2].x, + boxTL_y + digitPositions[2].y + ); + g.drawImage( + numbers[minutes % 10 >> 0], + boxTL_x + digitPositions[3].x, + boxTL_y + digitPositions[3].y + ); + g.drawImage(sprite, sprite_TL_x, sprite_TL_y); + // Bangle.drawWidgets(); + + if (this.drawing) { + const timeout = + time_advance <= 1 ? animation_duration / animation_steps : -999; + if (timeout > 0) { + setTimeout((_) => { + this.draw(new Date()); + }, timeout * 1000); + } + } + }, + + update: function(date, changed) { + if (this.drawing && changed.m) { + this.draw(date); + } + }, }); -// Show launcher when middle button pressed -Bangle.setUI("clock"); -// Load widgets -Bangle.loadWidgets(); - -draw(); +clock.start(); diff --git a/apps/bowserWF/metadata.json b/apps/bowserWF/metadata.json index a0bdfb8e9..bba15e5df 100644 --- a/apps/bowserWF/metadata.json +++ b/apps/bowserWF/metadata.json @@ -1,18 +1,18 @@ -{ +{ "id": "bowserWF", "name": "Bowser Watchface", - "shortName":"Bowser Watchface", - "version":"0.02", + "shortName": "Bowser Watchface", + "version": "0.03", "description": "Let bowser show you the time", "icon": "app.png", "type": "clock", "tags": "clock", - "supports" : ["BANGLEJS2"], + "supports": ["BANGLEJS2"], "allow_emulator": true, "readme": "README.md", "storage": [ - {"name":"bowserWF.app.js","url":"app.js"}, - {"name":"bowserWF.img","url":"app-icon.js","evaluate":true} + { "name": "bowserWF.app.js", "url": "app.js" }, + { "name": "bowserWF.img", "url": "app-icon.js", "evaluate": true } ], - "data": [{"name":"bowserWF.json"}] + "data": [{ "name": "bowserWF.json" }] } diff --git a/apps/ncfrun/ChangeLog b/apps/bthometemp/ChangeLog similarity index 100% rename from apps/ncfrun/ChangeLog rename to apps/bthometemp/ChangeLog diff --git a/apps/bthometemp/README.md b/apps/bthometemp/README.md new file mode 100644 index 000000000..1a8212ea4 --- /dev/null +++ b/apps/bthometemp/README.md @@ -0,0 +1,9 @@ +# BTHome Temperature and Pressure + +This app displays temperature and pressure and advertises them over bluetooth using BTHome.io standard (along with battery level) + +This can be used to integrate with [Home Assistant](https://www.home-assistant.io/), so you can use your Bangle as a wireless temperature/pressure sensor. + +More info on the standard at https://bthome.io + +And the data format used is https://bthome.io/format/ diff --git a/apps/bthometemp/app-icon.js b/apps/bthometemp/app-icon.js new file mode 100644 index 000000000..e2dff3eb9 --- /dev/null +++ b/apps/bthometemp/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4kA///1N6BIPf//1gMIwdE8sG2me+9Y/8C/2snXsoUNpdnzdt/xj/AH4AYgMRAAUQCyoYSCQNXs1muoFBFyHm1X//+qtwwPiMX1+YmczxP6uIwNFwN6yeDnGDmc504wNFwOpnGYC4OJweaGBsR9WTmYtBmc4GAOuC5ZGBt4SBAAQEBwf2JBcBiupnIuCmedxGTzVRC5cX1AuDnPZF4OKuIXLi3zIoedMgMzn9hC5uICQON5IDBxAXSznYC6RdDPQYXNO4JcB7pdCO56nBnGZ7p6DU5zXBXgSqDa5sAiPqIgOZd4c510RCxQXBi+pRQIXBxODzVxC5hIBvR1DnE505GMGAevzAvC/QuNGAfm1X//+qtwuOGAURq9ms11AoIWOGAQAEFw1EDBwWFggBCkUgAQMigUAAIIAJoABDCgIXQFwYXBCYYBDHAMCEAIkCFgcEAIIKCCoQFCkAhBAQIlCkAsBOoIXCBoIvEAwQTCAYI2BIwgXIF4YXDQwIVCC4YIBMIwfCAQRfGYBSPNC6TBFACgwBACouWAH4AiA=")) diff --git a/apps/bthometemp/app.js b/apps/bthometemp/app.js new file mode 100644 index 000000000..7b55777d1 --- /dev/null +++ b/apps/bthometemp/app.js @@ -0,0 +1,58 @@ +// history of temperature/pressure readings +var history = []; + +// When we get temperature... +function onTemperature(p) { + // Average the last 5 temperature readings + while (history.length>4) history.shift(); + history.push(p); + var avrTemp = history.reduce((i,h)=>h.temperature+i,0) / history.length; + var avrPressure = history.reduce((i,h)=>h.pressure+i,0) / history.length; + var t = require('locale').temp(avrTemp).replace("'","°"); + // Draw + var rect = Bangle.appRect; + g.reset(1).clearRect(rect.x, rect.y, rect.x2, rect.y2); + var x = (rect.x+rect.x2)/2; + var y = (rect.y+rect.y2)/2 + 10; + g.setFont("6x15").setFontAlign(0,0).drawString("Temperature:", x, y - 65); + g.setFontVector(50).setFontAlign(0,0).drawString(t, x, y-25); + g.setFont("6x15").setFontAlign(0,0).drawString("Pressure:", x, y+15 ); + g.setFont("12x20").setFontAlign(0,0).drawString(Math.round(avrPressure)+" hPa", x, y+40); + // Set Bluetooth Advertising + // https://bthome.io/format/ + var temp100 = Math.round(avrTemp*100); + var pressure100 = Math.round(avrPressure*100); + + Bangle.bleAdvert[0xFCD2] = [ 0x40, /* BTHome Device Information + bit 0: "Encryption flag" + bit 1-4: "Reserved for future use" + bit 5-7: "BTHome Version" */ + + 0x01, // Battery, 8 bit + E.getBattery(), + + 0x02, // Temperature, 16 bit + temp100&255,temp100>>8, + + 0x04, // Pressure, 16 bit + pressure100&255,(pressure100>>8)&255,pressure100>>16 + ]; + NRF.setAdvertising(Bangle.bleAdvert); +} + +// Gets the temperature in the most accurate way with pressure sensor +function drawTemperature() { + Bangle.getPressure().then(p =>{if (p) onTemperature(p);}); +} + +if (!Bangle.bleAdvert) Bangle.bleAdvert = {}; +setInterval(function() { + drawTemperature(); +}, 10000); // update every 10s +Bangle.loadWidgets(); +Bangle.setUI({ + mode : "custom", + back : function() {load();} +}); +E.showMessage("Reading temperature..."); +drawTemperature(); diff --git a/apps/bthometemp/app.png b/apps/bthometemp/app.png new file mode 100644 index 000000000..6c8eb3f14 Binary files /dev/null and b/apps/bthometemp/app.png differ diff --git a/apps/bthometemp/metadata.json b/apps/bthometemp/metadata.json new file mode 100644 index 000000000..4bfd08c31 --- /dev/null +++ b/apps/bthometemp/metadata.json @@ -0,0 +1,14 @@ +{ "id": "bthometemp", + "name": "BTHome Temperature and Pressure", + "shortName":"BTHome T", + "version":"0.01", + "description": "Displays temperature and pressure, and advertises them over bluetooth using BTHome.io standard", + "icon": "app.png", + "tags": "bthome,bluetooth,temperature", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"bthometemp.app.js","url":"app.js"}, + {"name":"bthometemp.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/bthrm/ChangeLog b/apps/bthrm/ChangeLog index 00ed856d6..000c5e3f8 100644 --- a/apps/bthrm/ChangeLog +++ b/apps/bthrm/ChangeLog @@ -23,3 +23,21 @@ 0.08: Allow scanning for devices in settings 0.09: Misc Fixes and improvements (https://github.com/espruino/BangleApps/pull/1655) 0.10: Use default Bangle formatter for booleans +0.11: App now shows status info while connecting + Fixes to allow cached BluetoothRemoteGATTCharacteristic to work with 2v14.14 onwards (>1 central) +0.12: Fix HRM fallback handling + Use default boolean formatter in custom menu and directly apply config if useful + Allow recording unmodified internal HR + Better connection retry handling +0.13: Less time used during boot if disabled +0.14: Allow bonding (Debug menu) + Prevent mixing of BT and internal HRM events if both are enabled + Always use a grace period (default 0 ms) to decouple some connection steps + Device not found errors now utilize increasing timeouts +0.15: Fix recording internal sensor + Handle fallback to internal sensor consistently if BT bpm is 0 + Power internal sensor down if not needed for fallback +0.16: Set powerdownRequested correctly on BTHRM power on + Additional logging on errors + Add debug option for disabling active scanning +0.17: New GUI based on layout library diff --git a/apps/bthrm/README.md b/apps/bthrm/README.md index 8d5872670..f4eaf43af 100644 --- a/apps/bthrm/README.md +++ b/apps/bthrm/README.md @@ -19,7 +19,14 @@ Just install the app, then install an app that uses the heart rate monitor. Once installed you will have to go into this app's settings while your heart rate monitor is available for bluetooth pairing and scan for devices. -**To disable this and return to normal HRM, uninstall the app** +**To disable this and return to normal HRM, uninstall the app or change the settings** + +### Modes + +* Off - Internal HRM is used, no attempt on connecting to BT HRM. +* Default - Replaces internal HRM with BT HRM and falls back to internal HRM if no valid measurements received. +* Both - The BT HRM needs to be started explicitly by an app that wants to use it. BT HRM has its own event and is completely separated from the internal HRM. Apps not supporting the BT HRM will not see the BT HRM measurements. +* Custom - Combine low level settings as you see fit. ## Compatible Heart Rate Monitors @@ -35,6 +42,10 @@ So far it has been tested on: * Polar OH1 * Wahoo TICKR X 2 +## Recorder plugin + +The recorder plugin can record the BT HRM event (blue) and the original unchanged HRM event (green). This is mainly useful for debugging purposes or comparing the BT with the internal HRM, as the resulting "merged" HRM can be recordet using the default HRM recorder. + ## Internals This replaces `Bangle.setHRMPower` with its own implementation. diff --git a/apps/bthrm/boot.js b/apps/bthrm/boot.js index e9e640563..3e3d35737 100644 --- a/apps/bthrm/boot.js +++ b/apps/bthrm/boot.js @@ -1,567 +1 @@ -(function() { - var settings = Object.assign( - require('Storage').readJSON("bthrm.default.json", true) || {}, - require('Storage').readJSON("bthrm.json", true) || {} - ); - - var log = function(text, param){ - if (settings.debuglog){ - var logline = new Date().toISOString() + " - " + text; - if (param){ - logline += " " + JSON.stringify(param); - } - print(logline); - } - }; - - log("Settings: ", settings); - - if (settings.enabled){ - - var clearCache = function() { - return require('Storage').erase("bthrm.cache.json"); - }; - - var getCache = function() { - var cache = require('Storage').readJSON("bthrm.cache.json", true) || {}; - if (settings.btid && settings.btid === cache.id) return cache; - clearCache(); - return {}; - }; - - var addNotificationHandler = function(characteristic) { - log("Setting notification handler: " + supportedCharacteristics[characteristic.uuid].handler); - characteristic.on('characteristicvaluechanged', (ev) => supportedCharacteristics[characteristic.uuid].handler(ev.target.value)); - }; - - var writeCache = function(cache) { - var oldCache = getCache(); - if (oldCache !== cache) { - log("Writing cache"); - require('Storage').writeJSON("bthrm.cache.json", cache); - } else { - log("No changes, don't write cache"); - } - }; - - var characteristicsToCache = function(characteristics) { - log("Cache characteristics"); - var cache = getCache(); - if (!cache.characteristics) cache.characteristics = {}; - for (var c of characteristics){ - //"handle_value":16,"handle_decl":15 - log("Saving handle " + c.handle_value + " for characteristic: ", c); - cache.characteristics[c.uuid] = { - "handle": c.handle_value, - "uuid": c.uuid, - "notify": c.properties.notify, - "read": c.properties.read - }; - } - writeCache(cache); - }; - - var characteristicsFromCache = function() { - log("Read cached characteristics"); - var cache = getCache(); - if (!cache.characteristics) return []; - var restored = []; - for (var c in cache.characteristics){ - var cached = cache.characteristics[c]; - var r = new BluetoothRemoteGATTCharacteristic(); - log("Restoring characteristic ", cached); - r.handle_value = cached.handle; - r.uuid = cached.uuid; - r.properties = {}; - r.properties.notify = cached.notify; - r.properties.read = cached.read; - addNotificationHandler(r); - log("Restored characteristic: ", r); - restored.push(r); - } - return restored; - }; - - log("Start"); - - var lastReceivedData={ - }; - - var supportedServices = [ - "0x180d", // Heart Rate - "0x180f", // Battery - ]; - - var supportedCharacteristics = { - "0x2a37": { - //Heart rate measurement - handler: function (dv){ - var flags = dv.getUint8(0); - - var bpm = (flags & 1) ? (dv.getUint16(1) / 100 /* ? */ ) : dv.getUint8(1); // 8 or 16 bit - - var sensorContact; - - if (flags & 2){ - sensorContact = !!(flags & 4); - } - - var idx = 2 + (flags&1); - - var energyExpended; - if (flags & 8){ - energyExpended = dv.getUint16(idx,1); - idx += 2; - } - var interval; - if (flags & 16) { - interval = []; - var maxIntervalBytes = (dv.byteLength - idx); - log("Found " + (maxIntervalBytes / 2) + " rr data fields"); - for(var i = 0 ; i < maxIntervalBytes / 2; i++){ - interval[i] = dv.getUint16(idx,1); // in milliseconds - idx += 2; - } - } - - var location; - if (lastReceivedData && lastReceivedData["0x180d"] && lastReceivedData["0x180d"]["0x2a38"]){ - location = lastReceivedData["0x180d"]["0x2a38"]; - } - - var battery; - if (lastReceivedData && lastReceivedData["0x180f"] && lastReceivedData["0x180f"]["0x2a19"]){ - battery = lastReceivedData["0x180f"]["0x2a19"]; - } - - if (settings.replace){ - var repEvent = { - bpm: bpm, - confidence: (sensorContact || sensorContact === undefined)? 100 : 0, - src: "bthrm" - }; - - log("Emitting HRM: ", repEvent); - Bangle.emit("HRM", repEvent); - } - - var newEvent = { - bpm: bpm - }; - - if (location) newEvent.location = location; - if (interval) newEvent.rr = interval; - if (energyExpended) newEvent.energy = energyExpended; - if (battery) newEvent.battery = battery; - if (sensorContact) newEvent.contact = sensorContact; - - log("Emitting BTHRM: ", newEvent); - Bangle.emit("BTHRM", newEvent); - } - }, - "0x2a38": { - //Body sensor location - handler: function(dv){ - if (!lastReceivedData["0x180d"]) lastReceivedData["0x180d"] = {}; - lastReceivedData["0x180d"]["0x2a38"] = parseInt(dv.buffer, 10); - } - }, - "0x2a19": { - //Battery - handler: function (dv){ - if (!lastReceivedData["0x180f"]) lastReceivedData["0x180f"] = {}; - lastReceivedData["0x180f"]["0x2a19"] = dv.getUint8(0); - } - } - }; - - var device; - var gatt; - var characteristics = []; - var blockInit = false; - var currentRetryTimeout; - var initialRetryTime = 40; - var maxRetryTime = 60000; - var retryTime = initialRetryTime; - - var connectSettings = { - minInterval: 7.5, - maxInterval: 1500 - }; - - var waitingPromise = function(timeout) { - return new Promise(function(resolve){ - log("Start waiting for " + timeout); - setTimeout(()=>{ - log("Done waiting for " + timeout); - resolve(); - }, timeout); - }); - }; - - if (settings.enabled){ - Bangle.isBTHRMOn = function(){ - return (Bangle._PWR && Bangle._PWR.BTHRM && Bangle._PWR.BTHRM.length > 0); - }; - - Bangle.isBTHRMConnected = function(){ - return gatt && gatt.connected; - }; - } - - if (settings.replace){ - var origIsHRMOn = Bangle.isHRMOn; - - Bangle.isHRMOn = function() { - if (settings.enabled && !settings.replace){ - return origIsHRMOn(); - } else if (settings.enabled && settings.replace){ - return Bangle.isBTHRMOn(); - } - return origIsHRMOn() || Bangle.isBTHRMOn(); - }; - } - - var clearRetryTimeout = function() { - if (currentRetryTimeout){ - log("Clearing timeout " + currentRetryTimeout); - clearTimeout(currentRetryTimeout); - currentRetryTimeout = undefined; - } - }; - - var retry = function() { - log("Retry"); - - if (!currentRetryTimeout){ - - var clampedTime = retryTime < 100 ? 100 : retryTime; - - log("Set timeout for retry as " + clampedTime); - clearRetryTimeout(); - currentRetryTimeout = setTimeout(() => { - log("Retrying"); - currentRetryTimeout = undefined; - initBt(); - }, clampedTime); - - retryTime = Math.pow(clampedTime, 1.1); - if (retryTime > maxRetryTime){ - retryTime = maxRetryTime; - } - } else { - log("Already in retry..."); - } - }; - - var buzzing = false; - var onDisconnect = function(reason) { - log("Disconnect: " + reason); - log("GATT: ", gatt); - log("Characteristics: ", characteristics); - retryTime = initialRetryTime; - clearRetryTimeout(); - switchInternalHrm(); - blockInit = false; - if (settings.warnDisconnect && !buzzing){ - buzzing = true; - Bangle.buzz(500,0.3).then(()=>waitingPromise(4500)).then(()=>{buzzing = false;}); - } - if (Bangle.isBTHRMOn()){ - retry(); - } - }; - - var createCharacteristicPromise = function(newCharacteristic) { - log("Create characteristic promise: ", newCharacteristic); - var result = Promise.resolve(); - // For values that can be read, go ahead and read them, even if we might be notified in the future - // Allows for getting initial state of infrequently updating characteristics, like battery - if (newCharacteristic.readValue){ - result = result.then(()=>{ - log("Reading data for " + JSON.stringify(newCharacteristic)); - return newCharacteristic.readValue().then((data)=>{ - if (supportedCharacteristics[newCharacteristic.uuid] && supportedCharacteristics[newCharacteristic.uuid].handler) { - supportedCharacteristics[newCharacteristic.uuid].handler(data); - } - }); - }); - } - if (newCharacteristic.properties.notify){ - result = result.then(()=>{ - log("Starting notifications for: ", newCharacteristic); - var startPromise = newCharacteristic.startNotifications().then(()=>log("Notifications started for ", newCharacteristic)); - if (settings.gracePeriodNotification > 0){ - log("Add " + settings.gracePeriodNotification + "ms grace period after starting notifications"); - startPromise = startPromise.then(()=>{ - log("Wait after connect"); - return waitingPromise(settings.gracePeriodNotification); - }); - } - return startPromise; - }); - } - return result.then(()=>log("Handled characteristic: ", newCharacteristic)); - }; - - var attachCharacteristicPromise = function(promise, characteristic) { - return promise.then(()=>{ - log("Handling characteristic:", characteristic); - return createCharacteristicPromise(characteristic); - }); - }; - - var createCharacteristicsPromise = function(newCharacteristics) { - log("Create characteristics promise: ", newCharacteristics); - var result = Promise.resolve(); - for (var c of newCharacteristics){ - if (!supportedCharacteristics[c.uuid]) continue; - log("Supporting characteristic: ", c); - characteristics.push(c); - if (c.properties.notify){ - addNotificationHandler(c); - } - - result = attachCharacteristicPromise(result, c); - } - return result.then(()=>log("Handled characteristics")); - }; - - var createServicePromise = function(service) { - log("Create service promise: ", service); - var result = Promise.resolve(); - result = result.then(()=>{ - log("Handling service: " + service.uuid); - return service.getCharacteristics().then((c)=>createCharacteristicsPromise(c)); - }); - return result.then(()=>log("Handled service" + service.uuid)); - }; - - var attachServicePromise = function(promise, service) { - return promise.then(()=>createServicePromise(service)); - }; - - var initBt = function () { - log("initBt with blockInit: " + blockInit); - if (blockInit){ - retry(); - return; - } - - blockInit = true; - - var promise; - var filters; - - if (!device){ - if (settings.btid){ - log("Configured device id", settings.btid); - filters = [{ id: settings.btid }]; - } else { - return; - } - log("Requesting device with filters", filters); - promise = NRF.requestDevice({ filters: filters, active: true }); - - if (settings.gracePeriodRequest){ - log("Add " + settings.gracePeriodRequest + "ms grace period after request"); - } - - promise = promise.then((d)=>{ - log("Got device: ", d); - d.on('gattserverdisconnected', onDisconnect); - device = d; - }); - - promise = promise.then(()=>{ - log("Wait after request"); - return waitingPromise(settings.gracePeriodRequest); - }); - } else { - promise = Promise.resolve(); - log("Reuse device: ", device); - } - - promise = promise.then(()=>{ - if (gatt){ - log("Reuse GATT: ", gatt); - } else { - log("GATT is new: ", gatt); - characteristics = []; - var cachedId = getCache().id; - if (device.id !== cachedId){ - log("Device ID changed from " + cachedId + " to " + device.id + ", clearing cache"); - clearCache(); - } - var newCache = getCache(); - newCache.id = device.id; - writeCache(newCache); - gatt = device.gatt; - } - - return Promise.resolve(gatt); - }); - - promise = promise.then((gatt)=>{ - if (!gatt.connected){ - var connectPromise = gatt.connect(connectSettings); - if (settings.gracePeriodConnect > 0){ - log("Add " + settings.gracePeriodConnect + "ms grace period after connecting"); - connectPromise = connectPromise.then(()=>{ - log("Wait after connect"); - return waitingPromise(settings.gracePeriodConnect); - }); - } - return connectPromise; - } else { - return Promise.resolve(); - } - }); - -/* promise = promise.then(() => { - log(JSON.stringify(gatt.getSecurityStatus())); - if (gatt.getSecurityStatus()['bonded']) { - log("Already bonded"); - return Promise.resolve(); - } else { - log("Start bonding"); - return gatt.startBonding() - .then(() => console.log(gatt.getSecurityStatus())); - } - });*/ - - promise = promise.then(()=>{ - if (!characteristics || characteristics.length === 0){ - characteristics = characteristicsFromCache(); - } - }); - - promise = promise.then(()=>{ - var characteristicsPromise = Promise.resolve(); - if (characteristics.length === 0){ - characteristicsPromise = characteristicsPromise.then(()=>{ - log("Getting services"); - return gatt.getPrimaryServices(); - }); - - characteristicsPromise = characteristicsPromise.then((services)=>{ - log("Got services:", services); - var result = Promise.resolve(); - for (var service of services){ - if (!(supportedServices.includes(service.uuid))) continue; - log("Supporting service: ", service.uuid); - result = attachServicePromise(result, service); - } - if (settings.gracePeriodService > 0) { - log("Add " + settings.gracePeriodService + "ms grace period after services"); - result = result.then(()=>{ - log("Wait after services"); - return waitingPromise(settings.gracePeriodService); - }); - } - return result; - }); - } else { - for (var characteristic of characteristics){ - characteristicsPromise = attachCharacteristicPromise(characteristicsPromise, characteristic, true); - } - } - - return characteristicsPromise; - }); - - return promise.then(()=>{ - log("Connection established, waiting for notifications"); - characteristicsToCache(characteristics); - clearRetryTimeout(); - }).catch((e) => { - characteristics = []; - log("Error:", e); - onDisconnect(e); - }); - }; - - Bangle.setBTHRMPower = function(isOn, app) { - // Do app power handling - if (!app) app="?"; - if (Bangle._PWR===undefined) Bangle._PWR={}; - if (Bangle._PWR.BTHRM===undefined) Bangle._PWR.BTHRM=[]; - if (isOn && !Bangle._PWR.BTHRM.includes(app)) Bangle._PWR.BTHRM.push(app); - if (!isOn && Bangle._PWR.BTHRM.includes(app)) Bangle._PWR.BTHRM = Bangle._PWR.BTHRM.filter(a=>a!==app); - isOn = Bangle._PWR.BTHRM.length; - // so now we know if we're really on - if (isOn) { - if (!Bangle.isBTHRMConnected()) initBt(); - } else { // not on - log("Power off for " + app); - if (gatt) { - if (gatt.connected){ - log("Disconnect with gatt: ", gatt); - try{ - gatt.disconnect().then(()=>{ - log("Successful disconnect"); - }).catch((e)=>{ - log("Error during disconnect promise", e); - }); - } catch (e){ - log("Error during disconnect attempt", e); - } - } - } - } - }; - - var origSetHRMPower = Bangle.setHRMPower; - - if (settings.startWithHrm){ - - Bangle.setHRMPower = function(isOn, app) { - log("setHRMPower for " + app + ": " + (isOn?"on":"off")); - if (settings.enabled){ - Bangle.setBTHRMPower(isOn, app); - } - if ((settings.enabled && !settings.replace) || !settings.enabled){ - origSetHRMPower(isOn, app); - } - }; - } - - var fallbackInterval; - - var switchInternalHrm = function() { - if (settings.allowFallback && !fallbackInterval){ - log("Fallback to HRM enabled"); - origSetHRMPower(1, "bthrm_fallback"); - fallbackInterval = setInterval(()=>{ - if (Bangle.isBTHRMConnected()){ - origSetHRMPower(0, "bthrm_fallback"); - clearInterval(fallbackInterval); - fallbackInterval = undefined; - log("Fallback to HRM disabled"); - } - }, settings.fallbackTimeout); - } - }; - - if (settings.replace){ - log("Replace HRM event"); - if (Bangle._PWR && Bangle._PWR.HRM){ - for (var i = 0; i < Bangle._PWR.HRM.length; i++){ - var app = Bangle._PWR.HRM[i]; - log("Moving app " + app); - origSetHRMPower(0, app); - Bangle.setBTHRMPower(1, app); - if (Bangle._PWR.HRM===undefined) break; - } - } - switchInternalHrm(); - } - - E.on("kill", ()=>{ - if (gatt && gatt.connected){ - log("Got killed, trying to disconnect"); - gatt.disconnect().then(()=>log("Disconnected on kill")).catch((e)=>log("Error during disconnnect on kill", e)); - } - }); - } -})(); +if ((require('Storage').readJSON("bthrm.json", true) || {}).enabled != false) require("bthrm").enable(); diff --git a/apps/bthrm/bthrm.js b/apps/bthrm/bthrm.js index dd9230386..b07e7bd37 100644 --- a/apps/bthrm/bthrm.js +++ b/apps/bthrm/bthrm.js @@ -1,5 +1,5 @@ -var intervalInt; -var intervalBt; +const BPM_FONT_SIZE="19%"; +const VALUE_TIMEOUT=3000; var BODY_LOCS = { 0: 'Other', @@ -7,83 +7,149 @@ var BODY_LOCS = { 2: 'Wrist', 3: 'Finger', 4: 'Hand', - 5: 'Ear Lobe', + 5: 'Earlobe', 6: 'Foot', +}; + +var Layout = require("Layout"); + +function border(l,c) { + g.setColor(c).drawLine(l.x+l.w*0.05, l.y-4, l.x+l.w*0.95, l.y-4); } -function clear(y){ - g.reset(); - g.clearRect(0,y,g.getWidth(),y+75); -} - -function draw(y, type, event) { - clear(y); - var px = g.getWidth()/2; - var str = event.bpm + ""; - g.reset(); - g.setFontAlign(0,0); - g.setFontVector(40).drawString(str,px,y+20); - str = "Event: " + type; - if (type === "HRM") { - str += " Confidence: " + event.confidence; - g.setFontVector(12).drawString(str,px,y+40); - str = " Source: " + (event.src ? event.src : "internal"); - g.setFontVector(12).drawString(str,px,y+50); +function getRow(id, text, additionalInfo){ + let additional = []; + let l = { + type:"h", c: [ + { + type:"v", + width: g.getWidth()*0.4, + c: [ + {type:"txt", halign:1, font:"8%", label:text, id:id+"text" }, + {type:"txt", halign:1, font:BPM_FONT_SIZE, label:"--", id:id, bgCol: g.theme.bg } + ] + },{ + type:undefined, fillx:1 + },{ + type:"v", + valign: -1, + width: g.getWidth()*0.45, + c: additional + },{ + type:undefined, width:g.getWidth()*0.05 + } + ] + }; + for (let i of additionalInfo){ + let label = {type:"txt", font:"6x8", label:i + ":" }; + let value = {type:"txt", font:"6x8", label:"--", id:id + i }; + additional.push({type:"h", halign:-1, c:[ label, {type:undefined, fillx:1}, value ]}); } - if (type === "BTHRM"){ - if (event.battery) str += " Bat: " + (event.battery ? event.battery : ""); - g.setFontVector(12).drawString(str,px,y+40); - str= ""; - if (event.location) str += "Loc: " + BODY_LOCS[event.location]; - if (event.rr && event.rr.length > 0) str += " RR: " + event.rr.join(","); - g.setFontVector(12).drawString(str,px,y+50); - str= ""; - if (event.contact) str += " Contact: " + event.contact; - if (event.energy) str += " kJoule: " + event.energy.toFixed(0); - g.setFontVector(12).drawString(str,px,y+60); - } - + + return l; } -var firstEventBt = true; -var firstEventInt = true; +var layout = new Layout( { + type:"v", c: [ + getRow("int", "INT", ["Confidence"]), + getRow("agg", "HRM", ["Confidence", "Source"]), + getRow("bt", "BT", ["Battery","Location","Contact", "RR", "Energy"]), + { type:undefined, height:8 } //dummy to protect debug output + ] +}, { + lazy:true +}); + +var int,agg,bt; +var firstEvent = true; + +function draw(){ + if (!(int || agg || bt)) return; + + if (firstEvent) { + g.clearRect(Bangle.appRect); + firstEvent = false; + } + + let now = Date.now(); + + if (int && int.time > (now - VALUE_TIMEOUT)){ + layout.int.label = int.bpm; + if (!isNaN(int.confidence)) layout.intConfidence.label = int.confidence; + } else { + layout.int.label = "--"; + layout.intConfidence.label = "--"; + } + + if (agg && agg.time > (now - VALUE_TIMEOUT)){ + layout.agg.label = agg.bpm; + if (!isNaN(agg.confidence)) layout.aggConfidence.label = agg.confidence; + if (agg.src) layout.aggSource.label = agg.src; + } else { + layout.agg.label = "--"; + layout.aggConfidence.label = "--"; + layout.aggSource.label = "--"; + } + + if (bt && bt.time > (now - VALUE_TIMEOUT)) { + layout.bt.label = bt.bpm; + if (!isNaN(bt.battery)) layout.btBattery.label = bt.battery + "%"; + if (bt.rr) layout.btRR.label = bt.rr.join(","); + if (!isNaN(bt.location)) layout.btLocation.label = BODY_LOCS[bt.location]; + if (bt.contact !== undefined) layout.btContact.label = bt.contact ? "Yes":"No"; + if (!isNaN(bt.energy)) layout.btEnergy.label = bt.energy.toFixed(0) + "kJ"; + } else { + layout.bt.label = "--"; + layout.btBattery.label = "--"; + layout.btRR.label = "--"; + layout.btLocation.label = "--"; + layout.btContact.label = "--"; + layout.btEnergy.label = "--"; + } + + layout.update(); + layout.render(); + let first = true; + for (let c of layout.l.c){ + if (first) { + first = false; + continue; + } + if (c.type && c.type == "h") + border(c,g.theme.fg); + } +} + + +// This can get called for the boot code to show what's happening +function showStatusInfo(txt) { + var R = Bangle.appRect; + g.reset().clearRect(R.x,R.y2-8,R.x2,R.y2).setFont("6x8"); + txt = g.wrapString(txt, R.w)[0]; + g.setFontAlign(0,1).drawString(txt, (R.x+R.x2)/2, R.y2); +} function onBtHrm(e) { - if (firstEventBt){ - clear(24); - firstEventBt = false; - } - draw(100, "BTHRM", e); - if (e.bpm === 0){ - Bangle.buzz(100,0.2); - } - if (intervalBt){ - clearInterval(intervalBt); - } - intervalBt = setInterval(()=>{ - clear(100); - }, 2000); + bt = e; + bt.time = Date.now(); } -function onHrm(e) { - if (firstEventInt){ - clear(24); - firstEventInt = false; - } - draw(24, "HRM", e); - if (intervalInt){ - clearInterval(intervalInt); - } - intervalInt = setInterval(()=>{ - clear(24); - }, 2000); +function onInt(e) { + int = e; + int.time = Date.now(); } +function onAgg(e) { + agg = e; + agg.time = Date.now(); +} var settings = require('Storage').readJSON("bthrm.json", true) || {}; Bangle.on('BTHRM', onBtHrm); -Bangle.on('HRM', onHrm); +Bangle.on('HRM_int', onInt); +Bangle.on('HRM', onAgg); + Bangle.setHRMPower(1,'bthrm'); if (!(settings.startWithHrm)){ @@ -95,10 +161,11 @@ Bangle.loadWidgets(); Bangle.drawWidgets(); if (Bangle.setBTHRMPower){ g.reset().setFont("6x8",2).setFontAlign(0,0); - g.drawString("Please wait...",g.getWidth()/2,g.getHeight()/2 - 24); + g.drawString("Please wait...",g.getWidth()/2,g.getHeight()/2); + setInterval(draw, 1000); } else { g.reset().setFont("6x8",2).setFontAlign(0,0); - g.drawString("BTHRM disabled",g.getWidth()/2,g.getHeight()/2 + 32); + g.drawString("BTHRM disabled",g.getWidth()/2,g.getHeight()/2); } E.on('kill', ()=>Bangle.setBTHRMPower(0,'bthrm')); diff --git a/apps/bthrm/default.json b/apps/bthrm/default.json index fb284bcd2..79605b412 100644 --- a/apps/bthrm/default.json +++ b/apps/bthrm/default.json @@ -16,5 +16,7 @@ "gracePeriodNotification": 0, "gracePeriodConnect": 0, "gracePeriodService": 0, - "gracePeriodRequest": 0 + "gracePeriodRequest": 0, + "bonding": false, + "active": true } diff --git a/apps/bthrm/lib.js b/apps/bthrm/lib.js new file mode 100644 index 000000000..a792167ca --- /dev/null +++ b/apps/bthrm/lib.js @@ -0,0 +1,664 @@ +exports.enable = () => { + var settings = Object.assign( + require('Storage').readJSON("bthrm.default.json", true) || {}, + require('Storage').readJSON("bthrm.json", true) || {} + ); + + var log = function(text, param){ + if (global.showStatusInfo) + showStatusInfo(text); + if (settings.debuglog){ + var logline = new Date().toISOString() + " - " + text; + if (param) logline += ": " + JSON.stringify(param); + print(logline); + } + }; + + log("Settings: ", settings); + + if (settings.enabled){ + + var clearCache = function() { + return require('Storage').erase("bthrm.cache.json"); + }; + + var getCache = function() { + var cache = require('Storage').readJSON("bthrm.cache.json", true) || {}; + if (settings.btid && settings.btid === cache.id) return cache; + clearCache(); + return {}; + }; + + var addNotificationHandler = function(characteristic) { + log("Setting notification handler"/*supportedCharacteristics[characteristic.uuid].handler*/); + characteristic.on('characteristicvaluechanged', (ev) => supportedCharacteristics[characteristic.uuid].handler(ev.target.value)); + }; + + var writeCache = function(cache) { + var oldCache = getCache(); + if (oldCache !== cache) { + log("Writing cache"); + require('Storage').writeJSON("bthrm.cache.json", cache); + } else { + log("No changes, don't write cache"); + } + }; + + var characteristicsToCache = function(characteristics) { + log("Cache characteristics"); + var cache = getCache(); + if (!cache.characteristics) cache.characteristics = {}; + for (var c of characteristics){ + //"handle_value":16,"handle_decl":15 + log("Saving handle " + c.handle_value + " for characteristic: ", c); + cache.characteristics[c.uuid] = { + "handle": c.handle_value, + "uuid": c.uuid, + "notify": c.properties.notify, + "read": c.properties.read + }; + } + writeCache(cache); + }; + + var characteristicsFromCache = function(device) { + var service = { device : device }; // fake a BluetoothRemoteGATTService + log("Read cached characteristics"); + var cache = getCache(); + if (!cache.characteristics) return []; + var restored = []; + for (var c in cache.characteristics){ + var cached = cache.characteristics[c]; + var r = new BluetoothRemoteGATTCharacteristic(); + log("Restoring characteristic ", cached); + r.handle_value = cached.handle; + r.uuid = cached.uuid; + r.properties = {}; + r.properties.notify = cached.notify; + r.properties.read = cached.read; + r.service = service; + addNotificationHandler(r); + log("Restored characteristic: ", r); + restored.push(r); + } + return restored; + }; + + log("Start"); + + var lastReceivedData={ + }; + + var supportedServices = [ + "0x180d", // Heart Rate + "0x180f", // Battery + ]; + + var bpmTimeout; + + var supportedCharacteristics = { + "0x2a37": { + //Heart rate measurement + active: false, + handler: function (dv){ + var flags = dv.getUint8(0); + + var bpm = (flags & 1) ? (dv.getUint16(1) / 100 /* ? */ ) : dv.getUint8(1); // 8 or 16 bit + supportedCharacteristics["0x2a37"].active = bpm > 0; + log("BTHRM BPM " + supportedCharacteristics["0x2a37"].active); + switchFallback(); + if (bpmTimeout) clearTimeout(bpmTimeout); + bpmTimeout = setTimeout(()=>{ + bpmTimeout = undefined; + supportedCharacteristics["0x2a37"].active = false; + startFallback(); + }, 3000); + + var sensorContact; + + if (flags & 2){ + sensorContact = !!(flags & 4); + } + + var idx = 2 + (flags&1); + + var energyExpended; + if (flags & 8){ + energyExpended = dv.getUint16(idx,1); + idx += 2; + } + var interval; + if (flags & 16) { + interval = []; + var maxIntervalBytes = (dv.byteLength - idx); + log("Found " + (maxIntervalBytes / 2) + " rr data fields"); + for(var i = 0 ; i < maxIntervalBytes / 2; i++){ + interval[i] = dv.getUint16(idx,1); // in milliseconds + idx += 2; + } + } + + var location; + if (lastReceivedData && lastReceivedData["0x180d"] && lastReceivedData["0x180d"]["0x2a38"]){ + location = lastReceivedData["0x180d"]["0x2a38"]; + } + + var battery; + if (lastReceivedData && lastReceivedData["0x180f"] && lastReceivedData["0x180f"]["0x2a19"]){ + battery = lastReceivedData["0x180f"]["0x2a19"]; + } + + if (settings.replace && bpm > 0){ + var repEvent = { + bpm: bpm, + confidence: (sensorContact || sensorContact === undefined)? 100 : 0, + src: "bthrm" + }; + + log("Emitting HRM_R(bt)", repEvent); + Bangle.emit("HRM_R", repEvent); + } + + var newEvent = { + bpm: bpm + }; + + if (location) newEvent.location = location; + if (interval) newEvent.rr = interval; + if (energyExpended) newEvent.energy = energyExpended; + if (battery) newEvent.battery = battery; + if (sensorContact) newEvent.contact = sensorContact; + + log("Emitting BTHRM", newEvent); + Bangle.emit("BTHRM", newEvent); + } + }, + "0x2a38": { + //Body sensor location + handler: function(dv){ + if (!lastReceivedData["0x180d"]) lastReceivedData["0x180d"] = {}; + lastReceivedData["0x180d"]["0x2a38"] = parseInt(dv.buffer, 10); + } + }, + "0x2a19": { + //Battery + handler: function (dv){ + if (!lastReceivedData["0x180f"]) lastReceivedData["0x180f"] = {}; + lastReceivedData["0x180f"]["0x2a19"] = dv.getUint8(0); + } + } + }; + + var device; + var gatt; + var characteristics = []; + var blockInit = false; + var currentRetryTimeout; + var initialRetryTime = 40; + var maxRetryTime = 60000; + var retryTime = initialRetryTime; + + var connectSettings = { + minInterval: 7.5, + maxInterval: 1500 + }; + + var waitingPromise = function(timeout) { + return new Promise(function(resolve){ + log("Start waiting for " + timeout); + setTimeout(()=>{ + log("Done waiting for " + timeout); + resolve(); + }, timeout); + }); + }; + + if (settings.enabled){ + Bangle.isBTHRMActive = function (){ + return supportedCharacteristics["0x2a37"].active; + }; + + Bangle.isBTHRMOn = function(){ + return (Bangle._PWR && Bangle._PWR.BTHRM && Bangle._PWR.BTHRM.length > 0); + }; + + Bangle.isBTHRMConnected = function(){ + return gatt && gatt.connected; + }; + } + + if (settings.replace){ + Bangle.origIsHRMOn = Bangle.isHRMOn; + + Bangle.isHRMOn = function() { + if (settings.enabled && !settings.replace){ + return Bangle.origIsHRMOn(); + } else if (settings.enabled && settings.replace){ + return Bangle.isBTHRMOn(); + } + return Bangle.origIsHRMOn() || Bangle.isBTHRMOn(); + }; + } + + var clearRetryTimeout = function(resetTime) { + if (currentRetryTimeout){ + log("Clearing timeout " + currentRetryTimeout); + clearTimeout(currentRetryTimeout); + currentRetryTimeout = undefined; + } + if (resetTime) { + log("Resetting retry time"); + retryTime = initialRetryTime; + } + }; + + var retry = function() { + log("Retry"); + + if (!currentRetryTimeout && !powerdownRequested){ + + var clampedTime = retryTime < 100 ? 100 : retryTime; + + log("Set timeout for retry as " + clampedTime); + clearRetryTimeout(); + currentRetryTimeout = setTimeout(() => { + log("Retrying"); + currentRetryTimeout = undefined; + initBt(); + }, clampedTime); + + retryTime = Math.pow(clampedTime, 1.1); + if (retryTime > maxRetryTime){ + retryTime = maxRetryTime; + } + } else { + log("Already in retry..."); + } + }; + + var buzzing = false; + var onDisconnect = function(reason) { + log("Disconnect: " + reason); + log("GATT", gatt); + log("Characteristics", characteristics); + + var retryTimeResetNeeded = true; + retryTimeResetNeeded &= reason != "Connection Timeout"; + retryTimeResetNeeded &= reason != "No device found matching filters"; + clearRetryTimeout(retryTimeResetNeeded); + supportedCharacteristics["0x2a37"].active = false; + if (!powerdownRequested) startFallback(); + blockInit = false; + if (settings.warnDisconnect && !buzzing){ + buzzing = true; + Bangle.buzz(500,0.3).then(()=>waitingPromise(4500)).then(()=>{buzzing = false;}); + } + if (Bangle.isBTHRMOn()){ + retry(); + } + }; + + var createCharacteristicPromise = function(newCharacteristic) { + log("Create characteristic promise", newCharacteristic); + var result = Promise.resolve(); + // For values that can be read, go ahead and read them, even if we might be notified in the future + // Allows for getting initial state of infrequently updating characteristics, like battery + if (newCharacteristic.readValue){ + result = result.then(()=>{ + log("Reading data", newCharacteristic); + return newCharacteristic.readValue().then((data)=>{ + if (supportedCharacteristics[newCharacteristic.uuid] && supportedCharacteristics[newCharacteristic.uuid].handler) { + supportedCharacteristics[newCharacteristic.uuid].handler(data); + } + }); + }); + } + if (newCharacteristic.properties.notify){ + result = result.then(()=>{ + log("Starting notifications", newCharacteristic); + var startPromise = newCharacteristic.startNotifications().then(()=>log("Notifications started", newCharacteristic)); + + log("Add " + settings.gracePeriodNotification + "ms grace period after starting notifications"); + startPromise = startPromise.then(()=>{ + log("Wait after connect"); + return waitingPromise(settings.gracePeriodNotification); + }); + + return startPromise; + }); + } + return result.then(()=>log("Handled characteristic", newCharacteristic)); + }; + + var attachCharacteristicPromise = function(promise, characteristic) { + return promise.then(()=>{ + log("Handling characteristic:", characteristic); + return createCharacteristicPromise(characteristic); + }); + }; + + var createCharacteristicsPromise = function(newCharacteristics) { + log("Create characteristics promis ", newCharacteristics); + var result = Promise.resolve(); + for (var c of newCharacteristics){ + if (!supportedCharacteristics[c.uuid]) continue; + log("Supporting characteristic", c); + characteristics.push(c); + if (c.properties.notify){ + addNotificationHandler(c); + } + + result = attachCharacteristicPromise(result, c); + } + return result.then(()=>log("Handled characteristics")); + }; + + var createServicePromise = function(service) { + log("Create service promise", service); + var result = Promise.resolve(); + result = result.then(()=>{ + log("Handling service" + service.uuid); + return service.getCharacteristics().then((c)=>createCharacteristicsPromise(c)); + }); + return result.then(()=>log("Handled service" + service.uuid)); + }; + + var attachServicePromise = function(promise, service) { + return promise.then(()=>createServicePromise(service)); + }; + + var initBt = function () { + log("initBt with blockInit: " + blockInit); + if (blockInit && !powerdownRequested){ + retry(); + return; + } + + blockInit = true; + + var promise; + var filters; + + if (!device){ + if (settings.btid){ + log("Configured device id", settings.btid); + filters = [{ id: settings.btid }]; + } else { + return; + } + log("Requesting device with filters", filters); + try { + promise = NRF.requestDevice({ filters: filters, active: settings.active }); + } catch (e){ + log("Error during initial request:", e); + onDisconnect(e); + return; + } + + if (settings.gracePeriodRequest){ + log("Add " + settings.gracePeriodRequest + "ms grace period after request"); + } + + promise = promise.then((d)=>{ + log("Got device", d); + d.on('gattserverdisconnected', onDisconnect); + device = d; + }); + + promise = promise.then(()=>{ + log("Wait after request"); + return waitingPromise(settings.gracePeriodRequest); + }); + } else { + promise = Promise.resolve(); + log("Reuse device", device); + } + + promise = promise.then(()=>{ + if (gatt){ + log("Reuse GATT", gatt); + } else { + log("GATT is new", gatt); + characteristics = []; + var cachedId = getCache().id; + if (device.id !== cachedId){ + log("Device ID changed from " + cachedId + " to " + device.id + ", clearing cache"); + clearCache(); + } + var newCache = getCache(); + newCache.id = device.id; + writeCache(newCache); + gatt = device.gatt; + } + + return Promise.resolve(gatt); + }); + + promise = promise.then((gatt)=>{ + if (!gatt.connected){ + log("Connecting..."); + var connectPromise = gatt.connect(connectSettings).then(function() { + log("Connected."); + }); + log("Add " + settings.gracePeriodConnect + "ms grace period after connecting"); + connectPromise = connectPromise.then(()=>{ + log("Wait after connect"); + return waitingPromise(settings.gracePeriodConnect); + }); + return connectPromise; + } else { + return Promise.resolve(); + } + }); + + if (settings.bonding){ + promise = promise.then(() => { + log(JSON.stringify(gatt.getSecurityStatus())); + if (gatt.getSecurityStatus()['bonded']) { + log("Already bonded"); + return Promise.resolve(); + } else { + log("Start bonding"); + return gatt.startBonding() + .then(() => log("Security status" + gatt.getSecurityStatus())); + } + }); + } + + promise = promise.then(()=>{ + if (!characteristics || characteristics.length === 0){ + characteristics = characteristicsFromCache(device); + } + }); + + promise = promise.then(()=>{ + var characteristicsPromise = Promise.resolve(); + if (characteristics.length === 0){ + characteristicsPromise = characteristicsPromise.then(()=>{ + log("Getting services"); + return gatt.getPrimaryServices(); + }); + + characteristicsPromise = characteristicsPromise.then((services)=>{ + log("Got services", services); + var result = Promise.resolve(); + for (var service of services){ + if (!(supportedServices.includes(service.uuid))) continue; + log("Supporting service", service.uuid); + result = attachServicePromise(result, service); + } + log("Add " + settings.gracePeriodService + "ms grace period after services"); + result = result.then(()=>{ + log("Wait after services"); + return waitingPromise(settings.gracePeriodService); + }); + return result; + }); + } else { + for (var characteristic of characteristics){ + characteristicsPromise = attachCharacteristicPromise(characteristicsPromise, characteristic, true); + } + } + + return characteristicsPromise; + }); + + return promise.then(()=>{ + log("Connection established, waiting for notifications"); + characteristicsToCache(characteristics); + clearRetryTimeout(true); + }).catch((e) => { + characteristics = []; + log("Error:", e); + onDisconnect(e); + }); + }; + + var powerdownRequested = false; + + Bangle.setBTHRMPower = function(isOn, app) { + // Do app power handling + if (!app) app="?"; + if (Bangle._PWR===undefined) Bangle._PWR={}; + if (Bangle._PWR.BTHRM===undefined) Bangle._PWR.BTHRM=[]; + if (isOn && !Bangle._PWR.BTHRM.includes(app)) Bangle._PWR.BTHRM.push(app); + if (!isOn && Bangle._PWR.BTHRM.includes(app)) Bangle._PWR.BTHRM = Bangle._PWR.BTHRM.filter(a=>a!==app); + isOn = Bangle._PWR.BTHRM.length; + // so now we know if we're really on + if (isOn) { + powerdownRequested = false; + switchFallback(); + if (!Bangle.isBTHRMConnected()) initBt(); + } else { // not on + log("Power off for " + app); + powerdownRequested = true; + clearRetryTimeout(true); + stopFallback(); + if (gatt) { + if (gatt.connected){ + log("Disconnect with gatt", gatt); + try{ + gatt.disconnect().then(()=>{ + log("Successful disconnect"); + }).catch((e)=>{ + log("Error during disconnect promise", e); + }); + } catch (e){ + log("Error during disconnect attempt", e); + } + } + } + } + }; + + if (settings.replace){ + // register a listener for original HRM events and emit as HRM_int + Bangle.on("HRM", (o) => { + let e = Object.assign({},o); + log("Emitting HRM_int", e); + Bangle.emit("HRM_int", e); + if (fallbackActive){ + // if fallback to internal HRM is active, emit as HRM_R to which everyone listens + o.src = "int"; + log("Emitting HRM_R(int)", o); + Bangle.emit("HRM_R", o); + } + }); + + // force all apps wanting to listen to HRM to actually get events for HRM_R + Bangle.on = ( o => (name, cb) => { + o = o.bind(Bangle); + if (name == "HRM") o("HRM_R", cb); + else o(name, cb); + })(Bangle.on); + + Bangle.removeListener = ( o => (name, cb) => { + o = o.bind(Bangle); + if (name == "HRM") o("HRM_R", cb); + else o(name, cb); + })(Bangle.removeListener); + } else { + Bangle.on("HRM", (o)=>{ + o.src = "int"; + let e = Object.assign({},o); + log("Emitting HRM_int", e); + Bangle.emit("HRM_int", e); + }); + } + + Bangle.origSetHRMPower = Bangle.setHRMPower; + + if (settings.startWithHrm){ + Bangle.setHRMPower = function(isOn, app) { + log("setHRMPower for " + app + ": " + (isOn?"on":"off")); + if (settings.enabled){ + Bangle.setBTHRMPower(isOn, app); + if (Bangle._PWR && Bangle._PWR.HRM && Object.keys(Bangle._PWR.HRM).length == 0) { + Bangle._PWR.BTHRM = []; + Bangle.setBTHRMPower(0); + if (!isOn) stopFallback(); + } + } + if ((settings.enabled && !settings.replace) || !settings.enabled){ + Bangle.origSetHRMPower(isOn, app); + } + }; + } + + var fallbackActive = false; + var inSwitch = false; + + var stopFallback = function(){ + if (fallbackActive){ + Bangle.origSetHRMPower(0, "bthrm_fallback"); + fallbackActive = false; + log("Fallback to HRM disabled"); + } + }; + + var startFallback = function(){ + if (!fallbackActive && settings.allowFallback) { + fallbackActive = true; + Bangle.origSetHRMPower(1, "bthrm_fallback"); + log("Fallback to HRM enabled"); + } + }; + + var switchFallback = function() { + log("Check falling back to HRM"); + if (!inSwitch){ + inSwitch = true; + if (Bangle.isBTHRMActive()){ + stopFallback(); + } else { + startFallback(); + } + } + inSwitch = false; + }; + + if (settings.replace){ + log("Replace HRM event"); + if (Bangle._PWR && Bangle._PWR.HRM){ + for (var i = 0; i < Bangle._PWR.HRM.length; i++){ + var app = Bangle._PWR.HRM[i]; + log("Moving app " + app); + Bangle.origSetHRMPower(0, app); + Bangle.setBTHRMPower(1, app); + if (Bangle._PWR.HRM===undefined) break; + } + } + } + + E.on("kill", ()=>{ + if (gatt && gatt.connected){ + log("Got killed, trying to disconnect"); + try { + gatt.disconnect().then(()=>log("Disconnected on kill")).catch((e)=>log("Error during disconnnect promise on kill", e)); + } catch (e) { + log("Error during disconnnect on kill", e) + } + } + }); + } +}; diff --git a/apps/bthrm/metadata.json b/apps/bthrm/metadata.json index 9e40896f0..fea274ff3 100644 --- a/apps/bthrm/metadata.json +++ b/apps/bthrm/metadata.json @@ -2,9 +2,10 @@ "id": "bthrm", "name": "Bluetooth Heart Rate Monitor", "shortName": "BT HRM", - "version": "0.10", + "version": "0.17", "description": "Overrides Bangle.js's build in heart rate monitor with an external Bluetooth one.", "icon": "app.png", + "screenshots": [{"url":"screen.png"}], "type": "app", "tags": "health,bluetooth,hrm,bthrm", "supports": ["BANGLEJS","BANGLEJS2"], @@ -15,6 +16,7 @@ {"name":"bthrm.0.boot.js","url":"boot.js"}, {"name":"bthrm.img","url":"app-icon.js","evaluate":true}, {"name":"bthrm.settings.js","url":"settings.js"}, + {"name":"bthrm","url":"lib.js"}, {"name":"bthrm.default.json","url":"default.json"} ] } diff --git a/apps/bthrm/recorder.js b/apps/bthrm/recorder.js index 21345a907..fcfed47c3 100644 --- a/apps/bthrm/recorder.js +++ b/apps/bthrm/recorder.js @@ -32,8 +32,42 @@ Bangle.removeListener('BTHRM', onHRM); if (Bangle.setBTRHMPower) Bangle.setBTHRMPower(0,"recorder"); }, - draw : (x,y) => g.setColor((bpm != "")?"#00f":"#88f").drawImage(atob("DAwBAAAAMMeef+f+f+P8H4DwBgAA"),x,y) + draw : (x,y) => g.setColor((Bangle.isBTHRMActive && Bangle.isBTHRMActive())?"#00f":"#88f").drawImage(atob("DAwBAAAAMMeef+f+f+P8H4DwBgAA"),x,y) }; - } + }; + recorders.hrmint = function() { + var active = false; + var bpmTimeout; + var bpm = "", bpmConfidence = ""; + function onHRM(h) { + bpmConfidence = h.confidence; + bpm = h.bpm; + if (h.bpm > 0){ + active = true; + if (bpmTimeout) clearTimeout(bpmTimeout); + bpmTimeout = setTimeout(()=>{ + active = false; + },3000); + } + } + return { + name : "HR int", + fields : ["Int Heartrate", "Int Confidence"], + getValues : () => { + var r = [bpm,bpmConfidence]; + bpm = ""; bpmConfidence = ""; + return r; + }, + start : () => { + Bangle.on('HRM_int', onHRM); + if (Bangle.origSetHRMPower) Bangle.origSetHRMPower(1,"recorder"); + }, + stop : () => { + Bangle.removeListener('HRM_int', onHRM); + if (Bangle.origSetHRMPower) Bangle.origSetHRMPower(0,"recorder"); + }, + draw : (x,y) => g.setColor(( Bangle.origIsHRMOn && Bangle.origIsHRMOn() && active)?"#0f0":"#8f8").drawImage(atob("DAwBAAAAMMeef+f+f+P8H4DwBgAA"),x,y) + }; + }; }) diff --git a/apps/bthrm/screen.png b/apps/bthrm/screen.png new file mode 100644 index 000000000..6b6b85227 Binary files /dev/null and b/apps/bthrm/screen.png differ diff --git a/apps/bthrm/settings.js b/apps/bthrm/settings.js index 8887ee81e..459ed29fc 100644 --- a/apps/bthrm/settings.js +++ b/apps/bthrm/settings.js @@ -17,6 +17,14 @@ var settings; readSettings(); + function applyCustomSettings(){ + writeSettings("enabled",true); + writeSettings("replace",settings.custom_replace); + writeSettings("startWithHrm",settings.custom_startWithHrm); + writeSettings("allowFallback",settings.custom_allowFallback); + writeSettings("fallbackTimeout",settings.custom_fallbackTimeout); + } + function buildMainMenu(){ var mainmenu = { '': { 'title': 'Bluetooth HRM' }, @@ -35,7 +43,6 @@ case 1: writeSettings("enabled",true); writeSettings("replace",true); - writeSettings("debuglog",false); writeSettings("startWithHrm",true); writeSettings("allowFallback",true); writeSettings("fallbackTimeout",10); @@ -43,17 +50,11 @@ case 2: writeSettings("enabled",true); writeSettings("replace",false); - writeSettings("debuglog",false); writeSettings("startWithHrm",false); writeSettings("allowFallback",false); break; case 3: - writeSettings("enabled",true); - writeSettings("replace",settings.custom_replace); - writeSettings("debuglog",settings.custom_debuglog); - writeSettings("startWithHrm",settings.custom_startWithHrm); - writeSettings("allowFallback",settings.custom_allowFallback); - writeSettings("fallbackTimeout",settings.custom_fallbackTimeout); + applyCustomSettings(); break; } writeSettings("mode",v); @@ -95,6 +96,18 @@ writeSettings("debuglog",v); } }, + 'Use bonding': { + value: !!settings.bonding, + onchange: v => { + writeSettings("bonding",v); + } + }, + 'Use active scanning': { + value: !!settings.active, + onchange: v => { + writeSettings("active",v); + } + }, 'Grace periods': function() { E.showMenu(submenu_grace); } }; @@ -138,23 +151,23 @@ '< Back': function() { E.showMenu(buildMainMenu()); }, 'Replace HRM': { value: !!settings.custom_replace, - format: v => settings.custom_replace ? "On" : "Off", onchange: v => { writeSettings("custom_replace",v); + if (settings.mode == 3) applyCustomSettings(); } }, 'Start w. HRM': { value: !!settings.custom_startWithHrm, - format: v => settings.custom_startWithHrm ? "On" : "Off", onchange: v => { writeSettings("custom_startWithHrm",v); + if (settings.mode == 3) applyCustomSettings(); } }, 'HRM Fallback': { value: !!settings.custom_allowFallback, - format: v => settings.custom_allowFallback ? "On" : "Off", onchange: v => { writeSettings("custom_allowFallback",v); + if (settings.mode == 3) applyCustomSettings(); } }, 'Fallback Timeout': { @@ -165,6 +178,7 @@ format: v=>v+"s", onchange: v => { writeSettings("custom_fallbackTimout",v*1000); + if (settings.mode == 3) applyCustomSettings(); } }, }; diff --git a/apps/bwclk/ChangeLog b/apps/bwclk/ChangeLog index ecd0c355f..e3e059318 100644 --- a/apps/bwclk/ChangeLog +++ b/apps/bwclk/ChangeLog @@ -6,4 +6,19 @@ 0.06: Design and usability improvements. 0.07: Improved positioning. 0.08: Select the color of widgets correctly. Additional settings to hide colon. -0.09: Larger font size if colon is hidden to improve readability further. \ No newline at end of file +0.09: Larger font size if colon is hidden to improve readability further. +0.10: HomeAssistant integration if HomeAssistant is installed. +0.11: Performance improvements. +0.12: Implements a 2D menu. +0.13: Clicks < 24px are for widgets, if fullscreen mode is disabled. +0.14: Adds humidity to weather data. +0.15: Added option for a dynamic mode to show widgets only if unlocked. +0.16: You can now show your agenda if your calendar is synced with Gadgetbridge. +0.17: Fix - Step count was no more shown in the menu. +0.18: Set timer for an agenda entry by simply clicking in the middle of the screen. Only one timer can be set. +0.19: Fix - Compatibility with "Digital clock widget" +0.20: Better handling of async data such as getPressure. +0.21: On the default menu the week of year can be shown. +0.22: Use the new clkinfo module for the menu. +0.23: Feedback of apps after run is now optional and decided by the corresponding clkinfo. +0.24: Update clock_info to avoid a redraw diff --git a/apps/bwclk/README.md b/apps/bwclk/README.md index f6a1c6522..d869fa2cf 100644 --- a/apps/bwclk/README.md +++ b/apps/bwclk/README.md @@ -1,17 +1,49 @@ # BW Clock +A very minimalistic clock. ![](screenshot.png) ## Features -- Fullscreen on/off -- Tab left/right of screen to show steps, temperature etc. -- Enable / disable lock icon in the settings. -- If the "sched" app is installed tab top / bottom of the screen to set the timer. -- The design is adapted to the theme of your bangle. -- The colon (e.g. 7:35 = 735) can be hidden now in the settings. +The BW clock implements features that are exposed by other apps through the `clkinfo` module. +For example, if you install the HomeAssistant app, this menu item will be shown if you click right +and additionally allows you to send triggers directly from the clock (select triggers via up/down and +send via click center). Here are examples of other apps that are integrated: + +- Bangle data such as steps, heart rate, battery or charging state. +- Show agenda entries. A timer for an agenda entry can also be set by simply clicking in the middle of the screen. This can be used to not forget a meeting etc. Note that only one agenda-timer can be set at a time. *Requirement: Gadgetbridge calendar sync enabled* +- Weather temperature as well as the wind speed can be shown. *Requirement: Weather app* +- HomeAssistant triggers can be executed directly. *Requirement: HomeAssistant app* + +Note: If some apps are not installed (e.gt. weather app), then this menu item is hidden. + +## Settings +- Screen: Normal (widgets shown), Dynamic (widgets shown if unlocked) or Full (widgets are hidden). +- Enable/disable lock icon in the settings. Useful if fullscreen mode is on. +- The colon (e.g. 7:35 = 735) can be hidden in the settings for an even larger time font to improve readability further. +- Your bangle uses the sys color settings so you can change the color too. + +## Menu structure +2D menu allows you to display lots of different data including data from 3rd party apps and it's also possible to control things e.g. to trigger HomeAssistant. + +Simply click left / right to go through the menu entries such as Bangle, Weather etc. +and click up/down to move into this sub-menu. You can then click in the middle of the screen +to e.g. send a trigger via HomeAssistant once you selected it. The actions really depend +on the app that provide this sub-menu through the `clkinfo` module. + +``` + Bangle -- Agenda -- Weather -- HomeAssistant + | | | | + Battery Entry 1 Temperature Trigger1 + | | | | + Steps ... ... ... + | + ... +``` + ## Thanks to -Icons created by Flaticon +- Thanks to Gordon Williams not only for the great BangleJs, but specifically also for the implementation of `clkinfo` which simplified the BWClock a lot and moved complexety to the apps where it should be located. +- Icons created by Flaticon ## Creator -- [David Peer](https://github.com/peerdavid) +[David Peer](https://github.com/peerdavid) diff --git a/apps/bwclk/app.js b/apps/bwclk/app.js index 5bfec4097..c29fdf2ef 100644 --- a/apps/bwclk/app.js +++ b/apps/bwclk/app.js @@ -1,25 +1,29 @@ -/* +/************************************************ * Includes */ const locale = require('locale'); const storage = require('Storage'); +const clock_info = require("clock_info"); -/* - * Statics + +/************************************************ + * Globals */ const SETTINGS_FILE = "bwclk.setting.json"; -const TIMER_IDX = "bwclk"; const W = g.getWidth(); const H = g.getHeight(); +var lock_input = false; -/* + +/************************************************ * Settings */ let settings = { - fullscreen: false, + screen: "Normal", showLock: true, hideColon: false, - showInfo: 0, + menuPosX: 0, + menuPosY: 0, }; let saved_settings = storage.readJSON(SETTINGS_FILE, 1) || settings; @@ -27,33 +31,21 @@ for (const key in saved_settings) { settings[key] = saved_settings[key] } - -/* +/************************************************ * Assets */ - // Manrope font Graphics.prototype.setLargeFont = function(scale) { - // Actual height 48 (49 - 2) + // Actual height 47 (48 - 2) this.setFontCustom( - E.toString(require('heatshrink').decompress(atob('AFcH+AHFh/gA4sf4AHFn+AA4t/E43+AwsB/gHFgf4PH4AMgJ9Ngf/Pot//6bF/59F///PokfA4J9DEgIABEwYkB/7DDEgIlFCoRMDEgQsEDoRLEEgpoBA4JhGOIsHZ40PdwwA/L4SjHNAgGCP4cHA4wWDA4aVCA4gGDA4SNBe4IiBA4MPHYRBBEwScCA4d/EQUBaoRKDA4UBLQYECgb+EAgMHYYcHa4MPHoLBCBgMfYgcfBgM/PIc/BgN/A4YECIIQEDHwkDHwQHDGwQHENQUHA4d/QIQnCRIJJCSgYTCA4hqCA4hqCA4hiCA4ZCEA4RFBGYbrFAHxDGSohdDcgagFAAjPCEzicDToU/A4jPCAwbQCBwgrBgIHEFYKrDWoa7DaggA/AC0PAYV+AYSBCgKpCg4DDVIUfAYZ9BToIDDPoKVBAYfARoQDDXgMPFwTIBdYSYCv4LCv7zCXgYKCXAK8CHoUPXgY9Cn/vEYMPEwX/z46Bj4mBgf+n77CDwX4v54EIIIzCOgX/4I+CAQI9BHYQCCQ4I7CRASDBHYQHCv/Aj4+BGYIeBGAI+Bj/8AIIRBQIZjCRIiWBXgYHCPQgHBBgJ6DA4IEBPQaKBGYQ+BbgiCCAGZFDIIUBaAZBCgYHCQAQTBA4SACUwS8DDYQHBQAbVCQAYwBA4SABgYEBPoQCBFgU/CQWACgRDCHwKVCIYX+aYRDCHwMPAgY+Cn4EDHwX/AgY+B8bEFj/HA4RGCn+f94MBv45Cv+fA4J6C//+j5gBGIMBFoJWBQoRMB8E//4DBHIJcBv4HBEwJUCA4ImCj5MBA4KZCPYQHBZgRBCE4LICvwaCXAYA5PgQAEMIQAEUwQADQAJlCAARlBWYIACT4JtDAAMPA4IWESgg8CAwI+EEoPhHwYlCgY+DEoP4g4+DEoPAh4+CEoReBHwUfLYU/CwgMBXARqBHYQCCGoIjBgI+CgZSCHwcHAYY+Ch4lBJ4IbCjhACPwqUBPwqFCPwhQBIQZ+DOAKVFXooHCXop9DFAi8EFAT0GPoYAygwFEgOATISLDwBWDTQc/A4L6CTQKkCVQX+BYIHBDwX+BYIHBVQX8B4KqD+/wA4aBBj/AgK8CQIIJBA4a/BBIMBAgL/BAgUDYgL/BAII7BAQXgAII7BAQXAYQQxBYARrCMwQ0BAgV/HwYECHwgEBgY+EA4MPGwI8BA4UfGwI8BgYHBPofAQYOHPoeAR4QmBHwQHCEwI+CA4RVBHwQHCaggnBDwQHEHoIAEEQIA6v5NFfgSECBwZtEf4IHFOYQHEj4HGDwYHCDwPgv/jA4UHXQS8E/ED/AHDZ4MPSYKlCv+AYwIHDDwL7EgL7DAgTzCEwIpCeYTZBg4CBeYIJBAgICBFgIJBAgICBeYIEDHII0BAgg+EgI5CMocHGwJBCA4MfGwMD/h/BwF/PoQHC451CJIMDSgIjBA4PAA4QmBA4IhBA4JVBgEMA4bUDV4QeCAAf/HoIAENIIApOoIAEW4QAEW4QAEW4QAEWQRSFNIcDfYQMDny8DO4Q7BAQQjCewh+EHwcPToQ+Dv//ewkHUoI+En68DeIS0EHwMf/46CeYYlCHwQ0BKIY+BGgJ4Dh/nGgZZCAwKPEHYLpFDoKuFGgj4JgY0EHwQ0EYhIA6MAkf+BRBLIa5BQAJSCBgP4R4iVB/YHERoIACA4QGDE4SFBAoV/A4MH/ggBWIL7C8EfVoL4DwBHBFYIHBfYIRBAgT7CDgQEBgP4BgUBEIMDDgIMBgYMBg/gBgS5Ch/ABgUPFIMf4EHA4IEBHwUPCgJGCIIM/CgLgCAQJlBFIQFB44HBEIUBQYc/EIIHDAAIuBA4oeBRoSfBLAIHC/gHBEwIXC+AHBZghHBDwQADj4WCAHEPAwpWBKYYOCLwIHELYJUBghlDA4UcQogHBvgeDD4K0DDwIHBWgQeB4CyBh68CUAMf8DeCdIYHDdIfAfYjxCAgj2BAgbHCvwJCIIYCBBIMDHIX4BgUHFwMD+AMCA4Q0BAgg5CHwxICAQY5BdgQHBEgMDIYV/DgR1CA4PwP4KvDRgIACEYIHFWggABMQQHEZwd/Dwq1DHoTFEdooA/ACrBBcAZmC8DTCAATGBaYR+DwDTCRwbYDAASLBCIIGCFgQRBAG4='))), + atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAAAAAAD/AAAAAAAAA/wAAAAAAAAP8AAAAAAAAD/AAAAAAAAA/wAAAAAAAAP8AAAAAAAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAD/AAAAAAAAP/wAAAAAAAf/8AAAAAAB///AAAAAAH///wAAAAAf///8AAAAB/////AAAAH////8AAAAP////wAAAA/////AAAAB////+AAAAA////4AAAAAP///gAAAAAD//+AAAAAAA//4AAAAAAAP/gAAAAAAAD/AAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///+AAAAAB////8AAAAB/////wAAAA/////+AAAA//////wAAAf/////+AAAH//////wAAD//////+AAB/+AAAf/gAAf+AAAA/8AAH/AAAAH/AAD/gAAAA/4AA/wAAAAH+AAP8AAAAB/gAD+AAAAAf4AA/gAAAAH+AAP4AAAAA/gAD+AAAAAf4AA/wAAAAH+AAP8AAAAB/gAD/AAAAA/4AA/4AAAAP+AAH/AAAAH/AAB/4AAAH/wAAP/wAAP/4AAD//////+AAAf//////AAAD//////gAAAf/////wAAAD/////4AAAAf////4AAAAB////4AAAAAB///gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAAAAAAH/AAAAAAAAD/gAAAAAAAA/4AAAAAAAAf8AAAAAAAAH+AAAAAAAAD/gAAAAAAAB/wAAAAAAAAf8AAAAAAAAP///////AAD///////wAA///////8AAP///////AAD///////wAA///////8AAP///////AAD///////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+AAAB/AAAA/gAAA/wAAA/4AAAf8AAAf+AAAP/AAAP/gAAH/wAAH/4AAD/8AAD/+AAB//AAA//gAA//wAAf/AAAP/8AAH/AAAH//AAD/gAAD//wAA/wAAB//8AAP8AAA///AAD/AAAf+fwAA/gAAP/n8AAP4AAH/x/AAD+AAD/4fwAA/gAB/8H8AAP8AAf+B/AAD/AAP/AfwAA/4AH/gH8AAH/AH/wB/AAB/8H/4AfwAAP///8AH8AAD////AB/AAAf///gAfwAAD///wAH8AAAf//4AB/AAAD//4AAfwAAAP/8AAH8AAAAf4AAB/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAADgAAAfwAAAB+AAAH8AAAAfwAAB/AAAAH+AAAfwAAAB/wAAH8AAAA/+AAB/AAAAP/gAAfwA4AA/8AAH8AfgAH/AAB/AP8AA/4AAfwD/gAH+AAH8B/4AB/gAB/A/8AAf4AAfwf/AAD+AAH8P/wAA/gAB/H/8AAf4AAfz//gAH+AAH8//4AB/gAB/f//AA/4AAf/+/4Af8AAH//P/AP/AAB//j////gAAf/wf///4AAH/4H///8AAB/8A///+AAAf+AH///AAAH/AA///gAAB/gAD//wAAAfwAAP/wAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAAAAAAH/wAAAAAAAH/8AAAAAAAH//AAAAAAAH//wAAAAAAH//8AAAAAAH///AAAAAAH///wAAAAAH///8AAAAAP//9/AAAAAP//8fwAAAAP//4H8AAAAP//4B/AAAAP//4AfwAAAP//4AH8AAAD//4AB/AAAA//4AAfwAAAP/4AAH8AAAD/wAAB/AAAA/wAAAfwAAAPwAH////AADwAB////wAAwAAf///8AAAAAH////AAAAAB////wAAAAAf///8AAAAAH////AAAAAA////wAAAAAAAfwAAAAAAAAH8AAAAAAAAB/AAAAAAAAAfwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAAAAAAAGAHwAAAB///gB+AAAH///8AfwAAB////AP+AAAf///wD/wAAH///+A/+AAB////gP/gAAf///4A/8AAH/8P8AH/AAB/AD+AA/4AAfwA/gAH+AAH8AfwAB/gAB/AH8AAf4AAfwB/AAH+AAH8AfwAB/gAB/AH8AAf4AAfwB/gAH+AAH8Af4AB/gAB/AH/AA/wAAfwB/4Af8AAH8AP/AP/AAB/AD////gAAfwAf///wAAH8AD///8AAB/AA///+AAAfwAH///AAAAAAA///gAAAAAAD//gAAAAAAAP/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB///4AAAAAH////wAAAAH/////AAAAD/////4AAAB//////AAAA//////4AAAf//////AAAP//////4AAD/8D/w/+AAB/4B/wD/wAAf8A/wAf8AAP+AP4AD/gAD/AD+AAf4AA/wB/AAH+AAP4AfwAB/gAD+AH8AAf4AA/gB/AAH+AAP4AfwAB/gAD+AH+AAf4AA/wB/gAH+AAP8Af8AD/gAD/gH/gB/wAAf8A/8A/8AAH/AP///+AAB/gB////gAAPwAP///wAAB4AD///4AAAMAAf//8AAAAAAD//+AAAAAAAP/+AAAAAAAA/+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAAH8AAAAAAAAB/AAAAAAAAAfwAAAAAAAAH8AAAAAAAAB/AAAAABwAAfwAAAAB8AAH8AAAAD/AAB/AAAAD/wAAfwAAAH/8AAH8AAAH//AAB/AAAP//wAAfwAAP//8AAH8AAf//+AAB/AAf//8AAAfwA///8AAAH8A///4AAAB/A///4AAAAfx///wAAAAH9///wAAAAB////gAAAAAf///gAAAAAH///AAAAAAB///AAAAAAAf/+AAAAAAAH/+AAAAAAAB/8AAAAAAAAf8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAf/AAAAAP+Af/8AAAAP/4P//wAAAP//P//+AAAH//////wAAB//////8AAA///////gAAf//////8AAH////gP/AAD/wf/wA/wAA/4D/4AP+AAP8Af8AB/gAD/AH/AAf4AA/gA/wAH+AAP4AP4AA/gAD+AD/AAP4AA/gA/wAH+AAP8Af8AB/gAD/AH/AAf4AA/4D/4AP+AAP/B//AH/AAB////4D/wAAf//////8AAD//////+AAAf//////AAAH//////wAAA//8///4AAAD/+D//8AAAAP+Af/8AAAAAAAB/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB/gAAAAAAAB//AAAAAAAB//8AAAAAAB///gAAgAAA///8AAcAAAf///gAPAAAH///8AH4AAD////AD/AAB/+H/4B/wAAf+Af+Af8AAP+AB/wD/gAD/gAf8Af4AA/wAD/AH+AAP8AA/wB/gAD+AAH8AP4AA/gAB/AD+AAP4AAfwB/gAD+AAH8Af4AA/wAD/AH+AAP8AA/gD/gAD/gAf4A/wAAf8AP8A/8AAH/gH/Af/AAA///////gAAP//////wAAB//////8AAAP/////+AAAB//////AAAAP/////AAAAA/////gAAAAD////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wA/wAAAAAP8AP8AAAAAD/AD/AAAAAA/wA/wAAAAAP8AP8AAAAAD/AD/AAAAAA/wA/wAAAAAP8AP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='), 46, - atob("EhooGyUkJiUnISYnFQ=="), - 63+(scale<<8)+(1<<16) + atob("ExspGyUkJiQnISYnFQ=="), + 62+(scale<<8)+(1<<16) ); return this; }; -Graphics.prototype.setXLargeFont = function(scale) { - // Actual height 53 (55 - 3) - this.setFontCustom( - E.toString(require('heatshrink').decompress(atob('AHM/8AIG/+AA4sD/wQGh/4EWQA/AC8YA40HNA0BRY8/RY0P/6LFgf//4iFA4IiFj4HBEQkHCAQiDHIIZGv4HCFQY5BDAo5CAAIpDDAfACA3wLYv//hsFKYxcCMgoiBOooiBQwwiBS40AHIgA/ACS/DLYjYCBAjQEBAYQDBAgHDUAbyDZQi3CegoHEVQQZFagUfW4Y0DaAgECaIJSEFYMPbIYNDv5ACGAIrBCgJ1EFYILCAAQWCj4zDGgILCegcDEQRNDHIIiCHgZ2BEQShFIqUDFYidCh5ODg4NCn40DAgd/AYR5BDILZEAAIMDAAYVCh7aHdYhKDbQg4Dv7rGBAihFCAwIDCAgA/AB3/eoa7GAAk/dgbVGDJrvCDK67DDIjaGdYpbCdYonCcQjjDEVUBEQ4A/AEMcAYV/NAUHcYUDawd/cYUPRYSmBBgaLBToP8BgYiBSgIiCj4iCg//EQSuDW4IMDVwYiCBgIiBBgrRDCATeBaIYqCv70DCgT4CEQMfIgQZBBoRnDv/3EQIvBDIffEQMHFwReBRYUfOgX/+IiDKIeHEQRRECwUHKwIuB8AiDIoJEBCwZFCv/4HIZaBIgPAEQS2CUYQiCD4SABEQcfOwIZBEQaHBO4RcEAAI/BEQQgBSIQiDTIRZBEQZuBVYQiDHoKWCEQQICFQIiDBAQeCEQQA/AANwA40BLIJ5BO4JWCBAUPAYR5En7RBUIQECN4SYCQQIiEh6CCEQk/BoQiBgYeCBoTrCAgT0CCgIfCFYQiBg4IBGgIiDj6rBg4rCBYLRDFYIiBbYIfBLgQiBIQYiD4JCCLgf/bQIWDBYV/EQV/BYXz/5FBgIiD5//IowZBD4M/NAX/BIPgDIJoC//5GgKUDn//4f/8KLE/wTBAAI8BEQPwj4HBVwYmBDgIZDN4QZCGYKJCHQP/JoSgCBATrCh5dBKITVDG4gICAAbvDAH5SCL4QADK4J5CCAiTCCAp1BCAqCDCAgiGCAIiFCAQiFeoIiFg6/FCAgiECAXnEQgQB/kfEQYQC4F/EQYQCgIiDfoIQBg4iDCAUAEQZUCcgIiDDIIQBEQhuBBoIiENoYiFDwQiECAQiFwEBPQQNCAQKDDEYMDDoMfRh4iGUwqvEESBiBaQ5oEbgr0FNAo+EEIwA+oAHGgJoFRAMHe4L0CAALNBBAT0BfwScDCAXweAL0DWgUPQYQiDwF/QYQiC/zTB+C0FBAL0CEQYIBGgMPCgIxBg4rCJIKsCh5IBBwTPCj4WBgYLBZ4V/MAIiBBQQrBEQYtCBYQiCO4QLFCwgiDIQIiGIoMHEQpFBn5FFD4JoENwRoGDgSUCAoKfBw//DgIiCT4auCFwN/T4RRET4TaCEQKoCDIQiCGgK/DAAQICdYQACHoIqCBAoQFEwIhFAH4AFQIROEj4IGXwIIGNwIACbgIhEBAiRCVwoqDTogHEW4QZFXgIZB/z9Cv49CF4MPBwI0Ca4LlB8ATCJoP4AoINDfQPAg7PBg4cBBwUfD4MfFYILCCwgOCf4QLEwEPCwILCgJaBn4WBBYQxCIQQiD+EDCYI5CBYRQBIo4fBMQIuBC4N/NAv8AoIcBSgU/FYIIBZIYrCW4hOCXIQZCgYUBv7jEh4uBZAscewZ8CgEgUYT0EEoQIBA4gICFQQIEHYQA+KQzdDAArdCAArpCEScHaIQiEvwiGe4QiFUwQiEbgIiFYIL0DEQTkBEQrJEEQc/cYYiCg4HBDIQiCfoRoEHQLaDEQQHBbQYiBCAT8Dn/BCAoXBJYP/OgZKC/6OEEARLCEQZLEEQZLEEQjKFEQI6EEQZLDEQbsGEQLjGYYYA/JIxzEg/AfgJSDAoPgfgiDC8COFAoPnaQj6CAAR+CW4TCFA4i6CDIqhCDIfwHoYHCYIN/GgKuBJ4JDBFYUf/C5CBYIZBv/Ag4ZBg4rBBYQTBAQIcBg4FBn5UBAQUfFwIfCEQeAgYfBAQUBFAKbCAQQiCGwIiE+A2BwBFNwE/AoM/EQJoIWwKCCh4cBFYKUERYV/W46uHFYIZGaJA0B/glBGYT0JIITiEMIJvCFQQAEHYQA/ABBlEOIhdGQAIRFSgQIBgQICn4IB8EAjiBCUYglCbQYeBEoQZCTwM/CYIZD/gEBUwIzBJ4UHYAU/EwIrBh4rCAoIXCn4rBCgUDAQN/FYMfBYIXBCYJnCBYXggf8HgQLCwEPEQQuBgJOECwILDCwgiLHIUHBYJFGD4IxBgYWCn4rBBwJoFDIYNBCgPADgKHBRYfDBQN/GAIrBToTLDVwYACDILiCWAb8DAAYzBYAjTCAAI9BAARNCBAoqCBAgQDFgbYCAH4AufgQACf4T8CAAT/CfgQACBwITCAAYOBCYQioh4iEAHQA=='))), - 46, - atob("FR4uHyopKyksJSssGA=="), - 70+(scale<<8)+(1<<16) - ); -}; - Graphics.prototype.setMediumFont = function(scale) { // Actual height 41 (42 - 2) this.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AAAAAAAA/AAAAAAAA/AAAAAAAA/AAAAAAAA/AAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAB/AAAAAAAP/AAAAAAD//AAAAAA///AAAAAP///AAAAB///8AAAAf///AAAAH///wAAAB///+AAAAH///gAAAAH//4AAAAAH/+AAAAAAH/wAAAAAAH8AAAAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///8AAAAH////AAAAP////wAAAf////4AAA/////8AAB/////+AAD/gAAH+AAD+AAAD/AAH8AAAB/AAH4AAAA/gAH4AAAAfgAH4AAAAfgAPwAAAAfgAPwAAAAfgAPwAAAAfgAHwAAAAfgAH4AAAAfgAH4AAAA/gAH8AAAA/AAD+AAAD/AAD/gAAH/AAB/////+AAB/////8AAA/////4AAAf////wAAAH////gAAAB///+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPgAAAAAAAfwAAAAAAA/gAAAAAAA/AAAAAAAB/AAAAAAAD+AAAAAAAD8AAAAAAAH8AAAAAAAH//////AAH//////AAH//////AAH//////AAH//////AAH//////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4AAA/AAAP4AAB/AAAf4AAD/AAA/4AAD/AAB/4AAH/AAD/4AAP/AAH/AAAf/AAH8AAA//AAH4AAB//AAP4AAD//AAPwAAH+/AAPwAAP8/AAPwAAf4/AAPwAA/4/AAPwAA/w/AAPwAB/g/AAPwAD/A/AAP4AH+A/AAH8AP8A/AAH/A/4A/AAD///wA/AAD///gA/AAB///AA/AAA//+AA/AAAP/8AA/AAAD/wAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAH4AAAHwAAH4AAAH4AAH4AAAH8AAH4AAAP+AAH4AAAH+AAH4A4AB/AAH4A+AA/AAH4B/AA/gAH4D/AAfgAH4H+AAfgAH4P+AAfgAH4f+AAfgAH4/+AAfgAH5/+AAfgAH5//AAfgAH7+/AA/gAH/8/gB/AAH/4f4H/AAH/wf//+AAH/gP//8AAH/AH//8AAH+AD//wAAH8AB//gAAD4AAf+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+AAAAAAAD/AAAAAAAP/AAAAAAB//AAAAAAH//AAAAAAf//AAAAAB///AAAAAH///AAAAAf/8/AAAAB//w/AAAAH/+A/AAAA//4A/AAAD//gA/AAAH/+AA/AAAH/4AA/AAAH/gAA/AAAH+AAA/AAAHwAAA/AAAHAAf///AAEAAf///AAAAAf///AAAAAf///AAAAAf///AAAAAf///AAAAAAA/AAAAAAAA/AAAAAAAA/AAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAP/AHgAAH///AP4AAH///gP8AAH///gP8AAH///gP+AAH///gD/AAH/A/AB/AAH4A/AA/gAH4A+AAfgAH4B+AAfgAH4B+AAfgAH4B8AAfgAH4B8AAfgAH4B+AAfgAH4B+AAfgAH4B+AA/gAH4B/AA/AAH4A/gD/AAH4A/4H+AAH4Af//+AAH4AP//8AAH4AP//4AAHwAD//wAAAAAB//AAAAAAAf8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///8AAAAD////AAAAP////wAAAf////4AAA/////8AAB/////+AAD/gP4H+AAD/AfgD/AAH8A/AB/AAH8A/AA/gAH4B+AAfgAH4B+AAfgAPwB8AAfgAPwB8AAfgAPwB+AAfgAPwB+AAfgAH4B+AAfgAH4B/AA/gAH8B/AB/AAH+A/wD/AAD+A/8P+AAB8Af//+AAB4AP//8AAAwAH//4AAAAAD//gAAAAAA//AAAAAAAP4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPwAAAAAAAPwAAAAAAAPwAAAAAAAPwAAAAAAAPwAAAAHAAPwAAAA/AAPwAAAD/AAPwAAAf/AAPwAAB//AAPwAAP//AAPwAA//8AAPwAH//wAAPwAf/+AAAPwB//4AAAPwP//AAAAPw//8AAAAP3//gAAAAP//+AAAAAP//wAAAAAP//AAAAAAP/4AAAAAAP/gAAAAAAP+AAAAAAAHwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP+AAAAH+A//gAAAf/h//4AAA//z//8AAB/////+AAD/////+AAD///+H/AAH+H/4B/AAH8B/wA/gAH4A/gAfgAH4A/gAfgAPwA/AAfgAPwA/AAfgAPwA/AAfgAPwA/AAfgAH4A/gAfgAH4A/gAfgAH8B/wA/gAH/H/4B/AAD///+H/AAD/////+AAB/////+AAA//z//8AAAf/h//4AAAH+A//gAAAAAAH+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/gAAAAAAD/8AAAAAAP/+AAAAAAf//AAcAAA///gA8AAB///wB+AAD/x/4B/AAD+AP4B/AAH8AH8A/gAH4AH8A/gAH4AD8AfgAP4AD8AfgAPwAB8AfgAPwAB8AfgAPwAB8AfgAPwAB8AfgAH4AD8AfgAH4AD4A/gAH8AH4B/AAD+APwD/AAD/g/wP+AAB/////+AAA/////8AAAf////4AAAP////wAAAH////AAAAA///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD8APwAAAAD8APwAAAAD8APwAAAAD8APwAAAAD8APwAAAAD8APwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="), 46, atob("DxcjFyAfISAiHCAiEg=="), 54+(scale<<8)+(1<<16)); @@ -62,211 +54,136 @@ Graphics.prototype.setMediumFont = function(scale) { Graphics.prototype.setSmallFont = function(scale) { // Actual height 28 (27 - 0) - this.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//84D//zgP/+GAAAAAAAAAAAAAAAAAAAD4AAAPgAAA+AAAAAAAAAAAAA+AAAD4AAAPgAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAg4AAHDgAAcOCABw54AHD/gAf/8AD/8AB//gAP8OAA9w4YCHD/gAcf+AB//gAf/gAP/uAA/w4ADnDgAAcOAABw4AAHAAAAcAAAAAAAAAAAAAAAIAA+A4AH8HwA/4PgHjgOAcHAcBwcBw/BwH78DgfvwOB8HA4HAOBw8A+HngB4P8ADgfgAAAYAAAAAAAAAAB4AAAf4AQB/gDgOHAeA4cDwDhweAOHDwA88eAB/nwAD88AAAHgAAA8AAAHn4AA8/wAHnvgA8cOAHhg4A8GDgHgcOA8B74BgD/AAAH4AAAAAAAAAAAAAAAAAMAAAH8AD8/4Af/3wB/8HgODwOA4HA4DgODgOAcOA4A44DwDzgHAH8AMAPwAQP+AAA/8AAAB4AAADAAAAAA+AAAD4AAAPgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/8AD//+A/+/+H4AD98AAB3gAADIAAAAAAAAAAAAAIAAABwAAAXwAAHPwAB8P8D/gP//4AH/8AAAAAAAAAAAAAAAAAAAAAAAAGAAAA4gAAB/AAAH8AAD/AAAP8AAAH4AAAfwAADiAAAOAAAAAAAAAAAAAAGAAAAYAAABgAAAGAAAAYAAABgAAD/+AAP/4AABgAAAGAAAAYAAABgAAAGAAAAYAAAAAAAAAAAAAADkAAAPwAAA/AAAAAAAAAAAAAAAAAAAAAAAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAAAAAAAAAAAAAAAAAAAAAADgAAAOAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAA4AAA/gAA/+AA//AA//AAP/AAA/AAADAAAAAAAAAAAAAAAAAAA//gAP//gB///AHgA8A8AB4DgADgOAAOA4AA4DgADgPAAeAeADwB///AD//4AD/+AAAAAAAAAAAAAAAA4AAAHgAAAcAAADwAAAP//+A///4D///gAAAAAAAAAAAAAAAAAAAAAAYAeADgD4AeAfAD4DwAfgOAD+A4Ae4DgDzgOAeOA4Dw4DweDgH/wOAP+A4AfwDgAAAAAAAAAAAAIAOAA4A4ADwDggHAOHgOA48A4DnwDgO/AOA7uA4D84HgPh/8A8H/gDgH8AAACAAAAAAAAAAAAAHgAAB+AAA/4AAP7gAD+OAA/g4AP4DgA+AOADAA4AAB/+AAH/4AAf/gAADgAAAOAAAAAAAAAAAAAAAAD4cAP/h4A/+HwDw4HgOHAOA4cA4DhwDgOHAOA4cA4Dh4HAOD58A4H/gAAP8AAAGAAAAAAAAAAAAAAAAD/+AAf/8AD//4AePDwDw4HgOHAOA4cA4DhwDgOHAOA4cB4Bw8PAHD/8AIH/gAAH4AAAAAAAAAADgAAAOAAAA4AAYDgAHgOAD+A4B/wDgf4AOP+AA7/AAD/gAAP4AAA8AAAAAAAAAAAAAAAAAAeH8AD+/4Af//wDz8HgOHgOA4OA4Dg4DgODgOA4eA4Dz8HgH//8AP7/gAeH8AAAAAAAAAAAAAAAA+AAAH+AgB/8HAHh4cA8Dg4DgODgOAcOA4Bw4DgODgPA4eAeHDwB///AD//4AD/+AAAAAAAAAAAAAAAAAAAAAAAAAAODgAA4OAADg4AAAAAAAAAAAAAAAAAAAAAAAAAAAAABwA5AHAD8AcAPgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAB8AAAP4AAB5wAAPDgAB4HAAHAOAAIAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGMAAAYwAABjAAAGMAAAYwAABjAAAGMAAAYwAABjAAAGMAAAYwAABjAAAGMAAAYwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAEAAcA4AB4HAADw4AADnAAAH4AAAPAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAB8AAAHgAAA4AAADgDzgOA/OA4D84DgeAAPHwAAf+AAA/wAAB8AAAAAAAAAAAAAAAAAAD+AAB/+AAP/8AB4B4AOABwBwADgHB8OA4P4cDhxxwMGDDAwYMMDBgwwOHHHA4f4cDh/xwHAHCAcAMAA8AwAB8PAAD/4AAD/AAAAAAAAAAAAAACAAAB4AAB/gAA/8AAf+AAP/wAH/nAA/gcADwBwAPwHAA/4cAA/9wAAf/AAAP/AAAD/gAAB+AAAA4AAAAAAAAAAAAAAD///gP//+A///4DgcDgOBwOA4HA4DgcDgOBwOA4HA4Dg8DgPHwOAf/h4A///AB8f4AAAfAAAAAAAP+AAD/+AAf/8AD4D4AeADwBwAHAOAAOA4AA4DgADgOAAOA4AA4DgADgOAAOAcABwB4APAD4D4AHgPAAOA4AAAAAAAAAAAAAAAP//+A///4D///gOAAOA4AA4DgADgOAAOA4AA4DgADgOAAOA8AB4BwAHAHwB8AP//gAP/4AAP+AAAAAAAAAAAAAAAA///4D///gP//+A4HA4DgcDgOBwOA4HA4DgcDgOBwOA4HA4DgcDgOBgOA4AA4AAAAAAAAAAAAAAD///gP//+A///4DgcAAOBwAA4HAADgcAAOBwAA4HAADgcAAOAwAA4AAAAAAAAAf+AAD/+AA//+ADwB4AeADwDwAHgOAAOA4AA4DgADgOAAOA4AA4DgMDgPAweAcDBwB8MfADw/4AHD/AAAPwAAAAAAAAAAAAAAAP//+A///4D///gABwAAAHAAAAcAAABwAAAHAAAAcAAABwAAAHAAAAcAAABwAA///4D///gP//+AAAAAAAAAAAAAAAAAAAD///gP//+A///4AAAAAAAAAAAADgAAAPAAAA+AAAA4AAADgAAAOAAAA4AAAHgP//8A///wD//8AAAAAAAAAAAAAAAAAAAA///4D///gP//+AAHAAAA+AAAP8AAB54AAPDwAB4HgAPAPAB4AfAPAA+A4AA4DAABgAAACAAAAAAAAAAP//+A///4D///gAAAOAAAA4AAADgAAAOAAAA4AAADgAAAOAAAA4AAADgAAAAAAAAAAAAAAP//+A///4D///gD+AAAD+AAAB+AAAB/AAAB/AAAB/AAAB+AAAH4AAB+AAA/gAAP4AAD+AAA/AAAfwAAD///gP//+A///4AAAAAAAAAAAAAAAAAAAP//+A///4D///gHwAAAPwAAAPgAAAfgAAAfAAAAfAAAA/AAAA+AAAB+AAAB8A///4D///gP//+AAAAAAAAAAAP+AAD/+AAf/8AD4D4AeADwBwAHAOAAOA4AA4DgADgOAAOA4AA4DgADgOAAOAcABwB4APAD4D4AH//AAP/4AAP+AAAAAAAAAAAP//+A///4D///gOAcAA4BwADgHAAOAcAA4BwADgHAAOAcAA4DgAD4eAAH/wAAP+AAAPgAAAAAAAA/4AAP/4AB//wAPgPgB4APAHAAcA4AA4DgADgOAAOA4AA4DgADgOAAOA4AO4BwA/AHgB8APgPwAf//gA//uAA/4QAAAAAAAAAA///4D///gP//+A4BwADgHAAOAcAA4BwADgHAAOAcAA4B8ADgP8APh/8Af/H4A/4HgA+AGAAAAAAAAAAAABgAHwHAA/g+AH/A8A8cBwDg4DgODgOA4OA4DgcDgOBwOA4HA4DwODgHg4cAPh/wAcH+AAwPwAAAAADgAAAOAAAA4AAADgAAAOAAAA4AAAD///gP//+A///4DgAAAOAAAA4AAADgAAAOAAAA4AAADgAAAAAAAAAAAAAAAAAP//AA///AD//+AAAB8AAABwAAADgAAAOAAAA4AAADgAAAOAAAA4AAAHgAAA8A///gD//8AP//gAAAAAAAAAAIAAAA8AAAD+AAAH/AAAD/wAAB/4AAA/8AAAf4AAAPgAAB+AAA/4AAf+AAP/AAH/gAD/wAAP4AAA4AAAAAAAAPAAAA/gAAD/4AAA/+AAAf/AAAH/gAAB+AAAf4AAf/AAf/AAP/gAD/gAAPwAAA/4AAA/+AAAf/AAAH/wAAB/gAAB+AAB/4AA/+AA/+AA/+AAD/AAAPAAAAgAAAAAAAAMAAGA4AA4D4APgHwB8APwfAAPn4AAf+AAAfwAAB/AAAf+AAD4+AA/B8AHwB8A+AD4DgADgMAAGAwAAADwAAAPwAAAPwAAAfgAAAfgAAAf/4AAf/gAH/+AB+AAAPwAAD8AAA/AAADwAAAMAAAAgAAAAAAAAMAACA4AA4DgAPgOAD+A4Af4DgH7gOB+OA4Pw4Dj8DgO/AOA/4A4D+ADgPgAOA4AA4DAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/////////gAAAOAAAA4AAADAAAAAAAAAAAAAAAAAAAAAAA4AAAD+AAAP/gAAH/4AAB/+AAAf+AAAH4AAABgAAAAAAAAADAAAAOAAAA4AAADgAAAP////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAADgAAAcAAADgAAAcAAADgAAAcAAAB4AAADwAAADgAAAHAAAAOAAAAYAAAAAAAAAAAAAAAAAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+AAHH8AA8/4AHzjgAcMOABxwYAHHBgAccOABxwwAHGHAAP/4AA//4AA//gAAAAAAAAAAAAAAAAAAA///4D///gP//+AA4BwAHADgAcAOABwA4AHADgAcAOAB4B4ADwPAAP/8AAf/AAAf4AAAAAAAAAAAAPwAAD/wAAf/gADwPAAeAeABwA4AHADgAcAOABwA4AHADgAeAeAA8DwABwOAADAwAAAAAAAAAAAA/AAAP/AAD//AAPA8AB4B4AHADgAcAOABwA4AHADgAcAOAA4BwD///gP//+A///4AAAAAAAAAAAAAAAAPwAAD/wAAf/gAD2PAAeYeABxg4AHGDgAcYOABxg4AHGDgAeYeAA/jwAB+OAAD4wAABgAAAAAAAAAAABgAAAGAAAB//+Af//4D///gPcAAA5gAADGAAAMYAAAAAAAAAPwAAD/wMA//w4DwPHgeAePBwA4cHADhwcAOHBwA4cHADhwOAcPB///4H///Af//wAAAAAAAAAAAAAAAAAAD///gP//+AA//4ADgAAAcAAABwAAAHAAAAcAAABwAAAHgAAAP/+AAf/4AA//gAAAAAAAAAAAAAAMf/+A5//4Dn//gAAAAAAAAAAAAAAAAAAHAAAAfn///+f//+5///wAAAAAAAAAAAAAAAAAAP//+A///4D///gAAcAAAD8AAAf4AADzwAAeHgAHwPAAeAeABgA4AEABgAAAAAAAAAD///gP//+A///4AAAAAAAAAAAAAAAAAAAAf/+AB//4AH//gAOAAABwAAAHAAAAcAAABwAAAHgAAAP/+AA//4AB//gAOAAABwAAAHAAAAcAAABwAAAHgAAAf/+AA//4AA//gAAAAAAAAAAAAAAAf/+AB//4AD//gAOAAABwAAAHAAAAcAAABwAAAHAAAAeAAAA//4AB//gAD/+AAAAAAAAAAAAAAAAD8AAA/8AAH/4AA8DwAHgHgAcAOABwA4AHADgAcAOABwA4AHgHgAPh8AAf/gAA/8AAA/AAAAAAAAAAAAAAAAB///8H///wf///A4BwAHADgAcAOABwA4AHADgAcAOAB4B4ADwPAAP/8AAf/AAAf4AAAAAAAAAAAAPwAAD/wAA//wADwPAAeAeABwA4AHADgAcAOABwA4AHADgAOAcAB///8H///wf///AAAAAAAAAAAAAAAAAAAH//gAf/+AB//4ADwAAAcAAABwAAAHAAAAcAAAAAAAAAAMAAHw4AA/jwAH+HgAcYOABxw4AHHDgAcMOABw44AHjjgAPH+AA8fwAAw+AAAAAABgAAAGAAAAcAAAf//wB///AH//+ABgA4AGADgAYAOABgA4AAAAAAAAAAAAAAAH/AAAf/wAB//wAAB/AAAAeAAAA4AAADgAAAOAAAA4AAADgAAAcAB//4AH//gAf/+AAAAAAAAAAAAAAABwAAAH4AAAf8AAAP8AAAH+AAAD+AAAD4AAA/gAAf8AAP+AAH/AAAfgAABwAAAAAAAAAAAABwAAAH8AAAf+AAAP/gAAD/gAAB+AAAf4AAP8AAP+AAB/AAAH4AAAf8AAAP+AAAD/gAAB+AAAf4AAf/AAP/AAB/gAAHgAAAQAAABAAIAHADgAeAeAA8HwAB8+AAD/gAAD8AAAPwAAD/gAAfPgADwfAAeAeABwA4AEAAgAAAAABAAAAHgAAAfwAAA/wAAAf4BwAP4/AAP/8AAP+AAD/AAB/wAA/4AAP8AAB+AAAHAAAAQAAAAAAIAHADgAcAeABwD4AHA/gAcHuABx84AHPDgAf4OAB/A4AHwDgAeAOABgA4AEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAH4Af//////n//AAAA4AAADgAAAAAAAAAAAAAAAAAP//+A///4D///gAAAAAAAAAAAAAAAAAAA4AAADgAAAOAAAA//5/9////wAH4AAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAeAAAD4AAAOAAAA4AAADgAAAHAAAAcAAAA4AAADgAAAOAAAD4AAAPAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), 32, atob("BgkMGhEZEgYMDAwQCAwICxILEBAREBEOEREJCREVEQ8ZEhEUExAOFBQHDREPGBMUERQSEhEUERsREBIMCwwTEg4QERAREQoREQcHDgcYEREREQoPDBEPFg8PDwwIDBMc"), 28+(scale<<8)+(1<<16)); + this.setFontCustom( + atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/+cB//5wH//nAAAAAAAAAAAAAAAAAAAB8AAAHwAAAfAAAAAAAAAAAAAfAAAB8AAAHwAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAQcAADhwAAOHBAA4c8ADh/wAP/+AB/+AA//wAH+HAAe4cMBDh/wAOP/AA//wAP/wAH/3AAf4cABzhwAAOHAAA4cAADgAAAOAAAAAAAAAAAAAAAAAAAAwAH8HwA/4PgD/geAePA8BwcBw/BwH78DgfvwOB+HA4HAeBwcA8HDgB4f+ADg/wAGB+AAAAAAAAAAAAAAAH4AAA/wBwHngPAcOB4Bw4PAHDh4AcOPAA/x4AD/PAADx4AAAPAAAB5wAAPPwAB5/gAPOPAB4wcAPDBwB4MHAPA4cA4B/gBAH8AAAHAAAAAAAAAAAAAPAAHD/AB/f+AP/x4B4+DwHB4HAcDwcBwHhwHAPHAcAccB4A5wDgB+AGA/4AAH/AAAf+AAAA8AAABgAAAAAfAAAB8AAAHwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/8AD//+A/+/+H4AD98AAB3gAADIAAAAAAAAAAAAAIAAABwAAAXwAAHPwAB8P8D/gP//4AH/8AAAAAAAAAAAAAAAAAAAAAAAAHAAAAcwAAA/gAAb8AAB/gAAH+AAAD+AAAOwAABxAAADAAAAAAAAAAAAAADAAAAMAAAAwAAADAAAAMAAAAwAAB//AAH/8AAAwAAADAAAAMAAAAwAAADAAAAMAAAAAAAAAAAAAABwAAAHIAAAfgAAB8AAAAAAAAAAAAAAAAAAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAAAAAAAAAAAAAAAAAAAABwAAAHAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAA/wAA//AA//AA//AAH/AAAfAAABAAAAAAAAAAAAAAAAAAAf/wAH//wA///gDgAOAcAAcBwABwHAAHAcAAcBwABwHgAPAPAB4Af//AA//4AA/+AAAAAAAAAAAAAAAAMAAABwAAAOAAAB4AAAH///Af//8B///wAAAAAAAAAAAAAAAAAAAAwAcAPADwB8AfAPAB8B4APwHAB/AcAPcBwB5wHAPHAcB4cA8PBwD/4HAH/AcAHwBwAAAAAAAAAAAAGAHAAcAcAB4BwYDwHDwHAceAcBz4BwHfgHAf3AcB+eDwHw/+AeB/wBwD+AAAAAAAAAAAAAAAAABwAAAfAAAP8AAD/wAA/nAAP4cAD+BwAfgHAB4AcAEA//AAD/8AAP/wAABwAAAHAAAAMAAAAAAAAAAAAAEAH/w4Af/D4B/8HgHDgPAcOAcBw4BwHDgHAcOAcBw8DwHB4eAcH/wBgP+AAAPwAAAAAAAAAAAAAAAB//AAf//AD//+AOHB4Bw4BwHDgHAcOAcBw4BwHDgHAcPA8A4eHgDh/8AEB/gAAD4AAAAAAAAAABwAAAHAAAAcAAMBwADwHAB/AcA/4BwP8AHH/AAd/gAB/wAAH8AAAeAAAAAAAAAAAAAAAEAAPD+AB/f8AP//4B4+DwHDwHAcHAcBwcBwHBwHAcPAcB/+DgD//+AH5/wACB8AAAAAAAAAAAAAAAAEAAAD+AAAf+DAD74OAODw8BwHBwHAOHAcA4cBwDBwHAcHAeBw8A+ePgB//8AD//gAB/wAAAAAAAAAAAAAAAAAAAAAHBwAAcHAABwcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4AcgDgB+AOAHwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAeAAAD8AAAf4AADzwAAeHgADwPAAGAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADGAAAMYAAAxgAADGAAAMYAAAxgAADGAAAMYAAAxgAADGAAAMYAAAxgAADGAAAMYAAAxgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABACAAOAcAA8DgAB4cAABzgAAD8AAAHgAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAHgAAA+AAAHgAAAcAAABwD5wHAfnAcD8cBweAAHzwAAP+AAAfwAAAcAAAAAAAAAAAAAAAAAAB/AAA//AAH/+AA8A8AHAA4A4ABwDg+HAcH8OBw444GDBhgYMGGBgwYYHDjjgcP8OBw/44DgDhAOAGAAeAYAA+HgAB/8AAB/gAAAAAAAAAAAAABAAAA8AAAfwAAP/AAH/gAD/4AB/zgAf4OAB8A4AHwDgAf4OAA/84AAP/gAAH/AAAD/gAAB/AAAA8AAAAQAAAAAAAAAB///wH///Af//8BwOBwHA4HAcDgcBwOBwHA4HAcDgcBweBwHj4HAP/58Afz/gAcH8AAAPAAAAAAAH/AAB//AAf//AB4A8APAB4B4ADwHAAHAcAAcBwABwHAAHAcAAcBwABwHAAHAOAA4A8AHgB8B8ADwHgADAYAAAAAAAAAAAAAAAH///Af//8B///wHAAHAcAAcBwABwHAAHAcAAcBwABwHAAHAeAA8A8AHgB8B+AD//gAH/8AAD/AAAAAAAAAAAAAAAAf//8B///wH///AcDgcBwOBwHA4HAcDgcBwOBwHA4HAcDgcBwOBwHAAHAcAAcAAAAAAAAAAAAAAB///wH///Af//8BwOAAHA4AAcDgABwOAAHA4AAcDgABwOAAHAAAAcAAAAAAAAAP/AAB//AAf//AB4A8APAB4B4ADwHAAHAcAAcBwABwHAAHAcAAcBwGBwHgYPAOBg4A+GPgB4f8ADh/gAAH4AAAAAAAAAAAAAAAH///Af//8B///wAA4AAADgAAAOAAAA4AAADgAAAOAAAA4AAADgAAAOAAAA4AAf//8B///wH///AAAAAAAAAAAAAAAAAAAB///wH///Af//8AAAAAAAAAAAABgAAAHgAAAeAAAA8AAABwAAAHAAAAcAAABwH///Af//4B///AAAAAAAAAAAAAAAAAAAAf//8B///wH///AAHgAAA/AAAH+AAA88AAHh8AA8D4AHgDwA8AHgHgAPAYAAcBAAAwAAABAAAAAAAAAAH///Af//8B///wAAAHAAAAcAAABwAAAHAAAAcAAABwAAAHAAAAcAAABwAAAAAAAAAAAAAAH///Af//8B///wB/AAAB/AAAA/AAAA/gAAA/gAAA/gAAA/AAAD8AAA/AAAfwAAH8AAB/AAAfgAAP4AAB///wH///Af//8AAAAAAAAAAAAAAAAAAAH///Af//8B///wD8AAAD4AAAH4AAAHwAAAPwAAAPgAAAPgAAAfAAAAfAAAA/Af//8B///wH///AAAAAAAAAAAH/AAB//AAf//AB4A8APAB4B4ADwHAAHAcAAcBwABwHAAHAcAAcBwABwHAAHAOAA4A8AHgB+D8AD//gAH/8AAD+AAAAAAAAAAAH///Af//8B///wHAOAAcA4ABwDgAHAOAAcA4ABwDgAHAeAAeBwAA+fAAD/4AAD/AAADgAAAAAAAAf8AAH/8AB//8AHgDwA8AHgHgAPAcAAcBwABwHAAHAcAAcBwABwHAAnAcAHcA4AfgDwA+AH4P4AP//wAf/3AAP4AAAAAAAAAAAf//8B///wH///AcA4ABwDgAHAOAAcA4ABwDgAHAOAAcB+AB4H+AD59/AP/h8AP8BwAOABAAAAAAAAAAAAAwAD4HwA/4fAD/geAePA8BwcBwHBwHAcDgcBwOBwHA4HAcDgcA4HDwD4eeAHw/4AOD/AAIDwAAAAABwAAAHAAAAcAAABwAAAHAAAAcAAABwAAAH///Af//8B///wHAAAAcAAABwAAAHAAAAcAAABwAAAGAAAAAAAAAAAAAH//wAf//gB///AAAAeAAAA8AAABwAAAHAAAAcAAABwAAAHAAAAcAAADgAAAeAf//wB//+AH//gAAAAAAAAAAGAAAAfAAAB/gAAB/wAAA/4AAAf8AAAP/AAAH8AAADwAAA/AAAf8AAP+AAP/AAH/gAB/wAAH4AAAcAAABAAAAHwAAAf4AAA/+AAAP/gAAH/wAAB/wAAA/AAAf8AAf/AAP/gAP/gAB/gAAH4AAAf+AAAf/AAAH/wAAB/8AAAfwAAB/AAB/8AA/+AA/+AAf+AAB/AAAHAAAAAAAAAAAAQGAADAeAA8B8AHwD8B+AD4PgAH74AAH/AAAPwAAA/gAAP/gAD8fAAfA/AH4A+AeAA8BwABwEAABAQAAABwAAAHwAAAPwAAAfwAAAfgAAAfgAAAf/wAB//AAf/8AH8AAA/AAAPwAAB8AAAHAAAAQAAAAAAAAAAABAcAAcBwADwHAA/AcAP8BwD/wHAfnAcH4cBx+BwHPwHAf8AcB/ABwH4AHAeAAcBgABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/////////gAAAOAAAA4AAADAAAAAAAAAAAAAAAAAAAAAAAeAAAB/gAAH/4AAB/+AAAf/gAAH/AAAB8AAAAQAAAAAAAAAAAAAAOAAAA4AAADgAAAP/////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAADgAAAcAAADgAAAcAAADgAAAcAAAB4AAADwAAADgAAAHAAAAOAAAAYAAAAAAAAAAAAAAAAAAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfAADj+AAef8AD5xwAOGHAA44MADjgwAOOHAA44YADjDgAH/8AAf/8AAf/wAAAAAAAAAAAAAAAAAAAf//8B///wH//+AAcA4ADgBwAOAHAA4AcADgBwAOAHAA8A8AB8PgAD/8AAH/gAAH4AAAAAAAAAAAAH4AAB/4AAP/wAB4HgAPAPAA4AcADgBwAOAHAA4AcADgBwAPAPAAeB4AA4HAABgYAAAAAAAAAAAAfgAAH/gAB//gAHgeAA8A8ADgBwAOAHAA4AcADgBwAOAHAAcA4B///wH///Af//8AAAAAAAAAAAAAAAAH4AAB/4AAP/wAB7HgAPMPAA4wcADjBwAOMHAA4wcADjBwAPMPAAfx4AA/HAAB8YAAAwAAAAAAAAAAAAwAAADAAAB///AP//8B///wHMAAAYwAABjAAAGMAAAAAAAAAPwAAD/wMA//w4DwPHgeAePBwA4cHADhwcAOHBwA4cHADhwOAcPB///4H///Af//wAAAAAAAAAAAAAAAAAAB///wH///AAf/8ABwAAAOAAAA4AAADgAAAOAAAA4AAADwAAAH//AAP/8AAf/wAAAAAAAAAAAAAAAAAAAc//8Bz//wHP//AAAAAAAAAAAAAAHAAAAcAAAH+f///5///7H//8AAAAAAAAAAAAAAH///Af//8B///wAAPAAAB+AAAP8AAB54AAfDwAD4HgAOAPAAwAcACAAwAAAAAAAAAB///wH///Af//8AAAAAAAAAAAAAAAAAAAAP//AA//8AB//wAHAAAA4AAADgAAAOAAAA4AAAD4AAAH//AAP/8AB//wAHAAAA4AAADgAAAOAAAA4AAADwAAAH//AAP/8AAf/wAAAAAAAAAAAAAAAP//AA//8AB//wAHAAAA4AAADgAAAOAAAA4AAADgAAAPAAAAf/8AA//wAB//AAAAAAAAAAAAAAAAB+AAAf+AAD/8AAeB4ADwDwAOAHAA4AcADgBwAOAHAA4AcADwDwAHw+AAP/wAAf+AAAfgAAAAAAAAAAAAAAAB///8H///wP///A4BwAHADgAcAOABwA4AHADgAcAOAB4B4AD4fAAH/4AAP/AAAPwAAAAAAAAAAAAPwAAD/wAA//wADwPAAeAeABwA4AHADgAcAOABwA4AHADgAOAcAB///8H///wf///AAAAAAAAAAAAAAAAAAAD//wAP//AAf/8ABwAAAOAAAA4AAADgAAAOAAAAAAAAAYGAAD4cAAfx4AD3DwAOOHAA44cADjhwAOGHAA4ccADxzwAHj+AAOP4AAYOAAAAAAAwAAADAAAAMAAAP//wA///gD///AAwAcADABwAMAHAAwAcADAAwAAAAAAAAAAD/gAAP/4AA//4AAA/gAAAPAAAAcAAABwAAAHAAAAcAAABwAAAOAA//8AD//wAP//AAAAAAAAAAAIAAAA4AAAD8AAAH+AAAH/AAAD/gAAB/AAAB8AAA/wAAf8AAP+AAD/AAAPgAAAwAAAAAAAAIAAAA8AAAD/AAAH/gAAD/wAAA/wAAA/AAAf8AAP+AAP+AAA/AAAD+AAAH/AAAD/gAAA/wAAA/AAAf8AAP/AAP/AAA/gAADgAAAAAAAAAAEADAAwAOAHAA+B8AB8PgAB74AAD/AAAH4AAA/wAAHvgAB8PgAPgfAA4AcADAAwAAABABAAAAHAAAAfgAAA/wAAA/wAwAf4fAAP/8AAP/AAB/gAA/wAAf4AAP+AAB/AAAHgAAAQAAAAAAEADAAwAOAPAA4B8ADgPwAOD/AA4ecADnxwAO8HAA/gcAD8BwAPAHAA4AcACAAwAAAAAAAAAAAAAAAAAAAAAAAAAA8AB////f//////n/+AAAA4AAADgAAAAAAAAAAAAAAAAAH///Af//8B///wAAAAAAAAAAAAAAAAAAA4AAADgAAAOAAAA//5/9////z////AAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAB8AAAHwAAAcAAABwAAAHgAAAOAAAA8AAABwAAAHAAAB8AAAHwAAAeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAGAAABwAAAOAAABwAAAHAAAAcAAAA4AAABwAAABgAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAOAB4B4ADwPAAHh4AAPPAAAf4AAA/AAAB4AAAPwAAB/gAAPPAAB4eAAPA8AB4B4AHADgAIAEAAAAAAADAAAAMAAAAwAAADAAAAMAAAAwAAHDDgA8MPADww8AGDBgAAMAAAAwAAADAAAAMAAAAwAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADn//gOf/+A5//4AAAAAAAAAAAAAAAAAAAD/AAA//AAH/+AA+B8ADgBwAOAHAHwAPgfAA+B8AD4A4AcADwDwAHgeAAOBwAAQCAAAAAAAAAAAADgcAAOBwAA4HAD//8A///wD///AeDgcBwOBwHA4HAcDgcB4GBwD4AHAHgAcAOAAAAAAAAAAAAAMAGAB7+8AD//gAHx8AAcBwADgDgAOAOAA4A4ADgDgAOAOAA4A4ABwHAAHg8AA//4AH//wAMOGAAAAAAQAAABwAAAHwMYAPwxgAfjGAAfsYAAf7gAAf/wAB//AAf/8AH7GAA/MYAPwxgB8DGAHAAAAQAAAAAAAAAAAAAf/D/5/8P/n/w/+AAAAAAAAAAAAAAAAAAAABwAAffhwD//Hgf+cfBzwwcGHDhwYcOHBxw4cHDhxwfOPvA8//4Bx//AADwwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAP/wAB//gAPAPAB4AOAPDw8A4/xwHH/jgc4HOBzgc4HMAzgcwDOBzgc4HPDjgOcOeA4whwBwAOAHwD4APw/AAf/4AAf+AAAPAAAAAAAATgAAD/AAANsAAA2wAADTAAAP8AAAfwAAAAAAAAAAAAAAAAAAgAAAPAAAB+AAAOeAADw8AAOIwAADxAAAfgAADngAA8PAADgMAAEAQAAAAAAAAAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAAB+AAAH4AAAAAAAAAAAAAAAAAAAAD8AAA/8AAHh4AAYDgAD/3AAN/MAA0QwADRjAAN/MAA7hwABwOAADhwAAH+AAAPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfgAAD/AAAeeAABw4AAGDgAAYOAABw4AAH/AAAP8AAAfAAAAAAAAAAAAAAAAAAAwYAADBgAAMGAAAwYAADBgAAMGAAP+YAA/5gAD/mAAAwYAADBgAAMGAAAwYAADBgAAAAAAAAAAAAAAAMDAABwcAAPDwAAwPAADB8AAMOwAA5zAAB+MAADwwAAAAAAAAAAAIBAAAwGAADMcAANwwAA/DAAD8MAAO/wAAx+AAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf///B///8H//AAAAeAAAA4AAADgAAAOAAAA4AAADgAAAcAB//gAH//gAf/+AAAAAAAAAAAAAAAAAAAAP4AAB/4AAP/gAB//AAH/8AAf/wAB//AAH///8f///x////AAAAAAAAAB////H///8f///wAAAAAAAAAAAAAAABAAAAOAAAB4AAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAzAAAPMAAA/wAAAeAAAAAAAAAAAAAAAAAAAIAAABgAAAMAAAA//AAD/8AAAAAAAAAAAAAAAAAAAAAA8AAAP4AAAwwAADDAAAMMAAA5wAAB+AAADwAAAAAAAAAAAAAAAAAMAwAA8HAAB44AAD/AAAD4AADGMAAOBwAAeOAAA/wAAA+AAABgAAAAAAAAAAAAAAABAAAAMAAABwAAAH/8CAf/wcAAAHgAAA8AAAHgAAB4AAAPAAAB4AAAeAAADwAAA+AAAHgCAA8A8APAfwB4H7AHB+MAAHAwAAQ/wAAD/AAAAwAAADAAAAAAAAAAAAAAAAAAAAEAAAAwAAAHAAAAf/wIB//BwAAAeAAADwAAAeAAAHgAAA8AAAHgAAB4AAAPAAAD4AAAeAAADwAAA8GAwHg4HAcHA8AAYHwABg7AAGHMAAf4wAA/DAAA4MAAAAAAAAAAYBgABgHAAGMOAAZwYABvBgAH8OCAe/wcBx+HgABg8AAAHgAAB4AAAPAAAB4AAAeAAADwAAA+AAAHgHAA8B8APAfwB4HzADB8MAAHAwAAQ/wAAD/AAAAwAAAAAAAAAAAAAAAAAA4AAAP4AAB/wAAPHgABwOA4/A4Dn4DgOfAOAAAA4AAAHgAAB8AAAHgAAAYAAAAAAAAEAAADwAAB/AAA/8AAf+AAP/gAH/OAB/g4AHwDgAfAOAB/g4AD/zgAA/+AAAf8AAAP+AAAH8AAADwAAABAAAAEAAADwAAB/AAA/8AAf+AAP/gAH/OAB/g4AHwDgAfAOAB/g4AD/zgAA/+AAAf8AAAP+AAAH8AAADwAAABAAAAEAAADwAAB/AAA/8AAf+AAP/gAH/OAB/g4AHwDgAfAOAB/g4AD/zgAA/+AAAf8AAAP+AAAH8AAADwAAABAAAAEAAADwAAB/AAA/8AAf+AAP/gAH/OAB/g4AHwDgAfAOAB/g4AD/zgAA/+AAAf8AAAP+AAAH8AAADwAAABAAAAEAAADwAAB/AAA/8AAf+AAP/gAH/OAB/g4AHwDgAfAOAB/g4AD/zgAA/+AAAf8AAAP+AAAH8AAADwAAABAAAAAAAAABwAAA/AAAf8AAP/AAH/wfD/nD+/wcMb4BwxvgHD+/wcHx/5wEAf/AAAP+AAAH/AAAD8AAABwAAAAAAAEAAADwAAB/AAA/8AAf+AAP/gAH/OAB/g4AHwDgAcAOABwA4AHADgAf//8B///wHA4HAcDgcBwOBwHA4HAcDgcBwOBwHA4HAcDgcBwOBwHAAHAYAAMAAAAAAAAAAA/4AAP/4AD//4APAHgB4APAPAAeA4AA4DgADg+AAPz4AA//gAD/+AAOe4AA4BwAHAHgA8APgPgAeA8AAYDAAAAAAAAAAAAAAAAf//8B///wH///AcDgcBwOBwHA4HAcDgcBwOBwHA4HAcDgcBwOBwHAAHAcAAcAAAAAAAAAAAAAAB///wH///Af//8BwOBwHA4HAcDgcBwOBwHA4HAcDgcBwOBwHA4HAcAAcBwABwAAAAAAAAAAAAAAH///Af//8B///wHA4HAcDgcBwOBwHA4HAcDgcBwOBwHA4HAcDgcBwABwHAAHAAAAAAAAAAAAAAAf//8B///wH///AcDgcBwOBwHA4HAcDgcBwOBwHA4HAcDgcBwOBwHAAHAcAAcAAAAAAAAAAAAAAB///wH///Af//8AAAAAAAAAAAAAAAAAAAH///Af//8B///wAAAAAAAAAAAAAAAAAAAf//8B///wH///AAAAAAAAAAAAAAAAAAAB///wH///Af//8AAAAAAAAAAABgAAAGAAH///Af//8B///wHAYHAcBgcBwGBwHAYHAcBgcBwABwHAAHAeAA8A8AHgB+D8AD//gAH/8AAD+AAAAAAAAAAAAAAAAf//8B///wH///APwAAAPgAAAfgAAAfAAAA/AAAA+AAAA+AAAB8AAAB8AAAD8B///wH///Af//8AAAAAAAAAAAf8AAH/8AB//8AHgDwA8AHgHgAPAcAAcBwABwHAAHAcAAcBwABwHAAHAcAAcA4ADgDwAeAH4PwAP/+AAf/wAAP4AAAAAAAH/AAB//AAf//AB4A8APAB4B4ADwHAAHAcAAcBwABwHAAHAcAAcBwABwHAAHAOAA4A8AHgB+D8AD//gAH/8AAD+AAAAAAAB/wAAf/wAH//wAeAPADwAeAeAA8BwABwHAAHAcAAcBwABwHAAHAcAAcBwABwDgAOAPAB4Afg/AA//4AB//AAA/gAAAAAAAf8AAH/8AB//8AHgDwA8AHgHgAPAcAAcBwABwHAAHAcAAcBwABwHAAHAcAAcA4ADgDwAeAH4PwAP/+AAf/wAAP4AAAAAAAH/AAB//AAf//AB4A8APAB4B4ADwHAAHAcAAcBwABwHAAHAcAAcBwABwHAAHAOAA4A8AHgB+D8AD//gAH/8AAD+AAAAAAAAAAAAGDgAA8eAAB7wAAD+AAAHwAAAfAAAD+AAAe8AADw4AAGBAAAAAAAAAAAAAAAAAf8MAH//4B///AHgD4A8AfgHgD/AcAecBwDxwHAeHAcDwcBw+BwHHgHAc8AcA/gDgD8AeAH4PwA//+AH//wAMP4AAAAAAAAAAAf//AB//+AH//8AAAB4AAADwAAAHAAAAcAAABwAAAHAAAAcAAABwAAAOAAAB4B///AH//4Af/+AAAAAAAAAAAAAAAAAAAAH//wAf//gB///AAAAeAAAA8AAABwAAAHAAAAcAAABwAAAHAAAAcAAADgAAAeAf//wB//+AH//gAAAAAAAAAAAAAAAAAAAB//8AH//4Af//wAAAHgAAAPAAAAcAAABwAAAHAAAAcAAABwAAAHAAAA4AAAHgH//8Af//gB//4AAAAAAAAAAAAAAAAAAAAf//AB//+AH//8AAAB4AAADwAAAHAAAAcAAABwAAAHAAAAcAAABwAAAOAAAB4B///AH//4Af/+AAAAAAAAAAAQAAABwAAAHwAAAPwAAAfwAAAfgAAAfgAAAf/wAB//AAf/8AH8AAA/AAAPwAAB8AAAHAAAAQAAAAAAAAAAAAAf//8B///wH///ABwHAAHAcAAcBwABwHAAHAcAAcBwABwHAAHg8AAP/gAAf8AAA/gAAAAAAAAAAAAAAAA///AP//8A///wHgAAAcAAcBwABwHBwHAcHAcB4+BwD/4PAH954APn/gAAP8AAAOAAAAAAAAAAAAAD4AAcfwADz/gAfOOCBww4PHHBg+ccGAZxw4AHHDAAcYcAA//gAD//gAD/+AAAAAAAAAAAAAAAAAPgABx/AAPP+AB844AHDDgAccGAZxwYPnHDg8ccMDBxhwAD/+AAP/+AAP/4AAAAAAAAAAAAAAAAA+AAHH8AA8/4BnzjgOcMOBxxwYOHHBg4ccOBxxwwDnGHAGP/4AA//4AA//gAAAAAAAAAAAAAAAAHwAA4/gAHn/A8+ccDzhhwMOODA444MBjjhwHOOGAM4w4Dx//AOH//AAH/8AAAAAAAAAAAAAAAAAfAADj+AAef8Bz5xwHOGHAc44MADjgwAOOHAY44YBzjDgHH/8AAf/8AAf/wAAAAAAAAAAAAAAAAAfAADj+AAef8AD5xweOGHD844MMzjgwzOOHD844YHjjDgAH/8AAf/8AAf/wAAAAAAAAAAAAAAAAHwAAx/gAHn/AAc4cADjhwAOMDAA4wcADjBwAOMHAA4w4AB//AAH/4AAP/wAB/fgAPMPAA4wcADjBwAOMHAA4wcADjBwAPMPAAfx4AA/HAAB8YAAAAAAAAAAAA/AAAP/AAB/+AAPA8AB4B4AHADgwcAPzBwA/8HADngcAOMB4B4ADwPAAHA4AAMDAAAAAAAAAAAAA/AAAP/AAB/+AAPY8AB5h4OHGDg+cYOB5xg4AnGDgAcYOAB5h4AD+PAAH44AAPjAAAGAAAAAAAAAAAAAPwAAD/wAAf/gAD2PAAeYeABxg4AHGDgOcYOD5xg4OHGDggeYeAA/jwAB+OAAD4wAABgAAAAAAAAAAAAD8AAA/8AAH/4AY9jwDnmHgecYODhxg4OHGDg8cYOB5xg4BnmHgCP48AAfjgAA+MAAAYAAAAAAAAAAAAB+AAAf+AAD/8Acex4BzzDwHOMHAA4wcADjBwAOMHAc4wcBzzDwGH8eAAPxwAAfGAAAMAAAAAAAAAAAOAAAA+f/+A5//4An//gAAAAAAAAAAAAAAAAAAAJ//4Dn//g+f/+DgAAAAAAAAMAAABwAAAOP//Aw//8Dj//wHAAAAMAAABwAAAHAAAAA//8AD//wAP//AcAAABwAAAAAAAAAA/gAAP/AAB//AAPA8AA4A4DDgDgPMAOA/wA4D7ADgPOAOB+8B4C/+/AA//4AB//AAAHAAAAAAAAAAAAP//AA//8Bx//wPHAAAw4AADjgAAGOAAAc4AAAzgAAPPAAA4f/8AA//wAB//AAAAAAAAAAAAAAAAA/AAAP/AAB/+AAPA8CB4B4OHADg+cAOA5wA4AHADgAcAOAB4B4AD4fAAH/4AAP/AAAPwAAAAAAAAAAAAPwAAD/wAAf/gADwPAAeAeABwA4AnADgecAOD5wA4OHADgAeAeAA+HwAB/+AAD/wAAD8AAAAAAAAAAAAD8AAA/8AAH/4AY8DwDngHgecAODhwA4OHADg8cAOB5wA4BngHgCPh8AAf/gAA/8AAA/AAAAAAAAAAAAB+AAAf+AAD/8AceB4DzwDwMOAHA44AcBjgBwHOAHAM4AcDzwDwOHw+AAP/wAAf+AAAfgAAAAAAAAAAAAfgAAH/gAA//AHHgeAc8A8BzgBwAOAHAA4AcADgBwHOAHAc8A8Bh8PgAD/8AAH/gAAH4AAAAAAAAAAAAMAAAAwAAADAAAAMAAAAwAAADAAADtwAAO3AAA7cAAAMAAAAwAAADAAAAMAAAAAAAAAAAAAH5gAB//AAP/4AB4PgAPB/AA4PcADh5wAOPHAA54cADvBwAP4PAAfD4AB//AAP/4AAZ+AAAAAAAAAAAAf8AAB//AAH//AAAH8AAAB4OAADg+AAOB4AA4AgADgAAAOAAABwAH//gAf/+AB//4AAAAAAAAAAAAAAAH/AAAf/wAB//wAAB/AAAAeAAAA4BgADgeAAOD4AA4MAADgAAAcAB//4AH//gAf/+AAAAAAAAAAAAAAAB/wAAH/8AAf/8AYAfwDgAHgcAAODgAA4OAADg8AAOB4AA4BgAHACf/+AB//4AH//gAAAAAAAAAAAAAAA/4AAD/+AAP/+AcAP4BwADwHAAHAAAAcAAABwAAAHAcAAcBwADgGP//AA//8AD//wAAAAAAAAAABAAAAHAAAAfgAAA/wAAA/wAAAf4cAAP/zgAP/+AB/jgA/wAAf4AAP+AAB/AAAHgAAAQAAAAAAAAAAAA//////////////A4BwAHADgAcAOABwA4AHADgAcAOAB4B4AD4fAAH/4AAP/AAAPwAAAAAABAAAAHAAAAfgAAw/wADg/wA+Af4fAAP/8AAP/AAB/g4A/wDgf4AOP+AAB/AAAHgAAAQAAA=='), + 32, + atob("BgkMGhEZEgYMDAwQCAwICxILEBAREBEOEREJCREVEQ8ZEhEUExAOFBQHDREPGBMUERQSEhEUERsREBIMCwwTEg4QERAREQoREQcHDgcYEREREQoPDBEPFg8PDwwIDBMcCgoAAAAAAAAAAAAAACERESEAAAAAAAAAAAAAAAAhIQAGCRAQEhAIDw8XCQ8RABIODRELCw4REwcLCQoPHBscDxISEhISEhoUEBAQEAcHBwcTExQUFBQUDhQUFBQUEBEREBAQEBAQGhARERERBwcHBxAREREREREPEREREREPEQ8="), + 28+(scale<<8)+(1<<16) + ); return this; }; -var imgLock = { - width : 16, height : 16, bpp : 1, - transparent : 0, - buffer : E.toArrayBuffer(atob("A8AH4A5wDDAYGBgYP/w//D/8Pnw+fD58Pnw//D/8P/w=")) +Graphics.prototype.setMiniFont = function(scale) { + // Actual height 16 (15 - 0) + this.setFontCustom( + atob('AAAAAAAAAAAAAP+w/5AAAAAA4ADgAOAA4AAAAAAAAAABgBmAGbAb8D+A+YDZ8B/wf4D5gJmAGQAQAAAAAAAeOD8cMwzxj/GPMYwc/Az4AAAAAHAA+DDIYMjA+YBzAAYADeA7MHMw4zDD4ADAAAAz4H/wzjDHMMMwwbBj4APgADAAAAAA4ADgAAAAAAAAAAfwH/54B+ABAAAAAOABeAcf/gfwAAAAACAAaAD4APgAOABgAAAAAAACAAIAAgA/wAMAAgACAAAAAAAAPAA4AAAAAAIAAgACAAIAAgAAAAAAADAAMAAAAAAAcAfwf4D4AIAAAAA/wH/gwDDAMMAwwDB/4D/AAAAAAGAAwAD/8P/wAAAAAHAw8HDA8MHww7DnMH4wGBAAAMBgyHDcMPww/DDv4MfAAAAAAAHgD+A+YPhgwGAH8AfwAEAAAAAA/GD8cMwwzDDMMM5wx+ABgAAAP8B/4MwwzDDMMMwwx+ADwAAAgADAAMBwwfDPgP4A8ADAAAAAe+D/8M4wxjDGMP5wf+ABwAAAfAB+cMYwwjDCMMYwf+A/wAAAAAAAAAxgBCAAAAAAAAAYPBA4AAAAAAAAAgAHAA+AHMAYYAAAAAAAAAAAAAAJAAkACQAJAAkACQAJAAkAAAAAAAAAAAAAABhgHMAPgAcAAgAAAAAAAABgAOAAwbDDsMYA/AA4AAAAAAAD4A/wGBgxzDPsMyQjJDPkM+wYIBxgD+AAAAAAABAA8A/gf8DwwODA/sAfwAHwADAAAP/w//DGMMYwxjDOMP9we+ABwA8AP8Bw4MAwwDDAMMAwwDDgcHDgMMAAAAAA//D/8MAwwDDAMMAw4HB/4D/AAAAAAP/w//DGMMYwxjDGMMQwgBAAAP/w//DDAMMAwwDDAMAADwA/wHDgwDDAMMAwwDDCMOJwc+ADwAAA//D/8AMAAwADAAMAAwD/8P/wAAAAAP/w//AAAABgAHAAMAAwAHD/4P+AAAAAAP/w//AOAB+AOcBw4MBwgDAAEAAA//D/8AAwADAAMAAwADAAAP/w//A8AA8AA+AA8AHwB8AeAHgA//D/8AAAAAD/8P/wcAAcAA8AA4AB4P/w//AAAA8AP8Bw4MAwwDDAMMAwwDDgcH/gP8AAAAAA//D/8MMAwwDDAMYA7gB8ABgADwA/wHDgwDDAMMAwwDDA8ODwf/A/8AAAAAD/8P/wwwDDAMMAx4Dv4HxwEBAAAHjg/HDMMMYwxjDGMONwc+ABwMAAwADAAMAA//D/8MAAwADAAIAAAAD/wP/gAHAAMAAwADAAMAHg/8AAAMAA+AA/AAfgAPAA8AfgPwD4AMAAwAD4AD+AA/AA8A/g/gDwAP4AH8AB8APwH8D8AMAAgBDAMPDgO8APAB8AOcDw8MAwgBCAAOAAeAAeAAfwH/B4AOAAwAAAAMAwwPDB8Mew3jD4MPAwwDAAAAAAAAB//3//QABAAAAAAADgAP4AH+AB8AAQAABAAEAAf/9//wAAAAAAAAAAGAAwAGAAwABgADAAGAAAAAAAAAQABAAEAAQABAAEAAQABAAEAAQABAAAAAAAAAAAAAAAAAAAAAAAQA3wHbAZMBswGzAf4A/wAAAAAP/w//AYMBgwGDAYMA/gB8AAAAEAD+Ae8BgwGDAYMBgwDGAAAAMAD+Ae8BgwGDAYMBhw//D/8AAAAYAP4B/wGTAZMBkwGTAP4AcAEAAYAP/w//CQAJAAAwAP4hz3GDMQMxAzGHcf/h/8AAAAAP/w//AYABgAGAAYAA/wB/AAAAAA3/Df8AAAAAOf/9//AAAAAP/w//ADgAfADGAYMBAQAAD/8P/wAAAAAB/wH/AYABgAGAAf8A/wGAAYABgAH/AP8AAAAAAf8B/wGAAYABgAGAAP8AfwAAADAA/gHvAYMBgwGDAYMA/gB8AAAAAAH/8f/xgwGDAYMBgwD+AHwAAAAwAP4B7wGDAYMBgwGHAf/x//AAAAAB/wH/AYABgAEAAAAA5gHzAbMBkwGbAd8AzgEAAYAP/wf/AQMBAwAAAAAB/gH/AAMAAwADAAcB/wH/AAABAAHgAPwAHwAPAH4B8AGAAQAB8AB+AA8APwHwAeAA/AAPAD8B+AHAAQEBgwHOAHwAOAD+AccBAwAAAQAB4AD4EB/wB8A/APgBwAAAAAEBgwGPAZ8B8wHjAcMBAQAAAAAABgf/9/n2AAAAAAAP/w//AAAEAAYAB/nz//AGAAAAAAAAAAAAcABgAGAAcAAwAHAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'), + 32, + atob("AwUHDwoOCwQHBwcJBAcEBgoGCQkKCQoICQoFBQoMCgkPCgoMCwkICwsECAoIDgsMCgwKCgoLCg8KCQoHBgcLCwgJCgkKCQYKCgQECAQOCgoKCgYIBwoIDAkJCAcEBwsQ"), + 16+(scale<<8)+(1<<16) + ); + return this; }; -var imgSteps = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("/H///wv4CBn4CD8ACCj4IBj8f+Eeh/wjgCBngCCg/4nEH//4h/+jEP/gRBAQX+jkf/wgB//8GwP4FoICDHgICCBwIA==")) -}; - -var imgBattery = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("/4AN4EAg4TBgd///9oEAAQv8ARQRDDQQgCEwQ4OA")) -}; - -var imgBpm = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("/4AOn4CD/wCCjgCCv/8jF/wGYgOA5MB//BC4PDAQnjAQPnAQgANA")) -}; - -var imgTemperature = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("//D///wICBjACBngCNkgCP/0kv/+s1//nDn/8wICEBAIOC/08v//IYJECA==")) -}; - -var imgWind = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("/0f//8h///Pn//zAQXzwf/88B//mvGAh18gEevn/DIICB/PwgEBAQMHBAIADFwM/wEAGAP/54CD84CE+eP//wIQU/A==")) -}; - -var imgTimer = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("/+B/4CD84CEBAPygFP+F+h/x/+P+fz5/n+HnAQNn5/wuYCBmYCC5kAAQfOgFz80As/ngHn+fD54mC/F+j/+gF/HAQA==")) -}; - -var imgCharging = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("//+v///k///4AQPwBANgBoMxBoMb/P+h/w/kH8H4gfB+EBwfggHH4EAt4CBn4CBj4CBh4FCCIO/8EB//Agf/wEH/8Gh//x////fAQIA=")) -}; - -var imgWatch = { - width : 24, height : 24, bpp : 1, - transparent : 1, - buffer : require("heatshrink").decompress(atob("/8B//+ARANB/l4//5/1/+f/n/n5+fAQnf9/P44CC8/n7/n+YOB/+fDQQgCEwQsCHBBEC")) -}; - - -/* - * INFO ENTRIES - */ -var infoArray = [ - function(){ return [ null, null, "left" ] }, - function(){ return [ "Bangle", imgWatch, "right" ] }, - function(){ return [ E.getBattery() + "%", imgBattery, "left" ] }, - function(){ return [ getSteps(), imgSteps, "left" ] }, - function(){ return [ Math.round(Bangle.getHealthStatus("last").bpm) + " bpm", imgBpm, "left"] }, - function(){ return [ getWeather().temp, imgTemperature, "left" ] }, - function(){ return [ getWeather().wind, imgWind, "left" ] }, -]; -const NUM_INFO=infoArray.length; - - -function getInfoEntry(){ - if(isAlarmEnabled()){ - return [getAlarmMinutes() + " min.", imgTimer, "left"] - } else if(Bangle.isCharging()){ - return [E.getBattery() + "%", imgCharging, "left"] - } else{ - return infoArray[settings.showInfo](); - } -} - - -/* - * Helper - */ -function getSteps() { - var steps = 0; - try{ - if (WIDGETS.wpedom !== undefined) { - steps = WIDGETS.wpedom.getSteps(); - } else if (WIDGETS.activepedom !== undefined) { - steps = WIDGETS.activepedom.getSteps(); - } else { - steps = Bangle.getHealthStatus("day").steps; - } - } catch(ex) { - // In case we failed, we can only show 0 steps. - } - - steps = Math.round(steps/100) / 10; // This ensures that we do not show e.g. 15.0k and 15k instead - return steps + "k"; -} - - -function getWeather(){ - var weatherJson; - - try { - weatherJson = storage.readJSON('weather.json'); - var weather = weatherJson.weather; - - // Temperature - weather.temp = locale.temp(weather.temp-273.15); - - // Humidity - weather.hum = weather.hum + "%"; - - // Wind - const wind = locale.speed(weather.wind).match(/^(\D*\d*)(.*)$/); - weather.wind = Math.round(wind[1]) + " km/h"; - - return weather - - } catch(ex) { - // Return default - } - +function imgLock(){ return { - temp: "? °C", - hum: "-", - txt: "-", - wind: "? km/h", - wdir: "-", - wrose: "-" - }; + width : 16, height : 16, bpp : 1, + transparent : 0, + buffer : E.toArrayBuffer(atob("A8AH4A5wDDAYGBgYP/w//D/8Pnw+fD58Pnw//D/8P/w=")) + } } -function isAlarmEnabled(){ - try{ - var alarm = require('sched'); - var alarmObj = alarm.getAlarm(TIMER_IDX); - if(alarmObj===undefined || !alarmObj.on){ - return false; + +/************************************************ + * Menu + */ +// Custom bwItems menu - therefore, its added here and not in a clkinfo.js file. +var bwItems = { + name: null, + img: null, + items: [ + { name: "WeekOfYear", + get: () => ({ text: "Week " + weekOfYear(), img: null}), + show: function() {}, + hide: function () {} + }, + ] +}; + +function weekOfYear() { + var date = new Date(); + date.setHours(0, 0, 0, 0); + // Thursday in current week decides the year. + date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); + // January 4 is always in week 1. + var week1 = new Date(date.getFullYear(), 0, 4); + // Adjust to Thursday in week 1 and count number of weeks from date to week1. + return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 + - 3 + (week1.getDay() + 6) % 7) / 7); +} + + +// Load menu +var menu = clock_info.load(); +menu = menu.concat(bwItems); + + +// Ensure that our settings are still in range (e.g. app uninstall). Otherwise reset the position it. +if(settings.menuPosX >= menu.length || settings.menuPosY > menu[settings.menuPosX].items.length ){ + settings.menuPosX = 0; + settings.menuPosY = 0; +} + +// Set draw functions for each item +menu.forEach((menuItm, x) => { + menuItm.items.forEach((item, y) => { + function drawItem() { + // For the clock, we have a special case, as we don't wanna redraw + // immediately when something changes. Instead, we update data each minute + // to save some battery etc. Therefore, we hide (and disable the listener) + // immedeately after redraw... + item.hide(); + + // After drawing the item, we enable inputs again... + lock_input = false; + + var info = item.get(); + drawMenuItem(info.text, info.img); } - return true; + item.on('redraw', drawItem); + }) +}); - } catch(ex){ } - return false; -} -function getAlarmMinutes(){ - if(!isAlarmEnabled()){ - return -1; +function canRunMenuItem(){ + if(settings.menuPosY == 0){ + return false; } - var alarm = require('sched'); - var alarmObj = alarm.getAlarm(TIMER_IDX); - return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000)); + var menuEntry = menu[settings.menuPosX]; + var item = menuEntry.items[settings.menuPosY-1]; + return item.run !== undefined; } -function increaseAlarm(){ + +function runMenuItem(){ + if(settings.menuPosY == 0){ + return; + } + + var menuEntry = menu[settings.menuPosX]; + var item = menuEntry.items[settings.menuPosY-1]; try{ - var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0; - var alarm = require('sched') - alarm.setAlarm(TIMER_IDX, { - timer : (minutes+5)*60*1000, - }); - alarm.reload(); - } catch(ex){ } -} - -function decreaseAlarm(){ - try{ - var minutes = getAlarmMinutes(); - minutes -= 5; - - var alarm = require('sched') - alarm.setAlarm(TIMER_IDX, undefined); - - if(minutes > 0){ - alarm.setAlarm(TIMER_IDX, { - timer : minutes*60*1000, - }); + var ret = item.run(); + if(ret){ + Bangle.buzz(300, 0.6); } - - alarm.reload(); - } catch(ex){ } + } catch (ex) { + // Simply ignore it... + } } -/* - * DRAW functions +/************************************************ + * Draw */ - function draw() { // Queue draw again queueDraw(); // Draw clock drawDate(); - drawTime(); + drawMenuAndTime(); drawLock(); drawWidgets(); } @@ -274,12 +191,12 @@ function draw() { function drawDate(){ // Draw background - var y = H/5*2; - g.reset().clearRect(0,0,W,W); + var y = H/5*2 + (isFullscreen() ? 0 : 8); + g.reset().clearRect(0,0,W,y); // Draw date - y = parseInt(y/2); - y += settings.fullscreen ? 2 : 15; + y = parseInt(y/2)+4; + y += isFullscreen() ? 0 : 8; var date = new Date(); var dateStr = date.getDate(); dateStr = ("0" + dateStr).substr(-2); @@ -293,21 +210,17 @@ function drawDate(){ var fullDateW = dateW + 10 + dayW; g.setFontAlign(-1,0); - g.setMediumFont(); - g.setColor(g.theme.fg); - g.drawString(dateStr, W/2 - fullDateW / 2, y+1); - - g.setSmallFont(); g.drawString(dayStr, W/2 - fullDateW/2 + 10 + dateW, y-12); g.drawString(monthStr, W/2 - fullDateW/2 + 10 + dateW, y+11); + + g.setMediumFont(); + g.setColor(g.theme.fg); + g.drawString(dateStr, W/2 - fullDateW / 2, y+2); } -function drawTime(){ +function drawTime(y, smallText){ // Draw background - var y = H/5*2 + (settings.fullscreen ? 0 : 8); - g.setColor(g.theme.fg); - g.fillRect(0,y,W,H); var date = new Date(); // Draw time @@ -323,56 +236,78 @@ function drawTime(){ // Set y coordinates correctly y += parseInt((H - y)/2) + 5; - var infoEntry = getInfoEntry(); - var infoStr = infoEntry[0]; - var infoImg = infoEntry[1]; - var printImgLeft = infoEntry[2] == "left"; - // Show large or small time depending on info entry - if(infoStr == null){ - if(settings.hideColon){ - g.setXLargeFont(); - } else { - g.setLargeFont(); - } - } else { + if(smallText){ y -= 15; g.setMediumFont(); + } else { + g.setLargeFont(); } g.drawString(timeStr, W/2, y); +} - // Draw info if set - if(infoStr == null){ +function drawMenuItem(text, image){ + // First clear the time region + var y = H/5*2 + (isFullscreen() ? 0 : 8); + + g.setColor(g.theme.fg); + g.fillRect(0,y,W,H); + + // Draw menu text + var hasText = (text != null && text != ""); + if(hasText){ + g.setFontAlign(0,0); + + // For multiline text we show an even smaller font... + text = String(text); + if(text.split('\n').length > 1){ + g.setMiniFont(); + } else { + g.setSmallFont(); + } + + var imgWidth = image == null ? 0 : 24; + var strWidth = g.stringWidth(text); + g.setColor(g.theme.fg).fillRect(0, 149-14, W, H); + g.setColor(g.theme.bg).drawString(text, W/2 + imgWidth/2 + 2, 149+3); + + if(image != null){ + var scale = imgWidth / image.width; + g.drawImage(image, W/2 + -strWidth/2-4 - parseInt(imgWidth/2), 149 - parseInt(imgWidth/2), {scale: scale}); + } + } + + // Draw time + drawTime(y, hasText); +} + + +function drawMenuAndTime(){ + var menuEntry = menu[settings.menuPosX]; + + // The first entry is the overview... + if(settings.menuPosY == 0){ + drawMenuItem(menuEntry.name, menuEntry.img); return; } - y += 35; - g.setFontAlign(0,0); - g.setSmallFont(); - var imgWidth = 0; - if(infoImg !== undefined){ - imgWidth = infoImg.width; - var strWidth = g.stringWidth(infoStr); - g.drawImage( - infoImg, - W/2 + (printImgLeft ? -strWidth/2-2 : strWidth/2+2) - infoImg.width/2, - y - infoImg.height/2 - ); - } - g.drawString(infoStr, printImgLeft ? W/2 + imgWidth/2 + 2 : W/2 - imgWidth/2 - 2, y+3); + // Draw item if needed + lock_input = true; + var item = menuEntry.items[settings.menuPosY-1]; + item.show(); } function drawLock(){ if(settings.showLock && Bangle.isLocked()){ g.setColor(g.theme.fg); - g.drawImage(imgLock, W-16, 2); + g.drawImage(imgLock(), W-16, 2); } } function drawWidgets(){ - if(settings.fullscreen){ + if(isFullscreen()){ for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} } else { Bangle.drawWidgets(); @@ -380,9 +315,19 @@ function drawWidgets(){ } +function isFullscreen(){ + var s = settings.screen.toLowerCase(); + if(s == "dynamic"){ + return Bangle.isLocked() + } else { + return s == "full" + } +} -/* - * Draw timeout + + +/************************************************ + * Listener */ // timeout used to update every minute var drawTimeout; @@ -410,69 +355,112 @@ Bangle.on('lcdPower',on=>{ Bangle.on('lock', function(isLocked) { if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = undefined; + + if(!isLocked && settings.screen.toLowerCase() == "dynamic"){ + // If we have to show the widgets again, we load it from our + // cache and not through Bangle.loadWidgets as its much faster! + for (let wd of WIDGETS) {wd.draw=wd._draw;wd.area=wd._area;} + } + draw(); }); Bangle.on('charging',function(charging) { if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = undefined; + + // Jump to battery + settings.menuPosX = 0; + settings.menuPosY = 1; draw(); }); Bangle.on('touch', function(btn, e){ - var left = parseInt(g.getWidth() * 0.2); + var widget_size = isFullscreen() ? 0 : 20; // Its not exactly 24px -- empirically it seems that 20 worked better... + var left = parseInt(g.getWidth() * 0.22); var right = g.getWidth() - left; - var upper = parseInt(g.getHeight() * 0.2); + var upper = parseInt(g.getHeight() * 0.22) + widget_size; var lower = g.getHeight() - upper; - var is_left = e.x < left; - var is_right = e.x > right; var is_upper = e.y < upper; var is_lower = e.y > lower; + var is_left = e.x < left && !is_upper && !is_lower; + var is_right = e.x > right && !is_upper && !is_lower; + var is_center = !is_upper && !is_lower && !is_left && !is_right; - if(is_upper){ - Bangle.buzz(40, 0.6); - increaseAlarm(); - drawTime(); + if(lock_input){ + return; } if(is_lower){ Bangle.buzz(40, 0.6); - decreaseAlarm(); - drawTime(); + settings.menuPosY = (settings.menuPosY+1) % (menu[settings.menuPosX].items.length+1); + + drawMenuAndTime(); + } + + if(is_upper){ + if(e.y < widget_size){ + return; + } + + Bangle.buzz(40, 0.6); + settings.menuPosY = settings.menuPosY-1; + settings.menuPosY = settings.menuPosY < 0 ? menu[settings.menuPosX].items.length : settings.menuPosY; + + drawMenuAndTime(); } if(is_right){ Bangle.buzz(40, 0.6); - settings.showInfo = (settings.showInfo+1) % NUM_INFO; - drawTime(); + settings.menuPosX = (settings.menuPosX+1) % menu.length; + settings.menuPosY = 0; + drawMenuAndTime(); } if(is_left){ Bangle.buzz(40, 0.6); - settings.showInfo = settings.showInfo-1; - settings.showInfo = settings.showInfo < 0 ? NUM_INFO-1 : settings.showInfo; - drawTime(); + settings.menuPosY = 0; + settings.menuPosX = settings.menuPosX-1; + settings.menuPosX = settings.menuPosX < 0 ? menu.length-1 : settings.menuPosX; + drawMenuAndTime(); + } + + if(is_center){ + if(canRunMenuItem()){ + runMenuItem(); + } } }); E.on("kill", function(){ - storage.write(SETTINGS_FILE, settings); + try{ + storage.write(SETTINGS_FILE, settings); + } catch(ex){ + // If this fails, we still kill the app... + } }); -/* - * Draw clock the first time +/************************************************ + * Startup Clock */ + // The upper part is inverse i.e. light if dark and dark if light theme // is enabled. In order to draw the widgets correctly, we invert the // dark/light theme as well as the colors. g.setTheme({bg:g.theme.fg,fg:g.theme.bg, dark:!g.theme.dark}).clear(); -// Load widgets and draw clock the first time -Bangle.loadWidgets(); -draw(); - // Show launcher when middle button pressed Bangle.setUI("clock"); + +// Load widgets and draw clock the first time +Bangle.loadWidgets(); + +// Cache draw function for dynamic screen to hide / show widgets +// Bangle.loadWidgets() could also be called later on but its much slower! +for (let wd of WIDGETS) {wd._draw=wd.draw; wd._area=wd.area;} + +// Draw first time +draw(); diff --git a/apps/bwclk/metadata.json b/apps/bwclk/metadata.json index eba1449a6..8ef812f41 100644 --- a/apps/bwclk/metadata.json +++ b/apps/bwclk/metadata.json @@ -1,13 +1,13 @@ { "id": "bwclk", "name": "BW Clock", - "version": "0.09", - "description": "BW Clock.", + "version": "0.24", + "description": "A very minimalistic clock to mainly show date and time.", "readme": "README.md", "icon": "app.png", - "screenshots": [{"url":"screenshot.png"}, {"url":"screenshot_2.png"}, {"url":"screenshot_3.png"}], + "screenshots": [{"url":"screenshot.png"}, {"url":"screenshot_2.png"}, {"url":"screenshot_3.png"}, {"url":"screenshot_4.png"}], "type": "clock", - "tags": "clock", + "tags": "clock,clkinfo", "supports": ["BANGLEJS2"], "allow_emulator": true, "storage": [ diff --git a/apps/bwclk/screenshot.png b/apps/bwclk/screenshot.png index 550913422..3a75f13d1 100644 Binary files a/apps/bwclk/screenshot.png and b/apps/bwclk/screenshot.png differ diff --git a/apps/bwclk/screenshot_2.png b/apps/bwclk/screenshot_2.png index ccbc9aae1..31bf6373e 100644 Binary files a/apps/bwclk/screenshot_2.png and b/apps/bwclk/screenshot_2.png differ diff --git a/apps/bwclk/screenshot_3.png b/apps/bwclk/screenshot_3.png index 5bf7083f0..8d982cac4 100644 Binary files a/apps/bwclk/screenshot_3.png and b/apps/bwclk/screenshot_3.png differ diff --git a/apps/bwclk/screenshot_4.png b/apps/bwclk/screenshot_4.png new file mode 100644 index 000000000..83de5c2ce Binary files /dev/null and b/apps/bwclk/screenshot_4.png differ diff --git a/apps/bwclk/settings.js b/apps/bwclk/settings.js index a421e81a9..116253fda 100644 --- a/apps/bwclk/settings.js +++ b/apps/bwclk/settings.js @@ -4,7 +4,7 @@ // initialize with default settings... const storage = require('Storage') let settings = { - fullscreen: false, + screen: "Normal", showLock: true, hideColon: false, }; @@ -17,15 +17,16 @@ storage.write(SETTINGS_FILE, settings) } - + var screenOptions = ["Normal", "Dynamic", "Full"]; E.showMenu({ '': { 'title': 'BW Clock' }, '< Back': back, - 'Fullscreen': { - value: settings.fullscreen, - format: () => (settings.fullscreen ? 'Yes' : 'No'), - onchange: () => { - settings.fullscreen = !settings.fullscreen; + 'Screen': { + value: 0 | screenOptions.indexOf(settings.screen), + min: 0, max: 2, + format: v => screenOptions[v], + onchange: v => { + settings.screen = screenOptions[v]; save(); }, }, diff --git a/apps/calclock/ChangeLog b/apps/calclock/ChangeLog new file mode 100644 index 000000000..90bcfb9d4 --- /dev/null +++ b/apps/calclock/ChangeLog @@ -0,0 +1,6 @@ +0.01: Initial version +0.02: More compact rendering & app icon +0.03: Tell clock widgets to hide. +0.04: Improve current time readability in light theme. +0.05: Show calendar colors & improved all day events. +0.06: Improved multi-line locations & titles diff --git a/apps/calclock/README.md b/apps/calclock/README.md new file mode 100644 index 000000000..2b4e93a0c --- /dev/null +++ b/apps/calclock/README.md @@ -0,0 +1,9 @@ +# Calendar Clock - Your day at a glance + +This clock shows a chronological view of your current and future events. +It uses events synced from Gadgetbridge to achieve this. + +The current time and date is highlighted in cyan. + +## Screenshot +![](screenshot.png) diff --git a/apps/calclock/calclock-icon.js b/apps/calclock/calclock-icon.js new file mode 100644 index 000000000..9d5514d80 --- /dev/null +++ b/apps/calclock/calclock-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwgpm5gAB4AVRhgWCAAQWWDCARC/4ACJR4uB54WDAAP8DBotFGIgXLFwv4GAouQC4gwMLooXF/gXJOowXGJBIXBCIgXQxgXLMAIXXMAmIC5OIx4XJhH/wAXIxnIC78IxGIHoIABI44MBC4wQBEQIDB5gXGPAJgEC6IxBC5oABC4wwDa4YTCxAWD5nPDAzvGFYgAB5AXWJBK+GcAq5CGBIuBC5X4GBIJBdoQXB/GIx4CDPJAuEC5JoCDAgWBFwYXJxCBIFwYXKYwoACCwZ3IPQoWIC5YABGYIABCwpHKAQYMBCwwX/C5QAMC8R3/R/4XNhAXNwAXHgGIABgWIAFwA==")) diff --git a/apps/calclock/calclock.js b/apps/calclock/calclock.js new file mode 100644 index 000000000..1f98502ef --- /dev/null +++ b/apps/calclock/calclock.js @@ -0,0 +1,135 @@ +var calendar = []; +var current = []; +var next = []; + +function updateCalendar() { + calendar = require("Storage").readJSON("android.calendar.json",true)||[]; + calendar = calendar.filter(e => isActive(e) || getTime() <= e.timestamp); + calendar.sort((a,b) => a.timestamp - b.timestamp); + + current = calendar.filter(isActive); + next = calendar.filter(e=>!isActive(e)); +} + +function isActive(event) { + var timeActive = getTime() - event.timestamp; + return timeActive >= 0 && timeActive <= event.durationInSeconds; +} +function zp(str) { + return ("0"+str).substr(-2); +} + +function drawEventHeader(event, y) { + var x = 0; + var time = isActive(event) ? new Date() : new Date(event.timestamp * 1000); + + //Don't need to know what time the event is at if its all day + if (isActive(event) || !event.allDay) { + g.setFont("Vector", 24); + var timeStr = zp(time.getHours()) + ":" + zp(time.getMinutes()); + g.drawString(timeStr, 0, y); + y += 3; + x = 13*timeStr.length+5; + } + + g.setFont("12x20", 1); + + if (isActive(event)) { + g.drawString(zp(time.getDate())+". " + require("locale").month(time,1),x,y); + } else { + var offset = 0-time.getTimezoneOffset()/1440; + var days = Math.floor((time.getTime()/1000)/86400+offset)-Math.floor(getTime()/86400+offset); + if(days > 0 || event.allDay) { + var daysStr = days===1?/*LANG*/"tomorrow":/*LANG*/"in "+days+/*LANG*/" days"; + g.drawString(daysStr,x,y); + } + } + y += 21; + return y; +} + +function drawEventBody(event, y) { + g.setFont("12x20", 1); + var lines = g.wrapString(event.title, g.getWidth()-15); + var yStart = y; + if (lines.length > 2) { + lines = lines.slice(0,2); + lines[1] += "..."; + } + g.drawString(lines.join('\n'),10,y); + y+=20 * lines.length; + if(event.location) { + g.drawImage(atob("DBSBAA8D/H/nDuB+B+B+B3Dn/j/B+A8A8AYAYAYAAAAAAA=="),10,y); + var loclines = g.wrapString(event.location, g.getWidth()-30); + if(loclines.length>1) loclines[0] += "..."; + g.drawString(loclines[0],25,y); + y+=20; + } + if (event.color) { + var oldColor = g.getColor(); + g.setColor("#"+(0x1000000+Number(event.color)).toString(16).padStart(6,"0")); + g.fillRect(0,yStart,5,y-3); + g.setColor(oldColor); + } + y+=5; + return y; +} + +function drawEvent(event, y) { + y = drawEventHeader(event, y); + y = drawEventBody(event, y); + return y; +} + +var curEventHeight = 0; + +function drawCurrentEvents(y) { + g.setColor(g.theme.dark ? "#0ff" : "#00f"); + g.clearRect(0,y,g.getWidth()-5,y+curEventHeight); + curEventHeight = y; + + if(current.length === 0) { + y = drawEvent({timestamp: getTime(), durationInSeconds: 100}, y); + } else { + y = drawEventHeader(current[0],y); + for (var e of current) { + y = drawEventBody(e,y); + } + } + curEventHeight = y-curEventHeight; + return y; +} + +function drawFutureEvents(y) { + g.setColor(g.theme.fg); + for (var e of next) { + y = drawEvent(e, y); + if(y>g.getHeight())break; + } + return y; +} + +function fullRedraw() { + g.clearRect(0,24,g.getWidth()-5,g.getHeight()); + updateCalendar(); + var y = 30; + y = drawCurrentEvents(y); + drawFutureEvents(y); +} + +function redraw() { + g.reset(); + if (current.find(e=>!isActive(e)) || next.find(isActive)) { + fullRedraw(); + } else { + drawCurrentEvents(30); + } +} + +g.clear(); +fullRedraw(); +var minuteInterval = setInterval(redraw, 60 * 1000); + +Bangle.setUI("clock"); +Bangle.loadWidgets(); +Bangle.drawWidgets(); diff --git a/apps/calclock/calclock.png b/apps/calclock/calclock.png new file mode 100644 index 000000000..5f953c1ee Binary files /dev/null and b/apps/calclock/calclock.png differ diff --git a/apps/calclock/location.png b/apps/calclock/location.png new file mode 100644 index 000000000..619e55775 Binary files /dev/null and b/apps/calclock/location.png differ diff --git a/apps/calclock/metadata.json b/apps/calclock/metadata.json new file mode 100644 index 000000000..bfd847595 --- /dev/null +++ b/apps/calclock/metadata.json @@ -0,0 +1,17 @@ +{ + "id": "calclock", + "name": "Calendar Clock", + "shortName": "CalClock", + "version": "0.06", + "description": "Show the current and upcoming events synchronized from Gadgetbridge", + "icon": "calclock.png", + "type": "clock", + "tags": "clock agenda", + "supports": ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"calclock.app.js","url":"calclock.js"}, + {"name":"calclock.img","url":"calclock-icon.js","evaluate":true} + ], + "screenshots": [{"url":"screenshot.png"}] +} diff --git a/apps/calclock/screenshot.patch b/apps/calclock/screenshot.patch new file mode 100644 index 000000000..3fdbf79d1 --- /dev/null +++ b/apps/calclock/screenshot.patch @@ -0,0 +1,32 @@ +diff --git a/apps/calclock/calclock.js b/apps/calclock/calclock.js +index cb8c6100e..2092c1a4e 100644 +--- a/apps/calclock/calclock.js ++++ b/apps/calclock/calclock.js +@@ -3,9 +3,24 @@ var current = []; + var next = []; + + function updateCalendar() { +- calendar = require("Storage").readJSON("android.calendar.json",true)||[]; +- calendar = calendar.filter(e => isActive(e) || getTime() <= e.timestamp); +- calendar.sort((a,b) => a.timestamp - b.timestamp); ++ calendar = [ ++ { ++ t: "calendar", ++ id: 2, type: 0, timestamp: getTime(), durationInSeconds: 200, ++ title: "Capture Screenshot", ++ description: "Capture Screenshot", ++ location: "", ++ calName: "", ++ color: -7151168, allDay: true }, ++ { ++ t: "calendar", ++ id: 7186, type: 0, timestamp: getTime() + 2000, durationInSeconds: 100, ++ title: "Upload to BangleApps", ++ description: "", ++ location: "", ++ calName: "", ++ color: -509406, allDay: false } ++ ]; + + current = calendar.filter(isActive); + next = calendar.filter(e=>!isActive(e)); diff --git a/apps/calclock/screenshot.png b/apps/calclock/screenshot.png new file mode 100644 index 000000000..8b2e39784 Binary files /dev/null and b/apps/calclock/screenshot.png differ diff --git a/apps/calculator/ChangeLog b/apps/calculator/ChangeLog index a08a0f5a7..2e1ace7bf 100644 --- a/apps/calculator/ChangeLog +++ b/apps/calculator/ChangeLog @@ -3,3 +3,5 @@ 0.03: Support for different screen sizes and touchscreen 0.04: Display current operation on LHS 0.05: Grid positioning and swipe controls to switch between numbers, operators and special (for Bangle.js 2) +0.06: Bangle.js 2: Exit with a short press of the physical button +0.07: Bangle.js 2: Exit by pressing upper left corner of the screen diff --git a/apps/calculator/README.md b/apps/calculator/README.md index b25d355bf..62f6cef24 100644 --- a/apps/calculator/README.md +++ b/apps/calculator/README.md @@ -12,12 +12,20 @@ Basic calculator reminiscent of MacOs's one. Handy for small calculus. ## Controls +Bangle.js 1 - UP: BTN1 - DOWN: BTN3 - LEFT: BTN4 - RIGHT: BTN5 - SELECT: BTN2 +Bangle.js 2 +- Swipes to change visible buttons +- Click physical button to exit +- Press upper left corner of screen to exit (where the red back button would be) ## Creator + +## Contributors +[thyttan](https://github.com/thyttan) diff --git a/apps/calculator/app.js b/apps/calculator/app.js index 40953254e..d9a89a989 100644 --- a/apps/calculator/app.js +++ b/apps/calculator/app.js @@ -3,6 +3,8 @@ * * Original Author: Frederic Rousseau https://github.com/fredericrous * Created: April 2020 + * + * Contributors: thyttan https://github.com/thyttan */ g.clear(); @@ -402,43 +404,42 @@ if (process.env.HWVERSION==1) { swipeEnabled = false; drawGlobal(); } else { // touchscreen? - selected = "NONE"; + selected = "NONE"; swipeEnabled = true; prepareScreen(numbers, numbersGrid, COLORS.DEFAULT); prepareScreen(operators, operatorsGrid, COLORS.OPERATOR); prepareScreen(specials, specialsGrid, COLORS.SPECIAL); drawNumbers(); - Bangle.on('touch',(n,e)=>{ - for (var key in screen) { - if (typeof screen[key] == "undefined") break; - var r = screen[key].xy; - if (e.x>=r[0] && e.y>=r[1] && - e.x{ + for (var key in screen) { + if (typeof screen[key] == "undefined") break; + var r = screen[key].xy; + if (e.x>=r[0] && e.y>=r[1] && e.x { - if (!e.b) { - if (lastX > 50) { // right + }, + swipe : (LR, UD) => { + if (LR == 1) { // right drawSpecials(); - } else if (lastX < -50) { // left + } + if (LR == -1) { // left drawOperators(); - } else if (lastY > 50) { // down - drawNumbers(); - } else if (lastY < -50) { // up + } + if (UD == 1) { // down + drawNumbers(); + } + if (UD == -1) { // up drawNumbers(); } - lastX = 0; - lastY = 0; - } else { - lastX = lastX + e.dx; - lastY = lastY + e.dy; } }); + } - displayOutput(0); diff --git a/apps/calculator/metadata.json b/apps/calculator/metadata.json index e78e4d54f..1674b7843 100644 --- a/apps/calculator/metadata.json +++ b/apps/calculator/metadata.json @@ -2,7 +2,7 @@ "id": "calculator", "name": "Calculator", "shortName": "Calculator", - "version": "0.05", + "version": "0.07", "description": "Basic calculator reminiscent of MacOs's one. Handy for small calculus.", "icon": "calculator.png", "screenshots": [{"url":"screenshot_calculator.png"}], diff --git a/apps/calendar/ChangeLog b/apps/calendar/ChangeLog index 0583ea45f..db455679c 100644 --- a/apps/calendar/ChangeLog +++ b/apps/calendar/ChangeLog @@ -9,3 +9,4 @@ read start of week from system settings 0.09: Fix scope of let variables 0.10: Use default Bangle formatter for booleans +0.11: Fix off-by-one-error on next year diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index f4676fc22..f8785e52c 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -226,15 +226,14 @@ drawCalendar(date); clearWatch(); Bangle.on("touch", area => { const month = date.getMonth(); - let prevMonth; if (area == 1) { let prevMonth = month > 0 ? month - 1 : 11; if (prevMonth === 11) date.setFullYear(date.getFullYear() - 1); date.setMonth(prevMonth); } else { - let prevMonth = month < 11 ? month + 1 : 0; - if (prevMonth === 0) date.setFullYear(date.getFullYear() + 1); - date.setMonth(month + 1); + let nextMonth = month < 11 ? month + 1 : 0; + if (nextMonth === 0) date.setFullYear(date.getFullYear() + 1); + date.setMonth(nextMonth); } drawCalendar(date); }); diff --git a/apps/calendar/metadata.json b/apps/calendar/metadata.json index 48fd52d3e..88f20026d 100644 --- a/apps/calendar/metadata.json +++ b/apps/calendar/metadata.json @@ -1,7 +1,7 @@ { "id": "calendar", "name": "Calendar", - "version": "0.10", + "version": "0.11", "description": "Simple calendar", "icon": "calendar.png", "screenshots": [{"url":"screenshot_calendar.png"}], diff --git a/apps/calibration/metadata.json b/apps/calibration/metadata.json index b60650300..f428bd538 100644 --- a/apps/calibration/metadata.json +++ b/apps/calibration/metadata.json @@ -3,7 +3,7 @@ "shortName":"Calibration", "icon": "calibration.png", "version":"0.03", - "description": "A simple calibration app for the touchscreen", + "description": "(NOT RECOMMENDED) A simple calibration app for the touchscreen. Please use the Touchscreen Calibration in the Settings app instead.", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "tags": "tool", diff --git a/apps/cassioWatch/ChangeLog b/apps/cassioWatch/ChangeLog index 419810021..1180554ff 100644 --- a/apps/cassioWatch/ChangeLog +++ b/apps/cassioWatch/ChangeLog @@ -8,4 +8,6 @@ 0.7: Update Rocket Sequences Scope to not use memory all time 0.8: Update Some Variable Scopes to not use memory until need 0.9: Remove ESLint spaces -0.10: Show daily steps, heartrate and the temperature if weather information is available. \ No newline at end of file +0.10: Show daily steps, heartrate and the temperature if weather information is available. +0.11: Tell clock widgets to hide. +0.12: Swipe down to see widgets, step counter now just uses getHealthStatus diff --git a/apps/cassioWatch/README.md b/apps/cassioWatch/README.md index aaeb3f122..6c13cdcac 100644 --- a/apps/cassioWatch/README.md +++ b/apps/cassioWatch/README.md @@ -8,4 +8,5 @@ It displays current temperature,day,steps,battery.heartbeat and weather. **To-do**: -Align and change size of some elements. + +* Align and change size of some elements diff --git a/apps/cassioWatch/app.js b/apps/cassioWatch/app.js index 6bbb9e823..19dd883d2 100644 --- a/apps/cassioWatch/app.js +++ b/apps/cassioWatch/app.js @@ -91,7 +91,6 @@ function getTemperature(){ var weatherJson = storage.readJSON('weather.json'); var weather = weatherJson.weather; return Math.round(weather.temp-273.15); - } catch(ex) { print(ex) return "?" @@ -99,20 +98,7 @@ function getTemperature(){ } function getSteps() { - var steps = 0; - try{ - if (WIDGETS.wpedom !== undefined) { - steps = WIDGETS.wpedom.getSteps(); - } else if (WIDGETS.activepedom !== undefined) { - steps = WIDGETS.activepedom.getSteps(); - } else { - steps = Bangle.getHealthStatus("day").steps; - } - } catch(ex) { - // In case we failed, we can only show 0 steps. - return "? k"; - } - + var steps = Bangle.getHealthStatus("day").steps; steps = Math.round(steps/1000); return steps + "k"; } @@ -121,8 +107,7 @@ function getSteps() { function draw() { queueDraw(); - g.reset(); - g.clear(); + g.clear(1); g.setColor(0, 255, 255); g.fillRect(0, 0, g.getWidth(), g.getHeight()); let background = getBackgroundImage(); @@ -143,9 +128,6 @@ function draw() { drawClock(); drawRocket(); drawBattery(); - - // Hide widgets - for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} } Bangle.on("lcdPower", (on) => { @@ -165,11 +147,10 @@ Bangle.on("lock", (locked) => { } }); +Bangle.setUI("clock"); // Load widgets, but don't show them Bangle.loadWidgets(); -Bangle.setUI("clock"); - -g.reset(); -g.clear(); -draw(); \ No newline at end of file +require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe +g.clear(1); +draw(); diff --git a/apps/cassioWatch/metadata.json b/apps/cassioWatch/metadata.json index dabdc2c93..5ac4502fd 100644 --- a/apps/cassioWatch/metadata.json +++ b/apps/cassioWatch/metadata.json @@ -4,7 +4,7 @@ "description": "Animated Clock with Space Cassio Watch Style", "screenshots": [{ "url": "screens/screen_night.png" },{ "url": "screens/screen_day.png" }], "icon": "app.png", - "version": "0.10", + "version": "0.12", "type": "clock", "tags": "clock, weather, cassio, retro", "supports": ["BANGLEJS2"], diff --git a/apps/chimer/ChangeLog b/apps/chimer/ChangeLog new file mode 100644 index 000000000..01bd00a0a --- /dev/null +++ b/apps/chimer/ChangeLog @@ -0,0 +1,2 @@ +0.01: Initial Creation +0.02: Fixed some sleep bugs. Added a sleep mode toggle \ No newline at end of file diff --git a/apps/chimer/README.MD b/apps/chimer/README.MD new file mode 100644 index 000000000..a78c677f2 --- /dev/null +++ b/apps/chimer/README.MD @@ -0,0 +1,11 @@ +# Chimer - For the BangleJS + +A fork of [Hour Chime](https://github.com/espruino/BangleApps/tree/master/apps/widchime) that adds extra features such as: + +- Buzz or beep on every 60, 30 or 15 minutes. +- Repeat Chime up to 3 times +- Set hours to disable chime + +Setting the hours you don't want your watch to chime for is done by setting the hour you want it to stop, and the hour you want it to start. + +Hours range from 0 - 23. diff --git a/apps/chimer/icon.txt b/apps/chimer/icon.txt new file mode 100644 index 000000000..cc969bc81 --- /dev/null +++ b/apps/chimer/icon.txt @@ -0,0 +1,2 @@ + +widget.png: "https://icons8.com/icon/114436/alarm" \ No newline at end of file diff --git a/apps/chimer/metadata.json b/apps/chimer/metadata.json new file mode 100644 index 000000000..d5bc04950 --- /dev/null +++ b/apps/chimer/metadata.json @@ -0,0 +1,16 @@ +{ + "id": "chimer", + "name": "Chimer", + "version": "0.02", + "description": "A fork of Hour Chime that adds extra features such as: \n - Buzz or beep on every 60, 30 or 15 minutes. \n - Reapeat Chime up to 3 times \n - Set hours to disable chime", + "icon": "widget.png", + "type": "widget", + "tags": "widget", + "supports": ["BANGLEJS", "BANGLEJS2"], + "readme": "README.MD", + "storage": [ + { "name": "chimer.wid.js", "url": "widget.js" }, + { "name": "chimer.settings.js", "url": "settings.js" } + ], + "data": [{ "name": "chimer.json" }] +} diff --git a/apps/chimer/settings.js b/apps/chimer/settings.js new file mode 100644 index 000000000..55160c9be --- /dev/null +++ b/apps/chimer/settings.js @@ -0,0 +1,94 @@ +/** + * @param {function} back Use back() to return to settings menu + */ + +(function (back) { + // default to buzzing + var FILE = "chimer.json"; + var settings = {}; + const chimes = ["Off", "Buzz", "Beep", "Both"]; + const frequency = ["60 min", "30 min", "15 min", "1 min"]; + + var showMainMenu = () => { + E.showMenu({ + "": { title: "Chimer" }, + "< Back": () => back(), + "Chime Type": { + value: settings.type, + min: 0, + max: 2, // both is just silly + format: (v) => chimes[v], + onchange: (v) => { + settings.type = v; + writeSettings(settings); + }, + }, + Frequency: { + value: settings.freq, + min: 0, + max: 2, + format: (v) => frequency[v], + onchange: (v) => { + settings.freq = v; + writeSettings(settings); + }, + }, + Repetition: { + value: settings.repeat, + min: 1, + max: 5, + format: (v) => v, + onchange: (v) => { + settings.repeat = v; + writeSettings(settings); + }, + }, + "Sleep Mode": { + value: !!settings.sleep, + onchange: (v) => { + settings.sleep = v; + writeSettings(settings); + }, + }, + "Sleep Start": { + value: settings.start, + min: 0, + max: 23, + format: (v) => v, + onchange: (v) => { + settings.start = v; + writeSettings(settings); + }, + }, + "Sleep End": { + value: settings.end, + min: 0, + max: 23, + format: (v) => v, + onchange: (v) => { + settings.end = v; + writeSettings(settings); + }, + }, + }); + }; + + var readSettings = () => { + var settings = require("Storage").readJSON(FILE, 1) || { + type: 1, + freq: 0, + repeat: 1, + sleep: true, + start: 6, + end: 22, + }; + return settings; + }; + + var writeSettings = (settings) => { + require("Storage").writeJSON(FILE, settings); + }; + + settings = readSettings(); + showMainMenu(); +}); diff --git a/apps/chimer/widget.js b/apps/chimer/widget.js new file mode 100644 index 000000000..18358df9e --- /dev/null +++ b/apps/chimer/widget.js @@ -0,0 +1,134 @@ +(function () { + // 0: off, 1: buzz, 2: beep, 3: both + var FILE = "chimer.json"; + + var readSettings = () => { + var settings = require("Storage").readJSON(FILE, 1) || { + type: 1, + freq: 0, + repeat: 1, + sleep: true, + start: 6, + end: 22, + }; + return settings; + }; + + var settings = readSettings(); + + function sleep(milliseconds) { + const date = Date.now(); + let currentDate = null; + do { + currentDate = Date.now(); + } while (currentDate - date < milliseconds); + } + + function chime() { + for (var i = 0; i < settings.repeat; i++) { + if (settings.type === 1) { + Bangle.buzz(100); + } else if (settings.type === 2) { + Bangle.beep(); + } else { + return; + } + sleep(150); + } + } + + let lastHour = new Date().getHours(); + let lastMinute = new Date().getMinutes(); // don't chime when (re)loaded at a whole hour + function check() { + const now = new Date(), + h = now.getHours(), + m = now.getMinutes(), + s = now.getSeconds(), + ms = now.getMilliseconds(); + if ( + (settings.sleep && h > settings.end) || + (settings.sleep && h >= settings.end && m !== 0) || + (settings.sleep && h < settings.start) + ) { + var mLeft = 60 - m, + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + setTimeout(check, msLeft); + return; + } + if (settings.freq === 1) { + if ((m !== lastMinute && m === 0) || (m !== lastMinute && m === 30)) + chime(); + lastHour = h; + lastMinute = m; + // check again in 30 minutes + switch (true) { + case m / 30 >= 1: + var mLeft = 30 - (m - 30), + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + break; + case m / 30 < 1: + var mLeft = 30 - m, + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + break; + } + setTimeout(check, msLeft); + } else if (settings.freq === 2) { + if ( + (m !== lastMinute && m === 0) || + (m !== lastMinute && m === 15) || + (m !== lastMinute && m === 30) || + (m !== lastMinute && m === 45) + ) + chime(); + lastHour = h; + lastMinute = m; + // check again in 15 minutes + switch (true) { + case m / 15 >= 3: + var mLeft = 15 - (m - 45), + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + break; + case m / 15 >= 2: + var mLeft = 15 - (m - 30), + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + break; + case m / 15 >= 1: + var mLeft = 15 - (m - 15), + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + break; + case m / 15 < 1: + var mLeft = 15 - m, + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + break; + } + setTimeout(check, msLeft); + } else if (settings.freq === 3) { + if (m !== lastMinute) chime(); + lastHour = h; + lastMinute = m; + // check again in 1 minute + + var mLeft = 1, + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + setTimeout(check, msLeft); + } else { + if (h !== lastHour && m === 0) chime(); + lastHour = h; + // check again in 60 minutes + var mLeft = 60 - m, + sLeft = mLeft * 60 - s, + msLeft = sLeft * 1000 - ms; + setTimeout(check, msLeft); + } + } + + check(); +})(); diff --git a/apps/chimer/widget.png b/apps/chimer/widget.png new file mode 100644 index 000000000..14edf4150 Binary files /dev/null and b/apps/chimer/widget.png differ diff --git a/apps/choozi/ChangeLog b/apps/choozi/ChangeLog index 03f7ef832..35adc7430 100644 --- a/apps/choozi/ChangeLog +++ b/apps/choozi/ChangeLog @@ -1,3 +1,9 @@ 0.01: New App! 0.02: Support Bangle.js 2 0.03: Fix bug for Bangle.js 2 where g.flip was not being called. +0.04: Combine code for both apps + Better colors for Bangle.js 2 + Fix selection animation for Bangle.js 2 + New icon + Slightly wider arc segments for better visibility + Extract arc drawing code in library diff --git a/apps/choozi/README.md b/apps/choozi/README.md index f1e4255bc..ccaa97a27 100644 --- a/apps/choozi/README.md +++ b/apps/choozi/README.md @@ -11,16 +11,21 @@ the players seated in a circle, set the number of segments equal to the number of players, ensure that each person knows which colour represents them, and then choose a segment. After a short animation, the chosen segment will fill the screen. -You can use Choozi to randomly select an element from any set with 2 to 13 members, +You can use Choozi to randomly select an element from any set with 2 to 15 members, as long as you can define a bijection between members of the set and coloured segments on the Bangle.js display. -## Controls +## Controls Bangle 1 BTN1: increase the number of segments BTN2: choose a segment at random BTN3: decrease the number of segments +## Controls Bangle 2 + +Swipe up/down: increase/decrease the number of segments +BTN1 or tap: choose a segment at random + ## Creator James Stanley diff --git a/apps/choozi/app-icon.js b/apps/choozi/app-icon.js index 51b3bead3..560286098 100644 --- a/apps/choozi/app-icon.js +++ b/apps/choozi/app-icon.js @@ -1 +1 @@ -require("heatshrink").decompress(atob("mEwggLIrnM4uqAAIhPgvMAAPFzIABzWgCxkMCweqC4QABDBYtC5QVFDBoWCCo5KLOQIWKDARFICxhJIFwOpC5owFFyAwGUYIuOGAwuRC4guSJAgXBCyIwDIyQXF5IXSzJeVMAReUAAOQhheTMAVcC6yOUC4aOUC7GZUyoXXzWqhQXVxGqC9mYC7OqC9eoxEKC6uBC6uIwAXBPCSmBwEAC6Z2BiAXBJCR2BgEAjQXSlGBC4JgSLwYABJCJGBLwJIDGB+IIwRIDGByNBIwZIDGBhdBRoQwSLoIuFGAYYKCwIuGGAgYI1QWBRgYYJMYmaFoSMEAAyrBAAgVCCxgYGjAWQAAMBC4UILZQA==")) +require("heatshrink").decompress(atob("mEwwcH/4AW/u27dt2wQL/YOBCIXbv4QI+AODAQVsh4RHwEbCI0LCI9gCIOANAXbsFbG437tkDPg1btoRFFoILBgmSpMggECHQO/CAf2CIVJkgRBAQIjC24RFsECCItIgIRFMYMAiQRFpMAlqmDVwPYgAOEAQUggu274RD4BWCCIskCIPbCIPt20ABwwCCwARFgIRJyEWCIVt2EJCJi2BCJmSUgIRCwARNt/7CIIOICI1sWAwCFoFbCOtt8EACJsAgARR8hwBCJlJk4RlgARQAgIRKDwMn/gRBdJgRPyARBn4RBpARLiQRB/4RBgIRJwAREpIRLAYP///ypMgCJMACI0ECI4JCp4RB/wZECIsAAYN/CIP/5JPDCIhjDCIraHTIWTCAX//K7DCI+fCIf/EZA1CCAn//ipCLIsBk4RF/5ZHCIIQG//wPo8vCI//6QRFpYQIAAPpCIeXCBQAC/VfBI4=")) \ No newline at end of file diff --git a/apps/choozi/app.js b/apps/choozi/app.js index 1a5b2f17e..b9f53bc89 100644 --- a/apps/choozi/app.js +++ b/apps/choozi/app.js @@ -4,15 +4,16 @@ * * James Stanley 2021 */ - -var colours = ['#ff0000', '#ff8080', '#00ff00', '#80ff80', '#0000ff', '#8080ff', '#ffff00', '#00ffff', '#ff00ff', '#ff8000', '#ff0080', '#8000ff', '#0080ff']; +const GU = require("graphics_utils"); +var colours = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#00ffff', '#ff00ff', '#ffffff']; +var colours2 = ['#808080', '#404040', '#000040', '#004000', '#400000', '#ff8000', '#804000', '#4000c0']; var stepAngle = 0.18; // radians - resolution of polygon var gapAngle = 0.035; // radians - gap between segments -var perimMin = 110; // px - min. radius of perimeter -var perimMax = 120; // px - max. radius of perimeter +var perimMin = g.getWidth()*0.40; // px - min. radius of perimeter +var perimMax = g.getWidth()*0.49; // px - max. radius of perimeter -var segmentMax = 106; // px - max radius of filled-in segment +var segmentMax = g.getWidth()*0.38; // px - max radius of filled-in segment var segmentStep = 5; // px - step size of segment fill animation var circleStep = 4; // px - step size of circle fill animation @@ -22,10 +23,10 @@ var minSpeed = 0.001; // rad/sec var animStartSteps = 300; // how many steps before it can start slowing? var accel = 0.0002; // rad/sec/sec - acc-/deceleration rate var ballSize = 3; // px - ball radius -var ballTrack = 100; // px - radius of ball path +var ballTrack = perimMin - ballSize*2; // px - radius of ball path -var centreX = 120; // px - centre of screen -var centreY = 120; // px - centre of screen +var centreX = g.getWidth()*0.5; // px - centre of screen +var centreY = g.getWidth()*0.5; // px - centre of screen var fontSize = 50; // px @@ -33,7 +34,6 @@ var radians = 2*Math.PI; // radians per circle var defaultN = 3; // default value for N var minN = 2; -var maxN = colours.length; var N; var arclen; @@ -51,42 +51,14 @@ function shuffle (array) { } } -// draw an arc between radii minR and maxR, and between -// angles minAngle and maxAngle -function arc(minR, maxR, minAngle, maxAngle) { - var step = stepAngle; - var angle = minAngle; - var inside = []; - var outside = []; - var c, s; - while (angle < maxAngle) { - c = Math.cos(angle); - s = Math.sin(angle); - inside.push(centreX+c*minR); // x - inside.push(centreY+s*minR); // y - // outside coordinates are built up in reverse order - outside.unshift(centreY+s*maxR); // y - outside.unshift(centreX+c*maxR); // x - angle += step; - } - c = Math.cos(maxAngle); - s = Math.sin(maxAngle); - inside.push(centreX+c*minR); - inside.push(centreY+s*minR); - outside.unshift(centreY+s*maxR); - outside.unshift(centreX+c*maxR); - - var vertices = inside.concat(outside); - g.fillPoly(vertices, true); -} - // draw the arc segments around the perimeter function drawPerimeter() { + g.setBgColor('#000000'); g.clear(); for (var i = 0; i < N; i++) { g.setColor(colours[i%colours.length]); var minAngle = (i/N)*radians; - arc(perimMin,perimMax,minAngle,minAngle+arclen); + GU.fillArc(g, centreX, centreY, perimMin,perimMax,minAngle,minAngle+arclen, stepAngle); } } @@ -131,6 +103,7 @@ function animateChoice(target) { g.fillCircle(x, y, ballSize); oldx=x; oldy=y; + if (process.env.HWVERSION == 2) g.flip(); } } @@ -141,11 +114,15 @@ function choose() { var maxAngle = minAngle + arclen; animateChoice((minAngle+maxAngle)/2); g.setColor(colours[chosen%colours.length]); - for (var i = segmentMax-segmentStep; i >= 0; i -= segmentStep) - arc(i, perimMax, minAngle, maxAngle); - arc(0, perimMax, minAngle, maxAngle); - for (var r = 1; r < segmentMax; r += circleStep) + for (var i = segmentMax-segmentStep; i >= 0; i -= segmentStep){ + GU.fillArc(g, centreX, centreY, i, perimMax, minAngle, maxAngle, stepAngle); + if (process.env.HWVERSION == 2) g.flip(); + } + GU.fillArc(g, centreX, centreY, 0, perimMax, minAngle, maxAngle, stepAngle); + for (var r = 1; r < segmentMax; r += circleStep){ g.fillCircle(centreX,centreY,r); + if (process.env.HWVERSION == 2) g.flip(); + } g.fillCircle(centreX,centreY,segmentMax); } @@ -171,38 +148,47 @@ function setN(n) { drawPerimeter(); } -// save N to choozi.txt +// save N to choozi.save function writeN() { - var file = require("Storage").open("choozi.txt","w"); - file.write(N); + var savedN = read(); + if (savedN != N) require("Storage").write("choozi.save","" + N); } -// load N from choozi.txt +function read(){ + var n = require("Storage").read("choozi.save"); + if (n !== undefined) return parseInt(n); + return defaultN; +} + +// load N from choozi.save function readN() { - var file = require("Storage").open("choozi.txt","r"); - var n = file.readLine(); - if (n !== undefined) setN(parseInt(n)); - else setN(defaultN); + setN(read()); } -shuffle(colours); // is this really best? -Bangle.setLCDMode("direct"); -Bangle.setLCDTimeout(0); // keep screen on +if (process.env.HWVERSION == 1){ + colours=colours.concat(colours2); + shuffle(colours); +} else { + shuffle(colours); + shuffle(colours2); + colours=colours.concat(colours2); +} + +var maxN = colours.length; +if (process.env.HWVERSION == 1){ + Bangle.setLCDMode("direct"); + Bangle.setLCDTimeout(0); // keep screen on +} readN(); drawN(); -setWatch(() => { - setN(N+1); - drawN(); -}, BTN1, {repeat:true}); - -setWatch(() => { - writeN(); - drawPerimeter(); - choose(); -}, BTN2, {repeat:true}); - -setWatch(() => { - setN(N-1); - drawN(); -}, BTN3, {repeat:true}); +Bangle.setUI("updown", (v)=>{ + if (!v){ + writeN(); + drawPerimeter(); + choose(); + } else { + setN(N-v); + drawN(); + } +}); diff --git a/apps/choozi/app.png b/apps/choozi/app.png index 99c9fa07a..50f09f164 100644 Binary files a/apps/choozi/app.png and b/apps/choozi/app.png differ diff --git a/apps/choozi/appb2.js b/apps/choozi/appb2.js deleted file mode 100644 index 5f217f638..000000000 --- a/apps/choozi/appb2.js +++ /dev/null @@ -1,207 +0,0 @@ -/* Choozi - Choose people or things at random using Bangle.js. - * Inspired by the "Chwazi" Android app - * - * James Stanley 2021 - */ - -var colours = ['#ff0000', '#ff8080', '#00ff00', '#80ff80', '#0000ff', '#8080ff', '#ffff00', '#00ffff', '#ff00ff', '#ff8000', '#ff0080', '#8000ff', '#0080ff']; - -var stepAngle = 0.18; // radians - resolution of polygon -var gapAngle = 0.035; // radians - gap between segments -var perimMin = 80; // px - min. radius of perimeter -var perimMax = 87; // px - max. radius of perimeter - -var segmentMax = 70; // px - max radius of filled-in segment -var segmentStep = 5; // px - step size of segment fill animation -var circleStep = 4; // px - step size of circle fill animation - -// rolling ball animation: -var maxSpeed = 0.08; // rad/sec -var minSpeed = 0.001; // rad/sec -var animStartSteps = 300; // how many steps before it can start slowing? -var accel = 0.0002; // rad/sec/sec - acc-/deceleration rate -var ballSize = 3; // px - ball radius -var ballTrack = 75; // px - radius of ball path - -var centreX = 88; // px - centre of screen -var centreY = 88; // px - centre of screen - -var fontSize = 50; // px - -var radians = 2*Math.PI; // radians per circle - -var defaultN = 3; // default value for N -var minN = 2; -var maxN = colours.length; -var N; -var arclen; - -// https://www.frankmitchell.org/2015/01/fisher-yates/ -function shuffle (array) { - var i = 0 - , j = 0 - , temp = null; - - for (i = array.length - 1; i > 0; i -= 1) { - j = Math.floor(Math.random() * (i + 1)); - temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } -} - -// draw an arc between radii minR and maxR, and between -// angles minAngle and maxAngle -function arc(minR, maxR, minAngle, maxAngle) { - var step = stepAngle; - var angle = minAngle; - var inside = []; - var outside = []; - var c, s; - while (angle < maxAngle) { - c = Math.cos(angle); - s = Math.sin(angle); - inside.push(centreX+c*minR); // x - inside.push(centreY+s*minR); // y - // outside coordinates are built up in reverse order - outside.unshift(centreY+s*maxR); // y - outside.unshift(centreX+c*maxR); // x - angle += step; - } - c = Math.cos(maxAngle); - s = Math.sin(maxAngle); - inside.push(centreX+c*minR); - inside.push(centreY+s*minR); - outside.unshift(centreY+s*maxR); - outside.unshift(centreX+c*maxR); - - var vertices = inside.concat(outside); - g.fillPoly(vertices, true); -} - -// draw the arc segments around the perimeter -function drawPerimeter() { - g.clear(); - for (var i = 0; i < N; i++) { - g.setColor(colours[i%colours.length]); - var minAngle = (i/N)*radians; - arc(perimMin,perimMax,minAngle,minAngle+arclen); - } -} - -// animate a ball rolling around and settling at "target" radians -function animateChoice(target) { - var angle = 0; - var speed = 0; - var oldx = -10; - var oldy = -10; - var decelFromAngle = -1; - var allowDecel = false; - for (var i = 0; true; i++) { - angle = angle + speed; - if (angle > radians) angle -= radians; - if (i < animStartSteps || (speed < maxSpeed && !allowDecel)) { - speed = speed + accel; - if (speed > maxSpeed) { - speed = maxSpeed; - /* when we reach max speed, we know how long it takes - * to accelerate, and therefore how long to decelerate, so - * we can work out what angle to start decelerating from */ - if (decelFromAngle < 0) { - decelFromAngle = target-angle; - while (decelFromAngle < 0) decelFromAngle += radians; - while (decelFromAngle > radians) decelFromAngle -= radians; - } - } - } else { - if (!allowDecel && (angle < decelFromAngle) && (angle+speed >= decelFromAngle)) allowDecel = true; - if (allowDecel) speed = speed - accel; - if (speed < minSpeed) speed = minSpeed; - if (speed == minSpeed && angle < target && angle+speed >= target) return; - } - - var r = i/2; - if (r > ballTrack) r = ballTrack; - var x = centreX+Math.cos(angle)*r; - var y = centreY+Math.sin(angle)*r; - g.setColor('#000000'); - g.fillCircle(oldx,oldy,ballSize+1); - g.setColor('#ffffff'); - g.fillCircle(x, y, ballSize); - oldx=x; - oldy=y; - g.flip(); - } -} - -// choose a winning segment and animate its selection -function choose() { - var chosen = Math.floor(Math.random()*N); - var minAngle = (chosen/N)*radians; - var maxAngle = minAngle + arclen; - animateChoice((minAngle+maxAngle)/2); - g.setColor(colours[chosen%colours.length]); - for (var i = segmentMax-segmentStep; i >= 0; i -= segmentStep) - arc(i, perimMax, minAngle, maxAngle); - arc(0, perimMax, minAngle, maxAngle); - for (var r = 1; r < segmentMax; r += circleStep) - g.fillCircle(centreX,centreY,r); - g.fillCircle(centreX,centreY,segmentMax); -} - -// draw the current value of N in the middle of the screen, with -// up/down arrows -function drawN() { - g.setColor(g.theme.fg); - g.setFont("Vector",fontSize); - g.drawString(N,centreX-g.stringWidth(N)/2+4,centreY-fontSize/2); - if (N < maxN) - g.fillPoly([centreX-6,centreY-fontSize/2-7, centreX+6,centreY-fontSize/2-7, centreX, centreY-fontSize/2-14]); - if (N > minN) - g.fillPoly([centreX-6,centreY+fontSize/2+5, centreX+6,centreY+fontSize/2+5, centreX, centreY+fontSize/2+12]); -} - -// update number of segments, with min/max limit, "arclen" update, -// and screen reset -function setN(n) { - N = n; - if (N < minN) N = minN; - if (N > maxN) N = maxN; - arclen = radians/N - gapAngle; - drawPerimeter(); -} - -// save N to choozi.txt -function writeN() { - var file = require("Storage").open("choozi.txt","w"); - file.write(N); -} - -// load N from choozi.txt -function readN() { - var file = require("Storage").open("choozi.txt","r"); - var n = file.readLine(); - if (n !== undefined) setN(parseInt(n)); - else setN(defaultN); -} - -shuffle(colours); // is this really best? -Bangle.setLCDTimeout(0); // keep screen on -readN(); -drawN(); - -setWatch(() => { - writeN(); - drawPerimeter(); - choose(); -}, BTN1, {repeat:true}); - -Bangle.on('touch', function(zone,e) { - if(e.x>+88){ - setN(N-1); - drawN(); - }else{ - setN(N+1); - drawN(); - } -}); diff --git a/apps/choozi/bangle1-choozi-screenshot1.png b/apps/choozi/bangle1-choozi-screenshot1.png index 104024958..ee422ed10 100644 Binary files a/apps/choozi/bangle1-choozi-screenshot1.png and b/apps/choozi/bangle1-choozi-screenshot1.png differ diff --git a/apps/choozi/bangle1-choozi-screenshot2.png b/apps/choozi/bangle1-choozi-screenshot2.png index f3b6868bf..20edf4c78 100644 Binary files a/apps/choozi/bangle1-choozi-screenshot2.png and b/apps/choozi/bangle1-choozi-screenshot2.png differ diff --git a/apps/choozi/metadata.json b/apps/choozi/metadata.json index 79af76fa2..c42abe079 100644 --- a/apps/choozi/metadata.json +++ b/apps/choozi/metadata.json @@ -1,7 +1,7 @@ { "id": "choozi", "name": "Choozi", - "version": "0.03", + "version": "0.04", "description": "Choose people or things at random using Bangle.js.", "icon": "app.png", "tags": "tool", @@ -10,8 +10,10 @@ "allow_emulator": true, "screenshots": [{"url":"bangle1-choozi-screenshot1.png"},{"url":"bangle1-choozi-screenshot2.png"}], "storage": [ - {"name":"choozi.app.js","url":"app.js","supports": ["BANGLEJS"]}, - {"name":"choozi.app.js","url":"appb2.js","supports": ["BANGLEJS2"]}, + {"name":"choozi.app.js","url":"app.js"}, {"name":"choozi.img","url":"app-icon.js","evaluate":true} + ], + "data": [ + {"name":"choozi.save"} ] } diff --git a/apps/circlesclock/ChangeLog b/apps/circlesclock/ChangeLog index c398a89b6..83abde6df 100644 --- a/apps/circlesclock/ChangeLog +++ b/apps/circlesclock/ChangeLog @@ -26,3 +26,16 @@ 0.12: Allow configuration of update interval 0.13: Load step goal from Bangle health app as fallback Memory optimizations +0.14: Support to show big weather info +0.15: Use Bangle.setUI({remove:...}) to allow loading the launcher without a full reset on 2v16 +0.16: Fix const error + Use widget_utils if available +0.17: Load circles from clkinfo +0.18: Improved clkinfo handling and using it for the weather circle +0.19: Remove old code and fixing clkinfo handling (fix HRM and other items that change) + Remove settings for what is displayed and instead allow circles to be changed by swiping +0.20: Add much faster circle rendering (250ms -> 40ms) + Add fast load capability +0.21: Remade all icons without a palette for dark theme + Now re-adds widgets if they were hidden when fast-loading +0.22: Fixed crash if item has no image and cutting long overflowing text diff --git a/apps/circlesclock/README.md b/apps/circlesclock/README.md index aa429d5ec..7f6a2585c 100644 --- a/apps/circlesclock/README.md +++ b/apps/circlesclock/README.md @@ -5,28 +5,41 @@ A clock with three or four circles for different data at the bottom in a probabl By default the time, date and day of week is shown. It can show the following information (this can be configured): + * Steps * Steps distance * Heart rate (automatically updates when screen is on and unlocked) * Battery (including charging status and battery low warning) - * Weather (requires [weather app](https://banglejs.com/apps/#weather)) + * Weather (requires [OWM weather provider](https://banglejs.com/apps/?id=owmweather)) * Humidity or wind speed as circle progress * Temperature inside circle * Condition as icon below circle - * Time and progress until next sunrise or sunset (requires [my location app](https://banglejs.com/apps/#mylocation)) - * Temperature, air pressure or altitude from internal pressure sensor + * Big weather icon next to clock + * Altitude from internal pressure sensor + * Active alarms (if `Alarm` app installed) + * Sunrise or sunset (if `Sunrise Clockinfo` app installed) +To change what is shown: -The color of each circle can be configured. The following colors are available: +* Unlock the watch +* Tap on the circle to change (a border is drawn around it) +* Swipe up/down to change the guage within the given group +* Swipe left/right to change the group (eg. between standard Bangle.js and Alarms/etc) + +Data is provided by ['Clock Info'](http://www.espruino.com/Bangle.js+Clock+Info) +so any apps that implement this feature can add extra information to be displayed. + +The color of each circle can be configured from `Settings -> Apps -> Circles Clock`. The following colors are available: * Basic colors (red, green, blue, yellow, magenta, cyan, black, white) * Color depending on value (green -> red, red -> green) - ## Screenshots ![Screenshot dark theme](screenshot-dark.png) ![Screenshot light theme](screenshot-light.png) ![Screenshot dark theme with four circles](screenshot-dark-4.png) ![Screenshot light theme with four circles](screenshot-light-4.png) +![Screenshot light theme with big weather enabled](screenshot-light-with-big-weather.png) + ## Ideas * Show compass heading @@ -35,4 +48,5 @@ The color of each circle can be configured. The following colors are available: Marco ([myxor](https://github.com/myxor)) ## Icons -Icons taken from [materialdesignicons](https://materialdesignicons.com) under Apache License 2.0 +Most of the icons are taken from [materialdesignicons](https://materialdesignicons.com) under Apache License 2.0 except the big weather icons which are from +[icons8](https://icons8.com/icon/set/weather/small--static--black) diff --git a/apps/circlesclock/app.js b/apps/circlesclock/app.js index 83a0aa027..30d6a48f4 100644 --- a/apps/circlesclock/app.js +++ b/apps/circlesclock/app.js @@ -1,5 +1,3 @@ -const locale = require("locale"); -const storage = require("Storage"); Graphics.prototype.setFontRobotoRegular50NumericOnly = function(scale) { // Actual height 39 (40 - 2) this.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAB8AAAAAAAfAAAAAAAPwAAAAAAB8AAAAAAAeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAA4AAAAAAB+AAAAAAD/gAAAAAD/4AAAAAH/4AAAAAP/wAAAAAP/gAAAAAf/gAAAAAf/AAAAAA/+AAAAAB/+AAAAAB/8AAAAAD/4AAAAAH/4AAAAAD/wAAAAAA/wAAAAAAPgAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///wAAAB////gAAA////8AAA/////gAAP////8AAH8AAA/gAB8AAAD4AA+AAAAfAAPAAAADwADwAAAA8AA8AAAAPAAPAAAADwADwAAAA8AA8AAAAPAAPgAAAHwAB8AAAD4AAfwAAD+AAD/////AAA/////wAAH////4AAAf///4AAAB///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeAAAAAAAPgAAAAAADwAAAAAAB8AAAAAAAfAAAAAAAHgAAAAAAD4AAAAAAA+AAAAAAAPAAAAAAAH/////wAB/////8AA//////AAP/////wAD/////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAfgAADwAAP4AAB8AAH+AAA/AAD/gAAfwAB/AAAf8AAfAAAP/AAPgAAH7wAD4AAD88AA8AAB+PAAPAAA/DwADwAAfg8AA8AAPwPAAPAAH4DwADwAH8A8AA+AD+APAAPwB/ADwAB/D/gA8AAf//gAPAAD//wADwAAf/wAA8AAD/4AAPAAAHwAADwAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAADgAAAHwAA+AAAD8AAP4AAB/AAD/AAA/wAA/wAAf4AAD+AAHwAAAPgAD4APAB8AA+ADwAPAAPAA8ADwADwAPAA8AA8ADwAPAAPAA8ADwADwAfAA8AA8AH4APAAPgD+AHwAB8B/wD4AAf7/+B+AAD//v//AAA//x//wAAD/4P/4AAAf8B/4AAAAYAH4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAAAAAHwAAAAAAH8AAAAAAD/AAAAAAD/wAAAAAD/8AAAAAB/vAAAAAB/jwAAAAA/g8AAAAA/wPAAAAAfwDwAAAAf4A8AAAAf4APAAAAP8ADwAAAP8AA8AAAH8AAPAAAD/////8AA//////AAP/////wAD/////8AA//////AAAAAAPAAAAAAADwAAAAAAA8AAAAAAAPAAAAAAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAB/APwAAH//wD+AAD//8A/wAA///AH+AAP//wAPgAD/B4AB8AA8A+AAfAAPAPAADwADwDwAA8AA8A8AAPAAPAPAADwADwD4AA8AA8A+AAPAAPAPwAHwADwD8AD4AA8AfwD+AAPAH///AADwA///wAA8AH//4AAPAAf/4AAAAAB/4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//AAAAAD//+AAAAD///4AAAD////AAAB////4AAA/78D/AAAfw8AH4AAPweAA+AAD4PgAHwAB8DwAA8AAfA8AAPAAHgPAADwAD4DwAA8AA+A8AAPAAPAPgAHwADwD4AB8AA8AfgA+AAPAH+B/gAAAA///wAAAAH//4AAAAA//8AAAAAH/8AAAAAAP4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwAAAAAAA8AAAAAAAPAAAAAAADwAAAAAAA8AAAABAAPAAAABwADwAAAB8AA8AAAB/AAPAAAB/wADwAAD/8AA8AAD/8AAPAAD/4AADwAD/4AAA8AD/4AAAPAH/wAAADwH/wAAAA8H/wAAAAPH/wAAAAD3/gAAAAA//gAAAAAP/gAAAAAD/gAAAAAA/AAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwA/4AAAH/Af/AAAH/8P/4AAD//n//AAA//7//4AAfx/+A+AAHwD+AHwAD4AfgB8AA8AHwAPAAPAA8ADwADwAPAA8AA8ADwAPAAPAA8ADwADwAfAA8AA+AH4AfAAHwD+AHwAB/D/4D4AAP/+/n+AAD//n//AAAf/w//gAAB/wH/wAAAHwA/4AAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB+AAAAAAD/8AAAAAD//wAAAAB//+AAAAA///wAAAAf4H+APAAH4AfgDwAD8AB8A8AA+AAfAPAAPAADwDwADwAA8B8AA8AAPAfAAPAADwHgADwAA8D4AA+AAeB+AAHwAHg/AAB+ADwfgAAP8D4/4AAD////8AAAf///8AAAB///+AAAAP//+AAAAAP/4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAOAAAB8AAHwAAAfgAD8AAAH4AA/AAAB8AAHwAAAOAAA4AAAAAAAAAAAAAAAAAAAAAAAAAA"), 46, atob("DRUcHBwcHBwcHBwcDA=="), 50+(scale<<8)+(1<<16)); @@ -12,54 +10,47 @@ Graphics.prototype.setFontRobotoRegular21 = function(scale) { return this; }; -const SETTINGS_FILE = "circlesclock.json"; +{ +let clock_info = require("clock_info"); +let locale = require("locale"); +let storage = require("Storage"); + +let SETTINGS_FILE = "circlesclock.json"; let settings = Object.assign( storage.readJSON("circlesclock.default.json", true) || {}, storage.readJSON(SETTINGS_FILE, true) || {} ); - + //TODO deprecate this (and perhaps use in the clkinfo module) // Load step goal from health app and pedometer widget as fallback if (settings.stepGoal == undefined) { let d = storage.readJSON("health.json", true) || {}; settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.stepGoal : undefined; - - if (settings.stepGoal == undefined) { + + if (settings.stepGoal == undefined) { d = storage.readJSON("wpedom.json", true) || {}; settings.stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000; } } -/* - * Read location from myLocation app - */ -function getLocation() { - return storage.readJSON("mylocation.json", 1) || undefined; -} -let location = getLocation(); - +let drawTimeout; const showWidgets = settings.showWidgets || false; const circleCount = settings.circleCount || 3; +const showBigWeather = settings.showBigWeather || false; -let hrtValue; +let hrtValue; //TODO deprecate this let now = Math.round(new Date().getTime() / 1000); - // layout values: -const colorFg = g.theme.dark ? '#fff' : '#000'; -const colorBg = g.theme.dark ? '#000' : '#fff'; -const colorGrey = '#808080'; -const colorRed = '#ff0000'; -const colorGreen = '#008000'; -const colorBlue = '#0000ff'; -const colorYellow = '#ffff00'; -const widgetOffset = showWidgets ? 24 : 0; -const dowOffset = circleCount == 3 ? 20 : 22; // dow offset relative to date -const h = g.getHeight() - widgetOffset; -const w = g.getWidth(); -const hOffset = (circleCount == 3 ? 34 : 30) - widgetOffset; -const h1 = Math.round(1 * h / 5 - hOffset); -const h2 = Math.round(3 * h / 5 - hOffset); -const h3 = Math.round(8 * h / 8 - hOffset - 3); // circle y position +let colorFg = g.theme.dark ? '#fff' : '#000'; +let colorBg = g.theme.dark ? '#000' : '#fff'; +let widgetOffset = showWidgets ? 24 : 0; +let dowOffset = circleCount == 3 ? 20 : 22; // dow offset relative to date +let h = g.getHeight() - widgetOffset; +let w = g.getWidth(); +let hOffset = (circleCount == 3 ? 34 : 30) - widgetOffset; +let h1 = Math.round(1 * h / 5 - hOffset); +let h2 = Math.round(3 * h / 5 - hOffset); +let h3 = Math.round(8 * h / 8 - hOffset - 3); // circle middle y position /* * circle x positions @@ -73,483 +64,133 @@ const h3 = Math.round(8 * h / 8 - hOffset - 3); // circle y position * | (1) (2) (3) (4) | * => circles start at 1,3,5,7 / 8 */ -const parts = circleCount * 2; -const circlePosX = [ +let parts = circleCount * 2; +let circlePosX = [ Math.round(1 * w / parts), // circle1 Math.round(3 * w / parts), // circle2 Math.round(5 * w / parts), // circle3 Math.round(7 * w / parts), // circle4 ]; -const radiusOuter = circleCount == 3 ? 25 : 20; -const radiusInner = circleCount == 3 ? 20 : 15; -const circleFontSmall = circleCount == 3 ? "Vector:14" : "Vector:10"; -const circleFont = circleCount == 3 ? "Vector:15" : "Vector:11"; -const circleFontBig = circleCount == 3 ? "Vector:16" : "Vector:12"; -const iconOffset = circleCount == 3 ? 6 : 8; -const defaultCircleTypes = ["steps", "hr", "battery", "weather"]; +let radiusOuter = circleCount == 3 ? 25 : 20; +let radiusBorder = radiusOuter+3; // absolute border of circles +let radiusInner = circleCount == 3 ? 20 : 15; +let circleFontSmall = circleCount == 3 ? "Vector:14" : "Vector:10"; +let circleFont = circleCount == 3 ? "Vector:15" : "Vector:11"; +let circleFontBig = circleCount == 3 ? "Vector:16" : "Vector:12"; +let iconOffset = circleCount == 3 ? 6 : 8; -function hideWidgets() { - /* - * we are not drawing the widgets as we are taking over the whole screen - * so we will blank out the draw() functions of each widget and change the - * area to the top bar doesn't get cleared. - */ - if (WIDGETS && typeof WIDGETS === "object") { - for (let wd of WIDGETS) { - wd.draw = () => {}; - wd.area = ""; - } - } -} -function draw() { - g.clear(true); - if (!showWidgets) { - hideWidgets(); - } else { - Bangle.drawWidgets(); - } +let draw = function() { + let R = Bangle.appRect; + g.reset().clearRect(R.x,R.y, R.x2, h3-(radiusBorder+1)); g.setColor(colorBg); g.fillRect(0, widgetOffset, w, h2 + 22); // time g.setFontRobotoRegular50NumericOnly(); - g.setFontAlign(0, -1); g.setColor(colorFg); - g.drawString(locale.time(new Date(), 1), w / 2, h1 + 6); + if (!showBigWeather) { + g.setFontAlign(0, -1); + g.drawString(locale.time(new Date(), 1), w / 2, h1 + 6); + } + else { + g.setFontAlign(-1, -1); + g.drawString(locale.time(new Date(), 1), 2, h1 + 6); + } now = Math.round(new Date().getTime() / 1000); // date & dow g.setFontRobotoRegular21(); - g.setFontAlign(0, 0); - g.drawString(locale.date(new Date()), w / 2, h2); - g.drawString(locale.dow(new Date()), w / 2, h2 + dowOffset); - - drawCircle(1); - drawCircle(2); - drawCircle(3); - if (circleCount >= 4) drawCircle(4); -} - -function drawCircle(index) { - let type = settings['circle' + index]; - if (!type) type = defaultCircleTypes[index - 1]; - const w = getCircleXPosition(type); - - switch (type) { - case "steps": - drawSteps(w); - break; - case "stepsDist": - drawStepsDistance(w); - break; - case "hr": - drawHeartRate(w); - break; - case "battery": - drawBattery(w); - break; - case "weather": - drawWeather(w); - break; - case "sunprogress": - case "sunProgress": - drawSunProgress(w); - break; - case "temperature": - drawTemperature(w); - break; - case "pressure": - drawPressure(w); - break; - case "altitude": - drawAltitude(w); - break; - case "empty": - // we draw nothing here - return; - } -} - -// serves as cache for quicker lookup of circle positions -let circlePositionsCache = []; -/* - * Looks in the following order if a circle with the given type is somewhere visible/configured - * 1. circlePositionsCache - * 2. settings - * 3. defaultCircleTypes - * - * In case 2 and 3 the circlePositionsCache will be updated - */ -function getCirclePosition(type) { - if (circlePositionsCache[type] >= 0) { - return circlePositionsCache[type]; - } - for (let i = 1; i <= circleCount; i++) { - const setting = settings['circle' + i]; - if (setting == type) { - circlePositionsCache[type] = i - 1; - return i - 1; - } - } - for (let i = 0; i < defaultCircleTypes.length; i++) { - if (type == defaultCircleTypes[i] && (!settings || settings['circle' + (i + 1)] == undefined)) { - circlePositionsCache[type] = i; - return i; - } - } - return undefined; -} - -function getCircleXPosition(type) { - const circlePos = getCirclePosition(type); - if (circlePos != undefined) { - return circlePosX[circlePos]; - } - return undefined; -} - -function isCircleEnabled(type) { - return getCirclePosition(type) != undefined; -} - -function getCircleColor(type) { - const pos = getCirclePosition(type); - const color = settings["circle" + (pos + 1) + "color"]; - if (color && color != "") return color; -} - -function getCircleIconColor(type, color, percent) { - const pos = getCirclePosition(type); - const colorizeIcon = settings["circle" + (pos + 1) + "colorizeIcon"] == true; - if (colorizeIcon) { - return getGradientColor(color, percent); + if (!showBigWeather) { + g.setFontAlign(0, 0); + g.drawString(locale.date(new Date()), w / 2, h2); + g.drawString(locale.dow(new Date()), w / 2, h2 + dowOffset); } else { - return ""; + g.setFontAlign(-1, 0); + g.drawString(locale.date(new Date()), 2, h2); + g.drawString(locale.dow(new Date()), 2, h2 + dowOffset, 1); } + + // weather + if (showBigWeather) { + let weather = getWeather(); + let tempString = weather ? locale.temp(weather.temp - 273.15) : undefined; + g.setFontAlign(1, 0); + if (tempString) g.drawString(tempString, w, h2); + + let code = weather ? weather.code : -1; + let icon = getWeatherIconByCode(code, true); + if (icon) g.drawImage(icon, w - 48, h1, {scale:0.75}); + } + + queueDraw(); } -function getGradientColor(color, percent) { +let getCircleColor = function(index) { + let color = settings["circle" + index + "color"]; + if (color && color != "") return color; + return g.theme.fg; +} + +let getGradientColor = function(color, percent) { if (isNaN(percent)) percent = 0; if (percent > 1) percent = 1; - const colorList = [ + let colorList = [ '#00FF00', '#80FF00', '#FFFF00', '#FF8000', '#FF0000' ]; if (color == "fg") { color = colorFg; } if (color == "green-red") { - const colorIndex = Math.round(colorList.length * percent); + let colorIndex = Math.round(colorList.length * percent); return colorList[Math.min(colorIndex, colorList.length) - 1] || "#00ff00"; } if (color == "red-green") { - const colorIndex = colorList.length - Math.round(colorList.length * percent); + let colorIndex = colorList.length - Math.round(colorList.length * percent); return colorList[Math.min(colorIndex, colorList.length)] || "#ff0000"; } return color; } -function getImage(graphic, color) { - if (!color || color == "") { - return graphic; +let getCircleIconColor = function(index, color, percent) { + let colorizeIcon = settings["circle" + index + "colorizeIcon"] == true; + if (colorizeIcon) { + return getGradientColor(color, percent); } else { - return { - width: 16, - height: 16, - bpp: 1, - transparent: 0, - buffer: E.toArrayBuffer(graphic), - palette: new Uint16Array([colorBg, g.toColor(color)]) - }; + return g.theme.fg; } } -function drawSteps(w) { - if (!w) w = getCircleXPosition("steps"); - const steps = getSteps(); - - drawCircleBackground(w); - - const color = getCircleColor("steps"); - - let percent; - const stepGoal = settings.stepGoal; - if (stepGoal > 0) { - percent = steps / stepGoal; - if (stepGoal < steps) percent = 1; - drawGauge(w, h3, percent, color); - } - +let drawEmpty = function(img, w, color) { + drawGauge(w, h3, 0, color); drawInnerCircleAndTriangle(w); - - writeCircleText(w, shortValue(steps)); - - g.drawImage(getImage(atob("EBCBAAAACAAcAB4AHgAeABwwADgGeAZ4AHgAMAAAAHAAIAAA"), getCircleIconColor("steps", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); + writeCircleText(w, "?"); + if(img) + g.setColor(getGradientColor(color, 0)) + .drawImage(img, w - iconOffset, h3 + radiusOuter - iconOffset, {scale: 16/24}); } -function drawStepsDistance(w) { - if (!w) w = getCircleXPosition("stepsDistance"); - const steps = getSteps(); - const stepDistance = settings.stepLength; - const stepsDistance = Math.round(steps * stepDistance); - +let drawCircle = function(index, item, data) { + var w = circlePosX[index-1]; drawCircleBackground(w); - - const color = getCircleColor("stepsDistance"); - - let percent; - const stepDistanceGoal = settings.stepDistanceGoal; - if (stepDistanceGoal > 0) { - percent = stepsDistance / stepDistanceGoal; - if (stepDistanceGoal < stepsDistance) percent = 1; - drawGauge(w, h3, percent, color); - } - - drawInnerCircleAndTriangle(w); - - writeCircleText(w, shortValue(stepsDistance)); - - g.drawImage(getImage(atob("EBCBAAAACAAcAB4AHgAeABwwADgGeAZ4AHgAMAAAAHAAIAAA"), getCircleIconColor("stepsDistance", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); -} - -function drawHeartRate(w) { - if (!w) w = getCircleXPosition("hr"); - - const heartIcon = atob("EBCBAAAAAAAeeD/8P/x//n/+P/w//B/4D/AH4APAAYAAAAAA"); - - drawCircleBackground(w); - - const color = getCircleColor("hr"); - - let percent; - if (hrtValue != undefined) { - const minHR = settings.minHR; - const maxHR = settings.maxHR; - percent = (hrtValue - minHR) / (maxHR - minHR); - if (isNaN(percent)) percent = 0; - drawGauge(w, h3, percent, color); - } - - drawInnerCircleAndTriangle(w); - - writeCircleText(w, hrtValue != undefined ? hrtValue : "-"); - - g.drawImage(getImage(heartIcon, getCircleIconColor("hr", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); -} - -function drawBattery(w) { - if (!w) w = getCircleXPosition("battery"); - const battery = E.getBattery(); - - const powerIcon = atob("EBCBAAAAA8ADwA/wD/AP8A/wD/AP8A/wD/AP8A/wD/AH4AAA"); - - drawCircleBackground(w); - - let color = getCircleColor("battery"); - - let percent; - if (battery > 0) { - percent = battery / 100; - drawGauge(w, h3, percent, color); - } - - drawInnerCircleAndTriangle(w); - - if (Bangle.isCharging()) { - color = colorGreen; - } else { - if (settings.batteryWarn != undefined && battery <= settings.batteryWarn) { - color = colorRed; - } - } - writeCircleText(w, battery + '%'); - - g.drawImage(getImage(powerIcon, getCircleIconColor("battery", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); -} - -function drawWeather(w) { - if (!w) w = getCircleXPosition("weather"); - const weather = getWeather(); - const tempString = weather ? locale.temp(weather.temp - 273.15) : undefined; - const code = weather ? weather.code : -1; - - drawCircleBackground(w); - - const color = getCircleColor("weather"); - let percent; - const data = settings.weatherCircleData; - switch (data) { - case "humidity": - const humidity = weather ? weather.hum : undefined; - if (humidity >= 0) { - percent = humidity / 100; - drawGauge(w, h3, percent, color); - } - break; - case "wind": - if (weather) { - const wind = locale.speed(weather.wind).match(/^(\D*\d*)(.*)$/); - if (wind[1] >= 0) { - if (wind[2] == "kmh") { - wind[1] = windAsBeaufort(wind[1]); - } - // wind goes from 0 to 12 (see https://en.wikipedia.org/wiki/Beaufort_scale) - percent = wind[1] / 12; - drawGauge(w, h3, percent, color); - } - } - break; - case "empty": - break; - } - - drawInnerCircleAndTriangle(w); - - writeCircleText(w, tempString ? tempString : "?"); - - if (code > 0) { - const icon = getWeatherIconByCode(code); - if (icon) g.drawImage(getImage(icon, getCircleIconColor("weather", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); - } else { - g.drawString("?", w, h3 + radiusOuter); - } -} - - -function drawSunProgress(w) { - if (!w) w = getCircleXPosition("sunprogress"); - const percent = getSunProgress(); - - // sunset icons: - const sunSetDown = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAAGYAPAAYAAAAAA"); - const sunSetUp = atob("EBCBAAAAAAABgAAAAAATyAZoBCB//gAAAAABgAPABmAAAAAA"); - - drawCircleBackground(w); - - const color = getCircleColor("sunprogress"); - + const color = getCircleColor(index); + //drawEmpty(info? info.img : null, w, color); + var img = data.img; + var percent = 1; //fill up if no range + var txt = ""+data.text; + if (txt.endsWith(" bpm")) txt=txt.slice(0,-4); // hack for heart rate - remove the 'bpm' text + if(item.hasRange) percent = (data.v-data.min) / (data.max-data.min); + if(data.short) txt = data.short; + //long text can overflow and we do not draw there anymore.. + if(txt.length>6) txt = txt.slice(0,5)+"\n"+txt.slice(5,10) drawGauge(w, h3, percent, color); - drawInnerCircleAndTriangle(w); - - let icon = sunSetDown; - let text = "?"; - const times = getSunData(); - if (times != undefined) { - const sunRise = Math.round(times.sunrise.getTime() / 1000); - const sunSet = Math.round(times.sunset.getTime() / 1000); - if (!isDay()) { - // night - if (now > sunRise) { - // after sunRise - const upcomingSunRise = sunRise + 60 * 60 * 24; - text = formatSeconds(upcomingSunRise - now); - } else { - text = formatSeconds(sunRise - now); - } - icon = sunSetUp; - } else { - // day, approx sunrise tomorrow: - text = formatSeconds(sunSet - now); - icon = sunSetDown; - } - } - - writeCircleText(w, text); - - g.drawImage(getImage(icon, getCircleIconColor("sunprogress", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); -} - -function drawTemperature(w) { - if (!w) w = getCircleXPosition("temperature"); - - getPressureValue("temperature").then((temperature) => { - drawCircleBackground(w); - - const color = getCircleColor("temperature"); - - let percent; - if (temperature) { - const min = -40; - const max = 85; - percent = (temperature - min) / (max - min); - drawGauge(w, h3, percent, color); - } - - drawInnerCircleAndTriangle(w); - - if (temperature) - writeCircleText(w, locale.temp(temperature)); - - g.drawImage(getImage(atob("EBCBAAAAAYADwAJAAkADwAPAA8ADwAfgB+AH4AfgA8ABgAAA"), getCircleIconColor("temperature", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); - - }); -} - -function drawPressure(w) { - if (!w) w = getCircleXPosition("pressure"); - - getPressureValue("pressure").then((pressure) => { - drawCircleBackground(w); - - const color = getCircleColor("pressure"); - - let percent; - if (pressure && pressure > 0) { - const minPressure = 950; - const maxPressure = 1050; - percent = (pressure - minPressure) / (maxPressure - minPressure); - drawGauge(w, h3, percent, color); - } - - drawInnerCircleAndTriangle(w); - - if (pressure) - writeCircleText(w, Math.round(pressure)); - - g.drawImage(getImage(atob("EBCBAAAAAYADwAJAAkADwAPAA8ADwAfgB+AH4AfgA8ABgAAA"), getCircleIconColor("pressure", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); - - }); -} - -function drawAltitude(w) { - if (!w) w = getCircleXPosition("altitude"); - - getPressureValue("altitude").then((altitude) => { - drawCircleBackground(w); - - const color = getCircleColor("altitude"); - - let percent; - if (altitude) { - const min = 0; - const max = 10000; - percent = (altitude - min) / (max - min); - drawGauge(w, h3, percent, color); - } - - drawInnerCircleAndTriangle(w); - - if (altitude) - writeCircleText(w, locale.distance(Math.round(altitude))); - - g.drawImage(getImage(atob("EBCBAAAAAYADwAJAAkADwAPAA8ADwAfgB+AH4AfgA8ABgAAA"), getCircleIconColor("altitude", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset); - - }); -} - -/* - * wind goes from 0 to 12 (see https://en.wikipedia.org/wiki/Beaufort_scale) - */ -function windAsBeaufort(windInKmh) { - const beaufort = [2, 6, 12, 20, 29, 39, 50, 62, 75, 89, 103, 118]; - let l = 0; - while (l < beaufort.length && beaufort[l] < windInKmh) { - l++; - } - return l; + writeCircleText(w, txt); + if(!img) return; //or get it from the clkinfo? + g.setColor(getCircleIconColor(index, color, percent)) + .drawImage(img, w - iconOffset, h3 + radiusOuter - iconOffset, {scale: 16/24}); } @@ -557,19 +198,21 @@ function windAsBeaufort(windInKmh) { * Choose weather icon to display based on weather conditition code * https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2 */ -function getWeatherIconByCode(code) { - const codeGroup = Math.round(code / 100); +let getWeatherIconByCode = function(code, big) { + let codeGroup = Math.round(code / 100); + if (big == undefined) big = false; // weather icons: - const weatherCloudy = atob("EBCBAAAAAAAAAAfgD/Af8H/4//7///////9//z/+AAAAAAAA"); - const weatherSunny = atob("EBCBAAAAAYAQCBAIA8AH4A/wb/YP8A/gB+ARiBAIAYABgAAA"); - const weatherMoon = atob("EBCBAAAAAYAP8B/4P/w//D/8f/5//j/8P/w//B/4D/ABgAAA"); - const weatherPartlyCloudy = atob("EBCBAAAAAAAYQAMAD8AIQBhoW+AOYBwwOBBgHGAGP/wf+AAA"); - const weatherRainy = atob("EBCBAAAAAYAH4AwwOBBgGEAOQAJBgjPOEkgGYAZgA8ABgAAA"); - const weatherPartlyRainy = atob("EBCBAAAAEEAQAAeADMAYaFvoTmAMMDgQIBxhhiGGG9wDwAGA"); - const weatherSnowy = atob("EBCBAAAAAAADwAGAEYg73C50BCAEIC50O9wRiAGAA8AAAAAA"); - const weatherFoggy = atob("EBCBAAAAAAADwAZgDDA4EGAcQAZAAgAAf74AAAAAd/4AAAAA"); - const weatherStormy = atob("EBCBAAAAAYAH4AwwOBBgGEAOQMJAgjmOGcgAgACAAAAAAAAA"); + let weatherCloudy = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAf/4AAAAAAAD//4AAAAAAA///wAAAAAAH+B/gAAAAAA/AA/AAAAAAH4AB+AAAAAAfAAD8AAAAAD4AAH/wAAAAfAAAP/wAAAB4AAAf/gAAAHgAAB//AAAB+AAACB+AAAfwAAAAB8AAH/AAAAAD4AA/8AAAAAHgAD8AAAAAAeAAfAAAAAAA8AB4AAAAAADwAPgAAAAAAPAA8AAAAAAA8APwAAAAAADwB/AAAAAAAPAP8AAAAAAB8B+AAAAAAAH4PgAAAAAAAHx8AAAAAAAAPngAAAAAAAAeeAAAAAAAAB7wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA94AAAAAAAAHngAAAAAAAAefAAAAAAAAD4+AAAAAAAAfB+AAAAAAAH4D/////////AH////////4AP////////AAH///////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAAAAAAfgD/Af8H/4//7///////9//z/+AAAAAAAA"); + let weatherSunny = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAMAA8AAwAAAB4ADwAHgAAAHwAPAA+AAAAPgA8AHwAAAAfADwA+AAAAA+AfgHwAAAAB8P/w+AAAAAD7//3wAAAAAH///+AAAAAAP+B/wAAAAAAfgB+AAAAAAD4AB8AAAAAAPAADwAAAAAB8AAPgAAAAAHgAAeAAAAAAeAAB4AAAAADwAADwAAAP//AAAP//AA//8AAA//8AD//wAAD//wAP//AAAP//AAAA8AAA8AAAAAB4AAHgAAAAAHgAAeAAAAAAfAAD4AAAAAA8AAPAAAAAAD4AB8AAAAAAH4AfgAAAAAA/4H/AAAAAAH///+AAAAAA+//98AAAAAHw//D4AAAAA+AfgHwAAAAHwA8APgAAAA+ADwAfAAAAHwAPAA+AAAAeAA8AB4AAAAwADwADAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAYAQCBAIA8AH4A/wb/YP8A/gB+ARiBAIAYABgAAA"); + let weatherMoon = big ? atob("QECBAAAGAAAADwAAAA+AAAAPAAAAD8AAAA8AAAAP4AAADwAAAAfwDwD/8AAAB/gPAP/wAAAH+A8A//AAAAf8DwD/8AAAB/4AAA8AAAAHvgAADwAAAAeeAAAPAAAAB54AAA8AAAAHjwAAAAAAAA+PDgAAAAAADw8PgAAAAAAfDw/AAAAAAB4PD+AAAAAAPg8D8AAAAAB8HwH4AAAAAfg+APwAAPAH8H4Af/AA///g/gA//AD//8H4AB/+AH//AfAAH/8Af/wD4AAIH4A/gAPAAAAHwB/AB8AAAAPgD/AfgAAAAeAH//+AAAAB4AP//4AAAADwAP//AAAAAPAAH/8AAAAA8AAAAAAAAADwAAAAAAAAAPAHAAAAAAAA8A/gAAAAAAHwH4AAAAAAAfg+AAAAAAAAfHwAAAAAAAA+eAAAAAAAAB54AAAAAAAAHvAAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD3gAAAAAAAAeeAAAAAAAAB58AAAAAAAAPj4AAAAAAAB8H4AAAAAAAfgP////////8Af////////gA////////8AAf//////+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAYAP8B/4P/w//D/8f/5//j/8P/w//B/4D/ABgAAA"); + let weatherPartlyCloudy = big ? atob("QECBAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAcADwAOAAAAB4APAB4AAAAHwA8APgAAAAPgH4B8AAAAAfD/8PgAAAAA+//98AAAAAB////gQAAAAD/gf8DgAAAAH4AfgfAAAAA+AA/B+AAAADwAP8D8AAAAfAB/gH/wAAB4APwAP/wAAHgB+AAf/gAA8AHwAB//AP/wA+AACB+A//AHwAAAB8D/8AeAAAAD4P/wB4AAAAHgAPAfgAAAAeAAeH8AAAAA8AB5/wAAAADwAH3/AAAAAPAAP/AAAAAA8AA/wAAAAADwBB+AAAAAAPAOD4AAAAAB8B4HAAAAAAH4PgMAAAAAAHx8AAAAAAAAPngAAAAAAAAeeAAAAAAAAB7wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA/wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA94AAAAAAAAHngAAAAAAAAefAAAAAAAAD4+AAAAAAAAfB+AAAAAAAH4D/////////AH////////4AP////////AAH///////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAAAYQAMAD8AIQBhoW+AOYBwwOBBgHGAGP/wf+AAA"); + let weatherRainy = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAf/4AAAAAAAD//4AAAAAAA///wAAAAAAH+B/gAAAAAA/AA/AAAAAAH4AB+AAAAAAfAAD8AAAAAD4AAH/wAAAAfAAAP/wAAAB4AAAf/gAAAHgAAB//AAAB+AAACB+AAAfwAAAAB8AAH/AAAAAD4AA/8AAAAAHgAD8AAAAAAeAAfAAAAAAA8AB4AAAAAADwAPgAAAAAAPAA8AAAAAAA8APwAAAAAADwB/AAAAAAAPAP8AAAAAAB8B+ADwAPAAH4PgAPAA8AAHx8AA8ADwAAPngADwAPAAAeeAAAAAAAAB7wAAAAAAAAD/AAAAAAAAAP8AAAAAAAAA/wAA8PDw8AD/AADw8PDwAP8AAPDw8PAA94AA8PDw8AHngAAAAAAAAefAAAAAAAAD4+AAAAAAAAfB+AAAAAAAH4D/8PDw8PD/AH/w8PDw8P4AP/Dw8PDw/AAH8PDw8PDgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8ADwAAAAAADwAPAAAAAAAPAA8AAAAAAA8ADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAYAH4AwwOBBgGEAOQAJBgjPOEkgGYAZgA8ABgAAA"); + let weatherPartlyRainy = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAf/4AAAAAAAD//4AAAAAAA///wAAAAAAH+B/gAAAAAA/AA/AAAAAAH4AB+AAAAAAfAAD8AAAAAD4AAH/wAAAAfAAAP/wAAAB4AAAf/gAAAHgAAB//AAAB+AAACB+AAAfwAAAAB8AAH/AAAAAD4AA/8AAAAAHgAD8AAAAAAeAAfAAAAAAA8AB4AAAAAADwAPgAAAAAAPAA8AAAAAAA8APwAAAAAADwB/AAAAAAAPAP8AAAAAAB8B+AAAAPAAH4PgAAAA8AAHx8AAAADwAAPngAAAAPAAAeeAAAAA8AAB7wAAAADwAAD/AAAAAPAAAP8AAAAA8AAA/wAAAPDwAAD/AAAA8PAAAP8AAADw8AAA94AAAPDwAAHngAAA8PAAAefAAADw8AAD4+AAAPDwAAfB+AAA8PAAH4D///Dw8P//AH//8PDw//4AP//w8PD//AAH//Dw8P/gAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAEEAQAAeADMAYaFvoTmAMMDgQIBxhhiGGG9wDwAGA"); + let weatherSnowy = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAf/4AAAAAAAD//4AAAAAAA///wAAAAAAH+B/gAAAAAA/AA/AAAAAAH4AB+AAAAAAfAAD8AAAAAD4AAH/wAAAAfAAAP/wAAAB4AAAf/gAAAHgAAB//AAAB+AAACB+AAAfwAAAAB8AAH/AAAAAD4AA/8AAAAAHgAD8AAAAAAeAAfAAAAAAA8AB4AAAAAADwAPgAAAAAAPAA8AAAAAAA8APwAAAAAADwB/AAAAAAAPAP8AAAAAAB8B+AAAAA8AH4PgAAAADwAHx8AAAAAPAAPngAAAAA8AAeeAAPAA//AB7wAA8AD/8AD/AADwAP/wAP8AAPAA//AA/wAP/wAPAAD/AA//AA8AAP8AD/8ADwAA94AP/wAPAAHngADwAAAAAefAAPAAAAAD4+AA8AAAAAfB+ADwAAAAH4D/8AAPAP//AH/wAA8A//4AP/AADwD//AAH8AAPAP/gAAAAAP/wAAAAAAAA//AAAAAAAAD/8AAAAAAAAP/wAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAAADwAGAEYg73C50BCAEIC50O9wRiAGAA8AAAAAA"); + let weatherFoggy = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAMAA8AAwAAAB4ADwAHgAAAHwAPAA+AAAAPgA8AHwAAAAfADwA+AAAAA+AfgHwAAAAB8P/w+AAAAAD7//3wAAAAAH///+AAAAAAP+B/wAAAAAAfgB+AAAAAAD4AB8AAAAAAPAADwAAAAAB8AAPgAAAAAHgAAeAAAAAAeAAB4AAAAADwAADwAAAAAAAAAP//AAAAAAAA//8AAAAAAAD//wAAAAAAAP//AA///wAA8AAAD///AAHgAAAP//8AAeAAAA///wAD4AAAAAAAAAPAAAAAAAAAB8AAAAAAAAAfgAAAAAAAAH/AAAAA///w/+AAAAD///D98AAAAP//8PD4AAAA///wgHwAAAAAAAAAPgAAAAAAAAAfAAAAAAAAAA+AAAAAAAAAB4AAD///DwADAAAP//8PAAAAAA///w8AAAAAD///DwAAAAAAAAAPAAAAAAAAAA8AAAAAAAAADwAAAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAAADwAZgDDA4EGAcQAZAAgAAf74AAAAAd/4AAAAA"); + let weatherStormy = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAf/4AAAAAAAD//4AAAAAAA///wAAAAAAH+B/gAAAAAA/AA/AAAAAAH4AB+AAAAAAfAAD8AAAAAD4AAH/wAAAAfAAAP/wAAAB4AAAf/gAAAHgAAB//AAAB+AAACB+AAAfwAAAAB8AAH/AAAAAD4AA/8AAAAAHgAD8AAAAAAeAAfAAAAAAA8AB4AAAAAADwAPgAAAAAAPAA8AAAAAAA8APwAAAAAADwB/AAAAAAAPAP8AAAAAAB8B+AAAAAAAH4PgAAAAAAAHx8AAAAAAAAPngAAAAAAAAeeAAAAA/wAB7wAAAAH+AAD/AAAAAf4AAP8AAAAD/AAA/wAAAAP4AAD/AAAAB/gAAP8AAAAH8AAA94AAAA/wAAHngAAAD+AAAefAAAAfwAAD4+AAAB/AAAfB+AAAP4AAH4D///g//w//AH//+H/+D/4AP//wf/wf/AAH//D//D/gAAAAAAD4AAAAAAAAAfAAAAAAAAAB8AAAAAAAAAPgAAAAAAAAA8AAAAAAAAAHwAAAAAAAAAeAAAAAAAAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : atob("EBCBAAAAAYAH4AwwOBBgGEAOQMJAgjmOGcgAgACAAAAAAAAA"); + let unknown = big ? atob("QECBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAAAAAAH/+AAAAAAAB//+AAAAAAAP//8AAAAAAB/gf4AAAAAAPwAPwAAAAAB+AAfgAAAAAPwAA+AAAAAA+B+B8AAAAAHwf+D4AAAAAfD/8HgAAAAB4P/4eAAAAAPh8Ph8AAAAA+HgfDwAAAAD/8A8PAAAAAP/wDw8AAAAA//APDwAAAAB/4A8PAAAAAAAAHw8AAAAAAAB+HwAAAAAAAfweAAAAAAAH+B4AAAAAAA/wPgAAAAAAH8B8AAAAAAA/APgAAAAAAD4B+AAAAAAAfAfwAAAAAAB4H+AAAAAAAPh/gAAAAAAA8H8AAAAAAADw/AAAAAAAAPDwAAAAAAAA//AAAAAAAAD/8AAAAAAAAP/wAAAAAAAAf+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/gAAAAAAAA//AAAAAAAAD/8AAAAAAAAP/wAAAAAAAA8PAAAAAAAADw8AAAAAAAAPDwAAAAAAAA8PAAAAAAAAD/8AAAAAAAAP/wAAAAAAAA//AAAAAAAAB/4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") : undefined; switch (codeGroup) { case 2: @@ -591,7 +234,6 @@ function getWeatherIconByCode(code) { default: return weatherRainy; } - break; case 6: return weatherSnowy; case 7: @@ -599,7 +241,9 @@ function getWeatherIconByCode(code) { case 8: switch (code) { case 800: - return isDay() ? weatherSunny : weatherMoon; + var hr = (new Date()).getHours(); + var isDay = (hr>6) && (hr<=18); // fixme we don't want to include ALL of suncalc just to choose one icon + return isDay ? weatherSunny : weatherMoon; case 801: return weatherPartlyCloudy; case 802: @@ -607,86 +251,24 @@ function getWeatherIconByCode(code) { default: return weatherCloudy; } - break; - default: - return undefined; - } -} - - -function isDay() { - const times = getSunData(); - if (times == undefined) return true; - const sunRise = Math.round(times.sunrise.getTime() / 1000); - const sunSet = Math.round(times.sunset.getTime() / 1000); - - return (now > sunRise && now < sunSet); -} - -function formatSeconds(s) { - if (s > 60 * 60) { // hours - return Math.round(s / (60 * 60)) + "h"; - } - if (s > 60) { // minutes - return Math.round(s / 60) + "m"; - } - return "<1m"; -} - -function getSunData() { - if (location != undefined && location.lat != undefined) { - const SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js"); - // get today's sunlight times for lat/lon - return SunCalc ? SunCalc.getTimes(new Date(), location.lat, location.lon) : undefined; - } - return undefined; -} - -/* - * Calculated progress of the sun between sunrise and sunset in percent - * - * Taken from rebble app and modified - */ -function getSunProgress() { - const times = getSunData(); - if (times == undefined) return 0; - const sunRise = Math.round(times.sunrise.getTime() / 1000); - const sunSet = Math.round(times.sunset.getTime() / 1000); - - if (isDay()) { - // during day - const dayLength = sunSet - sunRise; - if (now > sunRise) { - return (now - sunRise) / dayLength; - } else { - return (sunRise - now) / dayLength; - } - } else { - // during night - if (now < sunRise) { - const prevSunSet = sunSet - 60 * 60 * 24; - return 1 - (sunRise - now) / (sunRise - prevSunSet); - } else { - const upcomingSunRise = sunRise + 60 * 60 * 24; - return (upcomingSunRise - now) / (upcomingSunRise - sunSet); - } + default: + return unknown; } } /* * Draws the background and the grey circle */ -function drawCircleBackground(w) { - g.clearRect(w - radiusOuter - 3, h3 - radiusOuter - 3, w + radiusOuter + 3, h3 + radiusOuter + 3); +let drawCircleBackground = function(w) { // Draw rectangle background: g.setColor(colorBg); - g.fillRect(w - radiusOuter - 3, h3 - radiusOuter - 3, w + radiusOuter + 3, h3 + radiusOuter + 3); + g.fillRect(w - radiusBorder, h3 - radiusBorder, w + radiusBorder, g.getHeight()-1); // Draw grey background circle: - g.setColor(colorGrey); + g.setColor('#808080'); // grey g.fillCircle(w, h3, radiusOuter); } -function drawInnerCircleAndTriangle(w) { +let drawInnerCircleAndTriangle = function(w) { // Draw inner circle g.setColor(colorBg); g.fillCircle(w, h3, radiusInner); @@ -694,38 +276,39 @@ function drawInnerCircleAndTriangle(w) { g.fillPoly([w, h3, w - 15, h3 + radiusOuter + 5, w + 15, h3 + radiusOuter + 5]); } -function radians(a) { - return a * Math.PI / 180; -} - /* * This draws the actual gauge consisting out of lots of little filled circles */ -function drawGauge(cx, cy, percent, color) { - const offset = 15; - const end = 360 - offset; - const radius = radiusInner + (circleCount == 3 ? 3 : 2); - const size = radiusOuter - radiusInner - 2; +let drawGauge = function(cx, cy, percent, color) { + let offset = 15; + let end = 360 - offset; + let radius = radiusOuter+1; if (percent <= 0) return; // no gauge needed if (percent > 1) percent = 1; - const startRotation = -offset; - const endRotation = startRotation - ((end - offset) * percent); + let startRotation = -offset; + let endRotation = startRotation - ((end - offset) * percent); color = getGradientColor(color, percent); g.setColor(color); - - for (let i = startRotation; i > endRotation - size; i -= size) { - x = cx + radius * Math.sin(radians(i)); - y = cy + radius * Math.cos(radians(i)); - g.fillCircle(x, y, size); - } + // convert to radians + startRotation *= Math.PI / 180; + let amt = Math.PI / 10; + endRotation = (endRotation * Math.PI / 180) - amt; + // all we need to draw is an arc, because we'll fill the center + let poly = [cx,cy]; + for (let r = startRotation; r > endRotation; r -= amt) + poly.push( + cx + radius * Math.sin(r), + cy + radius * Math.cos(r) + ); + g.fillPoly(poly); } -function writeCircleText(w, content) { +let writeCircleText = function(w, content) { if (content == undefined) return; - const font = String(content).length > 4 ? circleFontSmall : String(content).length > 3 ? circleFont : circleFontBig; + let font = String(content).length > 4 ? circleFontSmall : String(content).length > 3 ? circleFont : circleFontBig; g.setFont(font); g.setFontAlign(0, 0); @@ -733,118 +316,55 @@ function writeCircleText(w, content) { g.drawString(content, w, h3); } -function shortValue(v) { - if (isNaN(v)) return '-'; - if (v <= 999) return v; - if (v >= 1000 && v < 10000) { - v = Math.floor(v / 100) * 100; - return (v / 1000).toFixed(1).replace(/\.0$/, '') + 'k'; - } - if (v >= 10000) { - v = Math.floor(v / 1000) * 1000; - return (v / 1000).toFixed(1).replace(/\.0$/, '') + 'k'; - } -} - -function getSteps() { - if (Bangle.getHealthStatus) { - return Bangle.getHealthStatus("day").steps; - } - if (WIDGETS && WIDGETS.wpedom !== undefined) { - return WIDGETS.wpedom.getSteps(); - } - return 0; -} - -function getWeather() { - const jsonWeather = storage.readJSON('weather.json'); +let getWeather=function() { + let jsonWeather = storage.readJSON('weather.json'); return jsonWeather && jsonWeather.weather ? jsonWeather.weather : undefined; } -function enableHRMSensor() { - Bangle.setHRMPower(1, "circleclock"); - if (hrtValue == undefined) { - hrtValue = '...'; - drawHeartRate(); +g.clear(1); // clear the whole screen + +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app (allowing for 'fast load') + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + clockInfoMenu.forEach(c => c.remove()); + delete Graphics.prototype.setFontRobotoRegular50NumericOnly; + delete Graphics.prototype.setFontRobotoRegular21; + if (!showWidgets) require("widget_utils").show(); } -} +}); -let pressureLocked = false; -let pressureCache; - -function getPressureValue(type) { - return new Promise((resolve) => { - if (Bangle.getPressure) { - if (!pressureLocked) { - pressureLocked = true; - if (pressureCache && pressureCache[type]) { - resolve(pressureCache[type]); - } - Bangle.getPressure().then(function(d) { - pressureLocked = false; - if (d) { - pressureCache = d; - if (d[type]) { - resolve(d[type]); - } - } - }).catch(() => {}); - } else { - if (pressureCache && pressureCache[type]) { - resolve(pressureCache[type]); - } - } - } +let clockInfoDraw = (itm, info, options) => { + //print("Draw",itm.name,options); + drawCircle(options.circlePosition, itm, info); + if (options.focus) g.reset().drawRect(options.x, options.y, options.x+options.w-2, options.y+options.h-1) +}; +let clockInfoItems = require("clock_info").load(); +let clockInfoMenu = []; +for(var i=0;i= (settings.confidence)) { - hrtValue = hrm.bpm; - if (Bangle.isLCDOn()) { - drawHeartRate(); - } - } - // Let us wait before we overwrite "good" HRM values: - if (Bangle.isLCDOn()) { - if (timerHrm) clearTimeout(timerHrm); - timerHrm = setTimeout(() => { - hrtValue = '...'; - drawHeartRate(); - }, settings.hrmValidity * 1000); - } - } -}); - -Bangle.on('charging', function(charging) { - if (isCircleEnabled("battery")) drawBattery(); -}); - -if (isCircleEnabled("hr")) { - enableHRMSensor(); + }, queueMillis - (Date.now() % queueMillis)); } -Bangle.setUI("clock"); -Bangle.loadWidgets(); - -// schedule a draw for the next minute -setTimeout(function() { - // draw in interval - setInterval(draw, settings.updateInterval * 1000); -}, 60000 - (Date.now() % 60000)); - draw(); +} diff --git a/apps/circlesclock/default.json b/apps/circlesclock/default.json index ea00dc347..ad409b992 100644 --- a/apps/circlesclock/default.json +++ b/apps/circlesclock/default.json @@ -1,18 +1,8 @@ { - "minHR": 40, - "maxHR": 200, - "confidence": 0, - "stepGoal": 10000, - "stepDistanceGoal": 8000, - "stepLength": 0.8, "batteryWarn": 30, "showWidgets": false, "weatherCircleData": "humidity", "circleCount": 3, - "circle1": "hr", - "circle2": "steps", - "circle3": "battery", - "circle4": "weather", "circle1color": "green-red", "circle2color": "#0000ff", "circle3color": "red-green", @@ -21,6 +11,15 @@ "circle2colorizeIcon": true, "circle3colorizeIcon": true, "circle4colorizeIcon": false, - "hrmValidity": 60, - "updateInterval": 60 + "updateInterval": 60, + "showBigWeather": false, + + "minHR": 40, + "maxHR": 200, + "confidence": 0, + "stepGoal": 10000, + "stepDistanceGoal": 8000, + "stepLength": 0.8, + "hrmValidity": 60 + } diff --git a/apps/circlesclock/metadata.json b/apps/circlesclock/metadata.json index 837fcaa88..1b94c00b3 100644 --- a/apps/circlesclock/metadata.json +++ b/apps/circlesclock/metadata.json @@ -1,7 +1,7 @@ { "id": "circlesclock", "name": "Circles clock", "shortName":"Circles clock", - "version":"0.13", + "version":"0.22", "description": "A clock with three or four circles for different data at the bottom in a probably familiar style", "icon": "app.png", "screenshots": [{"url":"screenshot-dark.png"}, {"url":"screenshot-light.png"}, {"url":"screenshot-dark-4.png"}, {"url":"screenshot-light-4.png"}], diff --git a/apps/circlesclock/screenshot-light-with-big-weather.png b/apps/circlesclock/screenshot-light-with-big-weather.png new file mode 100644 index 000000000..d1d569247 Binary files /dev/null and b/apps/circlesclock/screenshot-light-with-big-weather.png differ diff --git a/apps/circlesclock/settings.js b/apps/circlesclock/settings.js index fb23f8d5e..5c5ea4f27 100644 --- a/apps/circlesclock/settings.js +++ b/apps/circlesclock/settings.js @@ -1,6 +1,7 @@ (function(back) { const SETTINGS_FILE = "circlesclock.json"; const storage = require('Storage'); + const clock_info = require("clock_info"); let settings = Object.assign( storage.readJSON("circlesclock.default.json", true) || {}, storage.readJSON(SETTINGS_FILE, true) || {} @@ -11,9 +12,6 @@ storage.write(SETTINGS_FILE, settings); } - const valuesCircleTypes = ["empty", "steps", "stepsDist", "hr", "battery", "weather", "sunprogress", "temperature", "pressure", "altitude"]; - const namesCircleTypes = ["empty", "steps", "distance", "heart", "battery", "weather", "sun", "temperature", "pressure", "altitude"]; - const valuesColors = ["", "#ff0000", "#00ff00", "#0000ff", "#ffff00", "#ff00ff", "#00ffff", "#fff", "#000", "green-red", "red-green", "fg"]; const namesColors = ["default", "red", "green", "blue", "yellow", "magenta", @@ -36,8 +34,6 @@ /*LANG*/'circle 2': ()=>showCircleMenu(2), /*LANG*/'circle 3': ()=>showCircleMenu(3), /*LANG*/'circle 4': ()=>showCircleMenu(4), - /*LANG*/'heartrate': ()=>showHRMenu(), - /*LANG*/'steps': ()=>showStepMenu(), /*LANG*/'battery warn': { value: settings.batteryWarn, min: 10, @@ -68,96 +64,22 @@ return x + 's'; }, onchange: x => save('updateInterval', x), + }, + //TODO deprecated local icons, may disappear in future + /*LANG*/'legacy weather icons': { + value: !!settings.legacyWeatherIcons, + format: () => (settings.legacyWeatherIcons ? 'Yes' : 'No'), + onchange: x => save('legacyWeatherIcons', x), + }, + /*LANG*/'show big weather': { + value: !!settings.showBigWeather, + format: () => (settings.showBigWeather ? 'Yes' : 'No'), + onchange: x => save('showBigWeather', x), } }; E.showMenu(menu); } - function showHRMenu() { - let menu = { - '': { 'title': /*LANG*/'Heartrate' }, - /*LANG*/'< Back': ()=>showMainMenu(), - /*LANG*/'minimum': { - value: settings.minHR, - min: 0, - max : 250, - step: 5, - format: x => { - return x + " bpm"; - }, - onchange: x => save('minHR', x), - }, - /*LANG*/'maximum': { - value: settings.maxHR, - min: 20, - max : 250, - step: 5, - format: x => { - return x + " bpm"; - }, - onchange: x => save('maxHR', x), - }, - /*LANG*/'min. confidence': { - value: settings.confidence, - min: 0, - max : 100, - step: 10, - format: x => { - return x + "%"; - }, - onchange: x => save('confidence', x), - }, - /*LANG*/'valid period': { - value: settings.hrmValidity, - min: 10, - max : 1800, - step: 10, - format: x => { - return x + "s"; - }, - onchange: x => save('hrmValidity', x), - }, - }; - E.showMenu(menu); - } - - function showStepMenu() { - let menu = { - '': { 'title': /*LANG*/'Steps' }, - /*LANG*/'< Back': ()=>showMainMenu(), - /*LANG*/'goal': { - value: settings.stepGoal, - min: 1000, - max : 50000, - step: 500, - format: x => { - return x; - }, - onchange: x => save('stepGoal', x), - }, - /*LANG*/'distance goal': { - value: settings.stepDistanceGoal, - min: 1000, - max : 50000, - step: 500, - format: x => { - return x; - }, - onchange: x => save('stepDistanceGoal', x), - }, - /*LANG*/'step length': { - value: settings.stepLength, - min: 0.1, - max : 1.5, - step: 0.01, - format: x => { - return x; - }, - onchange: x => save('stepLength', x), - } - }; - E.showMenu(menu); - } function showCircleMenu(circleId) { const circleName = "circle" + circleId; const colorKey = circleName + "color"; @@ -166,12 +88,6 @@ const menu = { '': { 'title': /*LANG*/'Circle ' + circleId }, /*LANG*/'< Back': ()=>showMainMenu(), - /*LANG*/'data': { - value: valuesCircleTypes.indexOf(settings[circleName]), - min: 0, max: valuesCircleTypes.length - 1, - format: v => namesCircleTypes[v], - onchange: x => save(circleName, valuesCircleTypes[x]), - }, /*LANG*/'color': { value: valuesColors.indexOf(settings[colorKey]) || 0, min: 0, max: valuesColors.length - 1, @@ -187,6 +103,5 @@ E.showMenu(menu); } - showMainMenu(); }); diff --git a/apps/nato/changelog.txt b/apps/clkinfocal/ChangeLog similarity index 100% rename from apps/nato/changelog.txt rename to apps/clkinfocal/ChangeLog diff --git a/apps/clkinfocal/app.png b/apps/clkinfocal/app.png new file mode 100644 index 000000000..ed79cd884 Binary files /dev/null and b/apps/clkinfocal/app.png differ diff --git a/apps/clkinfocal/clkinfo.js b/apps/clkinfocal/clkinfo.js new file mode 100644 index 000000000..a7949cda4 --- /dev/null +++ b/apps/clkinfocal/clkinfo.js @@ -0,0 +1,32 @@ +(function() { + require("Font4x8Numeric").add(Graphics); + return { + name: "Bangle", + items: [ + { name : "Date", + get : () => { + let d = new Date(); + let g = Graphics.createArrayBuffer(24,24,1,{msb:true}); + g.drawImage(atob("FhgBDADAMAMP/////////////////////8AADwAAPAAA8AADwAAPAAA8AADwAAPAAA8AADwAAPAAA8AADwAAP///////"),1,0); + g.setFont("6x15").setFontAlign(0,0).drawString(d.getDate(),11,17); + return { + text : require("locale").dow(d,1).toUpperCase(), + img : g.asImage("string") + }; + }, + show : function() { + this.interval = setTimeout(()=>{ + this.emit("redraw"); + this.interval = setInterval(()=>{ + this.emit("redraw"); + }, 86400000); + }, 86400000 - (Date.now() % 86400000)); + }, + hide : function() { + clearInterval(this.interval); + this.interval = undefined; + } + } + ] + }; +}) diff --git a/apps/clkinfocal/metadata.json b/apps/clkinfocal/metadata.json new file mode 100644 index 000000000..6d6dd63fc --- /dev/null +++ b/apps/clkinfocal/metadata.json @@ -0,0 +1,12 @@ +{ "id": "clkinfocal", + "name": "Calendar Clockinfo", + "version":"0.01", + "description": "For clocks that display 'clockinfo' (messages that can be cycled through using the clock_info module) this displays the day of the month in the icon, and the weekday", + "icon": "app.png", + "type": "clkinfo", + "tags": "clkinfo,calendar", + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"clkinfocal.clkinfo.js","url":"clkinfo.js"} + ] +} diff --git a/apps/clkinfofw/ChangeLog b/apps/clkinfofw/ChangeLog new file mode 100644 index 000000000..10810802b --- /dev/null +++ b/apps/clkinfofw/ChangeLog @@ -0,0 +1,2 @@ +0.01: First release +0.02: Update clock_info to avoid a redraw and image allocation diff --git a/apps/clkinfofw/app.png b/apps/clkinfofw/app.png new file mode 100644 index 000000000..c6575b73b Binary files /dev/null and b/apps/clkinfofw/app.png differ diff --git a/apps/clkinfofw/clkinfo.js b/apps/clkinfofw/clkinfo.js new file mode 100644 index 000000000..2b3cb32ba --- /dev/null +++ b/apps/clkinfofw/clkinfo.js @@ -0,0 +1,17 @@ +(function() { + return { + name: "Bangle", + items: [ + { name : "FW", + get : () => { + return { + text : process.env.VERSION, + img : atob("GBjC////AADve773VWmmmmlVVW22nnlVVbLL445VVwAAAADVWAAAAAAlrAAAAAA6sAAAAAAOWAAAAAAlrAD//wA6sANVVcAOWANVVcAlrANVVcA6rANVVcA6WANVVcAlsANVVcAOrAD//wA6WAAAAAAlsAAAAAAOrAAAAAA6WAAAAAAlVwAAAADVVbLL445VVW22nnlVVWmmmmlV") + }; + }, + show : function() {}, + hide : function() {} + } + ] + }; +}) diff --git a/apps/clkinfofw/metadata.json b/apps/clkinfofw/metadata.json new file mode 100644 index 000000000..720a5baa5 --- /dev/null +++ b/apps/clkinfofw/metadata.json @@ -0,0 +1,13 @@ +{ "id": "clkinfofw", + "name": "Firmware Clockinfo", + "version":"0.02", + "description": "For clocks that display 'clockinfo', this displays the firmware version string", + "icon": "app.png", + "type": "clkinfo", + "screenshots": [{"url":"screenshot.png"}], + "tags": "clkinfo,firmware", + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"clkinfofw.clkinfo.js","url":"clkinfo.js"} + ] +} diff --git a/apps/clkinfofw/screenshot.png b/apps/clkinfofw/screenshot.png new file mode 100644 index 000000000..da185bd2e Binary files /dev/null and b/apps/clkinfofw/screenshot.png differ diff --git a/apps/clkinfosunrise/ChangeLog b/apps/clkinfosunrise/ChangeLog new file mode 100644 index 000000000..86e7a7fa8 --- /dev/null +++ b/apps/clkinfosunrise/ChangeLog @@ -0,0 +1,4 @@ +0.01: New App! +0.02: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps + Add a 'time' clockinfo that also displays a percentage of day left +0.03: Change 3rd mode to show the time to next sunrise/sunset time (not actual time) diff --git a/apps/clkinfosunrise/app.png b/apps/clkinfosunrise/app.png new file mode 100644 index 000000000..a1d53946d Binary files /dev/null and b/apps/clkinfosunrise/app.png differ diff --git a/apps/clkinfosunrise/clkinfo.js b/apps/clkinfosunrise/clkinfo.js new file mode 100644 index 000000000..22c507f34 --- /dev/null +++ b/apps/clkinfosunrise/clkinfo.js @@ -0,0 +1,76 @@ +(function() { + // get today's sunlight times for lat/lon + var sunrise, sunset, date; + var SunCalc = require("suncalc"); // from modules folder + const locale = require("locale"); + + function calculate() { + var location = require("Storage").readJSON("mylocation.json",1)||{}; + location.lat = location.lat||51.5072; + location.lon = location.lon||0.1276; // London + date = new Date(Date.now()); + var times = SunCalc.getTimes(date, location.lat, location.lon); + sunrise = times.sunrise; + sunset = times.sunset; + /* do we want to re-calculate this every day? Or we just assume + that 'show' will get called once a day? */ + } + + function show() { + this.interval = setTimeout(()=>{ + this.emit("redraw"); + this.interval = setInterval(()=>{ + this.emit("redraw"); + }, 60000); + }, 60000 - (Date.now() % 60000)); + } + function hide() { + clearInterval(this.interval); + this.interval = undefined; + } + + return { + name: "Bangle", + items: [ + { name : "Sunrise", + get : () => { calculate(); + return { text : locale.time(sunrise,1), + img : atob("GBiBAAAAAAAAAAAAAAAYAAA8AAB+AAD/AAAAAAAAAAAAAAAYAAAYAAQYIA4AcAYAYAA8AAB+AAD/AAH/gD///D///AAAAAAAAAAAAA==") }}, + show : show, hide : hide + }, { name : "Sunset", + get : () => { calculate(); + return { text : locale.time(sunset,1), + img : atob("GBiBAAAAAAAAAAAAAAB+AAA8AAAYAAAYAAAAAAAAAAAAAAAYAAAYAAQYIA4AcAYAYAA8AAB+AAD/AAH/gD///D///AAAAAAAAAAAAA==") }}, + show : show, hide : hide + }, { name : "Sunrise/set", // Time in day (uses v/min/max to show percentage through day) + hasRange : true, + get : () => { + calculate(); + let day = true; + let d = date.getTime(); + let dayLength = sunset.getTime()-sunrise.getTime(); + let timeUntil, timeTotal; + if (d < sunrise.getTime()) { + day = false; // early morning + timePast = sunrise.getTime()-d; + timeTotal = 86400000-dayLength; + } else if (d > sunset.getTime()) { + day = false; // evening + timePast = d-sunset.getTime(); + timeTotal = 86400000-dayLength; + } else { // day! + timePast = d-sunrise.getTime(); + timeTotal = dayLength; + } + let v = Math.round(100 * timePast / timeTotal); + let minutesTo = (timeTotal-timePast)/60000; + return { text : (minutesTo>90) ? (Math.round(minutesTo/60)+"h") : (Math.round(minutesTo)+"m"), + v : v, min : 0, max : 100, + img : day ? atob("GBiBAAAYAAAYAAAYAAgAEBwAOAx+MAD/AAH/gAP/wAf/4Af/4Of/5+f/5wf/4Af/4AP/wAH/gAD/AAx+MBwAOAgAEAAYAAAYAAAYAA==") : atob("GBiBAAfwAA/8AAP/AAH/gAD/wAB/wAB/4AA/8AA/8AA/8AAf8AAf8AAf8AAf8AA/8AA/8AA/4AB/4AB/wAD/wAH/gAf/AA/8AAfwAA==") + } + }, + show : show, hide : hide + } + ] + }; +}) diff --git a/apps/clkinfosunrise/metadata.json b/apps/clkinfosunrise/metadata.json new file mode 100644 index 000000000..d130c6453 --- /dev/null +++ b/apps/clkinfosunrise/metadata.json @@ -0,0 +1,12 @@ +{ "id": "clkinfosunrise", + "name": "Sunrise Clockinfo", + "version":"0.03", + "description": "For clocks that display 'clockinfo' (messages that can be cycled through using the clock_info module) this displays sunrise and sunset based on the location from the 'My Location' app", + "icon": "app.png", + "type": "clkinfo", + "tags": "clkinfo,sunrise", + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"sunrise.clkinfo.js","url":"clkinfo.js"} + ] +} diff --git a/apps/clockcal/ChangeLog b/apps/clockcal/ChangeLog index 20a46b5b7..27d4fc7f4 100644 --- a/apps/clockcal/ChangeLog +++ b/apps/clockcal/ChangeLog @@ -2,3 +2,5 @@ 0.02: Added scrollable calendar and swipe gestures 0.03: Configurable drag gestures 0.04: Use default Bangle formatter for booleans +0.05: Improved colors (connected vs disconnected) +0.06: Tell clock widgets to hide. diff --git a/apps/clockcal/app.js b/apps/clockcal/app.js index 5e8c7f796..58ddd7ef5 100644 --- a/apps/clockcal/app.js +++ b/apps/clockcal/app.js @@ -1,3 +1,4 @@ +Bangle.setUI("clock"); Bangle.loadWidgets(); var s = Object.assign({ @@ -123,7 +124,7 @@ function drawMinutes() { var d = new Date(); var hours = s.MODE24 ? d.getHours().toString().padStart(2, ' ') : ((d.getHours() + 24) % 12 || 12).toString().padStart(2, ' '); var minutes = d.getMinutes().toString().padStart(2, '0'); - var textColor = NRF.getSecurityStatus().connected ? '#fff' : '#f00'; + var textColor = NRF.getSecurityStatus().connected ? '#99f' : '#fff'; var size = 50; var clock_x = (w - 20) / 2; if (dimSeconds) { @@ -307,4 +308,4 @@ NRF.on('disconnect', BTevent); dimSeconds = Bangle.isLocked(); drawWatch(); -Bangle.setUI("clock"); + diff --git a/apps/clockcal/metadata.json b/apps/clockcal/metadata.json index 6d547a7a3..872211495 100644 --- a/apps/clockcal/metadata.json +++ b/apps/clockcal/metadata.json @@ -1,7 +1,7 @@ { "id": "clockcal", "name": "Clock & Calendar", - "version": "0.04", + "version": "0.06", "description": "Clock with Calendar", "readme":"README.md", "icon": "app.png", diff --git a/apps/color_catalog/Changelog b/apps/color_catalog/ChangeLog similarity index 100% rename from apps/color_catalog/Changelog rename to apps/color_catalog/ChangeLog diff --git a/apps/colorful_clock/ChangeLog b/apps/colorful_clock/ChangeLog new file mode 100644 index 000000000..54ee389e3 --- /dev/null +++ b/apps/colorful_clock/ChangeLog @@ -0,0 +1,3 @@ +... +0.03: First update with ChangeLog Added +0.04: Tell clock widgets to hide. diff --git a/apps/colorful_clock/app.js b/apps/colorful_clock/app.js index afc6b321f..ba6272e9b 100644 --- a/apps/colorful_clock/app.js +++ b/apps/colorful_clock/app.js @@ -3,6 +3,8 @@ let outerRadius = Math.min(CenterX,CenterY) * 0.9; + Bangle.setUI('clock'); + Bangle.loadWidgets(); /**** updateClockFaceSize ****/ @@ -241,7 +243,3 @@ refreshDisplay(); } }); - - Bangle.loadWidgets(); - - Bangle.setUI('clock'); diff --git a/apps/colorful_clock/metadata.json b/apps/colorful_clock/metadata.json index 5b6dbe87e..237acf81c 100644 --- a/apps/colorful_clock/metadata.json +++ b/apps/colorful_clock/metadata.json @@ -1,7 +1,7 @@ { "id": "colorful_clock", "name": "Colorful Analog Clock", "shortName":"Colorful Clock", - "version":"0.03", + "version":"0.04", "description": "a colorful analog clock", "icon": "app-icon.png", "type": "clock", diff --git a/apps/compass/ChangeLog b/apps/compass/ChangeLog index deb1072f5..cb1c6d463 100644 --- a/apps/compass/ChangeLog +++ b/apps/compass/ChangeLog @@ -5,3 +5,4 @@ 0.05: Fix bearing not clearing correctly (visible in single or double digit bearings) 0.06: Add button for force compass calibration 0.07: Use 360-heading to output the correct heading value (fix #1866) +0.08: Added adjustment for Bangle.js magnetometer heading fix diff --git a/apps/compass/compass.js b/apps/compass/compass.js index dd398ffa6..9a7aec2fc 100644 --- a/apps/compass/compass.js +++ b/apps/compass/compass.js @@ -20,7 +20,7 @@ ag.setColor(1).fillCircle(AGM,AGM,AGM-1,AGM-1); ag.setColor(0).fillCircle(AGM,AGM,AGM-11,AGM-11); function arrow(r,c) { - r=r*Math.PI/180; + r=(360-r)*Math.PI/180; var p = Math.PI/2; ag.setColor(c).fillPoly([ AGM+AGH*Math.sin(r), AGM-AGH*Math.cos(r), @@ -34,7 +34,7 @@ var oldHeading = 0; Bangle.on('mag', function(m) { if (!Bangle.isLCDOn()) return; g.reset(); - if (isNaN(m.heading)) { + if (isNaN(m.heading)) { if (!wasUncalibrated) { g.clearRect(0,24,W,48); g.setFontAlign(0,-1).setFont("6x8"); @@ -49,7 +49,7 @@ Bangle.on('mag', function(m) { g.setFontAlign(0,0).setFont("6x8",3); var y = 36; g.clearRect(M-40,24,M+40,48); - g.drawString(Math.round(360-m.heading),M,y,true); + g.drawString(Math.round(m.heading),M,y,true); } diff --git a/apps/compass/metadata.json b/apps/compass/metadata.json index a3995a123..1a614e1f8 100644 --- a/apps/compass/metadata.json +++ b/apps/compass/metadata.json @@ -1,7 +1,7 @@ { "id": "compass", "name": "Compass", - "version": "0.07", + "version": "0.08", "description": "Simple compass that points North", "icon": "compass.png", "screenshots": [{"url":"screenshot_compass.png"}], diff --git a/apps/configurable_clock/ChangeLog b/apps/configurable_clock/ChangeLog new file mode 100644 index 000000000..9d55c1a91 --- /dev/null +++ b/apps/configurable_clock/ChangeLog @@ -0,0 +1,3 @@ +... +0.02: First update with ChangeLog Added +0.03: Tell clock widgets to hide. diff --git a/apps/configurable_clock/app.js b/apps/configurable_clock/app.js index 157d57741..45c86c7e9 100644 --- a/apps/configurable_clock/app.js +++ b/apps/configurable_clock/app.js @@ -5,6 +5,7 @@ let ScreenWidth = g.getWidth(), CenterX; let ScreenHeight = g.getHeight(), CenterY, outerRadius; + Bangle.setUI('clock'); Bangle.loadWidgets(); /**** updateClockFaceSize ****/ @@ -1377,4 +1378,3 @@ } }); - Bangle.setUI('clock'); diff --git a/apps/configurable_clock/metadata.json b/apps/configurable_clock/metadata.json index 28feae7e4..687a5b212 100644 --- a/apps/configurable_clock/metadata.json +++ b/apps/configurable_clock/metadata.json @@ -1,7 +1,7 @@ { "id": "configurable_clock", "name": "Configurable Analog Clock", "shortName":"Configurable Clock", - "version":"0.02", + "version":"0.03", "description": "an analog clock with several kinds of faces, hands and colors to choose from", "icon": "app-icon.png", "type": "clock", diff --git a/apps/contourclock/ChangeLog b/apps/contourclock/ChangeLog index d415a604d..387340d5b 100644 --- a/apps/contourclock/ChangeLog +++ b/apps/contourclock/ChangeLog @@ -7,3 +7,4 @@ 0.25: Fixed a bug that would let widgets change the color of the clock. 0.26: Time formatted to locale 0.27: Fixed the timing code, which sometimes did not update for one minute +0.28: More config options for cleaner look, enabled fast loading diff --git a/apps/contourclock/README.md b/apps/contourclock/README.md new file mode 100644 index 000000000..3341439da --- /dev/null +++ b/apps/contourclock/README.md @@ -0,0 +1,6 @@ +# New Features: +- Fast load! (only works if your launcher uses widgets) +- widgets, date and weekday are individually configurable +- you can hide widgets, date and weekday for a cleaner look when the watch is locked + +Contact me for bug reports or feature requests: ContourClock@gmx.de diff --git a/apps/contourclock/app.js b/apps/contourclock/app.js index d5c97edfa..8efa406c6 100644 --- a/apps/contourclock/app.js +++ b/apps/contourclock/app.js @@ -1,35 +1,64 @@ -var digits = []; -var drawTimeout; -var fontName=""; -var settings = require('Storage').readJSON("contourclock.json", true) || {}; -if (settings.fontIndex==undefined) { - settings.fontIndex=0; - require('Storage').writeJSON("myapp.json", settings); -} +{ + let digits = []; + let drawTimeout; + let fontName=""; + let settings = require('Storage').readJSON("contourclock.json", true) || {}; + if (settings.fontIndex==undefined) { + settings.fontIndex=0; + settings.widgets=true; + settings.hide=false; + settings.weekday=true; + settings.hideWhenLocked=false; + settings.date=true; require('Storage').writeJSON("myapp.json", settings); + } -function queueDraw() { - setTimeout(function() { + let queueDraw = function() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + queueDraw(); + }, 60000 - (Date.now() % 60000)); + }; + + let draw = function() { + var date = new Date(); + // Draw day of the week + g.reset(); + if ((!settings.hideWhenLocked) || (!Bangle.isLocked())) { + // Draw day of the week + g.setFont("Teletext10x18Ascii"); + g.clearRect(0,138,g.getWidth()-1,176); + if (settings.weekday) g.setFontAlign(0,1).drawString(require("locale").dow(date).toUpperCase(),g.getWidth()/2,g.getHeight()-18); + // Draw Date + if (settings.date) g.setFontAlign(0,1).drawString(require('locale').date(new Date(),1),g.getWidth()/2,g.getHeight()); + } + require('contourclock').drawClock(settings.fontIndex); + }; + + require("FontTeletext10x18Ascii").add(Graphics); + g.clear(); + + draw(); + if (settings.hideWhenLocked) Bangle.on('lock', function (locked) { + if (!locked) require("widget_utils").show(); + else { + g.clear(); + if (settings.hide) require("widget_utils").swipeOn(); + else require("widget_utils").hide(); + } draw(); - queueDraw(); - }, 60000 - (Date.now() % 60000)); + }); + Bangle.setUI({mode:"clock", remove:function() { + if (drawTimeout) clearTimeout(drawTimeout); + if (settings.widgets && settings.hide) require("widget_utils").show(); + g.reset(); + g.clear(); + }}); + if (settings.widgets) { + Bangle.loadWidgets(); + if (settings.hide) require("widget_utils").swipeOn(); + else Bangle.drawWidgets(); + } + queueDraw(); } - -function draw() { - var date = new Date(); - // Draw day of the week - g.reset(); - g.setFont("Teletext10x18Ascii"); - g.clearRect(0,138,g.getWidth()-1,176); - g.setFontAlign(0,1).drawString(require("locale").dow(date).toUpperCase(),g.getWidth()/2,g.getHeight()-18); - // Draw Date - g.setFontAlign(0,1).drawString(require('locale').date(new Date(),1),g.getWidth()/2,g.getHeight()); - require('contourclock').drawClock(settings.fontIndex); -} - -require("FontTeletext10x18Ascii").add(Graphics); -Bangle.setUI("clock"); -g.clear(); -Bangle.loadWidgets(); -Bangle.drawWidgets(); -queueDraw(); -draw(); diff --git a/apps/contourclock/contourclock.settings.js b/apps/contourclock/contourclock.settings.js index a12538fc5..f2a75d9b5 100644 --- a/apps/contourclock/contourclock.settings.js +++ b/apps/contourclock/contourclock.settings.js @@ -1,43 +1,73 @@ (function(back) { - Bangle.removeAllListeners('drag'); Bangle.setUI(""); var settings = require('Storage').readJSON('contourclock.json', true) || {}; if (settings.fontIndex==undefined) { - settings.fontIndex=0; + settings.fontIndex=0; + settings.widgets=true; + settings.hide=false; + settings.weekday=true; + settings.date=true; + settings.hideWhenLocked=false; require('Storage').writeJSON("myapp.json", settings); } - savedIndex=settings.fontIndex; - saveListener = setWatch(function() { //save changes and return to settings menu - require('Storage').writeJSON('contourclock.json', settings); - Bangle.removeAllListeners('swipe'); - Bangle.removeAllListeners('lock'); - clearWatch(saveListener); - g.clear(); - back(); - }, BTN, { repeat:false, edge:'falling' }); - lockListener = Bangle.on('lock', function () { //discard changes and return to clock - settings.fontIndex=savedIndex; - require('Storage').writeJSON('contourclock.json', settings); - Bangle.removeAllListeners('swipe'); - Bangle.removeAllListeners('lock'); - clearWatch(saveListener); - g.clear(); - load(); - }); - swipeListener = Bangle.on('swipe', function (direction) { - var fontName = require('contourclock').drawClock(settings.fontIndex+direction); - if (fontName) { - settings.fontIndex+=direction; - g.clearRect(0,0,g.getWidth()-1,16); - g.setFont('6x8:2x2').setFontAlign(0,-1).drawString(fontName,g.getWidth()/2,0); - } else { - require('contourclock').drawClock(settings.fontIndex); - } - }); - g.reset(); - g.clear(); - g.setFont('6x8:2x2').setFontAlign(0,-1); - g.drawString(require('contourclock').drawClock(settings.fontIndex),g.getWidth()/2,0); - g.drawString('Swipe - change',g.getWidth()/2,g.getHeight()-36); - g.drawString('BTN - save',g.getWidth()/2,g.getHeight()-18); + function mainMenu() { + E.showMenu({ + "" : { "title" : "ContourClock" }, + "< Back" : () => back(), + 'Widgets': { + value: (settings.widgets !== undefined ? settings.widgets : true), + onchange : v => {settings.widgets=v; require('Storage').writeJSON('contourclock.json', settings);} + }, + 'hide Widgets': { + value: (settings.hide !== undefined ? settings.hide : false), + onchange : v => {settings.hide=v; require('Storage').writeJSON('contourclock.json', settings);} + }, + 'Weekday': { + value: (settings.weekday !== undefined ? settings.weekday : true), + onchange : v => {settings.weekday=v; require('Storage').writeJSON('contourclock.json', settings);} + }, + 'Date': { + value: (settings.date !== undefined ? settings.date : true), + onchange : v => {settings.date=v; require('Storage').writeJSON('contourclock.json', settings);} + }, + 'Hide when locked': { + value: (settings.hideWhenLocked !== undefined ? settings.hideWhenLocked : false), + onchange : v => {settings.hideWhenLocked=v; require('Storage').writeJSON('contourclock.json', settings);} + }, + 'set Font': () => fontMenu() + }); + } + function fontMenu() { + Bangle.setUI(""); + savedIndex=settings.fontIndex; + saveListener = setWatch(function() { //save changes and return to settings menu + require('Storage').writeJSON('contourclock.json', settings); + Bangle.removeAllListeners('swipe'); + Bangle.removeAllListeners('lock'); + mainMenu(); + }, BTN, { repeat:false, edge:'falling' }); + lockListener = Bangle.on('lock', function () { //discard changes and return to clock + settings.fontIndex=savedIndex; + require('Storage').writeJSON('contourclock.json', settings); + Bangle.removeAllListeners('swipe'); + Bangle.removeAllListeners('lock'); + mainMenu(); + }); + swipeListener = Bangle.on('swipe', function (direction) { + var fontName = require('contourclock').drawClock(settings.fontIndex+direction); + if (fontName) { + settings.fontIndex+=direction; + g.clearRect(0,g.getHeight()-36,g.getWidth()-1,g.getHeight()-36+16); + g.setFont('6x8:2x2').setFontAlign(0,-1).drawString(fontName,g.getWidth()/2,g.getHeight()-36); + } else { + require('contourclock').drawClock(settings.fontIndex); + } + }); + g.reset(); + g.clearRect(0,24,g.getWidth()-1,g.getHeight()-1); + g.setFont('6x8:2x2').setFontAlign(0,-1); + g.drawString(require('contourclock').drawClock(settings.fontIndex),g.getWidth()/2,g.getHeight()-36); + g.drawString('Button to save',g.getWidth()/2,g.getHeight()-18); + } + mainMenu(); }) diff --git a/apps/contourclock/metadata.json b/apps/contourclock/metadata.json index eb0dd39fb..6b2b51991 100644 --- a/apps/contourclock/metadata.json +++ b/apps/contourclock/metadata.json @@ -1,9 +1,10 @@ { "id": "contourclock", "name": "Contour Clock", "shortName" : "Contour Clock", - "version":"0.27", + "version":"0.28", "icon": "app.png", - "description": "A Minimalist clockface with large Digits. Now with more fonts!", + "readme": "README.md", + "description": "A Minimalist clockface with large Digits.", "screenshots" : [{"url":"cc-screenshot-1.png"},{"url":"cc-screenshot-2.png"}], "tags": "clock", "custom": "custom.html", diff --git a/apps/counter/ChangeLog b/apps/counter/ChangeLog index f3f1c4eac..8402b3467 100644 --- a/apps/counter/ChangeLog +++ b/apps/counter/ChangeLog @@ -1,3 +1,4 @@ 0.01: New App! 0.02: Added decrement and touch functions 0.03: Set color - ensures widgets don't end up coloring the counter's text +0.04: Adopted for BangleJS 2 diff --git a/apps/counter/counter.js b/apps/counter/counter.js index 3e0687944..0054ada6d 100644 --- a/apps/counter/counter.js +++ b/apps/counter/counter.js @@ -1,45 +1,104 @@ var counter = 0; +const BANGLEJS2 = process.env.HWVERSION == 2; + +if (BANGLEJS2) { + var drag; + var y = 45; + var x = 5; +} else { + var y = 100; + var x = 25; +} function updateScreen() { - g.clearRect(0, 50, 250, 150); - g.setColor(0xFFFF); + if (BANGLEJS2) { + g.clearRect(0, 50, 250, 130); + } else { + g.clearRect(0, 50, 250, 150); + } + g.setBgColor(g.theme.bg).setColor(g.theme.fg); g.setFont("Vector",40).setFontAlign(0,0); g.drawString(Math.floor(counter), g.getWidth()/2, 100); - g.drawString('-', 45, 100); - g.drawString('+', 185, 100); + if (!BANGLEJS2) { + g.drawString('-', 45, 100); + g.drawString('+', 185, 100); + } } -// add a count by using BTN1 or BTN5 -setWatch(() => { - counter += 1; - updateScreen(); -}, BTN1, {repeat:true}); +if (BANGLEJS2) { + setWatch(() => { + counter = 0; + updateScreen(); + }, BTN1, {repeat:true}); + Bangle.on("drag", e => { + if (!drag) { // start dragging + drag = {x: e.x, y: e.y}; + } else if (!e.b) { // released + const dx = e.x-drag.x, dy = e.y-drag.y; + drag = null; + if (Math.abs(dx)>Math.abs(dy)+10) { + // horizontal + if (dx < dy) { + //console.log("left " + dx + " " + dy); + } else { + //console.log("right " + dx + " " + dy); + } + } else if (Math.abs(dy)>Math.abs(dx)+10) { + // vertical + if (dx < dy) { + //console.log("down " + dx + " " + dy); + if (counter > 0) counter -= 1; + updateScreen(); + } else { + //console.log("up " + dx + " " + dy); + counter += 1; + updateScreen(); + } + } else { + //console.log("tap " + e.x + " " + e.y); + } + } + }); + } else { -setWatch(() => { - counter += 1; - updateScreen(); -}, BTN5, {repeat:true}); + // add a count by using BTN1 or BTN5 + setWatch(() => { + counter += 1; + updateScreen(); + }, BTN1, {repeat:true}); + + setWatch(() => { + counter += 1; + updateScreen(); + }, BTN5, {repeat:true}); + + // subtract a count by using BTN3 or BTN4 + setWatch(() => { + if (counter > 0) counter -= 1; + updateScreen(); + }, BTN4, {repeat:true}); + + setWatch(() => { + if (counter > 0) counter -= 1; + updateScreen(); + }, BTN3, {repeat:true}); + + // reset by using BTN2 + setWatch(() => { + counter = 0; + updateScreen(); + }, BTN2, {repeat:true}); +} -// subtract a count by using BTN3 or BTN4 -setWatch(() => { - counter -= 1; - updateScreen(); -}, BTN4, {repeat:true}); - -setWatch(() => { - counter -= 1; - updateScreen(); -}, BTN3, {repeat:true}); - -// reset by using BTN2 -setWatch(() => { - counter = 0; - updateScreen(); -}, BTN2, {repeat:true}); g.clear(1).setFont("6x8"); -g.drawString('Tap right or BTN1 to increase\nTap left or BTN3 to decrease\nPress BTN2 to reset.', 25, 200); +g.setBgColor(g.theme.bg).setColor(g.theme.fg); +if (BANGLEJS2) { + g.drawString('Swipe up to increase\nSwipe down to decrease\nPress button to reset.', x, 100 + y); +} else { + g.drawString('Tap right or BTN1 to increase\nTap left or BTN3 to decrease\nPress BTN2 to reset.', x, 100 + y); +} Bangle.loadWidgets(); Bangle.drawWidgets(); diff --git a/apps/counter/metadata.json b/apps/counter/metadata.json index e455fda95..daba58d39 100644 --- a/apps/counter/metadata.json +++ b/apps/counter/metadata.json @@ -1,11 +1,11 @@ { "id": "counter", "name": "Counter", - "version": "0.03", + "version": "0.04", "description": "Simple counter", "icon": "counter_icon.png", "tags": "tool", - "supports": ["BANGLEJS"], + "supports": ["BANGLEJS", "BANGLEJS2"], "screenshots": [{"url":"bangle1-counter-screenshot.png"}], "allow_emulator": true, "storage": [ diff --git a/apps/crowclk/ChangeLog b/apps/crowclk/ChangeLog index 4f48bdd14..1c4f6f43b 100644 --- a/apps/crowclk/ChangeLog +++ b/apps/crowclk/ChangeLog @@ -1,3 +1,4 @@ 0.01: New App! 0.02: Removed "wake LCD on face-up"-feature: A watch-face should not set things like "wake LCD on face-up". 0.03: Fix the clock for dark mode. +0.04: Tell clock widgets to hide. diff --git a/apps/crowclk/crow_clock.js b/apps/crowclk/crow_clock.js index eee1653cb..7e608ef19 100644 --- a/apps/crowclk/crow_clock.js +++ b/apps/crowclk/crow_clock.js @@ -136,9 +136,9 @@ Bangle.on('lcdPower', (on) => { g.clear(); +// Show launcher when button pressed +Bangle.setUI("clock"); Bangle.loadWidgets(); Bangle.drawWidgets(); startTimers(); -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/crowclk/metadata.json b/apps/crowclk/metadata.json index 6985cf11a..265a0398b 100644 --- a/apps/crowclk/metadata.json +++ b/apps/crowclk/metadata.json @@ -1,7 +1,7 @@ { "id": "crowclk", "name": "Crow Clock", - "version": "0.03", + "version": "0.04", "description": "A simple clock based on Bold Clock that has MST3K's Crow T. Robot for a face", "icon": "crow_clock.png", "screenshots": [{"url":"screenshot_crow.png"}], diff --git a/apps/daisy/ChangeLog b/apps/daisy/ChangeLog index 829ff3d13..61a09a18d 100644 --- a/apps/daisy/ChangeLog +++ b/apps/daisy/ChangeLog @@ -5,3 +5,5 @@ 0.05: changed text to uppercase, just looks better, removed colons on text 0.06: better contrast for light theme, use fg color instead of dithered for ring 0.07: Use default Bangle formatter for booleans +0.08: fix idle timer always getting set to true +0.09: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps diff --git a/apps/daisy/app.js b/apps/daisy/app.js index 7c513726f..c99b19228 100644 --- a/apps/daisy/app.js +++ b/apps/daisy/app.js @@ -1,4 +1,4 @@ -var SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js"); +var SunCalc = require("suncalc"); // from modules folder const storage = require('Storage'); const locale = require("locale"); const SETTINGS_FILE = "daisy.json"; @@ -70,7 +70,7 @@ function getSteps() { try { return Bangle.getHealthStatus("day").steps; } catch (e) { - if (WIDGETS.wpedom !== undefined) + if (WIDGETS.wpedom !== undefined) return WIDGETS.wpedom.getSteps(); else return 0; @@ -83,7 +83,7 @@ function loadSettings() { settings = require("Storage").readJSON(SETTINGS_FILE,1)||{}; settings.gy = settings.gy||'#020'; settings.fg = settings.fg||'#0f0'; - settings.idle_check = settings.idle_check||true; + settings.idle_check = (settings.idle_check === undefined ? true : settings.idle_check); assignPalettes(); } @@ -151,7 +151,7 @@ function prevInfo() { function clearInfo() { g.setColor(g.theme.bg); //g.setColor(g.theme.fg); - g.fillRect((w/2) - infoWidth, infoLine - infoHeight, (w/2) + infoWidth, infoLine + infoHeight); + g.fillRect((w/2) - infoWidth, infoLine - infoHeight, (w/2) + infoWidth, infoLine + infoHeight); } function drawInfo() { @@ -202,7 +202,7 @@ function drawClock() { var mm = da[4].substr(3,2); var steps = getSteps(); var p_steps = Math.round(100*(steps/10000)); - + g.reset(); g.setColor(g.theme.bg); g.fillRect(0, 0, w, h); @@ -218,7 +218,7 @@ function drawClock() { g.drawString(mm, (w/2) + 1, h/2); drawInfo(); - + // recalc sunrise / sunset every hour if (drawCount % 60 == 0) updateSunRiseSunSet(new Date(), location.lat, location.lon); @@ -254,7 +254,7 @@ function resetHrm() { Bangle.on('HRM', function(hrm) { hrmCurrent = hrm.bpm; hrmConfidence = hrm.confidence; - log_debug("HRM=" + hrm.bpm + " (" + hrm.confidence + ")"); + log_debug("HRM=" + hrm.bpm + " (" + hrm.confidence + ")"); if (infoMode == "ID_HRM" ) drawHrm(); }); @@ -360,7 +360,7 @@ function getGaugeImage(p) { palette : pal2, buffer : require("heatshrink").decompress(atob("AH4A/AH4AChWq1WpqtUFUgpBFYYABoApggQqDFYlVqBVjFYxZfFQorGLLrWCFZbgbVguoBQcFLD8qFQYMHiosDKzoOJFgZYYKwYPLFgZWawARMLDJWCawgAJcAZWYCZ6FCLCkKFQOgCZ8BFYNUFaZWSLAlAQShWQLAiESQQRtTLAKESFQOoFacFQiSCCwArTgCESQSyEUlTZTboyCnQiSCYQiSCYQiSCZQgdAVxwqYQgSwMVwOoFbMFWBquaWCArBVzKwDbRoqaWATcKbQKuaWAbcKbQKuaWAbcKVzqwNFYIqcWATaKVziwDbhDaebhjaebhgrBbTrcCFZDafbheqFcTcHbT7cDFY0CbT7cDqArxhWqwArfgFVqgrHFUDcBFY0qFcdVFY2oFcMFFY2qFclAFYugFcMBFYsCFctQFYuAFcMAFYsKFctUFYoqigEVFeEqFctVFYmoFccFFYmqFc1AcIdQFccBFf4rbGAoAhKQYr/Fa8FFc9UFYYqkgEVFf4r/FYwDDAEZTDFf4r/Ff4rbqorooArBqArlgIr/Ff4r/Ff4r/Ff4r/Ff4r/Ff4r/Ff4rbqgrlgorCioroAYIr/Ff4r/FbYDDAEZTDFf4r/FYtAFclVFYUBFc9QFf4rZAgoAgKQor/FbFUFccFFYkVFcwFDioFEAD4lFGIorgPogrtWoYAfqorEgIrlqArFAwgAdEg4rlPgqKFADrUHcQorfA4sVA4wAbEY4zHFbh7GRY4AbaY7jBqAqfERArrMBAAZUxNVbkEVFZAJBFcJhRAC6lJFYLcebQIrIBRTaXJhIrhUhLcfD5YLBbjtVFZTceZ5jceJRpkLVyaiLWDpJNFYKwaUIIrMSIKwaDhw6OVx50NFYKwZDZ6waOaCTBQjBGBZZw8CQi4ZBOR6EYeySEYQSCEaQSITDH6BvGIaKEWQSSEEbqQVVQgRYSKwLGUQgRCQKwTFUC4RYQKwSCTDAhEONQTwULAqcNCARWVLAhGMB55YPDhQqDKy4dFFhAMMLCzgFawZWbEI4AIGogAYFZtAFbgsMFTyyGVkBZOKr7gJazoA/AHIA=")) }; - + // p90 if (p >= 90 && p < 100) return { width : 176, height : 176, bpp : 2, @@ -410,7 +410,7 @@ function BUTTON(name,x,y,w,h,c,f,tx) { // if pressed the callback BUTTON.prototype.check = function(x,y) { //console.log(this.name + ":check() x=" + x + " y=" + y +"\n"); - + if (x>= this.x && x<= (this.x + this.w) && y>= this.y && y<= (this.y + this.h)) { log_debug(this.name + ":callback\n"); this.callback(); @@ -472,7 +472,7 @@ function checkIdle() { warned = false; return; } - + let hour = (new Date()).getHours(); let active = (hour >= 9 && hour < 21); //let active = true; @@ -501,7 +501,7 @@ function buzzer(n) { if (n-- < 1) return; Bangle.buzz(250); - + if (buzzTimeout) clearTimeout(buzzTimeout); buzzTimeout = setTimeout(function() { buzzTimeout = undefined; diff --git a/apps/daisy/metadata.json b/apps/daisy/metadata.json index 802ba6834..0bad50151 100644 --- a/apps/daisy/metadata.json +++ b/apps/daisy/metadata.json @@ -1,6 +1,6 @@ { "id": "daisy", "name": "Daisy", - "version":"0.07", + "version":"0.09", "dependencies": {"mylocation":"app"}, "description": "A beautiful digital clock with large ring guage, idle timer and a cyclic information line that includes, day, date, steps, battery, sunrise and sunset times", "icon": "app.png", diff --git a/apps/deko/Building_Typeface.ttf b/apps/deko/Building_Typeface.ttf new file mode 100644 index 000000000..d5a3933ab Binary files /dev/null and b/apps/deko/Building_Typeface.ttf differ diff --git a/apps/deko/ChangeLog b/apps/deko/ChangeLog new file mode 100644 index 000000000..9db0e26c5 --- /dev/null +++ b/apps/deko/ChangeLog @@ -0,0 +1 @@ +0.01: first release diff --git a/apps/deko/README.md b/apps/deko/README.md new file mode 100644 index 000000000..91e83bd23 --- /dev/null +++ b/apps/deko/README.md @@ -0,0 +1,10 @@ +# Deko Clock + +A simple clock with an Art Deko font + +The font was obtained from https://dafonttop.com/building.font and is free for personal use + + +![](screenshot.png) + +Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/) diff --git a/apps/deko/app-icon.js b/apps/deko/app-icon.js new file mode 100644 index 000000000..06f93e2ef --- /dev/null +++ b/apps/deko/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwIdah/wAof//4ECgYFB4AFBg4FB8AFBj/wh/4AoM/wEB/gFBvwCEBAU/AQP4gfAj8AgPwAoMPwED8AFBg/AAYIBDA4ngg4TB4EBApkPKgJSBJQIFTMgIFCJIIFDKoIFEvgFBGoMAnw7DP4IFEh+BAoItBg+DNIQwBMIaeCKoKxCPoIzCEgKVHUIqtFXIrFFaIrdFdIwAV")) diff --git a/apps/deko/app.js b/apps/deko/app.js new file mode 100644 index 000000000..8ae2c1d31 --- /dev/null +++ b/apps/deko/app.js @@ -0,0 +1,64 @@ +Graphics.prototype.setFontBuildingTypeface = function(scale) { + // Actual height 100 (102 - 3) + this.setFontCustom( + atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAf+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHgAAAAAAAAAAAAAAAAAAH/gAAAAAAAAAAAAAAAAAH//gAAAAAAAAAAAAAAAAD///gAAAAAAAAAAAAAAAD////gAAAAAAAAAAAAAAD/////gAAAAAAAAAAAAAB//////gAAAAAAAAAAAAB///////gAAAAAAAAAAAB////////gAAAAAAAAAAA////////4AAAAAAAAAAA////////4AAAAAAAAAAAf///////8AAAAAAAAAAAf///////8AAAAAAAAAAAf///////8AAAAAAAAAAAP///////+AAAAAAAAAAAP///////+AAAAAAAAAAAP///////+AAAAAAAAAAAH////////AAAAAAAAAAAAH///////AAAAAAAAAAAAAH//////AAAAAAAAAAAAAAH/////gAAAAAAAAAAAAAAH////gAAAAAAAAAAAAAAAH///wAAAAAAAAAAAAAAAAH//wAAAAAAAAAAAAAAAAAH/wAAAAAAAAAAAAAAAAAAH4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////AAAAAAAD/////////////wAAAAAAP/////////////4AAAAAAP/////////////8AAAAAAf/////////////+AAAAAAf/////////////+AAAAAA///////////////AAAAAA///////////////AAAAAA///////////////AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA/4AAAAAAAAAAAH/AAAAAA///////////////AAAAAA///////////////AAAAAA///////////////AAAAAA///////////////AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAP/////////////8AAAAAAH/////////////4AAAAAAD/////////////wAAAAAAA/////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP4AAAAAAAAAAAAAAAAAAAf4AAAAAAAAAAAAAAAAAAA/4AAAAAAAAAAAAAAAAAAB/4AAAAAAAAAAAAAAAAAAD/4AAAAAAAAAAAAAAAAAAH/4AAAAAAAAAAAAAAAAAAf/4AAAAAAAAAAAAAAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/wAAf///////+AAAAAAB//wAB////////+AAAAAAH//wAD////////+AAAAAAH//wAH////////+AAAAAAP//wAP////////+AAAAAAf//wAP////////+AAAAAAf//wAP////////+AAAAAAf//wAf////////+AAAAAAf//wAf////////+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf8AAAf8AAAAAAP+AAAAAAf/////8AAAA///+AAAAAAf/////8AAAA///+AAAAAAf/////8AAAA///+AAAAAAf/////8AAAA///+AAAAAAP/////8AAAA///+AAAAAAH/////8AAAA///+AAAAAAH/////8AAAA///+AAAAAAB/////8AAAA///+AAAAAAAf////8AAAA///+AAAAAAAAAAAAAAAAA///+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf//gAAAAAAAf//+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf//wAAAAAAA///+AAAAAAf8AAAAAAAAAAAP+AAAAAAf8AAAAAAAAAAAP+AAAAAAf8AAAAAAAAAAAP+AAAAAAf8AAAAEAAAAAAP+AAAAAAf8AAAB8AAAAAAP+AAAAAAf8AAAP8AAAAAAP+AAAAAAf8AAD/8AAAAAAP+AAAAAAf8AA//8AAAAAAP+AAAAAAf8AP//8AAAAAAP+AAAAAAf8B///8AAAAAAP+AAAAAAf8f///8AAAAAAP+AAAAAAf/////8AAAAAAP+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf///8P////////+AAAAAAf///gH////////+AAAAAAf//4AD////////+AAAAAAf/+AAB////////+AAAAAAf/gAAA////////+AAAAAAfwAAAAD///////+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/gAAAAAAAAAAAAAAAAAB//gAAAAAAAAAAAAAAAAAH//gAAAAAAAAAAAAAAAAA///gAAAAAAAAAAAAAAAAH///gAAAAAAAAAAAAAAAAf///gAAAAAAAAAAAAAAAD////gAAAAAAAAAAAAAAAf////gAAAAAAAAAAAAAAB/////gAAAAAAAAAAAAAAP///z/gAAAAAAAAAAAAAB///+D/gAAAAAAAAAAAAAH///wD/gAAAAAAAAAAAAA///+AD/gAAAAAAAAAAAAH///wAD/gAAAAAAAAAAAAf//+AAD/gAAAAAAAAAAAD///wAAD/gAAAAAAAAAAAf///AAAD/gAAAAAAAAAAB///4AAAD/gAAAAAAAAAAP///AAAAD/gAAAAAAAAAB///4AAAAD/gAAAAAAAAAH///AAAAAD/gAAAAAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAD/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//+AAAAAAAf/////8AAAA///wAAAAAAf/////8AAAA///4AAAAAAf/////8AAAA///8AAAAAAf/////8AAAA///+AAAAAAf/////8AAAA///+AAAAAAf/////8AAAA///+AAAAAAf/////8AAAA////AAAAAAf/////8AAAA////AAAAAAf/////8AAAA////AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf8AAAf8AAAAAAH/AAAAAAf//wAf8AAAAAAH/AAAAAAf//wAf/////////AAAAAAf//wAf/////////AAAAAAf//wAf/////////AAAAAAf//wAf////////+AAAAAAf//wAP////////+AAAAAAf//wAP////////8AAAAAAf//wAH////////8AAAAAAf//wAD////////wAAAAAAf//wAA////////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////AAAAAAAD/////////////wAAAAAAP/////////////4AAAAAAP/////////////8AAAAAAf/////////////+AAAAAAf/////////////+AAAAAA///////////////AAAAAA///////////////AAAAAA///////////////AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA/4AAAf8AAAAAAH/AAAAAA///wAf8AAAAAAH/AAAAAA///wAf/////////AAAAAA///wAf/////////AAAAAA///wAf/////////AAAAAAf//wAf/////////AAAAAAf//wAP////////+AAAAAAP//wAP////////+AAAAAAH//wAH////////8AAAAAAB//wAD////////4AAAAAAAf/wAB////////wAAAAAAAAAAAAf///////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf//wAAAAAAAAAAAAAAAAAf//wAAAAAAAAAAAAAAAAAf//wAAAAAAAAAAeAAAAAAf//wAAAAAAAAAP+AAAAAAf//wAAAAAAAAD/+AAAAAAf//wAAAAAAAA//+AAAAAAf//wAAAAAAAf//+AAAAAAf//wAAAAAAH///+AAAAAAf//wAAAAAD////+AAAAAAf8AAAAAAA/////+AAAAAAf8AAAAAAP/////+AAAAAAf8AAAAAH//////8AAAAAAf8AAAAB///////AAAAAAAf8AAAAf//////wAAAAAAAf8AAAP//////4AAAAAAAAf8AAD//////+AAAAAAAAAf8AB///////gAAAAAAAAAf8Af//////4AAAAAAAAAAf8H//////+AAAAAAAAAAAf////////gAAAAAAAAAAAf///////wAAAAAAAAAAAAf//////8AAAAAAAAAAAAAf//////AAAAAAAAAAAAAAf/////wAAAAAAAAAAAAAAf////8AAAAAAAAAAAAAAAf////AAAAAAAAAAAAAAAAf///wAAAAAAAAAAAAAAAAf//4AAAAAAAAAAAAAAAAAf/+AAAAAAAAAAAAAAAAAAf/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///gf//////+AAAAAAAB////4////////wAAAAAAH////9////////4AAAAAAP/////////////8AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAf/////////////+AAAAAA///////////////AAAAAA///////////////AAAAAA//////4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA/4AAA/4AAAAAAH/AAAAAA///////////////AAAAAA///////////////AAAAAA///////////////AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAP/////////////+AAAAAAP/////////////8AAAAAAH////9////////4AAAAAAB////4////////gAAAAAAAH///gP//////+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///////+AAAAAAAAAAAAD////////gAD//AAAAAAAP////////wAD//wAAAAAAP////////4AD//4AAAAAAf////////8AD//8AAAAAAf////////8AD//+AAAAAA/////////+AD//+AAAAAA/////////+AD///AAAAAA/////////+AD///AAAAAA/4AAAAAAP+AD///AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA/4AAAAAAP+AAAH/AAAAAA///////////////AAAAAA///////////////AAAAAA///////////////AAAAAAf/////////////+AAAAAAf/////////////+AAAAAAP/////////////8AAAAAAP/////////////4AAAAAAD/////////////wAAAAAAA/////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAD/wAAAf+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='), + 46, + atob("FCYpGigoKigoJykoFA=="), + 126+(scale<<8)+(1<<16) + ); + return this; +}; + + + +// timeout used to update every minute +var drawTimeout; + +// schedule a draw for the next minute +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +} + + +function draw() { + var x = g.getWidth()/2; + var y = g.getHeight()/2; + g.reset(); + var date = new Date(); + var timeStr = require("locale").time(date,1); + var dateStr = require("locale").date(date).toUpperCase(); + // draw time + g.setFontAlign(0,0).setFont("BuildingTypeface"); + g.clearRect(0, 24, g.getWidth(), y+35); // clear the background + g.drawString(timeStr,x,y); + // draw date + y += 60; + g.setFontAlign(0,0).setFont("6x8",2); + g.clearRect(0,y-8,g.getWidth(),y+8); // clear the background + g.drawString(dateStr,x,y); + // queue draw in one minute + queueDraw(); +} + +// Clear the screen once, at startup +g.clear(); +// draw immediately at first, queue update +draw(); +// Stop updates when LCD is off, restart when on +Bangle.on('lcdPower',on=>{ + if (on) { + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); +// Show launcher when middle button pressed +Bangle.setUI("clock"); +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); diff --git a/apps/deko/app.png b/apps/deko/app.png new file mode 100644 index 000000000..6f11e7019 Binary files /dev/null and b/apps/deko/app.png differ diff --git a/apps/deko/metadata.json b/apps/deko/metadata.json new file mode 100644 index 000000000..9bdd15429 --- /dev/null +++ b/apps/deko/metadata.json @@ -0,0 +1,16 @@ +{ + "id": "deko", + "name": "Deko Clock", + "version": "0.01", + "description": "Clock with Art Deko font", + "readme": "README.md", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"deko.app.js","url":"app.js"}, + {"name":"deko.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/deko/screenshot.png b/apps/deko/screenshot.png new file mode 100644 index 000000000..91ce2ea38 Binary files /dev/null and b/apps/deko/screenshot.png differ diff --git a/apps/demoapp/metadata.json b/apps/demoapp/metadata.json index df6554ef5..2fb30f718 100644 --- a/apps/demoapp/metadata.json +++ b/apps/demoapp/metadata.json @@ -12,6 +12,5 @@ "storage": [ {"name":"demoapp.app.js","url":"app.js"}, {"name":"demoapp.img","url":"app-icon.js","evaluate":true} - ], - "sortorder": -9 + ] } diff --git a/apps/distortclk/ChangeLog b/apps/distortclk/ChangeLog new file mode 100644 index 000000000..4c7291526 --- /dev/null +++ b/apps/distortclk/ChangeLog @@ -0,0 +1,2 @@ +0.01: New face! +0.02: Improved clock diff --git a/apps/distortclk/README.md b/apps/distortclk/README.md new file mode 100644 index 000000000..8c7c433c1 --- /dev/null +++ b/apps/distortclk/README.md @@ -0,0 +1,17 @@ +# Distort Watchface +Was playing around with custom fonts and made something with it +Made for Bangle.js 2 + +![screenshot (3)](https://user-images.githubusercontent.com/44651387/157507228-100452bf-94a6-476f-aec6-d13d5dad86d5.png) + +## Features + +Has a dark mode + +## Requests + +If you have any issues or would like to suggest a feature, click here to send a message -> [here](https://github.com/elykittytee/BangleApps/issues/new?title=Poketch%20Clock%20Bug). + +## Creator + +Eleanor Tayam diff --git a/apps/distortclk/app-icon.js b/apps/distortclk/app-icon.js new file mode 100644 index 000000000..c375de96e --- /dev/null +++ b/apps/distortclk/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("j0ewkBiIAxHIQMJiBJEIxAaCAIQfHDgIUFDwwNCHYgVFiAVBHYgIDEghKCCIQGCFYoaDAYgORGIJ2DBwYIBHgQOPgAOIPIYOGAgQOFFgh7DHZQeDBwhoFQgh3JEAgOFFoqkHYRzgOfx4bCJ4gNGSIaJEABA7EAGA")) diff --git a/apps/distortclk/app.js b/apps/distortclk/app.js new file mode 100644 index 000000000..a9fdd1ef2 --- /dev/null +++ b/apps/distortclk/app.js @@ -0,0 +1,65 @@ +Graphics.prototype.setFontSixCaps = function(scale) { + // Actual height 60 (59 - 0) + this.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADMzMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADMzMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0VniarM3u4AAAAAAAAAAAAAAAAAAAAAAAAAAABEZoiqzN3u////////8AAAAAAAAAAAAAAAAAAAJFZ4iqzN3u////////////////8AAAAAAAAAAARGZ4mrzd7v////////////////////////8AAAAAAAqszd7v////////////////////////////7u3MoAAAAAAA//////////////////////////7t3MqohmRCAAAAAAAAAA//////////////////7t3MqohmRAAAAAAAAAAAAAAAAAAA/////////+7dzKqYdlQwAAAAAAAAAAAAAAAAAAAAAAAAAA/+7dzKqIZkQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZkQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWazMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMqVAAAAAAAAAa7//////////////////////////////////+oQAAAAAAC/////////////////////////////////////+wAAAAAAf//////////////////////////////////////3AAAAAA3///7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u///9AAAAAA///GREREREREREREREREREREREREREREREREbP//AAAAAA//8wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///AAAAAA///GREREREREREREREREREREREREREREREREbP//AAAAAA3///7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u///9AAAAAAf//////////////////////////////////////3AAAAAAC/////////////////////////////////////+wAAAAAAAa7//////////////////////////////////+oQAAAAAAAAWazMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMqVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACqoAAAAAAA//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/8AAAAAAA//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/8AAAAAAA//3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3/8AAAAAAA//////////////////////////////////////8AAAAAAA//////////////////////////////////////8AAAAAAA//////////////////////////////////////8AAAAAAA3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADu4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAes3d3d3d0AAAAAAAAAAAAAAAAAAAAAAAADVorAAAAAAAA8////////8AAAAAAAAAAAAAAAAAAAAlaKze///wAAAAAAHf////////8AAAAAAAAAAAAAAAFGis3v///////wAAAAAAn/////////8AAAAAAAAAAARom83v///////////wAAAAAA7//+3d3d3d0AAAAAAEV5rN7//////////////v/wAAAAAA//xTAAAAAAAAA1eKze//////////////7cqXVP/wAAAAAA//UAAAAAFGis3v/////////////+3Kl2QAAAAP/wAAAAAA//6XZoq83v/////////////+26hkEAAAAAAAAP/wAAAAAA3//////////////////tyoZSAAAAAAAAAAAAAP/wAAAAAAb//////////////tuoZAAAAAAAAAAAAAAAAAAP/wAAAAAACv/////////tuXUwAAAAAAAAAAAAAAAAAAAAAP/wAAAAAAAI3////9yoZAAAAAAAAAAAAAAAAAAAAAAAAAAP/wAAAAAAAAJ4qodRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqgAAAAAAAAWazMzMzMzMzAAAAAAAAAAAAAzMzMzMzMzMqVAAAAAAAAAa7//////////wAAAAAAAAAAAA///////////+oQAAAAAADP///////////wAAAAAAAAAAAA/////////////AAAAAAAf////////////wAAAAiIgAAAAA/////////////3AAAAAA3///7u7u7u7u7gAAAA//8AAAAA7u7u7u7u7u///9AAAAAA//11RERERERERAAAAA//8AAAAAREREREREREV9//AAAAAA//QAAAAAAAAAAAAAAB//8QAAAAAAAAAAAAAAAE//AAAAAA//11RERERERERERERa//+lREREREREREREREV9//AAAAAA3///7u7u7u7u7u7u7/////7u7u7u7u7u7u7u///9AAAAAAf//////////////////////////////////////3AAAAAAC/////////////////+q//////////////////+wAAAAAAAa7///////////////0i3////////////////+oQAAAAAAAAWazMzMzMzMzMzMyoIAKKzMzMzMzMzMzMzMqVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkRGZniIqqoAAAAAAAAAAAAAAAAAAAAAAkRGZniIqqrMzd3u7v//////8AAAAAAAAAAAAAAAqqrMzd3u7v////////////////////8AAAAAAAAAAAAAAA//////////////////////////////8AAAAAAAAAAAAAAA//////////////////////////////8AAAAAAAAAAAAAAA///////////////+7t3czKqpiHZm//8AAAAAAAAAAAAAAA//7u3dzMuqqIhmZUQwAAAAAAAAAA//8AAAAAAAAAAAAAAAZmREAAAAAAAAAARERERERERERERE//9EREREREQAAAAAAAAAAAAAAAAAAAAA7u7u7u7u7u7u7u///u7u7u7u4AAAAAAAAAAAAAAAAAAAAA////////////////////////8AAAAAAAAAAAAAAAAAAAAA////////////////////////8AAAAAAAAAAAAAAAAAAAAA////////////////////////8AAAAAAAAAAAAAAAAAAAAAzMzMzMzMzMzMzMzMzMzMzMzMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARERERERERERERERERERAAABEREREREREREREAAAAAAAAAA7u7u7u7u7u7u7u7u7u7gAADu7u7u7u7u7u7u2TAAAAAAAA///////////////////wAAD//////////////+YAAAAAAA///////////////////wAAD///////////////4wAAAAAA///////////////////wAAD///////////////+gAAAAAA//zMzMzMzMzMzMzM3//AAADMzMzMzMzMzMzM7//wAAAAAA//AAAAAAAAAAAAAG//cAAAAAAAAAAAAAAAAAKf/wAAAAAA//AAAAAAAAAAAAAN//UAAAAAAAAAAAAAAAAAB//wAAAAAA//AAAAAAAAAAAAAP//6qqqqqqqqqqqqqqqqqv//wAAAAAA//AAAAAAAAAAAAAP///////////////////////AAAAAAA//AAAAAAAAAAAAAN//////////////////////9AAAAAAA//AAAAAAAAAAAAAF7/////////////////////gAAAAAAA//AAAAAAAAAAAAAAWu//////////////////7GAAAAAAAAZmAAAAAAAAAAAAAAADZmZmZmZmZmZmZmZmZmQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADREREREREREREREREREREREREREREREREMAAAAAAAAAADne7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7ZMAAAAAAABd////////////////////////////////////1QAAAAAALv/////////////////////////////////////iAAAAAAr//////////////////////////////////////6AAAAAA///szMzMzMzMzMzMzP//zMzMzMzMzMzMzMzM3///AAAAAA//ogAAAAAAAAAAAAC//5AAAAAAAAAAAAAAAACf//AAAAAA//cAAAAAAAAAAAAAD//zAAAAAAAAAAAAAAAABf//AAAAAA//+6qqqqqqqqAAAAD//8qqqqqqqqqqqqqqqqrv//AAAAAAz///////////AAAAD//////////////////////8AAAAAAT///////////AAAADv/////////////////////0AAAAAACP//////////AAAAB/////////////////////+AAAAAAAAGzv////////AAAAAGzv/////////////////sYAAAAAAAAABGZmZmZmZmAAAAAABGZmZmZmZmZmZmZmZmZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACQAAAAAAA//AAAAAAAAAAAAAAAAAAAAAAAAACRGZ4iqrM3e4AAAAAAA//AAAAAAAAAAAAAAACRGZ4iqrM3e7v////////8AAAAAAA//AAAAACRGZ4iqrM3e7v//////////////////8AAAAAAA//iqrM3e7v////////////////////////////8AAAAAAA//////////////////////////////////7u3cwAAAAAAA///////////////////////+7t3MyqmIZmRCAAAAAAAAAA/////////////u3dzLqoiGZUQgAAAAAAAAAAAAAAAAAAAA//7t3cyqqIhmVEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZlRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWazMzMzMqphjAAAAAAAAAARniqrMzMzMzMqVAAAAAAAAAa7//////////+yWEAAAAVi97////////////+oQAAAAAAC///////////////2VAGrf////////////////+wAAAAAAf////////////////+vP///////////////////3AAAAAA3///7u7u7u7/////////////////7u7u7u7u///9AAAAAA///GRERERERmis3////////typhmREREREREbP//AAAAAA//8wAAAAAAAAAAJ8/////8hgAAAAAAAAAAAAA///AAAAAA///GRERERERWis3////////typhmREREREREbP//AAAAAA3///7u7u7u7/////////////////7u7u7u7u///9AAAAAAf////////////////+vP///////////////////3AAAAAAC///////////////2VAGrf////////////////+wAAAAAAAa7//////////+yWIAAAAVi97////////////+oQAAAAAAAAWazMzMzMqphjAAAAAAAAAARniqrMzMzMzMqVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1ZmZmZmZmZmZmZmZmQgAAAAAAZmZmZmZmYwAAAAAAAAAFvv////////////////7rUAAAAA/////////rUAAAAAAAB+////////////////////9gAAAA//////////9wAAAAAAP//////////////////////gAAAA///////////zAAAAAAv//////////////////////wAAAA///////////7AAAAAA///7qqqqqqqqqqqqqqqq3//wAAAAqqqqqqqqrP//AAAAAA//9wAAAAAAAAAAAAAAAAT//wAAAAAAAAAAAAAH//AAAAAA//9wAAAAAAAAAAAAAAAAn//AAAAAAAAAAAAAAZ//AAAAAA///8zMzMzMzMzMzMzMzM///MzMzMzMzMzMzMzf//AAAAAAv//////////////////////////////////////7AAAAAAP//////////////////////////////////////zAAAAAABu////////////////////////////////////5gAAAAAAAEre7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7aQAAAAAAAAAAUREREREREREREREREREREREREREREREREQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzMwAAAAAAAAAAAzMzAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//8AAAAAAAAAAA///wAAAAAAAAAAAAAAAAAAAAAAAAAAAP//8AAAAAAAAAAA///wAAAAAAAAAAAAAAAAAAAAAAAAAAAP//8AAAAAAAAAAA///wAAAAAAAAAAAAAAAAAAAAAAAAAAAP//8AAAAAAAAAAA///wAAAAAAAAAAAAAAAAAAAAAAAAAAAMzMwAAAAAAAAAAAzMzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="), 46, atob("CAwODQ4PDw8QDA8QCA=="), 69+(scale<<8)+(4<<16)); + return this; +}; + +const offset = 25; +const width = g.getWidth(); +const height = g.getHeight(); + +var drawTimeout; +var fgTime = 0xf800; +var bgTime = 0x3333ff; +var dayDate = 0x000; + +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +} + +function time() { + require("Font4x5").add(Graphics); + var d = new Date(); + var day = d.getDate(); + var time = require("locale").time(d,1); + var date = require("locale").date(d); + var mo = require("date_utils").month(d.getMonth()+1,0); + + g.setFontAlign(0,0); + g.setFontSixCaps(2).setColor(fgTime).drawString(time, width/2, height/2+10); + + g.setFont("4x5",2); + g.setFontAlign(0,0); + g.setColor(dayDate).drawString(mo,width-55, height-16); + g.drawString(day,width-10, height-16); +} + +function draw() { + g.setColor(bgTime).fillRect(0,40,width,height-offset); + time(); + queueDraw(); +} + +//program start +g.clear(); // Clear the screen once, at startup + +if (g.theme.dark==true){ + dayDate = 0xffff; +} +else { + dayDate=0x000; +} + +draw(); // draw immediately at first + + + +// Show launcher when middle button pressed +Bangle.setUI("clock"); +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); diff --git a/apps/distortclk/app.png b/apps/distortclk/app.png new file mode 100644 index 000000000..b82a0913e Binary files /dev/null and b/apps/distortclk/app.png differ diff --git a/apps/distortclk/metadata.json b/apps/distortclk/metadata.json new file mode 100644 index 000000000..125dac590 --- /dev/null +++ b/apps/distortclk/metadata.json @@ -0,0 +1,17 @@ +{ + "id": "distortclk", + "name": "Distort Clock", + "shortName":"Distort Clock", + "version": "0.02", + "description": "A clockface", + "icon": "app.png", + "type": "clock", + "tags": "clock", + "supports": ["BANGLEJS2"], + "allow_emulator": true, + "readme":"README.md", + "storage": [ + {"name":"distortclk.app.js","url":"app.js"}, + {"name":"distortclk.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/distortclk/screenshot.png b/apps/distortclk/screenshot.png new file mode 100644 index 000000000..3207b4e1e Binary files /dev/null and b/apps/distortclk/screenshot.png differ diff --git a/apps/dotmatrixclock/ChangeLog b/apps/dotmatrixclock/ChangeLog index 7ab9e14a9..12edf33a3 100644 --- a/apps/dotmatrixclock/ChangeLog +++ b/apps/dotmatrixclock/ChangeLog @@ -1 +1,2 @@ 0.01: Create dotmatrix clock app +0.02: Added adjustment for Bangle.js magnetometer heading fix diff --git a/apps/dotmatrixclock/app.js b/apps/dotmatrixclock/app.js index ba34d4885..493a3c43f 100644 --- a/apps/dotmatrixclock/app.js +++ b/apps/dotmatrixclock/app.js @@ -186,7 +186,7 @@ function drawCompass(lastHeading) { 'NW' ]; const cps = Bangle.getCompass(); - let angle = cps.heading; + let angle = 360-cps.heading; let heading = angle? directions[Math.round(((angle %= 360) < 0 ? angle + 360 : angle) / 45) % 8]: "-- "; @@ -351,4 +351,4 @@ Bangle.on('faceUp', (up) => { setSensors(1); resetDisplayTimeout(); } -}); \ No newline at end of file +}); diff --git a/apps/dotmatrixclock/metadata.json b/apps/dotmatrixclock/metadata.json index 3425dc1b2..fdfb5271f 100644 --- a/apps/dotmatrixclock/metadata.json +++ b/apps/dotmatrixclock/metadata.json @@ -1,7 +1,7 @@ { "id": "dotmatrixclock", "name": "Dotmatrix Clock", - "version": "0.01", + "version": "0.02", "description": "A clear white-on-blue dotmatrix simulated clock", "icon": "dotmatrixclock.png", "type": "clock", diff --git a/apps/dragboard/ChangeLog b/apps/dragboard/ChangeLog index 48a1ffb03..265094e87 100644 --- a/apps/dragboard/ChangeLog +++ b/apps/dragboard/ChangeLog @@ -3,3 +3,4 @@ 0.03: Made the code shorter and somewhat more readable by writing some functions. Also made it work as a library where it returns the text once finished. The keyboard is now made to exit correctly when the 'back' event is called. The keyboard now uses theme colors correctly, although it still looks best with dark theme. The numbers row is now solidly green - except for highlights. 0.04: Now displays the opened text string at launch. 0.05: Now scrolls text when string gets longer than screen width. +0.06: The code is now more reliable and the input snappier. Widgets will be drawn if present. diff --git a/apps/dragboard/lib.js b/apps/dragboard/lib.js index b9b19f982..220f075d7 100644 --- a/apps/dragboard/lib.js +++ b/apps/dragboard/lib.js @@ -1,12 +1,9 @@ -//Keep banglejs screen on for 100 sec at 0.55 power level for development purposes -//Bangle.setLCDTimeout(30); -//Bangle.setLCDPower(1); - exports.input = function(options) { options = options||{}; var text = options.text; if ("string"!=typeof text) text=""; - + + var R = Bangle.appRect; var BGCOLOR = g.theme.bg; var HLCOLOR = g.theme.fg; var ABCCOLOR = g.toColor(1,0,0);//'#FF0000'; @@ -17,35 +14,38 @@ exports.input = function(options) { var SMALLFONTWIDTH = parseInt(SMALLFONT.charAt(0)*parseInt(SMALLFONT.charAt(-1))); var ABC = 'abcdefghijklmnopqrstuvwxyz'.toUpperCase(); - var ABCPADDING = (g.getWidth()-6*ABC.length)/2; + var ABCPADDING = ((R.x+R.w)-6*ABC.length)/2; var NUM = ' 1234567890!?,.- '; var NUMHIDDEN = ' 1234567890!?,.- '; - var NUMPADDING = (g.getWidth()-6*NUM.length)/2; + var NUMPADDING = ((R.x+R.w)-6*NUM.length)/2; var rectHeight = 40; - var delSpaceLast; function drawAbcRow() { g.clear(); + try { // Draw widgets if they are present in the current app. + if (WIDGETS) Bangle.drawWidgets(); + } catch (_) {} g.setFont(SMALLFONT); g.setColor(ABCCOLOR); - g.drawString(ABC, ABCPADDING, g.getHeight()/2); - g.fillRect(0, g.getHeight()-26, g.getWidth(), g.getHeight()); + g.setFontAlign(-1, -1, 0); + g.drawString(ABC, ABCPADDING, (R.y+R.h)/2); + g.fillRect(0, (R.y+R.h)-26, (R.x+R.w), (R.y+R.h)); } function drawNumRow() { g.setFont(SMALLFONT); g.setColor(NUMCOLOR); - g.drawString(NUM, NUMPADDING, g.getHeight()/4); + g.setFontAlign(-1, -1, 0); + g.drawString(NUM, NUMPADDING, (R.y+R.h)/4); - g.fillRect(NUMPADDING, g.getHeight()-rectHeight*4/3, g.getWidth()-NUMPADDING, g.getHeight()-rectHeight*2/3); + g.fillRect(NUMPADDING, (R.y+R.h)-rectHeight*4/3, (R.x+R.w)-NUMPADDING, (R.y+R.h)-rectHeight*2/3); } function updateTopString() { - "ram" g.setColor(BGCOLOR); g.fillRect(0,4+20,176,13+20); g.setColor(0.2,0,0); @@ -54,13 +54,10 @@ exports.input = function(options) { g.setColor(0.7,0,0); g.fillRect(rectLen+5,4+20,rectLen+10,13+20); g.setColor(1,1,1); + g.setFontAlign(-1, -1, 0); g.drawString(text.length<=27? text.substr(-27, 27) : '<- '+text.substr(-24,24), 5, 5+20); } - drawAbcRow(); - drawNumRow(); - updateTopString(); - var abcHL; var abcHLPrev = -10; var numHL; @@ -68,194 +65,182 @@ exports.input = function(options) { var type = ''; var typePrev = ''; var largeCharOffset = 6; - + function resetChars(char, HLPrev, typePadding, heightDivisor, rowColor) { - "ram" + "ram"; // Small character in list g.setColor(rowColor); g.setFont(SMALLFONT); - g.drawString(char, typePadding + HLPrev*6, g.getHeight()/heightDivisor); + g.setFontAlign(-1, -1, 0); + g.drawString(char, typePadding + HLPrev*6, (R.y+R.h)/heightDivisor); // Large character g.setColor(BGCOLOR); - g.fillRect(0,g.getHeight()/3,176,g.getHeight()/3+24); - //g.drawString(charSet.charAt(HLPrev), typePadding + HLPrev*6 -largeCharOffset, g.getHeight()/3);; //Old implementation where I find the shape and place of letter to remove instead of just a rectangle. + g.fillRect(0,(R.y+R.h)/3,176,(R.y+R.h)/3+24); + //g.drawString(charSet.charAt(HLPrev), typePadding + HLPrev*6 -largeCharOffset, (R.y+R.h)/3);; //Old implementation where I find the shape and place of letter to remove instead of just a rectangle. // mark in the list } function showChars(char, HL, typePadding, heightDivisor) { - "ram" + "ram"; // mark in the list g.setColor(HLCOLOR); g.setFont(SMALLFONT); - if (char != 'del' && char != 'space') g.drawString(char, typePadding + HL*6, g.getHeight()/heightDivisor); + g.setFontAlign(-1, -1, 0); + if (char != 'del' && char != 'space') g.drawString(char, typePadding + HL*6, (R.y+R.h)/heightDivisor); // show new large character g.setFont(BIGFONT); - g.drawString(char, typePadding + HL*6 -largeCharOffset, g.getHeight()/3); + g.drawString(char, typePadding + HL*6 -largeCharOffset, (R.y+R.h)/3); g.setFont(SMALLFONT); } - + + function initDraw() { + //var R = Bangle.appRect; // To make sure it's properly updated. Not sure if this is needed. + drawAbcRow(); + drawNumRow(); + updateTopString(); + } + initDraw(); + //setTimeout(initDraw, 0); // So Bangle.appRect reads the correct environment. It would draw off to the side sometimes otherwise. + function changeCase(abcHL) { g.setColor(BGCOLOR); - g.drawString(ABC, ABCPADDING, g.getHeight()/2); + g.setFontAlign(-1, -1, 0); + g.drawString(ABC, ABCPADDING, (R.y+R.h)/2); if (ABC.charAt(abcHL) == ABC.charAt(abcHL).toUpperCase()) ABC = ABC.toLowerCase(); else ABC = ABC.toUpperCase(); g.setColor(ABCCOLOR); - g.drawString(ABC, ABCPADDING, g.getHeight()/2); + g.drawString(ABC, ABCPADDING, (R.y+R.h)/2); } return new Promise((resolve,reject) => { - // Interpret touch input + // Interpret touch input Bangle.setUI({ - mode: 'custom', - back: ()=>{ - Bangle.setUI(); - g.clearRect(Bangle.appRect); - resolve(text); - }, - drag: function(event) { + mode: 'custom', + back: ()=>{ + Bangle.setUI(); + g.clearRect(Bangle.appRect); + resolve(text); + }, + drag: function(event) { + "ram"; + // ABCDEFGHIJKLMNOPQRSTUVWXYZ + // Choose character by draging along red rectangle at bottom of screen + if (event.y >= ( (R.y+R.h) - 12 )) { + // Translate x-position to character + if (event.x < ABCPADDING) { abcHL = 0; } + else if (event.x >= 176-ABCPADDING) { abcHL = 25; } + else { abcHL = Math.floor((event.x-ABCPADDING)/6); } - // ABCDEFGHIJKLMNOPQRSTUVWXYZ - // Choose character by draging along red rectangle at bottom of screen - if (event.y >= ( g.getHeight() - 12 )) { - // Translate x-position to character - if (event.x < ABCPADDING) { abcHL = 0; } - else if (event.x >= 176-ABCPADDING) { abcHL = 25; } - else { abcHL = Math.floor((event.x-ABCPADDING)/6); } + // Datastream for development purposes + //print(event.x, event.y, event.b, ABC.charAt(abcHL), ABC.charAt(abcHLPrev)); - // Datastream for development purposes - //print(event.x, event.y, event.b, ABC.charAt(abcHL), ABC.charAt(abcHLPrev)); + // Unmark previous character and mark the current one... + // Handling switching between letters and numbers/punctuation + if (typePrev != 'abc') resetChars(NUM.charAt(numHLPrev), numHLPrev, NUMPADDING, 4, NUMCOLOR); - // Unmark previous character and mark the current one... - // Handling switching between letters and numbers/punctuation - if (typePrev != 'abc') resetChars(NUM.charAt(numHLPrev), numHLPrev, NUMPADDING, 4, NUMCOLOR); - - if (abcHL != abcHLPrev) { - resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); - showChars(ABC.charAt(abcHL), abcHL, ABCPADDING, 2); + if (abcHL != abcHLPrev) { + resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); + showChars(ABC.charAt(abcHL), abcHL, ABCPADDING, 2); } - // Print string at top of screen - if (event.b == 0) { - text = text + ABC.charAt(abcHL); - updateTopString(); - - // Autoswitching letter case - if (ABC.charAt(abcHL) == ABC.charAt(abcHL).toUpperCase()) changeCase(abcHL); - } - // Update previous character to current one - abcHLPrev = abcHL; - typePrev = 'abc'; - } - - - - - - - - - - // 12345678901234567890 - // Choose number or puctuation by draging on green rectangle - else if ((event.y < ( g.getHeight() - 12 )) && (event.y > ( g.getHeight() - 52 ))) { - // Translate x-position to character - if (event.x < NUMPADDING) { numHL = 0; } - else if (event.x > 176-NUMPADDING) { numHL = NUM.length-1; } - else { numHL = Math.floor((event.x-NUMPADDING)/6); } - - // Datastream for development purposes - //print(event.x, event.y, event.b, NUM.charAt(numHL), NUM.charAt(numHLPrev)); - - // Unmark previous character and mark the current one... - // Handling switching between letters and numbers/punctuation - if (typePrev != 'num') resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); - - if (numHL != numHLPrev) { - resetChars(NUM.charAt(numHLPrev), numHLPrev, NUMPADDING, 4, NUMCOLOR); - showChars(NUM.charAt(numHL), numHL, NUMPADDING, 4); - } - // Print string at top of screen - if (event.b == 0) { - g.setColor(HLCOLOR); - // Backspace if releasing before list of numbers/punctuation - if (event.x < NUMPADDING) { - // show delete sign - showChars('del', 0, g.getWidth()/2 +6 -27 , 4); - delSpaceLast = 1; - text = text.slice(0, -1); - updateTopString(); - //print(text); - } - // Append space if releasing after list of numbers/punctuation - else if (event.x > g.getWidth()-NUMPADDING) { - //show space sign - showChars('space', 0, g.getWidth()/2 +6 -6*3*5/2 , 4); - delSpaceLast = 1; - text = text + ' '; - updateTopString(); - //print(text); - } - // Append selected number/punctuation - else { - text = text + NUMHIDDEN.charAt(numHL); + // Print string at top of screen + if (event.b == 0) { + text = text + ABC.charAt(abcHL); updateTopString(); // Autoswitching letter case - if ((text.charAt(text.length-1) == '.') || (text.charAt(text.length-1) == '!')) changeCase(); + if (ABC.charAt(abcHL) == ABC.charAt(abcHL).toUpperCase()) changeCase(abcHL); } + // Update previous character to current one + abcHLPrev = abcHL; + typePrev = 'abc'; } - // Update previous character to current one - numHLPrev = numHL; - typePrev = 'num'; - } - - - - - - - - - // Make a space or backspace by swiping right or left on screen above green rectangle - else if (event.y > 20+4) { - if (event.b == 0) { - g.setColor(HLCOLOR); - if (event.x < g.getWidth()/2) { - resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); + + // 12345678901234567890 + // Choose number or puctuation by draging on green rectangle + else if ((event.y < ( (R.y+R.h) - 12 )) && (event.y > ( (R.y+R.h) - 52 ))) { + // Translate x-position to character + if (event.x < NUMPADDING) { numHL = 0; } + else if (event.x > 176-NUMPADDING) { numHL = NUM.length-1; } + else { numHL = Math.floor((event.x-NUMPADDING)/6); } + + // Datastream for development purposes + //print(event.x, event.y, event.b, NUM.charAt(numHL), NUM.charAt(numHLPrev)); + + // Unmark previous character and mark the current one... + // Handling switching between letters and numbers/punctuation + if (typePrev != 'num') resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); + + if (numHL != numHLPrev) { resetChars(NUM.charAt(numHLPrev), numHLPrev, NUMPADDING, 4, NUMCOLOR); - - // show delete sign - showChars('del', 0, g.getWidth()/2 +6 -27 , 4); - delSpaceLast = 1; - - // Backspace and draw string upper right corner - text = text.slice(0, -1); - updateTopString(); - if (text.length==0) changeCase(abcHL); - //print(text, 'undid'); + showChars(NUM.charAt(numHL), numHL, NUMPADDING, 4); } - else { - resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); - resetChars(NUM.charAt(numHLPrev), numHLPrev, NUMPADDING, 4, NUMCOLOR); + // Print string at top of screen + if (event.b == 0) { + g.setColor(HLCOLOR); + // Backspace if releasing before list of numbers/punctuation + if (event.x < NUMPADDING) { + // show delete sign + showChars('del', 0, (R.x+R.w)/2 +6 -27 , 4); + delSpaceLast = 1; + text = text.slice(0, -1); + updateTopString(); + //print(text); + } + // Append space if releasing after list of numbers/punctuation + else if (event.x > (R.x+R.w)-NUMPADDING) { + //show space sign + showChars('space', 0, (R.x+R.w)/2 +6 -6*3*5/2 , 4); + delSpaceLast = 1; + text = text + ' '; + updateTopString(); + //print(text); + } + // Append selected number/punctuation + else { + text = text + NUMHIDDEN.charAt(numHL); + updateTopString(); - //show space sign - showChars('space', 0, g.getWidth()/2 +6 -6*3*5/2 , 4); - delSpaceLast = 1; + // Autoswitching letter case + if ((text.charAt(text.length-1) == '.') || (text.charAt(text.length-1) == '!')) changeCase(); + } + } + // Update previous character to current one + numHLPrev = numHL; + typePrev = 'num'; + } - // Append space and draw string upper right corner - text = text + NUMHIDDEN.charAt(0); - updateTopString(); - //print(text, 'made space'); + // Make a space or backspace by swiping right or left on screen above green rectangle + else if (event.y > 20+4) { + if (event.b == 0) { + g.setColor(HLCOLOR); + if (event.x < (R.x+R.w)/2) { + resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); + resetChars(NUM.charAt(numHLPrev), numHLPrev, NUMPADDING, 4, NUMCOLOR); + + // show delete sign + showChars('del', 0, (R.x+R.w)/2 +6 -27 , 4); + delSpaceLast = 1; + + // Backspace and draw string upper right corner + text = text.slice(0, -1); + updateTopString(); + if (text.length==0) changeCase(abcHL); + //print(text, 'undid'); + } + else { + resetChars(ABC.charAt(abcHLPrev), abcHLPrev, ABCPADDING, 2, ABCCOLOR); + resetChars(NUM.charAt(numHLPrev), numHLPrev, NUMPADDING, 4, NUMCOLOR); + + //show space sign + showChars('space', 0, (R.x+R.w)/2 +6 -6*3*5/2 , 4); + delSpaceLast = 1; + + // Append space and draw string upper right corner + text = text + NUMHIDDEN.charAt(0); + updateTopString(); + //print(text, 'made space'); + } } } } - } - }); -}); -/* return new Promise((resolve,reject) => { - Bangle.setUI({mode:"custom", back:()=>{ - Bangle.setUI(); - g.clearRect(Bangle.appRect); - Bangle.setUI(); - resolve(text); - }}); - }); */ - + }); + }); }; diff --git a/apps/dragboard/metadata.json b/apps/dragboard/metadata.json index f9c73ddde..64b6dbe18 100644 --- a/apps/dragboard/metadata.json +++ b/apps/dragboard/metadata.json @@ -1,6 +1,6 @@ { "id": "dragboard", "name": "Dragboard", - "version":"0.05", + "version":"0.06", "description": "A library for text input via swiping keyboard", "icon": "app.png", "type":"textinput", diff --git a/apps/drinkcounter/ChangeLog b/apps/drinkcounter/ChangeLog new file mode 100644 index 000000000..d8d174c4c --- /dev/null +++ b/apps/drinkcounter/ChangeLog @@ -0,0 +1,4 @@ +0.10: Initial release - still work in progress +0.15: Added settings and calculations +0.20: Added status saving +0.25: Adopted for Bangle.js 1 - kind of \ No newline at end of file diff --git a/apps/drinkcounter/README.md b/apps/drinkcounter/README.md new file mode 100644 index 000000000..5638ee066 --- /dev/null +++ b/apps/drinkcounter/README.md @@ -0,0 +1,15 @@ +# Drink Counter + +Counts drinks you had for science. Calculates BAC. + +## Usage + +Swipe left/right to select drink. Swipe up/down to add/remove drinks. + +## Important notes + +No warranty whatsoever. Use at your own risk. Calculations might be wrong. Do not drink and drive - even if BAC is low. + +## Creator + +Hank - contact at http://forum.espruino.com diff --git a/apps/drinkcounter/app.js b/apps/drinkcounter/app.js new file mode 100644 index 000000000..323d9fb41 --- /dev/null +++ b/apps/drinkcounter/app.js @@ -0,0 +1,291 @@ +g.reset().clear(); +Bangle.loadWidgets(); +Bangle.drawWidgets(); +require("Font8x16").add(Graphics); + +const BANGLEJS2 = process.env.HWVERSION == 2; +const SETTINGSFILE = "drinkcounter.json"; +setting = require("Storage").readJSON("setting.json",1); +E.setTimeZone(setting.timezone); // timezone = 1 for MEZ, = 2 for MESZ +var _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||false; +var ampm = "AM"; +let drag; + +var icoBeer = require("heatshrink").decompress(atob("lEoxH+AG2BAAoecEpAoWC4fXAAIGGAAowTDxAmJE4YGGE5QeJE5QHHE7owJE0pQKE7pQJE86fnE5QJSE5YUHBAIJQYxIpFAAvGBBAJIExYoGDgIACBBApFExonCDYoAOFSAnbFJYnE6vVDYYFHAwakQE4YaFAoQGJEIYoME7QoEE7ogFE/4neTBgntY84n/E+7HUE64mDE8IAFEw4nDTBifIE9gmId7gALE5IGCAooGDE6gASE8yaME7gmOFIgAREqIAhA==")); +var icoCocktail = require("heatshrink").decompress(atob("lEoxH+AH4AJtgABEkgmiEiXGAAIllAAiXeEAPXAQQDCFBYmTEgYqDFBZNWAIZRME6IfBEAYuEE5J2UwIAaJ5QncFBB3DB4YGCACQnKTQgoXE5bIEE6qfKPAZRFA4MUABgmNPAonBCgQnPExgpFPIgoNEyBSF4wGBFBgmSABCjJTZwoXEzwoHE0AoFE0QnCFAQmhKAonjFAInCE0Qn/E/4n/E/4n/wInDFEAhBEwQoDFLYdCEwooEFTAjHAAwoYIYgAMPDglT")); +var icoShot = require("heatshrink").decompress(atob("lEoxH+AH4A/AH4A/AH4AqwIAgE+HXADRPME8ZQM5AnSZBQkGAAYngEYonfJA5QQE8zGJFAYfKFBwmKE4iYIE7rpIeYgAJE5woEEpQKHTxhQIIpJaHJxgn/E8zGQZBAnQYxxQRFQYnlFgon5FCYmDE6LjHZRQmPE5AAOE/4njFCTGQKCwmRKAgATE54oWEyAqTDZY")); +var icoReset = require("heatshrink").decompress(atob("j0egILI8ACBh4DC/4DBh4DCv8f4ED8EPwEPEQMAvEAnkB4EA+AKBCAM8DYOA8EB//HwED/wXBg/wnAOC+EAjkDDoMgg+AJoRFCEIIAB/kHgEB/l8FwP/DYIDBC4MD/ASBgYeCAAw")); +var drawTimeout; +var activeDrink = 0; +var drinks = [0,0,0]; +const maxDrinks = 2; // 3 drinks +var firstDrinkTime = null; +var firstDrinkTimeTime = null; + +var confBeerSize; +var confSex; +var confWeight; +var confWeightUnit; + + +// Load Status =============== +var drinkStatus = require("Storage").open("drinkcounter.status.json", "r"); +var test = drinkStatus.read(drinkStatus.getLength()); +if(test!== undefined) { + drinkStatus = JSON.parse(test); + //console.log("read status: " + test); + for (let i = 0; i <= maxDrinks; i++) { + drinks[i] = drinkStatus.drinks[i]; + } + firstDrinkTime = Date.parse(drinkStatus.firstDrinkTime); + //console.log("read firstDrinkTime: " + firstDrinkTime); + if (firstDrinkTime) firstDrinkTimeTime = require("locale").time(new Date(firstDrinkTime), 1); + //console.log("read firstDrinkTimeTime: " + firstDrinkTimeTime); +} else { + drinkStatus = { + drinks: [0,0,0] + }; + //console.log("no status file - applying default"); +} +// Load Status =============== + + +var drinksAlcohol = [12,16,5.6]; // in gramm +// Beer: 0.3L 12g - 0.5L 20g +// Radler: 0.3L 6g - 0.5L 10g +// Wine: 0.2L 16g +// Jäger Shot: 0.02L 5.6g + +// sex: Women 60 - Men 70 (Percent) +// Formula: Alcohol in g /(Body weight in kg x sex) – (0,15 x Hours) = bac per mille +// Example: 5 Beer (0.3L=12g), 80KG, Male (70%), 5 hours +// (5 * 12) / (80 / 100 * 70) - (0.15 * 5) + +function drawBac(){ + if (firstDrinkTime) { + var sum_drinks = (drinks[0] * drinksAlcohol[0]) + (drinks[1] * drinksAlcohol[1]) + (drinks[2] * drinksAlcohol[2]); + + if (confSex == "male") { + sex = 70; + } else { + sex = 60; + } + var weight = confWeight; + + if (confWeightUnit == "US Pounds") { + weight = weight * 0.45359237; + } + var currentTime = new Date(); + var time_diff = Math.floor(((currentTime - firstDrinkTime) % 86400000) / 3600000); // in hours! + //console.log("currentTime: " + currentTime) + //console.log("firstDrinkTime: " + firstDrinkTime) + + //console.log("timediff: " + time_diff); + ebac = Math.round( ((sum_drinks) / (weight / 100 * sex) - (0.15 * time_diff) ) * 100) / 100; + + //console.log("BAC: " + ebac + " weight: " + confWeight + " weightInKilo: " + weight + " Unit: " + confWeightUnit); + //console.log("sum_drinks: " + sum_drinks); + g.clearRect(0,34 + 20 + 8,176,34 + 20 + 20 + 8); //Clear + g.setFontAlign(0,0).setFont("8x16").setColor(g.theme.fg).drawString("BAC: " + ebac, 90, 74); + } +} + + +// Load settings +function loadMySettings() { + // Helper function default setting + function def (value, def) {return value !== undefined ? value : def;} + + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; + confBeerSize = def(settings.beerSize, "0.3L"); + confSex = def(settings.sex, "male"); + confWeight = def(settings.weight, 80); + confWeightUnit = def(settings.weightUnit, "Kilo"); + //console.log("Read config - weight: " + confWeight); +} + + +function updateTime(){ + var d = require("locale").time(new Date(), 1); + + //console.log(d); + var time = d.split(":"); + var hours = time[0]; + var minutes = time[1]; + if (_12hour){ + //do 12 hour stuff + if (hours > 12) { + ampm = "PM"; + hours = hours - 12; + if (hours < 10) hours = doublenum(hours); + } else { + ampm = "AM"; + } + } else { + ampm = ""; + } + g.setBgColor(g.theme.bg).clearRect(0,24,176,44); //Clear + g.setFontAlign(0,0); // center font + g.setBgColor(g.theme.bg).setColor(g.theme.fg); + g.setFont("8x16").drawString("Time: " + hours + ":" + minutes + " " + ampm,90,34); + queueDrawTime(); +} + +function queueDrawTime() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + updateTime(); + }, 20000 - (Date.now() % 20000)); +} + + +function updateDrinks(){ + g.setBgColor(g.theme.bg).clearRect(0,145,176,176); //Clear + for (let i = 0; i <= maxDrinks; i++) { + if (i == activeDrink) { + g.setColor(g.theme.fg).fillRect((40 * (i + 1)) - 40 ,145,(40 * (i + 1)),176); + g.setColor(g.theme.bg); + } else { + g.setColor(g.theme.fg); + } + g.setFont("Vector",20).drawString(drinks[i], (40 * (i + 1)) - 20, 160); + g.setColor(g.theme.fg); + drinkStatus.drinks[i] = drinks[i]; + } + + g.setBgColor(g.theme.bg).setColor(g.theme.fg); + if (BANGLEJS2) { + g.drawImage(icoReset,145,145); + } + + drinkStatus.firstDrinkTime = firstDrinkTime; + settings_file = require("Storage").open("drinkcounter.status.json", "w"); + settings_file.write(JSON.stringify(drinkStatus)); + + drawBac(); +} + +function updateFirstDrinkTime(){ + if (firstDrinkTime){ + g.setFont("8x16"); + g.setFontAlign(0,0).drawString("1st drink @ " + firstDrinkTimeTime, 90, 34 + 20 ); + } +} + +function addDrink(){ + if (!firstDrinkTime){ + firstDrinkTime = new Date(); + firstDrinkTimeTime = require("locale").time(new Date(), 1); + //console.log("init drinking! " + firstDrinkTime); + } + drinks[activeDrink] = drinks[activeDrink] + 1; + updateFirstDrinkTime(); + updateDrinks(); +} + +function removeDrink(){ + if (drinks[activeDrink] > 0) drinks[activeDrink] = drinks[activeDrink] - 1; + updateDrinks(); + + if ((!BANGLEJS2) && (drinks[0] == 0) && (drinks[1] == 0) && (drinks[2] == 0)) { + resetDrinksFn() + } +} + +function previousDrink(){ + if (activeDrink > 0) activeDrink = activeDrink - 1; + updateDrinks(); +} + +function nextDrink(){ + if (activeDrink < maxDrinks) activeDrink = activeDrink + 1; + updateDrinks(); +} + +function showDrinks() { + g.setBgColor(g.theme.bg); + g.drawImage(icoBeer,0,100); + g.drawImage(icoCocktail,40,100); + g.drawImage(icoShot,80,100); +} + +function resetDrinksFn() { + g.clearRect(0,34,176,176); //Clear + resetDrinks = E.showPrompt("Reset drinks?", { + title: "Confirm", + buttons: { Yes: true, No: false }, + }); + resetDrinks.then((confirm) => { + if (confirm) { + for (let i = 0; i <= maxDrinks; i++) { + drinks[i] = 0; + } + //console.log("reset to default"); + } + //console.log("reset " + confirm); + firstDrinkTime = null; + showDrinks(); + updateDrinks(); + updateTime(); + updateFirstDrinkTime(); + }); +} + + +function initDragEvents() { + +if (BANGLEJS2) { + Bangle.on("drag", e => { + if (!drag) { // start dragging + drag = {x: e.x, y: e.y}; + } else if (!e.b) { // released + const dx = e.x-drag.x, dy = e.y-drag.y; + drag = null; + if (Math.abs(dx)>Math.abs(dy)+10) { + // horizontal + if (dx < dy) { + //console.log("left " + dx + " " + dy); + previousDrink(); + } else { + //console.log("right " + dx + " " + dy); + nextDrink(); + } + } else if (Math.abs(dy)>Math.abs(dx)+10) { + // vertical + if (dx < dy) { + //console.log("down " + dx + " " + dy); + removeDrink(); + } else { + //console.log("up " + dx + " " + dy); + addDrink(); + } + } else { + //console.log("tap " + e.x + " " + e.y); + if (e.x > 145 && e.y > 145) { + resetDrinksFn(); + } + } + } + }); + } else { + setWatch(addDrink, BTN1, { repeat: true, debounce:50 }); + setWatch(removeDrink, BTN3, { repeat: true, debounce:50 }); + setWatch(previousDrink, BTN4, { repeat: true, debounce:50 }); + setWatch(nextDrink, BTN5, { repeat: true, debounce:50 }); + } +} + + +loadMySettings(); +showDrinks(); + + +if (drawTimeout) clearTimeout(drawTimeout); +drawTimeout = undefined; +updateTime(); +queueDrawTime(); +initDragEvents(); +updateDrinks(); +updateFirstDrinkTime(); + diff --git a/apps/drinkcounter/drinkcounter-icon.js b/apps/drinkcounter/drinkcounter-icon.js new file mode 100644 index 000000000..e7b95f9ef --- /dev/null +++ b/apps/drinkcounter/drinkcounter-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A/AAWBAAomkFpAweD4fXAAIGGAAo4bExAuJF4YGGF6QmJF5QHHF8o4JF1pgSF7pgRF96/vF5QJSF6YcHBAIJQdyIxFAAvGBBAJIFyYwGEgIACBBAxFFyovCEYoAOGTAvbGKYvE6vVEYYFHAwbEYF4YiFAoQGJFIYwUF7QwEF8ooFF/4v2XBgv1d94v/F/7vsF64uDF9IAFFx4vDXBi/IF+guQR6wvCFSIvOAwQFFAwYvcACQvuXSgvcFywxEACItZAH4A/AH4AlA==")) diff --git a/apps/drinkcounter/drinkcounter.png b/apps/drinkcounter/drinkcounter.png new file mode 100644 index 000000000..91a0cd4ad Binary files /dev/null and b/apps/drinkcounter/drinkcounter.png differ diff --git a/apps/drinkcounter/metadata.json b/apps/drinkcounter/metadata.json new file mode 100644 index 000000000..2b8d7fe71 --- /dev/null +++ b/apps/drinkcounter/metadata.json @@ -0,0 +1,24 @@ +{ + "id": "drinkcounter", + "name": "Drink Counter", + "shortName": "Drink Counter", + "version": "0.25", + "description": "Counts drinks you had for science. Calculates blood alcohol content (BAC)", + "allow_emulator":true, + "icon": "drinkcounter.png", + "type": "app", + "tags": "health", + "screenshots": [{"url":"screenshot_drnkcnt.png"}], + "supports": ["BANGLEJS", "BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"drinkcounter.app.js","url":"app.js"}, + {"name":"drinkcounter.img","url":"drinkcounter-icon.js","evaluate":true}, + {"name":"drinkcounter.settings.js","url":"settings.js"} + ], + "data": [ + {"name":"drinkcounter.settings.json"}, + {"name":"drinkcounter.json"}, + {"name":"drinkcounter.status.json"} + ] +} \ No newline at end of file diff --git a/apps/drinkcounter/screenshot_drnkcnt.png b/apps/drinkcounter/screenshot_drnkcnt.png new file mode 100644 index 000000000..7547eb63f Binary files /dev/null and b/apps/drinkcounter/screenshot_drnkcnt.png differ diff --git a/apps/drinkcounter/settings.js b/apps/drinkcounter/settings.js new file mode 100644 index 000000000..336229b73 --- /dev/null +++ b/apps/drinkcounter/settings.js @@ -0,0 +1,58 @@ +(function(back) { + var FILE = "drinkcounter.json"; + var settings = Object.assign({ + secondsOnUnlock: false, + }, require('Storage').readJSON(FILE, true) || {}); + + function writeSettings() { + require('Storage').writeJSON(FILE, settings); + } + + // Helper method which uses int-based menu item for set of string values + function stringItems(startvalue, writer, values) { + return { + value: (startvalue === undefined ? 0 : values.indexOf(startvalue)), + format: v => values[v], + min: 0, + max: values.length - 1, + wrap: true, + step: 1, + onchange: v => { + writer(values[v]); + writeSettings(); + } + }; + } + + // Helper method which breaks string set settings down to local settings object + function stringInSettings(name, values) { + return stringItems(settings[name], v => settings[name] = v, values); + } + + var mainmenu = { + "": { + "title": "Drink counter" + }, + "< Back": () => back(), + + "Beer size": stringInSettings("beerSize", ["0.3L", "0.5L"]), + + + "Sex": stringInSettings("sex", ["male", "female"]), + + 'Weight': { + value: 80|settings.weight, + min: 40, max: 500, + onchange: v => { + settings.weight = v; + writeSettings(); + } + }, + "Weight unit": stringInSettings("weightUnit", ["Kilo", "US Pounds"]) + + + }; + + E.showMenu(mainmenu); + +}); diff --git a/apps/dtlaunch/ChangeLog b/apps/dtlaunch/ChangeLog index 16c550334..044b8c35f 100644 --- a/apps/dtlaunch/ChangeLog +++ b/apps/dtlaunch/ChangeLog @@ -14,3 +14,13 @@ 0.14: Don't move pages when doing exit swipe - Bangle 2. 0.15: 'Swipe to exit'-code is slightly altered to be more reliable - Bangle 2. 0.16: Use default Bangle formatter for booleans +0.17: Bangle 2: Fast loading on exit to clock face. Added option for exit to +clock face by timeout. +0.18: Bangle 2: Move interactions inside setUI. Replace "one click exit" with +back-functionality through setUI, adding the red back button as well. Hardware +button to exit is no longer an option. +0.19: Bangle 2: Utilize new Bangle.load(), Bangle.showClock() functions to +facilitate 'fast switching' of apps where available. +0.20: Bangle 2: Revert use of Bangle.load() to classic load() calls since +widgets would still be loaded when they weren't supposed to. + diff --git a/apps/dtlaunch/app-b2.js b/apps/dtlaunch/app-b2.js index 8cd5790bb..a7a318c18 100644 --- a/apps/dtlaunch/app-b2.js +++ b/apps/dtlaunch/app-b2.js @@ -1,61 +1,59 @@ -/* Desktop launcher -* -*/ +{ // must be inside our own scope here so that when we are unloaded everything disappears -var settings = Object.assign({ - showClocks: true, - showLaunchers: true, - direct: false, - oneClickExit:false, - swipeExit: false -}, require('Storage').readJSON("dtlaunch.json", true) || {}); + /* Desktop launcher + * + */ -if( settings.oneClickExit) - setWatch(_=> load(), BTN1); - -var s = require("Storage"); -var apps = s.list(/\.info$/).map(app=>{ - var a=s.readJSON(app,1); - return a && { - name:a.name, type:a.type, icon:a.icon, sortorder:a.sortorder, src:a.src - };}).filter( - app=>app && (app.type=="app" || (app.type=="clock" && settings.showClocks) || (app.type=="launch" && settings.showLaunchers) || !app.type)); + let settings = Object.assign({ + showClocks: true, + showLaunchers: true, + direct: false, + swipeExit: false, + timeOut: "Off" + }, require('Storage').readJSON("dtlaunch.json", true) || {}); -apps.sort((a,b)=>{ - var n=(0|a.sortorder)-(0|b.sortorder); - if (n) return n; // do sortorder first - if (a.nameb.name) return 1; - return 0; -}); -apps.forEach(app=>{ + let s = require("Storage"); + var apps = s.list(/\.info$/).map(app=>{ + let a=s.readJSON(app,1); + return a && { + name:a.name, type:a.type, icon:a.icon, sortorder:a.sortorder, src:a.src + };}).filter( + app=>app && (app.type=="app" || (app.type=="clock" && settings.showClocks) || (app.type=="launch" && settings.showLaunchers) || !app.type)); + + apps.sort((a,b)=>{ + let n=(0|a.sortorder)-(0|b.sortorder); + if (n) return n; // do sortorder first + if (a.nameb.name) return 1; + return 0; + }); + apps.forEach(app=>{ if (app.icon) app.icon = s.read(app.icon); // should just be a link to a memory area }); -var Napps = apps.length; -var Npages = Math.ceil(Napps/4); -var maxPage = Npages-1; -var selected = -1; -var oldselected = -1; -var page = 0; -const XOFF = 24; -const YOFF = 30; + let Napps = apps.length; + let Npages = Math.ceil(Napps/4); + let maxPage = Npages-1; + let selected = -1; + let oldselected = -1; + let page = 0; + const XOFF = 24; + const YOFF = 30; -function draw_icon(p,n,selected) { - var x = (n%2)*72+XOFF; - var y = n>1?72+YOFF:YOFF; + let drawIcon= function(p,n,selected) { + let x = (n%2)*72+XOFF; + let y = n>1?72+YOFF:YOFF; (selected?g.setColor(g.theme.fgH):g.setColor(g.theme.bg)).fillRect(x+11,y+3,x+60,y+52); g.clearRect(x+12,y+4,x+59,y+51); g.setColor(g.theme.fg); try{g.drawImage(apps[p*4+n].icon,x+12,y+4);} catch(e){} g.setFontAlign(0,-1,0).setFont("6x8",1); - var txt = apps[p*4+n].name.replace(/([a-z])([A-Z])/g, "$1 $2").split(" "); - var lineY = 0; - var line = ""; - while (txt.length > 0){ - var c = txt.shift(); - + let txt = apps[p*4+n].name.replace(/([a-z])([A-Z])/g, "$1 $2").split(" "); + let lineY = 0; + let line = ""; + while (txt.length > 0){ + let c = txt.shift(); if (c.length + 1 + line.length > 13){ if (line.length > 0){ g.drawString(line.trim(),x+36,y+54+lineY*8); @@ -67,70 +65,91 @@ function draw_icon(p,n,selected) { } } g.drawString(line.trim(),x+36,y+54+lineY*8); -} + }; -function drawPage(p){ + let drawPage = function(p){ g.reset(); g.clearRect(0,24,175,175); - var O = 88+YOFF/2-12*(Npages/2); - for (var j=0;j{ + Bangle.loadWidgets(); + drawPage(0); + + let swipeListenerDt = function(dirLeftRight, dirUpDown){ + updateTimeoutToClock(); selected = 0; oldselected=-1; - if(settings.swipeExit && dirLeftRight==1) load(); + if(settings.swipeExit && dirLeftRight==1) Bangle.showClock(); if (dirUpDown==-1||dirLeftRight==-1){ - ++page; if (page>maxPage) page=0; - drawPage(page); + ++page; if (page>maxPage) page=0; + drawPage(page); } else if (dirUpDown==1||(dirLeftRight==1 && !settings.swipeExit)){ - --page; if (page<0) page=maxPage; - drawPage(page); + --page; if (page<0) page=maxPage; + drawPage(page); } -}); + }; -function isTouched(p,n){ + let isTouched = function(p,n){ if (n<0 || n>3) return false; - var x1 = (n%2)*72+XOFF; var y1 = n>1?72+YOFF:YOFF; - var x2 = x1+71; var y2 = y1+81; + let x1 = (n%2)*72+XOFF; let y1 = n>1?72+YOFF:YOFF; + let x2 = x1+71; let y2 = y1+81; return (p.x>x1 && p.y>y1 && p.x{ - var i; + let touchListenerDt = function(_,p){ + updateTimeoutToClock(); + let i; for (i=0;i<4;i++){ - if((page*4+i)=0 || settings.direct) { - if (selected!=i && !settings.direct){ - draw_icon(page,selected,false); - } else { - load(apps[page*4+i].src); - } - } - selected=i; - break; + if((page*4+i)=0 || settings.direct) { + if (selected!=i && !settings.direct){ + drawIcon(page,selected,false); + } else { + load(apps[page*4+i].src); } + } + selected=i; + break; } + } } if ((i==4 || (page*4+i)>Napps) && selected>=0) { - draw_icon(page,selected,false); - selected=-1; + drawIcon(page,selected,false); + selected=-1; } -}); + }; -Bangle.loadWidgets(); -g.clear(); -Bangle.drawWidgets(); -drawPage(0); + Bangle.setUI({ + mode : 'custom', + back : Bangle.showClock, + swipe : swipeListenerDt, + touch : touchListenerDt, + remove : ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);} + }); + + // taken from Icon Launcher with minor alterations + let timeoutToClock; + const updateTimeoutToClock = function(){ + if (settings.timeOut!="Off"){ + let time=parseInt(settings.timeOut); //the "s" will be trimmed by the parseInt + if (timeoutToClock) clearTimeout(timeoutToClock); + timeoutToClock = setTimeout(Bangle.showClock,time*1000); + } + }; + updateTimeoutToClock(); + +} // end of app scope diff --git a/apps/dtlaunch/metadata.json b/apps/dtlaunch/metadata.json index 36728f342..b69a1a5e6 100644 --- a/apps/dtlaunch/metadata.json +++ b/apps/dtlaunch/metadata.json @@ -1,7 +1,7 @@ { "id": "dtlaunch", "name": "Desktop Launcher", - "version": "0.16", + "version": "0.20", "description": "Desktop style App Launcher with six (four for Bangle 2) apps per page - fast access if you have lots of apps installed.", "screenshots": [{"url":"shot1.png"},{"url":"shot2.png"},{"url":"shot3.png"}], "icon": "icon.png", diff --git a/apps/dtlaunch/settings-b2.js b/apps/dtlaunch/settings-b2.js index fac9c0fff..24959df8c 100644 --- a/apps/dtlaunch/settings-b2.js +++ b/apps/dtlaunch/settings-b2.js @@ -5,51 +5,56 @@ showClocks: true, showLaunchers: true, direct: false, - oneClickExit:false, - swipeExit: false + swipeExit: false, + timeOut: "Off" }, require('Storage').readJSON(FILE, true) || {}); function writeSettings() { require('Storage').writeJSON(FILE, settings); } + const timeOutChoices = [/*LANG*/"Off", "10s", "15s", "20s", "30s"]; + E.showMenu({ "" : { "title" : "Desktop launcher" }, - "< Back" : () => back(), - 'Show clocks': { + /*LANG*/"< Back" : () => back(), + /*LANG*/'Show clocks': { value: settings.showClocks, onchange: v => { settings.showClocks = v; writeSettings(); } }, - 'Show launchers': { + /*LANG*/'Show launchers': { value: settings.showLaunchers, onchange: v => { settings.showLaunchers = v; writeSettings(); } }, - 'Direct launch': { + /*LANG*/'Direct launch': { value: settings.direct, onchange: v => { settings.direct = v; writeSettings(); } }, - 'Swipe Exit': { + /*LANG*/'Swipe Exit': { value: settings.swipeExit, onchange: v => { settings.swipeExit = v; writeSettings(); } }, - 'One click exit': { - value: settings.oneClickExit, + /*LANG*/'Time Out': { // Adapted from Icon Launcher + value: timeOutChoices.indexOf(settings.timeOut), + min: 0, + max: timeOutChoices.length-1, + format: v => timeOutChoices[v], onchange: v => { - settings.oneClickExit = v; + settings.timeOut = timeOutChoices[v]; writeSettings(); } } }); -}) +}); diff --git a/apps/entonclk/ChangeLog b/apps/entonclk/ChangeLog new file mode 100644 index 000000000..62e2d0c20 --- /dev/null +++ b/apps/entonclk/ChangeLog @@ -0,0 +1 @@ +0.1: New App! \ No newline at end of file diff --git a/apps/entonclk/README.md b/apps/entonclk/README.md new file mode 100644 index 000000000..8c788c7a5 --- /dev/null +++ b/apps/entonclk/README.md @@ -0,0 +1,9 @@ +Enton - Enhanced Anton Clock + +This clock face is based on the 'Anton Clock'. + +Things I changed: + +- The main font for the time is now Audiowide +- Removed the written out day name and replaced it with steps and bpm +- Changed the date string to a (for me) more readable string \ No newline at end of file diff --git a/apps/entonclk/app-icon.js b/apps/entonclk/app-icon.js new file mode 100644 index 000000000..9993b0871 --- /dev/null +++ b/apps/entonclk/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkE/4A/AH4A/AH4A/AH4Aw+cikf/mQDCAAIFBAwQDBBYgXCgEDAQIABn4JBkAFBgIKDgQwFmMD+UCmcgl/zEIMzmcQmYKBmYiCAAfxC4QrBl8wBwcgkYsGC4sAiMAF4UxiIGBn8QAgMSC48wgMRiEDBAISCiYcFC48v//yC4PzgJAGiAXIiczPgPzC4JyBmf/AYQXI+KcCj8wmYFCgEjAYQ3G+cjbQIABJIMzAoUin7XIADpSEK4rWGI4MhmRJBn8j+U/d4MimUTkUzIw5dBl4UBMgIXBAgMyLYKOBmQXHiSbCDgMyl8z+UjmJ1BHgJbHCgM/IYQABAgQJBYYYA/AH4AtaQU/mTvBBozWBd44KBkUSkLnBEo8jkcvBI0/CgMiDAIXHHYIXImUzJQJHH+Y+Bn6Z/ABQA==")) \ No newline at end of file diff --git a/apps/entonclk/app.js b/apps/entonclk/app.js new file mode 100644 index 000000000..69fdea479 --- /dev/null +++ b/apps/entonclk/app.js @@ -0,0 +1,67 @@ +Graphics.prototype.setFontAudiowide = function() { + // Actual height 33 (36 - 4) + var widths = atob("CiAsESQjJSQkHyQkDA=="); + var font = atob("AAAAAAAAAAAAAAAAAAAAAPAAAAAAAfgAAAAAAfgAAAAAAfgAAAAAAfgAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAADgAAAAAAHgAAAAAAfgAAAAAA/gAAAAAD/gAAAAAH/gAAAAAf/AAAAAB/8AAAAAD/4AAAAAP/gAAAAAf/AAAAAB/8AAAAAD/4AAAAAP/gAAAAAf+AAAAAB/8AAAAAH/wAAAAAP/gAAAAA/+AAAAAB/8AAAAAD/wAAAAAD/gAAAAAD+AAAAAAD4AAAAAADwAAAAAADAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAAAA//+AAAAB///AAAAH///wAAAP///4AAAf///8AAA////+AAA/4AP+AAB/gAD/AAB/AA9/AAD+AB+/gAD+AD+/gAD+AD+/gAD8AH+fgAD8AP8fgAD8AP4fgAD8Af4fgAD8A/wfgAD8A/gfgAD8B/gfgAD8D/AfgAD8D+AfgAD8H+AfgAD8P8AfgAD8P4AfgAD8f4AfgAD8/wAfgAD8/gAfgAD+/gA/gAD+/AA/gAB/eAB/AAB/sAD/AAB/wAH/AAA////+AAAf///8AAAP///4AAAH///wAAAD///gAAAA//+AAAAAP/4AAAAAAAAAAAAAAAAAAAAAAAAAAAD8AAAAAAD8AAAAAAD8AAAAAAD8AAAAAAD8AAAAAAD8AAAAAAD/////gAD/////gAD/////gAD/////gAD/////gAD/////gAD/////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//gAAAAH//gAAAAP//gAD8Af//gAD8A///gAD8B///gAD8B///gAD8B/AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD+D+AfgAD//+AfgAD//+AfgAB//8AfgAA//4AfgAAf/wAfgAAP/gAfgAAB8AAfgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD+B+A/gAD/////gAB/////AAB/////AAA////+AAAf///8AAAP///4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//4AAAAD//8AAAAD//+AAAAD//+AAAAD//+AAAAD//+AAAAD//+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAAAB+AAAAD/////gAD/////gAD/////gAD/////gAD/////gAD/////gAD/////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//AAfgAD//wAfgAD//4AfgAD//8AfgAD//8AfgAD//+AfgAD8D+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B/A/gAD8B///gAD8B///gAD8A///AAD8A///AAAAAf/+AAAAAP/4AAAAAD/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB///AAAAH///wAAAf///8AAAf///8AAA////+AAB/////AAB/h+H/AAD/B+B/gAD+B+A/gAD+B+A/gAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B/A/gAD8B///gAD8B///gAD8A///AAAAAf//AAAAAf/+AAAAAH/4AAAAAB/gAAAAAAAAAAAAAAAAAAAAAAAAAAD8AAAAAAD8AAAAAAD8AAAAAAD8AAAAAAD8AAAAgAD8AAABgAD8AAAHgAD8AAAfgAD8AAA/gAD8AAD/gAD8AAP/gAD8AA//gAD8AB//AAD8AH/8AAD8Af/wAAD8A//AAAD8D/+AAAD8P/4AAAD8f/gAAAD9//AAAAD//8AAAAD//wAAAAD//gAAAAD/+AAAAAD/4AAAAAD/wAAAAAD/AAAAAAD8AAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/gAAAAAH/4AAAAAP/8AAAH+f/+AAAf////AAA/////gAB/////gAB///A/gAD//+AfgAD//+AfgAD+D+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD+D+AfgAD//+AfgAD//+AfgAB///A/gAB/////gAA/////AAAP////AAAD+f/+AAAAAP/8AAAAAH/4AAAAAA+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/AAAAAAf/wAAAAA//4AAAAB//8AAAAB//8AfgAD//+AfgAD/D+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD8B+AfgAD+B+A/gAD+B+A/gAD/B+B/gAB/////AAB/////AAA////+AAAf///8AAAP///4AAAH///wAAAB///AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeAAPAAAA/AAfgAAA/AAfgAAA/AAfgAAA/AAfgAAAeAAPAAAAAAAAAAAAAAAAAAAAAAAAAA"); + var scale = 1; // size multiplier for this font + g.setFontCustom(font, 46, widths, 48+(scale<<8)+(1<<16)); +}; + +function getSteps() { + var steps = 0; + try{ + if (WIDGETS.wpedom !== undefined) { + steps = WIDGETS.wpedom.getSteps(); + } else if (WIDGETS.activepedom !== undefined) { + steps = WIDGETS.activepedom.getSteps(); + } else { + steps = Bangle.getHealthStatus("day").steps; + } + } catch(ex) { + // In case we failed, we can only show 0 steps. + return "?"; + } + + return Math.round(steps); +} + +{ // must be inside our own scope here so that when we are unloaded everything disappears + // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global +let drawTimeout; + + +// Actually draw the watch face +let draw = function() { + var x = g.getWidth() / 2; + var y = g.getHeight() / 2; + g.reset().clearRect(Bangle.appRect); // clear whole background (w/o widgets) + var date = new Date(); + var timeStr = require("locale").time(date, 1); // Hour and minute + g.setFontAlign(0, 0).setFont("Audiowide").drawString(timeStr, x, y); + var dateStr = require("locale").date(date, 1).toUpperCase(); + g.setFontAlign(0, 0).setFont("6x8", 2).drawString(dateStr, x, y+28); + g.setFontAlign(0, 0).setFont("6x8", 2); + g.drawString(getSteps(), 50, y+70); + g.drawString(Math.round(Bangle.getHealthStatus("last").bpm), g.getWidth() -37, y + 70); + + // queue next draw + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +}; + +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFontAnton; + }}); +// Load widgets +Bangle.loadWidgets(); +draw(); +setTimeout(Bangle.drawWidgets,0); +} diff --git a/apps/entonclk/app.png b/apps/entonclk/app.png new file mode 100644 index 000000000..5b634de5a Binary files /dev/null and b/apps/entonclk/app.png differ diff --git a/apps/entonclk/metadata.json b/apps/entonclk/metadata.json new file mode 100644 index 000000000..7e4947406 --- /dev/null +++ b/apps/entonclk/metadata.json @@ -0,0 +1,17 @@ +{ + "id": "entonclk", + "name": "Enton Clock", + "version": "0.1", + "description": "A simple clock using the Audiowide font. ", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock", + "supports": ["BANGLEJS2"], + "allow_emulator": true, + "readme":"README.md", + "storage": [ + {"name":"entonclk.app.js","url":"app.js"}, + {"name":"entonclk.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/entonclk/screenshot.png b/apps/entonclk/screenshot.png new file mode 100644 index 000000000..0905c6fc8 Binary files /dev/null and b/apps/entonclk/screenshot.png differ diff --git a/apps/espruinoctrl/README.md b/apps/espruinoctrl/README.md index a7bca662c..7b2e434e7 100644 --- a/apps/espruinoctrl/README.md +++ b/apps/espruinoctrl/README.md @@ -17,7 +17,7 @@ showing available Espruino devices is popped up. device being connected to. Use this if you want to print data - eg: `print(E.getBattery())` When done, click 'Upload'. Your changes will be saved to local storage -so they'll be remembered next time you upload from the same device.s +so they'll be remembered next time you upload from the same device. ## Usage diff --git a/apps/espruinoctrl/app-icon.js b/apps/espruinoctrl/app-icon.js index 70d2dd062..3f9572f72 100644 --- a/apps/espruinoctrl/app-icon.js +++ b/apps/espruinoctrl/app-icon.js @@ -1 +1 @@ -require("heatshrink").decompress(atob("mEwhH+AH4A/AH4A/AH4AFwIuuAAIllAAYIGF041IF34AKqwuuAANXF9QuCAANdGHqQgGBwvdGCIud5mjGB4udAAIwPFz3MSR61VFxQwNci4vGeh4uXGAguHGBK3WGA4AIegtXc69dGBxoBGAouWO4IwNe4gwZa4YwLFwikEFzAwLFwwwCFzQwKFw68YGB4AdF5AwmF5IwlF5QwkF5Yw/F8IwEL9WBB4IuuADwuzGxAugFAgliGBYutAH4A/AH4A/ADA=")) +require("heatshrink").decompress(atob("mEw4UA///muVt9TgH+Jf4AQgILKgtABI9VqkVqAgHqoABC48FBYQKGhEVBQNUBY0qyoLJ1WlEZMq1ILJhWqBZMC1QwCBY0PGAYLGn/qGAQLG/4wDBIkggf8GARfF1ED+BhCTQgTBgfAMISaF1WAAYM61SBG0ADB/wLFgNq1EAHoIcDXYVaCYMP+EqC4kVqwTBn/AhDqFqowBn72HqowCBZAwCBZAwCBZAwCBZIwIiowKBYVWC5VUkAvJXYiaDBYS7FTQVUgr2HC4IgHAAYgHAH4AJA==")) diff --git a/apps/espruinoctrl/metadata.json b/apps/espruinoctrl/metadata.json index 253307fa0..5107bc6ae 100644 --- a/apps/espruinoctrl/metadata.json +++ b/apps/espruinoctrl/metadata.json @@ -5,7 +5,7 @@ "version": "0.01", "description": "Send commands to other Espruino devices via the Bluetooth UART interface. Customisable commands!", "icon": "app.png", - "tags": "", + "tags": "tool,bluetooth", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "custom": "custom.html", diff --git a/apps/espruinoprog/ChangeLog b/apps/espruinoprog/ChangeLog new file mode 100644 index 000000000..6fdcad1d6 --- /dev/null +++ b/apps/espruinoprog/ChangeLog @@ -0,0 +1,4 @@ +0.01: New App! +0.02: Add 'pre' code that can erase the device + Wait more between sending code snippets + Now force use of 'Storage' (assume 2v00 or later) diff --git a/apps/espruinoprog/README.md b/apps/espruinoprog/README.md new file mode 100644 index 000000000..aef4cccad --- /dev/null +++ b/apps/espruinoprog/README.md @@ -0,0 +1,43 @@ +# Espruino Programmer + +Finds Bluetooth devices with a specific name (eg `Puck.js`), connects and uploads code. Great for programming many devices at once! + +**WARNING:** This will reprogram **any matching Espruino device within range** while +the app is running. Unless you are careful to remove other devices from the area or +turn them off, you could find some of your devices unexpectedly get programmed! + +## Customising + +Click on the Customise button in the app loader to set up the programmer. + +* First you need to choose the kind of devices you want to upload to. This is +the text that should match the Bluetooth advertising name. So `Puck.js` for Puck.js +devices, or `Bangle.js` for Bangles. +* In the next box, you have code to run before the upload of the main code. By default +the code `require("Storage").list().forEach(f=>require("Storage").erase(f));reset();` will +erase all files on the device and reset it. +* Now paste in the code you want to write to the device. This is automatically +written to flash (`.bootcde`). See https://www.espruino.com/Saving#save-on-send-to-flash- +for more information. +* Now enter the code that should be sent **after** programming. This code +should make the device so it doesn't advertise on Bluetooth with the Bluetooth +name you entered for the first item. It may also help if it indicates to you that +the device is programmed properly. + * You could turn advertising off with `NRF.sleep()` + * You could change the advertising name with `NRF.setAdvertising({},{name:"Ok"});` + * On a Bangle, you could turn it off with `Bangle.off()` +* Finally scroll down and click `Upload` +* Now you can run the new `Programmer` app on the Bangle. + +## Usage + +Just run the app, and as soon as it starts it'll start scanning for +devices to upload to! + +To stop scanning, long-press the button to return to the clock. + +## Notes + +* This assumes the device being written to is at least version 2v00 of Espruino +* Currently, code is not minified before upload (so you need to supply pre-minified + code if you want that) diff --git a/apps/espruinoprog/app-icon.js b/apps/espruinoprog/app-icon.js new file mode 100644 index 000000000..532c60eea --- /dev/null +++ b/apps/espruinoprog/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4cA/4AB7wJB8/5uX+7uUgH41lSKf4AKpMkyQCCggEDAQVtCAMCCNWUx9JufSrmkCJeKqsiytICJtFkWRCJWAEaARCI5BkEoAGBymJ9eSvXkCJZ9JCLI1DyM9uQRLNYWRpRZMR5ARWAwSPCuWR9MuCJZZIgARGPouTCIcSA4OQAoMW7dt2wCEEZECCI1oCJAADrZyBAAcDuQRByOABQkKDAvbtwRBxu24AMFAAcGCIY/B7AQIhpOC3MjKIVsCJe3jYRCwiPEkARBQg227ieDAQO0CJPhCKHJCK1N0ARI28JCIjUDEY4OBzWRfAoRG3ARBygRH3oPBswRB4QjFfAYgCt9pYoJoEkmbCJONCI1ACJGSiQRE7TXDCIuQEYkmCIhpDEYSCFCIj2DCIOTrYRE6ARDAH4AHA")) diff --git a/apps/espruinoprog/app.js b/apps/espruinoprog/app.js new file mode 100644 index 000000000..58fac4a0b --- /dev/null +++ b/apps/espruinoprog/app.js @@ -0,0 +1,100 @@ +var uart; // require("ble_uart") +var device; // BluetoothDevice +var uploadTimeout; // a timeout used during upload - if we disconnect, kill this +Bangle.loadWidgets(); + +var json = require("Storage").readJSON("espruinoprog.json",1); +/*var json = { // for example + namePrefix : "Puck.js ", + code : "E.setBootCode('digitalPulse(LED2,1,100);')", + post : "LED.set();NRF.sleep()", +};*/ + +if ("object" != typeof json) { + E.showAlert("JSON not found","Programmer").then(() => load()); + throw new Error("JSON not found"); + // stops execution +} + +// Set up terminal +var R = Bangle.appRect; +var termg = Graphics.createArrayBuffer(R.w, R.h, 1, {msb:true}); +termg.setFont("6x8"); +var term; + +function showTerminal() { + E.showMenu(); // clear anything that was drawn + if (term) term.print(""); // redraw terminal +} + +function scanAndConnect() { + termg.clear(); + term = require("VT100").connect(termg, { + charWidth : 6, + charHeight : 8 + }); + term.print = str => { + for (var i of str) term.char(i); + g.reset().drawImage(termg,R.x,R.y); + }; + term.print(`\r\nScanning...\r\n`); + NRF.requestDevice({ filters: [{ namePrefix: json.namePrefix }] }).then(function(dev) { + term.print(`Found ${dev.name||dev.id.substr(0,17)}\r\n`); + device = dev; + + term.print(`Connect to ${dev.name||dev.id.substr(0,17)}...\r\n`); + device.removeAllListeners(); + device.on('gattserverdisconnected', function(reason) { + if (!uart) return; + term.print(`\r\nDISCONNECTED (${reason})\r\n`); + uart = undefined; + device = undefined; + if (uploadTimeout) clearTimeout(uploadTimeout); + uploadTimeout = undefined; + setTimeout(scanAndConnect, 1000); + }); + require("ble_uart").connect(device).then(function(u) { + uart = u; + term.print("Connected...\r\n"); + uart.removeAllListeners(); + uart.on('data', function(d) { term.print(d); }); + term.print("Upload initial...\r\n"); + uart.write((json.pre||"")+"\n").then(() => { + term.print("\r\Done.\r\n"); + uploadTimeout = setTimeout(function() { + uploadTimeout = undefined; + term.print("\r\nUpload Code...\r\n"); + uart.write((json.code||"")+"\n").then(() => { + term.print("\r\Done.\r\n"); + // main upload completed - wait a bit + uploadTimeout = setTimeout(function() { + uploadTimeout = undefined; + term.print("\r\Upload final...\r\n"); + // now upload the code to run after... + uart.write((json.post||"")+"\n").then(() => { + term.print("\r\nDone.\r\n"); + // now wait and disconnect (if not already done!) + uploadTimeout = setTimeout(function() { + uploadTimeout = undefined; + term.print("\r\nDisconnecting...\r\n"); + if (uart) uart.disconnect(); + }, 500); + }); + }, 2000); + }); + }, 2000); + }); + }); + }).catch(err => { + if (err.toString().startsWith("No device found")) { + // expected - try again + scanAndConnect(); + } else + term.print(`\r\ERROR ${err.toString()}\r\n`); + }); +} + +// now start +Bangle.drawWidgets(); +showTerminal(); +scanAndConnect(); diff --git a/apps/espruinoprog/app.png b/apps/espruinoprog/app.png new file mode 100644 index 000000000..b2b435f04 Binary files /dev/null and b/apps/espruinoprog/app.png differ diff --git a/apps/espruinoprog/custom.html b/apps/espruinoprog/custom.html new file mode 100644 index 000000000..a12189707 --- /dev/null +++ b/apps/espruinoprog/custom.html @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + +

Upload code to devices with names starting with:

+

+

Enter the code to send before upload here:

+

+

Enter your program to upload here:

+

+

Enter the code to send after upload here:

+

+

Then click  

+

Click here to reset to defaults.

+ + + + diff --git a/apps/espruinoprog/metadata.json b/apps/espruinoprog/metadata.json new file mode 100644 index 000000000..7371e005d --- /dev/null +++ b/apps/espruinoprog/metadata.json @@ -0,0 +1,18 @@ +{ + "id": "espruinoprog", + "name": "Espruino Programmer", + "shortName": "Programmer", + "version": "0.02", + "description": "Finds Bluetooth devices with a specific name (eg 'Puck.js'), connects and uploads code. Great for programming many devices at once!", + "icon": "app.png", + "tags": "tool,bluetooth", + "supports": ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "custom": "custom.html", + "storage": [ + {"name":"espruinoprog.app.js","url":"app.js"}, + {"name":"espruinoprog.img","url":"app-icon.js","evaluate":true} + ], "data": [ + {"name":"espruinoprog.json"} + ] +} diff --git a/apps/espruinoterm/ChangeLog b/apps/espruinoterm/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/espruinoterm/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/espruinoterm/README.md b/apps/espruinoterm/README.md new file mode 100644 index 000000000..df26d59a0 --- /dev/null +++ b/apps/espruinoterm/README.md @@ -0,0 +1,22 @@ +# Espruino Terminal + +Send commands to other Espruino devices via the Bluetooth UART interface and +see the result on a terminal. + +## Customising + +Once installed and you're connected to the Bangle you can click the button next to the app in the app loader +to change the commands (they will be read from the device). + +When done, click `Save to Bangle.js` and your changes will be saved to the same device. + +## Usage + +* Load the app and after a few seconds you'll see a menu with Espruino devices +in the vicinity. +* Tap on the device you want to connect to +* A terminal will pop up showing `Connecting...` and then `Connected` +* Now tap on the right (or press the button) to bring up a menu with options for commands, or the option to disconnect. + +You can also choose `Custom` in which case a keyboard (using the currently installed text input method) will +be displayed and you can enter the command you would like to send. diff --git a/apps/espruinoterm/app-icon.js b/apps/espruinoterm/app-icon.js new file mode 100644 index 000000000..f566aedf7 --- /dev/null +++ b/apps/espruinoterm/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwcCpMkyQC/AVW//4AK/oR/COD8LCP4R/CK8DCKNsCKFt2BHPhu2CJ8BCKAjQI4OQNaIUB23bsCPMCJzp/CP4Rf/4AKCKwC/AVIA==")) diff --git a/apps/espruinoterm/app.js b/apps/espruinoterm/app.js new file mode 100644 index 000000000..348190db4 --- /dev/null +++ b/apps/espruinoterm/app.js @@ -0,0 +1,101 @@ +var uart; // require("ble_uart") +var device; // BluetoothDevice +var customCommand = ""; +// Set up terminal +Bangle.loadWidgets(); +var R = Bangle.appRect; +var termg = Graphics.createArrayBuffer(R.w, R.h, 1, {msb:true}); +var termVisible = false; +termg.setFont("6x8"); +term = require("VT100").connect(termg, { + charWidth : 6, + charHeight : 8 +}); +term.print = str => { + for (var i of str) term.char(i); + if (termVisible) g.reset().drawImage(termg,R.x,R.y).setFont("6x8").setFontAlign(0,-1,1).drawString("MORE",R.w-1,(R.y+R.y2)/2); +}; + +function showConnectMenu() { + termVisible = false; + var m = { "" : {title:"Devices"} }; + E.showMessage("Scanning..."); + NRF.findDevices(devices => { + devices.forEach(dev=>{ + m[dev.name||dev.id.substr(0,17)] = ()=>{ + connectTo(dev); + }; + }); + m["< Back"] = () => showConnectMenu(); + E.showMenu(m); + },{filters:[ + { namePrefix: 'Puck.js' }, + { namePrefix: 'Pixl.js' }, + { namePrefix: 'MDBT42Q' }, + { namePrefix: 'Bangle.js' }, + { namePrefix: 'Espruino' }, + { services: [ "6e400001-b5a3-f393-e0a9-e50e24dcca9e" ] } + ],active:true,timeout:4000}); +} + +function showOptionsMenu() { + if (!uart) showConnectMenu(); + termVisible = false; + var menu = {"":{title:/*LANG*/"Options"}, + "< Back" : () => showTerminal(), + }; + var json = require("Storage").readJSON("espruinoterm.json",1); + if (Array.isArray(json)) { + json.forEach(j => { menu[j.title] = () => sendCommand(j.cmd); }); + } else { + Object.assign(menu,{ + "Version" : () => sendCommand("process.env.VERSION"), + "Battery" : () => sendCommand("E.getBattery()"), + "Flash LED" : () => sendCommand("LED.set();setTimeout(()=>LED.reset(),1000);") + }); + } + menu[/*LANG*/"Custom"] = () => { require("textinput").input({text:customCommand}).then(result => { + customCommand = result; + sendCommand(customCommand); + })}; + menu[/*LANG*/"Disconnect"] = () => { showTerminal(); term.print("\r\nDisconnecting...\r\n"); uart.disconnect(); } + + E.showMenu(menu); +} + +function showTerminal() { + E.showMenu(); + Bangle.setUI({ + mode : "custom", + btn : n=> { showOptionsMenu(); }, + touch : (n,e) => { if (n==2) showOptionsMenu(); } + }); + termVisible = true; + term.print(""); // redraw terminal +} + +function sendCommand(cmd) { + showTerminal(); + uart.write(cmd+"\n"); +} + +function connectTo(dev) { + device = dev; + showTerminal(); + term.print(`\r\nConnect to ${dev.name||dev.id.substr(0,17)}...\r\n`); + device.on('gattserverdisconnected', function(reason) { + term.print(`\r\nDISCONNECTED (${reason})\r\n`); + uart = undefined; + device = undefined; + setTimeout(showConnectMenu, 1000); + }); + require("ble_uart").connect(device).then(function(u) { + uart = u; + term.print("Connected...\r\n"); + uart.on('data', function(d) { term.print(d); }); + }); +} + +// now start +Bangle.drawWidgets(); +showConnectMenu(); diff --git a/apps/espruinoterm/app.json b/apps/espruinoterm/app.json new file mode 100644 index 000000000..72a12e635 --- /dev/null +++ b/apps/espruinoterm/app.json @@ -0,0 +1,5 @@ +[ + {"title":"Version", "cmd":"process.env.VERSION"}, + {"title":"Battery", "cmd":"E.getBattery()"}, + {"title":"Flash LED", "cmd":"LED.set();setTimeout(()=>LED.reset(),1000);"} +] diff --git a/apps/espruinoterm/app.png b/apps/espruinoterm/app.png new file mode 100644 index 000000000..e9a8c3758 Binary files /dev/null and b/apps/espruinoterm/app.png differ diff --git a/apps/espruinoterm/interface.html b/apps/espruinoterm/interface.html new file mode 100644 index 000000000..660b3a86c --- /dev/null +++ b/apps/espruinoterm/interface.html @@ -0,0 +1,104 @@ + + + + + + + + +

Enter the menu items you'd like to see appear in the app below. When finished, click `Save to Bangle.js` to save the JavaScript back.

+
+ + + + + + + + + + +
TitleCommand
+
+

+ + + + + + diff --git a/apps/espruinoterm/metadata.json b/apps/espruinoterm/metadata.json new file mode 100644 index 000000000..25e6183e1 --- /dev/null +++ b/apps/espruinoterm/metadata.json @@ -0,0 +1,20 @@ +{ + "id": "espruinoterm", + "name": "Espruino Terminal", + "shortName": "Espruino Term", + "version": "0.01", + "description": "Send commands to other Espruino devices via the Bluetooth UART interface, and see the result on a VT100 terminal. Customisable commands!", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "tags": "tool,bluetooth", + "supports": ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "interface": "interface.html", + "dependencies": {"textinput":"type"}, + "storage": [ + {"name":"espruinoterm.app.js","url":"app.js"}, + {"name":"espruinoterm.img","url":"app-icon.js","evaluate":true} + ],"data": [ + {"name":"espruinoterm.json","url":"app.json"} + ] +} diff --git a/apps/espruinoterm/screenshot.png b/apps/espruinoterm/screenshot.png new file mode 100644 index 000000000..cce881a37 Binary files /dev/null and b/apps/espruinoterm/screenshot.png differ diff --git a/apps/f9lander/ChangeLog b/apps/f9lander/ChangeLog index 5560f00bc..a13f2a313 100644 --- a/apps/f9lander/ChangeLog +++ b/apps/f9lander/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Add lightning diff --git a/apps/f9lander/app.js b/apps/f9lander/app.js index 7e52104c0..2f17a5bd5 100644 --- a/apps/f9lander/app.js +++ b/apps/f9lander/app.js @@ -46,6 +46,9 @@ var booster = { x : g.getWidth()/4 + Math.random()*g.getWidth()/2, var exploded = false; var nExplosions = 0; var landed = false; +var lightning = 0; + +var settings = require("Storage").readJSON('f9settings.json', 1) || {}; const gravity = 4; const dt = 0.1; @@ -61,18 +64,40 @@ function flameImageGen (throttle) { function drawFalcon(x, y, throttle, angle) { g.setColor(1, 1, 1).drawImage(falcon9, x, y, {rotate:angle}); - if (throttle>0) { + if (throttle>0 || lightning>0) { var flameImg = flameImageGen(throttle); var r = falcon9.height/2 + flameImg.height/2-1; var xoffs = -Math.sin(angle)*r; var yoffs = Math.cos(angle)*r; if (Math.random()>0.7) g.setColor(1, 0.5, 0); else g.setColor(1, 1, 0); - g.drawImage(flameImg, x+xoffs, y+yoffs, {rotate:angle}); + if (throttle>0) g.drawImage(flameImg, x+xoffs, y+yoffs, {rotate:angle}); + if (lightning>1 && lightning<30) { + for (var i=0; i<6; ++i) { + var r = Math.random()*6; + var x = Math.random()*5 - xoffs; + var y = Math.random()*5 - yoffs; + g.setColor(1, Math.random()*0.5+0.5, 0).fillCircle(booster.x+x, booster.y+y, r); + } + } } } +function drawLightning() { + var c = {x:cloudOffs+50, y:30}; + var dx = c.x-booster.x; + var dy = c.y-booster.y; + var m1 = {x:booster.x+0.6*dx+Math.random()*20, y:booster.y+0.6*dy+Math.random()*10}; + var m2 = {x:booster.x+0.4*dx+Math.random()*20, y:booster.y+0.4*dy+Math.random()*10}; + g.setColor(1, 1, 1).drawLine(c.x, c.y, m1.x, m1.y).drawLine(m1.x, m1.y, m2.x, m2.y).drawLine(m2.x, m2.y, booster.x, booster.y); +} + function drawBG() { + if (lightning==1) { + g.setBgColor(1, 1, 1).clear(); + Bangle.buzz(200); + return; + } g.setBgColor(0.2, 0.2, 1).clear(); g.setColor(0, 0, 1).fillRect(0, g.getHeight()-oceanHeight, g.getWidth()-1, g.getHeight()-1); g.setColor(0.5, 0.5, 1).fillCircle(cloudOffs+34, 30, 15).fillCircle(cloudOffs+60, 35, 20).fillCircle(cloudOffs+75, 20, 10); @@ -88,6 +113,7 @@ function renderScreen(input) { drawBG(); showFuel(); drawFalcon(booster.x, booster.y, Math.floor(input.throttle*12), input.angle); + if (lightning>1 && lightning<6) drawLightning(); } function getInputs() { @@ -97,6 +123,7 @@ function getInputs() { if (t > 1) t = 1; if (t < 0) t = 0; if (booster.fuel<=0) t = 0; + if (lightning>0 && lightning<20) t = 0; return {throttle: t, angle: a}; } @@ -121,7 +148,6 @@ function gameStep() { else { var input = getInputs(); if (booster.y >= targetY) { -// console.log(booster.x + " " + booster.y + " " + booster.vy + " " + droneX + " " + input.angle); if (Math.abs(booster.x-droneX-droneShip.width/2)40) && Math.random()>0.98) lightning = 1; booster.x += booster.vx*dt; booster.y += booster.vy*dt; booster.vy += gravity*dt; diff --git a/apps/f9lander/metadata.json b/apps/f9lander/metadata.json index 75c6a0164..1db777099 100644 --- a/apps/f9lander/metadata.json +++ b/apps/f9lander/metadata.json @@ -1,7 +1,7 @@ { "id": "f9lander", "name": "Falcon9 Lander", "shortName":"F9lander", - "version":"0.01", + "version":"0.02", "description": "Land a rocket booster", "icon": "f9lander.png", "screenshots" : [ { "url":"f9lander_screenshot1.png" }, { "url":"f9lander_screenshot2.png" }, { "url":"f9lander_screenshot3.png" }], @@ -10,6 +10,7 @@ "supports" : ["BANGLEJS", "BANGLEJS2"], "storage": [ {"name":"f9lander.app.js","url":"app.js"}, - {"name":"f9lander.img","url":"app-icon.js","evaluate":true} + {"name":"f9lander.img","url":"app-icon.js","evaluate":true}, + {"name":"f9lander.settings.js", "url":"settings.js"} ] } diff --git a/apps/f9lander/settings.js b/apps/f9lander/settings.js new file mode 100644 index 000000000..0f9fba302 --- /dev/null +++ b/apps/f9lander/settings.js @@ -0,0 +1,36 @@ +// This file should contain exactly one function, which shows the app's settings +/** + * @param {function} back Use back() to return to settings menu + */ +const boolFormat = v => v ? /*LANG*/"On" : /*LANG*/"Off"; +(function(back) { + const SETTINGS_FILE = 'f9settings.json' + // initialize with default settings... + let settings = { + 'lightning': false, + } + // ...and overwrite them with any saved values + // This way saved values are preserved if a new version adds more settings + const storage = require('Storage') + const saved = storage.readJSON(SETTINGS_FILE, 1) || {} + for (const key in saved) { + settings[key] = saved[key]; + } + // creates a function to safe a specific setting, e.g. save('color')(1) + function save(key) { + return function (value) { + settings[key] = value; + storage.write(SETTINGS_FILE, settings); + } + } + const menu = { + '': { 'title': 'OpenWind' }, + '< Back': back, + 'Lightning': { + value: settings.lightning, + format: boolFormat, + onchange: save('lightning'), + } + } + E.showMenu(menu); +}) diff --git a/apps/fastload/ChangeLog b/apps/fastload/ChangeLog new file mode 100644 index 000000000..53e3c2591 --- /dev/null +++ b/apps/fastload/ChangeLog @@ -0,0 +1,3 @@ +0.01: New App! +0.02: Allow redirection of loads to the launcher +0.03: Allow hiding the fastloading info screen diff --git a/apps/fastload/README.md b/apps/fastload/README.md new file mode 100644 index 000000000..a1feedcf8 --- /dev/null +++ b/apps/fastload/README.md @@ -0,0 +1,21 @@ +# Fastload Utils + +*EXPERIMENTAL* Use this with caution. When you find something misbehaving please check if the problem actually persists when removing this app. + +This allows fast loading of all apps with two conditions: +* Loaded app contains `Bangle.loadWidgets`. This is needed to prevent problems with apps not expecting widgets to be already loaded. +* Current app can be removed completely from RAM. + +## Settings + +* Allows to redirect all loads usually loading the clock to the launcher instead +* The "Fastloading..." screen can be switched off + +## Technical infos + +This is still experimental but it uses the same mechanism as `.bootcde` does. +It checks the app to be loaded for widget use and stores the result of that and a hash of the js in a cache. + +# Creator + +[halemmerich](https://github.com/halemmerich) diff --git a/apps/fastload/boot.js b/apps/fastload/boot.js new file mode 100644 index 000000000..c9271abbf --- /dev/null +++ b/apps/fastload/boot.js @@ -0,0 +1,66 @@ +{ +const SETTINGS = require("Storage").readJSON("fastload.json") || {}; + +let loadingScreen = function(){ + g.reset(); + + let x = g.getWidth()/2; + let y = g.getHeight()/2; + g.setColor(g.theme.bg); + g.fillRect(x-49, y-19, x+49, y+19); + g.setColor(g.theme.fg); + g.drawRect(x-50, y-20, x+50, y+20); + g.setFont("6x8"); + g.setFontAlign(0,0); + g.drawString("Fastloading...", x, y); + g.flip(true); +}; + +let cache = require("Storage").readJSON("fastload.cache") || {}; + +let checkApp = function(n){ + // no widgets, no problem + if (!global.WIDGETS) return true; + let app = require("Storage").read(n); + if (cache[n] && E.CRC32(app) == cache[n].crc) + return cache[n].fast + cache[n] = {}; + cache[n].fast = app.includes("Bangle.loadWidgets"); + cache[n].crc = E.CRC32(app); + require("Storage").writeJSON("fastload.cache", cache); + return cache[n].fast; +} + +global._load = load; + +let slowload = function(n){ + global._load(n); +} + +let fastload = function(n){ + if (!n || checkApp(n)){ + // Bangle.load can call load, to prevent recursion this must be the system load + global.load = slowload; + Bangle.load(n); + // if fastloading worked, we need to set load back to this method + global.load = fastload; + } + else + slowload(n); +}; +global.load = fastload; + +Bangle.load = (o => (name) => { + if (Bangle.uiRemove && !SETTINGS.hideLoading) loadingScreen(); + if (SETTINGS.autoloadLauncher && !name){ + let orig = Bangle.load; + Bangle.load = (n)=>{ + Bangle.load = orig; + fastload(n); + } + Bangle.showLauncher(); + Bangle.load = orig; + } else + o(name); +})(Bangle.load); +} diff --git a/apps/fastload/icon.png b/apps/fastload/icon.png new file mode 100644 index 000000000..7fe9afe6e Binary files /dev/null and b/apps/fastload/icon.png differ diff --git a/apps/fastload/metadata.json b/apps/fastload/metadata.json new file mode 100644 index 000000000..15adcb7e3 --- /dev/null +++ b/apps/fastload/metadata.json @@ -0,0 +1,16 @@ +{ "id": "fastload", + "name": "Fastload Utils", + "shortName" : "Fastload Utils", + "version": "0.03", + "icon": "icon.png", + "description": "Enable experimental fastloading for more apps", + "type":"bootloader", + "tags": "system", + "supports": ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"fastload.5.boot.js","url":"boot.js"}, + {"name":"fastload.settings.js","url":"settings.js"} + ], + "data": [{"name":"fastload.json"}] +} diff --git a/apps/fastload/settings.js b/apps/fastload/settings.js new file mode 100644 index 000000000..4904e057e --- /dev/null +++ b/apps/fastload/settings.js @@ -0,0 +1,38 @@ +(function(back) { + var FILE="fastload.json"; + var settings; + + function writeSettings(key, value) { + var s = require('Storage').readJSON(FILE, true) || {}; + s[key] = value; + require('Storage').writeJSON(FILE, s); + readSettings(); + } + + function readSettings(){ + settings = require('Storage').readJSON(FILE, true) || {}; + } + + readSettings(); + + function buildMainMenu(){ + var mainmenu = { + '': { 'title': 'Fastload', back: back }, + 'Force load to launcher': { + value: !!settings.autoloadLauncher, + onchange: v => { + writeSettings("autoloadLauncher",v); + } + }, + 'Hide "Fastloading..."': { + value: !!settings.hideLoading, + onchange: v => { + writeSettings("hideLoading",v); + } + } + }; + return mainmenu; + } + + E.showMenu(buildMainMenu()); +}) diff --git a/apps/fclock/ChangeLog b/apps/fclock/ChangeLog index 30e049f69..7e7307c59 100644 --- a/apps/fclock/ChangeLog +++ b/apps/fclock/ChangeLog @@ -1,2 +1,3 @@ 0.01: First published version of app 0.02: Move to Bangle.setUI to launcher support +0.03: Tell clock widgets to hide. diff --git a/apps/fclock/fclock.app.js b/apps/fclock/fclock.app.js index afa0c5e2d..838a5578d 100644 --- a/apps/fclock/fclock.app.js +++ b/apps/fclock/fclock.app.js @@ -173,6 +173,9 @@ const drawHR = function () { } }; +// Show launcher when button pressed +Bangle.setUI("clock"); + // clean app screen g.clear(); Bangle.loadWidgets(); @@ -198,6 +201,3 @@ Bangle.on('HRM', function (d) { // draw now drawClock(); - -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/fclock/metadata.json b/apps/fclock/metadata.json index da553e110..dffb197a2 100644 --- a/apps/fclock/metadata.json +++ b/apps/fclock/metadata.json @@ -2,7 +2,7 @@ "id": "fclock", "name": "fclock", "shortName": "F Clock", - "version": "0.02", + "version": "0.03", "description": "Simple design of a digital clock", "icon": "app.png", "type": "clock", diff --git a/apps/files/ChangeLog b/apps/files/ChangeLog index 1908f7e5c..4622e6f0f 100644 --- a/apps/files/ChangeLog +++ b/apps/files/ChangeLog @@ -3,4 +3,5 @@ 0.04: Add functionality to sort apps manually or alphabetically ascending/descending. 0.05: Tweaks to help with memory usage 0.06: Reduce memory usage -0.07: Allow negative numbers when manual-sorting \ No newline at end of file +0.07: Allow negative numbers when manual-sorting +0.08: Automatic translation of strings. diff --git a/apps/files/files.js b/apps/files/files.js index e81e9589f..2f7b5c9a1 100644 --- a/apps/files/files.js +++ b/apps/files/files.js @@ -3,20 +3,20 @@ const store = require('Storage'); function showMainMenu() { const mainmenu = { '': { - 'title': 'App Manager', + 'title': /*LANG*/'App Manager', }, '< Back': ()=> {load();}, - 'Sort Apps': () => showSortAppsMenu(), - 'Manage Apps': ()=> showApps(), - 'Compact': () => { - E.showMessage('Compacting...'); + /*LANG*/'Sort Apps': () => showSortAppsMenu(), + /*LANG*/'Manage Apps': ()=> showApps(), + /*LANG*/'Compact': () => { + E.showMessage(/*LANG*/'Compacting...'); try { store.compact(); } catch (e) { } showMainMenu(); }, - 'Free': { + /*LANG*/'Free': { value: undefined, format: (v) => { return store.getFree(); @@ -65,13 +65,13 @@ function eraseData(info) { }); } function eraseApp(app, files,data) { - E.showMessage('Erasing\n' + app.name + '...'); + E.showMessage(/*LANG*/'Erasing\n' + app.name + '...'); var info = store.readJSON(app.id + ".info", 1)||{}; if (files) eraseFiles(info); if (data) eraseData(info); } function eraseOne(app, files,data){ - E.showPrompt('Erase\n'+app.name+'?').then((v) => { + E.showPrompt(/*LANG*/'Erase\n'+app.name+'?').then((v) => { if (v) { Bangle.buzz(100, 1); eraseApp(app, files, data); @@ -82,7 +82,7 @@ function eraseOne(app, files,data){ }); } function eraseAll(apps, files,data) { - E.showPrompt('Erase all?').then((v) => { + E.showPrompt(/*LANG*/'Erase all?').then((v) => { if (v) { Bangle.buzz(100, 1); apps.forEach(app => eraseApp(app, files, data)); @@ -99,11 +99,11 @@ function showAppMenu(app) { '< Back': () => showApps(), }; if (app.hasData) { - appmenu['Erase Completely'] = () => eraseOne(app, true, true); - appmenu['Erase App,Keep Data'] = () => eraseOne(app, true, false); - appmenu['Only Erase Data'] = () => eraseOne(app, false, true); + appmenu[/*LANG*/'Erase Completely'] = () => eraseOne(app, true, true); + appmenu[/*LANG*/'Erase App,Keep Data'] = () => eraseOne(app, true, false); + appmenu[/*LANG*/'Only Erase Data'] = () => eraseOne(app, false, true); } else { - appmenu['Erase'] = () => eraseOne(app, true, false); + appmenu[/*LANG*/'Erase'] = () => eraseOne(app, true, false); } E.showMenu(appmenu); } @@ -111,7 +111,7 @@ function showAppMenu(app) { function showApps() { const appsmenu = { '': { - 'title': 'Apps', + 'title': /*LANG*/'Apps', }, '< Back': () => showMainMenu(), }; @@ -128,17 +128,17 @@ function showApps() { menu[app.name] = () => showAppMenu(app); return menu; }, appsmenu); - appsmenu['Erase All'] = () => { + appsmenu[/*LANG*/'Erase All'] = () => { E.showMenu({ - '': {'title': 'Erase All'}, - 'Erase Everything': () => eraseAll(list, true, true), - 'Erase Apps,Keep Data': () => eraseAll(list, true, false), - 'Only Erase Data': () => eraseAll(list, false, true), + '': {'title': /*LANG*/'Erase All'}, + /*LANG*/'Erase Everything': () => eraseAll(list, true, true), + /*LANG*/'Erase Apps,Keep Data': () => eraseAll(list, true, false), + /*LANG*/'Only Erase Data': () => eraseAll(list, false, true), '< Back': () => showApps(), }); }; } else { - appsmenu['...No Apps...'] = { + appsmenu[/*LANG*/'...No Apps...'] = { value: undefined, format: ()=> '', onchange: ()=> {} @@ -150,16 +150,16 @@ function showApps() { function showSortAppsMenu() { const sorterMenu = { '': { - 'title': 'App Sorter', + 'title': /*LANG*/'App Sorter', }, '< Back': () => showMainMenu(), - 'Sort: manually': ()=> showSortAppsManually(), - 'Sort: alph. ASC': () => { - E.showMessage('Sorting:\nAlphabetically\nascending ...'); + /*LANG*/'Sort: manually': ()=> showSortAppsManually(), + /*LANG*/'Sort: alph. ASC': () => { + E.showMessage(/*LANG*/'Sorting:\nAlphabetically\nascending ...'); sortAlphabet(false); }, 'Sort: alph. DESC': () => { - E.showMessage('Sorting:\nAlphabetically\ndescending ...'); + E.showMessage(/*LANG*/'Sorting:\nAlphabetically\ndescending ...'); sortAlphabet(true); } }; @@ -169,7 +169,7 @@ function showSortAppsMenu() { function showSortAppsManually() { const appsSorterMenu = { '': { - 'title': 'Sort: manually', + 'title': /*LANG*/'Sort: manually', }, '< Back': () => showSortAppsMenu(), }; @@ -186,7 +186,7 @@ function showSortAppsManually() { return menu; }, appsSorterMenu); } else { - appsSorterMenu['...No Apps...'] = { + appsSorterMenu[/*LANG*/'...No Apps...'] = { value: undefined, format: ()=> '', onchange: ()=> {} diff --git a/apps/files/metadata.json b/apps/files/metadata.json index ac73a7717..a53f914e6 100644 --- a/apps/files/metadata.json +++ b/apps/files/metadata.json @@ -1,7 +1,7 @@ { "id": "files", "name": "App Manager", - "version": "0.07", + "version": "0.08", "description": "Show currently installed apps, free space, and allow their deletion from the watch", "icon": "files.png", "tags": "tool,system,files", diff --git a/apps/flappy/ChangeLog b/apps/flappy/ChangeLog index 349cb9d07..d660f85aa 100644 --- a/apps/flappy/ChangeLog +++ b/apps/flappy/ChangeLog @@ -2,3 +2,4 @@ 0.03: A few tweaks to improve rendering speed 0.04: Add "ram" keyword to allow 2v06 Espruino builds to cache function that needs to be fast 0.05: Don't use Bangle.setLCDMode, just use offscreen buffer (allows widgets) +0.06: Bangle.js 2 enhancements - remove offscreen buffer and render direct diff --git a/apps/flappy/app.js b/apps/flappy/app.js index e9ca31fa5..70553fe97 100644 --- a/apps/flappy/app.js +++ b/apps/flappy/app.js @@ -1,19 +1,20 @@ -b = Graphics.createArrayBuffer(120,120,8); -var gimg = { - width:120, - height:104, - bpp:8, - buffer:b.buffer - }; - +var Y; if (process.env.HWVERSION==2) { - b.flip = function() { - g.drawImage(gimg,28,50); - }; + // we have offscreen graphics, so just go direct + b = g; + Y = 24; // widgets } else { + b = Graphics.createArrayBuffer(120,120,8); + var gimg = { + width:120, + height:104, + bpp:8, + buffer:b.buffer + }; b.flip = function() { g.drawImage(gimg,0,24,{scale:2}); }; + Y = 0; // we offset for widgets anyway } var BIRDIMG = E.toArrayBuffer(atob("EQyI/v7+/v7+/gAAAAAAAP7+/v7+/v7+/gYG0tLS0gDXAP7+/v7+/v4A0tLS0tIA19fXAP7+/v4AAAAA0tLS0gDX1wDXAP7+ANfX19cA0tLSANfXANcA/v4A19fX19cA0tLSANfX1wD+/gDS19fX0gDS0tLSAAAAAAD+/gDS0tIA0tLS0gDAwMDAwAD+/gAAAM3Nzc0AwAAAAAAA/v7+/v4Azc3Nzc0AwMDAwAD+/v7+/v4AAM3Nzc0AAAAAAP7+/v7+/v7+AAAAAP7+/v7+/g==")) @@ -30,14 +31,14 @@ function newBarrier(x) { barriers.push({ x1 : x-7, x2 : x+7, - y : 20+Math.random()*38, + y : Y+20+Math.random()*38, gap : 12+Math.random()*15 }); } function gameStart() { running = true; - birdy = 48/2; + birdy = Y + 48/2; birdvy = 0; barriers = []; for (var i=38;ibbot)) gameStop(); }); diff --git a/apps/flappy/metadata.json b/apps/flappy/metadata.json index 910797066..cb50f0094 100644 --- a/apps/flappy/metadata.json +++ b/apps/flappy/metadata.json @@ -1,7 +1,7 @@ { "id": "flappy", "name": "Flappy Bird", - "version": "0.05", + "version": "0.06", "description": "A Flappy Bird game clone", "icon": "app.png", "screenshots": [{"url":"screenshot1_flappy.png"},{"url":"screenshot2_flappy.png"}], diff --git a/apps/football/metadata.json b/apps/football/metadata.json index 253026c39..43e7ac1bf 100644 --- a/apps/football/metadata.json +++ b/apps/football/metadata.json @@ -2,7 +2,7 @@ "id": "football", "name": "football", "shortName": "football", - "version": "1.00", + "version": "1.01", "type": "app", "description": "Classic football game of the CASIO chronometer", "icon": "app.png", diff --git a/apps/ftclock/ChangeLog b/apps/ftclock/ChangeLog index 83ec21ee6..c30dae69f 100644 --- a/apps/ftclock/ChangeLog +++ b/apps/ftclock/ChangeLog @@ -1,3 +1,4 @@ 0.01: first release 0.02: RAM efficient version of `fourTwentyTz.js` (as suggested by @gfwilliams). 0.03: `mkFourTwentyTz.js` now handles new timezonedb.com CSV format +0.04: Tell clock widgets to hide. diff --git a/apps/ftclock/app.js b/apps/ftclock/app.js index b12db10f1..4f2cef895 100644 --- a/apps/ftclock/app.js +++ b/apps/ftclock/app.js @@ -33,6 +33,8 @@ function draw() { // Clear the screen once, at startup g.clear(); +// Show launcher when middle button pressed +Bangle.setUI("clock"); // Load widgets Bangle.loadWidgets(); Bangle.drawWidgets(); @@ -47,5 +49,4 @@ Bangle.on('lcdPower',on=>{ drawTimeout = undefined; } }); -// Show launcher when middle button pressed -Bangle.setUI("clock"); + diff --git a/apps/ftclock/metadata.json b/apps/ftclock/metadata.json index 876feb1bb..96a4f84b9 100644 --- a/apps/ftclock/metadata.json +++ b/apps/ftclock/metadata.json @@ -1,7 +1,7 @@ { "id": "ftclock", "name": "Four Twenty Clock", - "version": "0.03", + "version": "0.04", "description": "A clock that tells when and where it's going to be 4:20 next", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}, {"url":"screenshot1.png"}], diff --git a/apps/fwupdate/ChangeLog b/apps/fwupdate/ChangeLog index 06f84a11a..ea0b48eb9 100644 --- a/apps/fwupdate/ChangeLog +++ b/apps/fwupdate/ChangeLog @@ -5,3 +5,4 @@ 0.03: Improve bootloader update safety. Now sets unsafeFlash:1 to allow flash with 2v11 and later Add CRC checks for common bootloaders that we know don't work 0.04: Include a precompiled bootloader for easy bootloader updates +0.05: Rename Bootloader->DFU and add explanation to avoid confusion with Bootloader app diff --git a/apps/fwupdate/custom.html b/apps/fwupdate/custom.html index 3f8f50b3f..31eb4a256 100644 --- a/apps/fwupdate/custom.html +++ b/apps/fwupdate/custom.html @@ -3,7 +3,7 @@ -

This tool allows you to update the bootloader on Bangle.js 2 devices +

This tool allows you to update the firmware on Bangle.js 2 devices from within the App Loader.

@@ -12,27 +12,41 @@ see the Bangle.js 1 instructions

    -

    Your current firmware version is unknown and bootloader is unknown

    +

    Your current firmware version is unknown and DFU is unknown

Store on Bangle (file named log.csv, download with IDE)

- - - - +

+ +
+

+

+ + + + +

- + + @@ -23,6 +23,10 @@ Options:

+ +
+ +

@@ -30,7 +34,7 @@

Select watchface folder:

or

Select watchface zip file:


- +


@@ -53,15 +57,15 @@ var expectedFiles = 0; var rootZip = new JSZip(); var resourcesZip = rootZip.folder("resources"); - + function isNativeFormat(){ return document.getElementById("useNative").checked; } - + function addDebug(){ return document.getElementById("debugprints").checked; } - + function convertAmazfitTime(time){ var result = {}; if (time.Hours){ @@ -86,7 +90,7 @@ } return result; } - + function convertAmazfitDate(date){ var result = {}; if (date.MonthAndDay.Separate.Day) result.Day = convertAmazfitNumber(date.MonthAndDay.Separate.Day, "Day"); @@ -96,11 +100,11 @@ } return result; } - + var filesToMove={}; - + var zipChangePromise = Promise.resolve(); - + function performFileChanges(){ var promise = Promise.resolve(); //rename all files to just numbers without leading zeroes @@ -109,7 +113,7 @@ var tmp = resultJson[c]; delete resultJson[c]; resultJson[Number(c)] = tmp; - + async function modZip(c){ console.log("Async modification of ", c) var fileRegex = new RegExp(c + ".*"); @@ -118,27 +122,27 @@ console.log("Filedata is", fileData); var extension = resourcesZip.file(fileRegex)[0].name.match(/\.[^.]*$/); var newName = Number(c) + extension; - + console.log("Renaming to", newName); resourcesZip.remove(c + extension); resourcesZip.file(newName, fileData); } promise = promise.then(modZip(c)); - + } - - + + console.log("File moves:", filesToMove); - + for (var c in filesToMove){ var tmp = resultJson[c]; console.log("Handle filemove", c, filesToMove[c], tmp); - + var element = resultJson; var path = filesToMove[c]; - - + + async function modZip(c){ console.log("Async modification of ", c) var fileRegex = new RegExp(c + ".*"); @@ -147,13 +151,13 @@ console.log("Filedata is", fileData); var extension = resourcesZip.file(fileRegex)[0].name.match(/\.[^.]*$/); var newName = Number(c) + extension; - + console.log("Copying to", newName); resourcesZip.file(filesToMove[c].join("/") + extension, fileData); } promise = promise.then(modZip(c)); - - + + for (var i = 0; i< path.length; i++){ if (!element[path[i]]) element[path[i]] = {}; if (i == path.length - 1){ @@ -162,7 +166,7 @@ element = element[path[i]]; } } - + } promise.then(()=>{ document.getElementById('btnUpload').disabled = true; @@ -170,7 +174,7 @@ console.log("After moves", resultJson); return promise; }; - + function convertAmazfitMultistate(multistate, value, minValue, maxValue){ var result = { MultiState: { @@ -186,18 +190,18 @@ if (multistate.ImageIndexOff) filesToMove[multistate.ImageIndexOff] = ["status", value, "off"]; return result; } - + function convertAmazfitStatus(status){ var result = {}; - + if (status.Alarm) result.Alarm = convertAmazfitMultistate(status.Alarm,"Alarm"); if (status.Bluetooth) result.Bluetooth = convertAmazfitMultistate(status.Bluetooth,"Bluetooth"); if (status.DoNotDisturb) result.DoNotDisturb = convertAmazfitMultistate(status.DoNotDisturb,"Notifications"); if (status.Lock) result.Lock = convertAmazfitMultistate(status.Lock,"Lock"); - + return result; } - + function convertAmazfitNumber(element, value, minValue, maxValue){ var number = {}; var result = { @@ -231,10 +235,10 @@ if (maxValue !== undefined) number.MinValue = minValue; return result; } - + function moveWeatherIcons(icon){ filesToMove[icon.ImageIndex + 0] = ["weather", "fallback"]; - + // Light clouds filesToMove[icon.ImageIndex + 1] = ["weather", 801]; // Cloudy, possible rain @@ -280,7 +284,7 @@ // Very heavy shower filesToMove[icon.ImageIndex + 22] = ["weather", 531]; } - + function convertAmazfitTemperature(temp){ var result = {}; result = convertAmazfitNumber(temp.Number, "WeatherTemperature"); @@ -292,15 +296,15 @@ } return result; } - + function convertAmazfitWeather(weather){ var result = {}; - + if (weather.Temperature && weather.Temperature.Current){ if (!result.Temperature) result.Temperature = {}; result.Temperature.Current = convertAmazfitTemperature(weather.Temperature.Current); } - + if (weather.Temperature && weather.Temperature.Today){ if (!result.Temperature) result.Temperature = {}; if (weather.Temperature.Today.Separate){ @@ -325,10 +329,10 @@ } return result; } - + function convertAmazfitActivity(activity){ var result = {}; - + if (activity.Steps){ result.Steps = convertAmazfitNumber(activity.Steps, "Steps"); } @@ -337,7 +341,7 @@ } return result; } - + function convertAmazfitScale(scale, value, minValue, maxValue){ var result = {}; result.Scale = { @@ -354,10 +358,10 @@ Y: c.Y }); } - + return result; } - + function convertAmazfitStepsProgress(steps){ var result = {}; if (steps.GoalImage){ @@ -376,7 +380,7 @@ } return result; } - + function convertAmazfitBattery(battery){ var result = {}; if (battery.Scale){ @@ -387,7 +391,7 @@ } return result; } - + function convertAmazfitImage(image){ var result = { Image: { @@ -399,11 +403,11 @@ }; return result; } - + function convertAmazfitColor(color){ return "#" + color.substring(2); } - + function convertAmazfitHand(hand, rotationValue, minRotationValue, maxRotationValue){ var result = { Filled: !hand.OnlyBorder, @@ -416,18 +420,18 @@ MaxRotationValue: maxRotationValue, MinRotationValue: minRotationValue }; - + result.Vertices = [] for (var c of hand.Shape){ result.Vertices.push(c); } return { Poly: result }; } - + function convertAmazfitAnalog(analog, face){ var result = { }; - + if (analog.Hours){ result.Hours = {}; result.Hours.Hand = convertAmazfitHand(analog.Hours, "Hour12Analog", 0, 12); @@ -462,14 +466,14 @@ } return result; } - + function restructureAmazfitFormat(dataString){ console.log("Amazfit data:", dataString); - - + + var json = JSON.parse(dataString); faceJson = json; - + var result = {}; result.Properties = {}; @@ -477,8 +481,8 @@ result.Properties.Redraw.Unlocked = 60000; result.Properties.Redraw.Locked = 60000; result.Properties.Redraw.Clear = true; - - + + if (json.Background){ result.Background = json.Background; result.Background.Image.ImagePath = []; @@ -489,32 +493,32 @@ result.Time = convertAmazfitTime(json.Time); if (json.AnalogDialFace) result.Time.Plane = 1; } - + if (json.Date){ result.Date = convertAmazfitDate(json.Date); if (json.AnalogDialFace) result.Date.Plane = 1; } - + if (json.Status){ result.Status = convertAmazfitStatus(json.Status); if (json.AnalogDialFace) result.Status.Plane = 1; } - + if (json.Weather){ result.Weather = convertAmazfitWeather(json.Weather); if (json.AnalogDialFace) result.Weather.Plane = 1; } - + if (json.Activity){ result.Activity = convertAmazfitActivity(json.Activity); if (json.AnalogDialFace) result.Activity.Plane = 1; } - + if (json.StepsProgress){ result.StepsProgress = convertAmazfitStepsProgress(json.StepsProgress); if (json.AnalogDialFace) result.StepsProgress.Plane = 1; } - + if (json.Battery){ result.Battery = convertAmazfitBattery(json.Battery); if (json.AnalogDialFace) result.Battery.Plane = 1; @@ -527,7 +531,7 @@ return result; } - + function parseFaceJson(jsonString){ if (isNativeFormat()){ return JSON.parse(jsonString); @@ -535,7 +539,7 @@ return restructureAmazfitFormat(jsonString); } } - + function combineProperty(name, source, target){ if (source[name] && target[name]){ if (Array.isArray(target[name])){ @@ -554,7 +558,7 @@ if (typeof element == "string" || typeof element == "number") return []; for (var c in element){ var next = element[c]; - + combineProperty("X",element,next); combineProperty("Y",element,next); combineProperty("Width",element,next); @@ -569,7 +573,7 @@ combineProperty("MaxRotationValue",element,next); if (typeof element.Plane == "number") next.Plane = element.Plane; next.Layer = element.Layer ? (element.Layer) : "" + c; - + if (["MultiState","Image","CodedImage","Number","Circle","Poly","Rect","Scale"].includes(c)){ result.push({type:c, value: next}); } else { @@ -578,15 +582,12 @@ } return result; } - - function convertToCode(elements, properties, wrapInTimeouts){ + + function convertToCode(elements, properties, wrapInTimeouts, forceUseOrigPlane){ var code = "(function (wr, wf) {\n"; - if (!wrapInTimeouts){ - code += "var ct=Date.now();\n"; - } code += "var lc;\n"; code += "var p = Promise.resolve();\n"; - + //get mapped by layer var counter = 0; var planes = {}; @@ -595,7 +596,7 @@ var c = elements[i].value; console.log("Check element", c); var name = c.Layer; - var plane = wrapInTimeouts ? 1 : 0; + var plane = (wrapInTimeouts && !forceUseOrigPlane) ? 1 : 0; if (typeof c.Plane == "number"){ plane = c.Plane; } @@ -607,72 +608,57 @@ } if (!planeNumbers.includes(0)) planeNumbers.push(0); planeNumbers.sort().reverse(); - + console.log("Found planes", planes, "with numbers", planeNumbers) - - if (wrapInTimeouts && planes == 0) planes = 1; - + code += "p0 = g;\n"; - + for (var planeIndex = 0; planeIndex < planeNumbers.length; planeIndex++){ var layers = planes[planeNumbers[planeIndex]]; var plane = planeNumbers[planeIndex]; - + var lastSetColor; var lastSetBgColor; - + if (plane != 0) code += "if (!p" + plane + ") p" + plane + " = Graphics.createArrayBuffer(g.getWidth(),g.getHeight(),4,{msb:true});\n"; - + if (properties.Redraw && properties.Redraw.Clear){ - if (wrapInTimeouts && plane != 0){ + if (wrapInTimeouts && (plane != 0 || forceUseOrigPlane)){ code += "p = p.then(()=>delay(0)).then(()=>{\n"; } else { code += "p = p.then(()=>{\n"; } - code += "var ct=Date.now();\n" if (addDebug()) code += 'print("Clear for redraw of plane ' + p + '");'+"\n"; code += 'startPerfLog("initialDraw_g.clear");'+"\n"; code += "p" + plane + ".clear(true);\n"; code += 'endPerfLog("initialDraw_g.clear");'+ "\n"; - - code += "drawingTime += Date.now() - ct;\n"; code += "});\n"; } - + var previousPlane = plane + 1; if (previousPlane < planeNumbers.length){ code += "p = p.then(()=>{\n"; - code += "var ct=Date.now();\n"; - + if (addDebug()) code += 'print("Copying of plane ' + previousPlane + ' to display");'+"\n"; //code += "g.drawImage(p" + i + ".asImage());"; code += "p0.drawImage({width: p" + previousPlane + ".getWidth(), height: p" + previousPlane + ".getHeight(), bpp: p" + previousPlane + ".getBPP(), buffer: p" + previousPlane + ".buffer, palette: palette});\n"; - - - code += "drawingTime += Date.now() - ct;\n"; code += "});\n"; } - + console.log("Got layers", layers); for (var layername in layers){ var layerElements = layers[layername]; - + console.log("Layer elements", layername, layerElements); //code for whole layer - - if (wrapInTimeouts && plane != 0){ - code += "p = p.then(()=>delay(0)).then(()=>{\n"; - } else { - code += "p = p.then(()=>{\n"; - } - code += "var ct=Date.now();\n"; + if (addDebug()) code += 'print("Starting layer ' + layername + '");' + "\n"; - + var checkForLayerChange = false; var checkcode = ""; - + if (!(properties.Redraw && properties.Redraw.Clear)){ - checkcode = 'firstDraw'; + checkcode = 's.fd'; for (var i = 0; i< layerElements.length; i++){ var layerElement = layerElements[i]; var referencedElement = elements[layerElements[i].index]; @@ -680,38 +666,38 @@ console.log("Check for change:", layerElement, referencedElement); if (layerElement.element.Value){ if (elementType == "MultiState" && layerElement.element.Value) { - checkcode += '| isChangedMultistate(wf.Collapsed[' + layerElement.index + '].value)'; + checkcode += '| isChangedMultistate(wf.c[' + layerElement.index + '].value)'; } else { - checkcode += '| isChangedNumber(wf.Collapsed[' + layerElement.index + '].value)'; + checkcode += '| isChangedNumber(wf.c[' + layerElement.index + '].value)'; } checkForLayerChange = true; } } } - - + + //code for elements for (var i = 0; i< layerElements.length; i++){ var elementIndex = layerElements[i].index; var c = elements[elementIndex]; console.log("convert to code", c); - + var condition = ""; if (checkcode.length > 0 && checkForLayerChange){ if (condition.length > 0) condition += " && "; condition = '(' + checkcode + ')'; } - + if (c.value.HideOn && c.value.HideOn.includes("Lock")){ if (condition.length > 0) condition += " && "; condition = '!Bangle.isLocked()'; } - + if (c.value.Type == "Once"){ if (condition.length > 0) condition += " && "; - condition += "firstDraw"; + condition += "s.fd"; } - + var planeName = "p" + plane; var colorsetting = ""; if (c.value.ForegroundColor && lastSetColor != c.value.ForegroundColor){ @@ -728,25 +714,28 @@ else colorsetting += planeName + ".setBgColor(\"" + c.value.BackgroundColor + "\");\n"; } - - if (addDebug()) code += 'print("Element condition is ' + condition + '");' + "\n"; - code += "" + colorsetting; - code += (condition.length > 0 ? "if (" + condition + "){\n" : ""); - if (addDebug()) code += 'print("Drawing element ' + elementIndex + ' with type ' + c.type + ' on plane ' + planeName + '");' + "\n"; - code += "draw" + c.type + "(" + planeName + ", wr, wf.Collapsed[" + elementIndex + "].value);\n"; + if (addDebug()) code += 'print("Element condition is ' + condition + '");' + "\n"; + code += (condition.length > 0 ? "if (" + condition + "){\n" : ""); + if (wrapInTimeouts && (plane != 0 || forceUseOrigPlane)){ + code += "p = p.then(()=>delay(0)).then(()=>{\n"; + } else { + code += "p = p.then(()=>{\n"; + } + code += "" + colorsetting; + if (addDebug()) code += 'print("Drawing element ' + elementIndex + ' with type ' + c.type + ' on plane ' + planeName + '");' + "\n"; + code += "draw" + c.type + "(" + planeName + ", wr, wf.c[" + elementIndex + "].value);\n"; + + code += "});\n"; code += (condition.length > 0 ? "}\n" : ""); } - - code += "drawingTime += Date.now() - ct;\n"; - code += "});\n"; } console.log("Current plane is", plane); - - + + } - + code += "return p;})"; console.log("Code:", code); return code @@ -755,14 +744,14 @@ function postProcess(){ moveData(resultJson); console.log("Created data file", resourceDataString, resourceDataOffset, resultJson); - + var properties = faceJson.Properties; - faceJson = { Properties: properties, Collapsed: collapseTree(faceJson,{X:0,Y:0})}; + faceJson = { Properties: properties, c: collapseTree(faceJson,{X:0,Y:0})}; console.log("After collapsing", faceJson); - precompiledJs = convertToCode(faceJson.Collapsed, properties, document.getElementById('timeoutwrap').checked); + precompiledJs = convertToCode(faceJson.c, properties, document.getElementById('timeoutwrap').checked, document.getElementById('forceOrigPlane').checked); console.log("After precompiling", precompiledJs); } - + function convertJsToJson(imgstr){ var E = {}; E.toArrayBuffer = (s)=>s; @@ -781,7 +770,7 @@ function imageLoaded() { var options = {}; - + options.diffusion = infoJson.diffusion ? infoJson.diffusion : "none"; options.compression = false; options.alphaToColor = false; @@ -792,12 +781,12 @@ options.contrast = 0; options.mode = infoJson.color ? infoJson.color : "1bit"; options.output = "object"; - + console.log("Loaded image has path", this.path); var jsonPath = this.path.split("/"); - + var forcedTransparentColorMatch = jsonPath[jsonPath.length-1].match(/.*\.t([^.]+)\..*/) - + var forcedTransparentColor; if (jsonPath[jsonPath.length-1].includes(".t.")){ options.transparent = true; @@ -805,13 +794,13 @@ options.transparent = false; forcedTransparentColor = forcedTransparentColorMatch[1]; } - - + + console.log("image has transparency", options.transparent); console.log("image has forced transparent color", forcedTransparentColor); jsonPath[jsonPath.length-1] = jsonPath[jsonPath.length-1].replace(/([^.]*)\..*/, "$1"); console.log("Loaded image has json path", jsonPath); - + var canvas = document.getElementById("canvas") canvas.width = this.width*2; canvas.height = this.height; @@ -832,7 +821,7 @@ imgstr = imageconverter.RGBAtoString(rgba, options); var outputImageData = new ImageData(options.rgbaOut, options.width, options.height); ctx.putImageData(outputImageData,this.width,0); - + imgstr = convertJsToJson(imgstr); // checkerboard for transparency on original image @@ -840,9 +829,9 @@ imageconverter.RGBAtoCheckerboard(imageData.data, {width:this.width,height:this.height}); ctx.putImageData(imageData,0,0); - + var currentElement = resultJson; - + for (var i = 0; i < jsonPath.length; i++){ if (i == jsonPath.length - 1){ var resultingObject = JSON.parse(imgstr); @@ -854,18 +843,18 @@ currentElement = currentElement[jsonPath[i]]; } } - + handledFiles++; console.log("Expected:", expectedFiles, " handled:", handledFiles); - + if (handledFiles == expectedFiles){ if (!isNativeFormat()) { performFileChanges().then(()=>{ postProcess(); - + rootZip.file("face.json", JSON.stringify(faceJson, null, 2)); rootZip.file("info.json", JSON.stringify(infoJson, null, 2)); - + document.getElementById('btnSave').disabled = false; document.getElementById('btnSaveFace').disabled = false; document.getElementById('btnSaveZip').disabled = false; @@ -873,21 +862,21 @@ }); } else { postProcess(); - + document.getElementById('btnSave').disabled = false; document.getElementById('btnSaveFace').disabled = false; document.getElementById('btnUpload').disabled = false; } } } - + function handleWatchFace(infoFile, faceFile, resourceFiles){ if (isNativeFormat()){ var reader = new FileReader(); reader.path = infoFile.webkitRelativePath; reader.onload = function(event) { infoJson = JSON.parse(reader.result); - + handleFaceJson(faceFile, resourceFiles); }; reader.readAsText(infoFile); @@ -896,18 +885,18 @@ handleFaceJson(faceFile, resourceFiles); } } - + function handleFaceJson(faceFile, resourceFiles){ var reader = new FileReader(); reader.path = faceFile.webkitRelativePath; reader.onload = function(event) { faceJson = parseFaceJson(reader.result); - + handleResourceFiles(resourceFiles); }; reader.readAsText(faceFile); } - + function handleResourceFiles(files){ for (var current of files){ console.log('Handle resource file ', current); @@ -930,25 +919,25 @@ reader.readAsDataURL(current); } } - + function handleFileSelect(event) { handledFiles = 0; expectedFiles = undefined; - + document.getElementById('btnSave').disabled = true; document.getElementById('btnSaveZip').disabled = true; document.getElementById('btnSaveFace').disabled = true; document.getElementById('btnUpload').disabled = true; - + console.log("File select event", event); if (event.target.files.length == 0) return; result = ""; resultJson= {}; - + var resourceFiles = []; var faceFile; var infoFile; - + for (var current of event.target.files){ console.log('Handle file ', current); if (isNativeFormat()){ @@ -983,10 +972,10 @@ } } handleWatchFace(infoFile, faceFile, resourceFiles); - + }; document.getElementById('fileLoader').addEventListener('change', handleFileSelect, false); - + function moveData(json){ console.log("MoveData for", json); for (var k in json){ @@ -1010,7 +999,11 @@ } } } - + + document.getElementById("timeoutwrap").addEventListener("click", function() { + document.getElementById("forceOrigPlane").disabled = !document.getElementById("timeoutwrap").checked; + }); + document.getElementById("btnSave").addEventListener("click", function() { var h = document.createElement('a'); h.href = 'data:text/json;charset=utf-8,' + encodeURI(JSON.stringify(resultJson)); @@ -1019,25 +1012,48 @@ h.click(); }); document.getElementById("btnUpload").addEventListener("click", function() { - + + console.log("Fetching app"); + fetch('app.js').then((r) => { + console.log("Got response", r); + return r.text(); + } + ).then((imageclockSrc) => { + console.log("Got src", imageclockSrc) + + if (!document.getElementById('separateFiles').checked){ + if (precompiledJs.length > 0){ + const replacementString = 'eval(require("Storage").read("imageclock.draw.js"))'; + console.log("Can replace:", imageclockSrc.includes(replacementString)); + imageclockSrc = imageclockSrc.replace(replacementString, precompiledJs); + } + imageclockSrc = imageclockSrc.replace('require("Storage").readJSON("imageclock.face.json")', JSON.stringify(faceJson)); + imageclockSrc = imageclockSrc.replace('require("Storage").readJSON("imageclock.resources.json")', JSON.stringify(resultJson)); + } var appDef = { id : "imageclock", storage:[ - {name:"imageclock.app.js", url:"app.js"}, - {name:"imageclock.resources.json", content: JSON.stringify(resultJson)}, {name:"imageclock.img", url:"app-icon.js", evaluate:true}, ] }; + if (document.getElementById('separateFiles').checked){ + appDef.storage.push({name:"imageclock.app.js", url:"app.js"}); + if (precompiledJs.length > 0){ + appDef.storage.push({name:"imageclock.draw.js", content:precompiledJs}); + } + appDef.storage.push({name:"imageclock.face.json", content: JSON.stringify(faceJson)}); + appDef.storage.push({name:"imageclock.resources.json", content: JSON.stringify(resultJson)}); + } else { + appDef.storage.push({name:"imageclock.app.js", url:"pleaseminifycontent.js", content:imageclockSrc}); + } if (resourceDataString.length > 0){ appDef.storage.push({name:"imageclock.resources.data", content: resourceDataString}); } - appDef.storage.push({name:"imageclock.draw.js", content: precompiledJs.length > 0 ? precompiledJs : "//empty"}); - appDef.storage.push({name:"imageclock.face.json", content: JSON.stringify(faceJson)}); - console.log("Uploading app:", appDef); sendCustomizedApp(appDef); + }); }); - + function handleZipSelect(evt) { @@ -1049,18 +1065,18 @@ document.getElementById('btnSaveZip').disabled = true; document.getElementById('btnUpload').disabled = true; JSZip.loadAsync(f).then(function(zip) { - + console.log("Zip loaded", zip); result = ""; resultJson= {}; - + var resourceFiles = []; - + var promise = zip.file("face.json").async("string").then((data)=>{ console.log("face.json data", data); faceJson = parseFaceJson(data); }); - + if (isNativeFormat()){ promise = promise.then(zip.file("info.json").async("string").then((data)=>{ console.log("info.json data", data); @@ -1071,12 +1087,12 @@ "color": "3bit", "transparent": true }; - + } - + zip.folder("resources").forEach(function (relativePath, file){ console.log("iterating over", relativePath); - + if (!file.dir){ expectedFiles++; promise = promise.then(file.async("blob").then(function (blob) { @@ -1092,10 +1108,10 @@ reader.readAsDataURL(blob); })); } - + }); - - + + }, function (e) { console.log("Error reading " + f.name + ": " + e.message); }); @@ -1104,11 +1120,11 @@ console.log("Zip select event", evt); var files = evt.target.files; - + if (files.length > 1){ alert("Only one file allowed"); } - + handleFile(files[0]); } @@ -1122,7 +1138,7 @@ }); } - + document.getElementById("btnSaveFace").addEventListener("click", function() { var h = document.createElement('a'); h.href = 'data:text/json;charset=utf-8,' + encodeURI(JSON.stringify(faceJson)); @@ -1130,14 +1146,14 @@ h.download = "face.json"; h.click(); }); - + document.getElementById('zipLoader').addEventListener('change', handleZipSelect, false); document.getElementById('btnSaveZip').addEventListener('click', handleZipExport, false); document.getElementById('btnSave').disabled = true; document.getElementById('btnSaveFace').disabled = true; document.getElementById('btnSaveZip').disabled = true; document.getElementById('btnUpload').disabled = true; - + diff --git a/apps/imageclock/metadata.json b/apps/imageclock/metadata.json index c3ece0184..b291ab01e 100644 --- a/apps/imageclock/metadata.json +++ b/apps/imageclock/metadata.json @@ -2,7 +2,7 @@ "id": "imageclock", "name": "Imageclock", "shortName": "Imageclock", - "version": "0.08", + "version": "0.13", "type": "clock", "description": "BETA!!! File formats still subject to change --- This app is a highly customizable watchface. To use it, you need to select a watchface. You can build the watchfaces yourself without programming anything. All you need to do is write some json and create image files.", "icon": "app.png", diff --git a/apps/imgclock/ChangeLog b/apps/imgclock/ChangeLog index 01a6a4248..0895bb66d 100644 --- a/apps/imgclock/ChangeLog +++ b/apps/imgclock/ChangeLog @@ -7,3 +7,5 @@ 0.06: Support 12 hour time 0.07: Don't cut off wide date formats 0.08: Use Bangle.setUI for button/launcher handling +0.09: Bangle.js 2 compatibility +0.10: Tell clock widgets to hide. diff --git a/apps/imgclock/app.js b/apps/imgclock/app.js index 0e4435638..7d74bee82 100644 --- a/apps/imgclock/app.js +++ b/apps/imgclock/app.js @@ -10,8 +10,8 @@ var IX = inf.x, IY = inf.y, IBPP = inf.bpp; var IW = 174, IH = 45, OY = 24; var bgwidth = img.charCodeAt(0); var bgoptions; -if (bgwidth<240) - bgoptions = { scale : 240/bgwidth }; +if (bgwidth{ draw(); } }); -// Show launcher when button pressed -Bangle.setUI("clock"); + diff --git a/apps/imgclock/b2_122240.png b/apps/imgclock/b2_122240.png new file mode 100644 index 000000000..1a3f4daaa Binary files /dev/null and b/apps/imgclock/b2_122240.png differ diff --git a/apps/imgclock/b2_122271.png b/apps/imgclock/b2_122271.png new file mode 100644 index 000000000..31733fb2c Binary files /dev/null and b/apps/imgclock/b2_122271.png differ diff --git a/apps/imgclock/b2_explode.png b/apps/imgclock/b2_explode.png new file mode 100644 index 000000000..5252bbcd2 Binary files /dev/null and b/apps/imgclock/b2_explode.png differ diff --git a/apps/imgclock/b2_thisisfine.png b/apps/imgclock/b2_thisisfine.png new file mode 100644 index 000000000..1b7daaf60 Binary files /dev/null and b/apps/imgclock/b2_thisisfine.png differ diff --git a/apps/imgclock/custom.html b/apps/imgclock/custom.html index 2511f8a54..68d059b80 100644 --- a/apps/imgclock/custom.html +++ b/apps/imgclock/custom.html @@ -5,20 +5,59 @@
+ Please wait...
- + diff --git a/apps/imgclock/metadata.json b/apps/imgclock/metadata.json index 799d11acc..94dff5f17 100644 --- a/apps/imgclock/metadata.json +++ b/apps/imgclock/metadata.json @@ -2,18 +2,19 @@ "id": "imgclock", "name": "Image background clock", "shortName": "Image Clock", - "version": "0.08", + "version": "0.10", "description": "A clock with an image as a background", "icon": "app.png", "type": "clock", "tags": "clock", - "supports": ["BANGLEJS"], + "supports": ["BANGLEJS","BANGLEJS2"], "custom": "custom.html", + "customConnect": true, "storage": [ {"name":"imgclock.app.js","url":"app.js"}, {"name":"imgclock.img","url":"app-icon.js","evaluate":true}, {"name":"imgclock.face.img"}, {"name":"imgclock.face.json"}, - {"name":"imgclock.face.bg","content":""} + {"name":"imgclock.face.bg","content":"X"} ] } diff --git a/apps/impwclock/ChangeLog b/apps/impwclock/ChangeLog index 6555fcc8f..0af7c99d6 100644 --- a/apps/impwclock/ChangeLog +++ b/apps/impwclock/ChangeLog @@ -3,3 +3,4 @@ 0.03: Move to Bangle.setUI to launcher support 0.04: Tweaks for compatibility with BangleJS2 0.05: Time-word now readable on Bangle.js 2 +0.06: Tell clock widgets to hide. diff --git a/apps/impwclock/clock-impword.js b/apps/impwclock/clock-impword.js index c42dbda44..04421017b 100644 --- a/apps/impwclock/clock-impword.js +++ b/apps/impwclock/clock-impword.js @@ -154,6 +154,9 @@ Bangle.on('lcdPower', function(on) { if (on) drawWordClock(); }); +// Show launcher when button pressed +Bangle.setUI("clock"); + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); @@ -172,5 +175,4 @@ Bangle.on('touch',e=>{ } }); -// Show launcher when button pressed -Bangle.setUI("clock"); + diff --git a/apps/impwclock/metadata.json b/apps/impwclock/metadata.json index 733dbb957..1b92ea3ae 100644 --- a/apps/impwclock/metadata.json +++ b/apps/impwclock/metadata.json @@ -1,7 +1,7 @@ { "id": "impwclock", "name": "Imprecise Word Clock", - "version": "0.05", + "version": "0.06", "description": "Imprecise word clock for vacations, weekends, and those who never need accurate time.", "icon": "clock-impword.png", "type": "clock", diff --git a/apps/info/ChangeLog b/apps/info/ChangeLog index 07afedd21..093dd4606 100644 --- a/apps/info/ChangeLog +++ b/apps/info/ChangeLog @@ -1 +1,3 @@ -0.01: Release \ No newline at end of file +0.01: Release +0.02: Recfactoring and show weather data +0.03: Show sizes for used, free and trash through storage.getStats \ No newline at end of file diff --git a/apps/info/info.app.js b/apps/info/info.app.js index c61a88045..ade3f3ebb 100644 --- a/apps/info/info.app.js +++ b/apps/info/info.app.js @@ -1,27 +1,99 @@ -var s = require("Storage"); +const storage = require("Storage"); const locale = require('locale'); var ENV = process.env; var W = g.getWidth(), H = g.getHeight(); var screen = 0; -const maxScreen = 2; + + +var screens = [ + { + name: "General", + items: [ + {name: "Steps", fun: () => getSteps()}, + {name: "HRM", fun: () => getBpm()}, + {name: "", fun: () => ""}, + {name: "Temp.", fun: () => getWeatherTemp()}, + {name: "Humidity", fun: () => getWeatherHumidity()}, + {name: "Wind", fun: () => getWeatherWind()}, + ] + }, + { + name: "Hardware", + items: [ + {name: "Battery", fun: () => E.getBattery() + "%"}, + {name: "Charge?", fun: () => Bangle.isCharging() ? "Yes" : "No"}, + {name: "TempInt.", fun: () => locale.temp(parseInt(E.getTemperature()))}, + {name: "Bluetooth", fun: () => NRF.getSecurityStatus().connected ? "Conn" : "NoConn"}, + {name: "GPS", fun: () => Bangle.isGPSOn() ? "On" : "Off"}, + {name: "Compass", fun: () => Bangle.isCompassOn() ? "On" : "Off"}, + ] + }, + { + name: "Software", + items: [ + {name: "Firmw.", fun: () => ENV.VERSION}, + {name: "Git", fun: () => ENV.GIT_COMMIT}, + {name: "Boot.", fun: () => getVersion("boot.info")}, + {name: "Settings.", fun: () => getVersion("setting.info")}, + ] + }, + { + name: "Storage [kB]", + items: [ + {name: "Total", fun: () => storage.getStats().totalBytes>>10}, + {name: "Free", fun: () => storage.getStats().freeBytes>>10}, + {name: "Trash", fun: () => storage.getStats().trashBytes>>10}, + {name: "", fun: () => ""}, + {name: "#File", fun: () => storage.getStats().fileCount}, + {name: "#Trash", fun: () => storage.getStats().trashCount}, + ] + }, +]; + + +function getWeatherTemp(){ + try { + var weather = storage.readJSON('weather.json').weather; + return locale.temp(weather.temp-273.15); + } catch(ex) { } + + return "?"; +} + + +function getWeatherHumidity(){ + try { + var weather = storage.readJSON('weather.json').weather; + return weather.hum = weather.hum + "%"; + } catch(ex) { } + + return "?"; +} + + +function getWeatherWind(){ + try { + var weather = storage.readJSON('weather.json').weather; + var speed = locale.speed(weather.wind).replace("mph", ""); + return Math.round(speed * 1.609344) + "kph"; + } catch(ex) { } + + return "?"; +} + function getVersion(file) { - var j = s.readJSON(file,1); + var j = storage.readJSON(file,1); var v = ("object"==typeof j)?j.version:false; return v?((v?"v"+v:"Unknown")):"NO "; } -function drawData(name, value, y){ - g.drawString(name, 5, y); - g.drawString(value, 100, y); -} - function getSteps(){ try{ return Bangle.getHealthStatus("day").steps; } catch(e) { - return ">= 2v12"; + return ">2v12"; } } @@ -29,53 +101,36 @@ function getBpm(){ try{ return Math.round(Bangle.getHealthStatus("day").bpm) + "bpm"; } catch(e) { - return ">= 2v12"; + return ">2v12"; } } +function drawData(name, value, y){ + g.drawString(name, 10, y); + g.drawString(value, 100, y); +} + function drawInfo() { g.reset().clearRect(Bangle.appRect); var h=18, y = h;//-h; // Header - g.setFont("Vector", h+2).setFontAlign(0,-1); - g.drawString("--==|| INFO ||==--", W/2, 0); + g.drawLine(0,25,W,25); + g.drawLine(0,26,W,26); + + // Info body depending on screen g.setFont("Vector",h).setFontAlign(-1,-1); + screens[screen].items.forEach(function (item, index){ + drawData(item.name, item.fun(), y+=h); + }); - // Dynamic data - if(screen == 0){ - drawData("Steps", getSteps(), y+=h); - drawData("HRM", getBpm(), y+=h); - drawData("Battery", E.getBattery() + "%", y+=h); - drawData("Voltage", E.getAnalogVRef().toFixed(2) + "V", y+=h); - drawData("IntTemp.", locale.temp(parseInt(E.getTemperature())), y+=h); - } - - if(screen == 1){ - drawData("Charging?", Bangle.isCharging() ? "Yes" : "No", y+=h); - drawData("Bluetooth", NRF.getSecurityStatus().connected ? "Conn." : "Disconn.", y+=h); - drawData("GPS", Bangle.isGPSOn() ? "On" : "Off", y+=h); - drawData("Compass", Bangle.isCompassOn() ? "On" : "Off", y+=h); - drawData("HRM", Bangle.isHRMOn() ? "On" : "Off", y+=h); - } - - // Static data - if(screen == 2){ - drawData("Firmw.", ENV.VERSION, y+=h); - drawData("Boot.", getVersion("boot.info"), y+=h); - drawData("Settings", getVersion("setting.info"), y+=h); - drawData("Storage", "", y+=h); - drawData(" Total", ENV.STORAGE>>10, y+=h); - drawData(" Free", require("Storage").getFree()>>10, y+=h); - } - - if(Bangle.isLocked()){ - g.setFont("Vector",h-2).setFontAlign(-1,-1); - g.drawString("Locked", 0, H-h+2); - } - + // Bottom + g.drawLine(0,H-h-3,W,H-h-3); + g.drawLine(0,H-h-2,W,H-h-2); + g.setFont("Vector",h-2).setFontAlign(-1,-1); + g.drawString(screens[screen].name, 2, H-h+2); g.setFont("Vector",h-2).setFontAlign(1,-1); - g.drawString((screen+1) + "/3", W, H-h+2); + g.drawString((screen+1) + "/" + screens.length, W, H-h+2); } drawInfo(); @@ -88,14 +143,15 @@ Bangle.on('touch', function(btn, e){ var isRight = e.x > right; if(isRight){ - screen = (screen + 1) % (maxScreen+1); + screen = (screen + 1) % screens.length; } if(isLeft){ screen -= 1; - screen = screen < 0 ? maxScreen : screen; + screen = screen < 0 ? screens.length-1 : screen; } + Bangle.buzz(40, 0.6); drawInfo(); }); @@ -104,5 +160,4 @@ Bangle.on('lock', function(isLocked) { }); Bangle.loadWidgets(); -for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} -// Bangle.drawWidgets(); \ No newline at end of file +Bangle.drawWidgets(); \ No newline at end of file diff --git a/apps/info/metadata.json b/apps/info/metadata.json index f05f0e134..ac56cd5c3 100644 --- a/apps/info/metadata.json +++ b/apps/info/metadata.json @@ -1,7 +1,7 @@ { "id": "info", "name": "Info", - "version": "0.01", + "version": "0.03", "description": "An application that displays information such as battery level, steps etc.", "icon": "info.png", "type": "app", @@ -11,7 +11,8 @@ "screenshots": [ {"url":"screenshot_1.png"}, {"url":"screenshot_2.png"}, - {"url":"screenshot_3.png"}], + {"url":"screenshot_3.png"}, + {"url":"screenshot_4.png"}], "storage": [ {"name":"info.app.js","url":"info.app.js"}, {"name":"info.img","url":"info.icon.js","evaluate":true} diff --git a/apps/info/screenshot_1.png b/apps/info/screenshot_1.png index 97d42a896..6661c122c 100644 Binary files a/apps/info/screenshot_1.png and b/apps/info/screenshot_1.png differ diff --git a/apps/info/screenshot_2.png b/apps/info/screenshot_2.png index 2d25dd4e6..3d91fcabe 100644 Binary files a/apps/info/screenshot_2.png and b/apps/info/screenshot_2.png differ diff --git a/apps/info/screenshot_3.png b/apps/info/screenshot_3.png index 782e4a195..86bbb67cf 100644 Binary files a/apps/info/screenshot_3.png and b/apps/info/screenshot_3.png differ diff --git a/apps/info/screenshot_4.png b/apps/info/screenshot_4.png new file mode 100644 index 000000000..b8b59b1ef Binary files /dev/null and b/apps/info/screenshot_4.png differ diff --git a/apps/infoclk/ChangeLog b/apps/infoclk/ChangeLog new file mode 100644 index 000000000..4744f872a --- /dev/null +++ b/apps/infoclk/ChangeLog @@ -0,0 +1,3 @@ +0.01: New app! +0.02-0.07: Bug fixes +0.08: Submitted to the app loader \ No newline at end of file diff --git a/apps/infoclk/README.md b/apps/infoclk/README.md new file mode 100644 index 000000000..1dd563bec --- /dev/null +++ b/apps/infoclk/README.md @@ -0,0 +1,33 @@ +# Informational clock + +A configurable clock with extra info and shortcuts when unlocked, but large time when locked + +## Information + +The clock has two different screen arrangements, depending on whether the watch is locked or unlocked. The most commonly viewed piece of information is the time, so when the watch is locked it optimizes for the time being visible at a glance without the backlight. The hours and minutes take up nearly the entire top half of the display, with the date and seconds taking up nearly the entire bottom half. The day progress bar is between them if enabled, unless configured to be on the bottom row. The bottom row can be configured to display a weather summary, step count, step count and heart rate, the daily progress bar, or nothing. + +When the watch is unlocked, it can be assumed that the backlight is on and the user is actively looking at the watch, so instead we can optimize for information density. The bottom half of the display becomes shortcuts, and the top half of the display becomes 4 rows of information (date and time, step count and heart rate, 2 line weather summary) + an optional daily progress bar. (The daily progress bar can be independently enabled when locked and unlocked.) + +Most things are self-explanatory, but the day progress bar might not be. The day progress bar is intended to show approximately how far through the day you are, in the form of a progress bar. You might want to configure it to show how far you are through your waking hours, or you might want to use it to show how far you are through your work or school day. + +## Shortcuts + +There are generally a few apps that the user uses far more frequently than the others. For example, they might use a timer, alarm clock, and calculator every day, while everything else (such as the settings app) gets used only occasionally. This clock has space for 8 apps in the bottom half of the screen only one tap away, avoiding the need to wait for the launcher to open and then scroll through it. Tapping the top of the watch opens the launcher, eliminating the need for the button (which still opens the launcher due to bangle.js conventions). There is also handling for left, right, and vertical swipes. A vertical swipe by default opens the messages app, mimicking mobile operating systems which use a swipe down to view the notification shade. + +## Configurability + +Displaying the seconds allows for more precise timing, but waking up the CPU to refresh the display more often consumes battery. The user can enable or disable them completely, but can also configure them to be enabled or disabled automatically based on some hueristics: + +* They can be hidden while the display is locked, if the user expects to unlock their watch when they need the seconds. +* They can be hidden when the battery is too low, to make the last portion of the battery last a little bit longer. +* They can be hidden during a period of time such as when the user is asleep and therefore unlikely to need very much precision. + +The date format can be changed. + +As described earlier, the contents of the bottom row when locked can be changed. + +The 8 tap-based shortcuts on the bottom and the 3 swipe-based shortcuts can be changed to nothing, the launcher, or any app on the watch. + +The start and end time of the day progress bar can be changed. It can be enabled or disabled separately when the watch is locked and unlocked. The color can be changed. The time when it resets from full to empty can be changed. + +When the battery is below a defined point, the watch's color can change to another chosen color to help the user notice that the battery is low. \ No newline at end of file diff --git a/apps/infoclk/app.js b/apps/infoclk/app.js new file mode 100644 index 000000000..3d51191df --- /dev/null +++ b/apps/infoclk/app.js @@ -0,0 +1,405 @@ +const SETTINGS_FILE = "infoclk.json"; +const FONT = require('infoclk-font.js'); + +const storage = require("Storage"); +const locale = require("locale"); +const weather = require('weather'); + +let config = Object.assign({ + seconds: { + // Displaying the seconds can reduce battery life because the CPU must wake up more often to update the display. + // The seconds will be shown unless one of these conditions is enabled here, and currently true. + hideLocked: false, // Hide the seconds when the display is locked. + hideBattery: 20, // Hide the seconds when the battery is at or below a defined percentage. + hideTime: true, // Hide the seconds when between a certain period of time. Useful for when you are sleeping and don't need the seconds + hideStart: 2200, // The time when the seconds are hidden: first 2 digits are hours on a 24 hour clock, last 2 are minutes + hideEnd: 700, // The time when the seconds are shown again + hideAlways: false, // Always hide (never show) the seconds + }, + + date: { + // Settings related to the display of the date + mmdd: true, // If true, display the month first. If false, display the date first. + separator: '-', // The character that goes between the month and date + monthName: false, // If false, display the month as a number. If true, display the name. + monthFullName: false, // If displaying the name: If false, display an abbreviation. If true, display a full name. + dayFullName: false, // If false, display the day of the week's abbreviation. If true, display the full name. + }, + + bottomLocked: { + display: 'weather' // What to display in the bottom row when locked: + // 'weather': The current temperature and weather description + // 'steps': Step count + // 'health': Step count and bpm + // 'progress': Day progress bar + // false: Nothing + }, + + shortcuts: [ + //8 shortcuts, displayed in the bottom half of the screen (2 rows of 4 shortcuts) when unlocked + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + 'stlap', 'keytimer', 'pomoplus', 'alarm', + 'rpnsci', 'calendar', 'torch', 'weather' + ], + + swipe: { + // 3 shortcuts to launch upon swiping: + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + up: 'messages', // Swipe up or swipe down, due to limitation of event handler + left: '#LAUNCHER', + right: '#LAUNCHER', + }, + + dayProgress: { + // A progress bar representing how far through the day you are + enabledLocked: true, // Whether this bar is enabled when the watch is locked + enabledUnlocked: false, // Whether the bar is enabled when the watch is unlocked + color: [0, 0, 1], // The color of the bar + start: 700, // The time of day that the bar starts filling + end: 2200, // The time of day that the bar becomes full + reset: 300 // The time of day when the progress bar resets from full to empty + }, + + lowBattColor: { + // The text can change color to indicate that the battery is low + level: 20, // The percentage where this happens + color: [1, 0, 0] // The color that the text changes to + } +}, storage.readJSON(SETTINGS_FILE)); + +// Return whether the given time (as a date object) is between start and end (as a number where the first 2 digits are hours on a 24 hour clock and the last 2 are minutes), with end time wrapping to next day if necessary +function timeInRange(start, time, end) { + + // Convert the given date object to a time number + let timeNumber = time.getHours() * 100 + time.getMinutes(); + + // Normalize to prevent the numbers from wrapping around at midnight + if (end <= start) { + end += 2400; + if (timeNumber < start) timeNumber += 2400; + } + + return start <= timeNumber && timeNumber <= end; +} + +// Return whether settings should be displayed based on the user's configuration +function shouldDisplaySeconds(now) { + return !( + (config.seconds.hideAlways) || + (config.seconds.hideLocked && Bangle.isLocked()) || + (E.getBattery() <= config.seconds.hideBattery) || + (config.seconds.hideTime && timeInRange(config.seconds.hideStart, now, config.seconds.hideEnd)) + ); +} + +// Determine the font size needed to fit a string of the given length widthin maxWidth number of pixels, clamped between minSize and maxSize +function getFontSize(length, maxWidth, minSize, maxSize) { + let size = Math.floor(maxWidth / length); //Number of pixels of width available to character + size *= (20 / 12); //Convert to height, assuming 20 pixels of height for every 12 of width + + // Clamp to within range + if (size < minSize) return minSize; + else if (size > maxSize) return maxSize; + else return Math.floor(size); +} + +// Get the current day of the week according to user settings +function getDayString(now) { + if (config.date.dayFullName) return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][now.getDay()]; + else return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][now.getDay()]; +} + +// Pad a number with zeros to be the given number of digits +function pad(number, digits) { + let result = '' + number; + while (result.length < digits) result = '0' + result; + return result; +} + +// Get the current date formatted according to the user settings +function getDateString(now) { + let month; + if (!config.date.monthName) month = pad(now.getMonth() + 1, 2); + else if (config.date.monthFullName) month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][now.getMonth()]; + else month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now.getMonth()]; + + if (config.date.mmdd) return `${month}${config.date.separator}${pad(now.getDate(), 2)}`; + else return `${pad(now.getDate(), 2)}${config.date.separator}${month}`; +} + +// Get a floating point number from 0 to 1 representing how far between the user-defined start and end points we are +function getDayProgress(now) { + let start = config.dayProgress.start; + let current = now.getHours() * 100 + now.getMinutes(); + let end = config.dayProgress.end; + let reset = config.dayProgress.reset; + + // Normalize + if (end <= start) end += 2400; + if (current < start) current += 2400; + if (reset < start) reset += 2400; + + // Convert an hhmm number into a floating-point hours + function toDecimalHours(time) { + let hours = Math.floor(time / 100); + let minutes = time % 100; + + return hours + (minutes / 60); + } + + start = toDecimalHours(start); + current = toDecimalHours(current); + end = toDecimalHours(end); + reset = toDecimalHours(reset); + + let progress = (current - start) / (end - start); + + if (progress < 0 || progress > 1) { + if (current < reset) return 1; + else return 0; + } else { + return progress; + } +} + +// Get a Gadgetbridge weather string +function getWeatherString() { + let current = weather.get(); + if (current) return locale.temp(current.temp - 273.15) + ', ' + current.txt; + else return 'Weather unknown!'; +} + +// Get a second weather row showing humidity, wind speed, and wind direction +function getWeatherRow2() { + let current = weather.get(); + if (current) return `${current.hum}%, ${locale.speed(current.wind)} ${current.wrose}`; + else return 'Check Gadgetbridge'; +} + +// Get a step string +function getStepsString() { + return '' + Bangle.getHealthStatus('day').steps + ' steps'; +} + +// Get a health string including daily steps and recent bpm +function getHealthString() { + return `${Bangle.getHealthStatus('day').steps} steps ${Bangle.getHealthStatus('last').bpm} bpm`; +} + +// Set the next timeout to draw the screen +let drawTimeout; +function setNextDrawTimeout() { + if (drawTimeout) { + clearTimeout(drawTimeout); + drawTimeout = undefined; + } + + let time; + let now = new Date(); + if (shouldDisplaySeconds(now)) time = 1000 - (now.getTime() % 1000); + else time = 60000 - (now.getTime() % 60000); + + drawTimeout = setTimeout(draw, time); +} + + +const DIGIT_WIDTH = 40; // How much width is allocated for each digit, 37 pixels + 3 pixels of space (which will go off of the screen on the right edge) +const COLON_WIDTH = 19; // How much width is allocated for the colon, 16 pixels + 3 pixels of space +const HHMM_TOP = 27; // 24 pixels for widgets + 3 pixels of space +const DIGIT_HEIGHT = 64; // How tall the digits are + +const SECONDS_TOP = HHMM_TOP + DIGIT_HEIGHT + 3; // The top edge of the seconds, top of hours and minutes + digit height + space +const SECONDS_LEFT = 2 * DIGIT_WIDTH + COLON_WIDTH; // The left edge of the seconds: displayed after 2 digits and the colon +const DATE_LETTER_HEIGHT = DIGIT_HEIGHT / 2; // Each letter of the day of week and date will be half the height of the time digits + +const DATE_CENTER_X = SECONDS_LEFT / 2; // Day of week and date will be centered between left edge of screen and where seconds start +const DOW_CENTER_Y = SECONDS_TOP + (DATE_LETTER_HEIGHT / 2); // Day of week will be the top row +const DATE_CENTER_Y = DOW_CENTER_Y + DATE_LETTER_HEIGHT; // Date will be the bottom row +const DOW_DATE_CENTER_Y = SECONDS_TOP + (DIGIT_HEIGHT / 2); // When displaying both on one row, center it +const BOTTOM_CENTER_Y = ((SECONDS_TOP + DIGIT_HEIGHT + 3) + g.getHeight()) / 2; + +// Draw the clock +function draw() { + //Prepare to draw + g.reset() + .setFontAlign(0, 0); + + if (E.getBattery() <= config.lowBattColor.level) { + let color = config.lowBattColor.color; + g.setColor(color[0], color[1], color[2]); + } + now = new Date(); + + if (Bangle.isLocked()) { //When the watch is locked + g.clearRect(0, 24, g.getWidth(), g.getHeight()); + + //Draw the hours and minutes + let x = 0; + + for (let digit of locale.time(now, 1)) { //apparently this is how you get an hh:mm time string adjusting for the user's 12/24 hour preference + if (digit != ' ') g.drawImage(FONT[digit], x, HHMM_TOP); + if (digit == ':') x += COLON_WIDTH; + else x += DIGIT_WIDTH; + } + if (storage.readJSON('setting.json')['12hour']) g.drawImage(FONT[(now.getHours() < 12) ? 'am' : 'pm'], 0, HHMM_TOP); + + //Draw the seconds if necessary + if (shouldDisplaySeconds(now)) { + let tens = Math.floor(now.getSeconds() / 10); + let ones = now.getSeconds() % 10; + g.drawImage(FONT[tens], SECONDS_LEFT, SECONDS_TOP) + .drawImage(FONT[ones], SECONDS_LEFT + DIGIT_WIDTH, SECONDS_TOP); + + // Draw the day of week and date assuming the seconds are displayed + + g.setFont('Vector', getFontSize(getDayString(now).length, SECONDS_LEFT, 6, DATE_LETTER_HEIGHT)) + .drawString(getDayString(now), DATE_CENTER_X, DOW_CENTER_Y) + .setFont('Vector', getFontSize(getDateString(now).length, SECONDS_LEFT, 6, DATE_LETTER_HEIGHT)) + .drawString(getDateString(now), DATE_CENTER_X, DATE_CENTER_Y); + + } else { + //Draw the day of week and date without the seconds + + let string = getDayString(now) + ' ' + getDateString(now); + g.setFont('Vector', getFontSize(string.length, g.getWidth(), 6, DATE_LETTER_HEIGHT)) + .drawString(string, g.getWidth() / 2, DOW_DATE_CENTER_Y); + } + + // Draw the bottom area + if (config.bottomLocked.display == 'progress') { + let color = config.dayProgress.color; + g.setColor(color[0], color[1], color[2]) + .fillRect(0, SECONDS_TOP + DIGIT_HEIGHT + 3, g.getWidth() * getDayProgress(now), g.getHeight()); + } else { + let bottomString; + + if (config.bottomLocked.display == 'weather') bottomString = getWeatherString(); + else if (config.bottomLocked.display == 'steps') bottomString = getStepsString(); + else if (config.bottomLocked.display == 'health') bottomString = getHealthString(); + else bottomString = ' '; + + g.setFont('Vector', getFontSize(bottomString.length, 176, 6, g.getHeight() - (SECONDS_TOP + DIGIT_HEIGHT + 3))) + .drawString(bottomString, g.getWidth() / 2, BOTTOM_CENTER_Y); + } + + // Draw the day progress bar between the rows if necessary + if (config.dayProgress.enabledLocked && config.bottomLocked.display != 'progress') { + let color = config.dayProgress.color; + g.setColor(color[0], color[1], color[2]) + .fillRect(0, HHMM_TOP + DIGIT_HEIGHT, g.getWidth() * getDayProgress(now), SECONDS_TOP); + } + } else { + + //If the watch is unlocked + g.clearRect(0, 24, g.getWidth(), g.getHeight() / 2); + rows = [ + `${getDayString(now)} ${getDateString(now)} ${locale.time(now, 1)}`, + getHealthString(), + getWeatherString(), + getWeatherRow2() + ]; + if (shouldDisplaySeconds(now)) rows[0] += ':' + pad(now.getSeconds(), 2); + if (storage.readJSON('setting.json')['12hour']) rows[0] += ((now.getHours() < 12) ? ' AM' : ' PM'); + + let maxHeight = ((g.getHeight() / 2) - HHMM_TOP) / (config.dayProgress.enabledUnlocked ? (rows.length + 1) : rows.length); + + let y = HHMM_TOP + maxHeight / 2; + for (let row of rows) { + let size = getFontSize(row.length, g.getWidth(), 6, maxHeight); + g.setFont('Vector', size) + .drawString(row, g.getWidth() / 2, y); + y += maxHeight; + } + + if (config.dayProgress.enabledUnlocked) { + let color = config.dayProgress.color; + g.setColor(color[0], color[1], color[2]) + .fillRect(0, y - maxHeight / 2, 176 * getDayProgress(now), y + maxHeight / 2); + } + } + + setNextDrawTimeout(); +} + +// Draw the icons. This is done separately from the main draw routine to avoid having to scale and draw a bunch of images repeatedly. +function drawIcons() { + g.reset().clearRect(0, 24, g.getWidth(), g.getHeight()); + for (let i = 0; i < 8; i++) { + let x = [0, 44, 88, 132, 0, 44, 88, 132][i]; + let y = [88, 88, 88, 88, 132, 132, 132, 132][i]; + let appId = config.shortcuts[i]; + let appInfo = storage.readJSON(appId + '.info', 1); + if (!appInfo) continue; + icon = storage.read(appInfo.icon); + g.drawImage(icon, x, y, { + scale: 0.916666666667 + }); + } +} + +weather.on("update", draw); +Bangle.on("step", draw); +Bangle.on('lock', locked => { + //If the watch is unlocked, draw the icons + if (!locked) drawIcons(); + draw(); +}); + +// Show launcher when middle button pressed +Bangle.setUI("clock"); +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +// Launch an app given the current ID. Handles special cases: +// false: Do nothing +// '#LAUNCHER': Open the launcher +// nonexistent app: Do nothing +function launch(appId) { + if (appId == false) return; + else if (appId == '#LAUNCHER') { + Bangle.buzz(); + Bangle.showLauncher(); + } else { + let appInfo = storage.readJSON(appId + '.info', 1); + if (appInfo) { + Bangle.buzz(); + load(appInfo.src); + } + } +} + +//Set up touch to launch the selected app +Bangle.on('touch', function (button, xy) { + let x = Math.floor(xy.x / 44); + if (x < 0) x = 0; + else if (x > 3) x = 3; + + let y = Math.floor(xy.y / 44); + if (y < 0) y = -1; + else if (y > 3) y = 1; + else y -= 2; + + if (y < 0) { + Bangle.buzz(); + Bangle.showLauncher(); + } else { + let i = 4 * y + x; + launch(config.shortcuts[i]); + } +}); + +//Set up swipe handler +Bangle.on('swipe', function (direction) { + if (direction == -1) launch(config.swipe.left); + else if (direction == 0) launch(config.swipe.up); + else launch(config.swipe.right); +}); + +if (!Bangle.isLocked()) drawIcons(); + +draw(); \ No newline at end of file diff --git a/apps/infoclk/font.js b/apps/infoclk/font.js new file mode 100644 index 000000000..6063958e7 --- /dev/null +++ b/apps/infoclk/font.js @@ -0,0 +1,23 @@ +const heatshrink = require("heatshrink") + +function decompress(string) { + return heatshrink.decompress(atob(string)) +} + +exports = { + '0': decompress("ktAwIEB////EAj4EB+EDAYP/8E/AgWDAYX+CIX/+IDC//PBoYIDAAvwgEHAgOAgAnB/kAgIvCgEPAgJCBv5CCHwXAI4X+KAYk/En4kmAA4qBAAP7BAePAYX4BofBAYX8F4Q+BEwRHBIQI5BA"), + '1': decompress("ktAwIGDj/4AgX/4ADBg/+BAU/+ADBgP/wAEBh/8BoV/8ADBgf/En4k/En4k/EgQ="), + '2': decompress("ktAwMA/4AB/EHAgXwn4EC8IDC/+PAYX+v4EC+YND74NDBAYAE4A0Bg/+HIU/+ADBgP/wAEBh/8BoV/8ADBgf/BAUf/AECElQdBPA2HAYX8OYfHBAYRD8Z3Dj6TG/kPPYZm4EiwAHO4f7BAfPfI/xBoaTEPAfgQwY"), + '3': decompress("ktAwMA/4AB/EHAgXwn4EC8IDC/+PAYX+v4EC+YND74NDBAYAE4A0Bg/+HIU/+ADBgP/wAEBh/8BoV/8ADBgf/BAUf/AECElJWIAEpu/EhpgS34DC/IID54DC/l/AgXDAYX4j57DA"), + '4': decompress("ktAwMA//AgEf//+BYP///wgEHAgOAgE///8gEBBAPggEPAgIWBv///EAgYIBEn4kXABf9AgfnAgY4BAAP4BAfDAYX+EwfwIQRRCJIJRBJIRRBJIQICj5RBJIRRBJIJRCNwJRBNwQk/Ei4A=="), + '5': decompress("ktAwIEB/4AB/EfAgXDAYX+n4EC+YDC/+fAYX9BAfvAgYAJ+AwBgP/wAEBh/8H4V/8ADBgf/BAUf/AEC//AAYMH/wICn4kpPYUPAgXgv4EC4JfDg4DC/iFD8ANDwaTDCQfwEoZ2/EhrXNAAm/AYX5BAfPQoaTD4ahDj57DA=="), + '6': decompress("ktAwIEB/4AB/EfAgXDAYX+n4EC+YDC/+fAYX9BAfvAgYAJ+AwBgP/wAEBh/8H4V/8ADBgf/BAUf/AEC//AAYMH/wICn4kpPYUPAgXgv6AG/6JD/gID84ED358NJIIsCKIQ0BKIRJCFgJJCSYcHAgJuBXYJuBKIQkpAA58D/YIDx6PDBofBQoYvCHwImCI4KUCwA="), + '7': decompress("ktAwMA/4AB/EHAgXwn4EC8IDC/+PAYX+v4EC+YND74NDBAYAE4A0Bg/+HIU/+ADBgP/wAEBh/8BoV/8ADBgf/BAUf/AECEn4k/En4kVA"), + '8': decompress("ktAwIEB////EAj4EB+EDAYP/8E/AgWDAYX+CIX/+IDC//PBoYIDAAvwgEHAgOAgAnB/kAgIvCgEPAgJCBv5CCHwXAI4X+KAYkpAFpu/EhwAHFQIAB/YIDx4DC/AND4IDC/ieD4AmCI4JCBHIIA=="), + '9': decompress("ktAwIEB////EAj4EB+EDAYP/8E/AgWDAYX+CIX/+IDC//PBoYIDAAvwgEHAgOAgAnB/kAgIvCgEPAgJCBv5CCHwXAI4X+KAYkpABf9AgfnAgaFD/AID4Z8DEwfwIQRRCJIJRBJIRRBJIQICj5RBJIRRBJIJRCNwJRBNwQkoPhoAE34DC/L0H/iwBQAv4WAJ7CA=="), + + ':': decompress("iFAwITQg/gj/4n/8v/+AIP/ABQPDCoIZBDoJTfH94A=="), + + 'am': decompress("jFAwIEBngCEvwCH/4CFwEBAQkD//AgfnAQcH4fgAQsPwPwAQf/+Ef//4AQn8n0AvgCCHQN+vkAnwCC/EAj4CF+EAh4CCNIoLFC4v8gE/AQv+gF/AQpwB/4CDwICG+/D94CD8/v+fn54CC+P/x4CF+H/IgICFvwCEngCD"), + 'pm': decompress("jFAwMAn///l///+/4AE+EAh4CaEYoABFgX8BwMAAUwAFIIv4gEfAQX8OYICF/0Av4CF/8AKQICCwICG+/D94CD8/v+fn54CC+P/x4CF+H/IgICFvwCEngCDA") +} \ No newline at end of file diff --git a/apps/infoclk/font/am.png b/apps/infoclk/font/am.png new file mode 100644 index 000000000..a76ad25fc Binary files /dev/null and b/apps/infoclk/font/am.png differ diff --git a/apps/infoclk/font/colon.png b/apps/infoclk/font/colon.png new file mode 100644 index 000000000..878770dde Binary files /dev/null and b/apps/infoclk/font/colon.png differ diff --git a/apps/infoclk/font/digit0.png b/apps/infoclk/font/digit0.png new file mode 100644 index 000000000..5470154ee Binary files /dev/null and b/apps/infoclk/font/digit0.png differ diff --git a/apps/infoclk/font/digit1.png b/apps/infoclk/font/digit1.png new file mode 100644 index 000000000..26a35fd1b Binary files /dev/null and b/apps/infoclk/font/digit1.png differ diff --git a/apps/infoclk/font/digit2.png b/apps/infoclk/font/digit2.png new file mode 100644 index 000000000..92974daf3 Binary files /dev/null and b/apps/infoclk/font/digit2.png differ diff --git a/apps/infoclk/font/digit3.png b/apps/infoclk/font/digit3.png new file mode 100644 index 000000000..6751067c6 Binary files /dev/null and b/apps/infoclk/font/digit3.png differ diff --git a/apps/infoclk/font/digit4.png b/apps/infoclk/font/digit4.png new file mode 100644 index 000000000..fdb0c5f8d Binary files /dev/null and b/apps/infoclk/font/digit4.png differ diff --git a/apps/infoclk/font/digit5.png b/apps/infoclk/font/digit5.png new file mode 100644 index 000000000..5647ad00a Binary files /dev/null and b/apps/infoclk/font/digit5.png differ diff --git a/apps/infoclk/font/digit6.png b/apps/infoclk/font/digit6.png new file mode 100644 index 000000000..56c446881 Binary files /dev/null and b/apps/infoclk/font/digit6.png differ diff --git a/apps/infoclk/font/digit7.png b/apps/infoclk/font/digit7.png new file mode 100644 index 000000000..1fb6a6423 Binary files /dev/null and b/apps/infoclk/font/digit7.png differ diff --git a/apps/infoclk/font/digit8.png b/apps/infoclk/font/digit8.png new file mode 100644 index 000000000..a373205f1 Binary files /dev/null and b/apps/infoclk/font/digit8.png differ diff --git a/apps/infoclk/font/digit9.png b/apps/infoclk/font/digit9.png new file mode 100644 index 000000000..990a3a43b Binary files /dev/null and b/apps/infoclk/font/digit9.png differ diff --git a/apps/infoclk/font/pm.png b/apps/infoclk/font/pm.png new file mode 100644 index 000000000..a3db97eb8 Binary files /dev/null and b/apps/infoclk/font/pm.png differ diff --git a/apps/infoclk/icon.js b/apps/infoclk/icon.js new file mode 100644 index 000000000..ae230d8f4 --- /dev/null +++ b/apps/infoclk/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwgOAA4YFS/4AKEf5BlABcAjAgBjAfBAuhH/Apo")) \ No newline at end of file diff --git a/apps/infoclk/icon.png b/apps/infoclk/icon.png new file mode 100644 index 000000000..24423fbd6 Binary files /dev/null and b/apps/infoclk/icon.png differ diff --git a/apps/infoclk/metadata.json b/apps/infoclk/metadata.json new file mode 100644 index 000000000..bb6dea3a4 --- /dev/null +++ b/apps/infoclk/metadata.json @@ -0,0 +1,38 @@ +{ + "id": "infoclk", + "name": "Informational clock", + "version": "0.08", + "description": "A configurable clock with extra info and shortcuts when unlocked, but large time when locked", + "readme": "README.md", + "icon": "icon.png", + "type": "clock", + "tags": "clock", + "supports": [ + "BANGLEJS2" + ], + "allow_emulator": true, + "storage": [ + { + "name": "infoclk.app.js", + "url": "app.js" + }, + { + "name": "infoclk.settings.js", + "url": "settings.js" + }, + { + "name": "infoclk-font.js", + "url": "font.js" + }, + { + "name": "infoclk.img", + "url": "icon.js", + "evaluate": true + } + ], + "data": [ + { + "name": "infoclk.json" + } + ] +} \ No newline at end of file diff --git a/apps/infoclk/settings.js b/apps/infoclk/settings.js new file mode 100644 index 000000000..0bc3d4b15 --- /dev/null +++ b/apps/infoclk/settings.js @@ -0,0 +1,571 @@ +(function (back) { + const SETTINGS_FILE = "infoclk.json"; + const storage = require('Storage'); + + let config = Object.assign({ + seconds: { + // Displaying the seconds can reduce battery life because the CPU must wake up more often to update the display. + // The seconds will be shown unless one of these conditions is enabled here, and currently true. + hideLocked: false, // Hide the seconds when the display is locked. + hideBattery: 20, // Hide the seconds when the battery is at or below a defined percentage. + hideTime: true, // Hide the seconds when between a certain period of time. Useful for when you are sleeping and don't need the seconds + hideStart: 2200, // The time when the seconds are hidden: first 2 digits are hours on a 24 hour clock, last 2 are minutes + hideEnd: 700, // The time when the seconds are shown again + hideAlways: false, // Always hide (never show) the seconds + }, + + date: { + // Settings related to the display of the date + mmdd: true, // If true, display the month first. If false, display the date first. + separator: '-', // The character that goes between the month and date + monthName: false, // If false, display the month as a number. If true, display the name. + monthFullName: false, // If displaying the name: If false, display an abbreviation. If true, display a full name. + dayFullName: false, // If false, display the day of the week's abbreviation. If true, display the full name. + }, + + bottomLocked: { + display: 'weather' // What to display in the bottom row when locked: + // 'weather': The current temperature and weather description + // 'steps': Step count + // 'health': Step count and bpm + // 'progress': Day progress bar + // false: Nothing + }, + + shortcuts: [ + //8 shortcuts, displayed in the bottom half of the screen (2 rows of 4 shortcuts) when unlocked + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + 'stlap', 'keytimer', 'pomoplus', 'alarm', + 'rpnsci', 'calendar', 'torch', 'weather' + ], + + swipe: { + // 3 shortcuts to launch upon swiping: + // false = no shortcut + // '#LAUNCHER' = open the launcher + // any other string = name of app to open + up: 'messages', // Swipe up or swipe down, due to limitation of event handler + left: '#LAUNCHER', + right: '#LAUNCHER', + }, + + dayProgress: { + // A progress bar representing how far through the day you are + enabledLocked: true, // Whether this bar is enabled when the watch is locked + enabledUnlocked: false, // Whether the bar is enabled when the watch is unlocked + color: [0, 0, 1], // The color of the bar + start: 700, // The time of day that the bar starts filling + end: 2200, // The time of day that the bar becomes full + reset: 300 // The time of day when the progress bar resets from full to empty + }, + + lowBattColor: { + // The text can change color to indicate that the battery is low + level: 20, // The percentage where this happens + color: [1, 0, 0] // The color that the text changes to + } + }, storage.readJSON(SETTINGS_FILE)); + + function saveSettings() { + storage.writeJSON(SETTINGS_FILE, config); + } + + function hourToString(hour) { + if (storage.readJSON('setting.json')['12hour']) { + if (hour == 0) return '12 AM'; + else if (hour < 12) return `${hour} AM`; + else if (hour == 12) return '12 PM'; + else return `${hour - 12} PM`; + } else return '' + hour; + } + + // The menu for configuring when the seconds are shown + function showSecondsMenu() { + E.showMenu({ + '': { + 'title': 'Seconds display', + 'back': showMainMenu + }, + 'Show seconds': { + value: !config.seconds.hideAlways, + onchange: value => { + config.seconds.hideAlways = !value; + saveSettings(); + } + }, + '...unless locked': { + value: config.seconds.hideLocked, + onchange: value => { + config.seconds.hideLocked = value; + saveSettings(); + } + }, + '...unless battery below': { + value: config.seconds.hideBattery, + min: 0, + max: 100, + format: value => `${value}%`, + onchange: value => { + config.seconds.hideBattery = value; + saveSettings(); + } + }, + '...unless between these 2 times...': () => { + E.showMenu({ + '': { + 'title': 'Hide seconds between', + 'back': showSecondsMenu + }, + 'Enabled': { + value: config.seconds.hideTime, + onchange: value => { + config.seconds.hideTime = value; + saveSettings(); + } + }, + 'Start hour': { + value: Math.floor(config.seconds.hideStart / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.seconds.hideStart % 100; + config.seconds.hideStart = (100 * hour) + minute; + saveSettings(); + } + }, + 'Start minute': { + value: config.seconds.hideStart % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.seconds.hideStart / 100); + config.seconds.hideStart = (100 * hour) + minute; + saveSettings(); + } + }, + 'End hour': { + value: Math.floor(config.seconds.hideEnd / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.seconds.hideEnd % 100; + config.seconds.hideEnd = (100 * hour) + minute; + saveSettings(); + } + }, + 'End minute': { + value: config.seconds.hideEnd % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.seconds.hideEnd / 100); + config.seconds.hideEnd = (100 * hour) + minute; + saveSettings(); + } + } + }); + } + }); + } + + // Available month/date separators + const SEPARATORS = [ + { name: 'Slash', char: '/' }, + { name: 'Dash', char: '-' }, + { name: 'Space', char: ' ' }, + { name: 'Comma', char: ',' }, + { name: 'None', char: '' } + ]; + + // Available bottom row display options + const BOTTOM_ROW_OPTIONS = [ + { name: 'Weather', val: 'weather' }, + { name: 'Step count', val: 'steps' }, + { name: 'Steps + BPM', val: 'health' }, + { name: 'Day progresss bar', val: 'progress' }, + { name: 'Nothing', val: false } + ]; + + // The menu for configuring which apps have shortcut icons + function showShortcutMenu() { + //Builds the shortcut options + let shortcutOptions = [ + { name: 'Nothing', val: false }, + { name: 'Launcher', val: '#LAUNCHER' }, + ]; + + let infoFiles = storage.list(/\.info$/).sort((a, b) => { + if (a.name < b.name) return -1; + else if (a.name > b.name) return 1; + else return 0; + }); + for (let infoFile of infoFiles) { + let appInfo = storage.readJSON(infoFile); + if (appInfo.src) shortcutOptions.push({ + name: appInfo.name, + val: appInfo.id + }); + } + + E.showMenu({ + '': { + 'title': 'Shortcuts', + 'back': showMainMenu + }, + 'Top first': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[0]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[0] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Top second': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[1]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[1] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Top third': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[2]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[2] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Top fourth': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[3]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[3] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom first': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[4]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[4] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom second': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[5]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[5] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom third': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[6]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[6] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Bottom fourth': { + value: shortcutOptions.map(item => item.val).indexOf(config.shortcuts[7]), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.shortcuts[7] = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Swipe up': { + value: shortcutOptions.map(item => item.val).indexOf(config.swipe.up), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.swipe.up = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Swipe left': { + value: shortcutOptions.map(item => item.val).indexOf(config.swipe.left), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.swipe.left = shortcutOptions[value].val; + saveSettings(); + } + }, + 'Swipe right': { + value: shortcutOptions.map(item => item.val).indexOf(config.swipe.right), + format: value => shortcutOptions[value].name, + min: 0, + max: shortcutOptions.length - 1, + wrap: false, + onchange: value => { + config.swipe.right = shortcutOptions[value].val; + saveSettings(); + } + }, + }); + } + + const COLOR_OPTIONS = [ + { name: 'Black', val: [0, 0, 0] }, + { name: 'Blue', val: [0, 0, 1] }, + { name: 'Green', val: [0, 1, 0] }, + { name: 'Cyan', val: [0, 1, 1] }, + { name: 'Red', val: [1, 0, 0] }, + { name: 'Magenta', val: [1, 0, 1] }, + { name: 'Yellow', val: [1, 1, 0] }, + { name: 'White', val: [1, 1, 1] } + ]; + + // Workaround for being unable to use == on arrays: convert them into strings + function colorString(color) { + return `${color[0]} ${color[1]} ${color[2]}`; + } + + //Shows the top level menu + function showMainMenu() { + E.showMenu({ + '': { + 'title': 'Informational Clock', + 'back': back + }, + 'Seconds display': showSecondsMenu, + 'Day of week format': { + value: config.date.dayFullName, + format: value => value ? 'Full name' : 'Abbreviation', + onchange: value => { + config.date.dayFullName = value; + saveSettings(); + } + }, + 'Date format': () => { + E.showMenu({ + '': { + 'title': 'Date format', + 'back': showMainMenu, + }, + 'Order': { + value: config.date.mmdd, + format: value => value ? 'Month first' : 'Date first', + onchange: value => { + config.date.mmdd = value; + saveSettings(); + } + }, + 'Separator': { + value: SEPARATORS.map(item => item.char).indexOf(config.date.separator), + format: value => SEPARATORS[value].name, + min: 0, + max: SEPARATORS.length - 1, + wrap: true, + onchange: value => { + config.date.separator = SEPARATORS[value].char; + saveSettings(); + } + }, + 'Month format': { + // 0 = number only + // 1 = abbreviation + // 2 = full name + value: config.date.monthName ? (config.date.monthFullName ? 2 : 1) : 0, + format: value => ['Number', 'Abbreviation', 'Full name'][value], + min: 0, + max: 2, + wrap: true, + onchange: value => { + if (value == 0) config.date.monthName = false; + else { + config.date.monthName = true; + config.date.monthFullName = (value == 2); + } + saveSettings(); + } + } + }); + }, + 'Bottom row': { + value: BOTTOM_ROW_OPTIONS.map(item => item.val).indexOf(config.bottomLocked.display), + format: value => BOTTOM_ROW_OPTIONS[value].name, + min: 0, + max: BOTTOM_ROW_OPTIONS.length - 1, + wrap: true, + onchange: value => { + config.bottomLocked.display = BOTTOM_ROW_OPTIONS[value].val; + saveSettings(); + } + }, + 'Shortcuts': showShortcutMenu, + 'Day progress': () => { + E.showMenu({ + '': { + 'title': 'Day progress', + 'back': showMainMenu + }, + 'Enable while locked': { + value: config.dayProgress.enabledLocked, + onchange: value => { + config.dayProgress.enableLocked = value; + saveSettings(); + } + }, + 'Enable while unlocked': { + value: config.dayProgress.enabledUnlocked, + onchange: value => { + config.dayProgress.enabledUnlocked = value; + saveSettings(); + } + }, + 'Color': { + value: COLOR_OPTIONS.map(item => colorString(item.val)).indexOf(colorString(config.dayProgress.color)), + format: value => COLOR_OPTIONS[value].name, + min: 0, + max: COLOR_OPTIONS.length - 1, + wrap: false, + onchange: value => { + config.dayProgress.color = COLOR_OPTIONS[value].val; + saveSettings(); + } + }, + 'Start hour': { + value: Math.floor(config.dayProgress.start / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.dayProgress.start % 100; + config.dayProgress.start = (100 * hour) + minute; + saveSettings(); + } + }, + 'Start minute': { + value: config.dayProgress.start % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.dayProgress.start / 100); + config.dayProgress.start = (100 * hour) + minute; + saveSettings(); + } + }, + 'End hour': { + value: Math.floor(config.dayProgress.end / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.dayProgress.end % 100; + config.dayProgress.end = (100 * hour) + minute; + saveSettings(); + } + }, + 'End minute': { + value: config.dayProgress.end % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.dayProgress.end / 100); + config.dayProgress.end = (100 * hour) + minute; + saveSettings(); + } + }, + 'Reset hour': { + value: Math.floor(config.dayProgress.reset / 100), + format: hourToString, + min: 0, + max: 23, + wrap: true, + onchange: hour => { + minute = config.dayProgress.reset % 100; + config.dayProgress.reset = (100 * hour) + minute; + saveSettings(); + } + }, + 'Reset minute': { + value: config.dayProgress.reset % 100, + min: 0, + max: 59, + wrap: true, + onchange: minute => { + hour = Math.floor(config.dayProgress.reset / 100); + config.dayProgress.reset = (100 * hour) + minute; + saveSettings(); + } + } + }); + }, + 'Low battery color': () => { + E.showMenu({ + '': { + 'title': 'Low battery color', + back: showMainMenu + }, + 'Low battery threshold': { + value: config.lowBattColor.level, + min: 0, + max: 100, + format: value => `${value}%`, + onchange: value => { + config.lowBattColor.level = value; + saveSettings(); + } + }, + 'Color': { + value: COLOR_OPTIONS.map(item => colorString(item.val)).indexOf(colorString(config.lowBattColor.color)), + format: value => COLOR_OPTIONS[value].name, + min: 0, + max: COLOR_OPTIONS.length - 1, + wrap: false, + onchange: value => { + config.lowBattColor.color = COLOR_OPTIONS[value].val; + saveSettings(); + } + } + }); + }, + }); + } + + showMainMenu(); +}); \ No newline at end of file diff --git a/apps/invader/ChangeLog b/apps/invader/ChangeLog index 5560f00bc..6c5a33e59 100644 --- a/apps/invader/ChangeLog +++ b/apps/invader/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.11: Changes... diff --git a/apps/ios/ChangeLog b/apps/ios/ChangeLog index b6a386bcb..8ab99b4db 100644 --- a/apps/ios/ChangeLog +++ b/apps/ios/ChangeLog @@ -7,3 +7,7 @@ 0.07: Added more details from music (instead of Undefined), added more app identifiers 0.08: Added more app identifiers, added 'cannot display' in case a message goes empty because of replacements 0.09: Enable 'ams' on new firmwares (ams/ancs can now be enabled individually) (fix #1365) +0.10: Added more bundleIds +0.11: Added letters with caron to unicodeRemap, to properly display messages in Czech language +0.12: Use new message library +0.13: Making ANCS message receive more resilient (#2402) diff --git a/apps/ios/app.js b/apps/ios/app.js index b210886fd..2a9e8f322 100644 --- a/apps/ios/app.js +++ b/apps/ios/app.js @@ -1,2 +1,2 @@ // Config app not implemented yet -setTimeout(()=>load("messages.app.js"),10); +setTimeout(()=>require("messages").openGUI(),10); diff --git a/apps/ios/boot.js b/apps/ios/boot.js index 5ea7550eb..8952a047e 100644 --- a/apps/ios/boot.js +++ b/apps/ios/boot.js @@ -26,7 +26,7 @@ E.on('ANCS',msg=>{ // not a remove - we need to get the message info first function ancsHandler() { var msg = Bangle.ancsMessageQueue[0]; - NRF.ancsGetNotificationInfo( msg.uid ).then( info => { + NRF.ancsGetNotificationInfo( msg.uid ).then( info => { // success if(msg.preExisting === true){ info.new = false; @@ -38,6 +38,10 @@ E.on('ANCS',msg=>{ Bangle.ancsMessageQueue.shift(); if (Bangle.ancsMessageQueue.length) ancsHandler(); + }, err=>{ // failure + console.log("ancsGetNotificationInfo failed",err); + if (Bangle.ancsMessageQueue.length) + ancsHandler(); }); } Bangle.ancsMessageQueue.push(msg); @@ -63,6 +67,7 @@ E.on('notify',msg=>{ "name" : string, */ var appNames = { + "ch.publisheria.bring": "Bring", "com.apple.facetime": "FaceTime", "com.apple.mobilecal": "Calendar", "com.apple.mobilemail": "Mail", @@ -73,6 +78,9 @@ E.on('notify',msg=>{ "com.apple.podcasts": "Podcasts", "com.apple.reminders": "Reminders", "com.apple.shortcuts": "Shortcuts", + "com.apple.TestFlight": "TestFlight", + "com.apple.ScreenTimeNotifications": "ScreenTime", + "com.apple.wifid.usernotification": "WiFi", "com.atebits.Tweetie2": "Twitter", "com.burbn.instagram" : "Instagram", "com.facebook.Facebook": "Facebook", @@ -99,19 +107,22 @@ E.on('notify',msg=>{ "com.toyopagroup.picaboo": "Snapchat", "com.ubercab.UberClient": "Uber", "com.ubercab.UberEats": "UberEats", + "com.unitedinternet.mmc.mobile.gmx.iosmailer": "GMX", + "com.valvesoftware.Steam": "Steam", "com.vilcsak.bitcoin2": "Coinbase", "com.wordfeud.free": "WordFeud", + "com.yourcompany.PPClient": "PayPal", "com.zhiliaoapp.musically": "TikTok", + "de.no26.Number26": "N26", "io.robbie.HomeAssistant": "Home Assistant", + "net.superblock.Pushover": "Pushover", "net.weks.prowl": "Prowl", "net.whatsapp.WhatsApp": "WhatsApp", - "net.superblock.Pushover": "Pushover", "nl.ah.Appie": "Albert Heijn", "nl.postnl.TrackNTrace": "PostNL", "org.whispersystems.signal": "Signal", "ph.telegra.Telegraph": "Telegram", "tv.twitch": "Twitch", - // could also use NRF.ancsGetAppInfo(msg.appId) here }; var unicodeRemap = { @@ -120,18 +131,34 @@ E.on('notify',msg=>{ '261':"a", '262':"C", '263':"c", + '268':"C", + '269':"c", + '270':"D", + '271':"d", '280':"E", '281':"e", + '282':"E", + '283':"e", '321':"L", '322':"l", '323':"N", '324':"n", + '327':"N", + '328':"n", + '344':"R", + '345':"r", '346':"S", '347':"s", + '352':"S", + '353':"s", + '356':"T", + '357':"t", '377':"Z", '378':"z", '379':"Z", '380':"z", + '381':"Z", + '382':"z", }; var replacer = ""; //(n)=>print('Unknown unicode '+n.toString(16)); //if (appNames[msg.appId]) msg.a @@ -173,7 +200,11 @@ Bangle.messageResponse = (msg,response) => { // error/warn here? }; // remove all messages on disconnect -NRF.on("disconnect", () => require("messages").clearAll()); +NRF.on("disconnect", () => { + require("messages").clearAll(); + // Remove any messages from the ANCS queue + Bangle.ancsMessageQueue = []; +}); /* // For testing... diff --git a/apps/ios/metadata.json b/apps/ios/metadata.json index eb75a6dbc..42e0060d0 100644 --- a/apps/ios/metadata.json +++ b/apps/ios/metadata.json @@ -1,11 +1,11 @@ { "id": "ios", "name": "iOS Integration", - "version": "0.09", + "version": "0.13", "description": "Display notifications/music/etc from iOS devices", "icon": "app.png", "tags": "tool,system,ios,apple,messages,notifications", - "dependencies": {"messages":"app"}, + "dependencies": {"messages":"module"}, "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "storage": [ diff --git a/apps/isoclock/ChangeLog b/apps/isoclock/ChangeLog index 809091ce4..7b57ecfa9 100644 --- a/apps/isoclock/ChangeLog +++ b/apps/isoclock/ChangeLog @@ -1,2 +1,3 @@ 0.01: Created app based on digiclock with some small tweaks. 0.02: Swap to Bangle.setUI for launcher/buttons +0.03: Tell clock widgets to hide. diff --git a/apps/isoclock/checkout b/apps/isoclock/checkout new file mode 100644 index 000000000..e69de29bb diff --git a/apps/isoclock/isoclock.js b/apps/isoclock/isoclock.js index 59f28e66e..7526660b9 100644 --- a/apps/isoclock/isoclock.js +++ b/apps/isoclock/isoclock.js @@ -89,8 +89,8 @@ Bangle.on('lcdPower',on=>{ } }); -Bangle.loadWidgets(); -Bangle.drawWidgets(); - // Show launcher when button pressed Bangle.setUI("clock"); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); diff --git a/apps/isoclock/metadata.json b/apps/isoclock/metadata.json index 313153dde..488afcb41 100644 --- a/apps/isoclock/metadata.json +++ b/apps/isoclock/metadata.json @@ -2,7 +2,7 @@ "id": "isoclock", "name": "ISO Compliant Clock Face", "shortName": "ISO Clock", - "version": "0.02", + "version": "0.03", "description": "Tweaked fork of digiclock for ISO date and time", "icon": "isoclock.png", "type": "clock", diff --git a/apps/kanawatch/ChangeLog b/apps/kanawatch/ChangeLog index 7b83706bf..f2c991fd0 100644 --- a/apps/kanawatch/ChangeLog +++ b/apps/kanawatch/ChangeLog @@ -1 +1,5 @@ 0.01: First release +0.02: Improve battery life, sprite resolution, fix launcher issue and unaligned text bug +0.03: Reduce code size, refresh once a minute and faster refresh +0.04: Show a random kana every minute to improve learning +0.05: Tell clock widgets to hide. diff --git a/apps/kanawatch/README.md b/apps/kanawatch/README.md index 1fdf1927c..e213949dc 100644 --- a/apps/kanawatch/README.md +++ b/apps/kanawatch/README.md @@ -3,10 +3,17 @@ A simple watchface design with hiragana and katakana cards for learning. +## Changelog + +0.01: First release +0.02: Improve battery life, sprite resolution, fix launcher issue and unaligned text bug +0.03: Reduce code size, refresh once a minute and faster refresh +0.04: Show a random kana every minute to improve learning + ## Author Written by pancake in 2022, powered by insomnia ## Screenshots -![hiragana and katakana](screenshot.jpg) +![hiragana and katakana](screenshot.png) diff --git a/apps/kanawatch/app.js b/apps/kanawatch/app.js index ada6aa6df..088dab785 100644 --- a/apps/kanawatch/app.js +++ b/apps/kanawatch/app.js @@ -7,641 +7,107 @@ const w = g.getWidth(); /// ///////////////////////////////////////// const katakana = {}; const hiragana = {}; -katakana.A = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAjAEBfv4B/+yeAXwAOgBAAPAAAEHAAABzAAAAPgAAADgAAAAwAAAAMAAAAGAAAABgAAAAYAAAAMAAAADAAAABgAAAAYAAAAMAAAAGAAAADAAAABgAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.A = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAIAAAACAAAABgAAAAZ4AAGf4AAA/gAAAAQAAAAEAAAABBAAAAQwAAAN/wAADiGAADxAwABswEAAhYBgAQUAYAMHAEACBgDABh4AwAZ2AYAD4gcAAQAcAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.I = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAwAAAAGAAAADwAAAA0AAAAYAAAAUgAAAGAAAAFAAAADgAAAA8AAAA2AAAAZgAAAYYAAAMGAAAMFgAAGAYAAGAGAACABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.I = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAgAEAAEABAAAgAQAAMAGAABAAgAAYAIAAGACAAAwAQAAMAEAADABiAAQAIgAAADQAAAAcAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.U = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAQAAAAHAAAAAwAAAAICAAACIAAAAgIABQa3AAP7q4ADQANAAwADAAMABgADAAYAAwAGAAMADAADAAwAAwAYAAMAGAABADAAAABgAAAAwAAAAMAAAAGAAAACQAAADAAAABgAAAAwAAAAoAAAAAAAAAAAAAAAgAAA=') -}; -hiragana.U = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAIAAAABwAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfAAAA4YAAA4CAAAAAgAAAAIAAAACAAAAAgAAAAYAAAAGAAAABAAAAAQAAAAIAAAACAAAABAAAAAQAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.E = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAJXAAe+20ADRQAAAAOAAAABgAAAAQAAAAMAAAABAAAAAwAAAAEAACABAEAgJbvgP9qSsByAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.E = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAADgAAAAOAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAPAAAAdwAAAcYAAB8MAAAIGAAAADAAAABgAAAAwAAAAYAAAAMAAAAGAAAADIAAAB4gAAA4EAAAMAgAACAOGAAAB/wAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.O = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAADwAAAAOAAAADAAAAAwAAAAMAAAAjAABAAydAbff/wH/XAUAwDwAAAB0AAAA7AAAAMwAAAHMAAADjAAABkwAAA4MAAAZDAAAMEwAAGEMAAGQzAADAHwABAA8AAAAHAAAABAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.O = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAgAAAAMAAAADACAAAwAYAAMADAADIAQAA/AGAF+AAAAyAAAAAgAAAAIAAAACAAAAAg/gAAJwOAADgBgABgAMAAoADAAyAAwAIgAMAEIAGABCADAAJgBgAD4AgAAMAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.HA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAcGAAADgwAAB4HAAA4A4AAMgHAAHAA4ADAAXAAwAA4AYAAHAMAABwGAAAMGAAACDAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.HA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAABAACAAYAAwAGAAMABgACAAYAAgAHwAIAD4AGAfYABAAGAAQABgAEAAYABAAGAAQABgAEAAYABAAGAAQABgAEAAYABAOGAAQEfgAFCA8ABggPwAYG+GAGAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.HI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAXAAAABwAAAAYAgAAGAMAABgDgABYD0AAWF4gABvwAAAfAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAgAAal8AAD//gAAJQAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.HI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwEAAA8BAAB2AYAABACAAAwAQAAIAEAAGAJgABACIAAwAjAAIAIYACACGABABAwAQAQEAEAEAABADAAAAAgAAEAYAABAEAAAYDAAADDgAAAfgAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.HU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAAALwAYt/vAD/0DwAcABwAACAcAAAAGAAAADIAAAAwAAAAYAAAAOAAAAGAAAADgAAAAwAAAA0AAAAaAAAAOAAAAHAAAAHAAAAHAAAAGgAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.HU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAGAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAACAAAAAQAAAACAgAAAgEAAAMBgAABAYAgAwDAMAMAgBgCAAAYHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.HE = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeAAAANwAAAGHAAADA4AABwDgAIwBOADcABwQeAAHgDAAA8AIAADwAAAAeAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.HE = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAIMAAAMAgAAGAGAADAAwAAAADAAAAAYAAAADgAAAAMAAAABwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.HO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAEAAAADQAAAAYAAAASAAAABgAAAAIAACAGK4A273dAHoYAAAAGAAAAAgAAAIIQAAECGAABAgwAAgYGAAIGAwAGAgGADAIBwBiCAaAYRgDAMDIAgAAeAAAADgAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.HO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeAAQB+AAEAgAABAAQAAQAGAAIABgACAAQAAgAHwAIAD4ACAfQABAAEAAQABAAEAAQABAAGAAQABgAEAAYABAAGAAQBdgAHAg4ABwAHgAIB+OACAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.KA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAUAAAADwAAAAcAAAAGAAAABgAAAAYFABAOvwAfv9eAD6wHAAQMBwAADAYAABwGAAAYBgAAGAYAADAOAAAwDAAAYgwAAMgcAADEmAAFgzgAAwHwAA4B4ABYAcAAMABAAEAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.KA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAwAAAAIAAAACAAAABAAAAAQAgAAMAEAAD8AwAHggGAHQIBgAECAMADAgDAAgIAQAIGAEAEBAAABAwAAAwIAAAYGAAAGBgAAADwAAAAcAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.KI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAACwAAAAeAAAADgAAAAYAAAATBgAAAz8AAAP5AAxfQAAH8YAAA4GAAAABgHAAAYf4AAD+pAAF8AAMPsAAC/hgAAPAYAABAGAAAABwAAAAYAAAAHAAAAAwAAAAOAAAADAAAAAYAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.KI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAQAAAAGAAAAAgAAAAIAAAADDAAAAfwAAAeAAAA4gAAAwIAAAABAAAAAZwAAADwAAAHwAAAOGAAAAAgAAAAMAAAADAAAAAQAAAAAAAAAAAAAAAAAAEAAAABgAAAAPmAAAAfwAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.KU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAQAAAAHAAAAA4AAAAMAAAAHBwAAB/+AAA0XAAAaBkAAGA4AADAOAABgHAAAwBwAAYA4AAMAMAAGAHAAAADgAAABwAAAA0AAAAaAAAAOAAAAHAAAADIAAADgAAACgAAABgAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.KU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAQAAAAMAAAADAAAABgAAAAQAAAAIAAAAGAAAABAAAAAgAAAAQAAAAEAAAACAAAAAQAAAAEAAAAAgAAAAEAAAABgAAAAIAAAADAAAAAYAAAAGAAAAAwAAAAMAAAABgAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.KE = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAABwAAAAOAAAADgAAABwAAAAYAQAAGAAgABgF8AA79/gAb7gAAGQcQADAHgABgBgAAYAwAAZAMAAMAHAADABgAAgAwAAAAMAAAAGAAAALAAAABwAAAAYAAAAYAAAAMgAAAGAAAACAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.KE = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAABAAAAAYAAIAGAAGABgABgAYAAYAGAAEAB+ABAB/gAQHmAAEABgADAAYAAgAGAAIABgACAAYAAgAGAAIABAACAAQAAgAEAAKABAADgAwAAYAIAAGACAAAgBAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.KO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAwCtwAH//8AA+oGAAEABgAAAAYAAAAGAAAABgAAAAQAAAAsAAAADAAIAFwADv//AAf1CQACAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.KO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB/8AAAADwAAAB8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAYAAAAD8EAAAH/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.MA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAFcAIG/3ga/0h4H6gA4AcAAcACAAOAAAAHAAAYDAAAFjgAAAPgAAAB4AAAAOAAAABwAAAAMAAAADAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.MA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAEAAAABBAAAAf8AAD+AAAOBAAAAAQAAAAGAAAABgAAAAZwAAAHwAAB/gAAAAYAAAAGAAAABgAAAAYAAAAGAAAARgAAAR4AAAIHgAACDPAAARg4AABAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.MI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAegAAAC+gAAAB8AAAAHgAAAAYAAAAQAAAAgAAAegAAAB+AAAAD4AAAAPAAAABwAAAAMAAAAAAAAAAAAAAAAAAAUAAAAF8AAAAHwAAAAPgAAAA8AAAAHwAAAAeAAAADAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.MI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPgAAA+YAAAEMAAAADAAAABgAAAAQAAAAMAAAACAAAABgAAAAQAAAAIAIAAGAGAADgBgAO/wQAEIH8ACEAH4AiABnAJgAQQBgAIAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.MU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAACgAAAAcAAAADgAAAA4AAAAcAAAAHAAAABkAAAAYAAAAMQAAADEAAABwwAAAYGAAAGAwAADAHAAAwA4AAIAOAAWBfwBBX9OAf/oDgH+gAYA6AAGAAEAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.MU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAYAAAACAAAAAgAwAAIAGAACIAwAA/gEAB+ABAB2AAAAAgAAAAYAAAAGAAAABgAAAAYAAAAGAEAABgBAAGQAQAA0AEAAFABAAAwAQAAEAMAARgCAAGWHgAA8fgAAGAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.ME = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAcAAAABgAAAAcAAAAHAAAADgAAAAwAAABcAABgGAAAfDgAAAewAAAB8AAAAPAAAAD8AAABzgAAA44AAAcHAAAGAwAADAAAACgAAABwAAAAoAAAAcAAAAMAAAAMAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.ME = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABgAAAAYAABAGAAAIBAAACAwAAAgP4AAMeDgABZgMAAYQBgAOMAYAGiACADJgAgAjQAIAQcACAEGABgBBgAQARsAIAHwAEAAQAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.MO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAABAAUAASXfgAD7EQAAQwAAAAOAAAABAAAAAwAAAAEAUBADd/wNfaRID1EAAAIDAAAAAwAAAAEAAAADAAAAAQAAAAMAAAABiQAAAf+AAABKQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.MO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAACAAAAAgAAAAIAAAACAAAAB+AAAA/wAAB0AAAABAAAAAQAAAAEAAAABAAAAAQAAAAEYAAAf+AAABwAAAAMAAAACAIAAAgCAAAIAgAACAIAAAgCAAAEBAAABgwAAAP4AAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.NA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAPAAAAA4AAAAOAAAADAAAAAwBAAAMQAAADAaBAT9/wf/vbcD6DAAAQAxAAAAMAAAADAAAAAwAAAAMAAAAGAAAABgAAAAYAAAAMAAAAGAAAABgAAAAwAAAAYAAAAMAAAAEAAAABAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.NA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAgAAAAJgAAAH4AAA/gAAAMQAIAAIABAACAAYABgACAAQAAAAMAAAACAIAAAgCAAAAAgAAAAIAAAACAAAAAgAAAPIAAAEOAAABB4AAAQTgAAD4MAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.NI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgALAANb/8AB/6pAAMAAAAAACAAAAAAAAAAAAAAAAAAAAAAABAAAIAAAJvAKN//4D/1EGAdAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.NI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAGAAAABgA/AAYBwAAEAAAABAAAAAQAAAAMAAAACAAAAAgAAAAIAAAACAAAAAgAAAAIAAAACAAAAAAEAAAIAgAADAH/gAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.NU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAFgAML38AB/9OAAOgHAAAQBgABAA4AAAAMAADoHAAAPRgAAAfYAAAB4gAAAPQAAADeAAABjwAABwcAAI4DgAA4AcAAcADAAcAAQAaAAAAWAAAACAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.NU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAABAwAAAIMAAACDf4AAg4DAAIYAYACeACAAZAAgAMQAIAFMACACSAAgBDgAIAwwOGAIMEbACHBDgAjYPsAPCABgBggAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.NE = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAGAAAAA4AAAAHAAAAA4AAAAGAAAABgAAAAJYABAv/AAf+nwAD4DoAAQB4AAAA8AAAB8AAAAeAAAAPQAAAHzgAAHMeAAHDB4ADgwOAHgMBwHADAMKgAwAgAAMAAAADAAAAAwAAAAMAAAADAAAAAwAAAAEAAAAAAAAAAAAA=') -}; -hiragana.NE = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAgAAAAMAAAADAAAAAwAAAAIAAAADAHgAA8GIAA+CCAAzBAwAAhAMAAIgDAAGQAwABoAMAAsADAASAAwAFgAMAC4ACAAyAugAcgIYAGYCHABGAecABgABgAYAAIAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.NO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAGAAAABwAAAAeAAAAOAAAADgAAAAwAAAAcAAAANAAAADAAAABwAAAAYAAAAOAAAAHAAAABgAAAAwAAAAYAAAAMAAAAGAAAAGQAAADAAAADgAAAAkAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.NO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAD44AADEBAABBAIABgQBAAwMAYAICACAEBgAgAAQAIAgMACAICAAgCBgAYAwwAGAEIADABmAAgAPAAQADgAYAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.RA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAEAAQAIAANTvgAD/u0AAOAAAAAACAAAAAAABAACAAgAt4APf/vAB/UDQAIAJwAAAA4AAAAOAAAAHAAAABgAAAA4AAAAcAAAAOAAAAGgAAADQAAABoAAAA4AAAAcAAAAaAAAAMgAAAEIAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.RA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAQAAAACAAAAAwAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAIAAAACAAAAAgAAAAYAAAAEAAAABAAAAAQAAAAEA+AADBwQAA3gCAAPgAgADAAIAAAAGAAAADAAAABgAAAAwAAAAgAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.RI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAQBwAAHgOAAAsDgAAGAwAABgMAAAYDAAAGAwAABgMAAAYDAAAGAwAABgMAAAYDAAAGAwAABgMAAAYDAAACAwAAAAYAAAAGAAAADAAAAEwAAAA0AAAAcAAAAOAAAAOAAAAOAAAAGAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.RI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAABAAAAAYAAAAGAAAABAQAAAQGAAAEAgAABAIAAAwCAAAIAgAACAIAAAoCAAAOAgAADAIAAAQCAAAEAgAAAAYAAAAGAAAABAAAAAQAAAAEAAAACAAAAAgAAAAAAAAAEAAAACAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.RU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAABAAAAAeAAAADgAAAA4AAAcGAAADhgAAA4YAAAMGABAGDAAwBkYAYAYGAMAMDAOADAYHAAwGDgAYBjgAMgbwADAHyABgD4AAwA4AAYAEAAMAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.RU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAO4AAA8MAAAAGAAAADAAAAAgAAAAQAAAAIAAAAGAAAABAAAAAgAAAAQAAAAIYMAAE4BgAB4AIAA4ACAAMAAgAAAAYAAAAEAAATCAAAEZAAAB/AAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.RE = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAACgAAAAeAAAADgAAAAwAAAAMAAAADAAAAAwAAYAMAAMADAAGAAwAGAAsADgADABgAAwBwAAMBwAADA4AAAw8AAAM8AAAD8AAAA+AAAAGAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.RE = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAGAAAYDgAAfBIAANgiAAMQwgAAMYIAAHMCAAB2AgAAnAIAAJgCAAEwAgAAcAIAAvACAAewAggHMAIwBDADwAAwAAAAMAAAABAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.RO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAYABk3/AAP/a4ADQAYAAwAGAAMABgABAAwAAwAMAAMADAABAAwAAQEMAAEASAADEt4AA/++QAGgAAADAAQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.RO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAF8wAAAwYAAAAMAAAACAAAABAAAAAwAAAAYAAAAEAAAACAAAABAAAAAg/gAARgGAAPgAgAHgAMADgADAAQAAwAAAAYAAAAOAAAAGAAAAGAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.SA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAFAAAAA4AABAHAAAdBgAABwYAAAYGAAAGBgAABgYABAYGrAYu//4H/aomA4YGAAAGBgAABgYAAAYGAAAGBgAABgwAAAYMAAACGAAAABgAAAAwAAAAYAAAAOAAAAGAAAADgAAABgAAAAgAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.SA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAGAAAABgAAAAIAAAADAAAAAQgAAAG8AAAB4AAAB8AAAPhgAAAAIAAAABAAAAAYAAAADAAAABwAAAAGAAAAAgAAAAAAAAAAAAAAAAAAAAAAAEAAAAAwAAAAH/AAAAHwAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.SI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAA0AAAAHgAAAAcAAAAjgAAAAYABAAAAAwEAAAYB4AAMAHgAGAA4ADAAWABgAAgAyAAAAYAAAAcAAAAOAAAAOAAAIHAAAUHgAABnwAAAPwAAAB4AAAAIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.SI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAQAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAIAQAADA4AAAf4AAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.SU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAEAAGC/gAE/9cAAOgOAAAgHAAAABwAAAA4AAAAcAAAAGAAAAHgAAAB2AAAA44AAAYHAAAcA4AAOAHAALAA4AHAAOAGgABgDAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.SU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAADAAAAAQAAAAEAAAABAAAAAQAAAAE/gAAf/4AH4QAAHAEAAAABAAAAAQAAAGkAAABFAAAARQAAAEcAAABDAAAAYwAAAB8AAAAGAAAABgAAAAQAAAAMAAAAGAAAABAAAABgAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.SE = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAA4AAAAHgAAAA4AAAAMAAAADABAAAwG4CAN/vAw36DgH+wDgA6MBwACDA4AAAwZAAAMUAAADMAAAAyAAAAMAAAADAAAAAwAAAAMAAAADAGAAA//gAAL94AAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.SE = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAMAAAgCAAAMAgAADAIAAAwCAAAMAgAADAf8AAx+AAAPhgAAPAQAA8wEAAMMBAAADAwAAAwcAAAEGAAABAAAAAQAAAACAAAAA8OAAAB/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.SO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAQAAAALAAIAA4ADAAeAAcAHAADIBwAAYA4AAHAOAAAwDAAAIBwAAAAYAAAAMgAAAHAAAADAAAABwAAAAYAAAAMAAAAOAAAAHAAAADgAAADgAAADgAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.SO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAYAAAAzAAAHxgAAAwwAAAAYAAAAEAAAACAAAABAAAAAgAAAAQDwAAIDwAAEGQAACOIAABeEAAAMCAAAAAAAAAAQAAAAEAAAABAAAAAYAAAADAAAAAYAAAADwAAAAMAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.TA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAOAAAABwAAAAcAAAAGBYAAB/fAAA1DgAAMA4AAGAcAABgHAAA4DAABdwwAAMPcAAGA+AADADkABgB8AAQAzAAAAMAAAAGAAAADAAAADgAAABwAAAA4AAAAYAAAAcAAAAMAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.TA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAACAAAABgAAAAYAAAAEAAAADHgAAA/gAAH8AAAAmAAAABAAAAAQAAAAMAAAACAfgABg4AAAQAAAAEAAAADAAAAAgAAAAYAAAAEAAAADAAAAAwDjgAIAP8ACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.TI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAOAAAAH4AAAPwAAAvgAADe4AAL4OAABADAAABAwAQAAMV4ECv//B7/0IwPQmAAAgDAAAAQwAAAAMAAAADAAAABgAAAAYAAAAMAAAAGAAAACgAAAAwAAAAwAAAAsAAAAMAAAACAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.TI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAABAAAAAIAAAAGAAAABgAAAAQAAAAEAAAABHAAAB/AAAH4AAAACAAAAAgAAAAQAAAAEAAAABAAAAAQAAAAIPcAACMBgAAsAIAAcACAAGAAgAAAAIAAAAGAAAADAAAABgAAABgAAABgAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.TU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAACAAAAAyBgAgHAOAGA4DwAwOA8AGBgcABwYHAAcADgADAA4AAQAcAAAAGAAAALgAAABwAAAAYAAAAMAAAAOAAAADAAAADgAAABwAAABwAAABwAAADRAAAAgAAAAAAAAACAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.TU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/HAAB4AYADwACAPwAAwBgAAMAAAADAAAAAgAAAAYAAAAEAAAADAAAADAAAADgAAADAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.TE = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAACAACAn4AC3/vAAHoAAACQAAAAAAIAAAIAAAgAFfQG3+/8B/YwBAGAOAAAADgAAABgAAAAcAAAAGAAAADAAAABQAAAAYAAAAOAAAADAAAABgAAAAwAAAAwAAAAYAAAAKAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.TE = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAPAAAAbgAAA5gAABwgAADwYAAHgEAAAgCAAAABAAAAAQAAAAAAAAACAAAAAgAAAAIAAAACAAAAAQAAAAEAAAAAgAAAAOAAAABwAAAAHAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.TO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAA4AAAAHgAAAA4AAAAMAAAADAAAAAwAAAAMAAAADAAAAAwAAAAMAAAAD6AAAAzwAAAMPAAADA4AAAwHAAAMAwAADAEAAAwAAAAMAAAADAAAAAwAAAAMAAAAGAAAABwAAAAMAAAAAAAAAAAAAAAIAAAAAAAA=') -}; -hiragana.TO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAGAAAAAgAAAAMAYAABAHAAAQHAAAGDAAAAhgAAAIwAAABwAAAAYAAAAMAAAAEAAAACAAAABAAAAAQAAAAAAAAACAAAAAAAAAAGAAAAAf/wAAAfgAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.WA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAACAAANACsAB7//gAPtI4AJgAOAAYADAAMABwABgAYACYAGAAOABgABgA4AAwAcAAGAHAABADgAAAAwAAAAcAAAAOAAAAHAAAADgAAADgAAADgAAAFwAAACgAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.WA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAgAAAAMAAAADAAAAAwAAAAMAAAADAAAAA8AAAAfAAAAfgAAAIwAAAAIDnAAGCAYACiACAArAAwATAAMAJgADAD4AAgByAAYARgAEAAYACAAGACAABgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.WI = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAQAAAAPAAAAA4AAAAMAAAADAAAAAwAAAAsEABhLvgAP//cAB5MAAAGDAAADAwAAAQMAAAMDAAADAwcBg19/wf/7UsD1AwAAIAMAAAADAAAAAwAAAAMAAAADAAAAAwAAAAMAAAADAAAAAQAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.WI = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAAAAbAAAB4wAAAMIAAAACAAAABgAAAAQAAAAEAAAADAAAAA3+AAAeAwAAeAGAAZAAgAMQAMAEMADACCAAwBBgAMAwQACAIMDxgBCBGwARAQYADgCcAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.WE = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAFBK4AB//+AAPUHgABADgAAARwAAAOwAAABwAAAAMAAAADAAAAAwAAAAMAAAALAAAgAyVgPv//+B/qIrgIAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.WE = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAA8AAAB3AAAHhgAAAAwAAAAYAAAAMAAAAGAAAADAAAABhwAAAzDAAAaAYAAOAGAADADAAACRgAAANgAAAGAAAADAAAABgAAAAgAAAAwAcAAYAxwAfggGAOGwAwDA4AAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.WO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAABAAAgAAwAO37/AB//bwAMgAwAAABYAAgAHAAAABgAGFb4AA//uAAHQDAAAAQwAAAAYAAAAOAAAADAAAABgAAAAwAAAAsAAAAGAAAADAAAABgAAABoAAAAwAAAA4AAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.WO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAMAAAACOAAAB/AAAPwAAAAMAAAACAAAABAAAAAwAgAAIAcAAHMMAADBOAAAAeAAAAGAAAADgAAADIAAABCAAAAgAAAAIAAAACAAAAAgAAAAGBwAAAP8AAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.YA = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAEAAAAD4AAAAOAAAADAAAAAwAIAAGADAABgX4AAa/fAAX6OAZfwHAD9MDgAcDBgAEAwwAAAmYAAABogAAAYAAAAGAAAABgAAAAcAAAADAAAAAwAAAAOAAAADgAAAA4AAAAGAAAABgAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.YA = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAgAAAAGAAAAAgAAAAMAAAQAAAAEAAAABAHGAAQOAwAGcAEAA4ADAA4AAwA7AAYA4QA4AAEAAAAAgAAAAIAAAADAAAAAQAAAAGAAAAAgAAAAMAAAADAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.YU = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAABAC4AAd//AAH2hoAAQAyAAAAMAAAALAAAAAwAAAAMAAAADAAABAwQEABe+Bt//9wP+kAIBwAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.YU = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAgAAAAIAACADAAAwD3AAIDIIACBCDAAgggQAIwIGACICBgBkAgYASAIEAEACBABQBgwAcB4YAGAGcABgB8AAYAQAACAIAAAACAAAABAAAAAQAAAAIAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -katakana.YO = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAIAlgAD//8AAfUGAACABgAAAAYAAAAMAABABgABBLwAAf/8AAF0DAAAgAwAAAAMAAAADAAAQAwAAgAMAANN3AAD/3wAANAIAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.YO = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAEAAAABgAAAAMAAAACAAAAAgAAAAIAAAACDAAAA3wAAAOAAAACAAAAAgAAAAIAAAACAAAAAgAAAAIAAAACAAAAAgAAAAIAAAPCAAAEPgAABA8AAAQHwAAADPAAA/g8AAAADgAAAAYAAAAAAAAAAAAAAAAA=') -}; -katakana.N = { - width: 32, - height: 32, - bpp: 1, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAEAAAABgAAAAOAAAABwAAIAMgAGADgADAAwABgAAAAwAAAAwAAABYAAABOAAAAHAAAAHAAAADgAAADkAAABwAACB4AAAx4AAAP4QAAB8AAAAOAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; -hiragana.N = { - width: 32, - height: 32, - bpp: 1, - transparent: 0, - buffer: atob('AAAAAAAAAAAAAAAAAAAAAAAAgAAAAIAAAACAAAABgAAAAQAAAAMAAAACAAAABAAAAAQAAAAIAAAAGAAAABAAAAAkAAAALgAAAFIAIADiAAAAwwBAAYMAQAEBAIADAQGAAgGDAAYAzgAEAHgAAAAAAAAAAAAAAAAAAAAAAAAAAAA=') -}; +function image(x,y,b) { + return { + bpp:1, width:x,height:y, + buffer:require('heatshrink').decompress(atob(b)) + }; +} +katakana['A'] = image(56, 51, "v//AAfwAon//AGF/wGT/gGM/A3F/BDEn/wJQoGCj4RB//gAxUB//AAwcDAwsH/+AAwcP/4tCAwMf/wGEn/8Awl/JYYGBKQkf/I9DAwJgBGwQGDGwRlBAwJsE+42DAwPzGwYGB+J7EQIIvDQIIFEAw5DEAwRDDgCIEAxCPBKIcAR4IhER4hnCLAg9BLAgoBAwgoBcQiCBMwj0BHogGBHogGBfoooEQQREFEIgGBAokAhAGFA="); +katakana['I'] = image(54, 55, "AAkEAws+AokB/wGEg//Awk//gTE//gAwcPCYt/CYkDCYsfCYv//A0F4A0ECYg0BCYggBCYn/KwhBBGgl/EAgtBEAgMBEAZOBEAgMBEAYZB/+ABggTDBgQnDAoIaDJoIaDFgIABDQQFC74aBBgX8v4aBEwWBDQQgB/EHDQQ6BwEfGoX/+AJBDQMDWAKMBDQMPAQIaDiBFCPAgaDU4hrDDQiuDDX4acSAIaCA="); +katakana['U'] = image(52, 55, "AAMP/gGE//ABlH/AAnvAon+Bk5EDv/vIgcHBkHPBgZwBBgn/Bi8B/+PBgcf/AMFw/wBgYEDgED/6qEv4MEKYK3F8AFDj7EED4LREv/4CQn/wASEFginBDAgfEDAIfDn67BC4YABH4QXBCQcHZoQkEEoYMCHAYlBFYZEBLwk/MgpQEAAw"); +katakana['E'] = image(58, 45, "h//AAfwgYGE/0AAwn/wE/AwngDgv4DjhDCv/wJQkf/gGEg//AwkB//AA4gc/Dn4cjbAv/34GF94GF/YGF/wcjwA="); +katakana['O'] = image(57, 54, "AAcf+AGEh/8AwkH/wGEgf/AwkB/+AA4n/4AGEv/gAwk/GIsf/A4P/4AE+F/Awn4n4GE/kfAwn+h4cFg4GFwYGF4IGFKwYFBMQpxFAwJxEAwJxEAwJxEAwJxEK4JxEAwKqEMoQGE/o4En/8HAl//iqEAwKqEv/+VQgNBVQgNBcYgNBcYhLBcYhSCHAQKBAwI4CAwY4CD4IGBHASxBAYI4CAwY4CYwIGBHAQGBD4I4CBIJfCHASmDHAV/PYQ4Cj5QCHAUPLwQ4CgQGCOIgABOIgABHAIGEAAY="); +katakana['KA'] = image(54, 54, "AAMP/AGEv/gAocB/+AAwcH/wTEj4arg//AAf+j4GE/F/AwnhAon/w4aZHAMP/hTEn/wKYn/4BTDgf/KYgQCDQYQCBIQQDBIQQCBIc/DQouCDQQuCEghJBEhITBH4RTBLoRTEBIJTGCAUPNwoTCDQQWBDoIuCj4TCJIX/CYQ/BZQInBH4U//0HwBTBGgPwXAXwh4PBXAXAv4PCZIIgBEYTJBn5SBDQXABAIzBCYJcCDQXwgbOCAwIDBQgI4CgEOJwIADkAGFA"); +katakana['KI'] = image(58, 55, "AAU+Awv/4AGEn/wAwkP/gGEgf/Dkk/CAc//4ABwAGBj4GC8ATBAAf4h4GE/woBAAmAAwvgFAYcIwAcD/BFDFARFD/kBIoYACv5FBAAcfRL94DgkfHgf/95EBD4RgDD4MHLwf8AogAd+CPFGwiJCS4XHJgSGB8CJEkCJJUwYABg5pDD4amTNwKmXYbgcDLoY="); +katakana['KU'] = image(55, 55, "AAMHwAGEh/8Awkf/AGEv/wAwn/4AFDgf/EQkH/whF/4ACAwM/AoQQCBgY5BgIGDHIMHAwY5Bh4GD8AhEIAQFDIAIhBBIJACEIJpEj45CNIV/NgRpBDQIrBEoPgDQJlBEoQaDEoV/RwUP/wPBQ4Uf/gPBQ4QsBKAKSD8BvCSQXDDQYYBNYIaCGYIqBDQU//kPXoYYBj5QCEIPgj60DKoMcWga7FKoYABKogaDbojPBbojMDGob/ECYJBCbgYaDE4IaEPoIaDEAI1EbYQZECYgtBCZQGCLol/KwxxEAwJqEgIMFgIZEgA="); +katakana['KE'] = image(60, 54, "AAMcAwsD/4HFn/wBxl/8AGEg/+BxkP/gOF//ABxcB/+AA4kf/BCGAAZOBv4HEIQIOGAwgOBh4OFGYIOFn4OFEgoOBAwvgh52BKgYDBOwJUDv5nBBwY6BAYM/BwIKBJgJjBBQSbCWoQVBRgK1D/4oDBwJJBWos/WIS1CgIVCJoRGBWowCCj61HYgpRCdIjEGLgTLEIwTLEfAv/GYqtBEghyBGYjoCAwwkDAwQVEYwYjEHQt/CopeBQgQOEIIgOBPgxeFgZ7FA"); +katakana['KO'] = image(49, 46, "v//AAYFF34FE74FE94FE+4FE/IFE/gFE/w0Dgf/AocB/+AAwf/4BHE8AFDn/wAocf/AFDh/8AocHGH4w6YZf7Aon9YYoFEejBhEAAIA="); +katakana['SA'] = image(58, 53, "AAcD/wDBg4DC//AgEB/+AgE/+AKBv/ggEP/gGBj/4DgP/DnU//4A34CQ+DAIcEDAIcDDAQDDDAYDCDAYDD/4cDIgJADAAUfIAQACh4jCAAUHD4QACJwIfBAAQtBEYgGBI4QUDFQkP/4qEVYQvEAAIxCEIK5CBwV/AwsfAwocCAwYcCJogcBNIp3F"); +katakana['SI'] = image(56, 52, "gFwAwt+Awv/8AGF/gFDgP//4GGCocDAwIVDBoX/wAHCn4VFg4GB4AxEAwsfAworBEQYABv4GFj4DCjgrCBQYRFn/4JQfAIgIGD+F/JQcD/gGBMARQCOwcH/wNBCoUP/0PAwIrBj/8OwQGBn4fBGIIGCAQIlB+BcBAQKvDBIQRB8AfBIQUH4AXBP4RXBGgJmERoJsFAwv//yaFbYghBQIYaCeAi9FPQTZGdxKFCFASECFAZPBEIgNCJQaZEAwhDDAwRJDTAYGEQAiQBPIgAGA"); +katakana['SU'] = image(60, 51, "gH/AAYGBh4GD/AOG4AOF/gONDo+ABxAACgY7CAAd/+AGEg4OG//gAwkP/wGEgJCCAAcfKIQzEIQIzEIQozOj4zFEgIzFn4kHGYv/M4okIGYt/IQqXBFghuBHYs/bAY6DCwrJECod/HgYVB8ZLEcoMfLQYECCwYVB+BTBCwT7CCwYrBAYIKCCoQDC8BXBEIQSBNoQVBBYP4EAIoCOQPHCoYTB/xdBIwQ8B+6SET4N/dYn/4aCFFgKRFgC+EgPghivEAoI"); +katakana['SE'] = image(57, 53, "gEH/wGEgf/AwkB/+AA4n/4AGEv/gAwk/+AGEj/4AwkP/g4JjA4EBQQ4D/4DD4E/AwIuBv/vAoP/FwILCAAIuBv4GEBgn//wFEAwITEh//CgfwAwMfCIRGB/4BB/5xBAgJTBIQQGBwP/75CBAwOAD4JCBAwRmDDIKYBOIQGDOIQGDOIQbBAwSqBAwiqBAwiqBDYg4Cv4GCHAUfAwQ4Cg4GCHAUBbwbjnHAgADcYYADUYQxEEYq6CVwbDBdQi6CZQYqBAAZcCAwY1BEYi5DAAQ8CegfgA="); +katakana['SO'] = image(52, 52, "gGAAol8AYUD/Ef4AGCn/3/wFCg/+v/wAwV/8//Bgk//AMD8f/FoQMBj/8Bgfg//gBgcPFoYMBFocP/kHFof/4AtDBgMDFoYMBFoYMBgIIBgADBwAtDj4dBHQQMCFoYqCHQQqCFoc/BIIPCCwQtDKYIpBB4IwDIAQwCh45CBIVAFgSmDFIaaDOIYfCVgYfBRYYfCTASTCUoY1BQgZPCD4l/D4kfH4g4BH4YYBH4gFBGQd//4yDBYIyDn4SEJQIlEBgRXEHAg+BFYZRGZYQADBYgAG"); +katakana['TA'] = image(55, 56, "AAMHwAGEh/8Awkf/AGEv/gAwn/4AFDgf/EQkH/4oF/4ACAwM/AoX+FAQGCHIMBCYY5BEIIAC+AhFIAIhDHIQFDF4IhBJQMHF4JDDNIUfHIRpCv5sCn/wDQJsCDwIaBEIIKBwEf/9gOAQaB/gbBFAIPB+YsC/AaB54RBFAIaBAIOAEoJvBOgPh/+DNAJWB+//DQPBQIZyBM4f4LQSQC8EPKAIpBFAMPPgKKCgEcYIZwBiAGDbohwEZ4bdEFILxFf4ghBXwLjEDQhLBCYoaEE4IaDdIQaDBgLBCDIRQENYYTIewRkEAwJCFHYicBOIkAEAhDBS4IAJ"); +katakana['TI'] = image(57, 54, "AAkGAwsfwAGE//gAocP//wBgn//gEBgIFBAAIeBAof/wAYBAwkHAof+gEDAwf4E4YAB4AGBv4TDAAM/AwoxDKQhABLQwiCAAV/MIglBMIglBHwRwDNARbF//3Awv7Awv9Awv+Awv/MQQAD34GF74GFKAUHOIYABSAJxGaYp4Uv54FP40/P4oGHQwQGKKgt/AwrUEMIQGEVYIGLg4bMFII+Fv5TGNAsPQgsHTIoAG"); +katakana['TU'] = image(54, 53, "AAMBwAGEj4FEgf8AYPwgFgn/4BIP/g+Av/ggEP/n/gP/4EAv/v/wQBFQP/z/4CAMAg/+DAMfEIICBDAN/FgN/8YYBBAIaBw4hDDQIVBAYMAn/wDAIhCCwIhDCwIBBwAIBHAIYBEIQYDBAIuBwAjBFQghCJgQhEAIIhDEYQPBh5HBM4IhDQQQhCwYeBCwMBCoSPB/0CIQQhBAQKWDvytBCYTBDv5tBZYYTCAAQTCAAYTFHAITEj4TF/4TEh4TFv4TEg//JgIMDMYIMEO4ImD/53BAAM/AwIsEEAgFBEAZNBIIgTCFocfJwo6BPgpHEgZAEgEOAogAGA=="); +katakana['TE'] = image(57, 51, "h//AAfwg4GE/kDAwn+gIGE/8AAwuAv4GE4E/Awngj4GFNWJNF/gGF/5UF/+/AwvfAwvvAwv3Awv7GJn8IQV/4BJEv59Fn/wAwkf/DJFEAYABg/+AwjJBAxbQBwAGFH4gGBH4gGIIwgGNG4IGEg//LYjyBAwiyBAxc/EQoGGFIJTLdYJvEgF+fIsYAwo="); +katakana['TO'] = image(42, 54, "//AAgU/+AECh/8AgUD/4U/CgYPDn//wAUC/4VCCgIlDAgIKCCgIKCCgP//wUD//gCgQKCn/zBQQ+BDYP8CgMBEAQBBj4KBKYIKC54yBBQP7KYIKCG4QKB35YBBQIUCGQPjNAUD+BXDnB9Dgy8/CicAA="); +katakana['MA'] = image(57, 50, "/4AE/l/A4s/AwvfAwoAN/YGF/oxGHokf/wGLh4GN/4GSg4GChgGDwARBAw3gAwv4Awo7BAwn/4ACBAwIKB+AGDgJtBAwcAUgOPAwYLB94GDgaFCAwTBDAwcfAwoyBAwgyBAwgyCAwgcBAwgyBNgL0ENgIADn6oHDijhFW4wcB4AGDKwPwBwl/fwzUJDgZOFgAGGngGFhADCA"); +katakana['MI'] = image(52, 53, "gPwAwkf/wFDgf///gAwU/AwIVCBgX//AME//8gEHAoQGCBgYGCv4GDFIMPBggoE4A2CCoIuCAweAAwc/BghYBMwswNw0PNwkBGAIbEG4gMCOoYMCOoQMDAwRnE4BYDKYQTEKYRuCKYY8GgCjDAAV+LAtgcTMDbYhTCHobICBwbBDBghZDZwmAZoYGCAogGBCYgiBEIidCBwQ2DS4QMCVYT2CSAb2DBoLpFn72EdJAA=="); +katakana['MU'] = image(59, 54, "AAMDwAHFv/AAwkf/gVF/4VG8AGEh4VHFgoVPFdZBdRogVBgP4CokBFogVBn/wTIkHEwYrCv4ODCoMP/wVDFIP/JYQVCBwgVBGYLICCoTIDCoQCBBwQhCn5RCCoR/DNoZCDDIRRDCoQODg4+CIQYvGCoZCCCoZRDAQV//4SBRAM//4ABwEfAgQAB/ARBAAkPAwvxAwv+Dgv/8YGF/gkD/xCB543DH4P5AoaBBewsAvgGFhgGFAAQ="); +katakana['ME'] = image(55, 54, "AAcB8AGEgf/AwkP/wGEj/8Awk/+AGEv4iF//AFAuAAwcHFAsPFA34AYNwFAQvBgICCFAUHCAIoDDwQoDn4DBKIf/MYIoCDwIGB/5RBAwWDKIYGB456Dv//75RDAwP/JQQmBAwJ6Dj4GBOYYGCOYcP/5zEg//OYgGNDYw3BAwgvBAwaABAwgaBOARZC/wGDOoP8MQI1D+AGDFwPAAwJaBDAQNCJIc/AQJsBTYL3COQc/4ATBXoYdCSgU8J4SNCmCNCNQqoDAwQuBAwgFDFAITEAwK1DAAKZEAAIMFAA4="); +katakana['MO'] = image(55, 49, "j//AAfAv4GFAon/wIGFgYFE/0HAwn8h4GE/AvF8A4Bv4DCAAQzBAocB/+AAwYxBCYkH/wGEh/8MIv4Awk/+AGEGyJfFAFP9AwpOBNuikeAwxfEHoLpFNoZACAwZABIgIACJYYABIAYGCIAYwCHIoABA="); +katakana['NA'] = image(57, 55, "AAV/8AGEn/wAwkf/AGEh/8AwkH/wGEgf/AwkB/+AA4n/4A4rGoIAE/IGF/wGF/9/Awu/AwvfAwvvAwv3AwpQCOOqqEWLV/H4pGGn5GFAw0fJosfJooGGn4GGKgq6BLQoGEg4GFh4GFPoIpEDYIwFv5MFLQ4GFg6EFgaZFAAw"); +katakana['NI'] = image(56, 43, "h//AAf4A25+/AH4AuWggA5A="); +katakana['NU'] = image(55, 51, "g//AAcAh4GFj4FD/0An4GD/kAv4GD/EADQnwgIGE8EDAwnAAwuAIIgvBAAcPF4IADn4vBAAd/8AGEFAIDBAQIsBFAMDCAIoDh4eBj4oCj4GBFAd/CIJRBgBZCAQIlD/+HQIIGD54oCNwZKDPQZPDOYRdDOYqmBOYi0BOYjCBBogGGYQSAEAwimDGATdDAwQTBH4JFBLIP8AwYTB+AqBAwITB4AGBE4bADBIJyBUIJ6CVgXgJAQzBg+BAoJkCgxcBCYRIEPArlEH4YGDO4ibBeQs+AokAsAGF"); +katakana['NE'] = image(61, 55, "AAX/4AGEg/+Bws/+AGEgP/wAHEh/8Cwt/8AGEgf/Bwsf/AMEAAYnBj4GDHwQOEDAMHA4hVBn4WFJIIADHwMPA4hgCAwZkFCQKCGBwpHBPQwOFFAJyGBwt/BwozBBwpwDGYiYEEgP+iAkF4IPDCoP8j7WCUAXhbwYVB/4RBU4n4QISfD54vBS4f+FASPD+AEB+AFB/IjBFIPnA4LzCGAfAeYIjBGAP4eYQCBwZuBeYUH/EfIwJRCAoIDBg6ACnCmDR4oqBDIKfEHgKuFS4g5CBwo8CWwqOCAAQ8DcYg8Vn48FAAo="); +katakana['NO'] = image(47, 52, "AAcHAokP/gFDj/4Aod/+AFD//gAgUB//AAoUD/4oE/woJn4oLEQYoBwAoIh4oEj4oFJZ8HERU/EQhFEDgIiDH4JFDh4iEH4t/NAYcFHII/Dj4cEv4/DCwIcDCwIcDCwI5DCwhEBHIYQBKwf/GYYhBCwc/FoYKBFoYEBFoQKCE4RrBE4YFCHwQyBHAYnBJ4YFBcBN/AgcAPgYABA="); +katakana['HA'] = image(62, 52, "AAP/wEH/gGCgf/gE/+AHCh4MB//AA4QMBCIQeD4ARCDwv4Dwt/8AeEgI4BDwkH/weFj4eEAgIeF8AeEAgQeEAgQeEAgQeEAgQeGMggeCMggeCQYiACQYYbCDwgbCIogbCIoZZDIoYTCMggTCEwn/CYJFDBYZFDBYYmDv4LBEwYDDg4aCh5JCDQYiDaIQWBNAQ5CMAYLDcgYmCCwgqCGIYTBFwL7EJIIWEAgPgh4WDNAPACwgMBCwiHB/wWEFwV/CwZVB/YWEDgPHXgYuBDwLbDKQPwh60CGwWAngGDgAFBkAHEsAFEAAQA=="); +katakana['HI'] = image(47, 51, "//AAgUB/+AAoUD/4QDg/+AocP/gFDj/4Aoc/+AFDv/gFw8BwIuDj+DFwf/FwcP/4uD///FwQKB/wuBJwIFBFwM/AoP8//PAgP/+IDCAAJdBAAXwg4FDEoQKCIIIgCLoQFBKYV//5qDB4aMuF1YFDFwIRDUIQAC+YFE8YFE44FEw4FEUgn+Aon8WwhKBXggA="); +katakana['HU'] = image(49, 50, "/4AEv4FE34FE74FE94FE+4FE/YFE/oFE/w0Dg//AocD/+AAoUB//AI4ngAod/+AFDn4FEj/4Aon8AocPAokHHgg2BHhYFDHgJCLJBZCEAopIFAoxIEAoxOEApc/AojSBbwplEAoZxBAocPAojICBQhBCGYIFDBYRZCa4P/NYQuCPoYFBSoZGFZYsPAgYABA="); +katakana['HE'] = image(61, 43, "AAMH8AHF/4HFh//wAOF/wOG/AHEv4eFg//DwoOBDwgOCDwk//YeEgf/x4eEn/8n4eDgP/4AeEj/8DAIeCBwPgLgkfDYIeECYQeDh4LBIwIeC//wDIIeCBYJdCDwV/BwIwBDwIOBCQYeBn4pCDwRIBIAQeCMIJPD/AOB4CED4BhBMwf/MISbD/kHPovwj4ODDwV/UYhYBKQJ2DRoIGDHQINEcARCCWYgGEDwIOFgb+FDwL2EDwQGFIQoeCBw0YA40AA=="); +katakana['HO'] = image(61, 54, "AAV/8AGEgf/Bwsf/AHF//AAwkH/wOFn/wAwkB/+AA4kP/g8Rg//AAngv4HFCYIAE/EfA4vAAwv+Eo3wn4HFwAGFJwZ5UgfAPIJzDn/x/+PEgR/BAoJzDP4N/8JzD//D/6KDFYI8BCwYrCCAItBPQOH/wWDCgIQBCwf/4P/wIWCCQIBDWgYBCZ4KJBE4LPDEYInBh5sBBgKLBNgQ0CJoIWB4ACCBgIiBBwP8EYU/TQLXBHQQECFAI8BCwIqB8DzCDYMPAgQbCMoI3BF4IRB44OBWwQUBv4TBJIV//InBHgQCBw4OBHgUH/EfNgKOCj0A3BsCQwNgeaSdCABA="); +katakana['N'] = image(54, 50, "ggGFngFEgP+AwkPAws/AwkB/4GEh4GFn4Gaj///gNF/AGF4BEJAwITBgOAAwQTBh4GCnwJCCgVwLgRwMHAgTBHAgTGv4TEgYTFMIITEMAsHMBY0B+ClFCYiPFEAITEv//OIQMCTg3gBgggEDIIgDGYIgDMIJVDDAIABIIILCFoYYCJwZ0BHQgsBBgZnBBggnCKgYhBMIi3FgAFFgAA=="); +katakana['WA'] = image(51, 50, "/4Ay4A3E/AFCh4GBAoUBAoPgAwU///8AoUHBgOAD4nwAoUf//+AoUDGRYSBGQYSCGQd/94yDh/9GQZFB34yDn/zGQcPAgYSCG4YSBC4YSNv4SKJYJwDLwISEn5QDS4QSDDAJjDDAJ2DGIJ2DUYQ+DQYKcFFYYXBDASOCGIQFDGIQRCDwTaCG4YFBEgbHHN4hiFg6HEA="); +katakana['WO'] = image(50, 52, "/4AE34FE94FE/YFE/wYYGocB/+AAwd/8AFDn/4AocP/gFDgf/KovADAnwDB43B45EE+IFE/F/KAkfBgmHAonhAonwDAn8h4MEN5X/N4l/N4k/KwkfRwgoBDwcHOohoBOoYFBEgY2BEgYFBEgYFBJIYXBFQYpBFQZ3CAoIWCKoQQCGwQLDHgR8CAoQdCAoQvCOYYFFn5gENgKREbYgAGA"); +katakana['RA'] = image(51, 50, "n//AAcHAongAon8j4GEwYFE+F/Aof+h4ME4IFE/BYr+4FE/wFE//fAon7BgpYE//vAon9CQo3Ev/gAocP/gFDgP/wASX+ASJgYSFXwJ2ECQivBDAoSEWIs//wFDbYIrDAoI+DAoIYDQ4IYCFIIABDALlDGIJhBewS/EJQQYCG4YkED4QFDD4JJF4AFDA"); +katakana['RI'] = image(43, 53, "AAf/7/4AgMf/f/AgMD/9/8AFBv/v/gEBh/9/+AgEB/+/+AKBn/3/wEBg/+//AFX4q3v4qDh/8FQQPBz4PDAYQvBEYQvCEYI/CGYRPBB4cfIYQpBB4cH/5TCDwJjD/4kCn4EBCgN/AgIUBDoP/FIJHBAAIyCDIYjBIYYaBQ4QaBJoZHDAAoA="); +katakana['RU'] = image(61, 53, "AAUH/wHFn/wAgUB/+B/+AA4UP/gBBCgd/8ABBAwUD/4BBBwcf/ABBA4f/4ABBHQg8FHQI8/HksYHgwYBHgkPF4I8EvwlCHwOAg4gBEYI8CCIQjBHgITBCIP+HgU/CwIRBDAIgB4AMCAgMfEAIMBDAIOCBgQYCIwQMCPYJTBAQI8BBwUHEoN/8P/IYN/+AvBj4LBBwOAj/7BwZGB/4ABBwXAAQIODM4QOFHgIOC/4OBh4OCAYJGBv4OCn4OBHgJKBAYJkBIQISBaIYhCCwIOBSoTqBJQISBeYUHd4U+bYUwcAYAKA"); +katakana['RE'] = image(51, 51, "//AAocf/AFDgf/CQl/8AFDh/8AocB/+AAwc/+AFDg/+GX4ECgwyEgPgGQk+GQkP+IyDC4IyE//3GQc//gyDh//GQYYB8YyD//4GQc//wyDDAOBGQUH//gGQRvB/BlD/4DBGQU/CwIyCj4YBMoQkBBIIyBBAIYBGQIkBDAIDBGgIiD+AFBGoIyBv4eCGQIABJwQvBAAJnDEgTLCEgY8CIYLLDEgZVCAoZuBb4iaBfAj+EgE4AokAA"); +katakana['RO'] = image(50, 47, "/4AEn4FE94FE/YFE/wYF34YS4A1BgIYB+A8Cv/v/gFCj4YBAoUHDH4Y/DEbglDBQ8CAAYA=="); +katakana['YU'] = image(59, 46, "gP/AAX+A4M/A4fggEHAwf8BwIGD/4GBj4VFgYVGv4HDwEAh4GD+A+Eg46CAAf/4AGEj/4Coo6CCqJFBCot/KAIADh5QCQAhQBCrM/Myk/M3JQGh5QFMyIRBAH6NB"); +katakana['YO'] = image(50, 49, "v//AAefAonnAon5Aon+DDA1DgP/wA8E8AFDj/4AocHDFZjfDCJjxDD5WE/+/AonvAon7PgoYX/g3DAAQ"); +hiragana['A'] = image(52, 50, "gEB/wGEn/AAocD/gMcg//AAfgv4FD/wMYFIRNa54HDgYyCBgYsEBgX/+AGBHQYpBCQQaCh4JBJQPwgIdBBAP/wASB4H/j/8MIP8j5fBBIP/4P8gf+j/7/hVBj/jA4PH/C/Bn4RBv8Aj/3/Ef55FB/9/wI+D+/wj40BHwIWBL4QJB+BFBwAmB/4MBD4M/94MBD4JAB/4cBNYN/BgM//AsB/n/z4bBQgOHX4QVB/B3B/CQCAQTSC8BFCB4Q4CB4UAgIIBRQOAXojREn/gaIgAC"); +hiragana['I'] = image(58, 50, "v/gAgUggEf/AGCnkAg/+AwU/gEB/+AAwQZBDgcP/gcECQIcFCQIJCCol/4AGBgYLBj/wCokHCAIABFAIQCCon/DgQECn4cDCoItCAAI+BDggVCLoZeB+BgCCocPPQZUBwZdDJAQcEGAIcEGAIcEGQPDDghIBDggyBDggyBx4cBjxIC8aaCCAIyBLAMDM4IyBSARnC//HUIk/+IyBCASdBLAJKCGQOf/kDJQV/GQRKCJ4XgEYRPC/CoCDgOHNwl/8P/84jCDgM//5HCDgMHAwIjBgP8DwIsBQgYVBSQgVBaYZnCTIgtBbQhDCUAYkCfwYOCGIgAHA"); +hiragana['U'] = image(46, 50, "h//Aoc////8AFBAgIABgEDAofACwIAB/wWD//4CwgdBCIeAFQUfCwIADCwIAMj//+AEBv4tDAgQLBHAYFBAgf/8YFE54FECwRTB/wkCAoP7IAd/OgR2CKwcBQ4kH/hMEJYQcC4AWIh4WEn4tJg6EEj6EEVgIQDE4l/CAbABCAZqBBQgQDBQIQCXwIyCYYTIFeIhlCBQjxCLIQWBMgbdFvzYJ"); +hiragana['E'] = image(55, 50, "gF//4GE/4AB+AFBgIGC/+AgEDAwYNBg4FC/wGBh4GC/gGF/ArFFIQAD4BRVn42FLAIGEJQYGBLAhEBLAhEBLAf/8ArDBIIyEj5fCRYZYEEgJYEN4JNFDQouFDQKcBFwYGFMIIGDLQRJFAwgaBOYQuC8Y2DFwODAwcP/0HXAc//EPcQnAj5LCPAU/MwR4Cv5ECPAQ9CLoUBd4auE/guBVwf5PARaC+5qCAwXnJwSXB//HI4QGCw5ACAwUHNIn+gj/HAAg"); +hiragana['O'] = image(54, 50, "gEB/0AggGCg/4gE8AwUf8EA/gGCv+AB4QaDv/wDQn/CwIaCgP/4AaDgf/wAaCgPn/4PBAAXv/0HAwef/kfAoX+n/4v4GCAgPxCYfg/4jBAAWBGwQ1BgEDJoJQCJoJRBLYcPCAJrCgEcKAaGEHgSGDF4QPCJYYxCHoYMBn5YDBgoGBDIP8FQKiBDwabBFoIzCv/gEAJQCMwWfKAIbBh58BDQMH/l/4IaCh/xTgIaCn/P/BrD/8/4CGD/i3BDQfz/gaDv/P+AaCCAIaEHQQaDv/hGoV4h//g4VB8JnBa4ePZYRkBBwKNCbwPwCYR/C44CB4BtBfgSaD8ACBYQQWBAAYA=="); +hiragana['KA'] = image(55, 49, "gEH/AGEh/wAwkf8AGEn/AAwl/wEAhgGC/4CBngCBgP+AQP8AwMDAYIyDAYUPAwQ2CAwY2Cj/4gP/AAP4j/wgYGC/gGBg4GC/0/8EPAwsfCgd/4E/Awt/FIf/LgJmBE4IGCMwMf8JjBHwIPB4IDBgZmBv+DAYMHMwP/BQRfBOwIKCL4J2BOIQvBAgJxCGQIEBHAKPCCwIYDCwQBBQoRGBviIDIQJRC4AdCXAYdCKIcHboQ/CboY4BboghBboZKCFAYhBjAoDh/8nzME+CfBF4V/RgP/EgKVBwYGBFAMH/zIBFAQeBAwIoDboRRD4DrBJQUHAQJsDAAwA="); +hiragana['KI'] = image(48, 50, "AAMB+AFDh4FL/AFDg4FIn//AAX4ArpHC/xNEAov/LQgFCDgYAlF4UfPx8/g/8CoQbBKgQhCAoMDFAkHAoeAh4FEDgQAB4E/FgIUBwE/HwQdBn/gAoM+AoPAAoMMAohFCAqIpCgI7C4BEBI4oICAoZfE4C9BAob2EAoISCaQgACA="); +hiragana['KU'] = image(33, 45, "AAsB4ADC+ADC/wDBgf/wADMg//CYIDDh4DDD4UfAY/8AY34AZRDCh4DCg4DCgYbCgI/CgH/BgU/BgREBBgIQB8AMCFIRNDLoJ2Cv42DJwQdDFQIdDFQQdDFQIdDHYRkDgYhCgADDnwDChyzE"); +hiragana['KE'] = image(50, 49, "AAUB/0Ag/gAwN/wAICgEfBIIIBB4P4BAYPCh/wDAcD/gYE/4FBDAU/4AYEGIgOCDAQOBh//AAP+v+DAoX/7/AAof3+E/AoX9/gYD/9/gYFD/4YE/5QCGIJQDHYRvCJQU/N4JKCKAYYCKAQYWmAYEjwYEx6lDh/zUocDMgIYDv6cBKgUf/4yBBAMH/4eC4EBNQUfAQN/DYMPE4TjCAQQkCYgSJBDYLEBn7QCAQIbCE4UDDYP/PIV/CgLpD4EPP4UH+AkBAoIACCgIADh6LCAAMDAoYA=="); +hiragana['KO'] = image(52, 50, "h//AAX+gAFD//gBgn/BgvwBiWAAon4GwUBDIQACCQQFCn//4AFCg4lBCQc/DwYfBKQJdEDwYAB8CIihAFEgJJDIgQFEg5KEMgITEj/8D4hwED4JqEOIIfEv5eEg4fEFg0PHIwsEBigmFCYkOv65CJYPnbgn+ZgIAD8IMFewvgCYjRBE4IMDegQABIoUfAoK7HA=="); +hiragana['SA'] = image(51, 50, "AAMB/gFE/+AAwcf+AFDgf+DIl/4AFDg4fEgAfLgIfCj//AFQzCn/gLJYMELI5mEh6GGBgUHGAP4CAQ3COYILCBgUDIgYZBAoYmBn5REDwPgQQPgDAIVBj4fBJ4d+CQI1CgeAXhgSDKoYSEQQp1GQQpFBawXwD4IGBg42BaQngBgRlDBgmABgjzBRYZDCPIYvCv//MQoACA=="); +hiragana['SI'] = image(45, 50, "v/AAgUD/wKDj/wAof/wAECg/8BQc/8AbD/4bE/AbEFgcHFgk/FgcBFgkPDYhIgFgIKDFh8eFgn+FgcH/4sDv+/FgUD/osDn/vFgQ2BFgcf+YsD/+fFgUP/gsDv/HFgSKBLId/8IsCHgIXBSod/EIIKBwIhCv/4h4WBAQOAv/+IIP8AQIAC4AYBAAIkBn4KDJQIKDCwYpBCwRWCAoJhDAoK1DAAg="); +hiragana['SU'] = image(52, 50, "AAUf8AFDgP+BjH/AYP/AAnvAon+BjJAUgf9BgZFB/4MDn4kEg4MFGIwMED4QME+E/+AyC/x0DFgPABwIMC/gMGDIn8gYMFv/4EwcP/+AKYf/BgRACBgYRB/4mCgF/AwJ6DBgoTCRohNDTZE/VAkP/gFDE4PAUQhGCI4YeEUIgYBD4gMBEpI4GgIFEAAo"); +hiragana['SE'] = image(56, 50, "AAcP/ADB//AAwP8AwkHA34FBAAn+A1JalmAGFvinFv4GF//PXghEBAwfBAwoNGEQP/+AGDn4GFh//8AGDg5PCgF/AYP/wAGEgj/CAwQADAw4mCAwZCCAAQ8BFQgGBAAQGBj4GFJQIGEJQIGEgYGFGIIGCIQQVDHQgACA"); +hiragana['SO'] = image(53, 50, "gP/AAXggEPAweAgF/AoX+gEDBgfwgEfCYoFD/EAg4MFAAQMCAAQwBBhQpBJQozBAAU/IAIACIYJUBAAV//gsJD4IsEn4sEOAn+NIn/+4FEAA39AwvvAwqQDAAP7UYhmCx5bDuBVB4BCDg5bEJ4JoEgJ1EEQKCESwIFEg5vEEA4TFh4TFv4TGYgiLBCYrFG/5dDd4YHCOQKkBDQjbDDQQwDWgR5DAwSGEEAgAEA=="); +hiragana['TA'] = image(52, 50, "gEP+AGE/4Mjgf/AAXAgE/AoX8BjUAgP+GYkf8AFDBhHnEIQMBEQQhBn/jFAWAgYMD/AMH/gMF4f/F4UH/kQGYd/KIIACg4VBBgmAQ4gMFUJcB/8DDQZgBv6iD/wuEn/gKIJGDEIl/4KCDC4KPE/+BBgYXBBgY5BAIImCj4MBTIKFB/wMBAAKSB8EPAwXnUYIMDCwLYD95RBEAIZCFQN/AwPBKISpBwEGQAgAGA=="); +hiragana['TI'] = image(51, 49, "gED/wGEv/AAocP/AFDgP/CQk/8AFDg/8Bgn/wAFDj/wBQYAqJ4M/LBZrMJYZ+Ch5aDv/f/4bCBQIABCoMDHAYTBv4+Ej4MEg4DB4IMCAoIcCwE/TwU/+ASBEQI8BVQJLCv/gS4cP/kBMgYWBjyoEgLbJEYYSCQQkHCQg2EHASCEv4SBgYOBOQ70BQoYrBEQIABFYR/DJASRED4YFCBgJDDA="); +hiragana['TU'] = image(59, 45, "AAUP/4FFAAIGCAoX//EAg4GD//ACYYAB/kBAwgOBn4OFDgoOBAYX+BYP8j4GBwEAAgPDGwQ+C/F/BgIABCwOMLQl/+AGEg/+NIv/8BwF/gGEKwIqDAAM/HAYzDEhkfEgsDEgxJGh5JFHQPACqQrBCpkfCopXBCogcBCog5BK4jSCAwxtDDYK8EZIQcCAoQcDCYTjCJgQGCEYT0DIAYGGEgQGDEgRcEv5UEA="); +hiragana['TE'] = image(57, 50, "/4AFv4GF34GF74GF94GF+4GF/YGF/oGF/w7Cn//4BCDAwOAAwpQEj4ZDAxP8AyUPAwwiFg4GMgZFFAw0BLQqlBNAkAv4GG8AGEn/wKgv4KhZGGHALeGH4oxNh4xFOJBjGEYt/VQwVFg//BwhOBAAI7Dv4GBHYYcBCwgcB/5CEDgQyFGYgrCUwkPKAwAC"); +hiragana['TO'] = image(46, 49, "gEH/AFDj/wAod/4AECgP/Cwn8C0cICwcDBoIWC/4NBCwMfEgV/4f/BoIWBv//LAMH/4AB8AWBAoWAgE/BQYlBDYUAh4FBHwQPEEIJQDFYJhCgYwCLQQqCDYQKDDYIKDn5xEEAYQB/x8JDYkDCAkPYIk/JoQWTAol/AocZQwR6B8aNCAAOPAgf+TIZqBAongT4QfCBYY9BW4R1BA="); +hiragana['NA'] = image(55, 50, "AAd/wEAn4CBgH/BIXAgEB/wJEgf8AQIJCg/4AQIJBgEP+ACBBIMAj/gAQYsBEoIoCGwf/GwkB/8P/4AC4f+j4GDw/4n4GDj/wv4FC/0/8AMD/l/4IGD/H/wYGD+P/g4vELARtCMQRtDMQQKDL4YKCMQQKDMQQKDR4QKCTIYKCFYQ2bOoI2C4BgCGwWASAQ2BGQKJC8DNBBAIAB+DNBPYf4ZoKrDAgPwT4K7BAwRdBB4K3BVYIqCVYY6BAwKrB/0DVY3+v/hAwf8n4SBdIXwnxEBAwXgnBEBAwShBO4IbBSYSVCOYQAHA"); +hiragana['NI'] = image(57, 50, "AAMPwAGE//gAocf//wgFwgEH////kH/AZBAwP+gf+Bof/wP/gEDAwWAAIMBAwc/FgIGDj4sBv4GBE4P8HAIdBE4IqBAwYgBKAIGCKAYKBAwN/EYIGDn4jBAwZfBDAQfBLIPAAwZZBDgItENYN/CAIfBIAIGCLIRfDLIXwAwc/RQJmCHAPv/0PEoI4B+f/AwcH/P/w50D/l/wZ0CgP+j/BK4Q4Bg/gJoQ4BwIGBIwU/4EwAQI4CIYICCAYY/EJQMHHATcCbAQKEHARGBGgQqBCIc/D4IGDaITCDT4PAAQJfCQQRYDeQQGDSIIGEYYIGEE4IGEDgYFCcAQ+CGQZsCABAA="); +hiragana['NU'] = image(58, 50, "gEP/AGEgf//wHE/4ABAwc/AwIPDh4OC8AGBg4GCEwUBAwX8Dod/EgoHC4AsF+BJFjAGDg4iEFgRfF/+AAwk/IwQjDFIgjDvAjDMYJlCgRHB4ABBFIUf/ABBFIXH/0HCoUf+BcBLwQpBCogpBCYIVDv+ACohNBn/wCoRxBCohNCMoIVBOIQVBAIJNCCAIVCEYIQBCoOAb4QtDCAQtC/gjCdIIXCN4QwBC4SVBDQIXBEYUP/gXBI4QEBHwPD/8ODgR/CwZNCCYN/8P/5/4GQOf+DtBKgXv/jtBKgX5/0PAwJxB/0/DAL8CvkDJYP/IYMMgFgg//fot/VYQACgYGFAAoA=="); +hiragana['NE'] = image(67, 45, "AAXwA43/4AHFn/8A4sPCA0B//+CAt///gA4kfCA0H/4QGA4IyFn4IBGQg5BIYsD//nCAt//F/CAkf/wzBCAYFBwH//BaE8ArBwBzFCAgNBLoQQCHIPADYIQD/6dBCAk/OQIQEHIQQEHIQkCCARaBO4YUCSYQQDHIQQFHIQQERQgQCLQQQEHIKBDCAPAn5fDCAP8gbNECAaJDCAbVECAPgvj+Gg72GdoqYFCAgHFKIoQDDA0AKIjODDA0ARYQAEhwHGAAIA=="); +hiragana['NO'] = image(54, 50, "h4GFn+AAocB/0IAwcH/F//4AB+Ef8IFC//A/+PAwcD/0fAoX8h/wDQk/4ITDAgMDAwcH/hGC/EAj/wIwXggF/4AGB/+AJIIFBGQJJCDQoWBDQf/wZlBDQIWBh41Dx5kE/0/Mgn4IgIGD8f8MgYaBL4IaEPQJrD/6RCGoRkCKAR/BKAgaBKAoaFNYoWCKIIaC8BKCDQWAIYQaCgJCCDQRyDDQRXDEoOBK4ahBW4K+CAgKcBDgLcBMwIwC/1/4JHBCYP5CoQwC4aND/atBRofDAgPgdQaSBHgX4hxXBHQXAhAOBAwKXCAAJlBbIIAH"); +hiragana['HA'] = image(50, 50, "AAMH/gFDgP/Bgl/4AFDj/wDBsH/4AD/oFE/9/AwoARJVXhAon4JQn+j4MEw4YLn4YEJTIfCAooYCAoX4DgQwCwBdEBgMDHoYMB//3Bgd/8AUC4A7BJQP//kHBwQGB4JYBFoX8KgMP/gGBz/+h//AIPjGAXA//wAoXwh/4DgX4gP8IgQnCF4QFBgOAEIKIEv6SCAA4A=="); +hiragana['HI'] = image(59, 50, "gP/AAOAA4U/AwPwAwUHAwP+CwYVC4AGCj4GB/AGCgYOCCod/AwPgGokH/g8GHQY8CHQYVCHQg8CwEfCAYEBgYQDAgV/JYYEBh5LDj/4GoJKEGoJLCAwP4JYZ9C/BLCNwSGDQgSGDOoaGDAwg6BEYQHDh//EomDAIP+ToaQBEIIvCKoJyCJgPH/yDCEIIVB4BNBMwIgB+CZCn/n4f+h5jBAQMw/+BOgKyCCoN/PIICBS4I0BCoQJBJQJqCBIP5NQfgD4KACn5tDGQSDEwADBTIJaBGQKZEDISvCToR8BeAQDBAQLbCb4RSCAAcHcQYACvwGFg45BAAj/DAAw="); +hiragana['HU'] = image(55, 50, "gED/gGEg/4AwkP+EAhwGCj/ggF+AwU/4EB/wGCv+Ag4GD/4kBAwM//4AB84GBv4GC54GBAoX/x/+gIGDh/+gYFC/0P/kHAwX8AwMPAwX4j5cCGwJOBAwJIDj5jBv4QCAwIpBNoU/+AiBNoIGCJYJtBAwPhFwPANQXjAwOAgEEv+P/A2C/H+CoI2BTIIhBwY2Bh/xwH+UgUf+CwBUgSgBBYKkCn/gh/gToI1B4Ef4AvCBIM/4ZmCIAN/44oBSgKdCFAJ3CLAY0BUgQoBGgIGBEIUPAwSID+AGBQIZHBJQRECd4Q9DI4QvBJwQ2Cj4sBGATRBJwLcDFgTcDC4QGEEILqEAwIbDIARoCBgQAGA="); +hiragana['HE'] = image(55, 50, "AAUf+AGEn/gAwl/4AECBQP/wAYC4EB/4YDwED/wYDwEH/gGCCIMP/AFBgIRBGwcDCIN/GwUH/EP/4bCDAP/AAI2C+4GCHwMfAoX/JgM/AwYjBv4GI8YGCFoN/wIGBgYCBFwIiBHYJfBNAPAn/8IwIGBwAaBh/wAwOD//4R4IfBg//+B2BDoJKB+AoBg/+JQPjOwMP/n/z/nQIMf/IOB76BBn/3/gVBMgN/94nBOQX/7/gAwKbBOwSOCHoJMCEIMH/v/CAJxBh/7/hcCF4X4KYLEC5/wj5KBEIOfGwJRCL4PzF4V/JIQvBCYJJCH4JxB4AGB/xCCFQIJDDoIMBBIRNBAQJdCIwKUCeAb5CPgQACSgIFDSgIFEAAg="); +hiragana['HO'] = image(51, 50, "AAN+AokP+AFDgf+Bgl/4ASE/ASVv//AAX8h4FD/+BAonwn4FD/0HBgnAAogoBgP/HAk/8AFDg5LEgASM/gSFwADBFQIAC8E4Iof+/5FE5/wAof5/0fAwc/8YFD8f8PAYEB54MDJ4SRDJ4KRDj/gNYaoCLAYWBLAYWCLAQWCDYJvDgYSCCwV/NYQWBGQc/+AyDg4yBj4MBgYSBAQP4OwPwbIglBQAgpBBgZiBBgYYBBgY1CU4S0DFoIRCAAo="); +hiragana['MA'] = image(55, 49, "gEP+AGEj/gAwk/4EAkAGCv+AgAPD/8AgYdCgP+EgkD/gdB/AGBg4DBv4GCj/w/wGCv////8AwQFB//4AwMBAwXwEQMDAwXgAwMHAwXAAwMPAwWAG4QvBLgQGBL4X/AwRfBKgIGCL4X8n/gLARUBn5YDMwM8NQaLBQYIoCAQSIDAQRZBRYaBDRYQhBFAIJCKIYyCDwKoBToZkBOAIJBPYKLCGwMH/h2CAwMfKoKKCI4PgSIYYB4afDJQMP/gpB+AhBMgIjB/AhC4EfAwIhCEoIGCwJdBaIIZBMgSkCjhMBgakBG4LICUgKDBAwQuBPgRKCjgGE4EQAwgEBAAIbBRAQACQgIDB"); +hiragana['MI'] = image(50, 50, "h+AAocD/gFDgP/CQl/4AFDn/gv//AAOP/E/AoXj/0HAoX4/+BAoX+DAuf+EfAoXn/gYD/P/gYEBG48f+AFDg5QMMYkf8BvE/BvE/wYE/4YEKAIYYgZSCDAMBJgQYCCgYDBFoYDBj4tCDAJlDDAMBGYYYBNYYYBn4xCg/4h6ECPgIHBPgfBDwaVBQgYvBToYYCFYauBaIIwB5/wcAfz/0PAoX8cAn/IgQFC55dBAoXxFILtC/grBGgL5BYIoAGA=="); +hiragana['MU'] = image(58, 50, "AAV/4AGEj/wAwkH/gGEgP/Aod+Dgv/wAcEj/gDgkH/AcEgP+Dgt/Dg3wn4mBHwYGBDAIyCAwP/8AGBAoQODh4GC/4sBgYGD/AcCAAO/IQQcC4IkCDgI7Bj5YBg//w/8EAIjCwIEBv/gMQPgLAMPFYP//h1BgZpC/4LCNwIxB4YoBFoIxB/AjBNIMH/v+n5UB/4qBn/fIoIJBv+PLYUPQwPhOIUD/gvBGYMH/3/BAX/457CBAP/84GBDgIlB/YGBCYJwB/qECDgKREwBCC34YBDgfvLYP+HIM/+YYCIwM/MoIYB/hGBMoQEBz4nBKQfDAwODGQXwKQQMB/P4j4GBAQP+ngtBUgIRBg6aBRwKiBwOAf4TNBAobjCAogAEA"); +hiragana['ME'] = image(57, 50, "gEP+AGEg/4AwkD/gGEgP+Dgv/Awt/wAGEn/Agf/BIUf8EP/40CHAMf/4tBAYP4AQImBCIP8n4GB4EH//+AwXgEwP/v4CB/EBAYIPBg4jBAwX8BYJFBCQRKDFYIGBJQJxBIgUfAQIrBAYMPCAIfBBQR8CAwR8DMAZ8Cv4GCGIQGDGIU/AwR8BAwKqCWoU/FoS1Cj4tCHASEBWogGBUAQKBAwItBHARpB8BlBBQKuCAQIKBO4SqCBQX8AwX4h/9/wGC/kP/n/DYSlCv+P/ArB4K+B4/4SIV+j/jWIX8n0P+JSBDoMOMwJWBAwOCMwM//ZOCMwI4C75nB/5bC45nBv+DAwPhTgXAb4PAoCfCQQifBYoYAHA"); +hiragana['MO'] = image(60, 50, "AAX//4GEv4HFj4GB/wGCg4GB//4AwMBAwX/4AcEDwcPAwYWBgYGDCwQVC54tCCoX8F4PgFYP4CYI+BgE//0P/gaB/ARB4F/4ApBwAVBg4OBj/8EgITB4AiB4InBBwQgBCAIOCPQPjD4MPJ4MH/0/+ALBwARB84kBBwQ0Bv/gBwc/+5bBj5tEHAR8Bn5lBBwInBBxY2CBwcDWIQOEGwIODJwIOFIoRKC4CNCBQP3AgKwCDIIOBKIQKB8/8IQJgBj4OB8E/MAfD/ytBEgX8J4KeBZwWDIgJCBCoP4ZgIzCAYIqBeYRQB8DnCK4gGBGoIDBwAyBF4IKCCQWBAwIVBEoPgF4RFBg/4F4Q2BAAQOBTwIADHoQADbIQAIA"); +hiragana['YA'] = image(54, 50, "gEf+AGEv/AAocB/4MEg/8DUv///Aj//wEDAwIcBAwMP//8BgIGBn//+IFBAwICB54GCDQQAC/0HAgXAn45BD4IDBn45Bv4MBAYPgGYJKCFAIbB8EAgf+DQRbEv/4LYYaBOQU/4EPCwIhCCYJrCgf8CYkP+BlBCYQaBv6GDOwQaECYIaEKwIaD4JWDgP+CYIaCg/4NQYTB8Z+BFwef+4aCMgN/74aCn/z/zXCIAOH/IaCh5CB44aBJoU+a4QyBwFwDQLGBCAOBX4adBGIJMBRIQaBUYI4CDQJnDFYJ7EDQKzCDQYECAA4"); +hiragana['YU'] = image(52, 49, "AAMf+AFDgP+Bgk/8AFDgYMM/gkD/4AC+EBAof/BkA5FhEAg45Cg/AgF/AQMBBIMP/4DB//gE4Xwn5dBn4GB74IBgY0Fv4FD8AfBAoYfB/gbBIAIiBg///A7B/+A/4rBCQIxBBAISB/ghBCQeBEoIMBCQI0BBgQSCDIYSB54MBgIlB+AMCj0H/0PBgIABHQQMBOgP4BgZBBBwTDCMYIMDKIIMRWQQmDAwUMYYqyBAoaxBN4IMEV4QMCcggMBWwbZCAweA"); +hiragana['YO'] = image(55, 50, "AAMHAwsP+AGEn/gAwl/4AFDgP/BgkD/whF/AGEj4oFEIsA/+AEIgoFg/8EIooFJQ3/JRcHJSgoGJQxEEg//FIkfAws/Cgv/AwUGJQX/HwMP8AoB74GBj/gh/+IoU/4BzBBQJBCJQIKBNQRzBv+AWoIIDJAP4SoMBIgIkBOYMDHoKTBAIIRBXgQBBB4IfBEIQYBFALgCCwMP/iVCJAXwJ4QfDcAX/4JRBSoRvBEIZ2DcAQGCFQIhBPoIYBcAQGBDAJqBCgQ6Bg7rIAAY="); +hiragana['RA'] = image(48, 50, "gEP4AFDj//wAFE/gFE/4TCn4FBBgQFCBgQRC//gBgN/BYUP/EBAog3BGIIFCgH/BAIFCh4FEgQFEBoXwAqsfAoIuBAoROBEwIFBIwP+AoPnLIWALwZfBNQf/+AFE/AFBEIM/AoR6Bh/8OoIzBg4FBRgQFCL4UD/wlBAoikCAoM/W4QFBj5dCAoMGAohpDg4FEHYJ1EAog5DDgJWCb4Y/Cg7RDaARFCAoZFBAobiEeoruCAoQtCAoI+DAAgA="); +hiragana['RI'] = image(40, 49, "ngEDn/AAg9/4Ef/AEBwF//4EBwP//4HBw4EB4F/x4EB8F/z4EB+H/n4EDAQIjBCwUPAgUAAgX+gEH/n//gEDHIMDAg3wAgP+AgvgAhBeBAhmAAiJ3BAhf8AgRUBAhBXBAAJtBAgSgCVgRcBAAJXCEwIEDj5SCBoJDCBAKSBBASSBXwKICAgQmCAgIcCv4SCAgI0DeAY="); +hiragana['RU'] = image(51, 50, "gf/AAXAgF/AoX8gEPBgeAgIFD/EAn4MEg4FD8EACQoACn4lBAAUf/4FDDYOAAoQuBHwIACv/wDwgkEh/+DwoFDDw5ECDwRLDMwg5BLIZMBNgh/FGgIeB+AVB4AeBEYJmBBAJQBDgPBOocf/AoCVIU/Kwc/+5WDg/+Kwl/5/wh4mBh/4/A2CFgMOAoJDC8GBMgUHGAJQCCQKpCBgISBgf+SQMPCQN/4H/4YSBGIIwBCgMBDoTMCn/AEIROCLoKFEAIJvBTwZvCTAarFNIQFCXASyCYoYxBAoYAEA="); +hiragana['RE'] = image(56, 50, "gEf8AGF+AGigP/wAGDg//GYQGBh//C4M/AYICB/AGDv///gGC+P/AwQKB+YGB/wNC+//w4GDBYMDAwn4AwQ3BFQIGF8AGF4AGFgAGEAYMDHwIGBAYIGDn5XBAwhlBAwd/Axh6CAwSPBAwMHAxEDAwqdBAwidDAw5IBOoQGDU4QGDUAIGE//fAwufCgrmCh4iCAwk4nwGE/EcAwbSBjAGFegReCUgIGJOYIUEQIYGCIYOAAwPgAwIAIA="); +hiragana['RO'] = image(50, 50, "AAf4gEB/4AC8EAv4FC/kAj4MDwEHAofwDAgSBDAoACn/+AocfAokP/4FDE4OAApED//AAohJBAAI5BAocAIQIFEHghFCD4QFCBoU/KIQMBNQZ9BOAhOCQYYFE/B8CE4QFBM4JGB4YuDj/7AocD/xIE/+fP4c/84FDh/8QoZyBj5mE4aFDn5yEDAIFDGIIFDIgIXDDwKREv4eEv4eBiAFCDwMH+A8BIQLnEEgLnDSooqBQYQFCDgQ2DAoolCJAgAD"); +hiragana['WA'] = image(51, 50, "AAV/4AFDh/4AocB/4DBj/ggE/AQMD/0Ag/8DgWAgH/AQMP+ASB//AgISBAoIDC4Ef///+ASBh4FB/4SBgYFC+E/4IFC/8H/F///9//g/8f/3/x/+j/nAQPwv/j/H/wf+I4N/KAJlBv+P9/4MoMP/f9/xlBAIIqBwAUBn/vFwIdBg40BNIIOBIIR7B+BbC8B7BKoX4uAyCAwM+GQX5//f8IyCn/z/hHCK4N/4/8h/8/4EB/4lBF4P/z5wB8f+RYJjBPoPAFwO/BQP4IQX/wJkCTAUfVYf4gf4BgS4BbQRiCcgbSCAAILEcALkCAAM/DoYeCC4ZLBfoIeD/ASEDAhoBAoYlBDwcAg/ABggAEA="); +hiragana['N'] = image(54, 50, "AAVgAYUP8EHwAGCv/Av4RD/8D/wFCgf8g/8DQf4j/4AwU/8E/+AaDwF//4VBgIfB/4GCD4MPAwcf+YFB/4jBn4FC/4jBAof/4AYC//n/+DBYeD/wZC/f/FgIrCGIQsCKYU/444CKYP/z4xCvxOBv+/8EBQQP4B4KFCCoJeCNIYPBQgQKBj53CAYSbBCYQDBHgJbCTYUDOQZHBM4QTBTYX/GQQxBP4Y8BDQRGBTYY4Eh5MDHgZTDAojdEbAYGEHgIGEv7/DHgIhFfAh1EEIg8GEIg8GTYYhDHhYAF"); /// ///////////////////////////////////////// -let kana = katakana.KI; +let kana = katakana.KA; let scroll = 0; -function drawWheel () { - if (scroll > 20 || scroll < -20) { - scroll = 0; - next(); - } -} let hiramode = false; let curkana = 'KA'; function next () { @@ -658,6 +124,19 @@ function next () { } curkana = 'KA'; kana = hiramode ? hiragana[curkana] : katakana[curkana]; + updateWatch(ohhmm); +} + +function randKana() { + try { + const keys = Object.keys(katakana); + const total = keys.length; + let index = 0 | (Math.random() * total); + curkana = keys[index]; + kana = hiramode ? hiragana[curkana] : katakana[curkana]; + } catch (e) { + randKana(); + } } function prev () { @@ -669,7 +148,6 @@ function prev () { curkana = oldk; kana = katakana[curkana]; return; - } else { } } oldk = k; @@ -677,37 +155,18 @@ function prev () { } curkana = oldk; kana = katakana[curkana]; + updateWatch(ohhmm); } const kanacolors = { A: [] }; -const clocktop = false; function updateWatch (hhmm) { - if (!hhmm) { - hhmm = ohhmm; - } + g.setFontAlign(-1, -1, 0); g.setBgColor(0, 0, 0); g.setColor(0, 0, 0); - if (false) { - g.fillRect(0, 0, g.getWidth(), g.getHeight()); - g.setColor(0.3, 0.3, 0.3); - g.setColor(1, 0, 0); - - g.fillRect(stripe_pos, 0, stripe_pos + stripe_width, h); - - g.fillRect(stripe2_pos, 0, stripe2_pos + stripe_width, h); - - for (i = 0; i < h; i += 8) { - g.setColor(0.15, 0.15, 0.15); - g.fillRect(0, i, g.getWidth(), i + 3); - g.setColor(0.4, 0.4, 0.4); - g.fillRect(stripe_pos, i, stripe_pos + stripe_width, i + 3); - g.fillRect(stripe2_pos, i, stripe2_pos + stripe_width, i + 3); - } - } else { var whitecolor = false; if (curkana.indexOf('A') != -1) { g.setColor(1, 0, 0); @@ -723,27 +182,15 @@ function updateWatch (hhmm) { g.setColor(0, 1, 1); } g.fillRect(0, 0, w, h); - } - // GOOD FONT SIZE g.setFont("Vector", 62); - g.setFont('Vector', 50); - const bignumbers = false; - if (bignumbers) { - g.setColor(1, 1, 1); - g.drawString(hhmm, 12, 12); - g.setColor(0, 0, 0); - g.drawString(hhmm, 10, 10); - } else { + g.setFont('Vector', 50); if (whitecolor) { g.setColor(0, 0, 0); } else { g.setColor(0.5, 0.5, 0.5); } - if (clocktop) { - x = 26; y = 26; - } else { - x = 26; y = h - 42; - } + x = 26; + y = h - 42; g.drawString(hhmm, x - 3, y - 3); if (whitecolor) { g.setColor(1, 1, 1); @@ -751,63 +198,60 @@ function updateWatch (hhmm) { g.setColor(0, 0, 0); } g.drawString(hhmm, x, y - 1); - } - // drawKana(hira_a, 0, 60); - drawKana(hiragana.KA, g.getWidth() / 6, 60); + + drawKana(4 + (g.getWidth() / 6), 60); + drawMonthDay(); Bangle.drawWidgets(); } -function drawKana (img, x, y) { + +function drawMonthDay() { + g.setFont('Vector', 20); + g.setColor(1,1,1); + g.setFontAlign(-1, -1, 0); + g.drawString(month, 4, 112); + g.setFontAlign(1, -1, 0); + g.drawString(day, w, 112); +} + +function getPhoneme(k) { + switch (k) { + case "TU": return "TSU"; + case "TI": return "CHI"; + case "SI": return "SHI"; + case "HU": return "FU"; + } + return k; +} + +function drawKana (x, y) { g.setColor(0, 0, 0); - - // g.fillRect(0,0,g.getWidth(), h); - if (clocktop) { - g.fillRect(0, h / 2.5, g.getWidth(), h); - } else { - g.fillRect(0, 0, g.getWidth(), 6 * (h / 8) + 1); - } - - if (false) { - g.drawImage(hira_a, x, y); - g.setColor(1, 1, 1); - g.setFont('Vector', 30); - g.drawString(curkana, x + 32, y + 4); - } else { - if (clocktop) { - g.setColor(1, 1, 1); - g.drawImage(kana, x + 8, y + 12, { scale: 3.4 }); - g.setColor(1, 1, 1); - g.setFont('Vector', 30); - g.drawString(curkana, 0, y + 16); - g.drawString(hiramode ? 'H' : 'K', w - 20, y + 16); - } else { - g.setColor(1, 1, 1); - g.drawImage(kana, x + 8, 26, { scale: 3.4 }); - g.setColor(1, 1, 1); - g.setFont('Vector', 30); - g.drawString(curkana, 4, 32); - g.drawString(hiramode ? 'H' : 'K', w - 20, 32); - } - } + g.fillRect(0, 0, g.getWidth(), 6 * (h / 8) + 1); + g.setColor(1, 1, 1); + g.drawImage(kana, x + 20, 40, { scale: 1.6 }); + g.setColor(1, 1, 1); + g.setFont('Vector', 24); + g.drawString(getPhoneme(curkana), 4, 32); + g.drawString(hiramode ? 'H' : 'K', w - 20, 32); } var ohhmm = ''; function tickWatch () { const now = Date(); + month = now.getMonth() + 1; + day = now.getDate(); function zpad (n) { return (n < 10) ? '0' + n : n; } const hhmm = zpad(now.getHours()) + ':' + zpad(now.getMinutes()); if (hhmm !== ohhmm) { + randKana(); updateWatch(hhmm); + ohhmm = hhmm; } } Bangle.on('touch', function (tap, top) { - if (top.y < h / 3) { - // clocktop = !clocktop; - return; - } if (top.x < w / 4) { prev(); } else if (top.x > (w - (w / 4))) { @@ -816,10 +260,14 @@ Bangle.on('touch', function (tap, top) { hiramode = !hiramode; } kana = hiramode ? hiragana[curkana] : katakana[curkana]; - tickWatch(); + updateWatch(ohhmm); }); +g.clear(true); +// show launcher when button pressed +Bangle.setUI('clock'); Bangle.loadWidgets(); tickWatch(); -setInterval(tickWatch, 1000); +setInterval(tickWatch, 1000 * 60); + diff --git a/apps/kanawatch/fontmaker.zip b/apps/kanawatch/fontmaker.zip new file mode 100644 index 000000000..39c7d5d53 Binary files /dev/null and b/apps/kanawatch/fontmaker.zip differ diff --git a/apps/kanawatch/metadata.json b/apps/kanawatch/metadata.json index 09bfc2d36..b14703979 100644 --- a/apps/kanawatch/metadata.json +++ b/apps/kanawatch/metadata.json @@ -2,7 +2,7 @@ "id": "kanawatch", "name": "Kanawatch", "shortName": "Kanawatch", - "version": "0.01", + "version": "0.05", "type": "clock", "description": "Learn Hiragana and Katakana", "icon": "app.png", @@ -25,7 +25,7 @@ ], "screenshots": [ { - "url": "screenshot.jpg" + "url": "screenshot.png" } ] } diff --git a/apps/kanawatch/screenshot.jpg b/apps/kanawatch/screenshot.jpg deleted file mode 100644 index ac7447ee8..000000000 Binary files a/apps/kanawatch/screenshot.jpg and /dev/null differ diff --git a/apps/kanawatch/screenshot.png b/apps/kanawatch/screenshot.png new file mode 100644 index 000000000..b1ed879aa Binary files /dev/null and b/apps/kanawatch/screenshot.png differ diff --git a/apps/kbmorse/ChangeLog b/apps/kbmorse/ChangeLog index f62348ec8..c85361374 100644 --- a/apps/kbmorse/ChangeLog +++ b/apps/kbmorse/ChangeLog @@ -1 +1,2 @@ -0.01: New Keyboard! \ No newline at end of file +0.01: New Keyboard! +0.02: Temporarily fix because of firmware bug. diff --git a/apps/kbmorse/lib.js b/apps/kbmorse/lib.js index 8bc177a46..997f2cb16 100644 --- a/apps/kbmorse/lib.js +++ b/apps/kbmorse/lib.js @@ -82,6 +82,36 @@ exports.input = function(options) { } return new Promise((resolve, reject) => { + const Layout = require("Layout"); + let layout = new Layout({ + type: "h", c: [ + { + type: "v", width: Bangle.appRect.w-8, bgCol: g.theme.bg, c: [ + {id: "dots", type: "txt", font: "6x8:2", label: "", fillx: 1, bgCol: g.theme.bg}, + {filly: 1, bgCol: g.theme.bg}, + { + type: "h", fillx: 1, c: [ + {id: "del", type: "txt", font: "6x8", label: " + ({type: "txt", font: "6x8", height: Math.floor(Bangle.appRect.h/3), r: 1, label: l}) + ) + } + ] + }); function update() { let dots = [], dashes = []; @@ -157,36 +187,6 @@ exports.input = function(options) { } } - const Layout = require("Layout"); - let layout = new Layout({ - type: "h", c: [ - { - type: "v", width: Bangle.appRect.w-8, bgCol: g.theme.bg, c: [ - {id: "dots", type: "txt", font: "6x8:2", label: "", fillx: 1, bgCol: g.theme.bg}, - {filly: 1, bgCol: g.theme.bg}, - { - type: "h", fillx: 1, c: [ - {id: "del", type: "txt", font: "6x8", label: " - ({type: "txt", font: "6x8", height: Math.floor(Bangle.appRect.h/3), r: 1, label: l}) - ) - } - ] - }); g.reset().clear(); update(); @@ -244,4 +244,4 @@ exports.input = function(options) { }; Bangle.on("swipe", Bangle.swipeHandler); }); -}; \ No newline at end of file +}; diff --git a/apps/kbmorse/metadata.json b/apps/kbmorse/metadata.json index f9c5354f1..9111d514d 100644 --- a/apps/kbmorse/metadata.json +++ b/apps/kbmorse/metadata.json @@ -1,7 +1,7 @@ { "id": "kbmorse", "name": "Morse keyboard", - "version": "0.01", + "version": "0.02", "description": "A library for text input as morse code", "icon": "app.png", "type": "textinput", diff --git a/apps/kbmulti/ChangeLog b/apps/kbmulti/ChangeLog index 26647b548..4ef8f7bda 100644 --- a/apps/kbmulti/ChangeLog +++ b/apps/kbmulti/ChangeLog @@ -1,3 +1,5 @@ 0.01: New keyboard 0.02: Introduce setting "Show help button?". Make setting firstLaunch invisible by removing corresponding code from settings.js. Add marker that shows when character selection timeout has run out. Display opened text on launch when editing existing text string. Perfect horizontal alignment of buttons. Tweak help message letter casing. 0.03: Use default Bangle formatter for booleans +0.04: Allow moving the cursor +0.05: Switch swipe directions for Caps Lock and moving cursor. diff --git a/apps/kbmulti/README.md b/apps/kbmulti/README.md index 4c83d378e..b6754711d 100644 --- a/apps/kbmulti/README.md +++ b/apps/kbmulti/README.md @@ -2,7 +2,7 @@ A library that provides the ability to input text in a style familiar to anyone who had a mobile phone before they went all touchscreen. -Swipe right for Space, left for Backspace, and up/down for Caps lock. Tap the '?' button in the app if you need a reminder! +Swipe right for Space, left for Backspace, down for Caps lock switch, and up for cursor moving mode. Swipe left and right to move the cursor in moving mode. Tap the '?' button in the app if you need a reminder! At time of writing, only the [Noteify app](http://microco.sm/out/Ffe9i) uses a keyboard. diff --git a/apps/kbmulti/lib.js b/apps/kbmulti/lib.js index 5ccab4204..9b642a132 100644 --- a/apps/kbmulti/lib.js +++ b/apps/kbmulti/lib.js @@ -17,18 +17,50 @@ exports.input = function(options) { "4":"GHI4","5":"JKL5","6":"MNO6", "7":"PQRS7","8":"TUV80","9":"WXYZ9", }; - var helpMessage = 'Swipe:\nRight: Space\nLeft:Backspace\nUp/Down: Caps lock\n'; + var helpMessage = 'Swipe:\nRight: Space\nLeft:Backspace\nUp: Move mode\nDown:Caps lock'; var charTimeout; // timeout after a key is pressed var charCurrent; // current character (index in letters) var charIndex; // index in letters[charCurrent] + var textIndex = text.length; + var textWidth = settings.showHelpBtn ? 10 : 14; var caps = true; var layout; - var btnWidth = g.getWidth()/3 + var btnWidth = g.getWidth()/3; + + function getMoveChar(){ + return "\x00\x0B\x11\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00@\x1F\xE1\x00\x10\x00\x10\x01\x0F\xF0\x04\x01\x00"; + } + + function getMoreChar(){ + return "\x00\x0B\x11\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xDB\x1B`\x00\x00\x00"; + } + + + function getCursorChar(){ + return "\x00\x0B\x11\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xAA\xAA\x80"; } function displayText(hideMarker) { layout.clear(layout.text); - layout.text.label = text.slice(settings.showHelpBtn ? -11 : -13) + (hideMarker ? " " : "_"); + + let charsBeforeCursor = textIndex; + let charsAfterCursor = Math.min(text.length - textIndex, (textWidth)/2); + + + let start = textIndex - Math.ceil(textWidth - charsAfterCursor); + let startMore = false; + if (start > 0) {start++; startMore = true} + if (start < 0) start = 0; + let cursor = textIndex + 1; + + let end = cursor + Math.floor(start + textWidth - cursor); + if (end <= text.length) {end--; if (startMore) end--;} + if (end > text.length) end = text.length; + + let pre = (start > 0 ? getMoreChar() : "") + text.slice(start, cursor); + let post = text.slice(cursor, end) + (end < text.length - 1 ? getMoreChar() : ""); + + layout.text.label = pre + (hideMarker ? " " : (moveMode? getMoveChar():getCursorChar())) + post; layout.render(layout.text); } @@ -41,8 +73,11 @@ exports.input = function(options) { function backspace() { deactivateTimeout(charTimeout); - text = text.slice(0, -1); - newCharacter(); + if (textIndex > -1){ + text = text.slice(0, textIndex) + text.slice(textIndex + 1); + if (textIndex > -1) textIndex --; + newCharacter(); + } } function setCaps() { @@ -55,6 +90,7 @@ exports.input = function(options) { function newCharacter(ch) { displayText(); + if (ch && textIndex < text.length) textIndex ++; charCurrent = ch; charIndex = 0; } @@ -69,7 +105,11 @@ exports.input = function(options) { newCharacter(key); } var newLetter = letters[charCurrent][charIndex]; - text += (caps ? newLetter.toUpperCase() : newLetter.toLowerCase()); + let pre = text.slice(0, textIndex); + let post = text.slice(textIndex, text.length); + + text = pre + (caps ? newLetter.toUpperCase() : newLetter.toLowerCase()) + post; + // set a timeout charTimeout = setTimeout(function() { charTimeout = undefined; @@ -78,14 +118,29 @@ exports.input = function(options) { displayText(charTimeout); } + var moveMode = false; + function onSwipe(dirLeftRight, dirUpDown) { - if (dirUpDown) { + if (dirUpDown == -1) { + moveMode = !moveMode; + displayText(false); + } else if (dirUpDown == 1) { setCaps(); } else if (dirLeftRight == 1) { - text += ' '; - newCharacter(); + if (!moveMode){ + text = text.slice(0, textIndex + 1) + " " + text.slice(++textIndex); + newCharacter(); + } else { + if (textIndex < text.length) textIndex++; + displayText(false); + } } else if (dirLeftRight == -1) { - backspace(); + if (!moveMode){ + backspace(); + } else { + if (textIndex > -1) textIndex--; + displayText(false); + } } } diff --git a/apps/kbmulti/metadata.json b/apps/kbmulti/metadata.json index 30ffa6f9e..510454f79 100644 --- a/apps/kbmulti/metadata.json +++ b/apps/kbmulti/metadata.json @@ -1,6 +1,6 @@ { "id": "kbmulti", "name": "Multitap keyboard", - "version":"0.03", + "version":"0.05", "description": "A library for text input via multitap/T9 style keypad", "icon": "app.png", "type":"textinput", diff --git a/apps/kbswipe/ChangeLog b/apps/kbswipe/ChangeLog index f0dc54b69..a7b2d44c2 100644 --- a/apps/kbswipe/ChangeLog +++ b/apps/kbswipe/ChangeLog @@ -2,3 +2,6 @@ 0.02: Now keeps user input trace intact by changing how the screen is updated. 0.03: Positioning of marker now takes the height of the widget field into account. 0.04: Fix issue if going back without typing. +0.05: Keep drag-function in ram, hopefully improving performance and input reliability somewhat. +0.06: Support input of numbers and uppercase characters. +0.07: Support input of symbols. diff --git a/apps/kbswipe/README.md b/apps/kbswipe/README.md index 3f5575777..105d7cd9b 100644 --- a/apps/kbswipe/README.md +++ b/apps/kbswipe/README.md @@ -4,6 +4,10 @@ A library that provides the ability to input text by swiping PalmOS Graffiti-sty To get a legend of available characters, just tap the screen. +To switch between the input of alphabetic, numeric and symbol characters tap the widget which displays either "123", "ABC" or "?:$". + +To switch between lowercase and uppercase characters do an up swipe. + ![](key.png) ## Usage diff --git a/apps/kbswipe/lib.js b/apps/kbswipe/lib.js index 417ac98d9..ea6d78255 100644 --- a/apps/kbswipe/lib.js +++ b/apps/kbswipe/lib.js @@ -1,47 +1,101 @@ +exports.INPUT_MODE_ALPHA = 0; +exports.INPUT_MODE_NUM = 1; +exports.INPUT_MODE_SYM = 2; + /* To make your own strokes, type: Bangle.on('stroke',print) on the left of the IDE, then do a stroke and copy out the Uint8Array line */ -exports.getStrokes = function(cb) { - cb("a", new Uint8Array([58, 159, 58, 155, 62, 144, 69, 127, 77, 106, 86, 90, 94, 77, 101, 68, 108, 62, 114, 59, 121, 59, 133, 61, 146, 70, 158, 88, 169, 107, 176, 124, 180, 135, 183, 144, 185, 152])); - cb("b", new Uint8Array([51, 47, 51, 77, 56, 123, 60, 151, 65, 163, 68, 164, 68, 144, 67, 108, 67, 76, 72, 43, 104, 51, 121, 74, 110, 87, 109, 95, 131, 117, 131, 140, 109, 152, 88, 157])); - cb("c", new Uint8Array([153, 62, 150, 62, 145, 62, 136, 62, 123, 62, 106, 65, 85, 70, 65, 75, 50, 82, 42, 93, 37, 106, 36, 119, 36, 130, 40, 140, 49, 147, 61, 153, 72, 156, 85, 157, 106, 158, 116, 158])); - cb("d", new Uint8Array([57, 178, 57, 176, 55, 171, 52, 163, 50, 154, 49, 146, 47, 135, 45, 121, 44, 108, 44, 97, 44, 85, 44, 75, 44, 66, 44, 58, 44, 48, 44, 38, 46, 31, 48, 26, 58, 21, 75, 20, 99, 26, 120, 35, 136, 51, 144, 70, 144, 88, 137, 110, 124, 131, 106, 145, 88, 153])); - cb("e", new Uint8Array([150, 72, 141, 69, 114, 68, 79, 69, 48, 77, 32, 81, 31, 85, 46, 91, 73, 95, 107, 100, 114, 103, 83, 117, 58, 134, 66, 143, 105, 148, 133, 148, 144, 148])); - cb("f", new Uint8Array([157, 52, 155, 52, 148, 52, 137, 52, 124, 52, 110, 52, 96, 52, 83, 52, 74, 52, 67, 52, 61, 52, 57, 52, 55, 52, 52, 52, 52, 54, 52, 58, 52, 64, 54, 75, 58, 97, 59, 117, 60, 130])); - cb("g", new Uint8Array([160, 66, 153, 62, 129, 58, 90, 56, 58, 57, 38, 65, 31, 86, 43, 125, 69, 152, 116, 166, 145, 154, 146, 134, 112, 116, 85, 108, 97, 106, 140, 106, 164, 106])); - cb("h", new Uint8Array([58, 50, 58, 55, 58, 64, 58, 80, 58, 102, 58, 122, 58, 139, 58, 153, 58, 164, 58, 171, 58, 177, 58, 179, 58, 181, 58, 180, 58, 173, 58, 163, 59, 154, 61, 138, 64, 114, 68, 95, 72, 84, 80, 79, 91, 79, 107, 82, 123, 93, 137, 111, 145, 130, 149, 147, 150, 154, 150, 159])); - cb("i", new Uint8Array([89, 48, 89, 49, 89, 51, 89, 55, 89, 60, 89, 68, 89, 78, 89, 91, 89, 103, 89, 114, 89, 124, 89, 132, 89, 138, 89, 144, 89, 148, 89, 151, 89, 154, 89, 156, 89, 157, 89, 158])); - cb("j", new Uint8Array([130, 57, 130, 61, 130, 73, 130, 91, 130, 113, 130, 133, 130, 147, 130, 156, 130, 161, 130, 164, 130, 166, 129, 168, 127, 168, 120, 168, 110, 168, 91, 167, 81, 167, 68, 167])); - cb("k", new Uint8Array([149, 63, 147, 68, 143, 76, 136, 89, 126, 106, 114, 123, 100, 136, 86, 147, 72, 153, 57, 155, 45, 152, 36, 145, 29, 131, 26, 117, 26, 104, 27, 93, 30, 86, 35, 80, 45, 77, 62, 80, 88, 96, 113, 116, 130, 131, 140, 142, 145, 149, 148, 153])); - cb("l", new Uint8Array([42, 55, 42, 59, 42, 69, 44, 87, 44, 107, 44, 128, 44, 143, 44, 156, 44, 163, 44, 167, 44, 169, 45, 170, 49, 170, 59, 169, 76, 167, 100, 164, 119, 162, 139, 160, 163, 159])); - cb("m", new Uint8Array([49, 165, 48, 162, 46, 156, 44, 148, 42, 138, 42, 126, 42, 113, 43, 101, 45, 91, 47, 82, 49, 75, 51, 71, 54, 70, 57, 70, 61, 74, 69, 81, 75, 91, 84, 104, 94, 121, 101, 132, 103, 137, 106, 130, 110, 114, 116, 92, 125, 75, 134, 65, 139, 62, 144, 66, 148, 83, 151, 108, 155, 132, 157, 149])); - cb("n", new Uint8Array([50, 165, 50, 160, 50, 153, 50, 140, 50, 122, 50, 103, 50, 83, 50, 65, 50, 52, 50, 45, 50, 43, 52, 52, 57, 67, 66, 90, 78, 112, 93, 131, 104, 143, 116, 152, 127, 159, 135, 160, 141, 150, 148, 125, 154, 96, 158, 71, 161, 56, 162, 49])); - cb("o", new Uint8Array([107, 58, 104, 58, 97, 61, 87, 68, 75, 77, 65, 88, 58, 103, 54, 116, 53, 126, 55, 135, 61, 143, 75, 149, 91, 150, 106, 148, 119, 141, 137, 125, 143, 115, 146, 104, 146, 89, 142, 78, 130, 70, 116, 65, 104, 62])); - cb("p", new Uint8Array([52, 59, 52, 64, 54, 73, 58, 88, 61, 104, 65, 119, 67, 130, 69, 138, 71, 145, 71, 147, 71, 148, 71, 143, 70, 133, 68, 120, 67, 108, 67, 97, 67, 89, 68, 79, 72, 67, 83, 60, 99, 58, 118, 58, 136, 63, 146, 70, 148, 77, 145, 84, 136, 91, 121, 95, 106, 97, 93, 97, 82, 97])); - cb("q", new Uint8Array([95, 59, 93, 59, 88, 59, 79, 59, 68, 61, 57, 67, 50, 77, 48, 89, 48, 103, 50, 117, 55, 130, 65, 140, 76, 145, 85, 146, 94, 144, 101, 140, 105, 136, 106, 127, 106, 113, 100, 98, 92, 86, 86, 79, 84, 75, 84, 72, 91, 69, 106, 67, 126, 67, 144, 67, 158, 67, 168, 67, 173, 67, 177, 67])); - cb("r", new Uint8Array([53, 49, 53, 62, 53, 91, 53, 127, 53, 146, 53, 147, 53, 128, 53, 94, 53, 69, 62, 44, 82, 42, 94, 50, 92, 68, 82, 85, 77, 93, 80, 102, 95, 119, 114, 134, 129, 145, 137, 150])); - cb("s", new Uint8Array([159, 72, 157, 70, 155, 68, 151, 66, 145, 63, 134, 60, 121, 58, 108, 56, 96, 55, 83, 55, 73, 55, 64, 56, 57, 60, 52, 65, 49, 71, 49, 76, 50, 81, 55, 87, 71, 94, 94, 100, 116, 104, 131, 108, 141, 114, 145, 124, 142, 135, 124, 146, 97, 153, 70, 157, 52, 158])); - cb("t", new Uint8Array([45, 55, 48, 55, 55, 55, 72, 55, 96, 55, 120, 55, 136, 55, 147, 55, 152, 55, 155, 55, 157, 55, 158, 56, 158, 60, 156, 70, 154, 86, 151, 102, 150, 114, 148, 125, 148, 138, 148, 146])); - cb("u", new Uint8Array([35, 52, 35, 59, 35, 73, 35, 90, 36, 114, 38, 133, 42, 146, 49, 153, 60, 157, 73, 158, 86, 156, 100, 152, 112, 144, 121, 131, 127, 114, 132, 97, 134, 85, 135, 73, 136, 61, 136, 56])); - cb("v", new Uint8Array([36, 55, 37, 59, 40, 68, 45, 83, 51, 100, 58, 118, 64, 132, 69, 142, 71, 149, 73, 156, 76, 158, 77, 160, 77, 159, 80, 151, 82, 137, 84, 122, 86, 111, 90, 91, 91, 78, 91, 68, 91, 63, 92, 61, 97, 61, 111, 61, 132, 61, 150, 61, 162, 61])); - cb("w", new Uint8Array([33, 58, 34, 81, 39, 127, 44, 151, 48, 161, 52, 162, 57, 154, 61, 136, 65, 115, 70, 95, 76, 95, 93, 121, 110, 146, 119, 151, 130, 129, 138, 84, 140, 56, 140, 45])); - cb("x", new Uint8Array([56, 63, 56, 67, 57, 74, 60, 89, 66, 109, 74, 129, 85, 145, 96, 158, 107, 164, 117, 167, 128, 164, 141, 155, 151, 140, 159, 122, 166, 105, 168, 89, 170, 81, 170, 73, 169, 66, 161, 63, 141, 68, 110, 83, 77, 110, 55, 134, 47, 145])); - cb("y", new Uint8Array([42, 56, 42, 70, 48, 97, 62, 109, 85, 106, 109, 90, 126, 65, 134, 47, 137, 45, 137, 75, 127, 125, 98, 141, 70, 133, 65, 126, 92, 137, 132, 156, 149, 166])); - cb("z", new Uint8Array([29, 62, 35, 62, 43, 62, 63, 62, 87, 62, 110, 62, 125, 62, 134, 62, 138, 62, 136, 63, 122, 68, 103, 77, 85, 91, 70, 107, 59, 120, 50, 132, 47, 138, 43, 143, 41, 148, 42, 151, 53, 155, 80, 157, 116, 158, 146, 158, 163, 158])); +exports.getStrokes = function(mode, cb) { + if (mode === exports.INPUT_MODE_ALPHA) { + cb("a", new Uint8Array([58, 159, 58, 155, 62, 144, 69, 127, 77, 106, 86, 90, 94, 77, 101, 68, 108, 62, 114, 59, 121, 59, 133, 61, 146, 70, 158, 88, 169, 107, 176, 124, 180, 135, 183, 144, 185, 152])); + cb("b", new Uint8Array([51, 47, 51, 77, 56, 123, 60, 151, 65, 163, 68, 164, 68, 144, 67, 108, 67, 76, 72, 43, 104, 51, 121, 74, 110, 87, 109, 95, 131, 117, 131, 140, 109, 152, 88, 157])); + cb("c", new Uint8Array([153, 62, 150, 62, 145, 62, 136, 62, 123, 62, 106, 65, 85, 70, 65, 75, 50, 82, 42, 93, 37, 106, 36, 119, 36, 130, 40, 140, 49, 147, 61, 153, 72, 156, 85, 157, 106, 158, 116, 158])); + cb("d", new Uint8Array([57, 178, 57, 176, 55, 171, 52, 163, 50, 154, 49, 146, 47, 135, 45, 121, 44, 108, 44, 97, 44, 85, 44, 75, 44, 66, 44, 58, 44, 48, 44, 38, 46, 31, 48, 26, 58, 21, 75, 20, 99, 26, 120, 35, 136, 51, 144, 70, 144, 88, 137, 110, 124, 131, 106, 145, 88, 153])); + cb("e", new Uint8Array([150, 72, 141, 69, 114, 68, 79, 69, 48, 77, 32, 81, 31, 85, 46, 91, 73, 95, 107, 100, 114, 103, 83, 117, 58, 134, 66, 143, 105, 148, 133, 148, 144, 148])); + cb("f", new Uint8Array([157, 52, 155, 52, 148, 52, 137, 52, 124, 52, 110, 52, 96, 52, 83, 52, 74, 52, 67, 52, 61, 52, 57, 52, 55, 52, 52, 52, 52, 54, 52, 58, 52, 64, 54, 75, 58, 97, 59, 117, 60, 130])); + cb("g", new Uint8Array([160, 66, 153, 62, 129, 58, 90, 56, 58, 57, 38, 65, 31, 86, 43, 125, 69, 152, 116, 166, 145, 154, 146, 134, 112, 116, 85, 108, 97, 106, 140, 106, 164, 106])); + cb("h", new Uint8Array([58, 50, 58, 55, 58, 64, 58, 80, 58, 102, 58, 122, 58, 139, 58, 153, 58, 164, 58, 171, 58, 177, 58, 179, 58, 181, 58, 180, 58, 173, 58, 163, 59, 154, 61, 138, 64, 114, 68, 95, 72, 84, 80, 79, 91, 79, 107, 82, 123, 93, 137, 111, 145, 130, 149, 147, 150, 154, 150, 159])); + cb("i", new Uint8Array([89, 48, 89, 49, 89, 51, 89, 55, 89, 60, 89, 68, 89, 78, 89, 91, 89, 103, 89, 114, 89, 124, 89, 132, 89, 138, 89, 144, 89, 148, 89, 151, 89, 154, 89, 156, 89, 157, 89, 158])); + cb("j", new Uint8Array([130, 57, 130, 61, 130, 73, 130, 91, 130, 113, 130, 133, 130, 147, 130, 156, 130, 161, 130, 164, 130, 166, 129, 168, 127, 168, 120, 168, 110, 168, 91, 167, 81, 167, 68, 167])); + cb("k", new Uint8Array([149, 63, 147, 68, 143, 76, 136, 89, 126, 106, 114, 123, 100, 136, 86, 147, 72, 153, 57, 155, 45, 152, 36, 145, 29, 131, 26, 117, 26, 104, 27, 93, 30, 86, 35, 80, 45, 77, 62, 80, 88, 96, 113, 116, 130, 131, 140, 142, 145, 149, 148, 153])); + cb("l", new Uint8Array([42, 55, 42, 59, 42, 69, 44, 87, 44, 107, 44, 128, 44, 143, 44, 156, 44, 163, 44, 167, 44, 169, 45, 170, 49, 170, 59, 169, 76, 167, 100, 164, 119, 162, 139, 160, 163, 159])); + cb("m", new Uint8Array([49, 165, 48, 162, 46, 156, 44, 148, 42, 138, 42, 126, 42, 113, 43, 101, 45, 91, 47, 82, 49, 75, 51, 71, 54, 70, 57, 70, 61, 74, 69, 81, 75, 91, 84, 104, 94, 121, 101, 132, 103, 137, 106, 130, 110, 114, 116, 92, 125, 75, 134, 65, 139, 62, 144, 66, 148, 83, 151, 108, 155, 132, 157, 149])); + cb("n", new Uint8Array([50, 165, 50, 160, 50, 153, 50, 140, 50, 122, 50, 103, 50, 83, 50, 65, 50, 52, 50, 45, 50, 43, 52, 52, 57, 67, 66, 90, 78, 112, 93, 131, 104, 143, 116, 152, 127, 159, 135, 160, 141, 150, 148, 125, 154, 96, 158, 71, 161, 56, 162, 49])); + cb("o", new Uint8Array([107, 58, 104, 58, 97, 61, 87, 68, 75, 77, 65, 88, 58, 103, 54, 116, 53, 126, 55, 135, 61, 143, 75, 149, 91, 150, 106, 148, 119, 141, 137, 125, 143, 115, 146, 104, 146, 89, 142, 78, 130, 70, 116, 65, 104, 62])); + cb("p", new Uint8Array([29, 47, 29, 55, 29, 75, 29, 110, 29, 145, 29, 165, 29, 172, 29, 164, 30, 149, 37, 120, 50, 91, 61, 74, 72, 65, 85, 61, 103, 61, 118, 63, 126, 69, 129, 76, 130, 87, 126, 98, 112, 108, 97, 114, 87, 116])); + cb("q", new Uint8Array([95, 59, 93, 59, 88, 59, 79, 59, 68, 61, 57, 67, 50, 77, 48, 89, 48, 103, 50, 117, 55, 130, 65, 140, 76, 145, 85, 146, 94, 144, 101, 140, 105, 136, 106, 127, 106, 113, 100, 98, 92, 86, 86, 79, 84, 75, 84, 72, 91, 69, 106, 67, 126, 67, 144, 67, 158, 67, 168, 67, 173, 67, 177, 67])); + cb("r", new Uint8Array([53, 49, 53, 62, 53, 91, 53, 127, 53, 146, 53, 147, 53, 128, 53, 94, 53, 69, 62, 44, 82, 42, 94, 50, 92, 68, 82, 85, 77, 93, 80, 102, 95, 119, 114, 134, 129, 145, 137, 150])); + cb("s", new Uint8Array([159, 72, 157, 70, 155, 68, 151, 66, 145, 63, 134, 60, 121, 58, 108, 56, 96, 55, 83, 55, 73, 55, 64, 56, 57, 60, 52, 65, 49, 71, 49, 76, 50, 81, 55, 87, 71, 94, 94, 100, 116, 104, 131, 108, 141, 114, 145, 124, 142, 135, 124, 146, 97, 153, 70, 157, 52, 158])); + cb("t", new Uint8Array([45, 55, 48, 55, 55, 55, 72, 55, 96, 55, 120, 55, 136, 55, 147, 55, 152, 55, 155, 55, 157, 55, 158, 56, 158, 60, 156, 70, 154, 86, 151, 102, 150, 114, 148, 125, 148, 138, 148, 146])); + cb("u", new Uint8Array([35, 52, 35, 59, 35, 73, 35, 90, 36, 114, 38, 133, 42, 146, 49, 153, 60, 157, 73, 158, 86, 156, 100, 152, 112, 144, 121, 131, 127, 114, 132, 97, 134, 85, 135, 73, 136, 61, 136, 56])); + cb("v", new Uint8Array([36, 55, 37, 59, 40, 68, 45, 83, 51, 100, 58, 118, 64, 132, 69, 142, 71, 149, 73, 156, 76, 158, 77, 160, 77, 159, 80, 151, 82, 137, 84, 122, 86, 111, 90, 91, 91, 78, 91, 68, 91, 63, 92, 61, 97, 61, 111, 61, 132, 61, 150, 61, 162, 61])); + cb("w", new Uint8Array([25, 46, 25, 82, 25, 119, 33, 143, 43, 153, 60, 147, 73, 118, 75, 91, 76, 88, 85, 109, 96, 134, 107, 143, 118, 137, 129, 112, 134, 81, 134, 64, 134, 55])); + cb("x", new Uint8Array([56, 63, 56, 67, 57, 74, 60, 89, 66, 109, 74, 129, 85, 145, 96, 158, 107, 164, 117, 167, 128, 164, 141, 155, 151, 140, 159, 122, 166, 105, 168, 89, 170, 81, 170, 73, 169, 66, 161, 63, 141, 68, 110, 83, 77, 110, 55, 134, 47, 145])); + cb("y", new Uint8Array([30, 41, 30, 46, 30, 52, 30, 63, 30, 79, 33, 92, 38, 100, 47, 104, 54, 107, 66, 105, 79, 94, 88, 82, 92, 74, 94, 77, 96, 98, 96, 131, 94, 151, 91, 164, 85, 171, 75, 171, 71, 162, 74, 146, 84, 130, 95, 119, 106, 113])); + cb("z", new Uint8Array([29, 62, 35, 62, 43, 62, 63, 62, 87, 62, 110, 62, 125, 62, 134, 62, 138, 62, 136, 63, 122, 68, 103, 77, 85, 91, 70, 107, 59, 120, 50, 132, 47, 138, 43, 143, 41, 148, 42, 151, 53, 155, 80, 157, 116, 158, 146, 158, 163, 158])); + cb("SHIFT", new Uint8Array([100, 160, 100, 50])); + } else if (mode === exports.INPUT_MODE_NUM) { + cb("0", new Uint8Array([82, 50, 76, 50, 67, 50, 59, 50, 50, 51, 43, 57, 38, 68, 34, 83, 33, 95, 33, 108, 34, 121, 42, 136, 57, 148, 72, 155, 85, 157, 98, 155, 110, 149, 120, 139, 128, 127, 134, 119, 137, 114, 138, 107, 138, 98, 138, 88, 138, 77, 137, 71, 134, 65, 128, 60, 123, 58])); + cb("1", new Uint8Array([100, 50, 100, 160])); + cb("2", new Uint8Array([40, 79, 46, 74, 56, 66, 68, 58, 77, 49, 87, 45, 100, 45, 111, 46, 119, 50, 128, 58, 133, 71, 130, 88, 120, 106, 98, 128, 69, 150, 50, 162, 42, 167, 43, 168, 58, 169, 78, 170, 93, 170, 103, 170, 109, 170])); + cb("3", new Uint8Array([47, 65, 51, 60, 57, 56, 65, 51, 74, 47, 84, 45, 93, 45, 102, 45, 109, 46, 122, 51, 129, 58, 130, 65, 127, 74, 120, 85, 112, 92, 107, 96, 112, 101, 117, 105, 125, 113, 128, 123, 127, 134, 122, 145, 108, 156, 91, 161, 70, 163, 55, 163])); + cb("4", new Uint8Array([37, 58, 37, 60, 37, 64, 37, 69, 37, 75, 37, 86, 37, 96, 37, 105, 37, 112, 37, 117, 37, 122, 37, 126, 37, 128, 38, 129, 40, 129, 45, 129, 48, 129, 53, 129, 67, 129, 85, 129, 104, 129, 119, 129, 129, 129, 136, 129])); + cb("5", new Uint8Array([142, 60, 119, 60, 79, 60, 45, 60, 37, 64, 37, 86, 37, 103, 47, 107, 66, 106, 81, 103, 97, 103, 116, 103, 129, 108, 131, 130, 122, 152, 101, 168, 85, 172, 70, 172, 59, 172])); + cb("6", new Uint8Array([136, 54, 135, 49, 129, 47, 114, 47, 89, 54, 66, 66, 50, 81, 39, 95, 35, 109, 34, 128, 38, 145, 52, 158, 81, 164, 114, 157, 133, 139, 136, 125, 132, 118, 120, 115, 102, 117, 85, 123])); + cb("7", new Uint8Array([47, 38, 48, 38, 53, 38, 66, 38, 85, 38, 103, 38, 117, 38, 125, 38, 129, 38, 134, 41, 135, 47, 135, 54, 135, 66, 131, 93, 124, 126, 116, 149, 109, 161, 105, 168])); + cb("8", new Uint8Array([122, 61, 102, 61, 83, 61, 60, 61, 47, 62, 45, 78, 58, 99, 84, 112, 105, 122, 118, 134, 121, 149, 113, 165, 86, 171, 59, 171, 47, 164, 45, 144, 50, 132, 57, 125, 67, 117, 78, 109, 87, 102, 96, 94, 105, 86, 113, 85])); + cb("9", new Uint8Array([122, 58, 117, 55, 112, 51, 104, 51, 95, 51, 86, 51, 77, 51, 68, 51, 60, 51, 54, 56, 47, 64, 46, 77, 46, 89, 46, 96, 51, 103, 64, 109, 74, 110, 83, 110, 94, 107, 106, 102, 116, 94, 124, 84, 127, 79, 128, 78, 128, 94, 128, 123, 128, 161, 128, 175])); + } else if (mode === exports.INPUT_MODE_SYM) { + cb("?", new Uint8Array([36, 69, 39, 68, 44, 65, 52, 60, 61, 56, 70, 51, 78, 47, 87, 46, 96, 46, 108, 46, 121, 49, 128, 56, 129, 63, 126, 76, 119, 91, 108, 105, 103, 114, 98, 118, 93, 124, 91, 131, 91, 143, 91, 155, 91, 163])); + cb(".", new Uint8Array([105, 158, 97, 157, 80, 150, 60, 140, 44, 127, 34, 110, 31, 97, 31, 84, 35, 74, 48, 59, 78, 55, 115, 57, 145, 70, 159, 89, 162, 112, 160, 138, 153, 153, 144, 164, 125, 170, 103, 171])); + cb(",", new Uint8Array([140, 44, 139, 45, 138, 46, 137, 47, 135, 49, 132, 51, 127, 55, 123, 58, 117, 62, 112, 67, 105, 71, 100, 77, 93, 82, 86, 86, 80, 91, 74, 96, 69, 101, 64, 105, 60, 108, 57, 112, 53, 115, 51, 117, 49, 119, 48, 121, 47, 122, 46, 122, 46, 123])); + cb("'", new Uint8Array([100, 50, 100, 160])); + cb("-", new Uint8Array([34, 63, 36, 63, 40, 63, 46, 63, 54, 63, 63, 63, 72, 63, 82, 63, 92, 63, 103, 63, 113, 63, 124, 63, 132, 63, 139, 63, 143, 63, 145, 63, 147, 63, 149, 63, 152, 63])); + cb("_", new Uint8Array([34, 84, 36, 84, 40, 84, 47, 84, 56, 84, 67, 84, 81, 84, 95, 84, 108, 84, 120, 84, 131, 84, 139, 84, 146, 84, 149, 84, 151, 84, 154, 84, 155, 83, 154, 81, 150, 78, 143, 74, 130, 71, 111, 68, 90, 65, 73, 64, 60, 64, 51, 64, 46, 64])); + cb("\"", new Uint8Array([24, 168, 24, 158, 28, 132, 33, 102, 37, 82, 41, 66, 46, 54, 50, 47, 54, 46, 60, 49, 67, 64, 73, 88, 80, 114, 87, 138, 95, 149, 109, 145, 123, 128, 130, 108, 135, 87, 136, 70, 136, 57, 136, 50])); + cb(":", new Uint8Array([24, 62, 24, 63, 24, 68, 26, 73, 27, 80, 29, 88, 31, 94, 33, 101, 35, 108, 37, 114, 39, 121, 39, 127, 39, 131, 39, 134, 39, 135, 39, 133, 39, 130, 41, 125, 45, 114, 48, 100, 51, 89, 52, 81, 52, 74, 52, 70, 52, 67, 52, 63, 52, 60, 52, 57])); + cb(";", new Uint8Array([142, 58, 139, 59, 136, 61, 131, 65, 124, 71, 116, 79, 105, 87, 94, 98, 82, 109, 70, 121, 58, 132, 49, 141, 40, 149, 33, 156, 28, 160, 24, 164, 23, 166, 22, 164, 25, 156, 33, 138, 47, 111, 66, 81, 82, 58, 95, 41, 103, 30])); + cb("(", new Uint8Array([72, 51, 70, 51, 68, 51, 66, 54, 63, 56, 61, 59, 58, 61, 56, 65, 54, 70, 51, 74, 49, 79, 47, 83, 45, 87, 44, 92, 44, 94, 44, 96, 44, 99, 44, 101, 44, 104, 44, 107, 44, 114, 44, 120, 46, 127, 49, 135, 52, 141, 56, 145])); + cb(")", new Uint8Array([18, 42, 21, 43, 24, 45, 28, 47, 32, 50, 37, 53, 40, 58, 44, 62, 46, 69, 48, 76, 50, 81, 52, 85, 53, 90, 53, 94, 53, 98, 53, 103, 53, 106, 53, 111, 53, 119, 53, 129, 52, 137, 50, 142, 47, 146])); + cb("[", new Uint8Array([121, 138, 118, 143, 114, 146, 110, 149, 105, 152, 98, 152, 91, 152, 83, 152, 77, 152, 67, 151, 59, 146, 52, 138, 47, 131, 47, 124, 48, 118, 57, 115, 64, 115, 67, 113, 64, 106, 59, 95, 53, 85, 48, 80, 47, 74, 47, 64, 53, 57, 65, 56, 83, 56, 99, 61])); + cb("]", new Uint8Array([36, 136, 42, 140, 54, 145, 70, 149, 84, 151, 98, 149, 109, 143, 113, 135, 113, 127, 104, 115, 87, 105, 75, 103, 76, 98, 87, 84, 96, 67, 100, 54, 97, 48, 90, 45, 76, 45, 60, 47, 44, 52])); + cb("<", new Uint8Array([154, 122, 151, 122, 149, 121, 147, 118, 144, 116, 139, 114, 133, 112, 126, 110, 118, 107, 108, 105, 97, 102, 86, 97, 75, 93, 64, 90, 56, 88, 49, 85, 46, 84, 41, 82, 40, 80, 47, 76, 63, 69, 86, 59, 106, 50, 121, 44, 128, 40])); + cb(">", new Uint8Array([28, 115, 31, 115, 38, 113, 48, 110, 57, 107, 68, 103, 79, 98, 90, 94, 98, 92, 104, 90, 111, 88, 117, 85, 122, 83, 125, 81, 127, 80, 129, 80, 132, 80, 130, 78, 126, 75, 120, 72, 110, 69, 98, 66, 85, 63, 72, 60, 59, 57, 45, 53, 36, 49, 30, 46])); + cb("@", new Uint8Array([82, 50, 76, 50, 67, 50, 59, 50, 50, 51, 43, 57, 38, 68, 34, 83, 33, 95, 33, 108, 34, 121, 42, 136, 57, 148, 72, 155, 85, 157, 98, 155, 110, 149, 120, 139, 128, 127, 134, 119, 137, 114, 138, 107, 138, 98, 138, 88, 138, 77, 137, 71, 134, 65, 128, 60, 123, 58])); + cb("#", new Uint8Array([23, 70, 23, 76, 26, 85, 30, 97, 36, 112, 40, 129, 45, 142, 49, 152, 53, 158, 59, 161, 67, 155, 78, 130, 84, 98, 88, 76, 90, 68, 96, 62, 102, 61, 108, 61, 119, 67, 126, 80, 131, 101, 135, 129, 136, 152])); + cb("$", new Uint8Array([159, 72, 157, 70, 155, 68, 151, 66, 145, 63, 134, 60, 121, 58, 108, 56, 96, 55, 83, 55, 73, 55, 64, 56, 57, 60, 52, 65, 49, 71, 49, 76, 50, 81, 55, 87, 71, 94, 94, 100, 116, 104, 131, 108, 141, 114, 145, 124, 142, 135, 124, 146, 97, 153, 70, 157, 52, 158])); + cb("%", new Uint8Array([31, 39, 39, 54, 51, 78, 60, 97, 62, 107, 59, 118, 47, 118, 44, 109, 46, 92, 56, 73, 69, 62, 92, 61, 115, 70, 125, 90, 126, 110, 125, 122, 118, 127, 111, 127, 105, 124, 105, 115, 105, 97, 109, 75, 117, 56, 124, 45])); + cb("^", new Uint8Array([28, 175, 28, 168, 33, 156, 37, 142, 41, 128, 46, 111, 51, 95, 58, 82, 62, 75, 68, 68, 74, 57, 81, 49, 88, 44, 93, 44, 102, 56, 113, 79, 118, 95, 123, 110, 131, 130, 135, 146, 136, 158])); + cb("&", new Uint8Array([122, 61, 102, 61, 83, 61, 60, 61, 47, 62, 45, 78, 58, 99, 84, 112, 105, 122, 118, 134, 121, 149, 113, 165, 86, 171, 59, 171, 47, 164, 45, 144, 50, 132, 57, 125, 67, 117, 78, 109, 87, 102, 96, 94, 105, 86, 113, 85])); + cb("*", new Uint8Array([35, 61, 41, 62, 53, 68, 72, 78, 91, 91, 103, 99, 113, 103, 119, 106, 124, 107, 131, 107, 139, 107, 150, 107, 161, 104, 166, 97, 166, 89, 165, 78, 162, 70, 158, 61, 151, 54, 144, 51, 132, 51, 115, 57, 98, 66, 82, 78, 65, 89, 52, 100, 44, 109])); + cb("!", new Uint8Array([100, 160, 100, 50])); + cb("~", new Uint8Array([133, 40, 133, 48, 133, 65, 133, 87, 133, 105, 132, 116, 128, 125, 124, 133, 120, 140, 114, 146, 107, 148, 101, 147, 91, 139, 82, 126, 74, 108, 70, 91, 70, 82, 70, 75, 70, 65, 68, 57, 62, 51, 57, 50, 49, 57, 41, 76, 36, 96, 33, 114, 33, 132])); + cb("+", new Uint8Array([151, 41, 146, 46, 133, 55, 116, 71, 101, 87, 87, 98, 74, 105, 63, 109, 54, 110, 43, 106, 36, 94, 36, 80, 36, 68, 42, 60, 60, 58, 91, 64, 115, 77, 129, 88, 139, 99, 144, 106])); + cb("=", new Uint8Array([34, 46, 47, 46, 70, 46, 87, 46, 96, 46, 101, 46, 104, 46, 102, 50, 96, 58, 80, 78, 62, 100, 49, 117, 40, 127, 43, 132, 61, 132, 84, 132, 99, 132])); + cb("\\", new Uint8Array([25, 38, 26, 40, 30, 43, 35, 48, 43, 54, 54, 63, 65, 74, 76, 85, 87, 96, 98, 108, 108, 121, 116, 131, 123, 138, 127, 144, 131, 148, 134, 152, 136, 155])); + cb("|", new Uint8Array([66, 146, 66, 144, 66, 140, 66, 134, 66, 125, 66, 114, 66, 102, 66, 92, 66, 83, 66, 77, 66, 71, 66, 67, 66, 62, 66, 58, 66, 53, 66, 49, 66, 48, 66, 46, 64, 42, 61, 41, 58, 42, 54, 47, 51, 55, 46, 67, 40, 81, 37, 93, 34, 102, 30, 109, 28, 116])); + cb("/", new Uint8Array([24, 173, 26, 171, 30, 166, 36, 158, 44, 148, 53, 137, 63, 126, 73, 115, 82, 104, 91, 95, 99, 87, 105, 80, 112, 74, 117, 70, 122, 65, 125, 61, 127, 60, 129, 57, 133, 53, 136, 50, 137, 47])); + } cb("\b", new Uint8Array([183, 103, 182, 103, 180, 103, 176, 103, 169, 103, 159, 103, 147, 103, 133, 103, 116, 103, 101, 103, 85, 103, 73, 103, 61, 103, 52, 103, 38, 103, 34, 103, 29, 103, 27, 103, 26, 103, 25, 103, 24, 103])); - cb(" ", new Uint8Array([39, 118, 40, 118, 41, 118, 44, 118, 47, 118, 52, 118, 58, 118, 66, 118, 74, 118, 84, 118, 94, 118, 104, 117, 114, 116, 123, 116, 130, 116, 144, 116, 149, 116, 154, 116, 158, 116, 161, 116, 163, 116])); + if (mode === exports.INPUT_MODE_ALPHA || mode === exports.INPUT_MODE_NUM) { + cb(" ", new Uint8Array([39, 118, 40, 118, 41, 118, 44, 118, 47, 118, 52, 118, 58, 118, 66, 118, 74, 118, 84, 118, 94, 118, 104, 117, 114, 116, 123, 116, 130, 116, 144, 116, 149, 116, 154, 116, 158, 116, 161, 116, 163, 116])); + } }; exports.input = function(options) { options = options||{}; + let input_mode = exports.INPUT_MODE_ALPHA; var text = options.text; if ("string"!=typeof text) text=""; -Bangle.strokes = {}; -exports.getStrokes( (id,s) => Bangle.strokes[id] = Unistroke.new(s) ); + function setupStrokes() { + Bangle.strokes = {}; + exports.getStrokes(input_mode, (id,s) => Bangle.strokes[id] = Unistroke.new(s) ); + } + setupStrokes(); var flashToggle = false; const R = Bangle.appRect; @@ -49,6 +103,9 @@ exports.getStrokes( (id,s) => Bangle.strokes[id] = Unistroke.new(s) ); var Rx2; var Ry1; var Ry2; + let flashInterval; + let shift = false; + let lastDrag; function findMarker(strArr) { if (strArr.length == 0) { @@ -101,51 +158,117 @@ exports.getStrokes( (id,s) => Bangle.strokes[id] = Unistroke.new(s) ); */ function show() { + if (flashInterval) clearInterval(flashInterval); + flashInterval = undefined; + g.reset(); - g.clearRect(R).setColor("#f00"); - var n=0; - exports.getStrokes((id,s) => { - var x = n%6; - var y = (n-x)/6; + g.setFont("6x8"); + g.clearRect(R); + let n=0; + exports.getStrokes(input_mode, (id,s) => { + let x = n%6; + let y = (n-x)/6; s = g.transformVertices(s, {scale:0.16, x:R.x+x*30-4, y:R.y+y*30-4}); g.fillRect(s[0]-1,s[1]-2,s[0]+1,s[1]+1); - g.drawPoly(s); + g.setColor("#f00").drawPoly(s); + switch(id) { + case 'SHIFT': + g.setBgColor(0).setColor("#00f").drawImage(atob("CgqBAfP4fh8D4fh+H4fh+HA="), R.x+x*30+20, R.y+y*30+20); + break; + case '\b': + case '\n': + case ' ': + break; + default: + g.setColor("#00f").drawString(shift ? id.toUpperCase() : id, R.x+x*30+20, R.y+y*30+20); + } n++; }); } + function isInside(rect, e) { + return e.x>=rect.x && e.x=rect.y && e.y<=rect.y+rect.h; + } + + function isStrokeInside(rect, stroke) { + for(let i=0; i < stroke.length; i+=2) { + if (!isInside(rect, {x: stroke[i], y: stroke[i+1]})) { + return false; + } + } + return true; + } + function strokeHandler(o) { //print(o); if (!flashInterval) flashInterval = setInterval(() => { flashToggle = !flashToggle; - draw(); + draw(false); }, 1000); - if (o.stroke!==undefined) { + if (o.stroke!==undefined && o.xy.length >= 6 && isStrokeInside(R, o.xy)) { var ch = o.stroke; if (ch=="\b") text = text.slice(0,-1); - else text += ch; - g.clearRect(R); + else if (ch==="SHIFT") { shift=!shift; Bangle.drawWidgets(); } + else text += shift ? ch.toUpperCase() : ch; } + lastDrag = undefined; + g.clearRect(R); flashToggle = true; - draw(); + draw(false); } + + // Switches between alphabetic and numeric input + function cycleInput() { + input_mode++; + if (input_mode > exports.INPUT_MODE_SYM) input_mode = 0; + shift = false; + setupStrokes(); + show(); + Bangle.drawWidgets(); + } + Bangle.on('stroke',strokeHandler); g.reset().clearRect(R); show(); draw(false); - var flashInterval; + + // Create Widget to switch between alphabetic and numeric input + WIDGETS.kbswipe={ + area:"tl", + width: 36, // 3 chars, 6*2 px/char + draw: function() { + g.reset(); + g.setFont("6x8:2x3"); + g.setColor("#f00"); + if (input_mode === exports.INPUT_MODE_ALPHA) { + g.drawString(shift ? "ABC" : "abc", this.x, this.y); + } else if (input_mode === exports.INPUT_MODE_NUM) { + g.drawString("123", this.x, this.y); + } else if (input_mode === exports.INPUT_MODE_SYM) { + g.drawString("?:$", this.x, this.y); + } + } + }; return new Promise((resolve,reject) => { - var l;//last event Bangle.setUI({mode:"custom", drag:e=>{ - if (l) g.reset().setColor("#f00").drawLine(l.x,l.y,e.x,e.y); - l = e.b ? e : 0; - },touch:() => { - if (flashInterval) clearInterval(flashInterval); - flashInterval = undefined; - show(); + "ram"; + if (isInside(R, e)) { + if (lastDrag) g.reset().setColor("#f00").drawLine(lastDrag.x,lastDrag.y,e.x,e.y); + lastDrag = e.b ? e : 0; + } + },touch:(n,e) => { + if (WIDGETS.kbswipe && isInside({x: WIDGETS.kbswipe.x, y: WIDGETS.kbswipe.y, w: WIDGETS.kbswipe.width, h: 24}, e)) { + // touch inside widget + cycleInput(); + } else if (isInside(R, e)) { + // touch inside app area + show(); + } }, back:()=>{ + delete WIDGETS.kbswipe; Bangle.removeListener("stroke", strokeHandler); if (flashInterval) clearInterval(flashInterval); Bangle.setUI(); diff --git a/apps/kbswipe/metadata.json b/apps/kbswipe/metadata.json index d4026c815..6b597a371 100644 --- a/apps/kbswipe/metadata.json +++ b/apps/kbswipe/metadata.json @@ -1,6 +1,6 @@ { "id": "kbswipe", "name": "Swipe keyboard", - "version":"0.04", + "version":"0.07", "description": "A library for text input via PalmOS style swipe gestures (beta!)", "icon": "app.png", "type":"textinput", diff --git a/apps/kbtouch/metadata.json b/apps/kbtouch/metadata.json index f6d6d5228..89d121d63 100644 --- a/apps/kbtouch/metadata.json +++ b/apps/kbtouch/metadata.json @@ -6,10 +6,11 @@ "type":"textinput", "tags": "keyboard", "supports" : ["BANGLEJS2"], - "screenshots": [{"url":"screenshot.png"}], + "screenshots": [{"url":"screenshot.png"}], "readme": "README.md", "storage": [ {"name":"textinput","url":"lib.js"}, {"name":"kbtouch.settings.js","url":"settings.js"} - ] + ], + "sortorder":-1 } diff --git a/apps/keytimer/ChangeLog b/apps/keytimer/ChangeLog new file mode 100644 index 000000000..c819919ed --- /dev/null +++ b/apps/keytimer/ChangeLog @@ -0,0 +1,2 @@ +0.01: New app! +0.02: Submitted to the app loader \ No newline at end of file diff --git a/apps/keytimer/app.js b/apps/keytimer/app.js new file mode 100644 index 000000000..7d235f9a8 --- /dev/null +++ b/apps/keytimer/app.js @@ -0,0 +1,27 @@ +Bangle.keytimer_ACTIVE = true; +const common = require("keytimer-com.js"); +const storage = require("Storage"); + +const keypad = require("keytimer-keys.js"); +const timerView = require("keytimer-tview.js"); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +//Save our state when the app is closed +E.on('kill', () => { + storage.writeJSON(common.STATE_PATH, common.state); +}); + +//Handle touch here. I would implement these separately in each view, but I can't figure out how to clear the event listeners. +Bangle.on('touch', (button, xy) => { + if (common.state.wasRunning) timerView.touch(button, xy); + else keypad.touch(button, xy); +}); + +Bangle.on('swipe', dir => { + if (!common.state.wasRunning) keypad.swipe(dir); +}); + +if (common.state.wasRunning) timerView.show(common); +else keypad.show(common); diff --git a/apps/keytimer/boot.js b/apps/keytimer/boot.js new file mode 100644 index 000000000..f202bcbdf --- /dev/null +++ b/apps/keytimer/boot.js @@ -0,0 +1,11 @@ +const keytimer_common = require("keytimer-com.js"); + +//Only start the timeout if the timer is running +if (keytimer_common.state.running) { + setTimeout(() => { + //Check now to avoid race condition + if (Bangle.keytimer_ACTIVE === undefined) { + load('keytimer-ring.js'); + } + }, keytimer_common.getTimeLeft()); +} \ No newline at end of file diff --git a/apps/keytimer/common.js b/apps/keytimer/common.js new file mode 100644 index 000000000..8c702de66 --- /dev/null +++ b/apps/keytimer/common.js @@ -0,0 +1,42 @@ +const storage = require("Storage"); +const heatshrink = require("heatshrink"); + +exports.STATE_PATH = "keytimer.state.json"; + +exports.BUTTON_ICONS = { + play: heatshrink.decompress(atob("jEYwMAkAGBnACBnwCBn+AAQPgAQPwAQP8AQP/AQXAAQPwAQP8AQP+AQgICBwQUCEAn4FggyBHAQ+CIgQ")), + pause: heatshrink.decompress(atob("jEYwMA/4BBAX4CEA")), + reset: heatshrink.decompress(atob("jEYwMA/4BB/+BAQPDAQPnAQIAKv///0///8j///EP//wAQQICBwQUCEhgyCHAQ+CIgI=")) +}; + +//Store the minimal amount of information to be able to reconstruct the state of the timer at any given time. +//This is necessary because it is necessary to write to flash to let the timer run in the background, so minimizing the writes is necessary. +exports.STATE_DEFAULT = { + wasRunning: false, //If the timer ever was running. Used to determine whether to display a reset button + running: false, //Whether the timer is currently running + startTime: 0, //When the timer was last started. Difference between this and now is how long timer has run continuously. + pausedTime: 0, //When the timer was last paused. Used for expiration and displaying timer while paused. + elapsedTime: 0, //How much time the timer had spent running before the current start time. Update on pause or user skipping stages. + setTime: 0, //How long the user wants the timer to run for + inputString: '0' //The string of numbers the user typed in. +}; +exports.state = storage.readJSON(exports.STATE_PATH); +if (!exports.state) { + exports.state = exports.STATE_DEFAULT; +} + +//Get the number of milliseconds until the timer expires +exports.getTimeLeft = function () { + if (!exports.state.wasRunning) { + //If the timer never ran, the time left is just the set time + return exports.setTime + } else if (exports.state.running) { + //If the timer is running, the time left is current time - start time + preexisting time + var runningTime = (new Date()).getTime() - exports.state.startTime + exports.state.elapsedTime; + } else { + //If the timer is not running, the same as above but use when the timer was paused instead of now. + var runningTime = exports.state.pausedTime - exports.state.startTime + exports.state.elapsedTime; + } + + return exports.state.setTime - runningTime; +} \ No newline at end of file diff --git a/apps/keytimer/icon.js b/apps/keytimer/icon.js new file mode 100644 index 000000000..a47eb21f8 --- /dev/null +++ b/apps/keytimer/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwcAkmSpICOggRPpEACJ9AgESCJxMBhu27dtARVgCIMBCJpxDmwRL7ARDgwRL4CWECJaoFjYRJ2ARFgYRJwDNGCJFsb46SIRgQAFSRAQHSRCMEAAqSGRgoAFRhaSKRgySKRg6SIRhCSIRhCSICBqSCRhSSGRhY2FkARPhMkCJ9JkiONgECCIOQCJsSCIOSCJuSCIVACBcECIdICJYOBCIVJRhYRFSRSMBCIiSKBwgCCSRCMCCIqSIRgYCFRhYCFSQyMEAQqSGBw6SIRgySKRgtO4iSJBAmT23bOIqSCRgvtCINsSQ4aEndtCINt2KSGIggOBCIW2JQlARgZECCIhKEpBEGCIpKEA==")) \ No newline at end of file diff --git a/apps/keytimer/icon.png b/apps/keytimer/icon.png new file mode 100644 index 000000000..7dcf44b88 Binary files /dev/null and b/apps/keytimer/icon.png differ diff --git a/apps/keytimer/img/pause.png b/apps/keytimer/img/pause.png new file mode 100644 index 000000000..ad31dadcf Binary files /dev/null and b/apps/keytimer/img/pause.png differ diff --git a/apps/keytimer/img/play.png b/apps/keytimer/img/play.png new file mode 100644 index 000000000..6c20c24c5 Binary files /dev/null and b/apps/keytimer/img/play.png differ diff --git a/apps/keytimer/img/reset.png b/apps/keytimer/img/reset.png new file mode 100644 index 000000000..7a317d097 Binary files /dev/null and b/apps/keytimer/img/reset.png differ diff --git a/apps/keytimer/keypad.js b/apps/keytimer/keypad.js new file mode 100644 index 000000000..a5edeb2f2 --- /dev/null +++ b/apps/keytimer/keypad.js @@ -0,0 +1,136 @@ +let common; + +function inputStringToTime(inputString) { + let number = parseInt(inputString); + let hours = Math.floor(number / 10000); + let minutes = Math.floor((number % 10000) / 100); + let seconds = number % 100; + + return 3600000 * hours + + 60000 * minutes + + 1000 * seconds; +} + +function pad(number) { + return ('00' + parseInt(number)).slice(-2); +} + +function inputStringToDisplayString(inputString) { + let number = parseInt(inputString); + let hours = Math.floor(number / 10000); + let minutes = Math.floor((number % 10000) / 100); + let seconds = number % 100; + + if (hours == 0 && minutes == 0) return '' + seconds; + else if (hours == 0) return `${pad(minutes)}:${pad(seconds)}`; + else return `${hours}:${pad(minutes)}:${pad(seconds)}`; +} + +class NumberButton { + constructor(number) { + this.label = '' + number; + } + + onclick() { + if (common.state.inputString == '0') common.state.inputString = this.label; + else common.state.inputString += this.label; + common.state.setTime = inputStringToTime(common.state.inputString); + feedback(true); + updateDisplay(); + } +} + +let ClearButton = { + label: 'Clr', + onclick: () => { + common.state.inputString = '0'; + common.state.setTime = 0; + updateDisplay(); + feedback(true); + } +}; + +let StartButton = { + label: 'Go', + onclick: () => { + common.state.startTime = (new Date()).getTime(); + common.state.elapsedTime = 0; + common.state.wasRunning = true; + common.state.running = true; + feedback(true); + require('keytimer-tview.js').show(common); + } +}; + +const BUTTONS = [ + [new NumberButton(7), new NumberButton(8), new NumberButton(9), ClearButton], + [new NumberButton(4), new NumberButton(5), new NumberButton(6), new NumberButton(0)], + [new NumberButton(1), new NumberButton(2), new NumberButton(3), StartButton] +]; + +function feedback(acceptable) { + if (acceptable) Bangle.buzz(50, 0.5); + else Bangle.buzz(200, 1); +} + +function drawButtons() { + g.reset().clearRect(0, 44, 175, 175).setFont("Vector", 15).setFontAlign(0, 0); + //Draw lines + for (let x = 44; x <= 176; x += 44) { + g.drawLine(x, 44, x, 175); + } + for (let y = 44; y <= 176; y += 44) { + g.drawLine(0, y, 175, y); + } + for (let row = 0; row < 3; row++) { + for (let col = 0; col < 4; col++) { + g.drawString(BUTTONS[row][col].label, 22 + 44 * col, 66 + 44 * row); + } + } +} + +function getFontSize(length) { + let size = Math.floor(176 / length); //Characters of width needed per pixel + size *= (20 / 12); //Convert to height + // Clamp to between 6 and 20 + if (size < 6) return 6; + else if (size > 20) return 20; + else return Math.floor(size); +} + +function updateDisplay() { + let displayString = inputStringToDisplayString(common.state.inputString); + g.clearRect(0, 24, 175, 43).setColor(storage.readJSON('setting.json').theme.fg2).setFontAlign(1, -1).setFont("Vector", getFontSize(displayString.length)).drawString(displayString, 176, 24); +} + +exports.show = function (callerCommon) { + common = callerCommon; + g.reset(); + drawButtons(); + updateDisplay(); +}; + +exports.touch = function (button, xy) { + let row = Math.floor((xy.y - 44) / 44); + let col = Math.floor(xy.x / 44); + if (row < 0) return; + if (row > 2) row = 2; + if (col < 0) col = 0; + if (col > 3) col = 3; + + BUTTONS[row][col].onclick(); +}; + +exports.swipe = function (dir) { + if (dir == -1) { + if (common.state.inputString.length == 1) common.state.inputString = '0'; + else common.state.inputString = common.state.inputString.substring(0, common.state.inputString.length - 1); + + common.state.setTime = inputStringToTime(common.state.inputString); + + feedback(true); + updateDisplay(); + } else if (dir == 0) { + EnterButton.onclick(); + } +}; \ No newline at end of file diff --git a/apps/keytimer/metadata.json b/apps/keytimer/metadata.json new file mode 100644 index 000000000..a982594f1 --- /dev/null +++ b/apps/keytimer/metadata.json @@ -0,0 +1,44 @@ +{ + "id": "keytimer", + "name": "Keypad Timer", + "version": "0.02", + "description": "A timer with a keypad that runs in the background", + "icon": "icon.png", + "type": "app", + "tags": "tools", + "supports": [ + "BANGLEJS2" + ], + "allow_emulator": true, + "storage": [ + { + "name": "keytimer.app.js", + "url": "app.js" + }, + { + "name": "keytimer.img", + "url": "icon.js", + "evaluate": true + }, + { + "name": "keytimer.boot.js", + "url": "boot.js" + }, + { + "name": "keytimer-com.js", + "url": "common.js" + }, + { + "name": "keytimer-ring.js", + "url": "ring.js" + }, + { + "name": "keytimer-keys.js", + "url": "keypad.js" + }, + { + "name": "keytimer-tview.js", + "url": "timerview.js" + } + ] +} \ No newline at end of file diff --git a/apps/keytimer/ring.js b/apps/keytimer/ring.js new file mode 100644 index 000000000..c42c11394 --- /dev/null +++ b/apps/keytimer/ring.js @@ -0,0 +1,28 @@ +const common = require('keytimer-com.js'); + +Bangle.loadWidgets() +Bangle.drawWidgets() + +Bangle.setLocked(false); +Bangle.setLCDPower(true); + +let brightness = 0; + +setInterval(() => { + Bangle.buzz(200); + Bangle.setLCDBrightness(1 - brightness); + brightness = 1 - brightness; +}, 400); +Bangle.buzz(200); + +function stopTimer() { + common.state.wasRunning = false; + common.state.running = false; + require("Storage").writeJSON(common.STATE_PATH, common.state); +} + +E.showAlert("Timer expired!").then(() => { + stopTimer(); + load(); +}); +E.on('kill', stopTimer); \ No newline at end of file diff --git a/apps/keytimer/timerview.js b/apps/keytimer/timerview.js new file mode 100644 index 000000000..48c896ba0 --- /dev/null +++ b/apps/keytimer/timerview.js @@ -0,0 +1,107 @@ +let common; + +function drawButtons() { + //Draw the backdrop + const BAR_TOP = g.getHeight() - 24; + g.setColor(0, 0, 1).setFontAlign(0, -1) + .clearRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .fillRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .setColor(1, 1, 1) + .drawLine(g.getWidth() / 2, BAR_TOP, g.getWidth() / 2, g.getHeight()) + + //Draw the buttons + .drawImage(common.BUTTON_ICONS.reset, g.getWidth() / 4, BAR_TOP); + if (common.state.running) { + g.drawImage(common.BUTTON_ICONS.pause, g.getWidth() * 3 / 4, BAR_TOP); + } else { + g.drawImage(common.BUTTON_ICONS.play, g.getWidth() * 3 / 4, BAR_TOP); + } +} + +function drawTimer() { + let timeLeft = common.getTimeLeft(); + g.reset() + .setFontAlign(0, 0) + .setFont("Vector", 36) + .clearRect(0, 24, 176, 152) + + //Draw the timer + .drawString((() => { + let hours = timeLeft / 3600000; + let minutes = (timeLeft % 3600000) / 60000; + let seconds = (timeLeft % 60000) / 1000; + + function pad(number) { + return ('00' + parseInt(number)).slice(-2); + } + + if (hours >= 1) return `${parseInt(hours)}:${pad(minutes)}:${pad(seconds)}`; + else return `${parseInt(minutes)}:${pad(seconds)}`; + })(), g.getWidth() / 2, g.getHeight() / 2) + + if (timeLeft <= 0) load('keytimer-ring.js'); +} + +let timerInterval; + +function setupTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + } + setTimeout(() => { + timerInterval = setInterval(drawTimer, 1000); + drawTimer(); + }, common.timeLeft % 1000); +} + +exports.show = function (callerCommon) { + common = callerCommon; + drawButtons(); + drawTimer(); + if (common.state.running) { + setupTimerInterval(); + } +} + +function clearTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + timerInterval = undefined; + } +} + +exports.touch = (button, xy) => { + if (xy.y < 152) return; + + if (button == 1) { + //Reset the timer + let setTime = common.state.setTime; + let inputString = common.state.inputString; + common.state = common.STATE_DEFAULT; + common.state.setTime = setTime; + common.state.inputString = inputString; + clearTimerInterval(); + require('keytimer-keys.js').show(common); + } else { + if (common.state.running) { + //Record the exact moment that we paused + let now = (new Date()).getTime(); + common.state.pausedTime = now; + + //Stop the timer + common.state.running = false; + clearTimerInterval(); + drawTimer(); + drawButtons(); + } else { + //Start the timer and record when we started + let now = (new Date()).getTime(); + common.state.elapsedTime += common.state.pausedTime - common.state.startTime; + common.state.startTime = now; + common.state.running = true; + drawTimer(); + setupTimerInterval(); + drawButtons(); + } + } +}; \ No newline at end of file diff --git a/apps/kitchen/ChangeLog b/apps/kitchen/ChangeLog index 3767a9548..4e8c49c50 100644 --- a/apps/kitchen/ChangeLog +++ b/apps/kitchen/ChangeLog @@ -11,3 +11,4 @@ 0.11: Detect when waypoints.json is not present, error E-WPT 0.12: Added stepo2 as a replacement for stepo and digi 0.13: Added long press BTN2 toggle gpsrec status in GPS clock +0.14: Move waypoints.json (and editor) to 'waypoints' app diff --git a/apps/kitchen/README.md b/apps/kitchen/README.md index 102881d15..3049d9c6d 100644 --- a/apps/kitchen/README.md +++ b/apps/kitchen/README.md @@ -60,7 +60,7 @@ The following buttons depend on which face is currently in use ![](screenshot_stepo.jpg) - now replaced by Stepo2 but still available if you install manually -- Requires one of the pedominter widgets to be installed +- Requires one of the pedominter widgets to be installed - Displays the time in large font - Display current step count in a doughnut gauge - Show step count in the middle of the doughnut gauge @@ -208,14 +208,8 @@ which will obviously limit this. ### Waypoint Editor -Clicking on the download icon of gpsnav in the app loader invokes the -waypoint editor. The editor downloads and displays the current -`waypoints.json` file. Clicking the `Edit` button beside an entry -causes the entry to be deleted from the list and displayed in the -edit boxes. It can be restored - by clicking the `Add waypoint` -button. A new markable entry is created by using the `Add name` -button. The edited `waypoints.json` file is uploaded to the Bangle by -clicking the `Upload` button. +Clicking on the download icon of `Waypoints` in the app loader invokes the +waypoint editor. See the `Waypoints` app for more information. ### Calibration of the Compass diff --git a/apps/kitchen/kitchen.app.js b/apps/kitchen/kitchen.app.js index 5564b2807..2c2cebaef 100644 --- a/apps/kitchen/kitchen.app.js +++ b/apps/kitchen/kitchen.app.js @@ -23,7 +23,7 @@ function nextFace(){ iface += 1 iface = iface % FACES.length; face = FACES[iface](); - + g.clear(); g.reset(); face.init(gpsObj, swObj, hrmObj, tripObject); @@ -64,7 +64,7 @@ function buttonReleased(btn) { clearInterval(pressTimer); pressTimer = undefined; } - + if ( dur >= 1.5 ) { switch(btn) { case 1: @@ -165,11 +165,11 @@ GPS.prototype.getLastFix = function() { GPS.prototype.determineGPSState = function() { this.log_debug("determineGPSState"); gpsPowerState = Bangle.isGPSOn(); - + //this.log_debug("last_fix.fix " + this.last_fix.fix); //this.log_debug("gpsPowerState " + this.gpsPowerState); //this.log_debug("last_fix.satellites " + this.last_fix.satellites); - + if (!gpsPowerState) { this.gpsState = this.GPS_OFF; this.resetLastFix(); @@ -178,9 +178,9 @@ GPS.prototype.determineGPSState = function() { } else { this.gpsState = this.GPS_SATS; } - + this.log_debug("gpsState=" + this.gpsState); - + if (this.gpsState !== this.GPS_OFF) { if (this.listenerCount === 0) { Bangle.on('GPS', processFix); @@ -196,9 +196,9 @@ GPS.prototype.determineGPSState = function() { } }; -GPS.prototype.getGPSTime = function() { +GPS.prototype.getGPSTime = function() { var time; - + if (this.last_fix !== undefined && this.last_fix.time !== undefined && this.last_fix.time.toUTCString !== undefined && (this.gpsState == this.GPS_SATS || this.gpsState == this.GPS_RUNNING)) { time = this.last_fix.time.toUTCString().split(" "); @@ -216,7 +216,7 @@ GPS.prototype.toggleGPSPower = function() { this.gpsPowerState = Bangle.isGPSOn(); this.gpsPowerState = !this.gpsPowerState; Bangle.setGPSPower((this.gpsPowerState ? 1 : 0), 'kitchen'); - + this.resetLastFix(); this.determineGPSState(); @@ -247,11 +247,11 @@ GPS.prototype.processFix = function(fix) { //this.log_debug("GPS:processFix()"); //this.log_debug(fix); this.last_fix.time = fix.time; - + if (this.gpsState == this.GPS_TIME) { this.gpsState = this.GPS_SATS; } - + if (fix.fix) { //this.log_debug("Got fix - setting state to GPS_RUNNING"); this.gpsState = this.GPS_RUNNING; @@ -271,10 +271,10 @@ GPS.prototype.formatTime = function(now) { GPS.prototype.timeSince = function(t) { var hms = t.split(":"); var now = new Date(); - + var sn = 3600*(now.getHours()) + 60*(now.getMinutes()) + 1*(now.getSeconds()); var st = 3600*(hms[0]) + 60*(hms[1]) + 1*(hms[2]); - + return (sn - st); }; @@ -313,7 +313,7 @@ GPS.prototype.getWPdistance = function() { GPS.prototype.getWPbearing = function() { //log_debug(this.last_fix); //log_debug(this.wp_current); - + if (this.wp_current.name === "E-WPT" || this.wp_current.name === "NONE" || this.wp_current.lat === undefined || this.wp_current.lat === 0) return 0; else @@ -321,7 +321,7 @@ GPS.prototype.getWPbearing = function() { } GPS.prototype.loadFirstWaypoint = function() { - var waypoints = require("Storage").readJSON("waypoints.json")||[{name:"E-WPT"}]; + var waypoints = require("waypoints").load(); this.wp_index = 0; this.wp_current = waypoints[this.wp_index]; log_debug(this.wp_current); @@ -345,10 +345,10 @@ GPS.prototype.markWaypoint = function() { return; log_debug("GPS::markWaypoint()"); - - var waypoints = require("Storage").readJSON("waypoints.json")||[{name:"E-WPT"}]; + + var waypoints = require("waypoints").load(); this.wp_current = waypoints[this.wp_index]; - + if (this.waypointHasLocation()) { waypoints[this.wp_index] = {name:this.wp_current.name, lat:0, lon:0}; } else { @@ -356,12 +356,12 @@ GPS.prototype.markWaypoint = function() { } this.wp_current = waypoints[this.wp_index]; - require("Storage").writeJSON("waypoints.json", waypoints); + require("waypoints").save(waypoints); log_debug("GPS::markWaypoint() written"); } GPS.prototype.nextWaypoint = function(inc) { - var waypoints = require("Storage").readJSON("waypoints.json")||[{name:"E-WPT"}]; + var waypoints = require("waypoints").load(); this.wp_index+=inc; if (this.wp_index>=waypoints.length) this.wp_index=0; if (this.wp_index<0) this.wp_index = waypoints.length-1; @@ -520,7 +520,7 @@ function STOPWATCH() { this.redrawLaps = true; this.redrawTime = true; } - + STOPWATCH.prototype.log_debug = function(o) { //console.log(o); } @@ -531,7 +531,7 @@ STOPWATCH.prototype.timeToText = function(t) { let secs = Math.floor(t/1000)%60; let text; - if (hrs === 0) + if (hrs === 0) text = ("0"+mins).substr(-2) + ":" + ("0"+secs).substr(-2); else text = (""+hrs) + ":" + ("0"+mins).substr(-2) + ":" + ("0"+secs).substr(-2); @@ -551,7 +551,7 @@ STOPWATCH.prototype.stopStart = function() { if (this.running) this.tStart = Date.now() + this.tStart - this.tCurrent; - + this.tTotal = Date.now() + this.tTotal - this.tCurrent; this.tCurrent = Date.now(); this.redrawButtons = true; @@ -623,7 +623,7 @@ STOPWATCH.prototype.drawLaptimes = function() { g.setFont("Vector",24); g.setFontAlign(-1,-1); g.clearRect(4, 205, 239, 229); // clear the last line of the lap times - + let laps = 0; for (let i in this.lapTimes) { g.drawString(this.lapTimes.length-i + ": " + this.timeToText(this.lapTimes[i]), 4, this.timeY + 40 + i*24); @@ -645,7 +645,7 @@ STOPWATCH.prototype.drawTime = function() { g.setFont("Vector",38); g.setFontAlign(0,0); g.clearRect(0, this.timeY-21, 200, this.timeY+21); - g.setColor(0xFFC0); + g.setColor(0xFFC0); g.drawString(txtTotal, xTotal, this.timeY); // current lap time @@ -691,7 +691,7 @@ function HRM() { this.bpm = 0; this.confidence = 0; } - + HRM.prototype.log_debug = function(o) { //console.log(o); } @@ -782,7 +782,7 @@ Debug Object function DEBUG() { this.logfile = require("Storage").open("debug.log","a"); } - + DEBUG.prototype.log = function(msg) { let timestamp = new Date().toString().split(" ")[4]; let line = timestamp + ", " + msg + "\n"; diff --git a/apps/kitchen/metadata.json b/apps/kitchen/metadata.json index ab2e7183c..9c9f7b2ec 100644 --- a/apps/kitchen/metadata.json +++ b/apps/kitchen/metadata.json @@ -1,14 +1,14 @@ { "id": "kitchen", "name": "Kitchen Combo", - "version": "0.13", + "version": "0.14", "description": "Combination of the Stepo, Walkersclock, Arrow and Waypointer apps into a multiclock format. 'Everything but the kitchen sink'", "icon": "kitchen.png", "type": "clock", "tags": "tool,outdoors,gps", "supports": ["BANGLEJS"], "readme": "README.md", - "interface": "waypoints.html", + "dependencies" : { "waypoints":"type" }, "storage": [ {"name":"kitchen.app.js","url":"kitchen.app.js"}, {"name":"stepo2.kit.js","url":"stepo2.kit.js"}, @@ -16,6 +16,5 @@ {"name":"gps.kit.js","url":"gps.kit.js"}, {"name":"compass.kit.js","url":"compass.kit.js"}, {"name":"kitchen.img","url":"kitchen.icon.js","evaluate":true} - ], - "data": [{"name":"waypoints.json","url":"waypoints.json"}] + ] } diff --git a/apps/kitchen/waypoints.html b/apps/kitchen/waypoints.html deleted file mode 100644 index d02260732..000000000 --- a/apps/kitchen/waypoints.html +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - -

List of waypoints

- - - - - - - - - - - - -
NameLat.Long.Actions
-
-

Add a new waypoint

-
-
-
- -
-
- -
-
- -
-
-
-
- -
-
- -
-
-
-
- - - - - - - diff --git a/apps/kitchen/waypoints.json b/apps/kitchen/waypoints.json deleted file mode 100644 index 98a670c0d..000000000 --- a/apps/kitchen/waypoints.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "name":"NONE" - }, - { - "name":"No10", - "lat":51.5032, - "lon":-0.1269 - }, - { - "name":"Stone", - "lat":51.1788, - "lon":-1.8260 - }, - { "name":"WP0" }, - { "name":"WP1" }, - { "name":"WP2" }, - { "name":"WP3" }, - { "name":"WP4" } -] \ No newline at end of file diff --git a/apps/lato/README.md b/apps/lato/README.md new file mode 100644 index 000000000..556ee6fbc --- /dev/null +++ b/apps/lato/README.md @@ -0,0 +1,54 @@ +# Lato + +A simple clock with the Lato font, with fast load and clock_info + +![](screenshot1.png) +![](screenshot2.png) +![](screenshot3.png) + +This clock is a Lato version of Simplest++. Simplest++ provided the +smallest example of a clock that supports 'fast load' and 'clock +info'. Lato takes this one step further and adds the lovely Lato +font. The clock is derived from Simplest++ and inspired by the +Pastel Clock. + +## Usage + +* When the screen is unlocked, tap at the bottom of the csreen on the information text. + It should change color showing it is selected. + +* Swipe up or down to cycle through the info screens that can be displayed + when you have finished tap again towards the centre of the screen to unselect. + +* Swipe left or right to change the type of info screens displayed (by default + there is only one type of data so this will have no effect) + +* Settings are saved automatically and reloaded along with the clock. + +## About Clock Info's + +* The clock info modules enable all clocks to add the display of information to the clock face. + +* The default clock_info module provides a display of battery %, Steps, Heart Rate and Altitude. + +* Installing the [Sunrise ClockInfo](https://banglejs.com/apps/?id=clkinfosunrise) adds Sunrise and Sunset times into the list of info's. + + +## References + +* [What is Fast Load and how does it work](http://www.espruino.com/Bangle.js+Fast+Load) + +* [Clock Info Tutorial](http://www.espruino.com/Bangle.js+Clock+Info) + +* [How to load modules through the IDE](https://github.com/espruino/BangleApps/blob/master/modules/README.md) + + +## With Thanks + +* Gordon for support +* David Peer for his work on BW Clock + + +Written by: [Hugh Barney](https://github.com/hughbarney) For support +and discussion please post in the [Bangle JS +Forum](http://forum.espruino.com/microcosms/1424/) diff --git a/apps/lato/app.js b/apps/lato/app.js new file mode 100644 index 000000000..6045d7f17 --- /dev/null +++ b/apps/lato/app.js @@ -0,0 +1,138 @@ +/** + * + * Lato Clock + * + * The entire clock code is contained within the block below this + * supports 'fast load' + * + * To add support for clock_info_supprt we add the code marked at [1] and [2] + * + */ + +Graphics.prototype.setFontLato = function(scale) { + // Actual height 50 (54 - 5) + this.setFontCustom( + E.toString(require('heatshrink').decompress(atob('ADkD8AHFg/wA4sP/AHVD44HHgPALD0OA40+F43+H4wHGn/8A4v/L4sH/5PFj//CxkD/6eFCw9/GooWHh//wAWLgP/TgoWHn5rFCw41BMYqCHaRDKGgzLYKAJgFv//LIhQBAAI7DWgIABU4adBAAJTDn4HCVAaOCQQhvDAYQuBDYaxBgJEDh4HBgYzDPgUDIYYECA5DUDgIHBg4HEEgIHfF44/EA45HDL4xvHP46PHT5CvHX47PDGYcDb4zvHf5AA/AA9wA4yoDZYq/DXAgHDXYQHEXYQHEj4HHXYQHDn6UCA4d/e4sAXYYHCd4gHCXwbADA86DFA/4HGAGA3Db40HA4UDe40Hc4YHCh7nDA4UfA4X/A4U/A4b/Cv7vGX4UB/A+CZ4YaCgf9A4sH+IHCHwfjA4JWDj/DA4s/wYHFv4kCA4f+A4pKBA4sD/AHCG4R9BA4YCBj/gA4s/4AECN4R5BA4f/gf/Mgn///+A4wZBA4d//6JBA4c/VATHEVASUEEwIHEAAbnDAGbyCAAg+DgKwDA4S4DLQSlCSYQHCn4HDFAV/bAX/4ADFCYgbCh4zHZ4SlBR4iSEA46XCe4QHCDgJWCngHOnwHGvwHRG4iFBI4ppBA4f4OIRnCN4MD9+AO4f///v8CHCDoP/54CBS4f/44CBU4f/wYHBX4f/EQLHDh6gB/6jDZQaTDAEUcA40/A4xODYoYHGgYHGh4HGNIIuG74uGz4uGj4uF/gHFh/4A4sf+AHFn/AA4q0BA4kBVgIHEFwIHFFwIHFj7jBA4guBA4rjCA4YuCA4guCA4r0BAATgBA75SEa4wHvAEEBA40DUYIAEg4HDgZ0Bh67BXAQHCZYJMBA4UHA4KPCA4SXEAgQHL4IEBgIHC/AMCgP4CQUDFgIHoIQY3DA4wCEDggHFO4YHB/iHDCQX+gE/S4IHCOIP/U4IHCv6CBA4k/A4K1CEQKpBEIIHDh//HILSDTQK+CAAd/f64Amn4GFgLxCAAZfBSIIADN4heDP4YeDR4Z5CEwN/U4IABg4NBj6ADEwLHDIoQtBVgQuCHoIHDFwIHBe4QLB/14A4kH/i1BeQQuB/AHFn/wA4pLBA4guBwAHELoMAA4o9BA4Q3BgYFBJ4gCCA4pqBvxvDf4T2Bh4HCIIc/R4MCKISfBS4aQCU4gHDX4ioBY4paBNwQAD/6uDAAUOf4wAjO4QHNdQYHYmAHGW4gUEA4kPA4z7BA4v/A4qYBY4QHCh63CA4c/V4QHDV4Y6DV4YHCDwYHDDwYHDv7ODA4MBZwgHBcwL1DA4MfdogHBDwgHB+LtFgf3DwhMCDwgHCDwhcFA4geEA4IeFA4IeFd5AArj77EsCgB/gGCg5QBOQkf/6oB/77D//DA4JrCv//44HB4DkC//n/E/MgIcCRIMPA4X8RIUHegQCBFoL8DA4cBA4QaBv4HGvwHBTgMHHQM+HgIHhF44HFJ5RfGN45/Bz6NBP4SPHT4XnT4ivHX47PHgCQCb4bvIAHxdBMgRfD/58CKgf/WgIADP4JlFR4J1ET4QHCiACBQwQEBuC/CDIIHBX4QtBn+Aa4sfZ4bvCh+Ah4HGUAUHA4d/AgIHEa4QHDwJyCA4eDKIQHDx5pCA4bPDG4c/RIRPCjwuCA4aJBUwZnCRAcBP4SgE/+D/7+ET4ImDA4jIEX4KvFh7HGgbXGgF+f6oAggZeBSgShEb4RYCagQHGh5iDA5QXEE443HADoA=='))), + 46, + atob("DhglJSUlJSUlJSUlEA=="), + 64+(scale<<8)+(1<<16) + ); + return this; +} + + +Graphics.prototype.setFontLatoSmall = function(scale) { + // Actual height 25 (24 - 0) + this.setFontCustom( + E.toString(require('heatshrink').decompress(atob('ADE//lwj/+nEP/kcDCGAgEfAQIAFgfwgEB/AZIggCB4YCBsO8gEz/0Av/8gP/DgP+jAiBhvggO/+ED//gh/9wEH+HAgEYsEAhhMJkEB8E4gf4h0B70HgPDgOA4P//f///9//4mEYjk4h0PnkDgZEBwH8FhMfAQXAiEYDoMMjE8g0MDwOOnBgBvEAnwCBgFwAQJsBgHn8ACBGIPjg0B4ODgPA4OA4FxNoIvBgEHAQIAGVIMBTAM4/6bB8PAv/gsE4+BmCJQMHhgvB50D4F2gHgLwMwh7eCFwM+JwJhBZwgAHGwMAvwNJe4QCBv4TBVYPB/EB/J0Bj1AgECC4rZC8/AgfxDAPgn//4BsCABECEQMBkCkDCgaBBGQICBhJhCwAgIUgVgAQMwAQJ4CIoMB/4pB/6uCD4QYLABMHJgMDJgT0CO48GSogxMAA0cAQMOGIQMFVoMBAQMHAQMPEoM/agcBMoJIDGYTWDTIMHXQMH4H4g+Aj0DwEHJgIBBDAPAJgNgnEAuEPXgIeBSoQCBj49BABYjBjA+BhgCBgwCBga3B/+AAQPAv5EBZZIAK4CKB8D5B+ACB/CQB9iwB8ywB8Y9B8OA8Hg4E/8FgKwMwPILkLhA/BWgM8gY0CuACBnEMAAMGAAMDg5jB4eDMYPjGIO/4EPx6dBeAYACAoTZCZATOBgPMAQPGZQPDAQOBwDEBSYKPBSoyLDOgIAJjixB/4gB/+B4FxwFgmHAmEYsEYhk4CYMcjhjB/0BwP+D4N8FZSFBgEHLQMPCoMPPgMPGIMe4FgjwzBjwzBhwuBgkPToMDFwQCCBAIAFe4prBgTgBg6gBh6EBj8AsE+gEwKAMYIYMNUgMHVQJPCXIwADEIMH5/gg///EHj0OcAeDDQPBGYNgAIM4+Fwh/8vEH841B8ICBABZBCh4RBg57Bg8HGIMBx4vB58A4FvgFwv0AngCBGIJdBAQIMBFY8CgGAcoPggPACAJPBCQ0ICYI2B2CaB+A4BExBUCcwSTBgZaBgOwAQPcBgPGAQPjB4KGBJQIkBdIJ/MAAczAQMZDwMMDwMGsA0BmAxBzAPB5gCBswYKAB7QBI4ICBjhNBgwuBge4B4PYAQN8AQMcAQMOUoYAJDoMAVIUYhk4hkPjkGh6pBxxcB/wPBbIJTBD4s/LQN/foN4jyYBV4LVCmF+nEwv+MjFw80MuEjLIMw4cYmFhx/8mHH/0wseBzC2BxkGZAMB8bLBv40Bh6VBAAb0BPoIMCc4MfI4QLB/+Agf44ED+FggPgO4P8F4M/xgdBNoQYCg/wAwIJCh4xEPAv/+Ef//4h///kGAAMDAAMBwOBwHAAANgAAM4uFwj/8nEH+/4gPx/gmBvDHGgILBgZdBg//8BuB/CpBjgCBg8BNAOA8AEBsC0CcoL4BnD4BjkHaoIQBA4NAUwIAIMYo3B/0DH4J6BAIKmBGIydBjAxEhwxDf4SPBUgKhCOQQAHN4P/gICBwACBSocwAAMYAAMMAAKuKJQIsJAAJjDGIrGBMIJkBGAJhBMgIwBgAwBJQJ9Be47KEEoOAFYPwgPgvB8CY41wSo5hBhkHgZjBwOHLwIlBuF/wEQn45IMZR7DMYIwBAQIyBMgICBeQRjBMggYBv//8DNB+D5CTxcAY4QYFCpgyDPgIGB8ACBQIMAvEPGgJjB/hjBHRpKCDAP8PgRjGXAIIBEIMD7wCB47HB4HgAQM8YQMPC4IEBSwkgGgoxFVwSWHV6QAEVxEHEYR4Cj4aCRwQJGCYIWCAQUPIYIOCnwCBvgxKcCsHUIgoDh5AEgDyCjwCBCwiVKABH8C4P/XgI3BDoN8gPAhwCBY4PgAgNwgHgVgMwVgMYh0AjkHgEOCYIEB8ACBnhRBOwIrCGgN+H5I9BCQJ8FF4bcBhjcBgzcBgb1BgPBPgPxAQM/RgMPAQJSBFgkfQoM/R4N//xKCwE4CYM4gFwjkAnBjCGYx8ICoP4g+BVAXzwF/8C1B4CLBAA75FY4RjGwBXBF4VgR4M4m+Ah/5UYP4nkB/BPBDQIqCNQIABZ4Q9BIAPwMYM4Y4MOGYMHGYOBwJjB8IzBvPgjEf8EMg6ZBE4J8BF4ZKBAYKkCsACBNoRjFg//QQIYOcQIAGTYPwfILHBfgTbEQYKBBAQL9BY4ICBg4dCCoICCg/AVwPAJQKCBE4IxDJQRuCBYUfGAMD/DLCEIXwAwK7BgEPCYQMBv4cDDASuBAQIoBg5CCPgoqCv4GBj/8AwJKBDIIGCGIU/BgQfBBYIrCn4UBj5CCGIMDLQU/AwxhCBIIcD8ClBwEHKwimDAANAY4NgVIPwGIPwgfBDwP5EgMfNQQtEJoUH74CBwfgh+A/B8Bjx8BgcBFwOAP4TbCnhgCdAStCvgJCPIJUCAQPAB4Q3CHoUPAQKuGMQYABMYUwMAMYXIMMgP8g0B+xIB8cBwfhwHD4HAs/AsE34EwdYMYJoMMg8AgxjCGAoADv///8/AQOYBAPMAQNkAQMQfhDdCgZ5CnwCBg5tBQAgXCBITLBC4JmBgIxC543B84CBEYQAKkC4EewQWBgIsCAQTEGBIQ1BABcMAQMGMQRvFZIK9CEAa9BDAwMDjh7CD4oANLYMw/gpBvwfBsYsBmOAg0Y4EDhlggPmIAN/O4MfDAIALTwPgcAIuBuBMBmBWBmBWBjBvBhhPBg8BGIP3OQIbBgE/PAQAEgY6Bgf/AQPvwEDwHgEAIuB4CIBsAxEjiBBgykCAAouCv5NBn18gE4hxKGEAJKBXoXA8E///4j//Phf+PoS5B/pjB804gFjJQMxwwxB4YxBsJ8BmPAgP4GIN8d4QABoDnEUoICCwACB4DPBE4IzBZ4IZCgUAh0T4EP3/wh//jEGmeMgcI40BwwdB4wdBu4dBn+O8Efw/gPgPgEYKXHPgqzBMAICESoLKBAQLlBLQTXBn4YBgaMCAAhcBgHjewNx//wnAYCAAliAQMzx///PHB4IYBbQIAHOoP+g6VCgCkCXoLwBAQN/HIN5ZQN4BgMwfIMQLYRJDAAd/GgL5PHAPAgZjBgB8CAQRACcAUcKIeAgIYBAQPgSoYYIj4uDDAY+JZwauBKILEDY4xrCEAVwDAhHBagR8GB4IIBn5pBnzKBnCVBjApBhgpBGIJ8BLYJjBFgN/ZoMfAQMHaZJKBagJpBHwNgO4Nghh8BFIIxFg4sBDAJeBAQUfQo8DZoKVBAoPnDAOAVwOAFwPAjAxEAQMMMwJ/B/AbBdpSuIg6rEGIKuHcAQACg+GAQPDMYPwJQMYSoOOJQPHJQNhHoM4AQMIngeDgg0FPgJWB+BWDSoxFBA4LjDVwIFBDALKBN4R5BFIZbJAQKIBDAgAEhBpCDQMDdgV/AQMP8ADBDAUeTIQCBTYMBE4IYCcoILBHgQ5CnwCBj4hBgIYBeAcBBIKcBBAY3CSIUfIgQ6Cn4YEGoUPPgQLBGIS2BAASVCY4OB8EB+IbBn4CBh4YBgYCCLoMH7wCBw4YBwAYBgEQEwdAJRHwS4N+BQMPQYRUBJoUHGgJpCj7MEfITgDwFwKQN4SoN8fIP2MYPzfIPhwAkBJQPgsCuBmAYBOghUBgHB4OB///+P/7/8HgMGYAMDkDJEABEDDYP9AQLOCABJcCmYCBjPHx8cDAP8j4CBGwIaIH4MAOQICDL4LUDRIUHQwYDBLYMATwMAUgIbDAA8gS4NwnEAvAnBv8MgH+4kA/MygP4zsB+FOwfwl1D8EUk/ghkX4EEh/AgUHWAL8BgOBwEDIQUAnEGgUYh8BxEPwF0j9Aj0fkEPn0Qh2+hEOvkEgk8gRvBgZtCXRYANg8f/kDz/+gPD/4WNdwTcBgP/LgPgT4PgRoNgRQM/BgLXB4F8WoLWB4AEBDAOAagQAEMQMARQIrBweAeYPAEgPgAoMwjkYjEMAAMGAAIXBgcB4KjBbgPAIQT9EAA8wbwJ4BPgICBgeOHQQPB4KhBsBTBnBsBj/wgEd7kAHgIqJPQInBwMggPwyEAn1IBIPkBoJjBgF/EoP//EB/VAgfxkED8GQgPADALhOj/4v/v/k/EoIALjhsBz6SB//Dwf88HBx04sHHhkwsPHjEw8f8jk//kEh+8EYpKBAYJeBgCxBAAcIAQMOPgQVCDgsH/ACBx4SBEYMGnEwg1/zECv/mgdwucB2EcwGYg1ApkDkE2gOQjeBzEE4HMgazC4ACBmA8Bh88OYLjBAAsIK4MMSAMGtARBkhQByzGCUoS1MD4MBFYMD44FBxIWBj4OBn6KBniHBhCECABcwAQMYAQJcBJAICBM4IrBIISyCsACBnxOEh4MCAA6uJGoICBjEC//2gd//cB2PAVwNgVwM4kE3n0QjP77EEvHsIwMcVx50CL554CiBWEgYPBgbHBgYwBgOGBgPDAQNhVoQCBg7KIgw5BgY5BgOBCAPAFINgsED/+wgP/7CxBF4IYMAA8MK4MOnAaBPATABgP7B4N5I4VADAhzBDAdMDAMmDAP/B4N/DAMBbZKVE8ACETYQAGn//8Ef//wh//e4LzBWY8YJIQCDDALdB/6jGg4CCHAMHEwMHdgKeBLoQXB/40Bv///gvIg4PBwYCB8ICB8BIIbQgZCFYMDCYMBO4QAMgSzBgegAwPwAQKzBAA8QJoUggEcAwMPNIgjBDA8PIYMPIAMGKgMDhBJBwgPB9y6CAQMOJ5cOQgMDzwGBGoWcFgPhOAM9AQMHOwTAGLo0cLocILoMMLoMeLoM8PYl4Qgi2BUIPgU4PQgeB5ACB40BbwI4BHYY+DgjGCOwMHgkGgf+g75Bh4NBMwUcAQI9CHQVwAQPxw0B8PHgPA4+A4FnOAM+fYMOfY0DjACBwxFByIJB5gaBv/B8Ed8YeBgZQBg7LCVwkeX4M8hqBBjmAAQNgiDxCfYICBM4J2DgaQBgbIBgOOgPHwcA8fBwFx4A4BUAICBLQLDDEoR6C/weB/kgg/4jA3Bh0/xkDn8GgHegcAl4qBgf4FQM/FQIYBEIN/AQMPGgTbCGIRtBNwISEG4JZCfoMAj/GgHfLgPvNgPnfINh/lgmEfOQg7BT4QxCbAQxCGhkDGgMDz/GgOfGgPPGgNnGgM5GgMMGiaGBcIcfQwQFB/8B4P/gHH+IuDmfAsEN/Ewh1/jEGPgQYBTYjBBMAgxCeYYxBCQUf4JvBwPA/+A8bHBgfwsEB8EwgH8jDgCg8D/0BDAJmFRgIoBGIkAGIIgBCQY3Cn4LBv/AmKSBnpjBiXwjEPv0MgbgCgJmCDAUD/DEESoQxCTwsPBAMfAoM/C4l9BAJsBgJsHCIJfBn//IQMf/EMAAMGAAMDAAMBwOBwHAAANgAAMwAAIgBAIIAFVobABFYLCBg/AjkA8ACBnEOgEco5dB0ZjB6OAgO4DoPcuAVBnEAuAVBuECgBaBABEf//4h///nH//+sZaBnJaBxxZB4ZaGAAJzDgABBABaMCGIqMChYxBhoxBxgxB5wwBswwBmQxDgABBABf///Av//8G/GgPYDYPMJoNmGgMzGgMZGgOGGgPBMwaJLFw/nMYPzzAuBxjwHSoWcMYguJ4ACBsACBnIuBxwCB4ZgCIhgABgoVBwwCB4xKCBYMDAQMBCQUgAQI7CmYVBjICBxgbCCoWAAYNAAQI7CuACBiISBwB8FGIQYBgJgCGQcYAQLPBg///0DDYMBEISFB4CFDAALpDhCeBgCeBwEHFYIEBuACBj0HBQIhBEoI8Bn6JKj///EP//8IIUA+BJBnkAh0PwEGgPgSQN4GgMeYIMDJoIWBMoM8LQZ8EY5UfI4QyBv43BngyBnEB404gFzjjvB50Ajl2OYMbUIJzD8AEBXAPgCoPgg+BKIP/FYQ9Bh62DAAcB/AjB/64CDAPA/ApBjilFwQxB4ZwBsewgEzzhKBxxKBw6OBCoMORYKJBn4rCNIMA/h8V4G4gFw7kAnB8C8x8BuZYBjJKBwxKB4J8niZ8BjoxBxgxB4x8CmEAmBKFo58m475CVwIxDgx8BgZ8EzhKB5x8YAAUYhhbBLIMDcIMA9wCBnwCBBYIeBKYMOEgMOJYIYCgRFBABJsEwF///AvhBBdIU4gfwjkD3EOMQMGg5sBg8DPoK/B94VBvxpBUwPgj+B+EfNgMMNhzmD//8gP//8QOIOMBwPnAQNxKQMYoEAhkgO4cHAQh9BMAOAcwOAj7jIAAIxB/EAGgK6BPIILBKILgBGIMcGIMGmBEBUYMDzAdB5ACBDAMDOYJdBh4CBMYKxKv/+WII0BRIQxBnBjCGIMHAQMBGIMA5wCB8YCBuB8BuAFB/AxB/CVB/BjBVBQxBwBKB+AYB/gfBhxjCzhgDgFgAQMxAQM5BIMcQYMcBAM+GIJdBAQV/+AxDaILCEKIMBBwU+YwcBD4PhZAPxAQP54APB4F8gFAYYMBAQMADwRICRgIAGTwPwNgP4NgLtB4CaBsEYgEwhkAjEGJQMHJQMDIIPnJwKVCn7cCFw7gCTAQCB/BsCEwMMgcDg8BwfBwHD+HAue4sEfx1wh+D+EBwJkCFgw3Bh/AoOH8Ex40wjnDjEPsOMgOw40Aj1mLQLdBdpkAvBzBvxMBn52BmOAi0Y4E7hlgnOGmEY+cwhE/SoMPcAIAJgY0BNQMGsP4g1xxkHmHGgcYscBxgxBs+ZwEZSoMAv7YCABEeTgMfwFjPgNzxlgmJKBPgQ0BxkDnnMgeP/5DBPgIoKGgMw/kHPgMDzhKEgx8BkZ8C81gjl/YgMfPgIAJg6xBY4J8CjnjjEfJQMIY4MG7AxB98zJoSSBPgTKLhjKBh0/JQMw4CfBsBUBmEA404gFzAQMfKAMHKAMH94CBmIYIjAYBhgYBxwSB4w3BIwIADv4CCBIN9SoNwjlAmEHkEYgfQhkBdoMA7kDwAVB4FgRY4eBJQuHJQNjJQM5JQMOJQVjJQM5JQMPJQMD8aLHQoICBTYM/SQIYCjHDgHssOA8yVBGIUh5lwgF+P4MfGgIAFgJNBgP/gER/fAjIYBjhKBhhKBg0xw0DzAxBt1jwED+JEB/CcFAAMPJoMP/EDx/egPODAJKCY4oxCh1zjkCj+MY4gABF4MAVIU5//whn//ECv5aBABE3//Amf/8AYCO4UCAQMDAQUf/8Bx//wHnDAKNBgE4AQMcAQMEGIU//0Dz4YBOg0/AQN/8EQnhNBnEcg3Yg0D9g2B80BwFzgHAvnA8BQB8C3BcASeHAAUHJQMTCQM4CIMYAQMMQwMDK4MBzACB5wYB44YBFYcf+AoHBAMHNIMH78Aw5oBsawBnOAmEO4CXBsEMQwMOcYP+HAICBgACCAAsfJYI3Cj98T4MHKgJ8Bmx8BP4IxDiBoBPgP4FwICBgYCBAA1/AQQuBvvwg1wFgMwVwMYgcBxgxB8wxBmeAPgKrDAQMPAQIAFgJ/BSQMAmP34E54FwVwMYVwMMGISuBGIPOgeA4f/wAuBAQM/AQKuKgOHVwPnVwJ8CKQLYBGIMOGISuBgKuPYYMAgwCBgZgCHoMI4kAh1nHQJ9BgeZSoIYLABM/xACBRIM8boM4n0AjE7EgLYBXYPAgdwMYPwuEA/p2B/4CBs4CBQoxpC//AWgPwiAsBJgJ8BJwKNBJwoCBDAPgDARWJj/4dILdBg4uBBQLwCmEOLYICBhh+Bg0CQYQYBwAYEAA9/EIKCCz4uBJoOABQPAsDgBbwMwjgxBFIMYDAJzBj4YBABBjBNgJmBh1//h8BhwsBZY3AVINgnACBhH/OYIYBFA0IVwQaBgaRCv0BOAPHwA4B4eAn+DwAMBwAhBwYnBgZnBXYIbBHgTZF///+YCB/EDwInBwD5BwB+B4B5BsDiBnCzBj5/BewUAAQRrCAYRQDCIMP4EjwP4+PAn5IBg/wkAMBnEfwEcv8Agl8DYKGBgEQgA='))), + 32, + atob("BQkKDw8UEgYICAoPBQkFCQ8PDw8PDw8PDw8GBg8PDwoVERAREw8OEhMICxENFxMUDxQQDQ8SERkQEBAICQgPCggNDgwODQgNDgYGDQYVDg4ODgoLCQ4NEw0NDAgICA8AAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAADAAFCQ8PDw8IDQgUCQwPABQICg8ICAgOEQcICAoMEhISChERERERERcRDw8PDwgICAgUExQUFBQUDxQSEhISEA8PDQ0NDQ0NFAwNDQ0NBgYGBg4ODg4ODg4PDg4ODg4NDg0="), + 25+(scale<<8)+(1<<16) + ); + return this; +} + + + +{ + // must be inside our own scope here so that when we are unloaded everything disappears + // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global + + let draw = function() { + var date = new Date(); + var timeStr = require("locale").time(date,1); + var h = g.getHeight(); + var w = g.getWidth(); + + g.reset(); + g.setColor(g.theme.bg); + g.fillRect(Bangle.appRect); + + //g.setFont('Vector', w/3); + g.setFontLato(); + g.setFontAlign(0, 0); + g.setColor(g.theme.fg); + g.drawString(timeStr, w/2, h/2); + clockInfoMenu.redraw(); // clock_info_support + + // schedule a draw for the next minute + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); + }; + + /** + * clock_info_support + * this is the callback function that get invoked by clockInfoMenu.redraw(); + * + * We will display the image and text on the same line and centre the combined + * length of the image+text + * + * + */ + let clockInfoDraw = (itm, info, options) => { + //g.reset().setFont('Vector',24).setBgColor(options.bg).setColor(options.fg); + g.reset().setFontLatoSmall(); + g.setBgColor(options.bg).setColor(options.fg); + + //use info.text.toString(), steps does not have length defined + var text_w = g.stringWidth(info.text.toString()); + // gap between image and text + var gap = 10; + // width of the image and text combined + var w = gap + (info.img ? 24 :0) + text_w; + // different fg color if we tapped on the menu + if (options.focus) g.setColor(options.hl); + + // clear the whole info line, allow additional 2 pixels in case LatoFont overflows area + g.clearRect(0, options.y -2, g.getWidth(), options.y+ 23 + 2); + + // draw the image if we have one + if (info.img) { + // image start + var x = (g.getWidth() / 2) - (w/2); + g.drawImage(info.img, x, options.y); + // draw the text to the side of the image (left/centre alignment) + g.setFontAlign(-1,0).drawString(info.text, x + 23 + gap, options.y+12); + } else { + // text only option, not tested yet + g.setFontAlign(0,0).drawString(info.text, g.getWidth() / 2, options.y+12); + } + + }; + + // clock_info_support + // retrieve all the clock_info modules that are installed + let clockInfoItems = require("clock_info").load(); + + // clock_info_support + // setup the way we wish to interact with the menu + // the hl property defines the color the of the info when the menu is selected after tapping on it + let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { x:64, y:132, w:50, h:40, draw : clockInfoDraw, bg : g.theme.bg, fg : g.theme.fg, hl : "#0ff"} ); + + // timeout used to update every minute + var drawTimeout; + g.clear(); + + // Show launcher when middle button pressed, add updown button handlers + Bangle.setUI({ + mode : "clock", + remove : function() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + // remove info menu + clockInfoMenu.remove(); + delete clockInfoMenu; + // delete the custom fonts + delete Graphics.prototype.setFontLato; + delete Graphics.prototype.setFontLatoSmall; + } + }); + + // Load widgets + Bangle.loadWidgets(); + draw(); + setTimeout(Bangle.drawWidgets,0); +} // end of clock diff --git a/apps/lato/app.png b/apps/lato/app.png new file mode 100644 index 000000000..02a4031a3 Binary files /dev/null and b/apps/lato/app.png differ diff --git a/apps/lato/icon.js b/apps/lato/icon.js new file mode 100644 index 000000000..746f010dc --- /dev/null +++ b/apps/lato/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4UA///1NygH+zn/Jf4AJgdVAAnABZ8BBYtABbc1BYtcBYcVBYtUBbcC1QAEwALPgYLFQYoLWgAHBytWAYK0F1Wpv/9tQLH0v//9aBY+XBYPWBY3qz/1r/21YLGv/Vq/9BY3Vv6NB/tXBaMVBYamEBZ1fHYP1BY01r5TB+ruEBYVXNYPVBY9VBYNVBY0FqoiBqtQBY4ACBb0NBYdwBbsBBYdABYoA/AAg=")) diff --git a/apps/lato/metadata.json b/apps/lato/metadata.json new file mode 100644 index 000000000..0b5e4a0f3 --- /dev/null +++ b/apps/lato/metadata.json @@ -0,0 +1,16 @@ +{ + "id": "lato", + "name": "Lato", + "version": "0.01", + "description": "A Lato Font clock with fast load and clock_info", + "readme": "README.md", + "icon": "app.png", + "screenshots": [{"url":"screenshot3.png"}], + "type": "clock", + "tags": "clock", + "supports": ["BANGLEJS2"], + "storage": [ + {"name":"lato.app.js","url":"app.js"}, + {"name":"lato.img","url":"icon.js","evaluate":true} + ] +} diff --git a/apps/lato/screenshot1.png b/apps/lato/screenshot1.png new file mode 100644 index 000000000..14c8d6d04 Binary files /dev/null and b/apps/lato/screenshot1.png differ diff --git a/apps/lato/screenshot2.png b/apps/lato/screenshot2.png new file mode 100644 index 000000000..f40495c79 Binary files /dev/null and b/apps/lato/screenshot2.png differ diff --git a/apps/lato/screenshot3.png b/apps/lato/screenshot3.png new file mode 100644 index 000000000..1cf135a60 Binary files /dev/null and b/apps/lato/screenshot3.png differ diff --git a/apps/launch/ChangeLog b/apps/launch/ChangeLog index 44866b9f3..0aff8c49f 100644 --- a/apps/launch/ChangeLog +++ b/apps/launch/ChangeLog @@ -14,3 +14,9 @@ Add /*LANG*/ tags for internationalisation 0.13: Add fullscreen mode 0.14: Use default Bangle formatter for booleans +0.15: Support for unload and quick return to the clock on 2v16 +0.16: Use a cache of app.info files to speed up loading the launcher +0.17: Don't display 'Loading...' now the watch has its own loading screen +0.18: Add 'back' icon in top-left to go back to clock +0.19: Fix regression after back button added (returnToClock was called twice!) +0.20: Use Bangle.showClock for changing to clock diff --git a/apps/launch/app.js b/apps/launch/app.js index 556e61bfd..36f3aaf4b 100644 --- a/apps/launch/app.js +++ b/apps/launch/app.js @@ -1,61 +1,59 @@ -var s = require("Storage"); -var scaleval = 1; -var vectorval = 20; -var font = g.getFonts().includes("12x20") ? "12x20" : "6x8:2"; +{ // must be inside our own scope here so that when we are unloaded everything disappears +let s = require("Storage"); +// handle customised launcher +let scaleval = 1; +let vectorval = 20; +let font = g.getFonts().includes("12x20") ? "12x20" : "6x8:2"; let settings = Object.assign({ showClocks: true, fullscreen: false }, s.readJSON("launch.json", true) || {}); - -if ("vectorsize" in settings) { - vectorval = parseInt(settings.vectorsize); -} +if ("vectorsize" in settings) + vectorval = parseInt(settings.vectorsize); if ("font" in settings){ - if(settings.font == "Vector"){ - scaleval = vectorval/20; - font = "Vector"+(vectorval).toString(); - } - else{ - font = settings.font; - scaleval = (font.split("x")[1])/20; - } + if(settings.font == "Vector"){ + scaleval = vectorval/20; + font = "Vector"+(vectorval).toString(); + } else{ + font = settings.font; + scaleval = (font.split("x")[1])/20; + } } -var apps = s.list(/\.info$/).map(app=>{var a=s.readJSON(app,1);return a&&{name:a.name,type:a.type,icon:a.icon,sortorder:a.sortorder,src:a.src};}).filter(app=>app && (app.type=="app" || (app.type=="clock" && settings.showClocks) || !app.type)); -apps.sort((a,b)=>{ - var n=(0|a.sortorder)-(0|b.sortorder); - if (n) return n; // do sortorder first - if (a.nameb.name) return 1; - return 0; -}); -apps.forEach(app=>{ - if (app.icon) - app.icon = s.read(app.icon); // should just be a link to a memory area -}); -// FIXME: check not needed after 2v11 -if (g.wrapString) { - g.setFont(font); - apps.forEach(app=>app.name = g.wrapString(app.name, g.getWidth()-64).join("\n")); +// cache app list so launcher loads more quickly +let launchCache = s.readJSON("launch.cache.json", true)||{}; +let launchHash = require("Storage").hash(/\.info/); +if (launchCache.hash!=launchHash) { + launchCache = { + hash : launchHash, + apps : s.list(/\.info$/) + .map(app=>{var a=s.readJSON(app,1);return a&&{name:a.name,type:a.type,icon:a.icon,sortorder:a.sortorder,src:a.src};}) + .filter(app=>app && (app.type=="app" || (app.type=="clock" && settings.showClocks) || !app.type)) + .sort((a,b)=>{ + var n=(0|a.sortorder)-(0|b.sortorder); + if (n) return n; // do sortorder first + if (a.nameb.name) return 1; + return 0; + }) }; + s.writeJSON("launch.cache.json", launchCache); } - -function drawApp(i, r) { - var app = apps[i]; - if (!app) return; - g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1)); - g.setFont(font).setFontAlign(-1,0).drawString(app.name,64*scaleval,r.y+(32*scaleval)); - if (app.icon) try {g.drawImage(app.icon,8*scaleval, r.y+(8*scaleval), {scale: scaleval});} catch(e){} -} - -g.clear(); - -if (!settings.fullscreen) { +let apps = launchCache.apps; +// Now apps list is loaded - render +if (!settings.fullscreen) Bangle.loadWidgets(); - Bangle.drawWidgets(); -} E.showScroller({ h : 64*scaleval, c : apps.length, - draw : drawApp, + draw : (i, r) => { + var app = apps[i]; + if (!app) return; + g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1)); + g.setFont(font).setFontAlign(-1,0).drawString(app.name,64*scaleval,r.y+(32*scaleval)); + if (app.icon) { + if (!app.img) app.img = s.read(app.icon); // load icon if it wasn't loaded + try {g.drawImage(app.img,8*scaleval, r.y+(8*scaleval), {scale: scaleval});} catch(e){} + } + }, select : i => { var app = apps[i]; if (!app) return; @@ -63,24 +61,28 @@ E.showScroller({ E.showMessage(/*LANG*/"App Source\nNot found"); setTimeout(drawMenu, 2000); } else { - E.showMessage(/*LANG*/"Loading..."); load(app.src); } + }, + back : Bangle.showClock, // button press or tap in top left shows clock now + remove : () => { + // cleanup the timeout to not leave anything behind after being removed from ram + if (lockTimeout) clearTimeout(lockTimeout); + Bangle.removeListener("lock", lockHandler); } }); - -// on bangle.js 2, the screen is used for navigating, so the single button goes back -// on bangle.js 1, the buttons are used for navigating -if (process.env.HWVERSION==2) { - setWatch(_=>load(), BTN1, {edge:"falling"}); -} +g.flip(); // force a render before widgets have finished drawing // 10s of inactivity goes back to clock Bangle.setLocked(false); // unlock initially -var lockTimeout; -Bangle.on("lock", locked => { +let lockTimeout; +let lockHandler = function(locked) { if (lockTimeout) clearTimeout(lockTimeout); lockTimeout = undefined; if (locked) - lockTimeout = setTimeout(_=>load(), 10000); -}); + lockTimeout = setTimeout(Bangle.showClock, 10000); +} +Bangle.on("lock", lockHandler); +if (!settings.fullscreen) // finally draw widgets + Bangle.drawWidgets(); +} diff --git a/apps/launch/metadata.json b/apps/launch/metadata.json index 19ca74e73..85fcdd02f 100644 --- a/apps/launch/metadata.json +++ b/apps/launch/metadata.json @@ -2,17 +2,18 @@ "id": "launch", "name": "Launcher", "shortName": "Launcher", - "version": "0.14", + "version": "0.20", "description": "This is needed to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.", "readme": "README.md", "icon": "app.png", "type": "launch", + "default": true, "tags": "tool,system,launcher", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ {"name":"launch.app.js","url":"app.js"}, {"name":"launch.settings.js","url":"settings.js"} ], - "data": [{"name":"launch.json"}], + "data": [{"name":"launch.json"},{"name":"launch.cache.json"}], "sortorder": -10 } diff --git a/apps/lcars/ChangeLog b/apps/lcars/ChangeLog index 9a8ac4008..f97ddf540 100644 --- a/apps/lcars/ChangeLog +++ b/apps/lcars/ChangeLog @@ -21,3 +21,4 @@ 0.21: Add custom theming. 0.22: Fix alarm and add build in function for step counting. 0.23: Add warning for low flash memory +0.24: Add ability to disable alarm functionality \ No newline at end of file diff --git a/apps/lcars/lcars.app.js b/apps/lcars/lcars.app.js index e81c0d6f3..06a89a957 100644 --- a/apps/lcars/lcars.app.js +++ b/apps/lcars/lcars.app.js @@ -12,6 +12,7 @@ let settings = { themeColor1BG: "#FF9900", themeColor2BG: "#FF00DC", themeColor3BG: "#0094FF", + disableAlarms: false, }; let saved_settings = storage.readJSON(SETTINGS_FILE, 1) || settings; for (const key in saved_settings) { @@ -722,12 +723,12 @@ Bangle.on('touch', function(btn, e){ } if(lcarsViewPos == 0){ - if(is_upper){ + if(is_upper && !settings.disableAlarms){ feedback(); increaseAlarm(); drawState(); return; - } if(is_lower){ + } if(is_lower && !settings.disableAlarms){ feedback(); decreaseAlarm(); drawState(); diff --git a/apps/lcars/lcars.settings.js b/apps/lcars/lcars.settings.js index b64feb30e..e4b9b0a78 100644 --- a/apps/lcars/lcars.settings.js +++ b/apps/lcars/lcars.settings.js @@ -13,6 +13,7 @@ themeColor1BG: "#FF9900", themeColor2BG: "#FF00DC", themeColor3BG: "#0094FF", + disableAlarms: false, }; let saved_settings = storage.readJSON(SETTINGS_FILE, 1) || settings; for (const key in saved_settings) { @@ -102,6 +103,14 @@ settings.themeColor3BG = bg_code[v]; save(); }, - } + }, + 'Disable alarm functionality': { + value: settings.disableAlarms, + format: () => (settings.disableAlarms ? 'Yes' : 'No'), + onchange: () => { + settings.disableAlarms = !settings.disableAlarms; + save(); + }, + }, }); }) diff --git a/apps/lcars/metadata.json b/apps/lcars/metadata.json index 62a1c67db..6533ddd52 100644 --- a/apps/lcars/metadata.json +++ b/apps/lcars/metadata.json @@ -3,7 +3,7 @@ "name": "LCARS Clock", "shortName":"LCARS", "icon": "lcars.png", - "version":"0.23", + "version":"0.24", "readme": "README.md", "supports": ["BANGLEJS2"], "description": "Library Computer Access Retrieval System (LCARS) clock.", diff --git a/apps/lcdclock/ChangeLog b/apps/lcdclock/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/lcdclock/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/lcdclock/app-icon.js b/apps/lcdclock/app-icon.js new file mode 100644 index 000000000..ed3161c41 --- /dev/null +++ b/apps/lcdclock/app-icon.js @@ -0,0 +1 @@ +atob("MDABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf///T//+f///T///Q///Qf//Sf//Qf//Pf//Qf//AP//Yf//f///c///f///f///fiD/f8f/fur/f9f/fir/f9f/f67/f9f/fy7/f8f/fz//f+//AAAAAAAAAAAAAAAAf///////TD/u///vQB/EX/9PUV/d3/9fSd/F3/9HWd/d3/9Xf9/d//9Hf///////f///////f///8Hg/fmefwPAffmecz/Offmecz/Offmecz/OffmAcwHOffngc8DPffn+c/zOffn+c/zOffn+c/zOffn+f8DAff///8Hg/f///8Pw/f///////f//////+P//////8AAAAAAAAAAAAAAAAAAAAAAAA") diff --git a/apps/lcdclock/app.js b/apps/lcdclock/app.js new file mode 100644 index 000000000..2bc23247c --- /dev/null +++ b/apps/lcdclock/app.js @@ -0,0 +1,84 @@ +Graphics.prototype.setFont7Seg = function() { + return this.setFontCustom(atob("AAAAAAAAAAAACAQCAAAAAAIAd0BgMBdwAAAAAAAADuAAAB0RiMRcAAAAAiMRiLuAAAcAQCAQdwAADgiMRiIOAAAd0RiMRBwAAAAgEAgDuAAAd0RiMRdwAADgiMRiLuAAAABsAAAd0QiEQdwAADuCIRCIOAAAd0BgMBAAAAAOCIRCLuAAAd0RiMRAAAADuiEQiAAAAAd0BgMBBwAADuCAQCDuAAAdwAAAAAAAAAAAIBALuAAAdwQCAQdwAADuAIBAIAAAAd0AgEAcEAgEAdwAd0AgEAdwAADugMBgLuAAAd0QiEQcAAADgiEQiDuAAAd0AgEAAAAADgiMRiIOAAAAEAgEAdwAADuAIBALuAAAdwBAIBdwAADuAIBAIOAIBALuADuCAQCDuAAAcAQCAQdwAAAOiMRiLgAAAA=="), 32, atob("BwAAAAAAAAAAAAAAAAcCAAcHBwcHBwcHBwcEAAAAAAAABwcHBwcHBwcHBwcHCgcHBwcHBwcHBwoHBwc="), 9); +} + + +{ // must be inside our own scope here so that when we are unloaded everything disappears + // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global +let drawTimeout; + +// Actually draw the watch face +let draw = function() { + var x = R.x + R.w/2; + var y = R.y + R.h/2; + g.reset().setColor(g.theme.bg).setBgColor(g.theme.fg); + g.clearRect(R.x,barY+2,R.x2,R.y2-8); + var date = new Date(); + var timeStr = require("locale").time(date, 1); // Hour and minute + g.setFontAlign(0, 0).setFont("7Seg:5").drawString(timeStr, x, y+39); + // Show date and day of week + g.setFontAlign(0, 0).setFont("7Seg:2"); + g.setFontAlign(-1, 0).drawString(require("locale").meridian(date).toUpperCase(), R.x+6, y); + g.setFontAlign(0, 0).drawString(require("locale").dow(date, 1).toUpperCase(), x, y); + g.setFontAlign(1, 0).drawString(date.getDate(), R.x2 - 6, y); + + // queue next draw + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +}; + +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFont7Seg; + // remove info menu + clockInfoMenu.remove(); + delete clockInfoMenu; + clockInfoMenu2.remove(); + delete clockInfoMenu2; + // reset theme + g.setTheme(oldTheme); + }}); +// Load widgets +Bangle.loadWidgets(); +var R = Bangle.appRect; +R.x+=1; +R.y+=1; +R.x2-=1; +R.y2-=1; +R.w-=2; +R.h-=2; +var midX = R.x+R.w/2; +var barY = 80; +// Clear the screen once, at startup +let oldTheme = g.theme; +g.setTheme({bg:"#000",fg:"#fff",dark:true}).clear(1); +g.fillRect({x:R.x, y:R.y, w:R.w, h:R.h, r:8}).clearRect(R.x,barY,R.w,barY+1).clearRect(midX,R.y,midX+1,barY); +draw(); +setTimeout(Bangle.drawWidgets,0); + +let clockInfoDraw = (itm, info, options) => { + let texty = options.y+41; + g.reset().setFont("7Seg").setColor(g.theme.bg).setBgColor(g.theme.fg); + if (options.focus) g.setBgColor("#FF0"); + g.clearRect({x:options.x,y:options.y,w:options.w,h:options.h,r:8}); + + if (info.img) g.drawImage(info.img, options.x+2, options.y+2); + var title = clockInfoItems[options.menuA].name; + var text = info.text.toString().toUpperCase(); + if (title!="Bangle") g.setFontAlign(1,0).drawString(title.toUpperCase(), options.x+options.w-2, options.y+14); + if (g.setFont("7Seg:2").stringWidth(text)+8>options.w) g.setFont("7Seg"); + g.setFontAlign(0,0).drawString(text, options.x+options.w/2, options.y+40); + +}; +let clockInfoItems = require("clock_info").load(); +let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { x:R.x, y:R.y, w:midX-2, h:barY-R.y-2, draw : clockInfoDraw}); +let clockInfoMenu2 = require("clock_info").addInteractive(clockInfoItems, { x:midX+2, y:R.y, w:midX-3, h:barY-R.y-2, draw : clockInfoDraw}); +} diff --git a/apps/lcdclock/app.png b/apps/lcdclock/app.png new file mode 100644 index 000000000..6a117b525 Binary files /dev/null and b/apps/lcdclock/app.png differ diff --git a/apps/lcdclock/metadata.json b/apps/lcdclock/metadata.json new file mode 100644 index 000000000..d7d09b106 --- /dev/null +++ b/apps/lcdclock/metadata.json @@ -0,0 +1,14 @@ +{ "id": "lcdclock", + "name": "LCD Clock", + "version":"0.01", + "description": "A Casio-style clock, with ClockInfo areas at the top and bottom. Tap them and swipe up/down to toggle between different information", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock,clkinfo", + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"lcdclock.app.js","url":"app.js"}, + {"name":"lcdclock.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/lcdclock/screenshot.png b/apps/lcdclock/screenshot.png new file mode 100644 index 000000000..b0bb5934a Binary files /dev/null and b/apps/lcdclock/screenshot.png differ diff --git a/apps/lightswitch/ChangeLog b/apps/lightswitch/ChangeLog index 4c89bae76..c4aeb2c1e 100644 --- a/apps/lightswitch/ChangeLog +++ b/apps/lightswitch/ChangeLog @@ -3,3 +3,4 @@ 0.03: Settings page now uses built-in min/max/wrap (fix #1607) 0.04: Add masking widget input to other apps (using espruino/Espruino#2151), add a oversize option to increase the touch area. 0.05: Prevent drawing into app area. +0.06: Fix issue where .draw was being called by reference (not allowing widgets to be hidden) diff --git a/apps/lightswitch/metadata.json b/apps/lightswitch/metadata.json index b8da2f759..d1a8d6e2a 100644 --- a/apps/lightswitch/metadata.json +++ b/apps/lightswitch/metadata.json @@ -2,7 +2,7 @@ "id": "lightswitch", "name": "Light Switch Widget", "shortName": "Light Switch", - "version": "0.05", + "version": "0.06", "description": "A fast way to switch LCD backlight on/off, change the brightness and show the lock status. All in one widget.", "icon": "images/app.png", "screenshots": [ diff --git a/apps/lightswitch/widget.js b/apps/lightswitch/widget.js index d9d4d421d..9eb488aca 100644 --- a/apps/lightswitch/widget.js +++ b/apps/lightswitch/widget.js @@ -224,28 +224,20 @@ // main widget function // // display and setup/reset function - draw: function(locked) { + draw: function() { // setup shortcut to this widget var w = WIDGETS.lightswitch; - // set lcd brightness on unlocking - // all other cases are catched by the boot file - if (locked === false) Bangle.setLCDBrightness(w.isOn ? w.value : 0); - // read lock status - locked = Bangle.isLocked(); + var locked = Bangle.isLocked(); // remove listeners to prevent uncertainties - Bangle.removeListener("lock", w.draw); Bangle.removeListener("touch", w.touchListener); Bangle.removeListener("tap", require("lightswitch.js").tapListener); // draw widget icon w.drawIcon(locked); - // add lock listener - Bangle.on("lock", w.draw); - // add touch listener to control the light depending on settings at first position if (w.touchOn === "always" || !global.__FILE__ || w.touchOn.includes(__FILE__) || @@ -259,7 +251,15 @@ w = undefined; } }); + + Bangle.on("lock", locked => { + var w = WIDGETS.lightswitch; + // set lcd brightness on unlocking + // all other cases are catched by the boot file + if (locked === false) Bangle.setLCDBrightness(w.isOn ? w.value : 0); + w.draw() + }); // clear variable - settings = undefined; + delete settings; })() diff --git a/apps/limelight/ChangeLog b/apps/limelight/ChangeLog index 9db0e26c5..8fe3a0b2c 100644 --- a/apps/limelight/ChangeLog +++ b/apps/limelight/ChangeLog @@ -1 +1,2 @@ 0.01: first release +0.02: Tell clock widgets to hide. diff --git a/apps/limelight/limelight.app.js b/apps/limelight/limelight.app.js index 20d79deeb..84ded1039 100644 --- a/apps/limelight/limelight.app.js +++ b/apps/limelight/limelight.app.js @@ -10,6 +10,8 @@ * */ +Bangle.setUI('clock'); + g.clear(); const SETTINGS_FILE = "limelight.json"; @@ -259,5 +261,4 @@ Bangle.on('lcdPower',on=>{ } }); -Bangle.setUI('clock'); draw(); diff --git a/apps/limelight/metadata.json b/apps/limelight/metadata.json index 7c3736e1a..e484a2825 100644 --- a/apps/limelight/metadata.json +++ b/apps/limelight/metadata.json @@ -1,7 +1,7 @@ { "id": "limelight", "name": "Limelight", - "version": "0.01", + "version": "0.02", "description": "Simple analogue clock (with configurable fonts) based on the work of @Andreas_Rozek (Simple_Clock)", "icon": "limelight.png", "readme":"README.md", diff --git a/apps/linuxclock/ChangeLog b/apps/linuxclock/ChangeLog new file mode 100644 index 000000000..1c4f7d79b --- /dev/null +++ b/apps/linuxclock/ChangeLog @@ -0,0 +1,3 @@ +0.01: New App. +0.02: Performance improvements. +0.03: Update clock_info to avoid a redraw diff --git a/apps/linuxclock/README.md b/apps/linuxclock/README.md new file mode 100644 index 000000000..934ed2902 --- /dev/null +++ b/apps/linuxclock/README.md @@ -0,0 +1,13 @@ +# A Linux inspired clock + + +A linux inspired clock which also loads and shows clock_infos . +Simply click left/right to execute another command ;) +With up/down you can select an individual entry and with a click at the +center of the screen you can trigger an action if its supported (e.g. HomeAssistant). + +# Thanks +Icons from by Freepik - Flaticon + +## Creator +- [David Peer](https://github.com/peerdavid). \ No newline at end of file diff --git a/apps/linuxclock/app-icon.js b/apps/linuxclock/app-icon.js new file mode 100644 index 000000000..8a767a209 --- /dev/null +++ b/apps/linuxclock/app-icon.js @@ -0,0 +1 @@ +atob("JiaEAAAAAAAAAAAAD///AAAAAAAAAAAAAAAAAAAAD/////AAAAAAAAAAAAAAAAAAAA//////AAAAAAAAAAAAAAAAAAD///////AAAAAAAAAAAAAAAAAA///////wAAAAAAAAAAAAAAAAAPD/8AD/8AAAAAAAAAAAAAAAAADwD/AA//AAAAAAAAAAAAAAAAAADw/w8P/wAAAAAAAAAAAAAAAAAP////D/8AAAAAAAAAAAAAAAAAD/8AD///8AAAAAAAAAAAAAAAAA/wAAD///AAAAAAAAAAAAAAAAAP8AAP///wAAAAAAAAAAAAAAAADw8P8AD/8AAAAAAAAAAAAAAAAP8AAAAA//8AAAAAAAAAAAAAAADwAAAAAA//AAAAAAAAAAAAAAAP8AAAAAAP//AAAAAAAAAAAAAA/wAAAAAAAP//AAAAAAAAAAAAAP8AAAAAAAD///AAAAAAAAAAAA/wAAAAAAAA///wAAAAAAAAAAAP8AAAAAAAAA///wAAAAAAAAAA/wAAAAAAAAAP//8AAAAAAAAAAP8AAAAAAAAAD///8AAAAAAAAAD/AAAAAAAAAAD///AAAAAAAAAP8AAAAAAAAAAA///wAAAAAAAAD/AAAAAAAAAAAP//8AAAAAAAAA//AAAAAAAAAA////AAAAAAAAAP/wAAAAAAAAD////wAAAAAAAA8A/wAAAAAAAA////8AAAAAAA/wAA/wAAAAAAAPD///8AAAAA/wAAAP/wAAAAAADw//APAAAAAPAAAAAP/wAAAAAA8AAAD/AAAADwAAAAD/8AAAAAD/AAAAD/AAAA8AAAAAD/AAAAAP/wAAAADwAAAPAAAAAADwAAAP//AAAAD/AAAAD/AAAAAA///////wAAD/8AAAAAD///AAAP//////8AAP8AAAAAAAAAD//w/wAAAAAP8P8AAAAAAAAAAAAAD/AAAAAAAP/wAAAAAA") \ No newline at end of file diff --git a/apps/linuxclock/app.js b/apps/linuxclock/app.js new file mode 100644 index 000000000..9470b803c --- /dev/null +++ b/apps/linuxclock/app.js @@ -0,0 +1,386 @@ + +/************************************************ + * Includes + */ + const clock_info = require("clock_info"); + const storage = require('Storage'); + const locale = require('locale'); + +/* + * Some vars + */ +var W = g.getWidth(); +var H = g.getHeight(); + + /************************************************ + * Settings + */ + const SETTINGS_FILE = "linuxclock.setting.json"; + let settings = { + menuPosX: 0, + menuPosY: 0, + }; + + let saved_settings = storage.readJSON(SETTINGS_FILE, 1) || settings; + for (const key in saved_settings) { + settings[key] = saved_settings[key] + } + + + /************************************************ + * Assets + */ + Graphics.prototype.setFontUbuntuMono = function(scale) { + // Actual height 24 (27 - 4) + this.setFontCustom( + atob('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD+A4AP/ngA/+eAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAA/gAAD+AAAAAAAAAAAAD+AAAP4AAA8AAAAAAAAAAAAAAAAAAAAAAAMGAAAwfgAD/+AB//gAP/YAA/BgAAMH4AA3/gAP/8AD/+AAPwYAADBgAAAAAAAAAAAAAEAAfA4AD+DgAf4GABxwYA+HB8D4OHwBg4YAGDzgAcH8AAgPwAAAcAAAAAAA8AAAH8BgA9wOADBjwAOccAA/3gAA94AAAPeAAD3+AAcc4AHhhgA4H+ADAfwAAAeAAAAAAAAPgADx/AAf/eAD/wYAMHBgAw+GADneYAP4/AAfB8AAA/4AADzgAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/gAAD+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAB//AAP//AD4A+AeAA8DwAB4OAADwQAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAYOAABw8AAeB4ADwD4A+AD//wAH/8AAD/AAAAAAAAAAAAAAAAAAAAAAAAAA4AAABiAAAHcAAAPwAAP8AAA/wAAAPwAAB3AAAGIAAAYAAAAAAAAAAAAAAAAAABgAAAGAAAAYAAABgAAAGAAAP/wAA//AAAGAAAAYAAABgAAAGAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAABOAAAewAAB/AAAH4AAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAYAAABgAAAGAAAAYAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeAAAB4AAAHgAAAeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAB8AAA/wAAf4AAP8AAH+AAD/AAB/gAAPwAAA4AAAAAAAAAAAAAAAAAAB/AAA//gAH//AA8AeADhg4AMPBgAw8GADhg4APAHgAf/8AA//gAAfwAAAAAAAAAAAAAAAAGAAAAYAYADgBgAcAGAB//4AP//gA//+AAAAYAAABgAAAGAAAAIAAAAAAAAAAAAAAAGADgA4A+ADgH4AMA9gAwHGADA4YAOHBgA/4GAB/AYAD4BgAAAGAAAAAAAAAAAAAAABgA4AOADgA4AGADBgYAMGBgAw4GADjw4AP/ngAfv8AA8fgAAAYAAAAAAAAAAAAA4AAAPgAAD+AAAeYAADhgAA8GAAHgYAA8BgAD//4AP//gAABgAAAGAAAAAAAAAAAAAAAAAADgA/4OAD/gYAP+BgAw4GADDgYAMGDgAweeADA/wAMB+AAABgAAAAAAAAAAAAPAAAH/gAB//AAP4eABzA4AGMBgA4wGADjgYAMOHgAwf8ADA/gAAB4AAAAAAAAAAAAAAAAwAAADAAAAMADgAwB+ADA/4AMP8AAz8AADfAAAPwAAA8AAADgAAAAAAAAAAAAAAHAAD5/AAf38AD344AMHBgAwYGADBwYAOHBgA9+OAB/fwAD5/AAABwAAAAAAAAAAAHgAAA/gYAH+BgA4cGADAw4AMDDgAwMcADgzwAPD+AAf/wAA/+AAAfAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADweAAPB4AA8HgADweAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAADgA8HMADwfwAPB+AA8HwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAA8AAADwAAAPgAAB+AAAGYAAA5wAADDAAAcOAABw4AAGBgAAYGAAAAAAAAAAAAMYAAAxgAADGAAAMYAAAxgAADGAAAMYAAAxgAADGAAAMYAAAxgAADGAAAAAAAAAAAAGBgAAYHAABwYAAHDgAAMMAAA5wAABmAAAH4AAAfgAAA8AAADwAAAGAAAAAAAAAAAAAAAAAAAAAOAAAAwAMADAZ4AMHngAw8eADngAAP8AAAfgAAAYAAAAAAAAAAAAAAAAAAP+AAH/+AA//+AHgB8A4PhwDD/jgMP/GAxwcYDmAxgPYDGAf/8YA//wAAAAAAAAGAAAD4AAD/gAB/wAA/+AAP4YAA8BgADwGAAP8YAAP/gAAH/gAAD/gAAA+AAAAYAAAAAA//+AD//4AP//gAwYGADBgYAMGBgAwYGADjw4AP/DgAfv8AA8fgAAA8AAAAAAAAAAAAfwAAH/wAA//gAHgPAA8AOADgA4AMABgAwAGADAAYAOABgA4AOABAAwAAAAAAAAAAD//4AP//gA//+ADAAYAMABgAwAGADgA4AOADgAcAcAA//gAB/8AAB/AAAAAAAAAAAAAAAAD//4AP//gA//+ADBgYAMGBgAwYGADBgYAMGBgAwYGADBgYAIABgAAAAAAAAAAAAAAA//+AD//4AP//gAwYAADBgAAMGAAAwYAADBgAAMGAAAwYAADAAAAAAAAAAAAAAH8AAB/8AAP/4AB4DwAPADgA4AOADAAYAMABgAwAGADgf4AOD/gAQP+AAAAAAAAAAA//+AD//4AP//gAAYAAABgAAAGAAAAYAAABgAAAGAAA//+AD//4AP//gAAAAAAAAAAAAAAAwAGADAAYAMABgAwAGAD//4AP//gAwAGADAAYAMABgAwAGAAAAAAAAAAAAAAAAAAQAAADAAwAOADAAYAMABgAwAGADAAYAMADgA//8AD//wAP/8AAAAAAAAAAAAAAAAAAAAD//4AP//gAAcAAADwAAAfgAAHvAAA8eAAHg+AA8A8ADgB4AIADgAAACAAAAAAAAAAA//+AD//4AP//gAAAGAAAAYAAABgAAAGAAAAYAAABgAAAGAAAAYAAAAAAAAAAAP/4AP//gA/+AAD+AAAB/AAAA+AAAD4AAB/AAA/gAAD/4AAP//gAH/+AAAAAAAAAAA//+AD//4AP//gAfAAAA+AAAA+AAAA/AAAA/AAAA/AA//+AD//4AP//gAAAAAAAAAAB/8AAP/4AB+PwAOADgA4AOADAAYAMABgA4AOADgA4AH4/AAP/4AAf/AAAAAAAAAAAAAAAAP//gA//+AD//4AMBgAAwGAADAYAAODgAA4OAAB/wAAD+AAAHwAAAAAAAAAAAAD/wAA//wAH4fgA4APADgAcAMAA8AwAD4DgAfgPAD3Afh+MA//wwA/8CAAAAAAAAAAP//gA//+AD//4AMDAAAwMAADAwAAMDgAA4fgAD/vgAH+PgAPwOAAAAYAAAAAAAAAAAAAQAD4DAAfwOAD/AYAOOBgAwYGADBwYAMDDgA4OOADgfwAEB/AAABwAAAAAAAAAAAwAAADAAAAMAAAAwAAADAAAAP//gA//+ADAAAAMAAAAwAAADAAAAMAAAAAAAAAAAAAP/8AA//4AD//wAAADgAAAGAAAAYAAABgAAAGAAAA4AP//AA//4AD//AAAAAAAwAAAD4AAAP8AAAP/AAAD/gAAB/gAAAeAAAB4AAA/gAA/4AA/8AAP+AAA+AAADAAAAAAAAA//wAD//4AAf/gAAD+AAB/AAAPgAAA+AAAB/AAAA/gAB/+AD//4AP/4AAAAAAAAAAAIABgA4AeAD4H4AH5+AAH/gAAH4AAAfgAAH/gAB+fgAPgfgA4AeACAAYAAAAAAgAAADgAAAPgAAAfgAAAfgAAAfgAAAf+AAB/4AAfgAAH4AAB+AAAPgAAA4AAACAAAAAAAAAAAGADAB4AMAfgAwD+ADA+YAMHhgAx8GADPAYAP4BgA+AGADwAYAMABgAAAAAAAAAAAAAAAAAAAAAAAA////D///8MAAAwwAADDAAAMMAAAwwAADAAAAAAAAAAAAAAAAAAAAAAAA4AAAD8AAAH+AAAH/AAAD/gAAB/wAAAf4AAAP8AAAHwAAADAAAAAAAAAAAAAAAAAAAAAAAAwAADDAAAMMAAAwwAADDAAAMP///w////AAAAAAAAAAAAAAAAAAAAAAAAAGAAAA4AAAPgAAD4AAA+AAADwAAAPAAAA+AAAA+AAAA+AAAA4AAABgAAAAAAAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAADAAAAMAAAAwAAAAAAAAAAAAAAAAAAAAAAAOAAAA8AAAB4AAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAD8AAMPwAAxzgADGGAAMYYAAxhgADmGAAPYYAAf/gAA/+AAAAAAAAAAAAAAAAAAAA///gD//+AP//4AA4BgADAGAAMAYAA4DgADgeAAH/wAAP+AAAfwAAAAAAAAAAAAPgAAD/gAAf/AABwcAAOA4AA4DgADAGAAMAYAAwBgADAGAAOA4AAABgAAAAAAAAAAAH8AAA/4AAH/wAA4HgADgOAAMAYAAwBgADgGAH//4A///gD//+AAAAAAAAAAAAAAAAA/AAAP+AAB/8AAOZ4AA5jgADGGAAMYYAAxhgADmGAAH44AAfjgAAeAAAAAAAAAAAAAAAAAMAAAAwAAAf/+AH//4A///gDjAAAMMAAAwwAADDAAAMMAAA4AAABAAAAAAAAAAH8AAA/4cAH/xwA8DjADgOMAMAYwAwBjADAOcAP//wA//+AD//wAAAAAAAAAAAAAAAAAAA///gD//+AP//4AAwAAADAAAAMAAAA4AAAD4AAAH/4AAP/gAAAAAAAAAAAAAAADAAAAMAAAAwAADjAAAPP/gA8//ABj/+AAAA4AAABgAAAGAAAA4AAABAAAAAAAAAAAAAAAAAAAcAMABwAwADADAAMAMAAw8wAHDz//8PP//gY//8AAAAAAAAAAAAAAAAAAAAAAAA///gD//+AP//4AADwAAAfgAADvAAAeeAADw8AAOB4AAwDgACAGAAAAAAAAAADAAAAMAAAAwAAADAAAAP//gA///AD//+AAAA4AAABgAAAGAAAA4AAABAAAAAAAAAAAA//gAD/+AAOAAAAwAAADgAAAP8AAA/wAADAAAAMAAAA4AAAD/+AAH/4AAAAAAAAAAAAAAAA//gAD/+AAP/4AAwAAADAAAAMAAAA4AAAD4AAAH/4AAP/gAAAAAAAAAAAAAAAAfwAAD/gAAf/AADweAAOA4AAwBgADAGAAOA4AA8HgAB/8AAD/gAAH8AAAAAAAAAAAAAAAAD//8AP//wA///ADAOAAMAYAAwBgADgOAAPB4AAf/AAA/4AAB/AAAAAAAAAAAAB/AAAP+AAB/8AAPB4AA4DgADAGAAMAYAAwDgAD//8AP//wA///AAAAAAAAAAAAAAAAAAAAAAAAAf/gAD/+AAP/4AAwAAADAAAAMAAAAwAAADAAAAMAAAAAAAAAAAAAAAAAAAAAAA4OAAHw4AA/hgADOGAAMcYAAxxgADDGAAMO4AA4fAABB8AAAAAAAAAAAAAAAAAAAAAwAAADAAAD//AAP//AA//+AAMA4AAwBgADAGAAMAYAAwDgADAEAAAAAAAAAAAAAAAAP/gAA//AAAA+AAAA4AAABgAAAGAAAAYAA//gAD/+AAP/4AAAAAAAAAAAAAAAA4AAAD8AAAP8AAAH+AAAD+AAAB4AAAHgAAD8AAB/AAA/wAAD8AAAOAAAAAAAADAAAAP+AAA//gAAH+AAAD4AAB+AAAfAAAB8AAAD+AAAB+AAAP4AA//gAD/AAAMAAAAAAAACAGAAMA4AA8HgAB54AAD/AAAH4AAAPgAAD/AAAeeAADw+AAMA4AAgBgAAAAAAAAAAAgADAD4AMAP4AwAf8DAAH8cAAD/gAAD8AAB/AAB/wAA/4AAD8AAAMAAAAAAAAAAAAAAAAAAwDgADAeAAMH4AAw9gADPmAAN4YAA/BgAD4GAAPAYAAwBgAAAAAAAAAAAAAAAAAAAAAYAAABgAAAPAAD///Af/f+D/wf8MAAAwwAADDAAAMMAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///w////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAADDAAAMMAAAwwAADD/w/8H/3/gP//8AAPAAAAYAAABgAAAAAAAAAAAAAAAAADAAAA8AAADgAAAMAAAA4AAADgAAAHAAAAcAAAAwAAAHAAAA8AAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='), + 32, + atob("Dg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4c"), + 28+(scale<<8)+(1<<16) + ); + return this; + } + + + + /************************************************ + * Menu + */ + var dateMenu = { + name: "date", + img: null, + items: [ + { name: "time", + get: () => ({ text: getTime(), img: null}), + show: function() {}, + hide: function () {} + }, + { name: "day", + get: () => ({ text: getDay(), img: null}), + show: function() {}, + hide: function () {} + }, + { name: "date", + get: () => ({ text: getDate(), img: null}), + show: function() {}, + hide: function () {} + }, + { name: "week", + get: () => ({ text: weekOfYear(), img: null}), + show: function() {}, + hide: function () {} + }, + ] + }; + + var menu = clock_info.load(); + menu = menu.concat(dateMenu); + + // Set draw functions for each item + menu.forEach((menuItm, x) => { + menuItm.items.forEach((item, y) => { + function drawItem() { + item.hide(); + + var info = item.get(); + drawText(item.name, info.text, (y%4)+1); + } + + item.on('redraw', drawItem); + }) + }); + + + // Ensure that our settings are still in range (e.g. app uninstall). Otherwise reset the position it. + if(settings.menuPosX >= menu.length || settings.menuPosY > menu[settings.menuPosX].items.length ){ + settings.menuPosX = 0; + settings.menuPosY = 0; + } + +function canRunMenuItem(){ + var menuEntry = menu[settings.menuPosX]; + var item = menuEntry.items[settings.menuPosY]; + return item.run !== undefined; +} + + +function runMenuItem(){ + var menuEntry = menu[settings.menuPosX]; + var item = menuEntry.items[settings.menuPosY]; + try{ + var ret = item.run(); + if(ret){ + Bangle.buzz(300, 0.6); + } + } catch (ex) { + // Simply ignore it... + } +} + +/************************************************ +* Helper +*/ +function getTime(){ + var date = new Date(); + return twoD(date.getHours())+ ":" + twoD(date.getMinutes()); +} + +function getDate(){ + var date = new Date(); + return twoD(date.getDate()) + "." + twoD(date.getMonth()); +} + +function getDay(){ + var date = new Date(); + return locale.dow(date, true); +} + +function weekOfYear() { + var date = new Date(); + date.setHours(0, 0, 0, 0); + // Thursday in current week decides the year. + date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); + // January 4 is always in week 1. + var week1 = new Date(date.getFullYear(), 0, 4); + // Adjust to Thursday in week 1 and count number of weeks from date to week1. + return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 + - 3 + (week1.getDay() + 6) % 7) / 7); +} + + + +/************************************************ +* Draw +*/ +function draw() { + queueDraw(); + + g.setFontUbuntuMono(); + g.setFontAlign(-1, -1); + + g.clearRect(0,24,W,H); + + drawMainScreen(); +} + + + +function drawMainScreen(){ + // Get menu item based on x + var menuItem = menu[settings.menuPosX]; + var cmd = menuItem.name.slice(0,5).toLowerCase(); + drawCmd(cmd); + + // Draw menu items depending on our y value + drawMenuItems(menuItem); + + // And draw the cursor + drawCursor(); +} + +function drawMenuItems(menuItem) { + var start = parseInt(settings.menuPosY / 4) * 4; + for (var i = start; i < start + 4; i++) { + if (i >= menuItem.items.length) { + continue; + } + lock_input++; + menuItem.items[i].show(); + } +} + +function drawCursor(){ + g.setFontUbuntuMono(); + g.setFontAlign(-1, -1); + g.setColor(g.theme.fg); + + g.clearRect(0, 27 + 28, 15, H); + if(!Bangle.isLocked()){ + g.drawString(">", -2, ((settings.menuPosY % 4) + 1) * 27 + 28); + } +} + +function drawText(key, value, line){ + var x = 15; + var y = line * 27 + 28; + + g.setFontUbuntuMono(); + g.setFontAlign(-1, -1); + g.setColor(g.theme.fg); + + if(key){ + key = (key.toLowerCase() + " ").slice(0, 4) + "|"; + } else { + key = "" + } + + value = String(value).replace("\n", " "); + g.drawString(key + value, x, y); + + lock_input -= 1; +} + + +function drawCmd(cmd){ + var c = 0; + var x = 10; + var y = 28; + + g.setColor("#0f0"); + g.drawString("bjs", x+c, y); + c += g.stringWidth("bjs"); + + g.setColor(g.theme.fg); + g.drawString(":", x+c, y); + c += g.stringWidth(":"); + + g.setColor("#0ff"); + g.drawString("$ ", x+c, y); + c += g.stringWidth("$ "); + + g.setColor(g.theme.fg); + g.drawString(cmd, x+c, y); +} + +function twoD(str){ + return ("0" + str).slice(-2) +} + + +/************************************************ +* Listener +*/ +// timeout used to update every minute +var drawTimeout; + +// schedule a draw for the next minute +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +} + + +// Stop updates when LCD is off, restart when on +Bangle.on('lcdPower',on=>{ + if (on) { + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); + + +Bangle.on('lock', function(isLocked) { + drawCursor(); +}); + + +Bangle.on('charging',function(charging) { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + + settings.menuPosX=0; + settings.menuPosY=0; + + draw(); +}); + +var lock_input = 0; + +Bangle.on('touch', function(btn, e){ + if(lock_input > 0){ + return; + } + lock_input = 0; + + var left = parseInt(g.getWidth() * 0.22); + var right = g.getWidth() - left; + var upper = parseInt(g.getHeight() * 0.22) + 20; + var lower = g.getHeight() - upper; + + var is_upper = e.y < upper; + var is_lower = e.y > lower; + var is_left = e.x < left && !is_upper && !is_lower; + var is_right = e.x > right && !is_upper && !is_lower; + var is_center = !is_upper && !is_lower && !is_left && !is_right; + + var oldYScreen = parseInt(settings.menuPosY/4); + if(is_lower){ + if(settings.menuPosY >= menu[settings.menuPosX].items.length-1){ + return; + } + + Bangle.buzz(40, 0.6); + settings.menuPosY++; + if(parseInt(settings.menuPosY/4) == oldYScreen){ + drawCursor(); + return; + } + } + + if(is_upper){ + if(e.y < 20){ // Reserved for widget clicks + return; + } + + if(settings.menuPosY <= 0){ + return; + } + Bangle.buzz(40, 0.6); + settings.menuPosY--; + settings.menuPosY = settings.menuPosY < 0 ? 0 : settings.menuPosY; + + if(parseInt(settings.menuPosY/4) == oldYScreen){ + drawCursor(); + return; + } + } + + if(is_right){ + Bangle.buzz(40, 0.6); + settings.menuPosX = (settings.menuPosX+1) % menu.length; + settings.menuPosY = 0; + } + + if(is_left){ + Bangle.buzz(40, 0.6); + settings.menuPosY = 0; + settings.menuPosX = settings.menuPosX-1; + settings.menuPosX = settings.menuPosX < 0 ? menu.length-1 : settings.menuPosX; + } + + if(is_center){ + if(!canRunMenuItem()){ + return; + } + runMenuItem(); + } + + draw(); +}); + +E.on("kill", function(){ + try{ + storage.write(SETTINGS_FILE, settings); + } catch(ex){ + // If this fails, we still kill the app... + } +}); + + +/************************************************ +* Startup Clock +*/ +// Show launcher when middle button pressed +Bangle.setUI("clock"); + +// Load and draw widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +// Draw first time +draw(); diff --git a/apps/linuxclock/app.png b/apps/linuxclock/app.png new file mode 100644 index 000000000..3a09cd575 Binary files /dev/null and b/apps/linuxclock/app.png differ diff --git a/apps/linuxclock/metadata.json b/apps/linuxclock/metadata.json new file mode 100644 index 000000000..06ef66498 --- /dev/null +++ b/apps/linuxclock/metadata.json @@ -0,0 +1,18 @@ +{ + "id": "linuxclock", + "name": "Linux Clock", + "version": "0.03", + "description": "A Linux inspired clock.", + "readme": "README.md", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}, {"url":"screenshot_2.png"}], + "type": "clock", + "tags": "clock", + "supports": ["BANGLEJS2"], + "allow_emulator": true, + "storage": [ + {"name":"linuxclock.app.js","url":"app.js"}, + {"name":"linuxclock.img","url":"app-icon.js","evaluate":true}, + {"name":"linuxclock.settings.js","url":"settings.js"} + ] +} diff --git a/apps/linuxclock/screenshot.png b/apps/linuxclock/screenshot.png new file mode 100644 index 000000000..4bc7f9967 Binary files /dev/null and b/apps/linuxclock/screenshot.png differ diff --git a/apps/linuxclock/screenshot_2.png b/apps/linuxclock/screenshot_2.png new file mode 100644 index 000000000..abeba7a92 Binary files /dev/null and b/apps/linuxclock/screenshot_2.png differ diff --git a/apps/linuxclock/settings.js b/apps/linuxclock/settings.js new file mode 100644 index 000000000..116253fda --- /dev/null +++ b/apps/linuxclock/settings.js @@ -0,0 +1,50 @@ +(function(back) { + const SETTINGS_FILE = "bwclk.setting.json"; + + // initialize with default settings... + const storage = require('Storage') + let settings = { + screen: "Normal", + showLock: true, + hideColon: false, + }; + let saved_settings = storage.readJSON(SETTINGS_FILE, 1) || settings; + for (const key in saved_settings) { + settings[key] = saved_settings[key] + } + + function save() { + storage.write(SETTINGS_FILE, settings) + } + + var screenOptions = ["Normal", "Dynamic", "Full"]; + E.showMenu({ + '': { 'title': 'BW Clock' }, + '< Back': back, + 'Screen': { + value: 0 | screenOptions.indexOf(settings.screen), + min: 0, max: 2, + format: v => screenOptions[v], + onchange: v => { + settings.screen = screenOptions[v]; + save(); + }, + }, + 'Show Lock': { + value: settings.showLock, + format: () => (settings.showLock ? 'Yes' : 'No'), + onchange: () => { + settings.showLock = !settings.showLock; + save(); + }, + }, + 'Hide Colon': { + value: settings.hideColon, + format: () => (settings.hideColon ? 'Yes' : 'No'), + onchange: () => { + settings.hideColon = !settings.hideColon; + save(); + }, + } + }); + }) diff --git a/apps/locale/locales.js b/apps/locale/locales.js index bfb8fdceb..7b3146e15 100644 --- a/apps/locale/locales.js +++ b/apps/locale/locales.js @@ -97,6 +97,25 @@ var locales = { day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", // No translation for english... }, + "en_IE": { + lang: "en_IE", + decimal_point: ".", + thousands_sep: ",", + currency_symbol: "€", + int_curr_symbol: "EUR", + currency_first: true, + speed: 'kmh', + distance: { "0": "m", "1": "km" }, + temperature: '°C', + ampm: { 0: "am", 1: "pm" }, + timePattern: { 0: "%HH:%MM:%SS ", 1: "%HH:%MM" }, + datePattern: { 0: "%d %b %Y", 1: "%d/%m/%Y" }, // 28 Feb 2020" // "28/03/2020"(short) + abmonth: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + month: "January,February,March,April,May,June,July,August,September,October,November,December", + abday: "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + day: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + // No translation for english... + }, "en_NAV": { // navigation units nautical miles and knots lang: "en_NAV", decimal_point: ".", diff --git a/apps/macwatch2/ChangeLog b/apps/macwatch2/ChangeLog index a60193ba7..12559d732 100644 --- a/apps/macwatch2/ChangeLog +++ b/apps/macwatch2/ChangeLog @@ -1,3 +1,6 @@ 0.01: Created first version of the app with numeric date, only works in light mode 0.02: New icon, shimmied date right a bit 0.03: Incorporated improvements from Peer David for accuracy, fix dark mode, widgets run in background +0.04: Changed clock to use 12/24 hour format based on locale +0.05: Tell clock widgets to hide. +0.06: Widgets can now be made visible by swiping down (#2196) diff --git a/apps/macwatch2/app.js b/apps/macwatch2/app.js index 3b78d5baf..36917a988 100644 --- a/apps/macwatch2/app.js +++ b/apps/macwatch2/app.js @@ -20,7 +20,7 @@ function queueDraw() { function draw() { queueDraw(); - + // Fix theme to "light" g.setTheme({bg:"#fff", fg:"#000", dark:false}).clear(); g.reset(); @@ -30,20 +30,17 @@ function draw() { g.setFontAlign(0, -1, 0); g.setColor(0,0,0); var d = new Date(); - var da = d.toString().split(" "); - hh = da[4].substr(0,2); - mi = da[4].substr(3,2); + var dt = require("locale").time(d, 1); + var hh = dt.split(":")[0]; + var mm = dt.split(":")[1]; + g.drawString(hh, 52, 65, true); + g.drawString(mm, 132, 65, true); + g.drawString(':', 93,65); dd = ("0"+(new Date()).getDate()).substr(-2); mo = ("0"+((new Date()).getMonth()+1)).substr(-2); yy = ("0"+((new Date()).getFullYear())).substr(-2); - g.drawString(hh, 52, 65, true); - g.drawString(mi, 132, 65, true); - g.drawString(':', 93,65); g.setFontCustom(font, 48, 8, 521); g.drawString(dd + ':' + mo + ':' + yy, 88, 120, true); - - // Hide widgets - for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} } @@ -57,8 +54,9 @@ Bangle.on('lcdPower',on=>{ } }); +Bangle.setUI("clock"); // Load widgets but hide them Bangle.loadWidgets(); +require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe draw(); -Bangle.setUI("clock"); diff --git a/apps/macwatch2/metadata.json b/apps/macwatch2/metadata.json index 09ec01e06..701c82102 100644 --- a/apps/macwatch2/metadata.json +++ b/apps/macwatch2/metadata.json @@ -2,7 +2,7 @@ "name": "MacWatch2", "shortName":"MacWatch2", "icon": "app.png", - "version":"0.03", + "version":"0.06", "description": "Classic Mac Finder clock", "type": "clock", "tags": "clock", diff --git a/apps/matrixclock/ChangeLog b/apps/matrixclock/ChangeLog index 52f705301..02f7d109b 100644 --- a/apps/matrixclock/ChangeLog +++ b/apps/matrixclock/ChangeLog @@ -1,4 +1,7 @@ 0.01: Initial Release 0.02: Support for Bangle 2 0.03: Keep the date from being overwritten, use correct colour from theme for clearing -0.04: Removed "wake LCD on face-up"-feature: A watch-face should not set things like "wake LCD on face-up". +0.04: Removed "wake LCD on face-up"-feature: A watch-face should not set things like "wake LCD on face-up". +0.05: Added support to other color themes (other then black) +0.06: Added support for 24 hour clock enabled from settings +0.07: Tell clock widgets to hide. diff --git a/apps/matrixclock/README.md b/apps/matrixclock/README.md index 010524b60..01aef6544 100644 --- a/apps/matrixclock/README.md +++ b/apps/matrixclock/README.md @@ -2,6 +2,25 @@ ![](app.png) +## Settings +Please use the setting->App->Matrix Clock Menu to change the settings + +| Setting | Description | +|-------------|--------------------------------------------------------------------------------------------------------------------| +| Color | By default set to **'theme'** to follow the theme colors. Selector also offers a selection of other colour schemes | +| Time Format | Choose between 12 hour and 24 hour time format | +| Intensity | Changes the number of matrix streams that are falling | + +## Colour Themes + +Some of the colours schemes that are available from the settings screen + +| ![](matrix_green_on_black.jpg) | ![](matrix_black_on_white.jpg) | ![](matrix_white_on_gray.jpg) | +|-------------------------------|-------------------------------|-----| +| green on black | white on black | white on gray | + + + ## Requests Please reach out to adrian@adriankirk.com if you have feature requests or notice bugs. diff --git a/apps/matrixclock/matrix_black_on_white.jpg b/apps/matrixclock/matrix_black_on_white.jpg new file mode 100644 index 000000000..545545c65 Binary files /dev/null and b/apps/matrixclock/matrix_black_on_white.jpg differ diff --git a/apps/matrixclock/matrix_green_on_black.jpg b/apps/matrixclock/matrix_green_on_black.jpg new file mode 100644 index 000000000..7caa38bec Binary files /dev/null and b/apps/matrixclock/matrix_green_on_black.jpg differ diff --git a/apps/matrixclock/matrix_white_on_gray.jpg b/apps/matrixclock/matrix_white_on_gray.jpg new file mode 100644 index 000000000..dc9d2f3ba Binary files /dev/null and b/apps/matrixclock/matrix_white_on_gray.jpg differ diff --git a/apps/matrixclock/matrixclock.js b/apps/matrixclock/matrixclock.js index 2e4ba1ac4..9618c3a47 100644 --- a/apps/matrixclock/matrixclock.js +++ b/apps/matrixclock/matrixclock.js @@ -3,24 +3,107 @@ * * Matrix Clock * - * A simple clock inspired by the movie. - * Text shards move down the screen as a background to the + * A simple clock inspired by the movie. + * Text shards move down the screen as a background to the * time and date **/ const Locale = require('locale'); -const SHARD_COLOR =[0,1.0,0]; +const PREFERENCE_FILE = "matrixclock.settings.json"; +const settings = Object.assign({color: "theme", time_format: '12 hour', intensity: 'light'}, + require('Storage').readJSON(PREFERENCE_FILE, true) || {}); + +var format_time; +if(settings.time_format == '24 hour'){ + format_time = (t) => format_time_24_hour(t); +} else { + format_time = (t) => format_time_12_hour(t); +} + +const colors = { + 'gray' :[0.5,0.5,0.5], + 'green': [0,1.0,0], + 'red' : [1.0,0.0,0.0], + 'blue' : [0.0,0.0,1.0], + 'black': [0.0,0.0,0.0], + 'purple': [1.0,0.0,1.0], + 'white': [1.0,1.0,1.0], + 'yellow': [1.0,1.0,0.0] +}; + +const color_schemes = { + 'black on white': ['white','black'], + 'green on white' : ['white','green'], + 'green on black' : ['black','green'], + 'red on black' : ['black', 'red'], + 'red on white' : ['white', 'red'], + 'white on gray' : ['gray', 'white'], + 'white on red' : ['red', 'white'], + 'white on blue': ['blue','white'], + 'white on purple': ['purple', 'white'] +}; + +function int2Color(color_int){ + var blue_int = color_int & 31; + var blue = (blue_int)/31.0; + + var green_int = (color_int >> 5) & 31; + var green = (green_int)/31.0; + + var red_int = (color_int >> 11) & 31; + var red = red_int/ 31.0; + return [red,green,blue]; +} + +var fg_color = colors.black; +var bg_color = colors.white; + +// now lets deal with the settings +if(settings.color === "theme"){ + bg_color = int2Color(g.theme.bg); + if(g.theme.bg === 0) { + fg_color = colors.green; + } else { + fg_color = int2Color(g.theme.fg); + } +} else { + var color_scheme = color_schemes[settings.color]; + bg_color = colors[color_scheme[0]]; + fg_color = colors[color_scheme[1]]; + g.setBgColor(bg_color[0],bg_color[1],bg_color[2]); +} +if(fg_color === undefined) + fg_color = colors.black; + +if(bg_color === undefined) + bg_color = colors.white; + +const intensity_schemes = { + 'light': 3, + 'medium': 4, + 'high': 5 +}; + +var noShards = intensity_schemes.light; +if(settings.intensity !== undefined){ + noShards = intensity_schemes[settings.intensity]; +} +if(noShards === undefined){ + noShards = intensity_schemes.light; +} + const SHARD_FONT_SIZE = 12; const SHARD_Y_START = 30; + const w = g.getWidth(); /** -* The text shard object is responsible for creating the -* shards of text that move down the screen. As the -* shard moves down the screen the latest character added -* is brightest with characters being coloured darker and darker -* going back to the eldest -*/ + * The text shard object is responsible for creating the + * shards of text that move down the screen. As the + * shard moves down the screen the latest character added + * is brightest with characters being coloured darker and darker + * going back to the eldest + */ class TextShard { constructor(x,y,length){ @@ -34,44 +117,46 @@ class TextShard { this.txt = []; } /** - * The add method call adds another random character to - * the chain - */ + * The add method call adds another random character to + * the chain + */ add(){ this.txt.push(randomChar()); } /** - * The show method displays the latest shard image to the - * screen with the following rules: - * - latest addition is brightest, oldest is darker - * - display up to defined length of characters only - * of the shard to save cpu - */ + * The show method displays the latest shard image to the + * screen with the following rules: + * - latest addition is brightest, oldest is darker + * - display up to defined length of characters only + * of the shard to save cpu + */ show(){ g.setFontAlign(-1,-1,0); for(var i=0; i this.length - 2){ color_strength = 0; - } - g.setColor(color_strength*SHARD_COLOR[0], - color_strength*SHARD_COLOR[1], - color_strength*SHARD_COLOR[2]); + } + var bg_color_strength = 1 - color_strength; + g.setColor(Math.abs(color_strength*fg_color[0] - bg_color_strength*bg_color[0]), + Math.abs(color_strength*fg_color[1] - bg_color_strength*bg_color[1]), + Math.abs(color_strength*fg_color[2] - bg_color_strength*bg_color[2]) + ); g.setFont("Vector",SHARD_FONT_SIZE); - g.drawString(this.txt[idx], this.x, this.y + idx*SHARD_FONT_SIZE); + g.drawString(this.txt[idx], this.x, this.y + idx*SHARD_FONT_SIZE); } } /** - * Method tests to see if any part of the shard chain is still - * visible on the screen - */ + * Method tests to see if any part of the shard chain is still + * visible on the screen + */ isVisible(){ - return (this.y + (this.txt.length - this.length - 2)*SHARD_FONT_SIZE < g.getHeight()); + return (this.y + (this.txt.length - this.length - 2)*SHARD_FONT_SIZE < g.getHeight()); } /** - * resets the shard back to the top of the screen - */ + * resets the shard back to the top of the screen + */ reset(){ this.y = SHARD_Y_START; this.txt = []; @@ -79,8 +164,8 @@ class TextShard { } /** -* random character chooser to be called by the shard when adding characters -*/ + * random character chooser to be called by the shard when adding characters + */ const CHAR_CODE_START = 33; const CHAR_CODE_LAST = 126; const CHAR_CODE_LENGTH = CHAR_CODE_LAST - CHAR_CODE_START; @@ -90,11 +175,10 @@ function randomChar(){ // Now set up the shards // we are going to have a limited no of shards (to save cpu) -// but randomize the x value and length every reset to make it look as if there +// but randomize the x value and length every reset to make it look as if there // are more var shards = []; -const NO_SHARDS = 3; -const channel_width = g.getWidth()/NO_SHARDS; +const channel_width = g.getWidth()/noShards; function shard_x(i){ return i*channel_width + Math.random() * channel_width; @@ -104,7 +188,7 @@ function shard_length(){ return Math.floor(Math.random()*5) + 3; } -for(var i=0; i 99 || value < 0) - throw "must be between in range 0-99"; - if(value < 10) - return "0" + value.toString(); - else - return value.toString(); + var value = (num | 0); + if(value > 99 || value < 0) + throw "must be between in range 0-99"; + if(value < 10) + return "0" + value.toString(); + else + return value.toString(); } // The interval reference for updating the clock @@ -215,12 +304,12 @@ function startTimers(){ clearTimers(); if (Bangle.isLCDOn()) { intervalRef = setInterval(() => { - if (!shouldRedraw()) { - //console.log("draw clock callback - skipped redraw"); - } else { - draw_clock(); - } - }, 100 + if (!shouldRedraw()) { + //console.log("draw clock callback - skipped redraw"); + } else { + draw_clock(); + } + }, 100 ); draw_clock(); } else { @@ -239,11 +328,9 @@ Bangle.on('lcdPower', (on) => { } }); +Bangle.setUI("clock"); g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); startTimers(); -Bangle.setUI("clock"); - - diff --git a/apps/matrixclock/matrixclock.settings.js b/apps/matrixclock/matrixclock.settings.js new file mode 100644 index 000000000..1f22a045f --- /dev/null +++ b/apps/matrixclock/matrixclock.settings.js @@ -0,0 +1,52 @@ +(function(back) { + const PREFERENCE_FILE = "matrixclock.settings.json"; + var settings = Object.assign({color : "theme", time_format: '12 hour', intensity: "light"}, + require('Storage').readJSON(PREFERENCE_FILE, true) || {}); + + console.log("loaded:" + JSON.stringify(settings)); + + function writeSettings() { + console.log("saving:" + JSON.stringify(settings)); + require('Storage').writeJSON(PREFERENCE_FILE, settings); + } + + // Helper method which uses int-based menu item for set of string values + function stringItems(startvalue, writer, values) { + return { + value: (startvalue === undefined ? 0 : values.indexOf(startvalue)), + format: v => values[v], + min: 0, + max: values.length - 1, + wrap: true, + step: 1, + onchange: v => { + writer(values[v]); + writeSettings(); + } + }; + } + + // Helper method which breaks string set settings down to local settings object + function stringInSettings(name, values) { + return stringItems(settings[name], v => settings[name] = v, values); + } + + // Show the menu + E.showMenu({ + "" : { "title" : "Matrix Clock" }, + "< Back" : () => back(), + "Colour": stringInSettings("color", ['theme', + 'black on white', + 'green on white', + 'green on black', + 'red on white', + 'white on gray', + 'white on red', + 'white on blue' + ]), + "Time Format": stringInSettings("time_format", ['12 hour','24 hour']), + "Intensity": stringInSettings("intensity", ['light', + 'medium', + 'high']) + }); +}) \ No newline at end of file diff --git a/apps/matrixclock/metadata.json b/apps/matrixclock/metadata.json index 122cee3a1..718b878e5 100644 --- a/apps/matrixclock/metadata.json +++ b/apps/matrixclock/metadata.json @@ -1,10 +1,10 @@ { "id": "matrixclock", "name": "Matrix Clock", - "version": "0.04", + "version": "0.07", "description": "inspired by The Matrix, a clock of the same style", "icon": "matrixclock.png", - "screenshots": [{"url":"screenshot_matrix.png"}], + "screenshots": [{"url":"matrix_green_on_black.jpg"}], "type": "clock", "tags": "clock", "supports": ["BANGLEJS","BANGLEJS2"], @@ -12,6 +12,8 @@ "allow_emulator": true, "storage": [ {"name":"matrixclock.app.js","url":"matrixclock.js"}, + { "name":"matrixclock.settings.js","url":"matrixclock.settings.js"}, {"name":"matrixclock.img","url":"matrixclock-icon.js","evaluate":true} - ] + ], + "data": [{"name": "matrixclock.settings.json"}] } diff --git a/apps/matrixclock/screenshot_matrix.png b/apps/matrixclock/screenshot_matrix.png deleted file mode 100644 index 3d843848c..000000000 Binary files a/apps/matrixclock/screenshot_matrix.png and /dev/null differ diff --git a/apps/mclock/ChangeLog b/apps/mclock/ChangeLog index 05b422406..e3b164942 100644 --- a/apps/mclock/ChangeLog +++ b/apps/mclock/ChangeLog @@ -5,3 +5,4 @@ Fix issue where first digit could get stuck going from "2x:xx" to " x:xx" (fix #365) 0.06: Support 12 hour time 0.07: Use Bangle.setUI for button/launcher handling +0.08: Tell clock widgets to hide. diff --git a/apps/mclock/clock-morphing.js b/apps/mclock/clock-morphing.js index f1254860b..bd133206e 100644 --- a/apps/mclock/clock-morphing.js +++ b/apps/mclock/clock-morphing.js @@ -209,6 +209,9 @@ Bangle.on('lcdPower',function(on) { } }); +// Show launcher when button pressed +Bangle.setUI("clock"); + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); @@ -216,5 +219,3 @@ Bangle.drawWidgets(); timeInterval = setInterval(showTime, 1000); showTime(); -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/mclock/metadata.json b/apps/mclock/metadata.json index 513f823a1..a7d56f752 100644 --- a/apps/mclock/metadata.json +++ b/apps/mclock/metadata.json @@ -1,7 +1,7 @@ { "id": "mclock", "name": "Morphing Clock", - "version": "0.07", + "version": "0.08", "description": "7 segment clock that morphs between minutes and hours", "icon": "clock-morphing.png", "type": "clock", diff --git a/apps/medicalinfo/ChangeLog b/apps/medicalinfo/ChangeLog new file mode 100644 index 000000000..e8739a121 --- /dev/null +++ b/apps/medicalinfo/ChangeLog @@ -0,0 +1 @@ +0.01: Initial Medical Information application! diff --git a/apps/medicalinfo/README.md b/apps/medicalinfo/README.md new file mode 100644 index 000000000..6dd19d4c6 --- /dev/null +++ b/apps/medicalinfo/README.md @@ -0,0 +1,27 @@ +# Medical Information + +This app displays basic medical information, and provides a common way to set up the `medicalinfo.json` file, which other apps can use if required. + +## Medical information JSON file + +When the app is loaded from the app loader, a file named `medicalinfo.json` is loaded along with the javascript etc. +The file has the following contents: + +``` +{ + "bloodType": "", + "height": "", + "weight": "", + "medicalAlert": [ "" ] +} +``` + +## Medical information editor + +Clicking on the download icon of `Medical Information` in the app loader invokes the editor. +The editor downloads and displays the current `medicalinfo.json` file, which can then be edited. +The edited `medicalinfo.json` file is uploaded to the Bangle by clicking the `Upload` button. + +## Creator + +James Taylor ([jt-nti](https://github.com/jt-nti)) diff --git a/apps/medicalinfo/app-icon.js b/apps/medicalinfo/app-icon.js new file mode 100644 index 000000000..1ae7916fb --- /dev/null +++ b/apps/medicalinfo/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwg+7kUiCykCC4MgFykgDIIXUAQgAMiMRiREBC4YABkILBCxEBC4pHCC4kQFxIXEAAgXCGBERif/+QXHl//mIXJj//+YXHn//+IXL/8yCwsjBIIXNABIX/C63d7oDB+czmaPPC7hHR/oWBAAPfC65HRC7qnXX/4XDABAXkIIQAFI5wXXL/5f/L/5fvC9sTC5cxC5IAOC48BCxsQC44wOCxAArA")) diff --git a/apps/medicalinfo/app.js b/apps/medicalinfo/app.js new file mode 100644 index 000000000..9c4941744 --- /dev/null +++ b/apps/medicalinfo/app.js @@ -0,0 +1,61 @@ +const medicalinfo = require('medicalinfo').load(); +// const medicalinfo = { +// bloodType: "O+", +// height: "166cm", +// weight: "73kg" +// }; + +function hasAlert(info) { + return (Array.isArray(info.medicalAlert)) && (info.medicalAlert[0]); +} + +// No space for widgets! +// TODO: no padlock widget visible so prevent screen locking? + +g.clear(); +const bodyFont = g.getFonts().includes("12x20") ? "12x20" : "6x8:2"; +g.setFont(bodyFont); + +const title = hasAlert(medicalinfo) ? "MEDICAL ALERT" : "Medical Information"; +var lines = []; + +lines = g.wrapString(title, g.getWidth() - 10); +var titleCnt = lines.length; +if (titleCnt) lines.push(""); // add blank line after title + +if (hasAlert(medicalinfo)) { + medicalinfo.medicalAlert.forEach(function (details) { + lines = lines.concat(g.wrapString(details, g.getWidth() - 10)); + }); + lines.push(""); // add blank line after medical alert +} + +if (medicalinfo.bloodType) { + lines = lines.concat(g.wrapString("Blood group: " + medicalinfo.bloodType, g.getWidth() - 10)); +} +if (medicalinfo.height) { + lines = lines.concat(g.wrapString("Height: " + medicalinfo.height, g.getWidth() - 10)); +} +if (medicalinfo.weight) { + lines = lines.concat(g.wrapString("Weight: " + medicalinfo.weight, g.getWidth() - 10)); +} + +lines.push(""); + +// TODO: display instructions for updating medical info if there is none! + +E.showScroller({ + h: g.getFontHeight(), // height of each menu item in pixels + c: lines.length, // number of menu items + // a function to draw a menu item + draw: function (idx, r) { + // FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12 + g.setBgColor(idx < titleCnt ? g.theme.bg2 : g.theme.bg). + setColor(idx < titleCnt ? g.theme.fg2 : g.theme.fg). + clearRect(r.x, r.y, r.x + r.w, r.y + r.h); + g.setFont(bodyFont).drawString(lines[idx], r.x, r.y); + } +}); + +// Show launcher when button pressed +setWatch(() => load(), process.env.HWVERSION === 2 ? BTN : BTN3, { repeat: false, edge: "falling" }); diff --git a/apps/medicalinfo/app.png b/apps/medicalinfo/app.png new file mode 100644 index 000000000..16204ea89 Binary files /dev/null and b/apps/medicalinfo/app.png differ diff --git a/apps/medicalinfo/interface.html b/apps/medicalinfo/interface.html new file mode 100644 index 000000000..9376be32f --- /dev/null +++ b/apps/medicalinfo/interface.html @@ -0,0 +1,135 @@ + + + + + + + +
+ + + + + +

+
+    
+    
+  
+
diff --git a/apps/medicalinfo/lib.js b/apps/medicalinfo/lib.js
new file mode 100644
index 000000000..683005359
--- /dev/null
+++ b/apps/medicalinfo/lib.js
@@ -0,0 +1,21 @@
+const storage = require('Storage');
+
+exports.load = function () {
+  const medicalinfo = storage.readJSON('medicalinfo.json') || {
+    bloodType: "",
+    height: "",
+    weight: "",
+    medicalAlert: [""]
+  };
+
+  // Don't return anything unexpected
+  const expectedMedicalinfo = [
+    "bloodType",
+    "height",
+    "weight",
+    "medicalAlert"
+  ].filter(key => key in medicalinfo)
+    .reduce((obj, key) => (obj[key] = medicalinfo[key], obj), {});
+
+  return expectedMedicalinfo;
+};
diff --git a/apps/medicalinfo/medicalinfo.json b/apps/medicalinfo/medicalinfo.json
new file mode 100644
index 000000000..8b49725cb
--- /dev/null
+++ b/apps/medicalinfo/medicalinfo.json
@@ -0,0 +1,6 @@
+{
+    "bloodType": "",
+    "height": "",
+    "weight": "",
+    "medicalAlert": [ "" ]
+}
diff --git a/apps/medicalinfo/metadata.json b/apps/medicalinfo/metadata.json
new file mode 100644
index 000000000..f1a0c145f
--- /dev/null
+++ b/apps/medicalinfo/metadata.json
@@ -0,0 +1,20 @@
+{ "id": "medicalinfo",
+  "name": "Medical Information",
+  "version":"0.01",
+  "description": "Provides 'medicalinfo.json' used by various health apps, as well as a way to edit it from the App Loader",
+  "icon": "app.png",
+  "tags": "health,medical",
+  "type": "app",
+  "supports" : ["BANGLEJS","BANGLEJS2"],
+  "readme": "README.md",
+  "screenshots": [{"url":"screenshot_light.png"}],
+  "interface": "interface.html",
+  "storage": [
+    {"name":"medicalinfo.app.js","url":"app.js"},
+    {"name":"medicalinfo.img","url":"app-icon.js","evaluate":true},
+    {"name":"medicalinfo","url":"lib.js"}
+  ],
+  "data": [
+    {"name":"medicalinfo.json","url":"medicalinfo.json"}
+  ]
+}
diff --git a/apps/medicalinfo/screenshot_light.png b/apps/medicalinfo/screenshot_light.png
new file mode 100644
index 000000000..42970f9fc
Binary files /dev/null and b/apps/medicalinfo/screenshot_light.png differ
diff --git a/apps/messagegui/ChangeLog b/apps/messagegui/ChangeLog
new file mode 100644
index 000000000..228a952de
--- /dev/null
+++ b/apps/messagegui/ChangeLog
@@ -0,0 +1,88 @@
+0.01: New App!
+0.02: Add 'messages' library
+0.03: Fixes for Bangle.js 1
+0.04: Add require("messages").clearAll()
+0.05: Handling of message actions (ok/clear)
+0.06: New messages now go at the start (fix #898)
+      Answering true/false now exits the messages app if no new messages
+      Back now marks a message as read
+      Clicking top-left opens a menu which allows you to delete a message or mark unread
+0.07: Added settings menu with option to choose vibrate pattern and frequency (fix #909)
+0.08: Fix rendering of long messages (fix #969)
+      buzz on new message (fix #999)
+0.09: Message now disappears after 60s if no action taken and clock loads (fix 922)
+      Fix phone icon (#1014)
+0.10: Respect the 'new' attribute if it was set from iOS integrations
+0.11: Open app when touching the widget (Bangle.js 2 only)
+0.12: Extra app-specific notification icons
+      New animated notification icon (instead of large blinking 'MESSAGES')
+      Added screenshots
+0.13: Add /*LANG*/ comments for internationalisation
+      Add 'Delete All' option to message options
+      Now update correctly when 'require("messages").clearAll()' is called
+0.14: Hide widget when all unread notifications are dismissed from phone
+0.15: Don't buzz when Quiet Mode is active
+0.16: Fix text wrapping so it fits the screen even if title is big (fix #1147)
+0.17: Fix: Get dynamic dimensions of notify icon, fixed notification font
+0.18: Use app-specific icon colors
+      Spread message action buttons out
+      Back button now goes back to list of messages
+      If showMessage called with no message (eg all messages deleted) now return to the clock (fix #1267)
+0.19: Use a larger font for message text if it'll fit
+0.20: Allow tapping on the body to show a scrollable view of the message and title in a bigger font (fix #1405, #1031)
+0.21: Improve list readability on dark theme
+0.22: Add Home Assistant icon
+      Allow repeat to be switched Off, so there is no buzzing repetition.
+      Also gave the widget a pixel more room to the right
+0.23: Change message colors to match current theme instead of using green
+      Now attempt to use Large/Big/Medium fonts, and allow minimum font size to be configured
+0.24: Remove left-over debug statement
+0.25: Fix widget memory usage issues if message received and watch repeatedly calls Bangle.drawWidgets (fix #1550)
+0.26: Setting to auto-open music
+0.27: Add 'mark all read' option to popup menu (fix #1624)
+0.28: Option to auto-unlock the watch when a new message arrives
+0.29: Fix message list overwrites on Bangle.js 1 (fix #1642)
+0.30: Add new Icons (Youtube, Twitch, MS TODO, Teams, Snapchat, Signal, Post & DHL, Nina, Lieferando, Kalender, Discord, Corona Warn, Bibel)
+0.31: Option to disable icon flashing
+0.32: Added an option to allow quiet mode to override message auto-open
+0.33: Timeout from the message list screen if the message being displayed is removed and there is a timer going
+0.34: Don't buzz for 'map' update messages
+0.35: Reset graphics colors before rendering a message (possibly fix #1752)
+0.36: Ensure a new message plus an almost immediate deletion of that message doesn't load the messages app (fix #1362)
+0.37: Now use the setUI 'back' icon in the top left rather than specific buttons/menu items
+0.38: Add telegram foss handling
+0.39: Set default color for message icons according to theme
+0.40: Use default Bangle formatter for booleans
+0.41: Add notification icons in the widget
+0.42: Fix messages ignoring "Vibrate: Off" setting
+0.43: Add new Icons (Airbnb, warnwetter)
+0.44: Separate buzz pattern for incoming calls
+0.45: Added new app colors and icons
+0.46: Add 'Vibrate Timer' option to set how long to vibrate for, and fix Repeat:off
+      Fix message removal from widget bar (previously caused exception as .hide has been removed)
+0.47: Add new Icons (Nextbike, Mattermost, etc.)
+0.48: When getting new message from the clock, only buzz once the messages app is loaded
+0.49: Change messages icon (to fit within 24px) and ensure widget renders icons centrally
+0.50: Add `getMessages` and `status` functions to library
+      Option to disable auto-open of messages
+      Option to make message icons monochrome (not colored)
+      messages widget buzz now returns a promise
+0.51: Emit "message events"
+      Setting to hide widget
+      Add custom event handlers to prevent default app form loading
+      Move WIDGETS.messages.buzz() to require("messages").buzz()
+0.52: Fix require("messages").buzz() regression
+      Fix background color in messages list after one unread message is shown
+0.53: Messages now uses Bangle.load() to load messages app faster (if possible)
+0.54: Move icons out to messageicons module
+0.55: Rename to messagegui, move global message handling library to message module
+      Move widget to widmessage
+0.56: Fix handling of music messages
+0.57: Fix "unread Timeout" = off (previously defaulted to 60s)
+0.58: Fast load messages without writing to flash
+      Don't write messages to flash until the app closes
+0.59: Ensure we do write messages if messages app can't be fast loaded (see #2373)
+0.60: Fix saving of removal messages if UI not open
+0.61: Fix regression where loading into messages app stops back from working (#2398)
+0.62: Remove '.show' field, tidyup and fix .open if fast load not enabled
+0.63: Fix messages app loading on clock without fast load
diff --git a/apps/messagegui/README.md b/apps/messagegui/README.md
new file mode 100644
index 000000000..699588e1b
--- /dev/null
+++ b/apps/messagegui/README.md
@@ -0,0 +1,68 @@
+# Messages app
+
+Default app to handle the display of messages and message notifications. It allows 
+them to be listed, viewed, and responded to.
+It is installed automatically if you install `Android Integration` or `iOS Integration`.
+
+It is a replacement for the old `notify`/`gadgetbridge` apps.
+
+
+## Settings
+
+You can change settings by going to the global `Settings` app, then `App Settings`
+and `Messages`:
+
+* `Vibrate` - This is the pattern of buzzes that should be made when a new message is received
+* `Vibrate for calls` - This is the pattern of buzzes that should be made when an incoming call is received
+* `Repeat` - How often should buzzes repeat - the default of 4 means the Bangle will buzz every 4 seconds
+* `Vibrate Timer` - When a new message is received when in a non-clock app, we display the message icon and
+buzz every `Repeat` seconds. This is how long we continue to do that.
+* `Unread Timer` - When a new message is received when showing the clock we go into the Messages app.
+If there is no user input for this amount of time then the app will exit and return
+to the clock where a ringing bell will be shown in the Widget bar.
+* `Min Font` - The minimum font size used when displaying messages on the screen. A bigger font
+is chosen if there isn't much message text, but this specifies the smallest the font should get before
+it starts getting clipped.
+* `Auto-Open Music` - Should the app automatically open when the phone starts playing music?
+* `Unlock Watch` - Should the app unlock the watch when a new message arrives, so you can touch the buttons at the bottom of the app?
+
+## New Messages
+
+When a new message is received:
+
+* If you're in an app, the Bangle will buzz and a message icon appears in the Widget bar. You can tap this icon to view the message.
+* If you're in a clock, the Messages app will automatically start and show the message
+
+When a message is shown, you'll see a screen showing the message title and text.
+
+* The 'back-arrow' button (or physical button on Bangle.js 2) goes back to Messages, marking the current message as read.
+* The top-left icon shows more options, for instance deleting the message of marking unread
+* On Bangle.js 2 you can tap on the message body to view a scrollable version of the title and text (or can use the top-left icon + `View Message`)
+* If shown, the 'tick' button:
+   * **Android** opens the notification on the phone
+   * **iOS** responds positively to the notification (accept call/etc)
+* If shown, the 'cross' button:
+   * **Android** dismisses the notification on the phone
+   * **iOS** responds negatively to the notification (dismiss call/etc)
+
+## Images
+_1. Screenshot of a notification_
+
+![](screenshot.png)
+
+
+## Requests
+
+Please file any issues on https://github.com/espruino/BangleApps/issues/new?title=messages%20app
+
+## Creator
+
+Gordon Williams
+
+## Contributors
+
+[Jeroen Peters](https://github.com/jeroenpeters1986)
+
+## Attributions
+
+Icons used in this app are from https://icons8.com
diff --git a/apps/messages/app-icon.js b/apps/messagegui/app-icon.js
similarity index 100%
rename from apps/messages/app-icon.js
rename to apps/messagegui/app-icon.js
diff --git a/apps/messagegui/app-newmessage.js b/apps/messagegui/app-newmessage.js
new file mode 100644
index 000000000..73d9a79c1
--- /dev/null
+++ b/apps/messagegui/app-newmessage.js
@@ -0,0 +1,5 @@
+/* Called when we have a new message when we're in the clock...
+BUZZ_ON_NEW_MESSAGE is set so when messagegui.app.js loads it knows
+that it should buzz */
+global.BUZZ_ON_NEW_MESSAGE = true;
+eval(require("Storage").read("messagegui.app.js"));
diff --git a/apps/messages/app.js b/apps/messagegui/app.js
similarity index 83%
rename from apps/messages/app.js
rename to apps/messagegui/app.js
index d4540b797..b158310a1 100644
--- a/apps/messages/app.js
+++ b/apps/messagegui/app.js
@@ -19,7 +19,6 @@ require("messages").pushMessage({"t":"add","id":1,"src":"Maps","title":"0 yd - H
 // call
 require("messages").pushMessage({"t":"add","id":"call","src":"Phone","title":"Bob","body":"12421312",positive:true,negative:true})
 */
-
 var Layout = require("Layout");
 var settings = require('Storage').readJSON("messages.settings.json", true) || {};
 var fontSmall = "6x8";
@@ -48,14 +47,21 @@ we should start a timeout for settings.unreadTimeout to return
 to the clock. */
 var unreadTimeout;
 /// List of all our messages
-var MESSAGES = require("Storage").readJSON("messages.json",1)||[];
-if (!Array.isArray(MESSAGES)) MESSAGES=[];
-var onMessagesModified = function(msg) {
+var MESSAGES = require("messages").getMessages();
+if (Bangle.MESSAGES) {
+  // fast loading messages
+  Bangle.MESSAGES.forEach(m => require("messages").apply(m, MESSAGES));
+  delete Bangle.MESSAGES;
+}
+
+var onMessagesModified = function(type,msg) {
+  if (msg.handled) return;
+  msg.handled = true;
+  require("messages").apply(msg, MESSAGES);
   // TODO: if new, show this new one
   if (msg && msg.id!=="music" && msg.new && active!="map" &&
       !((require('Storage').readJSON('setting.json', 1) || {}).quiet)) {
-    if (WIDGETS["messages"]) WIDGETS["messages"].buzz();
-    else Bangle.buzz();
+    require("messages").buzz(msg.src);
   }
   if (msg && msg.id=="music") {
     if (msg.state && msg.state!="play") openMusic = false; // no longer playing music to go back to
@@ -63,14 +69,16 @@ var onMessagesModified = function(msg) {
   }
   showMessage(msg&&msg.id);
 };
+Bangle.on("message", onMessagesModified);
+
 function saveMessages() {
-  require("Storage").writeJSON("messages.json",MESSAGES)
+  require("messages").write(MESSAGES);
 }
+E.on("kill", saveMessages);
 
 function showMapMessage(msg) {
   active = "map";
-  var m;
-  var distance, street, target, eta;
+  var m, distance, street, target, eta;
   m=msg.title.match(/(.*) - (.*)/);
   if (m) {
     distance = m[1];
@@ -99,16 +107,18 @@ function showMapMessage(msg) {
   layout.render();
   function back() { // mark as not new and return to menu
     msg.new = false;
-    saveMessages();
     layout = undefined;
     checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0});
   }
   Bangle.setUI({mode:"updown", back: back}, back); // any input takes us back
 }
 
-var updateLabelsInterval;
+let updateLabelsInterval;
+
 function showMusicMessage(msg) {
   active = "music";
+  // defaults, so e.g. msg.xyz.length doesn't error. `msg` should contain up to date info
+  msg = Object.assign({artist: "", album: "", track: "Music"}, msg);
   openMusic = msg.state=="play";
   var trackScrollOffset = 0;
   var artistScrollOffset = 0;
@@ -132,7 +142,6 @@ function showMusicMessage(msg) {
     openMusic = false;
     var wasNew = msg.new;
     msg.new = false;
-    saveMessages();
     layout = undefined;
     if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
     else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
@@ -215,24 +224,20 @@ function showMessageSettings(msg) {
     },
     /*LANG*/"Delete" : () => {
       MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
-      saveMessages();
       checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
     },
     /*LANG*/"Mark Unread" : () => {
       msg.new = true;
-      saveMessages();
       checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
     },
     /*LANG*/"Mark all read" : () => {
       MESSAGES.forEach(msg => msg.new = false);
-      saveMessages();
       checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
     },
     /*LANG*/"Delete all messages" : () => {
       E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
         if (isYes) {
           MESSAGES = [];
-          saveMessages();
         }
         checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
       });
@@ -286,7 +291,8 @@ function showMessage(msgid) {
     }
   }
   function goBack() {
-    msg.new = false; saveMessages(); // read mail
+    layout = undefined;
+    msg.new = false; // read mail
     cancelReloadTimeout(); // don't auto-reload to clock now
     checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
   }
@@ -294,7 +300,7 @@ function showMessage(msgid) {
   ];
   if (msg.positive) {
     buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{
-      msg.new = false; saveMessages();
+      msg.new = false;
       cancelReloadTimeout(); // don't auto-reload to clock now
       Bangle.messageResponse(msg,true);
       checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
@@ -303,7 +309,7 @@ function showMessage(msgid) {
   if (msg.negative) {
     if (buttons.length) buttons.push({width:32}); // nasty hack...
     buttons.push({type:"btn", src:atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA="), cb:()=>{
-      msg.new = false; saveMessages();
+      msg.new = false;
       cancelReloadTimeout(); // don't auto-reload to clock now
       Bangle.messageResponse(msg,false);
       checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
@@ -317,10 +323,14 @@ function showMessage(msgid) {
         {type:"txt", font:fontSmall, label:msg.src||/*LANG*/"Message", bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2, halign:1 },
         title?{type:"txt", font:titleFont, label:title, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }:{},
       ]},
-      { type:"btn", src:require("messages").getMessageImage(msg), col:require("messages").getMessageImageCol(msg, g.theme.fg2), pad: 3, cb:()=>{
-        cancelReloadTimeout(); // don't auto-reload to clock now
-        showMessageSettings(msg);
-      }},
+      { type:"btn",
+        src:require("messageicons").getImage(msg),
+        col:require("messageicons").getColor(msg, {settings:settings, default:g.theme.fg2}),
+        pad: 3, cb:()=>{
+          cancelReloadTimeout(); // don't auto-reload to clock now
+          showMessageSettings(msg);
+        }
+      },
     ]},
     {type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
       // allow tapping to show a larger version
@@ -337,6 +347,7 @@ function showMessage(msgid) {
   clockIfNoMsg : bool
   clockIfAllRead : bool
   showMsgIfUnread : bool
+  openMusic : bool      // open music if it's playing
 }
 */
 function checkMessages(options) {
@@ -353,10 +364,21 @@ function checkMessages(options) {
   // we have >0 messages
   var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music");
   // If we have a new message, show it
-  if (options.showMsgIfUnread && newMessages.length)
-    return showMessage(newMessages[0].id);
-  // no new messages: show playing music? (only if we have playing music to show)
-  if (options.openMusic && MESSAGES.some(m=>m.id=="music" && m.track && m.state=="play"))
+  if (options.showMsgIfUnread && newMessages.length) {
+    delete newMessages[0].show; // stop us getting stuck here if we're called a second time
+    showMessage(newMessages[0].id);
+    // buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
+    if (global.BUZZ_ON_NEW_MESSAGE) {
+      // this is set if we entered the messages app by loading `messagegui.new.js`
+      // ... but only buzz the first time we view a new message
+      global.BUZZ_ON_NEW_MESSAGE = false;
+      // messages.buzz respects quiet mode - no need to check here
+      require("messages").buzz(newMessages[0].src);
+    }
+    return;
+  }
+  // no new messages: show playing music? Only if we have playing music, or state=="show" (set by messagesmusic)
+  if (options.openMusic && MESSAGES.some(m=>m.id=="music" && ((m.track && m.state=="play") || m.state=="show")))
     return showMessage('music');
   // no new messages - go to clock?
   if (options.clockIfAllRead && newMessages.length==0)
@@ -369,18 +391,19 @@ function checkMessages(options) {
     draw : function(idx, r) {"ram"
       var msg = MESSAGES[idx];
       if (msg && msg.new) g.setBgColor(g.theme.bgH).setColor(g.theme.fgH);
-      else g.setColor(g.theme.fg);
+      else g.setBgColor(g.theme.bg).setColor(g.theme.fg);
       g.clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
       if (!msg) return;
       var x = r.x+2, title = msg.title, body = msg.body;
-      var img = require("messages").getMessageImage(msg);
+      var img = require("messageicons").getImage(msg);
       if (msg.id=="music") {
         title = msg.artist || /*LANG*/"Music";
         body = msg.track;
       }
       if (img) {
-        var fg = g.getColor();
-        g.setColor(require("messages").getMessageImageCol(msg,fg)).drawImage(img, x+24, r.y+24, {rotate:0}) // force centering
+        var fg = g.getColor(),
+            col = require("messageicons").getColor(msg, {settings:settings, default:fg});
+        g.setColor(col).drawImage(img, x+24, r.y+24, {rotate:0}) // force centering
          .setColor(fg); // only color the icon
         x += 50;
       }
@@ -414,14 +437,16 @@ function cancelReloadTimeout() {
 g.clear();
 
 Bangle.loadWidgets();
+require("messages").toggleWidget(false);
 Bangle.drawWidgets();
 
 setTimeout(() => {
-  var unreadTimeoutMillis = (settings.unreadTimeout || 60) * 1000;
-  if (unreadTimeoutMillis) {
-    unreadTimeout = setTimeout(load, unreadTimeoutMillis);
-  }
-  // only openMusic on launch if music is new
-  var newMusic = MESSAGES.some(m => m.id === "music" && m.new);
-  checkMessages({ clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1, openMusic: newMusic && settings.openMusic });
+  if (!isFinite(settings.unreadTimeout)) settings.unreadTimeout=60;
+  if (settings.unreadTimeout)
+    unreadTimeout = setTimeout(load, settings.unreadTimeout*1000);
+  // only openMusic on launch if music is new, or state=="show" (set by messagesmusic)
+  var musicMsg = MESSAGES.find(m => m.id === "music");
+  checkMessages({
+    clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1,
+    openMusic: ((musicMsg&&musicMsg.new) && settings.openMusic) || (musicMsg&&musicMsg.state=="show") });
 }, 10); // if checkMessages wants to 'load', do that
diff --git a/apps/messagegui/app.png b/apps/messagegui/app.png
new file mode 100644
index 000000000..c9177692e
Binary files /dev/null and b/apps/messagegui/app.png differ
diff --git a/apps/messagegui/boot.js b/apps/messagegui/boot.js
new file mode 100644
index 000000000..ce7f1b99c
--- /dev/null
+++ b/apps/messagegui/boot.js
@@ -0,0 +1 @@
+Bangle.on("message", (type, msg) => require("messagegui").listener(type, msg));
diff --git a/apps/messagegui/lib.js b/apps/messagegui/lib.js
new file mode 100644
index 000000000..a9436a77b
--- /dev/null
+++ b/apps/messagegui/lib.js
@@ -0,0 +1,101 @@
+// Will calling Bangle.load reset everything? if false, we fast load
+function loadWillReset() {
+  return Bangle.load === load || !Bangle.uiRemove;
+    /* FIXME: Maybe we need a better way of deciding if an app will
+    be fast loaded than just hard-coding a Bangle.uiRemove check.
+    Bangle.load could return a bool (as the load doesn't happen immediately). */
+}
+
+/**
+ * Listener set up in boot.js, calls into here to keep boot.js short
+ */
+exports.listener = function(type, msg) {
+  // Default handler: Launch the GUI for all unhandled messages (except music if disabled in settings)
+  if (msg.handled || (global.__FILE__ && __FILE__.startsWith('messagegui.'))) return; // already handled or app open
+
+  // if no new messages now, make sure we don't load the messages app
+  if (exports.messageTimeout && !msg.new && require("messages").status(msg) !== "new") {
+    clearTimeout(exports.messageTimeout);
+    delete exports.messageTimeout;
+  }
+  if (msg.t==="remove") {
+    // we won't open the UI for removed messages, so make sure to delete it from flash
+    if (Bangle.MESSAGES) {
+      // we were waiting for exports.messageTimeout
+      require("messages").apply(msg, Bangle.MESSAGES);
+      if (!Bangle.MESSAGES.length) delete Bangle.MESSAGES;
+    }
+    return require("messages").save(msg); // always write removal to flash
+  }
+
+  const appSettings = require("Storage").readJSON("messages.settings.json", 1) || {};
+  let loadMessages = (Bangle.CLOCK || event.important); // should we load the messages app?
+  if (type==="music") {
+    if (Bangle.CLOCK && msg.state && msg.title && appSettings.openMusic) loadMessages = true;
+    else return;
+  }
+  // Write the message to Bangle.MESSAGES. We'll deal with it in messageTimeout below
+  if (!Bangle.MESSAGES) Bangle.MESSAGES = [];
+  require("messages").apply(msg, Bangle.MESSAGES);
+  if (!Bangle.MESSAGES.length) delete Bangle.MESSAGES;
+  const saveToFlash = () => {
+    // save messages from RAM to flash if we decide not to launch app
+    // We apply all of Bangle.MESSAGES here in one write
+    if (!Bangle.MESSAGES || !Bangle.MESSAGES.length) return;
+    let messages = require("messages").getMessages(msg);
+    (Bangle.MESSAGES || []).forEach(m => require("messages").apply(m, messages));
+    require("messages").write(messages);
+    delete Bangle.MESSAGES;
+  }
+  msg.handled = true;
+  if ((msg.t!=="add" || !msg.new) && (type!=="music")) // music always has t:"modify"
+    return saveToFlash();
+
+  const quiet = (require("Storage").readJSON("setting.json", 1) || {}).quiet;
+  const unlockWatch = appSettings.unlockWatch;
+  // don't auto-open messages in quiet mode if quietNoAutOpn is true
+  if ((quiet && appSettings.quietNoAutOpn) || appSettings.noAutOpn)
+    loadMessages = false;
+  // after a delay load the app, to ensure we have all the messages
+  if (exports.messageTimeout) clearTimeout(exports.messageTimeout);
+  exports.messageTimeout = setTimeout(function() {
+    delete exports.messageTimeout;
+    if (!Bangle.MESSAGES) return; // message was removed during the delay
+    if (type!=="music") {
+      if (!loadMessages) {
+        // not opening the app, just buzz
+        saveToFlash();
+        return require("messages").buzz(msg.src);
+      }
+      if (!quiet && unlockWatch) {
+        Bangle.setLocked(false);
+        Bangle.setLCDPower(1); // turn screen on
+      }
+    }
+    // if loading the gui would reload everything, we must save our messages
+    if (loadWillReset()) saveToFlash();
+    exports.open(msg);
+  }, 500);
+};
+
+/**
+ * Launch GUI app with given message
+ * @param {object} msg
+ */
+exports.open = function(msg) {
+  if (msg && msg.id) {
+    // force a display by setting it as new and ensuring it ends up at the beginning of messages list
+    msg.new = 1;
+    if (loadWillReset()) {
+      // no fast loading: store message to load in flash - `msg` will be put in first
+      require("messages").save(msg, {force: 1});
+    } else {
+      // fast load - putting it at the end of Bangle.MESSAGES ensures it goes at the start of messages list
+      if (!Bangle.MESSAGES) Bangle.MESSAGES=[];
+      Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id!=msg.id)
+      Bangle.MESSAGES.push(msg); // putting at the
+    }
+  }
+
+  Bangle.load((msg && msg.new && msg.id!=="music") ? "messagegui.new.js" : "messagegui.app.js");
+};
diff --git a/apps/messagegui/metadata.json b/apps/messagegui/metadata.json
new file mode 100644
index 000000000..1a7a6c750
--- /dev/null
+++ b/apps/messagegui/metadata.json
@@ -0,0 +1,24 @@
+{
+  "id": "messagegui",
+  "name": "Message UI",
+  "shortName": "Messages",
+  "version": "0.63",
+  "description": "Default app to display notifications from iOS and Gadgetbridge/Android",
+  "icon": "app.png",
+  "type": "app",
+  "tags": "tool,system",
+  "supports": ["BANGLEJS","BANGLEJS2"],
+  "dependencies" : { "messageicons":"module" },
+  "provides_modules": ["messagegui"],
+  "default": true,
+  "readme": "README.md",
+  "storage": [
+    {"name":"messagegui","url":"lib.js"},
+    {"name":"messagegui.app.js","url":"app.js"},
+    {"name":"messagegui.new.js","url":"app-newmessage.js"},
+    {"name":"messagegui.boot.js","url":"boot.js"},
+    {"name":"messagegui.img","url":"app-icon.js","evaluate":true}
+  ],
+  "screenshots": [{"url":"screenshot.png"}],
+  "sortorder": -9
+}
diff --git a/apps/messages/screenshot.png b/apps/messagegui/screenshot.png
similarity index 100%
rename from apps/messages/screenshot.png
rename to apps/messagegui/screenshot.png
diff --git a/apps/messageicons/ChangeLog b/apps/messageicons/ChangeLog
new file mode 100644
index 000000000..c923b169f
--- /dev/null
+++ b/apps/messageicons/ChangeLog
@@ -0,0 +1,5 @@
+0.01: Moved message icons from messages into standalone library
+0.02: Added several new icons and colors
+0.03: Fix icons broken in 0v02 (#2386)
+      Store all icons in a separate binary file (much faster lookup)
+
diff --git a/apps/messageicons/app.png b/apps/messageicons/app.png
new file mode 100644
index 000000000..1e47a39c6
Binary files /dev/null and b/apps/messageicons/app.png differ
diff --git a/apps/messageicons/icons.img b/apps/messageicons/icons.img
new file mode 100644
index 000000000..104168357
Binary files /dev/null and b/apps/messageicons/icons.img differ
diff --git a/apps/messageicons/icons/1password.png b/apps/messageicons/icons/1password.png
new file mode 100644
index 000000000..7e28c0c93
Binary files /dev/null and b/apps/messageicons/icons/1password.png differ
diff --git a/apps/messageicons/icons/airbnb.png b/apps/messageicons/icons/airbnb.png
new file mode 100644
index 000000000..f691469bc
Binary files /dev/null and b/apps/messageicons/icons/airbnb.png differ
diff --git a/apps/messageicons/icons/alarm.png b/apps/messageicons/icons/alarm.png
new file mode 100644
index 000000000..22a5b6cc4
Binary files /dev/null and b/apps/messageicons/icons/alarm.png differ
diff --git a/apps/messageicons/icons/amazon.png b/apps/messageicons/icons/amazon.png
new file mode 100644
index 000000000..9d446cb6a
Binary files /dev/null and b/apps/messageicons/icons/amazon.png differ
diff --git a/apps/messageicons/icons/bag.png b/apps/messageicons/icons/bag.png
new file mode 100644
index 000000000..70dab4221
Binary files /dev/null and b/apps/messageicons/icons/bag.png differ
diff --git a/apps/messageicons/icons/bank.png b/apps/messageicons/icons/bank.png
new file mode 100644
index 000000000..fa1500a41
Binary files /dev/null and b/apps/messageicons/icons/bank.png differ
diff --git a/apps/messageicons/icons/beeper.png b/apps/messageicons/icons/beeper.png
new file mode 100644
index 000000000..bea9138ec
Binary files /dev/null and b/apps/messageicons/icons/beeper.png differ
diff --git a/apps/messageicons/icons/bibel.png b/apps/messageicons/icons/bibel.png
new file mode 100644
index 000000000..053fcf178
Binary files /dev/null and b/apps/messageicons/icons/bibel.png differ
diff --git a/apps/messageicons/icons/bitcoin.png b/apps/messageicons/icons/bitcoin.png
new file mode 100644
index 000000000..85deecc36
Binary files /dev/null and b/apps/messageicons/icons/bitcoin.png differ
diff --git a/apps/messageicons/icons/bolt.png b/apps/messageicons/icons/bolt.png
new file mode 100644
index 000000000..215b9d052
Binary files /dev/null and b/apps/messageicons/icons/bolt.png differ
diff --git a/apps/messageicons/icons/bring.png b/apps/messageicons/icons/bring.png
new file mode 100644
index 000000000..673d1b7be
Binary files /dev/null and b/apps/messageicons/icons/bring.png differ
diff --git a/apps/messageicons/icons/cafe.png b/apps/messageicons/icons/cafe.png
new file mode 100644
index 000000000..26a3bb114
Binary files /dev/null and b/apps/messageicons/icons/cafe.png differ
diff --git a/apps/messageicons/icons/calendar.png b/apps/messageicons/icons/calendar.png
new file mode 100644
index 000000000..286952af5
Binary files /dev/null and b/apps/messageicons/icons/calendar.png differ
diff --git a/apps/messageicons/icons/cart.png b/apps/messageicons/icons/cart.png
new file mode 100644
index 000000000..dec53ef00
Binary files /dev/null and b/apps/messageicons/icons/cart.png differ
diff --git a/apps/messageicons/icons/cashapp.png b/apps/messageicons/icons/cashapp.png
new file mode 100644
index 000000000..23e897c82
Binary files /dev/null and b/apps/messageicons/icons/cashapp.png differ
diff --git a/apps/messageicons/icons/cbc.png b/apps/messageicons/icons/cbc.png
new file mode 100644
index 000000000..96e3ddd1b
Binary files /dev/null and b/apps/messageicons/icons/cbc.png differ
diff --git a/apps/messageicons/icons/chrome.png b/apps/messageicons/icons/chrome.png
new file mode 100644
index 000000000..b477c57ff
Binary files /dev/null and b/apps/messageicons/icons/chrome.png differ
diff --git a/apps/messageicons/icons/coronavirus.png b/apps/messageicons/icons/coronavirus.png
new file mode 100644
index 000000000..98b967954
Binary files /dev/null and b/apps/messageicons/icons/coronavirus.png differ
diff --git a/apps/messageicons/icons/crave.png b/apps/messageicons/icons/crave.png
new file mode 100644
index 000000000..ee6f0778a
Binary files /dev/null and b/apps/messageicons/icons/crave.png differ
diff --git a/apps/messageicons/icons/default.png b/apps/messageicons/icons/default.png
new file mode 100644
index 000000000..1f85079df
Binary files /dev/null and b/apps/messageicons/icons/default.png differ
diff --git a/apps/messageicons/icons/delivery.png b/apps/messageicons/icons/delivery.png
new file mode 100644
index 000000000..78ca0e190
Binary files /dev/null and b/apps/messageicons/icons/delivery.png differ
diff --git a/apps/messageicons/icons/desjardins.png b/apps/messageicons/icons/desjardins.png
new file mode 100644
index 000000000..c54899aab
Binary files /dev/null and b/apps/messageicons/icons/desjardins.png differ
diff --git a/apps/messageicons/icons/discord.png b/apps/messageicons/icons/discord.png
new file mode 100644
index 000000000..a8c4e2d39
Binary files /dev/null and b/apps/messageicons/icons/discord.png differ
diff --git a/apps/messageicons/icons/dollars.png b/apps/messageicons/icons/dollars.png
new file mode 100644
index 000000000..e5c1d2e68
Binary files /dev/null and b/apps/messageicons/icons/dollars.png differ
diff --git a/apps/messageicons/icons/dropbox.png b/apps/messageicons/icons/dropbox.png
new file mode 100644
index 000000000..ad6dd84a8
Binary files /dev/null and b/apps/messageicons/icons/dropbox.png differ
diff --git a/apps/messageicons/icons/etar.png b/apps/messageicons/icons/etar.png
new file mode 100644
index 000000000..24f0cc587
Binary files /dev/null and b/apps/messageicons/icons/etar.png differ
diff --git a/apps/messageicons/icons/facebook messenger.png b/apps/messageicons/icons/facebook messenger.png
new file mode 100644
index 000000000..286b5bc29
Binary files /dev/null and b/apps/messageicons/icons/facebook messenger.png differ
diff --git a/apps/messageicons/icons/facebook.png b/apps/messageicons/icons/facebook.png
new file mode 100644
index 000000000..5ba18eca3
Binary files /dev/null and b/apps/messageicons/icons/facebook.png differ
diff --git a/apps/messageicons/icons/fdroid.png b/apps/messageicons/icons/fdroid.png
new file mode 100644
index 000000000..4b5c6761e
Binary files /dev/null and b/apps/messageicons/icons/fdroid.png differ
diff --git a/apps/messageicons/icons/firefox.png b/apps/messageicons/icons/firefox.png
new file mode 100644
index 000000000..2dcae9270
Binary files /dev/null and b/apps/messageicons/icons/firefox.png differ
diff --git a/apps/messageicons/icons/generate.js b/apps/messageicons/icons/generate.js
new file mode 100755
index 000000000..e857032af
--- /dev/null
+++ b/apps/messageicons/icons/generate.js
@@ -0,0 +1,143 @@
+#!/usr/bin/node
+
+// Creates lib.js from icons
+// npm install png-js
+
+// default icon must come first in icon_names
+
+var imageconverter = require("../../../webtools/imageconverter.js");
+var icons = JSON.parse(require("fs").readFileSync(__dirname+"/icon_names.json"));
+const imgOptions = {
+  mode : "1bit",
+  inverted : true,
+  transparent : true,
+  output: "raw"
+};
+var PNG = require('png-js');
+var IMAGE_BYTES = 76;
+
+var iconTests = [];
+var iconImages = []; // array of converted icons
+var iconIndices = {}; // maps filename -> index in iconImages
+
+var promises = [];
+
+icons.forEach(icon => {
+  var index = iconIndices[icon.icon];
+  if (index===undefined) { // need a new icon
+    index = iconImages.length;
+    iconIndices[icon.icon] = index;
+    iconImages.push(""); // placeholder
+    // create image
+    console.log("Loading "+icon.icon);
+    var png = new PNG(require("fs").readFileSync(__dirname+"/"+icon.icon));
+    if (png.width!=24 || png.height!=24) {
+      console.warn(icon.icon+" should be 24x24px");
+    }
+
+    promises.push(new Promise(r => {
+      png.decode(function (pixels) {
+        var rgba = new Uint8Array(pixels);
+        var isTransparent = false;
+        for (var i=0;i {
+    // Yay, more JS. Why is it so hard to get the bytes???
+    iconData.set(Array.prototype.slice.call(Buffer.from(img,"binary")), idx*IMAGE_BYTES)
+  });
+
+  console.log("Saving images");
+  require("fs").writeFileSync(__dirname+"/../icons.img", Buffer.from(iconData,"binary"));
+
+  console.log("Saving library");
+  require("fs").writeFileSync(__dirname+"/../lib.js", `exports.getImage = function(msg) {
+  if (msg.img) return atob(msg.img);
+  let s = (("string"=== typeof msg) ? msg : (msg.src || "")).toLowerCase();
+  if (msg.id=="music") s="music";
+  let match = ${JSON.stringify(","+icons.map(icon=>icon.app+"|"+icon.index).join(",")+",")}.match(new RegExp(\`,\${s}\\\\|(\\\\d+)\`))
+  return require("Storage").read("messageicons.img", (match===null)?0:match[1]*${IMAGE_BYTES}, ${IMAGE_BYTES});
+};
+
+exports.getColor = function(msg,options) {
+  options = options||{};
+  var st = options.settings || require('Storage').readJSON("messages.settings.json", 1) || {};
+  if (options.default===undefined) options.default=g.theme.fg;
+  if (st.iconColorMode == 'mono') return options.default;
+  const s = (("string"=== typeof msg) ? msg : (msg.src || "")).toLowerCase();
+  return {
+    // generic colors, using B2-safe colors
+    // DO NOT USE BLACK OR WHITE HERE, just leave the declaration out and then the theme's fg color will be used
+    "airbnb": "#ff385c", // https://news.airbnb.com/media-assets/category/brand/
+    "mail": "#ff0",
+    "music": "#f0f",
+    "phone": "#0f0",
+    "sms message": "#0ff",
+    // brands, according to https://www.schemecolor.com/?s (picking one for multicolored logos)
+    // all dithered on B2, but we only use the color for the icons.  (Could maybe pick the closest 3-bit color for B2?)
+    "bibel": "#54342c",
+    "bring": "#455a64",
+    "discord": "#5865f2", // https://discord.com/branding
+    "etar": "#36a18b",
+    "facebook": "#1877f2", // https://www.facebook.com/brand/resources/facebookapp/logo
+    "gmail": "#ea4335",
+    "gmx": "#1c449b",
+    "google": "#4285F4",
+    "google home": "#fbbc05",
+// "home assistant": "#41bdf5", // ha-blue is #41bdf5, but that's the background
+    "instagram": "#ff0069", // https://about.instagram.com/brand/gradient
+    "lieferando": "#ff8000",
+    "linkedin": "#0a66c2", // https://brand.linkedin.com/
+    "messenger": "#0078ff",
+    "mastodon": "#563acc", // https://www.joinmastodon.org/branding
+    "mattermost": "#00f",
+    "n26": "#36a18b",
+    "nextbike": "#00f",
+    "newpipe": "#f00",
+    "nina": "#e57004",
+    "opentasks": "#409f8f",
+    "outlook mail": "#0078d4", // https://developer.microsoft.com/en-us/fluentui#/styles/web/colors/products
+    "paypal": "#003087",
+    "pocket": "#ef4154f", // https://blog.getpocket.com/press/
+    "post & dhl": "#f2c101",
+    "reddit": "#ff4500", // https://www.redditinc.com/brand
+    "signal": "#3a76f0", // https://github.com/signalapp/Signal-Desktop/blob/main/images/signal-logo.svg
+    "skype": "#0078d4", // https://developer.microsoft.com/en-us/fluentui#/styles/web/colors/products
+    "slack": "#e51670",
+    "snapchat": "#ff0",
+    "steam": "#171a21",
+    "teams": "#6264a7", // https://developer.microsoft.com/en-us/fluentui#/styles/web/colors/products
+    "telegram": "#0088cc",
+    "telegram foss": "#0088cc",
+    "to do": "#3999e5",
+    "twitch": "#9146ff", // https://brand.twitch.tv/
+    "twitter": "#1d9bf0", // https://about.twitter.com/en/who-we-are/brand-toolkit
+    "vlc": "#ff8800",
+    "whatsapp": "#4fce5d",
+    "wordfeud": "#e7d3c7",
+    "youtube": "#f00", // https://www.youtube.com/howyoutubeworks/resources/brand-resources/#logos-icons-and-colors
+  }[s]||options.default;
+};
+  `);
+});
diff --git a/apps/messageicons/icons/github.png b/apps/messageicons/icons/github.png
new file mode 100644
index 000000000..813cbb2c9
Binary files /dev/null and b/apps/messageicons/icons/github.png differ
diff --git a/apps/messageicons/icons/gitlab.png b/apps/messageicons/icons/gitlab.png
new file mode 100644
index 000000000..3e7280f59
Binary files /dev/null and b/apps/messageicons/icons/gitlab.png differ
diff --git a/apps/messageicons/icons/gmx.png b/apps/messageicons/icons/gmx.png
new file mode 100644
index 000000000..185c90aa3
Binary files /dev/null and b/apps/messageicons/icons/gmx.png differ
diff --git a/apps/messageicons/icons/google chat.png b/apps/messageicons/icons/google chat.png
new file mode 100644
index 000000000..6d8eb7741
Binary files /dev/null and b/apps/messageicons/icons/google chat.png differ
diff --git a/apps/messageicons/icons/google drive.png b/apps/messageicons/icons/google drive.png
new file mode 100644
index 000000000..97da419a8
Binary files /dev/null and b/apps/messageicons/icons/google drive.png differ
diff --git a/apps/messageicons/icons/google home.png b/apps/messageicons/icons/google home.png
new file mode 100644
index 000000000..f6ebaa77f
Binary files /dev/null and b/apps/messageicons/icons/google home.png differ
diff --git a/apps/messageicons/icons/google keep.png b/apps/messageicons/icons/google keep.png
new file mode 100644
index 000000000..f7d1f97c6
Binary files /dev/null and b/apps/messageicons/icons/google keep.png differ
diff --git a/apps/messageicons/icons/google opinion rewards.png b/apps/messageicons/icons/google opinion rewards.png
new file mode 100644
index 000000000..479ec0c5f
Binary files /dev/null and b/apps/messageicons/icons/google opinion rewards.png differ
diff --git a/apps/messageicons/icons/google photos.png b/apps/messageicons/icons/google photos.png
new file mode 100644
index 000000000..aecf00dbe
Binary files /dev/null and b/apps/messageicons/icons/google photos.png differ
diff --git a/apps/messageicons/icons/google play store.png b/apps/messageicons/icons/google play store.png
new file mode 100644
index 000000000..166094907
Binary files /dev/null and b/apps/messageicons/icons/google play store.png differ
diff --git a/apps/messageicons/icons/google.png b/apps/messageicons/icons/google.png
new file mode 100644
index 000000000..62797fefb
Binary files /dev/null and b/apps/messageicons/icons/google.png differ
diff --git a/apps/messageicons/icons/home assistant.png b/apps/messageicons/icons/home assistant.png
new file mode 100644
index 000000000..d08932ae8
Binary files /dev/null and b/apps/messageicons/icons/home assistant.png differ
diff --git a/apps/messageicons/icons/icon_names.json b/apps/messageicons/icons/icon_names.json
new file mode 100644
index 000000000..0085731cc
--- /dev/null
+++ b/apps/messageicons/icons/icon_names.json
@@ -0,0 +1,111 @@
+[
+  { "app":"default", "icon":"default.png" },
+  { "app":"airbnb", "icon":"airbnb.png" },
+  { "app":"alarm", "icon":"alarm.png" },
+	{ "app":"alarmclockreceiver", "icon":"alarm.png" },
+  { "app":"amazon shopping", "icon":"amazon.png" },
+  { "app":"bibel", "icon":"bibel.png" },
+  { "app":"bitwarden", "icon":"security.png" },
+	{ "app":"1password", "icon":"security.png" },
+	{ "app":"lastpass", "icon":"security.png" },
+	{ "app":"dashlane", "icon":"security.png" },
+  { "app":"bring", "icon":"bring.png" },
+  { "app":"calendar", "icon":"etar.png" },
+	{ "app":"etar", "icon":"etar.png" },
+  { "app":"chat", "icon":"google chat.png" },
+  { "app":"chrome", "icon":"chrome.png" },
+  { "app":"corona-warn", "icon":"coronavirus.png" },
+  { "app":"bmo", "icon":"bank.png" },
+	{ "app":"desjardins", "icon":"bank.png" },
+	{ "app":"rbc mobile", "icon":"bank.png" },
+	{ "app":"nbc", "icon":"bank.png" },
+	{ "app":"rabobank", "icon":"bank.png" },
+	{ "app":"scotiabank", "icon":"bank.png" },
+	{ "app":"td (canada)", "icon":"bank.png" },
+  { "app":"discord", "icon":"discord.png" },
+  { "app":"drive", "icon":"google drive.png" },
+  { "app":"element", "icon":"matrix element.png" },
+  { "app":"facebook", "icon":"facebook.png" },
+  { "app":"messenger", "icon":"facebook messenger.png" },
+  { "app":"firefox", "icon":"firefox.png" },
+	{ "app":"firefox beta", "icon":"firefox.png" },
+	{ "app":"firefox nightly", "icon":"firefox.png" },
+  { "app":"f-droid", "icon":"security.png" },
+	{ "app":"neo store", "icon":"security.png" },
+	{ "app":"aurora droid", "icon":"security.png" },
+  { "app":"github", "icon":"github.png" },
+  { "app":"gitlab", "icon":"gitlab.png" },
+  { "app":"gmx", "icon":"gmx.png" },
+  { "app":"google", "icon":"google.png" },
+  { "app":"google home", "icon":"google home.png" },
+  { "app":"google play store", "icon":"google play store.png" },
+  { "app":"home assistant", "icon":"home assistant.png" },
+  { "app":"instagram", "icon":"instagram.png" },
+  { "app":"kalender", "icon":"kalender.png" },
+  { "app":"keep notes", "icon":"google keep.png" },
+  { "app":"lieferando", "icon":"lieferando.png" },
+  { "app":"linkedin", "icon":"linkedin.png" },
+  { "app":"maps", "icon":"map.png" },
+	{ "app":"organic maps", "icon":"map.png" },
+	{ "app":"osmand", "icon":"map.png" },
+  { "app":"mastodon", "icon":"mastodon.png" },
+	{ "app":"fedilab", "icon":"mastodon.png" },
+	{ "app":"tooot", "icon":"mastodon.png" },
+	{ "app":"tusky", "icon":"mastodon.png" },
+  { "app":"mattermost", "icon":"mattermost.png" },
+  { "app":"n26", "icon":"n26.png" },
+  { "app":"netflix", "icon":"netflix.png" },
+  { "app":"news", "icon":"news.png" },
+	{ "app":"cbc news", "icon":"news.png" },
+	{ "app":"rc info", "icon":"news.png" },
+	{ "app":"reuters", "icon":"news.png" },
+	{ "app":"ap news", "icon":"news.png" },
+	{ "app":"la presse", "icon":"news.png" },
+	{ "app":"nbc news", "icon":"news.png" },
+  { "app":"nextbike", "icon":"nextbike.png" },
+  { "app":"nina", "icon":"nina.png" },
+  { "app":"outlook mail", "icon":"outlook.png" },
+  { "app":"paypal", "icon":"paypal.png" },
+  { "app":"phone", "icon":"phone.png" },
+  { "app":"plex", "icon":"plex.png" },
+  { "app":"pocket", "icon":"pocket.png" },
+  { "app":"post & dhl", "icon":"delivery.png" },
+  { "app":"proton mail", "icon":"protonmail.png" },
+  { "app":"reddit", "icon":"reddit.png" },
+	{ "app":"sync pro", "icon":"reddit.png" },
+	{ "app":"sync dev", "icon":"reddit.png" },
+	{ "app":"boost", "icon":"reddit.png" },
+	{ "app":"infinity", "icon":"reddit.png" },
+	{ "app":"slide", "icon":"reddit.png" },
+  { "app":"signal", "icon":"signal.png" },
+  { "app":"skype", "icon":"skype.png" },
+  { "app":"slack", "icon":"slack.png" },
+  { "app":"snapchat", "icon":"snapchat.png" },
+  { "app":"starbucks", "icon":"cafe.png" },
+  { "app":"steam", "icon":"steam.png" },
+  { "app":"teams", "icon":"teams.png" },
+  { "app":"telegram", "icon":"telegram.png" },
+	{ "app":"telegram foss", "icon":"telegram.png" },
+  { "app":"threema", "icon":"threema.png" },
+  { "app":"tiktok", "icon":"tiktok.png" },
+  { "app":"to do", "icon":"task.png" },
+	{ "app":"opentasks", "icon":"task.png" },
+	{ "app":"tasks", "icon":"task.png" },
+  { "app":"transit", "icon":"transit.png" },
+  { "app":"twitch", "icon":"twitch.png" },
+  { "app":"twitter", "icon":"twitter.png" },
+  { "app":"uber", "icon":"taxi.png" },
+	{ "app":"lyft", "icon":"taxi.png" },
+  { "app":"vlc", "icon":"vlc.png" },
+  { "app":"warnapp", "icon":"warnapp.png" },
+  { "app":"whatsapp", "icon":"whatsapp.png" },
+  { "app":"wordfeud", "icon":"wordfeud.png" },
+  { "app":"youtube", "icon":"youtube.png" },
+	{ "app":"newpipe", "icon":"youtube.png" },
+  { "app":"zoom", "icon":"videoconf.png" },
+	{ "app":"meet", "icon":"videoconf.png" },
+  { "app":"music", "icon":"music.png" },
+  { "app":"sms message", "icon":"default.png" },
+	{ "app":"mail", "icon":"default.png" },
+	{ "app":"gmail", "icon":"default.png" }
+]
diff --git a/apps/messageicons/icons/instagram.png b/apps/messageicons/icons/instagram.png
new file mode 100644
index 000000000..9bccd20af
Binary files /dev/null and b/apps/messageicons/icons/instagram.png differ
diff --git a/apps/messageicons/icons/kalender.png b/apps/messageicons/icons/kalender.png
new file mode 100644
index 000000000..dd807dd9e
Binary files /dev/null and b/apps/messageicons/icons/kalender.png differ
diff --git a/apps/messageicons/icons/kde connect.png b/apps/messageicons/icons/kde connect.png
new file mode 100644
index 000000000..f13298b1d
Binary files /dev/null and b/apps/messageicons/icons/kde connect.png differ
diff --git a/apps/messageicons/icons/lieferando.png b/apps/messageicons/icons/lieferando.png
new file mode 100644
index 000000000..7a31bc9e1
Binary files /dev/null and b/apps/messageicons/icons/lieferando.png differ
diff --git a/apps/messageicons/icons/linkedin.png b/apps/messageicons/icons/linkedin.png
new file mode 100644
index 000000000..016e29ca8
Binary files /dev/null and b/apps/messageicons/icons/linkedin.png differ
diff --git a/apps/messageicons/icons/mail.png b/apps/messageicons/icons/mail.png
new file mode 100644
index 000000000..8c29a4895
Binary files /dev/null and b/apps/messageicons/icons/mail.png differ
diff --git a/apps/messageicons/icons/map.png b/apps/messageicons/icons/map.png
new file mode 100644
index 000000000..215f3f971
Binary files /dev/null and b/apps/messageicons/icons/map.png differ
diff --git a/apps/messageicons/icons/mastodon.png b/apps/messageicons/icons/mastodon.png
new file mode 100644
index 000000000..82fe737a3
Binary files /dev/null and b/apps/messageicons/icons/mastodon.png differ
diff --git a/apps/messageicons/icons/matrix element.png b/apps/messageicons/icons/matrix element.png
new file mode 100644
index 000000000..9ae89dc37
Binary files /dev/null and b/apps/messageicons/icons/matrix element.png differ
diff --git a/apps/messageicons/icons/mattermost.png b/apps/messageicons/icons/mattermost.png
new file mode 100644
index 000000000..2d5f168ca
Binary files /dev/null and b/apps/messageicons/icons/mattermost.png differ
diff --git a/apps/messageicons/icons/mcdonalds.png b/apps/messageicons/icons/mcdonalds.png
new file mode 100644
index 000000000..efe4088a4
Binary files /dev/null and b/apps/messageicons/icons/mcdonalds.png differ
diff --git a/apps/messageicons/icons/message.png b/apps/messageicons/icons/message.png
new file mode 100644
index 000000000..a93cb3f4c
Binary files /dev/null and b/apps/messageicons/icons/message.png differ
diff --git a/apps/messageicons/icons/music.png b/apps/messageicons/icons/music.png
new file mode 100644
index 000000000..62f7acfee
Binary files /dev/null and b/apps/messageicons/icons/music.png differ
diff --git a/apps/messageicons/icons/n26.png b/apps/messageicons/icons/n26.png
new file mode 100644
index 000000000..aa441ab8b
Binary files /dev/null and b/apps/messageicons/icons/n26.png differ
diff --git a/apps/messageicons/icons/netflix.png b/apps/messageicons/icons/netflix.png
new file mode 100644
index 000000000..d956a103b
Binary files /dev/null and b/apps/messageicons/icons/netflix.png differ
diff --git a/apps/messageicons/icons/news.png b/apps/messageicons/icons/news.png
new file mode 100644
index 000000000..8e75513e9
Binary files /dev/null and b/apps/messageicons/icons/news.png differ
diff --git a/apps/messageicons/icons/nextbike.png b/apps/messageicons/icons/nextbike.png
new file mode 100644
index 000000000..467bed8ac
Binary files /dev/null and b/apps/messageicons/icons/nextbike.png differ
diff --git a/apps/messageicons/icons/nina.png b/apps/messageicons/icons/nina.png
new file mode 100644
index 000000000..2669b6401
Binary files /dev/null and b/apps/messageicons/icons/nina.png differ
diff --git a/apps/messageicons/icons/notification.png b/apps/messageicons/icons/notification.png
new file mode 100644
index 000000000..c29a6025c
Binary files /dev/null and b/apps/messageicons/icons/notification.png differ
diff --git a/apps/messageicons/icons/onedrive.png b/apps/messageicons/icons/onedrive.png
new file mode 100644
index 000000000..ff2b08304
Binary files /dev/null and b/apps/messageicons/icons/onedrive.png differ
diff --git a/apps/messageicons/icons/outlook.png b/apps/messageicons/icons/outlook.png
new file mode 100644
index 000000000..5519ccd4c
Binary files /dev/null and b/apps/messageicons/icons/outlook.png differ
diff --git a/apps/messageicons/icons/paypal.png b/apps/messageicons/icons/paypal.png
new file mode 100644
index 000000000..cd76aae90
Binary files /dev/null and b/apps/messageicons/icons/paypal.png differ
diff --git a/apps/messageicons/icons/phone.png b/apps/messageicons/icons/phone.png
new file mode 100644
index 000000000..376170f7c
Binary files /dev/null and b/apps/messageicons/icons/phone.png differ
diff --git a/apps/messageicons/icons/playstation.png b/apps/messageicons/icons/playstation.png
new file mode 100644
index 000000000..a97a38964
Binary files /dev/null and b/apps/messageicons/icons/playstation.png differ
diff --git a/apps/messageicons/icons/plex.png b/apps/messageicons/icons/plex.png
new file mode 100644
index 000000000..a0840b751
Binary files /dev/null and b/apps/messageicons/icons/plex.png differ
diff --git a/apps/messageicons/icons/pocket.png b/apps/messageicons/icons/pocket.png
new file mode 100644
index 000000000..d34f2e399
Binary files /dev/null and b/apps/messageicons/icons/pocket.png differ
diff --git a/apps/messageicons/icons/podcast.png b/apps/messageicons/icons/podcast.png
new file mode 100644
index 000000000..1be0f22b6
Binary files /dev/null and b/apps/messageicons/icons/podcast.png differ
diff --git a/apps/messageicons/icons/pokeball.png b/apps/messageicons/icons/pokeball.png
new file mode 100644
index 000000000..d023761eb
Binary files /dev/null and b/apps/messageicons/icons/pokeball.png differ
diff --git a/apps/messageicons/icons/protonmail.png b/apps/messageicons/icons/protonmail.png
new file mode 100644
index 000000000..065607c47
Binary files /dev/null and b/apps/messageicons/icons/protonmail.png differ
diff --git a/apps/messageicons/icons/protonvpn.png b/apps/messageicons/icons/protonvpn.png
new file mode 100644
index 000000000..6d837a3e2
Binary files /dev/null and b/apps/messageicons/icons/protonvpn.png differ
diff --git a/apps/messageicons/icons/radio.png b/apps/messageicons/icons/radio.png
new file mode 100644
index 000000000..ea1cbffe1
Binary files /dev/null and b/apps/messageicons/icons/radio.png differ
diff --git a/apps/messageicons/icons/reddit.png b/apps/messageicons/icons/reddit.png
new file mode 100644
index 000000000..96fcce901
Binary files /dev/null and b/apps/messageicons/icons/reddit.png differ
diff --git a/apps/messageicons/icons/restaurant.png b/apps/messageicons/icons/restaurant.png
new file mode 100644
index 000000000..9bf1fcea9
Binary files /dev/null and b/apps/messageicons/icons/restaurant.png differ
diff --git a/apps/messageicons/icons/router.png b/apps/messageicons/icons/router.png
new file mode 100644
index 000000000..4446342f6
Binary files /dev/null and b/apps/messageicons/icons/router.png differ
diff --git a/apps/messageicons/icons/rss.png b/apps/messageicons/icons/rss.png
new file mode 100644
index 000000000..b248b70e9
Binary files /dev/null and b/apps/messageicons/icons/rss.png differ
diff --git a/apps/messageicons/icons/rust.png b/apps/messageicons/icons/rust.png
new file mode 100644
index 000000000..b74eb6ec4
Binary files /dev/null and b/apps/messageicons/icons/rust.png differ
diff --git a/apps/messageicons/icons/security.png b/apps/messageicons/icons/security.png
new file mode 100644
index 000000000..b8cc5c77e
Binary files /dev/null and b/apps/messageicons/icons/security.png differ
diff --git a/apps/messageicons/icons/shopping.png b/apps/messageicons/icons/shopping.png
new file mode 100644
index 000000000..f966188b8
Binary files /dev/null and b/apps/messageicons/icons/shopping.png differ
diff --git a/apps/messageicons/icons/signal.png b/apps/messageicons/icons/signal.png
new file mode 100644
index 000000000..e8508706f
Binary files /dev/null and b/apps/messageicons/icons/signal.png differ
diff --git a/apps/messageicons/icons/skype.png b/apps/messageicons/icons/skype.png
new file mode 100644
index 000000000..867a8feb6
Binary files /dev/null and b/apps/messageicons/icons/skype.png differ
diff --git a/apps/messageicons/icons/slack.png b/apps/messageicons/icons/slack.png
new file mode 100644
index 000000000..7a5a5a71c
Binary files /dev/null and b/apps/messageicons/icons/slack.png differ
diff --git a/apps/messageicons/icons/snapchat.png b/apps/messageicons/icons/snapchat.png
new file mode 100644
index 000000000..42daddbaf
Binary files /dev/null and b/apps/messageicons/icons/snapchat.png differ
diff --git a/apps/messageicons/icons/steam.png b/apps/messageicons/icons/steam.png
new file mode 100644
index 000000000..f6212cdfb
Binary files /dev/null and b/apps/messageicons/icons/steam.png differ
diff --git a/apps/messageicons/icons/syncthing.png b/apps/messageicons/icons/syncthing.png
new file mode 100644
index 000000000..174384aba
Binary files /dev/null and b/apps/messageicons/icons/syncthing.png differ
diff --git a/apps/messageicons/icons/task.png b/apps/messageicons/icons/task.png
new file mode 100644
index 000000000..c43d355c4
Binary files /dev/null and b/apps/messageicons/icons/task.png differ
diff --git a/apps/messageicons/icons/taxi.png b/apps/messageicons/icons/taxi.png
new file mode 100644
index 000000000..b577eef0e
Binary files /dev/null and b/apps/messageicons/icons/taxi.png differ
diff --git a/apps/messageicons/icons/teams.png b/apps/messageicons/icons/teams.png
new file mode 100644
index 000000000..5160b007e
Binary files /dev/null and b/apps/messageicons/icons/teams.png differ
diff --git a/apps/messageicons/icons/telegram.png b/apps/messageicons/icons/telegram.png
new file mode 100644
index 000000000..fe8051006
Binary files /dev/null and b/apps/messageicons/icons/telegram.png differ
diff --git a/apps/messageicons/icons/terminal.png b/apps/messageicons/icons/terminal.png
new file mode 100644
index 000000000..10a35e71f
Binary files /dev/null and b/apps/messageicons/icons/terminal.png differ
diff --git a/apps/messageicons/icons/thermostat.png b/apps/messageicons/icons/thermostat.png
new file mode 100644
index 000000000..8e96f6241
Binary files /dev/null and b/apps/messageicons/icons/thermostat.png differ
diff --git a/apps/messageicons/icons/threema.png b/apps/messageicons/icons/threema.png
new file mode 100644
index 000000000..401660b5c
Binary files /dev/null and b/apps/messageicons/icons/threema.png differ
diff --git a/apps/messageicons/icons/tiktok.png b/apps/messageicons/icons/tiktok.png
new file mode 100644
index 000000000..99afd3dd9
Binary files /dev/null and b/apps/messageicons/icons/tiktok.png differ
diff --git a/apps/messageicons/icons/transit.png b/apps/messageicons/icons/transit.png
new file mode 100644
index 000000000..3ec108194
Binary files /dev/null and b/apps/messageicons/icons/transit.png differ
diff --git a/apps/messageicons/icons/twitch.png b/apps/messageicons/icons/twitch.png
new file mode 100644
index 000000000..cd7d479c1
Binary files /dev/null and b/apps/messageicons/icons/twitch.png differ
diff --git a/apps/messageicons/icons/twitter.png b/apps/messageicons/icons/twitter.png
new file mode 100644
index 000000000..88df293f8
Binary files /dev/null and b/apps/messageicons/icons/twitter.png differ
diff --git a/apps/messageicons/icons/videoconf.png b/apps/messageicons/icons/videoconf.png
new file mode 100644
index 000000000..9b420341a
Binary files /dev/null and b/apps/messageicons/icons/videoconf.png differ
diff --git a/apps/messageicons/icons/vlc.png b/apps/messageicons/icons/vlc.png
new file mode 100644
index 000000000..74949aded
Binary files /dev/null and b/apps/messageicons/icons/vlc.png differ
diff --git a/apps/messageicons/icons/voicemail.png b/apps/messageicons/icons/voicemail.png
new file mode 100644
index 000000000..2c1972a56
Binary files /dev/null and b/apps/messageicons/icons/voicemail.png differ
diff --git a/apps/messageicons/icons/wallet.png b/apps/messageicons/icons/wallet.png
new file mode 100644
index 000000000..536cae2ba
Binary files /dev/null and b/apps/messageicons/icons/wallet.png differ
diff --git a/apps/messageicons/icons/warnapp.png b/apps/messageicons/icons/warnapp.png
new file mode 100644
index 000000000..988485053
Binary files /dev/null and b/apps/messageicons/icons/warnapp.png differ
diff --git a/apps/messageicons/icons/warning.png b/apps/messageicons/icons/warning.png
new file mode 100644
index 000000000..59080713f
Binary files /dev/null and b/apps/messageicons/icons/warning.png differ
diff --git a/apps/messageicons/icons/webhook.png b/apps/messageicons/icons/webhook.png
new file mode 100644
index 000000000..7562fd759
Binary files /dev/null and b/apps/messageicons/icons/webhook.png differ
diff --git a/apps/messageicons/icons/wechat.png b/apps/messageicons/icons/wechat.png
new file mode 100644
index 000000000..55f4bd6a9
Binary files /dev/null and b/apps/messageicons/icons/wechat.png differ
diff --git a/apps/messageicons/icons/whatsapp.png b/apps/messageicons/icons/whatsapp.png
new file mode 100644
index 000000000..d6d89bc0c
Binary files /dev/null and b/apps/messageicons/icons/whatsapp.png differ
diff --git a/apps/messageicons/icons/wordfeud.png b/apps/messageicons/icons/wordfeud.png
new file mode 100644
index 000000000..83963d4d4
Binary files /dev/null and b/apps/messageicons/icons/wordfeud.png differ
diff --git a/apps/messageicons/icons/xbox.png b/apps/messageicons/icons/xbox.png
new file mode 100644
index 000000000..dce76128d
Binary files /dev/null and b/apps/messageicons/icons/xbox.png differ
diff --git a/apps/messageicons/icons/youtube.png b/apps/messageicons/icons/youtube.png
new file mode 100644
index 000000000..93e50ccad
Binary files /dev/null and b/apps/messageicons/icons/youtube.png differ
diff --git a/apps/messageicons/lib.js b/apps/messageicons/lib.js
new file mode 100644
index 000000000..c5be21bb0
--- /dev/null
+++ b/apps/messageicons/lib.js
@@ -0,0 +1,68 @@
+exports.getImage = function(msg) {
+  if (msg.img) return atob(msg.img);
+  let s = (("string"=== typeof msg) ? msg : (msg.src || "")).toLowerCase();
+  if (msg.id=="music") s="music";
+  let match = ",default|0,airbnb|1,alarm|2,alarmclockreceiver|2,amazon shopping|3,bibel|4,bitwarden|5,1password|5,lastpass|5,dashlane|5,bring|6,calendar|7,etar|7,chat|8,chrome|9,corona-warn|10,bmo|11,desjardins|11,rbc mobile|11,nbc|11,rabobank|11,scotiabank|11,td (canada)|11,discord|12,drive|13,element|14,facebook|15,messenger|16,firefox|17,firefox beta|17,firefox nightly|17,f-droid|5,neo store|5,aurora droid|5,github|18,gitlab|19,gmx|20,google|21,google home|22,google play store|23,home assistant|24,instagram|25,kalender|26,keep notes|27,lieferando|28,linkedin|29,maps|30,organic maps|30,osmand|30,mastodon|31,fedilab|31,tooot|31,tusky|31,mattermost|32,n26|33,netflix|34,news|35,cbc news|35,rc info|35,reuters|35,ap news|35,la presse|35,nbc news|35,nextbike|36,nina|37,outlook mail|38,paypal|39,phone|40,plex|41,pocket|42,post & dhl|43,proton mail|44,reddit|45,sync pro|45,sync dev|45,boost|45,infinity|45,slide|45,signal|46,skype|47,slack|48,snapchat|49,starbucks|50,steam|51,teams|52,telegram|53,telegram foss|53,threema|54,tiktok|55,to do|56,opentasks|56,tasks|56,transit|57,twitch|58,twitter|59,uber|60,lyft|60,vlc|61,warnapp|62,whatsapp|63,wordfeud|64,youtube|65,newpipe|65,zoom|66,meet|66,music|67,sms message|0,mail|0,gmail|0,".match(new RegExp(`,${s}\\|(\\d+)`))
+  return require("Storage").read("messageicons.img", (match===null)?0:match[1]*76, 76);
+};
+
+exports.getColor = function(msg,options) {
+  options = options||{};
+  var st = options.settings || require('Storage').readJSON("messages.settings.json", 1) || {};
+  if (options.default===undefined) options.default=g.theme.fg;
+  if (st.iconColorMode == 'mono') return options.default;
+  const s = (("string"=== typeof msg) ? msg : (msg.src || "")).toLowerCase();
+  return {
+    // generic colors, using B2-safe colors
+    // DO NOT USE BLACK OR WHITE HERE, just leave the declaration out and then the theme's fg color will be used
+    "airbnb": "#ff385c", // https://news.airbnb.com/media-assets/category/brand/
+    "mail": "#ff0",
+    "music": "#f0f",
+    "phone": "#0f0",
+    "sms message": "#0ff",
+    // brands, according to https://www.schemecolor.com/?s (picking one for multicolored logos)
+    // all dithered on B2, but we only use the color for the icons.  (Could maybe pick the closest 3-bit color for B2?)
+    "bibel": "#54342c",
+    "bring": "#455a64",
+    "discord": "#5865f2", // https://discord.com/branding
+    "etar": "#36a18b",
+    "facebook": "#1877f2", // https://www.facebook.com/brand/resources/facebookapp/logo
+    "gmail": "#ea4335",
+    "gmx": "#1c449b",
+    "google": "#4285F4",
+    "google home": "#fbbc05",
+// "home assistant": "#41bdf5", // ha-blue is #41bdf5, but that's the background
+    "instagram": "#ff0069", // https://about.instagram.com/brand/gradient
+    "lieferando": "#ff8000",
+    "linkedin": "#0a66c2", // https://brand.linkedin.com/
+    "messenger": "#0078ff",
+    "mastodon": "#563acc", // https://www.joinmastodon.org/branding
+    "mattermost": "#00f",
+    "n26": "#36a18b",
+    "nextbike": "#00f",
+    "newpipe": "#f00",
+    "nina": "#e57004",
+    "opentasks": "#409f8f",
+    "outlook mail": "#0078d4", // https://developer.microsoft.com/en-us/fluentui#/styles/web/colors/products
+    "paypal": "#003087",
+    "pocket": "#ef4154f", // https://blog.getpocket.com/press/
+    "post & dhl": "#f2c101",
+    "reddit": "#ff4500", // https://www.redditinc.com/brand
+    "signal": "#3a76f0", // https://github.com/signalapp/Signal-Desktop/blob/main/images/signal-logo.svg
+    "skype": "#0078d4", // https://developer.microsoft.com/en-us/fluentui#/styles/web/colors/products
+    "slack": "#e51670",
+    "snapchat": "#ff0",
+    "steam": "#171a21",
+    "teams": "#6264a7", // https://developer.microsoft.com/en-us/fluentui#/styles/web/colors/products
+    "telegram": "#0088cc",
+    "telegram foss": "#0088cc",
+    "to do": "#3999e5",
+    "twitch": "#9146ff", // https://brand.twitch.tv/
+    "twitter": "#1d9bf0", // https://about.twitter.com/en/who-we-are/brand-toolkit
+    "vlc": "#ff8800",
+    "whatsapp": "#4fce5d",
+    "wordfeud": "#e7d3c7",
+    "youtube": "#f00", // https://www.youtube.com/howyoutubeworks/resources/brand-resources/#logos-icons-and-colors
+  }[s]||options.default;
+};
+  
\ No newline at end of file
diff --git a/apps/messageicons/metadata.json b/apps/messageicons/metadata.json
new file mode 100644
index 000000000..079835a0b
--- /dev/null
+++ b/apps/messageicons/metadata.json
@@ -0,0 +1,16 @@
+{
+  "id": "messageicons",
+  "name": "Message Icons",
+  "version": "0.03",
+  "description": "Library containing a list of icons and colors for apps",
+  "icon": "app.png",
+  "type": "module",
+  "tags": "tool,system",
+  "supports": ["BANGLEJS","BANGLEJS2"],
+  "provides_modules" : ["messageicons"],
+  "default": true,
+  "storage": [
+    {"name":"messageicons","url":"lib.js"},
+    {"name":"messageicons.img","url":"icons.img"}
+  ]
+}
diff --git a/apps/messagelist/ChangeLog b/apps/messagelist/ChangeLog
new file mode 100644
index 000000000..759f68777
--- /dev/null
+++ b/apps/messagelist/ChangeLog
@@ -0,0 +1 @@
+0.01: New app!
\ No newline at end of file
diff --git a/apps/messagelist/README.md b/apps/messagelist/README.md
new file mode 100644
index 000000000..776d0d0e6
--- /dev/null
+++ b/apps/messagelist/README.md
@@ -0,0 +1,69 @@
+# Message List
+
+Display messages inline as a single list:   
+Displays one message at a time, if it doesn't fit on the screen you can scroll
+up/down.  When you reach the bottom, you can scroll on to the next message.
+
+## Installation
+**First** uninstall the default [Message UI](/?id=messagegui) app (`messagegui`,
+not the library!).   
+Then install this app.
+
+## Screenshots
+
+### Main menu:   
+![Screenshot](screenshot0.png)
+
+### Unread message:   
+![Screenshot](screenshot1.png)   
+The chevrons are hints for swipe actions:
+- Swipe right to go back
+- Swipe left for the message-actions menu
+- Swipe down to show the previous message: We are currently viewing message 2 of 2,
+  so message 1 is "above" this one.
+
+### Long (read) message:   
+![Screenshot](screenshot2.png)   
+The button is disabled until you scroll all the way to the bottom.
+
+### Music:   
+![Screenshot](screenshot3.png)   
+Minimal setup: album name and buttons disabled through settings.
+Swipe for next/previous song, tap to pause/resume.
+
+## Settings
+
+### Interface
+* `Font size` - The font size used when displaying messages/music.
+* `On Tap` - If messages are too large to fit on the screen, tapping the screen scrolls down.    
+  This is the action to take when tapping a message after reaching the bottom:
+  - `Message menu`: Open menu with message actions
+  - `Dismiss`: Dismiss message right away
+  - `Back`: Go back to clock/main menu
+  - `Nothing`: Do nothing
+* `Dismiss button` - Show inline button to dismiss message right away
+
+### Behaviour
+* `Vibrate` - The pattern of buzzes when a new message is received.
+* `Vibrate for calls` - The pattern of buzzes for incoming calls.
+* `Vibrate for alarms` - The pattern of buzzes for (phone) alarms.
+* `Repeat` - How often buzzes repeat - the default of 4 means the Bangle will buzz every 4 seconds.
+* `Unread timer` - When a new message is received the Messages app is opened.
+  If there is no user input for this amount of time then the app will exit and return to the clock.
+* `Auto-open` - Automatically open app when a new message arrives.
+* `Respect quiet mode` - Prevent auto-opening during quiet mode.
+
+### Music
+* `Auto-open` - Automatically open app when music starts playing.
+* `Always visible` - Show "music" in the main menu even when nothing is playing.
+* `Buttons` - Show `previous`/`play/pause`/`next` buttons on music screen.
+* `Show album` - Display album names?
+
+
+### Util
+* `Delete all` - Erase all messages.
+
+
+## Attributions
+
+Some icons used in this app are from https://icons8.com
diff --git a/apps/messagelist/TODO.txt b/apps/messagelist/TODO.txt
new file mode 100644
index 000000000..3a6d7b664
--- /dev/null
+++ b/apps/messagelist/TODO.txt
@@ -0,0 +1,17 @@
+## Nice to have:
+* Add labels to B1 music HW buttons
+* Add volume buttons to B2 music screen (when controls are enabled)
+* Draw messages ourselves instead of piling hacks on Layout
+* Make sure all icons are 24x24px: icon sizes affect layout
+* Check/optimize layout for B1, other fonts (scrolling for just 5px is a shame)
+
+## Wishlist:
+* Option to swipe-dismiss (instead of action menu)
+* Maybe refactor showGrid() out into a general-use module?
+
+* Message replies (needs `android` support)
+* Customize replies
+* Custom replies (i.e. `textinput`)
+* Hooks to add custom replies/actions, 
+  e.g. external code could add "Send intent" option to Home Assistant messages
+  Maybe just use this for all replies, so we don't hardcode anything in "messages"?
diff --git a/apps/messagelist/app-icon.js b/apps/messagelist/app-icon.js
new file mode 100644
index 000000000..6ed3c1141
--- /dev/null
+++ b/apps/messagelist/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEw4UA///rkcAYP9ohL/ABMBqoAEoALDioLFqgLDBQoABERIkEBZcFBY9QBed61QAC1oLF7wLD24LF24LD7wLF1vqBQOrvQLFA4IuC9QLFD4IuC1QLGGAQOBBYwgBEwQLHvQBBEZHVq4jI7wWBHY5TLNZaDLTZazLffMBBY9ABZsABY4KCgEVBQtUBYYkGEQYA/AAwA="))
diff --git a/apps/messagelist/app.js b/apps/messagelist/app.js
new file mode 100644
index 000000000..ebd5d4217
--- /dev/null
+++ b/apps/messagelist/app.js
@@ -0,0 +1,1208 @@
+/* MESSAGES is a list of:
+  {id:int,
+    src,
+    title,
+    subject,
+    body,
+    sender,
+    tel:string,
+    new:true // not read yet
+  }
+*/
+
+/* For example for maps:
+
+// a message
+{"t":"add","id":1575479849,"src":"Hangouts","title":"A Name","body":"message contents"}
+// maps
+{"t":"add","id":1,"src":"Maps","title":"0 yd - High St","body":"Campton - 11:48 ETA","img":"GhqBAAAMAAAHgAAD8AAB/gAA/8AAf/gAP/8AH//gD/98B//Pg/4B8f8Afv+PP//n3/f5//j+f/wfn/4D5/8Aef+AD//AAf/gAD/wAAf4AAD8AAAeAAADAAA="}
+// call
+{"t":"add","id":"call","src":"Phone","name":"Bob","number":"12421312",positive:true,negative:true}
+*/
+{
+  const B2 = process.env.HWVERSION>1, // Bangle.js 2?
+    RIGHT = 1, LEFT = -1, // swipe directions
+    UP = -1, DOWN = 1;    // updown directions
+  const Layout = require("Layout");
+
+  const settings = () => require("messagegui").settings();
+  const fontTiny = "6x8"; // fixed size, don't use this for important things
+  let fontNormal;
+  // setFont() is also called after we close the settings screen
+  const setFont = function() {
+    const fontSize = settings().fontSize;
+    if (fontSize===0) // small
+      fontNormal = g.getFonts().includes("6x15") ? "6x15" : "6x8:2";
+    else if (fontSize===2) // large
+      fontNormal = g.getFonts().includes("6x15") ? "6x15:2" : "6x8:4";
+    else // medium
+      fontNormal = g.getFonts().includes("12x20") ? "12x20" : "6x8:3";
+  };
+  setFont();
+
+  let active, back; // active screen, last active screen
+
+  /// List of all our messages
+  let MESSAGES;
+  const saveMessages = function() {
+    const noSave = ["alarm", "call", "music"]; // assume these are outdated once we close the app
+    noSave.forEach(id => remove({id: id}));
+    require("messages").write(MESSAGES
+      .filter(m => m.id && !noSave.includes(m.id))
+      .map(m => {
+        delete m.show;
+        return m;
+      })
+    );
+  };
+  const uiRemove = function() {
+    if (musicTimeout) clearTimeout(musicTimeout);
+    layout = undefined;
+    Bangle.removeListener("message", onMessage);
+    saveMessages();
+    clearUnreadStuff();
+    delete Bangle.appRect;
+  };
+  const quitApp = () => load(); // TODO: revert to Bangle.showClock after fixing memory leaks
+  try {
+    MESSAGES = require("messages").getMessages();
+    // Apply fast loaded messages
+    (Bangle.MESSAGES || []).forEach(m => require("messages").apply(m, MESSAGES));
+    delete Bangle.MESSAGES;
+    // Write them back to storage when we're done
+    E.on("kill", saveMessages);
+  } catch(e) {
+    g.reset().clear();
+    E.showPrompt(/*LANG*/"Message file corrupt, erase all messages?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
+      // We are troubleshooting, so do a clean "load" in both cases (instead of Bangle.load)
+      if (isYes) {    // OK: erase message file and reload this app
+        require("messages").clearAll();
+        load("messagelist.app.js");
+      } else {
+        load(); // well, this app won't work... let's go back to the clock
+      }
+    });
+  }
+
+  const setUI = function(options, cb) {
+    options = Object.assign({remove: () => uiRemove()}, options);
+    Bangle.setUI(options, cb);
+    Bangle.on("message", onMessage);
+  };
+
+  const remove = function(msg) {
+    if (msg.id==="call") call = undefined;
+    else if (msg.id==="map") map = undefined;
+    else if (msg.id==="alarm") alarm = undefined;
+    else if (msg.id==="music") music = undefined;
+    else MESSAGES = MESSAGES.filter(m => m.id!==msg.id);
+  };
+  const buzz = function(msg) {
+    return require("messages").buzz(msg.src);
+  };
+  const show = function(msg) {
+    delete msg.show; // don't show this again
+    if (msg.id==="call") showCall(msg);
+    else if (msg.id==="map") showMap(msg);
+    else if (msg.id==="alarm") showAlarm(msg);
+    else if (msg.id==="music") showMusic(msg);
+    else showMessage(msg);
+  };
+
+  const onMessage = function(type, msg) {
+    if (msg.handled) return;
+    msg.handled = true;
+    switch(type) {
+      case "call":
+        return onCall(msg);
+      case "music":
+        return onMusic(msg);
+      case "map":
+        return onMap(msg);
+      case "alarm":
+        return onAlarm(msg);
+      case "text":
+        return onText(msg);
+      case "clearAll":
+        MESSAGES = [];
+        if (["messages", "menu"].includes(active)) showMenu();
+        break;
+      default:
+        E.showAlert(/*LANG*/"Unknown message type:"+"\n"+type).then(goBack);
+    }
+  };
+  Bangle.on("message", onMessage);
+
+  const onCall = function(msg) {
+    if (msg.t==="remove") {
+      call = undefined;
+      return exitScreen("call");
+    }
+    // incoming call: show it
+    call = msg;
+    buzz(call);
+    showCall();
+  };
+  const onAlarm = function(msg) {
+    if (msg.t==="remove") {
+      alarm = undefined;
+      return exitScreen("alarm");
+    }
+    alarm = msg;
+    buzz(alarm);
+    showAlarm();
+  };
+  let musicTimeout;
+  const onMusic = function(msg) {
+    const hadMusic = !!music;
+    if (musicTimeout) clearTimeout(musicTimeout);
+    musicTimeout = undefined;
+    if (msg.t==="remove") {
+      music = undefined;
+      if (active==="main" && hadMusic) return showMain(); // refresh menu: remove "Music" entry (if not always visible)
+      else return exitScreen("music");
+    }
+
+    music = Object.assign({}, music, msg);
+
+    // auto-close after being paused
+    if (music.state!=="play") musicTimeout = setTimeout(function() {
+      musicTimeout = undefined;
+      if (active==="music" && (!music || music.state!=="play")) quitApp();
+    }, 60*1000); // paused for 1 minute
+    // auto-close after "playing" way beyond song duration (because "stop" messages don't seem to exist)
+    else musicTimeout = setTimeout(function() {
+      musicTimeout = undefined;
+      if (active==="music" && (!music || music.state==="play")) quitApp();
+    }, 2*Math.max(music.dur || 0, 5*60)*1000); // playing: assume ended after twice song duration, or at least 10 minutes
+
+    if (active==="music") showMusic(); // update music screen
+    else if (active==="main" && !hadMusic) {
+      if (settings().openMusic && music.state==="play" && music.track) showMusic();
+      else showMain(); // refresh menu: add "Music" entry
+    }
+  };
+  const onMap = function(msg) {
+    const hadMap = !!map;
+    if (msg.t==="remove") {
+      map = undefined;
+      if (back==="map") back = undefined;
+      if (active==="main" && hadMap) return showMain(); // refresh menu: remove "Map" entry
+      else return exitScreen("map");
+    }
+    map = msg;
+    if (["map", "music"].includes(active)) showMap(); // update map screen, or switch away from music (not other screens)
+    else if (active==="main" && !hadMap) showMain(); // refresh menu: add "Map" entry
+  };
+  const onText = function(msg) {
+    require("messages").apply(msg, MESSAGES);
+    const mIdx = MESSAGES.findIndex(m => m.id===msg.id);
+    if (!MESSAGES[mIdx]) if (back==="messages") back = undefined;
+    if (active==="main") showMain(); // update message count
+    if (MESSAGES.length===0) exitScreen("messages"); // removed last message
+    else if (active==="messages") showMessage(messageNum);
+    if (msg.new) buzz(msg);
+    if (active!=="call") {// don't switch away from incoming call
+      if (active!=="messages" || messageNum===mIdx) showMessage(mIdx);
+    }
+    if (active==="messages") drawFooter(); // update footer with new number of messages
+  };
+
+  const getImage = function(msg, def) {
+    // app icons, provided by `messages` app
+    return require("messageicons").getImage(msg);
+  };
+  const getImageColor = function(msg, def) {
+    // app colors, provided by `messages` app
+    return require("messageicons").getColor(msg, {default: def});
+  };
+  const getIcon = function(icon) {
+    return require("messagegui").getIcon(icon);
+  };
+  const getIconColor = function(icon) {
+    return require("messagegui").getColor(icon);
+  };
+
+  /*
+  * icons should be 24x24px with 1bpp colors and transparancy
+  */
+  const getMessageImage = function(msg) {
+    if (msg.img) return atob(msg.img);
+    if (msg.id==="music") return getIcon("Music");
+    if (msg.id==="back") return getIcon("Back");
+    const s = (msg.src || "").toLowerCase();
+
+    return getImage(s, "notification");
+  };
+
+  const showMap = function() {
+    setActive("map");
+    delete map.new;
+    let m, distance, street, target, eta;
+    m = map.title.match(/(.*) - (.*)/);
+    if (m) {
+      distance = m[1];
+      street = m[2];
+    } else {
+      street = map.title;
+    }
+    m = map.body.match(/(.*) - (.*)/);
+    if (m) {
+      target = m[1];
+      eta = m[2];
+    } else {
+      target = map.body;
+    }
+    let layout = new Layout({
+      type: "v", c: [
+        {type: "txt", font: fontNormal, label: target, bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, pad: 2},
+        {
+          type: "h", bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, c: [
+            {type: "txt", font: "6x8", label: "Towards"},
+            {type: "txt", font: fontNormal, label: street},
+          ]
+        },
+        {
+          type: "h", fillx: 1, filly: 1, c: [
+            map.img ? {type: "img", src: () => atob(map.img), scale: 2} : {},
+            {
+              type: "v", fillx: 1, c: [
+                {type: "txt", font: fontNormal, label: distance || ""},
+              ]
+            },
+          ]
+        },
+        {type: "txt", font: "6x8:2", label: eta}
+      ]
+    });
+    layout.render();
+    // go back on any input
+    setUI({
+      mode: "custom",
+      back: goBack,
+      btn: b => {
+        if (B2 || b===2) goBack();
+      },
+      swipe: dir => {
+        if (dir===RIGHT) showMain();
+      },
+    });
+  };
+
+  const toggleMusic = function() {
+    const mc = cmd => {
+      if (Bangle.musicControl) Bangle.musicControl(cmd);
+    };
+    if (!music) {
+      music = {state: "play"};
+      mc("play");
+    } else if (music.state==="play") {
+      music.state = "pause";
+      mc("pause");
+    } else {
+      music.state = "play";
+      mc("play");
+    }
+    if (layout && layout.musicIcon) {
+      // musicIcon/musicToggle .src returns icon based on current music.state
+      layout.update(layout.musicIcon);
+      if (layout.musicToggle) layout.update(layout.musicToggle);
+      layout.render();
+    }
+  };
+
+  const doMusic = function(action) {
+    if (!Bangle.musicControl) return;
+    Bangle.buzz(50);
+    if (action==="toggle") toggleMusic();
+    else Bangle.musicControl(action);
+  };
+  const showMusic = function() {
+    if (active!==music) setActive("music");
+    if (!music) music = {track: "", artist: "", album: "", state: "pause"};
+    delete music.new;
+    const w = Bangle.appRect.w-50; // title/album need to leave room for icon
+    let artist, album;
+    if (music.album && settings().showAlbum) {
+      // max 2 lines for artist/album
+      artist = g.setFont(fontNormal).wrapString(music.artist, w).slice(0, 2).join("\n");
+      album = g.wrapString(music.album, w).slice(0, 2).join("\n");
+    } else {
+      // no album: artist gets 3 lines
+      artist = g.setFont(fontNormal).wrapString(music.artist, w).slice(0, 3).join("\n");
+      album = "";
+    }
+    // place (subtitle) on a new line
+    let track = music.track.replace(/ \(/, "\n(");
+    track = g.wrapString(track, Bangle.appRect.w).slice(0, 5).join("\n");
+    // "unknown" n/c/dur can show up as -1
+    let num, dur;
+    if ("n" in music && music.n>0) {
+      num = "#"+music.n;
+      if ("c" in music && music.c>0) {
+        num += "/"+music.c;
+      }
+      num = {type: "txt", font: fontTiny, bgCol: g.theme.bg, label: num};
+    }
+    if ("dur" in music && music.dur>0) {
+      dur = Math.floor(music.dur/60)+":"+(music.dur%60).toString().padStart(2, "0");
+      dur = {type: "txt", font: fontTiny, bgCol: g.theme.bg, label: dur};
+    }
+    let info;
+    if (num && dur) info = {type: "h", fillx: 1, c: [{fillx: 1}, dur, {fillx: 1}, num, {fillx: 1},]};
+    else if (num) info = num;
+    else if (dur) info = dur;
+    else info = {};
+
+    layout = new Layout({
+      type: "v", c: [
+        {
+          type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
+            {
+              id: "musicIcon", type: "img", pad: 10, bgCol: g.theme.bg2, col: g.theme.fg2
+              , src: () => getIcon((music.state==="play") ? "music" : "pause")
+            },
+            {
+              type: "v", fillx: 1, c: [
+                {type: "txt", font: fontNormal, col: g.theme.fg2, bgCol: g.theme.bg2, label: artist, pad: 2, id: "artist"},
+                album ? {type: "txt", font: fontNormal, col: g.theme.fg2, bgCol: g.theme.bg2, label: album, pad: 2, id: "album"} : {},
+              ]
+            }
+          ]
+        },
+        {type: "txt", halign: 0, font: fontNormal, bgCol: g.theme.bg, label: track, fillx: 1, filly: 1, pad: 2, id: "track"},
+        settings().musicButtons ? {
+          type: "h", fillx: 1, c: [
+            B2 ? {} : {width: 4},
+            {
+              type: "btn", id: "previous", cb: () => doMusic("previous")
+              , src: () => getIcon("previous")
+            },
+            {fillx: 1},
+            {
+              type: "btn", id: "musicToggle", cb: () => doMusic("toggle")
+              , src: () => getIcon((music.state==="play") ? "pause" : "play")
+            },
+            {fillx: 1},
+            {
+              type: "btn", id: "next", cb: () => doMusic("next")
+              , src: () => getIcon("next")
+            },
+            B2 ? {} : {width: 4},
+          ]
+        } : {},
+        info,
+      ]
+    });
+    layout.render();
+    let options = {mode: "updown"};
+    // B1 with buttons: left hand side of screen is used for "previous"
+    if (B2 || !settings().musicButtons) options.back = goBack;
+    setUI(options, ud => {
+      if (ud) Bangle.musicControl(ud>0 ? "volumedown" : "volumeup");
+      else {
+        if (B2 || settings().musicButtons) goBack(); // B1 left-hand touch is "previous", so we need a way to go back
+        else doMusic("toggle");
+      }
+    });
+
+    Bangle.swipeHandler = dir => {
+      if (dir!==0) doMusic(dir===RIGHT ? "previous" : "next");
+    };
+    Bangle.on("swipe", Bangle.swipeHandler);
+
+    if (Bangle.touchHandler) Bangle.removeListener("touch", Bangle.touchHandler);
+    if (settings().musicButtons) {
+      // visible buttons
+      // left = previous, middle = toggle, right = next
+      if (B2) Bangle.touchHandler = (_side, xy) => {
+        // accept touches on the whole bottom and pick the closest button
+        if (xy.y2*Bangle.appRect.w/3) doMusic("next");
+        else doMusic("toggle");
+      };
+      else Bangle.touchHandler = (side) => {
+        if (side===1) doMusic("previous");
+        if (side===2) doMusic("next");
+        if (side===3) doMusic("toggle");
+      };
+    } else {
+      // no buttons: touch = toggle
+      // B2 setUI sets touchHandler, override that (we only want up/down swipes from the UI)
+      Bangle.touchHandler = (side, e) => {
+        // B1: side 1 (left) = back, B2: only toggle for e outside widget area
+        if ((!B2 && side>1) || (B2 && e.y>Bangle.appRect.y)) doMusic("toggle");
+      };
+    }
+    Bangle.on("touch", Bangle.touchHandler);
+  };
+
+  let layout;
+
+  const clearStuff = function() {
+    delete Bangle.appRect;
+    layout = undefined;
+    setUI();
+    g.reset().clearRect(Bangle.appRect);
+  };
+  const setActive = function(screen, args) {
+    clearStuff();
+    if (active && screen!==active) back = active;
+    if (screen==="messages") messageNum = args;
+    active = screen;
+  };
+  /**
+   * Go back to previous screen, preserving history
+   */
+  const goBack = function() {
+    if (back==="call" && call) showCall();
+    else if (back==="map" && map) showMap();
+    else if (back==="music" && music) showMusic();
+    else if (back==="messages" && MESSAGES.length) showMessage();
+    else if (back) showMain(); // previous screen was "main", or no longer valid
+    else quitApp(); // no previous screen: go back to clock
+  };
+  /**
+   * Leave screen, and make sure goBack() won't take us there anymore;
+   * @param {string} screen
+   */
+  const exitScreen = function(screen) {
+    if (back===screen) back = (active==="main") ? undefined : "main";
+    if (active===screen) {
+      active = undefined;
+      goBack();
+    }
+  };
+  const showMain = function() {
+    setActive("main");
+    let grid = {"": {title:/*LANG*/"Messages", align: 0, back: load}};
+    if (call) grid[/*LANG*/"Incoming Call"] = {icon: "Phone", cb: showCall};
+    if (alarm) grid[/*LANG*/"Alarm"] = {icon: "Alarm", cb: showAlarm};
+    const unread = MESSAGES.filter(m => m.new).length;
+    if (unread) {
+      grid[unread+" "+/*LANG*/"New"] = {icon: "Unread", cb: () => showMessage(MESSAGES.findIndex(m => m.new))};
+      grid[/*LANG*/"All"+` (${MESSAGES.length})`] = {icon: "Notification", cb: showMessage};
+    } else {
+      const allLabel = MESSAGES.length+" "+(MESSAGES.length===1 ?/*LANG*/"Message" :/*LANG*/"Messages");
+      if (MESSAGES.length) grid[allLabel] = {icon: "Notification", cb: showMessage};
+      else grid[/*LANG*/"No Messages"] = {icon: "Neg", cb: load};
+    }
+    if (unread {
+          E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Dismiss Read Messages"}).then(isYes => {
+            if (isYes) {
+              MESSAGES.filter(m => !m.new).forEach(msg => {
+                Bangle.messageResponse(msg, false);
+                remove(msg);
+              });
+            }
+            showMain();
+          });
+        }
+      };
+    }
+    if (map) grid[/*LANG*/"Map"] = {icon: "Map", cb: showMap};
+    if (music || settings().alwaysShowMusic) grid[/*LANG*/"Music"] = {icon: "Music", cb: showMusic};
+    grid[/*LANG*/"settings"] = {icon: "settings", cb: showSettings};
+    showGrid(grid);
+  };
+  const clamp = function(val, min, max) {
+    if (valmax) return max;
+    return val;
+  };
+  /**
+   * Show grid of labeled buttons,
+   *
+   * items:
+   *   {
+   *     cb: callback,
+   *     img: button image,
+   *     icon: icon name, // string, use getIcon(icon) instead of img
+   *     col: icon color, // optional: defaults to getColor(icon)
+   *   }
+   * "" item is options:
+   *   {
+   *     title: string,
+   *     back: callback,
+   *     rows/cols: (optional) fit to this many columns/rows, omit for automatic fit
+   *     align: bottom row alignment if items don't fit perfectly into a grid
+   *            -1: left
+   *             1: right
+   *             0: left, but move final button to the right
+   *             undefined: spread (can be unaligned with rest of grid!)
+   *   }
+   * @param items
+   */
+  const showGrid = function(items) {
+    clearStuff();
+    const options = items[""] || {},
+      back = options.back || items["< Back"];
+    const keys = Object.keys(items).filter(k => k!=="" && k!=="< Back");
+    let cols;
+    if (options.cols) {
+      cols = options.cols;
+    } else if (options.rows) {
+      cols = Math.ceil(keys.length/options.rows);
+    } else {
+      const rows = Math.round(Math.sqrt(keys.length));
+      cols = Math.ceil(keys.length/rows);
+    }
+
+    let l = {type: "v", c: []};
+    if (options.title) {
+      l.c.push({id: "title", type: "txt", label: options.title, font: (B2 ? "12x20" : "6x8:2"), fillx: 1});
+    }
+    const w = Bangle.appRect.w/cols, // set explicit width, because labels can stick out
+      bgs = [g.theme.bgH, g.theme.bg2], // background colors used for buttons
+      newRow = () => ({type: "h", filly: 1, c: []});
+    let row = newRow(),
+      cbs = [[]]; // callbacks for Bangle.js 2 touchHandler below
+    keys.forEach(key => {
+      const item = items[key],
+        label = g.setFont(fontTiny).wrapString(key, w).join("\n");
+      let color = "col" in item ? item.col : getIconColor(item.icon || "Unknown");
+      if (color && bgs.includes(g.setColor(color).getColor())) color = undefined; // make sure button is not invisible
+      row.c.push({
+        type: "v", pad: 2, width: w, c: [
+          {
+            type: "btn",
+            src: item.img || (() => getIcon(item.icon || "Unknown")),
+            col: color,
+            cb: B2
+              ? undefined // We handle B2 touches below
+              : () => setTimeout(item.cb), // prevent MEMORY error from running cb() inside the Layout touchHandler
+          },
+          {height: 2},
+          {type: "txt", label: label, font: fontTiny},
+        ]
+      });
+      if (B2) cbs[cbs.length-1].push(item.cb);
+      if (row.c.length>=cols) {
+        l.c.push(row);
+        row = newRow();
+        if (B2) cbs.push([]);
+      }
+    });
+    if (row.c.length) {
+      if (options.align!==undefined) {
+        const filler = {width: w*(cols-row.c.length)};
+        if (options.align=== -1) row.c.unshift(filler); // left
+        else if (options.align===1) row.c.push(filler); // right
+        else if (options.align===0) row.c.splice(row.c.length-1, 0, filler); // left, but final item on right
+      }
+      l.c.push(row);
+    }
+    layout = new Layout(l, {back: back});
+    layout.render();
+
+    if (B2) {
+      // override touchHandler: no need to hit buttons exactly, just pick the nearest
+      if (Bangle.touchHandler) Bangle.removeListener("touch", Bangle.touchHandler);
+      Bangle.touchHandler = (side, xy) => {
+        if (xy.y<=Bangle.appRect.y) return; // widgetbar: ignore
+        let rows = l.c.length,
+          y = Bangle.appRect.y, h = Bangle.appRect.h;
+        if (options.title) {
+          rows--;
+          y += layout.title.h;
+          h -= layout.title.h;
+        }
+        const r = clamp(Math.floor(rows*(xy.y-y)/h), 0, rows-1); // row (0-indexed)
+        let c; // column (0-indexed)
+        if (rcbs[r].length-2) return; // gap before final item
+          } else { // spread
+            c = clamp(Math.floor(cbs[r].length*(xy.x-Bangle.appRect.x)/Bangle.appRect.w), 0, cols-1);
+          }
+        }
+        if (r {
+      setFont();
+      showMain();
+    });
+  };
+  const showCall = function() {
+    setActive("call");
+    delete call.new;
+    Bangle.setLocked(false);
+    Bangle.setLCDPower(1);
+
+    const w = g.getWidth()-48,
+      lines = g.setFont(fontNormal).wrapString(call.title, w),
+      title = (lines.length>2) ? lines.slice(0, 2).join("\n")+"..." : lines.join("\n");
+    const respond = function(accept) {
+      Bangle.buzz(50);
+      Bangle.messageResponse(call, accept);
+      remove(call);
+      call = undefined;
+      goBack();
+    };
+    let options = {};
+    if (!B2) {
+      options.btns = [
+        {
+          label:/*LANG*/"accept",
+          cb: () => respond(true),
+        }, {
+          label:/*LANG*/"ignore",
+          cb: goBack,
+        }, {
+          label:/*LANG*/"reject",
+          cb: () => respond(false),
+        }
+      ];
+    }
+
+    layout = new Layout({
+      type: "v", c: [
+        {
+          type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
+            {type: "img", pad: 10, src: () => getIcon("phone"), col: getIconColor("phone")},
+            {
+              type: "v", fillx: 1, c: [
+                {type: "txt", font: fontTiny, label: call.src ||/*LANG*/"Incoming Call", bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, pad: 2, halign: 1},
+                title ? {type: "txt", font: fontNormal, label: title, bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, pad: 2} : {},
+              ]
+            },
+          ]
+        },
+        {type: "txt", font: fontNormal, label: call.body, fillx: 1, filly: 1, pad: 2, wrap: true},
+        {
+          type: "h", fillx: 1, c: [
+            // button callbacks won't actually be used: setUI below overrides the touchHandler set by Layout
+            {type: B2 ? "btn" : "img", src: () => getIcon("Neg"), cb: () => respond(false)},
+            {fillx: 1},
+            {type: B2 ? "btn" : "img", src: () => getIcon("Pos"), cb: () => respond(true)},
+          ]
+        }
+      ]
+    }, options);
+    layout.render();
+    setUI({
+      mode: "custom",
+      back: goBack,
+      touch: (side, xy) => {
+        if (B2 && xy.y {
+        if (B2 || b===2) goBack();
+        else if (b===1) respond(true);
+        else respond(false);
+      },
+      swipe: dir => {
+        if (dir===RIGHT) showMain();
+      },
+    });
+  };
+  const showAlarm = function() {
+    // dismissing alarms doesn't seem to work, so this is simple */
+    setActive("alarm");
+    delete alarm.new;
+    Bangle.setLocked(false);
+    Bangle.setLCDPower(1);
+
+    const w = g.getWidth()-48,
+      lines = g.setFont(fontNormal).wrapString(alarm.title, w),
+      title = (lines.length>2) ? lines.slice(0, 2).join("\n")+"..." : lines.join("\n");
+    layout = new Layout({
+      type: "v", c: [
+        {
+          type: "h", fillx: 1, bgCol: g.theme.bg2, col: g.theme.fg2, c: [
+            alarm.body ? {type: "img", pad: 10, src: () => getIcon("alarm"), col: getIconColor("alarm")} : {},
+            {type: "txt", font: fontNormal, label: title ||/*LANG*/"Alarm", bgCol: g.theme.bg2, col: g.theme.fg2, fillx: 1, pad: 2, halign: 1},
+          ]
+        },
+        alarm.body
+          ? {type: "txt", font: fontNormal, label: alarm.body, fillx: 1, filly: 1, pad: 2, wrap: true}
+          : {type: "img", pad: 10, scale: 3, src: () => getIcon("alarm"), col: getIconColor("alarm")},
+      ]
+    });
+    layout.render();
+    setUI({
+      mode: "custom",
+      back: goBack,
+      btn: b => {
+        if (B2 || b===2) goBack();
+      },
+      swipe: dir => {
+        if (dir===RIGHT) showMain();
+      },
+    });
+  };
+  /**
+   * Send message response, and delete it from list
+   * @param {string|boolean} reply Response text, false to dismiss (true to open on phone)
+   */
+  const respondToMessage = function(reply) {
+    const msg = MESSAGES[messageNum];
+    if (msg) {
+      Bangle.messageResponse(msg, reply);
+      if (reply===false) remove(msg);
+    }
+    if (MESSAGES.length<1) goBack(); // no more messages
+    else showMessage((msg && reply===false) ? messageNum : messageNum+1); // show next message
+  };
+  const showMessageActions = function() {
+    let title = MESSAGES[messageNum].title || "";
+    if (g.setFont(fontNormal).stringMetrics(title).width>Bangle.appRect.w-(B2 ? 0 : 20)) {
+      title = g.wrapString("..."+title, Bangle.appRect.w-(B2 ? 0 : 20))[0].substring(3)+"...";
+    }
+    clearStuff();
+    let grid = {
+      "": {
+        title: title ||/*LANG*/"Message",
+        back: () => showMessage(messageNum),
+        cols: 3, // fit all replies on first row, dismiss on bottom
+      }
+    };
+    // Text replies don't work (yet)
+    // grid[/*LANG*/"OK"] = {icon: "Ok", col: "#0f0", cb: () => respondToMessage("\u{1F44D}")}; // "Thumbs up" emoji
+    // grid[/*LANG*/"Nak"] = {icon: "Nak", col: "#f00", cb: () => respondToMessage("\u{1F44E}")}; // "Thumbs down" emoji
+    // grid[/*LANG*/"No Phone"] = {icon: "NoPhone", col: "#f0f", cb: () => respondToMessage("\u{1F4F5}")}; // "No Mobile Phones" emoji
+
+    grid[/*LANG*/"Dismiss"] = {icon: "Trash", col: "#ff0", cb: () => respondToMessage(false)};
+    showGrid(grid);
+  };
+  /**
+   * Show message
+   *
+   * @param {number} [num=0] Message to show
+   * @param {boolean} [bottom=false] Scroll message to bottom right away
+   */
+  let buzzing = false, moving = false, switching = false;
+  let h, fh, offset;
+
+  /**
+   * draw (sticky) footer
+   */
+  const drawFooter = function() {
+    // left hint: swipe from left for main menu
+    g.reset().clearRect(Bangle.appRect.x, Bangle.appRect.y2-fh, Bangle.appRect.x2, Bangle.appRect.y2)
+      .setFont(fontTiny)
+      .setFontAlign(-1, 1) // bottom left
+      .drawString(
+        "\0"+atob("CAiBACBA/EIiAnwA")+ // back
+        "\0"+atob("CAiBAEgkEgkSJEgA"), // >>
+        Bangle.appRect.x+(B2 ? 1 : 28), Bangle.appRect.y2
+      );
+    // center message count+hints: swipe up/down for next/prev message
+    const footer = `  ${messageNum+1}/${MESSAGES.length}  `,
+      fw = g.stringWidth(footer);
+    g.setFontAlign(0, 1); // bottom center
+    if (B2 && messageNum>0 && offset<=0)
+      g.drawString("\0"+atob("CAiBAABBIhRJIhQI"), Bangle.appRect.x+Bangle.appRect.w/2-fw/2, Bangle.appRect.y2); // ^ swipe to prev
+    g.drawString(footer, Bangle.appRect.x+Bangle.appRect.w/2, Bangle.appRect.y2);
+    if (B2 && messageNum=h-(Bangle.appRect.h-fh))
+      g.drawString("\0"+atob("CAiBABAoRJIoRIIA"), Bangle.appRect.x+Bangle.appRect.w/2+fw/2, Bangle.appRect.y2); // v swipe to next
+    // right hint: swipe from right for message actions
+    g.setFontAlign(1, 1) // bottom right
+      .drawString(
+        "\0"+atob("CAiBABIkSJBIJBIA")+ // <<
+        "\0"+atob("CAiBAP8AAP8AAP8A"), // = ("hamburger menu")
+        Bangle.appRect.x2-(B2 ? 1 : 28), Bangle.appRect.y2
+      );
+  };
+  const showMessage = function(num, bottom) {
+    if (num<0) num = 0;
+    if (!num) num = 0; // no number: show first
+    if (num>=MESSAGES.length) num = MESSAGES.length-1;
+    setActive("messages", num);
+    if (!MESSAGES.length) {
+      // I /think/ this should never happen...
+      return E.showPrompt(/*LANG*/"No Messages", {
+        title:/*LANG*/"Messages",
+        img: require("heatshrink").decompress(atob("kkk4UBrkc/4AC/tEqtACQkBqtUDg0VqAIGgoZFDYQIIM1sD1QAD4AIBhnqA4WrmAIBhc6BAWs8AIBhXOBAWz0AIC2YIC5wID1gkB1c6BAYFBEQPqBAYXBEQOqBAnDAIQaEnkAngaEEAPDFgo+IKA5iIOhCGIAFb7RqAIGgtUBA0VqobFgNVA")),
+        buttons: {/*LANG*/"Ok": 1}
+      }).then(showMain);
+    }
+    Bangle.setLocked(false);
+    Bangle.setLCDPower(1);
+    // only clear msg.new on user input
+    const msg = MESSAGES[messageNum]; // message
+    fh = 10; // footer height
+    offset = 0;
+    let oldOffset = 0;
+    const move = (dy) => {
+      offset = Math.max(0, Math.min(h-(Bangle.appRect.h-fh), offset+dy)); // clip at message height
+      dy = oldOffset-offset; // real dy
+      // move all elements to new offset
+      const offsetRecurser = function(l) {
+        if (l.y) l.y += dy;
+        if (l.c) l.c.forEach(offsetRecurser);
+      };
+      offsetRecurser(layout.l);
+      oldOffset = offset;
+      draw();
+    };
+    const draw = () => {
+      g.reset()
+        .clearRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2-fh)
+        .setClipRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2-fh);
+      g.reset = () => g.setColor(g.theme.fg).setBgColor(g.theme.bg); // stop Layout resetting ClipRect
+      layout.render();
+      if (layout.button && h>Bangle.appRect.h-fh && offset(Bangle.appRect.h-fh)) {
+        const sbh = (Bangle.appRect.h-fh)/h*(Bangle.appRect.h-fh), // scrollbar height
+          y1 = Bangle.appRect.y+offset/h*(Bangle.appRect.h-fh), y2 = y1+sbh;
+        g.setColor(g.theme.bg).drawLine(Bangle.appRect.x2, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2-fh);
+        g.setColor(g.theme.fg).drawLine(Bangle.appRect.x2, y1, Bangle.appRect.x2, y2);
+      }
+      drawFooter();
+    };
+    const buzzOnce = () => {
+      if (buzzing) return;
+      buzzing = true;
+      Bangle.buzz(50).then(() => setTimeout(() => {buzzing = false;}, 500));
+    };
+
+    layout = getMessageLayout(msg);
+    h = layout.l.h; // message height
+    if (bottom) move(h); // scrolling backwards: jump to bottom of message
+    else draw();
+    const PAGE_SIZE = Bangle.appRect.h-fh;
+    const // shared B1/B2 handlers
+      back = () => {
+        delete msg.new; // we mark messages as read on any input
+        goBack();
+      },
+      swipe = dir => {
+        delete msg.new;
+        if (dir===RIGHT) showMain();
+        else if (dir===LEFT) showMessageActions();
+      },
+      touch = (side, xy) => {
+        delete msg.new;
+        if (h<=Bangle.appRect.h-fh || offset>=h-(Bangle.appRect.h-fh)) { // already at bottom
+          // B2: check for button-press
+          //     setUI overrides Layout listeners, so we need to check for button presses ourselves
+          if (B2 && layout.button) {
+            const b = layout.button;
+            // the button is at the bottom of the screen, so we accept touches all the way down
+            if (xy.x>=b.x && xy.y>=b.y && xy.x<=b.x+b.w /*&& xy.y<=b.y+b.h*/) return b.cb();
+          }
+          if (B2 && xy.yBangle.appRect.h-fh && offset {
+          delete msg.new;
+          if (!switching) {
+            const dy = -e.dy;
+            if (dy>0) { // up
+              if (h>Bangle.appRect.h-fh && offset0) {
+                moving = true; // prevent scrolling right into prev message
+                move(dy);
+              } else if (messageNum>0) { // already at top: show prev
+                if (!moving) { // don't scroll right through to previous message
+                  Bangle.buzz(30);
+                  switching = true; // don't process any more drag events until we lift our finger
+                  showMessage(messageNum-1, true);
+                }
+              } else { // already at top of first message
+                buzzOnce();
+              }
+            }
+          }
+          if (!e.b) {
+            // touch end: we can swipe to another message (if we reached the top/bottom) or move the new message
+            moving = false;
+            switching = false;
+          }
+        },
+        touch: touch,
+      });
+    } else { // Bangle.js 1
+      setUI({
+        mode: "updown",
+        back: back,
+      }, dir => {
+        delete msg.new;
+        if (dir===DOWN) {
+          if (h>Bangle.appRect.h-fh && offset0) {
+            move(-PAGE_SIZE);
+          } else if (messageNum>0) { // top reached: show previous
+            Bangle.buzz(30);
+            showMessage(messageNum-1, true);
+          } else {
+            buzzOnce(); // already at top of first message
+          }
+        } else { // button
+          showMessageActions();
+        }
+      });
+      Bangle.swipeHandler = swipe;
+      Bangle.on("swipe", Bangle.swipeHandler);
+      Bangle.touchHandler = touch;
+      Bangle.on("touch", Bangle.touchHandler);
+    } // Bangle.js 1/2
+  };
+  /**
+   * Determine message layout information: size, fonts, and wrapped title/body texts
+   *
+   * @param msg
+   * @returns {{h: number, w: number,
+   *            src: (string),
+   *            title: (string), titleFont: (string),
+   *            body: (string), bodyFont: (string)}}
+   */
+  const getMessageLayoutInfo = function(msg) {
+    // header: [icon][title]
+    //         [ src]
+    //
+    // But: no title? -> use src as title
+    let w, src = msg.src || "",
+      title = msg.title || "",
+      body = msg.body || "",
+      h = 0, // total height
+      th = 0, // title height
+      ih = 46; // icon height: // icon(24) + internal padding(20) + icon<->src spacer(2)
+    if (!title) {
+      title = src;
+      src = "";
+    }
+
+    // top bar
+    if (title) {
+      w = Bangle.appRect.w-59;  // icon(24) + padding:left(5) + padding:btn-txt(5) + internal btn padding(20) + padding:right(5)
+      title = g.setFont(fontNormal).wrapString(title, w).join("\n");
+      th += 2+g.stringMetrics(title).height; // 2px padding
+    }
+    if (src) {
+      w = 59;  // icon(24) + padding:left(5) + padding:btn-txt(5) + internal btn padding(20) + padding:right(5)
+      src = g.setFont(fontTiny).wrapString(src, w).join("\n");
+      ih += g.stringMetrics(src).height;
+    }
+
+    h = Math.max(ih, th); // maximum of icon/title
+
+    // body
+    w = Bangle.appRect.w-4; // padding(2x2)
+    body = g.setFont(fontNormal).wrapString(msg.body, w).join("\n");
+    h += 4+g.stringMetrics(body).height; // padding(2x2)
+
+    if (settings().button) h += 44; // icon(24) + padding(2x2) + internal btn padding(16)
+
+    w = Bangle.appRect.w;
+    // always expand to -<(10x)footer>
+    h = Math.max(h, Bangle.appRect.h-10);
+
+    return {
+      src: src,
+      title: title,
+      body: body,
+      h: h,
+      w: w,
+    };
+  };
+
+  const getMessageLayout = function(msg) {
+    // Crafted so that on B2, with "medium" font, a message with
+    //   icon + src + 2-line title + 2-line body + button
+    // fits exactly, i.e. no need for scrolling
+    const info = getMessageLayoutInfo(msg);
+    const hCol = msg.new ? g.theme.fgH : g.theme.fg2,
+      hBg = msg.new ? g.theme.bgH : g.theme.bg2;
+
+    // lie to Layout library about available space
+    Bangle.appRect = Object.assign({}, Bangle.appRect,
+      {w: info.w, h: info.h, x2: Bangle.appRect.x+info.w-1, y2: Bangle.appRect.y+info.h-1});
+
+    // make sure icon is not invisible
+    let imageCol = getImageColor(msg);
+    if (g.setColor(imageCol).getColor()==hBg) imageCol = hCol;
+
+    layout = new Layout({
+      type: "v", c: [
+        {
+          type: "h", fillx: 1, bgCol: hBg, col: hCol, c: [
+            {width: 3},
+            {
+              type: "v", c: [
+                {type: "img", /*pad: 2,*/ src: () => getMessageImage(msg), col: imageCol},
+                {height: 2},
+                info.src ? {type: "txt", font: fontTiny, label: info.src, bgCol: hBg, col: hCol} : {},
+              ]
+            },
+            info.title ? {type: "txt", font: fontNormal, label: info.title, bgCol: hBg, col: hCol, fillx: 1, pad: 2} : {},
+            {width: 3},
+          ]
+        },
+        {type: "txt", font: fontNormal, label: info.body, fillx: 1, filly: 1, pad: 2},
+        {filly: 1},
+        settings().button ? {
+          type: "h", c: [
+            B2 ? {} : {fillx: 1}, // Bangle.js 1: touching right side = press button
+            {id: "button", type: "btn", pad: 2, src: () => getIcon("trash"), cb: () => respondToMessage(false)},
+          ]
+        } : {},
+      ]
+    });
+    layout.update();
+    delete Bangle.appRect;
+    return layout;
+  };
+
+  /** this is a timeout if the app has started and is showing a single message
+   but the user hasn't seen it (e.g. no user input) - in which case
+   we should start a timeout for settings().unreadTimeout to return
+   to the clock. */
+  let unreadTimeout;
+  /**
+   * Stop auto-unload timeout and buzzing, remove listeners for this function
+   */
+  const clearUnreadStuff = function() {
+    require("messages").stopBuzz();
+    if (unreadTimeout) clearTimeout(unreadTimeout);
+    unreadTimeout = undefined;
+    ["touch", "drag", "swipe"].forEach(l => Bangle.removeListener(l, clearUnreadStuff));
+    watches.forEach(w => clearWatch(w));
+    watches = [];
+  };
+
+  let messageNum, // currently visible message
+    watches = [], // button watches
+    savedMusic = false; // did we find a stored "music" message when loading?
+// special messages
+  let call, music, map, alarm;
+  /**
+   * Find special messages, and remove them from MESSAGES
+   */
+  const findSpecials = function() {
+    let idx = MESSAGES.findIndex(m => m.id==="call");
+    if (idx>=0) call = MESSAGES.splice(idx, 1)[0];
+    idx = MESSAGES.findIndex(m => m.id==="music");
+    if (idx>=0) {
+      music = MESSAGES.splice(idx, 1)[0];
+      savedMusic = true;
+    }
+    idx = MESSAGES.findIndex(m => m.id==="map");
+    if (idx>=0) map = MESSAGES.splice(idx, 1)[0];
+    idx = MESSAGES.findIndex(m => m.src && m.src.toLowerCase().startsWith("alarm"));
+    if (idx>=0) alarm = MESSAGES.splice(idx, 1)[0];
+  };
+  if (MESSAGES!==undefined) { // only if loading MESSAGES worked
+    g.reset().clear();
+    Bangle.loadWidgets();
+    require("messages").toggleWidget(false);
+    Bangle.drawWidgets();
+    findSpecials(); // sets global vars for special messages
+    // any message we asked to show?
+    const showIdx = MESSAGES.findIndex(m => m.show);
+    // any new text messages?
+    const newIdx = MESSAGES.findIndex(m => m.new);
+
+    // figure out why the app was loaded
+    if (showIdx>=0) show(showIdx);
+    else if (call && call.new) showCall();
+    else if (alarm && alarm.new) showAlarm();
+    else if (map && map.new) showMap();
+    else if (music && music.new && settings().openMusic) {
+      if (settings().alwaysShowMusic===undefined) {
+        // if not explicitly disabled, enable this the first time we see music
+        let s = settings();
+        s.alwaysShowMusic = true;
+        require("Storage").writeJSON("messages.settings.json", s);
+      }
+      showMusic();
+    }
+    // check for new message last: Maybe we already showed it, but timed out before
+    // if that happened, and we're loading for e.g. music now, we want to show the music screen
+    else if (newIdx>=0) {
+      showMessage(newIdx);
+      // auto-loaded for message(s): auto-close after timeout
+      let unreadTimeoutSecs = settings().unreadTimeout;
+      if (unreadTimeoutSecs===undefined) unreadTimeoutSecs = 60;
+      if (unreadTimeoutSecs) {
+        unreadTimeout = setTimeout(load, unreadTimeoutSecs*1000);
+      }
+    } else if (MESSAGES.length) { // not autoloaded, but we have messages to show
+      back = "main"; // prevent "back" from loading clock
+      showMessage();
+    } else showMain();
+
+    // stop buzzing, auto-close timeout on input
+    ["touch", "drag", "swipe"].forEach(l => Bangle.on(l, clearUnreadStuff));
+    (B2 ? [BTN1] : [BTN1, BTN2, BTN3]).forEach(b => watches.push(setWatch(clearUnreadStuff, b, false)));
+  }
+}
\ No newline at end of file
diff --git a/apps/messagelist/app.png b/apps/messagelist/app.png
new file mode 100644
index 000000000..6eae4bb96
Binary files /dev/null and b/apps/messagelist/app.png differ
diff --git a/apps/messagelist/boot.js b/apps/messagelist/boot.js
new file mode 100644
index 000000000..994a2cfed
--- /dev/null
+++ b/apps/messagelist/boot.js
@@ -0,0 +1,3 @@
+(function() {
+  Bangle.on("message", require("messagegui").messageListener);
+})();
\ No newline at end of file
diff --git a/apps/messagelist/lib.js b/apps/messagelist/lib.js
new file mode 100644
index 000000000..33b6d9d69
--- /dev/null
+++ b/apps/messagelist/lib.js
@@ -0,0 +1,246 @@
+// Handle incoming messages while the app is not loaded
+// The messages app overrides Bangle.messageListener
+// (placed in separate file, so we don't read this all at boot time)
+exports.messageListener = function(type, msg) {
+  if (msg.handled || (global.__FILE__ && __FILE__.startsWith("messagelist."))) return; // already handled/app open
+  // clean up, in case previous message didn't load the app after all
+  if (exports.loadTimeout) clearTimeout(exports.loadTimeout);
+  delete exports.loadTimeout;
+  delete exports.buzz;
+  const quiet = () => (require("Storage").readJSON("setting.json", 1) || {}).quiet;
+  /**
+   * Quietly load the app for music/map, if not already loading
+   */
+  function loadQuietly(msg) {
+    if (exports.loadTimeout) return; // already loading
+    exports.loadTimeout = setTimeout(function() {
+      Bangle.load("messagelist.app.js");
+    }, 500);
+  }
+  function loadNormal(msg) {
+    if (exports.loadTimeout) clearTimeout(exports.loadTimeout); // restart timeout
+    exports.loadTimeout = setTimeout(function() {
+      delete exports.loadTimeout;
+      // check there are still new messages (for #1362)
+      let messages = require("messages").getMessages(msg);
+      (Bangle.MESSAGES || []).forEach(m => require("messages").apply(m, messages));
+      if (!messages.some(m => m.new)) return; // don't use `status()`: also load for new music!
+      // if we're in a clock, or it's important, open app
+      if (Bangle.CLOCK || msg.important) {
+        if (exports.buzz) require("messages").buzz(msg.src);
+        Bangle.load("messagelist.app.js");
+      }
+    }, 500);
+  }
+
+  /**
+   * Mark message as handled, and save it for the app
+   */
+  const handled = () => {
+    if (!Bangle.MESSAGES) Bangle.MESSAGES = [];
+    require("messages").apply(msg, Bangle.MESSAGES);
+    if (!Bangle.MESSAGES.length) delete Bangle.MESSAGES;
+    if (msg.t==="remove") require("messages").save(msg);
+    else msg.handled = true;
+  };
+  /**
+   * Write messages to flash after all, when not laoding the app
+   */
+  const saveToFlash = () => {
+    (Bangle.MESSAGES||[]).forEach(m=>require("messages").save(m));
+    delete Bangle.MESSAGES;
+  }
+
+  switch(type) {
+    case "music":
+      if (!Bangle.CLOCK) return;
+      // only load app if we are playing, and we know which song
+      if (msg.state!=="play" || !msg.title) return;
+      if (exports.openMusic===undefined) {
+        // only read settings for first music message
+        exports.openMusic = !!(exports.settings().openMusic);
+      }
+      if (!exports.openMusic) return; // we don't care about music
+      if (quiet()) return;
+      msg.new = true;
+      handled();
+      return loadQuietly();
+
+    case "map":
+      handled();
+      if (msg.t!=="remove" && Bangle.CLOCK) loadQuietly();
+      else saveToFlash();
+      return;
+
+    case "text":
+      handled();
+      if (exports.settings().autoOpen===false) return saveToFlash();
+      if (quiet()) return saveToFlash();
+      if (msg.t!=="add" || !msg.new || !(Bangle.CLOCK || msg.important)) {
+        // not important enough to load the app
+        if (msg.t==="add" && msg.new) require("messages").buzz(msg);
+        return saveToFlash();
+      }
+      if (msg.t==="add" && msg.new) exports.buzz = true;
+      return loadNormal(msg);
+
+    case "alarm":
+      if (quiet()<2) return saveToFlash();
+    // fall through
+    case "call":
+      handled();
+      exports.buzz = true;
+      return loadNormal(msg);
+
+    // case "clearAll": do nothing
+  }
+};
+
+exports.settings = function() {
+  return Object.assign({
+      // Interface //
+      fontSize: 1,
+      onTap: 0, // [Message menu, Dismiss, Back, Nothing]
+      button: true,
+
+      // Behaviour //
+      vibrate: ":",
+      vibrateCalls: ":",
+      vibrateAlarms: ":",
+      repeat: 4,
+      vibrateTimeout: 60,
+      unreadTimeout: 60,
+      autoOpen: true,
+
+      // Music //
+      openMusic: true,
+      // no default: alwaysShowMusic (auto-enabled by app when music happens)
+      showAlbum: true,
+      musicButtons: false,
+
+      // Widget //
+      flash: true,
+      // showRead: false,
+
+      // Utils //
+    },
+    // fall back to default app settings if not set for messagelist
+    (require("Storage").readJSON("messages.settings.json", true) || {}),
+    (require("Storage").readJSON("messagelist.settings.json", true) || {}));
+};
+
+/**
+ * @param {string} icon Icon name
+ * @returns string Icon image string, for use with g.drawImage()
+ */
+exports.getIcon = function(icon) {
+  // TODO: icons should be 24x24px with 1bpp colors
+  switch(icon.toLowerCase()) {
+    // generic icons:
+    case "alert":
+      return atob("GBgBAAAAAP8AA//AD8PwHwD4HBg4ODwcODwccDwOcDwOYDwGYDwGYBgGYBgGcBgOcAAOOBgcODwcHDw4Hxj4D8PwA//AAP8AAAAA");
+    case "alarm":
+    case "alarmclockreceiver":
+      return atob("GBjBAP////8AAAAAAAACAEAHAOAefng5/5wTgcgHAOAOGHAMGDAYGBgYGBgYGBgYGBgYDhgYBxgMATAOAHAHAOADgcAB/4AAfgAAAAAAAAA=");
+    case "back": // TODO: 22x22
+      return atob("FhYBAAAAEAAAwAAHAAA//wH//wf//g///BwB+DAB4EAHwAAPAAA8AADwAAPAAB4AAHgAB+AH/wA/+AD/wAH8AA==");
+    case "calendar":
+      return atob("GBiBAAAAAAAAAAAAAA//8B//+BgAGBgAGBgAGB//+B//+B//+B9m2B//+B//+Btm2B//+B//+Btm+B//+B//+A//8AAAAAAAAAAAAA==");
+    case "mail":  // TODO: 28x18
+    case "sms message":
+    case "notification":
+      return atob("HBKBAD///8H///iP//8cf//j4//8f5//j/x/8//j/H//H4//4PB//EYj/44HH/Hw+P4//8fH//44///xH///g////A==");
+    case "map":  // TODO: 25x25,
+      return atob("GRmBAAAAAAAAAAAAAAIAYAHx/wH//+D/+fhz75w/P/4f//8P//uH///D///h3f/w4P+4eO/8PHZ+HJ/nDu//g///wH+HwAYAIAAAAAAAAAAAAAA=");
+    case "menu":
+      return atob("GBiBAAAAAAAAAAAAAAAAAP///////wAAAAAAAAAAAAAAAAAAAP///////wAAAAAAAAAAAAAAAAAAAP///////wAAAAAAAAAAAAAAAA==");
+    case "music":  // TODO: 22x22
+      return atob("FhaBAH//+/////////////h/+AH/4Af/gB/+H3/7/f/v9/+/3/7+f/vB/w8H+Dwf4PD/x/////////////3//+A=");
+    case "nak":  // TODO: 22x25
+      return atob("FhmBAA//wH//j//+P//8///7///v//+///7//////////////v//////////z//+D8AAPwAAfgAB+AAD4AAPgAAeAAB4AAHAAA==");
+    case "neg":  // TODO: 22x22
+      return atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA=");
+    case "next":
+      return atob("GBiBAAAAAAAAAAAAAAwAcB8A+B+A+B/g+B/4+B/8+B//+B//+B//+B//+B//+B//+B/8+B/4+B/g+B+A+B8A+AwAcAAAAAAAAAAAAA==");
+    case "nophone":  // TODO: 30x30
+      return atob("Hh6BAAAAAAGAAAAHAAAADgAAABwADwA4Af8AcA/8AOB/+AHH/+ADv/8AB//wAA/HAAAeAAACOAAADHAAAHjgAAPhwAAfg4AAfgcAAfwOAA/wHAA/wDgA/gBwA/gA4AfAAcAfAAOAGAAHAAAADgAAABgAAAAA");
+    case "ok":  // TODO: 22x25
+      return atob("FhmBAAHAAAeAAB4AAPgAA+AAH4AAfgAD8AAPwAD//+//////////////7//////////////v//+///7///v//8///gf/+A//wA==");
+    case "pause":
+      return atob("GBiBAAAAAAAAAAAAAAOBwAfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AfD4AOBwAAAAAAAAAAAAA==");
+    case "phone":  // TODO: 23x23
+    case "call":
+      return atob("FxeBABgAAPgAAfAAB/AAD+AAH+AAP8AAP4AAfgAA/AAA+AAA+AAA+AAB+AAB+AAB+OAB//AB//gB//gA//AA/8AAf4AAPAA=");
+    case "play":
+      return atob("GBiBAAAAAAAAAAAAAAcAAA+AAA/gAA/4AA/8AA//AA//wA//4A//8A//8A//4A//wA//AA/8AA/4AA/gAA+AAAcAAAAAAAAAAAAAAA==");
+    case "pos":  // TODO: 25x20
+      return atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA==");
+    case "previous":
+      return atob("GBiBAAAAAAAAAAAAAA4AMB8A+B8B+B8H+B8f+B8/+B//+B//+B//+B//+B//+B//+B8/+B8f+B8H+B8B+B8A+A4AMAAAAAAAAAAAAA==");
+    case "settings":  // TODO: 20x20
+      return atob("FBSBAAAAAA8AAPABzzgf/4H/+A//APnwfw/n4H5+B+fw/g+fAP/wH/+B//gc84APAADwAAAA");
+    case "to do":
+      return atob("GBgBAAAAAAAAAAAwAAB4AAD8AAH+AAP/DAf/Hg//Px/+f7/8///4///wf//gP//AH/+AD/8AB/4AA/wAAfgAAPAAAGAAAAAAAAAA");
+    case "trash":
+      return atob("GBiBAAAAAAAAAAB+AA//8A//8AYAYAYAYAZmYAZmYAZmYAZmYAZmYAZmYAZmYAZmYAZmYAZmYAZmYAYAYAYAYAf/4AP/wAAAAAAAAA==");
+    case "unknown":  // TODO: 30x30
+      return atob("Hh6BAAAAAAAAAAAAAAAAAAPwAAA/8AAB/+AAD//AAD4fAAHwPgAHwPgAAAPgAAAfAAAA/AAAD+AAAH8AAAHwAAAPgAAAPgAAAPgAAAAAAAAAAAAAAAAAAHAAAAPgAAAPgAAAPgAAAHAAAAAAAAAAAAAAAAAA");
+    case "unread":  // TODO: 29x24
+      return atob("HRiBAAAAH4AAAf4AAB/4AAHz4AAfn4AA/Pz/5+fj/z8/j/n5/j/P//j/Pn3j+PPPx+P8fx+Pw/x+AF/B4A78RiP3xwOPvHw+Pcf/+Ox//+NH//+If//+B///+A==");
+    default: //should never happen
+      return exports.getIcon("unknown");
+  }
+};
+/**
+ * @param {string} icon Icon
+ * @returns {string} Color to use with g.setColor()
+ */
+exports.getColor = function(icon) {
+  switch(icon.toLowerCase()) {
+    // generic colors, using B2-safe colors
+    case "alert":
+      return "#ff0";
+    case "alarm":
+      return "#fff";
+    case "calendar":
+      return "#f00";
+    case "mail":
+      return "#ff0";
+    case "map":
+      return "#f0f";
+    case "music":
+      return "#f0f";
+    case "neg":
+      return "#f00";
+    case "notification":
+      return "#0ff";
+    case "phone":
+    case "call":
+      return "#0f0";
+    case "settings":
+      return "#000";
+    case "sms message":
+      return "#0ff";
+    case "trash":
+      return "#f00";
+    case "unknown":
+      return g.theme.fg;
+    case "unread":
+      return "#ff0";
+    default:
+      return g.theme.fg;
+  }
+};
+
+/**
+ * Launch GUI app with given message
+ * @param {object} msg
+ */
+exports.open = function(msg) {
+  if (msg && msg.id && !msg.show) {
+    // store which message to load
+    msg.show = 1;
+  }
+
+  Bangle.load((msg && msg.new && msg.id!=="music") ? "messagelist.new.js" : "messagelist.app.js");
+};
diff --git a/apps/messagelist/metadata.json b/apps/messagelist/metadata.json
new file mode 100644
index 000000000..7947e2db4
--- /dev/null
+++ b/apps/messagelist/metadata.json
@@ -0,0 +1,28 @@
+{
+  "id": "messagelist",
+  "name": "Message List",
+  "version": "0.01",
+  "description": "Display notifications from iOS and Gadgetbridge/Android as a list",
+  "icon": "app.png",
+  "type": "app",
+  "tags": "tool,system",
+  "screenshots": [
+    {"url": "screenshot0.png"},
+    {"url": "screenshot1.png"},
+    {"url": "screenshot2.png"},
+    {"url": "screenshot3.png"}
+  ],
+  "supports": ["BANGLEJS","BANGLEJS2"],
+  "dependencies" : { "messageicons":"module" },
+  "provides_modules": ["messagegui"],
+  "readme": "README.md",
+  "storage": [
+    {"name":"messagelist.boot.js","url":"boot.js"},
+    {"name":"messagegui","url":"lib.js"},
+    {"name":"messagelist.app.js","url":"app.js"},
+    {"name":"messagelist.settings.js","url":"settings.js"},
+    {"name":"messagelist.img","url":"app-icon.js","evaluate":true}
+  ],
+  "data": [{"name":"messagelist.settings.json"}],
+  "sortorder": -9
+}
diff --git a/apps/messagelist/screenshot0.png b/apps/messagelist/screenshot0.png
new file mode 100644
index 000000000..b6f37c053
Binary files /dev/null and b/apps/messagelist/screenshot0.png differ
diff --git a/apps/messagelist/screenshot1.png b/apps/messagelist/screenshot1.png
new file mode 100644
index 000000000..f4d4db9fa
Binary files /dev/null and b/apps/messagelist/screenshot1.png differ
diff --git a/apps/messagelist/screenshot2.png b/apps/messagelist/screenshot2.png
new file mode 100644
index 000000000..67c192a1c
Binary files /dev/null and b/apps/messagelist/screenshot2.png differ
diff --git a/apps/messagelist/screenshot3.png b/apps/messagelist/screenshot3.png
new file mode 100644
index 000000000..02fed81a7
Binary files /dev/null and b/apps/messagelist/screenshot3.png differ
diff --git a/apps/messagelist/settings.js b/apps/messagelist/settings.js
new file mode 100644
index 000000000..cd2767336
--- /dev/null
+++ b/apps/messagelist/settings.js
@@ -0,0 +1,139 @@
+(function(back) {
+  let settings = require("messagegui").settings();
+  const inApp = (global.__FILE__ && __FILE__.startsWith("messagelist."));
+
+  function updateSetting(setting, value) {
+    settings[setting] = value;
+    let file;
+    switch(setting) {
+      case "flash":
+      case "showRead":
+      case "iconColorMode":
+      case "maxMessages":
+      case "maxUnreadTimeout":
+      case "openMusic":
+      case "repeat":
+      case "unlockWatch":
+      case "unreadTimeout":
+      case "vibrate":
+      case "vibrateCalls":
+      case "vibrateTimeout":
+        // Default app has this setting: update that file
+        file = "messages";
+        break;
+      default:
+        // write to our own settings file
+        file = "messagelist";
+    }
+    file += ".settings.json";
+    let saved = require("Storage").readJSON(file, true) || {};
+    saved[setting] = value;
+    require("Storage").writeJSON(file, saved);
+  }
+
+  function toggler(setting) {
+    return {
+      value: !!settings[setting],
+      onchange: v => updateSetting(setting, v)
+    };
+  }
+
+  function showIfMenu() {
+    const tapOptions = [/*LANG*/"Message menu",/*LANG*/"Dismiss",/*LANG*/"Back",/*LANG*/"Nothing"];
+    E.showMenu({
+      "": {"title": /*LANG*/"Interface"},
+      "< Back": () => showMainMenu(),
+      /*LANG*/"Font size": {
+        value: 0|settings.fontSize,
+        min: 0, max: 2,
+        format: v => [/*LANG*/"Small",/*LANG*/"Medium",/*LANG*/"Large",/*LANG*/"Huge"][v],
+        onchange: v => updateSetting("fontSize", v)
+      },
+      /*LANG*/"On Tap": {
+        value: settings.onTap,
+        min: 0, max: tapOptions.length-1, wrap: true,
+        format: v => tapOptions[v],
+        onchange: v => updateSetting("onTap", v)
+      },
+      /*LANG*/"Dismiss button": toggler("button"),
+    });
+  }
+
+  function showBMenu() {
+    E.showMenu({
+      "": {"title": /*LANG*/"Behaviour"},
+      "< Back": () => showMainMenu(),
+      /*LANG*/"Vibrate": require("buzz_menu").pattern(settings.vibrate, v => updateSetting("vibrate", v)),
+      /*LANG*/"Vibrate for calls": require("buzz_menu").pattern(settings.vibrateCalls, v => updateSetting("vibrateCalls", v)),
+      /*LANG*/"Vibrate for alarms": require("buzz_menu").pattern(settings.vibrateAlarms, v => updateSetting("vibrateAlarms", v)),
+      /*LANG*/"Repeat": {
+        value: settings.repeat,
+        min: 0, max: 10,
+        format: v => v ? v+"s" :/*LANG*/"Off",
+        onchange: v => updateSetting("repeat", v)
+      },
+      /*LANG*/"Vibrate timer": {
+        value: settings.vibrateTimeout,
+        min: 0, max: 240, step: 10,
+        format: v => v ? v+"s" :/*LANG*/"Forever",
+        onchange: v => updateSetting("vibrateTimeout", v)
+      },
+      /*LANG*/"Unread timer": {
+        value: settings.unreadTimeout,
+        min: 0, max: 240, step: 10,
+        format: v => v ? v+"s" :/*LANG*/"Off",
+        onchange: v => updateSetting("unreadTimeout", v)
+      },
+      /*LANG*/"Auto-open": toggler("autoOpen"),
+    });
+  }
+
+  function showMusicMenu() {
+    E.showMenu({
+      "": {"title": /*LANG*/"Music"},
+      "< Back": () => showMainMenu(),
+      /*LANG*/"Auto-open": toggler("openMusic"),
+      /*LANG*/"Always visible": toggler("alwaysShowMusic"),
+      /*LANG*/"Buttons": toggler("musicButtons"),
+      /*LANG*/"Show album": toggler("showAlbum"),
+    });
+  }
+
+  function showWidMenu() {
+    E.showMenu({
+      "": {"title": /*LANG*/"Widget"},
+      "< Back": () => showMainMenu(),
+      /*LANG*/"Flash icon": toggler("flash"),
+      // /*LANG*/"Show Read": toggler("showRead"),
+    });
+  }
+
+  function showUtilsMenu() {
+    let m = E.showMenu({
+      "": {"title": /*LANG*/"Utilities"},
+      "< Back": () => showMainMenu(),
+      /*LANG*/"Delete all": () => {
+        E.showPrompt(/*LANG*/"Are you sure?",
+          {title:/*LANG*/"Delete All Messages"})
+          .then(isYes => {
+            if (isYes) require("messages").write([]);
+            showUtilsMenu();
+          });
+      }
+    });
+  }
+
+  function showMainMenu() {
+    E.showMenu({
+      "": {"title": inApp ?/*LANG*/"Settings" :/*LANG*/"Messages"},
+      "< Back": back,
+      /*LANG*/"Interface": () => showIfMenu(),
+      /*LANG*/"Behaviour": () => showBMenu(),
+      /*LANG*/"Music": () => showMusicMenu(),
+      /*LANG*/"Widget": () => showWidMenu(),
+      /*LANG*/"Utils": () => showUtilsMenu(),
+    });
+  }
+
+  showMainMenu();
+});
diff --git a/apps/messages/ChangeLog b/apps/messages/ChangeLog
index 77334c54d..7d3414c1a 100644
--- a/apps/messages/ChangeLog
+++ b/apps/messages/ChangeLog
@@ -1,55 +1,4 @@
-0.01: New App!
-0.02: Add 'messages' library
-0.03: Fixes for Bangle.js 1
-0.04: Add require("messages").clearAll()
-0.05: Handling of message actions (ok/clear)
-0.06: New messages now go at the start (fix #898)
-      Answering true/false now exits the messages app if no new messages
-      Back now marks a message as read
-      Clicking top-left opens a menu which allows you to delete a message or mark unread
-0.07: Added settings menu with option to choose vibrate pattern and frequency (fix #909)
-0.08: Fix rendering of long messages (fix #969)
-      buzz on new message (fix #999)
-0.09: Message now disappears after 60s if no action taken and clock loads (fix 922)
-      Fix phone icon (#1014)
-0.10: Respect the 'new' attribute if it was set from iOS integrations
-0.11: Open app when touching the widget (Bangle.js 2 only)
-0.12: Extra app-specific notification icons
-      New animated notification icon (instead of large blinking 'MESSAGES')
-      Added screenshots
-0.13: Add /*LANG*/ comments for internationalisation
-      Add 'Delete All' option to message options
-      Now update correctly when 'require("messages").clearAll()' is called
-0.14: Hide widget when all unread notifications are dismissed from phone
-0.15: Don't buzz when Quiet Mode is active
-0.16: Fix text wrapping so it fits the screen even if title is big (fix #1147)
-0.17: Fix: Get dynamic dimensions of notify icon, fixed notification font
-0.18: Use app-specific icon colors
-      Spread message action buttons out
-      Back button now goes back to list of messages
-      If showMessage called with no message (eg all messages deleted) now return to the clock (fix #1267)
-0.19: Use a larger font for message text if it'll fit
-0.20: Allow tapping on the body to show a scrollable view of the message and title in a bigger font (fix #1405, #1031)
-0.21: Improve list readability on dark theme
-0.22: Add Home Assistant icon
-      Allow repeat to be switched Off, so there is no buzzing repetition.
-      Also gave the widget a pixel more room to the right
-0.23: Change message colors to match current theme instead of using green
-      Now attempt to use Large/Big/Medium fonts, and allow minimum font size to be configured
-0.24: Remove left-over debug statement
-0.25: Fix widget memory usage issues if message received and watch repeatedly calls Bangle.drawWidgets (fix #1550)
-0.26: Setting to auto-open music
-0.27: Add 'mark all read' option to popup menu (fix #1624)
-0.28: Option to auto-unlock the watch when a new message arrives
-0.29: Fix message list overwrites on Bangle.js 1 (fix #1642)
-0.30: Add new Icons (Youtube, Twitch, MS TODO, Teams, Snapchat, Signal, Post & DHL, Nina, Lieferando, Kalender, Discord, Corona Warn, Bibel)
-0.31: Option to disable icon flashing
-0.32: Added an option to allow quiet mode to override message auto-open
-0.33: Timeout from the message list screen if the message being displayed is removed and there is a timer going
-0.34: Don't buzz for 'map' update messages
-0.35: Reset graphics colors before rendering a message (possibly fix #1752)
-0.36: Ensure a new message plus an almost immediate deletion of that message doesn't load the messages app (fix #1362)
-0.37: Now use the setUI 'back' icon in the top left rather than specific buttons/menu items
-0.38: Add telegram foss handling
-0.39: Set default color for message icons according to theme
-0.40: Use default Bangle formatter for booleans
+0.55: Moved messages library into standalone library
+0.56: Fix handling of music messages
+0.57: Optimize saving empty message list
+0.58: show/hide "messages" widget directly, instead of through library stub
diff --git a/apps/messages/README.md b/apps/messages/README.md
index da2701f35..83524d7c8 100644
--- a/apps/messages/README.md
+++ b/apps/messages/README.md
@@ -1,61 +1,59 @@
-# Messages app
+# Messages library
 
-This app handles the display of messages and message notifications. It stores
-a list of currently received messages and allows them to be listed, viewed,
-and responded to.
+This library handles the passing of messages. It can storess a list of messages 
+and allows them to be retrieved by other apps.
 
-It is a replacement for the old `notify`/`gadgetbridge` apps.
+## Example
 
-## Settings
+Assuming you are using GadgetBridge and "overlay notifications":
 
-You can change settings by going to the global `Settings` app, then `App Settings`
-and `Messages`:
+1. Gadgetbridge sends an event to your watch for an incoming message
+2. The `android` app parses the message, and calls `require("messages").pushMessage({/** the message */})`
+3. `require("messages")` calls `Bangle.emit("message", "text", {/** the message */})`
+4. Overlay Notifications shows the message in an overlay, and marks it as `handled`
+5. The default UI app (Message UI, `messagegui`) sees the event is marked as `handled`, so does nothing.
+6. The default widget (`widmessages`) does nothing with `handled`, and shows a notification icon.
+7. You tap the notification, in order to open the full GUI: Overlay Notifications
+   calls `require("messages").openGUI({/** the message */})`
+8. `openGUI` calls `require("messagegui").open(/** copy of the message */)`.
+9. The `messagegui` library loads the Message UI app.
 
-* `Vibrate` - This is the pattern of buzzes that should be made when a new message is received
-* `Repeat` - How often should buzzes repeat - the default of 4 means the Bangle will buzz every 4 seconds
-* `Unread Timer` - When a new message is received we go into the Messages app.
-If there is no user input for this amount of time then the app will exit and return
-to the clock where a ringing bell will be shown in the Widget bar.
-* `Min Font` - The minimum font size used when displaying messages on the screen. A bigger font
-is chosen if there isn't much message text, but this specifies the smallest the font should get before
-it starts getting clipped.
-* `Auto-Open Music` - Should the app automatically open when the phone starts playing music?
-* `Unlock Watch` - Should the app unlock the watch when a new message arrives, so you can touch the buttons at the bottom of the app?
-* `Flash Icon` - Toggle flashing of the widget icon.
 
-## New Messages
 
-When a new message is received:
+## Events
 
-* If you're in an app, the Bangle will buzz and a 'new message' icon appears in the Widget bar. You can tap this bar to view the message.
-* If you're in a clock, the Messages app will automatically start and show the message
+When a new message arrives, a `"message"` event is emitted, you can listen for
+it like this:
 
-When a message is shown, you'll see a screen showing the message title and text.
+```js
+myMessageListener = Bangle.on("message", (type, message)=>{
+  if (message.handled) return; // another app already handled this message
+  //  is one of "text", "call", "alarm", "map", or "music"
+  // see `messages/lib.js` for possible  formats
+  // message.t could be "add", "modify" or "remove"
+  E.showMessage(`${message.title}\n${message.body}`, `${message.t} ${type} message`);
+  // You can prevent the default `message` app from loading by setting `message.handled = true`:
+  message.handled = true;
+});
+```
 
-* The 'back-arrow' button (or physical button on Bangle.js 2) goes back to Messages, marking the current message as read.
-* The top-left icon shows more options, for instance deleting the message of marking unread
-* On Bangle.js 2 you can tap on the message body to view a scrollable version of the title and text (or can use the top-left icon + `View Message`)
-* If shown, the 'tick' button:
-   * **Android** opens the notification on the phone
-   * **iOS** responds positively to the notification (accept call/etc)
-* If shown, the 'cross' button:
-   * **Android** dismisses the notification on the phone
-   * **iOS** responds negatively to the notification (dismiss call/etc)
+Apps can launch the full GUI by calling `require("messages").openGUI()`, if you
+want to write your own GUI, it should include boot code that listens for
+`"messageGUI"` events:
 
-## Images
-_1. Screenshot of a notification_
-
-![](screenshot.png)
-
-_2. What the notify icon looks like (it's touchable on Bangle.js2!)_
-
-![](screenshot-notify.gif)
+```js
+Bangle.on("messageGUI", message=>{
+  if (message.handled) return; // another app already opened it's GUI
+  message.handled = true; // prevent other apps form launching
+  Bangle.load("my_message_gui.app.js");
+})
 
+```
 
 
 ## Requests
 
-Please file any issues on https://github.com/espruino/BangleApps/issues/new?title=messages%20app
+Please file any issues on https://github.com/espruino/BangleApps/issues/new?title=[messages]%20library
 
 ## Creator
 
diff --git a/apps/messages/TEST_ME.txt b/apps/messages/TEST_ME.txt
new file mode 100644
index 000000000..8ce50d8b6
--- /dev/null
+++ b/apps/messages/TEST_ME.txt
@@ -0,0 +1,7 @@
+We need automated tests for this. Specifically:
+
+
+* send notification in clock with fast load -> messagesgui appears
+* send notification in clock without fast load -> messagesgui appears
+* send notification and delete notification quick -> messagesgui doesn't load
+* music?
diff --git a/apps/messages/lib.js b/apps/messages/lib.js
index 3f801e101..f301a91cd 100644
--- a/apps/messages/lib.js
+++ b/apps/messages/lib.js
@@ -1,187 +1,234 @@
-function openMusic() {
-  // only read settings file for first music message
-  if ("undefined"==typeof exports._openMusic) {
-    exports._openMusic = !!((require('Storage').readJSON("messages.settings.json", true) || {}).openMusic);
-  }
-  return exports._openMusic;
+exports.music = {};
+/**
+ * Emit "message" event with appropriate type from Bangle
+ * @param {object} msg
+ */
+function emit(msg) {
+  let type = "text";
+  if (["call", "music", "map"].includes(msg.id)) type = msg.id;
+  if (msg.src && msg.src.toLowerCase().startsWith("alarm")) type = "alarm";
+  Bangle.emit("message", type, msg);
 }
+
 /* Push a new message onto messages queue, event is:
   {t:"add",id:int, src,title,subject,body,sender,tel, important:bool, new:bool}
   {t:"add",id:int, id:"music", state, artist, track, etc} // add new
-  {t:"remove-",id:int} // remove
+  {t:"remove",id:int} // remove
   {t:"modify",id:int, title:string} // modified
 */
 exports.pushMessage = function(event) {
-  var messages, inApp = "undefined"!=typeof MESSAGES;
-  if (inApp)
-    messages = MESSAGES; // we're in an app that has already loaded messages
-  else   // no app - load messages
-    messages = require("Storage").readJSON("messages.json",1)||[];
   // now modify/delete as appropriate
-  var mIdx = messages.findIndex(m=>m.id==event.id);
-  if (event.t=="remove") {
-    if (mIdx>=0) messages.splice(mIdx, 1); // remove item
-    mIdx=-1;
+  if (event.t==="remove") {
+    if (event.id==="music") exports.music = {};
   } else { // add/modify
-    if (event.t=="add"){
-      if(event.new === undefined ) { // If 'new' has not been set yet, set it
-        event.new=true; // Assume it should be new
-      }
+    if (event.t==="add") {
+      if (event.new===undefined) event.new = true; // Assume it should be new
+    } else if (event.t==="modify") {
+      const old = exports.getMessages().find(m => m.id===event.id);
+      if (old) event = Object.assign(old, event);
     }
-    if (mIdx<0) {
-      mIdx=0;
-      messages.unshift(event); // add new messages to the beginning
-    }
-    else Object.assign(messages[mIdx], event);
-    if (event.id=="music" && messages[mIdx].state=="play") {
-      messages[mIdx].new = true; // new track, or playback (re)started
-    }
-  }
-  require("Storage").writeJSON("messages.json",messages);
-  // if in app, process immediately
-  if (inApp) return onMessagesModified(mIdx<0 ? {id:event.id} : messages[mIdx]);
-  // if we've removed the last new message, hide the widget
-  if (event.t=="remove" && !messages.some(m=>m.new)) {
-    if (global.WIDGETS && WIDGETS.messages) WIDGETS.messages.hide();
-    // if no new messages now, make sure we don't load the messages app
-    if (exports.messageTimeout && !messages.some(m=>m.new))
-      clearTimeout(exports.messageTimeout);
-  }
-  // ok, saved now
-  if (event.id=="music" && Bangle.CLOCK && messages[mIdx].new && openMusic()) {
-    // just load the app to display music: no buzzing
-    load("messages.app.js");
-  } else if (event.t!="add") {
-    // we only care if it's new
-    return;
-  } else if(event.new == false) {
-    return;
-  }
-  // otherwise load messages/show widget
-  var loadMessages = Bangle.CLOCK || event.important;
-  var quiet       = (require('Storage').readJSON('setting.json',1)||{}).quiet;
-  var appSettings = require('Storage').readJSON('messages.settings.json',1)||{};
-  var unlockWatch = appSettings.unlockWatch;
-  var quietNoAutOpn = appSettings.quietNoAutOpn;
-  delete appSettings;
-  // don't auto-open messages in quiet mode if quietNoAutOpn is true
-  if(quiet && quietNoAutOpn) {
-      loadMessages = false;
-  }
-  // first, buzz
-  if (!quiet && loadMessages && global.WIDGETS && WIDGETS.messages){
-      WIDGETS.messages.buzz();
-      if(unlockWatch != false){
-        Bangle.setLocked(false);
-        Bangle.setLCDPower(1); // turn screen on
-      }
-  }
-  // after a delay load the app, to ensure we have all the messages
-  if (exports.messageTimeout) clearTimeout(exports.messageTimeout);
-  exports.messageTimeout = setTimeout(function() {
-    exports.messageTimeout = undefined;
-    // if we're in a clock or it's important, go straight to messages app
-    if (loadMessages){
-      return load("messages.app.js");
-    }
-    if (!quiet && (!global.WIDGETS || !WIDGETS.messages)) return Bangle.buzz(); // no widgets - just buzz to let someone know
-    WIDGETS.messages.show();
-  }, 500);
-}
-/// Remove all messages
-exports.clearAll = function(event) {
-  var messages, inApp = "undefined"!=typeof MESSAGES;
-  if (inApp) {
-    MESSAGES = [];
-    messages = MESSAGES; // we're in an app that has already loaded messages
-  } else   // no app - empty messages
-    messages = [];
-  // Save all messages
-  require("Storage").writeJSON("messages.json",messages);
-  // update app if in app
-  if (inApp) return onMessagesModified();
-  // if we have a widget, update it
-  if (global.WIDGETS && WIDGETS.messages)
-    WIDGETS.messages.hide();
-}
 
-exports.getMessageImage = function(msg) {
-  /*
-  * icons should be 24x24px with 1bpp colors and 'Transparency to Color'
-  * http://www.espruino.com/Image+Converter
-  */
-  if (msg.img) return atob(msg.img);
-  var s = (msg.src||"").toLowerCase();
-  if (s=="alarm" || s =="alarmclockreceiver") return atob("GBjBAP////8AAAAAAAACAEAHAOAefng5/5wTgcgHAOAOGHAMGDAYGBgYGBgYGBgYGBgYDhgYBxgMATAOAHAHAOADgcAB/4AAfgAAAAAAAAA=");
-  if (s=="bibel") return atob("GBgBAAAAA//wD//4D//4H//4H/f4H/f4H+P4H4D4H4D4H/f4H/f4H/f4H/f4H/f4H//4H//4H//4GAAAEAAAEAAACAAAB//4AAAA");
-  if (s=="calendar") return atob("GBiBAAAAAAAAAAAAAA//8B//+BgAGBgAGBgAGB//+B//+B//+B9m2B//+B//+Btm2B//+B//+Btm+B//+B//+A//8AAAAAAAAAAAAA==");
-  if (s=="corona-warn") return atob("GBgBAAAAABwAAP+AAf/gA//wB/PwD/PgDzvAHzuAP8EAP8AAPAAAPMAAP8AAH8AAHzsADzuAB/PAB/PgA//wAP/gAH+AAAwAAAAA");
-  if (s=="discord") return atob("GBgBAAAAAAAAAAAAAIEABwDgDP8wH//4H//4P//8P//8P//8Pjx8fhh+fzz+f//+f//+e//ePH48HwD4AgBAAAAAAAAAAAAAAAAA");
-  if (s=="facebook" || s=="messenger") return atob("GBiBAAAAAAAAAAAYAAD/AAP/wAf/4A/48A/g8B/g+B/j+B/n+D/n/D8A/B8A+B+B+B/n+A/n8A/n8Afn4APnwADnAAAAAAAAAAAAAA==");
-  if (s=="google home") return atob("GBiCAAAAAAAAAAAAAAAAAAAAAoAAAAAACqAAAAAAKqwAAAAAqroAAAACquqAAAAKq+qgAAAqr/qoAACqv/6qAAKq//+qgA6r///qsAqr///6sAqv///6sAqv///6sAqv///6sA6v///6sA6v///qsA6qqqqqsA6qqqqqsA6qqqqqsAP7///vwAAAAAAAAAAAAAAAAA==");
-  if (s=="hangouts") return atob("FBaBAAH4AH/gD/8B//g//8P//H5n58Y+fGPnxj5+d+fmfj//4//8H//B//gH/4A/8AA+AAHAABgAAAA=");
-  if (s=="home assistant") return atob("FhaBAAAAAADAAAeAAD8AAf4AD/3AfP8D7fwft/D/P8ec572zbzbNsOEhw+AfD8D8P4fw/z/D/P8P8/w/z/AAAAA=");
-  if (s=="instagram") return atob("GBiBAAAAAAAAAAAAAAAAAAP/wAYAYAwAMAgAkAh+EAjDEAiBEAiBEAiBEAiBEAjDEAh+EAgAEAwAMAYAYAP/wAAAAAAAAAAAAAAAAA==");
-  if (s=="kalender") return atob("GBgBBgBgBQCgff++RQCiRgBiQAACf//+QAACQAACR//iRJkiRIEiR//iRNsiRIEiRJkiR//iRIEiRIEiR//iQAACQAACf//+AAAA");
-  if (s=="lieferando") return atob("GBgBABgAAH5wAP9wAf/4A//4B//4D//4H//4P/88fV8+fV4//V4//Vw/HVw4HVw4HBg4HBg4HBg4HDg4Hjw4Hj84Hj44Hj44Hj44");
-  if (s=="nina") return atob("GBgBAAAABAAQCAAICAAIEAAEEgAkJAgSJBwSKRxKSj4pUn8lVP+VVP+VUgAlSgApKQBKJAASJAASEgAkEAAECAAICAAIBAAQAAAA");
-  if (s=="outlook mail") return atob("HBwBAAAAAAAAAAAIAAAfwAAP/gAB/+AAP/5/A//v/D/+/8P/7/g+Pv8Dye/gPd74w5znHDnOB8Oc4Pw8nv/Dwe/8Pj7/w//v/D/+/8P/7/gf/gAA/+AAAfwAAACAAAAAAAAAAAA=");
-  if (s=="phone") return atob("FxeBABgAAPgAAfAAB/AAD+AAH+AAP8AAP4AAfgAA/AAA+AAA+AAA+AAB+AAB+AAB+OAB//AB//gB//gA//AA/8AAf4AAPAA=");
-  if (s=="post & dhl") return atob("GBgBAPgAE/5wMwZ8NgN8NgP4NgP4HgP4HgPwDwfgD//AB/+AAf8AAAAABs7AHcdgG4MwAAAAGESAFESAEkSAEnyAEkSAFESAGETw");
-  if (s=="signal") return atob("GBgBAAAAAGwAAQGAAhggCP8QE//AB//oJ//kL//wD//0D//wT//wD//wL//0J//kB//oA//ICf8ABfxgBYBAADoABMAABAAAAAAA");
-  if (s=="skype") return atob("GhoBB8AAB//AA//+Af//wH//+D///w/8D+P8Afz/DD8/j4/H4fP5/A/+f4B/n/gP5//B+fj8fj4/H8+DB/PwA/x/A/8P///B///gP//4B//8AD/+AAA+AA==");
-  if (s=="slack") return atob("GBiBAAAAAAAAAABAAAHvAAHvAADvAAAPAB/PMB/veD/veB/mcAAAABzH8B3v+B3v+B3n8AHgAAHuAAHvAAHvAADGAAAAAAAAAAAAAA==");
-  if (s=="snapchat") return atob("GBgBAAAAAAAAAH4AAf+AAf+AA//AA//AA//AA//AA//AH//4D//wB//gA//AB//gD//wH//4f//+P//8D//wAf+AAH4AAAAAAAAA");
-  if (s=="teams") return atob("GBgBAAAAAAAAAAQAAB4AAD8IAA8cP/M+f/scf/gIeDgAfvvefvvffvvffvvffvvff/vff/veP/PeAA/cAH/AAD+AAD8AAAQAAAAA");
-  if (s=="telegram" || s=="telegram foss") return atob("GBiBAAAAAAAAAAAAAAAAAwAAHwAA/wAD/wAf3gD/Pgf+fh/4/v/z/P/H/D8P/Acf/AM//AF/+AF/+AH/+ADz+ADh+ADAcAAAMAAAAA==");
-  if (s=="threema") return atob("GBjB/4Yx//8AAAAAAAAAAAAAfgAB/4AD/8AH/+AH/+AP//AP2/APw/APw/AHw+AH/+AH/8AH/4AH/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=");
-  if (s=="to do") return atob("GBgBAAAAAAAAAAAwAAB4AAD8AAH+AAP/DAf/Hg//Px/+f7/8///4///wf//gP//AH/+AD/8AB/4AA/wAAfgAAPAAAGAAAAAAAAAA");
-  if (s=="twitch") return atob("GBgBH//+P//+P//+eAAGeAAGeAAGeDGGeDOGeDOGeDOGeDOGeDOGeDOGeAAOeAAOeAAcf4/4f5/wf7/gf//Af/+AA/AAA+AAAcAA");
-  if (s=="twitter") return atob("GhYBAABgAAB+JgA/8cAf/ngH/5+B/8P8f+D///h///4f//+D///g///wD//8B//+AP//gD//wAP/8AB/+AB/+AH//AAf/AAAYAAA");
-  if (s=="whatsapp") return atob("GBiBAAB+AAP/wAf/4A//8B//+D///H9//n5//nw//vw///x///5///4///8e//+EP3/APn/wPn/+/j///H//+H//8H//4H//wMB+AA==");
-  if (s=="wordfeud") return atob("GBgCWqqqqqqlf//////9v//////+v/////++v/////++v8///Lu+v8///L++v8///P/+v8v//P/+v9v//P/+v+fx/P/+v+Pk+P/+v/PN+f/+v/POuv/+v/Ofdv/+v/NvM//+v/I/Y//+v/k/k//+v/i/w//+v/7/6//+v//////+v//////+f//////9Wqqqqqql");
-  if (s=="youtube") return atob("GBgBAAAAAAAAAAAAAAAAAf8AH//4P//4P//8P//8P5/8P4/8f4P8f4P8P4/8P5/8P//8P//8P//4H//4Af8AAAAAAAAAAAAAAAAA");
-  if (msg.id=="music") return atob("FhaBAH//+/////////////h/+AH/4Af/gB/+H3/7/f/v9/+/3/7+f/vB/w8H+Dwf4PD/x/////////////3//+A=");
-  // if (s=="sms message" || s=="mail" || s=="gmail") // .. default icon (below)
-  return atob("HBKBAD///8H///iP//8cf//j4//8f5//j/x/8//j/H//H4//4PB//EYj/44HH/Hw+P4//8fH//44///xH///g////A==");
+    // combine musicinfo and musicstate events
+    if (event.id==="music") {
+      if (event.state==="play") event.new = true; // new track, or playback (re)started
+      event = Object.assign(exports.music, event);
+    }
+  }
+  // reset state (just in case)
+  delete event.handled;
+  delete event.saved;
+  emit(event);
 };
 
-exports.getMessageImageCol = function(msg,def) {
-  return {
-    // generic colors, using B2-safe colors
-    "alarm": "#fff",
-    "mail": "#ff0",
-    "music": "#f0f",
-    "phone": "#0f0",
-    "sms message": "#0ff",
-    // brands, according to https://www.schemecolor.com/?s (picking one for multicolored logos)
-    // all dithered on B2, but we only use the color for the icons.  (Could maybe pick the closest 3-bit color for B2?)
-    "bibel": "#54342c",
-    "discord": "#738adb",
-    "facebook": "#4267b2",
-    "gmail": "#ea4335",
-    "google home": "#fbbc05",
-    "hangouts": "#1ba261",
-    "home assistant": "#fff", // ha-blue is #41bdf5, but that's the background
-    "instagram": "#dd2a7b",
-    "liferando": "#ee5c00",
-    "messenger": "#0078ff",
-    "nina": "#e57004",
-    "outlook mail": "#0072c6",
-    "post & dhl": "#f2c101",
-    "signal": "#00f",
-    "skype": "#00aff0",
-    "slack": "#e51670",
-    "snapchat": "#ff0",
-    "teams": "#464eb8",
-    "telegram": "#0088cc",
-    "telegram foss": "#0088cc",
-    "threema": "#000",
-    "to do": "#3999e5",
-    "twitch": "#6441A4",
-    "twitter": "#1da1f2",
-    "whatsapp": "#4fce5d",
-    "wordfeud": "#e7d3c7",
-    "youtube": "#f00",
-  }[(msg.src||"").toLowerCase()]||(def !== undefined?def:g.theme.fg);
+/**
+ * Save a single message to flash
+ * Also sets msg.saved=true
+ *
+ * @param {object} msg
+ * @param {object} [options={}] Options:
+ *                 {boolean} [force=false] Force save even if msg.saved is already set
+ */
+exports.save = function(msg, options) {
+  if (!options) options = {};
+  if (msg.saved && !options.force) return; //already saved
+  let messages = exports.getMessages();
+  exports.apply(msg, messages);
+  exports.write(messages);
+  msg.saved = true;
+};
+
+/**
+ * Apply incoming event to array of messages
+ *
+ * @param {object} event Event to apply
+ * @param {array} messages Array of messages, *will be modified in-place*
+ * @return {array} Modified messages array
+ */
+exports.apply = function(event, messages) {
+  if (!event || !event.id) return messages;
+  const mIdx = messages.findIndex(m => m.id===event.id);
+  if (event.t==="remove") {
+    if (mIdx<0) return messages; // already gone -> nothing to do
+    messages.splice(mIdx, 1);
+  } else if (event.t==="add") {
+    if (mIdx>=0) messages.splice(mIdx, 1); // duplicate ID! erase previous version
+    messages.unshift(event); // add at the beginning
+  } else if (event.t==="modify") {
+    if (mIdx>=0) messages[mIdx] = Object.assign(messages[mIdx], event);
+    else messages.unshift(event);
+  }
+  return messages;
+};
+
+/**
+ * Accept a call (or other acceptable event)
+ * @param {object} msg
+ */
+exports.accept = function(msg) {
+  if (msg.positive) Bangle.messageResponse(msg, true);
+};
+
+/**
+ * Dismiss a message (if applicable), and erase it from flash
+ * Emits a "message" event with t="remove", only if message existed
+ *
+ * @param {object} msg
+ */
+exports.dismiss = function(msg) {
+  if (msg.negative) Bangle.messageResponse(msg, false);
+  let messages = exports.getMessages();
+  const mIdx = messages.findIndex(m=>m.id===msg.id);
+  if (mIdx<0) return;
+  messages.splice(mIdx, 1);
+  exports.write(messages);
+  if (msg.t==="remove") return; // already removed, don't re-emit
+  msg.t = "remove";
+  emit(msg); // emit t="remove", so e.g. widgets know to update
+};
+
+/**
+ * Emit a "type=openGUI" event, to open GUI app
+ *
+ * @param {object} [msg={}] Message the app should show
+ */
+exports.openGUI = function(msg) {
+  if (!require("Storage").read("messagegui")) return; // "messagegui" module is missing!
+  // Mark the event as unhandled for GUI, but leave passed arguments intact
+  let copy = Object.assign({}, msg);
+  delete copy.handled;
+  require("messagegui").open(copy);
+};
+
+/**
+ * Show/hide the messages widget
+ *
+ * @param {boolean} show
+ */
+exports.toggleWidget = function(show) {
+  if (!global.WIDGETS || !WIDGETS["messages"]) return; // widget is missing!
+  const method = WIDGETS["messages"][show ? "show" : "hide"];
+  /* if (typeof(method)!=="function") return; // widget must always have show()+hide(), fail hard rather than hide problems */
+  method.apply(WIDGETS["messages"]);
+};
+
+/**
+ * Replace all stored messages
+ * @param {array} messages Messages to save
+ */
+exports.write = function(messages) {
+  if (!messages.length) require("Storage").erase("messages.json");
+  else require("Storage").writeJSON("messages.json", messages.map(m => {
+    // we never want to save saved/handled status to file;
+    delete m.saved;
+    delete m.handled;
+    return m;
+  }));
+};
+/**
+ * Erase all messages
+ */
+exports.clearAll = function() {
+  exports.write([]);
+  Bangle.emit("message", "clearAll", {});
+}
+
+/**
+ * Get saved messages
+ *
+ * Optionally pass in a message to apply to the list, this is for event handlers:
+ * By passing the message from the event, you can make sure the list is up-to-date,
+ * even if the message has not been saved (yet)
+ *
+ * Example:
+ *     Bangle.on("message", (type, msg) =>  {
+ *       console.log("All messages:", require("messages").getMessages(msg));
+ *     });
+ *
+ * @param {object} [withMessage] Apply this event to messages
+ * @returns {array} All messages
+ */
+exports.getMessages = function(withMessage) {
+  let messages = require("Storage").readJSON("messages.json", true);
+  messages = Array.isArray(messages) ? messages : []; // make sure we always return an array
+  if (withMessage && withMessage.id) exports.apply(withMessage, messages);
+  return messages;
+};
+
+/**
+ * Check if there are any messages
+ *
+ * @param {object} [withMessage] Apply this event to messages, see getMessages
+ * @returns {string} "new"/"old"/"none"
+ */
+exports.status = function(withMessage) {
+  try {
+    let status = "none";
+    for(const m of exports.getMessages(withMessage)) {
+      if (["music", "map"].includes(m.id)) continue;
+      if (m.new) return "new";
+      status = "old";
+    }
+    return status;
+  } catch(e) {
+    return "none"; // don't bother callers with errors
+  }
+};
+
+/**
+ * Start buzzing for new message
+ * @param {string} msgSrc Message src to buzz for
+ * @return {Promise} Resolves when initial buzz finishes (there might be repeat buzzes later)
+ */
+exports.buzz = function(msgSrc) {
+  exports.stopBuzz(); // cancel any previous buzz timeouts
+  if ((require("Storage").readJSON("setting.json", 1) || {}).quiet) return Promise.resolve(); // never buzz during Quiet Mode
+  const msgSettings = require("Storage").readJSON("messages.settings.json", true) || {};
+  let pattern;
+  if (msgSrc && msgSrc.toLowerCase()==="phone") {
+    // special vibration pattern for incoming calls
+    pattern = msgSettings.vibrateCalls;
+  } else {
+    pattern = msgSettings.vibrate;
+  }
+  if (pattern===undefined) { pattern = ":"; } // pattern may be "", so we can't use || ":" here
+  if (!pattern) return Promise.resolve();
+
+  let repeat = msgSettings.repeat;
+  if (repeat===undefined) repeat = 4; // repeat may be zero
+  if (repeat) {
+    exports.buzzTimeout = setTimeout(() => require("buzz").pattern(pattern), repeat*1000);
+    let vibrateTimeout = msgSettings.vibrateTimeout;
+    if (vibrateTimeout===undefined) vibrateTimeout = 60;
+    if (vibrateTimeout && !exports.stopTimeout) exports.stopTimeout = setTimeout(exports.stopBuzz, vibrateTimeout*1000);
+  }
+  return require("buzz").pattern(pattern);
+};
+/**
+ * Stop buzzing
+ */
+exports.stopBuzz = function() {
+  if (exports.buzzTimeout) clearTimeout(exports.buzzTimeout);
+  delete exports.buzzTimeout;
+  if (exports.stopTimeout) clearTimeout(exports.stopTimeout);
+  delete exports.stopTimeout;
 };
diff --git a/apps/messages/metadata.json b/apps/messages/metadata.json
index b30d31705..9c7c8b49e 100644
--- a/apps/messages/metadata.json
+++ b/apps/messages/metadata.json
@@ -1,21 +1,22 @@
 {
   "id": "messages",
   "name": "Messages",
-  "version": "0.40",
-  "description": "App to display notifications from iOS and Gadgetbridge/Android",
+  "version": "0.58",
+  "description": "Library to handle, load and store message events received from Android/iOS",
   "icon": "app.png",
-  "type": "app",
+  "type": "module",
   "tags": "tool,system",
   "supports": ["BANGLEJS","BANGLEJS2"],
+  "provides_modules" : ["messages"],
+  "dependencies" : {
+    "messagegui":"module",
+    "message":"widget"
+  },
+  "default": true,
   "readme": "README.md",
   "storage": [
-    {"name":"messages.app.js","url":"app.js"},
-    {"name":"messages.settings.js","url":"settings.js"},
-    {"name":"messages.img","url":"app-icon.js","evaluate":true},
-    {"name":"messages.wid.js","url":"widget.js"},
-    {"name":"messages","url":"lib.js"}
+    {"name":"messages","url":"lib.js"},
+    {"name":"messages.settings.js","url":"settings.js"}
   ],
-  "data": [{"name":"messages.json"},{"name":"messages.settings.json"}],
-  "screenshots": [{"url":"screenshot.png"},{"url":"screenshot-notify.gif"}],
-  "sortorder": -9
+  "data": [{"name":"messages.json"},{"name":"messages.settings.json"}]
 }
diff --git a/apps/messages/screenshot-notify.gif b/apps/messages/screenshot-notify.gif
deleted file mode 100644
index 3d0ed0b32..000000000
Binary files a/apps/messages/screenshot-notify.gif and /dev/null differ
diff --git a/apps/messages/settings.js b/apps/messages/settings.js
index b708213be..09c9db455 100644
--- a/apps/messages/settings.js
+++ b/apps/messages/settings.js
@@ -1,9 +1,15 @@
 (function(back) {
+  const iconColorModes = ['color', 'mono'];
+
   function settings() {
     let settings = require('Storage').readJSON("messages.settings.json", true) || {};
     if (settings.vibrate===undefined) settings.vibrate=":";
+    if (settings.vibrateCalls===undefined) settings.vibrateCalls=":";
     if (settings.repeat===undefined) settings.repeat=4;
+    if (settings.vibrateTimeout===undefined) settings.vibrateTimeout=60;
     if (settings.unreadTimeout===undefined) settings.unreadTimeout=60;
+    if (settings.maxMessages===undefined) settings.maxMessages=3;
+    if (settings.iconColorMode === undefined) settings.iconColorMode = iconColorModes[0];
     settings.unlockWatch=!!settings.unlockWatch;
     settings.openMusic=!!settings.openMusic;
     settings.maxUnreadTimeout=240;
@@ -20,12 +26,19 @@
     "" : { "title" : /*LANG*/"Messages" },
     "< Back" : back,
     /*LANG*/'Vibrate': require("buzz_menu").pattern(settings().vibrate, v => updateSetting("vibrate", v)),
+    /*LANG*/'Vibrate for calls': require("buzz_menu").pattern(settings().vibrateCalls, v => updateSetting("vibrateCalls", v)),
     /*LANG*/'Repeat': {
       value: settings().repeat,
       min: 0, max: 10,
       format: v => v?v+"s":/*LANG*/"Off",
       onchange: v => updateSetting("repeat", v)
     },
+    /*LANG*/'Vibrate timer': {
+      value: settings().vibrateTimeout,
+      min: 0, max: settings().maxUnreadTimeout, step : 10,
+      format: v => v?v+"s":/*LANG*/"Off",
+      onchange: v => updateSetting("vibrateTimeout", v)
+    },
     /*LANG*/'Unread timer': {
       value: settings().unreadTimeout,
       min: 0, max: settings().maxUnreadTimeout, step : 10,
@@ -54,6 +67,22 @@
       value: !!settings().quietNoAutOpn,
       onchange: v => updateSetting("quietNoAutOpn", v)
     },
+    /*LANG*/'Disable auto-open': {
+      value: !!settings().noAutOpn,
+      onchange: v => updateSetting("noAutOpn", v)
+    },
+    /*LANG*/'Widget messages': {
+      value:0|settings().maxMessages,
+      min: 0, max: 5,
+      format: v => v ? v :/*LANG*/"Hide",
+      onchange: v => updateSetting("maxMessages", v)
+    },
+    /*LANG*/'Icon color mode': {
+      value: Math.max(0,iconColorModes.indexOf(settings().iconColorMode)),
+      min: 0, max: iconColorModes.length - 1,
+      format: v => iconColorModes[v],
+      onchange: v => updateSetting("iconColorMode", iconColorModes[v])
+    }
   };
   E.showMenu(mainmenu);
-})
+});
diff --git a/apps/messages/widget.js b/apps/messages/widget.js
deleted file mode 100644
index 25573220f..000000000
--- a/apps/messages/widget.js
+++ /dev/null
@@ -1,49 +0,0 @@
-WIDGETS["messages"]={area:"tl", width:0, iconwidth:24,
-draw:function(recall) {
-  // If we had a setTimeout queued from the last time we were called, remove it
-  if (WIDGETS["messages"].i) {
-    clearTimeout(WIDGETS["messages"].i);
-    delete WIDGETS["messages"].i;
-  }
-  Bangle.removeListener('touch', this.touch);
-  if (!this.width) return;
-  var c = (Date.now()-this.t)/1000;
-  let settings = require('Storage').readJSON("messages.settings.json", true) || {};
-  if (settings.flash===undefined) settings.flash = true;
-  if (recall !== true || settings.flash) {
-    g.reset().clearRect(this.x, this.y, this.x+this.width, this.y+23);
-    g.drawImage(settings.flash && (c&1) ? atob("GBiBAAAAAAAAAAAAAAAAAAAAAB//+DAADDAADDAADDwAPD8A/DOBzDDn/DA//DAHvDAPvjAPvjAPvjAPvh///gf/vAAD+AAB8AAAAA==") : atob("GBiBAAAAAAAAAAAAAAAAAAAAAB//+D///D///A//8CP/xDj/HD48DD+B8D/D+D/3vD/vvj/vvj/vvj/vvh/v/gfnvAAD+AAB8AAAAA=="), this.x, this.y-1);
-  }
-  if (settings.repeat===undefined) settings.repeat = 4;
-  if (c<120 && (Date.now()-this.l)>settings.repeat*1000) {
-    this.l = Date.now();
-    WIDGETS["messages"].buzz(); // buzz every 4 seconds
-  }
-  WIDGETS["messages"].i=setTimeout(()=>WIDGETS["messages"].draw(true), 1000);
-  if (process.env.HWVERSION>1) Bangle.on('touch', this.touch);
-},show:function(quiet) {
-  WIDGETS["messages"].t=Date.now(); // first time
-  WIDGETS["messages"].l=Date.now()-10000; // last buzz
-  if (quiet) WIDGETS["messages"].t -= 500000; // if quiet, set last time in the past so there is no buzzing
-  WIDGETS["messages"].width=this.iconwidth;
-  Bangle.drawWidgets();
-},hide:function() {
-  delete WIDGETS["messages"].t;
-  delete WIDGETS["messages"].l;
-  WIDGETS["messages"].width=0;
-  Bangle.drawWidgets();
-},buzz:function() {
-  if ((require('Storage').readJSON('setting.json',1)||{}).quiet) return; // never buzz during Quiet Mode
-  require("buzz").pattern((require('Storage').readJSON("messages.settings.json", true) || {}).vibrate || ":");
-},touch:function(b,c) {
-  var w=WIDGETS["messages"];
-  if (!w||!w.width||c.xw.x+w.width||c.yw.y+w.iconwidth) return;
-  load("messages.app.js");
-}};
-/* We might have returned here if we were in the Messages app for a
-message but then the watch was never viewed. In that case we don't
-want to buzz but should still show that there are unread messages. */
-if (global.MESSAGES===undefined) (function() {
-  var messages = require("Storage").readJSON("messages.json",1)||[];
-  if (messages.some(m=>m.new&&m.id!="music")) WIDGETS["messages"].show(true);
-})();
diff --git a/apps/messages_light/ChangeLog b/apps/messages_light/ChangeLog
new file mode 100644
index 000000000..328e2a120
--- /dev/null
+++ b/apps/messages_light/ChangeLog
@@ -0,0 +1,7 @@
+1.0: New App!
+1.1: fix app opening when a remove notification arrives
+1.2: message_light overrides require() by sending requests to "message" to a proxy library which overrides pushMessage
+    settings now points to message settings
+    implemented use of the "messageicons" library
+    removed lib no longer used
+1.3: icon changed
\ No newline at end of file
diff --git a/apps/messages_light/README.md b/apps/messages_light/README.md
new file mode 100644
index 000000000..00fe39bd0
--- /dev/null
+++ b/apps/messages_light/README.md
@@ -0,0 +1,11 @@
+# Messages app
+
+This app handles the display of messages and message notifications. 
+
+It is a GUI replacement for the  `messages` apps.
+
+
+## Creator
+
+Rarder44
+
diff --git a/apps/messages_light/app-icon.js b/apps/messages_light/app-icon.js
new file mode 100644
index 000000000..7d1da35c9
--- /dev/null
+++ b/apps/messages_light/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEw4UA/4ACBIMQwhL/ABMBqoAEoALDioLFqgLDBQoABERIkEBZcFBY9QBYVe1QAB1YLGrSlC/YLGrYHCr4Lrr9drpLC1oLEAAN5rxKB/ILHEYV5EY4LIHYoLorRaBqoPCBYlfUoXrBYwGBrdeDIILIvXVBZFa1I+CBY/5BZIHBBwOq1ILGrXVvf//oLGq+trLLFBYVVvQxCBY9XJIQLCgILDHoVVoALHAAQLCgALHBQUAioKFqgLDEgwiDAH4AGA"))
\ No newline at end of file
diff --git a/apps/messages_light/app-icon.png b/apps/messages_light/app-icon.png
new file mode 100644
index 000000000..c9b4b62ac
Binary files /dev/null and b/apps/messages_light/app-icon.png differ
diff --git a/apps/messages_light/app.png b/apps/messages_light/app.png
new file mode 100644
index 000000000..1f738504d
Binary files /dev/null and b/apps/messages_light/app.png differ
diff --git a/apps/messages_light/full-size-app.png b/apps/messages_light/full-size-app.png
new file mode 100644
index 000000000..2df7915ed
Binary files /dev/null and b/apps/messages_light/full-size-app.png differ
diff --git a/apps/messages_light/messages_light.app.js b/apps/messages_light/messages_light.app.js
new file mode 100644
index 000000000..5d5363d38
--- /dev/null
+++ b/apps/messages_light/messages_light.app.js
@@ -0,0 +1,496 @@
+/* MESSAGES is a list of:
+  {id:int,
+    src,
+    title,
+    subject,
+    body,
+    sender,
+    tel:string,
+    new:true // not read yet
+  }
+*/
+
+let LOG=function(){  
+  //print.apply(null, arguments);
+}
+
+
+
+
+let settings= (()=>{
+  let tmp={};
+  tmp.NewEventFileName="messages_light.NewEvent.json";
+
+  tmp.fontSmall = "6x8";
+  tmp.fontMedium = g.getFonts().includes("Vector")?"Vector:16":"6x8:2";
+  tmp.fontBig = g.getFonts().includes("12x20")?"12x20":"6x8:2";
+  tmp.fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4";
+  
+  
+  tmp.colHeadBg = g.theme.dark ? "#141":"#4f4";
+  tmp.colBg = g.theme.dark ? "#000":"#fff";
+  tmp.colLock = g.theme.dark ? "#ff0000":"#ff0000";
+
+  tmp.quiet=((require('Storage').readJSON('setting.json', 1) || {}).quiet)
+
+  return tmp;
+})();
+let EventQueue=[];    //in posizione 0, c'è quello attualmente visualizzato
+let callInProgress=false;
+
+
+
+
+//TODO: RICORDARSI DI FARE IL DELETE
+var manageEvent = function(event) {
+
+  event.new=true;
+
+
+  LOG("manageEvent");
+  if( event.id=="call")
+  {
+    showCall(event);
+    return;
+  }
+  switch(event.t)
+  {
+    case "add":
+      EventQueue.unshift(event);
+
+      if(!callInProgress)
+        showMessage(event);
+    break;
+
+    case "modify":
+      //cerco l'evento nella lista, se lo trovo, lo modifico, altrimenti lo pusho
+      let find=false;
+      EventQueue.forEach(element => {
+        if(element.id == event.id)
+        {
+          find=true;
+          Object.assign(element,event);
+        }
+      });
+      if(!find)   //se non l'ho trovato, lo aggiungo in fondo
+        EventQueue.unshift(event);
+
+      if(!callInProgress)
+        showMessage(event);
+      break;
+
+    case "remove":
+      
+      //se non c'è niente nella queue e non c'è una chiamata in corso
+      if( EventQueue.length==0 && !callInProgress)
+        next();
+
+      //se l'id è uguale a quello attualmente visualizzato  ( e non siamo in chiamata ) 
+      if(!callInProgress &&  EventQueue[0] !== undefined && EventQueue[0].id == event.id)
+        next();   //passo al messaggio successivo ( per la rimozione ci penserà la next ) 
+
+      else{
+        //altrimenti rimuovo tutti gli elementi con quell'id( creando un nuovo array )
+        let newEventQueue=[];
+        EventQueue.forEach(element => {
+          if(element.id != event.id)
+            newEventQueue.push(element);
+        });
+        EventQueue=newEventQueue;
+      }
+      
+      
+
+      
+      break;
+    case "musicstate":
+    case "musicinfo":
+        
+        break;
+  }
+};
+
+
+
+
+
+
+let showMessage = function(msg){
+  LOG("showMessage");
+  LOG(msg);
+  g.setBgColor(settings.colBg);
+
+
+  if(typeof msg.CanScrollDown==="undefined")
+    msg.CanScrollDown=false;
+  if(typeof msg.CanScrollUp==="undefined")
+    msg.CanScrollUp=false;
+
+
+
+
+
+  // Normal text message display
+  let title=msg.title, titleFont = settings.fontLarge, lines;
+  if (title) {
+    let w = g.getWidth()-48;
+    if (g.setFont(titleFont).stringWidth(title) > w)
+      titleFont = settings.fontMedium;
+    if (g.setFont(titleFont).stringWidth(title) > w) {
+      lines = g.wrapString(title, w);
+      title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n");
+    }
+  }
+  
+
+ 
+  let Layout = require("Layout");
+  layout = new Layout({ type:"v", c: [
+    {type:"h", fillx:1, bgCol:settings.colHeadBg,  c: [
+      { type:"btn", src:require("messageicons").getImage(msg), col:require("messageicons").getColor(msg), pad: 3},
+      { type:"v", fillx:1, c: [
+        {type:"txt", font:settings.fontSmall, label:msg.src||/*LANG*/"Message", bgCol:settings.colHeadBg, fillx:1, pad:2, halign:1 },
+        title?{type:"txt", font:titleFont, label:title, bgCol:settings.colHeadBg, fillx:1, pad:2 }:{},
+      ]},
+    ]},
+    {type:"v",fillx:1,filly:1,pad:2 ,halign:-1,c:[]},
+
+   
+   
+    
+  ]});
+ 
+
+  if (!settings.quiet && msg.new)
+  {
+    msg.new=false;
+    Bangle.buzz();
+  }
+    
+
+  g.clearRect(Bangle.appRect);
+  layout.render();
+
+  PrintMessageStrings(msg);
+  Bangle.setLCDPower(1);
+
+  DrawLock();
+
+};
+let DrawLock=function()
+{
+  let w=8,h=8;
+  let x = g.getWidth()-w;
+  let y = 0;
+  if(Bangle.isLocked())
+    g.setBgColor(settings.colLock);
+  else
+    g.setBgColor(settings.colHeadBg);
+  g.clearRect(x,y,x+w,y+h);
+};
+
+
+
+
+
+
+let showCall = function(msg)
+{
+  LOG("showCall");
+  LOG(msg);
+  // se anche prima era una call    PrevMessage==msg.id 
+  //non so perchè prima era cosi
+  if( msg.t=="remove")
+  {
+    LOG("hide call screen");
+    next();    //dont shift
+    return;
+  }
+
+  callInProgress=true;
+
+
+
+  //se è una chiamata ( o una nuova chiamata, diversa dalla precedente )
+  //la visualizzo
+  
+  let title=msg.title, titleFont = settings.fontLarge, lines;
+  if (title) {
+    let w = g.getWidth()-48;
+    if (g.setFont(titleFont).stringWidth(title) > w)
+      titleFont = settings.fontMedium;
+    if (g.setFont(titleFont).stringWidth(title) > w) {
+      lines = g.wrapString(title, w);
+      title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n");
+    }
+  }
+  let Layout = require("Layout");
+  layout = new Layout({ type:"v", c: [
+    {type:"h", fillx:1, bgCol:settings.colHeadBg,  c: [
+      { type:"btn", src:require("messageicons").getImage(msg), col:require("messageicons").getColor(msg), pad: 3},
+      { type:"v", fillx:1, c: [
+        {type:"txt", font:settings.fontSmall, label:msg.src||/*LANG*/"Message", bgCol:settings.colHeadBg, fillx:1, pad:2, halign:1 },
+        title?{type:"txt", font:titleFont, label:title, bgCol:settings.colHeadBg, fillx:1, pad:2 }:{},
+      ]},
+    ]},
+    {type:"txt", font:settings.fontMedium, label:msg.body,  fillx:1,filly:1,pad:2 ,halign:0}   
+  ]});
+
+
+  StopBuzzCall();
+  if (  !settings.quiet  ) {
+    if(msg.new)
+    {
+      msg.new=false;
+      CallBuzzTimer = setInterval(function() {
+          Bangle.buzz(500);
+      }, 1000);
+      
+      Bangle.buzz(500);
+    }
+  }
+  g.clearRect(Bangle.appRect);
+  layout.render();
+  PrintMessageStrings(msg);
+  Bangle.setLCDPower(1);
+  DrawLock();
+};
+
+
+
+
+
+
+
+
+  
+let next=function(){
+  LOG("next");
+  StopBuzzCall();
+  
+
+  //se c'è una chiamata, non shifto
+  if(!callInProgress)
+    EventQueue.shift();    //passa al messaggio successivo, se presente - tolgo il primo
+
+  callInProgress=false; 
+  if( EventQueue.length == 0)
+  {
+    LOG("no element in queue - closing")
+    setTimeout(_ => load());
+    return;
+  }
+
+  
+  showMessage(EventQueue[0]);
+
+};
+
+
+
+
+
+
+
+
+
+
+
+let showMapMessage=function(msg) {
+
+  g.clearRect(Bangle.appRect);
+  PrintMessageStrings({body:"Not implemented!"});
+
+}
+
+
+
+
+
+let CallBuzzTimer=null;
+let StopBuzzCall=function()
+{
+  if (CallBuzzTimer){
+    clearInterval(CallBuzzTimer);
+    CallBuzzTimer=null;
+  }
+}
+let DrawTriangleUp=function()
+{
+  g.fillPoly([169,46,164,56,174,56]);
+}
+let DrawTriangleDown=function()
+{
+  g.fillPoly([169,170,164,160,174,160]);
+}
+
+
+
+
+let ScrollUp=function()
+{
+  msg= EventQueue[0];
+
+  if(typeof msg.FirstLine==="undefined")
+    msg.FirstLine=0;
+  if(typeof msg.CanScrollUp==="undefined")
+    msg.CanScrollUp=false;
+
+  if(!msg.CanScrollUp) return;
+  
+  msg.FirstLine = msg.FirstLine>0?msg.FirstLine-1:0;
+
+  PrintMessageStrings(msg);
+}
+let ScrollDown=function()
+{
+  msg= EventQueue[0];
+  if(typeof msg.FirstLine==="undefined")
+    msg.FirstLine=0;
+  if(typeof msg.CanScrollDown==="undefined")
+    msg.CanScrollDown=false;
+
+  if(!msg.CanScrollDown) return;
+  
+  msg.FirstLine = msg.FirstLine+1;
+  PrintMessageStrings(msg);
+}
+
+
+
+
+
+
+let PrintMessageStrings=function(msg)
+{
+  let MyWrapString = function (str,maxWidth)
+  {
+    str=str.replace("\r\n","\n").replace("\r","\n");
+    return g.wrapString(str,maxWidth);
+  }
+
+
+  if(typeof msg.FirstLine==="undefined")  msg.FirstLine=0;
+
+  let bodyFont = typeof msg.bodyFont==="undefined"? settings.fontMedium : msg.bodyFont;
+  let Padding=2;
+  if(typeof msg.lines==="undefined")
+  {
+    g.setFont(bodyFont);
+    msg.lines = MyWrapString(msg.body,g.getWidth()-(Padding*2))
+    if ( msg.lines.length<=2)
+    {
+      bodyFont=  g.getFonts().includes("Vector")?"Vector:20":"6x8:3";
+      g.setFont(bodyFont);
+      msg.lines = MyWrapString(msg.body,g.getWidth()-(Padding*2))
+      msg.bodyFont = bodyFont;
+    }
+  }
+
+  
+
+  //prendo le linee da stampare
+  let NumLines=8;
+  let linesToPrint = (msg.lines.length>NumLines) ? msg.lines.slice(msg.FirstLine,msg.FirstLine+NumLines):msg.lines;
+  
+    
+  let yText=45;
+  
+  //invalido l'area e disegno il testo
+  g.setBgColor(settings.colBg);
+  g.clearRect(0,yText,176,176);
+  let xText=Padding;
+  yText+=Padding;
+  g.setFont(bodyFont);
+  let HText=g.getFontHeight();
+
+  yText=((176-yText)/2)-(linesToPrint.length * HText / 2) + yText;
+
+  if( linesToPrint.length<=2)
+  {
+    g.setFontAlign(0,-1);
+    xText = g.getWidth()/2;
+  }
+  else
+    g.setFontAlign(-1,-1);
+
+  
+  linesToPrint.forEach((line, i)=>{
+    g.drawString(line,xText,yText+HText*i);
+  });
+
+  //disegno le freccie
+  if(msg.FirstLine!=0)
+  {
+    msg.CanScrollUp=true;
+    DrawTriangleUp();
+  }
+  else
+    msg.CanScrollUp=false;
+
+  if(msg.FirstLine+linesToPrint.length < msg.lines.length)
+  {
+    msg.CanScrollDown=true;
+    DrawTriangleDown();
+  }
+  else
+    msg.CanScrollDown=false;
+
+
+}
+
+
+
+
+let doubleTapUnlock=function(data) {
+  if( data.double)  //solo se in double
+  {
+    Bangle.setLocked(false);
+    Bangle.setLCDPower(1);
+  }
+}
+let toushScroll=function(button, xy) { 
+  let height=176; //g.getHeight(); -> 176 B2
+  height/=2;
+  
+  if(xy.y next(), BTN1,{repeat: true});
+
+  //il tap è il tocco con l'accellerometro!
+  Bangle.on('tap', doubleTapUnlock);
+  Bangle.on('touch', toushScroll);
+
+  //quando apro quest'app, do per scontato che c'è un messaggio da leggere posto in un file particolare ( NewMessage.json )
+  let eventToShow = require('Storage').readJSON(settings.NewEventFileName, true);
+  require("Storage").erase(settings.NewEventFileName)
+  if( eventToShow!==undefined)
+    manageEvent(eventToShow);
+  else
+  {
+    LOG("file not found!");
+    setTimeout(_ => load(), 0);
+  }
+};
+
+
+
+
+main();
\ No newline at end of file
diff --git a/apps/messages_light/messages_light.boot.js b/apps/messages_light/messages_light.boot.js
new file mode 100644
index 000000000..741d08b96
--- /dev/null
+++ b/apps/messages_light/messages_light.boot.js
@@ -0,0 +1,33 @@
+/*
+//OLD CODE -> backup purpose
+
+let messageBootManager=function(type,event){
+    //se l'app non è aperta
+    if ("undefined"==typeof manageEvent)
+    {
+        if(event.t=="remove") return; //l'app non è aperta, non c'è nessun messaggio da rimuovere dalla queue -> non lancio l'app
+        
+        //la apro
+        require("Storage").writeJSON("messages_light.NewEvent.json",{"event":event,"type":type});
+        load("messages_light.app.js");  
+    }
+    else
+    {
+        //altrimenti gli dico di gestire il messaggio
+        manageEvent(type,event); 
+    }
+}
+Bangle.on("message", messageBootManager);
+Bangle.on("call", messageBootManager);*/
+
+
+
+//override require to filter require("message")
+global.require_real=global.require;
+global.require = (_require => file => {
+    if (file==="messages") file = "messagesProxy";
+    //else if (file==="messages_REAL") file = "messages";    //backdoor to real message
+    
+    return _require(file);
+})(require);
+  
diff --git a/apps/messages_light/messages_light.messagesProxy.js b/apps/messages_light/messages_light.messagesProxy.js
new file mode 100644
index 000000000..723397057
--- /dev/null
+++ b/apps/messages_light/messages_light.messagesProxy.js
@@ -0,0 +1,30 @@
+
+//gestisco il messaggio a modo mio
+exports.pushMessage = function(event) {
+
+    //TODO: now i can't handle the music, so i call the real message app
+    if( event.id=="music") return require_real("messages").pushMessage(event);
+
+    //se l'app non è aperta
+    if ("undefined"==typeof manageEvent)
+    {
+        if(event.t=="remove") return; //l'app non è aperta, non c'è nessun messaggio da rimuovere dalla queue -> non lancio l'app
+        
+        //la apro
+        require_real("Storage").writeJSON("messages_light.NewEvent.json",event);
+        load("messages_light.app.js");  
+    }
+    else
+    {
+        //altrimenti gli dico di gestire il messaggio
+        manageEvent(event); 
+    }
+}
+
+
+//Call original message library
+exports.clearAll = function() { return require_real("messages").clearAll()}
+exports.getMessages = function() { return require_real("messages").getMessages()}
+exports.status = function() { return require_real("messages").status()}
+exports.buzz = function() { return require_real("messages").buzz(msgSrc)} 
+exports.stopBuzz = function() { return require_real("messages").stopBuzz()}
\ No newline at end of file
diff --git a/apps/messages_light/messages_light.settings.js b/apps/messages_light/messages_light.settings.js
new file mode 100644
index 000000000..b7197c70a
--- /dev/null
+++ b/apps/messages_light/messages_light.settings.js
@@ -0,0 +1 @@
+eval(require("Storage").read("messages.settings.js"));
diff --git a/apps/messages_light/metadata.json b/apps/messages_light/metadata.json
new file mode 100644
index 000000000..3515a75c2
--- /dev/null
+++ b/apps/messages_light/metadata.json
@@ -0,0 +1,21 @@
+{
+  "id": "messages_light",
+  "name": "Messages Light",
+  "version": "1.3",
+  "description": "A light implementation of messages App (display notifications from iOS and Gadgetbridge/Android)",
+  "icon": "app.png",
+  "type": "app",
+  "tags": "tool,system",
+  "supports": ["BANGLEJS","BANGLEJS2"],
+  "dependencies" : { "messageicons":"module","messages":"app" },
+  "readme": "README.md",
+  "storage": [
+    {"name":"messages_light.app.js","url":"messages_light.app.js"},
+    {"name":"messages_light.settings.js","url":"messages_light.settings.js"},
+    {"name":"messages_light.img","url":"app-icon.js","evaluate":true},
+    {"name":"messagesProxy","url":"messages_light.messagesProxy.js"},
+    {"name":"messages_light.boot.js","url":"messages_light.boot.js"}
+  ],
+  "data": [{"name":"messages_light.settings.json"},{"name":"messages_light.NewMessage.json"}],
+  "screenshots": [{"url":"screenshot-notify.png"} ,{"url":"screenshot-long-text1.png"},{"url":"screenshot-long-text2.png"}, {"url":"screenshot-call.png"} ]
+}
diff --git a/apps/messages_light/screenshot-call.png b/apps/messages_light/screenshot-call.png
new file mode 100644
index 000000000..703faad6f
Binary files /dev/null and b/apps/messages_light/screenshot-call.png differ
diff --git a/apps/messages_light/screenshot-long-text1.png b/apps/messages_light/screenshot-long-text1.png
new file mode 100644
index 000000000..147b0cd5c
Binary files /dev/null and b/apps/messages_light/screenshot-long-text1.png differ
diff --git a/apps/messages_light/screenshot-long-text2.png b/apps/messages_light/screenshot-long-text2.png
new file mode 100644
index 000000000..5408f2059
Binary files /dev/null and b/apps/messages_light/screenshot-long-text2.png differ
diff --git a/apps/messages_light/screenshot-notify.png b/apps/messages_light/screenshot-notify.png
new file mode 100644
index 000000000..8896b803a
Binary files /dev/null and b/apps/messages_light/screenshot-notify.png differ
diff --git a/apps/messagesmusic/ChangeLog b/apps/messagesmusic/ChangeLog
index 5560f00bc..cd1c49b60 100644
--- a/apps/messagesmusic/ChangeLog
+++ b/apps/messagesmusic/ChangeLog
@@ -1 +1,6 @@
 0.01: New App!
+0.02: Remove one line of code that didn't do anything other than in some instances hinder the function of the app.
+0.03: Use the new messages library
+0.04: Fix dependency on messages library
+      Fix loading message UI
+0.05: Ensure we don't clear artist info
diff --git a/apps/messagesmusic/README.md b/apps/messagesmusic/README.md
index 7aa9209df..9a50de93e 100644
--- a/apps/messagesmusic/README.md
+++ b/apps/messagesmusic/README.md
@@ -1,15 +1,9 @@
 Hacky app that uses Messages app and it's library to push a message that triggers the music controls. It's nearly not an app, and yet it moves.
 
-This app require Messages setting 'Auto-open Music' to be 'Yes'. If it isn't, the app will change it to 'Yes' and let it stay that way.
-
 Making the music controls accessible this way lets one start a music stream on the phone in some situations even though the message app didn't receive a music message from gadgetbridge to begin with. (I think.)
 
 It is suggested to use Messages Music along side the app Quick Launch.
 
-Messages Music v0.01 has been verified to work with Messages v0.31 on Bangle.js 2 fw2v13.
-
-Music Messages should work with forks of the original Messages app. At least as long as functions pushMessage() in the library and showMusicMessage() in app.js hasn't been changed too much.
-
 Messages app is created by Gordon Williams with contributions from [Jeroen Peters](https://github.com/jeroenpeters1986).
 
 The icon used for this app is from [https://icons8.com](https://icons8.com).
diff --git a/apps/messagesmusic/app.js b/apps/messagesmusic/app.js
index a6f7e075e..68e88c2d8 100644
--- a/apps/messagesmusic/app.js
+++ b/apps/messagesmusic/app.js
@@ -1,15 +1,2 @@
-let showMusic = () => {
-  Bangle.CLOCK = 1; // To pass condition in messages library
-  require('messages').pushMessage({"t":"add","artist":" ","album":" ","track":" ","dur":0,"c":-1,"n":-1,"id":"music","title":"Music","state":"play","new":true});
-  Bangle.CLOCK = undefined;
-};
-
-var settings = require('Storage').readJSON('messages.settings.json', true) || {}; //read settings if they exist else set to empty dict
-if (!settings.openMusic) {
-  settings.openMusic = true; // This app/hack works as intended only if this setting is true
-  require('Storage').writeJSON('messages.settings.json', settings);
-  E.showMessage("First run:\n\nMessages setting\n\n 'Auto-Open Music'\n\n set to 'Yes'");
-  setTimeout(()=>{showMusic();}, 5000);
-} else {
-  showMusic();
-}
+// don't define artist/etc here so we don't wipe them out of memory if they were stored from before
+setTimeout(()=>require('messages').openGUI({"t":"add","id":"music","state":"show","new":true}));
diff --git a/apps/messagesmusic/metadata.json b/apps/messagesmusic/metadata.json
index edc6835ed..eef528f55 100644
--- a/apps/messagesmusic/metadata.json
+++ b/apps/messagesmusic/metadata.json
@@ -1,7 +1,8 @@
 {
   "id": "messagesmusic",
   "name":"Messages Music",
-  "version":"0.01",
+  "shortName": "Music",
+  "version":"0.05",
   "description": "Uses Messages library to push a music message which in turn displays Messages app music controls",
   "icon":"app.png",
   "type": "app",
@@ -13,6 +14,5 @@
     {"name":"messagesmusic.app.js","url":"app.js"},
     {"name":"messagesmusic.img","url":"app-icon.js","evaluate":true}
   ],
-  "dependencies": {"messages":"app"}
-
+  "dependencies":{"messages":"module"}
 }
diff --git a/apps/miclock/ChangeLog b/apps/miclock/ChangeLog
index e92bad2e3..d1ac3e388 100644
--- a/apps/miclock/ChangeLog
+++ b/apps/miclock/ChangeLog
@@ -2,3 +2,4 @@
 0.03: Localization
 0.04: move jshint to the top
 0.05: Use Bangle.setUI for button/launcher handling
+0.06: Tell clock widgets to hide.
diff --git a/apps/miclock/clock-mixed.js b/apps/miclock/clock-mixed.js
index b3d6bea8d..cb3235406 100644
--- a/apps/miclock/clock-mixed.js
+++ b/apps/miclock/clock-mixed.js
@@ -77,11 +77,13 @@ Bangle.on('lcdPower', function(on) {
     drawMixedClock();
 });
 
+// Show launcher when button pressed
+Bangle.setUI("clock");
+
 g.clear();
 Bangle.loadWidgets();
 Bangle.drawWidgets();
 setInterval(drawMixedClock, 5E3);
 drawMixedClock();
 
-// Show launcher when button pressed
-Bangle.setUI("clock");
+
diff --git a/apps/miclock/metadata.json b/apps/miclock/metadata.json
index 6eece46b0..2c216dc33 100644
--- a/apps/miclock/metadata.json
+++ b/apps/miclock/metadata.json
@@ -1,7 +1,7 @@
 {
   "id": "miclock",
   "name": "Mixed Clock",
-  "version": "0.05",
+  "version": "0.06",
   "description": "A mix of analog and digital Clock",
   "icon": "clock-mixed.png",
   "type": "clock",
diff --git a/apps/minimal_clock/ChangeLog b/apps/minimal_clock/ChangeLog
new file mode 100644
index 000000000..54ee389e3
--- /dev/null
+++ b/apps/minimal_clock/ChangeLog
@@ -0,0 +1,3 @@
+...
+0.03: First update with ChangeLog Added
+0.04: Tell clock widgets to hide.
diff --git a/apps/minimal_clock/app.js b/apps/minimal_clock/app.js
index d78790347..47eca3c66 100644
--- a/apps/minimal_clock/app.js
+++ b/apps/minimal_clock/app.js
@@ -3,6 +3,7 @@
 
   let outerRadius = Math.min(CenterX,CenterY) * 0.9;
 
+  Bangle.setUI('clock');
   Bangle.loadWidgets();
 
 /**** updateClockFaceSize ****/
@@ -225,6 +226,5 @@
     }
   });
 
-  Bangle.loadWidgets();
 
-  Bangle.setUI('clock');
+  Bangle.loadWidgets();
diff --git a/apps/minimal_clock/metadata.json b/apps/minimal_clock/metadata.json
index 1702d97a9..3089780ce 100644
--- a/apps/minimal_clock/metadata.json
+++ b/apps/minimal_clock/metadata.json
@@ -1,7 +1,7 @@
 { "id": "minimal_clock",
   "name": "Minimal Analog Clock",
   "shortName":"Minimal Clock",
-  "version":"0.03",
+  "version":"0.04",
   "description": "a minimal analog clock - just with some hands and no clock face",
   "icon": "app-icon.png",
   "type": "clock",
diff --git a/apps/minionclk/ChangeLog b/apps/minionclk/ChangeLog
index a8b6efc81..5949a786d 100644
--- a/apps/minionclk/ChangeLog
+++ b/apps/minionclk/ChangeLog
@@ -3,3 +3,4 @@
 0.03: Fixed rendering for Espruino v2.06
 0.04: Fixed overlapped rendering of dates
 0.05: Use Bangle.setUI for button/launcher handling
+0.06: Tell clock widgets to hide.
diff --git a/apps/minionclk/app b/apps/minionclk/app
new file mode 100644
index 000000000..e69de29bb
diff --git a/apps/minionclk/app.js b/apps/minionclk/app.js
index 9648e3d89..c61f8d3bf 100644
--- a/apps/minionclk/app.js
+++ b/apps/minionclk/app.js
@@ -78,8 +78,10 @@ Bangle.on('lcdPower', (on) => {
   }
 });
 
+// Show launcher when button pressed
+Bangle.setUI("clock");
+
 Bangle.loadWidgets();
 startDrawing();
 
-// Show launcher when button pressed
-Bangle.setUI("clock");
+
diff --git a/apps/minionclk/metadata.json b/apps/minionclk/metadata.json
index 44fc2a82d..4df2ddc6b 100644
--- a/apps/minionclk/metadata.json
+++ b/apps/minionclk/metadata.json
@@ -1,7 +1,7 @@
 {
   "id": "minionclk",
   "name": "Minion clock",
-  "version": "0.05",
+  "version": "0.06",
   "description": "Minion themed clock.",
   "icon": "minionclk.png",
   "type": "clock",
diff --git a/apps/mitherm/ChangeLog b/apps/mitherm/ChangeLog
new file mode 100644
index 000000000..630459c15
--- /dev/null
+++ b/apps/mitherm/ChangeLog
@@ -0,0 +1 @@
+0.01: Create mitherm app with support for pvvx firmware only
diff --git a/apps/mitherm/README.md b/apps/mitherm/README.md
new file mode 100644
index 000000000..cdf3daa61
--- /dev/null
+++ b/apps/mitherm/README.md
@@ -0,0 +1,22 @@
+Reads BLE advertisement data from Xiaomi temperature/humidity sensors running the
+`pvvx` custom firmware (https://github.com/pvvx/ATC_MiThermometer).
+
+## Features
+
+* Display temperature
+* Display humidity
+* Display battery state of sensor
+* Auto-refresh every 5 minutes
+* Manual refresh on demand
+* Add aliases for MAC addresses to easily recognise devices
+
+## Planned features
+
+* Supprt for other advertising formats:
+  * atc1441 format
+  * BTHome
+  * Xiaomi Mijia format
+* Configurable auto-refresh interval
+* Configurable scan length (currently 30s)
+* Alerts when temperature outside defined limits (with a widget or bootcode to
+  work when app is inactive)
diff --git a/apps/mitherm/app-icon.js b/apps/mitherm/app-icon.js
new file mode 100644
index 000000000..2e8737704
--- /dev/null
+++ b/apps/mitherm/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwwhC/AH4Ac5gWVhnM4AWVAAIYTCwQABCywYRIoYADJJwWHDB4RD5sz7hJPFIlP//0MRxFE6f/AAM9JJgWE4gWCAANMDBZcEn4XE+ZiKFwhcBCYPdDYRiEGAoXDLgf97vfMQwXILggXFMQYXHLgoXB6czMQoXHLgQXJMQQXG4YWEI44ABngXGh4XHF4v/+DAGC6DXGC5BHGC509F4IXTdwIABV4gXOIwIABJAoX/C6p3Xa4a/UABAXfgczABswC/4XmAH4A/ABY"))
diff --git a/apps/mitherm/app.js b/apps/mitherm/app.js
new file mode 100644
index 000000000..b7abdb2fc
--- /dev/null
+++ b/apps/mitherm/app.js
@@ -0,0 +1,172 @@
+var filterTemperature = [{
+  serviceData: {
+    "181a": {}
+  }
+}];
+var results = {};
+var macs = [];
+
+var aliases = require("Storage").readJSON("mitherm.json", true);
+if (!aliases) aliases = {};
+
+var lastSeen = {};
+var current = 0;
+var scanning = false;
+var timeoutDraw;
+var timeoutScan;
+
+
+const scan = function() {
+  if (!scanning) { // Don't start scanning if already doing so.
+    scanning = true;
+    if (timeoutScan) clearTimeout(timeoutScan);
+    timeoutScan = setTimeout(scan, 300000); // Scan again in 5 minutes.
+    drawScanState(scanning);
+    NRF.findDevices(function(devices) {
+      onDevices(devices);
+    }, {
+      filters: filterTemperature,
+      timeout: 30000  // Scan for 30s
+    });
+  }
+};
+
+
+const onDevices = function(devices) {
+  let now = Date.now();
+  for (let i = 0; i < devices.length; i++) {
+    let device = devices[i];
+
+    let processedData = extractData(device.data);
+    console.log({
+      rssi: device.rssi,
+      data: processedData
+    });
+    if (!macs.includes(processedData.MAC)) {
+      macs.push(processedData.MAC);
+    }
+    results[processedData.MAC] = processedData;
+    lastSeen[processedData.MAC] = now;
+  }
+  console.log("Scan complete.");
+  scanning = false;
+  writeOutput();
+};
+
+
+const extractData = function(thedata) {
+  let data = DataView(thedata);
+  let MAC = [];
+  for (let i = 9; i > 3; i--) {
+    MAC.push(data.getUint8(i, true).toString(16).padStart(2, "0"));
+  }
+  out = {
+    size: data.getUint8(0, true),
+    uid: data.getUint8(1, true),
+    UUID: data.getUint16(2, true),
+    MAC: MAC.join(":"),
+    temperature: data.getInt16(10, true) * 0.01,
+    humidity: data.getUint16(12, true) * 0.01,
+    battery_mv: data.getUint16(14, true),
+    battery_level: data.getUint8(16, true),
+  };
+  return out;
+};
+
+
+const writeOutput = function() {
+  let now = Date.now();
+  if (timeoutDraw) clearTimeout(timeoutDraw);
+  timeoutDraw = setTimeout(writeOutput, 60000); // Refresh in 1 minute.
+  g.clear(true);
+  Bangle.drawWidgets();
+  g.reset();
+  drawScanState(scanning);
+
+  if (macs.length == 0) return;
+
+  processedData = results[macs[current]];
+  g.setFont12x20(2);
+  g.drawString(`${processedData.temperature.toFixed(2)}°C`, 10, 30);
+  g.drawString(`${processedData.humidity.toFixed(2)} %`, 10, 70);
+
+  g.setFont6x15();
+  g.drawString(`${((now - lastSeen[macs[current]]) / 60000).toFixed(0)} min ago`, 10, 130);
+  g.drawString(`${processedData.battery_level} % battery`, 80, 130);
+  g.drawString(` ${processedData.MAC in aliases ? aliases[processedData.MAC] : processedData.MAC}: ${current + 1} / ${macs.length}`, 10, 150);
+};
+
+
+const scrollDevices = function(directionLR) {
+  // Swipe left or right to move between devices.
+  current -= directionLR; // inverted feels a more familiar gesture.
+  if (current + 1 > macs.length)
+    current = 0;
+  if (current < 0)
+    current = macs.length - 1;
+  writeOutput();
+};
+
+const drawScanState = function(state) {
+  if (state)
+    g.fillRect(160, 160, 170, 170);
+  else
+    g.clearRect(160, 160, 170, 170);
+};
+
+const setAlias = function(mac, alias) {
+  if (alias === "") {
+    delete aliases[mac];
+  }
+  else {
+    aliases[mac] = alias;
+    require("Storage").writeJSON("mitherm.json", aliases);
+  }
+};
+
+const changeAlias = function(mac) {
+  g.clear();
+  require("textinput").input((mac in aliases) ? aliases[mac] : "").then(function(text) {
+    setAlias(mac, text);
+    setUI();
+    writeOutput();
+  });
+};
+
+
+const setUI = function() {
+  Bangle.setUI({
+    mode: "custom",
+    swipe: scrollDevices,
+    btn: function() {
+      E.showMenu(actionsMenu);
+    }
+  });
+};
+
+
+const actionsMenu = {
+  "": {
+    "title": "-- Actions --",
+    "back": function() {
+      E.showMenu();
+    },
+    "remove": function() {
+      setUI();
+      writeOutput();
+    },
+  },
+  "Scan now": function() {
+    scan();
+    E.showMenu();
+  },
+  "Edit alias": function() {
+    changeAlias(macs[current]);
+  },
+};
+
+setUI();
+Bangle.loadWidgets();
+g.setClipRect(Bangle.appRect);
+scan();
+writeOutput();
diff --git a/apps/mitherm/app.png b/apps/mitherm/app.png
new file mode 100644
index 000000000..81d6bb24f
Binary files /dev/null and b/apps/mitherm/app.png differ
diff --git a/apps/mitherm/metadata.json b/apps/mitherm/metadata.json
new file mode 100644
index 000000000..a8da6fd26
--- /dev/null
+++ b/apps/mitherm/metadata.json
@@ -0,0 +1,15 @@
+{
+  "id": "mitherm",
+  "name": "Xiaomi Mijia Temperature and Humidity display",
+  "shortName": "MiTherm",
+  "version": "0.01",
+  "description": "Reads and displays data from Xiaomi temperature/humidity sensors running custom firmware",
+  "icon": "app.png",
+  "tags": "xiaomi,mi,ble,bluetooth,thermometer,humidity",
+  "readme": "README.md",
+  "supports": ["BANGLEJS", "BANGLEJS2"],
+  "storage": [
+    {"name":"mitherm.app.js","url":"app.js"},
+    {"name":"mitherm.img","url":"app-icon.js","evaluate":true}
+  ]
+}
diff --git a/apps/mylocation/ChangeLog b/apps/mylocation/ChangeLog
index c14e64ba9..afe1810e9 100644
--- a/apps/mylocation/ChangeLog
+++ b/apps/mylocation/ChangeLog
@@ -5,3 +5,5 @@
 0.05: Fixed issue with back option
 0.06: renamed source files to match standard
 0.07: Move mylocation app into 'Settings -> Apps'
+0.08: Allow setting location from webinterface in the AppLoader
+0.09: Fix web interface so app can be installed (replaced custom with interface html)
diff --git a/apps/mylocation/README.md b/apps/mylocation/README.md
index a6a16ce83..11a644262 100644
--- a/apps/mylocation/README.md
+++ b/apps/mylocation/README.md
@@ -1,10 +1,15 @@
 # My Location
 
-   *Sets and stores GPS lat and lon of your preferred city*
+*Sets and stores GPS lat and lon of your preferred city*
 
-To access, go to `Settings -> Apps -> My Location`
+To access, you have two options:
 
-* Select one of the preset Cities or setup through the GPS
+**In the App Loader** once My Location is installed, click on the 'Save' icon
+next to it - and you can choose your location on a map.
+
+**On Bangle.js** go to `Settings -> Apps -> My Location`
+
+* Select one of the preset Cities, setup through the GPS or use the webinterface from the AppLoader
 * Other Apps can read this information to do calculations based on location
 * When the City shows ??? it means the location has been set through the GPS
 
diff --git a/apps/mylocation/interface.html b/apps/mylocation/interface.html
new file mode 100644
index 000000000..79a122bf7
--- /dev/null
+++ b/apps/mylocation/interface.html
@@ -0,0 +1,114 @@
+
+  
+    
+    
+    
+  
+    
+  
+  
+    
+
+
+ Click the map to select a location +
+
+ + + + + + + + + + + diff --git a/apps/mylocation/metadata.json b/apps/mylocation/metadata.json index 4ab9aa37e..1c2974030 100644 --- a/apps/mylocation/metadata.json +++ b/apps/mylocation/metadata.json @@ -4,11 +4,12 @@ "icon": "app.png", "type": "settings", "screenshots": [{"url":"screenshot_1.png"}], - "version":"0.07", - "description": "Sets and stores the lat and long of your preferred City or it can be set from the GPS. mylocation.json can be used by other apps that need your main location lat and lon. See README", + "version":"0.09", + "description": "Sets and stores the latitude and longitude of your preferred City. It can be set from GPS or webinterface. `mylocation.json` can be used by other apps that need your main location. See README for details.", "readme": "README.md", "tags": "tool,utility", "supports": ["BANGLEJS", "BANGLEJS2"], + "interface": "interface.html", "storage": [ {"name":"mylocation.settings.js","url":"settings.js"} ], diff --git a/apps/mysticclock/ChangeLog b/apps/mysticclock/ChangeLog index b486a29a1..cd91abe00 100644 --- a/apps/mysticclock/ChangeLog +++ b/apps/mysticclock/ChangeLog @@ -1,2 +1,3 @@ 1.00: First published version. 1.01: Use Bangle.setUI for Launcher/buttons +1.02: Tell clock widgets to hide. diff --git a/apps/mysticclock/metadata.json b/apps/mysticclock/metadata.json index 571a55ecd..bd2df2f8d 100644 --- a/apps/mysticclock/metadata.json +++ b/apps/mysticclock/metadata.json @@ -1,7 +1,7 @@ { "id": "mysticclock", "name": "Mystic Clock", - "version": "1.01", + "version": "1.02", "description": "A retro-inspired watchface featuring time, date, and an interactive data display line.", "icon": "mystic-clock.png", "type": "clock", diff --git a/apps/mysticclock/mystic-clock-app.js b/apps/mysticclock/mystic-clock-app.js index 2d95633fe..d7f4ab1c3 100644 --- a/apps/mysticclock/mystic-clock-app.js +++ b/apps/mysticclock/mystic-clock-app.js @@ -189,6 +189,13 @@ Bangle.on('touch', (button) => { if (button === 3 && Bangle.isLCDOn()) Bangle.setLCDPower(false); }); +// Show launcher when button pressed +Bangle.setUI("clockupdown", btn=>{ + if (btn<0) prevInfo(); + if (btn>0) nextInfo(); + drawAll(); +}); + // clean app screen g.clear(); Bangle.loadWidgets(); @@ -200,9 +207,3 @@ if (Bangle.isLCDOn()) { drawAll(); // draw immediately } -// Show launcher when button pressed -Bangle.setUI("clockupdown", btn=>{ - if (btn<0) prevInfo(); - if (btn>0) nextInfo(); - drawAll(); -}); diff --git a/apps/nato/ChangeLog b/apps/nato/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/nato/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/ncfrun/metadata.json b/apps/ncfrun/metadata.json deleted file mode 100644 index 831ae3d4e..000000000 --- a/apps/ncfrun/metadata.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "id": "ncfrun", - "name": "NCEU 5K Fun Run", - "version": "0.01", - "description": "Display a map of the NodeConf EU 2019 5K Fun Run route and your location on it", - "icon": "nceu-funrun.png", - "tags": "health", - "supports": ["BANGLEJS"], - "storage": [ - {"name":"ncfrun.app.js","url":"nceu-funrun.js"}, - {"name":"ncfrun.img","url":"nceu-funrun-icon.js","evaluate":true} - ] -} diff --git a/apps/ncfrun/nceu-funrun-icon.js b/apps/ncfrun/nceu-funrun-icon.js deleted file mode 100644 index a13452a8b..000000000 --- a/apps/ncfrun/nceu-funrun-icon.js +++ /dev/null @@ -1 +0,0 @@ -require("heatshrink").decompress(atob("mEwwgurglEC6tDmYYUgkzAANAFygXKKYIADBwgXDkg8LBwwXMoQXEH4hHNC4s0O6BfECAKhDHYKnOghCB3cga6dEnYYBaScC2cznewC6W7OQU7BYyIFAAhFBAAYwGC5RFBC5QAJlY0FSIQAMkUjGgrTJRYoXFPQIXGLg8iAAJFDDgIXGgYXJGAWweQJHOC4jtBC6cidgQXUUQQXBogACDYR3HmQXHAAYzKU4IACC48kJBwFBgg7EMZYwDJAReDoh5PC4QARJAoARJAYXTJChtDoSgNAAaeEAAU0C5wqCC4q5LOYYvWgjOEaJ4AGoZGQPY6OPFw0yF34uFRlYXCFykAoQuVeIQWUAB4A=")) diff --git a/apps/ncfrun/nceu-funrun.js b/apps/ncfrun/nceu-funrun.js deleted file mode 100644 index 30e587188..000000000 --- a/apps/ncfrun/nceu-funrun.js +++ /dev/null @@ -1,140 +0,0 @@ -var coordScale = 0.6068; -var coords = new Int32Array([-807016,6918514,-807057,6918544,-807135,6918582,-807238,6918630,-807289,6918646,-807308,6918663,-807376,6918755,-807413,6918852,-807454,6919002,-807482,6919080,-807509,6919158,-807523,6919221,-807538,6919256,-807578,6919336,-807628,6919447,-807634,6919485,-807640,6919505,-807671,6919531,-807703,6919558,-807760,6919613,-807752,6919623,-807772,6919643,-807802,6919665,-807807,6919670,-807811,6919685,-807919,6919656,-807919,6919645,-807890,6919584,-807858,6919533,-807897,6919503,-807951,6919463,-807929,6919430,-807916,6919412,-807907,6919382,-807901,6919347,-807893,6919322,-807878,6919292,-807858,6919274,-807890,6919232,-807909,6919217,-807938,6919206,-807988,6919180,-807940,6919127,-807921,6919100,-807908,6919072,-807903,6919039,-807899,6919006,-807911,6918947,-807907,6918936,-807898,6918905,-807881,6918911,-807874,6918843,-807870,6918821,-807854,6918775,-807811,6918684,-807768,6918593,-807767,6918593,-807729,6918516,-807726,6918505,-807726,6918498,-807739,6918481,-807718,6918465,-807697,6918443,-807616,6918355,-807518,6918263,-807459,6918191,-807492,6918162,-807494,6918147,-807499,6918142,-807500,6918142,-807622,6918041,-807558,6917962,-807520,6917901,-807475,6917933,-807402,6917995,-807381,6918024,-807361,6918068,-807323,6918028,-807262,6918061,-807263,6918061,-807159,6918116,-807148,6918056,-807028,6918063,-807030,6918063,-806979,6918068,-806892,6918090,-806760,6918115,-806628,6918140,-806556,6918162,-806545,6918175,-806531,6918173,-806477,6918169,-806424,6918180,-806425,6918180,-806367,6918195,-806339,6918197,-806309,6918191,-806282,6918182,-806248,6918160,-806225,6918136,-806204,6918107,-806190,6918076,-806169,6917968,-806167,6917953,-806157,6917925,-806140,6917896,-806087,6917839,-806071,6917824,-805969,6917904,-805867,6917983,-805765,6918063,-805659,6918096,-805677,6918131,-805676,6918131,-805717,6918212,-805757,6918294,-805798,6918397,-805827,6918459,-805877,6918557,-805930,6918608,-805965,6918619,-806037,6918646,-806149,6918676,-806196,6918685,-806324,6918703,-806480,6918735,-806528,6918738,-806644,6918712,-806792,6918667,-806846,6918659,-806914,6918654,-806945,6918661,-806971,6918676,-806993,6918689,-806992,6918692,-807065,6918753,-807086,6918786,-807094,6918788,-807102,6918795,-807104,6918793,-807107,6918799,-807102,6918802,-807112,6918812,-807106,6918815,-807115,6918826,-807120,6918823,-807132,6918841,-807141,6918850,-807151,6918841,-807170,6918832,-807193,6918813,-807222,6918775,-807246,6918718,-807250,6918694,-807264,6918637,-807238,6918630,-807148,6918587,-807057,6918544,-806948,6918463]); - -var min = {"x":-807988,"y":6917824}; -var max = {"x":-805659,"y":6919685}; -var gcoords = new Uint8Array(coords.length); -var coordDistance = new Uint16Array(coords.length/2); - -var PT_DISTANCE = 30; // distance to a point before we consider it complete - -function toScr(p) { - return { - x : 10 + (p.x-min.x)*100/(max.x-min.x), - y : 230 - (p.y-min.y)*100/(max.y-min.y) - }; -} - -var last; -var totalDistance = 0; -for (var i=0;i { } }); +// Show launcher when button pressed +Bangle.setUI("clock"); + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); drawHands(true); - -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/ncrclk/metadata.json b/apps/ncrclk/metadata.json index b50b554e1..fdab77450 100644 --- a/apps/ncrclk/metadata.json +++ b/apps/ncrclk/metadata.json @@ -2,7 +2,7 @@ "id": "ncrclk", "name": "NCR Clock", "shortName": "NCR Clock", - "version": "0.02", + "version": "0.03", "description": "NodeConf Remote clock", "icon": "app.png", "type": "clock", diff --git a/apps/ncstart/ChangeLog b/apps/ncstart/ChangeLog deleted file mode 100644 index 152fdc9d1..000000000 --- a/apps/ncstart/ChangeLog +++ /dev/null @@ -1,9 +0,0 @@ -0.02: Modified for use with new bootloader and firmware - Renamed as nodeconf-specific -0.03: Move configuration into App/widget settings - Move loader into welcome.boot.js -0.04: Run again when updated - Don't run again when settings app is updated (or absent) - Add "Run Now" option to settings -0.05: Don't overwrite existing settings on app update -0.06: Allow welcome to run after a fresh install diff --git a/apps/ncstart/boot.js b/apps/ncstart/boot.js deleted file mode 100644 index 62ac962f6..000000000 --- a/apps/ncstart/boot.js +++ /dev/null @@ -1,9 +0,0 @@ -(function() { - let s = require('Storage').readJSON('ncstart.json', 1) || {}; - if (!s.welcomed) { - setTimeout(() => { - require('Storage').write('ncstart.json', {welcomed: true}) - load('ncstart.app.js') - }) - } -})() diff --git a/apps/ncstart/metadata.json b/apps/ncstart/metadata.json deleted file mode 100644 index d2b3e2196..000000000 --- a/apps/ncstart/metadata.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "id": "ncstart", - "name": "NCEU Startup", - "version": "0.06", - "description": "NodeConfEU 2019 'First Start' Sequence", - "icon": "start.png", - "tags": "start,welcome", - "supports": ["BANGLEJS"], - "storage": [ - {"name":"ncstart.app.js","url":"start.js"}, - {"name":"ncstart.boot.js","url":"boot.js"}, - {"name":"ncstart.settings.js","url":"settings.js"}, - {"name":"ncstart.img","url":"start-icon.js","evaluate":true}, - {"name":"nc-bangle.img","url":"start-bangle.js","evaluate":true}, - {"name":"nc-nceu.img","url":"start-nceu.js","evaluate":true}, - {"name":"nc-nfr.img","url":"start-nfr.js","evaluate":true}, - {"name":"nc-nodew.img","url":"start-nodew.js","evaluate":true}, - {"name":"nc-tf.img","url":"start-tf.js","evaluate":true} - ], - "data": [{"name":"ncstart.json"}] -} diff --git a/apps/ncstart/settings.js b/apps/ncstart/settings.js deleted file mode 100644 index 560fad8ba..000000000 --- a/apps/ncstart/settings.js +++ /dev/null @@ -1,14 +0,0 @@ -(function(back) { - let settings = require('Storage').readJSON('ncstart.json', 1) - || require('Storage').readJSON('setting.json', 1) || {} - E.showMenu({ - '': { 'title': 'NCEU Startup' }, - 'Run on Next Boot': { - value: !settings.welcomed, - format: v => v ? 'OK' : 'No', - onchange: v => require('Storage').write('ncstart.json', {welcomed: !v}), - }, - 'Run Now': () => load('ncstart.app.js'), - '< Back': back, - }) -}) diff --git a/apps/ncstart/start-bangle.js b/apps/ncstart/start-bangle.js deleted file mode 100644 index 26f38ae14..000000000 --- a/apps/ncstart/start-bangle.js +++ /dev/null @@ -1 +0,0 @@ -require("heatshrink").decompress(atob("s8wxH+AH4AQ/4AJJX5mmM/5m/AH5m/M34A/M35l/M35mqM/5m/AH5m/M34A/MqQKQJm5laOh7kNM35MGbiQxLM9osWIiZnGDI5m/VTBm/MsrOGM35maB4xm/MsoZFORZm/Fq5mDAAwUKBhAHBDJYLGAY4rOPShmRF44TIIoqlJCIxmKEZLMSBxY1GE5RTIJpwYSP5hmQZxodKLBKpIDBQZHMxS4MM1IKCMzKNQHJJmtFwbbUMy4AIM35mcJR5mbLCo1GZrxLOLZ6BMH5wOHMyAYRSRLOWGRY+MAxRmODCZeNMyLNMAA4TIBgpmPFA4YMHBZnPFIp/cADa0cC9Zm2J5YkKMtgsIGjZRTCYLMsFow0dDqJluGAgzhEJwxiAGpYLMn70hAA5N/M34A/M35mzJn5m/AH5nNJf5m/AH5m/M34A/M35m/MpgA=")) diff --git a/apps/ncstart/start-icon.js b/apps/ncstart/start-icon.js deleted file mode 100644 index 0302cadbc..000000000 --- a/apps/ncstart/start-icon.js +++ /dev/null @@ -1 +0,0 @@ -require("heatshrink").decompress(atob("mEwxH+AHMPADQv/F+YxZYtb1wFto7SEbwwQBIsen0/ADU+jxfOjwtbAAYwDWZVWF79WfBAvEq4vfq4vIGQgviR44AEFz4vEGRQvnGA4v/F79YX9IHEq4aKh//jwvRrBcHG4ovL/4ABB5gAFRAwvVGIQveoAAIF4oABq0/CZIACF8BiBrAvTGIoaKF5AABIpVXd44AFJBQvKh4vOGBIvVL54vdX5iPhqztLoFYFpYvSh8/FxgABFpYvQRRgveoEP/8eFqAvbACi/CeA4IDP6IvUGIYGEF+EMADwvJR4ovmdoovnFoowDF8QsIF4dZF79ZF5RpCj1AFztAjy7JAAgwdFwbAFFwwAmF/4vhGFrxLFkoAvA=")) diff --git a/apps/ncstart/start-nceu.js b/apps/ncstart/start-nceu.js deleted file mode 100644 index 89a9850cc..000000000 --- a/apps/ncstart/start-nceu.js +++ /dev/null @@ -1 +0,0 @@ -require("heatshrink").decompress(atob("o9HxH+AEOAwAkiIkIADIv5CEI/4/IJHbNLbPA4Iv1+JHREIwkmk2EJBBE2IoUnIwJHBCx5GoBA2DIgQACBw5G3aQQADwRG+wEmagQCBvxGufoQpDFxOCI4YNIDgxNeD4gDHCY+EwgMKBQIjGJDJlHA4YlKvzRHDRZHZDJQkMBZojVECb+OHJgkOZ6w6KCJAHJCgY1dK5wPDCg4GICYjDZBY9+vxGMArItLeRgWDwOEwmBJA5Ggv2GlMMwJGTwRFBI5JGfv2HlIACwRGRwBFDAAIUGIz+FIYMMI4R0CIxzSCRwhaMIBy2FAAaMBhmHI4QjIRqwUFIxxFJOgLTDlMGRqJHFwF+CpAWDIxgwJBgN+aoSMEIyAGBweDXBg6FABIWLAgOCw+GMhRGKByI9IIxYtQIywaJC5YTTIzwRGOyQqTIzLGNCTJGgXqIRTIzILIIzQvUI5a4EBgh6TDI7dKZJo7IAwQLFIzAjKIhwQGChBvMEhojLIqIjGBaZGPEbppOEerrLBYpGVEZrVOBpJjJIzCHNcpoqPI6gaUIywfSCLJGgXBYSZIzwRFCxoSGFSJGYCA4XLCRArQIywOJYxDPLFqA3OwFPp4HCy4lKHogAIM5uulukMIxGNy1MAAWW2JENFBJIMv8B0ksAAQQDIx2AptMpoCCChZGQGROYIocslsBIyGVIQNOp5HByhaMIxj9IAAWMIYUtRwiNPaIKNCpgUGIB4FNAAMXRq/+yhDBAAOUtJGlgKOCAAOvCJRGH2OVp1OypFGI0BHB0jUBzCMCIyAABtJEHI0RICIgYRMJBBGMCg4GICYgnPCBhHPBwQSIA5IUDGpxWOJBwgLfpgkOIhwVOEBj9WIipsKA4YiKgMBERojIIqphHAgYjKy+n1VpTJYjIADZlGEpOVlwABhTJKRL4oHFxIIEIgUKlula44/hShwIG1RFB02lJQJVII2zTC0iNBhVpI24vGgOmlpIBl2WagwWIJGFp1UKhRFGImI0FGouAaIoPIJGQMWJG5E7H5BE/I4pF/JA4kiA")) diff --git a/apps/ncstart/start-nfr.js b/apps/ncstart/start-nfr.js deleted file mode 100644 index 2a0ad70ea..000000000 --- a/apps/ncstart/start-nfr.js +++ /dev/null @@ -1 +0,0 @@ -require("heatshrink").decompress(atob("5EuxH+AAkPABIQFABIaKDiIA/AH6qaVpwbbAH4A/YzysMDbYA/AH7GfVhbHgChrr0MT5FoTDobOQijH/Y/6aYcqzH/Y/5EeZDLHmFxTH/Y/4TVY84uJY/7H7TibHuC4rH5XmiHRZC7HpDAjSQF5QpJCgYGJY6Y8MFR4bJBSrITY9RNJb6LFNY5ALFP6CsVY55PQTzDH6MhrGPY7opYY7IZFAgqfRY9xzIWx7GQY6QsYFTTHQZDLHlL44ONDxIfJdKS3PA54qSCRL1MWpDIRY8yLNCg5FICB7ZMHZwrKaB4bQEpTHZH5bHgRhiZNbCTZSY5qBNHiDHZZCbHsOZjHPRSTHYOZbHyZDLH/Y8pQRY+zIYY8xPLG6bHsDJjHuUiTbQdTjHfQBjHYVaLHyUqbHoKJC2KCBgRDBA7HeThbHvZETHdVxKKPTkzISfJLHpZELHeOZLGOY9g8OY+TIgY74OJLqDHqFZIMJY/7HuFxRcPYJbHeXi7HUKAqGYCSgdRAH4A/XC7IdY/4A/Y9rIZY/4A/Y/7H/AH7H2ZDDH/AH7HvZC7H/SMrH/Io7IZDCoVIBgwNFBSA7JBRoZOJ5jboY6IOBY9oWKDpYLFApZkNH6YIHJ5BMNY97IZY6yvTTJCGRBwQRIExYVKB4zH+ZDDHpBQ7HgH5Q+QY/7IYY9KDJY6QeKY6xDOY/7H7BhRiPCRQGHA4SsRCJDH4ZDJqUfpQiIBR6UNDRISQOJ52TY9DIYNSyvSIZLfOAxoaIY/7HVZC4SQQBSJUC57HTDIw9QGZzH/Y7xmINyTHTAAwfKHyzH/OBTH3CRg1LYxAUFD5Y+QY9RXLLxQaWY6yIYY6g5SH57kHY9StRcbZPQQJivRC6AKJEBpGHBxrH/DcbHUEpQKQBojSPH5gpIXx7HjVp4caJkbjRGv4AkA==")) diff --git a/apps/ncstart/start-nodew.js b/apps/ncstart/start-nodew.js deleted file mode 100644 index 287d49a1b..000000000 --- a/apps/ncstart/start-nodew.js +++ /dev/null @@ -1 +0,0 @@ -require("heatshrink").decompress(atob("5E1xH+AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A6hEICD4A/AH7FlY6TJ/AH7G1Y6bI/AH7FyY6rJ/AH7GyY6zI/AH7H/Y/4A/Y3DHXg5g/AH4Ak5jH/AH4A/Y9VXq5l/AH4Ag47HjZAJm/AH7GgY5S9KZBjHDZH4A/Y9S5KBxrH/AH7GkY5DGOCIrHJZA4pGBiQAPKpAQLHKQmPADRSQY6LFQCZLHPQJjIeQqwKVHTLHoEpDISY4rIGJRbH/IjBYXC67GCY5LGRY7CCaY8hEPV87Ha4zHEYyoXGY6SOKY9IQJIhRDUY+YdEY64YCAgTIBY6CDPMBxRIDpAvMIaZALV5z/NFRrHH5glGYyqOFY4LIJDJoHKaZolPMZIRMUZAyLHxotLLJzHJ4zGBY8TICY6KXJO6wdQWiJCHGRp+QJaTINYoRbQY6bICZINRY8RJQDhowPY8RMYY5YABgR9US6MHgIwGJ5QMLE44GIURY4NBSoyKIZQRObhrIMg7HkgQvIJBapSBzrBPCBhdJY5w+NeBgAFzO93rIFY8AFBxmGwydKFxSFOMJR6JFZhXLIKbHVPhbHPZALJBZA7HcAgLFBY5qFYY+KsLY/DICY4rIWC4kC/2MY6CGJOZjWPRBy8KY95MHY62ZAoLICY64/G/zGIMRxcQdB7HWBZqeQEZxcIY7e9Y4ZMHY/AwJIByrOY7JzLCJAbNY8jITCozHVURqDRDrY/MGSDHWPhTHOZAbHFZCgxHY4gxGIJbrLT6AQIDiRLQOp7ITGBbHcZB4wKY5o+IOxwWLBoQdUY54zMCJTTQBQ6GSZAjHGZCJCLY5IA/AH4AWY5L7LBpzHDNH4A/ZEDHIXQoALaZLH/AH7HsZB4WHgTHCM34A/AELHjY34A/AErHhAH4A/AEzH/AH4A/Y8xe/AH7IwCsgA/AH7IiCkYA/AH7IjCcQA/AH7JkCMAA/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AHIA=")) diff --git a/apps/ncstart/start-tf.js b/apps/ncstart/start-tf.js deleted file mode 100644 index d09185caf..000000000 --- a/apps/ncstart/start-tf.js +++ /dev/null @@ -1 +0,0 @@ -require("heatshrink").decompress(atob("4M7ghC/AH4A/AEcBiMQAgY+3iIACIAQhcAgYjdTzZgfYH5giYHo5BIIQGDAQYLHgMQBoZZFYAoYENGREDGgI6BAYYMDBYrXDA4RTDAobnFLgbNEYF5LFVAIGCAghsEBQYMFYAoMEC4TAxAAg5DLoqiCZQZ2CAQa2DYAiGFA4bAvXYj6DAIZkEVYizHLYhyDNoaGCL9zAEHw5aGOIwHJYAqBFL96zCHxJsEKwcBYAx5GYA4SCFobAuMohoDAQ4UCKgYCEYBR7FYGqsDIIwLFYAzUFYAhbEL+IyGIojAFBYbAEKYZYHCgghEYGoGFWoQGFJIYHBgRZDbQpsFYGiNuIP4AedooA/L/4A5gJf/AH4A/AH4A/AH4A/AH4A/AH4A/ACsN7oAJG+oJC6AoaL5QmbG7PQTLrA/YH7A/YH7AhFgxbrYA4JQFkTArWwzAlEQhnCA4bPDBQwLDHwwJH5oGBEAydNAwQHDEgggDcaJBDEY4JDJoYSEH5A7GBAbAPHg5aHCQoiSEYpNHBIxpIBIQHGTpwzGGQJlMESZCIFowTNCQLAVSZAXFGQnNL5AiNBJAeBBIYsDNJIJHTpwyMCQhGEQQwsFYo7kGAoQJDEQQyDS5ChDCgxRJGRJ4DUIpAFYBQiFJgwUGBIr3IIAy5EaJgyNcgoTGcZZCFWwxMLboxqLYBoUJGw5GIYBaSGFoo3GLApAOYCAUJQYycLYBCSHDIoUJYBfdYDwKDEwQFCBAbAfIwwHEFA6rKTpLAPEoQCDYEBgIFgzAMHwzAOXpDAkMIxALYD4wEAozAOaA7AKMIxAJVZjAWApLAOBxasGEYYZCIAyrOYCQlBYC4jGhpHCYBBpJAYSrSTp4FELQZmFYBoRDBQjAMGwvcHQYiEdBDANHgpTFApbALaYgWERpISGHYoJFYCo8JVBKAHFg5COAoY2JBI65IYBofHOYZmIYBxgGNIr4KSxJJHYCQfGCQhmIYBwjFPZDVKQg53IYCI8IBIgFIERgjEPZLVJEhHcAwUMYCo8IYBIfGAH4A/AHw")) diff --git a/apps/ncstart/start.js b/apps/ncstart/start.js deleted file mode 100644 index d2d713cb2..000000000 --- a/apps/ncstart/start.js +++ /dev/null @@ -1,120 +0,0 @@ -g.setFontAlign(1, 1, 0); -const d = g.getWidth() - 18; -function c(a) { - return { - width: 8, - height: a.length, - bpp: 1, - buffer: (new Uint8Array(a)).buffer - }; -} - -function welcome() { - var welcomes = [ - 'Welcome', - 'Failte', - 'Bienvenue', - 'Willkommen', - 'Bienvenido' - ]; - function next() { - var n = welcomes.shift(); - E.showMessage(n); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,116); - welcomes.push(n); - } - return new Promise((res) => { - next(); - var i = setInterval(next, 2000); - setWatch(() => { - clearInterval(i); - clearWatch(); - E.showMessage('Loading...'); - res(); - }, BTN2, {repeat:false}); - }); -} - -function logos() { - var logos = [ - ['nfr', 20, 90, ()=>{}], - ['nceu', 20, 90, ()=>{ - g.setFont("6x8", 2); - g.setColor(0,0,1); - g.drawString('Welcome To', 160, 110); - g.drawString('NodeConfEU', 160, 130); - g.drawString('2019', 200, 150); - }], - ['bangle', 70, 90, ()=>{}], - ['nodew', 20, 90, ()=>{}], - ['tf', 24, 90, ()=>{}], - ]; - function next() { - var n = logos.shift(); - var img = require("Storage").read("nc-"+n[0]+".img"); - g.clear(); - g.drawImage(img, n[1], n[2]); - n[3](); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,116); - logos.push(n); - } - return new Promise((res) => { - next(); - var i = setInterval(next, 2000); - setWatch(() => { - clearInterval(i); - clearWatch(); - res(); - }, BTN2, {repeat:false}); - }); -} - -function info() { - var slides = [ - () => E.showMessage('Visit\nnodewatch.dev\nfor info'), - () => E.showMessage('Visit\nbanglejs.com/apps\nfor apps'), - () => E.showMessage('Remember\nto charge\nyour watch!'), - () => { - g.clear(); - g.setFont('6x8',2); - g.setColor(1,1,1); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,40); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,194); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,116); - g.drawString('Menu Up', d - 50, 42); - g.drawString('Select', d - 40, 118); - g.drawString('Menu Down', d - 60, 196); - }, - () => { - g.clear(); - E.showMessage('Hold\nto return\nto clock'); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,194); - }, - () => { - g.clear(); - E.showMessage('Hold both\nto reboot'); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,40); - g.drawImage(c([0,8,12,14,255,14,12,8]),d,116); - }, - () => E.showMessage('Open Settings\nto enable\nBluetooth') - ]; - function next() { - var n = slides.shift(); - n(); - slides.push(n); - } - return new Promise((res) => { - next(); - var i = setInterval(next, 2000); - setWatch(()=>{ - clearInterval(i); - clearWatch(); - res(); - }, BTN2, {repeat:false}); - }); -} - -welcome() - .then(logos) - .then(info) - .then(load); diff --git a/apps/ncstart/start.png b/apps/ncstart/start.png deleted file mode 100644 index 9df0974c8..000000000 Binary files a/apps/ncstart/start.png and /dev/null differ diff --git a/apps/nixie/nixie.info b/apps/nixie/nixie.info deleted file mode 100644 index 66f5ff2a5..000000000 --- a/apps/nixie/nixie.info +++ /dev/null @@ -1,10 +0,0 @@ -{ -"id":"jvNixie", -"name":"Nixie Clock", -"type":"clock", -"src":"nixie.app.js", -"icon": "nixie.img", -"sortorder":1, -"version":"1.1", -"files":"nixie.info,nixie.app.js,nixie.img, m_vatch.js" -} diff --git a/apps/noteify/ChangeLog b/apps/noteify/ChangeLog index d7bc46dcd..a37a66731 100644 --- a/apps/noteify/ChangeLog +++ b/apps/noteify/ChangeLog @@ -1,2 +1,3 @@ 0.01: Initial version 0.02: Use default Bangle formatter for booleans +0.03: Drop duplicate alarm widget diff --git a/apps/noteify/README.md b/apps/noteify/README.md index c846709de..dbdceb399 100644 --- a/apps/noteify/README.md +++ b/apps/noteify/README.md @@ -1,6 +1,6 @@ # WARNING -This app uses the [Scheduler library](https://banglejs.com/apps/?id=sched) and requires a keyboard such as [Swipe keyboard](https://banglejs.com/apps/?id=kbswipe). +This app uses the [Scheduler library](https://banglejs.com/apps/?id=sched) and requires a [keyboard library](https://banglejs.com/apps/?c=textinput#). ## Usage diff --git a/apps/noteify/interface.html b/apps/noteify/interface.html index 027c98860..4d7974ad9 100644 --- a/apps/noteify/interface.html +++ b/apps/noteify/interface.html @@ -18,6 +18,11 @@ var notesElement = document.getElementById("notes"); var notes = {}; +function disableFormInput() { + document.querySelectorAll(".form-input").forEach(el => el.disabled = true); + document.querySelectorAll(".btn").forEach(el => el.disabled = true); +} + function getData() { // show loading window Util.showModal("Loading..."); @@ -53,8 +58,10 @@ function getData() { buttonSave.classList.add('btn-default'); buttonSave.onclick = function() { notes[i].note = textarea.value; - Util.writeStorage("noteify.json", JSON.stringify(notes)); - location.reload(); + disableFormInput(); + Util.writeStorage("noteify.json", JSON.stringify(notes), () => { + location.reload(); // reload so we see current data + }); } divColumn2.appendChild(buttonSave); @@ -64,8 +71,10 @@ function getData() { buttonDelete.onclick = function() { notes[i].note = textarea.value; notes.splice(i, 1); - Util.writeStorage("noteify.json", JSON.stringify(notes)); - location.reload(); // reload so we see current data + disableFormInput(); + Util.writeStorage("noteify.json", JSON.stringify(notes), () => { + location.reload(); // reload so we see current data + }); } divColumn2.appendChild(buttonDelete); divColumn.appendChild(divColumn2); @@ -77,8 +86,10 @@ function getData() { document.getElementById("btnAdd").addEventListener("click", function() { const note = document.getElementById("note-new").value; notes.push({"note": note}); - Util.writeStorage("noteify.json", JSON.stringify(notes)); - location.reload(); // reload so we see current data + disableFormInput(); + Util.writeStorage("noteify.json", JSON.stringify(notes), () => { + location.reload(); // reload so we see current data + }); }); }); } diff --git a/apps/noteify/metadata.json b/apps/noteify/metadata.json index eb6dc695a..850628c46 100644 --- a/apps/noteify/metadata.json +++ b/apps/noteify/metadata.json @@ -1,16 +1,15 @@ { "id": "noteify", "name": "Noteify", - "version": "0.02", + "version": "0.03", "description": "Write notes using an onscreen keyboard and use them as custom messages for alarms or timers.", "icon": "app.png", "tags": "tool,alarm", - "supports": ["BANGLEJS2"], + "supports": ["BANGLEJS", "BANGLEJS2"], "readme": "README.md", "storage": [ {"name":"noteify.app.js","url":"app.js"}, - {"name":"noteify.img","url":"app-icon.js","evaluate":true}, - {"name":"noteify.wid.js","url":"widget.js"} + {"name":"noteify.img","url":"app-icon.js","evaluate":true} ], "data": [{"name":"noteify.json"}], "dependencies": {"scheduler":"type","textinput":"type"}, diff --git a/apps/noteify/widget.js b/apps/noteify/widget.js deleted file mode 100644 index 052ac9ebd..000000000 --- a/apps/noteify/widget.js +++ /dev/null @@ -1,8 +0,0 @@ -WIDGETS["alarm"]={area:"tl",width:0,draw:function() { - if (this.width) g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y); - },reload:function() { - // don't include library here as we're trying to use as little RAM as possible - WIDGETS["alarm"].width = (require('Storage').readJSON('sched.json',1)||[]).some(alarm=>alarm.on&&(alarm.hidden!==false)) ? 24 : 0; - } -}; -WIDGETS["alarm"].reload(); diff --git a/apps/novaclock/ChangeLog b/apps/novaclock/ChangeLog new file mode 100644 index 000000000..8b05ff9ec --- /dev/null +++ b/apps/novaclock/ChangeLog @@ -0,0 +1,3 @@ +... +0.10: First update with ChangeLog Added +0.11: Tell clock widgets to hide. diff --git a/apps/novaclock/app.js b/apps/novaclock/app.js index e5bd37b06..52bee0dbd 100644 --- a/apps/novaclock/app.js +++ b/apps/novaclock/app.js @@ -249,13 +249,13 @@ var open = false; var timemode = true; var clockmode; var novaYPos = -7; +Bangle.setUI("clock"); g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); g.drawImage(nova(), -10, -10, { scale: 2.2 }); -Bangle.setUI("clock"); g.drawImage(star(), 5, -5, {scale:0.8}); g.drawImage(star(), -10, 120, {scale:0.8}); diff --git a/apps/novaclock/metadata.json b/apps/novaclock/metadata.json index c1dad60a1..69b7627f8 100644 --- a/apps/novaclock/metadata.json +++ b/apps/novaclock/metadata.json @@ -3,7 +3,7 @@ "shortName":"Nova Clock", "icon": "app.png", "type": "clock", - "version":"0.1", + "version":"0.11", "description": "A clock inspired by the Kirby series", "tags": "clock", "supports": ["BANGLEJS2"], diff --git a/apps/numberchaser/app-icon.js b/apps/numberchaser/app-icon.js new file mode 100644 index 000000000..a4bb5054d --- /dev/null +++ b/apps/numberchaser/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkA/4AC+c/AoYAR+QTTj4DBkYXS+YUB+cSl4YS+P/mUiL4RLQ+chiUziPyAAIXPmJEC+Ui+UhO6QABj8iVKocEACUTC60j+YXWPoZHTkcyC6sibYaPpC63ziXzkYXUkXyO6nykMykIXUl8xmcykQ2BSZ4XBkTXB+LdBMgPyDRnzj8vmf/AIMyDgMjAoIALiQSCVYI0CD4QAL+MTIILFCI4TJOmMRkUzn40CGQRLBMRipBiIABkR2DTAIAQmURF4KcBZScxn5qBACgWWbwUhMCT7CmU/WQQAR+awBF6jdBVggXSPCwXXVAPyJCkimUieKinBI6sxAQIvUeAMyMQIXT+MjI6iNC+RIT+bAB+cSYiZdBMQMzSCkf+ZIUGAMiYKsjkTbVkMSl4A==")) diff --git a/apps/numberchaser/app.js b/apps/numberchaser/app.js new file mode 100644 index 000000000..f68119fb2 --- /dev/null +++ b/apps/numberchaser/app.js @@ -0,0 +1,104 @@ +var randomNumber; +var guessNumber = 1; + +function mathRandomInt(a, b) { + if (a > b) { + // Swap a and b to ensure a is smaller. + var c = a; + a = b; + b = c; + } + return Math.floor(Math.random() * (b - a + 1) + a); +} + +/** + * Describe this function... + */ +function game() { + + g.drawString('',0,20,true); + E.showMenu(numMenu); + console.log(randomNumber); +} + +var numMenu = { + "" : { + "title" : "Number Chaser", + }, + "Guess Number" : { + value : guessNumber, + min:1,max:100,step:1, + onchange : v => { guessNumber=v; } + }, + "OK" : function () { + g.clear(); + if (guessNumber == randomNumber) { + //if guess is correct + g.setFont("Vector",13);g.setFontAlign(-1,-1); + status = "You won! "; + gameOver(); + } else { + //if guess is incorrect + g.setFont("Vector",13);g.setFontAlign(-1,-1); + if (guessNumber > randomNumber) { + //Decreases number if guess is greater + randomNumber = randomNumber - 1; + status = "Too high!"; + } else if (guessNumber < randomNumber) { + //Increases number if guess is lower + status = "Too low!"; + randomNumber = randomNumber + 1; + } + if (randomNumber < 0 || randomNumber > 100) { + //You lose when the number is out of the 1 to 100 range + g.setFont("Vector",13);g.setFontAlign(-1,-1); + g.drawString('You have lost\nNumber is out\nof range.',10,10,true); + status = "You lost!"; + } else { + g.drawString(status+"\nTry again!",10,10); + Bangle.on('tap', function() { + delay(3000).then(() => game()); + } + ); + } + } + } +}; + +function gameOver() +{ + E.showPrompt(status+'Play again?',{title:""+'Number Chaser'}).then(function(a) { + if (a) { + randomNumber = mathRandomInt(1, 100); + game(); + } else { + load(); + } + } + ); +} + +function delay(time) { + return new Promise(resolve => setTimeout(resolve, time)); +} + +function instructions() +{ + g.setFont("Vector",13);g.setFontAlign(-1,-1); + g.drawString('Guess the number\nbetween 1 and 100.\nGuess too high, it\ndecreases by 1.\nToo low, it increases\nby 1.\nIf the number\ngoes below 0 or\nabove 100, it\nis out of range\nand you have\nlost.',10,10,true); + randomNumber = mathRandomInt(1, 100); + delay(10000).then(() => game()); +} + + +g.clear(); +E.showPrompt('Do you need instructions?',{title:""+'Number Chaser'}).then(function(a) + { if (a) { + instructions(); + } else + { + randomNumber = mathRandomInt(1, 100); + game(); + } + } +); diff --git a/apps/numberchaser/metadata.json b/apps/numberchaser/metadata.json new file mode 100644 index 000000000..f9b6ff4b2 --- /dev/null +++ b/apps/numberchaser/metadata.json @@ -0,0 +1,13 @@ +{ "id": "numberchaser", + "name": "Number Chaser", + "shortName":"Number Chaser", + "version":"0.01", + "description": "A number guessing game, but the number goes up or down based on if you're guessing too high or too low.", + "icon": "numberchaser.png", + "tags": "game,fun", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"numberchaser.app.js","url":"app.js"}, + {"name":"numberchaser.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/numberchaser/numberchaser.png b/apps/numberchaser/numberchaser.png new file mode 100644 index 000000000..2042cc22b Binary files /dev/null and b/apps/numberchaser/numberchaser.png differ diff --git a/apps/openhaystack/ChangeLog b/apps/openhaystack/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/openhaystack/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/openhaystack/README.md b/apps/openhaystack/README.md new file mode 100644 index 000000000..e2d5e2212 --- /dev/null +++ b/apps/openhaystack/README.md @@ -0,0 +1,18 @@ +# OpenHaystack (AirTag) + +Copy a base64 key from https://github.com/seemoo-lab/openhaystack and make your Bangle.js trackable as if it's an AirTag + +Based on https://github.com/seemoo-lab/openhaystack/issues/59 + +## Usage + +* Follow the steps on https://github.com/seemoo-lab/openhaystack#how-to-use-openhaystack to install OpenHaystack and get a unique base64 code +* Click the ≡ icon next to `OpenHaystack (AirTag)` +* Paste in the base64 code +* Click `Upload` + +## Note + +This code changes your Bangle's MAC address, so while it still advertises with +the same `Bangle.js abcd` name, devices that were previously paired with it +won't automatically reconnect it until you re-pair. diff --git a/apps/openhaystack/custom.html b/apps/openhaystack/custom.html new file mode 100644 index 000000000..f56e94a98 --- /dev/null +++ b/apps/openhaystack/custom.html @@ -0,0 +1,56 @@ + + + + + + +

Follow the steps on https://github.com/seemoo-lab/openhaystack to install OpenHaystack and get a unique base64 code

+

Then paste the key in below and click Upload

+ +

Base64 key:

+

 

+ +

Click

+ + + + + + + diff --git a/apps/openhaystack/icon.png b/apps/openhaystack/icon.png new file mode 100644 index 000000000..f5e4f7f3b Binary files /dev/null and b/apps/openhaystack/icon.png differ diff --git a/apps/openhaystack/metadata.json b/apps/openhaystack/metadata.json new file mode 100644 index 000000000..5573529f7 --- /dev/null +++ b/apps/openhaystack/metadata.json @@ -0,0 +1,14 @@ +{ "id": "openhaystack", + "name": "OpenHaystack (AirTag)", + "icon": "icon.png", + "version":"0.01", + "description": "Copy a base64 key from https://github.com/seemoo-lab/openhaystack and make your Bangle.js trackable as if it's an AirTag", + "tags": "openhaystack,bluetooth,ble,tracking,airtag", + "type": "bootloader", + "custom": "custom.html", + "readme": "README.md", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"openhaystack.boot.js"} + ] +} diff --git a/apps/openstmap/ChangeLog b/apps/openstmap/ChangeLog index 6cb9d061e..7f788c139 100644 --- a/apps/openstmap/ChangeLog +++ b/apps/openstmap/ChangeLog @@ -10,3 +10,9 @@ 0.10: Improve scale factor calculation to fix scaling issues (#984) 0.11: Add slight offset to OSM data to align it properly (fix #984) Fix alignment of satellite info text +0.12: switch to using normal OpenStreetMap tiles (opentopomap was too slow) +0.13: Use a single image file with 'frames' of data (drastically reduces file count, possibility of >1 map on device) +0.14: Added ability to upload multiple sets of map tiles + Support for zooming in on map + Satellite count moved to widget bar to leave more room for the map +0.15: Make track drawing an option (default off) diff --git a/apps/openstmap/README.md b/apps/openstmap/README.md new file mode 100644 index 000000000..f19b13bd1 --- /dev/null +++ b/apps/openstmap/README.md @@ -0,0 +1,53 @@ +# OpenStreetMap + +This app allows you to upload and use OpenSteetMap map tiles onto your +Bangle. There's an uploader, the app, and also a library that +allows you to use the maps in your Bangle.js applications. + +## Uploader + +Once you've installed OpenStreepMap on your Bangle, find it +in the App Loader and click the Disk icon next to it. + +A window will pop up showing what maps you have loaded. + +To add a map: + +* Click `Add Map` +* Scroll and zoom to the area of interest or use the Search button in the top left +* Now choose the size you want to upload (Small/Medium/etc) +* On Bangle.js 1 you can choose if you want a 3 bits per pixel map (this is lower +quality but uploads faster and takes less space). On Bangle.js 2 you only have a 3bpp +display so can only use 3bpp. +* Click `Get Map`, and a preview will be displayed. If you need to adjust the area you +can change settings, move the map around, and click `Get Map` again. +* When you're ready, click `Upload` + +## Bangle.js App + +The Bangle.js app allows you to view a map - it also turns the GPS on and marks +the path that you've been travelling (if enabled). + +* Drag on the screen to move the map +* Press the button to bring up a menu, where you can zoom, go to GPS location +, put the map back in its default location, or choose whether to draw the currently +recording GPS track (from the `Recorder` app). + +**Note:** If enabled, drawing the currently recorded GPS track can take a second +or two (which happens after you've finished scrolling the screen with your finger). + + +## Library + +See the documentation in the library itself for full usage info: +https://github.com/espruino/BangleApps/blob/master/apps/openstmap/openstmap.js + +Or check the app itself: https://github.com/espruino/BangleApps/blob/master/apps/openstmap/app.js + +But in the most simple form: + +``` +var m = require("openstmap"); +// m.lat/lon are now the center of the loaded map +m.draw(); // draw centered on the middle of the loaded map +``` diff --git a/apps/openstmap/app.js b/apps/openstmap/app.js index 62597ca20..89e2d2ddb 100644 --- a/apps/openstmap/app.js +++ b/apps/openstmap/app.js @@ -1,20 +1,31 @@ var m = require("openstmap"); var HASWIDGETS = true; -var y1,y2; +var R; var fix = {}; +var mapVisible = false; +var hasScrolled = false; +var settings = require("Storage").readJSON("openstmap.json",1)||{}; +// Redraw the whole page function redraw() { - g.setClipRect(0,y1,g.getWidth()-1,y2); + g.setClipRect(R.x,R.y,R.x2,R.y2); m.draw(); drawMarker(); - if (WIDGETS["gpsrec"] && WIDGETS["gpsrec"].plotTrack) { - g.flip(); // force immediate draw on double-buffered screens - track will update later - g.setColor(0.75,0.2,0); - WIDGETS["gpsrec"].plotTrack(m); + // if track drawing is enabled... + if (settings.drawTrack) { + if (HASWIDGETS && WIDGETS["gpsrec"] && WIDGETS["gpsrec"].plotTrack) { + g.setColor("#f00").flip(); // force immediate draw on double-buffered screens - track will update later + WIDGETS["gpsrec"].plotTrack(m); + } + if (HASWIDGETS && WIDGETS["recorder"] && WIDGETS["recorder"].plotTrack) { + g.setColor("#f00").flip(); // force immediate draw on double-buffered screens - track will update later + WIDGETS["recorder"].plotTrack(m); + } } g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); } +// Draw the marker for where we are function drawMarker() { if (!fix.fix) return; var p = m.latLonToXY(fix.lat, fix.lon); @@ -22,50 +33,70 @@ function drawMarker() { g.fillRect(p.x-2, p.y-2, p.x+2, p.y+2); } -var fix; Bangle.on('GPS',function(f) { fix=f; - g.reset().clearRect(0,y1,g.getWidth()-1,y1+8).setFont("6x8").setFontAlign(0,0); - var txt = fix.satellites+" satellites"; - if (!fix.fix) - txt += " - NO FIX"; - g.drawString(txt,g.getWidth()/2,y1 + 4); - drawMarker(); + if (HASWIDGETS) WIDGETS["sats"].draw(WIDGETS["sats"]); + if (mapVisible) drawMarker(); }); Bangle.setGPSPower(1, "app"); if (HASWIDGETS) { Bangle.loadWidgets(); + WIDGETS["sats"] = { area:"tl", width:48, draw:w=>{ + var txt = (0|fix.satellites)+" Sats"; + if (!fix.fix) txt += "\nNO FIX"; + g.reset().setFont("6x8").setFontAlign(0,0) + .drawString(txt,w.x+24,w.y+12); + } + }; Bangle.drawWidgets(); - y1 = 24; - var hasBottomRow = Object.keys(WIDGETS).some(w=>WIDGETS[w].area[0]=="b"); - y2 = g.getHeight() - (hasBottomRow ? 24 : 1); -} else { - y1=0; - y2=g.getHeight()-1; } +R = Bangle.appRect; -redraw(); - -function recenter() { - if (!fix.fix) return; - m.lat = fix.lat; - m.lon = fix.lon; +function showMap() { + mapVisible = true; + g.reset().clearRect(R); redraw(); + Bangle.setUI({mode:"custom",drag:e=>{ + if (e.b) { + g.setClipRect(R.x,R.y,R.x2,R.y2); + g.scroll(e.dx,e.dy); + m.scroll(e.dx,e.dy); + g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); + hasScrolled = true; + } else if (hasScrolled) { + hasScrolled = false; + redraw(); + } + }, btn: btn=>{ + mapVisible = false; + var menu = {"":{title:"Map"}, + "< Back": ()=> showMap(), + /*LANG*/"Zoom In": () =>{ + m.scale /= 2; + showMap(); + }, + /*LANG*/"Zoom Out": () =>{ + m.scale *= 2; + showMap(); + }, + /*LANG*/"Draw Track": { + value : !!settings.drawTrack, + onchange : v => { settings.drawTrack=v; require("Storage").writeJSON("openstmap.json",settings); } + }, + /*LANG*/"Center Map": () =>{ + m.lat = m.map.lat; + m.lon = m.map.lon; + m.scale = m.map.scale; + showMap(); + }}; + if (fix.fix) menu[/*LANG*/"Center GPS"]=() =>{ + m.lat = fix.lat; + m.lon = fix.lon; + showMap(); + }; + E.showMenu(menu); + }}); } -setWatch(recenter, global.BTN2?BTN2:BTN1, {repeat:true}); - -var hasScrolled = false; -Bangle.on('drag',e=>{ - if (e.b) { - g.setClipRect(0,y1,g.getWidth()-1,y2); - g.scroll(e.dx,e.dy); - m.scroll(e.dx,e.dy); - g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); - hasScrolled = true; - } else if (hasScrolled) { - hasScrolled = false; - redraw(); - } -}); +showMap(); diff --git a/apps/openstmap/custom.html b/apps/openstmap/interface.html similarity index 51% rename from apps/openstmap/custom.html rename to apps/openstmap/interface.html index 6e79a6e9a..0bf2268a4 100644 --- a/apps/openstmap/custom.html +++ b/apps/openstmap/interface.html @@ -9,7 +9,8 @@ padding: 0; margin: 0; } - html, body, #map { + html, body, #map, #mapsLoaded, #mapContainer { + position: relative; height: 100%; width: 100%; } @@ -27,24 +28,46 @@ width: 256px; height: 256px; } + .tile-title { + font-weight:bold; + font-size: 125%; + } + .tile-map { + width: 128px; + height: 128px; + } -
+
-
-

3 bit
-
- - +
+
+
+
+

3 bit
+
+ +
+
+ + +
- + - - + + diff --git a/apps/openstmap/metadata.json b/apps/openstmap/metadata.json index 2dc9bd427..819dc4122 100644 --- a/apps/openstmap/metadata.json +++ b/apps/openstmap/metadata.json @@ -2,17 +2,21 @@ "id": "openstmap", "name": "OpenStreetMap", "shortName": "OpenStMap", - "version": "0.11", + "version": "0.15", "description": "Loads map tiles from OpenStreetMap onto your Bangle.js and displays a map of where you are. Once installed this also adds map functionality to `GPS Recorder` and `Recorder` apps", + "readme": "README.md", "icon": "app.png", "tags": "outdoors,gps,osm", "supports": ["BANGLEJS","BANGLEJS2"], "screenshots": [{"url":"screenshot.png"}], - "custom": "custom.html", - "customConnect": true, + "interface": "interface.html", "storage": [ {"name":"openstmap","url":"openstmap.js"}, {"name":"openstmap.app.js","url":"app.js"}, {"name":"openstmap.img","url":"app-icon.js","evaluate":true} + ], "data": [ + {"name":"openstmap.json"}, + {"wildcard":"openstmap.*.json"}, + {"wildcard":"openstmap.*.img"} ] } diff --git a/apps/openstmap/openstmap.js b/apps/openstmap/openstmap.js index d995aca25..692344357 100644 --- a/apps/openstmap/openstmap.js +++ b/apps/openstmap/openstmap.js @@ -20,34 +20,59 @@ function center() { m.draw(); } +// you can even change the scale - eg 'm/scale *= 2' + */ -var map = require("Storage").readJSON("openstmap.json"); -map.center = Bangle.project({lat:map.lat,lon:map.lon}); -exports.map = map; -exports.lat = map.lat; // actual position of middle of screen -exports.lon = map.lon; // actual position of middle of screen var m = exports; +m.maps = require("Storage").list(/openstmap\.\d+\.json/).map(f=>{ + let map = require("Storage").readJSON(f); + map.center = Bangle.project({lat:map.lat,lon:map.lon}); + return map; +}); +// we base our start position on the middle of the first map +m.map = m.maps[0]; +m.scale = m.map.scale; // current scale (based on first map) +m.lat = m.map.lat; // position of middle of screen +m.lon = m.map.lon; // position of middle of screen exports.draw = function() { - var s = require("Storage"); var cx = g.getWidth()/2; var cy = g.getHeight()/2; var p = Bangle.project({lat:m.lat,lon:m.lon}); - var ix = (p.x-map.center.x)/map.scale + (map.imgx/2) - cx; - var iy = (map.center.y-p.y)/map.scale + (map.imgy/2) - cy; - //console.log(ix,iy); - var tx = 0|(ix/map.tilesize); - var ty = 0|(iy/map.tilesize); - var ox = (tx*map.tilesize)-ix; - var oy = (ty*map.tilesize)-iy; - for (var x=ox,ttx=tx;x { + var d = map.scale/m.scale; + var ix = (p.x-map.center.x)/m.scale + (map.imgx*d/2) - cx; + var iy = (map.center.y-p.y)/m.scale + (map.imgy*d/2) - cy; + var o = {}; + var s = map.tilesize; + if (d!=1) { // if the two are different, add scaling + s *= d; + o.scale = d; } - } + //console.log(ix,iy); + var tx = 0|(ix/s); + var ty = 0|(iy/s); + var ox = (tx*s)-ix; + var oy = (ty*s)-iy; + var img = require("Storage").read(map.fn); + // fix out of range so we don't have to iterate over them + if (tx<0) { + ox+=s*-tx; + tx=0; + } + if (ty<0) { + oy+=s*-ty; + ty=0; + } + var mx = g.getWidth(); + var my = g.getHeight(); + for (var x=ox,ttx=tx; x { + if (!waiting){ + waiting = true; + require("owmweather").pull(completion); + } + }, 5000); + } + setInterval(() => { + if (!waiting && NRF.getSecurityStatus().connected){ + waiting = true; + require("owmweather").pull(completion); + } + }, settings.refresh * 1000 * 60); + } +} diff --git a/apps/owmweather/default.json b/apps/owmweather/default.json new file mode 100644 index 000000000..9d8998867 --- /dev/null +++ b/apps/owmweather/default.json @@ -0,0 +1 @@ +{"enabled":false,"refresh":180} diff --git a/apps/owmweather/interface.html b/apps/owmweather/interface.html new file mode 100644 index 000000000..3f9467a83 --- /dev/null +++ b/apps/owmweather/interface.html @@ -0,0 +1,63 @@ + + + + + +

Set OpenWeatherMap (OWM) API key

+

+ +

Where to get your personal API key?

+

Go to https://home.openweathermap.org/users/sign_up and sign up for a free account.
+ After registration you can login and optain your personal API key.

+ + + + + + + diff --git a/apps/owmweather/lib.js b/apps/owmweather/lib.js new file mode 100644 index 000000000..6ba52b498 --- /dev/null +++ b/apps/owmweather/lib.js @@ -0,0 +1,53 @@ +function parseWeather(response) { + let owmData = JSON.parse(response); + + let isOwmData = owmData.coord && owmData.weather && owmData.main; + + if (isOwmData) { + let json = require("Storage").readJSON('weather.json') || {}; + let weather = {}; + weather.time = Date.now(); + weather.hum = owmData.main.humidity; + weather.temp = owmData.main.temp; + weather.code = owmData.weather[0].id; + weather.wdir = owmData.wind.deg; + weather.wind = owmData.wind.speed; + weather.loc = owmData.name; + weather.txt = owmData.weather[0].main; + + if (weather.wdir != null) { + let deg = weather.wdir; + while (deg < 0 || deg > 360) { + deg = (deg + 360) % 360; + } + weather.wrose = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'n'][Math.floor((deg + 22.5) / 45)]; + } + + json.weather = weather; + require("Storage").writeJSON('weather.json', json); + require("weather").emit("update", json.weather); + return undefined; + } else { + return /*LANG*/"Not OWM data"; + } +} + +exports.pull = function(completionCallback) { + let location = require("Storage").readJSON("mylocation.json", 1) || { + "lat": 51.50, + "lon": 0.12, + "location": "London" + }; + let settings = require("Storage").readJSON("owmweather.json", 1); + let uri = "https://api.openweathermap.org/data/2.5/weather?lat=" + location.lat.toFixed(2) + "&lon=" + location.lon.toFixed(2) + "&exclude=hourly,daily&appid=" + settings.apikey; + if (Bangle.http){ + Bangle.http(uri, {timeout:10000}).then(event => { + let result = parseWeather(event.resp); + if (completionCallback) completionCallback(result); + }).catch((e)=>{ + if (completionCallback) completionCallback(e); + }); + } else { + if (completionCallback) completionCallback(/*LANG*/"No http method found"); + } +}; diff --git a/apps/owmweather/metadata.json b/apps/owmweather/metadata.json new file mode 100644 index 000000000..56f9afca7 --- /dev/null +++ b/apps/owmweather/metadata.json @@ -0,0 +1,22 @@ +{ "id": "owmweather", + "name": "OpenWeatherMap weather provider", + "shortName":"OWM Weather", + "version":"0.02", + "description": "Pulls weather from OpenWeatherMap (OWM) API", + "icon": "app.png", + "type": "bootloader", + "tags": "boot,tool,weather", + "supports" : ["BANGLEJS2"], + "interface": "interface.html", + "readme": "README.md", + "data": [ + {"name":"owmweather.json"}, + {"name":"weather.json"} + ], + "storage": [ + {"name":"owmweather.default.json","url":"default.json"}, + {"name":"owmweather.boot.js","url":"boot.js"}, + {"name":"owmweather","url":"lib.js"}, + {"name":"owmweather.settings.js","url":"settings.js"} + ] +} diff --git a/apps/owmweather/settings.js b/apps/owmweather/settings.js new file mode 100644 index 000000000..a4d21dd7c --- /dev/null +++ b/apps/owmweather/settings.js @@ -0,0 +1,84 @@ +(function(back) { + function writeSettings(key, value) { + var s = require('Storage').readJSON(FILE, true) || {}; + s[key] = value; + require('Storage').writeJSON(FILE, s); + readSettings(); + } + + function readSettings(){ + settings = Object.assign( + require('Storage').readJSON("owmweather.default.json", true) || {}, + require('Storage').readJSON(FILE, true) || {} + ); + } + + var FILE="owmweather.json"; + var settings; + readSettings(); + + function buildMainMenu(){ + var mainmenu = { + '': { 'title': 'OWM weather' }, + '< Back': back, + "Enabled": { + value: !!settings.enabled, + onchange: v => { + writeSettings("enabled", v); + } + }, + "Refresh every": { + value: settings.refresh / 60, + min: 1, + max: 48, + step: 1, + format: v=>v+"h", + onchange: v => { + writeSettings("refresh",Math.round(v * 60)); + } + }, + "Force refresh": ()=>{ + if (!settings.apikey){ + E.showAlert("API key is needed","Hint").then(()=>{ + E.showMenu(buildMainMenu()); + }); + } else { + E.showMessage("Reloading weather"); + require("owmweather").pull((e)=>{ + if (e) { + E.showAlert(e,"Error").then(()=>{ + E.showMenu(buildMainMenu()); + }); + } else { + E.showAlert("Success").then(()=>{ + E.showMenu(buildMainMenu()); + }); + } + }); + } + } + }; + + mainmenu["API key"] = function (){ + if (require("textinput")){ + require("textinput").input({text:settings.apikey}).then(result => { + if (result != "") { + print("Result is", result); + settings.apikey = result; + writeSettings("apikey",result); + } + E.showMenu(buildMainMenu()); + }); + } else { + E.showPrompt("Install a text input lib"),then(()=>{ + E.showMenu(buildMainMenu()); + }); + } + }; + + + return mainmenu; + } + + E.showMenu(buildMainMenu()); +}); diff --git a/apps/palikkainen/ChangeLog b/apps/palikkainen/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/palikkainen/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/palikkainen/README.md b/apps/palikkainen/README.md new file mode 100644 index 000000000..81d857209 --- /dev/null +++ b/apps/palikkainen/README.md @@ -0,0 +1,7 @@ +# Palikkainen + +By Jukio Kallio + +A minimal watch face consisting of blocks. Minutes fills the blocks, and after 12 hours it starts to empty them. + +![](screenshot1.png) diff --git a/apps/palikkainen/app-icon.js b/apps/palikkainen/app-icon.js new file mode 100644 index 000000000..a99602121 --- /dev/null +++ b/apps/palikkainen/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkBiIA0/4AKCpMfCxYAB+ItTGJQuOGBAWPGAwuQGAwXvCyJgFC+PwgAAEh4X/C/6//A4gX/C/6//A4QX/C/6/vC6sfCyPxC+ZgSCwgwRFwowRCwwwPFw4xOCpIArA")) diff --git a/apps/palikkainen/app.js b/apps/palikkainen/app.js new file mode 100644 index 000000000..42013af69 --- /dev/null +++ b/apps/palikkainen/app.js @@ -0,0 +1,184 @@ +// Palikkainen +// +// Bangle.js 2 watch face +// by Jukio Kallio +// www.jukiokallio.com + +require("Font6x8").add(Graphics); + +// settings +const watch = { + x:0, y:0, w:0, h:0, + bgcolor:g.theme.bg, + fgcolor:g.theme.fg, + font: "6x8", fontsize: 1, + finland:true, // change if you want Finnish style date, or US style +}; + +// set some additional settings +watch.w = g.getWidth(); // size of the background +watch.h = g.getHeight(); +watch.x = watch.w * 0.5; // position of the circles +watch.y = watch.h * 0.45; + +const dateWeekday = { 0: "SUN", 1: "MON", 2: "TUE", 3: "WED", 4:"THU", 5:"FRI", 6:"SAT" }; // weekdays + +var wait = 60000; // wait time, normally a minute + + +// timeout used to update every minute +var drawTimeout; + +// schedule a draw for the next minute +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, wait - (Date.now() % wait)); +} + + +// main function +function draw() { + // make date object + var date = new Date(); + + // work out the date string + var dateDay = date.getDate(); + var dateMonth = date.getMonth() + 1; + var dateYear = date.getFullYear(); + var dateStr = dateWeekday[date.getDay()] + " " + dateMonth + "." + dateDay + "." + dateYear; + if (watch.finland) dateStr = dateWeekday[date.getDay()] + " " + dateDay + "." + dateMonth + "." + dateYear; // the true way of showing date + + // Reset the state of the graphics library + g.reset(); + + // Clear the area where we want to draw the time + g.setColor(watch.bgcolor); + g.fillRect(0, 0, watch.w, watch.h); + + // setup watch face + const block = { + w: watch.w / 2 - 6, + h: 18, + pad: 4, + }; + + // get hours and minutes + var hour = date.getHours(); + var minute = date.getMinutes(); + + // calculate size of the block face + var facew = block.w * 2 + block.pad; + var faceh = (block.h + block.pad) * 6; + + + // loop through first 12 hours and draw blocks accordingly + g.setColor(watch.fgcolor); // set foreground color + + for (var i = 0; i < 12; i++) { + // where to draw + var x = watch.x - facew / 2; // starting position + var y = watch.y + faceh / 2 - block.h - block.pad / 2; // draw blocks from bottom up + if (i > 5) { + // second column + x += block.w + block.pad; + y -= (block.h + block.pad) * (i - 6); + } else { + // first column + x += 0; + y -= (block.h + block.pad) * i; + } + + if (i < hour) { + // draw full hour block + g.fillRect(x, y, x + block.w, y + block.h); + } else if (i == hour) { + // draw minutes + g.fillRect(x, y, x + block.w * (minute / 60), y + block.h); + + // minute reading help + for (var m = 1; m < 12; m++) { + // set color + if (m * 5 < minute) g.setColor(watch.bgcolor); else g.setColor(watch.fgcolor); + + var mlineh = 1; // minute line height + if (m == 3 || m == 6 || m == 9) mlineh = 3; // minute line height at 15, 30 and 45 minutes + + g.drawLine(x + (block.w / 12 * m), y + block.h / 2 - mlineh, x + (block.w / 12 * m), y + block.h / 2 + mlineh); + } + } + } + + + // loop through second 12 hours and draw blocks accordingly + if (hour >= 12) { + g.setColor(watch.bgcolor); // set foreground color + + for (var i2 = 0; i2 < 12; i2++) { + // where to draw + var x2 = watch.x - facew / 2; // starting position + var y2 = watch.y + faceh / 2 - block.h - block.pad / 2; // draw blocks from bottom up + if (i2 > 5) { + // second column + x2 += block.w + block.pad; + y2 -= (block.h + block.pad) * (i2 - 6); + } else { + // first column + x2 += 0; + y2 -= (block.h + block.pad) * i2; + } + + if (i2 < hour % 12) { + // draw full hour block + g.fillRect(x2, y2, x2 + block.w, y2 + block.h); + } else if (i2 == hour % 12) { + // draw minutes + g.fillRect(x2, y2, x2 + block.w * (minute / 60), y2 + block.h); + + // minute reading help + for (var m2 = 1; m2 < 12; m2++) { + // set color + if (m2 * 5 < minute) g.setColor(watch.fgcolor); else g.setColor(watch.bgcolor); + + var mlineh2 = 1; // minute line height + if (m2 == 3 || m2 == 6 || m2 == 9) mlineh2 = 3; // minute line height at 15, 30 and 45 minutes + + g.drawLine(x2 + (block.w / 12 * m2), y2 + block.h / 2 - mlineh2, x2 + (block.w / 12 * m2), y2 + block.h / 2 + mlineh2); + } + } + } + } + + + // draw date + var datey = 11; + g.setFontAlign(0,-1).setFont(watch.font, watch.fontsize).setColor(watch.fgcolor); + g.drawString(dateStr, watch.x, watch.y + faceh / 2 + datey); + + + // queue draw + queueDraw(); +} + + +// Clear the screen once, at startup +g.clear(); +// draw immediately at first +draw(); + + +// Stop updates when LCD is off, restart when on +Bangle.on('lcdPower',on=>{ + if (on) { + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); + + +// Show launcher when middle button pressed +Bangle.setUI("clock"); diff --git a/apps/palikkainen/app.png b/apps/palikkainen/app.png new file mode 100644 index 000000000..142d429e9 Binary files /dev/null and b/apps/palikkainen/app.png differ diff --git a/apps/palikkainen/metadata.json b/apps/palikkainen/metadata.json new file mode 100644 index 000000000..4ed8be817 --- /dev/null +++ b/apps/palikkainen/metadata.json @@ -0,0 +1,16 @@ +{ "id": "palikkainen", + "name": "Palikkainen - A blocky watch face", + "shortName":"Palikkainen", + "version":"0.01", + "description": "A minimal watch face consisting of blocks.", + "icon": "app.png", + "screenshots": [{"url":"screenshot1.png"}], + "type": "clock", + "tags": "clock", + "supports" : ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"palikkainen.app.js","url":"app.js"}, + {"name":"palikkainen.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/palikkainen/screenshot1.png b/apps/palikkainen/screenshot1.png new file mode 100644 index 000000000..43a630d59 Binary files /dev/null and b/apps/palikkainen/screenshot1.png differ diff --git a/apps/pastel/ChangeLog b/apps/pastel/ChangeLog index f4640426b..02cef7774 100644 --- a/apps/pastel/ChangeLog +++ b/apps/pastel/ChangeLog @@ -18,3 +18,5 @@ added setting to enable/disable idle timer warning 0.16: make check_idle boolean setting work properly with new B2 menu 0.17: Use default Bangle formatter for booleans +0.18: fix idle option always getting defaulted to true +0.19: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps diff --git a/apps/pastel/metadata.json b/apps/pastel/metadata.json index 1fe176d5f..cf4bbbe9b 100644 --- a/apps/pastel/metadata.json +++ b/apps/pastel/metadata.json @@ -2,7 +2,7 @@ "id": "pastel", "name": "Pastel Clock", "shortName": "Pastel", - "version": "0.17", + "version": "0.19", "description": "A Configurable clock with custom fonts, background and weather display. Has a cyclic information line that includes, day, date, battery, sunrise and sunset times", "icon": "pastel.png", "dependencies": {"mylocation":"app","weather":"app"}, diff --git a/apps/pastel/pastel.app.js b/apps/pastel/pastel.app.js index 605b78ad0..bc41588d8 100644 --- a/apps/pastel/pastel.app.js +++ b/apps/pastel/pastel.app.js @@ -1,4 +1,4 @@ -var SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js"); +var SunCalc = require("suncalc"); // from modules folder require("f_latosmall").add(Graphics); const storage = require('Storage'); const locale = require("locale"); @@ -34,7 +34,7 @@ function loadSettings() { settings = require("Storage").readJSON(SETTINGS_FILE,1)||{}; settings.grid = settings.grid||false; settings.font = settings.font||"Lato"; - settings.idle_check = settings.idle_check||true; + settings.idle_check = (settings.idle_check === undefined ? true : settings.idle_check); } // requires the myLocation app @@ -85,7 +85,7 @@ function getSteps() { try { return Bangle.getHealthStatus("day").steps; } catch (e) { - if (WIDGETS.wpedom !== undefined) + if (WIDGETS.wpedom !== undefined) return WIDGETS.wpedom.getSteps(); else return '???'; @@ -181,12 +181,12 @@ function drawClock() { var d = new Date(); var da = d.toString().split(" "); var time = da[4].substr(0,5); - + var hh = da[4].substr(0,2); var mm = da[4].substr(3,2); var day = da[0]; var month_day = da[1] + " " + da[2]; - + // fix hh for 12hr clock var h2 = "0" + parseInt(hh) % 12 || 12; if (parseInt(hh) > 12) @@ -215,12 +215,12 @@ function drawClock() { g.reset(); g.setColor(g.theme.bg); g.fillRect(Bangle.appRect); - + // draw a grid like graph paper if (settings.grid && process.env.HWVERSION !=1) { g.setColor("#0f0"); for (var gx=20; gx <= w; gx += 20) - g.drawLine(gx, 30, gx, h - 24); + g.drawLine(gx, 30, gx, h - 24); for (var gy=30; gy <= h - 24; gy += 20) g.drawLine(0, gy, w, gy); } @@ -238,7 +238,7 @@ function drawClock() { g.drawString( (w_wind.split(' ').slice(0, 2).join(' ')), (w/2) + 6, 24 + ((y - 24)/2)); // display first 2 words of the wind string eg '4 mph' } - + if (settings.font == "Architect") g.setFontArchitect(); else if (settings.font == "GochiHand") @@ -253,7 +253,7 @@ function drawClock() { g.setFontSpecialElite(); else g.setFontLato(); - + g.setFontAlign(1,-1); // right aligned g.drawString(hh, x - 6, y); g.setFontAlign(-1,-1); // left aligned @@ -310,7 +310,7 @@ function BUTTON(name,x,y,w,h,c,f,tx) { // if pressed the callback BUTTON.prototype.check = function(x,y) { //console.log(this.name + ":check() x=" + x + " y=" + y +"\n"); - + if (x>= this.x && x<= (this.x + this.w) && y>= this.y && y<= (this.y + this.h)) { log_debug(this.name + ":callback\n"); this.callback(); @@ -366,7 +366,7 @@ function checkIdle() { warned = false; return; } - + let hour = (new Date()).getHours(); let active = (hour >= 9 && hour < 21); //let active = true; @@ -397,7 +397,7 @@ function buzzer(n) { if (n-- < 1) return; Bangle.buzz(250); - + if (buzzTimeout) clearTimeout(buzzTimeout); buzzTimeout = setTimeout(function() { buzzTimeout = undefined; diff --git a/apps/pebble/ChangeLog b/apps/pebble/ChangeLog index 274c34a34..9c21e09bc 100644 --- a/apps/pebble/ChangeLog +++ b/apps/pebble/ChangeLog @@ -8,3 +8,6 @@ 0.08: Add theme options and optional lock symbol 0.09: Add support for internationalization (LANG placeholders + "locale" module) Get steps from built-in step counter (widpedom no more needed, fix #1697) +0.10: Tell clock widgets to hide. +0.11: Swipe down to see widgets + Support for fast loading diff --git a/apps/pebble/metadata.json b/apps/pebble/metadata.json index f3c1fcc12..0ccb8e2af 100644 --- a/apps/pebble/metadata.json +++ b/apps/pebble/metadata.json @@ -2,7 +2,7 @@ "id": "pebble", "name": "Pebble Clock", "shortName": "Pebble", - "version": "0.09", + "version": "0.11", "description": "A pebble style clock to keep the rebellion going", "readme": "README.md", "icon": "pebble.png", diff --git a/apps/pebble/pebble.app.js b/apps/pebble/pebble.app.js index 774b24c3f..48acbae87 100644 --- a/apps/pebble/pebble.app.js +++ b/apps/pebble/pebble.app.js @@ -1,22 +1,24 @@ Graphics.prototype.setFontLECO1976Regular42 = function(scale) { // Actual height 42 (41 - 0) g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAA/AAAAAAAAH/AAAAAAAA//AAAAAAAP//AAAAAAB///AAAAAAP///AAAAAB////AAAAAf////AAAAD////4AAAAf////AAAAH////4AAAA////+AAAAA////wAAAAA///+AAAAAA///gAAAAAA//8AAAAAAA//gAAAAAAA/4AAAAAAAA/AAAAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAH/AAAAAAAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//h////AAA//h////AAA//h////AAA//h////AAA//h////AAA//h////AAA//h////AAA//h////AAA//h////AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////gD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4AAAH/AAA/4B/gH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////wAAAAA////wAAAAA////wAAAAA////wAAAAA////wAAAAA////wAAAAA////wAAAAA////wAAAAA////wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAAAAB/wAAAAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////x//AAA////x//AAA////x//AAA////x//AAA////x//AAA////x//AAA////x//AAA////x//AAA////x//AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/wB////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/4B////AAA/wB////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//gAAAAAAA//gAAAAAAA//gAAAAAAA//gAAAAAAA//gAAAAAAA//gAAAAAAA//gAAAAAAA//gAAAAAAA//gAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA/4AAAAAAAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA////wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA/4B/wH/AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAA///////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP+AAH/AAAAP+AAH/AAAAP+AAH/AAAAP+AAH/AAAAP+AAH/AAAAP+AAH/AAAAP+AAH/AAAAP+AAH/AAAAH+AAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), 46, atob("ERkmHyYmJiYmJCYmEQ=="), 60+(scale<<8)+(1<<16)); -} +}; Graphics.prototype.setFontLECO1976Regular22 = function(scale) { // Actual height 22 (21 - 0) g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/nA/+cD/5wP/nAAAAAAAAPwAA/gAD+AAPwAAAAAD+AAP4AA/gAAAAAAAAAAAAAcOAP//A//8D//wP//AHDgAcOAP//A//8D//wP//AHDgAAAAAAAAH/jgf+OB/44H/jj8OP/w4//Dj/8OPxw/4HD/gcP+Bw/4AAAAAAAP+AA/8AD/wQOHHA4c8D//wP/8A//gAD4AAfAAH/8A//wP//A84cDjhwIP/AA/8AB/wAAAAAAAD//wP//A//8D//wOHHA4ccDhxwOHHA4f8Dh/wOH/A4f8ABwAAAAAAAAD8AAP4AA/gAD8AAAAAAAAAAAEAAD+AB//A///v/D//gB/wABwAAAAAADgAA/wAf/4P8///wf/4AP8AAOAAAAAAAAAyAAHcAAPwAD/gAP/AA/8AA/AAH8AAMwAAAAAAAAAAAAADgAAOAAA4AAf8AD/wAP/AA/8AAOAAA4AADgAAAAAAAAAAD8AAfwAB/AAD8AAAAAAAADgAAOAAA4AADgAAOAAA4AADgAAAAAAAAAADgAAOAAA4AADgAAAAAAAAABwAB/AA/8A//gP/gA/wADwAAIAAAAAAD//wP//A//8D//wOAHA4AcDgBwOAHA//8D//wP//A//8AAAAAAAA4AcDgBwOAHA//8D//wP//A//8AABwAAHAAAcAAAAAAAA+f8D5/wPn/A+f8DhxwOHHA4ccDhxwP/HA/8cD/xwP/HAAAAAAAAOAHA4AcDhxwOHHA4ccDhxwOHHA4ccD//wP//A//8D//wAAAAAAAD/wAP/AA/8AD/wAAHAAAcAABwAAHAA//8D//wP//A//8AAAAAAAA/98D/3wP/fA/98DhxwOHHA4ccDhxwOH/A4f8Dh/wOH/AAAAAAAAP//A//8D//wP//A4ccDhxwOHHA4ccDh/wOH/A4f8Dh/wAAAAAAAD4AAPgAA+AADgAAOAAA4AADgAAP//A//8D//wP//AAAAAAAAP//A//8D//wP//A4ccDhxwOHHA4ccD//wP//A//8D//wAAAAAAAD/xwP/HA/8cD/xwOHHA4ccDhxwOHHA//8D//wP//A//8AAAAAAAAOA4A4DgDgOAOA4AAAAAAAAOA/A4H8DgfwOA/AAAAAAAAB4AAPwAA/AAD8AAf4ABzgAPPAA8cAHh4AAAAAAAAAAAAHHAAccABxwAHHAAccABxwAHHAAccABxwAHHAAAAAAAAAOHAA4cADzwAPPAAf4AB/gAD8AAPwAAeAAB4AAAAAAAAA+AAD4AAPgAA+ecDh9wOH3A4fcDhwAP/AA/8AD/wAP/AAAAAAAAAP//4///j//+P//44ADjn/OOf845/zjnHOP8c4//zj//OP/84AAAAAAAP//A//8D//wP//A4cADhwAOHAA4cAD//wP//A//8D//wAAAAAAAD//wP//A//8D//wOHHA4ccDhxwOHHA//8D//wP9/A/j8AAAAAAAA//8D//wP//A//8DgBwOAHA4AcDgBwOAHA4AcDgBwOAHAAAAAAAAP//A//8D//wP//A4AcDgBwOAHA8A8D//wH/+AP/wAf+AAAAAAAAD//wP//A//8D//wOHHA4ccDhxwOHHA4ccDhxwOAHA4AcAAAAAAAA//8D//wP//A//8DhwAOHAA4cADhwAOHAA4cADgAAOAAAAAAD//wP//A//8D//wOAHA4ccDhxwOHHA4f8Dh/wOH/A4f8AAAAAAAA//8D//wP//A//8ABwAAHAAAcAABwAP//A//8D//wP//AAAAAAAAP//A//8D//wP//AAAAAAAAOAHA4AcDgBwOAHA4AcDgBwOAHA//8D//wP//A//8AAAAAAAA//8D//wP//A//8AHwAA/AAP8AB/wAPn/A8f8DB/wIH/AAAAAAAAP//A//8D//wP//AAAcAABwAAHAAAcAABwAAHAAAAAAAAP//A//8D//wP//Af8AAP+AAH/AAD8AAHwAD/AB/wAf8AP+AA//8D//wP//AAAAAAAAP//A//8D//wP//AfwAAfwAAfwAAfwAAfwP//A//8D//wAAAAAAAAAAAP//A//8D//wP//A4AcDgBwOAHA4AcD//wP//A//8D//wAAAAAAAD//wP//A//8D//wOHAA4cADhwAOHAA/8AD/wAP/AA/8AAAAAP//A//8D//wP//A4AcDgBwOAHA4AcD//+P//4///j//+AAA4AADgAAAP//A//8D//wP//A4eADh+AOH8A4f4D/3wP/HA/8MD/wQAAAAAAAD/xwP/HA/8cD/xwOHHA4ccDhxwOHHA4f8Dh/wOH/A4f8AAAAAAAA4AADgAAOAAA//8D//wP//A//8DgAAOAAA4AADgAAAAAA//8D//wP//A//8AABwAAHAAAcAABwP//A//8D//wP//AAAADAAAPgAA/wAD/4AB/8AA/8AAfwAB/AA/8Af+AP/AA/wAD4AAMAAA4AAD+AAP/gA//8AH/wAB/AAf8Af/wP/4A/4AD/gAP/4AH/8AB/wAB/AB/8D//wP/gA/gADgAAIABA4AcDwDwPw/Afn4Af+AA/wAD/AA//AH5+A/D8DwDwOAHAgAEAAAAP/AA/8AD/wAP/AAAf8AB/wAH/AAf8D/wAP/AA/8AD/wAAAAAAAADh/wOH/A4f8Dh/wOHHA4ccDhxwOHHA/8cD/xwP/HA/8cAAAAAAAAf//9///3///f//9wAA3AADcAAMAAAOAAA/gAD/wAH/8AB/8AA/wAAPAAAEAAAAHAADcAANwAB3///f//9///wAA"), 32, atob("BwYLDg4UDwYJCQwMBgkGCQ4MDg4ODg4NDg4GBgwMDA4PDg4ODg4NDg4GDQ4MEg8ODQ8ODgwODhQODg4ICQg="), 22+(scale<<8)+(1<<16)); -} +}; +{ const SETTINGS_FILE = "pebble.json"; let settings; let theme; +let drawTimeout; -function loadSettings() { +let loadSettings = function() { settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#0f0', 'color': 'Green', 'theme':'System', 'showlock':false}; -} +}; -var img = require("heatshrink").decompress(atob("oFAwkEogA/AH4A/AH4A/AH4A/AE8AAAoeXoAfeDQUBmcyD7A+Dh///8QD649CiAfaHwUvD4sEHy0DDYIfEICg+Cn4fHICY+DD4nxcgojOHwgfEIAYfRCIQaDD4ZAFD5r7DH4//kAfRCIZ/GAAnwD5p9DX44fTHgYSBf4ofVDAQEBl4fFUAgfOXoQzBgIfFBAIfPP4RAEAoYAB+cRiK/SG4h/WIBAfXIA7CBAAswD55AHn6fUIBMCD65AHl4gCmcziAfQQJqfQQJpiDgk0IDXxQLRAEECaBM+QgRYRYgUIA0CD4ggSQJiDCiAKBICszAAswD55AHABKBVD7BAFABIqBD5pAFABPxD55AOD6BADiIAJQAyxLABwf/gaAPAH4A/AH4ARA==")); +const img = require("heatshrink").decompress(atob("oFAwkEogA/AH4A/AH4A/AH4A/AE8AAAoeXoAfeDQUBmcyD7A+Dh///8QD649CiAfaHwUvD4sEHy0DDYIfEICg+Cn4fHICY+DD4nxcgojOHwgfEIAYfRCIQaDD4ZAFD5r7DH4//kAfRCIZ/GAAnwD5p9DX44fTHgYSBf4ofVDAQEBl4fFUAgfOXoQzBgIfFBAIfPP4RAEAoYAB+cRiK/SG4h/WIBAfXIA7CBAAswD55AHn6fUIBMCD65AHl4gCmcziAfQQJqfQQJpiDgk0IDXxQLRAEECaBM+QgRYRYgUIA0CD4ggSQJiDCiAKBICszAAswD55AHABKBVD7BAFABIqBD5pAFABPxD55AOD6BADiIAJQAyxLABwf/gaAPAH4A/AH4ARA==")); const h = g.getHeight(); const w = g.getWidth(); @@ -26,7 +28,7 @@ const h3 = 7*h/8; let batteryWarning = false; -function draw() { +let draw = function() { let locale = require("locale"); let date = new Date(); let dayOfWeek = locale.dow(date, 1).toUpperCase(); @@ -81,10 +83,16 @@ function draw() { drawCalendar(((w/2) - 42)/2, 14, 42, 4, dayOfMonth); drawLock(); -} + // queue next draw + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +}; // at x,y width:wi thicknes:th -function drawCalendar(x,y,wi,th,str) { +let drawCalendar = function(x,y,wi,th,str) { g.setColor(theme.fg); g.fillRect(x, y, x + wi, y + wi); g.setColor(theme.bg); @@ -100,9 +108,9 @@ function drawCalendar(x,y,wi,th,str) { g.setFontLECO1976Regular22(); g.setFontAlign(0, 0); g.drawString(str, x + wi/2, y + wi/2 + th); -} +}; -function loadThemeColors() { +let loadThemeColors = function() { theme = {fg: g.theme.fg, bg: g.theme.bg, day: g.toColor(0,0,0)}; if (settings.theme === "Dark") { theme.fg = g.toColor(1,1,1); @@ -114,9 +122,9 @@ function loadThemeColors() { // day and steps if (settings.color == 'Blue' || settings.color == 'Red') theme.day = g.toColor(1,1,1); // white on blue or red best contrast -} +}; -function drawLock(){ +let drawLock = function(){ if (settings.showlock) { if (Bangle.isLocked()){ g.setColor(theme.day); @@ -127,26 +135,28 @@ function drawLock(){ g.fillRect(0, 0, 20, 20); } } -} +}; -Bangle.on('lock', function(on) { - drawLock(); -}); +Bangle.on('lock', drawLock); + +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app + Bangle.removeListener('lock', drawLock); + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFontLECO1976Regular22; + delete Graphics.prototype.setFontLECO1976Regular42; + require("widget_utils").show(); // re-show widgets + }}); g.clear(); Bangle.loadWidgets(); - -// We are not drawing the widgets as we are taking over the whole screen -// so we will blank out the draw() functions of each widget and change the -// area to the top bar doesn't get cleared. -for (let wd of WIDGETS) { - wd.draw=()=>{}; - wd.area=""; -} +require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe loadSettings(); loadThemeColors(); -setInterval(draw, 15000); // refresh every 15s draw(); - -Bangle.setUI("clock"); +} diff --git a/apps/pebbled/ChangeLog b/apps/pebbled/ChangeLog index 9db0e26c5..d2f71f908 100644 --- a/apps/pebbled/ChangeLog +++ b/apps/pebbled/ChangeLog @@ -1 +1,4 @@ 0.01: first release +0.02: Tell clock widgets to hide. +0.03: Swipe down to see widgets + Support for fast loading diff --git a/apps/pebbled/metadata.json b/apps/pebbled/metadata.json index c16025f6f..9e71a914b 100644 --- a/apps/pebbled/metadata.json +++ b/apps/pebbled/metadata.json @@ -2,7 +2,7 @@ "id": "pebbled", "name": "Pebble Clock with distance", "shortName": "Pebble + distance", - "version": "0.01", + "version": "0.03", "description": "Fork of Pebble Clock with distance in KM. Both step count and the distance are on the main screen. Default step length = 0.75m (can be changed in settings).", "readme": "README.md", "icon": "pebbled.png", diff --git a/apps/pebbled/pebbled.app.js b/apps/pebbled/pebbled.app.js index bbe98823f..627a7651c 100644 --- a/apps/pebbled/pebbled.app.js +++ b/apps/pebbled/pebbled.app.js @@ -8,14 +8,16 @@ Graphics.prototype.setFontLECO1976Regular22 = function(scale) { g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/nA/+cD/5wP/nAAAAAAAAPwAA/gAD+AAPwAAAAAD+AAP4AA/gAAAAAAAAAAAAAcOAP//A//8D//wP//AHDgAcOAP//A//8D//wP//AHDgAAAAAAAAH/jgf+OB/44H/jj8OP/w4//Dj/8OPxw/4HD/gcP+Bw/4AAAAAAAP+AA/8AD/wQOHHA4c8D//wP/8A//gAD4AAfAAH/8A//wP//A84cDjhwIP/AA/8AB/wAAAAAAAD//wP//A//8D//wOHHA4ccDhxwOHHA4f8Dh/wOH/A4f8ABwAAAAAAAAD8AAP4AA/gAD8AAAAAAAAAAAEAAD+AB//A///v/D//gB/wABwAAAAAADgAA/wAf/4P8///wf/4AP8AAOAAAAAAAAAyAAHcAAPwAD/gAP/AA/8AA/AAH8AAMwAAAAAAAAAAAAADgAAOAAA4AAf8AD/wAP/AA/8AAOAAA4AADgAAAAAAAAAAD8AAfwAB/AAD8AAAAAAAADgAAOAAA4AADgAAOAAA4AADgAAAAAAAAAADgAAOAAA4AADgAAAAAAAAABwAB/AA/8A//gP/gA/wADwAAIAAAAAAD//wP//A//8D//wOAHA4AcDgBwOAHA//8D//wP//A//8AAAAAAAA4AcDgBwOAHA//8D//wP//A//8AABwAAHAAAcAAAAAAAA+f8D5/wPn/A+f8DhxwOHHA4ccDhxwP/HA/8cD/xwP/HAAAAAAAAOAHA4AcDhxwOHHA4ccDhxwOHHA4ccD//wP//A//8D//wAAAAAAAD/wAP/AA/8AD/wAAHAAAcAABwAAHAA//8D//wP//A//8AAAAAAAA/98D/3wP/fA/98DhxwOHHA4ccDhxwOH/A4f8Dh/wOH/AAAAAAAAP//A//8D//wP//A4ccDhxwOHHA4ccDh/wOH/A4f8Dh/wAAAAAAAD4AAPgAA+AADgAAOAAA4AADgAAP//A//8D//wP//AAAAAAAAP//A//8D//wP//A4ccDhxwOHHA4ccD//wP//A//8D//wAAAAAAAD/xwP/HA/8cD/xwOHHA4ccDhxwOHHA//8D//wP//A//8AAAAAAAAOA4A4DgDgOAOA4AAAAAAAAOA/A4H8DgfwOA/AAAAAAAAB4AAPwAA/AAD8AAf4ABzgAPPAA8cAHh4AAAAAAAAAAAAHHAAccABxwAHHAAccABxwAHHAAccABxwAHHAAAAAAAAAOHAA4cADzwAPPAAf4AB/gAD8AAPwAAeAAB4AAAAAAAAA+AAD4AAPgAA+ecDh9wOH3A4fcDhwAP/AA/8AD/wAP/AAAAAAAAAP//4///j//+P//44ADjn/OOf845/zjnHOP8c4//zj//OP/84AAAAAAAP//A//8D//wP//A4cADhwAOHAA4cAD//wP//A//8D//wAAAAAAAD//wP//A//8D//wOHHA4ccDhxwOHHA//8D//wP9/A/j8AAAAAAAA//8D//wP//A//8DgBwOAHA4AcDgBwOAHA4AcDgBwOAHAAAAAAAAP//A//8D//wP//A4AcDgBwOAHA8A8D//wH/+AP/wAf+AAAAAAAAD//wP//A//8D//wOHHA4ccDhxwOHHA4ccDhxwOAHA4AcAAAAAAAA//8D//wP//A//8DhwAOHAA4cADhwAOHAA4cADgAAOAAAAAAD//wP//A//8D//wOAHA4ccDhxwOHHA4f8Dh/wOH/A4f8AAAAAAAA//8D//wP//A//8ABwAAHAAAcAABwAP//A//8D//wP//AAAAAAAAP//A//8D//wP//AAAAAAAAOAHA4AcDgBwOAHA4AcDgBwOAHA//8D//wP//A//8AAAAAAAA//8D//wP//A//8AHwAA/AAP8AB/wAPn/A8f8DB/wIH/AAAAAAAAP//A//8D//wP//AAAcAABwAAHAAAcAABwAAHAAAAAAAAP//A//8D//wP//Af8AAP+AAH/AAD8AAHwAD/AB/wAf8AP+AA//8D//wP//AAAAAAAAP//A//8D//wP//AfwAAfwAAfwAAfwAAfwP//A//8D//wAAAAAAAAAAAP//A//8D//wP//A4AcDgBwOAHA4AcD//wP//A//8D//wAAAAAAAD//wP//A//8D//wOHAA4cADhwAOHAA/8AD/wAP/AA/8AAAAAP//A//8D//wP//A4AcDgBwOAHA4AcD//+P//4///j//+AAA4AADgAAAP//A//8D//wP//A4eADh+AOH8A4f4D/3wP/HA/8MD/wQAAAAAAAD/xwP/HA/8cD/xwOHHA4ccDhxwOHHA4f8Dh/wOH/A4f8AAAAAAAA4AADgAAOAAA//8D//wP//A//8DgAAOAAA4AADgAAAAAA//8D//wP//A//8AABwAAHAAAcAABwP//A//8D//wP//AAAADAAAPgAA/wAD/4AB/8AA/8AAfwAB/AA/8Af+AP/AA/wAD4AAMAAA4AAD+AAP/gA//8AH/wAB/AAf8Af/wP/4A/4AD/gAP/4AH/8AB/wAB/AB/8D//wP/gA/gADgAAIABA4AcDwDwPw/Afn4Af+AA/wAD/AA//AH5+A/D8DwDwOAHAgAEAAAAP/AA/8AD/wAP/AAAf8AB/wAH/AAf8D/wAP/AA/8AD/wAAAAAAAADh/wOH/A4f8Dh/wOHHA4ccDhxwOHHA/8cD/xwP/HA/8cAAAAAAAAf//9///3///f//9wAA3AADcAAMAAAOAAA/gAD/wAH/8AB/8AA/wAAPAAAEAAAAHAADcAANwAB3///f//9///wAA"), 32, atob("BwYLDg4UDwYJCQwMBgkGCQ4MDg4ODg4NDg4GBgwMDA4PDg4ODg4NDg4GDQ4MEg8ODQ8ODgwODhQODg4ICQg="), 22+(scale<<8)+(1<<16)); }; +{ const SETTINGS_FILE = "pebbleDistance.json"; let settings; +let drawTimeout; -function loadSettings() { +let loadSettings = function() { settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#0f0', 'color': 'Green', 'avStep': 0.75}; -} +}; -var img = require("heatshrink").decompress(atob("oFAwkEogA/AH4A/AH4A/AH4A/AE8AAAoeXoAfeDQUBmcyD7A+Dh///8QD649CiAfaHwUvD4sEHy0DDYIfEICg+Cn4fHICY+DD4nxcgojOHwgfEIAYfRCIQaDD4ZAFD5r7DH4//kAfRCIZ/GAAnwD5p9DX44fTHgYSBf4ofVDAQEBl4fFUAgfOXoQzBgIfFBAIfPP4RAEAoYAB+cRiK/SG4h/WIBAfXIA7CBAAswD55AHn6fUIBMCD65AHl4gCmcziAfQQJqfQQJpiDgk0IDXxQLRAEECaBM+QgRYRYgUIA0CD4ggSQJiDCiAKBICszAAswD55AHABKBVD7BAFABIqBD5pAFABPxD55AOD6BADiIAJQAyxLABwf/gaAPAH4A/AH4ARA==")); +const img = require("heatshrink").decompress(atob("oFAwkEogA/AH4A/AH4A/AH4A/AE8AAAoeXoAfeDQUBmcyD7A+Dh///8QD649CiAfaHwUvD4sEHy0DDYIfEICg+Cn4fHICY+DD4nxcgojOHwgfEIAYfRCIQaDD4ZAFD5r7DH4//kAfRCIZ/GAAnwD5p9DX44fTHgYSBf4ofVDAQEBl4fFUAgfOXoQzBgIfFBAIfPP4RAEAoYAB+cRiK/SG4h/WIBAfXIA7CBAAswD55AHn6fUIBMCD65AHl4gCmcziAfQQJqfQQJpiDgk0IDXxQLRAEECaBM+QgRYRYgUIA0CD4ggSQJiDCiAKBICszAAswD55AHABKBVD7BAFABIqBD5pAFABPxD55AOD6BADiIAJQAyxLABwf/gaAPAH4A/AH4ARA==")); const h = g.getHeight(); const w = g.getWidth(); @@ -25,12 +27,12 @@ const h3 = 7*h/8 - 10; let batteryWarning = false; -function draw() { +let draw = function() { let date = new Date(); let da = date.toString().split(" "); let timeStr = da[4].substr(0,5); const t = 6; - const stps = getSteps(); + let stps = Bangle.getHealthStatus("day").steps; // turn the warning on once we have dipped below 15% if (E.getBattery() < 15) @@ -80,17 +82,24 @@ function draw() { g.setColor(settings.bg); g.drawImage(img, w/2 + ((w/2) - 64)/2, -2, { scale: 1 }); drawCalendar(((w/2) - 42)/2, 11, 42, 4, da[2]); - - // distance + + // distance if (settings.color == 'Blue' || settings.color == 'Red') g.setColor('#fff'); // white on blue or red best contrast else g.setColor('#000'); // otherwise black regardless of theme g.drawString((stps / 1000 * settings.avStep).toFixed(2) + ' KM', w/2, ha + 107); -} + + // queue next draw + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); +}; // at x,y width:wi thicknes:th -function drawCalendar(x,y,wi,th,str) { +let drawCalendar = function(x,y,wi,th,str) { g.setColor(g.theme.fg); g.fillRect(x, y, x + wi, y + wi); g.setColor(g.theme.bg); @@ -106,24 +115,23 @@ function drawCalendar(x,y,wi,th,str) { g.setFontLECO1976Regular22(); g.setFontAlign(0, 0); g.drawString(str, x + wi/2, y + wi/2 + th); -} +}; -function getSteps() { - if (WIDGETS.wpedom !== undefined) { - return WIDGETS.wpedom.getSteps(); - } - return '0'; -} +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFontLECO1976Regular22; + delete Graphics.prototype.setFontLECO1976Regular42; + require("widget_utils").show(); // re-show widgets + }}); g.clear(); Bangle.loadWidgets(); -/* - * we are not drawing the widgets as we are taking over the whole screen - * so we will blank out the draw() functions of each widget and change the - * area to the top bar doesn't get cleared. - */ -for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} +require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe loadSettings(); -setInterval(draw, 15000); // refresh every 15s draw(); -Bangle.setUI("clock"); +} diff --git a/apps/pisteinen/ChangeLog b/apps/pisteinen/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/pisteinen/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/pisteinen/README.md b/apps/pisteinen/README.md new file mode 100644 index 000000000..20e8bf9a1 --- /dev/null +++ b/apps/pisteinen/README.md @@ -0,0 +1,7 @@ +# Pisteinen + +By Jukio Kallio + +A Minimal digital watch face consisting of dots. Big dots for hours, small dots for minutes. + +![](screenshot1.png) diff --git a/apps/pisteinen/app-icon.js b/apps/pisteinen/app-icon.js new file mode 100644 index 000000000..d8ad05c50 --- /dev/null +++ b/apps/pisteinen/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkDmYA0/4AKCpM/CxYAB+YtTGJQuOGBAWPGAwuQGAwXvCyJgFC+UhiQDNC43ygEAl4DLC4/xBYMfAZYXfI653XX/6//X/6//O5gBKU5gGBAZAXfI66//C7s/CyPzC+ZgSCwgwRFwowRCwwwPFw4xOCpIArA==")) diff --git a/apps/pisteinen/app.js b/apps/pisteinen/app.js new file mode 100644 index 000000000..a455875ec --- /dev/null +++ b/apps/pisteinen/app.js @@ -0,0 +1,121 @@ +// Pisteinen +// +// Bangle.js 2 watch face +// by Jukio Kallio +// www.jukiokallio.com + + +// settings +const watch = { + x:0, y:0, w:0, h:0, + bgcolor:g.theme.bg, + fgcolor:g.theme.fg, +}; + +// set some additional settings +watch.w = g.getWidth(); // size of the background +watch.h = g.getHeight(); +watch.x = watch.w * 0.5; // position of the circles +watch.y = watch.h * 0.5; + +var wait = 60000; // wait time, normally a minute + + +// timeout used to update every minute +var drawTimeout; + +// schedule a draw for the next minute +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, wait - (Date.now() % wait)); +} + + +// main function +function draw() { + // make date object + var date = new Date(); + + // Reset the state of the graphics library + g.reset(); + + // Clear the area where we want to draw the time + g.setColor(watch.bgcolor); + g.fillRect(0, 0, watch.w, watch.h); + + // setup watch face + const hball = { + size: 9, + pad: 9, + }; + const mball = { + size: 3, + pad: 4, + pad2: 2, + }; + + // get hours and minutes + var hour = date.getHours(); + var minute = date.getMinutes(); + + // calculate size of the hour face + var hfacew = (hball.size * 2 + hball.pad) * 6 - hball.pad; + var hfaceh = (hball.size * 2 + hball.pad) * 4 - hball.pad; + var mfacew = (mball.size * 2 + mball.pad) * 15 - mball.pad + mball.pad2 * 2; + var mfaceh = (mball.size * 2 + mball.pad) * 4 - mball.pad; + var faceh = hfaceh + mfaceh + hball.pad + mball.pad; + + g.setColor(watch.fgcolor); // set foreground color + + // draw hour balls + for (var i = 0; i < 24; i++) { + var x = ((hball.size * 2 + hball.pad) * (i % 6)) + (watch.x - hfacew / 2) + hball.size; + var y = watch.y - faceh / 2 + hball.size; + if (i >= 6) y += hball.size * 2 + hball.pad; + if (i >= 12) y += hball.size * 2 + hball.pad; + if (i >= 18) y += hball.size * 2 + hball.pad; + + if (i < hour) g.fillCircle(x, y, hball.size); else g.drawCircle(x, y, hball.size); + } + + // draw minute balls + for (var j = 0; j < 60; j++) { + var x2 = ((mball.size * 2 + mball.pad) * (j % 15)) + (watch.x - mfacew / 2) + mball.size; + if (j % 15 >= 5) x2 += mball.pad2; + if (j % 15 >= 10) x2 += mball.pad2; + var y2 = watch.y - faceh / 2 + hfaceh + mball.size + hball.pad + mball.pad; + if (j >= 15) y2 += mball.size * 2 + mball.pad; + if (j >= 30) y2 += mball.size * 2 + mball.pad; + if (j >= 45) y2 += mball.size * 2 + mball.pad; + + if (j < minute) g.fillCircle(x2, y2, mball.size); else g.drawCircle(x2, y2, mball.size); + } + + + // queue draw + queueDraw(); +} + + +// Clear the screen once, at startup +g.clear(); +// draw immediately at first +draw(); + + +// Stop updates when LCD is off, restart when on +Bangle.on('lcdPower',on=>{ + if (on) { + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); + + +// Show launcher when middle button pressed +Bangle.setUI("clock"); diff --git a/apps/pisteinen/app.png b/apps/pisteinen/app.png new file mode 100644 index 000000000..a6c441423 Binary files /dev/null and b/apps/pisteinen/app.png differ diff --git a/apps/pisteinen/metadata.json b/apps/pisteinen/metadata.json new file mode 100644 index 000000000..f1137e589 --- /dev/null +++ b/apps/pisteinen/metadata.json @@ -0,0 +1,16 @@ +{ "id": "pisteinen", + "name": "Pisteinen - Dotted watch face", + "shortName":"Pisteinen", + "version":"0.01", + "description": "A minimal digital watch face made with dots.", + "icon": "app.png", + "screenshots": [{"url":"screenshot1.png"}], + "type": "clock", + "tags": "clock", + "supports" : ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"pisteinen.app.js","url":"app.js"}, + {"name":"pisteinen.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/pisteinen/screenshot1.png b/apps/pisteinen/screenshot1.png new file mode 100644 index 000000000..556c004c0 Binary files /dev/null and b/apps/pisteinen/screenshot1.png differ diff --git a/apps/podadrem/ChangeLog b/apps/podadrem/ChangeLog new file mode 100644 index 000000000..3c68f15ac --- /dev/null +++ b/apps/podadrem/ChangeLog @@ -0,0 +1,9 @@ +0.01: Inital release. +0.02: Misc fixes. Add Search and play. +0.03: Simplify "Search and play" function after some bugfixes to Podcast +Addict. +0.04: New layout. +0.05: Add widget field, tweak layout. +0.06: Add compatibility with Fastload Utils. +0.07: Remove just the specific listeners to not interfere with Quick Launch +when fastloading. diff --git a/apps/podadrem/README.md b/apps/podadrem/README.md new file mode 100644 index 000000000..3760e6b5b --- /dev/null +++ b/apps/podadrem/README.md @@ -0,0 +1,21 @@ +Requires Gadgetbridge 71.0 or later. Allow intents in Gadgetbridge in order for this app to work. + +Touch input: + +Press the different ui elements to control Podcast Addict and open menus. +Press left or right arrow to move backward/forward in current playlist. + +Swipe input: + +Swipe left/right to jump backward/forward within the current podcast episode. +Swipe up/down to change the volume. + +It's possible to start a podcast by searching with the remote. It's also possible to change the playback speed. + +The swipe logic was inspired by the implementation in [rigrig](https://git.tubul.net/rigrig/)'s Scrolling Messages. + +Podcast Addict Remote was created by [thyttan](https://github.com/thyttan/). + +Podcast Addict is developed by [Xavier Guillemane](https://twitter.com/xguillem) and can be installed via the [Google Play Store](https://play.google.com/store/apps/details?id=com.bambuna.podcastaddict&hl=en_US&gl=US). + +The Podcast Addict icon is used with permission. diff --git a/apps/podadrem/app-icon.js b/apps/podadrem/app-icon.js new file mode 100644 index 000000000..fc4406666 --- /dev/null +++ b/apps/podadrem/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwgHEhvdABnQDwwVNAAYtTGI4WSGAgWTGAYXUGAJGUGAQXXCyoXKmf/AAPznogQn4WCAAQYP6YWFDB4WFJQhFSA4gwMIYogEGBffLg0zKAYwKRgwTDBQP9Ix09n7DCpowBJBKNEBwIXBAQIsBMwgXKIQReCDoRgJOwYQDLQU/poMBC5B2DIAUzLwIKBnoXBPBAXEIQQVDA4IXNCIQXaWAgXNI4kzNQoXLO4wXLU4a+CU4gXR7ovBcIoXIBobMFPAgXILQKPDmgxCR5omDc4QAHC5ITCC6hgCC6hICC6owBC6phBC6zcFAAMzeogALdQjdBC6AZCeYfTmczAwfQhocOAAwXYgAXVgAXVFwMAJCgXCDCYWDJKYWEGKAtEA==")) diff --git a/apps/podadrem/app.js b/apps/podadrem/app.js new file mode 100644 index 000000000..9c9ed8b04 --- /dev/null +++ b/apps/podadrem/app.js @@ -0,0 +1,326 @@ +{ +/* + Bluetooth.println(JSON.stringify({t:"intent", action:"", flags:["flag1", "flag2",...], categories:["category1","category2",...], mimetype:"", data:"", package:"", class:"", target:"", extra:{someKey:"someValueOrString"}})); + + Podcast Addict is developed by Xavier Guillemane and can be downloaded on Google Play Store: https://play.google.com/store/apps/details?id=com.bambuna.podcastaddict&hl=en_US&gl=US + + How to use intents to control Podcast Addict: https://podcastaddict.com/faq/130 +*/ + +let R; +let widgetUtils = require("widget_utils"); +let backToMenu = false; +let dark = g.theme.dark; // bool + +// The main layout of the app +let gfx = function() { + widgetUtils.hide(); + R = Bangle.appRect; + marigin = 8; + // g.drawString(str, x, y, solid) + g.clearRect(R); + g.reset(); + + if (dark) {g.setColor(0xFD20);} else {g.setColor(0xF800);} // Orange on dark theme, RED on light theme. + g.setFont("4x6:2"); + g.setFontAlign(1, 0, 0); + g.drawString("->", R.x2 - marigin, R.y + R.h/2); + + g.setFontAlign(-1, 0, 0); + g.drawString("<-", R.x + marigin, R.y + R.h/2); + + g.setFontAlign(-1, 0, 1); + g.drawString("<-", R.x + R.w/2, R.y + marigin); + + g.setFontAlign(1, 0, 1); + g.drawString("->", R.x + R.w/2, R.y2 - marigin); + + g.setFontAlign(0, 0, 0); + g.drawString("Play\nPause", R.x + R.w/2, R.y + R.h/2); + + g.setFontAlign(-1, -1, 0); + g.drawString("Menu", R.x + 2*marigin, R.y + 2*marigin); + + g.setFontAlign(-1, 1, 0); + g.drawString("Wake", R.x + 2*marigin, R.y + R.h - 2*marigin); + + g.setFontAlign(1, -1, 0); + g.drawString("Srch", R.x + R.w - 2*marigin, R.y + 2*marigin); + + g.setFontAlign(1, 1, 0); + g.drawString("Speed", R.x + R.w - 2*marigin, R.y + R.h - 2*marigin); +}; + +// Touch handler for main layout +let touchHandler = function(_, xy) { + x = xy.x; + y = xy.y; + len = (R.wb-1 instead of a>=b. + if ((R.x-1{ + Bangle.removeListener("touch", touchHandler); + Bangle.removeListener("swipe", swipeHandler); + clearWatch(buttonHandler); + widgetUtils.show(); + } + }, + ud => { + if (ud) Bangle.musicControl(ud>0 ? "volumedown" : "volumeup"); + } + ); + Bangle.on("touch", touchHandler); + Bangle.on("swipe", swipeHandler); + let buttonHandler = setWatch(()=>{load();}, BTN, {edge:'falling'}); +}; + +/* +The functions for interacting with Android and the Podcast Addict app +*/ + +let pkg = "com.bambuna.podcastaddict"; +let standardCls = pkg + ".receiver.PodcastAddictPlayerReceiver"; +let updateCls = pkg + ".receiver.PodcastAddictBroadcastReceiver"; +let speed = 1.0; + +let simpleSearch = ""; + +let simpleSearchTerm = function() { // input a simple search term without tags, overrides search with tags (artist and track) + require("textinput").input({ + text: simpleSearch + }).then(result => { + simpleSearch = result; + }).then(() => { + E.showMenu(searchMenu); + }); +}; + +let searchPlayWOTags = function() { //make a search and play using entered terms + searchString = simpleSearch; + Bluetooth.println(JSON.stringify({ + t: "intent", + action: "android.media.action.MEDIA_PLAY_FROM_SEARCH", + package: pkg, + target: "activity", + extra: { + query: searchString + }, + flags: ["FLAG_ACTIVITY_NEW_TASK"] + })); +}; + +let gadgetbridgeWake = function() { + Bluetooth.println(JSON.stringify({ + t: "intent", + target: "activity", + flags: ["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_CLEAR_TASK", "FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS", "FLAG_ACTIVITY_NO_ANIMATION"], + package: "gadgetbridge", + class: "nodomain.freeyourgadget.gadgetbridge.activities.WakeActivity" + })); +}; + +// For stringing together the action for Podcast Addict to perform +let actFn = function(actName, activOrServ) { + return "com.bambuna.podcastaddict." + (activOrServ == "service" ? "service." : "") + actName; +}; + +// Send the intent message to Gadgetbridge +let btMsg = function(activOrServ, cls, actName, xtra) { + + Bluetooth.println(JSON.stringify({ + t: "intent", + action: actFn(actName, activOrServ), + package: pkg, + class: cls, + target: "broadcastreceiver", + extra: xtra + })); +}; + +// Get back to the main layout +let backToGfx = function() { + E.showMenu(); + g.clear(); + g.reset(); + setUI(); + gfx(); + backToMenu = false; +}; + +// Podcast Addict Menu +let paMenu = { + "": { + title: " ", + back: backToGfx + }, + "Controls": () => { + E.showMenu(controlMenu); + }, + "Speed Controls": () => { + E.showMenu(speedMenu); + }, + "Search and play": () => { + E.showMenu(searchMenu); + }, + "Navigate and play": () => { + E.showMenu(navigationMenu); + }, + "Wake the android": () => { + gadgetbridgeWake(); + gadgetbridgeWake(); + }, + "Exit PA Remote": ()=>{load();} +}; + + +let controlMenu = { + "": { + title: " ", + back: () => {if (backToMenu) E.showMenu(paMenu); + if (!backToMenu) backToGfx(); + } + }, + "Toggle Play/Pause": () => { + btMsg("service", standardCls, "player.toggle"); + }, + "Jump Backward": () => { + btMsg("service", standardCls, "player.jumpbackward"); + }, + "Jump Forward": () => { + btMsg("service", standardCls, "player.jumpforward"); + }, + "Previous": () => { + btMsg("service", standardCls, "player.previoustrack"); + }, + "Next": () => { + btMsg("service", standardCls, "player.nexttrack"); + }, + "Play": () => { + btMsg("service", standardCls, "player.play"); + }, + "Pause": () => { + btMsg("service", standardCls, "player.pause"); + }, + "Stop": () => { + btMsg("service", standardCls, "player.stop"); + }, + "Update": () => { + btMsg("service", updateCls, "update"); + }, + "Messages Music Controls": () => { + load("messagesmusic.app.js"); + }, +}; + +let speedMenu = { + "": { + title: " ", + back: () => {if (backToMenu) E.showMenu(paMenu); + if (!backToMenu) backToGfx(); + } + }, + "Regular Speed": () => { + speed = 1.0; + btMsg("service", standardCls, "player.1xspeed"); + }, + "1.5x Regular Speed": () => { + speed = 1.5; + btMsg("service", standardCls, "player.1.5xspeed"); + }, + "2x Regular Speed": () => { + speed = 2.0; + btMsg("service", standardCls, "player.2xspeed"); + }, + //"Faster" : ()=>{speed+=0.1; speed=((speed>5.0)?5.0:speed); btMsg("service",standardCls,"player.customspeed",{arg1:speed});}, + //"Slower" : ()=>{speed-=0.1; speed=((speed<0.1)?0.1:speed); btMsg("service",standardCls,"player.customspeed",{arg1:speed});}, +}; + +let searchMenu = { + "": { + title: " ", + + back: () => {if (backToMenu) E.showMenu(paMenu); + if (!backToMenu) backToGfx();} + + }, + "Search term": () => { + simpleSearchTerm(); + }, + "Execute search and play": () => { + btMsg("service", standardCls, "player.play"); + setTimeout(() => { + searchPlayWOTags(); + setTimeout(() => { + btMsg("service", standardCls, "player.play"); + }, 200); + }, 1500); + }, + "Simpler search and play" : searchPlayWOTags, +}; + +let navigationMenu = { + "": { + title: " ", + back: () => {if (backToMenu) E.showMenu(paMenu); + if (!backToMenu) backToGfx();} + }, + "Open Main Screen": () => { + btMsg("activity", standardCls, "openmainscreen"); + }, + "Open Player Screen": () => { + btMsg("activity", standardCls, "openplayer"); + }, +}; + +Bangle.loadWidgets(); +setUI(); +widgetUtils.hide(); +gfx(); +} diff --git a/apps/podadrem/app.png b/apps/podadrem/app.png new file mode 100644 index 000000000..b9cdf4fed Binary files /dev/null and b/apps/podadrem/app.png differ diff --git a/apps/podadrem/metadata.json b/apps/podadrem/metadata.json new file mode 100644 index 000000000..c58b9241d --- /dev/null +++ b/apps/podadrem/metadata.json @@ -0,0 +1,18 @@ +{ + "id": "podadrem", + "name": "Podcast Addict Remote", + "shortName": "PA Remote", + "version": "0.07", + "description": "Control Podcast Addict on your android device.", + "readme": "README.md", + "type": "app", + "tags": "remote,podcast,podcasts,radio,player,intent,intents,gadgetbridge,podadrem,pa remote", + "icon": "app.png", + "screenshots" : [ {"url":"screenshot1.png"}, {"url":"screenshot2.png"} ], + "supports": ["BANGLEJS2"], + "dependencies": { "textinput":"type"}, + "storage": [ + {"name":"podadrem.app.js","url":"app.js"}, + {"name":"podadrem.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/podadrem/screenshot1.png b/apps/podadrem/screenshot1.png new file mode 100644 index 000000000..50f3f17f1 Binary files /dev/null and b/apps/podadrem/screenshot1.png differ diff --git a/apps/podadrem/screenshot2.png b/apps/podadrem/screenshot2.png new file mode 100644 index 000000000..e20c808a2 Binary files /dev/null and b/apps/podadrem/screenshot2.png differ diff --git a/apps/poikkipuinen/ChangeLog b/apps/poikkipuinen/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/poikkipuinen/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/poikkipuinen/README.md b/apps/poikkipuinen/README.md new file mode 100644 index 000000000..12f8d5d7e --- /dev/null +++ b/apps/poikkipuinen/README.md @@ -0,0 +1,7 @@ +# Poikkipuinen + +By Jukio Kallio + +A Minimal digital watch face. Follows the theme colors. + +![](screenshot1.png) diff --git a/apps/poikkipuinen/app-icon.js b/apps/poikkipuinen/app-icon.js new file mode 100644 index 000000000..d7ddba399 --- /dev/null +++ b/apps/poikkipuinen/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkEogA0/4AKCpNPCxYAB+gtTGJQuOGBAWPGAwuQGAwXamQULkYXGBQUgn4WJ+cCMAwXNiQXV+MBC6swh4XU+cAn4XU+IUBC6kgj4XUIwKnV+EDC6sQl4XU+UBd6q8BC6q8BC6i8CC6i8CC6a8DC6a8DC6a8DC6S8EC6S8EC6S8EC6K8FC6K8FC6C8BIwwXOXgwXQXgwXQkIWHd6IXPp4GBmQWJAAMjAQP0C4wAPC7hgDABwWEGCIuFGCIWGGB4uHGJwVJAFY=")) diff --git a/apps/poikkipuinen/app.js b/apps/poikkipuinen/app.js new file mode 100644 index 000000000..0bf09c5e5 --- /dev/null +++ b/apps/poikkipuinen/app.js @@ -0,0 +1,158 @@ +// Poikkipuinen +// +// Bangle.js 2 watch face +// by Jukio Kallio +// www.jukiokallio.com + +require("Font5x9Numeric7Seg").add(Graphics); +require("FontSinclair").add(Graphics); + +// settings +const watch = { + x:0, y:0, w:0, h:0, + bgcolor:g.theme.bg, + fgcolor:g.theme.fg, + font: "5x9Numeric7Seg", fontsize: 1, + font2: "Sinclair", font2size: 1, + finland:true, // change if you want Finnish style date, or US style +}; + + +// set some additional settings +watch.w = g.getWidth(); // size of the background +watch.h = g.getHeight(); +watch.x = watch.w * 0.5; // position of the circles +watch.y = watch.h * 0.41; + +const dateWeekday = { 0: "SUN", 1: "MON", 2: "TUE", 3: "WED", 4:"THU", 5:"FRI", 6:"SAT" }; // weekdays + +var wait = 60000; // wait time, normally a minute + + +// timeout used to update every minute +var drawTimeout; + +// schedule a draw for the next minute +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, wait - (Date.now() % wait)); +} + + +// main function +function draw() { + // make date object + var date = new Date(); + + // work out the date string + var dateDay = date.getDate(); + var dateMonth = date.getMonth() + 1; + var dateYear = date.getFullYear(); + var dateStr = dateMonth + "." + dateDay + "." + dateYear; + if (watch.finland) dateStr = dateDay + "." + dateMonth + "." + dateYear; // the true way of showing date + var dateStr2 = dateWeekday[date.getDay()]; + + // Reset the state of the graphics library + g.reset(); + + // Clear the area where we want to draw the time + g.setColor(watch.bgcolor); + g.fillRect(0, 0, watch.w, watch.h); + + // set foreground color + g.setColor(watch.fgcolor); + g.setFontAlign(1,-1).setFont(watch.font, watch.fontsize); + + // watch face size + var facew, faceh; // halves of the size for easier calculation + facew = 50; + faceh = 59; + + // save hour and minute y positions + var houry, minutey; + + // draw hour meter + g.drawLine(watch.x - facew, watch.y - faceh, watch.x - facew, watch.y + faceh); + var lines = 13; + var lineh = faceh * 2 / (lines - 2); + for (var i = 1; i < lines; i++) { + var w = 3; + var y = faceh - lineh * (i - 1); + + if (i % 3 == 0) { + // longer line and numbers every 3 + w = 5; + g.drawString(i, watch.x - facew - 2, y + watch.y); + } + + g.drawLine(watch.x - facew, y + watch.y, watch.x - facew + w, y + watch.y); + + // get hour y position + var hour = date.getHours() % 12; // modulate away the 24h + if (hour == 0) hour = 12; // fix a problem with 0-23 hours + //var hourMin = date.getMinutes() / 60; // move hour line by minutes + var hourMin = Math.floor(date.getMinutes() / 15) / 4; // move hour line by 15-minutes + if (hour == 12) hourMin = 0; // don't do minute moving if 12 (line ends there) + if (i == hour) houry = y - (lineh * hourMin); + } + + // draw minute meter + g.drawLine(watch.x + facew, watch.y - faceh, watch.x + facew, watch.y + faceh); + g.setFontAlign(-1,-1); + lines = 60; + lineh = faceh * 2 / (lines - 1); + for (i = 0; i < lines; i++) { + var mw = 3; + var my = faceh - lineh * i; + + if (i % 15 == 0 && i != 0) { + // longer line and numbers every 3 + mw = 5; + g.drawString(i, watch.x + facew + 4, my + watch.y); + } + + //if (i % 2 == 0 || i == 15 || i == 45) + g.drawLine(watch.x + facew, my + watch.y, watch.x + facew - mw, my + watch.y); + + // get minute y position + if (i == date.getMinutes()) minutey = my; + } + + // draw the time + var timexpad = 8; + g.drawLine(watch.x - facew + timexpad, watch.y + houry, watch.x + facew - timexpad, watch.y + minutey); + + // draw date + var datey = 14; + g.setFontAlign(0,-1); + g.drawString(dateStr, watch.x, watch.y + faceh + datey); + g.setFontAlign(0,-1).setFont(watch.font2, watch.font2size); + g.drawString(dateStr2, watch.x, watch.y + faceh + datey*2); + + // queue draw + queueDraw(); +} + + +// Clear the screen once, at startup +g.clear(); +// draw immediately at first +draw(); + + +// Stop updates when LCD is off, restart when on +Bangle.on('lcdPower',on=>{ + if (on) { + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); + + +// Show launcher when middle button pressed +Bangle.setUI("clock"); diff --git a/apps/poikkipuinen/app.png b/apps/poikkipuinen/app.png new file mode 100644 index 000000000..fa506c886 Binary files /dev/null and b/apps/poikkipuinen/app.png differ diff --git a/apps/poikkipuinen/metadata.json b/apps/poikkipuinen/metadata.json new file mode 100644 index 000000000..ec95ab7ce --- /dev/null +++ b/apps/poikkipuinen/metadata.json @@ -0,0 +1,16 @@ +{ "id": "poikkipuinen", + "name": "Poikkipuinen - Minimal watch face", + "shortName":"Poikkipuinen", + "version":"0.01", + "description": "A minimal digital watch face.", + "icon": "app.png", + "screenshots": [{"url":"screenshot1.png"}], + "type": "clock", + "tags": "clock", + "supports" : ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"poikkipuinen.app.js","url":"app.js"}, + {"name":"poikkipuinen.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/poikkipuinen/screenshot1.png b/apps/poikkipuinen/screenshot1.png new file mode 100644 index 000000000..23fcc348c Binary files /dev/null and b/apps/poikkipuinen/screenshot1.png differ diff --git a/apps/pokeclk/ChangeLog b/apps/pokeclk/ChangeLog index 8e506ce50..5838e596d 100644 --- a/apps/pokeclk/ChangeLog +++ b/apps/pokeclk/ChangeLog @@ -1,2 +1,3 @@ 0.01: New face :) 0.02: Color image compressed +0.03: Improved clock diff --git a/apps/pokeclk/app.js b/apps/pokeclk/app.js index 17a487bc0..7e495f7d2 100644 --- a/apps/pokeclk/app.js +++ b/apps/pokeclk/app.js @@ -5,7 +5,7 @@ const width = g.getWidth(); const height = g.getHeight(); const font = "Vector:12"; -const locale = require("locale"); +var drawTimeout; var img = { width : 176, height : 149, bpp : 4, @@ -20,34 +20,12 @@ var night= { buffer : (atob("ERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERABEREREREREAEREREREREREREREREREREREREREREREREREREREREREREREQABERERERHwABEREREREREREREREREREREREREREREREREREREREREREREREQ/xERERER/wERERERERERERERERERERERERERERERERERERERERERERERERH//xERERH//xERERERERERERERERERERERERERERERERERERERERERERERERH//xEREf/xERERERERERERERERERERERERERERERERERERERERERERERERERH///////ERERERERERERERERERERERERERERERERERERERERERERERERERER////////8RERERERERERERERERERERERERERERERERERERERERERERERERH/////////ERERERERERERERERERERERERERERERERERERERERERERERERER////D///DxERERERERERERERERERERERERERERERERERERERERERERERERH////w///w8RERERERERERERERERERERERERERERERERERERERER//ERERER//AA///w/w8REREREREREREREREREREREREREREREREREREREREf////EREf/wAP/wAA8PERERERERERERERERERERERERERERERERERERERERH////xERH/8AD/////DxERERERERERERERERERERERERERERERERERERERER////8REf//////////ERERERERERERERERERERERERERERERERERERERERERERH/8R/////////xERERERERERERERERERERERERERERERERERERERER////////Ef////////////////////////////////////////////////////////////////////////////////////////////////////////////8RERERH////////////xERERERERERERERERERERERERERERERERERERERERERERERH///////////EREREREREREREREREREREREREREREREREREREREREf/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////w==")) }; -var time= "10:20"; - -function time() { //numbers - // work out how to display the current time - const d = new Date(); - const h = d.getHours(), - m = d.getMinutes(); - const time = h + ":" + ("0" + m).substr(-2); - const day = Date.now(); - const mo = d.getMonth()+1; - const damo = d.getDate(); - - var dayMonth = mo+"-"+damo; - - // time - require("Font4x5").add(Graphics); - isDark(); - g.setFontAlign(0,0); - //g.setFont("6x8:4x5"); - g.setFont("4x5",7); - g.drawString(time, width/2, height/2); - // date - require("Font4x5").add(Graphics); - g.setFontAlign(1,1); - //g.setFont("4x6",2); - g.setFont("4x5",3); - g.drawString(dayMonth, width/2+60, height/2+40); - +function queueDraw() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); } function isDark(){ @@ -59,6 +37,22 @@ function isDark(){ } } +function time() { + var d = new Date(); + var day = d.getDate(); + var time = require("locale").time(d,1); + var date = require("locale").date(d); + var mo = require("date_utils").month(d.getMonth()+1,1); + + require("Font4x5").add(Graphics); // time + isDark(); + g.setFontAlign(0,0); + g.setFont("4x5",7.5).drawString(time, width/2, height/2); + + g.setFontAlign(1,1); + g.setFont("4x5",3).drawString(mo+" "+day, width-15, height-35); +} + function draw() { //poketch background if (g.theme.dark==true){ g.drawImage(night, 0, 25, {scale:2}); //poketch is life @@ -67,20 +61,13 @@ function draw() { //poketch background g.drawImage(img, 0, 25); //poketch is life } time(); + queueDraw(); } //program start g.clear(); draw(); -var secondInterval = setInterval(draw, 1000); // Stop updates when LCD is off, restart when on -Bangle.on('lcdPower',on=>{ - if (secondInterval) clearInterval(secondInterval); - secondInterval = undefined; - if (on) { - secondInterval = setInterval(draw, 1000); - draw(); // draw immediately - } -}); + // Show launcher when middle button pressed Bangle.setUI("clock"); // Load widgets diff --git a/apps/pokeclk/metadata.json b/apps/pokeclk/metadata.json index 433077efe..c022868ec 100644 --- a/apps/pokeclk/metadata.json +++ b/apps/pokeclk/metadata.json @@ -2,7 +2,7 @@ "id": "pokeclk", "name": "Poketch Clock", "shortName":"Poketch Clock", - "version": "0.02", + "version": "0.03", "description": "A clock based on the Poketch electronic device found in Sinnoh", "icon": "app.png", "type": "clock", diff --git a/apps/pomoplus/ChangeLog b/apps/pomoplus/ChangeLog new file mode 100644 index 000000000..1a137aad0 --- /dev/null +++ b/apps/pomoplus/ChangeLog @@ -0,0 +1,3 @@ +0.01: New app! +0.02-0.04: Bug fixes +0.05: Submitted to the app loader \ No newline at end of file diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js new file mode 100644 index 000000000..73af5c935 --- /dev/null +++ b/apps/pomoplus/app.js @@ -0,0 +1,157 @@ +Bangle.POMOPLUS_ACTIVE = true; //Prevent the boot code from running. To avoid having to reload on every interaction, we'll control the vibrations from here when the user is in the app. + +const storage = require("Storage"); +const common = require("pomoplus-com.js"); + +//Expire the state if necessary +if ( + common.settings.pausedTimerExpireTime != 0 && + !common.state.running && + (new Date()).getTime() - common.state.pausedTime > common.settings.pausedTimerExpireTime +) { + common.state = common.STATE_DEFAULT; +} + +function drawButtons() { + //Draw the backdrop + const BAR_TOP = g.getHeight() - 24; + g.setColor(0, 0, 1).setFontAlign(0, -1) + .clearRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .fillRect(0, BAR_TOP, g.getWidth(), g.getHeight()) + .setColor(1, 1, 1); + + if (!common.state.wasRunning) { //If the timer was never started, only show a play button + g.drawImage(common.BUTTON_ICONS.play, g.getWidth() / 2, BAR_TOP); + } else { + g.drawLine(g.getWidth() / 2, BAR_TOP, g.getWidth() / 2, g.getHeight()); + if (common.state.running) { + g.drawImage(common.BUTTON_ICONS.pause, g.getWidth() / 4, BAR_TOP) + .drawImage(common.BUTTON_ICONS.skip, g.getWidth() * 3 / 4, BAR_TOP); + } else { + g.drawImage(common.BUTTON_ICONS.reset, g.getWidth() / 4, BAR_TOP) + .drawImage(common.BUTTON_ICONS.play, g.getWidth() * 3 / 4, BAR_TOP); + } + } +} + +function drawTimerAndMessage() { + g.reset() + .setFontAlign(0, 0) + .setFont("Vector", 36) + .clearRect(0, 24, 176, 152) + + //Draw the timer + .drawString((() => { + let timeLeft = common.getTimeLeft(); + let hours = timeLeft / 3600000; + let minutes = (timeLeft % 3600000) / 60000; + let seconds = (timeLeft % 60000) / 1000; + + function pad(number) { + return ('00' + parseInt(number)).slice(-2); + } + + if (hours >= 1) return `${parseInt(hours)}:${pad(minutes)}:${pad(seconds)}`; + else return `${parseInt(minutes)}:${pad(seconds)}`; + })(), g.getWidth() / 2, g.getHeight() / 2) + + //Draw the phase label + .setFont("Vector", 12) + .drawString(((currentPhase, numShortBreaks) => { + if (!common.state.wasRunning) return "Not started"; + else if (currentPhase == common.PHASE_WORKING) return `Work ${numShortBreaks + 1}/${common.settings.numShortBreaks + 1}` + else if (currentPhase == common.PHASE_SHORT_BREAK) return `Short break ${numShortBreaks + 1}/${common.settings.numShortBreaks}`; + else return "Long break!"; + })(common.state.phase, common.state.numShortBreaks), + g.getWidth() / 2, g.getHeight() / 2 + 18); + + //Update phase with vibation if needed + if (common.getTimeLeft() <= 0) { + common.nextPhase(true); + } +} + +drawButtons(); +Bangle.on("touch", (button, xy) => { + //If we support full touch and we're not touching the keys, ignore. + //If we don't support full touch, we can't tell so just assume we are. + if (xy !== undefined && xy.y <= g.getHeight() - 24) return; + + if (!common.state.wasRunning) { + //If we were never running, there is only one button: the start button + let now = (new Date()).getTime(); + common.state = { + wasRunning: true, + running: true, + startTime: now, + pausedTime: now, + elapsedTime: 0, + phase: common.PHASE_WORKING, + numShortBreaks: 0 + }; + setupTimerInterval(); + drawButtons(); + + } else if (common.state.running) { + //If we are running, there are two buttons: pause and skip + if (button == 1) { + //Record the exact moment that we paused + let now = (new Date()).getTime(); + common.state.pausedTime = now; + + //Stop the timer + common.state.running = false; + clearInterval(timerInterval); + timerInterval = undefined; + drawTimerAndMessage(); + drawButtons(); + + } else { + common.nextPhase(false); + } + + } else { + //If we are stopped, there are two buttons: Reset and continue + if (button == 1) { + //Reset the timer + common.state = common.STATE_DEFAULT; + drawTimerAndMessage(); + drawButtons(); + + } else { + //Start the timer and record old elapsed time and when we started + let now = (new Date()).getTime(); + common.state.elapsedTime += common.state.pausedTime - common.state.startTime; + common.state.startTime = now; + common.state.running = true; + drawTimerAndMessage(); + setupTimerInterval(); + drawButtons(); + } + } +}); + +let timerInterval; + +function setupTimerInterval() { + if (timerInterval !== undefined) { + clearInterval(timerInterval); + } + setTimeout(() => { + timerInterval = setInterval(drawTimerAndMessage, 1000); + drawTimerAndMessage(); + }, common.timeLeft % 1000); +} + +drawTimerAndMessage(); +if (common.state.running) { + setupTimerInterval(); +} + +//Save our state when the app is closed +E.on('kill', () => { + storage.writeJSON(common.STATE_PATH, common.state); +}); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); \ No newline at end of file diff --git a/apps/pomoplus/boot.js b/apps/pomoplus/boot.js new file mode 100644 index 000000000..edc233853 --- /dev/null +++ b/apps/pomoplus/boot.js @@ -0,0 +1,19 @@ +const POMOPLUS_storage = require("Storage"); +const POMOPLUS_common = require("pomoplus-com.js"); + +function setNextTimeout() { + setTimeout(() => { + //Make sure that the pomoplus app isn't in the foreground. The pomoplus app handles the vibrations when it is in the foreground in order to avoid having to reload every time the user changes state. That means that when the app is in the foreground, we shouldn't do anything here. + //We do this after the timer rather than before because the timer will start before the app executes. + if (Bangle.POMOPLUS_ACTIVE === undefined) { + POMOPLUS_common.nextPhase(true); + setNextTimeout(); + POMOPLUS_storage.writeJSON(POMOPLUS_common.STATE_PATH, POMOPLUS_common.state) + } + }, POMOPLUS_common.getTimeLeft()); +} + +//Only start the timeout if the timer is running +if (POMOPLUS_common.state.running) { + setNextTimeout(); +} \ No newline at end of file diff --git a/apps/pomoplus/common.js b/apps/pomoplus/common.js new file mode 100644 index 000000000..b1cd42de8 --- /dev/null +++ b/apps/pomoplus/common.js @@ -0,0 +1,118 @@ +const storage = require("Storage"); +const heatshrink = require("heatshrink"); + +exports.STATE_PATH = "pomoplus.state.json"; +exports.SETTINGS_PATH = "pomoplus.json"; + +exports.PHASE_WORKING = 0; +exports.PHASE_SHORT_BREAK = 1; +exports.PHASE_LONG_BREAK = 2; + +exports.BUTTON_ICONS = { + play: heatshrink.decompress(atob("jEYwMAkAGBnACBnwCBn+AAQPgAQPwAQP8AQP/AQXAAQPwAQP8AQP+AQgICBwQUCEAn4FggyBHAQ+CIgQ")), + pause: heatshrink.decompress(atob("jEYwMA/4BBAX4CEA")), + reset: heatshrink.decompress(atob("jEYwMA/4BB/+BAQPDAQPnAQIAKv///0///8j///EP//wAQQICBwQUCEhgyCHAQ+CIgI=")), + skip: heatshrink.decompress(atob("jEYwMAwEIgHAhkA8EOgHwh8A/EPwH8h/A/0P8H/h/w/+P/H/5/8//v/3/AAoICBwQUCDQIgCEwQsCGQQ4CHwRECA")) +}; + +exports.settings = storage.readJSON(exports.SETTINGS_PATH); +if (!exports.settings) { + exports.settings = { + workTime: 1500000, //Work for 25 minutes + shortBreak: 300000, //5 minute short break + longBreak: 900000, //15 minute long break + numShortBreaks: 3, //3 short breaks for every long break + pausedTimerExpireTime: 21600000, //If the timer was left paused for >6 hours, reset it on next launch + widget: false //If a widget is added in the future, whether the user wants it + }; +} + +//Store the minimal amount of information to be able to reconstruct the state of the timer at any given time. +//This is necessary because it is necessary to write to flash to let the timer run in the background, so minimizing the writes is necessary. +exports.STATE_DEFAULT = { + wasRunning: false, //If the timer ever was running. Used to determine whether to display a reset button + running: false, //Whether the timer is currently running + startTime: 0, //When the timer was last started. Difference between this and now is how long timer has run continuously. + pausedTime: 0, //When the timer was last paused. Used for expiration and displaying timer while paused. + elapsedTime: 0, //How much time the timer had spent running before the current start time. Update on pause or user skipping stages. + phase: exports.PHASE_WORKING, //What phase the timer is currently in + numShortBreaks: 0 //Number of short breaks that have occured so far +}; +exports.state = storage.readJSON(exports.STATE_PATH); +if (!exports.state) { + exports.state = exports.STATE_DEFAULT; +} + +//Get the number of milliseconds until the next phase change +exports.getTimeLeft = function () { + if (!exports.state.wasRunning) { + //If the timer never ran, the time left is just the amount of work time. + return exports.settings.workTime; + } else if (exports.state.running) { + //If the timer is running, the time left is current time - start time + preexisting time + var runningTime = (new Date()).getTime() - exports.state.startTime + exports.state.elapsedTime; + } else { + //If the timer is not running, the same as above but use when the timer was paused instead of now. + var runningTime = exports.state.pausedTime - exports.state.startTime + exports.state.elapsedTime; + } + + if (exports.state.phase == exports.PHASE_WORKING) { + return exports.settings.workTime - runningTime; + } else if (exports.state.phase == exports.PHASE_SHORT_BREAK) { + return exports.settings.shortBreak - runningTime; + } else { + return exports.settings.longBreak - runningTime; + } +} + +//Get the next phase to change to +exports.getNextPhase = function () { + if (exports.state.phase == exports.PHASE_WORKING) { + if (exports.state.numShortBreaks < exports.settings.numShortBreaks) { + return exports.PHASE_SHORT_BREAK; + } else { + return exports.PHASE_LONG_BREAK; + } + } else { + return exports.PHASE_WORKING; + } +} + +//Change to the next phase and update numShortBreaks, and optionally vibrate. DOES NOT WRITE STATE CHANGE TO STORAGE! +exports.nextPhase = function (vibrate) { + a = { + startTime: 0, //When the timer was last started. Difference between this and now is how long timer has run continuously. + pausedTime: 0, //When the timer was last paused. Used for expiration and displaying timer while paused. + elapsedTime: 0, //How much time the timer had spent running before the current start time. Update on pause or user skipping stages. + phase: exports.PHASE_WORKING, //What phase the timer is currently in + numShortBreaks: 0 //Number of short breaks that have occured so far + } + let now = (new Date()).getTime(); + exports.state.startTime = now; //The timer is being reset, so say it starts now. + exports.state.pausedTime = now; //This prevents a paused timer from having the start time moved to the future and therefore having been run for negative time. + exports.state.elapsedTime = 0; //Because we are resetting the timer, we no longer need to care about whether it was paused previously. + + let oldPhase = exports.state.phase; //Cache the old phase because we need to remember it when counting the number of short breaks + exports.state.phase = exports.getNextPhase(); + + if (oldPhase == exports.PHASE_SHORT_BREAK) { + //If we just left a short break, increase the number of short breaks + exports.state.numShortBreaks++; + } else if (oldPhase == exports.PHASE_LONG_BREAK) { + //If we just left a long break, set the number of short breaks to zero + exports.state.numShortBreaks = 0; + } + + if (vibrate) { + if (exports.state.phase == exports.PHASE_WORKING) { + Bangle.buzz(750, 1); + } else if (exports.state.phase == exports.PHASE_SHORT_BREAK) { + Bangle.buzz(); + setTimeout(Bangle.buzz, 400); + } else { + Bangle.buzz(); + setTimeout(Bangle.buzz, 400); + setTimeout(Bangle.buzz, 600); + } + } +} \ No newline at end of file diff --git a/apps/pomoplus/icon.js b/apps/pomoplus/icon.js new file mode 100644 index 000000000..e4ecc7d1c --- /dev/null +++ b/apps/pomoplus/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwcBkmSpICG5AIHCLMmoQOKycJAoUyiQRLAgIOBAQQyKsmSpAROpgEBhmQzIHBC4JTIDIxcHDQYgCBQUSphEGpMJkwcEwgLByBoFCIMyCIgpDL4RQEBwWQ5ICBDoRKCBAIFBNYeSjJHDKYYaCR4YLBiYgDKYo4DEwQgECIpiECISqFkJlCCIILETwYRGDo1CsiJECIiPCdIaqCSoabFCgYRHAQ5iBCJ8hcAgRNKwOQgARLU4IRCvwRMa4QRPfwQR5YooR/cAYOGgAADvwEDCI8H/4AG/Ek5IRXGpMkzJZNoQGByYRNiQJCsgRLyAJDpgRQpIRLwgJEWxARBkIJFUg4RChIJGQA4RJNw4RKLg0kCJQ4DVoUACIY")) \ No newline at end of file diff --git a/apps/pomoplus/icon.png b/apps/pomoplus/icon.png new file mode 100644 index 000000000..60d8023db Binary files /dev/null and b/apps/pomoplus/icon.png differ diff --git a/apps/pomoplus/img/pause.png b/apps/pomoplus/img/pause.png new file mode 100644 index 000000000..ad31dadcf Binary files /dev/null and b/apps/pomoplus/img/pause.png differ diff --git a/apps/pomoplus/img/play.png b/apps/pomoplus/img/play.png new file mode 100644 index 000000000..6c20c24c5 Binary files /dev/null and b/apps/pomoplus/img/play.png differ diff --git a/apps/pomoplus/img/reset.png b/apps/pomoplus/img/reset.png new file mode 100644 index 000000000..7a317d097 Binary files /dev/null and b/apps/pomoplus/img/reset.png differ diff --git a/apps/pomoplus/img/skip.png b/apps/pomoplus/img/skip.png new file mode 100644 index 000000000..375318069 Binary files /dev/null and b/apps/pomoplus/img/skip.png differ diff --git a/apps/pomoplus/metadata.json b/apps/pomoplus/metadata.json new file mode 100644 index 000000000..068eeed91 --- /dev/null +++ b/apps/pomoplus/metadata.json @@ -0,0 +1,37 @@ +{ + "id": "pomoplus", + "name": "Pomodoro Plus", + "version": "0.05", + "description": "A configurable pomodoro timer that runs in the background.", + "icon": "icon.png", + "type": "app", + "tags": "pomodoro,cooking,tools", + "supports": [ + "BANGLEJS", + "BANGLEJS2" + ], + "allow_emulator": true, + "storage": [ + { + "name": "pomoplus.app.js", + "url": "app.js" + }, + { + "name": "pomoplus.img", + "url": "icon.js", + "evaluate": true + }, + { + "name": "pomoplus.boot.js", + "url": "boot.js" + }, + { + "name": "pomoplus-com.js", + "url": "common.js" + }, + { + "name": "pomoplus.settings.js", + "url": "settings.js" + } + ] +} \ No newline at end of file diff --git a/apps/pomoplus/settings.js b/apps/pomoplus/settings.js new file mode 100644 index 000000000..1ff52340a --- /dev/null +++ b/apps/pomoplus/settings.js @@ -0,0 +1,94 @@ +const SETTINGS_PATH = 'pomoplus.json'; +const storage = require("Storage"); + +(function (back) { + let settings = storage.readJSON(SETTINGS_PATH); + if (!settings) { + settings = { + workTime: 1500000, //Work for 25 minutes + shortBreak: 300000, //5 minute short break + longBreak: 900000, //15 minute long break + numShortBreaks: 3, //3 short breaks for every long break + pausedTimerExpireTime: 21600000, //If the timer was left paused for >6 hours, reset it on next launch + widget: false //If a widget is added in the future, whether the user wants it + }; + } + + function save() { + storage.writeJSON(SETTINGS_PATH, settings); + } + + const menu = { + '': { 'title': 'Pomodoro Plus' }, + '< Back': back, + 'Work time': { + value: settings.workTime, + step: 60000, //1 minute + min: 60000, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.workTime = value; + save(); + }, + format: function (value) { + return '' + (value / 60000) + 'm' + } + }, + 'Short break time': { + value: settings.shortBreak, + step: 60000, + min: 60000, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.shortBreak = value; + save(); + }, + format: function (value) { + return '' + (value / 60000) + 'm' + } + }, + '# Short breaks': { + value: settings.numShortBreaks, + step: 1, + min: 0, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.numShortBreaks = value; + save(); + } + }, + 'Long break time': { + value: settings.longBreak, + step: 60000, + min: 60000, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.longBreak = value; + save(); + }, + format: function (value) { + return '' + (value / 60000) + 'm' + } + }, + 'Timer expiration': { + value: settings.pausedTimerExpireTime, + step: 900000, //15 minutes + min: 0, + // max: 10800000, + // wrap: true, + onchange: function (value) { + settings.pausedTimerExpireTime = value; + save(); + }, + format: function (value) { + if (value == 0) return "Off" + else return `${Math.floor(value / 3600000)}h ${(value % 3600000) / 60000}m` + } + }, + }; + E.showMenu(menu) +}) \ No newline at end of file diff --git a/apps/pooqroman/ChangeLog b/apps/pooqroman/ChangeLog index c4f3171d3..b21b34b58 100644 --- a/apps/pooqroman/ChangeLog +++ b/apps/pooqroman/ChangeLog @@ -1,3 +1,4 @@ 0.01: Initial check-in. 0.02: Make internal menu time out + small fixes. 0.03: Autolight feature. +0.04: Added adjustment for Bangle.js magnetometer heading fix diff --git a/apps/pooqroman/app.js b/apps/pooqroman/app.js index fcb2437e1..7bd749ac4 100644 --- a/apps/pooqroman/app.js +++ b/apps/pooqroman/app.js @@ -70,7 +70,7 @@ class Options { delay ); } - + bless(k) { Object.defineProperty(this, k, { get: () => this.backing[k], @@ -103,7 +103,7 @@ class Options { if (this.bored) clearTimeout(this.bored); this.bored = setTimeout(_ => this.showMenu(), 15000); } - + reset() { this.backing = {__proto__: this.constructor.defaults}; this.writeBack(0); @@ -145,7 +145,7 @@ class RomanOptions extends Options { Defaults: _ => {this.reset(); this.interact();} }; } - + interact() {this.showMenu(this.menu);} } @@ -337,7 +337,7 @@ const events = { // colour: colour, dramatic?: bool, event?: any} fixed: [{time: Number.POSITIVE_INFINITY}], // indexed by ms absolute wall: [{time: Number.POSITIVE_INFINITY}], // indexed by nominal ms + TZ ms - + clean: function(now, l) { let o = now.getTimezoneOffset() * 60000; let tf = now.getTime() + l, tw = tf - o; @@ -345,7 +345,7 @@ const events = { while (this.wall[0].time <= tw) this.wall.shift(); while (this.fixed[0].time <= tf) this.fixed.shift(); }, - + scan: function(now, from, to, f) { result = Infinity; let o = now.getTimezoneOffset() * 60000; @@ -482,7 +482,7 @@ class Sidebar { compassI, this.x + 4 + imageWidth(compassI) / 2, this.y + 4 + imageHeight(compassI) / 2, - a ? {rotate: c.heading / 180 * Math.PI} : undefined + a ? {rotate: (360-c.heading) / 180 * Math.PI} : undefined ); this.y += 4 + imageHeight(compassI); } @@ -535,13 +535,13 @@ class Roman { static pos(p, r) { let h = r * rectW / 2; let v = r * rectH / 2; - p = (p + 1) % 12; + p = (p + 1) % 12; return p <= 2 ? [faceCX + h * (p - 1), faceCY - v] : p < 6 ? [faceCX + h, faceCY + v / 2 * (p - 4)] : p <= 8 ? [faceCX - h * (p - 7), faceCY + v] : [faceCX - h, faceCY - v / 2 * (p - 10)]; } - + alert(e, date, now, past) { const g = this.g; g.setColor(e.colour); @@ -564,7 +564,7 @@ class Roman { } return Infinity; } - + render(d, rate) { const g = this.g; const state = this.state || (g.clear(true), this.state = {}); @@ -625,7 +625,7 @@ class Roman { for (let h = keyHour; h < keyHour + 12; h++) { g.drawString( numeral(h % 24, options), - faceX + layout[h % 12 * 2], + faceX + layout[h % 12 * 2], faceY + layout[h % 12 * 2 + 1] ); } @@ -643,7 +643,7 @@ class Roman { (e, t, p) => this.alert(e, t, d, p) ); if (rate > requestedRate) rate = requestedRate; - + // Hands // Here we are using incremental hands for hours and minutes. // If we quantised, we could use hand-crafted bitmaps, though. @@ -668,7 +668,7 @@ class Clock { this.rates = {}; this.options.on('done', () => this.start()); - + this.listeners = { charging: _ => {face.doIcons('charging'); this.active();}, lock: _ => {face.doIcons('locked'); this.active();}, @@ -723,7 +723,7 @@ class Clock { this.face.reset(); // Cancel any ongoing background rendering return this; } - + active() { const prev = this.rate; const now = Date.now(); diff --git a/apps/pooqroman/metadata.json b/apps/pooqroman/metadata.json index 8cdbea728..0294e22a0 100644 --- a/apps/pooqroman/metadata.json +++ b/apps/pooqroman/metadata.json @@ -1,7 +1,7 @@ { "id": "pooqroman", "name": "pooq Roman watch face", "shortName":"pooq Roman", - "version":"0.03", + "version":"0.04", "description": "A classic watch face with a certain dynamicity. Most amusing in 24h mode. Slide up to show more hands, down for less(!). By design does not support standard widgets, sorry!", "icon": "app.png", "type": "clock", diff --git a/apps/powermanager/ChangeLog b/apps/powermanager/ChangeLog index f0b60a45a..a83e8c676 100644 --- a/apps/powermanager/ChangeLog +++ b/apps/powermanager/ChangeLog @@ -1,3 +1,5 @@ 0.01: New App! 0.02: Allow forcing monotonic battery voltage/percentage 0.03: Use default Bangle formatter for booleans +0.04: Remove calibration with current voltage (Calibrate->Auto) as it is now handled by settings app + Allow automatic calibration on every charge longer than 3 hours diff --git a/apps/powermanager/README.md b/apps/powermanager/README.md index 434ec814e..88b3c370a 100644 --- a/apps/powermanager/README.md +++ b/apps/powermanager/README.md @@ -3,8 +3,9 @@ Manages settings for charging. Features: * Warning threshold to be able to disconnect the charger at a given percentage -* Set the battery calibration offset. +* Set the battery calibration offset * Force monotonic battery percentage or voltage +* Automatic calibration on charging uninterrupted longer than 3 hours (reloads of the watch reset the timer). ## Internals diff --git a/apps/powermanager/boot.js b/apps/powermanager/boot.js index 077e24413..2bc2aaa35 100644 --- a/apps/powermanager/boot.js +++ b/apps/powermanager/boot.js @@ -5,7 +5,6 @@ ); if (settings.warnEnabled){ - print("Charge warning enabled"); var chargingInterval; function handleCharging(charging){ @@ -48,4 +47,13 @@ return v; }; } + + if (settings.autoCalibration){ + let chargeStart; + Bangle.on("charging", (charging)=>{ + if (charging) chargeStart = Date.now(); + if (chargeStart && !charging && (Date.now() - chargeStart > 1000*60*60*3)) require("powermanager").setCalibration(); + if (!charging) chargeStart = undefined; + }); + } })(); diff --git a/apps/powermanager/lib.js b/apps/powermanager/lib.js new file mode 100644 index 000000000..f4a7e3378 --- /dev/null +++ b/apps/powermanager/lib.js @@ -0,0 +1,6 @@ +// set battery calibration value by either applying the given value or setting the currently read battery voltage +exports.setCalibration = function(calibration){ + let s = require('Storage').readJSON("setting.json", true) || {}; + s.batFullVoltage = calibration?calibration:((analogRead(D3) + analogRead(D3) + analogRead(D3) + analogRead(D3)) / 4); + require('Storage').writeJSON("setting.json", s); +} diff --git a/apps/powermanager/metadata.json b/apps/powermanager/metadata.json index dd1727657..0777feee3 100644 --- a/apps/powermanager/metadata.json +++ b/apps/powermanager/metadata.json @@ -2,7 +2,7 @@ "id": "powermanager", "name": "Power Manager", "shortName": "Power Manager", - "version": "0.03", + "version": "0.04", "description": "Allow configuration of warnings and thresholds for battery charging and display.", "icon": "app.png", "type": "bootloader", @@ -12,6 +12,7 @@ "storage": [ {"name":"powermanager.boot.js","url":"boot.js"}, {"name":"powermanager.settings.js","url":"settings.js"}, + {"name":"powermanager","url":"lib.js"}, {"name":"powermanager.default.json","url":"default.json"} ] } diff --git a/apps/powermanager/settings.js b/apps/powermanager/settings.js index 7cc683024..9eeb29e00 100644 --- a/apps/powermanager/settings.js +++ b/apps/powermanager/settings.js @@ -23,7 +23,6 @@ '': { 'title': 'Power Manager' }, - '< Back': back, 'Monotonic percentage': { value: !!settings.forceMonoPercentage, onchange: v => { @@ -44,29 +43,29 @@ } }; - function roundToDigits(number, stepsize) { return Math.round(number / stepsize) * stepsize; } - function getCurrentVoltageDirect() { - return (analogRead(D3) + analogRead(D3) + analogRead(D3) + analogRead(D3)) / 4; - } - var stepsize = 0.0002; - var full = 0.32; + var full = 0.3144; function getInitialCalibrationOffset() { return roundToDigits(systemsettings.batFullVoltage - full, stepsize) || 0; } - var submenu_calibrate = { '': { - title: "Calibrate" + title: "Calibrate", + back: function() { + E.showMenu(mainmenu); + }, }, - '< Back': function() { - E.showMenu(mainmenu); + 'Autodetect': { + value: !!settings.autoCalibration, + onchange: v => { + writeSettings("autoCalibration", v); + } }, 'Offset': { min: -0.05, @@ -75,25 +74,9 @@ value: getInitialCalibrationOffset(), format: v => roundToDigits(v, stepsize).toFixed((""+stepsize).length - 2), onchange: v => { - print(typeof v); - systemsettings.batFullVoltage = v + full; - require("Storage").writeJSON("setting.json", systemsettings); + require("powermanager").setCalibration(v + full); } }, - 'Auto': function() { - var newVoltage = getCurrentVoltageDirect(); - E.showAlert("Please charge fully before auto setting").then(() => { - E.showPrompt("Set current charge as full").then((r) => { - if (r) { - systemsettings.batFullVoltage = newVoltage; - require("Storage").writeJSON("setting.json", systemsettings); - //reset value shown in menu to the newly set one - submenu_calibrate.Offset.value = getInitialCalibrationOffset(); - E.showMenu(mainmenu); - } - }); - }); - }, 'Clear': function() { E.showPrompt("Clear charging offset?").then((r) => { if (r) { @@ -109,10 +92,10 @@ var submenu_chargewarn = { '': { - title: "Charge warning" - }, - '< Back': function() { - E.showMenu(mainmenu); + title: "Charge warning", + back: function() { + E.showMenu(mainmenu); + }, }, 'Enabled': { value: !!settings.warnEnabled, diff --git a/apps/powersave/ChangeLog b/apps/powersave/ChangeLog new file mode 100644 index 000000000..28d913cc8 --- /dev/null +++ b/apps/powersave/ChangeLog @@ -0,0 +1,3 @@ +0.01: Initial release +0.02: Removed accelerometer poll interval adjustment, fixed a few issues with detecting the current app +0.03: Fix a couple of silly mistakes \ No newline at end of file diff --git a/apps/powersave/README.md b/apps/powersave/README.md new file mode 100644 index 000000000..51ba044e1 --- /dev/null +++ b/apps/powersave/README.md @@ -0,0 +1,25 @@ +# Power Saver + +Save your watch's battery power by halting foreground app execution while the screen is off. + +## Features +- Stops foreground app processes +- Background processes still run +- Clears screen +- Foreground app is returned to when screen is turned back on (app state is not preserved) + +## Controls +- Automatically activates when screen times out, timing can be adjusted using normal timeout settings +- Deactivates when screen is turned back on + +## Warnings +- This is not compatible with apps that need to run in the foreground even while the screen is off, such as most stopwatch apps and some health trackers. +- If you check your watch super often (like multiple times per minute), this may end of costing you more power than it saves since the app you are using will have to restart everytime you check it. + +## Requests + +[Contact information is on my website](https://kyleplo.com/#contact) + +## Creator + +[kyleplo](https://kyleplo.com) \ No newline at end of file diff --git a/apps/powersave/boot.js b/apps/powersave/boot.js new file mode 100644 index 000000000..f37fbc536 --- /dev/null +++ b/apps/powersave/boot.js @@ -0,0 +1,20 @@ +var Storage = Storage || require("Storage"); +Bangle.on("lock", locked => { + if(locked){ + load("powersave.screen.js"); + }else{ + const data = JSON.parse(Storage.read("powersave.json") || Storage.read("setting.json")); + load(data.app || data.clock); + } +}); +E.on("init", () => { + if("__FILE__" in global && __FILE__ !== "powersave.screen.js"){ + Storage.write("powersave.json", { + app: __FILE__ + }); + }else if(!("__FILE__" in global)){ + Storage.write("powersave.json", { + app: null + }); + } +}); \ No newline at end of file diff --git a/apps/powersave/metadata.json b/apps/powersave/metadata.json new file mode 100644 index 000000000..705384058 --- /dev/null +++ b/apps/powersave/metadata.json @@ -0,0 +1,18 @@ +{ + "id": "powersave", + "name": "Power Save", + "version": "0.03", + "description": "Halts foreground app execution while screen is off while still allowing background processes.", + "readme": "README.md", + "icon": "powersave.png", + "type": "bootloader", + "tags": "tool", + "supports": ["BANGLEJS2"], + "storage": [ + {"name":"powersave.boot.js","url":"boot.js"}, + {"name":"powersave.screen.js","url":"screen.js"} + ], + "data": [ + {"name": "powersave.json"} + ] +} \ No newline at end of file diff --git a/apps/powersave/powersave.png b/apps/powersave/powersave.png new file mode 100644 index 000000000..fa0399b73 Binary files /dev/null and b/apps/powersave/powersave.png differ diff --git a/apps/powersave/screen.js b/apps/powersave/screen.js new file mode 100644 index 000000000..c920b205d --- /dev/null +++ b/apps/powersave/screen.js @@ -0,0 +1,7 @@ +g.clear(); +Bangle.setLCDBrightness(0); +if(!Bangle.isLocked()){ + var Storage = Storage || require("Storage"); + const data = JSON.parse(Storage.read("powersave.json") || Storage.read("setting.json")); + load(data.app || data.clock); +} \ No newline at end of file diff --git a/apps/presentation_timer/ChangeLog b/apps/presentation_timer/ChangeLog new file mode 100644 index 000000000..2ed460931 --- /dev/null +++ b/apps/presentation_timer/ChangeLog @@ -0,0 +1,2 @@ +0.01: first release +0.02: added interface for configuration from app loader diff --git a/apps/presentation_timer/README.md b/apps/presentation_timer/README.md new file mode 100644 index 000000000..4539fc2f9 --- /dev/null +++ b/apps/presentation_timer/README.md @@ -0,0 +1,47 @@ +# Presentation Timer + +*Forked from Stopwatch Touch* + +Simple application to keep track of slides and +time during a presentation. Useful for conferences, +lectures or any presentation with a somewhat strict timing. + +The interface is pretty simple, it shows a stopwatch +and the number of the current slide (based on the time), +when the time for the last slide is approaching, +the button becomes red, when it passed, +the time will go on for another half a minute and stop automatically. + +You can set personalized timings from the web interface +by uploading a CSV to the bangle (floppy disk button in the app loader). + +Each line in the file (`presentation_timer.csv`) +contains the time in minutes at which the slide +is supposed to finish and the slide number, +separated by a semicolon. +For instance the line `1.5;1` means that slide 1 +is lasting until 1 minutes 30 seconds (yes it's decimal), +after another slide will start. +The only requirement is that timings are increasing, +so slides number don't have to be consecutive, +some can be skipped and they can even be short texts. + +At the moment the app is just quick and dirty +but it should do its job. + +## Screenshots + +![](screenshot1.png) +![](screenshot2.png) +![](screenshot3.png) +![](screenshot4.png) + +## Example configuration file + +_presentation_timer.csv_ +```csv +1.5;1 +2;2 +2.5;3 +3;4 +``` diff --git a/apps/presentation_timer/interface.html b/apps/presentation_timer/interface.html new file mode 100644 index 000000000..137ea8475 --- /dev/null +++ b/apps/presentation_timer/interface.html @@ -0,0 +1,136 @@ + + + + + + + +
+ + + + + +

+
+    
+    
+  
+
diff --git a/apps/presentation_timer/metadata.json b/apps/presentation_timer/metadata.json
new file mode 100644
index 000000000..8790d6208
--- /dev/null
+++ b/apps/presentation_timer/metadata.json
@@ -0,0 +1,17 @@
+{
+  "id": "presentation_timer",
+  "name": "Presentation Timer",
+  "version": "0.02",
+  "description": "A touch based presentation timer for Bangle JS 2",
+  "icon": "presentation_timer.png",
+  "screenshots": [{"url":"screenshot1.png"},{"url":"screenshot2.png"},{"url":"screenshot3.png"},{"url":"screenshot4.png"}],
+  "tags": "tools,app",
+  "supports": ["BANGLEJS2"],
+  "readme": "README.md",
+  "interface": "interface.html",
+  "storage": [
+    {"name":"presentation_timer.app.js","url":"presentation_timer.app.js"},
+    {"name":"presentation_timer.img","url":"presentation_timer.icon.js","evaluate":true}
+  ],
+  "data": [{ "name": "presentation_timer.csv" }]
+}
diff --git a/apps/presentation_timer/presentation_timer.app.js b/apps/presentation_timer/presentation_timer.app.js
new file mode 100644
index 000000000..1d0e5945d
--- /dev/null
+++ b/apps/presentation_timer/presentation_timer.app.js
@@ -0,0 +1,272 @@
+let w = g.getWidth();
+let h = g.getHeight();
+let tTotal = Date.now();
+let tStart = tTotal;
+let tCurrent = tTotal;
+let running = false;
+let timeY = 2*h/5;
+let displayInterval;
+let redrawButtons = true;
+const iconScale = g.getWidth() / 178; // scale up/down based on Bangle 2 size
+
+// 24 pixel images, scale to watch
+// 1 bit optimal, image string, no E.toArrayBuffer()
+const pause_img = atob("GBiBAf////////////////wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP/wYP////////////////w==");
+const play_img = atob("GBjBAP//AAAAAAAAAAAIAAAOAAAPgAAP4AAP+AAP/AAP/wAP/8AP//AP//gP//gP//AP/8AP/wAP/AAP+AAP4AAPgAAOAAAIAAAAAAAAAAA=");
+const reset_img = atob("GBiBAf////////////AAD+AAB+f/5+f/5+f/5+cA5+cA5+cA5+cA5+cA5+cA5+cA5+cA5+f/5+f/5+f/5+AAB/AAD////////////w==");
+
+const margin = 0.5; //half a minute tolerance
+
+//dummy default values
+var slides = [
+  [1.5, 1],
+  [2, 2],
+  [2.5, 3],
+  [3,4]
+];
+
+function log_debug(o) {
+  //console.log(o);
+}
+
+//first must be a number
+function readSlides() {
+  let csv = require("Storage").read("presentation_timer.csv");
+  if(!csv) return;
+  let lines = csv.split("\n").filter(e=>e);
+  log_debug("Loading "+lines.length+" slides");
+  slides = lines.map(line=>{let s=line.split(";");return [+s[0],s[1]];});
+}
+
+
+function timeToText(t) {
+  let hrs = Math.floor(t/3600000);
+  let mins = Math.floor(t/60000)%60;
+  let secs = Math.floor(t/1000)%60;
+  let tnth = Math.floor(t/100)%10;
+  let text;
+
+  if (hrs === 0)
+    text = ("0"+mins).substr(-2) + ":" + ("0"+secs).substr(-2) + "." + tnth;
+  else
+    text = ("0"+hrs) + ":" + ("0"+mins).substr(-2) + ":" + ("0"+secs).substr(-2);
+
+  //log_debug(text);
+  return text;
+}
+
+function drawButtons() {
+  log_debug("drawButtons()");
+  if (!running && tCurrent == tTotal) {
+    bigPlayPauseBtn.draw();
+  } else if (!running && tCurrent != tTotal) {
+    resetBtn.draw();
+    smallPlayPauseBtn.draw();
+  } else {
+    bigPlayPauseBtn.draw();
+  }
+
+  redrawButtons = false;
+}
+
+//not efficient but damn easy
+function findSlide(time) {
+  time /= 60000;
+  //change colour for the last 30 seconds
+  if(time > slides[slides.length-1][0] - margin && bigPlayPauseBtn.color!="#f00") {
+    bigPlayPauseBtn.color="#f00";
+    drawButtons();
+  }
+  for(let i=0; i time)
+      return slides[i][1];
+  }
+  //stop automatically
+  if(time > slides[slides.length-1][0] + margin) {
+    bigPlayPauseBtn.color="#0ff"; //restore
+    stopTimer();
+  }
+  return /*LANG*/"end!";
+}
+
+function drawTime() {
+  log_debug("drawTime()");
+  let Tt = tCurrent-tTotal;
+  let Ttxt = timeToText(Tt);
+
+  Ttxt += "\n"+findSlide(Tt);
+  // total time
+  g.setFont("Vector",38);  // check
+  g.setFontAlign(0,0);
+  g.clearRect(0, timeY - 42, w, timeY + 42);
+  g.setColor(g.theme.fg);
+  g.drawString(Ttxt, w/2, timeY);
+}
+
+function draw() {
+  let last = tCurrent;
+  if (running) tCurrent = Date.now();
+  g.setColor(g.theme.fg);
+  if (redrawButtons) drawButtons();
+  drawTime();
+}
+
+function startTimer() {
+  log_debug("startTimer()");
+  draw();
+  displayInterval = setInterval(draw, 100);
+}
+
+function stopTimer() {
+  log_debug("stopTimer()");
+  if (displayInterval) {
+    clearInterval(displayInterval);
+    displayInterval = undefined;
+  }
+}
+
+// BTN stop start
+function stopStart() {
+  log_debug("stopStart()");
+
+  if (running)
+    stopTimer();
+
+  running = !running;
+  Bangle.buzz();
+
+  if (running)
+    tStart = Date.now() + tStart- tCurrent;  
+  tTotal = Date.now() + tTotal - tCurrent;
+  tCurrent = Date.now();
+
+  setButtonImages();
+  redrawButtons = true;
+  if (running) {
+    startTimer();
+  } else {
+    draw();
+  }
+}
+
+function setButtonImages() {
+  if (running) {
+    bigPlayPauseBtn.setImage(pause_img);
+    smallPlayPauseBtn.setImage(pause_img);
+    resetBtn.setImage(reset_img);
+  } else {
+    bigPlayPauseBtn.setImage(play_img);
+    smallPlayPauseBtn.setImage(play_img);
+    resetBtn.setImage(reset_img);
+  }
+}
+
+// lap or reset
+function lapReset() {
+  log_debug("lapReset()");
+  if (!running && tStart != tCurrent) {
+    redrawButtons = true;
+    Bangle.buzz();
+    tStart = tCurrent = tTotal = Date.now();
+    g.clearRect(0,24,w,h);
+    draw();
+  }
+}
+
+// simple on screen button class
+function BUTTON(name,x,y,w,h,c,f,i) {
+  this.name = name;
+  this.x = x;
+  this.y = y;
+  this.w = w;
+  this.h = h;
+  this.color = c;
+  this.callback = f;
+  this.img = i;
+}
+
+BUTTON.prototype.setImage = function(i) {
+  this.img = i;
+}
+
+// if pressed the callback
+BUTTON.prototype.check = function(x,y) {
+  //console.log(this.name + ":check() x=" + x + " y=" + y +"\n");
+  
+  if (x>= this.x && x<= (this.x + this.w) && y>= this.y && y<= (this.y + this.h)) {
+    log_debug(this.name + ":callback\n");
+    this.callback();
+    return true;
+  }
+  return false;
+};
+
+BUTTON.prototype.draw = function() {
+  g.setColor(this.color);
+  g.fillRect(this.x, this.y, this.x + this.w, this.y + this.h);
+  g.setColor("#000"); // the icons and boxes are drawn black
+  if (this.img != undefined) {
+    let iw = iconScale * 24;  // the images were loaded as 24 pixels, we will scale
+    let ix = this.x + ((this.w - iw) /2);
+    let iy = this.y + ((this.h - iw) /2);
+    log_debug("g.drawImage(" + ix + "," + iy + "{scale: " + iconScale + "})");
+    g.drawImage(this.img, ix, iy, {scale: iconScale}); 
+  }
+  g.drawRect(this.x, this.y, this.x + this.w, this.y + this.h);
+};
+
+
+var bigPlayPauseBtn = new BUTTON("big",0, 3*h/4 ,w, h/4, "#0ff", stopStart, play_img);
+var smallPlayPauseBtn = new BUTTON("small",w/2, 3*h/4 ,w/2, h/4, "#0ff", stopStart, play_img);
+var resetBtn = new BUTTON("rst",0, 3*h/4, w/2, h/4, "#ff0", lapReset, pause_img);
+
+bigPlayPauseBtn.setImage(play_img);
+smallPlayPauseBtn.setImage(play_img);
+resetBtn.setImage(pause_img);
+
+
+Bangle.on('touch', function(button, xy) {
+  var x = xy.x;
+  var y = xy.y;
+
+  // adjust for outside the dimension of the screen
+  // http://forum.espruino.com/conversations/371867/#comment16406025
+  if (y > h) y = h;
+  if (y < 0) y = 0;
+  if (x > w) x = w;
+  if (x < 0) x = 0;
+
+  // not running, and reset
+  if (!running && tCurrent == tTotal && bigPlayPauseBtn.check(x, y)) return;
+
+  // paused and hit play
+  if (!running && tCurrent != tTotal && smallPlayPauseBtn.check(x, y)) return;
+
+  // paused and press reset
+  if (!running && tCurrent != tTotal && resetBtn.check(x, y)) return;
+
+  // must be running
+  if (running && bigPlayPauseBtn.check(x, y)) return;
+});
+
+// Stop updates when LCD is off, restart when on
+Bangle.on('lcdPower',on=>{
+  if (on) {
+    draw(); // draw immediately, queue redraw
+  } else { // stop draw timer
+    if (drawTimeout) clearTimeout(drawTimeout);
+    drawTimeout = undefined;
+  }
+});
+
+// Clear the screen once, at startup
+g.setTheme({bg:"#000",fg:"#fff",dark:true}).clear();
+// above not working, hence using next 2 lines
+g.setColor("#000");
+g.fillRect(0,0,w,h);
+
+Bangle.loadWidgets();
+Bangle.drawWidgets();
+readSlides();
+draw();
+setWatch(() => load(), BTN, { repeat: false, edge: "falling" });
diff --git a/apps/presentation_timer/presentation_timer.icon.js b/apps/presentation_timer/presentation_timer.icon.js
new file mode 100644
index 000000000..f18768b2b
--- /dev/null
+++ b/apps/presentation_timer/presentation_timer.icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwxH+AC1WwIZXACmBF7FWAH4Ae/0WAFiQBF9+sAFgv/AAvXAAgvmFgoyWF6IuLGCIvPFpoxRF5wlIwIKJF8lWwIvjQpIvKGBgv8cpWBF5QwLF/4vrEJQvNGBQv/F5FWSCq/XGAVWB5DviEgRiJF8gxDF9q+SF5owWEJYv9GCggMF5wwSD5ovPGCAeOF6AwODp4vRGJYbRF6YAbF/4v/F8eBAYYECAYYvRACFWqwEGwNWwIeSF7IEFAD5VBGhpekAo6QiEYo1LR0QpGBgyOhAxCQfKIIhFGxpegA44+HF85gRA=="))
diff --git a/apps/presentation_timer/presentation_timer.png b/apps/presentation_timer/presentation_timer.png
new file mode 100644
index 000000000..7db9866d7
Binary files /dev/null and b/apps/presentation_timer/presentation_timer.png differ
diff --git a/apps/presentation_timer/screenshot1.png b/apps/presentation_timer/screenshot1.png
new file mode 100644
index 000000000..d26720d7e
Binary files /dev/null and b/apps/presentation_timer/screenshot1.png differ
diff --git a/apps/presentation_timer/screenshot2.png b/apps/presentation_timer/screenshot2.png
new file mode 100644
index 000000000..cbd6f0bd1
Binary files /dev/null and b/apps/presentation_timer/screenshot2.png differ
diff --git a/apps/presentation_timer/screenshot3.png b/apps/presentation_timer/screenshot3.png
new file mode 100644
index 000000000..40b375b37
Binary files /dev/null and b/apps/presentation_timer/screenshot3.png differ
diff --git a/apps/presentation_timer/screenshot4.png b/apps/presentation_timer/screenshot4.png
new file mode 100644
index 000000000..7c43cf91f
Binary files /dev/null and b/apps/presentation_timer/screenshot4.png differ
diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json
index e5b5e289f..2d0a22102 100644
--- a/apps/presentor/metadata.json
+++ b/apps/presentor/metadata.json
@@ -12,7 +12,8 @@
   "allow_emulator": true,
   "storage": [
     {"name":"presentor.app.js","url":"app.js"},
-    {"name":"presentor.img","url":"app-icon.js","evaluate":true},
+    {"name":"presentor.img","url":"app-icon.js","evaluate":true}
+  ], "data": [
     {"name":"presentor.json","url":"settings.json"}
   ]
 }
diff --git a/apps/primetime/README.md b/apps/primetime/README.md
new file mode 100644
index 000000000..a07c19f52
--- /dev/null
+++ b/apps/primetime/README.md
@@ -0,0 +1,10 @@
+# App Name
+
+Watchface that displays time and the prime factors of the "military time" (i.e. 21:05 => 2105, shows prime factors of 2105 which are 5 & 421). Displays "Prime Time!" if prime. 
+
+![image](https://user-images.githubusercontent.com/115424919/194777279-7f5e4d2a-f475-4099-beaf-38db5b460714.png)
+
+
+## Creator
+
+Adapted from simplestclock by [Eve Bury](https://www.github.com/eveeeon)
diff --git a/apps/primetime/app.png b/apps/primetime/app.png
new file mode 100644
index 000000000..5024727fb
Binary files /dev/null and b/apps/primetime/app.png differ
diff --git a/apps/primetime/metadata.json b/apps/primetime/metadata.json
new file mode 100644
index 000000000..d796d290c
--- /dev/null
+++ b/apps/primetime/metadata.json
@@ -0,0 +1,15 @@
+{ "id": "primetime",
+  "name": "Prime Time Clock",
+  "version": "0.01",  
+  "type": "clock",
+  "description": "A clock that tells you the primes of the time",
+  "icon": "app.png",
+  "screenshots": [{"url":"screenshot.png"}],  
+  "tags": "clock",
+  "supports": ["BANGLEJS2"],  
+  "readme": "README.md",
+  "storage": [
+    {"name":"primetime.app.js","url":"primetime.js"},
+    {"name":"primetime.img","url":"primetime-icon.js","evaluate":true}
+  ]
+}
diff --git a/apps/primetime/primetime-icon.js b/apps/primetime/primetime-icon.js
new file mode 100644
index 000000000..57969a68b
--- /dev/null
+++ b/apps/primetime/primetime-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwgVVABVADJMBBf4L/Bf4LMgtQgIHCitAqoHBoEv+EHwALBv/S//4BYO//svwELoP//X/+gLB2E93+Ah9B9f+//QBYMVvv3C4XvvwLDl/0q+AgsB998qt4F4XgHYIXB/1+6ALC//93/4F4I7CI4QLBAIMLoF/6ABBBYNVqgBBgprCAIKz0qkAooLHgP8gXvvALH/EL7e4BY+tz/+vovH3PR1++L9YL/BYdVABQ="))
diff --git a/apps/primetime/primetime.js b/apps/primetime/primetime.js
new file mode 100644
index 000000000..bba63bc48
--- /dev/null
+++ b/apps/primetime/primetime.js
@@ -0,0 +1,89 @@
+const h = g.getHeight();
+const w = g.getWidth();
+
+
+
+// creates a list of prime factors of n and outputs them as a string, if n is prime outputs "Prime Time!"
+function primeFactors(n) {
+  const factors = [];
+  let divisor = 2;
+
+  while (n >= 2) {
+    if (n % divisor == 0) {
+      factors.push(divisor);
+      n = n / divisor;
+    } else {
+      divisor++;
+    }
+  }
+  if (factors.length === 1) {
+    return "Prime Time!";
+  }
+  else
+    return factors.toString();
+}
+
+
+// converts time HR:MIN to integer HRMIN e.g. 15:35 => 1535
+function timeToInt(t) {
+    var arr = t.split(':');
+    var intTime = parseInt(arr[0])*100+parseInt(arr[1]);
+
+    return intTime;
+}
+
+
+
+function draw() {
+  var date = new Date();
+  var timeStr = require("locale").time(date,1);
+  var primeStr = primeFactors(timeToInt(timeStr));
+
+  g.reset();
+  g.setColor(0,0,0);
+  g.fillRect(Bangle.appRect);
+
+  g.setFont("6x8", w/30);
+  g.setFontAlign(0, 0);
+  g.setColor(100,100,100);
+  g.drawString(timeStr, w/2, h/2);
+  g.setFont("6x8", w/60);
+  g.drawString(primeStr, w/2, 3*h/4);
+  queueDraw();
+}
+
+// timeout used to update every minute
+var drawTimeout;
+
+// schedule a draw for the next minute
+function queueDraw() {
+  if (drawTimeout) clearTimeout(drawTimeout);
+  drawTimeout = setTimeout(function() {
+    drawTimeout = undefined;
+    draw();
+  }, 60000 - (Date.now() % 60000));
+}
+
+// Stop updates when LCD is off, restart when on
+Bangle.on('lcdPower',on=>{
+  if (on) {
+    draw(); // draw immediately, queue redraw
+  } else { // stop draw timer
+    if (drawTimeout) clearTimeout(drawTimeout);
+    drawTimeout = undefined;
+  }
+});
+
+g.clear();
+
+// Show launcher when middle button pressed
+// Bangle.setUI("clock");
+// use  clockupdown as it tests for issue #1249
+Bangle.setUI("clockupdown", btn=> {
+  draw();
+});
+
+// Load widgets
+Bangle.loadWidgets();
+Bangle.drawWidgets();
+draw();
diff --git a/apps/primetime/screenshot.png b/apps/primetime/screenshot.png
new file mode 100644
index 000000000..cb625a9b6
Binary files /dev/null and b/apps/primetime/screenshot.png differ
diff --git a/apps/primetimelato/ChangeLog b/apps/primetimelato/ChangeLog
new file mode 100644
index 000000000..7781e93a1
--- /dev/null
+++ b/apps/primetimelato/ChangeLog
@@ -0,0 +1,4 @@
+0.01: first release
+0.02: added option to buzz on prime, with settings
+0.03: added option to debug settings and test fw 2.15.93 load speed ups
+0.04: changed icon
diff --git a/apps/primetimelato/README.md b/apps/primetimelato/README.md
new file mode 100644
index 000000000..0ffd5a3fa
--- /dev/null
+++ b/apps/primetimelato/README.md
@@ -0,0 +1,19 @@
+# Prime Lato (clock)
+
+A watchface that displays time and its prime factors in the Lato font.
+For example when the time is 21:05, the prime factors are 5,421.
+Displays 'Prime Time!' when the time is a prime number.
+
+There is a settings option added in the Settings App.  If 'Buzz on
+Prime' is ticked then the buzzer will sound when 'Prime Time!' is
+detected.  Note the buzzer is limited to between 8am and 8pm so it
+should not go off when you want to sleep.
+
+
+![](screenshot.jpg)
+
+Written by: [Hugh Barney](https://github.com/hughbarney)
+
+Adapted from primetime by [Eve Bury](https://www.github.com/eveeeon)
+
+For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/)
diff --git a/apps/primetimelato/app.js b/apps/primetimelato/app.js
new file mode 100644
index 000000000..b4b9d5bb9
--- /dev/null
+++ b/apps/primetimelato/app.js
@@ -0,0 +1,156 @@
+const h = g.getHeight();
+const w = g.getWidth();
+const SETTINGS_FILE = "primetimelato.json";
+let settings;
+let setStr = 'U';
+    
+Graphics.prototype.setFontLato = function(scale) {
+  // Actual height 41 (43 - 3)
+  this.setFontCustom(
+    E.toString(require('heatshrink').decompress(atob('ACEfAokB/AGEn+AAocDBgsfBgkB+A6Yg4FEgYgF/4FEv/gHIhAEh/+DwgYEgP/4AeJn4eF/hDEDwxrE/4eFKAgeFgJDERQ5DEXJI0Eh//IIZlB/4pDAoP/HgQYBAAIaBPARDDv4JBj5WBh5ZCv4CBPATPCeQcPwDYECAIMGPId4gEeSIYMHDIYMCExZAGh6ICn5QEK4RnGOgqBGaoKOECYSiDn78FAFgxFR4bcCKISOBgF+RwYCBTgQMCOIQMCj5eCBgIfDBgQfCBgSbDWoSHC/61CAwYMUAAYzCAAZNCBkYAfgYmBgJ7CTYsPTYQMBgJnBgYMCn4MBv64CBgMPXYSBBD4cfBgQIBgf3RwK7CvybCGQXPBgIfBGQIMBeoU/DoIMCF4IMDgP8BgQmBn8AEwb+BBgQIBIQJAC4BYBIgTNBDYIMBg///xRDn//OoIMBcYISBBgUHNATpCgjCngIEDFIM+AoV8TYKYCMIJQBAQLCCgZcBYQIJBX4UHCwSJBYQaSCMYQDCYQabEBgngW4V4WoQBBOgIMN+AoCEwY+BGYZfBYwQIBv+AG4X+j/8K4TCB+bECM4P+YgcD//B/67Ch/4h//K4SSBv5IBAAdAWqMYAokDD4t+AokfBgi0DAAX/Bgkf7wSE/IME/6PBCQfBBgcD/AME/ypCCQXABgYSBBgg+BBgYSBBgatBBggSBBgYSBBgcB/4ACZ4QGDZ4IMLFARAEAAJaEBjQAUhAnFMgIABuD5CVwWAboUDLwZ0DNYKLBM4IMBh50C55rBCoWACAIMC+EPFIN4EQQMBg4MSHgYzEBgIzBIAUAvhND+EH8DZCBAN/bIfwMQP/OgIMBLgalCBgKlDg//V4kfCQIAqWgYzC/gFDIAJgBZoS3CAwV//4TDh/+j5UCCQOAn4SD8DPCCQSbCCQR/BNAV/3i1CB4PzAYLCBgP8AYIMCv+HBgcP+AMDCQMHEwb2BYQLPDgYMBIAKoBOYLPCwDNBZ4UQBQPhJ4J0EDYJbCZ4R7EAoZiDSoaUDADBNBFQj5EKwQMEGAoMEOgQFCnAMEQIYFBgaOCBgTRBBgc/AYIMCaIQMCgb2CBgX/JQIMCDAQMCh/8JoYYBJoiNDBgIYDBgIYDBgPzUwkfUwisBOokfDAYMCQIq/ERwwAcn4pCgfwg42D//B/6hBCAP+KwYQBMQKbBgF//9+g5EBh4YB4CfC/EHDwK1Dn7PD8A0BgF4gEeAIUHBgQBBBi4mEGYpAEAIMP4BNELQpnGOgM/ZYaBFGQMPYos/JAIAuj4xEKgJrBfoX//hEE/4TDCQJSCCoN/gZfBjCBCj+AgaOCAIiKBg4OCgKKBvgbCWYMDToK1CgE8JIQMC4ZCBBgU4HYTNCz4JBEwV7KoQzCUIYvBLYZNBn60CLQPfCQcDM4LHCEALHDZ4TaCCYaODHYK8fh6FDEwKSCF4Uf4COCBgJsBn4MDDIJPDVgYAZA='))),
+    46,
+    atob("CxMeHh4eHh4eHh4eDQ=="),
+    52+(scale<<8)+(1<<16)
+  );
+  return this;
+};
+
+Graphics.prototype.setFontLatoSmall = function(scale) {
+  // Actual height 21 (20 - 0)
+  this.setFontCustom(
+    E.toString(require('heatshrink').decompress(atob('AB0B/+ch/88EAgQPHg/AgE+A4cPwEAvwTHoEAscQgc/wE//EP/0Au0wgEz/ED/+A//gg9jgEDiEAAIIACgcBwF+h0H+EwmPBwOf/4AB8Ng4cDg84hkfwFAvA/EgZfBneAwOEjkMkPAuccgPzwAbBCQJeBuZBBKYNxxkOhkgsFjgUD+B5BNox+Bgf4g/Y8F/wcDjkYjFw4HB40Gg8wjkfQgJLBj6bB84fBjCQDU5AAFj/wg//+A1B9xEGhkAg18gPx//+bgJmBAAckAQOgDQa+BgI2BjQ0HsBoBJogSBZgX/DQIrBG4IUFAAs7CQKVBFJ0GB4kEAQNwYQYACEIKaBRYX4RoQGCCoIADMwMf/kB8HwdQPA4EGGAMwmEBwPAjkHwfACgMAv4iBAAxICuEMSQNguEDgf//Ef/5ZEmCDDAAkBgHgnEOgfA8Eeg0B2EwjOBweMh04sE/wZlBfYomCjkPEIM8VwNgsI+BhkYjHg4HnFoPv8EOQYIAFQwMHJAN8gEOW4PjAgMYQwUPcIN/cI4ACkCNBgP8hkPsFgsY+BHoMYD4PHjkGj/gkAxBAAoHBh/wgPxV4J8B7EwnnBwPGhkMnHggLUBg/gXI6oDCgLiBsE+gb0BjD7B74bDni1CAAk8gP3+EP/ZTBfYMYfYI+Bw0Mh148E+HwPj+A6DAAIpBj6HB/0EhkwPwPPgcE+EYt4ZB8EDDwMP4EAiAeDgUCgE4nEB4INBAAcBKQMcjuA8BhBAAh2BgY5BjwUBJAMMDwPGJoMYf4ImFAAoUCswhBEgMZEgPMDgL7BmYpBzAUDABnBwEDhhTBFIiIBh4PBuDKCCwR6BgITBDAKSB88Dh84jAKB/geBHAQcBj/wgPhcIMDgOBhkYn0w4exw0wwkhxkhxHBhl/hFj7BKBo0Mg0wnnjgF+LIkEbQc/gEH8EBHgM/sEH4bGBjEB/HAgf2JIKvBCgICBJ4MOaYv//kP//gsHDga/BjEw4HBw0GjkwnHhwH9/kH54hBnggDkB1D//AjydBPIIyBFIMDgcAFIILB4EGg0AFIILBCgLLHj4kB//+CgUwTwOAhi8DFIccZANghkD4Pgh/+D4L7IFIpuBmHBwOGFIMwsFhwcDaAJTCwECSRasBJgIjBgDXBgxMBEYMBwUAhAdEn+Ag//gF8vkDwHgPoJoIXgnhw0Dh/gjF/Mo8D//4NASDBIgICBPQJLBIgJZBwEAF4IwBgB9BIYPwE44pHBYoiHg4EBvAUBwAZBExMAv//FIQbCKYU8AgJABnPggeHwE4jyKBnC8CgC8LEQZ2PNBA4BgIgCDYMHCwMfJIYNCnwMBB4N4gEPBYY+CNAJyHU4U/QoIxCFwQNBjwCBnACBHgpoGAAz4BB4PAj5OB8E4hwDBsEDPwMYSQXAgx+BmE4TwIUBPAOAh65Bj5wBAAxTBwI+BhgiBsHAgYiBjChB4OAg8cDwJVBvgfHB4KCBvl8HQmBwEMXoNgKY/ghwUBPAP+SoPhwF8ghOH//+U4UwsEBwbnBKYXwgcPRQPngF+jzMBuAbBOYnAn8GgP4nEc8HA4aSBjkwmHhwPDzkGNwMgNwYwBDoMAQgKoBcYIqBfYhoBChQAFv/4YIPwewIgBboIoFSIJnBgEHAgPwj6nBDIQVEAwMH8BBBAQQ6BdIUeCAc/BgR4BHwI6BCYJTCEIQCBj4CBh4CCE4QVBDQP+dYYLBnwcBBIMBAQoUBg/Agf8KwIZBHYIoBNIQSBfYUcIQP4nkB8YZBDwMPLoK5BJIXz8EPg+A8EeU4KmCXgYFBngCBDwL2BLAJGBMwIHCB4JKBgF4BwIWBiBGCgQpBuEwg+BwF8hkPsFg+cDj0YjPg4HcgwhBmBXBCgJnDAALmB/+f//8JYMkIoIMCHYJqCAQUfBYICCUYU4EgkIJINAgETFIgPEgAhBHoJtEgb3DQoacBSAQAGkBLDGYMAGYMCQ4gYBgiLCAQMYAQIzBDQQAFsbZBMYMxzEBxlAhlmgFikCIBwEPLowABn//4P/aIMwCgJUBjBpB4FgWYISBMIP/OYYAEg4MBv/Ag4UBmEYEAPAhjlBsEwgLyCAAcBIYMf+EB4IUFHwcIj//8C5BLA4cB4EBBgMdjkA5BTBocAmQ+ByBGBx0AjlgDISoCfwJ4BQ4P4jKwB5kAgwTDsEP3+A//mg03mEwzOBwnMU4Ngv8zgfh+EYPAKEEFIIuB4BnBEoMAPgTcEHgMAh/4NQ8gBwOf/kcPoKWEyEAhvP//uv7UBQgiSETgJ4BAgLJBnPAgeHcweAGALDGfYMP/4XBAAxmBSoP4FYQgBNAsPcIN/8CBCmBADCgV/dwP/BAIpIYgQpHLoIpCdwT7Mj08EIL7BDoMwfYOA4EOhwxBT4KUFHwXwZ4ITB4EMaQNgmEDDoMYH4LeBgZtBgZdFHwscCgI+HwOAUoPgv5eIPp8QCgcD4YUBFIOYKYPGgFjKYMfwEIvAUCgi8Dj5qBcwJoGGQQADn7JCH4J9BbRHAKYoAEuBLBVIMHAQMPEIMPBoIUBJYIMCvhoDAAQZFDgkeBQUBDwIGBEYUBXgIKCgYUBNAM/wA+CSQi8CnE4gH3B4PwFIINBIIMPSQPh8AUCAAMBLQR3Bn4KBn4SBv4fDDgJlBgI2BTw0AU4XBFIMfgEx7EB3nAh+GgF4XgOBF4JRCGAP/8f+/+YbAINBkArGbwIQB/5BBAArwBgLSBhP/v/H/6QBBAIACjhrDKwVgdAwHBRQThBgIbD'))),
+    32,
+    atob("BAcIDAwRDwUGBggMBAcECAwMDAwMDAwMDAwFBQwMDAgRDg4OEAwMDxAGCQ4LExARDREOCwwPDhUODQ0GCAYMCAYLDAoMCwcLDAUFCwURDAwMDAgJCAwLEAsLCgYGBgwA"),
+    21+(scale<<8)+(1<<16)
+  );
+  return this;
+};
+
+function loadSettings() {
+  settings = require("Storage").readJSON(SETTINGS_FILE,1)||{};
+  settings.buzz_on_prime = (settings.buzz_on_prime === undefined ? false : settings.buzz_on_prime);
+  settings.debug = (settings.debug === undefined ? false : settings.debug);
+
+  switch(settings.buzz_on_prime) {
+  case true:
+    setStr = 'T';
+    break;
+
+  case false:
+    setStr = 'F';
+    break;
+
+  case undefined:
+  default:
+    setStr = 'U';
+    break;
+  }
+}
+	
+// creates a list of prime factors of n and outputs them as a string, if n is prime outputs "Prime Time!"
+function primeFactors(n) {
+  const factors = [];
+  let divisor = 2;
+
+  while (n >= 2) {
+    if (n % divisor == 0) {
+      factors.push(divisor);
+      n = n / divisor;
+    } else {
+      divisor++;
+    }
+  }
+  if (factors.length === 1) {
+    return "Prime Time!";
+  }
+  else
+    return factors.toString();
+}
+
+
+// converts time HR:MIN to integer HRMIN e.g. 15:35 => 1535
+function timeToInt(t) {
+    var arr = t.split(':');
+    var intTime = parseInt(arr[0])*100+parseInt(arr[1]);
+
+    return intTime;
+}
+
+function draw() {
+  var date = new Date();
+  var timeStr = require("locale").time(date,1);
+  var intTime = timeToInt(timeStr);
+  var primeStr = primeFactors(intTime);
+
+  g.reset();
+  g.setColor(0,0,0);
+  g.fillRect(Bangle.appRect);
+
+  g.setColor(100,100,100);
+
+  if (settings.debug) {
+    g.setFontLatoSmall();
+    g.setFontAlign(0, 0);
+    g.drawString(setStr, w/2, h/4);
+  }
+  
+  g.setFontLato();
+  g.setFontAlign(0, 0);
+  g.drawString(timeStr, w/2, h/2);
+
+  g.setFontLatoSmall();
+  g.drawString(primeStr, w/2, 3*h/4);
+
+  // Buzz if Prime Time and between 8am and 8pm
+  if (settings.buzz_on_prime && primeStr == "Prime Time!" && intTime >= 800 && intTime <= 2000)
+      buzzer(2);
+  queueDraw();
+}
+
+// timeout for multi-buzzer
+var buzzTimeout;
+
+// n buzzes
+function buzzer(n) {
+  if (n-- < 1) return;
+  Bangle.buzz(250);
+  
+  if (buzzTimeout) clearTimeout(buzzTimeout);
+  buzzTimeout = setTimeout(function() {
+    buzzTimeout = undefined;
+    buzzer(n);
+  }, 500);
+}
+	
+// timeout used to update every minute
+var drawTimeout;
+
+// schedule a draw for the next minute
+function queueDraw() {
+  if (drawTimeout) clearTimeout(drawTimeout);
+  drawTimeout = setTimeout(function() {
+    drawTimeout = undefined;
+    draw();
+  }, 60000 - (Date.now() % 60000));
+}
+
+// Stop updates when LCD is off, restart when on
+Bangle.on('lcdPower',on=>{
+  if (on) {
+    draw(); // draw immediately, queue redraw
+  } else { // stop draw timer
+    if (drawTimeout) clearTimeout(drawTimeout);
+    drawTimeout = undefined;
+  }
+});
+
+
+loadSettings();
+g.clear();
+// Show launcher when middle button pressed
+Bangle.setUI("clock");
+
+// Load widgets
+Bangle.loadWidgets();
+Bangle.drawWidgets();
+draw();
diff --git a/apps/primetimelato/app.png b/apps/primetimelato/app.png
new file mode 100644
index 000000000..e5762b97c
Binary files /dev/null and b/apps/primetimelato/app.png differ
diff --git a/apps/primetimelato/icon.js b/apps/primetimelato/icon.js
new file mode 100644
index 000000000..7c8d5380b
--- /dev/null
+++ b/apps/primetimelato/icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEw4X/AAIHB8cYttrJf4AR1gKJgdYBZMCBZdcBZMNsALKuALJhNABZMFwALJmvAAwkOqvAmtAkwSF83+uEV4EMOIpZBznWII5NB7mXGo5BB7Z0HkpBB6x0HFYXVNA4rC6pcFAANXDQhSFqgaEBZGYaBLfIaAUBBZUJNQ4jCm+cHZPcBZFXgdwzELBg1W/PAy/rBY3VPAOVTY863kAnaPHAH4A/ADAA=="))
diff --git a/apps/primetimelato/metadata.json b/apps/primetimelato/metadata.json
new file mode 100644
index 000000000..400220b10
--- /dev/null
+++ b/apps/primetimelato/metadata.json
@@ -0,0 +1,18 @@
+{ "id": "primetimelato",
+  "name": "Prime Lato",
+  "version": "0.04",  
+  "type": "clock",
+  "description": "A clock that tells you the primes of the time in the Lato font",
+  "icon": "app.png",
+  "screenshots": [{"url":"screenshot.png"}],  
+  "tags": "clock",
+  "supports": ["BANGLEJS2"],  
+  "readme": "README.md",
+  "storage": [
+    {"name":"primetimelato.app.js","url":"app.js"},
+    {"name":"primetimelato.img","url":"icon.js","evaluate":true},
+    {"name":"primetimelato.settings.js","url":"settings.js"}
+
+  ],
+  "data": [{"name":"primetimelato.json"}]
+}
diff --git a/apps/primetimelato/screenshot.png b/apps/primetimelato/screenshot.png
new file mode 100644
index 000000000..7f6e7cc0d
Binary files /dev/null and b/apps/primetimelato/screenshot.png differ
diff --git a/apps/primetimelato/settings.js b/apps/primetimelato/settings.js
new file mode 100644
index 000000000..069c976c8
--- /dev/null
+++ b/apps/primetimelato/settings.js
@@ -0,0 +1,45 @@
+(function(back) {
+  const SETTINGS_FILE = "primetimelato.json";
+
+  // initialize with default settings...
+  let s = {
+    'buzz_on_prime': true,
+    'debug': false
+  }
+
+  // ...and overwrite them with any saved values
+  // This way saved values are preserved if a new version adds more settings
+  const storage = require('Storage')
+  let settings = storage.readJSON(SETTINGS_FILE, 1) || {}
+  const saved = settings || {}
+  for (const key in saved) {
+    s[key] = saved[key]
+  }
+
+  function save() {
+      settings = s;
+      storage.write(SETTINGS_FILE, settings);
+  }
+
+  E.showMenu({
+    '': { 'title': 'Prime Time Lato' },
+    '< Back': back,
+    'Buzz on Prime': {
+      value: !!s.buzz_on_prime,
+      onchange: v => {
+        s.buzz_on_prime = v;
+        save();
+      },
+    },
+
+    'Debug': {
+      value: !!s.debug,
+      onchange: v => {
+        s.debug = v;
+        save();
+      },
+    }
+
+    
+  })
+})
diff --git a/apps/ptlaunch/ChangeLog b/apps/ptlaunch/ChangeLog
index eec3610ed..5871b1fdc 100644
--- a/apps/ptlaunch/ChangeLog
+++ b/apps/ptlaunch/ChangeLog
@@ -6,3 +6,4 @@
 0.12: Improve pattern detection code readability by PaddeK http://forum.espruino.com/profiles/117930/
 0.13: Improve pattern rendering by HughB http://forum.espruino.com/profiles/167235/
 0.14: Update setUI to work with new Bangle.js 2v13 menu style
+0.15: Update to support clocks in custom setUI mode
diff --git a/apps/ptlaunch/boot.js b/apps/ptlaunch/boot.js
index 748d564f3..885962761 100644
--- a/apps/ptlaunch/boot.js
+++ b/apps/ptlaunch/boot.js
@@ -76,13 +76,8 @@
   var sui = Bangle.setUI;
   Bangle.setUI = function (mode, cb) {
     sui(mode, cb);
-    if ("object"==typeof mode) mode = mode.mode;
-    if (!mode) {
-      Bangle.removeListener("drag", dragHandler);
-      storedPatterns = {};
-      return;
-    }
-    if (!mode.startsWith("clock")) {
+    if (typeof mode === "object") mode = (mode.clock ? "clock" : "") + mode.mode;
+    if (!mode || !mode.startsWith("clock")) {
       storedPatterns = {};
       Bangle.removeListener("drag", dragHandler);
       return;
diff --git a/apps/ptlaunch/metadata.json b/apps/ptlaunch/metadata.json
index 0b6dce3d1..6f8a9e16f 100644
--- a/apps/ptlaunch/metadata.json
+++ b/apps/ptlaunch/metadata.json
@@ -2,7 +2,7 @@
   "id": "ptlaunch",
   "name": "Pattern Launcher",
   "shortName": "Pattern Launcher",
-  "version": "0.14",
+  "version": "0.15",
   "description": "Directly launch apps from the clock screen with custom patterns.",
   "icon": "app.png",
   "screenshots": [{"url":"manage_patterns_light.png"}],
diff --git a/apps/qcenter/ChangeLog b/apps/qcenter/ChangeLog
new file mode 100644
index 000000000..900b9017c
--- /dev/null
+++ b/apps/qcenter/ChangeLog
@@ -0,0 +1,2 @@
+0.01: New App!
+0.02: Fix fast loading on swipe to clock
diff --git a/apps/qcenter/README.md b/apps/qcenter/README.md
new file mode 100644
index 000000000..4931b9c7f
--- /dev/null
+++ b/apps/qcenter/README.md
@@ -0,0 +1,20 @@
+# Quick Center
+
+An app with a status bar showing various information and up to six shortcuts for your favorite apps!
+Designed for use with any kind of quick launcher, such as Quick Launch or Pattern Launcher.
+
+![](screenshot.png)
+
+## Usage
+
+Pin your apps with settings, then launch them with your favorite quick launcher to access them quickly.
+If you don't have any apps pinned, the settings and about apps will be shown as an example.
+
+## Features
+
+Battery and GPS status display (for now)
+Up to six shortcuts to your favorite apps
+
+## Upcoming features
+- Quick switches for toggleable features such as Bluetooth or HID mode
+- Customizable status information
\ No newline at end of file
diff --git a/apps/qcenter/app-icon.js b/apps/qcenter/app-icon.js
new file mode 100644
index 000000000..bfc94d10a
--- /dev/null
+++ b/apps/qcenter/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEw4UB6cA/4ACBYNVAElQHAsFBYZFHCxIYEoALHgILNOxILChWqAAmgBYNUBZMVBYIAIBc0C1WAlWoAgQL/O96D/Qf4LZqoLJqoLMoAKHgILNqALHgoLBGBAKCDA4WDAEQA="))
\ No newline at end of file
diff --git a/apps/qcenter/app.js b/apps/qcenter/app.js
new file mode 100644
index 000000000..be28db3b6
--- /dev/null
+++ b/apps/qcenter/app.js
@@ -0,0 +1,129 @@
+{
+require("Font8x12").add(Graphics);
+
+// load pinned apps from config
+let settings = require("Storage").readJSON("qcenter.json", 1) || {};
+let pinnedApps = settings.pinnedApps || [];
+let exitGesture = settings.exitGesture || "swipeup";
+
+// if empty load a default set of apps as an example
+if (pinnedApps.length == 0) {
+  pinnedApps = [
+    { src: "setting.app.js", icon: "setting.img" },
+    { src: "about.app.js", icon: "about.img" },
+  ];
+}
+
+// button drawing from Layout.js, edited to have completely custom button size with icon
+let drawButton = function(l) {
+  let x = l.x + (0 | l.pad),
+    y = l.y + (0 | l.pad),
+    w = l.w - (l.pad << 1),
+    h = l.h - (l.pad << 1);
+  let poly = [
+      x,
+      y + 4,
+      x + 4,
+      y,
+      x + w - 5,
+      y,
+      x + w - 1,
+      y + 4,
+      x + w - 1,
+      y + h - 5,
+      x + w - 5,
+      y + h - 1,
+      x + 4,
+      y + h - 1,
+      x,
+      y + h - 5,
+      x,
+      y + 4,
+    ],
+    bg = l.selected ? g.theme.bgH : g.theme.bg2;
+  g.setColor(bg)
+    .fillPoly(poly)
+    .setColor(l.selected ? g.theme.fgH : g.theme.fg2)
+    .drawPoly(poly);
+  if (l.src)
+    g.setBgColor(bg).drawImage(
+      "function" == typeof l.src ? l.src() : l.src,
+      l.x + l.w / 2,
+      l.y + l.h / 2,
+      { scale: l.scale || undefined, rotate: Math.PI * 0.5 * (l.r || 0) }
+    );
+}
+
+// function to split array into group of 3, for button placement
+let groupBy3 = function(data) {
+  let result = [];
+  for (let i = 0; i < data.length; i += 3) result.push(data.slice(i, i + 3));
+  return result;
+}
+
+// generate object with buttons for apps by group of 3
+let appButtons = groupBy3(pinnedApps).map((appGroup, i) => {
+  return appGroup.map((app, j) => {
+    return {
+      type: "custom",
+      render: drawButton,
+      width: 50,
+      height: 50,
+      pad: 5,
+      src: require("Storage").read(app.icon),
+      scale: 0.75,
+      cb: (l) => load(app.src),
+    };
+  });
+});
+
+// create basic layout content with status info and sensor status on top
+let layoutContent = [
+  {
+    type: "h",
+    pad: 5,
+    fillx: 1,
+    c: [
+      { type: "txt", font: "8x12", pad: 3, scale: 2, label: E.getBattery() + "%" },
+      { type: "txt", font: "8x12", pad: 3, scale: 2, label: "GPS: " + (Bangle.isGPSOn() ? "ON" : "OFF") },
+    ],
+  },
+];
+
+// create rows for buttons and add them to layoutContent
+appButtons.forEach((appGroup) => {
+  layoutContent.push({
+    type: "h",
+    pad: 2,
+    c: appGroup,
+  });
+});
+
+// create layout with content
+
+Bangle.loadWidgets();
+
+let Layout = require("Layout");
+let layout = new Layout({
+  type: "v",
+  c: layoutContent
+}, {
+  remove: ()=>{
+    Bangle.removeListener("swipe", onSwipe);
+    delete Graphics.prototype.setFont8x12;
+  }
+});
+g.clear();
+layout.render();
+Bangle.drawWidgets();
+
+// swipe event listener for exit gesture
+let onSwipe = function (lr, ud) {
+  if(exitGesture == "swipeup" && ud == -1) Bangle.showClock();
+  if(exitGesture == "swipedown" && ud == 1) Bangle.showClock();
+  if(exitGesture == "swipeleft" && lr == -1) Bangle.showClock();
+  if(exitGesture == "swiperight" && lr == 1) Bangle.showClock();
+}
+
+Bangle.on("swipe", onSwipe);
+}
diff --git a/apps/qcenter/app.png b/apps/qcenter/app.png
new file mode 100644
index 000000000..27ec75f1c
Binary files /dev/null and b/apps/qcenter/app.png differ
diff --git a/apps/qcenter/metadata.json b/apps/qcenter/metadata.json
new file mode 100644
index 000000000..a325de10f
--- /dev/null
+++ b/apps/qcenter/metadata.json
@@ -0,0 +1,18 @@
+{
+  "id": "qcenter",
+  "name": "Quick Center",
+  "shortName": "QCenter",
+  "version": "0.02",
+  "description": "An app for quickly launching your favourite apps, inspired by the control centres of other watches.",
+  "icon": "app.png",
+  "tags": "",
+  "supports": ["BANGLEJS2"],
+  "readme": "README.md",
+  "screenshots": [{ "url": "screenshot.png" }],
+  "storage": [
+    { "name": "qcenter.app.js", "url": "app.js" },
+    { "name": "qcenter.settings.js", "url": "settings.js" },
+    { "name": "qcenter.img", "url": "app-icon.js", "evaluate": true }
+  ],
+  "data": [{"name":"qcenter.json"}]
+}
diff --git a/apps/qcenter/screenshot.png b/apps/qcenter/screenshot.png
new file mode 100644
index 000000000..8c0a335aa
Binary files /dev/null and b/apps/qcenter/screenshot.png differ
diff --git a/apps/qcenter/settings.js b/apps/qcenter/settings.js
new file mode 100644
index 000000000..2c97f8a5f
--- /dev/null
+++ b/apps/qcenter/settings.js
@@ -0,0 +1,133 @@
+// make sure to enclose the function in parentheses
+(function (back) {
+  let settings = require("Storage").readJSON("qcenter.json", 1) || {};
+  var apps = require("Storage")
+    .list(/\.info$/)
+    .map((app) => {
+      var a = require("Storage").readJSON(app, 1);
+      return (
+        a && {
+          name: a.name,
+          type: a.type,
+          sortorder: a.sortorder,
+          src: a.src,
+          icon: a.icon,
+        }
+      );
+    })
+    .filter(
+      (app) =>
+        app &&
+        (app.type == "app" ||
+          app.type == "launch" ||
+          app.type == "clock" ||
+          !app.type)
+    );
+  apps.sort((a, b) => {
+    var n = (0 | a.sortorder) - (0 | b.sortorder);
+    if (n) return n; // do sortorder first
+    if (a.name < b.name) return -1;
+    if (a.name > b.name) return 1;
+    return 0;
+  });
+
+  function save(key, value) {
+    settings[key] = value;
+    require("Storage").write("qcenter.json", settings);
+  }
+
+  var pinnedApps = settings.pinnedApps || [];
+  var exitGesture = settings.exitGesture || "swipeup";
+
+  function showMainMenu() {
+    var mainmenu = {
+      "": { title: "Quick Center", back: back},
+    };
+
+    // Set exit gesture
+    mainmenu["Exit Gesture: " + exitGesture] = function () {
+      E.showMenu(exitGestureMenu);
+    };
+
+    //List all pinned apps, redirecting to menu with options to unpin and reorder
+    pinnedApps.forEach((app, i) => {
+      mainmenu[app.name] = function () {
+        E.showMenu({
+          "": { title: app.name, back: showMainMenu },
+          "Unpin": () => {
+            pinnedApps.splice(i, 1);
+            save("pinnedApps", pinnedApps);
+            showMainMenu();
+          },
+          "Move Up": () => {
+            if (i > 0) {
+              pinnedApps.splice(i - 1, 0, pinnedApps.splice(i, 1)[0]);
+              save("pinnedApps", pinnedApps);
+              showMainMenu();
+            }
+          },
+          "Move Down": () => {
+            if (i < pinnedApps.length - 1) {
+              pinnedApps.splice(i + 1, 0, pinnedApps.splice(i, 1)[0]);
+              save("pinnedApps", pinnedApps);
+              showMainMenu();
+            }
+          },
+        });
+      };
+    });
+
+    // Show pin app menu, or show alert if max amount of apps are pinned
+    mainmenu["Pin App"] = function () {
+      if (pinnedApps.length < 6) {
+        E.showMenu(pinAppMenu);
+      } else {
+        E.showAlert("Max apps pinned").then(showMainMenu);
+      }
+    };
+
+    return E.showMenu(mainmenu);
+  }
+
+  // menu for adding apps to the quick launch menu, listing all apps
+  var pinAppMenu = {
+    "": { title: "Add App", back: showMainMenu }
+  };
+  apps.forEach((a) => {
+    pinAppMenu[a.name] = function () {
+      // strip unncecessary properties
+      delete a.type;
+      delete a.sortorder;
+      pinnedApps.push(a);
+      save("pinnedApps", pinnedApps);
+      showMainMenu();
+    };
+  });
+
+  // menu for setting exit gesture
+  var exitGestureMenu = {
+    "": { title: "Exit Gesture", back: showMainMenu }
+  };
+  exitGestureMenu["Swipe Up"] = function () {
+    exitGesture = "swipeup";
+    save("exitGesture", "swipeup");
+    showMainMenu();
+  };
+  exitGestureMenu["Swipe Down"] = function () {
+    exitGesture = "swipedown";
+    save("exitGesture", "swipedown");
+    showMainMenu();
+  };
+  exitGestureMenu["Swipe Left"] = function () {
+    exitGesture = "swipeleft";
+    save("exitGesture", "swipeleft");
+    showMainMenu();
+  };
+  exitGestureMenu["Swipe Right"] = function () {
+    exitGesture = "swiperight";
+    save("exitGesture", "swiperight");
+    showMainMenu();
+  };
+
+  showMainMenu();
+});
diff --git a/apps/qrcode/custom.html b/apps/qrcode/custom.html
index 9955ea6c9..a3362f101 100644
--- a/apps/qrcode/custom.html
+++ b/apps/qrcode/custom.html
@@ -106,8 +106,8 @@
 
     
     
-    
-    
+    
+    
     
     
+    
+  
+
\ No newline at end of file
diff --git a/apps/sleeplog/lib.js b/apps/sleeplog/lib.js
index 752139e27..83c45de66 100644
--- a/apps/sleeplog/lib.js
+++ b/apps/sleeplog/lib.js
@@ -1,199 +1,380 @@
+// define accessable functions
 exports = {
   // define en-/disable function, restarts the service to make changes take effect
-  setEnabled: function(enable, logfile, powersaving) {
-    // check if sleeplog is available
-    if (typeof global.sleeplog !== "object") return;
-
-    // set default logfile
-    if ((typeof logfile !== "string" || !logfile.endsWith(".log")) &&
-      logfile !== false) logfile = "sleeplog.log";
-
+  setEnabled: function(enable) {
     // stop if enabled
-    if (global.sleeplog.enabled) global.sleeplog.stop();
+    if (global.sleeplog && sleeplog.enabled) sleeplog.stop();
 
-    // define storage and filename
-    var storage = require("Storage");
-    var filename = "sleeplog.json";
+    // define settings filename
+    var settings = "sleeplog.json";
 
     // change enabled value in settings
-    storage.writeJSON(filename, Object.assign(storage.readJSON(filename, true) || {}, {
-      enabled: enable,
-      logfile: logfile,
-      powersaving: powersaving || false
-    }));
+    require("Storage").writeJSON(settings, Object.assign(
+      require("Storage").readJSON(settings, true) || {}, {
+        enabled: enable
+      }
+    ));
 
     // force changes to take effect by executing the boot script
-    eval(storage.read("sleeplog.boot.js"));
+    eval(require("Storage").read("sleeplog.boot.js"));
 
-    // clear variables
-    storage = undefined;
-    filename = undefined;
     return true;
   },
 
-  // define read log function
-  // sorting: latest first, format:
-  // [[number, int, float, string], [...], ... ]
-  // - number // timestamp in ms
-  // - int    // status: 0 = unknown, 1 = not worn, 2 = awake, 3 = sleeping
-  // - float  // internal temperature
-  // - string // additional information
-  readLog: function(logfile, since, until) {
-    // check/set logfile
-    if (typeof logfile !== "string" || !logfile.endsWith(".log")) {
-      logfile = (global.sleeplog || {}).logfile || "sleeplog.log";
+  // define read log function, returns log array
+  // sorting: ascending (latest first), format:
+  // [[number, int, int], [...], ... ]
+  // - number // timestamp in 10min
+  // - int    // status: 0 = unknown, 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep
+  // - int    // consecutive: 0 = unknown, 1 = no consecutive sleep, 2 = consecutive sleep
+  readLog: function(since, until) {
+    // set now and check if now is before since
+    var now = Date.now();
+    if (now < since) return [];
+
+    // set defaults and convert since, until and now to 10min steps
+    since = Math.floor((since || 0) / 6E5);
+    until = Math.ceil((until || now) / 6E5);
+    now = Math.ceil(now / 6E5);
+
+    // define output log
+    var log = [];
+
+    // open StorageFile
+    var file = require("Storage").open("sleeplog.log", "r");
+    // cache StorageFile size
+    var storageFileSize = file.getLength();
+    // check if a Storage File needs to be read
+    if (storageFileSize) {
+      // define previous line cache
+      var prevLine;
+      // loop through StorageFile entries
+      while (true) {
+        // cache new line
+        var line = file.readLine();
+        // exit loop if all lines are read
+        if (!line) break;
+        // skip lines starting with ","
+        if (line.startsWith(",")) continue;
+        // parse line
+        line = line.trim().split(",").map(e => parseInt(e));
+        // exit loop if new line timestamp is not before until
+        if (line[0] >= until) break;
+        // check if new line timestamp is 24h before since or not after since
+        if (line[0] + 144 < since) {
+          // skip roughly the next 10 lines
+          file.read(118);
+          file.readLine();
+        } else if (line[0] <= since) {
+          // cache line for next cycle
+          prevLine = line;
+        } else {
+          // add previous line if it was cached
+          if (prevLine) log.push(prevLine);
+          // add new line at the end of log
+          log.push(line);
+          // clear previous line cache
+          prevLine = undefined;
+        }
+      }
+      // add previous line if it was cached
+      if (prevLine) log.push(prevLine);
+      // set unknown consecutive statuses
+      log = log.reverse().map((entry, index) => {
+        if (entry[2] === 0) entry[2] = (log[index - 1] || [])[2] || 0;
+        return entry;
+      }).reverse();
+      // remove duplicates
+      log = log.filter((entry, index) =>
+        !(index > 0 && entry[1] === log[index - 1][1] && entry[2] === log[index - 1][2])
+      );
     }
 
-    // check if since is in the future
-    if (since > Date()) return [];
+    // check if log empty or first entry is after since
+    if (!log[0] || log[0][0] > since) {
+      // look for all needed storage files
+      var files = require("Storage").list(/^sleeplog_\d\d\d\d\.log$/, {
+        sf: false
+      });
 
-    // read logfile
-    var log = require("Storage").read(logfile);
-    // return empty log
-    if (!log) return [];
-    // decode data if needed 
-    if (log[0] !== "[") log = atob(log);
-    // do a simple check before parsing
-    if (!log.startsWith("[[") || !log.endsWith("]]")) return [];
-    log = JSON.parse(log) || [];
+      // check if any file available
+      if (files.length) {
+        // generate start and end times in 10min steps
+        files = files.map(file => {
+          var start = this.fnToMs(parseInt(file.substr(9, 4))) / 6E5;
+          return {
+            name: file,
+            start: start,
+            end: start + 2016
+          };
+        }).sort((a, b) => b.start - a.start);
 
-    // check if filtering is needed
-    if (since || until) {
-      // search for latest entry befor since
-      if (since) since = (log.find(element => element[0] <= since) || [0])[0];
-      // filter selected time period
-      log = log.filter(element => (element[0] >= since) && (element[0] <= (until || 1E14)));
+        // read all neccessary files
+        var filesLog = [];
+        files.some(file => {
+          // exit loop if since after end
+          if (since >= file.end) return true;
+          // read file if until after start and since before end
+          if (until > file.start || since < file.end) {
+            var thisLog = require("Storage").readJSON(file.name, 1) || [];
+            if (thisLog.length) filesLog = thisLog.concat(filesLog);
+          }
+        });
+        // free ram
+        files = undefined;
+
+        // check if log from files is available 
+        if (filesLog.length) {
+          // remove unwanted entries
+          filesLog = filesLog.filter((entry, index, filesLog) => (
+            (filesLog[index + 1] || [now])[0] >= since && entry[0] <= until
+          ));
+          // add to log as previous entries
+          log = filesLog.concat(log);
+        }
+        // free ram
+        filesLog = undefined;
+      }
     }
 
-    // output log
+    // define last index
+    var lastIndex = log.length - 1;
+    // set timestamp of first entry to since if first entry before since
+    if (log[0] && log[0][0] < since) log[0][0] = since;
+    // add timestamp at now with unknown status if until after now
+    if (until > now) log.push([now, 0, 0]);
+
     return log;
   },
 
-  // define write log function, append or replace log depending on input
-  // append input if array length >1 and element[0] >9E11
-  // replace log with input if at least one entry like above is inside another array
-  writeLog: function(logfile, input) {
-    // check/set logfile
-    if (typeof logfile !== "string" || !logfile.endsWith(".log")) {
-      if (!global.sleeplog || sleeplog.logfile === false) return;
-      logfile = sleeplog.logfile || "sleeplog.log";
-    }
+  // define move log function, move StorageFile content into files seperated by fortnights
+  moveLog: function(force) {
+    // first day of this fortnight period
+    var thisFirstDay = this.fnToMs(this.msToFn(Date.now()));
 
-    // check if input is an array
-    if (typeof input !== "object" || typeof input.length !== "number") return;
+    // read timestamp of the first StorageFile entry
+    var firstDay = (require("Storage").open("sleeplog.log", "r").read(47) || "").match(/\n\d*/);
+    // calculate the first day of the fortnight period
+    if (firstDay) firstDay = this.fnToMs(this.msToFn(parseInt(firstDay[0].trim()) * 6E5));
 
-    // check for entry plausibility
-    if (input.length > 1 && input[0] * 1 > 9E11) {
-      // read log
-      var log = this.readLog(logfile);
+    // check if moving is neccessary or forced
+    if (force || firstDay && firstDay < thisFirstDay) {
+      // read log for each fortnight period
+      while (firstDay) {
+        // calculate last day
+        var lastDay = firstDay + 12096E5;
+        // read log of the fortnight period
+        var log = require("sleeplog").readLog(firstDay, lastDay);
 
-      // remove last state if it was unknown and less then 5min ago
-      if (log.length > 0 && log[0][1] === 0 &&
-        Math.floor(Date.now()) - log[0][0] < 3E5) log.shift();
+        // check if before this fortnight period
+        if (firstDay < thisFirstDay) {
+          // write log in seperate file
+          require("Storage").writeJSON("sleeplog_" + this.msToFn(firstDay) + ".log", log);
+          // set last day as first
+          firstDay = lastDay;
+        } else {
+          // rewrite StorageFile
+          require("Storage").open("sleeplog.log", "w").write(log.map(e => e.join(",")).join("\n"));
+          // clear first day to exit loop
+          firstDay = undefined;
+        }
 
-      // add entry at the first position if it has changed
-      if (log.length === 0 || input.some((e, index) => index > 0 && input[index] !== log[0][index])) log.unshift(input);
-
-      // map log as input
-      input = log;
-    }
-
-    // check and if neccessary reduce logsize to prevent low mem
-    if (input.length > 750) input = input.slice(-750);
-
-    // simple check for log plausibility
-    if (input[0].length > 1 && input[0][0] * 1 > 9E11) {
-      // write log to storage
-      require("Storage").write(logfile, btoa(JSON.stringify(input)));
-      return true;
-    }
-  },
-
-  // define log to humanreadable string function
-  // sorting: latest last, format:
-  // "{substring of ISO date} - {status} for {duration}min\n..."
-  getReadableLog: function(printLog, since, until, logfile) {
-    // read log and check
-    var log = this.readLog(logfile, since, until);
-    if (!log.length) return;
-    // reverse array to set last timestamp to the end
-    log.reverse();
-
-    // define status description and log string
-    var statusText = ["unknown ", "not worn", "awake   ", "sleeping"];
-    var logString = [];
-
-    // rewrite each entry
-    log.forEach((element, index) => {
-      logString[index] = "" +
-        Date(element[0] - Date().getTimezoneOffset() * 6E4).toISOString().substr(0, 19).replace("T", " ") + " - " +
-        statusText[element[1]] +
-        (index === log.length - 1 ?
-          element.length < 3 ? "" : " ".repeat(12) :
-          " for " + ("" + Math.round((log[index + 1][0] - element[0]) / 60000)).padStart(4) + "min"
-        ) +
-        (element[2] ? " | Temp: " + ("" + element[2]).padEnd(5) + "°C" : "") +
-        (element[3] ? " | " + element[3] : "");
-    });
-    logString = logString.join("\n");
-
-    // if set print and return string
-    if (printLog) {
-      print(logString);
-      print("- first", Date(log[0][0]));
-      print("-  last", Date(log[log.length - 1][0]));
-      var period = log[log.length - 1][0] - log[0][0];
-      print("-     period= " + Math.floor(period / 864E5) + "d " + Math.floor(period % 864E5 / 36E5) + "h " + Math.floor(period % 36E5 / 6E4) + "min");
-    }
-    return logString;
-  },
-
-  // define function to eliminate some errors inside the log
-  restoreLog: function(logfile) {
-    // read log and check
-    var log = this.readLog(logfile);
-    if (!log.length) return;
-
-    // define output variable to show number of changes
-    var output = log.length;
-
-    // remove non decremental entries
-    log = log.filter((element, index) => log[index][0] >= (log[index + 1] || [0])[0]);
-
-    // write log
-    this.writeLog(logfile, log);
-
-    // return difference in length
-    return output - log.length;
-  },
-
-  // define function to reinterpret worn status based on given temperature threshold
-  reinterpretTemp: function(logfile, tempthresh) {
-    // read log and check
-    var log = this.readLog(logfile);
-    if (!log.length) return;
-
-    // set default tempthresh
-    tempthresh = tempthresh || (global.sleeplog ? sleeplog.tempthresh : 27);
-
-    // define output variable to show number of changes
-    var output = 0;
-
-    // remove non decremental entries
-    log = log.map(element => {
-      if (element[2]) {
-        var tmp = element[1];
-        element[1] = element[2] > tempthresh ? 3 : 1;
-        if (tmp !== element[1]) output++;
+        // free ram
+        log = undefined;
       }
-      return element;
+    }
+  },
+
+  // define function to return stats from the last date [ms] for a specific duration [ms] or for the complete log
+  getStats: function(until, duration, log) {
+    // define stats variable
+    var stats = {
+      calculatedAt: //   [date] timestamp of the calculation
+        Math.round(Date.now()),
+      deepSleep: 0, //   [min] deep sleep duration
+      lightSleep: 0, //  [min] light sleep duration
+      awakeSleep: 0, //  [min] awake duration inside consecutive sleep
+      consecSleep: 0, // [min] consecutive sleep duration
+      awakeTime: 0, //   [min] awake duration outside consecutive sleep
+      notWornTime: 0, // [min] duration of not worn status
+      unknownTime: 0, // [min] duration of unknown status
+      logDuration: 0, // [min] duration of all entries taken into account
+      firstDate: undefined, // [date] first entry taken into account
+      lastDate: undefined // [date] last entry taken into account
+    };
+
+    // set default inputs
+    until = until || stats.calculatedAt;
+    if (!duration) duration = 864E5;
+
+    // read log for the specified duration or complete log if not handed over
+    if (!log) log = this.readLog(duration ? until - duration : 0, until);
+
+    // check if log not empty or corrupted
+    if (log && log.length && log[0] && log[0].length === 3) {
+      // calculate and set first log date from 10min steps
+      stats.firstDate = log[0][0] * 6E5;
+      stats.lastDate = log[log.length - 1][0] * 6E5;
+
+      // cycle through log to calculate sums til end or duration is exceeded
+      log.forEach((entry, index, log) => {
+        // calculate duration of this entry from 10min steps to minutes
+        var duration = ((log[index + 1] || [until / 6E5 | 0])[0] - entry[0]) * 10;
+
+        // check if duration greater 0
+        if (duration) {
+          // calculate sums
+          if (entry[1] === 4) stats.deepSleep += duration;
+          else if (entry[1] === 3) stats.lightSleep += duration;
+          else if (entry[1] === 2) {
+            if (entry[2] === 2) stats.awakeSleep += duration;
+            else if (entry[2] === 1) stats.awakeTime += duration;
+          }
+          if (entry[2] === 2) stats.consecSleep += duration;
+          if (entry[1] === 1) stats.notWornTime += duration;
+          if (entry[1] === 0) stats.unknownTime += duration;
+          stats.logDuration += duration;
+        }
+      });
+    }
+
+    // free ram
+    log = undefined;
+
+    // return stats of the last day
+    return stats;
+  },
+
+  // define function to return last break time of day from date or now (default: 12 o'clock)
+  getLastBreak: function(date, ToD) {
+    // set default date or correct date type if needed
+    if (!date || !date.getDay) date = date ? new Date(date) : new Date();
+    // set default ToD as set in sleeplog.conf or settings if available
+    if (ToD === undefined) ToD = (global.sleeplog && sleeplog.conf ? sleeplog.conf.breakToD :
+      (require("Storage").readJSON("sleeplog.json", true) || {}).breakToD) || 12;
+    // calculate last break time and return
+    return new Date(date.getFullYear(), date.getMonth(), date.getDate(), ToD);
+  },
+
+  // define functions to convert ms to the number of fortnights since the first Sunday at noon: 1970-01-04T12:00
+  fnToMs: function(no) {
+    return (no + 0.25) * 12096E5;
+  },
+  msToFn: function(ms) {
+    return (ms / 12096E5 - 0.25) | 0;
+  },
+
+  // define set debug function, options:
+  //  enable as boolean, start/stop debugging
+  //  duration in hours, generate csv log if set, max: 96h
+  setDebug: function(enable, duration) {
+    // check if global variable accessable
+    if (!global.sleeplog) return new Error("sleeplog: Can't set debugging, global object missing!");
+
+    // check if nothing has to be changed
+    if (!duration &&
+      (enable && sleeplog.debug === true) ||
+      (!enable && !sleeplog.debug)) return;
+
+    // check if en- or disable debugging
+    if (enable) {
+      // define debug object
+      sleeplog.debug = {};
+
+      // check if a file should be generated
+      if (typeof duration === "number") {
+        // check duration boundaries, 0 => 8
+        duration = duration > 96 ? 96 : duration || 12;
+        // calculate and set writeUntil in 10min steps
+        sleeplog.debug.writeUntil = ((Date.now() / 6E5 | 0) + duration * 6) * 6E5;
+        // set fileid to "{hours since 1970}"
+        sleeplog.debug.fileid = Date.now() / 36E5 | 0;
+        // write csv header on empty file
+        var file = require("Storage").open("sleeplog_" + sleeplog.debug.fileid + ".csv", "a");
+        if (!file.getLength()) file.write(
+          "timestamp,movement,status,consecutive,asleepSince,awakeSince,bpm,bpmConfidence\n"
+        );
+        // free ram
+        file = undefined;
+      } else {
+        // set debug as active
+        sleeplog.debug = true;
+      }
+    } else {
+      // disable debugging
+      delete sleeplog.debug;
+    }
+
+    // save status forced
+    sleeplog.saveStatus(true);
+  },
+
+  // define debugging function, called after logging if debug is set
+  debug: function(data) {
+    // check if global variable accessable and debug active
+    if (!global.sleeplog || !sleeplog.debug) return;
+
+    // set functions to convert timestamps
+    function localTime(timestamp) {
+      return timestamp ? Date(timestamp).toString().split(" ")[4].substr(0, 5) : "- - -";
+    }
+    function officeTime(timestamp) {
+      // days since 30.12.1899
+      return timestamp / 864E5 + 25569;
+    }
+
+    // generate console output
+    var console = "sleeplog: " +
+      localTime(data.timestamp) + " > " +
+      "movement: " + ("" + data.movement).padStart(4) + ", " +
+      "unknown    ,non consec.,consecutive".split(",")[sleeplog.consecutive] + " " +
+      "unknown,not worn,awake,light sleep,deep sleep".split(",")[data.status].padEnd(12) + ", " +
+      "asleep since: " + localTime(sleeplog.info.asleepSince) + ", " +
+      "awake since: " + localTime(sleeplog.info.awakeSince);
+    // add bpm if set
+    if (data.bpm) console += ", " +
+      "bpm: " + ("" + data.bpm).padStart(3) + ", " +
+      "confidence: " + data.bpmConfidence;
+    // output to console
+    print(console);
+
+    // check if debug is set as object with a file id and it is not past writeUntil
+    if (typeof sleeplog.debug === "object" && sleeplog.debug.fileid &&
+      Date.now() < sleeplog.debug.writeUntil) {
+      // generate next csv line
+      var csv = [
+        officeTime(data.timestamp),
+        data.movement,
+        data.status,
+        sleeplog.consecutive,
+        sleeplog.info.asleepSince ? officeTime(sleeplog.info.asleepSince) : "",
+        sleeplog.info.awakeSince ? officeTime(sleeplog.info.awakeSince) : "",
+        data.bpm || "",
+        data.bpmConfidence || ""
+      ].join(",");
+      // write next line to log if set
+      require("Storage").open("sleeplog_" + sleeplog.debug.fileid + ".csv", "a").write(csv + "\n");
+    } else {
+      // clear file setting in debug
+      sleeplog.debug = true;
+    }
+
+  },
+
+  // print log as humanreadable output similar to debug output
+  printLog: function(since, until) {
+    // set default until
+    until = until || Date.now();
+    // print each entry inside log
+    this.readLog(since, until).forEach((entry, index, log) => {
+      // calculate duration of this entry from 10min steps to minutes
+      var duration = ((log[index + 1] || [until / 6E5 | 0])[0] - entry[0]) * 10;
+      // print this entry
+      print((index + ")").padStart(4) + " " +
+        Date(entry[0] * 6E5).toString().substr(0, 21) + " > " +
+        "unknown    ,non consec.,consecutive".split(",")[entry[2]] + " " +
+        "unknown,not worn,awake,light sleep,deep sleep".split(",")[entry[1]].padEnd(12) +
+        "for" + (duration + "min").padStart(8));
     });
-
-    // write log
-    this.writeLog(logfile, log);
-
-    // return output
-    return output;
   }
-
 };
diff --git a/apps/sleeplog/metadata.json b/apps/sleeplog/metadata.json
index c4dbe8631..353476446 100644
--- a/apps/sleeplog/metadata.json
+++ b/apps/sleeplog/metadata.json
@@ -2,27 +2,32 @@
   "id":"sleeplog",
   "name":"Sleep Log",
   "shortName": "SleepLog",
-  "version": "0.06",
-  "description": "Log and view your sleeping habits. This app derived from SleepPhaseAlarm and uses also the principe of Estimation of Stationary Sleep-segments (ESS). It also provides a power saving mode using the built in movement calculation.",
+  "version": "0.12",
+  "description": "Log and view your sleeping habits. This app is using the built in movement calculation.",
   "icon": "app.png",
   "type": "app",
   "tags": "tool,boot",
   "supports": ["BANGLEJS2"],
   "readme": "README.md",
+  "interface": "interface.html",
   "storage": [
     {"name": "sleeplog.app.js", "url": "app.js"},
-    {"name": "sleeplog.img", "url": "app-icon.js", "evaluate":true},
+    {"name": "sleeplog.img", "url": "app-icon.js", "evaluate": true},
     {"name": "sleeplog.boot.js", "url": "boot.js"},
     {"name": "sleeplog", "url": "lib.js"},
     {"name": "sleeplog.settings.js", "url": "settings.js"}
   ],
   "data": [
-    {"name": "sleeplog.json"},
-    {"name": "sleeplog.log"}
+    {"name": "sleeplog.json"}
   ],
   "screenshots": [
-    {"url": "screenshot1.png"},
-    {"url": "screenshot2.png"},
-    {"url": "screenshot3.png"}
-   ]
+    {"url": "screenshot-1_app_light.png"},
+    {"url": "screenshot-2_day_light.png"},
+    {"url": "screenshot-3_graph_light.png"},
+    {"url": "screenshot-4_graph2_light.png"},
+    {"url": "screenshot-5_app_dark.png"},
+    {"url": "screenshot-6_day_dark.png"},
+    {"url": "screenshot-7_graph_dark.png"},
+    {"url": "screenshot-8_graph2_dark.png"}
+  ]
 }
diff --git a/apps/sleeplog/nolog.png b/apps/sleeplog/nolog.png
deleted file mode 100644
index b153b5769..000000000
Binary files a/apps/sleeplog/nolog.png and /dev/null differ
diff --git a/apps/sleeplog/off_20x20.png b/apps/sleeplog/off_20x20.png
new file mode 100644
index 000000000..abf3d3bfc
Binary files /dev/null and b/apps/sleeplog/off_20x20.png differ
diff --git a/apps/sleeplog/powersaving.png b/apps/sleeplog/powersaving.png
deleted file mode 100644
index ea487b48c..000000000
Binary files a/apps/sleeplog/powersaving.png and /dev/null differ
diff --git a/apps/sleeplog/screenshot-1_app_light.png b/apps/sleeplog/screenshot-1_app_light.png
new file mode 100644
index 000000000..f4c01773c
Binary files /dev/null and b/apps/sleeplog/screenshot-1_app_light.png differ
diff --git a/apps/sleeplog/screenshot-2_day_light.png b/apps/sleeplog/screenshot-2_day_light.png
new file mode 100644
index 000000000..61e0a60f6
Binary files /dev/null and b/apps/sleeplog/screenshot-2_day_light.png differ
diff --git a/apps/sleeplog/screenshot-3_graph_light.png b/apps/sleeplog/screenshot-3_graph_light.png
new file mode 100644
index 000000000..4b74afd25
Binary files /dev/null and b/apps/sleeplog/screenshot-3_graph_light.png differ
diff --git a/apps/sleeplog/screenshot-4_graph2_light.png b/apps/sleeplog/screenshot-4_graph2_light.png
new file mode 100644
index 000000000..300be5d05
Binary files /dev/null and b/apps/sleeplog/screenshot-4_graph2_light.png differ
diff --git a/apps/sleeplog/screenshot-5_app_dark.png b/apps/sleeplog/screenshot-5_app_dark.png
new file mode 100644
index 000000000..82e1f8c2f
Binary files /dev/null and b/apps/sleeplog/screenshot-5_app_dark.png differ
diff --git a/apps/sleeplog/screenshot-6_day_dark.png b/apps/sleeplog/screenshot-6_day_dark.png
new file mode 100644
index 000000000..a727f73e0
Binary files /dev/null and b/apps/sleeplog/screenshot-6_day_dark.png differ
diff --git a/apps/sleeplog/screenshot-7_graph_dark.png b/apps/sleeplog/screenshot-7_graph_dark.png
new file mode 100644
index 000000000..71612fa8e
Binary files /dev/null and b/apps/sleeplog/screenshot-7_graph_dark.png differ
diff --git a/apps/sleeplog/screenshot-8_graph2_dark.png b/apps/sleeplog/screenshot-8_graph2_dark.png
new file mode 100644
index 000000000..09c19e95c
Binary files /dev/null and b/apps/sleeplog/screenshot-8_graph2_dark.png differ
diff --git a/apps/sleeplog/screenshot1.png b/apps/sleeplog/screenshot1.png
deleted file mode 100644
index 200a305c4..000000000
Binary files a/apps/sleeplog/screenshot1.png and /dev/null differ
diff --git a/apps/sleeplog/screenshot2.png b/apps/sleeplog/screenshot2.png
deleted file mode 100644
index 61f580336..000000000
Binary files a/apps/sleeplog/screenshot2.png and /dev/null differ
diff --git a/apps/sleeplog/screenshot3.png b/apps/sleeplog/screenshot3.png
deleted file mode 100644
index 4a29b5008..000000000
Binary files a/apps/sleeplog/screenshot3.png and /dev/null differ
diff --git a/apps/sleeplog/settings.js b/apps/sleeplog/settings.js
index 11c7c0adb..9bf37ed69 100644
--- a/apps/sleeplog/settings.js
+++ b/apps/sleeplog/settings.js
@@ -1,144 +1,431 @@
 (function(back) {
+  // define settings filename
   var filename = "sleeplog.json";
+  // define logging prompt display status
+  var thresholdsPrompt = true;
 
-  // set storage and load settings
-  var storage = require("Storage");
-  var settings = Object.assign({
-    breaktod: 10, // time of day when to start/end graphs
-    maxawake: 36E5, // 60min in ms
-    minconsec: 18E5, // 30min in ms
-    tempthresh: 27, // every temperature above ist registered as worn
-    powersaving: false, // disables ESS and uses build in movement detection
-    maxmove: 100, // movement threshold on power saving mode
-    nomothresh: 0.012, // values lower than 0.008 getting triggert by noise
-    sleepthresh: 577, // 577 times no movement * 1.04s window width > 10min
-    winwidth: 13, // 13 values, read with 12.5Hz = every 1.04s
-    enabled: true, // en-/disable completely
-    logfile: "sleeplog.log", // logfile
-  }, storage.readJSON(filename, true) || {});
+  // define default vaules
+  var defaults = {
+    // main settings
+    enabled: true, //   en-/disable completely
+    // threshold settings
+    maxAwake: 36E5, //  [ms] maximal awake time to count for consecutive sleep
+    minConsec: 18E5, // [ms] minimal time to count for consecutive sleep
+    deepTh: 100, //     threshold for deep sleep
+    lightTh: 200, //    threshold for light sleep
+    // app settings
+    breakToD: 12, //    [h] time of day when to start/end graphs
+    appTimeout: 0 //   lock and backlight timeouts for the app
+  };
 
-  // write change to global.sleeplog and storage
-  function writeSetting(key, value) {
-    // change key in global.sleeplog
-    if (typeof global.sleeplog === "object") global.sleeplog[key] = value;
-    // reread settings to only change key
-    settings = Object.assign(settings, storage.readJSON(filename, true) || {});
-    // change the value of key
-    settings[key] = value;
-    // write to storage
-    storage.writeJSON(filename, settings);
+  // assign loaded settings to default values
+  var settings = Object.assign(defaults, require("Storage").readJSON(filename, true) || {});
+
+  // write change to storage
+  function writeSetting() {
+    require("Storage").writeJSON(filename, settings);
   }
 
-  // define function to change values that need a restart of the service
-  function changeRestart() {
-    require("sleeplog").setEnabled(settings.enabled, settings.logfile, settings.powersaving);
+  // plot a debug file
+  function plotDebug(filename) {    
+    // handle swipe events
+    function swipeHandler(x, y) {
+      if (x) {
+        start -= x;
+        if (start < 0 || maxStart && start > maxStart) {
+          start = start < 0 ? 0 : maxStart;
+        } else {
+          drawGraph();
+        }
+      } else {
+        minMove += y * 10;
+        if (minMove < 0 || minMove > 300) {
+          minMove = minMove < 0 ? 0 : 300;
+        } else {
+          drawGraph();
+        }
+      }
+    }
+    // handle touch events
+    function touchHandler() {
+      invert = !invert;
+      drawGraph();
+    }
+
+    // read required entries
+    function readEntries(count) {
+      // extract usabble data from line
+      function extract(line) {
+        if (!line) return;
+        line = line.trim().split(",");
+        return [Math.round((parseFloat(line[0]) - 25569) * 144), parseInt(line[1])];
+      }
+
+      // open debug file
+      var file = require("Storage").open(filename, "r");
+      // skip title
+      file.readLine();
+      // skip past entries
+      for (var i = 0; i < start * count; i++) { file.readLine(); }
+      // define data with first entry
+      var data = [extract(file.readLine())];
+      // get start time in 10min steps
+      var start10min = data[0][0];
+      // read first required entry
+      var line = extract(file.readLine());
+      
+      // read next count entries from file
+      while (data.length < count) {
+        // check if line is immediately after the last entry
+        if (line[0] === start10min + data.length) {
+          // add line to data
+          data.push(line);
+          // read new line
+          line = extract(file.readLine());
+          // stop if no more data available
+          if (!line) break;
+        } else {
+          // add line with unknown movement
+          data.push([start10min + data.length, 0]);
+        }
+      }
+
+      // free ram
+      file = undefined
+      // set this start as max, if less entries than expected
+      if (data.length < count) maxStart = start;
+      return data;
+    }
+
+    // draw graph at starting point
+    function drawGraph() {
+      // set correct or inverted drawing
+      function rect(fill, x0, y0, x1, y1) {
+        if (fill ^ invert) {
+          g.fillRect(x0, y0, x1, y1);
+        } else {
+          g.clearRect(x0, y0, x1, y1);
+        }
+      }
+
+      // set witdh
+      var width = g.getWidth();
+      // calculate entries to display (+ set width zero based)
+      var count = (width--) / 4;
+      // read required entries
+      var data = readEntries(count);
+
+      // clear app area
+      g.reset().clearRect(0, width - 13, width, width);
+      rect(false, 0, 24, width, width - 14);
+      // draw x axis
+      g.drawLine(0, width - 13, width, width - 13);
+      // draw x label
+      data.forEach((e, i) => {
+        var startTime = new Date(e[0] * 6E5);
+        if (startTime.getMinutes() === 0) {
+          g.fillRect(4 * i, width - 12, 4 * i, width - 9);
+          g.setFontAlign(-1, -1).setFont("6x8")
+            .drawString(startTime.getHours(), 4 * i + 1, width - 8);
+        } else if (startTime.getMinutes() === 30) {
+          g.fillRect(4 * i, width - 12, 4 * i, width - 11);
+        }
+      });
+
+      // calculate max height
+      var height = width - 38;
+      // cycle through entries
+      data.forEach((e, i) => {
+        // check if movement available 
+        if (e[1]) {
+          // set color depending on recognised status
+          var color = e[1] < deepTh ? 31 : e[1] < lightTh ? 2047 : 2016;
+          // correct according to min movement
+          e[1] -= minMove;
+          // keep movement in bounderies
+          e[1] = e[1] < 0 ? 0 : e[1] > height ? height : e[1];
+          // draw line and rectangle
+          g.reset();
+          rect(true, 4 * i, width - 14, 4 * i, width - 14 - e[1]);
+          g.setColor(color).fillRect(4 * i + 1, width - 14, 4 * i + 3, width - 14 - e[1]);
+        } else {
+          // draw error in red
+          g.setColor(63488).fillRect(4 * i, width - 14, 4 * i, width - 14 - height);
+        }
+      });
+      // draw threshold lines
+      [deepTh, lightTh].forEach(th => {
+        th -= minMove;
+        if (th > 0 && th < height) {
+          // draw line
+          g.reset();
+          rect(true, 0, width - 14 - th, width, width - 14 - th);
+          // draw value above or below line
+          var yAlign = th < height / 2 ? -1 : 1;
+          if (invert) g.setColor(1);
+          g.setFontAlign(1, yAlign).setFont("6x8")
+            .drawString(th + minMove, width - 2, width - 13 - th + 10 * yAlign);
+        }
+      });
+
+      // free ram
+      data = undefined;
+    }
+
+    // get thresholds
+    var deepTh = global.sleeplog ? sleeplog.conf.deepTh : defaults.deepTh;
+    var lightTh = global.sleeplog ? sleeplog.conf.lightTh : defaults.lightTh;
+    // set lowest movement displayed
+    var minMove = deepTh - 20;
+    // set start point
+    var start = 0;
+    // define max start point value
+    var maxStart = 0;
+    // define inverted color status
+    var invert = false;
+
+    // setup UI
+    Bangle.setUI({
+      mode: "custom",
+      back: selectDebug,
+      touch: touchHandler,
+      swipe: swipeHandler
+    });
+
+    // first draw
+    drawGraph(start);
   }
 
-  // calculate sleepthresh factor
-  var stFactor = settings.winwidth / 12.5 / 60;
+  // select a debug logfile
+  function selectDebug() {
+    // load debug files
+    var files = require("Storage").list(/^sleeplog_\d\d\d\d\d\d\.csv$/, {sf:true});
+
+    // check if no files found
+    if (!files.length) {
+      // show prompt
+      E.showPrompt( /*LANG*/"No debug files found.", {
+        title: /*LANG*/"Debug log",
+        buttons: {
+          /*LANG*/"Back": 0
+        }
+      }).then(showDebug);
+    } else {
+      // prepare scroller
+      const H = 40;
+      var menuIcon = "\0\f\f\x81\0\xFF\xFF\xFF\0\0\0\0\x0F\xFF\xFF\xF0\0\0\0\0\xFF\xFF\xFF";
+      // show scroller
+      E.showScroller({
+        h: H, c: files.length,
+        back: showDebug,
+        scrollMin : -24, scroll : -24, // title is 24px, rendered at -1
+          draw : (idx, r) => {
+            if (idx < 0) {
+              return g.setFont("12x20").setFontAlign(-1,0).drawString(menuIcon + " Select file", r.x + 12, r.y + H - 12);
+            } else {
+              g.setColor(g.theme.bg2).fillRect({x: r.x + 4, y: r.y + 2, w: r.w - 8, h: r.h - 4, r: 5});
+              var name = new Date(parseInt(files[idx].match(/\d\d\d\d\d\d/)[0]) * 36E5);
+              name = name.toString().slice(0, -12).split(" ").filter((e, i) => i !== 3).join(" ");
+              g.setColor(g.theme.fg2).setFont("12x20").setFontAlign(-1, 0).drawString(name, r.x + 12, r.y + H / 2);
+            }
+          },
+        select: (idx) => plotDebug(files[idx])
+      });
+    }
+  }
+
+  // show menu or promt to change debugging
+  function showDebug() {
+    // check if sleeplog is available
+    if (global.sleeplog) {
+      // get debug status, file and duration
+      var enabled = !!sleeplog.debug;
+      var file = typeof sleeplog.debug === "object";
+      var duration = 0;
+      // setup debugging menu
+      var debugMenu = {
+        "": {
+          title: /*LANG*/"Debugging"
+        },
+        /*LANG*/"< Back": () => {
+          // check if some value has changed
+          if (enabled !== !!sleeplog.debug || file !== (typeof sleeplog.debug === "object") || duration)
+            require("sleeplog").setDebug(enabled, file ? duration || 12 : undefined);
+          // redraw main menu
+          showMain(7);
+        },
+        /*LANG*/"View log": () => selectDebug(),
+        /*LANG*/"Enable": {
+          value: enabled,
+          onchange: v => enabled = v
+        },
+        /*LANG*/"write File": {
+          value: file,
+          onchange: v => file = v
+        },
+        /*LANG*/"Duration": {
+          value: file ? (sleeplog.debug.writeUntil - Date.now()) / 36E5 | 0 : 12,
+          min: 1,
+          max: 96,
+          wrap: true,
+          format: v => v + /*LANG*/ "h",
+          onchange: v => duration = v
+        },
+        /*LANG*/"Cancel": () => showMain(7),
+      };
+      // show menu
+      var menu = E.showMenu(debugMenu);
+    } else {
+      // show error prompt
+      E.showPrompt("Sleeplog" + /*LANG*/"not enabled!", {
+        title: /*LANG*/"Debugging",
+        buttons: {
+          /*LANG*/"Back": 7
+        }
+      }).then(showMain);
+    }
+  }
+
+  // show menu to change thresholds
+  function showThresholds() {
+    // setup logging menu
+    var menu;
+    var thresholdsMenu = {
+      "": {
+        title: /*LANG*/"Thresholds"
+      },
+      /*LANG*/"< Back": () => showMain(2),
+      /*LANG*/"Max Awake": {
+        value: settings.maxAwake / 6E4,
+        step: 10,
+        min: 10,
+        max: 120,
+        wrap: true,
+        noList: true,
+        format: v => v + /*LANG*/"min",
+        onchange: v => {
+          settings.maxAwake = v * 6E4;
+          writeSetting();
+        }
+      },
+      /*LANG*/"Min Consecutive": {
+        value: settings.minConsec / 6E4,
+        step: 10,
+        min: 10,
+        max: 120,
+        wrap: true,
+        noList: true,
+        format: v => v + /*LANG*/"min",
+        onchange: v => {
+          settings.minConsec = v * 6E4;
+          writeSetting();
+        }
+      },
+      /*LANG*/"Deep Sleep": {
+        value: settings.deepTh,
+        step: 1,
+        min: 30,
+        max: 200,
+        wrap: true,
+        noList: true,
+        onchange: v => {
+          settings.deepTh = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"Light Sleep": {
+        value: settings.lightTh,
+        step: 10,
+        min: 100,
+        max: 400,
+        wrap: true,
+        noList: true,
+        onchange: v => {
+          settings.lightTh = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"Reset to Default": () => {
+        settings.maxAwake = defaults.maxAwake;
+        settings.minConsec = defaults.minConsec;
+        settings.deepTh = defaults.deepTh;
+        settings.lightTh = defaults.lightTh;
+        writeSetting();
+        showThresholds();
+      }
+    };
+
+    // display info/warning prompt or menu
+    if (thresholdsPrompt) {
+      thresholdsPrompt = false;
+      E.showPrompt("Changes take effect from now on, not retrospective", {
+        title: /*LANG*/"Thresholds",
+        buttons: {
+          /*LANG*/"Ok": 0
+        }
+      }).then(() => menu = E.showMenu(thresholdsMenu));
+    } else {
+      menu = E.showMenu(thresholdsMenu);
+    }
+  }
 
   // show main menu
   function showMain(selected) {
+    // set debug image
+    var debugImg = !global.sleeplog ?
+      "FBSBAOAAfwAP+AH3wD4+B8Hw+A+fAH/gA/wAH4AB+AA/wAf+APnwHw+D4Hx8A++AH/AA/gAH" : // X
+      typeof sleeplog.debug === "object" ?
+      "FBSBAB/4AQDAF+4BfvAX74F+CBf+gX/oFJKBf+gUkoF/6BSSgX/oFJ6Bf+gX/oF/6BAAgf/4" : // file
+      sleeplog.debug ?
+      "FBSBAP//+f/V///4AAGAABkAAZgAGcABjgAYcAGDgBhwAY4AGcABmH+ZB/mAABgAAYAAH///" : // console
+      0; // off
+    debugImg = debugImg ? "\0" + atob(debugImg) : false;
+    // set menu
     var mainMenu = {
       "": {
         title: "Sleep Log",
         selected: selected
       },
-      "Exit": () => load(),
-      "< Back": () => back(),
-      "Break Tod": {
-        value: settings.breaktod,
+      /*LANG*/"< Back": () => back(),
+      /*LANG*/"Thresholds": () => showThresholds(),
+      /*LANG*/"Break ToD": {
+        value: settings.breakToD,
         step: 1,
         min: 0,
         max: 23,
         wrap: true,
-        onchange: v => writeSetting("breaktod", v),
-      },
-      "Max Awake": {
-        value: settings.maxawake / 6E4,
-        step: 5,
-        min: 15,
-        max: 120,
-        wrap: true,
-        format: v => v + "min",
-        onchange: v => writeSetting("maxawake", v * 6E4),
-      },
-      "Min Consec": {
-        value: settings.minconsec / 6E4,
-        step: 5,
-        min: 15,
-        max: 120,
-        wrap: true,
-        format: v => v + "min",
-        onchange: v => writeSetting("minconsec", v * 6E4),
-      },
-      "Temp Thresh": {
-        value: settings.tempthresh,
-        step: 0.5,
-        min: 20,
-        max: 40,
-        wrap: true,
-        format: v => v + "°C",
-        onchange: v => writeSetting("tempthresh", v),
-      },
-      "Power Saving": {
-        value: settings.powersaving,
-        format: v => v ? "on" : "off",
-        onchange: function(v) {
-          settings.powersaving = v;
-          changeRestart();
-          // redraw menu with changed entries subsequent to onchange
-          // https://github.com/espruino/Espruino/issues/2149
-          setTimeout(showMain, 1, 6);
+        noList: true,
+        format: v => v + ":00",
+        onchange: v => {
+          settings.breakToD = v;
+          writeSetting();
         }
       },
-      "Max Move": {
-        value: settings.maxmove,
-        step: 1,
-        min: 50,
-        max: 200,
+      /*LANG*/"App Timeout": {
+        value: settings.appTimeout / 1E3,
+        step: 10,
+        min: 0,
+        max: 120,
         wrap: true,
-        onchange: v => writeSetting("maxmove", v),
+        noList: true,
+        format: v => v ? v + "s" : "-",
+        onchange: v => {
+          settings.appTimeout = v * 1E3;
+          writeSetting();
+        }
       },
-      "NoMo Thresh": {
-        value: settings.nomothresh,
-        step: 0.001,
-        min: 0.006,
-        max: 0.02,
-        wrap: true,
-        format: v => ("" + v).padEnd(5, "0"),
-        onchange: v => writeSetting("nomothresh", v),
-      },
-      "Min Duration": {
-        value: Math.floor(settings.sleepthresh * stFactor),
-        step: 1,
-        min: 5,
-        max: 15,
-        wrap: true,
-        format: v => v + "min",
-        onchange: v => writeSetting("sleepthresh", Math.ceil(v / stFactor)),
-      },
-      "Enabled": {
+      /*LANG*/"Enabled": {
         value: settings.enabled,
-        format: v => v ? "on" : "off",
-        onchange: function(v) {
+        onchange: v => {
           settings.enabled = v;
-          changeRestart();
+          require("sleeplog").setEnabled(v);
         }
       },
-      "Logfile ": {
-        value: settings.logfile === "sleeplog.log" ? true : (settings.logfile || "").endsWith(".log") ? "custom" : false,
-        format: v => v === true ? "default" : v ? "custom" : "off",
-        onchange: function(v) {
-          if (v !== "custom") {
-            settings.logfile = v ? "sleeplog.log" : false;
-            changeRestart();
-          }
-        }
+      /*LANG*/"Debugging": {
+        value: debugImg,
+        onchange: () => setTimeout(showDebug, 10)
       }
     };
-    // check power saving mode to delete unused entries
-    (settings.powersaving ? ["NoMo Thresh", "Min Duration"] : ["Max Move"]).forEach(property => delete mainMenu[property]);
     var menu = E.showMenu(mainMenu);
   }
 
diff --git a/apps/sleeplogalarm/ChangeLog b/apps/sleeplogalarm/ChangeLog
new file mode 100644
index 000000000..80f8bd7e4
--- /dev/null
+++ b/apps/sleeplogalarm/ChangeLog
@@ -0,0 +1,4 @@
+0.01: New App!
+0.02: Add "from Consec."-setting
+0.03: Correct how to ignore last triggered alarm
+0.04: Make "disable alarm" possible on next day; correct alarm filtering; improve settings
\ No newline at end of file
diff --git a/apps/sleeplogalarm/README.md b/apps/sleeplogalarm/README.md
new file mode 100644
index 000000000..005377fb1
--- /dev/null
+++ b/apps/sleeplogalarm/README.md
@@ -0,0 +1,56 @@
+# Sleep Log Alarm
+
+This widget searches for active alarms and raises an own alarm event up to the defined time earlier, if in light sleep or awake phase. Optional the earlier alarm will only be triggered if comming from or in consecutive sleep. The settings of the earlier alarm can be adjusted and it is possible to filter the targeting alarms by time and message. By default the time of the targeting alarm is displayed inside the widget which can be adjusted, too.
+
+_This widget does not detect sleep on its own and can not create alarms. It requires the [sleeplog](/apps/?id=sleeplog) app and any alarm app that uses [sched](/apps/?id=sched) to be installed._
+
+---
+### Settings
+---
+
+  - __earlier__ | duration to trigger alarm earlier  
+    _10min_ / _20min_ / __30min__ / ... / _120min_
+  - __from Consec.__ | only trigger if comming from consecutive sleep  
+    _on_ / __off__
+  - __vib pattern__ | vibration pattern for the earlier alarm  
+    __..__ / ...
+  - __msg__ | customized message for the earlier alarm  
+    __...__ / ...
+  - __msg as prefix__ | use the customized message as prefix to the original message or replace it comlpetely if disabled  
+    __on__ / _off_
+  - __disable alarm__ | if enabled the original alarm will be disabled  
+    _on_ / __off__
+  - __auto snooze__ | auto snooze option for the earlier alarm  
+    __on__ / _off_
+  - __Filter Alarm__ submenu
+    - __time from__ | exclude alarms before this time  
+      _0:00_ / _0:15_ / ... / __3:00__ / ... / _24:00_
+    - __time to__ | exclude alarms after this time  
+      _0:00_ / _0:15_ / ... / __12:00__ / ... / _24:00_
+    - __msg includes__ | include only alarms including this string in msg  
+      __""__ / ...
+  - __Widget__ submenu
+    - __hide__ | completely hide the widget  
+      _on_ / __off__
+    - __show time__ | show the time of the targeting alarm  
+      __on__ / _off_
+    - __color__ | color of the widget
+      _red_ / __yellow__ / ... / _white_
+  - __Enabled__ | completely en-/disables the background service
+    __on__ / _off_
+
+---
+### Worth Mentioning
+---
+
+#### Requests, Bugs and Feedback
+Please leave requests and bug reports by raising an issue at [github.com/storm64/BangleApps](https://github.com/storm64/BangleApps) (or send me a [mail](mailto:banglejs@storm64.de)).
+
+#### Creator
+Storm64 ([Mail](mailto:banglejs@storm64.de), [github](https://github.com/storm64))
+
+#### Attributions
+The app icon is downloaded from [https://icons8.com](https://icons8.com).
+
+#### License
+[MIT License](LICENSE)
diff --git a/apps/sleeplogalarm/app.png b/apps/sleeplogalarm/app.png
new file mode 100644
index 000000000..1a8e53865
Binary files /dev/null and b/apps/sleeplogalarm/app.png differ
diff --git a/apps/sleeplogalarm/lib.js b/apps/sleeplogalarm/lib.js
new file mode 100644
index 000000000..343e811af
--- /dev/null
+++ b/apps/sleeplogalarm/lib.js
@@ -0,0 +1,141 @@
+// load library
+var sched = require("sched");
+
+// find next active alarm in range
+function getNextAlarm(allAlarms, fo, withId) {
+  if (withId) allAlarms = allAlarms.map((a, idx) => {
+    a.idx = idx;
+    return a;
+  });
+  // return next active alarms in range, filter for
+  //  active && not timer && not own alarm &&
+  //  after from && before to && includes msg
+  var ret = allAlarms.filter(
+      a => a.on && !a.timer && a.id !== "sleeplog" &&
+      a.t >= fo.from && a.t < fo.to && (!fo.msg || a.msg.includes(fo.msg))
+    ).map(a => { // add time to alarm
+      a.tTo = sched.getTimeToAlarm(a);
+      return a;
+    }).filter(a => a.tTo // filter non active alarms
+    // sort to get next alarm first
+    ).sort((a, b) => a.tTo - b.tTo);
+  // prevent triggering for an already triggered alarm again if available
+  if (fo.lastDate) {
+    var toLast = fo.lastDate - new Date().valueOf() + 1000;
+    if (toLast > 0) ret = ret.filter(a => a.tTo > toLast);
+  }
+  // return first entry
+  return ret[0] || {};
+}
+
+exports = {
+  // function to read settings with defaults
+  getSettings: function() {
+    return Object.assign({
+      enabled: true,
+      earlier: 30,
+      fromConsec: false,
+      vibrate: "..",
+      msg: "...\n",
+      msgAsPrefix: true,
+      disableOnAlarm: false, // !!! not available if alarm is at the next day
+      as: true,
+      filter: {
+        from: 3 * 36E5,
+        to: 12 * 36E5,
+        msg: ""
+      },
+      wid: {
+        hide: false,
+        time: true,
+        color: g.theme.dark ? 65504 : 31 // yellow or blue
+      }
+    }, require("Storage").readJSON("sleeplogalarm.settings.json", true) || {});
+  },
+
+  // widget reload function
+  widReload: function() {
+    // abort if trigger object is not available
+    if (typeof (global.sleeplog || {}).trigger !== "object") return;
+
+    // read settings to calculate alarm range
+    var settings = exports.getSettings();
+
+    // set the alarm time
+    this.time = getNextAlarm(sched.getAlarms(), settings.filter).t;
+
+    // abort if no alarm time could be found inside range
+    if (!this.time) return;
+
+    // set widget width if not hidden
+    if (!this.hidden) this.width = 8;
+
+    // insert sleeplogalarm conditions and function
+    sleeplog.trigger.sleeplogalarm = {
+      from: this.time - settings.earlier * 6E4,
+      to: this.time - 1,
+      fn: function (data) {
+        // execute trigger function if on light sleep or awake
+        //  and if set if comming from consecutive
+        if ((data.status === 3 || data.status === 2) && !settings.fromConsec ||
+            data.consecutive === 3 || data.prevConsecutive === 3)
+          require("sleeplogalarm").trigger();
+      }
+    };
+  },
+
+  // trigger function
+  trigger: function() {
+    // read settings
+    var settings = exports.getSettings();
+
+    // read all alarms
+    var allAlarms = sched.getAlarms();
+
+    // find first active alarm
+    var alarm = getNextAlarm(sched.getAlarms(), settings.filter, settings.disableOnAlarm);
+
+    // return if no alarm is found
+    if (!alarm) return;
+
+    // get now
+    var now = new Date();
+
+    // get date of the alarm
+    var aDate = new Date(now + alarm.tTo);
+
+    // disable earlier triggered alarm if set
+    if (settings.disableOnAlarm) {
+      // set alarms last to the day it would trigger
+      allAlarms[alarm.idx].last = aDate.getDate();
+      // remove added indexes
+      allAlarms = allAlarms.map(a => {
+        delete a.idx;
+        return a;
+      });
+    }
+
+    // add new alarm for now with data from found alarm
+    allAlarms.push({
+      id: "sleeplog",
+      appid: "sleeplog",
+      on: true,
+      t: ((now.getHours() * 60 + now.getMinutes()) * 60 + now.getSeconds()) * 1000,
+      dow: 127,
+      msg: settings.msg + (settings.msgAsPrefix ? alarm.msg || "" : ""),
+      vibrate: settings.vibrate || alarm.vibrate,
+      as: settings.as,
+      del: true
+    });
+
+    // save date of the alarm to prevent triggering for the same alarm again
+    settings.filter.lastDate = aDate.valueOf();
+    require("Storage").writeJSON("sleeplogalarm.settings.json", settings);
+
+    // write changes
+    sched.setAlarms(allAlarms);
+
+    // trigger sched.js
+    load("sched.js");
+  }
+};
\ No newline at end of file
diff --git a/apps/sleeplogalarm/metadata.json b/apps/sleeplogalarm/metadata.json
new file mode 100644
index 000000000..fd85507e6
--- /dev/null
+++ b/apps/sleeplogalarm/metadata.json
@@ -0,0 +1,21 @@
+{
+  "id":"sleeplogalarm",
+  "name":"Sleep Log Alarm",
+  "shortName": "SleepLogAlarm",
+  "version": "0.04",
+  "description": "Enhance your morning and let your alarms wake you up when you are in light sleep.",
+  "icon": "app.png",
+  "type": "widget",
+  "tags": "tool,widget",
+  "supports": ["BANGLEJS2"],
+  "dependencies": {
+    "scheduler": "type",
+    "sleeplog": "app"
+  },
+  "readme": "README.md",
+  "storage": [
+    {"name": "sleeplogalarm", "url": "lib.js"},
+    {"name": "sleeplogalarm.settings.js", "url": "settings.js"},
+    {"name": "sleeplogalarm.wid.js", "url": "widget.js"}
+  ]
+}
diff --git a/apps/sleeplogalarm/settings.js b/apps/sleeplogalarm/settings.js
new file mode 100644
index 000000000..1f3a13272
--- /dev/null
+++ b/apps/sleeplogalarm/settings.js
@@ -0,0 +1,192 @@
+(function(back) {
+  // read settings
+  var settings = require("sleeplogalarm").getSettings();
+
+  // write change to storage
+  function writeSetting() {
+    require("Storage").writeJSON("sleeplogalarm.settings.json", settings);
+  }
+
+  // read input from keyboard
+  function readInput(v, cb) {
+    // setTimeout required to load after menu refresh
+    setTimeout((v, cb) => {
+      if (require("Storage").read("textinput")) {
+        g.clear();
+        require("textinput").input({text: v}).then(v => cb(v));
+      } else {
+        E.showAlert(/*LANG*/"No keyboard app installed").then(() => cb());
+      }
+    }, 0, v, cb);
+  }
+
+  // show widget menu
+  function showFilterMenu() {
+    // set menu
+    var filterMenu = {
+      "": {
+        title: "Filter Alarm"
+      },
+      /*LANG*/"< Back": () => showMain(8),
+      /*LANG*/"time from": {
+        value: settings.filter.from / 6E4,
+        step: 10,
+        min: 0,
+        max: 1440,
+        wrap: true,
+        noList: true,
+        format: v => (0|v/60) + ":" + ("" + (v%60)).padStart(2, "0"),
+        onchange: v => {
+          settings.filter.from = v * 6E4;
+          writeSetting();
+        }
+      },
+      /*LANG*/"time to": {
+        value: settings.filter.to / 6E4,
+        step: 10,
+        min: 0,
+        max: 1440,
+        wrap: true,
+        noList: true,
+        format: v => (0|v/60) + ":" + ("" + (v%60)).padStart(2, "0"),
+        onchange: v => {
+          settings.filter.to = v * 6E4;
+          writeSetting();
+        }
+      },
+      /*LANG*/"msg includes": {
+        value: settings.filter.msg,
+        format: v => !v ? "" : v.length > 6 ? v.substring(0, 6)+"..." : v,
+        onchange: v => readInput(v, v => {
+          settings.filter.msg = v;
+          writeSetting();
+          showFilterMenu(3);
+        })
+      }
+    };
+    var menu = E.showMenu(filterMenu);
+  }
+
+  // show widget menu
+  function showWidMenu() {
+    // define color values and names
+    var colName = ["red", "yellow", "green", "cyan", "blue", "magenta", "black", "white"];
+    var colVal = [63488, 65504, 2016, 2047, 31, 63519, 0, 65535];
+
+    // set menu
+    var widgetMenu = {
+      "": {
+        title: "Widget Settings"
+      },
+      /*LANG*/"< Back": () => showMain(9),
+      /*LANG*/"hide": {
+        value: settings.wid.hide,
+        onchange: v => {
+          settings.wid.hide = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"show time": {
+        value: settings.wid.time,
+        onchange: v => {
+          settings.wid.time = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"color": {
+        value: colVal.indexOf(settings.wid.color),
+        min: 0,
+        max: colVal.length -1,
+        wrap: true,
+        format: v => colName[v],
+        onchange: v => {
+          settings.wid.color = colVal[v];
+          writeSetting();
+        }
+      }
+    };
+    var menu = E.showMenu(widgetMenu);
+  }
+
+  // show main menu
+  function showMain(selected) {
+    // set menu
+    var mainMenu = {
+      "": {
+        title: "Sleep Log Alarm",
+        selected: selected
+      },
+      /*LANG*/"< Back": () => back(),
+      /*LANG*/"erlier": {
+        value: settings.earlier,
+        step: 10,
+        min: 10,
+        max: 120,
+        wrap: true,
+        noList: true,
+        format: v => v + /*LANG*/"min",
+        onchange: v => {
+          settings.earlier = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"from Consec.": {
+        value: settings.fromConsec,
+        onchange: v => {
+          settings.fromConsec = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"vib pattern": require("buzz_menu").pattern(
+        settings.vibrate,
+        v => {
+          settings.vibrate = v;
+          writeSetting();
+        }
+      ),
+      /*LANG*/"msg": {
+        value: settings.msg,
+        format: v => !v ? "" : v.length > 6 ? v.substring(0, 6)+"..." : v,
+        onchange: v => readInput(v, v => {
+          settings.msg = v;
+          writeSetting();
+          showMenu(4);
+        })
+      },
+      /*LANG*/"msg as prefix": {
+        value: settings.msgAsPrefix,
+        onchange: v => {
+          settings.msgAsPrefix = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"disable alarm": {
+        value: settings.disableOnAlarm,
+        onchange: v => {
+          settings.disableOnAlarm = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"auto snooze": {
+        value: settings.as,
+        onchange: v => {
+          settings.as = v;
+          writeSetting();
+        }
+      },
+      /*LANG*/"Filter Alarm": () => showFilterMenu(),
+      /*LANG*/"Widget": () => showWidMenu(),
+      /*LANG*/"Enabled": {
+        value: settings.enabled,
+        onchange: v => {
+          settings.enabled = v;
+          writeSetting();
+        }
+      }
+    };
+    var menu = E.showMenu(mainMenu);
+  }
+
+  // draw main menu
+  showMain();
+})
diff --git a/apps/sleeplogalarm/widget.js b/apps/sleeplogalarm/widget.js
new file mode 100644
index 000000000..e3171751f
--- /dev/null
+++ b/apps/sleeplogalarm/widget.js
@@ -0,0 +1,32 @@
+// check if enabled in settings
+if ((require("Storage").readJSON("sleeplogalarm.settings.json", true) || {enabled: true}).enabled) {
+  // read settings
+  settings = require("sleeplogalarm").getSettings(); // is undefined if used with var
+
+  // insert neccessary settings into widget
+  WIDGETS.sleeplogalarm = {
+    area: "tl",
+    width: 0,
+    time: 0,
+    earlier: settings.earlier,
+    draw: function () {
+      // draw zzz
+      g.reset().setColor(settings.wid.color).drawImage(atob("BwoBD8SSSP4EEEDg"), this.x + 1, this.y);
+      // call function to draw the time of alarm if a alarm is found
+      if (this.time) this.drawTime(this.time + 1);
+    },
+    drawTime: () => {},
+    reload: require("sleeplogalarm").widReload
+  };
+
+  // add function to draw the time of alarm if enabled
+  if (settings.wid.time) WIDGETS.sleeplogalarm.drawTime = function(time) {
+    // directly include Font4x5Numeric
+    g.setFontCustom(atob("CAZMA/H4PgvXoK1+DhPg7W4P1uCEPg/X4O1+AA=="), 46, atob("AgQEAgQEBAQEBAQE"), 5).setFontAlign(1, 1);
+    g.drawString(0|(time / 36E5), this.x + this.width + 1, this.y + 17);
+    g.drawString(0|((time / 36E5)%1 * 60), this.x + this.width + 1, this.y + 23);
+  };
+
+  // load widget
+  WIDGETS.sleeplogalarm.reload();
+}
\ No newline at end of file
diff --git a/apps/sleepphasealarm/ChangeLog b/apps/sleepphasealarm/ChangeLog
index 6bf296342..795c62fa2 100644
--- a/apps/sleepphasealarm/ChangeLog
+++ b/apps/sleepphasealarm/ChangeLog
@@ -10,4 +10,6 @@
 0.09: Vibrate with configured pattern
       Add setting to defer start of algorithm
       Add setting to disable scheduler alarm
-
+0.10: Fix: Do not wake when falling asleep
+0.11: Minor tweaks
+0.12: Support javascript command to execute as defined in scheduler 'js' configuration
diff --git a/apps/sleepphasealarm/README.md b/apps/sleepphasealarm/README.md
index ecb3feb06..574e84e1e 100644
--- a/apps/sleepphasealarm/README.md
+++ b/apps/sleepphasealarm/README.md
@@ -9,6 +9,8 @@ The display shows:
 - Time difference between current time and alarm time (ETA).
 - Current state of the ESS algorithm, "Sleep" or "Awake", useful for debugging. State can also be "Deferred", see the "Run before alarm"-option.
 
+Replacing the watch strap with a more comfortable one (e.g. made of nylon) is recommended.
+
 ## Settings
 
 * **Keep alarm enabled**
@@ -16,7 +18,7 @@ The display shows:
   - No: No action at configured alarm time from scheduler.
 * **Run before alarm**
   - disabled: (default) The ESS algorithm starts immediately when the application starts.
-  - 1..23: The ESS algorithm starts the configured time before the alarm. E.g. when set to 1h for an alarm at 7:00 the ESS algorithm will start at 6:00. This improves battery life.
+  - 1..23: The ESS algorithm starts the configured time before the alarm. E.g. when set to 1h for an alarm at 7:00 the ESS algorithm will start at 6:00. This increases battery life.
 
 ## Logging
 
diff --git a/apps/sleepphasealarm/app.js b/apps/sleepphasealarm/app.js
index b19799c4b..ba8bff9b2 100644
--- a/apps/sleepphasealarm/app.js
+++ b/apps/sleepphasealarm/app.js
@@ -21,8 +21,8 @@ let logs = [];
 //
 // Function needs to be called for every measurement but returns a value at maximum once a second (see winwidth)
 // start of sleep marker is delayed by sleepthresh due to continous data reading
-const winwidth=13;
-const nomothresh=0.03; // 0.006 was working on Bangle1, but Bangle2 has higher noise.
+const winwidth=13; // Actually 12.5 Hz, rounded
+const nomothresh=0.023; // Original implementation: 6, resolution 11 bit, scale +-4G = 6/(2^(11-1))*4 = 0.023438 in G
 const sleepthresh=600;
 var ess_values = [];
 var slsnds = 0;
@@ -69,6 +69,9 @@ active.forEach(alarm => {
   }
 });
 
+const LABEL_ETA = /*LANG*/"ETA";
+const LABEL_WAKEUP_TIME = /*LANG*/"Alarm at";
+
 var layout = new Layout({
   type:"v", c: [
     {type:"txt", font:"10%", label:"Sleep Phase Alarm", bgCol:g.theme.bgH, fillx: true, height:Bangle.appRect.h/6},
@@ -84,7 +87,7 @@ function drawApp() {
   var alarmMinute = nextAlarmDate.getMinutes();
   if (alarmHour < 10) alarmHour = "0" + alarmHour;
   if (alarmMinute < 10) alarmMinute = "0" + alarmMinute;
-  layout.alarm_date.label = "Alarm at " + alarmHour + ":" + alarmMinute;
+  layout.alarm_date.label = `${LABEL_WAKEUP_TIME}: ${alarmHour}:${alarmMinute}`;
   layout.render();
 
   function drawTime() {
@@ -94,7 +97,7 @@ function drawApp() {
       const diff = nextAlarmDate - now;
       const diffHour = Math.floor((diff % 86400000) / 3600000).toString();
       const diffMinutes = Math.floor(((diff % 86400000) % 3600000) / 60000).toString();
-      layout.eta.label = "ETA: -"+ diffHour + ":" + diffMinutes.padStart(2, '0');
+      layout.eta.label = `${LABEL_ETA}: ${diffHour}:${diffMinutes.padStart(2, '0')}`;
       layout.render();
     }
 
@@ -139,7 +142,7 @@ if (nextAlarmDate !== undefined) {
   // minimum alert 30 minutes early
   minAlarm.setTime(nextAlarmDate.getTime() - (30*60*1000));
   run = () => {
-    layout.state.label = "Start";
+    layout.state.label = /*LANG*/"Start";
     layout.render();
     Bangle.setOptions({powerSave: false}); // do not dynamically change accelerometer poll interval
     Bangle.setPollInterval(80); // 12.5Hz
@@ -150,7 +153,7 @@ if (nextAlarmDate !== undefined) {
 
       if (swest !== undefined) {
         if (Bangle.isLCDOn()) {
-          layout.state.label = swest ? "Sleep" : "Awake";
+          layout.state.label = swest ? /*LANG*/"Sleep" : /*LANG*/"Awake";
           layout.render();
         }
         // log
@@ -168,14 +171,18 @@ if (nextAlarmDate !== undefined) {
         // The alarm widget should handle this one
         addLog(now, "alarm");
         setTimeout(load, 1000);
-      } else if (measure && now >= minAlarm && swest_last === false) {
+      } else if (measure && now >= minAlarm && swest === false) {
         addLog(now, "alarm");
-        buzz();
         measure = false;
-        if (config.settings.disableAlarm) {
-          // disable alarm for scheduler
-          nextAlarmConfig.last = now.getDate();
-          require("Storage").writeJSON("sched.json", alarms);
+        if (nextAlarmConfig.js) {
+          eval(nextAlarmConfig.js); // run nextAlarmConfig.js if set
+        } else {
+          buzz();
+          if (config.settings.disableAlarm) {
+            // disable alarm for scheduler
+            nextAlarmConfig.last = now.getDate();
+            require('Storage').writeJSON('sched.json', alarms);
+          }
         }
       }
     });
diff --git a/apps/sleepphasealarm/interface.html b/apps/sleepphasealarm/interface.html
index f45c183e1..8c8cea990 100644
--- a/apps/sleepphasealarm/interface.html
+++ b/apps/sleepphasealarm/interface.html
@@ -30,7 +30,7 @@ function getData() {
     // remove window
     Util.hideModal();
 
-    logs = logs.filter(log => log != null);
+    logs = logs.filter(log => log != null && log.filter(entry => entry.type === "alarm").length > 0);
     logs.sort(function(a, b) {return new Date(b?.filter(entry => entry.type === "alarm")[0]?.time) - new Date(a?.filter(entry => entry.type === "alarm")[0]?.time)}); // sort by alarm date desc
     logs.forEach((log, i) => {
       const timeStr = log.filter(entry => entry.type === "alarm")[0]?.time;
diff --git a/apps/sleepphasealarm/metadata.json b/apps/sleepphasealarm/metadata.json
index 6ec5f4180..ced99062f 100644
--- a/apps/sleepphasealarm/metadata.json
+++ b/apps/sleepphasealarm/metadata.json
@@ -2,7 +2,7 @@
   "id": "sleepphasealarm",
   "name": "SleepPhaseAlarm",
   "shortName": "SleepPhaseAlarm",
-  "version": "0.09",
+  "version": "0.12",
   "description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.",
   "icon": "app.png",
   "tags": "alarm",
diff --git a/apps/slidingtext/ChangeLog b/apps/slidingtext/ChangeLog
index 0327ff387..5c4a9fa75 100644
--- a/apps/slidingtext/ChangeLog
+++ b/apps/slidingtext/ChangeLog
@@ -5,4 +5,7 @@
 0.05: BUGFIX: pedometer widget interfered with the clock Font Alignment
 0.06: Use Bangle.setUI for button/launcher handling
 0.07: Support for Bangle.js 2 and themes
-0.08: Removed "wake LCD on face-up"-feature: A watch-face should not set things like "wake LCD on face-up". 
+0.08: Removed "wake LCD on face-up"-feature: A watch-face should not set things like "wake LCD on face-up".
+0.09: Added button control toggle and other live controls to new settings screen.
+0.10: Tell clock widgets to hide.
+0.11: Added new styling and watch faces
diff --git a/apps/slidingtext/README.md b/apps/slidingtext/README.md
index d2d2fb5b6..dde2b62af 100644
--- a/apps/slidingtext/README.md
+++ b/apps/slidingtext/README.md
@@ -1,27 +1,81 @@
 # Sliding Text Clock - See the time in different languages
 
-Inspired by the Pebble sliding clock, old times are scrolled off the screen and new times on. You are also able to change language on the fly so you can see the time written in other languages using button 1. Please use the upload page to choose which languages you want loaded.
+Inspired by the Pebble sliding clock, previous times are scrolled off the screen and new times scrolled on. There are a variety of colours schemes, clock faces and languages available through the settings menu 
 
 ![](app.png)
 
-## Usage
+## Settings
 
-### Button 1
+Please go to the sliding text clock menu under the settings menu to customise clock. Settings -> Apps -> Sliding Clock
 
-Use Button 1 (the top right button) to change the language
 
-|   English   |  English (Traditional)    |  French    | Japanese (Romanji) |
-| ---- | ---- | ---- | ---- |
-|   ![](./format-01.jpg)   | ![](format-02.jpg)     |  ![](format-03.jpg) |![](format-04.jpg)    |
-|   **German**   |  **Spanish**    |      |  |
-|   ![](./format-05.jpg)   | ![](format-06.jpg)     | |    |
 
-### Button 3
-Button 3 (bottom right button) is used to change the colour
+## Colour
+
+The colour selection allows to select between different colour schemes. Colour schemes that are currently available are:
+
+- White background  with black lettering
+- Black background with red and white lettering
+- Red background with yellow and white lettering.
+- Grey background with black and white lettering
+- Purple with yellow and white lettering
+- Blue with yellow and white lettering
+
+## Live Control
+
+Live control allows you to change the colour scheme of the clock by pressing 
+
+- The bottom right hand corner of the screen for a bangle 2
+- Button 3 on on a bangle 1
+
+When select the watch will move to the next colour in the scheme. The selected colour will not be saved so it will will revert to the last colour select in the menu when the clock is restarted. This option is included to help select the preferred colour with having to continuously go back to the settings menu.
+
+The Live Control is turned off by default on a bangle 2, but is on by default for a bangle 1
+
+## Style
+
+Style controls the clock face.
+
+
+
+### English
+
+| Style  | English 1                                       | English 1 Alternative                                        | English 2                                | English 2 Alternative                                  | English Hybrid                                            |
+| ------ | ----------------------------------------------- | ------------------------------------------------------------ | ---------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------- |
+| Screen | ![](slidingtext-screenshot.english.png)         | ![](slidingtext-screenshot.english_alt.png)                  | ![](slidingtext-screenshot.english2.png) | ![](slidingtext-screenshot.english2_alt.png)           | ![](slidingtext-screenshot.hybrid.png)                    |
+| Notes  | Straight 12 hour English time and Date in words | Straight 12 hour English time and Date in words in alternative style | Traditional English Time                 | Traditional English Time and Date in alternative style | 24 Hour clock  in numbers with minutes  and date in words |
+
+### French
+| Style  | French         |
+| ------ | -------------- |
+| Screen | ![](slidingtext-screenshot.french.png) |
+
+### Spanish
+| Style  | Spanish         |
+| ------ | -------------- |
+| Screen | ![](slidingtext-screenshot.spanish.png) |
+
+### German 
+
+| Style  | German 12 Hour | German 24 Hour |
+| ------ | -------------- | -------------- |
+| Screen | ![](slidingtext-screenshot.german.png) |![](slidingtext-screenshot.german24.png) |
+| Notes  | 12 Hour German clock in words | 24 Hour German clock in words |
+
+### Japanese
+
+| Style  | Japanese                                 |
+| ------ | ---------------------------------------- |
+| Screen | ![](slidingtext-screenshot.japanese.png) |
+| Notes  | Simplified Romanji Japanese Clock.       |
+
+### Digital
+
+| Style  | Digits                                  |
+| ------ | --------------------------------------- |
+| Screen | ![](slidingtext-screenshot.digital.png) |
+| Notes  | Sliding version of a digital clock      |
 
-|  Black   |  Red    |  Gray    |  Purple    |
-| ---- | ---- | ---- | ---- |
-|   ![](./color-01.jpg) | ![](color-02.jpg) |  ![](color-03.jpg)   | ![](color-04.jpg)   |
 
 ## Further Details
 
@@ -29,7 +83,7 @@ For further details of design and working please visit [The Project Page](https:
 
 ## Requests
 
-Reach out to adrian@adriankirk.com if you have feature requests or notice bugs.
+Thank you so much for the feedback so far. Please reach out to adrian@adriankirk.com if you have feature requests or notice bugs.
 
 ## Creator
 
diff --git a/apps/slidingtext/color-01.jpg b/apps/slidingtext/color-01.jpg
deleted file mode 100644
index 49efb0481..000000000
Binary files a/apps/slidingtext/color-01.jpg and /dev/null differ
diff --git a/apps/slidingtext/color-02.jpg b/apps/slidingtext/color-02.jpg
deleted file mode 100644
index 446491cc4..000000000
Binary files a/apps/slidingtext/color-02.jpg and /dev/null differ
diff --git a/apps/slidingtext/color-03.jpg b/apps/slidingtext/color-03.jpg
deleted file mode 100644
index 0b26419a5..000000000
Binary files a/apps/slidingtext/color-03.jpg and /dev/null differ
diff --git a/apps/slidingtext/color-04.jpg b/apps/slidingtext/color-04.jpg
deleted file mode 100644
index 385c42a90..000000000
Binary files a/apps/slidingtext/color-04.jpg and /dev/null differ
diff --git a/apps/slidingtext/custom.html b/apps/slidingtext/custom.html
deleted file mode 100644
index 5e89e230b..000000000
--- a/apps/slidingtext/custom.html
+++ /dev/null
@@ -1,71 +0,0 @@
-
-  
-    
-  
-  
-      
-      

Please select watch languages (Max 3, only the first 3 selected will be loaded)

- - - - - - -
EnabledName
- -

Click

- - - - - - diff --git a/apps/slidingtext/format-01.jpg b/apps/slidingtext/format-01.jpg deleted file mode 100644 index b8bc4552e..000000000 Binary files a/apps/slidingtext/format-01.jpg and /dev/null differ diff --git a/apps/slidingtext/format-02.jpg b/apps/slidingtext/format-02.jpg deleted file mode 100644 index c8b7a5e60..000000000 Binary files a/apps/slidingtext/format-02.jpg and /dev/null differ diff --git a/apps/slidingtext/format-03.jpg b/apps/slidingtext/format-03.jpg deleted file mode 100644 index 5dfdd8b23..000000000 Binary files a/apps/slidingtext/format-03.jpg and /dev/null differ diff --git a/apps/slidingtext/format-04.jpg b/apps/slidingtext/format-04.jpg deleted file mode 100644 index 19b01fd64..000000000 Binary files a/apps/slidingtext/format-04.jpg and /dev/null differ diff --git a/apps/slidingtext/format-05.jpg b/apps/slidingtext/format-05.jpg deleted file mode 100644 index d6bd2b9aa..000000000 Binary files a/apps/slidingtext/format-05.jpg and /dev/null differ diff --git a/apps/slidingtext/format-06.jpg b/apps/slidingtext/format-06.jpg deleted file mode 100644 index 493777d23..000000000 Binary files a/apps/slidingtext/format-06.jpg and /dev/null differ diff --git a/apps/slidingtext/metadata.json b/apps/slidingtext/metadata.json index 2937a618b..098fdb747 100644 --- a/apps/slidingtext/metadata.json +++ b/apps/slidingtext/metadata.json @@ -1,17 +1,18 @@ { "id": "slidingtext", "name": "Sliding Clock", - "version": "0.08", + "version": "0.11", "description": "Inspired by the Pebble sliding clock, old times are scrolled off the screen and new times on. You are also able to change language on the fly so you can see the time written in other languages using button 1. Currently English, French, Japanese, Spanish and German are supported", "icon": "slidingtext.png", + "screenshots": [{"url":"slidingtext-screenshot.english.png"},{"url":"slidingtext-screenshot.english2.png"},{"url":"slidingtext-screenshot.hybrid.png"}], "type": "clock", "tags": "clock", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", - "custom": "custom.html", - "allow_emulator": false, + "allow_emulator": true, "storage": [ {"name":"slidingtext.app.js","url":"slidingtext.js"}, + {"name":"slidingtext.settings.js","url":"slidingtext.settings.js"}, {"name":"slidingtext.img","url":"slidingtext-icon.js","evaluate":true}, {"name":"slidingtext.locale.en.js","url":"slidingtext.locale.en.js"}, {"name":"slidingtext.locale.en2.js","url":"slidingtext.locale.en2.js"}, @@ -19,7 +20,12 @@ {"name":"slidingtext.locale.es.js","url":"slidingtext.locale.es.js"}, {"name":"slidingtext.locale.fr.js","url":"slidingtext.locale.fr.js"}, {"name":"slidingtext.locale.jp.js","url":"slidingtext.locale.jp.js"}, + {"name":"slidingtext.utils.de.js","url":"slidingtext.utils.de.js"}, {"name":"slidingtext.locale.de.js","url":"slidingtext.locale.de.js"}, + {"name":"slidingtext.locale.de2.js","url":"slidingtext.locale.de2.js"}, + {"name":"slidingtext.locale.dgt.js","url":"slidingtext.locale.dgt.js"}, + {"name":"slidingtext.locale.hyb.js","url":"slidingtext.locale.hyb.js"}, {"name":"slidingtext.dtfmt.js","url":"slidingtext.dtfmt.js"} - ] + ], + "data": [{"name": "slidingtext.settings.json"}] } diff --git a/apps/slidingtext/slidingtext-screenshot.digital.png b/apps/slidingtext/slidingtext-screenshot.digital.png new file mode 100644 index 000000000..b06d2ef18 Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.digital.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.english.png b/apps/slidingtext/slidingtext-screenshot.english.png new file mode 100644 index 000000000..14c91ba43 Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.english.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.english2.png b/apps/slidingtext/slidingtext-screenshot.english2.png new file mode 100644 index 000000000..3005d19ee Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.english2.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.english2_alt.png b/apps/slidingtext/slidingtext-screenshot.english2_alt.png new file mode 100644 index 000000000..88131afa4 Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.english2_alt.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.english_alt.png b/apps/slidingtext/slidingtext-screenshot.english_alt.png new file mode 100644 index 000000000..2ce813710 Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.english_alt.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.french.png b/apps/slidingtext/slidingtext-screenshot.french.png new file mode 100644 index 000000000..8f04fb8dc Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.french.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.german.png b/apps/slidingtext/slidingtext-screenshot.german.png new file mode 100644 index 000000000..0726f575d Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.german.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.german24.png b/apps/slidingtext/slidingtext-screenshot.german24.png new file mode 100644 index 000000000..99d93b475 Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.german24.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.hybrid.png b/apps/slidingtext/slidingtext-screenshot.hybrid.png new file mode 100644 index 000000000..2ae7721fa Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.hybrid.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.japanese.png b/apps/slidingtext/slidingtext-screenshot.japanese.png new file mode 100644 index 000000000..80c9cdee9 Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.japanese.png differ diff --git a/apps/slidingtext/slidingtext-screenshot.spanish.png b/apps/slidingtext/slidingtext-screenshot.spanish.png new file mode 100644 index 000000000..7160f29d6 Binary files /dev/null and b/apps/slidingtext/slidingtext-screenshot.spanish.png differ diff --git a/apps/slidingtext/slidingtext.dtfmt.js b/apps/slidingtext/slidingtext.dtfmt.js index 865ea47e6..2543610c1 100644 --- a/apps/slidingtext/slidingtext.dtfmt.js +++ b/apps/slidingtext/slidingtext.dtfmt.js @@ -3,13 +3,20 @@ class DateFormatter { * A pure virtual class which all the other date formatters will * inherit from. * The name will be used to declare the date format when selected - * and the date formatDate methid will return the time formated + * and the date formatDate method will return the time formated * to the lines of text on the screen */ - name(){return "no name";} - formatDate(date){ - return ["no","date","defined"]; - } + formatDate(date){ return ["no","date","defined"]; } + + /** + * returns a map of the different row types + */ + defaultRowTypes(){} + + /** + * returns a list of row definitions (1 definition can cover m + */ + defaultRowDefs(){ return [];} } module.exports = DateFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.js b/apps/slidingtext/slidingtext.js index 7b56af1a1..47a24ea6a 100644 --- a/apps/slidingtext/slidingtext.js +++ b/apps/slidingtext/slidingtext.js @@ -8,8 +8,14 @@ const color_schemes = [ { name: "black", background : [0.0,0.0,0.0], - main_bar: [1.0,1.0,1.0], - other_bars: [0.85,0.85,0.85], + main_bar: [1.0,0.0,0.0], + other_bars: [0.9,0.9,0.9], + }, + { + name: "white", + background : [1.0,1.0,1.0], + main_bar: [0.0,0.0,0.0], + other_bars: [0.1,0.1,0.1], }, { name: "red", @@ -25,14 +31,14 @@ const color_schemes = [ }, { name: "purple", - background : [1.0,0.0,1.0], + background : [0.3,0.0,0.6], main_bar: [1.0,1.0,0.0], other_bars: [0.85,0.85,0.85] }, { name: "blue", - background : [0.4,0.7,1.0], - main_bar: [1.0,1.0,1.0], + background : [0.1,0.2,1.0], + main_bar: [1.0,1.0,0.0], other_bars: [0.9,0.9,0.9] } ]; @@ -60,17 +66,12 @@ let command_stack_high_priority = []; let command_stack_low_priority = []; function next_command(){ - command = command_stack_high_priority.pop(); + var command = command_stack_high_priority.pop(); if(command == null){ - //console.log("Low priority command"); command = command_stack_low_priority.pop(); - } else { - //console.log("High priority command"); } if(command != null){ command.call(); - } else { - //console.log("no command"); } } @@ -81,7 +82,7 @@ function reset_commands(){ function has_commands(){ return command_stack_high_priority.length > 0 || - command_stack_low_priority.lenth > 0; + command_stack_low_priority.length > 0; } class ShiftText { @@ -96,7 +97,9 @@ class ShiftText { constructor(x,y,txt,font_name, font_size,speed_x,speed_y,freq_millis, color, - bg_color){ + bg_color, + row_context, + rotation){ this.x = x; this.tgt_x = x; this.init_x = x; @@ -112,17 +115,15 @@ class ShiftText { this.freq_millis = freq_millis; this.color = color; this.bg_color = bg_color; + this.row_context = row_context; + this.rotation = rotation; this.finished_callback=null; this.timeoutId = null; } - setColor(color){ - this.color = color; - } - setBgColor(bg_color){ - this.bg_color = bg_color; - } + getRowContext(){ return this.row_context;} + setColor(color){ this.color = color; } + setBgColor(bg_color){ this.bg_color = bg_color; } reset(hard_reset) { - //console.log("reset"); this.hide(); this.x = this.init_x; this.y = this.init_y; @@ -135,13 +136,13 @@ class ShiftText { } } show() { - g.setFontAlign(-1,-1,0); + g.setFontAlign(-1,-1,this.rotation); g.setFont(this.font_name,this.font_size); g.setColor(this.color[0],this.color[1],this.color[2]); g.drawString(this.txt, this.x, this.y); } hide(){ - g.setFontAlign(-1,-1,0); + g.setFontAlign(-1,-1,this.rotation); g.setFont(this.font_name,this.font_size); //console.log("bgcolor:" + this.bg_color); g.setColor(this.bg_color[0],this.bg_color[1],this.bg_color[2]); @@ -182,6 +183,36 @@ class ShiftText { this.tgt_y = new_y; this._doMove(); } + scrollInFromBottom(txt,to_y){ + if(to_y == null) + to_y = this.init_y; + + this.setTextPosition(txt, this.init_x, g.getHeight()*2); + this.moveTo(this.init_x,to_y); + } + scrollInFromLeft(txt,to_x){ + if(to_x == null) + to_x = this.init_x; + + this.setTextPosition(txt, -txt.length * this.font_size - this.font_size, this.init_y); + this.moveTo(to_x,this.init_y); + } + scrollInFromRight(txt,to_x){ + if(to_x == null) + to_x = this.init_x; + + this.setTextPosition(txt, g.getWidth() + this.font_size, this.init_y); + this.moveTo(to_x,this.init_y); + } + scrollOffToLeft(){ + this.moveTo(-this.txt.length * this.font_size, this.init_y); + } + scrollOffToRight(){ + this.moveTo(g.getWidth() + this.font_size, this.init_y); + } + scrollOffToBottom(){ + this.moveTo(this.init_x,g.getHeight()*2); + } onFinished(finished_callback){ this.finished_callback = finished_callback; } @@ -224,131 +255,234 @@ class ShiftText { if(!finished){ this.timeoutId = setTimeout(this._doMove.bind(this), this.freq_millis); } else if(this.finished_callback != null){ - //console.log("finished - calling:" + this.finished_callback); this.finished_callback.call(); this.finished_callback = null; } } } -const CLOCK_TEXT_SPEED_X = 10; -// a list of display rows -let row_displays; -function setRowDisplays(y, heights) { - var cols = [ - main_color(), other_color(), other_color(), other_color(), main_color() - ]; - row_displays = []; - for (var i=0;i200)? 1 : 2; +} + +let row_displays; +function initDisplay(settings) { + if(row_displays != null){ + return; + } + if(settings == null){ + settings = {}; + } + var row_types = { + large: { + color: 'major', + speed: 'medium', + angle_to_horizontal: 0, + scroll_off: ['left'], + scroll_in: ['right'], + size: 'large' + }, + medium: { + color: 'minor', + speed: 'slow', + angle_to_horizontal: 0, + scroll_off: ['left'], + scroll_in: ['right'], + size: 'medium' + }, + small: { + color: 'minor', + speed: 'superslow', + angle_to_horizontal: 0, + scroll_off: ['left'], + scroll_in: ['right'], + size: 'small' + } + }; + + function mergeMaps(map1,map2){ + if(map2 == null){ + return; + } + Object.keys(map2).forEach(key => { + if(map1.hasOwnProperty(key)){ + map1[key] = mergeObjects(map1[key], map2[key]); + } else { + map1[key] = map2[key]; + } + }); + } + + function mergeObjects(obj1, obj2){ + const result = {}; + Object.keys(obj1).forEach(key => result[key] = (obj2.hasOwnProperty(key))? obj2[key] : obj1[key]); + return result; + } + + const row_type_overide = date_formatter.defaultRowTypes(); + mergeMaps(row_types,row_type_overide); + mergeMaps(row_types,settings.row_types); + var row_defs = (settings.row_defs != null && settings.row_defs.length > 0)? + settings.row_defs : date_formatter.defaultRowDefs(); + + var heights = { + vvsmall: [15,13], + vsmall: [20,15], + ssmall: [22,17], + small: [25,20], + msmall: [29,22], + medium: [40,25], + mlarge: [45,35], + large: [50,40], + vlarge: [60,50], + slarge: [110,90] + }; + + var rotations = { + 0: 0, + 90: 3, + 180: 2, + 270: 1, + }; + + var speeds = { + fast: 20, + medium: 10, + slow: 5, + vslow: 2, + superslow: 1 + }; + + function create_row_type(row_type, row_def){ + const speed = speeds[row_type.speed]; + const rotation = rotations[row_type.angle_to_horizontal]; + const height = heights[row_type.size]; + const scroll_ins = []; + if(row_type.scroll_in.includes('left')){ + scroll_ins.push((row_display,txt)=> row_display.scrollInFromLeft(txt)); + } + if(row_type.scroll_in.includes('right')){ + scroll_ins.push((row_display,txt)=> row_display.scrollInFromRight(txt)); + } + if(row_type.scroll_in.includes('up')){ + scroll_ins.push((row_display,txt)=> row_display.scrollInFromBottom(txt)); + } + var scroll_in; + if(scroll_ins.length === 0){ + scroll_in = (row_display,txt)=> row_display.scrollInFromLeft(txt); + } else if(scroll_ins.length === 1){ + scroll_in = scroll_ins[0]; + } else { + scroll_in = (row_display,txt) =>{ + const idx = (Math.random() * scroll_ins.length) | 0; + return scroll_ins[idx](row_display,txt); + }; + } + + const scroll_offs = []; + if(row_type.scroll_off.includes('left')){ + scroll_offs.push((row_display)=> row_display.scrollOffToLeft()); + } + if(row_type.scroll_off.includes('right')){ + scroll_offs.push((row_display)=> row_display.scrollOffToRight()); + } + if(row_type.scroll_off.includes('down')){ + scroll_offs.push((row_display)=> row_display.scrollOffToBottom()); + } + var scroll_off; + if(scroll_offs.length === 0){ + scroll_off = (row_display)=> row_display.scrollOffToLeft(); + } else if(scroll_offs.length === 1){ + scroll_off = scroll_offs[0]; + } else { + scroll_off = (row_display) =>{ + var idx = (Math.random() * scroll_off.length) | 0; + return scroll_offs[idx](row_display); + }; + } + + var text_formatter = (txt)=>txt; + const SPACES = ' '; + if(row_def.hasOwnProperty("alignment")){ + const alignment = row_def.alignment; + if(alignment.startsWith("centre")){ + const padding = parseInt(alignment.split("-")[1]); + if(padding > 0){ + text_formatter = (txt) => { + const front_spaces = (padding - txt.length)/2 | 0; + return front_spaces > 0? SPACES.substring(0,front_spaces + 1) + txt : txt; + }; + } + } + } + + const version = bangleVersion() - 1; + const Y_RESERVED = 20; + return { + row_speed: speed, + row_height: height[version], + row_rotation: rotation, + x: (row_no) => row_def.init_coords[0] * g.getWidth() + row_def.row_direction[0] * height[version] * row_no, + y: (row_no) => Y_RESERVED + row_def.init_coords[1] * (g.getHeight() - Y_RESERVED) + row_def.row_direction[1] * height[version] * row_no, + scroll_in: scroll_in, + scroll_off: scroll_off, + fg_color: () => (row_type.color === 'major')? main_color(): other_color(), + row_text_formatter : text_formatter + }; + } + row_displays = []; + row_defs.forEach(row_def =>{ + const row_type = create_row_type(row_types[row_def.type],row_def); + // we now create the number of rows specified of that type + for(var row_no=0; row_no200) - setRowDisplays(50, [40,30,30,30,40]); -else - setRowDisplays(34, [35,25,25,25,35]); function nextColorTheme(){ - //console.log("next color theme"); color_scheme_index += 1; - if(color_scheme_index >= row_displays.length){ + if(color_scheme_index >= color_schemes.length){ color_scheme_index = 0; } - setColorScheme(color_schemes[color_scheme_index]); - reset_clock(true); - draw_clock(); + updateColorScheme(); + resetClock(true); + drawClock(); } -function setColorScheme(color_scheme){ - setColor(color_scheme.main_bar, - color_scheme.other_bars, - color_scheme.background); -} - -function setColor(main_color,other_color,bg_color){ - row_displays[0].setColor(main_color); - row_displays[0].setBgColor(bg_color); - for(var i=1; i= date_formatters.length){ - date_formatter_idx = 0; - } - console.log("changing to formatter " + date_formatter_idx); - date_formatter = date_formatters[date_formatter_idx]; - reset_clock(true); - draw_clock(); - command_stack_high_priority.unshift( - function() { - //console.log("move in new:" + txt); - // first select the top or bottom to display the formatter name - // We choose the first spare row without text - var format_name_display = row_displays[row_displays.length - 1]; - if (format_name_display.txt != '') { - format_name_display = row_displays[0]; - } - if (format_name_display.txt != ''){ - return; - } - format_name_display.speed_x = 3; - format_name_display.onFinished(function(){ - format_name_display.speed_x = CLOCK_TEXT_SPEED_X; - console.log("return speed to:" + format_name_display.speed_x) - next_command(); - }); - format_name_display.setTextXPosition(date_formatter.name(),220); - format_name_display.moveToX(-date_formatter.name().length * format_name_display.font_size); - } - ); - -} - -var DISPLAY_TEXT_X = 20; -function reset_clock(hard_reset){ +function resetClock(hard_reset){ console.log("reset_clock hard_reset:" + hard_reset); - setColorScheme(color_schemes[color_scheme_index]); + updateColorScheme(); if(!hard_reset && last_draw_time != null){ // If its not a hard reset then we want to reset the // rows set to the last time. If the last time is too long @@ -356,15 +490,14 @@ function reset_clock(hard_reset){ // In this way the watch wakes by scrolling // off the last time and scroll on the new time var reset_time = last_draw_time; - var last_minute_millis = Date.now() - 60000; + const last_minute_millis = Date.now() - 60000; if(reset_time.getTime() < last_minute_millis){ reset_time = display_time(new Date(last_minute_millis)); } - var rows = date_formatter.formatDate(reset_time); + const rows = date_formatter.formatDate(reset_time); for (var i = 0; i < rows.length; i++) { row_displays[i].hide(); - row_displays[i].speed_x = CLOCK_TEXT_SPEED_X; - row_displays[i].x = DISPLAY_TEXT_X; + row_displays[i].x = row_displays[i].init_x; row_displays[i].y = row_displays[i].init_y; if(row_displays[i].timeoutId != null){ clearTimeout(row_displays[i].timeoutId); @@ -374,12 +507,8 @@ function reset_clock(hard_reset){ } } else { // do a hard reset and clear everything out - for (var i = 0; i < row_displays.length; i++) { - row_displays[i].speed_x = CLOCK_TEXT_SPEED_X; - row_displays[i].reset(hard_reset); - } + row_displays.forEach(row_display => row_display.reset(hard_reset)); } - reset_commands(); } @@ -395,13 +524,13 @@ function display_time(date){ } } -function draw_clock(){ +function drawClock(){ var date = new Date(); // we don't want the time to be displayed // and then immediately be trigger another time if(last_draw_time != null && - Date.now() - last_draw_time.getTime() < next_minute_boundary_secs * 1000 && + date.getTime() - last_draw_time.getTime() < next_minute_boundary_secs * 1000 && has_commands() ){ console.log("skipping draw clock"); return; @@ -410,66 +539,54 @@ function draw_clock(){ } reset_commands(); date = display_time(date); - console.log("draw_clock:" + last_draw_time.toISOString() + " display:" + date.toISOString()); - // for debugging only - //date.setMinutes(37); - var rows = date_formatter.formatDate(date); - var display; + const mem = process.memory(false); + console.log("draw_clock:" + last_draw_time.toISOString() + " display:" + date.toISOString() + + " memory:" + mem.usage / mem.total); + + const rows = date_formatter.formatDate(date); for (var i = 0; i < rows.length; i++) { - display = row_displays[i]; - var txt = rows[i]; - //console.log(i + "->" + txt); - display_row(display,txt); + const display = row_displays[i]; + if(display != null){ + const txt = display.getRowContext().row_text_formatter(rows[i]); + display_row(display,txt); + } } // If the dateformatter has not returned enough - // rows then treat the reamining rows as empty + // rows then treat the remaining rows as empty for (var j = i; j < row_displays.length; j++) { - display = row_displays[j]; - //console.log(i + "->''(empty)"); + const display = row_displays[j]; display_row(display,''); } next_command(); - //console.log(date); } function display_row(display,txt){ if(display == null) { - console.log("no display for text:" + txt) return; } - if(display.txt == null || display.txt == ''){ - if(txt != '') { - command_stack_high_priority.unshift( - function () { - //console.log("move in new:" + txt); + if(display.txt == null || display.txt === ''){ + if(txt !== '') { + command_stack_high_priority.unshift(()=>{ display.onFinished(next_command); - display.setTextXPosition(txt, 240); - display.moveToX(DISPLAY_TEXT_X); + display.getRowContext().scroll_in(display,txt); } ); } - } else if(txt != display.txt && display.txt != null){ - command_stack_high_priority.push( - function(){ - //console.log("move out:" + txt); + } else if(txt !== display.txt && display.txt != null){ + command_stack_high_priority.push(()=>{ display.onFinished(next_command); - display.moveToX(-display.txt.length * display.font_size); + display.getRowContext().scroll_off(display); } ); - command_stack_low_priority.push( - function(){ - //console.log("move in:" + txt); + command_stack_low_priority.push(() => { display.onFinished(next_command); - display.setTextXPosition(txt,240); - display.moveToX(DISPLAY_TEXT_X); + display.getRowContext().scroll_in(display,txt); } ); } else { - command_stack_high_priority.push( - function(){ - //console.log("move in2:" + txt); - display.setTextXPosition(txt,DISPLAY_TEXT_X); + command_stack_high_priority.push(() => { + display.setTextPosition(txt,display.init_x, display.init_y); next_command(); } ); @@ -480,80 +597,139 @@ function display_row(display,txt){ * called from load_settings on startup to * set the color scheme to named value */ -function set_colorscheme(colorscheme_name){ +function setColorScheme(colorscheme_name){ console.log("setting color scheme:" + colorscheme_name); for (var i=0; i < color_schemes.length; i++) { - if(color_schemes[i].name == colorscheme_name){ + if(color_schemes[i].name === colorscheme_name){ color_scheme_index = i; - console.log("match"); - setColorScheme(color_schemes[color_scheme_index]); + updateColorScheme(); break; } } } -function set_dateformat(dateformat_name){ - console.log("setting date format:" + dateformat_name); - for (var i=0; i < date_formatters.length; i++) { - if(date_formatters[i].name() == dateformat_name){ - date_formatter_idx = i; - date_formatter = date_formatters[date_formatter_idx]; - console.log("match"); +var date_formatter; +function setDateformat(shortname){ + /** + * Demonstration Date formatter so that we can see the + * clock working in the emulator + */ + class DigitDateTimeFormatter { + constructor() {} + + format00(num){ + const value = (num | 0); + if(value > 99 || value < 0) + throw "must be between in range 0-99"; + if(value < 10) + return "0" + value.toString(); + else + return value.toString(); } + + formatDate(now){ + const hours = now.getHours() ; + const time_txt = this.format00(hours) + ":" + this.format00(now.getMinutes()); + const date_txt = require('locale').dow(now,1) + " " + this.format00(now.getDate()); + const month_txt = require('locale').month(now); + return [time_txt, date_txt, month_txt]; + } + + defaultRowTypes(){ + return { + large: { + scroll_off: ['left', 'right', 'down'], + scroll_in: ['left', 'right', 'up'], + size: 'vlarge' + }, + small: { + angle_to_horizontal: 90, + scroll_off: ['down'], + scroll_in: ['up'], + size: 'vvsmall' + } + }; + } + + defaultRowDefs() { + return [ + { + type: 'large', + row_direction: [0.0,1.0], + init_coords: [0.1,0.35], + rows: 1 + }, + { + type: 'small', + row_direction: [1.0,0], + init_coords: [0.85,0.99], + rows: 2 + } + ]; + } + } + console.log("setting date format:" + shortname); + try { + if (date_formatter == null) { + if(shortname === "default"){ + date_formatter = new DigitDateTimeFormatter(); + } else { + const date_formatter_class = require("slidingtext.locale." + shortname + ".js"); + date_formatter = new date_formatter_class(); + } + } + } catch(e){ + console.log("not loaded:" + shortname); + } + if(date_formatter == null){ + date_formatter = new DigitDateTimeFormatter(); } } +var enable_live_controls = false; const PREFERENCE_FILE = "slidingtext.settings.json"; /** * Called on startup to set the watch to the last preference settings */ -function load_settings(){ - var setScheme = false; - try{ - settings = require("Storage").readJSON(PREFERENCE_FILE); - if(settings != null){ - console.log("loaded:" + JSON.stringify(settings)); - if(settings.color_scheme != null){ - set_colorscheme(settings.color_scheme); - setScheme = true; - } - if(settings.date_format != null){ - set_dateformat(settings.date_format); - } - } else { - console.log("no settings to load"); +function loadSettings() { + try { + const settings = Object.assign({}, + require('Storage').readJSON(PREFERENCE_FILE, true) || {}); + if (settings.date_formatter == null) { + settings.date_formatter = "en"; } - } catch(e){ + console.log("loaded settings:" + JSON.stringify(settings)); + setDateformat(settings.date_formatter); + initDisplay(settings); + if (settings.color_scheme != null) { + setColorScheme(settings.color_scheme); + } else { + setColorScheme("black"); + } + if (settings.enable_live_controls == null) { + settings.enable_live_controls = (bangleVersion() <= 1); + } + enable_live_controls = settings.enable_live_controls; + console.log("enable_live_controls=" + enable_live_controls); + } catch (e) { console.log("failed to load settings:" + e); } // just set up as default - if (!setScheme) - setColorScheme(color_schemes[color_scheme_index]); -} - -/** - * Called on button press to save down the last preference settings - */ -function save_settings(){ - var settings = { - date_format : date_formatter.name(), - color_scheme : color_schemes[color_scheme_index].name, - }; - console.log("saving:" + JSON.stringify(settings)); - require("Storage").writeJSON(PREFERENCE_FILE,settings); -} - -function button1pressed() { - changeFormatter(); - save_settings(); + if (row_displays === undefined) { + setDateformat("default"); + initDisplay(); + updateColorScheme(); + } + const mem = process.memory(true); + console.log("init complete memory:" + mem.usage / mem.total); } function button3pressed() { - console.log("button3pressed"); - nextColorTheme(); - reset_clock(true); - draw_clock(); - save_settings(); + if (enable_live_controls) { + nextColorTheme(); + resetClock(true); + drawClock(); + } } // The interval reference for updating the clock @@ -567,12 +743,11 @@ function clearTimers(){ } function startTimers(){ - var date = new Date(); - var secs = date.getSeconds(); - var nextMinuteStart = 60 - secs; - //console.log("scheduling clock draw in " + nextMinuteStart + " seconds"); + const date = new Date(); + const secs = date.getSeconds(); + const nextMinuteStart = 60 - secs; setTimeout(scheduleDrawClock,nextMinuteStart * 1000); - draw_clock(); + drawClock(); } /** @@ -591,17 +766,17 @@ function scheduleDrawClock(){ if (Bangle.isLCDOn()) { console.log("schedule draw of clock"); intervalRef = setInterval(() => { - if (!shouldRedraw()) { - console.log("draw clock callback - skipped redraw"); - } else { - console.log("draw clock callback"); - draw_clock() - } - }, 60 * 1000 + if (!shouldRedraw()) { + console.log("draw clock callback - skipped redraw"); + } else { + console.log("draw clock callback"); + drawClock(); + } + }, 60 * 1000 ); if (shouldRedraw()) { - draw_clock(); + drawClock(); } else { console.log("scheduleDrawClock - skipped redraw"); } @@ -614,23 +789,23 @@ Bangle.on('lcdPower', (on) => { if (on) { console.log("lcdPower: on"); Bangle.drawWidgets(); - reset_clock(false); + resetClock(false); startTimers(); } else { console.log("lcdPower: off"); - reset_clock(false); + resetClock(false); clearTimers(); } }); g.clear(); -load_settings(); +loadSettings(); +// Show launcher when button pressed +Bangle.setUI("clockupdown", d=>{ + if (d>0) button3pressed(); +}); Bangle.loadWidgets(); Bangle.drawWidgets(); startTimers(); -// Show launcher when button pressed -Bangle.setUI("clockupdown", d=>{ - if (d<0) button1pressed(); - if (d>0) button3pressed(); -}); + diff --git a/apps/slidingtext/slidingtext.locale.de.js b/apps/slidingtext/slidingtext.locale.de.js index 3cb178232..7be61e965 100644 --- a/apps/slidingtext/slidingtext.locale.de.js +++ b/apps/slidingtext/slidingtext.locale.de.js @@ -1,94 +1,43 @@ -var DateFormatter = require("slidingtext.dtfmt.js"); - -const germanNumberStr = [ ["NULL",""], // 0 - ["EINS",""], // 1 - ["ZWEI",""], //2 - ["DREI",''], //3 - ["VIER",''], //4 - ["FÜNF",''], //5 - ["SECHS",''], //6 - ["SIEBEN",''], //7 - ["ACHT",''], //8 - ["NEUN",''], // 9, - ["ZEHN",''], // 10 - ["ELF",''], // 11, - ["ZWÖLF",''], // 12 - ["DREI",'ZEHN'], // 13 - ["VIER",'ZEHN'], // 14 - ["FÜNF",'ZEHN'], // 15 - ["SECH",'ZEHN'], // 16 - ["SIEB",'ZEHN'], // 17 - ["ACHT",'ZEHN'], // 18 - ["NEUN",'ZEHN'], // 19 -]; - -const germanTensStr = ["NULL",//0 - "ZEHN",//10 - "ZWANZIG",//20 - "DREIßIG",//30 - "VIERZIG",//40 - "FÜNFZIG",//50 - "SECHZIG"//60 -] - -const germanUnit = ["",//0 - "EINUND",//1 - "ZWEIUND",//2 - "DREIUND",//3 - "VIERUND", //4 - "FÜNFUND", //5 - "SECHSUND", //6 - "SIEBENUND", //7 - "ACHTUND", //8 - "NEUNUND" //9 -] - -function germanHoursToText(hours){ - hours = hours % 12; - if(hours == 0){ - hours = 12; - } - return germanNumberStr[hours][0]; -} - -function germanMinsToText(mins) { - if (mins < 20) { - return germanNumberStr[mins]; - } else { - var tens = (mins / 10 | 0); - var word1 = germanTensStr[tens]; - var remainder = mins - tens * 10; - var word2 = germanUnit[remainder]; - return [word2, word1]; - } -} +const DateFormatter = require("slidingtext.dtfmt.js"); +const germanHoursToText = require("slidingtext.utils.de.js").germanHoursToText; +const germanMinsToText = require("slidingtext.utils.de.js").germanMinsToText; +/** + * German 12 hour clock + */ class GermanDateFormatter extends DateFormatter { - constructor() { super();} - name(){return "German";} + constructor() { + super(); + } formatDate(date){ - var mins = date.getMinutes(); - var hourOfDay = date.getHours(); - var hours = germanHoursToText(hourOfDay); - //console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours) - // Deal with the special times first - if(mins == 0){ - var hours = germanHoursToText(hourOfDay); + const mins = date.getMinutes(); + const hourOfDay = date.getHours(); + const hours = germanHoursToText(hourOfDay); + if(mins === 0){ return [hours,"UHR", "","",""]; - } /*else if(mins == 30){ - var hours = germanHoursToText(hourOfDay+1); - return ["", "", "HALB","", hours]; - } else if(mins == 15){ - var hours = germanHoursToText(hourOfDay); - return ["", "", "VIERTEL", "NACH",hours]; - } else if(mins == 45) { - var hours = germanHoursToText(hourOfDay+1); - return ["", "", "VIERTEL", "VOR",hours]; - } */ else { - var mins_txt = germanMinsToText(mins); + } else { + const mins_txt = germanMinsToText(mins); return [hours, "UHR", mins_txt[0],mins_txt[1]]; } } + defaultRowTypes(){ return {};} + + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'medium', + init_coords: [0.05,0.4], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } } module.exports = GermanDateFormatter; diff --git a/apps/slidingtext/slidingtext.locale.de2.js b/apps/slidingtext/slidingtext.locale.de2.js new file mode 100644 index 000000000..a4c8c2fa6 --- /dev/null +++ b/apps/slidingtext/slidingtext.locale.de2.js @@ -0,0 +1,49 @@ +const DateFormatter = require("slidingtext.dtfmt.js"); +const german24HoursToText = require("slidingtext.utils.de.js").german24HoursToText; +const germanMinsToText = require("slidingtext.utils.de.js").germanMinsToText; + +/** + * German 24 hour clock + */ +class German24HourDateFormatter extends DateFormatter { + constructor() { + super(); + } + formatDate(date){ + const mins = date.getMinutes(); + const hourOfDay = date.getHours(); + const hours = german24HoursToText(hourOfDay); + const display_hours = (hours[1] === '')? ["", hours[0]] : hours; + if(mins === 0){ + return [display_hours[0],display_hours[1],"UHR", "","",""]; + } else { + const mins_txt = germanMinsToText(mins); + + return [display_hours[0],display_hours[1], "UHR", mins_txt[0],mins_txt[1]]; + } + } + defaultRowTypes(){ return { + large:{ + size: 'mlarge' + } + };} + + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.06], + row_direction: [0.0,1.0], + rows: 2 + }, + { + type: 'medium', + init_coords: [0.05,0.5], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } +} + +module.exports = German24HourDateFormatter; diff --git a/apps/slidingtext/slidingtext.locale.dgt.js b/apps/slidingtext/slidingtext.locale.dgt.js new file mode 100644 index 000000000..446a4cd50 --- /dev/null +++ b/apps/slidingtext/slidingtext.locale.dgt.js @@ -0,0 +1,63 @@ +const Locale = require('locale'); + +class DigitDateTimeFormatter { + constructor() {} + + format00(num){ + const value = (num | 0); + if(value > 99 || value < 0) + throw "must be between in range 0-99"; + if(value < 10) + return "0" + value.toString(); + else + return value.toString(); + } + + formatDate(now){ + const hours = now.getHours() ; + const time_txt = this.format00(hours) + ":" + this.format00(now.getMinutes()); + const date_txt = Locale.dow(now,1) + " " + this.format00(now.getDate()); + return [time_txt[0], time_txt[1],time_txt[2], time_txt[3],time_txt[4],date_txt]; + } + + defaultRowTypes(){ + return { + large: { + scroll_off: ['down'], + scroll_in: ['up'], + size: 'vlarge', + speed: 'medium' + }, + small: { + angle_to_horizontal: 0, + scroll_off: ['left'], + scroll_in: ['right'], + } + }; + } + + defaultRowDefs() { + return [ + { + type: 'large', + row_direction: [0.7,0.0], + init_coords: [0.1,0.35], + rows: 3 + }, + { + type: 'large', + row_direction: [0.7,0.0], + init_coords: [0.6,0.35], + rows: 2 + }, + { + type: 'small', + row_direction: [0.0,1.0], + init_coords: [0.1,0.05], + rows: 1 + } + ]; + } +} + +module.exports = DigitDateTimeFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.locale.en.js b/apps/slidingtext/slidingtext.locale.en.js index 7d37fcae1..545cc9f09 100644 --- a/apps/slidingtext/slidingtext.locale.en.js +++ b/apps/slidingtext/slidingtext.locale.en.js @@ -1,14 +1,55 @@ -var DateFormatter = require("slidingtext.dtfmt.js"); +const DateFormatter = require("slidingtext.dtfmt.js"); const hoursToText = require("slidingtext.utils.en.js").hoursToText; const numberToText = require("slidingtext.utils.en.js").numberToText; +const dayOfWeek = require("slidingtext.utils.en.js").dayOfWeek; +const numberToDayNumberText = require("slidingtext.utils.en.js").numberToDayNumberText; +const monthToText = require("slidingtext.utils.en.js").monthToText; class EnglishDateFormatter extends DateFormatter { - constructor() { super();} - name(){return "English";} + constructor() { + super(); + } formatDate(date){ - var hours_txt = hoursToText(date.getHours()); - var mins_txt = numberToText(date.getMinutes()); - return [hours_txt,mins_txt[0],mins_txt[1]]; + const hours_txt = hoursToText(date.getHours()); + const mins_txt = numberToText(date.getMinutes()); + const day_of_week = dayOfWeek(date); + const date_txt = numberToDayNumberText(date.getDate()).join(' '); + const month = monthToText(date); + return [hours_txt,mins_txt[0],mins_txt[1],day_of_week,date_txt,month]; + } + defaultRowTypes() { + return { + small: {size: 'ssmall'} + }; + } + + defaultRowDefs(){ + const row_defs = [ + { + type: 'large', + init_coords: [0.05,0.07], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'medium', + init_coords: [0.05,0.31], + row_direction: [0.0,1.0], + rows: 2 + } + ]; + const bangleVersion = (g.getHeight()>200)? 1 : 2; + if(bangleVersion > 1){ + row_defs.push( + { + type: 'small', + init_coords: [0.05,0.75], + row_direction: [0.0,1.0], + rows: 2 + } + ) + } + return row_defs; } } diff --git a/apps/slidingtext/slidingtext.locale.en2.js b/apps/slidingtext/slidingtext.locale.en2.js index cd07e8848..ac2ae02ff 100644 --- a/apps/slidingtext/slidingtext.locale.en2.js +++ b/apps/slidingtext/slidingtext.locale.en2.js @@ -1,4 +1,6 @@ -var DateFormatter = require("slidingtext.dtfmt.js"); +const DateFormatter = require("slidingtext.dtfmt.js"); +const dayOfWeekShort = require("slidingtext.utils.en.js").dayOfWeekShort; +const numberToDayNumberText = require("slidingtext.utils.en.js").numberToDayNumberText; const hoursToText = require("slidingtext.utils.en.js").hoursToText; const numberToText = require("slidingtext.utils.en.js").numberToText; @@ -6,23 +8,24 @@ class EnglishTraditionalDateFormatter extends DateFormatter { constructor() { super(); } - name(){return "English (Traditional)";} formatDate(date){ - var mins = date.getMinutes(); + const day_of_week = dayOfWeekShort(date); + const date_txt = numberToDayNumberText(date.getDate()).join(' '); + const mins = date.getMinutes(); var hourOfDay = date.getHours(); if(mins > 30){ hourOfDay += 1; } - var hours = hoursToText(hourOfDay); + const hours = hoursToText(hourOfDay); // Deal with the special times first - if(mins == 0){ - return [hours,"", "O'","CLOCK"]; - } else if(mins == 30){ - return ["","HALF", "PAST", "", hours]; - } else if(mins == 15){ - return ["","QUARTER", "PAST", "", hours]; - } else if(mins == 45) { - return ["", "QUARTER", "TO", "", hours]; + if(mins === 0){ + return [hours,"", "O'","CLOCK","", day_of_week, date_txt]; + } else if(mins === 30){ + return ["","HALF", "PAST", "", hours, day_of_week, date_txt]; + } else if(mins === 15){ + return ["","QUARTER", "PAST", "", hours, day_of_week, date_txt]; + } else if(mins === 45) { + return ["", "QUARTER", "TO", "", hours, day_of_week, date_txt]; } var mins_txt; var from_to; @@ -36,18 +39,57 @@ class EnglishTraditionalDateFormatter extends DateFormatter { from_to = "PAST"; mins_txt = numberToText(mins_value); } - if(mins_txt[1] != '') { - return ['', mins_txt[0], mins_txt[1], from_to, hours]; + + if(mins_txt[1] !== '') { + return ['', mins_txt[0], mins_txt[1], from_to, hours, day_of_week, date_txt]; } else { - if(mins_value % 5 == 0) { - return ['', mins_txt[0], from_to, '', hours]; - } else if(mins_value == 1){ - return ['', mins_txt[0], 'MINUTE', from_to, hours]; + if(mins_value % 5 === 0) { + return ['', mins_txt[0], from_to, '', hours, day_of_week, date_txt]; + } else if(mins_value === 1){ + return ['', mins_txt[0], 'MINUTE', from_to, hours, day_of_week, date_txt]; } else { - return ['', mins_txt[0], 'MINUTES', from_to, hours]; + return ['', mins_txt[0], 'MINUTES', from_to, hours, day_of_week, date_txt]; } } } + defaultRowTypes(){ + return { + small: { + speed: 'medium', + scroll_off: ['left','right'], + scroll_in: ['left','right'], + }, + large: { + speed: 'medium', + color: 'major', + scroll_off: ['left','right'], + scroll_in: ['left','right'] + } + }; + } + + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'small', + init_coords: [0.05,0.35], + row_direction: [0.0,1.0], + rows: 3 + }, + { + type: 'large', + init_coords: [0.05,0.75], + row_direction: [0.0,1.0], + rows: 1 + } + ]; + } } module.exports = EnglishTraditionalDateFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.locale.es.js b/apps/slidingtext/slidingtext.locale.es.js index 1b6f6d11b..041497e04 100644 --- a/apps/slidingtext/slidingtext.locale.es.js +++ b/apps/slidingtext/slidingtext.locale.es.js @@ -34,7 +34,7 @@ const spanishNumberStr = [ ["ZERO"], // 0 function spanishHoursToText(hours){ hours = hours % 12; - if(hours == 0){ + if(hours === 0){ hours = 12; } return spanishNumberStr[hours][0]; @@ -45,33 +45,52 @@ function spanishMinsToText(mins){ } class SpanishDateFormatter extends DateFormatter { - constructor() { super();} - name(){return "Spanish";} + constructor() { + super(); + } formatDate(date){ - var mins = date.getMinutes(); + const mins = date.getMinutes(); var hourOfDay = date.getHours(); if(mins > 30){ hourOfDay += 1; } - var hours = spanishHoursToText(hourOfDay); + const hours = spanishHoursToText(hourOfDay); //console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours) // Deal with the special times first - if(mins == 0){ + if(mins === 0){ return [hours,"", "","",""]; - } else if(mins == 30){ + } else if(mins === 30){ return [hours, "Y", "MEDIA",""]; - } else if(mins == 15){ + } else if(mins === 15){ return [hours, "Y", "CUARTO",""]; - } else if(mins == 45) { + } else if(mins === 45) { return [hours, "MENOS", "CUARTO",""]; } else if(mins > 30){ - var mins_txt = spanishMinsToText(60-mins); + const mins_txt = spanishMinsToText(60-mins); return [hours, "MENOS", mins_txt[0],mins_txt[1]]; } else { - var mins_txt = spanishMinsToText(mins); + const mins_txt = spanishMinsToText(mins); return [hours, "Y", mins_txt[0],mins_txt[1]]; } } + defaultRowTypes(){ return {};} + + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'medium', + init_coords: [0.05,0.4], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } } module.exports = SpanishDateFormatter; diff --git a/apps/slidingtext/slidingtext.locale.fr.js b/apps/slidingtext/slidingtext.locale.fr.js index 5844c1a4e..6da0e232d 100644 --- a/apps/slidingtext/slidingtext.locale.fr.js +++ b/apps/slidingtext/slidingtext.locale.fr.js @@ -14,14 +14,14 @@ const frenchNumberStr = [ "ZERO", "UNE", "DEUX", "TROIS", "QUATRE", function frenchHoursToText(hours){ hours = hours % 12; - if(hours == 0){ + if(hours === 0){ hours = 12; } return frenchNumberStr[hours]; } function frenchHeures(hours){ - if(hours % 12 == 1){ + if(hours % 12 === 1){ return 'HEURE'; } else { return 'HEURES'; @@ -29,32 +29,33 @@ function frenchHeures(hours){ } class FrenchDateFormatter extends DateFormatter { - constructor() { super(); } - name(){return "French";} + constructor() { + super(); + } formatDate(date){ var hours = frenchHoursToText(date.getHours()); var heures = frenchHeures(date.getHours()); - var mins = date.getMinutes(); - if(mins == 0){ - if(hours == 0){ + const mins = date.getMinutes(); + if(mins === 0){ + if(hours === 0){ return ["MINUIT", "",""]; - } else if(hours == 12){ + } else if(hours === 12){ return ["MIDI", "",""]; } else { return [hours, heures,""]; } - } else if(mins == 30){ + } else if(mins === 30){ return [hours, heures,'ET DEMIE']; - } else if(mins == 15){ + } else if(mins === 15){ return [hours, heures,'ET QUART']; - } else if(mins == 45){ + } else if(mins === 45){ var next_hour = date.getHours() + 1; hours = frenchHoursToText(next_hour); heures = frenchHeures(next_hour); return [hours, heures,"MOINS",'LET QUART']; } if(mins > 30){ - var to_mins = 60-mins; + const to_mins = 60-mins; var mins_txt = frenchNumberStr[to_mins]; next_hour = date.getHours() + 1; hours = frenchHoursToText(next_hour); @@ -65,6 +66,30 @@ class FrenchDateFormatter extends DateFormatter { return [ hours, heures , mins_txt ]; } } + defaultRowTypes(){ + return { + small: { + speed: 'vslow' + } + }; + } + + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'small', + init_coords: [0.05,0.4], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } } module.exports = FrenchDateFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.locale.hyb.js b/apps/slidingtext/slidingtext.locale.hyb.js new file mode 100644 index 000000000..aa47b349f --- /dev/null +++ b/apps/slidingtext/slidingtext.locale.hyb.js @@ -0,0 +1,80 @@ +const DateFormatter = require("slidingtext.dtfmt.js"); +const numberToText = require("slidingtext.utils.en.js").numberToText; +const dayOfWeek = require("slidingtext.utils.en.js").dayOfWeekShort; + +class EnglishDateFormatter extends DateFormatter { + constructor() { + super(); + } + + format00(num){ + const value = (num | 0); + if(value > 99 || value < 0) + throw "must be between in range 0-99"; + if(value < 10) + return "0" + value.toString(); + else + return value.toString(); + } + + formatDate(date){ + + const hours_txt = this.format00(date.getHours()); + const mins_txt = numberToText(date.getMinutes()); + const day_of_week = dayOfWeek(date); + const date_txt = day_of_week + " " + this.format00(date.getDate()); + return [hours_txt,mins_txt[0],mins_txt[1],date_txt]; + } + defaultRowTypes() { + return { + large: { + size: 'slarge', + scroll_off: ['left','down'], + scroll_in: ['up','left'], + }, + medium: { + size: 'msmall', + scroll_off: ['down'], + scroll_in: ['up'], + angle_to_horizontal: 90 + }, + small: { + size: 'ssmall', + scroll_off: ['left'], + scroll_in: ['left'], + } + }; + } + + defaultRowDefs(){ + const row_defs = [ + { + type: 'large', + init_coords: [0.05,0.35], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'medium', + init_coords: [0.68,0.95], + row_direction: [1.0,0.0], + angle_to_horizontal: 90, + rows: 2 + }]; + + const bangleVersion = (g.getHeight()>200)? 1 : 2; + if(bangleVersion > 1){ + row_defs.push( + { + type: 'small', + init_coords: [0.05, 0.1], + row_direction: [0.0, 1.0], + rows: 1 + } + ) + } + return row_defs; + } +} + +module.exports = EnglishDateFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.locale.jp.js b/apps/slidingtext/slidingtext.locale.jp.js index c28780e88..b2f9106a2 100644 --- a/apps/slidingtext/slidingtext.locale.jp.js +++ b/apps/slidingtext/slidingtext.locale.jp.js @@ -1,4 +1,4 @@ -var DateFormatter = require("slidingtext.dtfmt.js"); +const DateFormatter = require("slidingtext.dtfmt.js"); /** * Japanese date formatting @@ -28,21 +28,21 @@ const japaneseMinuteStr = [ ["", "PUN"], function japaneseHoursToText(hours){ hours = hours % 12; - if(hours == 0){ + if(hours === 0){ hours = 12; } return japaneseHourStr[hours]; } function japaneseMinsToText(mins){ - if(mins == 0){ + if(mins === 0){ return ["",""]; - } else if(mins == 30) + } else if(mins === 30) return ["HAN",""]; else { - var units = mins % 10; - var mins_txt = japaneseMinuteStr[units]; - var tens = mins /10 | 0; + const units = mins % 10; + const mins_txt = japaneseMinuteStr[units]; + const tens = mins /10 | 0; if(tens > 0){ var tens_txt = tensPrefixStr[tens]; var minutes_txt; @@ -59,13 +59,32 @@ function japaneseMinsToText(mins){ } class JapaneseDateFormatter extends DateFormatter { - constructor() { super(); } - name(){return "Japanese (Romanji)";} + constructor() { + super(); + } formatDate(date){ - var hours_txt = japaneseHoursToText(date.getHours()); - var mins_txt = japaneseMinsToText(date.getMinutes()); + const hours_txt = japaneseHoursToText(date.getHours()); + const mins_txt = japaneseMinsToText(date.getMinutes()); return [hours_txt,"JI", mins_txt[0], mins_txt[1] ]; } + defaultRowTypes(){ return {}; } + + defaultRowDefs(){ + return [ + { + type: 'large', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 1 + }, + { + type: 'medium', + init_coords: [0.05,0.4], + row_direction: [0.0,1.0], + rows: 3 + } + ]; + } } module.exports = JapaneseDateFormatter; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.settings.js b/apps/slidingtext/slidingtext.settings.js new file mode 100644 index 000000000..e13c857fd --- /dev/null +++ b/apps/slidingtext/slidingtext.settings.js @@ -0,0 +1,184 @@ +(function(back) { + const PREFERENCE_FILE = "slidingtext.settings.json"; + const settings = Object.assign({}, + require('Storage').readJSON(PREFERENCE_FILE, true) || {}); + const bangleVersion = (g.getHeight()>200)? 1 : 2; + // the screen controls are defaulted on for a bangle 1 and off for a bangle 2 + if(settings.enable_live_controls == null){ + settings.enable_live_controls = bangleVersion < 2; + } + console.log("loaded:" + JSON.stringify(settings)); + const locale_mappings = (bangleVersion > 1)? { + 'english' : { date_formatter: 'en' }, + 'english alt': { + date_formatter: 'en', + row_types: { + large:{ + size: 'mlarge', + angle_to_horizontal: 90, + scroll_off: ['down'], + scroll_in: ['up'], + speed: 'vslow' + }, + medium: { + size: 'msmall', + scroll_off: ['right'], + scroll_in: ['right'], + }, + small: { + scroll_off: ['right'], + scroll_in: ['right'], + } + }, + row_defs: [ + { + type: 'large', + init_coords: [0.05,0.99], + row_direction: [1.0,0.0], + alignment: 'centre-6', + rows: 1 + }, + { + type: 'medium', + init_coords: [0.26,0.1], + row_direction: [0.0,1.0], + rows: 2 + }, + { + type: 'small', + init_coords: [0.26,0.65], + row_direction: [0.0,1.0], + rows: 3 + } + ] + }, + 'english2': { date_formatter: 'en2' }, + 'english2 alt': { date_formatter: 'en2', + row_types: { + vsmall: { + color: 'minor', + speed: 'superslow', + angle_to_horizontal: 0, + scroll_off: ['left'], + scroll_in: ['left'], + size: 'ssmall' + }, + small: { + scroll_off: ['left'], + scroll_in: ['left'] + }, + large: { + size: 'mlarge', + angle_to_horizontal: 90, + color: 'major', + scroll_off: ['down'], + scroll_in: ['up'] + } + }, + row_defs: [ + { + type: 'large', + init_coords: [0.8,0.99], + row_direction: [0.0,1.0], + alignment: 'centre-6', + rows: 1 + }, + { + type: 'small', + init_coords: [0.05,0.45], + row_direction: [0.0,1.0], + rows: 3 + }, + { + type: 'large', + init_coords: [0.8,0.99], + row_direction: [0.0,1.0], + alignment: 'centre-6', + rows: 1 + }, + { + type: 'vsmall', + init_coords: [0.05,0.1], + row_direction: [0.0,1.0], + rows: 2 + }, + ] + }, + 'french': { date_formatter:'fr'}, + 'german': { date_formatter: 'de'}, + 'german 24h': { date_formatter: 'de2'}, + 'spanish': { date_formatter: 'es'}, + 'japanese': { date_formatter: 'jp'}, + 'hybrid': { date_formatter: 'hyb'}, + 'digits': { date_formatter: 'dgt'}, + } : { + 'english' : { date_formatter: 'en' }, + 'french': { date_formatter:'fr'}, + 'german': { date_formatter: 'de'}, + 'spanish': { date_formatter: 'es'}, + 'japanese': { date_formatter: 'jp'}, + 'hybrid': { date_formatter: 'hyb'}, + 'digits': { date_formatter: 'dgt'}, + } + + const locales = Object.keys(locale_mappings); + + function writeSettings() { + if(settings.date_format == null){ + settings.date_format = 'en'; + } + const styling = locale_mappings[settings.date_format]; + if(styling.date_formatter != null) + settings.date_formatter = styling.date_formatter; + + settings.row_types = {}; + if(styling.row_types != null) + settings.row_types = styling.row_types; + + settings.row_defs = []; + if(styling.row_defs != null) + settings.row_defs = styling.row_defs; + + console.log("saving:" + JSON.stringify(settings)); + + require('Storage').writeJSON(PREFERENCE_FILE, settings); + } + + // Helper method which uses int-based menu item for set of string values + function stringItems(startvalue, writer, values, value_mapping) { + return { + value: (startvalue === undefined ? 0 : values.indexOf(startvalue)), + format: v => values[v], + min: 0, + max: values.length - 1, + wrap: true, + step: 1, + onchange: v => { + const write_value = (value_mapping == null)? values[v] : value_mapping(values[v]); + writer(write_value); + writeSettings(); + } + }; + } + + // Helper method which breaks string set settings down to local settings object + function stringInSettings(name, values) { + return stringItems(settings[name], v => settings[name] = v, values); + } + + // Show the menu + E.showMenu({ + "" : { "title" : "Sliding Text" }, + "< Back" : () => back(), + "Colour": stringInSettings("color_scheme", ["black","white", "red","grey","purple","blue"]), + "Style": stringInSettings("date_format", locales, (l)=>locale_mappings[l] ), + "Live Control": { + value: (settings.enable_live_controls !== undefined ? settings.enable_live_controls : true), + format: v => v ? "On" : "Off", + onchange: v => { + settings.enable_live_controls = v; + writeSettings(); + } + }, + }); +}) \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.utils.de.js b/apps/slidingtext/slidingtext.utils.de.js new file mode 100644 index 000000000..a240f8dd8 --- /dev/null +++ b/apps/slidingtext/slidingtext.utils.de.js @@ -0,0 +1,86 @@ +const germanNumberStr = [ ["NULL",""], // 0 + ["EINS",""], // 1 + ["ZWEI",""], //2 + ["DREI",""], //3 + ["VIER",""], //4 + ["FÜNF",""], //5 + ["SECHS",""], //6 + ["SIEBEN",""], //7 + ["ACHT",""], //8 + ["NEUN",""], // 9, + ["ZEHN",""], // 10 + ["ELF",""], // 11, + ["ZWÖLF",""], // 12 + ["DREI","ZEHN"], // 13 + ["VIER","ZEHN"], // 14 + ["FÜNF","ZEHN"], // 15 + ["SECH","ZEHN"], // 16 + ["SIEB","ZEHN"], // 17 + ["ACHT","ZEHN"], // 18 + ["NEUN","ZEHN"], // 19 + ["ZWANZIG",""], // 20 + ["EIN","UNDZWANZIG"], // 21 + ["ZWEI","UNDZWANZIG"], //22 + ["DREI","UNDZWANZIG"], // 23 + ["VIER","UNDZWANZIG"] // 24 +]; + +const germanTensStr = ["NULL",//0 + "ZEHN",//10 + "ZWANZIG",//20 + "DREIßIG",//30 + "VIERZIG",//40 + "FÜNFZIG",//50 + "SECHZIG"//60 +] + +const germanUnit = ["",//0 + "EINUND",//1 + "ZWEIUND",//2 + "DREIUND",//3 + "VIERUND", //4 + "FÜNFUND", //5 + "SECHSUND", //6 + "SIEBENUND", //7 + "ACHTUND", //8 + "NEUNUND" //9 +] + +function germanHoursToText(hours){ + hours = hours % 12; + if(hours === 0){ + hours = 12; + } + if(hours === 1){ + return "EIN" + } else { + return germanNumberStr[hours][0]; + } +} +function german24HoursToText(hours){ + hours = hours % 24; + if(hours === 0){ + return hours[24] ; + } else if(hours === 1){ + return ["EIN",""]; + } else { + return germanNumberStr[hours]; + } +} + + +function germanMinsToText(mins) { + if (mins < 20) { + return germanNumberStr[mins]; + } else { + const tens = (mins / 10 | 0); + const word1 = germanTensStr[tens]; + const remainder = mins - tens * 10; + const word2 = germanUnit[remainder]; + return [word2, word1]; + } +} + +exports.germanMinsToText = germanMinsToText; +exports.germanHoursToText = germanHoursToText; +exports.german24HoursToText = german24HoursToText; \ No newline at end of file diff --git a/apps/slidingtext/slidingtext.utils.en.js b/apps/slidingtext/slidingtext.utils.en.js index a91fcbd16..a66ae456c 100644 --- a/apps/slidingtext/slidingtext.utils.en.js +++ b/apps/slidingtext/slidingtext.utils.en.js @@ -3,12 +3,26 @@ const numberStr = ["ZERO","ONE", "TWO", "THREE", "FOUR", "FIVE", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN", "TWENTY"]; -const tensStr = ["ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", - "FIFTY"]; +const tensStr = ["ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY"]; +const dayNames = ["SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"]; +const monthStr = [ + "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JULY", + "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" +] + +const dateNumberStr = ["ZEROTH", "FIRST", "SECOND", "THIRD", "FORTH", "FIFTH", + "SIXTH","SEVENTH","EIGHTH","NINTH","TENTH","ELEVENTH","TWELFTH","THIRTEENTH", + "FOURTEENTH", "FIFTEENTH", "SIXTEENTH", "SEVENTEENTH", "EIGHTEENTH", "NINETEENTH", + "TWENTIETH" +] + +const dayOfWeek = (date) => dayNames[date.getDay()]; +const dayOfWeekShort = (date) => dayNames[date.getDay()].substring(0,3); +const monthToText = (date)=>monthStr[date.getMonth()-1]; const hoursToText = (hours)=>{ hours = hours % 12; - if(hours == 0){ + if(hours === 0){ hours = 12; } return numberStr[hours]; @@ -18,9 +32,9 @@ const numberToText = (value)=> { var word1 = ''; var word2 = ''; if(value > 20){ - var tens = (value / 10 | 0); + const tens = (value / 10 | 0); word1 = tensStr[tens]; - var remainder = value - tens * 10; + const remainder = value - tens * 10; if(remainder > 0){ word2 = numberStr[remainder]; } @@ -30,5 +44,27 @@ const numberToText = (value)=> { return [word1,word2]; } +const numberToDayNumberText = (value) => { + var word1 = ''; + var word2 = ''; + if(value === 30) { + word1 = "THIRTIETH"; + } else if(value > 20){ + const tens = (value / 10 | 0); + word1 = tensStr[tens]; + const remainder = value - tens * 10; + if(remainder > 0){ + word2 = dateNumberStr[remainder]; + } + } else if(value > 0) { + word1 = dateNumberStr[value]; + } + return [word1,word2]; +} + +exports.monthToText = monthToText; exports.hoursToText = hoursToText; -exports.numberToText = numberToText; \ No newline at end of file +exports.numberToText = numberToText; +exports.numberToDayNumberText = numberToDayNumberText; +exports.dayOfWeek = dayOfWeek; +exports.dayOfWeekShort = dayOfWeekShort; \ No newline at end of file diff --git a/apps/slopeclock/ChangeLog b/apps/slopeclock/ChangeLog new file mode 100644 index 000000000..da82f6355 --- /dev/null +++ b/apps/slopeclock/ChangeLog @@ -0,0 +1,4 @@ +0.01: New App! +0.02: Reset font to save some memory during remove +0.03: Added support for locale based time +0.04: Stability improvements diff --git a/apps/slopeclock/app-icon.js b/apps/slopeclock/app-icon.js new file mode 100644 index 000000000..528758a7a --- /dev/null +++ b/apps/slopeclock/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4X/AAMfBIWSyhL/ACkD1cAlWq1WABYk6BYnABQcO1QLa3//FwgLEHIoABlQLO3WsBZHqHYwLGEooLF0ALHnW/BZMDDII8DmoLDAAILDmtVBZHV+oLEmEA1Ws6vAgNVh5EB+Eq/2lq4cCqqPBIYMqytVoALCioLD6tVBYMDqALEr4KBqotBqkAgsP/9VvkMhoLBhoLCKwQrCIoQLCBQITBM4QPB+ALBFYYLBhpHDBY0BIoILFuEPBYNcBY1XP4fAmgLENIYDBI4JGCNIlXqp3CCof/F4UPIIILEI4wtEIQVwAYIzCO4oLCSgIXFqpfCIwjTBCQXAEQgA/AAoA=")) diff --git a/apps/slopeclock/app.js b/apps/slopeclock/app.js new file mode 100644 index 000000000..2164e7ede --- /dev/null +++ b/apps/slopeclock/app.js @@ -0,0 +1,120 @@ +{ // must be inside our own scope here so that when we are unloaded everything disappears + // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global + +const fontBitmap = E.toString(require('heatshrink').decompress(atob('AH8AgP/BpcD//gBpn4Bpn+Bpn/wANMHBRTB//wBphGLBoJGLv4OBBpU/KhkfBoPABpMPMRkHMRh+CMRRwC/hwmMQQNKMQTTNBpRGCRhSpCBpY4BFJY4BBpcAjgMLAHUwBpl4BhcBd5Z/Bd5abCBpa3BTZd/YpcBcIPgBpMHBoPwIhf//BEL/5wKIgP/OBJECAAJELAAJwIIgQABOBBECOBRECOBJEEOBBEEOBBEEOBBEEOBBEEOA5EFBo5EFFI5EFKY5EGN4woGTIpEpj5EMDYzeGG4xEFgEDWZhhFbo59FfI7QFIgynGIgxwGBg5wEIhBwE+ANIOAZEIOAhEIOAgMJOAREJOAZEJOAZEJOAZEKOAQMKOAJELOAJELAAJELAH0EBhaQBSJa6BZJbkCDhMDBof4XJIADBpvAKRIqKBov+Bo0fBogqHBozpGBoyAGBoxjGBo44FBo44FMIpxHBo5xFBo7HFU4pGHBpBGEBpB/EdohGIgINHIwgNJIwgWEn4EC8ANGQ4SNHv4VEQgRUEEgQxCHwRUEYgRNDEQQNKFQRUDAwQNDQoRUDTQQUDHASpDCgR3EHAJiDCgR3ELYJiEBow/BMQgiBbQ4iFSYg/CLYZwBGAg/COAwNGOAwiDJoRwUKggNBOAwGEBoJwEcIT2GaYw4DAoINEMQQ/CHwRbEMQQHCLQTaHI4QvCNIoHCAArMEJoQAFO4gkDBpJUCAAraHBpRUDAAihEIxANFIw4NFIw7EEIxANFRo4NGcQQNKHAwNGHAwNGHAwNHHAoNHf4YNJVQqLFFQ7DEFRDtEKpHgBpCADwANIDgRSHKwvABpQA/AFp7BZwkfXIyXFVoLVFv//bArxFBoLBDga6GfgK0DHwIiEH4TrEcgw/BJogwBa4g/BJogwBEQgNGOAxNBAAwUEJoQAFOAoNHOAoNHOApbBAAxwEBpBwENIIAGOAgNIOAh3BOBYNIOAi2BOBYNIOAgNJOAbEBOBbEIOAjEIOAoNIOAioIOAiaIOAiMIOH5wLAAw/BOAgAGH4JwEAAw/CBpQ/COAYAHWAJwDAA6wBOAYAHWAJwEAAywBODIA/ABsDUBYNBOwpwGZgIcEcIwNBDggNBcIraFBoQjEbQK+DBoThEBoIqDBoThEdAJNDBoThEBpBNEewJbDBoRwEewINGOAiFBNIYNCOAgNJO5INDOAaaBAwYNDOAgGEBoZwEBpBwEVAgNDOAiMBCgQNDOAiMBCgRnCOAqMEBohwDPwgNEOAZ+EBohwDPwQGBFwJwJAwINEOAxUBLAP/+5wHIwIDC/ZwHHAInC/JwHAAn4OBAAD/g/BOAwNEHYJwGBog/BOAgiBAAf+H4JwELwQNDH4JwEMQQNDH4JwEMQv+H4QNDKgoYBOApUGJoRwDKgxNCOAZUGJoRwEIwoGCOAhGFWARwEIwoUCOAhGEBIJwGRogXCOAriEBoRwGHAZBCOAxxDBoRwGFQZrCOAxADEgRwGCwZOCOA4A/AEMBXggAISQ0AjCZFZYgjBTQt/AwqgBBoraFfozgBbQgNBGIgNGEQIGEewJVECgIGEHwJGEAxr9BKggGBewImBfoRUEAwQ7CBIJUFgINCFoIJBO4oNCwAtBBIJ3JFoIJBFoJNEEQQfBBIJNDRgwJCJoaMGBIQ/DPwgNBFoJiHRgYtBMQ4+DFoJiHHwYfBMQbFDPwoJBXww+CFoZwGHwQtDOAz2CFoZwGUIQJCTwRwGGAIJBTwRwGEQICBKAIRDOAngAQJCBJoJwGAAfhD4ZwEAAxwGBpZiBAA4NDMQIAHPwZiCAAx+DMQQNKKhKMDKhKMDKhINEKgf7BoaaDIwn5BpCpD/A8DVAhGD/g8DBooJC/g8DBoqNC/A8DWwg4DIAINIe4k/BpA0BPAI4CBowmBWAI4CBo4uFKYoAFM4KLEAAxZBWogA/ADSMBRZaaCBpTlCwANMXYIAIaQXgBpioKBoTEKaILgLBoRwKn4NBOBQNDOBINDOBN/BoRwJBoZwJBgRwKBoZwJBoZwIgILCOBINDJAJwHfQX8OQJwHBoaqBOA4NC/DUBOA8HBoQDBOA4NC+AfBOA76C8BXBOA4NDQIQNJLwJwILoINCOBANCC4JwIfQQNBOBAbCMwZwGIoQAGJAZ9CAAxIDU4QAGJAbfCAAxIEBpBIEQ4IAGXIhwCAAq5EOAQAGOH5w/OH5wvBoYAELIInEAA4ZKLIiYDAA5ZBTAYAHLIKYDAA5ZBTAgAGZQKYEAAzKBTAhwjAH4A8U4LRCh7xGS4LRCcYwGBAATDBAwLjEBojDBeILVEAwIADwA7Baoj4BAAfAcYLVECgIADGgIRCfAgAD/EAn5UFBohUIv4OEKg4iBKghNBKghwEGgJNCOBJCBD4RwIIQI/BMQZwHH4JUDOArFDOgJwHBIJiGOAQtBBoJiGSYQNBC4JiGSYTPDH4RiDGAP4Z4jFFGAImBBoY/BYoYmDEoZwIRAhwIwDrDBoJwG4AXDJoJwHRAbMCOAzICZgZwGRAXADYRwGK4X4EQLhGOAYADPwZwFcopwHcopwHBpBwEAAaMEOAoACRgjhFBo7hFAAYNDOAZiFBoZwDKgqoDOAZUFBohwCW4QNHfQYNEWwZwDCIQNHGgINBIwgNEOAIDDBo8DLAoNGAAg4DBpJxDMIgAEXAYNJFQYMJXgTtEAA8HIhIA/ACp9BN5SZD8B7JBoX+YZjSJb4f//ANMYpF/BogqHBovwBowMEKpANF/+ABpiAGBoxjGBoyrGBoxxGBo5xFBo5xFPopGHBo5/FBo5GFYYpGHBpCNEj5UMBpCNEh4ICw//g5UGA4X8AYOAHwQNG/EDBoIGCcQYJBH4IDB4EBKgoGCBoQJBQoJUDBoYDBBIJbBVIgNGHAJiEEQIUBAQQtBMQhbBBoQXBGISMFBQN/C4RiFRgIKBD4IxDYoY+BBoIfBC4IRBOAZ+CBoQJBAYJwGwAtBBIIDBOA3AFoIJBOBHgNgY/DOAiMCHYLFCOAp+CFoZwGPwQRBAwINEGAb6CAAR+DGgYtBAAZ+DGgYmCBo5iCIQQACRgZiGAASMEKgYNJKgYtBAASaEYoZiEBohUIVAhUIBoomB/BUEBopUIBoipIBogmBDYJGEBogmBO4JmCBo8/V4QNJh7nCHAYNFgxYEMIxKGBpYqCU4oAFOoLtEAA8PBhYA/AB9///AQ5jFCABEfQ47MCYAbvBXQgiEUYKxFg4iEgbNGh4UEbgRNFCgoNBH4hpBOBYUBAwhwFHwJ3FOApaBNIpwFCYJpFOAovBNIpwFBgJbFOAgECKgwUDIgQABTYhwDJQIACKghwDKQRGGOAYfBAAZwHBghUEOASXCAAaiF/xSEKgprCIgibGAwO/BopUEKApwJAAyMEGoyoGSwhvHWQqLHOARgKbgpSHfAqYGOBJSEOBAMFOAyXEOBBEGOAyXEOBBEGOAyXEOA5EHOAqXFOA5EHOAqXGOAxEIOAgMIOAZEJOAaXHMQpEJAH4AOn6QJbIaDKQgYcKUATXJVxwNCZQ8fCwIND4C4H4ANDHAzUCBoY4GBAP+MIQEBBo//4IDCOIoXD+ANDewozDBoZGFBIZXBIw4NDAAZGFBo6NFEoYAERogNIKgk/Bo5UEBpBUEj5UMh5UMBpKpDg4KFAwRUDbgP4JARCBKgrEB/AsC/BNCAYINEfYQJBCQJiEBIQpDCQJiEv4JBHAT2DRggTBQIReBWAJiDBQJlDYIIgBYoY+BwBGCLwIVBOAYYBCYJUFOAYYBCYIzBHgIVBOAoTBKgYVBOA6NCwAVBOA6zEOAwlDSIhwF4ANCEAJKBOAvwcgYNCOAv/TQQYBGILhFAAn4DYJwDHwQAGBogUBAAx+ERIQAFPwiJCAAwNDL4YNJPYQAGRgZUJRgZUJBoiKC/wNETQZGEMwiaDIwhmEBohGDMwgNFEwS7EVAiNDLAgNFDARYDBowqBWAJGDBo0DH4JYDaQgAFDZKRGBpRxCBpQqCPooAFKoLDEAA8cBhYA/ACM/8AMKcQYAJaASXKWYTdDgwNI/+AawSyHAAJHCn64FBobeCHgwND/xLCeAoNDHAIFBCIINI8BnCKZA0BQYRGEBohxBv5YDBow0Bn5UFGIRGFSIYNG4AiBKgg/CKhQNFPYJUGBohUIBohUICgIADSYSpECgJiEKgwNCKAXAKg0fCgRCCLYWAYggNBCIJiHGAYDBBoJiFGAINBEwJwBMQowCOgQtFPwh0DH4TFEJgYYBOA4XBJgIYBaYRwEHwJMBBQLTDOAYlBJgIKBPwZwFHwIKB+ANCOA5KBD4INBOAwwBTQhwGGAN/BpBiBEQM/HYINBPwhiBS4X8GAR+EMQI4BBoJvCPwiFC/kPAIINGCof//oEDRgYxCAAwNDKgQAGTQZUCBpZUCAAqoDKgYNKKggADWwapDBpZGHBopGHBopGHBoqNHBoqNHBow4GBow4GBow4GBow4GTIgACfIYNJFQrREFRD7EKo/+Bg7HE/ANJDgQ2IeYZRHAH4AmgaYDn50HRgKLCv/8BpD6CZQINIC4QNBVgy2CBoYgCIojEDBoI4GBoRQBn7yHgLuDBoJGGBoQlBj7zIBAIlBh4uDAAhBBEoJYCKgwzCwBKCHgIAEGYY8EAAgzEHgaMHGYI8DPw5wEwBwTEoJwLUgatEMQ4uDPwzhNC4RPBEAKMGC4QNBEAINHC4INBEAIpGKAQgDBo8AnASDRYoAnA='))); + +Graphics.prototype.setFontPaytoneOne = function(scale) { + // Actual height 81 (91 - 11) + this.setFontCustom( + fontBitmap, + 46, + atob("ITZOMzs7SDxHNUdGIQ=="), + 113+(scale<<8)+(1<<16) + ); + return this; +}; + +let drawTimeout; + +let g2 = Graphics.createArrayBuffer(g.getWidth(),90,1,{msb:true}); +let g2img = { + width:g2.getWidth(), height:g2.getHeight(), bpp:1, + buffer:g2.buffer, transparent:0 +}; +const slope = 20; +const offsy = 20; // offset of numbers from middle +const fontBorder = 4; // offset from left/right +const slopeBorder = 10, slopeBorderUpper = 4; // fudge-factor to move minutes down from slope +let R,x,y; // middle of the clock face +let dateStr = ""; +let bgColors = g.theme.dark ? ["#ff0","#0ff","#f0f"] : ["#f00","#0f0","#00f"]; +let bgColor = bgColors[(Math.random()*bgColors.length)|0]; + + +// Draw the hour, and the minute into an offscreen buffer +let draw = function() { + R = Bangle.appRect; + x = R.w / 2; + y = R.y + R.h / 2 - 12; // 12 = room for date + var date = new Date(); + var local_time = require("locale").time(date, 1); + var hourStr = local_time.split(":")[0].trim().padStart(2,'0'); + var minStr = local_time.split(":")[1].trim().padStart(2, '0'); + dateStr = require("locale").dow(date, 1).toUpperCase()+ " "+ + require("locale").date(date, 0).toUpperCase(); + + // Draw hour + g.reset().clearRect(R); // clear whole background (w/o widgets) + g.setFontAlign(-1, 0).setFont("PaytoneOne"); + g.drawString(hourStr, fontBorder, y-offsy).setFont("4x6"); // draw and unload custom font + // add slope in background color + g.setColor(g.theme.bg).fillPoly([0,y+slope-slopeBorderUpper, R.w,y-slope-slopeBorderUpper, + R.w,y-slope, 0,y+slope]); + // Draw minute to offscreen buffer + g2.setColor(0).fillRect(0,0,g2.getWidth(),g2.getHeight()).setFontAlign(1, 0).setFont("PaytoneOne"); + g2.setColor(1).drawString(minStr, g2.getWidth()-fontBorder, g2.getHeight()/2).setFont("4x6"); // draw and unload custom font + g2.setColor(0).fillPoly([0,0, g2.getWidth(),0, 0,slope*2]); + // start the animation *in* + animate(true); + + // queue next draw + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + animate(false, function() { + draw(); + }); + }, 60000 - (Date.now() % 60000)); +}; + +let isAnimIn = true; +let animInterval; +// Draw *just* the minute image +let drawMinute = function() { + var yo = slopeBorder + offsy + y - 2*slope*minuteX/R.w; + // draw over the slanty bit + g.setColor(bgColor).fillPoly([0,y+slope, R.w,y-slope, R.w,R.h+R.y, 0,R.h+R.y]); + // draw the minutes + g.setColor(g.theme.bg).drawImage(g2img, x+minuteX-(g2.getWidth()/2), yo-(g2.getHeight()/2)); +}; +let animate = function(isIn, callback) { + if (animInterval) clearInterval(animInterval); + isAnimIn = isIn; + minuteX = isAnimIn ? -g2.getWidth() : 0; + drawMinute(); + animInterval = setInterval(function() { + minuteX += 8; + let stop = false; + if (isAnimIn && minuteX>=0) { + minuteX=0; + stop = true; + } else if (!isAnimIn && minuteX>=R.w) + stop = true; + drawMinute(); + if (stop) { + clearInterval(animInterval); + animInterval=undefined; + if (isAnimIn) // draw the date + g.setColor(g.theme.bg).setFontAlign(0, 0).setFont("6x15").drawString(dateStr, R.x + R.w/2, R.y+R.h-9); + if (callback) callback(); + } + }, 20); +}; + + +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app + if (animInterval) clearInterval(animInterval); + animInterval = undefined; + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFontPaytoneOne; + }}); +// Load widgets +Bangle.loadWidgets(); +draw(); +setTimeout(Bangle.drawWidgets,0); +} diff --git a/apps/slopeclock/app.png b/apps/slopeclock/app.png new file mode 100644 index 000000000..d72b8faf9 Binary files /dev/null and b/apps/slopeclock/app.png differ diff --git a/apps/slopeclock/metadata.json b/apps/slopeclock/metadata.json new file mode 100644 index 000000000..d9d4d85ca --- /dev/null +++ b/apps/slopeclock/metadata.json @@ -0,0 +1,14 @@ +{ "id": "slopeclock", + "name": "Slope Clock", + "version":"0.04", + "description": "A clock where hours and minutes are divided by a sloping line. When the minute changes, the numbers slide off the screen", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock", + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"slopeclock.app.js","url":"app.js"}, + {"name":"slopeclock.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/slopeclock/screenshot.png b/apps/slopeclock/screenshot.png new file mode 100644 index 000000000..4a59f5c4a Binary files /dev/null and b/apps/slopeclock/screenshot.png differ diff --git a/apps/slopeclockpp/ChangeLog b/apps/slopeclockpp/ChangeLog new file mode 100644 index 000000000..58299b236 --- /dev/null +++ b/apps/slopeclockpp/ChangeLog @@ -0,0 +1,11 @@ +0.01: Clone of original SlopeClock +0.02: Added configuration +0.03: Reset font to save some memory during remove +0.04: Changed to use clock_info for displayed data + Made fonts smaller to avoid overlap when (eg) 22:00 + Allowed black/white background (as that can look nice too) +0.05: Images in clkinfo are optional now +0.06: Added support for locale based time +0.07: README file update as UI interaction was not easy to understand +0.08: Stability improvements - ensure we continue even if a flat string can't be allocated + Stop ClockInfo text drawing outside the allocated area diff --git a/apps/slopeclockpp/README.md b/apps/slopeclockpp/README.md new file mode 100644 index 000000000..c9e9d523d --- /dev/null +++ b/apps/slopeclockpp/README.md @@ -0,0 +1,18 @@ +# Slope Clock ++ + +A version of Slope Clock with extra information displayed on +the clock face using the clock_info module. + +## Usage + +When the screen is unlocked, tap on the information that you would like +to change (top right or bottom left). It should change color showing +it is selected. + +* Swipe up or down to cycle through the info screens that can be displayed + when you have finished tap again towards the centre of the screen to unselect. + +* Swipe left or right to change the type of info screens displayed (by default + there is only one type of data so this will have no effect) + +Settings are saved automatically and reloaded along with the clock. diff --git a/apps/slopeclockpp/app-icon.js b/apps/slopeclockpp/app-icon.js new file mode 100644 index 000000000..bd62b928d --- /dev/null +++ b/apps/slopeclockpp/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4P/AAMA/Ayq8EH8AEBgfgj4zCj/gn/8Aod//wFDvk/gEEAoP4AoMAEIP4j4FFwAFC/gFEv//ApM/74FDg4XBgZLCFIMzAoU4g8BK4dwgMP+Ewg+AgMfK4PhAoXwh+B/0Bj0B/4FBgYnB/8B/kDgf/+ED/kHn//HgIFBW4IFB/AFDgf4h4FB+EBFgLKCAoInBAAOAAoqkBAgPAWAIuBAoXAn+zCAMB4F/8YFBgYFB4YFBRgY7BYwIoCABX4zkY74FB/mMiALC/3mug6CAAgA==")) diff --git a/apps/slopeclockpp/app.js b/apps/slopeclockpp/app.js new file mode 100644 index 000000000..dca4a84e4 --- /dev/null +++ b/apps/slopeclockpp/app.js @@ -0,0 +1,168 @@ +{ // must be inside our own scope here so that when we are unloaded everything disappears + // we also define functions using 'let fn = function() {..}' for the same reason. function decls are global + +let settings = Object.assign( + require("Storage").readJSON("slopeclockpp.default.json", true) || {}, + require("Storage").readJSON("slopeclockpp.json", true) || {} +); +const fontBitmap = E.toString(require('heatshrink').decompress(atob('AFv4BZU/+ALJh//wALIgP//gYJj//8ALIgf//4YJv//HxMHDAI+JDAJkJDBgLBDBJvBDEZKYDBaVMn6VKY4P+cBfAXZQ9JEoIkKAGcDBZUBPhJkCBZU/DBSJBBZLUBDBLHMBYIYJdgIYJj4YKJAIYJHgQYIe4IYKBYYYHn4YKJAQYIQoIYJJAYYHJAgYHQoQYIJAn//iFIAAP+JBX/wBIJ//AQpAAB8BIK/CFJJAxtMDApIEDAxIFW5gYEJAoYFQooYGBYwYEJAoYFQooYFJAwYEQooYFJA4YEBZAYCQowYEJBAYCQo4YDJBIYCBZUBQo4A5WBKYDOhLWCDJE/cZUPBYT8HgYLDTY4LDGQ7VBEpIkEfw9/EpRJEEox6CJZJuDOI8HBYo+FBYo+FHow+EHoy9FHo3/4B7IK4wYHK4ZWGK4qUC/BCDK4ZWCIoIMDN4o4CIYQYGApAYCIgY3BOAYSBLoYlCRIQ4CR4b+BDAYFFCQoYGFYIYFYIgYHZooYebQhjTPhKVOVwwYFY5gGCcAz5CGQIECDAcHCYQAD/wYGAAhQDHAQYJn4MG4DaFAAiCDRIQAFN4ZeDAAbNEK44LDHw5WDK449EHw49EHww9EHwx7EEo57DEo7rDEo4kGEopJFZIpuEWAwwGPwh6FBgoLJAH4AVSgKRDRoKHFQoazBcIgYaX4oYFCQYYSXAIYKn74DAATeGAAgYEFYIYJFYIYWh4YLBYwYEN4IYJRAIYKN44YDN46bGDBJvHDH4Y0AAwSBBZIrBDH4YhAHF4BZUPLghjG//gAohjEh//4AFCj4YEgISBwAFBgYYFCQqIBAoYSFFQIYEn4+DFQQYF/wREDAgrBJQRiBDAgGB/hiEDBJPBDBJPCDAhvEDoIYELoP4MQgYIMQQYJMQQYIMQQYJBYQYIEgYYHEgYYG4BJDDAyuBEgRxBDAvwSYX3DAwAD/wYHAAfHDBX8DBeHY4xUEDArCCHoQSBDBPgDBX8DAr0DUoQYFVQYVBDAqeETAIYFSQSxCDApwEZQIYFaAoYGHwfgDAw+D/gYHV4Z2DBYZ9D4AYHEoRJBDA4TBGAIYHGQILCDA4A/ABMHBhd+Aws8NwjpBTYiZBcAZ7DBYIFEfILRBbIYFDVoIlDAooYCFYYeFgYxEDAwrBDAbyBY4YYB/AVBBAL9DZoeAFwIYGcwIYQCQQYE+AYDCQSIDCoIYIG4RNBDBRmBDEgIBDBWADBAIDDBAICDBACBZQIYHwACB4APBDAv8RAP+TAIYG+4CB/BNBDAoAGDAoAFDBjgFAAr5FDCyrBAAv+DAZdBAAvgDA3vAYSYBAASGBEAI1D4AMDA4XHN4xwDSYSIFK4Y1DKwY+D8A1DBYYlCFgI9HEoSNDHohLCHAI+CBYpbFPYYAFIQIkGIQiHEAH4ADPgKgEAAkBPZaIBDBLXCEhYYJVpYkCDBAkCDBIkCDBAkCDBAkDDBF/DBQkDDA4kDDBAkDDA4kC34YHgYLB8YYIEgP8OIIkJDYIYGEgXgDBAkB/AYIj5gCDA4kC4AYIEgQYIEgP+DgQYFEgYYIEgIUBDA8HVgawHVgYADIYIYKwAY/DH4Y/DF4AEn//BI4ABgf/+AMJDH4YjAH4AJj/ABRDiB/jzCdgcBdIfgOIIPBAAQLD/wnB/4oDh4MD+AeBDBCgBDAPgDBASBFAIYHwASBDBH4CQQYI4ASBZIYYEI4J0BDBJ8BDBAxBDAKJDJQoYBB4JjIDBSuCDAvwBAJsBDAyCBAQQYH8CFDDBLgDDAzQDDA7QDDBQxBOYQYGGgISBDBD5CDBAIBn4YJ/ybCDBClEDAylEDEZzBVwwACOYKuGAAalBDBKlBDAq3BAARvDDAS3BAASIDDAaSBKwwYCK4hWDDAY+DHogIBG4I9HgFgAQMDSgwAESwR7EAAh7GAAglCEhBCCJIgMGBZQA9j5JKcAKHJaYQMIUATrFAAT4Eb4gABdYjTFGAjsGVYYlJEgv/EhRLGJIjtHBYpxFNwYACfQkDBYpkFT4I+JHow+FBYx9EHox9EPYxXFPYoYFKw6WEDAXh/+DOApWC+E/+AFCN4v8FAJQCOAYSDv4hBRIpECcQISCDAYIBOwJTCIgIYFwEfNgI0BDAv4P4IYV+AIBDBIICDBZjBDCwIBR4IYIwBdCDA/8cwQYI+AkBY4YYEcA4SBfgrgF/AYLwAYERgIYJUoIACCoPAewIAC4ALCMAoABcwIYKN4YVBFYJWHgAVB8BBBKwyJDLQJWFRIXgK4Y9ECoIrBHwY9DOALACHo8AniADPYoAESwR7DAAokHAAaNCBZAMBBZQA5PAKoENYyDJXQYYQjgYKg4FEDAsDAogYGAowSEZIIYJfYLIEDAjuCwAYHagP//AYIBYIYJv4LBcQgYDHgIAB4AYGHgRdFAoQ8CAAJdDDAYLDOAgYCHgQABOAYYCHgYYHBwIADOAYJB8YLEOAgYBBYoYFAApjFAAzHFAAqIDDA7TEDAzGEDAw8EDA4LEDAw8EDAy4DDA48FDAr2EDA4LGDAiqDDA48GDAiFEDAw8HDAaFFDAw8HDAY8HDAY8IDAQ8IAH4AFv5nJgE/QBMAg6ZKgKBLEgIlGEIICCRwwhBFoN/WY4IB+DxDZA/Bfo5GC/0fco5GC+YLCHwhGC/+/AYXAdooAEDAhGDAAZXDHoQAESwhGDAAZXDgYLGOAhWCDBBWDDBCdCDB2DRIt//gzC8BpB/BvEwALBBAIrBDAYqBE4RdCDArVDLoQYE8ByCwCPBDAiOBCgIIBR4IYFUgXADBAUBYgIYHawQYJJoIcDMYoYCGoRjGOAZjGCIKJCPg/AUQWADA3/z4CB/goBDAoAD+LHGfMa4CDBJUCAAicBDBKYBAASbBDBJwC/5BDZQJwF+YYD4BXF/xBDRAY+D4IYDRAY+C/CZDN4Y+DQAZWEEoXAM4Y9EUYIGBHwRWEFAyUEDYp7GAAglBEhJLBJIoyGBZQA/MBDPEPI7DFfQy3FAAUBaAkBUQrdCGQSKFewYlBv41EEgQlCj//wBJFAAPwaoJbEbgTqCCIJOEHoQVBgbhFHoYuBGIJXDHoYVBAoLuECQJXDDAorBDAZvBOAhWDCoI3BOAYYEFwIYFKwYYBNIIYDN4gYBCQKJDAoPwAQIYCRIY3BMAgYFPIQPBDBA3Bv4YIBAIVBDBCCBn4YKOYIYY4ASBDBCuDDCn4cwR8FDAWAZoIYFAoM/+C0CY4b2CBIIFCY4xgB8DyCcAv+g/8j7jCcA7jEfI78DBYRTBAAp/BAAQ4CAAnABYR2CAAhvDgBFCAAgLDNQQAEN4aJCKxJXHHoZXHHog+HBYg+GPYY+HPYh9HdYZ9HEgolFEgwlFBYxLENwhxGGAzvET4gZGC5AA/ABl8AYV4BY0fdIU/OQx8BSYIDDUQv+AYokESgQDDcI2AWQTUHHwIDDY43AXwWADAz3Bv4YGCgQYJCgIYDAYIYKOAoYYJRZjOPhKVGDAqqBCgKuHYYKqBDgLHGHQPggEPcA8/NYU/HoolCIQQkGAEIA=='))); + +Graphics.prototype.setFontPaytoneOne = function(scale) { + // Actual height 71 (81 - 11) + this.setFontCustom(fontBitmap, + 46, + atob("HTBFLTQ0PzU/Lz8+HQ=="), + 100+(scale<<8)+(1<<16) + ); + return this; +}; + +let drawTimeout; + +let g2 = Graphics.createArrayBuffer(g.getWidth(),90,1,{msb:true}); +let g2img = { + width:g2.getWidth(), height:g2.getHeight(), bpp:1, + buffer:g2.buffer, transparent:0 +}; +const slope = 20; +const offsy = 20; // offset of numbers from middle +const fontBorder = 4; // offset from left/right +const slopeBorder = 10, slopeBorderUpper = 4; // fudge-factor to move minutes down from slope +let R,x,y; // middle of the clock face +let dateStr = ""; +let bgColors = []; +if (g.theme.dark) { + if (settings.colorYellow) bgColors.push("#ff0"); + if (settings.colorCyan) bgColors.push("#0ff"); + if (settings.colorMagenta) bgColors.push("#f0f"); + if (settings.colorWhite) bgColors.push("#fff"); +} else { + if (settings.colorRed) bgColors.push("#f00"); + if (settings.colorGreen) bgColors.push("#0f0"); + if (settings.colorBlue) bgColors.push("#00f"); + if (settings.colorBlack) bgColors.push("#000"); +} +let bgColor = bgColors[(Math.random()*bgColors.length)|0]||"#000"; + + +// Draw the hour, and the minute into an offscreen buffer +let draw = function() { + // queue next draw + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + animate(false, function() { + draw(); + }); + }, 60000 - (Date.now() % 60000)); + // Now draw this one + R = Bangle.appRect; + x = R.w / 2; + y = R.y + R.h / 2 - 12; // 12 = room for date + var date = new Date(); + var local_time = require("locale").time(date, 1); + var hourStr = local_time.split(":")[0].trim().padStart(2,'0'); + var minStr = local_time.split(":")[1].trim().padStart(2, '0'); + dateStr = require("locale").dow(date, 1).toUpperCase()+ " "+ + require("locale").date(date, 0).toUpperCase(); + + // Draw hour + g.reset().clearRect(R); // clear whole background (w/o widgets) + g.setFontAlign(-1, 0).setFont("PaytoneOne"); + g.drawString(hourStr, fontBorder, y-offsy).setFont("4x6"); // draw and unload custom font + // add slope in background color + g.setColor(g.theme.bg).fillPoly([0,y+slope-slopeBorderUpper, R.w,y-slope-slopeBorderUpper, + R.w,y-slope, 0,y+slope]); + // Draw minute to offscreen buffer + g2.setColor(0).fillRect(0,0,g2.getWidth(),g2.getHeight()).setFontAlign(1, 0).setFont("PaytoneOne"); + g2.setColor(1).drawString(minStr, g2.getWidth()-fontBorder, g2.getHeight()/2).setFont("4x6"); // draw and unload custom font + g2.setColor(0).fillPoly([0,0, g2.getWidth(),0, 0,slope*2]); + // start the animation *in* + animate(true); +}; + +let isAnimIn = true; +let animInterval; +// Draw *just* the minute image +let drawMinute = function() { + var yo = slopeBorder + offsy + y - 2*slope*minuteX/R.w; + // draw over the slanty bit + g.setColor(bgColor).fillPoly([0,y+slope, R.w,y-slope, R.w,R.h+R.y, 0,R.h+R.y]); + // draw the minutes + g.setColor(g.theme.bg).drawImage(g2img, x+minuteX-(g2.getWidth()/2), yo-(g2.getHeight()/2)); +}; +let animate = function(isIn, callback) { + if (animInterval) clearInterval(animInterval); + isAnimIn = isIn; + minuteX = isAnimIn ? -g2.getWidth() : 0; + drawMinute(); + animInterval = setInterval(function() { + minuteX += 8; + let stop = false; + if (isAnimIn && minuteX>=0) { + minuteX=0; + stop = true; + } else if (!isAnimIn && minuteX>=R.w) + stop = true; + drawMinute(); + if (stop) { + clearInterval(animInterval); + animInterval=undefined; + if (isAnimIn) { + // draw the date + g.setColor(g.theme.bg).setFontAlign(0, 0).setFont("6x15").drawString(dateStr, R.x + R.w/2, R.y+R.h-9); + // draw the menu items + clockInfoMenu.redraw(); + clockInfoMenu2.redraw(); + } + if (callback) callback(); + } + }, 20); +}; + +// clock info menus (scroll up/down for info) +let clockInfoDraw = (itm, info, options) => { + let texty = options.y+41; + // set a cliprect to stop us drawing outside our box + g.reset().setClipRect(options.x, options.y, options.x+options.w-1, options.y+options.h-1); + g.setFont("6x15").setBgColor(options.bg).setColor(options.fg).clearRect(options.x, texty-15, options.x+options.w-2, texty); + + if (options.focus) g.setColor(options.hl); + if (options.x < g.getWidth()/2) { // left align + let x = options.x+2; + if (info.img) g.clearRect(x, options.y, x+23, options.y+23).drawImage(info.img, x, options.y); + g.setFontAlign(-1,1).drawString(info.text, x,texty); + } else { // right align + let x = options.x+options.w-3; + if (info.img) g.clearRect(x-23, options.y, x, options.y+23).drawImage(info.img, x-23, options.y); + g.setFontAlign(1,1).drawString(info.text, x,texty); + } + // return ClipRect + g.setClipRect(0,0,g.getWidth()-1, g.getHeight()-1); +}; +let clockInfoItems = require("clock_info").load(); +let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { x:126, y:24, w:50, h:40, draw : clockInfoDraw, bg : g.theme.bg, fg : g.theme.fg, hl : "#f00"/*red*/ }); +let clockInfoMenu2 = require("clock_info").addInteractive(clockInfoItems, { x:0, y:115, w:50, h:40, draw : clockInfoDraw, bg : bgColor, fg : g.theme.bg, hl : (bgColor=="#000")?"#f00"/*red*/:g.theme.fg }); + +// Show launcher when middle button pressed +Bangle.setUI({ + mode : "clock", + remove : function() { + // Called to unload all of the clock app + if (animInterval) clearInterval(animInterval); + animInterval = undefined; + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + delete Graphics.prototype.setFontPaytoneOne; + // remove info menu + clockInfoMenu.remove(); + delete clockInfoMenu; + clockInfoMenu2.remove(); + delete clockInfoMenu2; + } +}); +// Load widgets +Bangle.loadWidgets(); +draw(); +setTimeout(Bangle.drawWidgets,0); +} diff --git a/apps/slopeclockpp/app.png b/apps/slopeclockpp/app.png new file mode 100644 index 000000000..2f5912fcf Binary files /dev/null and b/apps/slopeclockpp/app.png differ diff --git a/apps/slopeclockpp/default.json b/apps/slopeclockpp/default.json new file mode 100644 index 000000000..29b618735 --- /dev/null +++ b/apps/slopeclockpp/default.json @@ -0,0 +1,10 @@ +{ + "colorRed": true, + "colorGreen": true, + "colorBlue": true, + "colorYellow": true, + "colorMagenta": true, + "colorCyan": true, + "colorBlack": true, + "colorWhite": true +} diff --git a/apps/slopeclockpp/metadata.json b/apps/slopeclockpp/metadata.json new file mode 100644 index 000000000..fbab02fca --- /dev/null +++ b/apps/slopeclockpp/metadata.json @@ -0,0 +1,20 @@ +{ "id": "slopeclockpp", + "name": "Slope Clock ++", + "version":"0.08", + "description": "A clock where hours and minutes are divided by a sloping line. When the minute changes, the numbers slide off the screen. This is a clone of the original Slope Clock which shows extra information and allows the colors to be selected.", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"slopeclockpp.app.js","url":"app.js"}, + {"name":"slopeclockpp.img","url":"app-icon.js","evaluate":true}, + {"name":"slopeclockpp.settings.js","url":"settings.js"}, + {"name":"slopeclockpp.default.json","url":"default.json"} + ], + "data": [ + {"name":"slopeclockpp.json"} + ] +} diff --git a/apps/slopeclockpp/screenshot.png b/apps/slopeclockpp/screenshot.png new file mode 100644 index 000000000..dfa76fed7 Binary files /dev/null and b/apps/slopeclockpp/screenshot.png differ diff --git a/apps/slopeclockpp/settings.js b/apps/slopeclockpp/settings.js new file mode 100644 index 000000000..1d285767a --- /dev/null +++ b/apps/slopeclockpp/settings.js @@ -0,0 +1,64 @@ +(function(back) { + const SETTINGS_FILE = "slopeclockpp.json"; + const storage = require('Storage'); + let settings = Object.assign( + storage.readJSON("slopeclockpp.default.json", true) || {}, + storage.readJSON(SETTINGS_FILE, true) || {} + ); + + function save(key, value) { + settings[key] = value; + storage.write(SETTINGS_FILE, settings); + } + + function showMainMenu() { + let menu ={ + '': { 'title': 'Slope Clock ++' }, + /*LANG*/'< Back': back, + /*LANG*/'Red': { + value: !!settings.colorRed, + format: () => (settings.colorRed ? 'Yes' : 'No'), + onchange: x => save('colorRed', x), + }, + /*LANG*/'Green': { + value: !!settings.colorGreen, + format: () => (settings.colorGreen ? 'Yes' : 'No'), + onchange: x => save('colorGreen', x), + }, + /*LANG*/'Blue': { + value: !!settings.colorBlue, + format: () => (settings.colorBlue ? 'Yes' : 'No'), + onchange: x => save('colorBlue', x), + }, + /*LANG*/'Magenta': { + value: !!settings.colorMagenta, + format: () => (settings.colorMagenta ? 'Yes' : 'No'), + onchange: x => save('colorMagenta', x), + }, + /*LANG*/'Cyan': { + value: !!settings.colorCyan, + format: () => (settings.colorCyan ? 'Yes' : 'No'), + onchange: x => save('colorCyan', x), + }, + /*LANG*/'Yellow': { + value: !!settings.colorYellow, + format: () => (settings.colorYellow ? 'Yes' : 'No'), + onchange: x => save('colorYellow', x), + }, + /*LANG*/'Black': { + value: !!settings.colorBlack, + format: () => (settings.colorBlack ? 'Yes' : 'No'), + onchange: x => save('colorBlack', x), + }, + /*LANG*/'White': { + value: !!settings.colorWhite, + format: () => (settings.colorWhite ? 'Yes' : 'No'), + onchange: x => save('colorWhite', x), + } + }; + E.showMenu(menu); + } + + + showMainMenu(); +}); diff --git a/apps/smpltmr/ChangeLog b/apps/smpltmr/ChangeLog index bf128e2fb..61111482e 100644 --- a/apps/smpltmr/ChangeLog +++ b/apps/smpltmr/ChangeLog @@ -1,2 +1,7 @@ 0.01: Release -0.02: Rewrite with new interface \ No newline at end of file +0.02: Rewrite with new interface +0.03: Added clock infos to expose timer functionality to clocks. +0.04: Improvements of clock infos. +0.05: Updated clkinfo icon. +0.06: Ensure Timer supplies an image for clkinfo items +0.07: Update clock_info to avoid a redraw diff --git a/apps/smpltmr/clkinfo.js b/apps/smpltmr/clkinfo.js new file mode 100644 index 000000000..ac01cfb59 --- /dev/null +++ b/apps/smpltmr/clkinfo.js @@ -0,0 +1,97 @@ +(function() { + const TIMER_IDX = "smpltmr"; + + function isAlarmEnabled(){ + try{ + var alarm = require('sched'); + var alarmObj = alarm.getAlarm(TIMER_IDX); + if(alarmObj===undefined || !alarmObj.on){ + return false; + } + + return true; + + } catch(ex){ } + return false; + } + + function getAlarmMinutes(){ + if(!isAlarmEnabled()){ + return -1; + } + + var alarm = require('sched'); + var alarmObj = alarm.getAlarm(TIMER_IDX); + return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000)); + } + + function getAlarmMinutesText(){ + var min = getAlarmMinutes(); + if(min < 0){ + return "OFF"; + } + + return "T-" + String(min); + } + + function increaseAlarm(t){ + try{ + var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0; + var alarm = require('sched') + alarm.setAlarm(TIMER_IDX, { + timer : (minutes+t)*60*1000, + }); + alarm.reload(); + } catch(ex){ } + } + + function decreaseAlarm(t){ + try{ + var minutes = getAlarmMinutes(); + minutes -= t; + + var alarm = require('sched') + alarm.setAlarm(TIMER_IDX, undefined); + + if(minutes > 0){ + alarm.setAlarm(TIMER_IDX, { + timer : minutes*60*1000, + }); + } + + alarm.reload(); + } catch(ex){ } + } + + var smpltmrItems = { + name: "Timer", + img: atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwMMBgPGBgPmDAPjDAPzDAPzDP/zDP/zDH/jBn/mBj/GAw8MA4AcAeB4AH/gAB+AA=="), + items: [ + { + name: null, + get: () => ({ text: getAlarmMinutesText() + (isAlarmEnabled() ? " min" : ""), img: smpltmrItems.img }), + show: function() {}, + hide: function () {}, + run: function() { } + }, + ] + }; + + var offsets = [+5,-5]; + offsets.forEach((o, i) => { + smpltmrItems.items = smpltmrItems.items.concat({ + name: null, + get: () => ({ text: (o > 0 ? "+" : "") + o + " min.", img: smpltmrItems.img }), + show: function() {}, + hide: function () {}, + run: function() { + if(o > 0) increaseAlarm(o); + else decreaseAlarm(Math.abs(o)); + this.show(); + return true; + } + }); + }); + + return smpltmrItems; +}) diff --git a/apps/smpltmr/metadata.json b/apps/smpltmr/metadata.json index cb1ef6eab..b0d1a34da 100644 --- a/apps/smpltmr/metadata.json +++ b/apps/smpltmr/metadata.json @@ -2,16 +2,17 @@ "id": "smpltmr", "name": "Simple Timer", "shortName": "Simple Timer", - "version": "0.02", + "version": "0.07", "description": "A very simple app to start a timer.", "icon": "app.png", - "tags": "tool,alarm,timer", + "tags": "tool,alarm,timer,clkinfo", "dependencies": {"scheduler":"type"}, "supports": ["BANGLEJS2"], "screenshots": [{"url":"screenshot_1.png"}, {"url": "screenshot_2.png"}, {"url": "screenshot_3.png"}, {"url": "screenshot_4.png"}], "readme": "README.md", "storage": [ {"name":"smpltmr.app.js","url":"app.js"}, + {"name":"smpltmr.clkinfo.js","url":"clkinfo.js"}, {"name":"smpltmr.img","url":"app-icon.js","evaluate":true} ] } diff --git a/apps/sonicclk/Changelog b/apps/sonicclk/ChangeLog similarity index 100% rename from apps/sonicclk/Changelog rename to apps/sonicclk/ChangeLog diff --git a/apps/speedalt/README.md b/apps/speedalt/README.md index 6f0d4efe5..e629f94bb 100644 --- a/apps/speedalt/README.md +++ b/apps/speedalt/README.md @@ -2,7 +2,7 @@ You can switch between three display modes. One showing speed and altitude (A), one showing speed and distance to waypoint (D) and a large dispay of time and selected waypoint. -Within the [A]ltitude and [D]istance displays modes one figure is displayed on the watch face using the largest possible characters depending on the number of digits. The other is in a smaller characters below that. Both are always visible. You can display the current or maximum observed speed/altitude values. Current time is always displayed. +Within the [A]ltitude and [D]istance displays modes one figure is displayed on the watch face using the largest possible characters depending on the number of digits. The other is in a smaller characters below that. Both are always visible. You can display the current or maximum observed speed/altitude values. Current time is always displayed. The waypoints list is the same as that used with the [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app so the same set of waypoints can be used across both apps. Refer to that app for waypoint file information. @@ -36,7 +36,7 @@ BTN4 : Left Display Tap : Swaps which figure is in the large display. You can ha ## App Settings -Select the desired display units. Speed can be as per the default locale, kph, knots, mph or m/s. Distance can be km, miles or nautical miles. Altitude can be feet or metres. Select one of three colour schemes. Default (three colours), high contrast (all white on black) or night ( all red on black ). +Select the desired display units. Speed can be as per the default locale, kph, knots, mph or m/s. Distance can be km, miles or nautical miles. Altitude can be feet or metres. Select one of three colour schemes. Default (three colours), high contrast (all white on black) or night ( all red on black ). ## Kalman Filter @@ -67,13 +67,11 @@ This app will work quite happily on its own but will use the [GPS Setup App](htt When using the GPS Setup App this app switches the GPS to SuperE (default) mode while the display is lit and showing fix information. This ensures that that fixes are updated every second or so. 10 seconds after the display is blanked by the watch this app will switch the GPS to PSMOO mode and will only attempt to get a fix every two minutes. This improves power saving while the display is off and the delay gives an opportunity to restore the display before the GPS power mode is switched. -The MAX values continue to be collected with the display off so may appear a little odd after the intermittent fixes of the low power mode. +The MAX values continue to be collected with the display off so may appear a little odd after the intermittent fixes of the low power mode. ## Waypoints -Waypoints are used in [D]istance mode. Create a file waypoints.json and write to storage on the Bangle.js using the IDE. The first 6 characters of the name are displayed in Speed+[D]istance mode. - -The [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app in the App Loader has a really nice waypoints file editor. (Must be connected to your Bangle.JS and then click on the Download icon.) +Waypoints are used in Distance and VMG modes. See the `Waypoints` app for information on how to create/edit waypoints. The first 6 characters of the name are displayed in Speed+[D]istance mode. Sample waypoints.json (My sailing waypoints) @@ -149,5 +147,3 @@ Developed for my use in sailing, cycling and motorcycling. If you find this soft Many thanks to Gordon Williams. Awesome job. Special thanks also to @jeffmer, for the [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app and @hughbarney for the Low power GPS code development and Wouter Bulten for the Kalman filter code. - - diff --git a/apps/speedalt/app.js b/apps/speedalt/app.js index 79db932db..4587252c2 100644 --- a/apps/speedalt/app.js +++ b/apps/speedalt/app.js @@ -209,7 +209,7 @@ function nxtWp(inc){ } function loadWp() { - var w = require("Storage").readJSON('waypoints.json')||[{name:"NONE"}]; + var w = require("waypoints").load(); if (cfg.wp>=w.length) cfg.wp=0; if (cfg.wp<0) cfg.wp = w.length-1; savSettings(); diff --git a/apps/speedalt/metadata.json b/apps/speedalt/metadata.json index b23d2692c..89bfd4a57 100644 --- a/apps/speedalt/metadata.json +++ b/apps/speedalt/metadata.json @@ -8,12 +8,12 @@ "type": "app", "tags": "tool,outdoors", "supports": ["BANGLEJS","BANGLEJS2"], + "dependencies" : { "waypoints":"type" }, "readme": "README.md", "allow_emulator": true, "storage": [ {"name":"speedalt.app.js","url":"app.js"}, {"name":"speedalt.img","url":"app-icon.js","evaluate":true}, {"name":"speedalt.settings.js","url":"settings.js"} - ], - "data": [{"name":"speedalt.json"}] + ] } diff --git a/apps/speedalt2/ChangeLog b/apps/speedalt2/ChangeLog index 0e54d5db3..ec76c6a16 100644 --- a/apps/speedalt2/ChangeLog +++ b/apps/speedalt2/ChangeLog @@ -15,3 +15,4 @@ 0.15: Droidscript mirroring prog automatically uses last connection address. Auto connects when run. 0.16: Add configuration item Wpt File Suffix. A one character suffix to append to the waypoints.json file. A number of other apps also use this file name. Using the file name suffix allows the speedalt2 waypoints to be retained if one of these other apps is installed for a different use. 0.17: Use default Bangle formatter for booleans +0.18: Move waypoints.json to 'waypoints' app (with editor) diff --git a/apps/speedalt2/README.md b/apps/speedalt2/README.md index a86f787cf..d6a5e1d71 100644 --- a/apps/speedalt2/README.md +++ b/apps/speedalt2/README.md @@ -25,7 +25,7 @@ Touch functions as BTN1 short press. ## App Settings -Select the desired display units. Speed can be as per the default locale, kph, knots, mph or m/s. Distance can be km, miles or nautical miles. Altitude can be feet or metres. Select one of three colour schemes. Default (three colours), high contrast (all white on black) or night ( all red on black ). +Select the desired display units. Speed can be as per the default locale, kph, knots, mph or m/s. Distance can be km, miles or nautical miles. Altitude can be feet or metres. Select one of three colour schemes. Default (three colours), high contrast (all white on black) or night ( all red on black ). ## Kalman Filter @@ -43,7 +43,7 @@ This app will work quite happily on its own but will use the [GPS Setup App](htt When using the GPS Setup App this app switches the GPS to SuperE (default) mode while the display is lit and showing fix information. This ensures that that fixes are updated every second or so. 10 seconds after the display is blanked by the watch this app will switch the GPS to PSMOO mode and will only attempt to get a fix every two minutes. This improves power saving while the display is off and the delay gives an opportunity to restore the display before the GPS power mode is switched. -The MAX values continue to be collected with the display off so may appear a little odd after the intermittent fixes of the low power mode. +The MAX values continue to be collected with the display off so may appear a little odd after the intermittent fixes of the low power mode. ## Velocity Made Good - VMG @@ -63,9 +63,9 @@ The Droidscript script file is called : **GPS Adv Sports II.js** **Important Gotcha :** For the BLE comms to find and connect to the Bangle.js it must be paired with the Android device but **NOT** connected. The Bangle.js must have been set in the Bluetooth settings as connectable. -Start/Stop buttons tell the Bangle.js to start or stop sending BLE data packets to the Android device. While stopped the Bangle.js reverts to full power saving mode when the screen is asleep. +Start/Stop buttons tell the Bangle.js to start or stop sending BLE data packets to the Android device. While stopped the Bangle.js reverts to full power saving mode when the screen is asleep. -When running a blue 'led' will flash each time a data packet is recieved to refresh the android display. +When running a blue 'led' will flash each time a data packet is recieved to refresh the android display. An orange 'led' will flash for each reconnection attempt if no data is received for 30 seconds. It will keep trying to reconnect so you can restart the Bangle, run another Bangle app or temprarily turn off bluetooth. The android mirror display will automatically reconnect when the GPS Adv Sports II app is running on the Bangle again. ( Designed to leave the Android device running as the display mirror in a sealed case all day while retaining the ability to do other functions on the Bangle.js and returning to the GPS Speed Alt II app. ) @@ -74,14 +74,12 @@ Android Screen Mirroring:
## Waypoints -Waypoints are used in Distance and VMG modes. Create a file waypoints.json and write to storage on the Bangle.js using the IDE. The first 6 characters of the name are displayed in Speed+[D]istance mode. - -The [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app in the App Loader has a really nice waypoints file editor. (Must be connected to your Bangle.JS and then click on the Download icon.) +Waypoints are used in Distance and VMG modes. See the `Waypoints` app for information on how to create/edit waypoints. The first 6 characters of the name are displayed in Speed+[D]istance mode. By default the waypoints file is called waypoints.json -**Note** : The waypoints.json file is used by a number of different gps apps. The setting 'Wpt File Suffix' allows one of waypoints1.json, waypoints2.json or waypoints3.json to be used instead. This allows the other apps to be used with a different set of waypoints without losing the speedalt2 waypoint set. - +**Note** : The waypoints.json file is used by a number of different gps apps. The setting 'Wpt File Suffix' allows one of waypoints.1.json, waypoints.2.json or waypoints.3.json to be used instead. This allows the other apps to be used with a different set of waypoints without losing the speedalt2 waypoint set. + Sample waypoints.json (My sailing waypoints)
@@ -156,4 +154,3 @@ Developed for my use in sailing, cycling and motorcycling. If you find this soft
 Many thanks to Gordon Williams. Awesome job.
 
 Special thanks also to @jeffmer, for the [GPS Navigation](https://banglejs.com/apps/#gps%20navigation) app and @hughbarney for the Low power GPS code development and Wouter Bulten for the Kalman filter code.
-
diff --git a/apps/speedalt2/app.js b/apps/speedalt2/app.js
index 4cdf71913..839ac63eb 100644
--- a/apps/speedalt2/app.js
+++ b/apps/speedalt2/app.js
@@ -185,7 +185,7 @@ let LED = // LED as minimal and only definition (as instance / singleton)
 , reset: function() { this.set(false); } // turn off
 , write: function(v) { this.set(v); }  // turn on w/ no arg or truey, else off
 , toggle: function() { this.set( ! this.isOn); } // toggle the LED
-}, LED1 = LED; // LED1 as 'synonym' for LED 
+}, LED1 = LED; // LED1 as 'synonym' for LED
 
 
 var lf = {fix:0,satellites:0};
@@ -210,7 +210,7 @@ function nxtWp(){
 }
 
 function loadWp() {
-  var w = require("Storage").readJSON('waypoints'+cfg.wptSfx+'.json')||[{name:"NONE"}];
+  var w = require("waypoints").load(cfg.wptSfx);
   if (cfg.wp>=w.length) cfg.wp=0;
   if (cfg.wp<0) cfg.wp = w.length-1;
   savSettings();
@@ -239,7 +239,7 @@ function bearing(a,b){
 function distance(a,b){
   var x = radians(a.lon-b.lon) * Math.cos(radians((a.lat+b.lat)/2));
   var y = radians(b.lat-a.lat);
-  
+
   // Distance in metres
   var d = Math.sqrt(x*x + y*y) * 6371000;
   return d;
@@ -251,38 +251,38 @@ function drawScrn(dat) {
 
   buf.clear();
   buf.setBgColor(0);
-  
+
   var n;
   n = dat.val.toString();
-  
+
   var s=50;    // Font size
   var l=n.length;
-  
+
   if ( l <= 7 ) s=55;
   if ( l <= 6 ) s=60;
   if ( l <= 5 ) s=80;
   if ( l <= 4 ) s=100;
   if ( l <= 3 ) s=120;
-        
-  buf.setFontAlign(0,0); //Centre 
-  buf.setColor(1);  
+
+  buf.setFontAlign(0,0); //Centre
+  buf.setColor(1);
   buf.setFontVector(s);
   buf.drawString(n,126,52);
 
-  
+
   // Primary Units
   buf.setFontAlign(-1,1); //left, bottom
-  buf.setColor(2);  
+  buf.setColor(2);
   buf.setFontVector(35);
-  buf.drawString(dat.unit,5,164);  
-  
+  buf.drawString(dat.unit,5,164);
+
   drawMax(dat.max); // MAX display indicator
   drawWP(dat.wp);  // Waypoint name
   drawSats(dat.sats);
-   
+
   g.reset();
   g.drawImage(img,0,40);
-  
+
   LED1.write(!pwrSav);
 
 }
@@ -295,7 +295,7 @@ function drawPosn(dat) {
   var x, y;
   x=210;
   y=0;
-  buf.setFontAlign(1,-1); 
+  buf.setFontAlign(1,-1);
   buf.setFontVector(60);
   buf.setColor(1);
 
@@ -320,45 +320,45 @@ function drawPosn(dat) {
 
 function drawClock() {
   if (!canDraw) return;
-  
+
   buf.clear();
   buf.setBgColor(0);
-  
+
   var x, y;
   x=185;
   y=0;
-  buf.setFontAlign(1,-1); 
+  buf.setFontAlign(1,-1);
   buf.setFontVector(94);
   time = require("locale").time(new Date(),1);
-  
+
   buf.setColor(1);
-  
+
   buf.drawString(time.substring(0,2),x,y);
   buf.drawString(time.substring(3,5),x,y+80);
-  
+
   g.reset();
   g.drawImage(img,0,40);
-  
+
   LED1.write(!pwrSav);
 }
 
 function drawWP(wp) {
-  buf.setColor(3);  
+  buf.setColor(3);
   buf.setFontAlign(0,1); //left, bottom
   buf.setFontVector(40);
-  buf.drawString(wp,120,132);  
+  buf.drawString(wp,120,132);
 }
 
 function drawSats(sats) {
-  buf.setColor(3);  
+  buf.setColor(3);
   buf.setFont("6x8", 2);
   buf.setFontAlign(1,1); //right, bottom
-  buf.drawString(sats,240,160);  
+  buf.drawString(sats,240,160);
 }
 
 function drawMax(max) {
   buf.setFontVector(30);
-  buf.setColor(2); 
+  buf.setColor(2);
   buf.setFontAlign(0,1); //centre, bottom
   buf.drawString(max,120,164);
 }
@@ -369,7 +369,7 @@ if ( emulator ) {
     fix.speed = 10 + (Math.random()*5);
     fix.alt = 354 + (Math.random()*50);
     fix.lat = -38.92;
-    fix.lon = 175.7613350;   
+    fix.lon = 175.7613350;
     fix.course = 245;
     fix.satellites = 12;
     fix.time = new Date();
@@ -378,7 +378,7 @@ if ( emulator ) {
 
   var m;
 
-  var sp = '---';        
+  var sp = '---';
   var al = sp;
   var di = sp;
   var brg = ''; // bearing
@@ -390,15 +390,15 @@ if ( emulator ) {
   var lon = '---.--';
   var sats = sp;
   var vmg = sp;
-  
-  
+
+
   // Waypoint name
   var wpName = wp.name;
   if ( wpName == undefined || wpName == 'NONE' ) wpName = '';
-  wpName = wpName.substring(0,8);  
+  wpName = wpName.substring(0,8);
 
   if (fix.fix) lf = fix;
-  
+
   if (lf.fix) {
 
     // Smooth data
@@ -408,10 +408,10 @@ if ( emulator ) {
       lf.smoothed = 1;
       if ( maxN <= 15 ) maxN++;
     }
-    
+
     // Bearing to waypoint
     brg = bearing(lf,wp);
-    
+
     // Current course
     crs = lf.course;
 
@@ -447,19 +447,19 @@ if ( emulator ) {
     if ( di >= 100 ) di = parseFloat(di).toFixed(1);
     if ( di >= 1000 ) di = parseFloat(di).toFixed(0);
     if (isNaN(di)) di = '------';
-    
+
     // Age of last fix (secs)
     age = Math.max(0,Math.round(getTime())-(lf.time.getTime()/1000));
 
     // Lat / Lon
     ns = 'N';
     if ( lf.lat < 0 ) ns = 'S';
-    lat = Math.abs(lf.lat.toFixed(2)); 
+    lat = Math.abs(lf.lat.toFixed(2));
 
     ew = 'E';
     if ( lf.lon < 0 ) ew = 'W';
-    lon = Math.abs(lf.lon.toFixed(2)); 
-    
+    lon = Math.abs(lf.lon.toFixed(2));
+
     // Sats
     if ( age > 10 ) {
       sats = 'Age:'+Math.round(age);
@@ -573,7 +573,7 @@ if ( emulator ) {
         ew:ew
       });
   }
-  
+
   if ( cfg.modeA == 5 )  {
     // Large clock
     drawClock();
@@ -585,14 +585,14 @@ function prevScrn() {
     cfg.modeA = cfg.modeA-1;
     if ( cfg.modeA < 0 ) cfg.modeA = 5;
     savSettings();
-    onGPS(lf); 
+    onGPS(lf);
 }
 
 function nextScrn() {
     cfg.modeA = cfg.modeA+1;
     if ( cfg.modeA > 5 ) cfg.modeA = 0;
     savSettings();
-    onGPS(lf); 
+    onGPS(lf);
 }
 
 // Next function on a screen
@@ -610,7 +610,7 @@ function nextFunc(dur) {
 function updateClock() {
   if (!canDraw) return;
   if ( cfg.modeA != 5 )  return;
-  drawClock(); 
+  drawClock();
   if ( emulator ) {maxSpd++;maxAlt++;}
 }
 
@@ -661,10 +661,10 @@ function setButtons(){
     var dur = e.time - e.lastTime;
     nextFunc(dur);
   }, BTN1, { edge:"falling",repeat:true});
-  
-  // Power saving on/off 
+
+  // Power saving on/off
   setWatch(function(e){
-    pwrSav=!pwrSav; 
+    pwrSav=!pwrSav;
     if ( pwrSav ) {
       var s = require('Storage').readJSON('setting.json',1)||{};
       var t = s.timeout||10;
@@ -676,7 +676,7 @@ function setButtons(){
     }
       LED1.write(!pwrSav);
   }, BTN2, {repeat:true,edge:"falling"});
-  
+
   // BTN3 - next screen
   setWatch(function(e){
     nextScrn();
@@ -685,7 +685,7 @@ function setButtons(){
 
 Bangle.on('lcdPower',function(on) {
   if (!SCREENACCESS.withApp) return;
-  if (on) startDraw(); 
+  if (on) startDraw();
   else stopDraw();
 });
 
@@ -702,7 +702,7 @@ Bangle.on('touch', function(button){
 
 // == Main Prog
 
-// Read settings. 
+// Read settings.
 let cfg = require('Storage').readJSON('speedalt2.json',1)||{};
 
 cfg.spd = cfg.spd||1;  // Multiplier for speed unit conversions. 0 = use the locale values for speed
@@ -713,13 +713,13 @@ cfg.dist = cfg.dist||1000;// Multiplier for distnce unit conversions.
 cfg.dist_unit = cfg.dist_unit||'km';  // Displayed altitude units
 cfg.colour = cfg.colour||0;          // Colour scheme.
 cfg.wp = cfg.wp||0;        // Last selected waypoint for dist
-cfg.modeA = cfg.modeA||0;    // 0=Speed 1=Alt 2=Dist 3 = vmg 4=Position 5=Clock 
+cfg.modeA = cfg.modeA||0;    // 0=Speed 1=Alt 2=Dist 3 = vmg 4=Position 5=Clock
 cfg.primSpd = cfg.primSpd||0;    // 1 = Spd in primary, 0 = Spd in secondary
 
-cfg.spdFilt = cfg.spdFilt==undefined?true:cfg.spdFilt; 
+cfg.spdFilt = cfg.spdFilt==undefined?true:cfg.spdFilt;
 cfg.altFilt = cfg.altFilt==undefined?true:cfg.altFilt;
 cfg.touch = cfg.touch==undefined?true:cfg.touch;
-cfg.wptSfx = cfg.wptSfx==undefined?'':cfg.wptSfx; 
+cfg.wptSfx = cfg.wptSfx==undefined?'':cfg.wptSfx;
 
 if ( cfg.spdFilt ) var spdFilter = new KalmanFilter({R: 0.1 , Q: 1 });
 if ( cfg.altFilt ) var altFilter = new KalmanFilter({R: 0.01, Q: 2 });
@@ -749,7 +749,7 @@ var SCREENACCESS = {
       withApp:true,
       request:function(){this.withApp=false;stopDraw();},
       release:function(){this.withApp=true;startDraw();}
-}; 
+};
 
 var gpssetup;
 try {
diff --git a/apps/speedalt2/metadata.json b/apps/speedalt2/metadata.json
index ae513acd5..2c8d37f79 100644
--- a/apps/speedalt2/metadata.json
+++ b/apps/speedalt2/metadata.json
@@ -2,12 +2,13 @@
   "id": "speedalt2",
   "name": "GPS Adventure Sports II",
   "shortName":"GPS Adv Sport II",
-  "version":"0.17",
+  "version":"0.18",
   "description": "GPS speed, altitude and distance to waypoint display. Designed for easy viewing and use during outdoor activities such as para-gliding, hang-gliding, sailing, cycling etc.",
   "icon": "app.png",
   "type": "app",
   "tags": "tool,outdoors",
   "supports": ["BANGLEJS"],
+  "dependencies" : { "waypoints":"type" },
   "readme": "README.md",
   "allow_emulator": true,
   "storage": [
@@ -16,10 +17,6 @@
     {"name":"speedalt2.settings.js","url":"settings.js"}
   ],
   "data": [
-    {"name":"speedalt2.json"},
-    {"name":"waypoints.json"},
-    {"name":"waypoints1.json"},
-    {"name":"waypoints2.json"},
-    {"name":"waypoints3.json"}
+    {"name":"speedalt2.json"}
   ]
 }
diff --git a/apps/spotrem/ChangeLog b/apps/spotrem/ChangeLog
new file mode 100644
index 000000000..a92ed3de2
--- /dev/null
+++ b/apps/spotrem/ChangeLog
@@ -0,0 +1,8 @@
+0.01: New app.
+0.02: Restructure menu.
+0.03: change handling of intent extras.
+0.04: New layout.
+0.05: Add widgets field. Tweak layout.
+0.06: Make compatible with Fastload Utils app.
+0.07: Remove just the specific listeners to not interfere with Quick Launch
+when fastloading.
diff --git a/apps/spotrem/README.md b/apps/spotrem/README.md
new file mode 100644
index 000000000..346ec9eba
--- /dev/null
+++ b/apps/spotrem/README.md
@@ -0,0 +1,21 @@
+Requires Gadgetbridge 71.0 or later. Allow intents in Gadgetbridge in order for this app to work.
+
+Touch input:
+
+Press the different ui elements to control Podcast Addict and open menus. Press left or right arrow to go to previous/next track.
+
+Swipe input:
+
+Swipe left/right to go to previous/next track. Swipe up/down to change the volume.
+
+It's possible to start tracks by searching with the remote. Search term without tags will override search with tags.
+
+To start playing 'from cold' the command for previous/next track via touch or swipe can be used. Pressing just play/pause is not guaranteed to initiate spotify in all circumstances (this will probably change with subsequent releases).
+
+In order to search to play or start music from the 'Saved' menu the Android device must be awake and unlocked. The remote can wake and unlock the device if the Bangle.js has been added as a 'trusted device' under Android Settings->Security->Smart Lock->Trusted devices.
+
+The swipe logic was inspired by the implementation in [rigrig](https://git.tubul.net/rigrig/)'s Scrolling Messages.
+
+Spotify Remote was created by [thyttan](https://github.com/thyttan/).
+
+Spotify icon by Icons8
diff --git a/apps/spotrem/app-icon.js b/apps/spotrem/app-icon.js
new file mode 100644
index 000000000..8da55b9a5
--- /dev/null
+++ b/apps/spotrem/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwwhC/AFV3AAQVVDKQWHDB0HC5NwCyoYMCxZJKFxgwKCxowJC6xGOJBAWPGA4MGogXOIwdCmf/AAczkhIKC4VzCogAD+YZEC49PC5AABmgXO+czJYoYDC4gfCuRYGoUjDAZ4GUJlyn4XNukjIwMzmVHBAU/+YXKoZ0GmQLCDgQXIU5IVDC5JVCIwIECDA5HIR4hkBDAX0C5YAHOoIXJa4QRDoUikiOEm7vKE4YADmZ1FC5N/R48nC5tzFQMiokimYYHC4h4KJwX3Ow6QMOwoXGSAoAKIwrBNFxIXZJBxGHGB4WIGBouJDBgWLJJYWMDBIWODIwVRAH4AXA="))
diff --git a/apps/spotrem/app.js b/apps/spotrem/app.js
new file mode 100644
index 000000000..f9046c4a6
--- /dev/null
+++ b/apps/spotrem/app.js
@@ -0,0 +1,288 @@
+{
+/*
+Bluetooth.println(JSON.stringify({t:"intent", action:"", flags:["flag1", "flag2",...], categories:["category1","category2",...], mimetype:"", data:"",  package:"", class:"", target:"", extra:{someKey:"someValueOrString"}}));
+*/
+
+let R;
+let widgetUtils = require("widget_utils");
+let backToMenu = false;
+let isPaused = true;
+let dark = g.theme.dark; // bool
+
+// The main layout of the app
+let gfx = function() {
+  widgetUtils.hide();
+  R = Bangle.appRect;
+  marigin = 8;
+  // g.drawString(str, x, y, solid)
+  g.clearRect(R);
+  g.reset();
+
+  if (dark) {g.setColor(0x07E0);} else {g.setColor(0x03E0);} // Green on dark theme, DarkGreen on light theme.
+  g.setFont("4x6:2");
+  g.setFontAlign(1, 0, 0);
+  g.drawString("->", R.x2 - marigin, R.y + R.h/2);
+
+  g.setFontAlign(-1, 0, 0);
+  g.drawString("<-", R.x + marigin, R.y + R.h/2);
+
+  g.setFontAlign(-1, 0, 1);
+  g.drawString("<-", R.x + R.w/2, R.y + marigin);
+
+  g.setFontAlign(1, 0, 1);
+  g.drawString("->", R.x + R.w/2, R.y2 - marigin);
+
+  g.setFontAlign(0, 0, 0);
+  g.drawString("Play\nPause", R.x + R.w/2, R.y + R.h/2);
+
+  g.setFontAlign(-1, -1, 0);
+  g.drawString("Menu", R.x + 2*marigin, R.y + 2*marigin);
+
+  g.setFontAlign(-1, 1, 0);
+  g.drawString("Wake", R.x + 2*marigin, R.y + R.h - 2*marigin);
+
+  g.setFontAlign(1, -1, 0);
+  g.drawString("Srch", R.x + R.w - 2*marigin, R.y + 2*marigin);
+
+  g.setFontAlign(1, 1, 0);
+  g.drawString("Saved", R.x + R.w - 2*marigin, R.y + R.h - 2*marigin);
+};
+
+// Touch handler for main layout
+let touchHandler = function(_, xy) {
+  x = xy.x;
+  y = xy.y;
+  len = (R.wb-1 instead of a>b.
+  if ((R.x-1{
+        Bangle.removeListener("touch", touchHandler);
+        Bangle.removeListener("swipe", swipeHandler);
+        clearWatch(buttonHandler);
+        widgetUtils.show();
+      }
+    },
+      ud => {
+        if (ud) Bangle.musicControl(ud>0 ? "volumedown" : "volumeup");
+      }
+  );
+  Bangle.on("touch", touchHandler);
+  Bangle.on("swipe", swipeHandler);
+  let buttonHandler = setWatch(()=>{load();}, BTN, {edge:'falling'});
+};
+
+// Get back to the main layout
+let backToGfx = function() {
+  E.showMenu();
+  g.clear();
+  g.reset();
+  setUI();
+  gfx();
+  backToMenu = false;
+};
+
+/*
+The functions for interacting with Android and the Spotify app
+*/
+
+simpleSearch = "";
+let simpleSearchTerm = function() { // input a simple search term without tags, overrides search with tags (artist and track)
+  require("textinput").input({text:simpleSearch}).then(result => {simpleSearch = result;}).then(() => {E.showMenu(searchMenu);});
+};
+
+artist = "";
+let artistSearchTerm = function() { // input artist to search for
+  require("textinput").input({text:artist}).then(result => {artist = result;}).then(() => {E.showMenu(searchMenu);});
+};
+
+track = "";
+let trackSearchTerm = function() { // input track to search for
+  require("textinput").input({text:track}).then(result => {track = result;}).then(() => {E.showMenu(searchMenu);});
+};
+
+album = "";
+let albumSearchTerm = function() { // input album to search for
+  require("textinput").input({text:album}).then(result => {album = result;}).then(() => {E.showMenu(searchMenu);});
+};
+
+let searchPlayWOTags = function() {//make a spotify search and play using entered terms
+  searchString = simpleSearch;
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.media.action.MEDIA_PLAY_FROM_SEARCH", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", target:"activity", extra:{query:searchString}, flags:["FLAG_ACTIVITY_NEW_TASK"]}));
+};
+
+let searchPlayWTags = function() {//make a spotify search and play using entered terms
+  searchString = (artist=="" ? "":("artist:\""+artist+"\"")) + ((artist!="" && track!="") ? " ":"") + (track=="" ? "":("track:\""+track+"\"")) + (((artist!="" && album!="") || (track!="" && album!="")) ? " ":"") + (album=="" ? "":(" album:\""+album+"\""));
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.media.action.MEDIA_PLAY_FROM_SEARCH", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", target:"activity", extra:{query:searchString}, flags:["FLAG_ACTIVITY_NEW_TASK"]}));
+};
+
+let playVreden = function() {//Play the track "Vreden" by Sara Parkman via spotify uri-link
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let playVredenAlternate = function() {//Play the track "Vreden" by Sara Parkman via spotify uri-link
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK"]}));
+};
+
+let searchPlayVreden = function() {//Play the track "Vreden" by Sara Parkman via search and play
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.media.action.MEDIA_PLAY_FROM_SEARCH", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", target:"activity", extra:{query:'artist:"Sara Parkman" track:"Vreden"'}, flags:["FLAG_ACTIVITY_NEW_TASK"]}));
+};
+
+let openAlbum = function() {//Play EP "The Blue Room" by Coldplay
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:album:3MVb2CWB36x7VwYo5sZmf2", target:"activity", flags:["FLAG_ACTIVITY_NEW_TASK"]}));
+};
+
+let searchPlayAlbum = function() {//Play EP "The Blue Room" by Coldplay via search and play
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.media.action.MEDIA_PLAY_FROM_SEARCH", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", target:"activity", extra:{query:'album:"The blue room" artist:"Coldplay"', "android.intent.extra.focus":"vnd.android.cursor.item/album"}, flags:["FLAG_ACTIVITY_NEW_TASK"]}));
+};
+
+let spotifyWidget = function(action) {
+  Bluetooth.println(JSON.stringify({t:"intent", action:("com.spotify.mobile.android.ui.widget."+action), package:"com.spotify.music", target:"broadcastreceiver"}));
+};
+
+let gadgetbridgeWake = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", target:"activity", flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_CLEAR_TASK", "FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS", "FLAG_ACTIVITY_NO_ANIMATION"], package:"gadgetbridge", class:"nodomain.freeyourgadget.gadgetbridge.activities.WakeActivity"}));
+};
+
+let spotifyPlaylistDW = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZEVXcRfaeEbxXIgb:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistDM1 = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZF1E365VyzxE0mxF:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistDM2 = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZF1E38LZHLFnrM61:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistDM3 = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZF1E36RU87qzgBFP:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistDM4 = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZF1E396gGyCXEBFh:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistDM5 = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZF1E37a0Tt6CKJLP:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistDM6 = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZF1E36UIQLQK79od:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistDD = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZF1EfWFiI7QfIAKq:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+let spotifyPlaylistRR = function() {
+  Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", categories:["android.intent.category.DEFAULT"], package:"com.spotify.music", data:"spotify:user:spotify:playlist:37i9dQZEVXbs0XkE2V8sMO:play", target:"activity" , flags:["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_NO_ANIMATION"/*,  "FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_PREVIOUS_IS_TOP"*/]}));
+};
+
+// Spotify Remote Menu
+let spotifyMenu = {
+  "" : { title : " Menu ",
+        back: backToGfx },
+  "Controls" : ()=>{E.showMenu(controlMenu);},
+  "Search and play" : ()=>{E.showMenu(searchMenu);},
+  "Saved music" : ()=>{E.showMenu(savedMenu);},
+  "Wake the android" : function() {gadgetbridgeWake();gadgetbridgeWake();},
+  "Exit Spotify Remote" : ()=>{load();}
+};
+
+
+let controlMenu = {
+  "" : { title : " Controls ",
+        back: () => {if (backToMenu) E.showMenu(spotifyMenu);
+                     if (!backToMenu) backToGfx();} },
+  "Play" : ()=>{Bangle.musicControl("play");},
+  "Pause" : ()=>{Bangle.musicControl("pause");},
+  "Previous" : ()=>{spotifyWidget("PREVIOUS");},
+  "Next" : ()=>{spotifyWidget("NEXT");},
+  "Play (widget, next then previous)" : ()=>{spotifyWidget("NEXT"); spotifyWidget("PREVIOUS");},
+  "Messages Music Controls" : ()=>{load("messagesmusic.app.js");},
+};
+
+let searchMenu = {
+  "" : { title : " Search ",
+        back: () => {if (backToMenu) E.showMenu(spotifyMenu);
+                     if (!backToMenu) backToGfx();} },
+  "Search term w/o tags" : ()=>{simpleSearchTerm();},
+  "Execute search and play w/o tags" : ()=>{searchPlayWOTags();},
+  "Search term w tag \"artist\"" : ()=>{artistSearchTerm();},
+  "Search term w tag \"track\"" : ()=>{trackSearchTerm();},
+  "Search term w tag \"album\"" : ()=>{albumSearchTerm();},
+  "Execute search and play with tags" : ()=>{searchPlayWTags();},
+};
+
+let savedMenu = {
+  "" : { title : " Saved ",
+        back: () => {if (backToMenu) E.showMenu(spotifyMenu);
+                     if (!backToMenu) backToGfx();} },
+  "Play Discover Weekly" : ()=>{spotifyPlaylistDW();},
+  "Play Daily Mix 1" : ()=>{spotifyPlaylistDM1();},
+  "Play Daily Mix 2" : ()=>{spotifyPlaylistDM2();},
+  "Play Daily Mix 3" : ()=>{spotifyPlaylistDM3();},
+  "Play Daily Mix 4" : ()=>{spotifyPlaylistDM4();},
+  "Play Daily Mix 5" : ()=>{spotifyPlaylistDM5();},
+  "Play Daily Mix 6" : ()=>{spotifyPlaylistDM6();},
+  "Play Daily Drive" : ()=>{spotifyPlaylistDD();},
+  "Play Release Radar" : ()=>{spotifyPlaylistRR();},
+  "Play \"Vreden\" by Sara Parkman via uri-link" : ()=>{playVreden();},
+  "Open \"The Blue Room\" EP (no autoplay)" : ()=>{openAlbum();},
+  "Play \"The Blue Room\" EP via search&play" : ()=>{searchPlayAlbum();},
+};
+
+Bangle.loadWidgets();
+setUI();
+gfx();
+}
diff --git a/apps/spotrem/app.png b/apps/spotrem/app.png
new file mode 100644
index 000000000..3c0d65eee
Binary files /dev/null and b/apps/spotrem/app.png differ
diff --git a/apps/spotrem/metadata.json b/apps/spotrem/metadata.json
new file mode 100644
index 000000000..5818d9aee
--- /dev/null
+++ b/apps/spotrem/metadata.json
@@ -0,0 +1,17 @@
+{
+  "id": "spotrem",
+  "name": "Remote for Spotify",
+  "version": "0.07",
+  "description": "Control spotify on your android device.",
+  "readme": "README.md",
+  "type": "app",
+  "tags": "spotify,music,player,remote,control,intent,intents,gadgetbridge,spotrem",
+  "icon": "app.png",
+  "screenshots" : [ {"url":"screenshot1.png"}, {"url":"screenshot2.png"} ],
+  "supports": ["BANGLEJS2"],
+  "dependencies": { "textinput":"type"},
+  "storage": [
+    {"name":"spotrem.app.js","url":"app.js"},
+    {"name":"spotrem.img","url":"app-icon.js","evaluate":true}
+  ]
+}
diff --git a/apps/spotrem/screenshot1.png b/apps/spotrem/screenshot1.png
new file mode 100644
index 000000000..730e98547
Binary files /dev/null and b/apps/spotrem/screenshot1.png differ
diff --git a/apps/spotrem/screenshot2.png b/apps/spotrem/screenshot2.png
new file mode 100644
index 000000000..7801a3034
Binary files /dev/null and b/apps/spotrem/screenshot2.png differ
diff --git a/apps/stardateclock/ChangeLog b/apps/stardateclock/ChangeLog
index 1b1719352..bb6430b65 100644
--- a/apps/stardateclock/ChangeLog
+++ b/apps/stardateclock/ChangeLog
@@ -1,2 +1,3 @@
 0.01: Initial release on the app repository for Bangle.js 1 and 2
 0.02: Fixed let/const usage while using firmware version >=2v14
+0.03: Tell clock widgets to hide.
diff --git a/apps/stardateclock/app.js b/apps/stardateclock/app.js
index cdc730970..adf2c14c7 100644
--- a/apps/stardateclock/app.js
+++ b/apps/stardateclock/app.js
@@ -334,10 +334,10 @@ updateStardate();
 updateConventionalTime();
 // Make sure widgets can be shown.
 //g.setColor("#FF0000"); g.fillRect(0, 0, g.getWidth(), widgetsHeight); // debug
-Bangle.loadWidgets();
-Bangle.drawWidgets();
 // Show launcher on button press as usual for a clock face
 Bangle.setUI("clock", Bangle.showLauncher);
+Bangle.loadWidgets();
+Bangle.drawWidgets();
 // Stop updates when LCD is off, restart when on
 Bangle.on('lcdPower', on => {
   if (on) {
diff --git a/apps/stardateclock/metadata.json b/apps/stardateclock/metadata.json
index 9569d3a53..d27b14512 100644
--- a/apps/stardateclock/metadata.json
+++ b/apps/stardateclock/metadata.json
@@ -3,7 +3,7 @@
   "name":"Stardate Clock",
   "shortName":"Stardate Clock",
   "description": "A clock displaying a stardate along with a 'standard' digital/analog clock in LCARS design",
-  "version":"0.02",
+  "version":"0.03",
   "icon": "app.png",
   "type":"clock",
   "tags": "clock",
diff --git a/apps/stlap/ChangeLog b/apps/stlap/ChangeLog
new file mode 100644
index 000000000..35ba8b130
--- /dev/null
+++ b/apps/stlap/ChangeLog
@@ -0,0 +1,3 @@
+0.01: New app!
+0.02: Bug fixes
+0.03: Submitted to the app loader
\ No newline at end of file
diff --git a/apps/stlap/app.js b/apps/stlap/app.js
new file mode 100644
index 000000000..0bd18311f
--- /dev/null
+++ b/apps/stlap/app.js
@@ -0,0 +1,304 @@
+const storage = require("Storage");
+const heatshrink = require("heatshrink");
+const STATE_PATH = "stlap.state.json";
+g.setFont("Vector", 24);
+const BUTTON_ICONS = {
+  play: heatshrink.decompress(atob("jEYwMAkAGBnACBnwCBn+AAQPgAQPwAQP8AQP/AQXAAQPwAQP8AQP+AQgICBwQUCEAn4FggyBHAQ+CIgQ")),
+  pause: heatshrink.decompress(atob("jEYwMA/4BBAX4CEA")),
+  reset: heatshrink.decompress(atob("jEYwMA/4BB/+BAQPDAQPnAQIAKv///0///8j///EP//wAQQICBwQUCEhgyCHAQ+CIgI="))
+};
+
+let state = storage.readJSON(STATE_PATH);
+const STATE_DEFAULT = {
+  wasRunning: false,              //If the stopwatch was ever running since being reset
+  sessionStart: 0,                //When the stopwatch was first started
+  running: false,                 //Whether the stopwatch is currently running
+  startTime: 0,                   //When the stopwatch was last started.
+  pausedTime: 0,                  //When the stopwatch was last paused.
+  elapsedTime: 0                  //How much time was spent running before the current start time. Update on pause.
+};
+if (!state) {
+  state = STATE_DEFAULT;
+}
+
+let lapFile;
+let lapHistory;
+if (state.wasRunning) {
+  lapFile = 'stlap-' + state.sessionStart + '.json';
+  lapHistory = storage.readJSON(lapFile);
+  if (!lapHistory)
+    lapHistory = {
+      final: false, //Whether the stopwatch has been reset. It is expected that the stopwatch app will create a final split when reset. If this is false, it is expected that this hasn't been done, and that the current time should be used as the "final split"
+      splits: []  //List of times when the Lap button was pressed
+    };
+} else
+  lapHistory = {
+    final: false, //Whether the stopwatch has been reset. It is expected that the stopwatch app will create a final split when reset. If this is false, it is expected that this hasn't been done, and that the current time should be used as the "final split"
+    splits: []  //List of times when the Lap button was pressed
+  };
+
+//Get the number of milliseconds that stopwatch has run for
+function getTime() {
+  if (!state.wasRunning) {
+    //If the timer never ran, zero ms have passed
+    return 0;
+  } else if (state.running) {
+    //If the timer is running, the time left is current time - start time + preexisting time
+    return (new Date()).getTime() - state.startTime + state.elapsedTime;
+  } else {
+    //If the timer is not running, the same as above but use when the timer was paused instead of now.
+    return state.pausedTime - state.startTime + state.elapsedTime;
+  }
+}
+
+let gestureMode = false;
+
+function drawButtons() {
+  //Draw the backdrop
+  const BAR_TOP = g.getHeight() - 48;
+  const BUTTON_Y = BAR_TOP + 12;
+  const BUTTON_LEFT = g.getWidth() / 4 - 12;    //For the buttons, we have to subtract 12 because images do not obey alignment, but their size is known in advance
+  const TEXT_LEFT = g.getWidth() / 4;           //For text, we do not have to subtract 12 because they do obey alignment.
+  const BUTTON_MID = g.getWidth() / 2 - 12;
+  const TEXT_MID = g.getWidth() / 2;
+  const BUTTON_RIGHT = g.getHeight() * 3 / 4 - 12;
+
+  g.setColor(0, 0, 1).setFontAlign(0, -1)
+    .clearRect(0, BAR_TOP, g.getWidth(), g.getHeight())
+    .fillRect(0, BAR_TOP, g.getWidth(), g.getHeight())
+    .setColor(1, 1, 1);
+
+  if (gestureMode)
+    g.setFont('Vector', 16)
+      .drawString('Button: Lap/Reset\nSwipe: Start/stop\nTap: Light', TEXT_MID, BAR_TOP);
+  else {
+    g.setFont('Vector', 24);
+    if (!state.wasRunning) {  //If the timer was never running:
+      if (storage.read('stlapview.app.js') !== undefined)         //If stlapview is installed, there should be a button to open it and a button to start the timer
+        g.drawLine(g.getWidth() / 2, BAR_TOP, g.getWidth() / 2, g.getHeight())
+          .drawString("Laps", TEXT_LEFT, BUTTON_Y)
+          .drawImage(BUTTON_ICONS.play, BUTTON_RIGHT, BUTTON_Y);
+      else g.drawImage(BUTTON_ICONS.play, BUTTON_MID, BUTTON_Y);  //Otherwise, only a button to start the timer
+    } else {                  //If the timer was running:
+      g.drawLine(g.getWidth() / 2, BAR_TOP, g.getWidth() / 2, g.getHeight());
+      if (state.running) {    //If it is running now, have a lap button and a pause button
+        g.drawString("LAP", TEXT_LEFT, BUTTON_Y)
+          .drawImage(BUTTON_ICONS.pause, BUTTON_RIGHT, BUTTON_Y);
+      } else {                //If it is not running now, have a reset button and a
+        g.drawImage(BUTTON_ICONS.reset, BUTTON_LEFT, BUTTON_Y)
+          .drawImage(BUTTON_ICONS.play, BUTTON_RIGHT, BUTTON_Y);
+      }
+    }
+  }
+}
+
+function drawTime() {
+  function pad(number) {
+    return ('00' + parseInt(number)).slice(-2);
+  }
+
+  let time = getTime();
+  g.reset(0, 0, 0)
+    .setFontAlign(0, 0)
+    .setFont("Vector", 36)
+    .clearRect(0, 24, g.getWidth(), g.getHeight() - 48)
+
+    //Draw the time
+    .drawString((() => {
+      let hours = Math.floor(time / 3600000);
+      let minutes = Math.floor((time % 3600000) / 60000);
+      let seconds = Math.floor((time % 60000) / 1000);
+      let hundredths = Math.floor((time % 1000) / 10);
+
+      if (hours >= 1) return `${hours}:${pad(minutes)}:${pad(seconds)}`;
+      else return `${minutes}:${pad(seconds)}:${pad(hundredths)}`;
+    })(), g.getWidth() / 2, g.getHeight() / 2);
+
+  //Draw the lap labels if necessary
+  if (lapHistory.splits.length >= 1) {
+    let lastLap = lapHistory.splits.length;
+    let curLap = lastLap + 1;
+
+    g.setFont("Vector", 12)
+      .drawString((() => {
+        let lapTime = time - lapHistory.splits[lastLap - 1];
+        let hours = Math.floor(lapTime / 3600000);
+        let minutes = Math.floor((lapTime % 3600000) / 60000);
+        let seconds = Math.floor((lapTime % 60000) / 1000);
+        let hundredths = Math.floor((lapTime % 1000) / 10);
+
+        if (hours == 0) return `Lap ${curLap}: ${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`;
+        else return `Lap ${curLap}: ${hours}:${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`;
+      })(), g.getWidth() / 2, g.getHeight() / 2 + 18)
+      .drawString((() => {
+        let lapTime;
+        if (lastLap == 1) lapTime = lapHistory.splits[lastLap - 1];
+        else lapTime = lapHistory.splits[lastLap - 1] - lapHistory.splits[lastLap - 2];
+        let hours = Math.floor(lapTime / 3600000);
+        let minutes = Math.floor((lapTime % 3600000) / 60000);
+        let seconds = Math.floor((lapTime % 60000) / 1000);
+        let hundredths = Math.floor((lapTime % 1000) / 10);
+
+        if (hours == 0) return `Lap ${lastLap}: ${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`;
+        else return `Lap ${lastLap}: ${hours}:${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`;
+      })(), g.getWidth() / 2, g.getHeight() / 2 + 30);
+  }
+}
+
+drawButtons();
+
+function firstTimeStart(now, time) {
+  state = {
+    wasRunning: true,
+    sessionStart: Math.floor(now),
+    running: true,
+    startTime: now,
+    pausedTime: 0,
+    elapsedTime: 0,
+  };
+  lapFile = 'stlap-' + state.sessionStart + '.json';
+  setupTimerInterval();
+  Bangle.buzz(200);
+  drawButtons();
+}
+
+function split(now, time) {
+  lapHistory.splits.push(time);
+  Bangle.buzz();
+}
+
+function pause(now, time) {
+  //Record the exact moment that we paused
+  state.pausedTime = now;
+
+  //Stop the timer
+  state.running = false;
+  stopTimerInterval();
+  Bangle.buzz(200);
+  drawTime();
+  drawButtons();
+}
+
+function reset(now, time) {
+  //Record the time
+  lapHistory.splits.push(time);
+  lapHistory.final = true;
+  storage.writeJSON(lapFile, lapHistory);
+
+  //Reset the timer
+  state = STATE_DEFAULT;
+  lapHistory = {
+    final: false,
+    splits: []
+  };
+  Bangle.buzz(500);
+  drawTime();
+  drawButtons();
+}
+
+function start(now, time) {
+  //Start the timer and record when we started
+  state.elapsedTime += (state.pausedTime - state.startTime);
+  state.startTime = now;
+  state.running = true;
+  setupTimerInterval();
+  Bangle.buzz(200);
+  drawTime();
+  drawButtons();
+}
+
+Bangle.on("touch", (button, xy) => {
+  //In gesture mode, just turn on the light and then return
+  if (gestureMode) {
+    Bangle.setLCDPower(true);
+    return;
+  }
+
+  //If we support full touch and we're not touching the keys, ignore.
+  //If we don't support full touch, we can't tell so just assume we are.
+  if (xy !== undefined && xy.y <= g.getHeight() - 48) return;
+
+  let now = (new Date()).getTime();
+  let time = getTime();
+
+  if (!state.wasRunning) {
+    if (storage.read('stlapview.app.js') !== undefined) {
+      //If we were never running and stlapview is installed, there are two buttons: open stlapview and start the timer
+      if (button == 1) load('stlapview.app.js');
+      else firstTimeStart(now, time);
+    }
+    //If stlapview there is only one button: the start button
+    else firstTimeStart(now, time);
+  } else if (state.running) {
+    //If we are running, there are two buttons: lap and pause
+    if (button == 1) split(now, time);
+    else pause(now, time);
+
+  } else {
+    //If we are stopped, there are two buttons: reset and continue
+    if (button == 1) reset(now, time);
+    else start(now, time);
+  }
+});
+
+Bangle.on('swipe', direction => {
+  let now = (new Date()).getTime();
+  let time = getTime();
+
+  if (gestureMode) {
+    Bangle.setLCDPower(true);
+    if (!state.wasRunning) firstTimeStart(now, time);
+    else if (state.running) pause(now, time);
+    else start(now, time);
+  } else {
+    gestureMode = true;
+    Bangle.setOptions({
+      lockTimeout: 0
+    });
+    drawTime();
+    drawButtons();
+  }
+});
+
+setWatch(() => {
+  let now = (new Date()).getTime();
+  let time = getTime();
+
+  if (gestureMode) {
+    Bangle.setLCDPower(true);
+    if (state.running) split(now, time);
+    else reset(now, time);
+  }
+}, BTN1, { repeat: true });
+
+let timerInterval;
+
+function setupTimerInterval() {
+  if (timerInterval !== undefined) {
+    clearInterval(timerInterval);
+  }
+  timerInterval = setInterval(drawTime, 10);
+}
+
+function stopTimerInterval() {
+  if (timerInterval !== undefined) {
+    clearInterval(timerInterval);
+    timerInterval = undefined;
+  }
+}
+
+drawTime();
+if (state.running) {
+  setupTimerInterval();
+}
+
+//Save our state when the app is closed
+E.on('kill', () => {
+  storage.writeJSON(STATE_PATH, state);
+  if (state.wasRunning) {
+    storage.writeJSON(lapFile, lapHistory);
+  }
+});
+
+Bangle.loadWidgets();
+Bangle.drawWidgets();
\ No newline at end of file
diff --git a/apps/stlap/icon.js b/apps/stlap/icon.js
new file mode 100644
index 000000000..eb0ec64c7
--- /dev/null
+++ b/apps/stlap/icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwwcCpMkyQCCB4oLFAQsf/4AC/ARvIYM//hHNAQIRBBxgRliQECCJgHFCJWJA4slCJEiDI+UIhYCFAw1IJ5NSAwtECI8/yVKNBYCC/5uGyIRHp/8AoMpCJvkCIyMGAQN/CISSECI+T/6kHPQ+f/IFD0gRL5IRP/4RHag8n/zaHCI8/+QRQfxARHYQQRNYQYROWAQ1OAQwR4YpACFa5YRbxIRLkoGDCKORCJcpCKuSCJYGFogRJpQGFpARJqQJGiQRIDY7aIagYCFSQyMEAQxoLJRQLG"))
\ No newline at end of file
diff --git a/apps/stlap/icon.png b/apps/stlap/icon.png
new file mode 100644
index 000000000..6b9ba85bb
Binary files /dev/null and b/apps/stlap/icon.png differ
diff --git a/apps/stlap/img/pause.png b/apps/stlap/img/pause.png
new file mode 100644
index 000000000..ad31dadcf
Binary files /dev/null and b/apps/stlap/img/pause.png differ
diff --git a/apps/stlap/img/play.png b/apps/stlap/img/play.png
new file mode 100644
index 000000000..6c20c24c5
Binary files /dev/null and b/apps/stlap/img/play.png differ
diff --git a/apps/stlap/img/reset.png b/apps/stlap/img/reset.png
new file mode 100644
index 000000000..7a317d097
Binary files /dev/null and b/apps/stlap/img/reset.png differ
diff --git a/apps/stlap/metadata.json b/apps/stlap/metadata.json
new file mode 100644
index 000000000..1ecdc5b6e
--- /dev/null
+++ b/apps/stlap/metadata.json
@@ -0,0 +1,24 @@
+{
+  "id": "stlap",
+  "name": "Stopwatch",
+  "version": "0.03",
+  "description": "A stopwatch that remembers its state, with a lap timer and a gesture mode (enable by swiping)",
+  "icon": "icon.png",
+  "type": "app",
+  "tags": "tools,app",
+  "supports": [
+    "BANGLEJS2"
+  ],
+  "allow_emulator": true,
+  "storage": [
+    {
+      "name": "stlap.app.js",
+      "url": "app.js"
+    },
+    {
+      "name": "stlap.img",
+      "url": "icon.js",
+      "evaluate": true
+    }
+  ]
+}
\ No newline at end of file
diff --git a/apps/stlapview/ChangeLog b/apps/stlapview/ChangeLog
new file mode 100644
index 000000000..c819919ed
--- /dev/null
+++ b/apps/stlapview/ChangeLog
@@ -0,0 +1,2 @@
+0.01: New app!
+0.02: Submitted to the app loader
\ No newline at end of file
diff --git a/apps/stlapview/app.js b/apps/stlapview/app.js
new file mode 100644
index 000000000..7a58b5782
--- /dev/null
+++ b/apps/stlapview/app.js
@@ -0,0 +1,110 @@
+const storage = require("Storage");
+
+Bangle.loadWidgets();
+Bangle.drawWidgets();
+
+function pad(number) {
+  return ('00' + parseInt(number)).slice(-2);
+}
+
+function fileNameToDateString(fileName) {
+  let timestamp = 0;
+  let foundDigitYet = false;
+  for (let character of fileName) {
+    if ('1234567890'.includes(character)) {
+      foundDigitYet = true;
+      timestamp *= 10;
+      timestamp += parseInt(character);
+    } else if (foundDigitYet) break;
+  }
+  let date = new Date(timestamp);
+
+  let dayOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()];
+  let completed = storage.readJSON(fileName).final;
+
+  return `${dayOfWeek} ${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}` + (completed ? '' : ' (running)');
+}
+
+function msToHumanReadable(ms) {
+
+  let hours = Math.floor(ms / 3600000);
+  let minutes = Math.floor((ms % 3600000) / 60000);
+  let seconds = Math.floor((ms % 60000) / 1000);
+  let hundredths = Math.floor((ms % 1000) / 10);
+
+  return `${hours}:${pad(minutes)}:${pad(seconds)}:${pad(hundredths)}`;
+}
+
+function view(fileName) {
+  let lapTimes = [];
+  let fileData = storage.readJSON(fileName).splits;
+  for (let i = 0; i < fileData.length; i++) {
+    if (i == 0) lapTimes.push(fileData[i]);
+    else lapTimes.push(fileData[i] - fileData[i - 1]);
+  }
+
+  let fastestIndex = 0;
+  let slowestIndex = 0;
+  for (let i = 0; i < lapTimes.length; i++) {
+    if (lapTimes[i] < lapTimes[fastestIndex]) fastestIndex = i;
+    else if (lapTimes[i] > lapTimes[slowestIndex]) slowestIndex = i;
+  }
+
+  let lapMenu = {
+    '': {
+      'title': fileNameToDateString(fileName),
+      'back': () => { E.showMenu(mainMenu); }
+    },
+  };
+  lapMenu[`Total time: ${msToHumanReadable(fileData[fileData.length - 1])}`] = () => { };
+  lapMenu[`Fastest lap: ${fastestIndex + 1}: ${msToHumanReadable(lapTimes[fastestIndex])}`] = () => { };
+  lapMenu[`Slowest lap: ${slowestIndex + 1}: ${msToHumanReadable(lapTimes[slowestIndex])}`] = () => { };
+  lapMenu[`Average lap: ${msToHumanReadable(fileData[fileData.length - 1] / fileData.length)}`] = () => { };
+
+  for (let i = 0; i < lapTimes.length; i++) {
+    lapMenu[`Lap ${i + 1}: ${msToHumanReadable(lapTimes[i])}`] = () => { };
+  }
+
+  lapMenu.Delete = () => {
+    E.showMenu({
+      '': {
+        'title': 'Are you sure?',
+        'back': () => { E.showMenu(lapMenu); }
+      },
+      'Yes': () => {
+        storage.erase(fileName);
+        showMainMenu();
+      },
+      'No': () => { E.showMenu(lapMenu); }
+    });
+  };
+
+  E.showMenu(lapMenu);
+}
+
+function showMainMenu() {
+  let LAP_FILES = storage.list(/stlap-[0-9]*\.json/);
+  LAP_FILES.sort();
+  LAP_FILES.reverse();
+
+  let mainMenu = {
+    '': {
+      'title': 'Sessions'
+    }
+  };
+
+  //I know eval is evil, but I can't think of any other way to do this.
+  for (let lapFile of LAP_FILES) {
+    mainMenu[fileNameToDateString(lapFile)] = eval(`(function() {
+      view('${lapFile}');
+    })`);
+  }
+
+  if (LAP_FILES.length == 0) {
+    mainMenu['No data'] = _ => { load(); };
+  }
+
+  E.showMenu(mainMenu);
+}
+
+showMainMenu();
\ No newline at end of file
diff --git a/apps/stlapview/icon.js b/apps/stlapview/icon.js
new file mode 100644
index 000000000..9e10b10a8
--- /dev/null
+++ b/apps/stlapview/icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwwcCpMkyQCCB4oLFAQsf/4AC/ARvIYM//hHNAQIRBBxgRliQECCJgHFCJWJA4slCJEiDI+UIhYCFAw1IJ5NSAwtECI8/yVKNBOQYYMCpP/Nw2RAgYQBAAMP/gIBlIRHCAYAB8gRGRgVICIsESQwRCoANBA4OAAgIRGJgQRBSQWeCIck0gRFBYmf4AXDCI5BCkn/5ARGagSMBCIUn/xfBSQLaDCIiwD+SDBCJyVCCJrCCCJtPYQQROYQQ1OboYRKR4bdCCJChFCIShCCI7FDbooRCdJAXFa4wRBgAFBwARLIIIAFfY2JO4YAFNYMlQ4YRDkgSGCIuRAgaSBEAI7ChMpCJCzFgEBCImSCJEgCQPpBIlECI5NCjoJEpARISQMDPoYCBWAYCEL4V0BIjaDAQmeCI6SFAQMlkvACI5uGAYO4CJBKEBAWX//0yQ="))
\ No newline at end of file
diff --git a/apps/stlapview/icon.png b/apps/stlapview/icon.png
new file mode 100644
index 000000000..be24b8e6f
Binary files /dev/null and b/apps/stlapview/icon.png differ
diff --git a/apps/stlapview/metadata.json b/apps/stlapview/metadata.json
new file mode 100644
index 000000000..aa54a7b67
--- /dev/null
+++ b/apps/stlapview/metadata.json
@@ -0,0 +1,27 @@
+{
+  "id": "stlapview",
+  "name": "Stopwatch laps",
+  "version": "0.02",
+  "description": "Optional lap viewer for my stopwatch app",
+  "icon": "icon.png",
+  "type": "app",
+  "tags": "tools,app",
+  "supports": [
+    "BANGLEJS2"
+  ],
+  "allow_emulator": true,
+  "storage": [
+    {
+      "name": "stlapview.app.js",
+      "url": "app.js"
+    },
+    {
+      "name": "stlapview.img",
+      "url": "icon.js",
+      "evaluate": true
+    }
+  ],
+  "dependencies": {
+    "stlap": "app"
+  }
+}
\ No newline at end of file
diff --git a/apps/sunclock/ChangeLog b/apps/sunclock/ChangeLog
new file mode 100644
index 000000000..d63f1567e
--- /dev/null
+++ b/apps/sunclock/ChangeLog
@@ -0,0 +1,2 @@
+0.01: First commit
+0.02: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps
diff --git a/apps/sunclock/app.js b/apps/sunclock/app.js
index 4609565a2..1685bc218 100644
--- a/apps/sunclock/app.js
+++ b/apps/sunclock/app.js
@@ -9,8 +9,8 @@ SunCalc = require("suncalc.js");
 loc = require('locale');
 const LOCATION_FILE = "mylocation.json";
 const xyCenter = g.getWidth() / 2 + 3;
-const yposTime =  60; 
-const yposDate = 100; 
+const yposTime =  60;
+const yposDate = 100;
 const yposRS   = 135;
 const yposPos  = 160;
 var rise = "07:00";
@@ -19,13 +19,21 @@ var pos     = {altitude: 20, azimuth: 135};
 var noonpos = {altitude: 37, azimuth: 180};
 let idTimeout = null;
 
+
+
 function updatePos() {
+  function radToDeg(pos) {
+    return { // instead of mofidying suncalc
+        azimuth:  Math.round((pos.azimuth / rad + 180) % 360),
+        altitude: Math.round( pos.altitude / rad)
+    };
+  }
   coord = require("Storage").readJSON(LOCATION_FILE,1)|| {"lat":53.3,"lon":10.1,"location":"Pattensen"};
-  pos = SunCalc.getPosition(Date.now(), coord.lat, coord.lon);  
+  pos = radToDeg(SunCalc.getPosition(Date.now(), coord.lat, coord.lon));
   times = SunCalc.getTimes(Date.now(), coord.lat, coord.lon);
   rise = times.sunrise.toString().split(" ")[4].substr(0,5);
   set  = times.sunset.toString().split(" ")[4].substr(0,5);
-  noonpos = SunCalc.getPosition(times.solarNoon, coord.lat, coord.lon);
+  noonpos = radToDeg(SunCalc.getPosition(times.solarNoon, coord.lat, coord.lon));
 }
 
 function drawSimpleClock() {
@@ -38,7 +46,7 @@ function drawSimpleClock() {
 
   var time = da[4].substr(0, 5); // draw time
 
-  g.setFont("Vector",60); 
+  g.setFont("Vector",60);
   g.drawString(time, xyCenter, yposTime, true);
 
   var date = [loc.dow(new Date(),1), loc.date(d,1)].join(" "); // draw day of week, date
@@ -51,7 +59,7 @@ function drawSimpleClock() {
 
   g.setFont("Vector",21);
   g.drawString(`H${pos.altitude}/${noonpos.altitude} Az${pos.azimuth}`, xyCenter, yposPos, true); // draw sun pos
-    
+
   let t = d.getSeconds()*1000 + d.getMilliseconds();
   idTimeout = setTimeout(drawSimpleClock, 60000 - t); // time till next minute
 }
diff --git a/apps/sunclock/metadata.json b/apps/sunclock/metadata.json
index 617d76821..a9155f6f6 100644
--- a/apps/sunclock/metadata.json
+++ b/apps/sunclock/metadata.json
@@ -1,7 +1,7 @@
 {
   "id": "sunclock",
   "name": "Sun Clock",
-  "version": "0.01",
+  "version": "0.02",
   "description": "A clock with sunset/sunrise, sun height/azimuth",
   "icon": "app.png",
   "type": "clock",
@@ -11,7 +11,6 @@
   "allow_emulator": true,
   "storage": [
     {"name":"sunclock.app.js","url":"app.js"},
-    {"name":"sunclock.img","url":"app-icon.js","evaluate":true},
-    {"name":"suncalc.js","url":"suncalc.js"}
+    {"name":"sunclock.img","url":"app-icon.js","evaluate":true}
   ]
 }
diff --git a/apps/swiperclocklaunch/ChangeLog b/apps/swiperclocklaunch/ChangeLog
index 244b602b5..e7ad4555c 100644
--- a/apps/swiperclocklaunch/ChangeLog
+++ b/apps/swiperclocklaunch/ChangeLog
@@ -1,3 +1,4 @@
 0.01: New App!
 0.02: Fix issue with mode being undefined
 0.03: Update setUI to work with new Bangle.js 2v13 menu style
+0.04: Update to work with new 'fast switch' clock->launcher functionality
diff --git a/apps/swiperclocklaunch/boot.js b/apps/swiperclocklaunch/boot.js
index bb285ea94..ea00a6735 100644
--- a/apps/swiperclocklaunch/boot.js
+++ b/apps/swiperclocklaunch/boot.js
@@ -1,19 +1,19 @@
-// clock -> launcher
 (function() {
-    var sui = Bangle.setUI;
-    Bangle.setUI = function(mode, cb) {
-        sui(mode,cb);
-        if(!mode) return;
-        if ("object"==typeof mode) mode = mode.mode;
-        if (!mode.startsWith("clock")) return;
-        Bangle.swipeHandler = dir => { if (dir<0) Bangle.showLauncher(); };
-        Bangle.on("swipe", Bangle.swipeHandler);
-    };
-})();
-// launcher -> clock
-setTimeout(function() {  
-    if (global.__FILE__ && __FILE__.endsWith(".app.js") && (require("Storage").readJSON(__FILE__.slice(0,-6)+"info",1)||{}).type=="launch") {
+  var sui = Bangle.setUI;
+  Bangle.setUI = function(mode, cb) {
+    sui(mode,cb);
+    if(!mode) return;
+    if ("object"==typeof mode) mode = mode.mode;
+    if (mode.startsWith("clock")) {
+      // clock -> launcher
+      Bangle.swipeHandler = dir => { if (dir<0) Bangle.showLauncher(); };
+      Bangle.on("swipe", Bangle.swipeHandler);
+    } else {
+      if (global.__FILE__ && __FILE__.endsWith(".app.js") && (require("Storage").readJSON(__FILE__.slice(0,-6)+"info",1)||{}).type=="launch") {
+        // launcher -> clock
         Bangle.swipeHandler = dir => { if (dir>0) load(); };
         Bangle.on("swipe", Bangle.swipeHandler);
+      }
     }
-}, 10);
+  };
+})();
diff --git a/apps/swiperclocklaunch/metadata.json b/apps/swiperclocklaunch/metadata.json
index 5e4a0d648..4f27da528 100644
--- a/apps/swiperclocklaunch/metadata.json
+++ b/apps/swiperclocklaunch/metadata.json
@@ -1,7 +1,7 @@
 {
   "id": "swiperclocklaunch",
   "name": "Swiper Clock Launch",
-  "version": "0.03",
+  "version": "0.04",
   "description": "Navigate between clock and launcher with Swipe action",
   "icon": "swiperclocklaunch.png",
   "type": "bootloader",
diff --git a/apps/swp2clk/ChangeLog b/apps/swp2clk/ChangeLog
index ea6473980..d6f9f6e8c 100644
--- a/apps/swp2clk/ChangeLog
+++ b/apps/swp2clk/ChangeLog
@@ -1 +1,4 @@
 0.01: Initial creation of "Swipe back to the Clock" App. Let's you swipe from left to right on any app to return back to the clock face. 
+0.02: Fix deleting from white and black lists.
+0.03: Adapt to availability of Bangle.showClock and Bangle.load
+0.04: Fix 'Uncaught ReferenceError: "__FILE__" is not defined' error (fix #2326)
diff --git a/apps/swp2clk/boot.js b/apps/swp2clk/boot.js
index bb8e792c4..f2c642adf 100644
--- a/apps/swp2clk/boot.js
+++ b/apps/swp2clk/boot.js
@@ -1,109 +1,48 @@
-/**
- * How does this work?
- * 
- * Every *boot.js file is executed everytime any app is loaded, including this one.
- * We just need to figure out which app is currently loaded, in case we are in the white list / black list mode,
- * to figure out if the swipe handler should be attached or not.
- * It does not seem to be the case that this can be done easily, but we can work around it.
- * It seems that every app is loaded via the global "load" function, which takes a fileName as it's first parameter to load any app
- * or the default clock when the fileName is undefined.
- * To be able to use this for us, we wrap the global "load" function, and determine before loading the next app,
- * whether the swipe handler should be added or not, since we now know which app will be loaded.
- * Note: We cannot add the swipe handler inside the wrapped "load" function, because once the "load" function is complete
- * everything is cleaned up. That's why we merely save a flag, whether the swipe handler should be attached or not,
- * which is evaluated once this file is executed again, which will be right after the load function completes
- * (since every *boot.js file is executed everytime any app is loaded).
- */
+{
+  const DEBUG = false;
+  const FILE = "swp2clk.data.json";
 
-(function () {
-  var DEBUG = false;
-  var FILE = "swp2clk.data.json";
-
-  var main = () => {
-    var settings = readSettings();
-
-    if (settings.addSwipeHandler) {
-      var swipeHandler = (dir) => {
-        log("swipe");
-        log(dir);
-        if (dir === 1) {
-          load();
-        }
-      };
-      Bangle.on("swipe", swipeHandler);
-    }
-
-    var global_load = global.load;
-    global.load = (fileName) => {
-      log("loading filename!");
-      log(fileName);
-      var settings = readSettings();
-
-      if (fileName) {
-        // "Off"
-        if (settings.mode === 0) {
-          settings.addSwipeHandler = false;
-        }
-
-        // "White List"
-        if (settings.mode === 1) {
-          if (settings.whiteList.indexOf(fileName) >= 0) {
-            settings.addSwipeHandler = true;
-          } else {
-            settings.addSwipeHandler = false;
-          }
-        }
-
-        // "Black List"
-        if (settings.mode === 2) {
-          if (settings.blackList.indexOf(fileName) >= 0) {
-            settings.addSwipeHandler = false;
-          } else {
-            settings.addSwipeHandler = true;
-          }
-        }
-
-        // "Always"
-        if (settings.mode === 3) {
-          settings.addSwipeHandler = true;
-        }
-      } else {
-        // Clock will load
-        settings.addSwipeHandler = false;
-      }
-
-      writeSettings(settings);
-      global_load(fileName);
-    };
-  };
-
-  // lib functions
-
-  var log = (message) => {
+  let    log = (message) => {
     if (DEBUG) {
       console.log(JSON.stringify(message));
     }
   };
 
-  var readSettings = () => {
+  let readSettings = () => {
     log("reading settings");
-    var settings = require("Storage").readJSON(FILE, 1) || {
+    let settings = require("Storage").readJSON(FILE, 1) || {
       mode: 0,
       whiteList: [],
-      blackList: [],
-      addSwipeHandler: false,
+      blackList: []
     };
     log(settings);
     return settings;
   };
 
-  var writeSettings = (settings) => {
-    log("writing settings");
-    log(settings);
-    require("Storage").writeJSON(FILE, settings);
+  let settings = readSettings();
+  //inhibit is needed to filter swipes that had another handler load anything earlier than this handler was called
+  let inhibit = false;
+  Bangle.load = ( o => (f) => {
+    o(f);
+    log("inhibit caused by change to:" + f);
+    inhibit = true;
+  })(Bangle.load);
+
+  let swipeHandler = (dir) => {
+    let currentFile = global.__FILE__||"default";
+    log("swipe:" + dir + " on app: " + currentFile);
+
+    if (!inhibit && dir === 1 && !Bangle.CLOCK) {
+      log("on a not clock app " + currentFile);
+      if ((settings.mode === 1 && settings.whiteList.includes(currentFile)) || // "White List"
+      (settings.mode === 2 && !settings.blackList.includes(currentFile)) || // "Black List"
+      settings.mode === 3) { // "Always"
+        log("load clock");
+        Bangle.showClock();
+      }
+    }
+    inhibit = false;
   };
 
-  // start main function
-
-  main();
-})();
+  Bangle.on("swipe", swipeHandler);
+}
diff --git a/apps/swp2clk/metadata.json b/apps/swp2clk/metadata.json
index 8b0cce2d8..b4436bd39 100644
--- a/apps/swp2clk/metadata.json
+++ b/apps/swp2clk/metadata.json
@@ -2,7 +2,7 @@
   "id": "swp2clk",
   "name": "Swipe back to the Clock",
   "shortName": "Swipe to Clock",
-  "version": "0.01",
+  "version": "0.04",
   "description": "Let's you swipe from left to right on any app to return back to the clock face. Please configure in the settings app after installing to activate, since its disabled by default.",
   "icon": "app.png",
   "type": "bootloader",
diff --git a/apps/swp2clk/settings.js b/apps/swp2clk/settings.js
index a97b51fab..4f8db5eb8 100644
--- a/apps/swp2clk/settings.js
+++ b/apps/swp2clk/settings.js
@@ -53,6 +53,7 @@
 
     appList.forEach((app) => {
       if (settings.whiteList.indexOf(app.src) >= 0) {
+        let index = settings.whiteList.indexOf(app.src);
         whiteListMenu[app.name] = () => {
           E.showPrompt("Delete from WL?", {
             title: "Delete from WL?",
@@ -101,6 +102,7 @@
 
     appList.forEach((app) => {
       if (settings.blackList.indexOf(app.src) >= 0) {
+        let index = settings.whiteList.indexOf(app.src);
         blackListMenu[app.name] = () => {
           E.showPrompt("Delete from BL?", {
             title: "Delete from BL?",
diff --git a/apps/swscroll/ChangeLog b/apps/swscroll/ChangeLog
new file mode 100644
index 000000000..c5fc9dcb4
--- /dev/null
+++ b/apps/swscroll/ChangeLog
@@ -0,0 +1,2 @@
+0.01: Inital release.
+0.02: Rebasing on latest changes to showScroller_Q3 (https://github.com/espruino/Espruino/commit/2d3c34ef7c2b9fe2118e816aacd2e096adb99596).
diff --git a/apps/swscroll/README.md b/apps/swscroll/README.md
new file mode 100644
index 000000000..f97d59b71
--- /dev/null
+++ b/apps/swscroll/README.md
@@ -0,0 +1,9 @@
+This first release seems servicable in testing so far.
+
+To get the standard menu scrolling back, just remove this app from your Bangle.
+
+TODO:
+- Maybe have how much of "trailing space" there are after the last entry should be dynamic in size, now it's always 8 pixels which corresponds to if there are a widget field and a menu title present.
+- I want to change the size of menu entries to be a little bigger vertically. 
+
+Drag List Down icon by Icons8
diff --git a/apps/swscroll/app.png b/apps/swscroll/app.png
new file mode 100644
index 000000000..7abd582c2
Binary files /dev/null and b/apps/swscroll/app.png differ
diff --git a/apps/swscroll/boot.js b/apps/swscroll/boot.js
new file mode 100644
index 000000000..2b1b00de3
--- /dev/null
+++ b/apps/swscroll/boot.js
@@ -0,0 +1,106 @@
+E.showScroller = (function(options) {    
+  /* options = {
+    h = height
+    c = # of items
+    scroll = initial scroll position
+    scrollMin = minimum scroll amount (can be negative)
+    draw = function(idx, rect)
+    remove = function()
+    select = function(idx, touch)
+  }
+
+  returns {
+    draw  = draw all
+    drawItem(idx) = draw specific item
+  }
+  */
+if (!options) return Bangle.setUI(); // remove existing handlers
+
+Bangle.setUI({
+  mode : "custom",
+  back : options.back,
+  remove : options.remove,
+  swipe : (_,UD)=>{
+    pixels = 120;
+    var dy = UD*pixels;
+    if (s.scroll - dy > menuScrollMax)
+      dy = s.scroll - menuScrollMax-8; // Makes it so the last 'page' has the same position as previous pages. This should be done dynamically (change the static 8 to be a variable) so the offset is correct even when no widget field or title field is present.
+    if (s.scroll - dy < menuScrollMin)
+      dy = s.scroll - menuScrollMin;
+    s.scroll -= dy;
+    var oldScroll = rScroll;
+    rScroll = s.scroll &~1;
+    dy = oldScroll-rScroll;
+    if (!dy || options.c<=3) return; //options.c<=3 should maybe be dynamic, so 3 would be replaced by a variable dependent on R=Bangle.appRect. It's here so we don't try to scroll if all entries fit in the app rectangle.
+    g.reset().setClipRect(R.x,R.y,R.x2,R.y2);
+    g.scroll(0,dy);
+    var d = UD*pixels;
+    if (d < 0) {
+      g.setClipRect(R.x,R.y2-(1-d),R.x2,R.y2);
+      let i = YtoIdx(R.y2-(1-d));
+      let y = idxToY(i);
+      //print(i, options.c, options.c-i); //debugging info
+      while (y < R.y2 - (options.h*((options.c-i)<=0)) ) { //- (options.h*((options.c-i)<=0)) makes sure we don't go beyond the menu entries in the menu object "options". This has to do with "dy = s.scroll - menuScrollMax-8" above.
+        options.draw(i, {x:R.x,y:y,w:R.w,h:options.h});
+        i++;
+        y += options.h;
+      }
+    } else { // d>0
+      g.setClipRect(R.x,R.y,R.x2,R.y+d);
+      let i = YtoIdx(R.y+d);
+      let y = idxToY(i);
+      //print(i, options.c, options.c-i); //debugging info
+      while (y > R.y-options.h) {
+        options.draw(i, {x:R.x,y:y,w:R.w,h:options.h});
+        y -= options.h;
+        i--;
+      }
+    }
+    g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
+  }, touch : (_,e)=>{
+    if (e.y=0) && i {
+  g.reset().clearRect(R.x,R.y,R.x2,R.y2);
+  g.setClipRect(R.x,R.y,R.x2,R.y2);
+  var a = YtoIdx(R.y);
+  var b = Math.min(YtoIdx(R.y2),options.c-1);
+  for (var i=a;i<=b;i++)
+    options.draw(i, {x:R.x,y:idxToY(i),w:R.w,h:options.h});
+  g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
+}, drawItem : i => {
+  var y = idxToY(i);
+  g.reset().setClipRect(R.x,y,R.x2,y+options.h);
+  options.draw(i, {x:R.x,y:y,w:R.w,h:options.h});
+  g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
+}};
+var rScroll = s.scroll&~1; // rendered menu scroll (we only shift by 2 because of dither)
+s.draw(); // draw the full scroller
+g.flip(); // force an update now to make this snappier
+return s;
+})
diff --git a/apps/swscroll/metadata.json b/apps/swscroll/metadata.json
new file mode 100644
index 000000000..4edbfa2ba
--- /dev/null
+++ b/apps/swscroll/metadata.json
@@ -0,0 +1,14 @@
+{
+  "id": "swscroll",
+  "name": "Swipe menus",
+  "version": "0.02",
+  "description": "Replace built in E.showScroller to act on swipe instead of drag. Navigate menus in discrete steps instead of a continuous motion.",
+  "readme": "README.md",
+  "icon": "app.png",
+  "type": "bootloader",
+  "tags": "system",
+  "supports": ["BANGLEJS2"],
+  "storage": [
+    {"name":"swscroll.boot.js","url":"boot.js"}
+  ]
+}
diff --git a/apps/tabanchi/ChangeLog b/apps/tabanchi/ChangeLog
index 3889ade8e..4e2facf6f 100644
--- a/apps/tabanchi/ChangeLog
+++ b/apps/tabanchi/ChangeLog
@@ -1,2 +1,3 @@
 0.01: Initial implementation
 0.02: Fix app icon
+0.03: Fix clock animation issue and reduce source size
diff --git a/apps/tabanchi/app.js b/apps/tabanchi/app.js
index c87a08817..f159052b7 100644
--- a/apps/tabanchi/app.js
+++ b/apps/tabanchi/app.js
@@ -2,14 +2,18 @@
 // TABANCHI -- たばんち
 
 const scale = 6;
-let tool = -1;
 const w = g.getWidth();
 const h = g.getHeight();
+const yy = 34;
+const y = 40 - scale;
+let tool = -1;
 let hd = 1;
 let vd = 1;
 let x = 20;
 let sx = 0; // screen scroll x position
-const y = 40 - scale;
+let cacaLevel = 0;
+let cacaBirth = null;
+let angryState = 0;
 let animated = true;
 let transition = false;
 let caca = null;
@@ -22,9 +26,38 @@ let oldMode = '';
 let gameChoice = 0;
 let gameTries = 0;
 let gameWins = 0;
+let statusMode = 0;
+let lightSelect = 0;
+let lightMode = 0; // on is zero
+let frame = 0;
+
+const tama = {
+  age: 0,
+  weight: 1,
+  aspect: 6,
+  discipline: 0,
+  happy: 3,
+  sick: false,
+  hungry: 3,
+  cacas: 0,
+  // hidden
+  sickness: 0,
+  defenses: 100,
+  tummy: 100,
+  awake: 3
+};
+
 
 g.setBgColor(0);
 
+const sun = {
+  width: 8,
+  height: 8,
+  bpp: 1,
+  transparent: 1,
+  buffer: atob('773nW9rnvfc=')
+};
+
 const tama06eat0 = {
   width: 16,
   height: 16,
@@ -387,7 +420,6 @@ const caca01 = {
   buffer: atob('////v/33v7+3+f4v0HwH////')
 };
 
-// var img = hs.decompress(atob("sFggP/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A+A"));
 const tama00 = {
   width: 16,
   height: 16,
@@ -574,23 +606,6 @@ g.drawString('Loading...', 10, 10);
 egg = egg00;
 n = tama00;
 
-const tama = {
-  // visible
-  age: 0,
-  weight: 1,
-  aspect: 6,
-  discipline: 0,
-  happy: 3,
-  sick: false,
-  hungry: 3,
-  cacas: 0, // move from cacas
-  // hidden
-  sickness: 0,
-  defenses: 100,
-  tummy: 100,
-  awake: 3
-};
-
 function drawHearts (n) {
   for (i = 0; i < 4; i++) {
     const himg = (i < n) ? heart1 : heart0;
@@ -599,7 +614,6 @@ function drawHearts (n) {
 }
 
 function drawLinebar (n, arrow) { // 0-100
-  const yy = 34;
   g.drawImage(linebar, 0, yy + (scale * 8), { scale: scale });
 
   let wop = scale * 2; // (frame++%2)? scale*3:scale*2;
@@ -631,7 +645,6 @@ function drawLinebar (n, arrow) { // 0-100
 }
 
 function drawStatus () {
-  const yy = 34;
   switch (statusMode) {
     case 0:
       g.drawImage(face, scale, yy, { scale: scale });
@@ -774,11 +787,6 @@ function drawScene () {
   }
 }
 
-var statusMode = 0;
-var lightSelect = 0;
-var lightMode = 0; // on is zero
-let frame = 0;
-
 function drawAngry () {
   const one = angryState % 2;
   g.drawImage(one ? tama06no0 : tama06no1, (scale * 5), 40, { scale: scale });
@@ -833,14 +841,6 @@ function drawMedicine () { // food eating animation
   g.drawImage(tama06no0, (scale * 10), 40, { scale: scale });
 }
 
-var sun = {
-  width: 8,
-  height: 8,
-  bpp: 1,
-  transparent: 1,
-  buffer: atob('773nW9rnvfc=')
-};
-
 function drawEating () { // food eating animation
   const one = angryState % 2;
   const snack = [snack0, snack1, snack2];
@@ -953,6 +953,7 @@ function nextItem () {
   tool++;
   if (tool > 6) tool = 0;
 }
+
 function prevItem () {
   tool--;
   if (tool < 0) tool = 7;
@@ -1099,7 +1100,6 @@ function drawCaca () {
     }
   }
 }
-var angryState = 0;
 
 function animateHappy () {
   if (transition || mode == 'happy') {
@@ -1208,7 +1208,7 @@ function animateShower () {
 }
 
 function animateToGame () {
-  if (transition || mode == 'game') {
+  if (transition || mode === 'game') {
     return;
   }
   mode = 'game';
@@ -1298,14 +1298,6 @@ function button (n) {
   }
 
   if (mode == 'game') {
-    /*
-    if (gameTries > 3) {
-      mode = "";
-      gameWins = 0;
-      gameTries = 0;
-      //tama.tired++;
-    }
-    */
     switch (n) {
       case 1:
         // pick left
@@ -1345,8 +1337,7 @@ function button (n) {
           drawScene();
           break;
         case 'status':
-          if (oldMode == 'clock') {
-          } else {
+          if (oldMode != 'clock') {
             statusMode++;
             drawScene();
           }
@@ -1363,8 +1354,7 @@ function button (n) {
           animateFromClock();
           break;
         case 'status':
-          if (oldMode == 'clock') {
-          } else {
+          if (oldMode != 'clock') {
             statusMode++;
             drawScene();
           }
@@ -1433,7 +1423,6 @@ function drawGame () {
       }
       mode = oldMode;
       oldMode = '';
-    //  g.drawImage();
     } else {
       g.drawImage(one ? tama06no1 : tama06no0, (scale * 7) + sx, 40, { scale: scale });
     }
@@ -1467,7 +1456,6 @@ function drawClock () {
     const s1 = numbers[ts[1] - '0'];
     const s2 = numbers[ts[3] - '0'];
     const s3 = numbers[ts[4] - '0'];
-    const yy = 34;
     // hours
     if (s0) {
       g.drawImage(s0, wsx, yy, { scale: scale });
@@ -1515,17 +1503,11 @@ function drawClock () {
 }
 
 setInterval(function () {
-  // if (animated) {
   updateAnimation();
   drawScene();
-  // }
 }, 1000);
 
-let cacaLevel = 0;
-let cacaBirth = null;
-
-setInterval(function () {
-  // poo maker
+function pooMaker() {
   if (tama.hungry > 0 && !tama.sleep) {
     const a = 0 | (cacaLevel / tama.tummy);
     const b = 0 | ((cacaLevel + tama.hungry) / tama.tummy);
@@ -1545,9 +1527,8 @@ setInterval(function () {
     tama.awake--;
     tama.sleep = false;
   }
-}, 5000);
-
-setInterval(function () {
+}
+function sickMaker() {
   if (tama.sleep) {
     return;
   }
@@ -1569,8 +1550,10 @@ setInterval(function () {
   if (tama.sick > 0) {
     callForAttention = true;
   }
-}, 2000);
+}
 
+setInterval(pooMaker, 5e3);
+setInterval(sickMaker, 2e3);
 updateAnimation();
 
 Bangle.on('touch', function (r, s) {
@@ -1600,4 +1583,3 @@ Bangle.on('touch', function (r, s) {
     button(2);
   }
 });
-
diff --git a/apps/tabanchi/metadata.json b/apps/tabanchi/metadata.json
index 335dd0326..f72147162 100644
--- a/apps/tabanchi/metadata.json
+++ b/apps/tabanchi/metadata.json
@@ -2,7 +2,7 @@
   "id": "tabanchi",
   "name": "Tabanchi",
   "shortName": "Tabanchi",
-  "version": "0.02",
+  "version": "0.03",
   "type": "app",
   "description": "Tamagotchi WatchApp",
   "icon": "app.png",
diff --git a/apps/taglaunch/ChangeLog b/apps/taglaunch/ChangeLog
new file mode 100644
index 000000000..981f50386
--- /dev/null
+++ b/apps/taglaunch/ChangeLog
@@ -0,0 +1,2 @@
+0.01: New App!
+0.02: Use Bangle.showClock for changing to clock (Backport from launch)
diff --git a/apps/taglaunch/README.md b/apps/taglaunch/README.md
new file mode 100644
index 000000000..71eebae9f
--- /dev/null
+++ b/apps/taglaunch/README.md
@@ -0,0 +1,15 @@
+Launcher
+========
+
+Based on the default launcher but puts all applications in a submenu by their tag.
+With many applications installed this can result in a faster applications selection than the linear access of the default launcher.
+
+Currently the following tags are supported: clock, game, tool, bluetooth, outdoors, misc.
+
+Settings
+--------
+
+- `Font` - The font used (`4x6`, `6x8`, `12x20`, `6x15` or `Vector`). Default `12x20`.
+- `Vector Font Size` - The size of the font if `Font` is set to `Vector`. Default `10`.
+- `Show Clocks` -  If set to `No` then clocks won't appear in the app list. Default `Yes`.
+- `Fullscreen` - If set to `Yes` then widgets won't be loaded. Default `No`.
diff --git a/apps/taglaunch/app.js b/apps/taglaunch/app.js
new file mode 100644
index 000000000..c940284c2
--- /dev/null
+++ b/apps/taglaunch/app.js
@@ -0,0 +1,138 @@
+{ // must be inside our own scope here so that when we are unloaded everything disappears
+let s = require("Storage");
+
+// TODO: Move icons to separate files
+// TODO: Allow change sortorder in settings
+let tags = {"clock": {name: /*LANG*/"Clocks", icon: atob("MDCEBERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERESIiIiIREREREREREREREREREREREREiIiIiIiIiIhERERERERERERERERERESIiIiIiIiIiIiIREREREREREREREREREiIiIiIiIiIiIiIhERERERERERERERESIiIiIgz//8ziIiIiIREREREREREREREiIiIg////////ziIiIhERERERERERERIiIiD//////////84iIiERERERERERESIiIg/////8A/////ziIiIRERERERERESIiI//////8A//////+IiIREREREREREiIiP//////8A///////4iIhERERERERIiIg///////8A///////ziIiERERERERIiIP///////8A////////OIiERERERESIiI////////8A////////+IiIRERERESIiD////////8A////////84iIRERERESIiP////////8A/////////4iIRERERESIiP////////8A/////////4iIREREREiIg/////////8A/////////ziIhEREREiIg/////////IAL////////ziIhEREREiIj////////yAAAv////////iIhEREREiIgiIv/////wCIAP/////yIiiIhEREREiIgiIv/////wCIAP/////yIiiIhEREREiIj////////yAAAD////////iIhEREREiIg/////////IAABP//////ziIhEREREiIg///////////IAE//////ziIhERERESIiP//////////8gAT/////4iIRERERESIiP///////////yABP////4iIRERERESIiD////////////IAL///84iIRERERESIiI////////////8i////+IiIRERERERIiIP/////////////////OIiERERERERIiIg////////////////ziIiEREREREREiIiP///////////////4iIhERERERERESIiI//////////////+IiIRERERERERESIiIg/////8i/////ziIiIRERERERERERIiIiD////8i////84iIiEREREREREREREiIiIg///8i///ziIiIhERERERERERERESIiIiIgz8i8ziIiIiIREREREREREREREREiIiIiIiIiIiIiIhERERERERERERERERESIiIiIiIiIiIiIREREREREREREREREREREiIiIiIiIiIhERERERERERERERERERERERESIiIiIRERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERA==")},
+            "game": {name: /*LANG*/"Games", sortorder: 1, icon: atob("MDCEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzMzMzMzMzMzMzMzMzMzMzMwAAAAAAAAAzMzMzMzMzMzMzMzMzMzMzMwAAAAAAAAAzIiIiIiIiIiIiIiIiIiIiMwAAAAAAAAAzL///IiIi////IiIi///yMwAAAAAAAAAzL///IiIi////IiIi///yMwAAAAAAAAAzL///IiIi////IiIi///yMwAAAAAAAAAzL///IiIi////IiIi///yMwAAAAAAAAAzL///IiIi////IiIi///yMwAAAAAAAAAzIiIi////IiIi////IiIiMwAAAAAAAAAzIiIi////IiIi////IiIiMwAAAAAAAAAzIiIi////IiIi////IiIiMwAAAAAAAAAzIiIi////IiIi////IiIiMwAAAAAAAAAzIiIi////IiIi////IiIiMwAAAAAAAAAzIiIi////IiIi////IiIiMwAAAAAAAAAzL///IiIi////IiIi///yMwAAAAAAAAAzL///IiIi////IiIi///yMwAAAAAAAAAzL///IiIi////IiIi8R/xERABEAAAAAAzL///IiIi////IiIi8R/xERABEAAAAAAzL///IiIi////IiIi8R/xERABEAAAAAAzL///IiIi////IiIi8RMxERABEAAAAAAzIiIi////IiIi////IREREREREAAAAAAzIiIi////IiIi////IREREREREAAAAAAzIiIi////IiIi////IREREREREAAAAAAzIiIi////IiIi////IhERERERAAAAAAAzIiIi////IiIi////IiMzMzMwAAAAAAAzIiIi////IiIi////IiMzMzMwAAAAAAAzL///IiIi////IiIi///xERAAAAAAAAAzL///IiIi////IiIi//8xERAAAAAAAAAzL///IiIi////IiIi//8hEREAAAAAAAAzL///IiIi////IiIi//8REREAAAAAAAAzL///IiIi////IiIi//MREREAAAAAAAAzIiIiIiIiIiIiIiIiIzMzMzMzMAAAAAAzMzMzMzMzMzMzMzMzMzMzMzMzMAAAAAAzMzMzMzMzMzMzMzMzMhEREREREAAAAAAAAAAAAAAAAAAAAAAAEREREREREQAAAAAAAAAAAAAAAAAAAAAAEREREREREQAAAAAAAAAAAAAAAAAAAAAAEREREREREQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")},
+            "tool": {name: /*LANG*/"Tools", sortorder: -1, icon: atob("MDCEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMwAAAAAAAAAAAAAAIiIgAAAAAAAAAAADMzMAAAAAAAAAAAAiIiIgAAAAAAAAAAADMzMwAAAAAAAAAAIiIiIAAAAAAAAAAAAAMzMzAAAAAAAAACIiIiAAAAAAAAAAAAAAMzMzMAAAAAAAACIiIgAAAAAAAAAAAAAAAzMzMAAAAAAAAiIiIAAAAAAAAAAAAAAAADMzMwAAAAAAAiIiIAAAAAIgAAAAAAAAAAMzMzAAAAAAAiIiIgAAACIgAAAAAAAAAAADMzMAAAAAAiIiIiAAAiIgAAAAAAAAAAAAMzMwAAAAAiIiIiIAIiIgAAAAAAAAAAAAAzMzAAAAACIiIiIiIiIgAAAAAAAAAAAAADMzMAAAAiIiIiIiIiIAAAAAAAAAAAAAAAMzMwDdQiIiIiIiIiIAAAAAAAAAAAAAAAAzMz3d0iIiIiIiIiAAAAAAAAAAAAAAAAADM93d1CIiIiIiIgAAAAAAAAAAAAAAAAAAPd3d3iIiACIiAAAAAAAAAAAAAAAAAAAA3d3d7kIgAAAAAAAAAAAAAAAAAAAAAAAN3d3e7uQAAAAAAAAAAAAAAAAAAAAAAAAN3d3u7u4AAAAAAAAAAAAAAAAAAAAAAAAC3d7u7u7gAAAAAAAAAAAAAAAAAAAAAAAiJO7u7u7uAAAAAAAAAAAAAAAAAAAAAAIiIiTu7u7u7gAAAAAAAAAAAAAAAAAAACIiIiIu7u7u7uAAAAAAAAAAAAAAAAAAAiIiIiIA7u7u7u4AAAAAAAAAAAAAAAAAIiIiIiAADu7u7u7uAAAAAAAAAAAAAAACIiIiIgAAAO7u7u7u4AAAAAAAAAAAAAAiIiIiIAAAAO7u7u7u7gAAAAAAAAAAAAIiIiIiAAAAAA7u7u7u7uAAAAAAAAAAAiIiIiIgAAAAAADu7u7u7u4AAAAAAAAAIiIiIiIAAAAAAAAO7u7u7u7gAAAAAAAAIiIiIiAAAAAAAAAO7u7u7u7gAAAAAAACIgAiIgAAAAAAAAAA7u7u7u7gAAAAAAACIgAiIAAAAAAAAAAADu7u7u7gAAAAAAACIiIiIAAAAAAAAAAAAO7u7u4AAAAAAAAAIiIiAAAAAAAAAAAAAO7u7uAAAAAAAAAAAiIAAAAAAAAAAAAAAADu7gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")},
+            "bluetooth": {name: /*LANG*/"Bluetooth", icon: atob("MDCEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqqoAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqqqgAAAAAAAAAAAAAAAAAAAAAAAAAAAKqqqqoAAAAAAAAAAAAAAAAAAAAAAAAAAKqqqqqgAAAAAAAAAAAAAAAAAAAAAAAAAKqqqqqqAAAAAAAAAAAAAAAAAAAAAAAAAKqqCqqqoAAAAAAAAAAAAAAAAAAAAAAAAKqqAKqqqgAAAAAAAAAAAAAAAAAAAAAAAKqqAAqqqqAAAAAAAAAAAAAAAAAKqgAAAKqqAACqqqqgAAAAAAAAAAAAAAAKqqAAAKqqAAAKqqoAAAAAAAAAAAAAAAAKqqoAAKqqAACqqqAAAAAAAAAAAAAAAAAAqqqgAKqqAAqqqgAAAAAAAAAAAAAAAAAACqqqAKqqAKqqoAAAAAAAAAAAAAAAAAAAAKqqoKqqCqqqAAAAAAAAAAAAAAAAAAAAAAqqqqqqqqqgAAAAAAAAAAAAAAAAAAAAAACqqqqqqqoAAAAAAAAAAAAAAAAAAAAAAAAKqqqqqqAAAAAAAAAAAAAAAAAAAAAAAAAAqqqqqgAAAAAAAAAAAAAAAAAAAAAAAAAACqqqoAAAAAAAAAAAAAAAAAAAAAAAAAAACqqqoAAAAAAAAAAAAAAAAAAAAAAAAAAAqqqqqgAAAAAAAAAAAAAAAAAAAAAAAAAKqqqqqqAAAAAAAAAAAAAAAAAAAAAAAACqqqqqqqoAAAAAAAAAAAAAAAAAAAAAAAqqqqqqqqqgAAAAAAAAAAAAAAAAAAAAAKqqoKqqCqqqAAAAAAAAAAAAAAAAAAAACqqqAKqqAKqqoAAAAAAAAAAAAAAAAAAAqqqgAKqqAAqqqgAAAAAAAAAAAAAAAAAKqqoAAKqqAACqqqAAAAAAAAAAAAAAAACqqqAAAKqqAAAKqqoAAAAAAAAAAAAAAAAKqgAAAKqqAACqqqoAAAAAAAAAAAAAAAAAoAAAAKqqAAqqqqAAAAAAAAAAAAAAAAAAAAAAAKqqAKqqqgAAAAAAAAAAAAAAAAAAAAAAAKqqCqqqoAAAAAAAAAAAAAAAAAAAAAAAAKqqqqqqAAAAAAAAAAAAAAAAAAAAAAAAAKqqqqqgAAAAAAAAAAAAAAAAAAAAAAAAAKqqqqoAAAAAAAAAAAAAAAAAAAAAAAAAAKqqqgAAAAAAAAAAAAAAAAAAAAAAAAAAAKqqoAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")},
+            "outdoors": {name: /*LANG*/"Outdoor", icon: atob("MDCEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3dAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN3d0AAAAAAAAAAAAAAAAAAAAAAAAADd3d3d3d3QAAAAAAAAAAAAAAAAAAAAAADd3d3d3d3QAAAAAAAAAAAAAAAAAAAAAADd3e7u7d3QAAAAAAAAAAAAAAAAAAAAAADd3u7u7t3QAAAAAAAAAAAAAAAAAAAAAA3d7u7u7u3dAAAAAAAAAAAAAAAAAAAAAN3d7u7u7u3d0AAAAAAAAAAAAAAAAAAADd3d7u7u7u3d3QAAAAAAAAAAAAAAAAAAAN3d7u7u7u3d0AAAAAAAAAAAAAAAAAAAAA3d3u7u7u3dAAAAAAAAAAAAAAAAAAAAAADd3u7u7t3QAAAAAAAAAAAAAAAAAAAAAADd3d7u7d3QAMzMwAAAAAAAAO4AAAAAAADd3d3d3d3QAMzMwAAAAAAA7u7gAAAAAADd3d3d3d3QAAzMwAAAAAAO7u7gAAAAAAAAAN3d0AAAAAzMAAAAAAAO7u7gAAAAAAAAAA3dAAAAAAzMAAAAAADu7u4AAAAAAAAAAADQAAAAAAzMAAAAAADu7u4AAAAAAAAAAAAAAAAAAAERAAAAAA7u7uAAAAAAAAAAAAAAAAAAAAERAAAAQO7u7uAAAAAAAAAAAAAAAAAAAAEREAAEAO7u7gAAAAAAAAAAAAAAAAAAABEREN3U3e7u7gAAAAAAAAAAAAAAAAAAARERFN3d3d7u4AAAAAAAAAAAAAAAAAAAARERFEREREREQAAAAAAAAAAAAAAAAAEREREREREREREREREAAAAAAAAAAAAAAAEREREREREREREREREAAAAAAAAAAAAAAAARERERERERERERERAAAAAAAAAAAAAAAAAEREREREREREREREAAAAAAAAAAAAAAAAAERERERERERERERAAAAAAAAAADMzMzMzMxFEERRBEUQRFEETMzMzAAAAADMzMzMzMyFEERRBEUQRFEETMzMzAAAAADMzMzMzMzREREREREREREQzMzMzAAAAADMzMzMzMzJEREREREREREIzMzMzAAAAADMzMzMzMzMkRERERERERCMzMzMzAAAAADMzMzMzMzMzJEREREREIzMzMzMzAAAAADMzMzMzMzMzMzMzMzMzMzMzMzMzAAAAADMzMzMzMzMzMzMzMzMzMzMzMzMzAAAAADMzMzMzMzMzMzMzMzMzMzMzMzMzAAAAADMzMzMzMzMzMzMzMzMzMzMzMzMzAAAAADMzMzMzMzMzMzMzMzMzMzMzMzMzAAAAADMzMzMzMzMzMzMzMzMzMzMzMzMzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")},
+            "misc": {name: /*LANG*/"Misc", icon: atob("MDCEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAACIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")}
+           };
+
+// handle customised launcher
+let scaleval = 1;
+let vectorval = 20;
+let font = g.getFonts().includes("12x20") ? "12x20" : "6x8:2";
+let settings = Object.assign({
+  showClocks: true,
+  fullscreen: false
+}, s.readJSON("taglaunch.json", true) || {});
+if ("vectorsize" in settings)
+  vectorval = parseInt(settings.vectorsize);
+if ("font" in settings){
+  if(settings.font == "Vector"){
+    scaleval = vectorval/20;
+    font = "Vector"+(vectorval).toString();
+  } else{
+    font = settings.font;
+    scaleval = (font.split("x")[1])/20;
+  }
+}
+
+let sort = (a, b) => {
+  let n=(0|a.sortorder)-(0|b.sortorder);
+  if (n) return n; // do sortorder first
+  if (a.nameb.name) return 1;
+  return 0;
+};
+
+// cache app list so launcher loads more quickly
+let launchCache = s.readJSON("taglaunch.cache.json", true)||{};
+let launchHash = require("Storage").hash(/\.info/);
+if (launchCache.hash!=launchHash) {
+  let appsByTag = Object.keys(tags).reduce((acc,curr)=> (acc[curr]=[],acc),{});
+  s.list(/\.info$/).map(app=>s.readJSON(app,1))
+    .filter(app=>app && app.type=="app" || app.type=="clock" || !app.type)
+    .sort((a,b)=>sort(a,b))
+    .forEach(app => {
+      let appTags = app.tags.split(",")
+        .map(tag => tag.trim())
+        .map(tag => tag === "tools" ? "tool" : tag) // tool = tools
+        .filter(tag => Object.keys(tags).includes(tag));
+      if (appTags.length === 0) {
+        appTags.push("misc");
+      }
+      appTags.forEach(tag => appsByTag[tag].push(app));
+    });
+  launchCache = {hash: launchHash, appsByTag: appsByTag};
+  s.writeJSON("taglaunch.cache.json", launchCache);
+}
+let appsByTag = launchCache.appsByTag;
+let tagKeys = Object.keys(tags).filter(tag => tag !== "clock" || settings.showClocks)
+  .filter(tag => appsByTag[tag].length > 0)
+  .sort((a,b)=>sort(tags[a],tags[b]));
+
+// Now apps list is loaded - render
+if (!settings.fullscreen)
+  Bangle.loadWidgets();
+
+let showTagMenu = (tag) => {
+  E.showScroller({
+    h : 64*scaleval, c : appsByTag[tag].length,
+    draw : (i, r) => {
+      let app = appsByTag[tag][i];
+      if (!app) return;
+      g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1));
+      g.setFont(font).setFontAlign(-1,0).drawString(app.name,64*scaleval,r.y+(32*scaleval));
+      if (app.icon) {
+        if (!app.img) app.img = s.read(app.icon); // load icon if it wasn't loaded
+        try {g.drawImage(app.img,8*scaleval, r.y+(8*scaleval), {scale: scaleval});} catch(e){}
+      }
+    },
+    select : i => {
+      let app = appsByTag[tag][i];
+      if (!app) return;
+      if (!app.src || require("Storage").read(app.src)===undefined) {
+        E.showMessage(/*LANG*/"App Source\nNot found");
+        setTimeout(drawMenu, 2000);
+      } else {
+        load(app.src);
+      }
+    },
+    back : showMainMenu
+  });
+};
+
+let showMainMenu = () => {
+  E.showScroller({
+    h : 64*scaleval, c : tagKeys.length,
+    draw : (i, r) => {
+      let tag = tagKeys[i];
+      g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1));
+      g.setFont(font).setFontAlign(-1,0).drawString(tags[tag].name,64*scaleval,r.y+(32*scaleval));
+      if (tags[tag].icon) {
+        try {g.drawImage(tags[tag].icon,8*scaleval, r.y+(8*scaleval), {scale: scaleval});} catch(e){}
+      }
+    },
+    select : i => {
+      let tag = tagKeys[i];
+      showTagMenu(tag);
+    },
+    back : Bangle.showClock, // button press or tap in top left shows clock now
+    remove : () => {
+      // cleanup the timeout to not leave anything behind after being removed from ram
+      if (lockTimeout) clearTimeout(lockTimeout);
+      Bangle.removeListener("lock", lockHandler);
+  }
+  });
+};
+showMainMenu();
+g.flip(); // force a render before widgets have finished drawing
+
+// 10s of inactivity goes back to clock
+Bangle.setLocked(false); // unlock initially
+let lockTimeout;
+let lockHandler = function(locked) {
+  if (lockTimeout) clearTimeout(lockTimeout);
+  lockTimeout = undefined;
+  if (locked) {
+    lockTimeout = setTimeout(Bangle.showClock, 10000);
+  }
+};
+Bangle.on("lock", lockHandler);
+if (!settings.fullscreen) // finally draw widgets
+  Bangle.drawWidgets();
+}
diff --git a/apps/taglaunch/app.png b/apps/taglaunch/app.png
new file mode 100644
index 000000000..8b4e6caa2
Binary files /dev/null and b/apps/taglaunch/app.png differ
diff --git a/apps/taglaunch/metadata.json b/apps/taglaunch/metadata.json
new file mode 100644
index 000000000..d7f1954b1
--- /dev/null
+++ b/apps/taglaunch/metadata.json
@@ -0,0 +1,17 @@
+{
+  "id": "taglaunch",
+  "name": "Tag Launcher",
+  "shortName": "Taglauncher",
+  "version": "0.02",
+  "description": "Launcher that puts all applications into submenus based on their tag. With many applications installed this can result in a faster application selection than the linear access of the default launcher.",
+  "readme": "README.md",
+  "icon": "app.png",
+  "type": "launch",
+  "tags": "tool,system,launcher",
+  "supports": ["BANGLEJS2"],
+  "storage": [
+    {"name":"taglaunch.app.js","url":"app.js"},
+    {"name":"taglaunch.settings.js","url":"settings.js"}
+  ],
+  "data": [{"name":"taglaunch.json"},{"name":"taglaunch.cache.json"}]
+}
diff --git a/apps/taglaunch/settings.js b/apps/taglaunch/settings.js
new file mode 100644
index 000000000..52fa07a7f
--- /dev/null
+++ b/apps/taglaunch/settings.js
@@ -0,0 +1,37 @@
+// make sure to enclose the function in parentheses
+(function(back) {
+  let settings = Object.assign({
+    showClocks: true,
+    fullscreen: false
+  }, require("Storage").readJSON("taglaunch.json", true) || {});
+
+  let fonts = g.getFonts();
+  function save(key, value) {
+    settings[key] = value;
+    require("Storage").write("taglaunch.json",settings);
+  }
+  const appMenu = {
+    "": { "title": /*LANG*/"Tag Launcher" },
+    /*LANG*/"< Back": back,
+    /*LANG*/"Font": {
+      value: fonts.includes(settings.font)? fonts.indexOf(settings.font) : fonts.indexOf("12x20"),
+      min:0, max:fonts.length-1, step:1,wrap:true,
+      onchange: (m) => {save("font", fonts[m])},
+      format: v => fonts[v]
+     },
+    /*LANG*/"Vector Font Size": {
+      value: settings.vectorsize || 10,
+      min:10, max: 20,step:1,wrap:true,
+      onchange: (m) => {save("vectorsize", m)}
+    },
+    /*LANG*/"Show Clocks": {
+      value: settings.showClocks == true,
+      onchange: (m) => { save("showClocks", m) }
+    },
+    /*LANG*/"Fullscreen": {
+      value: settings.fullscreen == true,
+      onchange: (m) => { save("fullscreen", m) }
+    }
+  };
+  E.showMenu(appMenu);
+});
diff --git a/apps/teatimer/ChangeLog b/apps/teatimer/ChangeLog
new file mode 100644
index 000000000..db8dd270b
--- /dev/null
+++ b/apps/teatimer/ChangeLog
@@ -0,0 +1,3 @@
+0.01: New App!
+0.02: Fix issue setting colors after showMessage
+0.03: Fix BG/FG Color if e.g. theme background is black
diff --git a/apps/teatimer/app.js b/apps/teatimer/app.js
index dd7afdadb..c394b5e00 100644
--- a/apps/teatimer/app.js
+++ b/apps/teatimer/app.js
@@ -67,9 +67,9 @@ function startTimer() {
   - hint for help in state start
 */ 
 function showCounter(withHint) {
-  //g.clear();
+  g.reset(); // workaround for E.showMessage bg color in 2v14 and earlier
   E.showMessage("", appTitle());
-  g.setFontAlign(0,0); // center font
+  g.reset().setFontAlign(0,0); // center font
   // draw the current counter value
   g.setBgColor(-1).setColor(0,0,1); // blue
   g.setFont("Vector",20); // vector font, 20px  
@@ -123,9 +123,9 @@ function countUp() {
     outOfTime();
     return;
   }
-  g.clear();
+  g.reset(); // workaround for E.showMessage bg color in 2v14 and earlier
   E.showMessage("", appTitle());
-  g.setFontAlign(0,0); // center font
+  g.reset().setFontAlign(0,0); // center font
   g.setBgColor(-1).setColor(0,0,1); // blue
   g.setFont("Vector",20); // vector font, 20px
   g.drawString("Timer: " + timeFormated(counterStart),80,55);
@@ -216,6 +216,8 @@ function initDragEvents() {
 function showHelp() {
   if (state == states.start) {
     state = states.help;
+	g.setBgColor(g.theme.bg);
+	g.setColor(g.theme.fg);
     E.showMessage("Swipe up/down\n+/- one minute\n\nSwipe left/right\n+/- 15 seconds\n\nPress Btn1 to start","Tea timer help");
   }
   // return to start
diff --git a/apps/teatimer/metadata.json b/apps/teatimer/metadata.json
index acace0402..b5cdce92e 100644
--- a/apps/teatimer/metadata.json
+++ b/apps/teatimer/metadata.json
@@ -1,7 +1,7 @@
 {
   "id": "teatimer",
   "name": "Tea Timer",
-  "version": "0.01",
+  "version": "0.03",
   "description": "A simple timer. You can easyly set up the time.",
   "icon": "teatimer.png",
   "type": "app",
diff --git a/apps/tempmonitor/ChangeLog b/apps/tempmonitor/ChangeLog
new file mode 100644
index 000000000..2d9536fb9
--- /dev/null
+++ b/apps/tempmonitor/ChangeLog
@@ -0,0 +1 @@
+0.01: 1st version: saves values to csv
diff --git a/apps/tempmonitor/README.md b/apps/tempmonitor/README.md
new file mode 100644
index 000000000..094a47868
--- /dev/null
+++ b/apps/tempmonitor/README.md
@@ -0,0 +1,40 @@
+# Temperature Monitor (with logging)
+Temperature monitor that shows temperature on real time but also allows to store in a file for a later process.
+
+Compatible with BangleJS1,BangleJS2,and EMSCRIPTENx emulators
+
+## Pictures:
+
+Bangle JS1
+
+![](photo_banglejs1.jpg)
+
+Screenshot BJS2
+
+![](ss_emul_bjs2.png)
+
+Screenshot BJS1
+
+![](ss_emul_bjs1.png)
+
+
+
+## Usage
+
+Open and see a temperature in the screen 
+Download the CSV file and process in your favourite spreadsheet software
+
+## Features
+
+Colours, all inputs , graph, widgets loaded 
+Counter for Times Display
+
+
+## Controls
+
+exit: left side
+
+
+## Creator
+
+Daniel Perez
\ No newline at end of file
diff --git a/apps/tempmonitor/app-icon.js b/apps/tempmonitor/app-icon.js
new file mode 100644
index 000000000..807f58d38
--- /dev/null
+++ b/apps/tempmonitor/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEw4X/AoPzvswnmT54cQgWAhWq1ALGlWoBZOptUKqtoBQsK0ta1QLHlWVqwLHgWpqtVtQLGEQILBrQLGCYIADBYgiDBY8KyoLJIQIAEtQiDHIQADrWALgYLFqyECEQpiDLggHC1QdBrWgEQVqAQOmLAQkBlIUB02lq28gFpKoQLBq2+1NW+2qGwVolQIB20prPaBYVq1ALCuwLB8sC02VBYMAhILB1Nb/uqgWVsBfBBYdZ/wLIEYP//TwBC41a/9v+wLHq1/7/6BYxjBz//9IXHqtpuqWBBY9aOwQjHAAYXHBZSNBAAOpBYsq3//AAPZBYda+wLJrawB34GBgwLEs9l0QLChILFz9i3+qxWrBYuvC4ILB1ALEtdqy2/4WKgALErPVuwXIrV/7QLIqxyB3+f4EoBYUqUgVVC4N60/ZtWolS4BAAO/qv1r/ZrWoV4iDEqtolSjDAAojBBZRIBABIA="))
\ No newline at end of file
diff --git a/apps/tempmonitor/app.png b/apps/tempmonitor/app.png
new file mode 100644
index 000000000..f1e576134
Binary files /dev/null and b/apps/tempmonitor/app.png differ
diff --git a/apps/tempmonitor/metadata.json b/apps/tempmonitor/metadata.json
new file mode 100644
index 000000000..bba8c6095
--- /dev/null
+++ b/apps/tempmonitor/metadata.json
@@ -0,0 +1,15 @@
+{
+  "id": "tempmonitor",
+  "name": "Temperature monitor",
+  "version": "0.01",
+  "description": "Displays the current temperature and stores in a CSV file",
+  "icon": "app.png",
+  "tags": "tool",
+  "supports": ["BANGLEJS", "BANGLEJS2"],
+  "screenshots": [{"url":"photo_banglejs1.jpg"}],
+  "allow_emulator": true,
+  "storage": [
+    {"name":"tempmonitor.app.js","url":"tempmonitor.app.js"},
+    {"name":"tempmonitor.img","url":"app-icon.js","evaluate":true}
+  ]
+}
diff --git a/apps/tempmonitor/photo_banglejs1.jpg b/apps/tempmonitor/photo_banglejs1.jpg
new file mode 100644
index 000000000..58c64b01c
Binary files /dev/null and b/apps/tempmonitor/photo_banglejs1.jpg differ
diff --git a/apps/tempmonitor/ss_emul_bjs1.png b/apps/tempmonitor/ss_emul_bjs1.png
new file mode 100644
index 000000000..1865ebc85
Binary files /dev/null and b/apps/tempmonitor/ss_emul_bjs1.png differ
diff --git a/apps/tempmonitor/ss_emul_bjs2.png b/apps/tempmonitor/ss_emul_bjs2.png
new file mode 100644
index 000000000..1cc2140f9
Binary files /dev/null and b/apps/tempmonitor/ss_emul_bjs2.png differ
diff --git a/apps/tempmonitor/tempmonitor.app.js b/apps/tempmonitor/tempmonitor.app.js
new file mode 100644
index 000000000..36b4bb654
--- /dev/null
+++ b/apps/tempmonitor/tempmonitor.app.js
@@ -0,0 +1,137 @@
+// Temperature monitor that saves a log of measures
+// Version 001 standalone for  developer
+//  PEND
+//test with small savefreq
+var v_mode_debug=0; //, 0=no, 1 min, 2 prone detail
+//var required for drawing with dynamic screen
+var rect = Bangle.appRect;
+var history = [];
+var readFreq=5000; //ms //PEND add to settings
+var saveFreq=30000; //ms
+var v_saveToFile='Y'; //Y save //N
+//with upload file º is not displayed properly
+//with upload RAM º is  displayed
+var v_t_symbol="";//ºC
+var v_saved_entries=0;
+var filename ="temphistory.csv";
+var lastMeasure = new String();
+var v_model=process.env.BOARD;
+
+//EMSCRIPTEN,EMSCRIPTEN2
+if (v_model=='BANGLEJS'||v_model=='EMSCRIPTEN') {
+     v_font_size1=16;
+     v_font_size2=60;
+     //g.setColor("#0ff"); //light color
+  }else{
+    v_font_size1=11;
+    v_font_size2=40;
+    //g.setColor("#000"); //black or dark
+  }
+
+function onTemperature(v_temp) {
+  if (v_mode_debug>1) console.log("v_temp in "+v_temp);
+  ClearBox();
+  //g.setFont("6x8",2).setFontAlign(0,0);
+  g.setFontVector(v_font_size1).setFontAlign(0,0);
+  var x = (rect.x+rect.x2)/2;
+  var y = (rect.y+rect.y2)/2 + 20;
+  g.drawString("Records: "+v_saved_entries, x, rect.y+35);
+  g.drawString("Temperature:", x, rect.y+37+v_font_size1);
+  //dynamic font (g.getWidth() > 200 ? 60 : 40)
+  g.setFontVector(v_font_size2).setFontAlign(0,0);
+  // Avg of temperature readings
+  while (history.length>4) history.shift();
+  history.push(v_temp);
+  var avrTemp = E.sum(history) / history.length;
+  //var t = require('locale').temp(avrTemp);
+  //.replace("'","°");
+  lastMeasure=avrTemp.toString();
+  if (lastMeasure.length>4) lastMeasure=lastMeasure.substr(0,4);
+  //DRAW temperature in the center
+  g.drawString("     ", x-20, y);
+  g.drawString(v_temp+v_t_symbol, x-20, y);
+  g.flip();
+}
+// from: BJS2 pressure sensor,  BJS1 inbuilt thermistor
+function drawTemperature() {
+  if(v_model.substr(0,10)!='EMSCRIPTEN'){
+    if (Bangle.getPressure) {
+      Bangle.getPressure().then(p =>{if (p) onTemperature(p);});
+    } else onTemperature(E.getTemperature());
+  }
+  else  onTemperature(11);//fake temp for emulators
+}
+
+function saveToFile() {
+  //input global vars: lastMeasure
+  var a=new Date();
+  var strlastSaveTime=new String();
+  strlastSaveTime=a.toISOString();
+  //strlastSaveTime=strlastSaveTime.concat(a.getFullYear(),a.getMonth()+1,a.getDate(),a.getHours(),a.getMinutes());;
+  if (v_mode_debug==1) console.log("saving="+strlastSaveTime+","+lastMeasure);
+
+  if (v_saveToFile=='Y'){
+    require("Storage").open(filename,"a").write(strlastSaveTime+","+lastMeasure+"\n");
+    //(getTime()+",");
+    v_saved_entries=v_saved_entries+1;
+  }
+}
+
+function drawGraph(){
+    var img_obj_thermo =   {
+      width : 36, height : 36, bpp : 3,
+      transparent : 0,
+      buffer : require("heatshrink").decompress(atob("AEFt2AMKm3bsAMJjdt23ABhEB+/7tgaJ///DRUP//7tuADRP923YDRXbDRfymwaJhu/koaK7eyiwaK3cLDRlWDRY1NKBY1Ztu5kjmJg3cyVI7YMHgdu5Mkyu2fxHkyVJjdgDRFJkmRDRPsDQNbDQ5QBGoONKBJrBoxQIQwO2eRcbtu24AMIFIQLJAH4AMA=="))
+    };
+    g.drawImage(img_obj_thermo,rect.x2-50,rect.y2/2);
+    g.flip();
+}
+function ClearScreen(){
+  //avoid widget areas
+  g.reset(1).clearRect(rect.x, rect.y+24, rect.x2, rect.y2-24);
+  g.flip();
+}
+function ClearBox(){
+  //custom boxarea , left space for static graph at right
+  g.reset(1).clearRect(rect.x, rect.y+24, rect.x2-50, rect.y2-24);
+  g.flip();
+}
+function introPage(){
+  //g.setFont("6x8",2).setFontAlign(0,0);
+  g.setFontVector(v_font_size1).setFontAlign(-1,0);
+  //x alignment. -1=left (default), 0=center, 1=right
+    var x=3;
+    //dynamic positions as height for BJS1 is double than BJS2
+    var y = (rect.y+rect.y2)/2 + 10;
+    g.drawString("   Default values  ", x, y - ((v_font_size1*3)+2));
+    g.drawString("--------------------", x, y - ((v_font_size1*2)+2));
+    g.drawString("Mode debug: "+v_mode_debug, x, y - ((v_font_size1*1)+2));
+    g.drawString("Read freq(ms): "+readFreq, x, y );
+    g.drawString("Save to file: "+v_saveToFile, x, y+ ((v_font_size1*1)+2) );
+    g.drawString("Save freq(ms):"+saveFreq, x, y+((v_font_size1*2)+2) );
+    fr=require("Storage").read(filename+"\1");//suffix required
+    if (fr)  g.drawString("Current filesize:"+fr.length.toString()+"kb", x, y+((v_font_size1*3)+2) );
+     else g.drawString("File not exist", x, y+((v_font_size1*3)+2));
+}
+//MAIN
+Bangle.loadWidgets();
+Bangle.setUI({
+  mode : "custom",
+  back : function() {load();}
+});
+
+ClearScreen();
+introPage();
+
+setInterval(function() {
+  drawTemperature();
+}, readFreq); //ms
+
+if (v_saveToFile=="Y") {
+    setInterval(function() {
+      saveToFile();
+    }, saveFreq); //ms
+}
+setTimeout(ClearScreen, 3500);
+setTimeout(drawGraph,4000);
+setTimeout(drawTemperature,4500);
\ No newline at end of file
diff --git a/apps/tempmonitor/tempmonitor.img b/apps/tempmonitor/tempmonitor.img
new file mode 100644
index 000000000..275109759
Binary files /dev/null and b/apps/tempmonitor/tempmonitor.img differ
diff --git a/apps/tempmonitor/tempmonitor.info b/apps/tempmonitor/tempmonitor.info
new file mode 100644
index 000000000..1824c5c86
--- /dev/null
+++ b/apps/tempmonitor/tempmonitor.info
@@ -0,0 +1 @@
+{"id":"tempmonitor","name":"tempmonitor","src":"tempmonitor.app.js","icon":"tempmonitor.img","version":"0.01","files":"tempmonitor.info,tempmonitor.app.js,tempmonitor.img"}
\ No newline at end of file
diff --git a/apps/testuserinput/README.md b/apps/testuserinput/README.md
index 47c1779be..7e1160bfb 100644
--- a/apps/testuserinput/README.md
+++ b/apps/testuserinput/README.md
@@ -43,7 +43,7 @@ Colours, font, user input, image, load widgets
  - Press center area - Prints Touch3
  - Swipe Left - Displays Switch OFF image
  - Swipe Right - Displays Switch ON image
- - BTN1 - Prints Button1
+ - BTN1 - Prints Button1, Down (moves selection to next row)
  - BTN2 - Prints Button2
  - BTN3 - Quit to Launcher
 
diff --git a/apps/tetris/README.md b/apps/tetris/README.md
new file mode 100644
index 000000000..2c41657f4
--- /dev/null
+++ b/apps/tetris/README.md
@@ -0,0 +1,8 @@
+# Tetris
+
+Bangle version of the classic game of Tetris.
+
+## Controls
+
+Tapping the screen rotates the pieces once, swiping left, right or down moves the
+piece in that direction, if possible.
\ No newline at end of file
diff --git a/apps/tetris/app-icon.js b/apps/tetris/app-icon.js
new file mode 100644
index 000000000..b87ef84f4
--- /dev/null
+++ b/apps/tetris/app-icon.js
@@ -0,0 +1 @@
+require("heatshrink").decompress(atob("mEwxH+If4A/AH4A/AH4A/ABe5AA0jABwvYAIovBgABEFAQHFL7IuEL4QuFA45fcF4YuNL7i/FFwoHHL7QvFFxpfaF4wAOF/4nHF5+0AAy3SXYoHGW4QBDF4MAAIgvRFwwHHdAbqDFIQuDL6ouJL4ovDFwpfUAAoHFL4a/FFwhfTFxZfDF4ouFL6QANFopfDF/4vNjwAGF8ABFF4MAAIgvBX4IBDX4YBDL6TyFFIIuEL4QuEL4QuEL6ovDFwpfFF4YuFL6i/FFwhfEX4ouEL6YvFFwpfDF4ouFL6QvGAAwtFL4Yv/AAonHAB4vHG563CAIbuDA5i/CAIb2DA4hfJEwoHPFApZEGwpfLFyJfFFxJfMAAoHNFAa5GX54uTL4YuLL5QAVFowAIF+4A/AH4A/AH4A/AHY"))
diff --git a/apps/tetris/metadata.json b/apps/tetris/metadata.json
new file mode 100644
index 000000000..f683a5be7
--- /dev/null
+++ b/apps/tetris/metadata.json
@@ -0,0 +1,14 @@
+{ "id": "tetris",
+  "name": "Tetris",
+  "shortName":"Tetris",
+  "version":"0.01",
+  "description": "Tetris",
+  "icon": "tetris.png",
+  "readme": "README.md",
+  "tags": "game",
+  "supports" : ["BANGLEJS2"],  
+  "storage": [
+    {"name":"tetris.app.js","url":"tetris.app.js"},
+    {"name":"tetris.img","url":"app-icon.js","evaluate":true}
+  ]
+}
diff --git a/apps/tetris/tetris.app.js b/apps/tetris/tetris.app.js
new file mode 100644
index 000000000..e24a731a9
--- /dev/null
+++ b/apps/tetris/tetris.app.js
@@ -0,0 +1,170 @@
+const block = Graphics.createImage(`
+########
+# # # ##
+## # ###
+# # ####
+## #####
+# ######
+########
+########
+`);
+const tcols = [ {r:0, g:0, b:1}, {r:0, g:1, b:0}, {r:0, g:1, b:1}, {r:1, g:0, b:0}, {r:1, g:0, b:1}, {r:1, g:1, b:0}, {r:1, g:0.5, b:0.5} ];
+const tiles = [
+  [[0, 0, 0, 0],
+   [0, 0, 0, 0],
+   [1, 1, 1, 1],
+   [0, 0, 0, 0]],
+  [[0, 0, 0],
+   [0, 1, 0],
+   [1, 1, 1]],
+  [[0, 0, 0],
+   [1, 0, 0],
+   [1, 1, 1]],
+  [[0, 0, 0],
+   [0, 0, 1],
+   [1, 1, 1]],
+  [[0, 0, 0],
+   [1, 1, 0],
+   [0, 1, 1]],
+  [[0, 0, 0],
+   [0, 1, 1],
+   [1, 1, 0]],
+  [[1, 1],
+   [1, 1]]
+];
+
+const ox = 176/2 - 5*8;
+const oy = 8;
+
+var pf = Array(23).fill().map(()=>Array(12).fill(0)); // field is really 10x20, but adding a border for collision checks
+pf[20].fill(1);
+pf[21].fill(1);
+pf[22].fill(1);
+pf.forEach((x,i) => { pf[i][0] = 1; pf[i][11] = 1; });
+
+function rotateTile(t, r) {
+  var nt = JSON.parse(JSON.stringify(t));
+  if (t.length==2) return nt;
+  var s = t.length;
+  for (m=0; m0)
+        if (qClear) g.fillRect(x+8*i, y+8*j, x+8*(i+1)-1, y+8*(j+1)-1);
+        else g.drawImage(block, x+8*i, y+8*j);
+}
+
+function showNext(n, r) {
+  var nt = rotateTile(tiles[n], r);
+  g.setColor(0).fillRect(176-33, 40, 176-33+33, 82);
+  drawTile(nt, ntn, 176-33, 40);
+}
+
+var time = Date.now();
+var px=4, py=0;
+var ctn = Math.floor(Math.random()*7); // current tile number
+var ntn = Math.floor(Math.random()*7); // next tile number
+var ntr = Math.floor(Math.random()*4); // next tile rotation
+var ct = rotateTile(tiles[ctn], Math.floor(Math.random()*4)); // current tile (rotated)
+var dropInterval = 450;
+var nlines = 0;
+
+function redrawPF(ly) {
+  for (y=0; y<=ly; ++y)
+    for (x=1; x<11; ++x) {
+      c = pf[y][x];
+      if (c>0) g.setColor(tcols[c-1].r, tcols[c-1].g, tcols[c-1].b).drawImage(block, ox+(x-1)*8, oy+y*8);
+      else g.setColor(0, 0, 0).fillRect(ox+(x-1)*8, oy+y*8, ox+x*8-1, oy+(y+1)*8-1);
+    }
+}
+
+function insertAndCheck() {
+  for (y=0; y0) pf[py+y][px+x+1] = ctn+1;
+  // check for full lines
+  for (y=19; y>0; y--) {
+    var qFull = true;
+    for (x=1; x<11; ++x) qFull &= pf[y][x]>0;
+    if (qFull) {
+      nlines++;
+      dropInterval -= 5;
+      Bangle.buzz(30);
+      for (ny=y; ny>0; ny--) pf[ny] = JSON.parse(JSON.stringify(pf[ny-1]));
+      redrawPF(y);
+      g.setColor(0).fillRect(5, 30, 41, 80).setColor(1, 1, 1).drawString(nlines.toString(), 22, 50);
+    }
+  }
+  // spawn new tile
+  px = 4; py = 0;
+  ctn = ntn;
+  ntn = Math.floor(Math.random()*7);
+  ct = rotateTile(tiles[ctn], ntr);
+  ntr = Math.floor(Math.random()*4);
+  showNext(ntn, ntr);
+}
+
+function moveOk(t, dx, dy) {
+  var ok = true;
+  for (y=0; y 0) ok = false;
+  return ok;
+}
+
+function gameStep() {
+  if (Date.now()-time > dropInterval) { // drop one step
+    time = Date.now();
+    if (moveOk(ct, 0, 1)) {
+      drawTile(ct, ctn, ox+px*8, oy+py*8, true);
+      py++;
+    }
+    else { // reached the bottom
+      insertAndCheck(ct, ctn, px, py);
+    }
+    drawTile(ct, ctn, ox+px*8, oy+py*8, false);
+  }
+}
+
+Bangle.setUI();
+Bangle.on("touch", (e) => {
+  t = rotateTile(ct, 3);
+  if (moveOk(t, 0, 0)) {
+    drawTile(ct, ctn, ox+px*8, oy+py*8, true);
+    ct = t;
+    drawTile(ct, ctn, ox+px*8, oy+py*8, false);
+  }
+});
+
+Bangle.on("swipe", (x,y) => {
+  if (y<0) y = 0;
+  if (moveOk(ct, x, y)) {
+    drawTile(ct, ctn, ox+px*8, oy+py*8, true);
+    px += x;
+    py += y;
+    drawTile(ct, ctn, ox+px*8, oy+py*8, false);
+  }
+});
+
+drawBoundingBox();
+g.setColor(1, 1, 1).setFontAlign(0, 1, 0).setFont("6x15", 1).drawString("Lines", 22, 30).drawString("Next", 176-22, 30);
+showNext(ntn, ntr);
+g.setColor(0).fillRect(5, 30, 41, 80).setColor(1, 1, 1).drawString(nlines.toString(), 22, 50);
+var gi = setInterval(gameStep, 20);
diff --git a/apps/tetris/tetris.png b/apps/tetris/tetris.png
new file mode 100644
index 000000000..8e884eaf3
Binary files /dev/null and b/apps/tetris/tetris.png differ
diff --git a/apps/themesetter/ChangeLog b/apps/themesetter/ChangeLog
new file mode 100644
index 000000000..ddbd06706
--- /dev/null
+++ b/apps/themesetter/ChangeLog
@@ -0,0 +1,2 @@
+...
+0.04: First update with ChangeLog Added
diff --git a/apps/thermom/ChangeLog b/apps/thermom/ChangeLog
index 6d3a966e3..0b8c325e5 100644
--- a/apps/thermom/ChangeLog
+++ b/apps/thermom/ChangeLog
@@ -4,3 +4,5 @@
 0.05: Use temperature from current locale
       Update every 10s, average last 5 readings
       Changes based on #1092
+0.06: Minor tweaks for stability. Update every 5 seconds
+0.07: Add back button
diff --git a/apps/thermom/app.js b/apps/thermom/app.js
index 0e45ed3e7..3aa99c015 100644
--- a/apps/thermom/app.js
+++ b/apps/thermom/app.js
@@ -24,7 +24,7 @@ function onTemperature(p) {
 // Gets the temperature in the most accurate way (pressure sensor or inbuilt thermistor)
 function drawTemperature() {
   if (Bangle.getPressure) {
-    Bangle.getPressure().then(onTemperature);
+    Bangle.getPressure().then(p =>{if (p) onTemperature(p);});
   } else {
     onTemperature({
       temperature : E.getTemperature()
@@ -34,8 +34,11 @@ function drawTemperature() {
 
 setInterval(function() {
   drawTemperature();
-}, 10000);
+}, 5000);
+Bangle.loadWidgets();
+Bangle.setUI({
+  mode : "custom",
+  back : function() {load();}
+});
 E.showMessage("Reading temperature...");
 drawTemperature();
-Bangle.loadWidgets();
-Bangle.drawWidgets();
diff --git a/apps/thermom/metadata.json b/apps/thermom/metadata.json
index 381f85e17..a215df624 100644
--- a/apps/thermom/metadata.json
+++ b/apps/thermom/metadata.json
@@ -1,7 +1,7 @@
 {
   "id": "thermom",
   "name": "Thermometer",
-  "version": "0.05",
+  "version": "0.07",
   "description": "Displays the current temperature in degree Celsius/Fahrenheit (depending on locale), updates every 10 seconds with average of last 5 readings.",
   "icon": "app.png",
   "tags": "tool",
diff --git a/apps/timerclk/ChangeLog b/apps/timerclk/ChangeLog
index 7a357b1aa..5a954d58c 100644
--- a/apps/timerclk/ChangeLog
+++ b/apps/timerclk/ChangeLog
@@ -1,3 +1,4 @@
 0.01: New App!
 0.02: Add sunrise/sunset. Fix timer bugs.
 0.03: Use default Bangle formatter for booleans
+0.04: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps
diff --git a/apps/timerclk/app.js b/apps/timerclk/app.js
index c750fcfde..ee30b059a 100644
--- a/apps/timerclk/app.js
+++ b/apps/timerclk/app.js
@@ -3,7 +3,7 @@ Graphics.prototype.setFontAnton = function(scale) {
   g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAA/gAAAAAAAAAAP/gAAAAAAAAAH//gAAAAAAAAB///gAAAAAAAAf///gAAAAAAAP////gAAAAAAD/////gAAAAAA//////gAAAAAP//////gAAAAH///////gAAAB////////gAAAf////////gAAP/////////gAD//////////AA//////////gAA/////////4AAA////////+AAAA////////gAAAA///////wAAAAA//////8AAAAAA//////AAAAAAA/////gAAAAAAA////4AAAAAAAA///+AAAAAAAAA///gAAAAAAAAA//wAAAAAAAAAA/8AAAAAAAAAAA/AAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////AAAAAB///////8AAAAH////////AAAAf////////wAAA/////////4AAB/////////8AAD/////////+AAH//////////AAP//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wA//8AAAAAB//4A//wAAAAAAf/4A//gAAAAAAP/4A//gAAAAAAP/4A//gAAAAAAP/4A//wAAAAAAf/4A///////////4Af//////////wAf//////////wAf//////////wAf//////////wAP//////////gAP//////////gAH//////////AAH//////////AAD/////////+AAB/////////8AAA/////////4AAAP////////gAAAD///////+AAAAAf//////4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/gAAAAAAAAAAP/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/AAAAAAAAAAA//AAAAAAAAAAA/+AAAAAAAAAAB/8AAAAAAAAAAD//////////gAH//////////gAP//////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/4AAAAB/gAAD//4AAAAf/gAAP//4AAAB//gAA///4AAAH//gAB///4AAAf//gAD///4AAA///gAH///4AAD///gAP///4AAH///gAP///4AAP///gAf///4AAf///gAf///4AB////gAf///4AD////gA////4AH////gA////4Af////gA////4A/////gA//wAAB/////gA//gAAH/////gA//gAAP/////gA//gAA///8//gA//gAD///w//gA//wA////g//gA////////A//gA///////8A//gA///////4A//gAf//////wA//gAf//////gA//gAf/////+AA//gAP/////8AA//gAP/////4AA//gAH/////gAA//gAD/////AAA//gAB////8AAA//gAA////wAAA//gAAP///AAAA//gAAD//8AAAA//gAAAP+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB/+AAAAAD/wAAB//8AAAAP/wAAB///AAAA//wAAB///wAAB//wAAB///4AAD//wAAB///8AAH//wAAB///+AAP//wAAB///+AAP//wAAB////AAf//wAAB////AAf//wAAB////gAf//wAAB////gA///wAAB////gA///wAAB////gA///w//AAf//wA//4A//AAA//wA//gA//AAAf/wA//gB//gAAf/wA//gB//gAAf/wA//gD//wAA//wA//wH//8AB//wA///////////gA///////////gA///////////gA///////////gAf//////////AAf//////////AAP//////////AAP/////////+AAH/////////8AAH///+/////4AAD///+f////wAAA///8P////gAAAf//4H///+AAAAH//gB///wAAAAAP4AAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAA//wAAAAAAAAAP//wAAAAAAAAB///wAAAAAAAAf///wAAAAAAAH////wAAAAAAA/////wAAAAAAP/////wAAAAAB//////wAAAAAf//////wAAAAH///////wAAAA////////wAAAP////////wAAA///////H/wAAA//////wH/wAAA/////8AH/wAAA/////AAH/wAAA////gAAH/wAAA///4AAAH/wAAA//+AAAAH/wAAA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAH/4AAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB//8AAA/////+B///AAA/////+B///wAA/////+B///4AA/////+B///8AA/////+B///8AA/////+B///+AA/////+B////AA/////+B////AA/////+B////AA/////+B////gA/////+B////gA/////+B////gA/////+A////gA//gP/gAAB//wA//gf/AAAA//wA//gf/AAAAf/wA//g//AAAAf/wA//g//AAAA//wA//g//gAAA//wA//g//+AAP//wA//g////////gA//g////////gA//g////////gA//g////////gA//g////////AA//gf///////AA//gf//////+AA//gP//////+AA//gH//////8AA//gD//////4AA//gB//////wAA//gA//////AAAAAAAH////8AAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////gAAAAB///////+AAAAH////////gAAAf////////4AAB/////////8AAD/////////+AAH//////////AAH//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wAf//////////4A//wAD/4AAf/4A//gAH/wAAP/4A//gAH/wAAP/4A//gAP/wAAP/4A//gAP/4AAf/4A//wAP/+AD//4A///wP//////4Af//4P//////wAf//4P//////wAf//4P//////wAf//4P//////wAP//4P//////gAP//4H//////gAH//4H//////AAH//4D/////+AAD//4D/////8AAB//4B/////4AAA//4A/////wAAAP/4AP////AAAAB/4AD///4AAAAAAAAAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//AAAAAAAAAAA//gAAAAAAAAAA//gAAAAAAAAAA//gAAAAAAADgA//gAAAAAAP/gA//gAAAAAH//gA//gAAAAB///gA//gAAAAP///gA//gAAAD////gA//gAAAf////gA//gAAB/////gA//gAAP/////gA//gAB//////gA//gAH//////gA//gA///////gA//gD///////gA//gf///////gA//h////////gA//n////////gA//////////gAA/////////AAAA////////wAAAA///////4AAAAA///////AAAAAA//////4AAAAAA//////AAAAAAA/////4AAAAAAA/////AAAAAAAA////8AAAAAAAA////gAAAAAAAA///+AAAAAAAAA///4AAAAAAAAA///AAAAAAAAAA//4AAAAAAAAAA/+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//gB///wAAAAP//4H///+AAAA///8P////gAAB///+f////4AAD///+/////8AAH/////////+AAH//////////AAP//////////gAP//////////gAf//////////gAf//////////wAf//////////wAf//////////wA///////////wA//4D//wAB//4A//wB//gAA//4A//gA//gAAf/4A//gA//AAAf/4A//gA//gAAf/4A//wB//gAA//4A///P//8AH//4Af//////////wAf//////////wAf//////////wAf//////////wAf//////////gAP//////////gAP//////////AAH//////////AAD/////////+AAD///+/////8AAB///8f////wAAAf//4P////AAAAH//wD///8AAAAA/+AAf//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//gAAAAAAAAB///+AA/+AAAAP////gA//wAAAf////wA//4AAB/////4A//8AAD/////8A//+AAD/////+A///AAH/////+A///AAP//////A///gAP//////A///gAf//////A///wAf//////A///wAf//////A///wAf//////A///wA///////AB//4A//4AD//AAP/4A//gAB//AAP/4A//gAA//AAP/4A//gAA/+AAP/4A//gAB/8AAP/4A//wAB/8AAf/4Af//////////wAf//////////wAf//////////wAf//////////wAf//////////wAP//////////gAP//////////gAH//////////AAH/////////+AAD/////////8AAB/////////4AAAf////////wAAAP////////AAAAB///////4AAAAAD/////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/AAB/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAA//AAD/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="), 46, atob("EiAnGicnJycnJycnEw=="), 78+(scale<<8)+(1<<16));
 };
 
-var SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js");
+var SunCalc = require("suncalc"); // from modules folder
 const LOCATION_FILE = "mylocation.json";
 let location;
 var sunRise = "--:--";
@@ -72,7 +72,7 @@ function drawSpecial() {
   g.setFontAlign(0,0).setFont(settings.specialFont, settings.specialFontSize);
   var y = Bangle.appRect.y + g.stringMetrics("00:00").height/2;
   g.clearRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y+g.stringMetrics("00:00").height);
-  
+
   if (stopwatches.length) {
     time = timerclk.getTime(stopwatches[stopwatch]);
     g.drawString(timerclk.formatTime(time, true), x, y);
@@ -111,7 +111,7 @@ function draw() {
   var dateStr = require("locale").date(date,settings.shortDate).toUpperCase();
   var dowStr = require("locale").dow(date).toUpperCase();
   var srssStr = sunRise + sunIcons + sunSet;
-  
+
   // draw time
   if (settings.timeFont == "Anton") {
     g.setFontAlign(0,0).setFont("Anton");
diff --git a/apps/timerclk/metadata.json b/apps/timerclk/metadata.json
index 72f42d8d4..5bd6bee24 100644
--- a/apps/timerclk/metadata.json
+++ b/apps/timerclk/metadata.json
@@ -1,8 +1,8 @@
-{ 
+{
 	"id": "timerclk",
 	"name": "Timer Clock",
 	"shortName":"Timer Clock",
-	"version":"0.03",
+	"version":"0.04",
 	"description": "A clock with stopwatches, timers and alarms build in.",
 	"icon": "app-icon.png",
 	"type": "clock",
@@ -30,6 +30,5 @@
 		{"name":"timerclk.alarm.js","url":"alarm.js"},
 		{"name":"timerclk.alarm.alert.js","url":"alarm.alert.js"}
 	],
-	"data": [{"name":"timerclk.json"},{"name":"timerclk.stopwatch.json"},{"name":"timerclk.timer.json"},{"name":"timerclk.alarm.json"}],
-	"sortorder": 0
+	"data": [{"name":"timerclk.json"},{"name":"timerclk.stopwatch.json"},{"name":"timerclk.timer.json"},{"name":"timerclk.alarm.json"}]
 }
diff --git a/apps/tinyVario/ChangeLog b/apps/tinyVario/ChangeLog
index 6c352f82b..a201ee465 100644
--- a/apps/tinyVario/ChangeLog
+++ b/apps/tinyVario/ChangeLog
@@ -1 +1,5 @@
 0.01: Initial Version
+0.02: Touch data fields to configure them.
+0.03: Changed menu layout, fixed automatic flight time detection.
+0.04: flight time detection should work without GPS now. New vario display available.
+0.05: some bugs fiexed, no new features.
diff --git a/apps/tinyVario/README.md b/apps/tinyVario/README.md
index e23f3af66..c375585c2 100644
--- a/apps/tinyVario/README.md
+++ b/apps/tinyVario/README.md
@@ -1,5 +1,7 @@
 # Turn your Bangle.js2 into a flight computer!
 
+All settings can be accessed by touching the corresponding data fields. I made all interface objects as big as possible to make it easier to use with gloves. 
+
 ## This is a work in progress. Working features so far:
 - Altimeter
 - Variometer
@@ -7,8 +9,9 @@
 - Ground speed
 - Flying time with automatic take-off detection
 
+
 ## Planned features:
-- Settings page to adjust QNH, change units 
+- glide slope display
 - final glide computer
 - waypoint navigation
 - flight log (possibly IGC file export)
diff --git a/apps/tinyVario/app.js b/apps/tinyVario/app.js
index cf7bc286d..b9a87c821 100644
--- a/apps/tinyVario/app.js
+++ b/apps/tinyVario/app.js
@@ -1,204 +1,465 @@
 /*
 To do:
-  -setup page
-  -different units
   -flight log
   -statistics page
-  -nav page
+  -navigation
 */
-Bangle.setBarometerPower(true, "tinyVario");
-Bangle.setGPSPower(true, "tinyVario");
+
+getAltitude = (p,baseP) => (44330 * (1.0 - Math.pow(p/baseP, 0.1903)));
+getFL = () => (44330 * (1.0 - Math.pow(pressure/1013.25, 0.1903))).toFixed(0);
+getTimeString = () => (settings.localTime) ? (require("locale").time(Date(),1)):(Date().toUTCString().slice(Date().toUTCString().length-12,Date().toUTCString().length-7));
+
+var fg=g.getColor();
+var bg=g.getBgColor();
+var red="#F00",green="#0F0";
 
 const unitsRoc=[
   {name:"m/s", factor:1, precision:1, layoutCode:{type:"v", halign:1, c: [
             {type:"txt", font:"12%", halign:0, filly:0, label:"m"},
-            {type:"", height:1,width:"20", bgCol:"#FFF"},
+            {type:"", height:1,width:"20", bgCol:fg},
             {type:"txt", font:"12%", halign:0, filly:0, label:"s"}]}},
   {name:"ft/m", factor:196.85039370078738, precision:0, layoutCode:{type:"v", halign:1, c: [
             {type:"txt", font:"12%", halign:0, filly:0, label:"ft"},
-            {type:"", height:1,width:"30", bgCol:"#FFF"},
+            {type:"", height:1,width:"30", bgCol:fg},
             {type:"txt", font:"12%", halign:0, filly:0, label:"min"}]}},
   {name:"kt", factor:1.9438444924406, precision:1, layoutCode:
             {type:"txt", font:"12%", halign:0, filly:0, label:"kt"}}
   ];
-
 const unitsGs=[
   {name:"km/h", factor:1, precision:1, layoutCode:{type:"v", halign:1, c: [
             {type:"txt", font:"12%", halign:0, filly:0, label:"km"},
-            {type:"", height:1,width:"30", bgCol:"#FFF"},
+            {type:"", height:1,width:"30", bgCol:fg},
             {type:"txt", font:"12%", halign:0, filly:0, label:"h"}]}},
-  {name:"kt", factor:196.85039370078738, precision:0, layoutCode:{type:"txt", font:"12%", halign:0, filly:0, label:"kt"}},
+  {name:"kt", factor:0.5399568, precision:0, layoutCode:{type:"txt", font:"12%", halign:0, filly:0, label:"kt"}},
   {name:"m/s", factor:0.2777777777777778, precision:1, layoutCode:{type:"v", halign:1, c: [
             {type:"txt", font:"12%", halign:0, filly:0, label:"m"},
-            {type:"", height:1,width:"20", bgCol:"#FFF"},
+            {type:"", height:1,width:"20", bgCol:fg},
             {type:"txt", font:"12%", halign:0, filly:0, label:"s"}]}}
   ];
-
 const unitsAlt=[
   {name:"m", factor:1, precision:0, layoutCode:{type:"txt", font:"12%", halign:0, filly:0, label:"m"}},
   {name:"ft", factor:3.280839895013123, precision:0, layoutCode:{type:"txt", font:"12%", halign:0, filly:0, label:"ft"}}
   ];
-
-var intTime=10,pressureInterval=100;
-var altH = [];
-var altRaw=-9999, altFast=0, altSlow=0;
-var fastGain=0.2, slowGain=0.168;
-var roc=0,rocAvg=0;
-var gs;
-var lastPressure = Date.now();
-var flying=false;
-var takeoffTime, flyingTime;
-var Layout = require("Layout");
-var speedUnit="km/h", speedFactor=1;
-var altUnit="m", altFactor=1;
-var rocUnit=unitsRoc[0];
-var altUnit=unitsAlt[0];
-var gsUnit=unitsGs[0];
-
-function drawVario() {
-  var p = pfd.vario;
-  g.reset();
-  g.clearRect(p.x,p.y,p.x+p.w-1,p.y+p.h-1);
-  if (roc>0.1) g.setColor(0,1,0);
-  if (roc<-1) g.setColor(1,0,0);
-  var y=p.y+p.h/2-roc*(p.h/2)/5;
-  g.fillRect(p.x,p.y+(p.h/2),p.x+p.w-1,Math.clip(y,p.y,p.y+p.h-1));
-}
-
-function updateText(t) {
-  if (t.halign==1) 
-    g.setFont(t.font).setFontAlign(1,0,0).drawString(t.label, t.x+t.w, t.y+(t.h>>1));
-  else if (t.halign==-1)
-    g.setFont(t.font).setFontAlign(-1,0,0).drawString(t.label, t.x, t.y+(t.h>>1));
-  else 
-    g.setFont(t.font).setFontAlign(0,0,0).drawString(t.label, t.x+(t.w>>1), t.y+(t.h>>1));
-}
-
-unitROC={type:"v", halign:1, c: [
+const unitROC={type:"v", halign:1, c: [
             {type:"txt", font:"12%", halign:0, filly:0, label:"m"},
-            {type:"", height:1,width:"20", bgCol:"#FFF"},
+            {type:"", height:1,width:"20", bgCol:fg},
             {type:"txt", font:"12%", halign:0, filly:0, label:"s"}
           ]};
 
-var pfd = new Layout(
-  {type:"v",c: [
-    {type:"h",c: [
-      {type:"", fillx:1, height:"1"}
-      ]},
-    {type:"h", c: [
-      /*{type:"v", c:[
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"},
-        {type:"", filly:1},
-        {type:"", width:"3", height:"3", bgCol:"#FFF"}
-      ]},*/
-      {type:"custom", width:"25", render:drawVario, id:"vario",filly:1 },
-      {type:"", filly:1, width:1, bgCol:"#FFF"},
-      {type:"v",fillx:1, c: [
-        {type:"h", halign:1, c:[
-          {type:"txt",font:"22%", halign:1, filly:1, label:"19999", id:"alt"},
-          altUnit.layoutCode 
-        ]},
-        {type:"", fillx:1, height:"1", bgCol:"#FFF"},
-        {type:"h", halign:1, c:[
-          {type:"txt", font:"25%", halign:1, filly:1, label:"-99.9", id:"avg" },
-          rocUnit.layoutCode
-        ]},
-        {type:"", fillx:1, height:"1", bgCol:"#FFF"},
-        {type:"h", halign:1, c:[
-          {type:"txt", font:"25%", halign:1, filly:1, label:"XXX", id:"gs" },
-          gsUnit.layoutCode
+const ground=0, flying=1, landed=2, maybeFlying=3, maybeLanded=4;
+
+var settings = Object.assign({
+  rocU: 0,
+  altU: 0,
+  gsU:0,
+  intTime:10,
+  localTime:true,
+  autoDetect:true,
+  bargraph:false
+}, require('Storage').readJSON("tinyVario.json", true) || {});
+
+var qnh=Math.floor(Bangle.getOptions().seaLevelPressure) || 1013;
+var pfdHandle;
+var rawP=0, samples=0;
+var altH = [];
+var altRaw=-9999, altFast=0, altSlow=0;
+var fastGain=0.5, slowGain=0.3;
+var roc=0,rocAvg=0, gs;
+var lastPressure = Date.now();
+var pressure = 1000;
+var state=ground;
+var takeoffTime=0, landingTime=0, flyingTime;
+var Layout = require("Layout");
+var oldSettings;
+
+//var delta=0;//TESTING
+
+
+function updateText(t) {
+  g.reset();
+  g.clearRect(t.x,t.y,t.x+t.w-1,t.y+t.h-1);
+  if (t.col) g.setColor(t.col);
+  else g.setColor(fg);
+  if (t.halign==1)
+    g.setFont(t.font).setFontAlign(1,0,0).drawString(t.label, t.x+t.w, t.y+(t.h>>1));
+  else if (t.halign==-1)
+    g.setFont(t.font).setFontAlign(-1,0,0).drawString(t.label, t.x, t.y+(t.h>>1));
+  else
+    g.setFont(t.font).setFontAlign(0,0,0).drawString(t.label, t.x+(t.w>>1), t.y+(t.h>>1));
+}
+
+function initPFD() {
+  Bangle.setUI();
+  var pfd = new Layout(
+    {type:"v",c: [
+      /*{type:"h",c: [
+        {type:"", fillx:1, height:"1"}
+        ]},*/
+      {type:"h",filly:1, c: [
+        {type:"custom", width:"25", render:()=>{
+          var p = pfd.vario;
+          if (roc>0.1) g.setColor(0,1,0);
+          if (roc<-1) g.setColor(1,0,0);
+          var y=p.y+p.h/2-roc*(p.h/2)/5;
+          if (settings.bargraph==false) {
+            g.clearRect(p.x,p.y,p.x+p.w-1,p.y+p.h-1);
+            g.fillRect(p.x,p.y+(p.h/2),p.x+p.w-1,Math.clip(y,p.y,p.y+p.h-1));
+          } else {
+            g.setClipRect(p.x,p.y,p.x+p.w-1,p.y+p.h-1);
+            g.scroll(-1,0);
+            g.drawLine(p.x+p.w-1,p.y+(p.h/2),p.x+p.w-1,Math.clip(y,p.y,p.y+p.h-1));
+          }
+          g.reset();
+        }, id:"vario",filly:1, cb:()=>initVarioMenu()},
+        {type:"", filly:1, width:1, bgCol:fg},
+        {type:"v",fillx:1, c: [
+          {type:"h", halign:1, c:[
+            {type:"txt", font:"22%", halign:1, filly:1, fillx:1, label:"9999", id:"alt", cb:()=>initAltMenu()},
+            unitsAlt[settings.altU].layoutCode
+          ]},
+          {type:"", fillx:1, height:"1", bgCol:fg},
+          {type:"h", halign:1, c:[
+            {type:"txt", font:"25%", halign:1, filly:1, fillx:1, label:"-9.9", id:"avg", cb:()=>initAvgMenu()},
+            unitsRoc[settings.rocU].layoutCode
+          ]},
+          {type:"", fillx:1, height:"1", bgCol:fg},
+          {type:"h", halign:1, c:[
+            {type:"txt", font:"25%", halign:1, filly:1, fillx:1, label:"XXX", id:"gs", cb:()=>initGsMenu()},
+            unitsGs[settings.gsU].layoutCode
+          ]}
         ]}
+      ]},
+      {type:"", fillx:1, height:"1", bgCol:fg},
+      {type:"h",c: [
+        {type:"txt",pad:0, halign:0, font:"15%",fillx:1, label:"99:99", id:"time", cb:()=>initTimeMenu()},
+        {type:"", width:1,height:g.getHeight()*0.15, bgCol:fg},
+        {type:"txt",pad:0, halign:0, font:"15%", fillx:1, label:"--:--", id:"flyingtime", cb:()=>initFlyingTimeMenu() }
       ]}
-    ]},
-    {type:"", fillx:1, height:"1", bgCol:"#FFF"},
-    {type:"h",c: [
-      {type:"txt",pad:"1", halign:0, font:"15%",fillx:"1", label:"99:99", id:"time"},
-      {type:"", width:"1", height:g.getHeight()*0.15+2, bgCol:"#FFF"},
-      {type:"txt",pad:"1", halign:0, font:"15%", fillx:"1", label:"99:99", id:"flyingtime" }
-    ]}
-  ]}//,{lazy:"true"}
-);
-pfd.update();
+    ]},{lazy:true}
+  );
+  g.clear();
+  pfd.render();
+  //-------testing------
+  //rawP=1000;
+  //samples=1;
+  //--------------------
+  pfdHandle = setInterval(function() {
+    t1=Date().getTime();
+    //process pressure readings
+    if (samples) {
+      pressure=rawP/samples;
+      samples=0;
+      rawP=0;
+      if (altRaw==-9999) {//first measurement)
+        altRaw=getAltitude(pressure,qnh);
+        altFast=altRaw;
+        altSlow=altRaw;
+        for (let i = 0; i < settings.intTime*4+1; i++) altH.push(altRaw);
+      }
+    }
+    //altRaw=altRaw+delta;getAltitude(pressure,qnh);//TESTING
+    altRaw=getAltitude(pressure,qnh);
+    altFast=altFast+(altRaw-altFast)*fastGain;
+    altSlow=altSlow+(altRaw-altSlow)*slowGain;
+    altH.push(altFast);
+    while (altH.length>settings.intTime*4) {
+      rocAvg=(altH[altH.length-1]-altH[0])/settings.intTime;
+      altH.shift();
+    }
+    roc=(altFast-altSlow)/((0.25/slowGain)-(0.25/fastGain));
+
+    if (settings.autoDetect==true) switch (state) {
+      case ground:
+        if ((gs>=5) || (roc>=1) || (roc<=-1)) {
+          state=maybeFlying;
+          takeoffTime=Date().getTime();
+        }
+        break;
+      case maybeFlying:
+        if (!(gs>=5) && (roc<1) && (roc>-1)) state=ground;
+        else if (Date().getTime()-takeoffTime>60000) state=flying;
+        break;
+      case flying:
+        if (!(gs>=5) && (roc<1) && (roc>-1)) {
+          state=maybeLanded;
+          landingTime=Date().getTime();
+        }
+        break;
+      case maybeLanded:
+        if ((gs>=5) || (roc>=1) || (roc<=-1)) state=flying;
+        else if (Date().getTime()-landingTime>60000) state=landed;
+        break;
+    }
+    if ((state==flying) || (state==maybeLanded)) {
+      flyingTime=Date().getTime()-takeoffTime;
+      pfd.flyingtime.label=(flyingTime / 3600000).toFixed(0)+":"+(flyingTime / 60000 % 60).toFixed(0).padStart(2,'0');
+      pfd.flyingtime.col=fg;
+    } else if (state==landed) {
+      flyingTime=landingTime-takeoffTime;
+      pfd.flyingtime.label=(flyingTime / 3600000).toFixed(0)+":"+(flyingTime / 60000 % 60).toFixed(0).padStart(2,'0');
+      pfd.flyingtime.col=green;
+    }
+
+    pfd.alt.label=(altRaw*unitsAlt[settings.altU].factor).toFixed(unitsAlt[settings.altU].precision);
+    pfd.avg.col=(rocAvg<-1) ? (red):((rocAvg>0.1) ? (green):(fg));
+    pfd.avg.label=(rocAvg*unitsRoc[settings.rocU].factor).toFixed(unitsRoc[settings.rocU].precision);
+
+    var gps = Bangle.getGPSFix();
+    if (gps!=undefined) {
+      pfd.gs.label=(gps.speed*unitsGs[settings.gsU].factor).toFixed(unitsGs[settings.gsU].precision);
+      updateText(pfd.gs);
+      gs=gps.speed;
+    } //else gs=0;
+    
+    pfd.time.label=getTimeString();
+    updateText(pfd.alt);
+    updateText(pfd.avg);
+    updateText(pfd.time);
+    updateText(pfd.flyingtime);
+
+    pfd.vario.render();
+    //print(Date().getTime()-t1);
+  }, 250);
+
+}
+
+function initAltMenu() {
+  var oldQnh=qnh;
+  function updateAltMenu() {
+    altMenu.clear();
+    altMenu.alt.label=
+      (getAltitude(pressure,qnh)*unitsAlt[settings.altU].factor).toFixed(unitsAlt[settings.altU].precision)
+      +unitsAlt[settings.altU].name;
+    altMenu.qnh.label=qnh;
+    altMenu.render();
+  }
+  oldSettings=Object.assign({},settings);
+  clearInterval(pfdHandle);
+  var altMenu = new Layout ({
+    type:"v", c: [{
+      type:"v", width:180, c: [
+        {type:"h", c: [
+          {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label:"-", cb:l=>{qnh--; updateAltMenu();}},
+          {type:"btn", font:"15%", pad:1, fillx:1, filly:1, label:"+", cb:l=>{qnh++; updateAltMenu();}}
+        ]},
+        {type:"v", c: [
+          {type:"h", c: [
+            {type:"txt", font:"13%", fillx:1, filly:1, label:"QNH: "},
+            {type:"txt", font:"13%", fillx:1, filly:1, id:"qnh", label:"    "},
+          ]},
+          {type:"h", c: [
+            {type:"txt", font:"13%", fillx:1, filly:1, label:"Alt: "},
+            {type:"txt", font:"13%", fillx:1, filly:1, id:"alt", label: "      "},
+          ]}
+        ]},
+        {type:"btn", font:"12%", id:"units", pad:2, fillx:1, filly:1, label:"Units: "+unitsAlt[settings.altU].name, cb:()=>{
+          settings.altU=(settings.altU+1)%unitsAlt.length;
+          altMenu.units.label="Units: "+unitsAlt[settings.altU].name;
+          altMenu.render();
+        }},
+      ]},
+      {type:"h", c: [
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"BACK", cb: ()=>{
+          settings=Object.assign({},oldSettings);
+          print("old settings restored");
+          initPFD();
+        }},
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"SAVE", cb: ()=>{
+          require('Storage').writeJSON("tinyVario.json", settings);
+          Bangle.setOptions({seaLevelPressure:qnh});
+          initPFD();
+        }}
+      ]}
+    ], lazy:true});
+  g.clear();
+  altMenu.render();
+  updateAltMenu();
+}
+
+function initAvgMenu() {
+  oldSettings=Object.assign({},settings);
+  clearInterval(pfdHandle);
+  var avgMenu = new Layout ({
+    type:"v", c: [{
+      type:"v", width:180, c: [
+        {type:"h", c: [
+          {type:"btn", font:"12%", pad:2, fillx:1, filly:1, label:"-", cb:l=>{
+            settings.intTime=Math.clip(settings.intTime-1,1,60);
+            avgMenu.clear();
+            avgMenu.interval.label="Interval: "+settings.intTime+"s";
+            avgMenu.render();
+          }},
+          {type:"btn", font:"12%", pad:1, fillx:1, filly:1, label:"+", cb:l=>{
+            settings.intTime=Math.clip(settings.intTime+1,1,60);
+            avgMenu.clear();
+            avgMenu.interval.label="Interval: "+settings.intTime+"s";
+            avgMenu.render();
+          }}
+        ]},
+        {type:"txt", id:"interval", font:"10%", pad:1, fillx:1, filly:1, label:"Interval: "+settings.intTime+"s"},
+        {type:"btn", font:"12%", id:"units", pad:1, fillx:1, filly:1, label:"Units: "+unitsRoc[settings.rocU].name, cb:()=>{
+          settings.rocU=(settings.rocU+1)%unitsRoc.length;
+          avgMenu.units.label="Units: "+unitsRoc[settings.rocU].name;
+          avgMenu.render();
+        }},
+      ]},
+      {type:"h", c: [
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"BACK", cb: ()=>{
+          settings=Object.assign({},oldSettings);
+          initPFD();
+        }},
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"SAVE", cb: ()=>{
+          require('Storage').writeJSON("tinyVario.json", settings);
+          initPFD();
+        }}
+      ]}
+    ], lazy:true});
+  g.clear();
+  avgMenu.render();
+}
+
+function initGsMenu() {
+  oldSettings=Object.assign({},settings);
+  clearInterval(pfdHandle);
+  var gsMenu = new Layout ({
+    type:"v", c: [
+      {type:"btn", font:"20%", id:"units", pad:1, fillx:1, filly:1, label:"Units:\n"+unitsGs[settings.gsU].name, cb:()=>{
+        settings.gsU=(settings.gsU+1)%unitsGs.length;
+        gsMenu.units.label="Units:\n"+unitsGs[settings.gsU].name;
+        gsMenu.render();
+      }},
+      {type:"h", c: [
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"BACK", cb: ()=>{
+          settings=Object.assign({},oldSettings);
+          print("old settings restored");
+          initPFD();
+        }},
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"SAVE", cb: ()=>{
+          require('Storage').writeJSON("tinyVario.json", settings);
+          initPFD();
+        }}
+      ]}
+    ], lazy:true});
+  g.clear();
+  gsMenu.render();
+}
+
+function initTimeMenu() {
+  oldSettings=Object.assign({},settings);
+  clearInterval(pfdHandle);
+  var timeMenu = new Layout ({
+    type:"v", c: [
+      {type:"btn", font:"20%", id:"format", pad:1, fillx:1, filly:1, label:"Time:\n"+((settings.localTime==true) ? ("LCL") : ("UTC")), cb:()=>{
+        settings.localTime=!settings.localTime;
+        timeMenu.format.label="Time:\n"+((settings.localTime==true) ? ("LCL") : ("UTC"));
+        timeMenu.render();
+      }},
+      {type:"h", c: [
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"BACK", cb: ()=>{
+          settings=Object.assign({},oldSettings);
+          initPFD();
+        }},
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"SAVE", cb: ()=>{
+          require('Storage').writeJSON("tinyVario.json", settings);
+          initPFD();
+        }}
+      ]}
+    ], lazy:true});
+  g.clear();
+  timeMenu.render();
+}
+
+function initVarioMenu() {
+  oldSettings=Object.assign({},settings);
+  clearInterval(pfdHandle);
+  var varioMenu = new Layout ({
+    type:"v", c: [
+      {type:"btn", font:"20%", id:"format", pad:1, fillx:1, filly:1, label:"Display:\n"+((settings.bargraph==true) ? ("graph") : ("simple")), cb:()=>{
+        settings.bargraph=!settings.bargraph;
+        varioMenu.format.label="Display:\n"+((settings.bargraph==true) ? ("graph") : ("simple"));
+        varioMenu.render();
+      }},
+      {type:"h", c: [
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"BACK", cb: ()=>{
+          settings=Object.assign({},oldSettings);
+          initPFD();
+        }},
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"SAVE", cb: ()=>{
+          require('Storage').writeJSON("tinyVario.json", settings);
+          initPFD();
+        }}
+      ]}
+    ], lazy:true});
+  g.clear();
+  varioMenu.render();
+}
+function initFlyingTimeMenu() {
+  oldSettings=Object.assign({},settings);
+  clearInterval(pfdHandle);
+  var ftMenu = new Layout (
+    {type:"v", c: [
+      {type:"v", c: [
+        {type:"h", c: [
+          {type:"btn", font:"12%", pad:1, fillx:1, filly:1, label:"Toggle\nAuto", cb:()=>{
+            settings.autoDetect=!settings.autoDetect;
+            ftMenu.manual.label= (settings.autoDetect==true)? 
+              ("AUTO"):((state==flying) ? ("LAND") : ("TAKE\nOFF"));
+            ftMenu.render();
+          }},
+          {type:"btn", font:"12%", id:"manual", pad:1, fillx:1, filly:1, label:(settings.autoDetect==true)? 
+            ("AUTO"):((state==flying) ? ("LAND") : ("TAKE\nOFF")), cb:()=>{
+              if (settings.autoDetect==false) {
+                if (state!=flying) {
+                  E.showPrompt("Take off now?").then((v)=> {
+                    if (v) {
+                      state=flying;
+                      takeoffTime=Date().getTime();
+                      initPFD();
+                    }
+                  });
+                } else {
+                  E.showPrompt("Land now?").then((v)=> {
+                    if (v) {
+                      state=landed;
+                      landingTime=Date().getTime();
+                      initPFD();
+                    }
+                  });
+                }
+              }
+            }
+          }
+        ]},
+        {type:"btn", font:"12%", pad:1, fillx:1, filly:1, label:"Reset", cb:()=>{
+          E.showPrompt("Reset Flight?").then((v)=> {
+            state=ground;
+            initPFD();
+          });
+        }}
+      ]},
+      {type:"h", c: [
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"BACK", cb: ()=>{
+          settings=Object.assign({},oldSettings);
+          initPFD();
+        }},
+        {type:"btn", font:"16%", pad:1, fillx:1, label:"SAVE", cb: ()=>{
+          require('Storage').writeJSON("tinyVario.json", settings);
+          initPFD();
+        }}
+      ]}
+    ], lazy:true});
+  g.clear();
+  ftMenu.render();
+}
+
+Bangle.setGPSPower(true, "tinyVario");
+Bangle.setBarometerPower(true, "tinyVario");
 
 Bangle.on('pressure', function(e) {
-  if (altRaw==-9999) {
-    altFast=e.altitude;
-    altSlow=e.altitude;
-    altRaw=e.altitude;
+  if (samples<10) { //no need to gather more samples when stuck in a menu
+    rawP+=e.pressure;
+    samples++;
   }
-  altRaw=altRaw+(e.altitude-altRaw)*0.2;
 });
 
-Bangle.on('GPS', function(fix) {
-  gs=fix.speed;
-});
-          
-/*setWatch(function() {
-  
-}, BTN1);*/
-
-setInterval(function () { 
-  altFast=altFast+(altRaw-altFast)*fastGain;
-  altSlow=altSlow+(altRaw-altSlow)*0.09093;
-  altH.push(altSlow);
-  if (altH.length>intTime*1000/pressureInterval) {
-    altH.shift();
-    rocAvg=(altH[altH.length-1]-altH[0])/intTime;
-  }
-}, pressureInterval);
-
-g.clear();
-pfd.render();
-
-setInterval(function() {
-  pfd.clear(pfd.alt);
-  pfd.clear(pfd.avg);
-  pfd.clear(pfd.time);
-  if ((!flying) && ((rocAvg>1) || (rocAvg<-1) || (gs>10))) { //take-off detected
-    takeoffTime=Date().getTime();
-    flying=true;
-  } 
-  if (flying) {
-    pfd.clear(pfd.flyingtime);
-    flyingTime=Date().getTime()-takeoffTime;
-    pfd.flyingtime.label=(flyingTime / 3600000).toFixed(0)+":"+(flyingTime / 60000 % 60).toFixed(0).padStart(2,'0');
-  } 
-  roc=(altFast-altSlow)/(pressureInterval/1000/slowGain)-(pressureInterval/1000/fastGain);
-  pfd.alt.label=(altSlow).toFixed(0);
-  if (rocAvg>0.1) pfd.avg.col="#0f0";
-    else if (rocAvg<-1) pfd.avg.col="#f00";
-    else pfd.avg.col="#fff";
-  pfd.avg.label=(rocAvg*rocUnit.factor).toFixed(rocUnit.precision);
-  if (!isNaN(gs)) {
-    pfd.gs.label=gs.toFixed(0);
-    pfd.clear(pfd.gs);
-  } 
-  pfd.time.label=require("locale").time(Date(),1);
-  updateText(pfd.alt);
-  updateText(pfd.avg);
-  updateText(pfd.gs);
-  updateText(pfd.time);
-  updateText(pfd.flyingtime);
-  drawVario();
- // pfd.debug(pfd.roc);
-  //pfd.render();  
-}, 250);
-
+initPFD();
diff --git a/apps/tinyVario/metadata.json b/apps/tinyVario/metadata.json
index c8bc3659e..f038e7515 100644
--- a/apps/tinyVario/metadata.json
+++ b/apps/tinyVario/metadata.json
@@ -1,7 +1,7 @@
 { "id": "tinyVario",
   "name": "Tiny Vario",
   "shortName" : "tinyVario",
-  "version":"0.01",
+  "version":"0.05",
   "icon": "app.png",
   "readme": "README.md",
   "description": "A very simple app for gliding / paragliding / hang gliding etc.",
@@ -10,5 +10,6 @@
   "storage": [
     {"name":"tinyVario.app.js","url":"app.js"},
     {"name":"tinyVario.img","url":"app-icon.js","evaluate":true}
-    ]
+    ],
+  "data": [{"name":"tinyVario.json"}]
 }
diff --git a/apps/torch/ChangeLog b/apps/torch/ChangeLog
index 4d8f47500..35d3f5927 100644
--- a/apps/torch/ChangeLog
+++ b/apps/torch/ChangeLog
@@ -2,3 +2,10 @@
 0.02: Change start sequence to BTN1/3/1/3 to avoid accidental turning on (fix #342)
 0.03: Add Color Changing Settings
 0.04: Add Support For Bangle.js 2
+0.05: Default full Brightness
+0.06: Press upper left corner to exit on Bangle.js 2
+0.07: Code tweaks
+0.08: Force background of widget field to the torch colour
+0.09: Change code taking FW tweaks into account
+0.10: Introduce fast switching.
+0.11: Make compatible with Fastload Utils by loading and hiding widgets.
diff --git a/apps/torch/README.md b/apps/torch/README.md
new file mode 100644
index 000000000..e06861071
--- /dev/null
+++ b/apps/torch/README.md
@@ -0,0 +1,2 @@
+On Bangle.js 2, pressing the upper left corner where the red back button would be exits the app if the screen is unlocked.
+
diff --git a/apps/torch/app.js b/apps/torch/app.js
index 864efb883..b44cfb929 100644
--- a/apps/torch/app.js
+++ b/apps/torch/app.js
@@ -1,19 +1,36 @@
-const SETTINGS_FILE = "torch.json";
-let settings;
+{
+  const SETTINGS_FILE = "torch.json";
+  let settings;
+  let s = require("Storage");
+  let wu = require("widget_utils");
 
-function loadSettings() {
-  settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#FFFFFF', 'color': 'White'};
+  let loadSettings = function() {
+    settings = s.readJSON(SETTINGS_FILE,1)|| {'bg': '#FFFFFF', 'color': 'White'};
+  };
+
+  loadSettings();
+
+  let brightnessBackup = s.readJSON('setting.json').brightness;
+  let optionsBackup = Bangle.getOptions();
+  Bangle.setLCDBrightness(1);
+  Bangle.setLCDPower(1);
+  Bangle.setLCDTimeout(0);
+  g.reset();
+  let themeBackup = g.theme;
+  g.setTheme({bg:settings.bg,fg:"#000"});
+  g.setColor(settings.bg);
+  g.fillRect(0,0,g.getWidth(),g.getHeight());
+  Bangle.loadWidgets();
+  wu.hide();
+  Bangle.setUI({
+    mode : 'custom',
+    back : Bangle.showClock, // B2: SW back button to exit
+    btn :  _=>Bangle.showClock(), // B1&2: HW button to exit. 
+    remove : ()=>{
+      Bangle.setLCDBrightness(brightnessBackup);
+      Bangle.setOptions(optionsBackup);
+      g.setTheme(themeBackup);
+      wu.show();
+    }
+  });
 }
-
-loadSettings();
-
-Bangle.setLCDPower(1);
-Bangle.setLCDTimeout(0);
-g.reset();
-g.setColor(settings.bg);
-g.fillRect(0,0,g.getWidth(),g.getHeight());
-// Any button turns off
-setWatch(()=>load(), BTN1);
-if (global.BTN2) setWatch(()=>load(), BTN2);
-if (global.BTN3) setWatch(()=>load(), BTN3);
-
diff --git a/apps/torch/metadata.json b/apps/torch/metadata.json
index 37e6f6b95..4e8794663 100644
--- a/apps/torch/metadata.json
+++ b/apps/torch/metadata.json
@@ -2,7 +2,7 @@
   "id": "torch",
   "name": "Torch",
   "shortName": "Torch",
-  "version": "0.04",
+  "version": "0.11",
   "description": "Turns screen white to help you see in the dark. Select from the launcher or press BTN1,BTN3,BTN1,BTN3 quickly to start when in any app that shows widgets on Bangle.js 1. You can also set the color through the app's setting menu.",
   "icon": "app.png",
   "tags": "tool,torch",
diff --git a/apps/twenties/ChangeLog b/apps/twenties/ChangeLog
new file mode 100644
index 000000000..89eb9547f
--- /dev/null
+++ b/apps/twenties/ChangeLog
@@ -0,0 +1,4 @@
+0.01: New Widget!
+0.02: Fix calling null on draw
+0.03: Only vibrate during work
+0.04: Convert to boot code
\ No newline at end of file
diff --git a/apps/twenties/README.md b/apps/twenties/README.md
new file mode 100644
index 000000000..8ee917b0e
--- /dev/null
+++ b/apps/twenties/README.md
@@ -0,0 +1,17 @@
+# Twenties
+
+Follow the [20-20-20 rule](https://www.aoa.org/AOA/Images/Patients/Eye%20Conditions/20-20-20-rule.pdf) with discrete reminders. Your Bangle will buzz every 20 minutes for you to look away from your screen, and then buzz 20 seconds later to look back. Additionally, alternate between standing and sitting every 20 minutes to be standing for [more than 30 minutes](https://uwaterloo.ca/kinesiology-health-sciences/how-long-should-you-stand-rather-sit-your-work-station) per hour.
+
+## Usage
+
+Download this app and it will automatically run in the background.
+
+## Features
+
+Vibrates to remind you to stand up and look away for healthy living.
+
+Only vibrates during work days and hours.
+
+## Creator
+
+[@splch](https://github.com/splch/)
diff --git a/apps/twenties/app.png b/apps/twenties/app.png
new file mode 100644
index 000000000..7c6b02055
Binary files /dev/null and b/apps/twenties/app.png differ
diff --git a/apps/twenties/boot.js b/apps/twenties/boot.js
new file mode 100644
index 000000000..722af43bc
--- /dev/null
+++ b/apps/twenties/boot.js
@@ -0,0 +1,19 @@
+(() => {
+  const move = 20 * 60 * 1000; // 20 minutes
+  const look = 20 * 1000;      // 20 seconds
+
+  const buzz = _ => {
+    const date = new Date();
+    const day = date.getDay();
+    const hour = date.getHours();
+    // buzz at work
+    if (day >= 1 && day <= 5 &&
+      hour >= 8 && hour <= 17) {
+      Bangle.buzz().then(_ => {
+        setTimeout(Bangle.buzz, look);
+      });
+    }
+  };
+
+  setInterval(buzz, move); // buzz to stand / sit
+})();
diff --git a/apps/twenties/metadata.json b/apps/twenties/metadata.json
new file mode 100644
index 000000000..b1dfe2134
--- /dev/null
+++ b/apps/twenties/metadata.json
@@ -0,0 +1,13 @@
+{
+  "id": "twenties",
+  "name": "Twenties",
+  "shortName": "twenties",
+  "version": "0.04",
+  "description": "Buzzes every 20m to stand / sit and look 20ft away for 20s.",
+  "icon": "app.png",
+  "type": "bootloader",
+  "tags": "alarm,tool",
+  "supports": ["BANGLEJS", "BANGLEJS2"],
+  "readme": "README.md",
+  "storage": [{ "name": "twenties.boot.js", "url": "boot.js" }]
+}
diff --git a/apps/verticalface/ChangeLog b/apps/verticalface/ChangeLog
index 99ab68ec4..dc6c11eab 100644
--- a/apps/verticalface/ChangeLog
+++ b/apps/verticalface/ChangeLog
@@ -4,3 +4,4 @@
 0.07: Added leading zero to hours and minutes
 0.08: Show step count by calling wpedom.getSteps() or activepedom.getSteps()
 0.09: Fix time when minutes<10 and hours>9 (fix #767)
+0.10: Tell clock widgets to hide.
diff --git a/apps/verticalface/app.js b/apps/verticalface/app.js
index 4fcae5642..178481047 100644
--- a/apps/verticalface/app.js
+++ b/apps/verticalface/app.js
@@ -97,6 +97,28 @@ function drawBattery() {
 // Clear the screen once, at startup
 g.clear();
 
+// Show launcher when button pressed
+Bangle.setUI("clockupdown", btn=>{
+  if (btn!=0) return;
+  //HRM Controller.
+  if(!HRMstate){
+    //console.log("Toggled HRM");
+    //Turn on.
+    Bangle.buzz();
+    Bangle.setHRMPower(1);
+    currentHRM = "CALC";
+    HRMstate = true;
+  } else if(HRMstate){
+    //console.log("Toggled HRM");
+    //Turn off.
+    Bangle.buzz();
+    Bangle.setHRMPower(0);
+    HRMstate = false;
+    currentHRM = [];
+  }
+  drawBPM(HRMstate);
+});
+
 // Load and draw widgets
 Bangle.loadWidgets();
 Bangle.drawWidgets();
@@ -128,28 +150,6 @@ Bangle.on('lcdPower',on=>{
   }
 });
 
-// Show launcher when button pressed
-Bangle.setUI("clockupdown", btn=>{
-  if (btn!=0) return;
-  //HRM Controller.
-  if(!HRMstate){
-    //console.log("Toggled HRM");
-    //Turn on.
-    Bangle.buzz();
-    Bangle.setHRMPower(1);
-    currentHRM = "CALC";
-    HRMstate = true;
-  } else if(HRMstate){
-    //console.log("Toggled HRM");
-    //Turn off.
-    Bangle.buzz();
-    Bangle.setHRMPower(0);
-    HRMstate = false;
-    currentHRM = [];
-  }
-  drawBPM(HRMstate);
-});
-
 Bangle.on('touch', function(button) {
   if(button == 1 || button == 2){
     Bangle.showLauncher();
diff --git a/apps/verticalface/metadata.json b/apps/verticalface/metadata.json
index da41b3f0d..273070022 100644
--- a/apps/verticalface/metadata.json
+++ b/apps/verticalface/metadata.json
@@ -2,7 +2,7 @@
   "id": "verticalface",
   "name": "Vertical watch face",
   "shortName": "Vertical Face",
-  "version": "0.09",
+  "version": "0.10",
   "description": "A simple vertical watch face with the date. Heart rate monitor is toggled with BTN1",
   "icon": "app.png",
   "type": "clock",
diff --git a/apps/waypointer/ChangeLog b/apps/waypointer/ChangeLog
index 7ccad08ea..8613ef799 100644
--- a/apps/waypointer/ChangeLog
+++ b/apps/waypointer/ChangeLog
@@ -1,3 +1,7 @@
 0.01: New app!
 0.02: Make Bangle.js 2 compatible
 0.03: Silently use built in heading when no magnav calibration file is present
+0.04: Move waypoints.json (and editor) to 'waypoints' app
+0.05: Fix not displaying of wpindex = 0
+0.06: Added adjustment for Bangle.js magnetometer heading fix
+0.07: Add settings file with the option to disable the slow direction updates
diff --git a/apps/waypointer/README.md b/apps/waypointer/README.md
index c0b4c5125..241d70a65 100644
--- a/apps/waypointer/README.md
+++ b/apps/waypointer/README.md
@@ -61,58 +61,10 @@ The app indicates that WP2 is now marked by adding the prefix @ to
 it's name. The distance should be small as shown in the screen shot
 as you have just marked your current location.
 
-## Waypoint JSON file
-
-When the app is loaded from the app loader, a file named
-`waypoints.json` is loaded along with the javascript etc. The file
-has the following contents:
-
-
-```
-[
-  {
-  "name":"NONE"
-  },
-  {
-  "name":"No10",
-  "lat":51.5032,
-  "lon":-0.1269
-  },
-  {
-  "name":"Stone",
-  "lat":51.1788,
-  "lon":-1.8260
-  },
-  { "name":"WP0" },
-  { "name":"WP1" },
-  { "name":"WP2" },
-  { "name":"WP3" },
-  { "name":"WP4" }
-]
-```
-
-The file contains the initial NONE waypoint which is useful if you
-just want to display course and speed. The next two entries are
-waypoints to No 10 Downing Street and to Stone Henge - obtained from
-Google Maps. The last five entries are entries which can be *marked*.
-
-You add and delete entries using the Web IDE to load and then save
-the file from and to watch storage. The app itself does not limit the
-number of entries although it does load the entire file into RAM
-which will obviously limit this.
-
-
-## Waypoint Editor
-
-Clicking on the download icon of gpsnav in the app loader invokes the
-waypoint editor.  The editor downloads and displays the current
-`waypoints.json` file. Clicking the `Edit` button beside an entry
-causes the entry to be deleted from the list and displayed in the
-edit boxes. It can be restored - by clicking the `Add waypoint`
-button. A new markable entry is created by using the `Add name`
-button. The edited `waypoints.json` file is uploaded to the Bangle by
-clicking the `Upload` button.
+## Setting Waypoints
 
+Check out the documentation for the `Waypoints` app. This provides
+the ability to set waypoints from your browser.
 
 ## Calibration of the Compass
 
diff --git a/apps/waypointer/app.js b/apps/waypointer/app.js
index bdb6f6857..de6bfdcaa 100644
--- a/apps/waypointer/app.js
+++ b/apps/waypointer/app.js
@@ -8,6 +8,11 @@ var buf1 = Graphics.createArrayBuffer(160*scale,160*scale,1, {msb:true});
 var buf2 = Graphics.createArrayBuffer(g.getWidth()/3,40*scale,1, {msb:true});
 var arrow_img = require("heatshrink").decompress(atob("lEowIPMjAEDngEDvwED/4DCgP/wAEBgf/4AEBg//8AEBh//+AEBj///AEBn///gEBv///wmCAAImCAAIoBFggE/AkaaEABo="));
 
+var settings = Object.assign({
+  // default values
+  smoothDirection: true,
+}, require('Storage').readJSON("waypointer.json", true) || {});
+
 function flip1(x,y) {
   g.drawImage({width:160*scale,height:160*scale,bpp:1,buffer:buf1.buffer, palette:pal_by},x,y);
   buf1.clear();
@@ -50,7 +55,7 @@ function drawCompass(course) {
   if(!candraw) return;
   if (Math.abs(previous.course - course) < 9) return; // reduce number of draws due to compass jitter
   previous.course = course;
-  
+
   buf1.setColor(1);
   buf1.fillCircle(buf1.getWidth()/2,buf1.getHeight()/2,79*scale);
   buf1.setColor(0);
@@ -63,12 +68,17 @@ function drawCompass(course) {
 /***** COMPASS CODE ***********/
 
 var heading = 0;
-function newHeading(m,h){ 
+function newHeading(m,h){
     var s = Math.abs(m - h);
     var delta = (m>h)?1:-1;
-    if (s>=180){s=360-s; delta = -delta;} 
+    if (s>=180){s=360-s; delta = -delta;}
     if (s<2) return h;
-    var hd = h + delta*(1 + Math.round(s/5));
+    var hd;
+    if (settings.smoothDirection) {
+        hd = h + delta*(1 + Math.round(s/5));
+    } else {
+        hd = h + delta*s;
+    }
     if (hd<0) hd+=360;
     if (hd>360)hd-= 360;
     return hd;
@@ -80,7 +90,7 @@ function tiltfixread(O,S){
   var m = Bangle.getCompass();
   if (O === undefined || S === undefined) {
     // no valid calibration from magnav, use built in
-    return 360-m.heading;
+    return m.heading;
   }
   var g = Bangle.getAccel();
   m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z;
@@ -147,9 +157,9 @@ function drawN(){
   var bs = wp_bearing.toString();
   bs = wp_bearing<10?"00"+bs : wp_bearing<100 ?"0"+bs : bs;
   var dst = loc.distance(dist);
-  
+
   // -1=left (default), 0=center, 1=right
-  
+
   // show distance on the left
   if (previous.dst !== dst) {
     previous.dst = dst;
@@ -159,7 +169,7 @@ function drawN(){
     buf2.drawString(dst,0,0);
     flip2_bw(0, g.getHeight()-40*scale);
   }
-  
+
   // bearing, place in middle at bottom of compass
   if (previous.bs !== bs) {
     previous.bs = bs;
@@ -192,7 +202,7 @@ function onGPS(fix) {
   if (fix!==undefined){
     satellites = fix.satellites;
   }
-  
+
   if (candraw) {
     if (fix!==undefined && fix.fix==1){
       dist = distance(fix,wp);
@@ -240,7 +250,7 @@ function setButtons(){
     else { doselect(); }
   });
 }
- 
+
 Bangle.on('lcdPower',function(on) {
   if (on) {
     clear_previous();
@@ -250,7 +260,7 @@ Bangle.on('lcdPower',function(on) {
   }
 });
 
-var waypoints = require("Storage").readJSON("waypoints.json")||[{name:"NONE"}];
+var waypoints = require("waypoints").load();
 wp=waypoints[0];
 
 function nextwp(inc){
@@ -263,10 +273,10 @@ function nextwp(inc){
 }
 
 function doselect(){
-  if (selected && wpindex!=0 && waypoints[wpindex].lat===undefined && savedfix.fix) {
+  if (selected && wpindex>=0 && waypoints[wpindex].lat===undefined && savedfix.fix) {
      waypoints[wpindex] ={name:"@"+wp.name, lat:savedfix.lat, lon:savedfix.lon};
      wp = waypoints[wpindex];
-     require("Storage").writeJSON("waypoints.json", waypoints);
+     require("waypoints").save(waypoints);
   }
   selected=!selected;
   drawN();
diff --git a/apps/waypointer/metadata.json b/apps/waypointer/metadata.json
index 707da94cf..0bbc42322 100644
--- a/apps/waypointer/metadata.json
+++ b/apps/waypointer/metadata.json
@@ -1,16 +1,17 @@
 {
   "id": "waypointer",
   "name": "Way Pointer",
-  "version": "0.03",
+  "version": "0.07",
   "description": "Navigate to a waypoint using the GPS for bearing and compass to point way, uses the same waypoint interface as GPS Navigation",
   "icon": "waypointer.png",
   "tags": "tool,outdoors,gps",
   "supports": ["BANGLEJS", "BANGLEJS2"],
+  "dependencies" : { "waypoints":"type" },
   "readme": "README.md",
-  "interface": "waypoints.html",
   "storage": [
     {"name":"waypointer.app.js","url":"app.js"},
+    {"name":"waypointer.settings.js","url":"settings.js"},
     {"name":"waypointer.img","url":"icon.js","evaluate":true}
   ],
-  "data": [{"name":"waypoints.json","url":"waypoints.json"}]
+  "data": [{"name":"waypointer.json"}]
 }
diff --git a/apps/waypointer/settings.js b/apps/waypointer/settings.js
new file mode 100644
index 000000000..c8b06b9f9
--- /dev/null
+++ b/apps/waypointer/settings.js
@@ -0,0 +1,25 @@
+(function(back) {
+  var FILE = "waypointer.json";
+  // Load settings
+  var settings = Object.assign({
+    smoothDirection: true,
+  }, require('Storage').readJSON(FILE, true) || {});
+
+  function writeSettings() {
+    require('Storage').writeJSON(FILE, settings);
+  }
+
+  // Show the menu
+  E.showMenu({
+    "" : { "title" : "Way Pointer" },
+    "< Back" : () => back(),
+    'Smooth arrow rot': {
+      value: !!settings.smoothDirection,
+      format: v => v?"Yes":"No",
+      onchange: v => {
+        settings.smoothDirection = v;
+        writeSettings();
+      }
+    },
+  });
+})
diff --git a/apps/waypointer/waypoints.html b/apps/waypointer/waypoints.html
deleted file mode 100644
index 7a65821a2..000000000
--- a/apps/waypointer/waypoints.html
+++ /dev/null
@@ -1,170 +0,0 @@
-
-  
-    
-    
-  
-  
-
-    

List of waypoints

- - - - - - - - - - - - -
NameLat.Long.Actions
-
-

Add a new waypoint

-
-
-
- -
-
- -
-
- -
-
-
-
- -
-
- -
-
-
-
- - - - - - - diff --git a/apps/waypointer/waypoints.json b/apps/waypointer/waypoints.json deleted file mode 100644 index 98a670c0d..000000000 --- a/apps/waypointer/waypoints.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "name":"NONE" - }, - { - "name":"No10", - "lat":51.5032, - "lon":-0.1269 - }, - { - "name":"Stone", - "lat":51.1788, - "lon":-1.8260 - }, - { "name":"WP0" }, - { "name":"WP1" }, - { "name":"WP2" }, - { "name":"WP3" }, - { "name":"WP4" } -] \ No newline at end of file diff --git a/apps/waypoints/ChangeLog b/apps/waypoints/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/waypoints/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/waypoints/README.md b/apps/waypoints/README.md new file mode 100644 index 000000000..e252054f2 --- /dev/null +++ b/apps/waypoints/README.md @@ -0,0 +1,56 @@ +# Waypoints + +This app provides a common way to set up the `waypoints.json` file, +which several other apps rely on for navigation. + +## Waypoint JSON file + +When the app is loaded from the app loader, a file named +`waypoints.json` is loaded along with the javascript etc. The file +has the following contents: + + +``` +[ + { + "name":"NONE" + }, + { + "name":"No10", + "lat":51.5032, + "lon":-0.1269 + }, + { + "name":"Stone", + "lat":51.1788, + "lon":-1.8260 + }, + { "name":"WP0" }, + { "name":"WP1" }, + { "name":"WP2" }, + { "name":"WP3" }, + { "name":"WP4" } +] +``` + +The file contains the initial NONE waypoint which is useful if you +just want to display course and speed. The next two entries are +waypoints to No 10 Downing Street and to Stone Henge - obtained from +Google Maps. The last five entries are entries which can be *marked*. + +You add and delete entries using the Web IDE to load and then save +the file from and to watch storage. The app itself does not limit the +number of entries although it does load the entire file into RAM +which will obviously limit this. + + +## Waypoint Editor + +Clicking on the download icon of `Waypoints` in the app loader invokes the +waypoint editor. The editor downloads and displays the current +`waypoints.json` file. Clicking the `Edit` button beside an entry +causes the entry to be deleted from the list and displayed in the +edit boxes. It can be restored - by clicking the `Add waypoint` +button. A new markable entry is created by using the `Add name` +button. The edited `waypoints.json` file is uploaded to the Bangle by +clicking the `Upload` button. diff --git a/apps/waypoints/app-icon.js b/apps/waypoints/app-icon.js new file mode 100644 index 000000000..49232b838 --- /dev/null +++ b/apps/waypoints/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwJC/AH4A/AH4AgA==")) diff --git a/apps/waypoints/app.js b/apps/waypoints/app.js new file mode 100644 index 000000000..06c254a36 --- /dev/null +++ b/apps/waypoints/app.js @@ -0,0 +1,34 @@ +// place your const, vars, functions or classes here + +// clear the screen +g.clear(); + +var n = 0; + +// redraw the screen +function draw() { + g.reset().clearRect(Bangle.appRect); + g.setFont("6x8").setFontAlign(0,0).drawString("Up / Down",g.getWidth()/2,g.getHeight()/2 - 20); + g.setFont("Vector",60).setFontAlign(0,0).drawString(n,g.getWidth()/2,g.getHeight()/2 + 30); +} + +// Respond to user input +Bangle.setUI({mode: "updown"}, function(dir) { + if (dir<0) { + n--; + draw(); + } else if (dir>0) { + n++; + draw(); + } else { + n = 0; + draw(); + } +}); + +// First draw... +draw(); + +// Load widgets +Bangle.loadWidgets(); +Bangle.drawWidgets(); diff --git a/apps/waypoints/app.png b/apps/waypoints/app.png new file mode 100644 index 000000000..0b9344405 Binary files /dev/null and b/apps/waypoints/app.png differ diff --git a/apps/wpmoto/wpmoto.html b/apps/waypoints/interface.html similarity index 60% rename from apps/wpmoto/wpmoto.html rename to apps/waypoints/interface.html index 9966f51f6..48e47df57 100644 --- a/apps/wpmoto/wpmoto.html +++ b/apps/waypoints/interface.html @@ -4,6 +4,7 @@ + @@ -11,6 +12,8 @@ html, body { height: 100% } .flex-col { display:flex; flex-direction:column; height:100% } #map { width:100%; height:100% } + #tab-map { width:100%; height:100% } + #tab-list { width:100%; height:100% } /* https://stackoverflow.com/a/58686215 */ .arrow-icon { @@ -23,6 +26,7 @@ transform-origin: center center; font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif; } + @@ -32,8 +36,57 @@
+
+ +
+
+
+
@@ -44,8 +97,23 @@ - + + diff --git a/apps/waypoints/lib.js b/apps/waypoints/lib.js new file mode 100644 index 000000000..88b402a73 --- /dev/null +++ b/apps/waypoints/lib.js @@ -0,0 +1,7 @@ +exports.load = (num) => { + return require("Storage").readJSON(`waypoints${num?"."+num:""}.json`)||[{name:"NONE"}]; +}; + +exports.save = (waypoints,num) => { + require("Storage").writeJSON(`waypoints${num?"."+num:""}.json`, waypoints); +}; diff --git a/apps/waypoints/metadata.json b/apps/waypoints/metadata.json new file mode 100644 index 000000000..d7fa00f7e --- /dev/null +++ b/apps/waypoints/metadata.json @@ -0,0 +1,20 @@ +{ "id": "waypoints", + "name": "Waypoints", + "version":"0.01", + "description": "Provides 'waypoints.json' used by various navigation apps, as well as a way to edit it from the App Loader with maps or a list", + "icon": "app.png", + "tags": "tool,outdoors,gps", + "type": "waypoints", + "supports" : ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "interface": "interface.html", + "storage": [ + {"name":"waypoints","url":"lib.js"} + ], + "data": [ + {"name":"waypoints.json","url":"waypoints.json"}, + {"name":"waypoints.1.json"}, + {"name":"waypoints.2.json"}, + {"name":"waypoints.3.json"} + ] +} diff --git a/apps/waypoints/waypoints.json b/apps/waypoints/waypoints.json new file mode 100644 index 000000000..066f05c10 --- /dev/null +++ b/apps/waypoints/waypoints.json @@ -0,0 +1,12 @@ +[ + { + "name":"No10", + "lat":51.5032, + "lon":-0.1269 + }, + { + "name":"Stone", + "lat":51.1788, + "lon":-1.8260 + } +] diff --git a/apps/wclock/ChangeLog b/apps/wclock/ChangeLog index 9a2ebdd5f..e50ee6842 100644 --- a/apps/wclock/ChangeLog +++ b/apps/wclock/ChangeLog @@ -1,2 +1,3 @@ 0.02: Modified for use with new bootloader and firmware 0.03: setUI and support for different screens +0.04: Tell clock widgets to hide. diff --git a/apps/wclock/clock-word.js b/apps/wclock/clock-word.js index aff134273..7ddb7bc35 100644 --- a/apps/wclock/clock-word.js +++ b/apps/wclock/clock-word.js @@ -122,11 +122,11 @@ Bangle.on('lcdPower', function(on) { if (on) drawWordClock(); }); +// Show launcher when button pressed +Bangle.setUI("clock"); + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); setInterval(drawWordClock, 1E4); drawWordClock(); - -// Show launcher when button pressed -Bangle.setUI("clock"); diff --git a/apps/wclock/metadata.json b/apps/wclock/metadata.json index f22b53dc1..820af7ac0 100644 --- a/apps/wclock/metadata.json +++ b/apps/wclock/metadata.json @@ -1,7 +1,7 @@ { "id": "wclock", "name": "Word Clock", - "version": "0.03", + "version": "0.04", "description": "Display Time as Text", "icon": "clock-word.png", "screenshots": [{"url":"screenshot_word.png"}], diff --git a/apps/weather/ChangeLog b/apps/weather/ChangeLog index 101da48e1..4b70d3531 100644 --- a/apps/weather/ChangeLog +++ b/apps/weather/ChangeLog @@ -12,3 +12,11 @@ 0.13: Tweak Bangle.js 2 light theme colors 0.14: Use weather condition code for icon selection 0.15: Fix widget icon +0.16: Don't mark app as clock +0.17: Added clkinfo for clocks. +0.18: Added hasRange to clkinfo. +0.19: Added weather condition to clkinfo. +0.20: Added weather condition with temperature to clkinfo. +0.21: Updated clkinfo icon. +0.22: Automatic translation of strings, some left untranslated. +0.23: Update clock_info to avoid a redraw diff --git a/apps/weather/app.js b/apps/weather/app.js index efd9b0209..8988c5002 100644 --- a/apps/weather/app.js +++ b/apps/weather/app.js @@ -16,10 +16,10 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [ {type: "txt", font: "12%", valign: -1, id: "tempUnit", label: "°C"}, ]}, {filly: 1}, - {type: "txt", font: "6x8", pad: 2, halign: 1, label: "Humidity"}, + {type: "txt", font: "6x8", pad: 2, halign: 1, label: /*LANG*/"Humidity"}, {type: "txt", font: "9%", pad: 2, halign: 1, id: "hum", label: "000%"}, {filly: 1}, - {type: "txt", font: "6x8", pad: 2, halign: -1, label: "Wind"}, + {type: "txt", font: "6x8", pad: 2, halign: -1, label: /*LANG*/"Wind"}, {type: "h", halign: -1, c: [ {type: "txt", font: "9%", pad: 2, id: "wind", label: "00"}, {type: "txt", font: "6x8", pad: 2, valign: -1, id: "windUnit", label: "km/h"}, @@ -27,22 +27,22 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [ ]}, ]}, {filly: 1}, - {type: "txt", font: "9%", wrap: true, height: g.getHeight()*0.18, fillx: 1, id: "cond", label: "Weather condition"}, + {type: "txt", font: "9%", wrap: true, height: g.getHeight()*0.18, fillx: 1, id: "cond", label: /*LANG*/"Weather condition"}, {filly: 1}, {type: "h", c: [ {type: "txt", font: "6x8", pad: 4, id: "loc", label: "Toronto"}, {fillx: 1}, - {type: "txt", font: "6x8", pad: 4, id: "updateTime", label: "15 minutes ago"}, + {type: "txt", font: "6x8", pad: 4, id: "updateTime", label: /*LANG*/"15 minutes ago"}, ]}, {filly: 1}, ]}, {lazy: true}); function formatDuration(millis) { let pluralize = (n, w) => n + " " + w + (n == 1 ? "" : "s"); - if (millis < 60000) return "< 1 minute"; - if (millis < 3600000) return pluralize(Math.floor(millis/60000), "minute"); - if (millis < 86400000) return pluralize(Math.floor(millis/3600000), "hour"); - return pluralize(Math.floor(millis/86400000), "day"); + if (millis < 60000) return /*LANG*/"< 1 minute"; + if (millis < 3600000) return pluralize(Math.floor(millis/60000), /*LANG*/"minute"); + if (millis < 86400000) return pluralize(Math.floor(millis/3600000), /*LANG*/"hour"); + return pluralize(Math.floor(millis/86400000), /*LANG*/"day"); } function draw() { @@ -57,7 +57,7 @@ function draw() { layout.windUnit.label = wind[2] + " " + (current.wrose||'').toUpperCase(); layout.cond.label = current.txt.charAt(0).toUpperCase()+(current.txt||'').slice(1); layout.loc.label = current.loc; - layout.updateTime.label = `${formatDuration(Date.now() - current.time)} ago`; + layout.updateTime.label = `${formatDuration(Date.now() - current.time)} ago`; // How to autotranslate this and similar? layout.update(); layout.render(); } @@ -77,9 +77,9 @@ function update() { } else { layout.forgetLazyState(); if (NRF.getSecurityStatus().connected) { - E.showMessage("Weather\nunknown\n\nIs Gadgetbridge\nweather\nreporting set\nup on your\nphone?"); + E.showMessage(/*LANG*/"Weather\nunknown\n\nIs Gadgetbridge\nweather\nreporting set\nup on your\nphone?"); } else { - E.showMessage("Weather\nunknown\n\nGadgetbridge\nnot connected"); + E.showMessage(/*LANG*/"Weather\nunknown\n\nGadgetbridge\nnot connected"); NRF.on("connect", update); } } @@ -101,7 +101,11 @@ weather.on("update", update); update(); -// Show launcher when middle button pressed +// We want this app to behave like a clock: +// i.e. show launcher when middle button pressed Bangle.setUI("clock"); +// But the app is not actually a clock +// This matters for widgets that hide themselves for clocks, like widclk or widclose +delete Bangle.CLOCK; Bangle.drawWidgets(); diff --git a/apps/weather/clkinfo.js b/apps/weather/clkinfo.js new file mode 100644 index 000000000..f40924e06 --- /dev/null +++ b/apps/weather/clkinfo.js @@ -0,0 +1,75 @@ +(function() { + var weather = { + temp: "?", + hum: "?", + wind: "?", + txt: "?", + }; + + var weatherJson = require("Storage").readJSON('weather.json'); + if(weatherJson !== undefined && weatherJson.weather !== undefined){ + weather = weatherJson.weather; + weather.temp = require("locale").temp(weather.temp-273.15); + weather.hum = weather.hum + "%"; + weather.wind = require("locale").speed(weather.wind).match(/^(\D*\d*)(.*)$/); + weather.wind = Math.round(weather.wind[1]) + "kph"; + } + + function weatherIcon(code) { + var ovr = Graphics.createArrayBuffer(24,24,1,{msb:true}); + require("weather").drawIcon({code:code},12,12,12,ovr); + var img = ovr.asImage(); + img.transparent = 0; + //for (var i=0;i ({ text: weather.temp, img: weatherIcon(weather.code), + v: parseInt(weather.temp), min: -30, max: 55}), + show: function() {}, + hide: function () {} + }, + { + name: "condition", + get: () => ({ text: weather.txt, img: weatherIcon(weather.code), + v: weather.code}), + show: function() {}, + hide: function () {} + }, + { + name: "temperature", + hasRange : true, + get: () => ({ text: weather.temp, img: atob("GBiBAAA8AAB+AADnAADDAADDAADDAADDAADDAADbAADbAADbAADbAADbAADbAAHbgAGZgAM8wAN+wAN+wAM8wAGZgAHDgAD/AAA8AA=="), + v: parseInt(weather.temp), min: -30, max: 55}), + show: function() {}, + hide: function () {} + }, + { + name: "humidity", + hasRange : true, + get: () => ({ text: weather.hum, img: atob("GBiBAAAEAAAMAAAOAAAfAAAfAAA/gAA/gAI/gAY/AAcfAA+AQA+A4B/A4D/B8D/h+D/j+H/n/D/n/D/n/B/H/A+H/AAH/AAD+AAA8A=="), + v: parseInt(weather.hum), min: 0, max: 100}), + show: function() {}, + hide: function () {} + }, + { + name: "wind", + hasRange : true, + get: () => ({ text: weather.wind, img: atob("GBiBAAHgAAPwAAYYAAwYAAwMfAAY/gAZh3/xg//hgwAAAwAABg///g//+AAAAAAAAP//wH//4AAAMAAAMAAYMAAYMAAMcAAP4AADwA=="), + v: parseInt(weather.wind), min: 0, max: 118}), + show: function() {}, + hide: function () {} + }, + ] + }; + + return weatherItems; +}) diff --git a/apps/weather/lib.js b/apps/weather/lib.js index 1d48116e1..8c59fd3e3 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -62,12 +62,29 @@ scheduleExpiry(storage.readJSON('weather.json')||{}); * @param x Left * @param y Top * @param r Icon Size + * @param ovr Graphics instance (or undefined for g) */ -exports.drawIcon = function(cond, x, y, r) { +exports.drawIcon = function(cond, x, y, r, ovr) { var palette; - + var monochrome=1; + if(!ovr) { + ovr = g; + monochrome=0; + } + if(monochrome) { + palette = { + sun: '#FFF', + cloud: '#FFF', + bgCloud: '#FFF', + rain: '#FFF', + lightning: '#FFF', + snow: '#FFF', + mist: '#FFF', + background: '#000' + }; + } else if (B2) { - if (g.theme.dark) { + if (ovr.theme.dark) { palette = { sun: '#FF0', cloud: '#FFF', @@ -89,7 +106,7 @@ exports.drawIcon = function(cond, x, y, r) { }; } } else { - if (g.theme.dark) { + if (ovr.theme.dark) { palette = { sun: '#FE0', cloud: '#BBB', @@ -113,19 +130,19 @@ exports.drawIcon = function(cond, x, y, r) { } function drawSun(x, y, r) { - g.setColor(palette.sun); - g.fillCircle(x, y, r); + ovr.setColor(palette.sun); + ovr.fillCircle(x, y, r); } function drawCloud(x, y, r, c) { const u = r/12; if (c==null) c = palette.cloud; - g.setColor(c); - g.fillCircle(x-8*u, y+3*u, 4*u); - g.fillCircle(x-4*u, y-2*u, 5*u); - g.fillCircle(x+4*u, y+0*u, 4*u); - g.fillCircle(x+9*u, y+4*u, 3*u); - g.fillPoly([ + ovr.setColor(c); + ovr.fillCircle(x-8*u, y+3*u, 4*u); + ovr.fillCircle(x-4*u, y-2*u, 5*u); + ovr.fillCircle(x+4*u, y+0*u, 4*u); + ovr.fillCircle(x+9*u, y+4*u, 3*u); + ovr.fillPoly([ x-8*u, y+7*u, x-8*u, y+3*u, x-4*u, y-2*u, @@ -137,19 +154,23 @@ exports.drawIcon = function(cond, x, y, r) { function drawBrokenClouds(x, y, r) { drawCloud(x+1/8*r, y-1/8*r, 7/8*r, palette.bgCloud); + if(monochrome) + drawCloud(x-1/8*r, y+2/16*r, r, palette.background); drawCloud(x-1/8*r, y+1/8*r, 7/8*r); } function drawFewClouds(x, y, r) { drawSun(x+3/8*r, y-1/8*r, 5/8*r); + if(monochrome) + drawCloud(x-1/8*r, y+2/16*r, r, palette.background); drawCloud(x-1/8*r, y+1/8*r, 7/8*r); } function drawRainLines(x, y, r) { - g.setColor(palette.rain); + ovr.setColor(palette.rain); const y1 = y+1/2*r; const y2 = y+1*r; - const poly = g.fillPolyAA ? p => g.fillPolyAA(p) : p => g.fillPoly(p); + const poly = ovr.fillPolyAA ? p => ovr.fillPolyAA(p) : p => ovr.fillPoly(p); poly([ x-6/12*r, y1, x-8/12*r, y2, @@ -182,8 +203,8 @@ exports.drawIcon = function(cond, x, y, r) { function drawThunderstorm(x, y, r) { function drawLightning(x, y, r) { - g.setColor(palette.lightning); - g.fillPoly([ + ovr.setColor(palette.lightning); + ovr.fillPoly([ x-2/6*r, y-r, x-4/6*r, y+1/6*r, x-1/6*r, y+1/6*r, @@ -194,8 +215,9 @@ exports.drawIcon = function(cond, x, y, r) { ]); } - drawBrokenClouds(x, y-1/3*r, r); + if(monochrome) drawBrokenClouds(x, y-1/3*r, r); drawLightning(x-1/12*r, y+1/2*r, 1/2*r); + drawBrokenClouds(x, y-1/3*r, r); } function drawSnow(x, y, r) { @@ -210,7 +232,7 @@ exports.drawIcon = function(cond, x, y, r) { } } - g.setColor(palette.snow); + ovr.setColor(palette.snow); const w = 1/12*r; for(let i = 0; i<=6; ++i) { const points = [ @@ -220,7 +242,7 @@ exports.drawIcon = function(cond, x, y, r) { x+w, y+r, ]; rotatePoints(points, x, y, i/3*Math.PI); - g.fillPoly(points); + ovr.fillPoly(points); for(let j = -1; j<=1; j += 2) { const points = [ @@ -231,7 +253,7 @@ exports.drawIcon = function(cond, x, y, r) { ]; rotatePoints(points, x, y+7/12*r, j/3*Math.PI); rotatePoints(points, x, y, i/3*Math.PI); - g.fillPoly(points); + ovr.fillPoly(points); } } } @@ -245,18 +267,18 @@ exports.drawIcon = function(cond, x, y, r) { [-0.2, 0.3], ]; - g.setColor(palette.mist); + ovr.setColor(palette.mist); for(let i = 0; i<5; ++i) { - g.fillRect(x+layers[i][0]*r, y+(0.4*i-0.9)*r, x+layers[i][1]*r, + ovr.fillRect(x+layers[i][0]*r, y+(0.4*i-0.9)*r, x+layers[i][1]*r, y+(0.4*i-0.7)*r-1); - g.fillCircle(x+layers[i][0]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5); - g.fillCircle(x+layers[i][1]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5); + ovr.fillCircle(x+layers[i][0]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5); + ovr.fillCircle(x+layers[i][1]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5); } } function drawUnknown(x, y, r) { drawCloud(x, y, r, palette.bgCloud); - g.setColor(g.theme.fg).setFontAlign(0, 0).setFont('Vector', r*2).drawString("?", x+r/10, y+r/6); + ovr.setColor(ovr.theme.fg).setFontAlign(0, 0).setFont('Vector', r*2).drawString("?", x+r/10, y+r/6); } /* diff --git a/apps/weather/metadata.json b/apps/weather/metadata.json index 1d0b6b469..77ca37721 100644 --- a/apps/weather/metadata.json +++ b/apps/weather/metadata.json @@ -1,11 +1,11 @@ { "id": "weather", "name": "Weather", - "version": "0.15", + "version": "0.23", "description": "Show Gadgetbridge weather report", "icon": "icon.png", "screenshots": [{"url":"screenshot.png"}], - "tags": "widget,outdoors", + "tags": "widget,outdoors,clkinfo", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "readme.md", "storage": [ @@ -13,7 +13,8 @@ {"name":"weather.wid.js","url":"widget.js"}, {"name":"weather","url":"lib.js"}, {"name":"weather.img","url":"icon.js","evaluate":true}, - {"name":"weather.settings.js","url":"settings.js"} + {"name":"weather.settings.js","url":"settings.js"}, + {"name":"weather.clkinfo.js","url":"clkinfo.js"} ], "data": [{"name":"weather.json"}] } diff --git a/apps/weather/readme.md b/apps/weather/readme.md index b37d0b38e..2187ef061 100644 --- a/apps/weather/readme.md +++ b/apps/weather/readme.md @@ -14,6 +14,34 @@ You can view the full report through the app: If using the `Bangle.js Gadgetbridge` app on your phone (as opposed to the standard F-Droid `Gadgetbridge`) you need to set the package name to `com.espruino.gadgetbridge.banglejs` in the settings of the weather app (`settings -> gadgetbridge support -> package name`). +## Android Weather Apps + +There are two weather apps for Android that can connect with Gadgetbridge + * Tiny Weather Forecast Germany + ** F-Droid - https://f-droid.org/en/packages/de.kaffeemitkoffein.tinyweatherforecastgermany/ + ** Source code - https://codeberg.org/Starfish/TinyWeatherForecastGermany + * QuickWeather + ** F-Droid - https://f-droid.org/en/packages/com.ominous.quickweather/ + ** Google Play - https://play.google.com/store/apps/details?id=com.ominous.quickweather + ** Source code - https://github.com/TylerWilliamson/QuickWeather + + ### Tiny Weather Forecast Germany + Even though Tiny Weather Forecast Germany is made for Germany, it can be used around the world. To do this: + +1. Tap on the three dots in the top right hand corner and go to settings +2. Go down to Location and tap on the checkbox labeled "Use location services". You may also want to check on the "Check Location checkbox". Alternatively, you may select the "manual" checkbox and choose your location. +3. Scroll down further to the "other" section and tap "Gadgetbridge support". Then tap on "Enable". You may also choose to tap on "Send current time". +4. If you're using the specific Gadgetbridge for Bangle.JS app, you'll want to tap on "Package name." In the dialog box that appears, you'll want to put in "com.espruino.gadgetbridge.banglejs" without the quotes. If you're using the original Gadgetbridge, leave this as the default. + + +### QuickWeather +QuickWeather requires an OpenWeatherMap API. You will need the "One Call By Call" plan, which is free if you're not making too many calls. Sign up or get more information at https://openweathermap.org/api + +1. When you first load QuickWeather, it will take you through the setup process. You will fill out all the required information as well as put your API key in. If you do not have the "One Call By Call", or commonly known as "One Call", API, you will need to sign up for that. QuickWeather will work automatically with both the main version of Gadgetbridge and Gadgetbridge for bangle.JS. + +### Weather Notification +* Note - at one time, the Weather Notification app also worked with Gadgetbridge. However, many users are reporting it's no longer seeing the OpenWeatherMap API key as valid. The app has not received any updates since August of 2020, and may be unmaintained. + ## Settings * Expiration timespan can be set after which the local weather data is considered as invalid diff --git a/apps/wid_edit/ChangeLog b/apps/wid_edit/ChangeLog index 2fa857bd8..d8e165029 100644 --- a/apps/wid_edit/ChangeLog +++ b/apps/wid_edit/ChangeLog @@ -1 +1,4 @@ -0.01: new Widget Editor! \ No newline at end of file +0.01: new Widget Editor! +0.02: Wrap loadWidgets instead of replacing to keep original functionality intact + Change back entry to menu option + Allow changing widgets into all areas, including bottom widget bar diff --git a/apps/wid_edit/boot.js b/apps/wid_edit/boot.js index 872965c97..3cb545a34 100644 --- a/apps/wid_edit/boot.js +++ b/apps/wid_edit/boot.js @@ -1,24 +1,20 @@ -Bangle.loadWidgets = function() { - global.WIDGETS={}; - require("Storage").list(/\.wid\.js$/) - .forEach(w=>{ - try { eval(require("Storage").read(w)); } - catch (e) { print(w, e); } - }); - const s = require("Storage").readJSON("wid_edit.json", 1) || {}, - c = s.custom || {}; +Bangle.loadWidgets = (o => ()=>{ + o(); + const s = require("Storage").readJSON("wid_edit.json", 1) || {}; + const c = s.custom || {}; for (const w in c){ if (!(w in WIDGETS)) continue; // widget no longer exists // store defaults of customized values in _WIDGETS - global._WIDGETS=global._WIDGETS||{}; - _WIDGETS[w] = {}; - Object.keys(c[w]).forEach(k => _WIDGETS[w][k] = WIDGETS[w][k]); - Object.assign(WIDGETS[w], c[w]); + if (!global._WIDGETS) global._WIDGETS = {}; + if (!global._WIDGETS[w]) global._WIDGETS[w] = {}; + Object.keys(c[w]).forEach(k => global._WIDGETS[w][k] = global.WIDGETS[w][k]); + //overide values in widget with configured ones + Object.assign(global.WIDGETS[w], c[w]); } - const W = WIDGETS; - WIDGETS = {}; + const W = global.WIDGETS; + global.WIDGETS = {}; Object.keys(W) .sort() .sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder)) - .forEach(k => WIDGETS[k] = W[k]); -} \ No newline at end of file + .forEach(k => global.WIDGETS[k] = W[k]); +})(Bangle.loadWidgets); diff --git a/apps/wid_edit/metadata.json b/apps/wid_edit/metadata.json index 66d0192f6..d963a53d0 100644 --- a/apps/wid_edit/metadata.json +++ b/apps/wid_edit/metadata.json @@ -1,6 +1,6 @@ { "id": "wid_edit", - "version": "0.01", + "version": "0.02", "name": "Widget Editor", "icon": "icon.png", "description": "Customize widget locations", diff --git a/apps/wid_edit/settings.js b/apps/wid_edit/settings.js index 0969ed533..1d34ae0ca 100644 --- a/apps/wid_edit/settings.js +++ b/apps/wid_edit/settings.js @@ -9,7 +9,7 @@ let cleanup = false; for (const id in settings.custom) { - if (!(id in WIDGETS)) { + if (!(id in global.WIDGETS)) { // widget which no longer exists cleanup = true; delete settings.custom[id]; @@ -24,12 +24,12 @@ * Sort & redraw all widgets */ function redrawWidgets() { - let W = WIDGETS; + let W = global.WIDGETS; global.WIDGETS = {}; Object.keys(W) .sort() .sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder)) - .forEach(k => {WIDGETS[k] = W[k]}); + .forEach(k => {global.WIDGETS[k] = W[k];}); Bangle.drawWidgets(); } @@ -52,9 +52,9 @@ } function edit(id) { - let WIDGET = WIDGETS[id], + let WIDGET = global.WIDGETS[id], def = {area: WIDGET.area, sortorder: WIDGET.sortorder|0}; // default values - Object.assign(def, _WIDGETS[id]||{}); // defaults were saved in _WIDGETS + Object.assign(def, global._WIDGETS[id]||{}); // defaults were saved in _WIDGETS settings.custom = settings.custom||{}; let saved = settings.custom[id] || {}, @@ -102,7 +102,7 @@ settings.custom = settings.custom || {}; settings.custom[id] = saved; } else if (settings.custom) { - delete settings.custom[id] + delete settings.custom[id]; } if (!Object.keys(settings.custom).length) delete settings.custom; require("Storage").writeJSON("wid_edit.json", settings); @@ -112,8 +112,8 @@ let _W = {}; if (saved.area) _W.area = def.area; if ('sortorder' in saved) _W.sortorder = def.sortorder; - if (Object.keys(_W).length) _WIDGETS[id] = _W; - else delete _WIDGETS[id]; + if (Object.keys(_W).length) global._WIDGETS[id] = _W; + else delete global._WIDGETS[id]; // drawWidgets won't clear e.g. bottom bar if we just disabled the last bottom widget redrawWidgets(); @@ -122,17 +122,23 @@ m.draw(); } + const AREA_NAMES = [ "Top left", "Top right", "Bottom left", "Bottom right" ]; + const AREAS = [ "tl", "tr", "bl", "br" ]; + const menu = { - "": {"title": name(id)}, - /*LANG*/"< Back": () => { - redrawWidgets(); - mainMenu(); - }, - /*LANG*/"Side": { - value: (area === 'tl'), - format: tl => tl ? /*LANG*/"Left" : /*LANG*/"Right", - onchange: tl => { - area = tl ? "tl" : "tr"; + "": {"title": name(id), + back: () => { + redrawWidgets(); + mainMenu(); + } }, + /*LANG*/"Position": { + value: AREAS.indexOf(area), + format: v => AREA_NAMES[v], + min: 0, + max: AREAS.length - 1, + onchange: v => { + print("v", v); + area = AREAS[v]; save(); } }, @@ -149,7 +155,7 @@ save(); mainMenu(); // changing multiple values made the rest of the menu wrong, so take the easy out } - } + }; let m = E.showMenu(menu); } @@ -157,31 +163,32 @@ function mainMenu() { let menu = { - "": {"title": /*LANG*/"Widgets"}, + "": { + "title": /*LANG*/"Widgets", + back: ()=>{ + if (!Object.keys(global._WIDGETS).length) delete global._WIDGETS; // no defaults to remember + back(); + }}, }; - menu[/*LANG*/"< Back"] = ()=>{ - if (!Object.keys(_WIDGETS).length) delete _WIDGETS; // no defaults to remember - back(); - }; - Object.keys(WIDGETS).forEach(id=>{ + Object.keys(global.WIDGETS).forEach(id=>{ // mark customized widgets with asterisk - menu[name(id)+((id in _WIDGETS) ? " *" : "")] = () => edit(id); + menu[name(id)+((id in global._WIDGETS) ? " *" : "")] = () => edit(id); }); - if (Object.keys(_WIDGETS).length) { // only show reset if there is anything to reset + if (Object.keys(global._WIDGETS).length) { // only show reset if there is anything to reset menu[/*LANG*/"Reset All"] = () => { E.showPrompt(/*LANG*/"Reset all widgets?").then(confirm => { if (confirm) { delete settings.custom; require("Storage").writeJSON("wid_edit.json", settings); - for(let id in _WIDGETS) { - Object.assign(WIDGETS[id], _WIDGETS[id]) // restore defaults + for(let id in global._WIDGETS) { + Object.assign(global.WIDGETS[id], global._WIDGETS[id]); // restore defaults } global._WIDGETS = {}; redrawWidgets(); } mainMenu(); // reload with reset widgets - }) - } + }); + }; } E.showMenu(menu); diff --git a/apps/widagps/ChangeLog b/apps/widagps/ChangeLog new file mode 100644 index 000000000..6728683c8 --- /dev/null +++ b/apps/widagps/ChangeLog @@ -0,0 +1 @@ +0.01: first version diff --git a/apps/widagps/README.md b/apps/widagps/README.md new file mode 100644 index 000000000..e5e9a8f8a --- /dev/null +++ b/apps/widagps/README.md @@ -0,0 +1,12 @@ +# A-GPS Data + +Load assisted GPS data directly to the watch using the new http requests on Android GadgetBridge. + +Make sure: +* your GadgetBridge version supports http requests +* turn on internet access in GadgetBridge settings + +The widget loads the data in the background every 12 hours. It retries every 10min if the http request fails. It is only visible during a request or on error. + +## Creator +[@pidajo](https://github.com/pidajo) diff --git a/apps/widagps/metadata.json b/apps/widagps/metadata.json new file mode 100644 index 000000000..ee1eb9f08 --- /dev/null +++ b/apps/widagps/metadata.json @@ -0,0 +1,14 @@ +{ "id": "widagps", + "name": "AGPS Widget (automatic download)", + "shortName":"AGPS Widget", + "icon": "widget.png", + "type": "widget", + "version":"0.01", + "description": "Once installed, this widget allows your Bangle.js 2 to load AGPS data in the background **via Gadgetbridge on an Android phone** so it is always up to date. If you just want to upload the latest AGPS data from this app loader, please use the `Assisted GPS Update (AGPS)` app.", + "readme": "README.md", + "tags": "widget,agps,http", + "supports": ["BANGLEJS2"], + "storage": [ + {"name":"widagps.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widagps/widget.js b/apps/widagps/widget.js new file mode 100644 index 000000000..57ed801e1 --- /dev/null +++ b/apps/widagps/widget.js @@ -0,0 +1,165 @@ +if (!global.WIDGETS) { + WIDGETS = {}; + Bangle.loadWidgets(); + var isTest = true; +} + +(function(){ + var warnTime = 24*60*60000; //warn missing data + var nextTime = 12*60*60000; //time between requests + var retryTime = 10*60000; //time between retries + + const JSON_FILE = "agpsdata.json"; + var isRequesting = false; + var lastAGPS = 0; + var nextGet = null; + + const WIDGET_ID = "widagps"; + WIDGETS[WIDGET_ID]={ + area:"tl", + width:24, + draw:function() { + var w = 0; + var x = this.x, y = this.y; + g.reset(); + if (isRequesting) { + g.setColor("#00f"); + w = 24; + } + else { + if (Date.now() - lastAGPS > warnTime) { + g.setColor("#f00"); + w = 24; + } + } + if (w) { +g.drawImage(atob("FBQBAAAABgAAYAAPAACwABOAATgAI8ACPABD4AQ+AEPgD8EAg/AQP4AD+CD/wjD8WAHmAAY="), x + 1, y + 1); + } + if (WIDGETS[WIDGET_ID].width != w) { + WIDGETS[WIDGET_ID].width = w; + Bangle.drawWidgets(); + } + } + }; + + var _GB = global.GB; + + global.GB = function(msg) { + //console.log(msg); + if (msg.t == "http") { + applyAGPS(msg.resp); + } + if (_GB) { + _GB(msg); + } + } + + function nextAGPS(when) { + if (nextGet) { + clearTimeout(nextGet); + nextGet = null; + } + console.log("Next AGPS request:", new Date(Date.now() + when)); + nextGet = setTimeout(() => { + getAGPS(); + }, when); + } + + function applyAGPS(data) { + isRequesting = false; + var success = false; + if (data) { + success = setAGPS(data); + } + if (success) { + lastAGPS = Date.now(); + nextAGPS(nextTime); + require("Storage").writeJSON(JSON_FILE, {lastAGPS: lastAGPS}); + } + else { + console.log("Failed to apply AGPS data"); + nextAGPS(retryTime); + } + Bangle.drawWidgets(); + } + + function setAGPS(data) { + var js = jsFromBase64(data); + Bangle.setGPSPower(true, "agpsdata"); + try { + eval(js); + Bangle.setGPSPower(false, "agpsdata"); + return true; + } + catch(e) { + console.log("Error:", e); + } + Bangle.setGPSPower(false, "agpsdata"); + return false; + } + + function jsFromBase64(b64) { + var bin = atob(b64); + var chunkSize = 128; + var js = "";//"Bangle.setGPSPower(1);\n"; // turn GPS on + var gnss_select="1"; + js += `Serial1.println("${CASIC_CHECKSUM("$PCAS04,"+gnss_select)}")\n`; // set GNSS mode + // What about: + // NAV-TIMEUTC (0x01 0x10) + // NAV-PV (0x01 0x03) + // or AGPS.zip uses AID-INI (0x0B 0x01) + + for (var i=0;i { + GB({t:"http", resp:testData}); + }, 5000); + } + //check for request timeout + setTimeout(() => { + if (isRequesting) { + applyAGPS(); + } + }, 10000); + Bangle.drawWidgets(); + } + + var data = require("Storage").readJSON(JSON_FILE); + if (data && data.lastAGPS) { + //lastAGPS = data.lastAGPS; + } + + nextAGPS(Math.max(0, nextTime - (Date.now() - lastAGPS))); + NRF.on('connect', () => { + if (Date.now() - lastAGPS > warnTime) { + nextAGPS(0); + } + }); + + var testData = "QUdOU1MgZGF0YSBmcm9tIENBU0lDLgpEYXRhTGVuZ3RoOiAyNTk4LgpMaW1pdGF0aW9uOiAzLzEwMDAuCrrOSAAIB7YdxSr+Sg2h8NYlBux1jiUgQbrXgJk/KJvFZVv8pP//uy3i/PH6rv9EMQH6SwBfAOxepgDsXgAAlCULALv/AAtCAAAAAQMAALQ7kly6zkgACAdBzVam9HANoXGycgoqGmnG5X9h3mKrWicvBKhXAp7//+00U/9j/jP/SDHM/Vn/JADrXqYA614AAF6d6v8DAADaEAAAAAIDAADKmrVTus5IAAgHTUirJrjvDKHJDjACcmXJJ+8Lv6rw5LQnl4OChUCt//9XKG3/+u6ZE84ZQuwDAMf/7F6mAOxeAADa0Pb/mP8ABDUAAAADAwAA4pBeVLrOSAAIB5291DTIzAyhJGfzAJ7pCIcIUQMgcfEoJ2TIjrHkqv//YjDTCKj/wRPdGIz/8/9NAOxepgDsXgAAl9/6/yQAAPbhAAAABAMAAIJ7sXC6zkgACAeKKDOgmwEOocKrFwP8Jmgqq4lOQ1VtLSfEi8yDVqn//5MskP6E7WQRPxzv6vv/0//sXqYA7F4AAM4w/f/0/wDoJwAAAAUDAABcUW5Hus5IAAgHu+Va48nxDaFaw0UBkVc73Y3FB+HFmDgoUWIPW+Ck//+iLcf9X/t5/ikzgPrT/wgA7F6mAOxeAAADVgsAiQAACB0AAAAGAwAAvsu9zbrOSAAIB0OVp/7+JQ2hFANPCF+F6KOOMwe9/nC5JsX0CtthqP//WzhzADr/dgqbIRj/nwDj/+xepgDsXgAAP4oKAPv/AOg4AAAABwMAAM4qVwS6zkgACAey9J9b+zwOofLIzwObDg0HLdEmMOA3PydWaUQvr6b//0wxwf/7EJ8K/yLREhkANADsXqYA7F4AALug/f/y/wALLAAAAAgDAACs6Ue+us5IAAgHm7NJLLhaDKEumRQBAFtVTExfuke3AeEmNg9cr2Cq//92MTIJm/63FCkXPv4gABgA616mAOteAACQQfX/HgAAAzUAAAAJAwAAfmebX7rOSAAIB9fgVnnchw2hNlTrAyWnJ5rnBMWFV9GyJzPfZYV8rf//Oyh2AA3xmhLdGtXu/f/Z/+xepgDsXgAA8gXx/37/AAU/AAAACgMAAPbBtfm6zkgACAc+F7Ct97wMoVEVPQCJJG1yeakXMm80PSet+BBd+aH//5AzPf2J+uX97jG7+fj/DgDsXqYA7F4AAGqE//8WAADufQIAAAsDAADELmhius5IAAgHW3g6rwRJDqFpPmYEPf8lNRy9lKO/IX8nJPRjCLOt//90Lir7QQcEGFYUTAguAA4A7F6mAOxeAADrZfj/zP8A5SsAAAAMAwAA/vB8ZbrOSAAIB1mVSsfiXw2hUX8RA60JSyUgLkEgC910JykTq7Usqv//8S9rBw//HhIpGyT/+v8fAOxepgDsXgAAitgKAD4AAOcpAAAADQMAAPoqnZW6zkgACAcCLzz8Q1ANocBvBQFuUWqAxVSgoRjR0SaS5AkH3qr//7cx3vlcB2AYPROjCOr/vf/sXqYA7F4AAA5Y/P/7/wDvGwMAAA4DAABMXoD/us5IAAgH+RiyseCLDKGnOjkHATiXLOud6AnbGuclr2roqg2l///FNxcHi/0hFLoW4fyj/10A7F6mAOxeAAANRf7/GgAA6TQAAAAPAwAAOjJsarrOSAAIB1/+xFM3Xg2hVDKBBg6Tsx25u5hYROV9J/QyJQmLrf//zC1e+7QGxRfmFOAHhf+s/+xepgDsXgAAaE/v/+j/AOonAAAAEAMAAAb9ka66zkgACAc74z4AUZEMofLN6wbbUEjD/w54MWPC3SfOFa4yQ6f//4wtrwH5EOwKOCRTFLz/UP/sXqYA7F4AAOaAFAApAADoOQAAABEDAAC+xoUHus5IAAgH1yXSbYfZDaFOrzwBIM5keona3uYD8JYnC6ekWw+l//8JMC/9ivsaAGEwM/ssAN//7F6mAOxeAAAymwQAof8A7l8AAAASAwAA9kus4rrOSAAIB/9znedCsA2h5VDBBLdHG1Uw8P6P93bRJw5UgTR9qf//LS1BAj0TAwkqJioWBABHAOxepgDsXgAAD54FACwAAN6xAAAAEwMAAEboQta6zkgACAdVJvSzetsMoRclcgKU4/OAvUl5A73wdCYbpBB/P6X//08yQ/4N7voNgx5160gAFwDsXqYA7F4AADa+EADk/wDuLwAAABQDAADyTPBuus5IAAgHhpZXHJnuDaGfsmkMbSLS2QeTnDZBLR8ntwGPV8mj//+SM6n8rftj/EUyZfw7AaX/7F6mAOxeAAAvSQUAAAAA6j4AAAAVAwAAVC23P7rOSAAIB8FSSGuHmw2hXoTeBoU+tLS9TdsrYGopJ+h3h7O9p///mjEIB3X/GhN5GXP/c//V/+xepgDsXgAASREJADgAAO4rAAAAFgMAAMqlmN26zkgACAeGsPJwF8ENoU2cJwHhxiN62PG7uVyKfydPWVyEG6z//8spSgCQ8NkRnxsl7sr/EQDsXqYA7F4AAI0S///u/wDudQEAABcDAABUYe3ous5IAAgHtHJyvWVdDaFr1mwGwPVWIZcaxOQXwAwmeHqW1+Sh//+PPnAAQgAOCxwhof8sAGwA7F6mAOxeAAAhMQcAtf8ABjsAAAAYAwAAsOXsgbrOSAAIB4nxObhoSQ2hOjBcBf2n5ijflOaX/Iz8JpPiNAUTrP//ajEL++oEchfzE9AFSgDT/+tepgDrXgAAohMLACkAAAweAAAAGQMAAFrje3e6zkgACAexAdJ/MyYOoeXvjwPazb0PcXcXfIVaNCZ2mjMDkqn//z02W/qPBMcW7BM7BcX/6//sXqYA7F4AABv4BgAVAAAPIgAAABoDAACqA6wGus5IAAgHxYz/b8dNDaH6/WQF3AILHLKDgTJ+VponRocZMKSm//8bLycAMRANDG8i/RHR/2wA7F6mAOxeAAArEwcAHAAABEgAAQAbAwAA0hkH57rOSAAIB5HXkJcOjA2h8B4kAebzvl2gmkU1K1TzJ86wODP6qP//0CzCAM4OmQrkI1UR7f/n/+xepgDsXgAAcs/u/9//AOplAAAAHQMAAGqvKTa6zkgACAekogIGh+8NoYBTBQMDtQeTiKQ4u0KYHiYkF4HbzaT//7A80v9N/gQLmSC4/icA6v/sXqYA7F4AAB2V7v/2/wAIGQAAAB4DAACQRQ0Tus5IAAgHUsOCUJ71DaHkPFgFdJcpEDguP6ldR+UmgbrM2+6m//9vOPT/S/7vC1sh6/49AJH/7F6mAOxeAAAQCfr/8/8A4wwAAAAfAwAA7IYNqLrOSAAIByZDZIfa4AyhxlEVA9QtFKN+R+1NPIIIJ8xm1q8Qqv//djDzB9H+pBNQGGj+rv++/+xepgDsXgAA3f/6/67/AAFUAAAAIAMAAJSG0BW6zhQACAWVGZOmAAAAAPr///8SEpCmiQcDAD4zLlK6zhAACAZIDf33DwP+/jYK//gDAAAAoBoC9g=="; + +})() +if (global.isTest) { + Bangle.drawWidgets(); +} + diff --git a/apps/widagps/widget.png b/apps/widagps/widget.png new file mode 100644 index 000000000..ee16c114a Binary files /dev/null and b/apps/widagps/widget.png differ diff --git a/apps/widalarm/ChangeLog b/apps/widalarm/ChangeLog new file mode 100644 index 000000000..63568a9bd --- /dev/null +++ b/apps/widalarm/ChangeLog @@ -0,0 +1 @@ +0.01: Moved out of 'alarm' app diff --git a/apps/widalarm/app.png b/apps/widalarm/app.png new file mode 100644 index 000000000..a859dd2ef Binary files /dev/null and b/apps/widalarm/app.png differ diff --git a/apps/widalarm/metadata.json b/apps/widalarm/metadata.json new file mode 100644 index 000000000..b91457138 --- /dev/null +++ b/apps/widalarm/metadata.json @@ -0,0 +1,15 @@ +{ + "id": "widalarm", + "name": "Alarms Widget", + "version": "0.01", + "description": "Displays an alarm icon in the widgets bar if any alarm is active", + "icon": "app.png", + "type": "widget", + "tags": "tool,alarm,widget", + "supports": [ "BANGLEJS", "BANGLEJS2" ], + "provides_widgets" : ["alarm"], + "default" : true, + "storage": [ + { "name": "widalarm.wid.js", "url": "widget.js" } + ] +} diff --git a/apps/alarm/widget.js b/apps/widalarm/widget.js similarity index 100% rename from apps/alarm/widget.js rename to apps/widalarm/widget.js diff --git a/apps/widalarmeta/metadata.json b/apps/widalarmeta/metadata.json index b6d8bd62b..ef9f55ba8 100644 --- a/apps/widalarmeta/metadata.json +++ b/apps/widalarmeta/metadata.json @@ -8,6 +8,7 @@ "type": "widget", "tags": "widget", "supports": ["BANGLEJS","BANGLEJS2"], + "provides_widgets" : ["alarm"], "screenshots" : [ { "url":"screenshot.png" } ], "storage": [ {"name":"widalarmeta.wid.js","url":"widget.js"} diff --git a/apps/widalt/ChangeLog b/apps/widalt/ChangeLog new file mode 100644 index 000000000..ec66c5568 --- /dev/null +++ b/apps/widalt/ChangeLog @@ -0,0 +1 @@ +0.01: Initial version diff --git a/apps/widalt/README.md b/apps/widalt/README.md new file mode 100644 index 000000000..08ee4f83d --- /dev/null +++ b/apps/widalt/README.md @@ -0,0 +1,2 @@ +# Altimeter widget +Displays barometric altitude in the top right corner. diff --git a/apps/widalt/metadata.json b/apps/widalt/metadata.json new file mode 100644 index 000000000..309c5bf2c --- /dev/null +++ b/apps/widalt/metadata.json @@ -0,0 +1,18 @@ + +{ + "id": "widalt", + "name": "Altimeter widget", + "version": "0.01", + "description": "Displays barometric altitude", + "readme": "README.md", + "icon": "widalt.png", + "type": "widget", + "tags": "widget", + "supports": ["BANGLEJS2"], + "allow_emulator":false, + "storage": [ + {"name":"widalt.wid.js","url":"widalt.wid.js"}, + {"name":"widalt.settings.js","url":"widalt.settings.js"} + ], + "data": [{"name":"widalt.json"}] + } diff --git a/apps/widalt/widalt.png b/apps/widalt/widalt.png new file mode 100644 index 000000000..43e5465bc Binary files /dev/null and b/apps/widalt/widalt.png differ diff --git a/apps/widalt/widalt.settings.js b/apps/widalt/widalt.settings.js new file mode 100644 index 000000000..57993474e --- /dev/null +++ b/apps/widalt/widalt.settings.js @@ -0,0 +1,27 @@ +(function(back) { + var settings = Object.assign({ + interval: 5000, + }, require('Storage').readJSON("widalt.json", true) || {}); + o=Bangle.getOptions(); + Bangle.getPressure().then((p)=>{ + E.showMenu({ + "" : { "title" : "Altimeter Widget" }, + "< Back" : () => back(), + 'QNH': { + value: Math.floor(o.seaLevelPressure), + min: 100, max: 10000, + format: v=>(v+"hPa\nAlt: "+(44330 * (1.0 - Math.pow(p.pressure/v, 0.1903))).toFixed(0)+"m"), + onchange: v => {Bangle.setOptions({seaLevelPressure:v});} + }, + 'update Interval': { + value: settings.interval/1000, + min: 1, max: 60, + format: v=>(v+"s"), + onchange: v => { + settings.interval=v*1000; + require('Storage').writeJSON("widalt.json", settings); + } + } + }); + }); +}) diff --git a/apps/widalt/widalt.wid.js b/apps/widalt/widalt.wid.js new file mode 100644 index 000000000..dbd1a763e --- /dev/null +++ b/apps/widalt/widalt.wid.js @@ -0,0 +1,38 @@ +(()=>{ + var alt=""; + var lastAlt=0; + var settings = Object.assign({ + interval: 5000, + }, require('Storage').readJSON("widalt.json", true) || {}); + Bangle.setBarometerPower(true,"widalt"); + Bangle.on("pressure", (p)=>{ + if (Math.floor(p.altitude)!=lastAlt) { + lastAlt=Math.floor(p.altitude); + alt=p.altitude.toFixed(0); + var w = WIDGETS["widalt"].width; + WIDGETS["widalt"].width = 1 + (alt.length)*12+16; + if (w!=WIDGETS["widalt"].width) Bangle.drawWidgets(); + else WIDGETS["widalt"].draw(); + } + Bangle.setBarometerPower(false,"widalt") + setTimeout(()=>{Bangle.setBarometerPower(true,"widalt");},settings.interval); + }); + + function draw() { + if (!Bangle.isLCDOn()) return; + g.reset(); + g.setColor(g.theme.bg); + g.fillRect(this.x, this.y, this.x + this.width, this.y + 23); + g.setColor(g.theme.fg); + g.drawImage(atob("EBCBAAAAAAAIAAwgFXAX0BCYIIggTD/EYPZADkACf/4AAAAA"), this.x, this.y+4); +g.setFontCustom(atob("AAAAABwAAOAAAgAAHAADwAD4AB8AB8AA+AAeAADAAAAOAAP+AH/8B4DwMAGBgAwMAGBgAwOAOA//gD/4AD4AAAAAAAABgAAcAwDAGAwAwP/+B//wAAGAAAwAAGAAAAAAAAIAwHgOA4DwMA+BgOwMDmBg4wOeGA/gwDwGAAAAAAAAAGAHA8A4DwMAGBhAwMMGBjgwOcOA+/gDj4AAAAABgAAcAAHgADsAA5gAOMAHBgBwMAP/+B//wABgAAMAAAAAAAgD4OB/AwOYGBjAwMYGBjBwMe8Bh/AIHwAAAAAAAAAfAAP8AHxwB8GAdgwPMGBxgwMOOAB/gAH4AAAAAAABgAAMAABgAwMAeBgPgMHwBj4AN8AB+AAPAABAAAAAAAMfAH38B/xwMcGBhgwMMGBjgwP+OA+/gDj4AAAAAAAAOAAH4AA/gQMMGBgzwME8BhvAOPgA/4AD8AAEAAAAAAGAwA4OAHBwAAA="), 46, atob("BAgMDAwMDAwMDAwMBQ=="), 21+(1<<8)+(1<<16)); + g.setFontAlign(-1, 0); + g.drawString(alt, this.x+16, this.y + 12); + } + WIDGETS["widalt"] = { + area: "tr", + width: 6, + draw: draw + }; + +})(); diff --git a/apps/widanclk/ChangeLog b/apps/widanclk/ChangeLog new file mode 100644 index 000000000..337288ad2 --- /dev/null +++ b/apps/widanclk/ChangeLog @@ -0,0 +1,2 @@ +0.01: New app +0.02: Clear between redraws diff --git a/apps/widanclk/metadata.json b/apps/widanclk/metadata.json new file mode 100644 index 000000000..cd9347601 --- /dev/null +++ b/apps/widanclk/metadata.json @@ -0,0 +1,13 @@ +{ + "id": "widanclk", + "name": "Analog clock widget", + "version": "0.02", + "description": "A simple analog clock widget that appears when not showing a fullscreen clock", + "icon": "widget.png", + "type": "widget", + "tags": "widget,clock", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"widanclk.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widanclk/widget.js b/apps/widanclk/widget.js new file mode 100644 index 000000000..c58f56459 --- /dev/null +++ b/apps/widanclk/widget.js @@ -0,0 +1,25 @@ +/* Simple analog clock that appears in the widget bar if no other clock +is running. We update once per minute, but don't bother stopping +if the */ +WIDGETS["wdanclk"]={area:"tl",width:Bangle.CLOCK?0:24,draw:function() { + if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not... + this.width = Bangle.CLOCK?0:24; + return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw + } + if (!this.width) return; // if size not right, return + g.reset(); + let d = new Date(); + let x=this.x+12, y=this.y+12, + ah = (d.getHours()+d.getMinutes()/60)*Math.PI/6, + am = d.getMinutes()*Math.PI/30; + g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23). + drawCircle(x, y, 11). + drawLine(x,y, x+Math.sin(ah)*7, y-Math.cos(ah)*7). + drawLine(x,y, x+Math.sin(am)*9, y-Math.cos(am)*9); + // queue draw in one minute + if (this.drawTimeout) clearTimeout(this.drawTimeout); + this.drawTimeout = setTimeout(()=>{ + this.drawTimeout = undefined; + this.draw(); + }, 60000 - (Date.now() % 60000)); +}}; diff --git a/apps/widanclk/widget.png b/apps/widanclk/widget.png new file mode 100644 index 000000000..9e4b37c39 Binary files /dev/null and b/apps/widanclk/widget.png differ diff --git a/apps/widbaroalarm/ChangeLog b/apps/widbaroalarm/ChangeLog index 86a902605..2dfe8336d 100644 --- a/apps/widbaroalarm/ChangeLog +++ b/apps/widbaroalarm/ChangeLog @@ -3,3 +3,7 @@ 0.03: Fix crash 0.04: Use Prompt with dismiss and pause Improve barometer value median calculation +0.05: Fix warning calculation + Show difference of last measurement to pressure average of the the last three hours in the widget + Only use valid pressure values +0.06: Fix exception diff --git a/apps/widbaroalarm/README.md b/apps/widbaroalarm/README.md index 59d91ff66..478b48a71 100644 --- a/apps/widbaroalarm/README.md +++ b/apps/widbaroalarm/README.md @@ -19,7 +19,9 @@ Get a notification when the pressure reaches defined thresholds. * Pause delay: Same as Dismiss delay but longer (useful for meetings and such). From 30 to 240 min ## Widget -The widget shows two rows: pressure value of last measurement and pressure average of the the last three hours. +The widget shows two rows: +1. pressure value of last measurement +2. difference of last measurement to pressure average of the the last three hours ## Creator Marco ([myxor](https://github.com/myxor)) diff --git a/apps/widbaroalarm/metadata.json b/apps/widbaroalarm/metadata.json index 41b8d3e17..ba6c47b37 100644 --- a/apps/widbaroalarm/metadata.json +++ b/apps/widbaroalarm/metadata.json @@ -2,13 +2,14 @@ "id": "widbaroalarm", "name": "Barometer Alarm Widget", "shortName": "Barometer Alarm", - "version": "0.04", + "version": "0.06", "description": "A widget that can alarm on when the pressure reaches defined thresholds.", "icon": "widget.png", "type": "widget", "tags": "tool,barometer", "supports": ["BANGLEJS2"], "readme": "README.md", + "screenshots": [{"url":"screenshot.png"}], "storage": [ {"name":"widbaroalarm.wid.js","url":"widget.js"}, {"name":"widbaroalarm.settings.js","url":"settings.js"}, diff --git a/apps/widbaroalarm/screenshot.png b/apps/widbaroalarm/screenshot.png new file mode 100644 index 000000000..fcb6ad67e Binary files /dev/null and b/apps/widbaroalarm/screenshot.png differ diff --git a/apps/widbaroalarm/widget.js b/apps/widbaroalarm/widget.js index e1516b6f1..d877c4384 100644 --- a/apps/widbaroalarm/widget.js +++ b/apps/widbaroalarm/widget.js @@ -1,141 +1,158 @@ (function() { - let medianPressure; - let threeHourAvrPressure; - let currentPressures = []; - let stop = false; // semaphore +let medianPressure; +let threeHourAvrPressure; +let currentPressures = []; +let stop = false; // semaphore - const LOG_FILE = "widbaroalarm.log.json"; - const SETTINGS_FILE = "widbaroalarm.json"; - const storage = require('Storage'); +const LOG_FILE = "widbaroalarm.log.json"; +const SETTINGS_FILE = "widbaroalarm.json"; +const storage = require('Storage'); - let settings; +let settings; - function loadSettings() { - settings = Object.assign( - storage.readJSON("widbaroalarm.default.json", true) || {}, - storage.readJSON(SETTINGS_FILE, true) || {} - ); - } +function loadSettings() { + settings = + Object.assign(storage.readJSON("widbaroalarm.default.json", true) || {}, + storage.readJSON(SETTINGS_FILE, true) || {}); +} - loadSettings(); +loadSettings(); +function setting(key) { return settings[key]; } - function setting(key) { - return settings[key]; - } +function saveSetting(key, value) { + settings[key] = value; + storage.write(SETTINGS_FILE, settings); +} - function saveSetting(key, value) { - settings[key] = value; - storage.write(SETTINGS_FILE, settings); - } +const interval = setting("interval"); - const interval = setting("interval"); +let history3 = + storage.readJSON(LOG_FILE, true) || []; // history of recent 3 hours - let history3 = storage.readJSON(LOG_FILE, true) || []; // history of recent 3 hours +function showAlarm(body, key, type) { + if (body == undefined) + return; + stop = true; - function showAlarm(body, key) { - if (body == undefined) return; - stop = true; - - E.showPrompt(body, { - title: "Pressure alarm", - buttons: { - "Ok": 1, - "Dismiss": 2, - "Pause": 3 - } - }).then(function(v) { - const tsNow = Math.round(Date.now() / 1000); // seconds - - if (v == 1) { - saveSetting(key, tsNow); - } - if (v == 2) { - // save timestamp of the future so that we do not warn again for the same event until then - saveSetting(key, tsNow + 60 * setting('dismissDelayMin')); - } - if (v == 3) { - // save timestamp of the future so that we do not warn again for the same event until then - saveSetting(key, tsNow + 60 * setting('pauseDelayMin')); - } - stop = false; - load(); - }); - - if (setting("buzz") && - !(storage.readJSON('setting.json', 1) || {}).quiet) { - Bangle.buzz(); - } - - setTimeout(function() { - stop = false; - load(); - }, 20000); - } - - - function doWeNeedToWarn(key) { + E.showPrompt(body, { + title : "Pressure " + (type != undefined ? type : "alarm"), + buttons : {"Ok" : 1, "Dismiss" : 2, "Pause" : 3} + }).then(function(v) { const tsNow = Math.round(Date.now() / 1000); // seconds - return setting(key) == 0 || setting(key) < tsNow; + + if (v == 1) { + saveSetting(key, tsNow); + } + if (v == 2) { + // save timestamp of the future so that we do not warn again for the same + // event until then + saveSetting(key, tsNow + 60 * setting('dismissDelayMin')); + } + if (v == 3) { + // save timestamp of the future so that we do not warn again for the same + // event until then + saveSetting(key, tsNow + 60 * setting('pauseDelayMin')); + } + stop = false; + load(); + }); + + if (setting("buzz") && !(storage.readJSON('setting.json', 1) || {}).quiet) { + Bangle.buzz(); } - function checkForAlarms(pressure) { - if (pressure == undefined || pressure <= 0) return; + setTimeout(function() { + stop = false; + load(); + }, 20000); +} - let alreadyWarned = false; +/* + * returns true if an alarm should be triggered + */ +function doWeNeedToAlarm(key) { + const tsNow = Math.round(Date.now() / 1000); // seconds + return setting(key) == undefined || setting(key) == 0 || tsNow > setting(key); +} - const ts = Math.round(Date.now() / 1000); // seconds - const d = { - "ts": ts, - "p": pressure - }; +function isValidPressureValue(pressure) { + if (pressure == undefined || pressure <= 0) + return false; + return pressure > 800 && pressure < 1200; // very rough values +} - // delete entries older than 3h - for (let i = 0; i < history3.length; i++) { - if (history3[i]["ts"] < ts - (3 * 60 * 60)) { - history3.shift(); - } - } - // delete oldest entries until we have max 50 - while (history3.length > 50) { +function handlePressureValue(pressure) { + if (pressure == undefined || pressure <= 0) + return; + + const ts = Math.round(Date.now() / 1000); // seconds + const d = {"ts" : ts, "p" : pressure}; + + history3.push(d); + + // delete oldest entries until we have max 50 + while (history3.length > 50) { + history3.shift(); + } + + // delete entries older than 3h + for (let i = 0; i < history3.length; i++) { + if (history3[i]["ts"] < ts - (3 * 60 * 60)) { history3.shift(); + } else { + break; } + } - if (setting("lowalarm")) { - // Is below the alarm threshold? - if (pressure <= setting("min")) { - if (!doWeNeedToWarn("lastLowWarningTs")) { - showAlarm("Pressure low: " + Math.round(pressure) + " hPa", "lastLowWarningTs"); - alreadyWarned = true; - } - } else { - saveSetting("lastLowWarningTs", 0); + // write data to storage + storage.writeJSON(LOG_FILE, history3); + + calculcate3hAveragePressure(); + + if (setting("lowalarm") || setting("highalarm") || setting("drop3halarm") || + setting("raise3halarm")) { + checkForAlarms(pressure, ts); + } +} + +function checkForAlarms(pressure, ts) { + let alreadyWarned = false; + + if (setting("lowalarm")) { + // Is below the alarm threshold? + if (pressure <= setting("min")) { + if (!doWeNeedToAlarm("lowWarnTs")) { + showAlarm("Pressure low: " + Math.round(pressure) + " hPa", "lowWarnTs", + "low"); + alreadyWarned = true; } + } else { + saveSetting("lowWarnTs", 0); } + } - if (setting("highalarm")) { - // Is above the alarm threshold? - if (pressure >= setting("max")) { - if (doWeNeedToWarn("lastHighWarningTs")) { - showAlarm("Pressure high: " + Math.round(pressure) + " hPa", "lastHighWarningTs"); - alreadyWarned = true; - } - } else { - saveSetting("lastHighWarningTs", 0); + if (setting("highalarm")) { + // Is above the alarm threshold? + if (pressure >= setting("max")) { + if (doWeNeedToAlarm("highWarnTs")) { + showAlarm("Pressure high: " + Math.round(pressure) + " hPa", + "highWarnTs", "high"); + alreadyWarned = true; } + } else { + saveSetting("highWarnTs", 0); } + } - if (history3.length > 0 && !alreadyWarned) { - // 3h change detection - const drop3halarm = setting("drop3halarm"); - const raise3halarm = setting("raise3halarm"); - if (drop3halarm > 0 || raise3halarm > 0) { - // we need at least 30min of data for reliable detection - const diffDateAge = Math.abs(history3[0]["ts"] - ts); - if (diffDateAge < 10 * 60) { // todo change to 1800 - return; - } - + if (history3.length > 0 && !alreadyWarned) { + // 3h change detection + const drop3halarm = setting("drop3halarm"); + const raise3halarm = setting("raise3halarm"); + if (drop3halarm > 0 || raise3halarm > 0) { + // we need at least 30 minutes of data for reliable detection + const diffDateAge = Math.abs(history3[0]["ts"] - ts); + if (diffDateAge > 30 * 60) { // Get oldest entry: const oldestPressure = history3[0]["p"]; if (oldestPressure != undefined && oldestPressure > 0) { @@ -143,66 +160,76 @@ // drop alarm if (drop3halarm > 0 && oldestPressure > pressure) { - if (diffPressure > drop3halarm) { - if (doWeNeedToWarn("lastDropWarningTs")) { - showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " + - Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "lastDropWarningTs"); + if (diffPressure >= drop3halarm) { + if (doWeNeedToAlarm("dropWarnTs")) { + showAlarm((Math.round(diffPressure * 10) / 10) + + " hPa/3h from " + Math.round(oldestPressure) + + " to " + Math.round(pressure) + " hPa", + "dropWarnTs", "drop"); } } else { - saveSetting("lastDropWarningTs", 0); + if (ts > setting("dropWarnTs")) + saveSetting("dropWarnTs", 0); } } else { - saveSetting("lastDropWarningTs", 0); + if (ts > setting("dropWarnTs")) + saveSetting("dropWarnTs", 0); } // raise alarm if (raise3halarm > 0 && oldestPressure < pressure) { - if (diffPressure > raise3halarm) { - if (doWeNeedToWarn("lastRaiseWarningTs")) { - showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " + - Math.round(oldestPressure) + " to " + Math.round(pressure) + " hPa", "lastRaiseWarningTs"); + if (diffPressure >= raise3halarm) { + if (doWeNeedToAlarm("raiseWarnTs")) { + showAlarm((Math.round(diffPressure * 10) / 10) + + " hPa/3h from " + Math.round(oldestPressure) + + " to " + Math.round(pressure) + " hPa", + "raiseWarnTs", "raise"); } } else { - saveSetting("lastRaiseWarningTs", 0); + if (ts > setting("raiseWarnTs")) + saveSetting("raiseWarnTs", 0); } } else { - saveSetting("lastRaiseWarningTs", 0); + if (ts > setting("raiseWarnTs")) + saveSetting("raiseWarnTs", 0); } } } } - - history3.push(d); - // write data to storage - storage.writeJSON(LOG_FILE, history3); - - // calculate 3h average for widget - if (history3.length > 0) { - let sum = 0; - for (let i = 0; i < history3.length; i++) { - sum += history3[i]["p"]; - } - threeHourAvrPressure = sum / history3.length; - } else { - threeHourAvrPressure = undefined; - } } +} +function calculcate3hAveragePressure() { + if (history3 != undefined && history3.length > 0) { + let sum = 0; + for (let i = 0; i < history3.length; i++) { + sum += history3[i]["p"]; + } + threeHourAvrPressure = sum / history3.length; + } else { + threeHourAvrPressure = undefined; + } +} - /* - turn on barometer power - take multiple measurements - sort the results - take the middle one (median) - turn off barometer power - */ - function check() { - if (stop) return; - const MEDIANLENGTH = 20; - Bangle.setBarometerPower(true, "widbaroalarm"); - Bangle.on('pressure', function(e) { - while (currentPressures.length > MEDIANLENGTH) currentPressures.pop(); - currentPressures.unshift(e.pressure); +/* + turn on barometer power + take multiple measurements + sort the results + take the middle one (median) + turn off barometer power +*/ +function getPressureValue() { + if (stop) + return; + const MEDIANLENGTH = 20; + Bangle.setBarometerPower(true, "widbaroalarm"); + Bangle.on('pressure', function(e) { + while (currentPressures.length > MEDIANLENGTH) + currentPressures.pop(); + + const pressure = e.pressure; + if (isValidPressureValue(pressure)) { + currentPressures.unshift(pressure); median = currentPressures.slice().sort(); if (median.length > 10) { @@ -210,59 +237,68 @@ medianPressure = Math.round(E.sum(median.slice(mid - 4, mid + 5)) / 9); if (medianPressure > 0) { turnOff(); - checkForAlarms(medianPressure); + draw(); + handlePressureValue(medianPressure); } } - }); - - setTimeout(function() { - turnOff(); - }, 10000); - } - - function turnOff() { - if (Bangle.isBarometerOn()) - Bangle.setBarometerPower(false, "widbaroalarm"); - } - - function reload() { - check(); - } - - function draw() { - if (global.WIDGETS != undefined && typeof global.WIDGETS === "object") { - global.WIDGETS["baroalarm"] = { - width: setting("show") ? 24 : 0, - reload: reload, - area: "tr", - draw: draw - }; } - g.reset(); - if (setting("show")) { - g.setFont("6x8", 1).setFontAlign(1, 0); - if (medianPressure == undefined) { - check(); - const x = this.x, - y = this.y; - g.drawString("...", x + 24, y + 6); - setTimeout(function() { - g.setFont("6x8", 1).setFontAlign(1, 0); - g.drawString(Math.round(medianPressure), x + 24, y + 6); - }, 10000); - } else { + }); + + setTimeout(function() { turnOff(); }, 30000); +} + +function turnOff() { + if (Bangle.isBarometerOn()) + Bangle.setBarometerPower(false, "widbaroalarm"); +} + +function draw() { + if (global.WIDGETS != undefined && typeof global.WIDGETS === "object") { + global.WIDGETS["baroalarm"] = { + width : setting("show") ? 24 : 0, + area : "tr", + draw : draw + }; + } + g.reset(); + + if (this.x == undefined || this.y != 0) + return; // widget not yet there + + g.clearRect(this.x, this.y, this.x + this.width - 1, this.y + 23); + + if (setting("show")) { + g.setFont("6x8", 1).setFontAlign(1, 0); + if (medianPressure == undefined) { + // trigger a new check + getPressureValue(); + + // lets load last value from log (if available) + if (history3.length > 0) { + medianPressure = history3[history3.length - 1]["p"]; g.drawString(Math.round(medianPressure), this.x + 24, this.y + 6); + } else { + g.drawString("...", this.x + 24, this.y + 6); } + } else { + g.drawString(Math.round(medianPressure), this.x + 24, this.y + 6); + } - if (threeHourAvrPressure != undefined && threeHourAvrPressure > 0) { - g.drawString(Math.round(threeHourAvrPressure), this.x + 24, this.y + 6 + 10); + if (threeHourAvrPressure == undefined) { + calculcate3hAveragePressure(); + } + if (threeHourAvrPressure != undefined) { + if (medianPressure != undefined) { + const diff = Math.round(medianPressure - threeHourAvrPressure); + g.drawString((diff > 0 ? "+" : "") + diff, this.x + 24, + this.y + 6 + 10); } } } +} - if (interval > 0) { - setInterval(check, interval * 60000); - } - draw(); - +if (interval > 0) { + setInterval(getPressureValue, interval * 60000); +} +getPressureValue(); })(); diff --git a/apps/widbars/ChangeLog b/apps/widbars/ChangeLog index 61e28e6e4..0065c1b27 100644 --- a/apps/widbars/ChangeLog +++ b/apps/widbars/ChangeLog @@ -1,3 +1,4 @@ 0.01: New Widget! 0.02: Battery bar turns yellow on charge Memory status bar does not trigger garbage collect +0.03: Set battery color on load diff --git a/apps/widbars/metadata.json b/apps/widbars/metadata.json index a9981305c..06965e77e 100644 --- a/apps/widbars/metadata.json +++ b/apps/widbars/metadata.json @@ -1,7 +1,7 @@ { "id": "widbars", "name": "Bars Widget", - "version": "0.02", + "version": "0.03", "description": "Display several measurements as vertical bars.", "icon": "icon.png", "screenshots": [{"url":"screenshot.png"}], diff --git a/apps/widbars/widget.js b/apps/widbars/widget.js index cceeb0897..0a4bba76c 100644 --- a/apps/widbars/widget.js +++ b/apps/widbars/widget.js @@ -42,7 +42,7 @@ if (top) g .clearRect(x,y, x+w-1,y+top-1); // erase above bar if (f) g.setColor(col).fillRect(x,y+top, x+w-1,y+h-1); // even for f=0.001 this is still 1 pixel high } - let batColor='#0f0'; + let batColor=Bangle.isCharging()?'#ff0':'#0f0'; function draw() { g.reset(); const x = this.x, y = this.y, diff --git a/apps/widbat/metadata.json b/apps/widbat/metadata.json index 0f040396f..993310eb2 100644 --- a/apps/widbat/metadata.json +++ b/apps/widbat/metadata.json @@ -6,6 +6,8 @@ "icon": "widget.png", "type": "widget", "tags": "widget,battery", + "provides_widgets" : ["battery"], + "default" : true, "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ {"name":"widbat.wid.js","url":"widget.js"} diff --git a/apps/widbata/metadata.json b/apps/widbata/metadata.json index 26968a7d7..ddc901e80 100644 --- a/apps/widbata/metadata.json +++ b/apps/widbata/metadata.json @@ -10,6 +10,7 @@ "readme": "README.md", "description": "Shows the current battery level status in the top right using the clocks colour theme", "tags": "widget,battery", + "provides_widgets" : ["battery"], "storage": [ {"name":"widbata.wid.js","url":"widbata.wid.js"} ] diff --git a/apps/widbatpc/metadata.json b/apps/widbatpc/metadata.json index 7da4e3e0c..953f8d345 100644 --- a/apps/widbatpc/metadata.json +++ b/apps/widbatpc/metadata.json @@ -7,6 +7,7 @@ "icon": "widget.png", "type": "widget", "tags": "widget,battery", + "provides_widgets" : ["battery"], "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "screenshots": [{"url":"widbatpc.full.jpg"},{"url":"widbatpc.part.jpg"}], diff --git a/apps/widbatv/metadata.json b/apps/widbatv/metadata.json index 37cf6197b..d4ef28315 100644 --- a/apps/widbatv/metadata.json +++ b/apps/widbatv/metadata.json @@ -6,6 +6,7 @@ "icon": "widget.png", "type": "widget", "tags": "widget,battery", + "provides_widgets" : ["battery"], "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ {"name":"widbatv.wid.js","url":"widget.js"} diff --git a/apps/widbt/metadata.json b/apps/widbt/metadata.json index e2d5082a5..1623db7a1 100644 --- a/apps/widbt/metadata.json +++ b/apps/widbt/metadata.json @@ -6,6 +6,8 @@ "icon": "widget.png", "type": "widget", "tags": "widget,bluetooth", + "provides_widgets" : ["bluetooth"], + "default" : true, "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ {"name":"widbt.wid.js","url":"widget.js"} diff --git a/apps/widbt_notify/ChangeLog b/apps/widbt_notify/ChangeLog index 3708089c1..d48cdca63 100644 --- a/apps/widbt_notify/ChangeLog +++ b/apps/widbt_notify/ChangeLog @@ -9,3 +9,8 @@ 0.10: Bug fix 0.11: Avoid too many notifications. Change disconnected colour to red. 0.12: Prevent repeated execution of `draw()` from the current app. +0.13: Added "connection restored" notification. Fixed restoring of the watchface. +0.14: Added configuration option +0.15: Added option to hide widget when connected +0.16: Simplify code, add option to disable displaying a message +0.17: Minor display fix \ No newline at end of file diff --git a/apps/widbt_notify/metadata.json b/apps/widbt_notify/metadata.json index 0a144ade1..5e3f15af2 100644 --- a/apps/widbt_notify/metadata.json +++ b/apps/widbt_notify/metadata.json @@ -1,13 +1,18 @@ { "id": "widbt_notify", "name": "Bluetooth Widget with Notification", - "version": "0.12", - "description": "Show the current Bluetooth connection status in the top right of the clock and vibrate when disconnected.", + "version": "0.17", + "description": "Show the current Bluetooth connection status with some optional features: show message, buzz on connect/loss, hide always/if connected.", "icon": "widget.png", "type": "widget", "tags": "widget,bluetooth", + "provides_widgets" : ["bluetooth"], "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"widbt_notify.wid.js","url":"widget.js"} + {"name":"widbt_notify.wid.js","url":"widget.js"}, + {"name":"widbt_notify.settings.js","url":"settings.js"} + ], + "data": [ + {"name":"widbt_notify.json"} ] } diff --git a/apps/widbt_notify/settings.js b/apps/widbt_notify/settings.js new file mode 100644 index 000000000..5c67fed7b --- /dev/null +++ b/apps/widbt_notify/settings.js @@ -0,0 +1,57 @@ +(function(back) { + + var filename = "widbt_notify.json"; + + // set Storage and load settings + var storage = require("Storage"); + var settings = Object.assign({ + showWidget: true, + buzzOnConnect: true, + buzzOnLoss: true, + hideConnected: true, + showMessage: true, + nextBuzz: 30000 + }, storage.readJSON(filename, true) || {}); + + // setup boolean menu entries + function boolEntry(key) { + return { + value: settings[key], + onchange: v => { + // change the value of key + settings[key] = v; + // write to storage + storage.writeJSON(filename, settings); + } + }; + } + + // setup menu + var menu = { + "": { + "title": "Bluetooth Widget WN" + }, + "< Back": () => back(), + "Show Widget": boolEntry("showWidget"), + "Buzz on connect": boolEntry("buzzOnConnect"), + "Buzz on loss": boolEntry("buzzOnLoss"), + "Hide connected": boolEntry("hideConnected"), + "Show Message": boolEntry("showMessage"), + "Next Buzz": { + value: settings.nextBuzz, + step: 1000, + min: 1000, + max: 120000, + wrap: true, + format: v => (v / 1000) + "s", + onchange: v => { + settings.nextBuzz = v; + storage.writeJSON(filename, settings); + } + } + }; + + // draw main menu + E.showMenu(menu); + +}) \ No newline at end of file diff --git a/apps/widbt_notify/widget.js b/apps/widbt_notify/widget.js index fd088c670..4730db5b5 100644 --- a/apps/widbt_notify/widget.js +++ b/apps/widbt_notify/widget.js @@ -1,46 +1,90 @@ -WIDGETS.bluetooth_notify = { +(function() { + // load settings + var settings = Object.assign({ + showWidget: true, + buzzOnConnect: true, + buzzOnLoss: true, + hideConnected: true, + showMessage: true, + nextBuzz: 30000 + }, require("Storage").readJSON("widbt_notify.json", true) || {}); + + // setup widget with to hide if connected and option set + var widWidth = settings.hideConnected && NRF.getSecurityStatus().connected ? 0 : 15; + + // write widget with loaded settings + WIDGETS.bluetooth_notify = Object.assign(settings, { + + // set area and width area: "tr", - width: 15, + width: widWidth, + + // setup warning status warningEnabled: 1, + draw: function() { + if (this.showWidget) { g.reset(); if (NRF.getSecurityStatus().connected) { + if (!this.hideConnected) { g.setColor((g.getBPP() > 8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); + } } else { - // g.setColor(g.theme.dark ? "#666" : "#999"); - g.setColor("#f00"); // red is easier to distinguish from blue + // g.setColor(g.theme.dark ? "#666" : "#999"); + g.setColor("#f00"); // red is easier to distinguish from blue + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); } - g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); + } }, - - redrawCurrentApp: function(){ - if(typeof(draw)=='function'){ - draw(); - }else{ - load(); // fallback. This might reset some variables - } - }, - - connect: function() { - WIDGETS.bluetooth_notify.draw(); - }, - - disconnect: function() { - if(WIDGETS.bluetooth_notify.warningEnabled == 1){ - E.showMessage(/*LANG*/'Connection\nlost.', 'Bluetooth'); - setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. - - WIDGETS.bluetooth_notify.warningEnabled = 0; - setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds. - - var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; - if(!quiet){ - Bangle.buzz(700, 1); // buzz on connection loss - } - } - WIDGETS.bluetooth_notify.draw(); - } -}; -NRF.on('connect', WIDGETS.bluetooth_notify.connect); -NRF.on('disconnect', WIDGETS.bluetooth_notify.disconnect); + redrawCurrentApp: function() { + if (typeof(draw) == 'function') { + g.reset().clear(); + draw(); + Bangle.loadWidgets(); + Bangle.drawWidgets(); + } else { + load(); // fallback. This might reset some variables + } + }, + + onNRF: function(connect) { + // setup widget with and reload widgets to show/hide if hideConnected is enabled + if (this.hideConnected) { + this.width = connect ? 0 : 15; // ensures correct redraw + Bangle.drawWidgets(); + } else { + // redraw widget + this.draw(); + } + + if (this.warningEnabled) { + if (this.showMessage) { + E.showMessage( /*LANG*/ 'Connection\n' + (connect ? /*LANG*/ 'restored.' : /*LANG*/ 'lost.'), 'Bluetooth'); + setTimeout(() => { + WIDGETS.bluetooth_notify.redrawCurrentApp(); + }, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. + } + + this.warningEnabled = 0; + setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', this.nextBuzz); // don't buzz for the next X seconds. + + var quiet = (require('Storage').readJSON('setting.json', 1) || {}).quiet; + if (!quiet && (connect ? this.buzzOnConnect : this.buzzOnLoss)) { + Bangle.buzz(700, 1); // buzz on connection resume or loss + } + } + } + + }); + + // clear variables + settings = undefined; + widWidth = undefined; + + // setup bluetooth connection events + NRF.on('connect', (addr) => WIDGETS.bluetooth_notify.onNRF(addr)); + NRF.on('disconnect', () => WIDGETS.bluetooth_notify.onNRF()); + +})() \ No newline at end of file diff --git a/apps/widbthide/metadata.json b/apps/widbthide/metadata.json index 59b13adb4..e3ac5cd54 100644 --- a/apps/widbthide/metadata.json +++ b/apps/widbthide/metadata.json @@ -6,6 +6,7 @@ "icon": "widget.png", "type": "widget", "tags": "widget,bluetooth", + "provides_widgets" : ["bluetooth"], "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ {"name":"widbthide.wid.js","url":"widget.js"} diff --git a/apps/widclk/ChangeLog b/apps/widclk/ChangeLog index c74857ab4..1a89e2780 100644 --- a/apps/widclk/ChangeLog +++ b/apps/widclk/ChangeLog @@ -3,3 +3,4 @@ 0.04: Fix regression stopping correct widget updates 0.05: Don't show clock widget if already showing clock app 0.06: Use 7 segment font, update *on* the minute, use less memory +0.07: allow turning on/off when quick-switching apps diff --git a/apps/widclk/metadata.json b/apps/widclk/metadata.json index 6996f4080..e4d7d76d1 100644 --- a/apps/widclk/metadata.json +++ b/apps/widclk/metadata.json @@ -1,8 +1,8 @@ { "id": "widclk", "name": "Digital clock widget", - "version": "0.06", - "description": "A simple digital clock widget", + "version": "0.07", + "description": "A simple digital clock widget that appears when not showing a fullscreen clock", "icon": "widget.png", "type": "widget", "tags": "widget,clock", diff --git a/apps/widclk/widget.js b/apps/widclk/widget.js index 9e035ca9a..7c281f761 100644 --- a/apps/widclk/widget.js +++ b/apps/widclk/widget.js @@ -1,10 +1,13 @@ /* Simple clock that appears in the widget bar if no other clock is running. We update once per minute, but don't bother stopping if the */ - -// don't show widget if we know we have a clock app running -if (!Bangle.CLOCK) WIDGETS["wdclk"]={area:"tl",width:52/* g.stringWidth("00:00") */,draw:function() { - g.reset().setFontCustom(atob("AAAAAAAAAAIAAAQCAQAAAd0BgMBdwAAAAAAAdwAB0RiMRcAAAERiMRdwAcAQCAQdwAcERiMRBwAd0RiMRBwAAEAgEAdwAd0RiMRdwAcERiMRdwAFAAd0QiEQdwAdwRCIRBwAd0BgMBAAABwRCIRdwAd0RiMRAAAd0QiEQAAAAAAAAAA="), 32, atob("BgAAAAAAAAAAAAAAAAYCAAYGBgYGBgYGBgYCAAAAAAAABgYGBgYG"), 512+9); +WIDGETS["wdclk"]={area:"tl",width:Bangle.CLOCK?0:52/* g.stringWidth("00:00") */,draw:function() { + if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not... + this.width = Bangle.CLOCK?0:52; + return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw + } + if (!this.width) return; // if size not right, return +g.reset().setFontCustom(atob("AAAAAAAAAAIAAAQCAQAAAd0BgMBdwAAAAAAAdwAB0RiMRcAAAERiMRdwAcAQCAQdwAcERiMRBwAd0RiMRBwAAEAgEAdwAd0RiMRdwAcERiMRdwAFAAd0QiEQdwAdwRCIRBwAd0BgMBAAABwRCIRdwAd0RiMRAAAd0QiEQAAAAAAAAAA="), 32, atob("BgAAAAAAAAAAAAAAAAYCAAYGBgYGBgYGBgYCAAAAAAAABgYGBgYG"), 512+9); var time = require("locale").time(new Date(),1); g.drawString(time, this.x, this.y+3, true); // 5 * 6*2 = 60 // queue draw in one minute diff --git a/apps/widclkbttm/ChangeLog b/apps/widclkbttm/ChangeLog index 326169af5..373337378 100644 --- a/apps/widclkbttm/ChangeLog +++ b/apps/widclkbttm/ChangeLog @@ -1,4 +1,6 @@ 0.01: Fork of widclk v0.04 github.com/espruino/BangleApps/tree/master/apps/widclk 0.02: Modification for bottom widget area and text color 0.03: based in widclk v0.05 compatible at same time, bottom area and color +0.04: refactored to use less memory, and allow turning on/off when quick-switching apps +0.05: Remove cyan color, use theme foreground instead diff --git a/apps/widclkbttm/metadata.json b/apps/widclkbttm/metadata.json index 9e92f7c46..2bcd6bc58 100644 --- a/apps/widclkbttm/metadata.json +++ b/apps/widclkbttm/metadata.json @@ -2,8 +2,8 @@ "id": "widclkbttm", "name": "Digital clock (Bottom) widget", "shortName": "Digital clock Bottom Widget", - "version": "0.03", - "description": "Displays time in the bottom area.", + "version": "0.05", + "description": "Displays time in the bottom of the screen (may not be compatible with some apps)", "icon": "widclkbttm.png", "type": "widget", "tags": "widget", diff --git a/apps/widclkbttm/widclkbttm.wid.js b/apps/widclkbttm/widclkbttm.wid.js index c27906786..2278b5380 100644 --- a/apps/widclkbttm/widclkbttm.wid.js +++ b/apps/widclkbttm/widclkbttm.wid.js @@ -1,31 +1,16 @@ -(function() { - // don't show widget if we know we have a clock app running - if (Bangle.CLOCK) return; - - let intervalRef = null; - var width = 5 * 6*2; - var text_color=0x07FF;//cyan - - function draw() { - g.reset().setFont("6x8", 2).setFontAlign(-1, 0).setColor(text_color); - var time = require("locale").time(new Date(),1); - g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60 +WIDGETS["wdclkbttm"]={area:"br",width:Bangle.CLOCK?0:60,draw:function() { + if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not... + this.width = Bangle.CLOCK?0:60; + return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw } - function clearTimers(){ - if(intervalRef) { - clearInterval(intervalRef); - intervalRef = null; - } - } - function startTimers(){ - intervalRef = setInterval(()=>WIDGETS["wdclkbttm"].draw(), 60*1000); - WIDGETS["wdclkbttm"].draw(); - } - Bangle.on('lcdPower', (on) => { - clearTimers(); - if (on) startTimers(); - }); - - WIDGETS["wdclkbttm"]={area:"br",width:width,draw:draw}; - if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdclkbttm"].draw(), 60*1000); -})() + if (!this.width) return; // if size not right, return + g.reset().setFont("6x8", 2).setFontAlign(-1, 0); + var time = require("locale").time(new Date(),1); + g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60 + // queue draw in one minute + if (this.drawTimeout) clearTimeout(this.drawTimeout); + this.drawTimeout = setTimeout(()=>{ + this.drawTimeout = undefined; + this.draw(); + }, 60000 - (Date.now() % 60000)); +}}; diff --git a/apps/widclose/ChangeLog b/apps/widclose/ChangeLog index 4be6afb16..1e0c86fc6 100644 --- a/apps/widclose/ChangeLog +++ b/apps/widclose/ChangeLog @@ -1 +1,2 @@ -0.01: New widget! \ No newline at end of file +0.01: New widget! +0.02: allow turning on/off when quick-switching apps diff --git a/apps/widclose/metadata.json b/apps/widclose/metadata.json index e044a2d39..19009fd82 100644 --- a/apps/widclose/metadata.json +++ b/apps/widclose/metadata.json @@ -1,7 +1,7 @@ { "id": "widclose", "name": "Close Button", - "version": "0.01", + "version": "0.02", "description": "A button to close the current app", "readme": "README.md", "icon": "icon.png", diff --git a/apps/widclose/widget.js b/apps/widclose/widget.js index 3a354018b..aeba1de00 100644 --- a/apps/widclose/widget.js +++ b/apps/widclose/widget.js @@ -1,14 +1,17 @@ -if (!Bangle.CLOCK) WIDGETS.close = { - area: "tr", width: 24, sortorder: 10, // we want the right-most spot please +WIDGETS.close = { + area: "tr", width: Bangle.CLOCK?0:24, sortorder: 10, // we want the right-most spot please draw: function() { - Bangle.removeListener("touch", this.touch); - Bangle.on("touch", this.touch); - g.reset().setColor("#f00").drawImage(atob( // hardcoded red to match setUI back button + if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not... + this.width = Bangle.CLOCK?0:24; + return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw + } + if (this.width) g.reset().setColor("#f00").drawImage(atob( // red to match setUI back button // b/w version of preview.png, 24x24 "GBgBABgAAf+AB//gD//wH//4P//8P//8fn5+fjx+fxj+f4H+/8P//8P/f4H+fxj+fjx+fn5+P//8P//8H//4D//wB//gAf+AABgA" ), this.x, this.y); - }, touch: function(_, c) { - const w = WIDGETS.close; - if (w && c.x>=w.x && c.x<=w.x+24 && c.y>=w.y && c.y<=w.y+24) load(); + }, touch: function(_, c) { // if touched + const w = WIDGETS.close; // if in range, go back to the clock + if (w && c.x>=w.x && c.x=w.y && c.y<=w.y+24) load(); } -}; \ No newline at end of file +}; +Bangle.on("touch", WIDGETS.close.touch); diff --git a/apps/widcloselaunch/ChangeLog b/apps/widcloselaunch/ChangeLog new file mode 100644 index 000000000..1e0c86fc6 --- /dev/null +++ b/apps/widcloselaunch/ChangeLog @@ -0,0 +1,2 @@ +0.01: New widget! +0.02: allow turning on/off when quick-switching apps diff --git a/apps/widcloselaunch/README.md b/apps/widcloselaunch/README.md new file mode 100644 index 000000000..1eb384ce1 --- /dev/null +++ b/apps/widcloselaunch/README.md @@ -0,0 +1,9 @@ +# Close Button Launcher + +Adds a ![X](preview.png) button to close the current app and go back to the launcher. +(Widget is not visible on the clock screen) + +Copied from widclose by @rigrig and slightly modified. + +![Light theme screenshot](screenshot_light.png) +![Dark theme screenshot](screenshot_dark.png) diff --git a/apps/widcloselaunch/icon.png b/apps/widcloselaunch/icon.png new file mode 100644 index 000000000..1d95ba0ce Binary files /dev/null and b/apps/widcloselaunch/icon.png differ diff --git a/apps/widcloselaunch/metadata.json b/apps/widcloselaunch/metadata.json new file mode 100644 index 000000000..b5c83e37e --- /dev/null +++ b/apps/widcloselaunch/metadata.json @@ -0,0 +1,15 @@ +{ + "id": "widcloselaunch", + "name": "Close Button to launcher", + "version": "0.02", + "description": "A button to close the current app and go to launcher", + "readme": "README.md", + "icon": "icon.png", + "type": "widget", + "tags": "widget,tools", + "supports": ["BANGLEJS2"], + "screenshots": [{"url":"screenshot_light.png"},{"url":"screenshot_dark.png"}], + "storage": [ + {"name":"widcloselaunch.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widcloselaunch/preview.png b/apps/widcloselaunch/preview.png new file mode 100644 index 000000000..d90a3b4c5 Binary files /dev/null and b/apps/widcloselaunch/preview.png differ diff --git a/apps/widcloselaunch/screenshot_dark.png b/apps/widcloselaunch/screenshot_dark.png new file mode 100644 index 000000000..58067a3b9 Binary files /dev/null and b/apps/widcloselaunch/screenshot_dark.png differ diff --git a/apps/widcloselaunch/screenshot_light.png b/apps/widcloselaunch/screenshot_light.png new file mode 100644 index 000000000..32817ea8d Binary files /dev/null and b/apps/widcloselaunch/screenshot_light.png differ diff --git a/apps/widcloselaunch/widget.js b/apps/widcloselaunch/widget.js new file mode 100644 index 000000000..2c9147d16 --- /dev/null +++ b/apps/widcloselaunch/widget.js @@ -0,0 +1,17 @@ +WIDGETS.close = { + area: "tr", width: Bangle.CLOCK?0:24, sortorder: 10, // we want the right-most spot please + draw: function() { + if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not... + this.width = Bangle.CLOCK?0:24; + return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw + } + if (this.width) g.reset().setColor("#f00").drawImage(atob( // red to match setUI back button + // b/w version of preview.png, 24x24 + "GBgBABgAAf+AB//gD//wH//4P//8P//8fn5+fjx+fxj+f4H+/8P//8P/f4H+fxj+fjx+fn5+P//8P//8H//4D//wB//gAf+AABgA" + ), this.x, this.y); + }, touch: function(_, c) { + const w = WIDGETS.close; + if (w && c.x>=w.x && c.x=w.y && c.y<=w.y+24) Bangle.showLauncher(); + } +}; +Bangle.on("touch", WIDGETS.close.touch); diff --git a/apps/widcw/ChangeLog b/apps/widcw/ChangeLog index a4bc24d1a..07b8f7424 100644 --- a/apps/widcw/ChangeLog +++ b/apps/widcw/ChangeLog @@ -1 +1,2 @@ -0.01: First version \ No newline at end of file +0.01: First version +0.02: Fix memory leak \ No newline at end of file diff --git a/apps/widcw/metadata.json b/apps/widcw/metadata.json index 653b093ec..467ab1729 100644 --- a/apps/widcw/metadata.json +++ b/apps/widcw/metadata.json @@ -1,7 +1,7 @@ { "id": "widcw", "name": "Calendar Week Widget", - "version": "0.01", + "version": "0.02", "description": "Widget which shows the current calendar week", "icon": "widget.png", "type": "widget", diff --git a/apps/widcw/widget.js b/apps/widcw/widget.js index ef43a4551..e33ad0aad 100644 --- a/apps/widcw/widget.js +++ b/apps/widcw/widget.js @@ -34,8 +34,8 @@ } // redraw when date changes - setTimeout(()=>WIDGETS["widcw"].draw(), (86401 - Math.floor(date/1000) % 86400)*1000); - + if (WIDGETS["widcw"].to) clearTimeout(WIDGETS["widcw"].to); + WIDGETS["widcw"].to = setTimeout(()=>WIDGETS["widcw"].draw(), (86401 - Math.floor(date/1000) % 86400)*1000); } // add your widget diff --git a/apps/widdst/ChangeLog b/apps/widdst/ChangeLog new file mode 100644 index 000000000..e350137ee --- /dev/null +++ b/apps/widdst/ChangeLog @@ -0,0 +1,2 @@ +0.01: Initial version +0.02: Checks for correct firmware; E.setDST(...) moved to boot.js diff --git a/apps/widdst/README.md b/apps/widdst/README.md new file mode 100644 index 000000000..ca41c2bed --- /dev/null +++ b/apps/widdst/README.md @@ -0,0 +1,34 @@ +# Daylight savings time widget + +This widget will set the daylight saving rules on your watch. Note you may need a firmware update before this can work. + +## Settings + +You need to set your timezone, and your daylight savings rules, in `Settings -> Apps -> Daylight Savings`. The settings are + +**Enabled** enables or disables the widget + +**Icon** enables or disables the showing of a small "DST" icon when daylight savings is in effect + +**Base TZ** is your "base" timezone - i.e. the timezone you keep when daylight savings is not in effect. It is positive east. + +**Change** is the size of the daylight savings change, which is +1 hour almost everywhere. + +**DST Start, DST End** set the rules for the start and end of daylight savings. + +## Setting the daylight savings rules + +The page for setting **DST Start** and **DST End** ask you to describe the rules for daylight savings changes. For instance, in the UK, the rules are + +**DST Start** `The [last] [Sun] of [Mar] minus [0 days] at [01:00]` + +**DST End** `The [last] [Sun] of [Oct] minus [0 days] at [02:00]` + +In most of the US, the rules are + +**DST Start** `The [2nd] [Sun] of [Mar] minus [0 days] at [02:00]` + +**DST End** `The [1st] [Sun] of [Nov] minus [0 days] at [02:00]` + + + diff --git a/apps/widdst/boot.js b/apps/widdst/boot.js new file mode 100644 index 000000000..b0a844532 --- /dev/null +++ b/apps/widdst/boot.js @@ -0,0 +1,15 @@ +(() => { + + if (E.setDST) { + var dstSettings = require('Storage').readJSON('widdst.json',1)||{}; + if (dstSettings.has_dst) { + E.setDST(60*dstSettings.dst_size, 60*dstSettings.tz, dstSettings.dst_start.dow_number, dstSettings.dst_start.dow, + dstSettings.dst_start.month, dstSettings.dst_start.day_offset, 60*dstSettings.dst_start.at, + dstSettings.dst_end.dow_number, dstSettings.dst_end.dow, dstSettings.dst_end.month, dstSettings.dst_end.day_offset, + 60*dstSettings.dst_end.at); + } else { + E.setDST(0,0,0,0,0,0,0,0,0,0,0,0); + } + } + +})() diff --git a/apps/widdst/icon.png b/apps/widdst/icon.png new file mode 100644 index 000000000..aa7142959 Binary files /dev/null and b/apps/widdst/icon.png differ diff --git a/apps/widdst/metadata.json b/apps/widdst/metadata.json new file mode 100644 index 000000000..144c02998 --- /dev/null +++ b/apps/widdst/metadata.json @@ -0,0 +1,16 @@ +{ "id": "widdst", + "name": "Daylight Saving", + "version":"0.02", + "description": "Widget to set daylight saving rules. Requires Espruino 2v14.49 or later - see the instructions below for more information.", + "icon": "icon.png", + "type": "widget", + "tags": "widget,tool", + "supports" : ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"widdst.wid.js","url":"widget.js"}, + {"name":"widdst.boot.js","url":"boot.js"}, + {"name":"widdst.settings.js","url":"settings.js"} + ], + "data": [{"name":"widdst.json"}] +} diff --git a/apps/widdst/settings.js b/apps/widdst/settings.js new file mode 100644 index 000000000..9a7e579b7 --- /dev/null +++ b/apps/widdst/settings.js @@ -0,0 +1,184 @@ +(function(back) { + + var dows = require("date_utils").dows(0,1); + var months = require("date_utils").months(1); + + var settings = Object.assign({ + has_dst: false, + show_icon: true, + tz: 0, + dst_size: 1, + dst_start: { + dow_number: 4, // "1st", "2nd", "3rd", "4th", "last" + dow: 0, // "Sun", "Mon", ... + month: 2, + day_offset: 0, + at: 1 + }, + dst_end: { + dow_number: 4, + dow: 0, + month: 9, + day_offset: 0, + at: 2 + } + }, require("Storage").readJSON("widdst.json", true) || {}); + + var dst_start_end = { + is_start: true, + day_offset: 0, + dow_number: 0, + dow: 0, + month: 0, + at: 0 + }; + + function writeSettings() { + require('Storage').writeJSON("widdst.json", settings); + } + + function writeSubMenuSettings() { + if (dst_start_end.is_start) { + settings.dst_start.day_offset = dst_start_end.day_offset; + settings.dst_start.dow_number = dst_start_end.dow_number; + settings.dst_start.dow = dst_start_end.dow; + settings.dst_start.month = dst_start_end.month; + settings.dst_start.at = dst_start_end.at; + } else { + settings.dst_end.day_offset = dst_start_end.day_offset; + settings.dst_end.dow_number = dst_start_end.dow_number; + settings.dst_end.dow = dst_start_end.dow; + settings.dst_end.month = dst_start_end.month; + settings.dst_end.at = dst_start_end.at; + } + writeSettings(); + } + + function hoursToString(h) { + return (h|0) + ':' + (((6*h)%6)|0) + (((60*h)%10)|0); + } + + function getDSTStartEndMenu(start) { + dst_start_end.is_start = start; + if (start) { + dst_start_end.day_offset = settings.dst_start.day_offset; + dst_start_end.dow_number = settings.dst_start.dow_number; + dst_start_end.dow = settings.dst_start.dow; + dst_start_end.month = settings.dst_start.month; + dst_start_end.at = settings.dst_start.at; + } else { + dst_start_end.day_offset = settings.dst_end.day_offset; + dst_start_end.dow_number = settings.dst_end.dow_number; + dst_start_end.dow = settings.dst_end.dow; + dst_start_end.month = settings.dst_end.month; + dst_start_end.at = settings.dst_end.at; + } + return { + "": { + "Title": start ? /*LANG*/"DST Start" : /*LANG*/"DST End" + }, + "< Back": () => E.showMenu(dstMenu), + /*LANG*/"The" : { + value: dst_start_end.dow_number, + format: v => [/*LANG*/"1st",/*LANG*/"2nd",/*LANG*/"3rd",/*LANG*/"4th",/*LANG*/"last"][v], + min: 0, + max: 4, + onchange: v => { + dst_start_end.dow_number = v; + writeSubMenuSettings(); + } + }, + " -" : { + value: dst_start_end.dow, + format: v => dows[v], + min:0, + max:6, + onchange: v => { + dst_start_end.dow = v; + writeSubMenuSettings(); + } + }, + /*LANG*/"of": { + value: dst_start_end.month, + format: v => months[v], + min: 0, + max: 11, + onchange: v => { + dst_start_end.month = v; + writeSubMenuSettings(); + } + }, + /*LANG*/"minus" : { + value: dst_start_end.day_offset, + format: v => v + ((v == 1) ? /*LANG*/" day" : /*LANG*/" days"), + min: 0, + max: 7, + onchange: v => { + dst_start_end.day_offset = v; + writeSubMenuSettings(); + } + }, + /*LANG*/"at": { + value: dst_start_end.at, + format: v => hoursToString(v), + min: 0, + max: 23, + // step: 0.05, // every 3 minutes - FOR DEVELOPMENT PURPOSES + onchange: v => { + dst_start_end.at = v; + writeSubMenuSettings(); + } + } + } + } + + var dstMenu = { + "": { + "Title": /*LANG*/"Daylight Saving" + }, + "< Back": () => back(), + /*LANG*/"Enabled": { + value: settings.has_dst, + format: v => v ? /*LANG*/"Yes" : /*LANG*/"No", + onchange: v => { + settings.has_dst = v; + writeSettings(); + } + }, + /*LANG*/"Icon": { + value: settings.show_icon, + format: v => v ? /*LANG*/"Yes" : /*LANG*/"No", + onchange: v => { + settings.show_icon = v; + writeSettings(); + } + }, + /*LANG*/"Base TZ": { + value: settings.tz, + format: v => (v >= 0 ? '+' + hoursToString(v) : '-' + hoursToString(-v)), + onchange: v => { + settings.tz = v; + writeSettings(); + }, + min: -13, + max: 13, + step: 0.25 + }, + /*LANG*/"Change": { + value: settings.dst_size, + format: v => (v >= 0 ? '+' + hoursToString(v): '-' + hoursToString(-v)), + min: -1, + max: 1, + step: 0.5, + onchange: v=> { + settings.dst_size = v; + writeSettings(); + } + }, + /*LANG*/"DST Start": () => E.showMenu(getDSTStartEndMenu(true)), + /*LANG*/"DST End": () => E.showMenu(getDSTStartEndMenu(false)) + }; + + E.showMenu(dstMenu); + +}); diff --git a/apps/widdst/widget.js b/apps/widdst/widget.js new file mode 100644 index 000000000..f690cc68f --- /dev/null +++ b/apps/widdst/widget.js @@ -0,0 +1,55 @@ +(() => { + + // our setTimeout() return value for the function that periodically check the status of DST + var check_timeout = undefined; + + // Called by draw() when we are not in DST or when we are not displaying the icon + function clear() { + if (this.width) { + this.width = 0; + Bangle.drawWidgets(); + } + } + + // draw, or erase, our little "dst" icon in the widgets area + function draw() { + var dstSettings = require('Storage').readJSON('widdst.json',1)||{}; + if ((dstSettings.has_dst) && (dstSettings.show_icon)) { + var now = new Date(); + if (now.getIsDST()) { + if (this.width) { + g.drawImage( + { + width : 24, height : 24, bpp : 1, palette: new Uint16Array([g.theme.bg, g.theme.fg]), + buffer : atob("AAAAAAAAPAAAIgAAIQAAIQAAIQAAIQAAIngAPIQAAIAAAPAAAAwAAAQAAIX8AHggAAAgAAAgAAAgAAAgAAAgAAAgAAAAAAAA") + }, this.x, this.y + ); + } else { + this.width = 24; + Bangle.drawWidgets(); + } + } else { + clear(); + } + if (check_timeout) clearTimeout(check_timeout); + check_timeout = setTimeout( function() { + check_timeout = undefined; + draw(); + }, 3600000 - (now.getTime() % 3600000)); // Check every hour. + } else { + clear(); + } + } + + // Register ourselves + if (E.setDST) { + WIDGETS["widdst"] = { + area: "tl", + width: 0, + draw: draw + }; + } else { + E.showAlert("Firmware update needed to support Daylight Saving Time"); + } + +})() diff --git a/apps/widgps/ChangeLog b/apps/widgps/ChangeLog index 0eb9e5692..b530843e7 100644 --- a/apps/widgps/ChangeLog +++ b/apps/widgps/ChangeLog @@ -4,3 +4,6 @@ 0.04: Show GPS fix status 0.05: Don't poll for GPS status, override setGPSPower handler (fix #1456) 0.06: Periodically update so the always on display does show current GPS fix +0.07: Alternative marker icon (configurable via settings) +0.08: Add ability to hide the icon when GPS is off, for a cleaner appearance. +0.09: Do not take widget space if icon is hidden diff --git a/apps/widgps/README.md b/apps/widgps/README.md index 37e088bcf..98f0ba6f7 100644 --- a/apps/widgps/README.md +++ b/apps/widgps/README.md @@ -6,12 +6,22 @@ The GPS can quickly run the battery down if it is on all the time so it is useful to know if it has been switched on or not. - Uses Bangle.isGPSOn() -- Shows in grey when the GPS is off -- Shows in amber when the GPS is on but has no fix -- Shows in green when the GPS is on and has a fix +There are two icons which can be used to visualize the GPS/GNSS status: +1. A cross colored depending on the GPS/GNSS status + - Shows in grey when the GPS is off + - Shows in amber when the GPS is on but has no fix + - Shows in green when the GPS is on and has a fix +2. Different place markers depending on GPS/GNSS status + +You can also choose to hide the icon when the GPS is off in the settings. + Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/) Extended by Marco ([myxor](https://github.com/myxor)) + +Extended by khromov ([khromov](https://github.com/khromov)) + +Place marker icons from [icons8.com](https://icons8.com/icon/set/maps/material-outlined). diff --git a/apps/widgps/default.json b/apps/widgps/default.json new file mode 100644 index 000000000..28482ddb0 --- /dev/null +++ b/apps/widgps/default.json @@ -0,0 +1 @@ +{"crossIcon": true, "hideWhenGpsOff": false} \ No newline at end of file diff --git a/apps/widgps/metadata.json b/apps/widgps/metadata.json index b135c77bd..cfd35f5bb 100644 --- a/apps/widgps/metadata.json +++ b/apps/widgps/metadata.json @@ -1,14 +1,19 @@ { "id": "widgps", "name": "GPS Widget", - "version": "0.06", - "description": "Tiny widget to show the power and fix status of the GPS", + "version": "0.09", + "description": "Tiny widget to show the power and fix status of the GPS/GNSS", "icon": "widget.png", "type": "widget", "tags": "widget,gps", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "storage": [ - {"name":"widgps.wid.js","url":"widget.js"} + {"name":"widgps.wid.js","url":"widget.js"}, + {"name":"widgps.default.json","url":"default.json"}, + {"name":"widgps.settings.js","url":"settings.js"} + ], + "data": [ + {"name":"widgps.json"} ] } diff --git a/apps/widgps/settings.js b/apps/widgps/settings.js new file mode 100644 index 000000000..7a1c186c9 --- /dev/null +++ b/apps/widgps/settings.js @@ -0,0 +1,32 @@ +(function(back) { +function writeSettings(key, value) { + var s = require('Storage').readJSON(FILE, true) || {}; + s[key] = value; + require('Storage').writeJSON(FILE, s); + readSettings(); +} + +function readSettings() { + settings = Object.assign( + require('Storage').readJSON("widgps.default.json", true) || {}, + require('Storage').readJSON(FILE, true) || {}); +} + +var FILE = "widgps.json"; +var settings; +readSettings(); + +var mainmenu = { + '' : {'title' : 'GPS widget'}, + '< Back' : back, + "Cross icon" : { + value : settings.crossIcon , + onchange : v => { writeSettings("crossIcon", v); } + }, + "Hide icon when GPS off" : { + value : settings.hideWhenGpsOff , + onchange : v => { writeSettings("hideWhenGpsOff", v); } + }, +}; +E.showMenu(mainmenu); +}); \ No newline at end of file diff --git a/apps/widgps/widget.js b/apps/widgps/widget.js index 206096013..73351eaa6 100644 --- a/apps/widgps/widget.js +++ b/apps/widgps/widget.js @@ -1,36 +1,85 @@ -(function(){ - var interval; +(function() { - // override setGPSPower so we know if GPS is on or off - var oldSetGPSPower = Bangle.setGPSPower; - Bangle.setGPSPower = function(on,id) { - var isGPSon = oldSetGPSPower(on,id); - WIDGETS.gps.draw(); - return isGPSon; - } +let settings = Object.assign( + require('Storage').readJSON("widgps.default.json", true) || {}, + require('Storage').readJSON("widgps.json", true) || {} +); - WIDGETS.gps={area:"tr",width:24,draw:function() { +var interval; + +// override setGPSPower so we know if GPS is on or off +var oldSetGPSPower = Bangle.setGPSPower; +Bangle.setGPSPower = function(on, id) { + var isGPSon = oldSetGPSPower(on, id); + WIDGETS.gps.width = !isGPSon && settings.hideWhenGpsOff ? 0 : 24; + Bangle.drawWidgets(); + return isGPSon; +}; + +WIDGETS.gps = { + area : "tr", + width : !Bangle.isGPSOn() && settings.hideWhenGpsOff ? 0 : 24, + draw : function() { g.reset(); - if (Bangle.isGPSOn()) { - const gpsObject = Bangle.getGPSFix(); - if (gpsObject && gpsObject.fix > 0) { - g.setColor("#0F0"); // on and has fix = green - } else { - g.setColor("#FD0"); // on but no fix = amber - } - } else { - g.setColor("#888"); // off = grey - } // check if we need to update the widget periodically if (Bangle.isGPSOn() && interval === undefined) { - interval = setInterval(function() { - WIDGETS.gps.draw(WIDGETS.gps); - }, 10*1000); // update every 10 seconds to show gps fix/no fix + interval = setInterval( + function() { WIDGETS.gps.draw(WIDGETS.gps); }, + 10 * 1000); // update every 10 seconds to show gps fix/no fix } else if (!Bangle.isGPSOn() && interval !== undefined) { clearInterval(interval); interval = undefined; } - g.drawImage(atob("GBiBAAAAAAAAAAAAAA//8B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+A//8AAAAAAAAAAAAA=="), this.x, 2+this.y); - }}; + if (settings.crossIcon) { + if (Bangle.isGPSOn()) { + const gpsObject = Bangle.getGPSFix(); + if (gpsObject && gpsObject.fix > 0) { + g.setColor("#0F0"); // on and has fix = green + } else { + g.setColor("#FD0"); // on but no fix = amber + } + + g.drawImage( + atob( + "GBiBAAAAAAAAAAAAAA//8B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+A//8AAAAAAAAAAAAA=="), + this.x, 2 + this.y); + + } else { + if(!settings.hideWhenGpsOff) { + g.setColor("#888"); // off = grey + + g.drawImage( + atob( + "GBiBAAAAAAAAAAAAAA//8B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+A//8AAAAAAAAAAAAA=="), + this.x, 2 + this.y); + } + } + + } else { // marker icons + if (Bangle.isGPSOn()) { + const gpsObject = Bangle.getGPSFix(); + if (gpsObject && gpsObject.fix > 0) { + // on and has fix + g.drawImage( + atob("GBiBAAAAAAAAAAB+AAD/AAHDgAMAwAcAwAY8YAY8YAY8YAY8YAMAwAMAwAOBwAGBgAHDgADDAABmAAB+AAA8AAAYAAAAAAAAAAAAAA=="), + this.x, 2 + this.y); + + } else { + // GNSS on but no fix + g.drawImage( + atob("GBiBAAAAAAAAAAh+AA3/gA+B4A8AcA+AMAA8GAB+GADnDADDDADDDDDDADBmADB+ABg8ABgYAAwB8A4A8AeB8AH/sAB+EAAAAAAAAA=="), + this.x, 2 + this.y); + } + } else { + // GNSS off + if(!settings.hideWhenGpsOff) { + g.drawImage( + atob("GBiBAAAAAAAAAAB+ABj/ABxDgA4AwAcAwAeMYAfEYAbgYAZwYAM4wAMcQAOOAAGHAAHDgADDwABm4AB+cAA8OAAYGAAAAAAAAAAAAA=="), + this.x, 2 + this.y); + } + } + } + } +}; })(); diff --git a/apps/widhrm/ChangeLog b/apps/widhrm/ChangeLog index 93e2eaf66..1b5d6da57 100644 --- a/apps/widhrm/ChangeLog +++ b/apps/widhrm/ChangeLog @@ -3,3 +3,4 @@ 0.03: Ensure redrawing works with variable size widget system 0.04: tag HRM power requests to allow this ot work alongside other widgets/apps (fix #799) 0.05: Use new 'lock' event, not LCD (so it works on Bangle.js 2) +0.06: Allow configuration of minimum confidence for HRM values diff --git a/apps/widhrm/metadata.json b/apps/widhrm/metadata.json index e566142d2..51a7f3392 100644 --- a/apps/widhrm/metadata.json +++ b/apps/widhrm/metadata.json @@ -1,13 +1,15 @@ { "id": "widhrm", "name": "Simple Heart Rate widget", - "version": "0.05", + "version": "0.06", "description": "When the screen is on, the widget turns on the heart rate monitor and displays the current heart rate (or last known in grey). For this to work well you'll need at least a 15 second LCD Timeout.", "icon": "widget.png", "type": "widget", "tags": "health,widget", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"widhrm.wid.js","url":"widget.js"} - ] + {"name":"widhrm.wid.js","url":"widget.js"}, + {"name":"widhrm.settings.js","url":"settings.js"} + ], + "data": [{"name":"widhrm.json"}] } diff --git a/apps/widhrm/settings.js b/apps/widhrm/settings.js new file mode 100644 index 000000000..0b8c989ac --- /dev/null +++ b/apps/widhrm/settings.js @@ -0,0 +1,36 @@ +/** + * @param {function} back Use back() to return to settings menu + */ +(function(back) { + const SETTINGS_FILE = "widhrm.json"; + const storage = require("Storage"); + + let s = { + confidence: 0 + }; + const saved = storage.readJSON(SETTINGS_FILE, 1) || {}; + for(const key in saved) { + s[key] = saved[key]; + } + + function save(key, value) { + s[key] = value; + storage.write(SETTINGS_FILE, s); + } + + const menu = { + "": {"title": "Simple Heart Rate widget"}, + "< Back": back, + /*LANG*/'min. confidence': { + value: s.confidence, + min: 0, + max : 100, + step: 5, + format: x => { + return x + "%"; + }, + onchange: x => save('confidence', x), + }, + }; + E.showMenu(menu); +}); diff --git a/apps/widhrm/widget.js b/apps/widhrm/widget.js index 7ffe1aa6d..891f284a7 100644 --- a/apps/widhrm/widget.js +++ b/apps/widhrm/widget.js @@ -1,5 +1,18 @@ (() => { if (!Bangle.isLocked) return; // old firmware + + const SETTINGS_FILE = 'widhrm.json'; + let settings; + function loadSettings() { + settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {}; + const DEFAULTS = { + 'confidence': 0 + }; + Object.keys(DEFAULTS).forEach(k=>{ + if (settings[k]===undefined) settings[k]=DEFAULTS[k]; + }); + } + var currentBPM; var lastBPM; var isHRMOn = false; @@ -39,7 +52,7 @@ bpm = lastBPM; isCurrent = false; } - if (bpm===undefined) + if (bpm===undefined || (settings && bpm7) { + //replace 3 digits by k + //substring betw x and y + v_str_hw=v_str_hw.substr(0,v_str_hw.length-3)+"k"; + } + } //else storage + g.reset().setFontVector(v_font_size).setFontAlign(-1, 0); + //clean a longer previous string, care with br widgets + g.drawString(" ", this.x, this.y+11, true); + g.drawString(v_str_hw, this.x, this.y+11, true); + } //end draw + +WIDGETS["wdhwbttm"]={area:"bl",width:60,draw:draw}; +//{area:"bl",width:Bangle.CLOCK?0:60,draw:draw}; +if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdhwbttm"].draw(), 10*1000); +})() diff --git a/apps/widlock/ChangeLog b/apps/widlock/ChangeLog index bb84c2d44..abceba48e 100644 --- a/apps/widlock/ChangeLog +++ b/apps/widlock/ChangeLog @@ -4,3 +4,5 @@ 0.04: Set sortorder to -1 so that widget always takes up the furthest left position 0.05: Set sortorder to -10 so that others can take -1 etc 0.06: Set sortorder to -10 in widget code +0.07: Remove check for .isLocked (extremely old firmwares), speed up widget loading +0.08: Don't completely remove the lock widget when screen unlocked (use 1px) to ensure appRect/drawWidgets still thinks there are widgets diff --git a/apps/widlock/metadata.json b/apps/widlock/metadata.json index 8635a5434..509a5b7a5 100644 --- a/apps/widlock/metadata.json +++ b/apps/widlock/metadata.json @@ -1,7 +1,7 @@ { "id": "widlock", "name": "Lock Widget", - "version": "0.06", + "version": "0.08", "description": "On devices with always-on display (Bangle.js 2) this displays lock icon whenever the display is locked", "icon": "widget.png", "type": "widget", diff --git a/apps/widlock/widget.js b/apps/widlock/widget.js index 592361cd9..b5787e09d 100644 --- a/apps/widlock/widget.js +++ b/apps/widlock/widget.js @@ -1,11 +1,8 @@ -(function(){ - if (!Bangle.isLocked) return; // bail out on old firmware - Bangle.on("lock", function(on) { - WIDGETS["lock"].width = Bangle.isLocked()?16:0; - Bangle.drawWidgets(); - }); - WIDGETS["lock"]={area:"tl",sortorder:10,width:Bangle.isLocked()?16:0,draw:function(w) { - if (Bangle.isLocked()) - g.reset().drawImage(atob("DhABH+D/wwMMDDAwwMf/v//4f+H/h/8//P/z///f/g=="), w.x+1, w.y+4); - }}; -})() +Bangle.on("lock", function() { + WIDGETS["lock"].width = Bangle.isLocked()?16:1; + Bangle.drawWidgets(); +}); +WIDGETS["lock"]={area:"tl",sortorder:10,width:Bangle.isLocked()?16:1,draw:function(w) { + if (Bangle.isLocked()) + g.reset().drawImage(atob("DhABH+D/wwMMDDAwwMf/v//4f+H/h/8//P/z///f/g=="), w.x+1, w.y+4); +}}; diff --git a/apps/widlockunlock/ChangeLog b/apps/widlockunlock/ChangeLog new file mode 100644 index 000000000..b4d1ae593 --- /dev/null +++ b/apps/widlockunlock/ChangeLog @@ -0,0 +1 @@ +0.01: First commit diff --git a/apps/widlockunlock/metadata.json b/apps/widlockunlock/metadata.json new file mode 100644 index 000000000..d701279b9 --- /dev/null +++ b/apps/widlockunlock/metadata.json @@ -0,0 +1,13 @@ +{ + "id": "widlockunlock", + "name": "Lock/Unlock Widget", + "version": "0.01", + "description": "On devices with always-on display (Bangle.js 2) this displays lock icon whenever the display is locked, or an unlock icon otherwise", + "icon": "widget.png", + "type": "widget", + "tags": "widget,lock", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"widlockunlock.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widlockunlock/widget.js b/apps/widlockunlock/widget.js new file mode 100644 index 000000000..0716a9edf --- /dev/null +++ b/apps/widlockunlock/widget.js @@ -0,0 +1,6 @@ +Bangle.on("lockunlock", function() { + Bangle.drawWidgets(); +}); +WIDGETS["lockunlock"]={area:"tl",sortorder:10,width:14,draw:function(w) { + g.reset().drawImage(atob(Bangle.isLocked() ? "DBGBAAAA8DnDDCBCBP////////n/n/n//////z/A" : "DBGBAAAA8BnDDCBABP///8A8A8Y8Y8Y8A8A//z/A"), w.x+1, w.y+3); +}}; diff --git a/apps/widlockunlock/widget.png b/apps/widlockunlock/widget.png new file mode 100644 index 000000000..3a6b98161 Binary files /dev/null and b/apps/widlockunlock/widget.png differ diff --git a/apps/widmeda/ChangeLog b/apps/widmeda/ChangeLog new file mode 100644 index 000000000..6ac092a85 --- /dev/null +++ b/apps/widmeda/ChangeLog @@ -0,0 +1,2 @@ +0.01: Initial Medical Alert Widget! +0.02: Use Medical Information app for medical alert text, and to display details diff --git a/apps/widmeda/README.md b/apps/widmeda/README.md new file mode 100644 index 000000000..151b11058 --- /dev/null +++ b/apps/widmeda/README.md @@ -0,0 +1,23 @@ +# Medical Alert Widget + +Shows a medical alert logo in the top right widget area, and a medical alert message in the bottom widget area. + +**Note:** this is not a replacement for a medical alert band but hopefully a useful addition. + +## Features + +Implemented: + +- Basic medical alert logo and message +- Only display bottom widget on clocks +- High contrast colours depending on theme +- Configure medical alert text (using Medical Information app) +- Show details when touched (using Medical Information app) + +Future: + +- Configure when to show bottom widget (always/never/clocks) + +## Creator + +James Taylor ([jt-nti](https://github.com/jt-nti)) diff --git a/apps/widmeda/metadata.json b/apps/widmeda/metadata.json new file mode 100644 index 000000000..8ce051dd4 --- /dev/null +++ b/apps/widmeda/metadata.json @@ -0,0 +1,16 @@ +{ "id": "widmeda", + "name": "Medical Alert Widget", + "shortName":"Medical Alert", + "version":"0.02", + "description": "Display a medical alert in the bottom widget section.", + "icon": "widget.png", + "type": "widget", + "dependencies" : { "medicalinfo":"app" }, + "tags": "health,medical,tools,widget", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "screenshots": [{"url":"screenshot_light.png"}], + "storage": [ + {"name":"widmeda.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widmeda/screenshot_light.png b/apps/widmeda/screenshot_light.png new file mode 100644 index 000000000..bf92d753d Binary files /dev/null and b/apps/widmeda/screenshot_light.png differ diff --git a/apps/widmeda/widget.js b/apps/widmeda/widget.js new file mode 100644 index 000000000..2758ae11f --- /dev/null +++ b/apps/widmeda/widget.js @@ -0,0 +1,47 @@ +(() => { + function getAlertText() { + const medicalinfo = require("medicalinfo").load(); + const alertText = ((Array.isArray(medicalinfo.medicalAlert)) && (medicalinfo.medicalAlert[0])) ? medicalinfo.medicalAlert[0] : ""; + return (g.wrapString(alertText, g.getWidth()).length === 1) ? alertText : "MEDICAL ALERT"; + } + + // Top right star of life logo + WIDGETS["widmedatr"] = { + area: "tr", + width: 24, + draw: function () { + g.reset(); + g.setColor("#f00"); + g.drawImage(atob("FhYBAAAAA/AAD8AAPwAc/OD/P8P8/x/z/n+/+P5/wP58A/nwP5/x/v/n/P+P8/w/z/Bz84APwAA/AAD8AAAAAA=="), this.x + 1, this.y + 1); + } + }; + + // Bottom medical alert text + WIDGETS["widmedabl"] = { + area: "bl", + width: Bangle.CLOCK ? Bangle.appRect.w : 0, + draw: function () { + // Only show the widget on clocks + if (!Bangle.CLOCK) return; + + g.reset(); + g.setBgColor(g.theme.dark ? "#fff" : "#f00"); + g.setColor(g.theme.dark ? "#f00" : "#fff"); + g.setFont("Vector", 16); + g.setFontAlign(0, 0); + g.clearRect(this.x, this.y, this.x + this.width - 1, this.y + 23); + + const alertText = getAlertText(); + g.drawString(alertText, this.width / 2, this.y + (23 / 2)); + } + }; + + Bangle.on("touch", (_, c) => { + const bl = WIDGETS.widmedabl; + const tr = WIDGETS.widmedatr; + if ((bl && c.x >= bl.x && c.x < bl.x + bl.width && c.y >= bl.y && c.y <= bl.y + 24) + || (tr && c.x >= tr.x && c.x < tr.x + tr.width && c.y >= tr.y && c.y <= tr.y + 24)) { + load("medicalinfo.app.js"); + } + }); +})(); diff --git a/apps/widmeda/widget.png b/apps/widmeda/widget.png new file mode 100644 index 000000000..249bf15bf Binary files /dev/null and b/apps/widmeda/widget.png differ diff --git a/apps/widmessages/ChangeLog b/apps/widmessages/ChangeLog new file mode 100644 index 000000000..348d49528 --- /dev/null +++ b/apps/widmessages/ChangeLog @@ -0,0 +1,5 @@ +0.01: Moved messages widget into standalone widget app +0.02: Fix 'srcs' being defined in global scope + Remove library stub +0.03: Fix messages not showing if UI auto-open is disabled +0.04: Now shows message icons again (#2416) diff --git a/apps/widmessages/README.md b/apps/widmessages/README.md new file mode 100644 index 000000000..398cb4fa8 --- /dev/null +++ b/apps/widmessages/README.md @@ -0,0 +1,30 @@ +# Messages widget + +The default widget to show icons for new messages +It is installed automatically if you install `Android Integration` or `iOS Integration`. + +![screenshot](screenshot.gif) + +## Settings +You can change settings by going to the global `Settings` app, then `App Settings` +and `Messages`: + +* `Flash icon` Toggle flashing of the widget icons. + +* `Widget messages` Not used by this widget. + +## Requests + +Please file any issues on https://github.com/espruino/BangleApps/issues/new?title=widmessages%widget + +## Creator + +Gordon Williams + +## Contributors + +[Jeroen Peters](https://github.com/jeroenpeters1986) + +## Attributions + +Icons used in this app are from https://icons8.com diff --git a/apps/widmessages/app.png b/apps/widmessages/app.png new file mode 100644 index 000000000..c9177692e Binary files /dev/null and b/apps/widmessages/app.png differ diff --git a/apps/widmessages/metadata.json b/apps/widmessages/metadata.json new file mode 100644 index 000000000..0e399f71f --- /dev/null +++ b/apps/widmessages/metadata.json @@ -0,0 +1,18 @@ +{ + "id": "widmessages", + "name": "Message Widget", + "version": "0.04", + "description": "Widget showing new messages", + "icon": "app.png", + "type": "widget", + "tags": "tool,system", + "supports": ["BANGLEJS","BANGLEJS2"], + "screenshots": [{"url": "screenshot.gif"}], + "dependencies" : { "messageicons":"module" }, + "provides_widgets" : ["message"], + "default" : true, + "readme": "README.md", + "storage": [ + {"name":"widmessages.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widmessages/screenshot.gif b/apps/widmessages/screenshot.gif new file mode 100644 index 000000000..e5cc669bd Binary files /dev/null and b/apps/widmessages/screenshot.gif differ diff --git a/apps/widmessages/widget.js b/apps/widmessages/widget.js new file mode 100644 index 000000000..44f525ec8 --- /dev/null +++ b/apps/widmessages/widget.js @@ -0,0 +1,76 @@ +(() => { + if ((require("Storage").readJSON("messages.settings.json", true) || {}).maxMessages===0) return; + + function filterMessages(msgs) { + return msgs.filter(msg => msg.new && msg.id != "music") + .map(m => m.src) // we only need this for icon/color + .filter((msg, i, arr) => arr.findIndex(nmsg => msg.src == nmsg.src) == i); + } + + // NOTE when adding a custom "essages" widget: + // the name still needs to be "messages": the library calls WIDGETS["messages'].hide()/show() + // see e.g. widmsggrid + WIDGETS["messages"] = { + area: "tl", width: 0, srcs: [], draw: function(recall) { + // If we had a setTimeout queued from the last time we were called, remove it + if (WIDGETS["messages"].i) { + clearTimeout(WIDGETS["messages"].i); + delete WIDGETS["messages"].i; + } + Bangle.removeListener("touch", this.touch); + if (!this.width) return; + let settings = Object.assign({flash: true, maxMessages: 3}, require("Storage").readJSON("messages.settings.json", true) || {}); + if (recall!==true || settings.flash) { + const msgsShown = E.clip(this.srcs.length, 0, settings.maxMessages); + g.reset().clearRect(this.x, this.y, this.x+this.width, this.y+23); + for(let i = 0; isettings.maxMessages ? atob("EASBAGGG88/zz2GG") : require("messageicons").getImage(src), + this.x+12+i*24, this.y+12, {rotate: 0/*force centering*/}); + } + } + WIDGETS["messages"].i = setTimeout(() => WIDGETS["messages"].draw(true), 1000); + if (process.env.HWVERSION>1) Bangle.on("touch", this.touch); + }, onMsg: function(type, msg) { + if (this.hidden) return; + if (type==="music") return; + if (msg.id && !msg.new && msg.t!=="remove") return; + this.srcs = filterMessages(require("messages").getMessages(msg)); + const settings = Object.assign({maxMessages:3},require('Storage').readJSON("messages.settings.json", true) || {}); + this.width = 24 * E.clip(this.srcs.length, 0, settings.maxMessages); + if (type!=="init") Bangle.drawWidgets(); // "init" is not a real message type: see below + }, touch: function(b, c) { + var w = WIDGETS["messages"]; + if (!w || !w.width || c.xw.x+w.width || c.yw.y+24) return; + require("messages").openGUI(); + }, + // hide() and show() are required by the "message" library! + hide() { + this.hidden=true; + if (this.width) { + // hide widget + this.width = 0; + Bangle.drawWidgets(); + } + }, show() { + delete this.hidden + this.onMsg("show", {}); // reload messages+redraw + } + }; + + Bangle.on("message", WIDGETS["messages"].onMsg.bind(WIDGETS["messages"])); + WIDGETS["messages"].onMsg("init", {}); // abuse type="init" to prevent Bangle.drawWidgets(); +})(); diff --git a/apps/widminbat/ChangeLog b/apps/widminbat/ChangeLog new file mode 100644 index 000000000..8ff6e2cb6 --- /dev/null +++ b/apps/widminbat/ChangeLog @@ -0,0 +1 @@ +0.01: Initial Version: Display at under 30% battery diff --git a/apps/widminbat/metadata.json b/apps/widminbat/metadata.json new file mode 100644 index 000000000..1c7c10b15 --- /dev/null +++ b/apps/widminbat/metadata.json @@ -0,0 +1,13 @@ +{ "id": "widminbat", + "name": "Minimal Battery", + "shortName":"MinBat", + "version":"0.01", + "description": "A minimal version of the battery widget that only appears if the battery is running low (below 30%)", + "icon": "widget.png", + "type": "widget", + "tags": "widget,battery,minimal", + "supports" : ["BANGLEJS2", "BANGLEJS"], + "storage": [ + {"name":"widminbat.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widminbat/widget.js b/apps/widminbat/widget.js new file mode 100644 index 000000000..9c088bf06 --- /dev/null +++ b/apps/widminbat/widget.js @@ -0,0 +1,29 @@ +(()=>{ + function getWidth() { + return E.getBattery() <= 30 ? 40 : 0; + } + WIDGETS.minbat={area:"tr",width:getWidth(),draw:function() { + if(this.width < 40) return; + var s = 39; + var bat = E.getBattery(); + var x = this.x, y = this.y; + g.reset(); + g.clearRect(x,y,x+s,y+24); + g.setColor(g.theme.fg).fillRect(x,y+2,x+s-4,y+21).clearRect(x+2,y+4,x+s-6,y+19).fillRect(x+s-3,y+10,x+s,y+14); + var barWidth = bat*(s-12)/100; + var color = bat < 15 ? "#f00" : "#f80"; + g.setColor(color).fillRect(x+4,y+6,x+4+barWidth,y+17); + },update: function() { + var newWidth = getWidth(); + if(newWidth != this.width) { + this.width = newWidth; + Bangle.drawWidgets();//relayout + }else{ + this.draw(); + } + }}; + setInterval(()=>{ + var widget = WIDGETS.minbat; + if(widget) {widget.update();} + }, 10*60*1000); +})(); diff --git a/apps/widminbat/widget.png b/apps/widminbat/widget.png new file mode 100644 index 000000000..b04bc4ef9 Binary files /dev/null and b/apps/widminbat/widget.png differ diff --git a/apps/widminbt/ChangeLog b/apps/widminbt/ChangeLog new file mode 100644 index 000000000..28f11c1c7 --- /dev/null +++ b/apps/widminbt/ChangeLog @@ -0,0 +1 @@ +0.01: Initial Release diff --git a/apps/widminbt/metadata.json b/apps/widminbt/metadata.json new file mode 100644 index 000000000..a78f9e0a4 --- /dev/null +++ b/apps/widminbt/metadata.json @@ -0,0 +1,13 @@ +{ + "id": "widminbt", + "name": "Minimal Bluetooth Widget", + "version": "0.01", + "description": "Appears whenever bluetooth is disconnected", + "icon": "widget.png", + "type": "widget", + "tags": "widget,bluetooth,minimal", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"widminbt.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widminbt/widget.js b/apps/widminbt/widget.js new file mode 100644 index 000000000..87439f8c4 --- /dev/null +++ b/apps/widminbt/widget.js @@ -0,0 +1,15 @@ +(()=> { + WIDGETS.minbt={area:"tr",width:NRF.getSecurityStatus().connected?0:15,draw:function() { + if(this.width<15)return; + g.reset(); + g.setColor((g.getBPP()>8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="),2+this.x,2+this.y); + g.setColor("#f00"); + g.drawImage(atob("CxSBAMA8DYG4YwxzBmD4DwHAGAeA8DcGYY4wzB2B4DA="), 2+this.x, 2+this.y); + },changed:function(){ + WIDGETS.minbt.width=NRF.getSecurityStatus().connected?0:15; + Bangle.drawWidgets(); + }}; + NRF.on('connect',WIDGETS.minbt.changed); + NRF.on('disconnect',WIDGETS.minbt.changed); +})(); diff --git a/apps/widminbt/widget.png b/apps/widminbt/widget.png new file mode 100644 index 000000000..661d1a64c Binary files /dev/null and b/apps/widminbt/widget.png differ diff --git a/apps/widmp/ChangeLog b/apps/widmp/ChangeLog index 809173d54..a51ac080a 100644 --- a/apps/widmp/ChangeLog +++ b/apps/widmp/ChangeLog @@ -5,3 +5,4 @@ 0.05: Fixed the algorithm for calculating the moon's phase 0.06: Darkmode, custom colours, and fix a bug with acting on mylocation changes 0.07: Use default Bangle formatter for booleans +0.08: Better formula for the moon's phase diff --git a/apps/widmp/metadata.json b/apps/widmp/metadata.json index 6cfd239f2..654b5a383 100644 --- a/apps/widmp/metadata.json +++ b/apps/widmp/metadata.json @@ -1,7 +1,7 @@ { "id": "widmp", "name": "Moon Phase", - "version": "0.07", + "version": "0.08", "description": "Display the current moon phase in blueish (in light mode) or white (in dark mode) for both hemispheres. In the southern hemisphere the 'My Location' app is needed.", "icon": "widget.png", "type": "widget", diff --git a/apps/widmp/widget.js b/apps/widmp/widget.js index 22a7d6572..e5aa7fef2 100644 --- a/apps/widmp/widget.js +++ b/apps/widmp/widget.js @@ -4,15 +4,14 @@ var phase = 0; // The last phase we calculated var southernHemisphere = false; // when in southern hemisphere -- use the "My Location" App - // https://deirdreobyrne.github.io/calculating_moon_phases/ - function moonPhase(millis) { - k = (millis - 946728000000) / 3155760000000; - mp = (8328.69142475915 * k) + 2.35555563685; - m = (628.30195516723 * k) + 6.24006012726; - d = (7771.37714483372 * k) + 5.19846652984; - t = d + (0.109764 * Math.sin (mp)) - (0.036652 * Math.sin(m)) + (0.022235 * Math.sin(d+d-mp)) + (0.011484 * Math.sin(d+d)) + (0.003735 * Math.sin(mp+mp)) + (0.00192 * Math.sin(d)); - k = (1 - Math.cos(t))/2; - if (Math.sin(t) < 0) { + // https://github.com/deirdreobyrne/LunarPhase + function moonPhase(sec) { + d = (4.847408287988257 + sec/406074.7465115577) % (2.0*Math.PI); + m = (6.245333801867877 + sec/5022682.784840698) % (2.0*Math.PI); + l = (4.456038755040014 + sec/378902.2499653011) % (2.0*Math.PI); + t = d+1.089809730923715e-01 * Math.sin(l)-3.614132757006379e-02 * Math.sin(m)+2.228248661252023e-02 * Math.sin(d+d-l)+1.353592753655652e-02 * Math.sin(d+d)+4.238560208195022e-03 * Math.sin(l+l)+1.961408105275610e-03 * Math.sin(d); + k = (1.0 - Math.cos(t))/2.0; + if ((t >= Math.PI) && (t < 2.0*Math.PI)) { k = -k; } return (k); // Goes 0 -> 1 for waxing, and from -1 -> 0 for waning @@ -71,7 +70,7 @@ millis = (new Date()).getTime(); if ((millis - lastCalculated) >= 7000000) { // if it's more than 7,000 sec since last calculation, re-calculate! - phase = moonPhase(millis); + phase = moonPhase(millis/1000); lastCalculated = millis; } diff --git a/apps/widmsggrid/ChangeLog b/apps/widmsggrid/ChangeLog new file mode 100644 index 000000000..9be40817a --- /dev/null +++ b/apps/widmsggrid/ChangeLog @@ -0,0 +1,4 @@ +0.01: New widget! +0.02: Adjust to message icons moving to messageicons lib +0.03: Use new message library +0.04: Remove library stub \ No newline at end of file diff --git a/apps/widmsggrid/README.md b/apps/widmsggrid/README.md new file mode 100644 index 000000000..36aad20e2 --- /dev/null +++ b/apps/widmsggrid/README.md @@ -0,0 +1,23 @@ +# Messages Grid Widget + +Widget that displays multiple notification icons in a grid. +The widget has a fixed size: if there are multiple notifications it uses smaller +icons. +It shows a single icon per application, so if you have two SMS messages, the +grid only has one SMS icon. +If there are multiple messages waiting, the total number is shown in the +bottom-right corner. + +Example: one SMS, one Signal, and two WhatsApp messages: +![screenshot](screenshot.png) + +## Installation +There can only be one messages widget, so you should uninstall the default "Message Widget". + +## Settings +You can change settings by going to the global `Settings` app, then `App Settings` +and `Messages`: + +* `Flash icon` Toggle flashing of the widget icons. + +* `Widget messages` Not used by this widget. \ No newline at end of file diff --git a/apps/widmsggrid/metadata.json b/apps/widmsggrid/metadata.json new file mode 100644 index 000000000..17d3573ad --- /dev/null +++ b/apps/widmsggrid/metadata.json @@ -0,0 +1,17 @@ +{ + "id": "widmsggrid", + "name": "Messages Grid Widget", + "version": "0.04", + "description": "Widget that displays notification icons in a grid", + "icon": "widget.png", + "type": "widget", + "tags": "tool,system", + "supports": ["BANGLEJS","BANGLEJS2"], + "dependencies" : { "messages":"module" }, + "provides_widgets" : ["message"], + "readme": "README.md", + "storage": [ + {"name":"widmsggrid.wid.js","url":"widget.js"} + ], + "screenshots": [{"url":"screenshot.png"}] +} diff --git a/apps/widmsggrid/screenshot.png b/apps/widmsggrid/screenshot.png new file mode 100644 index 000000000..b1cdb2a5a Binary files /dev/null and b/apps/widmsggrid/screenshot.png differ diff --git a/apps/widmsggrid/widget.js b/apps/widmsggrid/widget.js new file mode 100644 index 000000000..6a5b175ac --- /dev/null +++ b/apps/widmsggrid/widget.js @@ -0,0 +1,102 @@ +(function () { + if (global.MESSAGES) return; // don't load widget while in the app + let settings = require('Storage').readJSON("messages.settings.json", true) || {}; + const s = { + flash: (settings.flash === undefined) ? true : !!settings.flash, + showRead: !!settings.showRead, + }; + delete settings; + // widget name needs to be "messages": the library calls WIDGETS["messages'].hide()/show() + WIDGETS["messages"] = { + area: "tl", width: 0, + flash: s.flash, + showRead: s.showRead, + init: function() { + // runs on first draw + delete w.init; // don't run again + Bangle.on("touch", w.touch); + Bangle.on("message", w.listener); + w.listener(); // update status now + }, + draw: function () { + if (w.init) w.init(); + // If we had a setTimeout queued from the last time we were called, remove it + if (w.t) { + clearTimeout(w.t); + delete w.t; + } + if (!w.width || this.hidden) return; + const b = w.flash && w.status === "new" && ((Date.now() / 1000) & 1), // Blink(= inverse colors) on this second? + // show multiple icons in a grid, by scaling them down + cols = Math.ceil(Math.sqrt(w.srcs.length - 0.1)); // cols===rows, -0.1 to work around rounding error + g.reset().clearRect(w.x, w.y, w.x + w.width - 1, w.y + 24) + .setClipRect(w.x, w.y, w.x + w.width - 1, w.y + 24); // guard against oversized icons + let r = 0, c = 0; // row, column + const offset = pos => Math.floor(pos / cols * 24); // pixel offset for position in row/column + let icons = require("messageicons"); + let defaultCol = icons.getColor("alert", {settings:settings}); + w.srcs.forEach(src => { + const appColor = icons.getColor(src, {settings:settings,default:defaultCol}); + let colors = [g.theme.bg, appColor]; + if (b) { + if (colors[1] == g.theme.fg) colors = colors.reverse(); + else colors[1] = g.theme.fg; + } + g.setColor(colors[1]).setBgColor(colors[0]); + g.drawImage(icons.getImage(src), w.x+offset(c), w.y+offset(r), { scale: 1 / cols }); + if (++c >= cols) { + c = 0; + r++; + } + }); + if (w.total > 1) { + // show total number of messages in bottom-right corner + g.reset(); + if (w.total < 10) g.fillCircle(w.x + w.width - 5, w.y + 20, 4); // single digits get a round background, double digits fill their rectangle + g.setColor(g.theme.bg).setBgColor(g.theme.fg) + .setFont('6x8').setFontAlign(1, 1) + .drawString(w.total, w.x + w.width - 1, w.y + 24, w.total > 9); + } + if (w.flash && w.status === "new") w.t = setTimeout(w.draw, 1000); // schedule redraw while blinking + }, + // show() and hide() are required by the "message" library! + show: function (m) { + delete w.hidden; + w.width = 24; + w.srcs = require("messages").getMessages(m) + .filter(m => !['call', 'map', 'music'].includes(m.id)) + .filter(m => m.new || w.showRead) + .map(m => m.src); + w.total = w.srcs.length; + w.srcs = w.srcs.filter((src, i, uniq) => uniq.indexOf(src) === i); // keep unique entries only + Bangle.drawWidgets(); + Bangle.setLCDPower(1); // turns screen on + }, hide: function () { + w.hidden = true; + w.width = 0; + w.srcs = []; + w.total = 0; + Bangle.drawWidgets(); + }, touch: function (b, c) { + if (!w || !w.width) return; // widget not shown + if (process.env.HWVERSION < 2) { + // Bangle.js 1: open app when on clock we touch the side with widget + if (!Bangle.CLOCK) return; + const m = Bangle.appRect / 2; + if ((w.x < m && b !== 1) || (w.x > m && b !== 2)) return; + } + // Bangle.js 2: open app when touching the widget + else if (c.x < w.x || c.x > w.x + w.width || c.y < w.y || c.y > w.y + 24) return; + require("messages").openGUI(); + }, listener: function (t,m) { + if (this.hidden) return; + w.status = require("messages").status(m); + if (w.status === "new" || (w.status === "old" && w.showRead)) w.show(m); + else w.hide(); + delete w.hidden; // always set by w.hide(), but we checked it wasn't there before + } + }; + delete s; + const w = WIDGETS["messages"]; + Bangle.on("message", w.listener); +})(); diff --git a/apps/widmsggrid/widget.png b/apps/widmsggrid/widget.png new file mode 100644 index 000000000..ce6e7b7ac Binary files /dev/null and b/apps/widmsggrid/widget.png differ diff --git a/apps/widram/ChangeLog b/apps/widram/ChangeLog index e7b406081..7b00c8a48 100644 --- a/apps/widram/ChangeLog +++ b/apps/widram/ChangeLog @@ -1,2 +1,3 @@ 0.01: New Widget! 0.02: Now also visible on Bangle.js 2 +0.03: Remove global declaration of BANGLEJS2 var (fix #2123) diff --git a/apps/widram/metadata.json b/apps/widram/metadata.json index 19ae6d311..ebf23742b 100644 --- a/apps/widram/metadata.json +++ b/apps/widram/metadata.json @@ -2,7 +2,7 @@ "id": "widram", "name": "RAM Widget", "shortName": "RAM Widget", - "version": "0.02", + "version": "0.03", "description": "Display your Bangle's RAM usage percentage in a widget", "icon": "widget.png", "type": "widget", diff --git a/apps/widram/widget.js b/apps/widram/widget.js index 210c85357..07b7c0a5f 100644 --- a/apps/widram/widget.js +++ b/apps/widram/widget.js @@ -1,6 +1,6 @@ (() => { function draw() { - BANGLEJS2 = process.env.HWVERSION==2; + const BANGLEJS2 = process.env.HWVERSION==2; g.reset(); var m = process.memory(); var percent = Math.round(m.usage*100/m.total); diff --git a/apps/widscrlock/ChangeLog b/apps/widscrlock/ChangeLog index e6d9f3512..84e926362 100644 --- a/apps/widscrlock/ChangeLog +++ b/apps/widscrlock/ChangeLog @@ -1,2 +1,3 @@ 0.01: 25/Jun/2022 Added Screenlock widget to depository. 0.02: 26/Jun/2022 Tidied up graphics. Fixed versioning style... +0.03: 28/Jun/2022 Tidied up code. diff --git a/apps/widscrlock/metadata.json b/apps/widscrlock/metadata.json index 9ff76b910..5110d76c1 100644 --- a/apps/widscrlock/metadata.json +++ b/apps/widscrlock/metadata.json @@ -1,7 +1,7 @@ { "id": "widscrlock", "name": "Screenlock Widget", "shortName":"Screenlock", - "version":"0.02", + "version":"0.03", "description": "Lock a Bangle 2 screen by tapping a widget.", "icon": "widget.png", "type": "widget", diff --git a/apps/widscrlock/widget.js b/apps/widscrlock/widget.js index 27ba2df07..cbb71e4cc 100644 --- a/apps/widscrlock/widget.js +++ b/apps/widscrlock/widget.js @@ -1,14 +1,10 @@ // Screenlock Widget (() => { - var widX = 0; - var widY = 0; function draw() { // Draw icon. g.reset(); - widX = this.x; - widY = this.y; - g.drawImage(atob("GBiDAkkkkiSSSUkkkkkkiSSSSSUkkkkiSSf/ySSUkkkSSf///ySSkkiST/ySf+SQUkiST+SST+SAUkSSfySSSfwACkSSfySSSewACiSSfySSSWwAASSSfySSSGwAASSSfySSQGwAASST///+222AASST///2222AASST//+A222AASST//wAG22AASST/+AAA22AASST/2wAG22AAUST+22A222ACkiT222A222ACkiSG22A22wAUkkQA22222ACkkkiAG222wAUkkkkSAAAAASkkkkkkSQACSkkkg=="),widX,widY); + g.drawImage(atob("GBiDAkkkkiSSSUkkkkkkiSSSSSUkkkkiSSf/ySSUkkkSSf///ySSkkiST/ySf+SQUkiST+SST+SAUkSSfySSSfwACkSSfySSSewACiSSfySSSWwAASSSfySSSGwAASSSfySSQGwAASST///+222AASST///2222AASST//+A222AASST//wAG22AASST/+AAA22AASST/2wAG22AAUST+22A222ACkiT222A222ACkiSG22A22wAUkkQA22222ACkkkiAG222wAUkkkkSAAAAASkkkkkkSQACSkkkg=="),scrlock.x,scrlock.y); } // add widget. @@ -18,7 +14,7 @@ draw:draw // Draw widget. }; - setInterval(()=>WIDGETS.widscrlock.draw(), 60000); + var scrlock = WIDGETS.widscrlock; function restoreTimeout(){ // Restore LCDTimeout settings. @@ -27,7 +23,7 @@ var options = []; Bangle.on('touch', function(button, xy) { - if(xy.x>=widX && xy.x<=widX+23 && xy.y>=widY && xy.y<=widY+23) { + if(xy.x>=scrlock.x && xy.x<=scrlock.x+23 && xy.y>=scrlock.y && xy.y<=scrlock.y+23) { options = Bangle.getOptions(); // Store current Timeout settings. Bangle.setLCDTimeout(0.1); // Lock screen. setTimeout(restoreTimeout, 1000); diff --git a/apps/widsleepstatus/ChangeLog b/apps/widsleepstatus/ChangeLog new file mode 100644 index 000000000..bb17be181 --- /dev/null +++ b/apps/widsleepstatus/ChangeLog @@ -0,0 +1,4 @@ +0.01: First version +0.02: Load settings only once + Better icons + Read sleep status on every draw diff --git a/apps/widsleepstatus/metadata.json b/apps/widsleepstatus/metadata.json new file mode 100644 index 000000000..bd0e5d537 --- /dev/null +++ b/apps/widsleepstatus/metadata.json @@ -0,0 +1,16 @@ +{ + "id": "widsleepstatus", + "name": "Sleep Status Widget", + "version": "0.02", + "description": "Shows current status of sleep from sleeplog app.", + "icon": "widget.png", + "type": "widget", + "tags": "widget,sleep", + "supports": ["BANGLEJS","BANGLEJS2"], + "dependencies" : { "sleeplog":"app" }, + "storage": [ + {"name":"widsleepstatus.wid.js","url":"widget.js"}, + {"name":"widsleepstatus.settings.js","url":"settings.js"} + ], + "data": [{"name":"widsleepstatus.json"}] +} diff --git a/apps/widsleepstatus/settings.js b/apps/widsleepstatus/settings.js new file mode 100644 index 000000000..da402e08e --- /dev/null +++ b/apps/widsleepstatus/settings.js @@ -0,0 +1,32 @@ +/** + * @param {function} back Use back() to return to settings menu + */ +(function(back) { + const SETTINGS_FILE = "widsleepstatus.json"; + const storage = require("Storage"); + + let s = { + hidewhenawake: true + }; + const saved = storage.readJSON(SETTINGS_FILE, 1) || {}; + for(const key in saved) { + s[key] = saved[key]; + } + + function save(key) { + return function(value) { + s[key] = value; + storage.write(SETTINGS_FILE, s); + }; + } + + const menu = { + "": {"title": "Sleep Status Widget"}, + "< Back": back, + "Hide when awake": { + value: s.hidewhenawake, + onchange: save("hidewhenawake"), + }, + }; + E.showMenu(menu); +}); diff --git a/apps/widsleepstatus/widget.js b/apps/widsleepstatus/widget.js new file mode 100644 index 000000000..82a058993 --- /dev/null +++ b/apps/widsleepstatus/widget.js @@ -0,0 +1,49 @@ +(function() { + if (!sleeplog) return; + const SETTINGS_FILE = 'widsleepstatus.json'; + let settings; + + function loadSettings() { + settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {}; + const DEFAULTS = { + 'hidewhenawake': true + }; + Object.keys(DEFAULTS).forEach(k => { + if (settings[k] === undefined) settings[k] = DEFAULTS[k]; + }); + } + loadSettings(); + + WIDGETS.sleepstatus = { + area: "tr", + width: 0, + draw: function(w) { + let status = sleeplog.status || 0; + if (w.width != (status >= 2 ? 24 : 0)){ + w.width = status >= 2 ? 24 : 0; + return Bangle.drawWidgets(); + } + g.reset(); + switch (status) { + case 0: + case 1: + break; + case 2: // awake + if (settings && !settings["hidewhenawake"]) g.drawImage(atob("GBiBAAAAAAAAAAAMAAA+AAAjAAEjMAGyYAGeYAzAwB5/gB4/AB4jAB4jAB4jAB4jAB//+Bv/+Bg2GB+2+B+2eB42eAAAAAAAAAAAAA=="), w.x, w.y); + break; + case 3: // light sleep + g.drawImage(atob("GBiBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAGAAAGAAAGAAAGcf/Ge//GWwBGewBmcwBn///mAABmAABmAABgAAAAAAAAAAAA=="), w.x, w.y); + break; + case 4: // deep sleep + g.drawImage(atob("GBiBAAAAAAAAAAAB4APw4APxwADh8AHAAAOAAGPwAGAAAGAAAGAAAGcf/Ge//GWwBGewBmcwBn///mAABmAABmAABgAAAAAAAAAAAA=="), w.x, w.y); + break; + } + } + }; + + setInterval(()=>{ + WIDGETS.sleepstatus.draw(WIDGETS.sleepstatus); + }, 60000); + + Bangle.drawWidgets(); +})() diff --git a/apps/widsleepstatus/widget.png b/apps/widsleepstatus/widget.png new file mode 100644 index 000000000..bb7f11f67 Binary files /dev/null and b/apps/widsleepstatus/widget.png differ diff --git a/apps/widviztime/changelog b/apps/widviztime/ChangeLog similarity index 100% rename from apps/widviztime/changelog rename to apps/widviztime/ChangeLog diff --git a/apps/wpmoto/ChangeLog b/apps/wpmoto/ChangeLog new file mode 100644 index 000000000..63f4bf24c --- /dev/null +++ b/apps/wpmoto/ChangeLog @@ -0,0 +1,4 @@ +... +0.02: First update with ChangeLog Added +0.03: Move waypoints.json (and editor) to 'waypoints' app +0.04: Added adjustment for Bangle.js magnetometer heading fix diff --git a/apps/wpmoto/app.js b/apps/wpmoto/app.js index 7deacb6ca..f08cb8279 100644 --- a/apps/wpmoto/app.js +++ b/apps/wpmoto/app.js @@ -1,6 +1,6 @@ var loc = require("locale"); -var waypoints = require("Storage").readJSON("waypoints.json") || []; +var waypoints = require("waypoints").load(); var wp = waypoints[0]; if (wp == undefined) wp = {name:"NONE"}; var wp_bearing = 0; @@ -134,7 +134,7 @@ function read_heading() { Bangle.setCompassPower(1); var d = 0; var m = Bangle.getCompass(); - if (!isNaN(m.heading)) d = -m.heading; + if (!isNaN(m.heading)) d = m.heading; heading = d; } @@ -196,7 +196,7 @@ function addCurrentWaypoint() { } function saveWaypoints() { - require("Storage").writeJSON("waypoints.json", waypoints); + require("waypoints").save(waypoints); } function deleteWaypoint(w) { diff --git a/apps/wpmoto/metadata.json b/apps/wpmoto/metadata.json index f562b23ba..32c41d757 100644 --- a/apps/wpmoto/metadata.json +++ b/apps/wpmoto/metadata.json @@ -2,17 +2,16 @@ "id": "wpmoto", "name": "Waypointer Moto", "shortName": "Waypointer Moto", - "version": "0.02", + "version": "0.04", "description": "Waypoint-based motorcycle navigation aid", "icon": "wpmoto.png", "tags": "tool,outdoors,gps", "supports": ["BANGLEJS","BANGLEJS2"], "screenshots": [{"url":"screenshot.png"},{"url":"screenshot-menu.png"},{"url":"screenshot-delete.png"}], "readme": "README.md", - "interface": "wpmoto.html", + "dependencies" : { "waypoints":"type" }, "storage": [ {"name":"wpmoto.app.js","url":"app.js"}, {"name":"wpmoto.img","url":"icon.js","evaluate":true} - ], - "data": [{"name":"waypoints.json","url":"waypoints.json"}] + ] } diff --git a/apps/wpmoto/waypoints.json b/apps/wpmoto/waypoints.json deleted file mode 100644 index 8a4ab83b8..000000000 --- a/apps/wpmoto/waypoints.json +++ /dev/null @@ -1,5 +0,0 @@ -[ - { - "name":"NONE" - }, -] diff --git a/backup.js b/backup.js index 8a894666e..06d98a366 100644 --- a/backup.js +++ b/backup.js @@ -101,6 +101,7 @@ function bangleUpload() { return Comms.showMessage(`Restoring...`); }) .then(() => Comms.write("\x10"+Comms.getProgressCmd()+"\n")) .then(() => Comms.uploadCommandList(cmds, 0, cmds.length)) + .then(() => getInstalledApps(true)) .then(() => Comms.showMessage(Const.MESSAGE_RELOAD)) .then(() => { Progress.hide({sticky:true}); diff --git a/bin/apploader.js b/bin/apploader.js index 427a0ef99..d4a5f828e 100755 --- a/bin/apploader.js +++ b/bin/apploader.js @@ -1,4 +1,4 @@ -#!/usr/bin/nodejs +#!/usr/bin/env node /* Simple Command-line app loader for Node.js =============================================== @@ -8,52 +8,46 @@ as a normal dependency) because we want `sanitycheck.js` to be able to run *quickly* in travis for every commit, and we don't want NPM pulling in (and compiling native modules) for Noble. + */ var SETTINGS = { pretokenise : true }; -var APPSDIR = __dirname+"/../apps/"; -var Utils = require("../core/js/utils.js"); -var AppInfo = require("../core/js/appinfo.js"); var noble; -try { - noble = require('@abandonware/noble'); -} catch (e) {} -if (!noble) try { - noble = require('noble'); -} catch (e) { } +["@abandonware/noble", "noble"].forEach(module => { + if (!noble) try { + noble = require(module); + } catch(e) { + if (e.code !== 'MODULE_NOT_FOUND') { + throw e; + } + } +}); if (!noble) { console.log("You need to:") console.log(" npm install @abandonware/noble") console.log("or:") console.log(" npm install noble") + process.exit(1); } - -var apps = []; - function ERROR(msg) { console.error(msg); process.exit(1); } -var apps = []; -var dirs = require("fs").readdirSync(APPSDIR, {withFileTypes: true}); -dirs.forEach(dir => { - var appsFile; - if (dir.name.startsWith("_example") || !dir.isDirectory()) - return; - try { - appsFile = require("fs").readFileSync(APPSDIR+dir.name+"/metadata.json").toString(); - } catch (e) { - ERROR(dir.name+"/metadata.json does not exist"); - return; - } - apps.push(JSON.parse(appsFile)); -}); +var deviceId = "BANGLEJS2"; +var apploader = require("./lib/apploader.js"); var args = process.argv; +var bangleParam = args.findIndex(arg => /-b\d/.test(arg)); +if (bangleParam!==-1) { + deviceId = "BANGLEJS"+args.splice(bangleParam, 1)[0][2]; +} +apploader.init({ + DEVICEID : deviceId +}); if (args.length==3 && args[2]=="list") cmdListApps(); else if (args.length==3 && args[2]=="devices") cmdListDevices(); else if (args.length==4 && args[2]=="install") cmdInstallApp(args[3]); @@ -68,13 +62,16 @@ apploader.js list - list available apps apploader.js devices - list available device addresses -apploader.js install appname [de:vi:ce:ad:dr:es] +apploader.js install [-b1] appname [de:vi:ce:ad:dr:es] + +NOTE: By default this App Loader expects the device it uploads to +(deviceId) to be BANGLEJS2, pass '-b1' for it to work with Bangle.js 1 `); process.exit(0); } function cmdListApps() { - console.log(apps.map(a=>a.id).join("\n")); + console.log(apploader.apps.map(a=>a.id).join("\n")); } function cmdListDevices() { var foundDevices = []; @@ -97,16 +94,10 @@ function cmdListDevices() { } function cmdInstallApp(appId, deviceAddress) { - var app = apps.find(a=>a.id==appId); + var app = apploader.apps.find(a=>a.id==appId); if (!app) ERROR(`App ${JSON.stringify(appId)} not found`); if (app.custom) ERROR(`App ${JSON.stringify(appId)} requires HTML customisation`); - return AppInfo.getFiles(app, { - fileGetter:function(url) { - console.log(__dirname+"/"+url); - return Promise.resolve(require("fs").readFileSync(__dirname+"/../"+url).toString("binary")); - }, settings : SETTINGS}).then(files => { - //console.log(files); - var command = files.map(f=>f.cmd).join("\n")+"\n"; + return apploader.getAppFilesString(app).then(command => { bangleSend(command, deviceAddress).then(() => process.exit(0)); }); } diff --git a/bin/create_app_supports_field.js b/bin/create_app_supports_field.js index d6aada357..24d6694f2 100644 --- a/bin/create_app_supports_field.js +++ b/bin/create_app_supports_field.js @@ -1,4 +1,4 @@ -#!/usr/bin/nodejs +#!/usr/bin/env nodejs /* Quick hack to add proper 'supports' field to apps.json */ diff --git a/bin/create_apps_json.sh b/bin/create_apps_json.sh index 30c58bc93..c9f310e57 100755 --- a/bin/create_apps_json.sh +++ b/bin/create_apps_json.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # ================================================================ # apps.json used to contain the metadata for every app. Now the # metadata is stored in each apps's directory - app/yourapp/metadata.js diff --git a/bin/firmwaremaker.js b/bin/firmwaremaker.js index 1c2d9cb77..4535c4a5e 100755 --- a/bin/firmwaremaker.js +++ b/bin/firmwaremaker.js @@ -1,17 +1,12 @@ -#!/usr/bin/nodejs +#!/usr/bin/env node /* Mashes together a bunch of different apps to make a single firmware JS file which can be uploaded. */ -var SETTINGS = { - pretokenise : true -}; - var path = require('path'); var ROOTDIR = path.join(__dirname, '..'); -var APPDIR = ROOTDIR+'/apps'; var OUTFILE = ROOTDIR+'/firmware.js'; -var DEVICE = "BANGLEJS"; +var DEVICEID = "BANGLEJS"; var APPS = [ // IDs of apps to install "boot","launch","mclock","setting", "about","alarm","widbat","widbt","welcome" @@ -19,53 +14,17 @@ var APPS = [ // IDs of apps to install var MINIFY = true; var fs = require("fs"); -global.Const = { - /* Are we only putting a single app on a device? If so - apps should all be saved as .bootcde and we write info - about the current app into app.info */ - SINGLE_APP_ONLY : false, -}; +var apploader = require("./lib/apploader.js"); +apploader.init({ + DEVICEID : DEVICEID +}); -var AppInfo = require(ROOTDIR+"/core/js/appinfo.js"); var appfiles = []; -function fileGetter(url) { - console.log("Loading "+url) - if (MINIFY) { - /*if (url.endsWith(".js")) { - var f = url.slice(0,-3); - console.log("MINIFYING "+f); - const execSync = require('child_process').execSync; - // --config PRETOKENISE=true - // --minify - code = execSync(`espruino --config SET_TIME_ON_WRITE=false --minify --board BANGLEJS ${f}.js -o ${f}.min.js`); - console.log(code.toString()); - url = f+".min.js"; - }*/ - if (url.endsWith(".json")) { - var f = url.slice(0,-5); - console.log("MINIFYING JSON "+f); - var j = eval("("+fs.readFileSync(url).toString("binary")+")"); - var code = JSON.stringify(j); - //console.log(code); - url = f+".min.json"; - fs.writeFileSync(url, code); - } - } - return Promise.resolve(fs.readFileSync(url).toString("binary")); -} - Promise.all(APPS.map(appid => { - try { - var app = JSON.parse(fs.readFileSync(APPDIR + "/" + appid + "/metadata.json").toString()); - } catch (e) { - throw new Error(`App ${appid} not found`); - } - return AppInfo.getFiles(app, { - fileGetter : fileGetter, - settings : SETTINGS, - device : { id : DEVICE } - }).then(files => { + var app = apploader.apps.find(a => a.id==appid); + if (!app) throw new Error(`App ${appid} not found`); + return apploader.getAppFiles(app).then(files => { appfiles = appfiles.concat(files); }); })).then(() => { diff --git a/bin/firmwaremaker_c.js b/bin/firmwaremaker_c.js index fd8072e06..54b63d5d9 100755 --- a/bin/firmwaremaker_c.js +++ b/bin/firmwaremaker_c.js @@ -1,4 +1,4 @@ -#!/usr/bin/node +#!/usr/bin/env node /* Mashes together a bunch of different apps into a big binary blob. We then store this *inside* the Bangle.js firmware and can use it @@ -7,29 +7,24 @@ to populate Storage initially. Bangle.js 1 doesn't really have anough flash space for this, but we have enough on v2. */ -var SETTINGS = { - pretokenise : true -}; - -var DEVICE = process.argv[2]; +var DEVICEID = process.argv[2]; var path = require('path'); +var fs = require("fs"); var ROOTDIR = path.join(__dirname, '..'); -var APPDIR = ROOTDIR+'/apps'; -var MINIFY = true; var OUTFILE, APPS; -if (DEVICE=="BANGLEJS") { +if (DEVICEID=="BANGLEJS") { var OUTFILE = path.join(ROOTDIR, '../Espruino/libs/banglejs/banglejs1_storage_default.c'); var APPS = [ // IDs of apps to install "boot","launch","mclock","setting", - "about","alarm","widbat","widbt","welcome" + "about","alarm","sched","widbat","widbt","welcome" ]; -} else if (DEVICE=="BANGLEJS2") { +} else if (DEVICEID=="BANGLEJS2") { var OUTFILE = path.join(ROOTDIR, '../Espruino/libs/banglejs/banglejs2_storage_default.c'); var APPS = [ // IDs of apps to install "boot","launch","antonclk","setting", - "about","alarm","health","widlock","widbat","widbt","widid","welcome" + "about","alarm","sched","health","widlock","widbat","widbt","widid","welcome" ]; } else { console.log("USAGE:"); @@ -37,16 +32,12 @@ if (DEVICE=="BANGLEJS") { console.log(" bin/firmwaremaker_c.js BANGLEJS2"); process.exit(1); } -console.log("Device = ",DEVICE); +console.log("Device = ",DEVICEID); - -var fs = require("fs"); -global.Const = { - /* Are we only putting a single app on a device? If so - apps should all be saved as .bootcde and we write info - about the current app into app.info */ - SINGLE_APP_ONLY : false, -}; +var apploader = require("./lib/apploader.js"); +apploader.init({ + DEVICEID : DEVICEID +}); function atob(input) { @@ -84,37 +75,14 @@ function atob(input) { return new Uint8Array(output); } -var AppInfo = require(ROOTDIR+"/core/js/appinfo.js"); var appfiles = []; -function fileGetter(url) { - console.log("Loading "+url) - if (MINIFY) { - if (url.endsWith(".json")) { - var f = url.slice(0,-5); - console.log("MINIFYING JSON "+f); - var j = eval("("+fs.readFileSync(url).toString("binary")+")"); - var code = JSON.stringify(j); - //console.log(code); - url = f+".min.json"; - fs.writeFileSync(url, code); - } - } - var blob = fs.readFileSync(url); - var data; - if (url.endsWith(".js") || url.endsWith(".json")) - data = blob.toString(); // allow JS/etc to be written in UTF-8 - else - data = blob.toString("binary") - return Promise.resolve(data); -} - // If file should be evaluated, try and do it... function evaluateFile(file) { var hsStart = 'require("heatshrink").decompress(atob("'; var hsEnd = '"))'; if (file.content.startsWith(hsStart) && file.content.endsWith(hsEnd)) { - var heatshrink = require(ROOTDIR+"/core/lib/heatshrink.js"); + var heatshrink = require(ROOTDIR+"/webtools/heatshrink.js"); var b64 = file.content.slice(hsStart.length, -hsEnd.length); var decompressed = heatshrink.decompress(atob(b64)); file.content = ""; @@ -132,16 +100,9 @@ function evaluateFile(file) { } Promise.all(APPS.map(appid => { - try { - var app = JSON.parse(fs.readFileSync(APPDIR + "/" + appid + "/metadata.json").toString()); - } catch (e) { - throw new Error(`App ${appid} not found`); - } - return AppInfo.getFiles(app, { - fileGetter : fileGetter, - settings : SETTINGS, - device : { id : DEVICE } - }).then(files => { + var app = apploader.apps.find(a => a.id==appid); + if (!app) throw new Error(`App ${appid} not found`); + return apploader.getAppFiles(app).then(files => { appfiles = appfiles.concat(files); }); })).then(() => { @@ -172,7 +133,7 @@ Promise.all(APPS.map(appid => { // Generated by BangleApps/bin/build_bangles_c.js const int jsfStorageInitialContentLength = ${storageContent.length}; -const char jsfStorageInitialContents[] = { +const unsigned char jsfStorageInitialContents[] = { `; for (var i=0;i { + var appsFile; + if (dir.name.startsWith("_example") || !dir.isDirectory()) + return; + try { + appsFile = require("fs").readFileSync(APPSDIR+dir.name+"/metadata.json").toString(); + } catch (e) { + ERROR(dir.name+"/metadata.json does not exist"); + return; + } + apps.push(JSON.parse(appsFile)); + }); +}; + +exports.AppInfo = AppInfo; +exports.apps = apps; + +// used by getAppFiles +function fileGetter(url) { + url = BASE_DIR+"/"+url; + console.log("Loading "+url) + var data; + if (MINIFY && url.endsWith(".json")) { + var f = url.slice(0,-5); + console.log("MINIFYING JSON "+f); + var j = eval("("+require("fs").readFileSync(url).toString("binary")+")"); + data = JSON.stringify(j); + } else { + var blob = require("fs").readFileSync(url); + if (url.endsWith(".js") || url.endsWith(".json")) + data = blob.toString(); // allow JS/etc to be written in UTF-8 + else + data = blob.toString("binary") + } + return Promise.resolve(data); +} + +exports.getAppFiles = function(app) { + return AppInfo.getFiles(app, { + fileGetter:fileGetter, + settings : SETTINGS, + device : { id : DEVICEID } + }); +}; + +// Get all the files for this app as a string of Storage.write commands +exports.getAppFilesString = function(app) { + return exports.getAppFiles(app).then(files => { + return files.map(f=>f.cmd).join("\n")+"\n" + }) +}; diff --git a/bin/lib/emulator.js b/bin/lib/emulator.js new file mode 100644 index 000000000..f7c82ec3c --- /dev/null +++ b/bin/lib/emulator.js @@ -0,0 +1,115 @@ +/* Node.js library with utilities to handle using the emulator from node.js */ + +var EMULATOR = "banglejs2"; +var DEVICEID = "BANGLEJS2"; + +var BASE_DIR = __dirname + "/../.."; +var DIR_IDE = BASE_DIR + "/../EspruinoWebIDE"; + +/* we factory reset ONCE, get this, then we can use it to reset +state quickly for each new app */ +var factoryFlashMemory; + +// Log of messages from app +var appLog = ""; +var lastOutputLine = ""; + +function onConsoleOutput(txt) { + appLog += txt + "\n"; + lastOutputLine = txt; +} + +exports.init = function(options) { + if (options.EMULATOR) + EMULATOR = options.EMULATOR; + if (options.DEVICEID) + DEVICEID = options.DEVICEID; + + eval(require("fs").readFileSync(DIR_IDE + "/emu/emulator_"+EMULATOR+".js").toString()); + eval(require("fs").readFileSync(DIR_IDE + "/emu/emu_"+EMULATOR+".js").toString()); + eval(require("fs").readFileSync(DIR_IDE + "/emu/common.js").toString()/*.replace('console.log("EMSCRIPTEN:"', '//console.log("EMSCRIPTEN:"')*/); + + jsRXCallback = function() {}; + jsUpdateGfx = function() {}; + + factoryFlashMemory = new Uint8Array(FLASH_SIZE); + factoryFlashMemory.fill(255); + + exports.flashMemory = flashMemory; + exports.GFX_WIDTH = GFX_WIDTH; + exports.GFX_HEIGHT = GFX_HEIGHT; + exports.tx = jsTransmitString; + exports.idle = jsIdle; + exports.stopIdle = jsStopIdle; + exports.getGfxContents = jsGetGfxContents; + + return new Promise(resolve => { + setTimeout(function() { + console.log("Emulator Loaded..."); + jsInit(); + jsIdle(); + console.log("Emulator Factory reset"); + exports.tx("Bangle.factoryReset()\n"); + factoryFlashMemory.set(flashMemory); + console.log("Emulator Ready!"); + + resolve(); + },0); + }); +}; + +// Factory reset +exports.factoryReset = function() { + exports.flashMemory.set(factoryFlashMemory); + exports.tx("reset()\n"); + appLog=""; +}; + +// Transmit a string +exports.tx = function() {}; // placeholder +exports.idle = function() {}; // placeholder +exports.stopIdle = function() {}; // placeholder +exports.getGfxContents = function() {}; // placeholder + +exports.flashMemory = undefined; // placeholder +exports.GFX_WIDTH = undefined; // placeholder +exports.GFX_HEIGHT = undefined; // placeholder + +// Get last line sent to console +exports.getLastLine = function() { + return lastOutputLine; +}; + +// Gets the screenshot as RGBA Uint32Array +exports.getScreenshot = function() { + var rgba = new Uint8Array(exports.GFX_WIDTH*exports.GFX_HEIGHT*4); + exports.getGfxContents(rgba); + var rgba32 = new Uint32Array(rgba.buffer); + return rgba32; +} + +// Write the screenshot to a file options={errorIfBlank} +exports.writeScreenshot = function(imageFn, options) { + options = options||{}; + return new Promise((resolve,reject) => { + var rgba32 = exports.getScreenshot(); + + if (options.errorIfBlank) { + var firstPixel = rgba32[0]; + var blankImage = rgba32.every(col=>col==firstPixel); + if (blankImage) reject("Image is blank"); + } + + var Jimp = require("jimp"); + let image = new Jimp(exports.GFX_WIDTH, exports.GFX_HEIGHT, function (err, image) { + if (err) throw err; + let buffer = image.bitmap.data; + buffer.set(new Uint8Array(rgba32.buffer)); + image.write(imageFn, (err) => { + if (err) return reject(err); + console.log("Image written as "+imageFn); + resolve(); + }); + }); + }); +} diff --git a/bin/pre-publish.sh b/bin/pre-publish.sh index ee73968d7..710160ded 100755 --- a/bin/pre-publish.sh +++ b/bin/pre-publish.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash cd `dirname $0`/.. nodejs bin/sanitycheck.js || exit 1 diff --git a/bin/runapptests.js b/bin/runapptests.js new file mode 100755 index 000000000..8a415b109 --- /dev/null +++ b/bin/runapptests.js @@ -0,0 +1,138 @@ +#!/usr/bin/node +/* + +This allows us to test apps using the Bangle.js emulator + +IT IS UNFINISHED + +It searches for `test.json` in each app's directory and will +run them in sequence. + +TODO: + +* more code to test with +* run tests that we have found and loaded (currently we just use TEST) +* documentation +* actual tests +* detecting 'Uncaught Error' +* logging of success/fail +* ... + +*/ + +// A si +var TEST = { + app : "android", + tests : [ { + load : "messagesgui.app.js", + steps : [ + {t:"gb", "obj":{"t":"notify","id":1234,"src":"Twitter","title":"A Name","body":"message contents"}}, + {t:"cmd", "js":"X='hello';"}, + {t:"eval", "js":"X", eq:"hello"} + ] + }] +}; + +var EMULATOR = "banglejs2"; +var DEVICEID = "BANGLEJS2"; + +var BASE_DIR = __dirname + "/.."; +var APP_DIR = BASE_DIR + "/apps"; +var DIR_IDE = BASE_DIR + "/../EspruinoWebIDE"; + + +if (!require("fs").existsSync(DIR_IDE)) { + console.log("You need to:"); + console.log(" git clone https://github.com/espruino/EspruinoWebIDE"); + console.log("At the same level as this project"); + process.exit(1); +} + +var apploader = require(BASE_DIR+"/bin/lib/apploader.js"); +apploader.init({ + DEVICEID : DEVICEID +}); +var emu = require(BASE_DIR+"/bin/lib/emulator.js"); + +// Last set of text received +var lastTxt; + +function ERROR(s) { + console.error(s); + process.exit(1); +} + +function runTest(test) { + var app = apploader.apps.find(a=>a.id==test.app); + if (!app) ERROR(`App ${JSON.stringify(test.app)} not found`); + if (app.custom) ERROR(`App ${JSON.stringify(appId)} requires HTML customisation`); + return apploader.getAppFilesString(app).then(command => { + // What about dependencies?? + test.tests.forEach((subtest,subtestIdx) => { + console.log(`==============================`); + console.log(`"${test.app}" Test ${subtestIdx}`); + console.log(`==============================`); + emu.factoryReset(); + console.log("Sending app "+test.app); + emu.tx(command); + console.log("Sent app"); + emu.tx(test.load ? `load(${JSON.stringify(test.load)})\n` : "load()\n"); + console.log("App Loaded."); + var ok = true; + subtest.steps.forEach(step => { + if (ok) switch(step.t) { + case "cmd" : emu.tx(`${step.js}\n`); break; + case "gb" : emu.tx(`GB(${JSON.stringify(step.obj)})\n`); break; + case "tap" : emu.tx(`Bangle.emit(...)\n`); break; + case "eval" : + emu.tx(`\x10print(JSON.stringify(${step.js}))\n`); + var result = emu.getLastLine(); + var expected = JSON.stringify(step.eq); + console.log("GOT "+result); + if (result!=expected) { + console.log("EXPECTED "+expected); + ok = false; + } + break; + // tap/touch/drag/button press + // delay X milliseconds? + case "screenshot" : + console.log("Compare screenshots"); + break; + default: ERROR("Unknown step type "+step.t); + } + }); + }); + emu.stopIdle(); + }); +} + + +emu.init({ + EMULATOR : EMULATOR, + DEVICEID : DEVICEID +}).then(function() { + // Emulator is now loaded + console.log("Loading tests"); + var tests = []; + apploader.apps.forEach(app => { + var testFile = APP_DIR+"/"+app.id+"/test.json"; + if (!require("fs").existsSync(testFile)) return; + var test = JSON.parse(require("fs").readFileSync(testFile).toString()); + test.app = app.id; + tests.push(test); + }); + // Running tests + runTest(TEST); +}); +/* + if (erroredApps.length) { + erroredApps.forEach(app => { + console.log(`::error file=${app.id}::${app.id}`); + console.log("::group::Log"); + app.log.split("\n").forEach(line => console.log(`\u001b[38;2;255;0;0m${line}`)); + console.log("::endgroup::"); + }); + process.exit(1); + } +*/ diff --git a/bin/sanitycheck.js b/bin/sanitycheck.js index 81c0f75ac..82b2896b8 100755 --- a/bin/sanitycheck.js +++ b/bin/sanitycheck.js @@ -1,9 +1,9 @@ -#!/usr/bin/node +#!/usr/bin/env node /* Checks for any obvious problems in apps.json */ var fs = require("fs"); -var heatshrink = require("../core/lib/heatshrink"); +var heatshrink = require("../webtools/heatshrink"); var acorn; try { acorn = require("acorn"); @@ -17,13 +17,25 @@ try { } var BASEDIR = __dirname+"/../"; -var APPSDIR = BASEDIR+"apps/"; -function ERROR(s) { - console.error("ERROR: "+s); - process.exit(1); +var APPSDIR_RELATIVE = "apps/"; +var APPSDIR = BASEDIR + APPSDIR_RELATIVE; +var warningCount = 0; +var errorCount = 0; +function ERROR(msg, opt) { + // file=app.js,line=1,col=5,endColumn=7 + opt = opt||{}; + console.log(`::error${Object.keys(opt).length?" ":""}${Object.keys(opt).map(k=>k+"="+opt[k]).join(",")}::${msg}`); + errorCount++; } -function WARN(s) { - console.log("Warning: "+s); +function WARN(msg, opt) { + // file=app.js,line=1,col=5,endColumn=7 + opt = opt||{}; + if (KNOWN_WARNINGS.includes(msg)) { + console.log(`Known warning : ${msg}`); + } else { + console.log(`::warning${Object.keys(opt).length?" ":""}${Object.keys(opt).map(k=>k+"="+opt[k]).join(",")}::${msg}`); + } + warningCount++; } var apps = []; @@ -43,16 +55,20 @@ dirs.forEach(dir => { } catch (e) { console.log(e); var m = e.toString().match(/in JSON at position (\d+)/); + var messageInfo = { + file : "apps/"+dir.name+"/metadata.json", + }; if (m) { var char = parseInt(m[1]); + messageInfo.line = appsFile.substr(0,char).split("\n").length; console.log("==============================================="); - console.log("LINE "+appsFile.substr(0,char).split("\n").length); + console.log("LINE "+messageInfo.line); console.log("==============================================="); console.log(appsFile.substr(char-10, 20)); console.log("==============================================="); } console.log(m); - ERROR(dir.name+"/metadata.json not valid JSON"); + ERROR(messageInfo.file+" not valid JSON", messageInfo); } }); @@ -60,15 +76,26 @@ const APP_KEYS = [ 'id', 'name', 'shortName', 'version', 'icon', 'screenshots', 'description', 'tags', 'type', 'sortorder', 'readme', 'custom', 'customConnect', 'interface', 'storage', 'data', 'supports', 'allow_emulator', - 'dependencies' + 'dependencies', 'provides_modules', 'provides_widgets', "default" ]; -const STORAGE_KEYS = ['name', 'url', 'content', 'evaluate', 'noOverwite', 'supports']; +const STORAGE_KEYS = ['name', 'url', 'content', 'evaluate', 'noOverwite', 'supports', 'noOverwrite']; const DATA_KEYS = ['name', 'wildcard', 'storageFile', 'url', 'content', 'evaluate']; const SUPPORTS_DEVICES = ["BANGLEJS","BANGLEJS2"]; // device IDs allowed for 'supports' -const METADATA_TYPES = ["app","clock","widget","bootloader","RAM","launch","textinput","scheduler","notify","locale","settings"]; // values allowed for "type" field +const METADATA_TYPES = ["app","clock","widget","bootloader","RAM","launch","scheduler","notify","locale","settings","waypoints","textinput","module","clkinfo"]; // values allowed for "type" field const FORBIDDEN_FILE_NAME_CHARS = /[,;]/; // used as separators in appid.info const VALID_DUPLICATES = [ '.tfmodel', '.tfnames' ]; const GRANDFATHERED_ICONS = ["s7clk", "snek", "astral", "alpinenav", "slomoclock", "arrow", "pebble", "rebble"]; +const INTERNAL_FILES_IN_APP_TYPE = { // list of app types and files they SHOULD provide... + 'textinput' : ['textinput'], + 'waypoints' : ['waypoints'], + // notify? +}; +/* These are warnings we know about but don't want in our output */ +var KNOWN_WARNINGS = [ +"App gpsrec data file wildcard .gpsrc? does not include app ID", +"App owmweather data file weather.json is also listed as data file for app weather", + "App messagegui storage file messagegui is also listed as storage file for app messagelist", +]; function globToRegex(pattern) { const ESCAPE = '.*+-?^${}()|[]\\'; @@ -87,87 +114,98 @@ let allFiles = []; let existingApps = []; apps.forEach((app,appIdx) => { if (!app.id) ERROR(`App ${appIdx} has no id`); - if (existingApps.includes(app.id)) ERROR(`Duplicate app '${app.id}'`); + var appDirRelative = APPSDIR_RELATIVE+app.id+"/"; + var appDir = APPSDIR+app.id+"/"; + var metadataFile = appDirRelative+"metadata.json"; + if (existingApps.includes(app.id)) ERROR(`Duplicate app '${app.id}'`, {file:metadataFile}); existingApps.push(app.id); //console.log(`Checking ${app.id}...`); - var appDir = APPSDIR+app.id+"/"; + if (!fs.existsSync(APPSDIR+app.id)) ERROR(`App ${app.id} has no directory`); - if (!app.name) ERROR(`App ${app.id} has no name`); + if (!app.name) ERROR(`App ${app.id} has no name`, {file:metadataFile}); var isApp = !app.type || app.type=="app"; - if (app.name.length>20 && !app.shortName && isApp) ERROR(`App ${app.id} has a long name, but no shortName`); + if (app.name.length>20 && !app.shortName && isApp) ERROR(`App ${app.id} has a long name, but no shortName`, {file:metadataFile}); if (app.type && !METADATA_TYPES.includes(app.type)) - ERROR(`App ${app.id} 'type' is one one of `+METADATA_TYPES); - if (!Array.isArray(app.supports)) ERROR(`App ${app.id} has no 'supports' field or it's not an array`); + ERROR(`App ${app.id} 'type' is one one of `+METADATA_TYPES, {file:metadataFile}); + if (!Array.isArray(app.supports)) ERROR(`App ${app.id} has no 'supports' field or it's not an array`, {file:metadataFile}); else { app.supports.forEach(dev => { if (!SUPPORTS_DEVICES.includes(dev)) - ERROR(`App ${app.id} has unknown device in 'supports' field - ${dev}`); + ERROR(`App ${app.id} has unknown device in 'supports' field - ${dev}`, {file:metadataFile}); }); } - if (!app.version) WARN(`App ${app.id} has no version`); + if (!app.version) ERROR(`App ${app.id} has no version`, {file:metadataFile}); else { if (!fs.existsSync(appDir+"ChangeLog")) { - if (app.version != "0.01") - WARN(`App ${app.id} has no ChangeLog`); + var invalidChangeLog = fs.readdirSync(appDir).find(f => f.toLowerCase().startsWith("changelog") && f!="ChangeLog"); + if (invalidChangeLog) + ERROR(`App ${app.id} has wrongly named ChangeLog (${invalidChangeLog})`, {file:appDirRelative+invalidChangeLog}); + else if (app.version != "0.01") + WARN(`App ${app.id} has no ChangeLog`, {file:metadataFile}); } else { var changeLog = fs.readFileSync(appDir+"ChangeLog").toString(); var versions = changeLog.match(/\d+\.\d+:/g); - if (!versions) ERROR(`No versions found in ${app.id} ChangeLog (${appDir}ChangeLog)`); + if (!versions) ERROR(`No versions found in ${app.id} ChangeLog (${appDir}ChangeLog)`, {file:metadataFile}); var lastChangeLog = versions.pop().slice(0,-1); if (lastChangeLog != app.version) - WARN(`App ${app.id} app version (${app.version}) and ChangeLog (${lastChangeLog}) don't agree`); + ERROR(`App ${app.id} app version (${app.version}) and ChangeLog (${lastChangeLog}) don't agree`, {file:appDirRelative+"ChangeLog", line:changeLog.split("\n").length-1}); } } - if (!app.description) ERROR(`App ${app.id} has no description`); - if (!app.icon) ERROR(`App ${app.id} has no icon`); - if (!fs.existsSync(appDir+app.icon)) ERROR(`App ${app.id} icon doesn't exist`); + if (!app.description) ERROR(`App ${app.id} has no description`, {file:metadataFile}); + if (!app.icon) ERROR(`App ${app.id} has no icon`, {file:metadataFile}); + if (!fs.existsSync(appDir+app.icon)) ERROR(`App ${app.id} icon doesn't exist`, {file:metadataFile}); if (app.screenshots) { - if (!Array.isArray(app.screenshots)) ERROR(`App ${app.id} screenshots is not an array`); + if (!Array.isArray(app.screenshots)) ERROR(`App ${app.id} screenshots is not an array`, {file:metadataFile}); app.screenshots.forEach(screenshot => { if (!fs.existsSync(appDir+screenshot.url)) - ERROR(`App ${app.id} screenshot file ${screenshot.url} not found`); + ERROR(`App ${app.id} screenshot file ${screenshot.url} not found`, {file:metadataFile}); }); } - if (app.readme && !fs.existsSync(appDir+app.readme)) ERROR(`App ${app.id} README file doesn't exist`); - if (app.custom && !fs.existsSync(appDir+app.custom)) ERROR(`App ${app.id} custom HTML doesn't exist`); - if (app.customConnect && !app.custom) ERROR(`App ${app.id} has customConnect but no customn HTML`); - if (app.interface && !fs.existsSync(appDir+app.interface)) ERROR(`App ${app.id} interface HTML doesn't exist`); + if (app.readme && !fs.existsSync(appDir+app.readme)) ERROR(`App ${app.id} README file doesn't exist`, {file:metadataFile}); + if (app.custom && !fs.existsSync(appDir+app.custom)) ERROR(`App ${app.id} custom HTML doesn't exist`, {file:metadataFile}); + if (app.customConnect && !app.custom) ERROR(`App ${app.id} has customConnect but no customn HTML`, {file:metadataFile}); + if (app.interface && !fs.existsSync(appDir+app.interface)) ERROR(`App ${app.id} interface HTML doesn't exist`, {file:metadataFile}); if (app.dependencies) { if (("object"==typeof app.dependencies) && !Array.isArray(app.dependencies)) { Object.keys(app.dependencies).forEach(dependency => { - if (!["type","app"].includes(app.dependencies[dependency])) - ERROR(`App ${app.id} 'dependencies' must all be tagged 'type' or 'app' right now`); + if (!["type","app","module","widget"].includes(app.dependencies[dependency])) + ERROR(`App ${app.id} 'dependencies' must all be tagged 'type/app/module/widget' right now`, {file:metadataFile}); if (app.dependencies[dependency]=="type" && !METADATA_TYPES.includes(dependency)) - ERROR(`App ${app.id} 'type' dependency must be one of `+METADATA_TYPES); - + ERROR(`App ${app.id} 'type' dependency must be one of `+METADATA_TYPES, {file:metadataFile}); }); } else - ERROR(`App ${app.id} 'dependencies' must be an object`); + ERROR(`App ${app.id} 'dependencies' must be an object`, {file:metadataFile}); } + var fileNames = []; app.storage.forEach((file) => { - if (!file.name) ERROR(`App ${app.id} has a file with no name`); - if (isGlob(file.name)) ERROR(`App ${app.id} storage file ${file.name} contains wildcards`); + if (!file.name) ERROR(`App ${app.id} has a file with no name`, {file:metadataFile}); + if (isGlob(file.name)) ERROR(`App ${app.id} storage file ${file.name} contains wildcards`, {file:metadataFile}); let char = file.name.match(FORBIDDEN_FILE_NAME_CHARS) - if (char) ERROR(`App ${app.id} storage file ${file.name} contains invalid character "${char[0]}"`) + if (char) ERROR(`App ${app.id} storage file ${file.name} contains invalid character "${char[0]}"`, {file:metadataFile}) if (fileNames.includes(file.name) && !file.supports) // assume that there aren't duplicates if 'supports' is set - ERROR(`App ${app.id} file ${file.name} is a duplicate`); + ERROR(`App ${app.id} file ${file.name} is a duplicate`, {file:metadataFile}); if (file.supports && !Array.isArray(file.supports)) - ERROR(`App ${app.id} file ${file.name} supports field must be an array`); + ERROR(`App ${app.id} file ${file.name} supports field must be an array`, {file:metadataFile}); if (file.supports) file.supports.forEach(dev => { if (!SUPPORTS_DEVICES.includes(dev)) - ERROR(`App ${app.id} file ${file.name} has unknown device in 'supports' field - ${dev}`); + ERROR(`App ${app.id} file ${file.name} has unknown device in 'supports' field - ${dev}`, {file:metadataFile}); }); fileNames.push(file.name); - allFiles.push({app: app.id, file: file.name}); - if (file.url) if (!fs.existsSync(appDir+file.url)) ERROR(`App ${app.id} file ${file.url} doesn't exist`); - if (!file.url && !file.content && !app.custom) ERROR(`App ${app.id} file ${file.name} has no contents`); + var fileInternal = false; + if (app.type && INTERNAL_FILES_IN_APP_TYPE[app.type]) { + if (INTERNAL_FILES_IN_APP_TYPE[app.type].includes(file.name)) + fileInternal = true; + } + allFiles.push({app: app.id, file: file.name, internal:fileInternal}); + if (file.url) if (!fs.existsSync(appDir+file.url)) ERROR(`App ${app.id} file ${file.url} doesn't exist`, {file:metadataFile}); + if (!file.url && !file.content && !app.custom) ERROR(`App ${app.id} file ${file.name} has no contents`, {file:metadataFile}); var fileContents = ""; if (file.content) fileContents = file.content; if (file.url) fileContents = fs.readFileSync(appDir+file.url).toString(); - if (file.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`); + if (file.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`, {file:metadataFile}); if (file.evaluate) { try { acorn.parse("("+fileContents+")"); @@ -179,7 +217,7 @@ apps.forEach((app,appIdx) => { console.log("====================================================="); console.log(fileContents); console.log("====================================================="); - ERROR(`App ${app.id}'s ${file.name} has evaluate:true but is not valid JS expression`); + ERROR(`App ${app.id}'s ${file.name} has evaluate:true but is not valid JS expression`, {file:appDirRelative+file.url}); } } if (file.name.endsWith(".js")) { @@ -194,14 +232,21 @@ apps.forEach((app,appIdx) => { console.log("====================================================="); console.log(fileContents); console.log("====================================================="); - ERROR(`App ${app.id}'s ${file.name} is a JS file but isn't valid JS`); + ERROR(`App ${app.id}'s ${file.name} is a JS file but isn't valid JS`, {file:appDirRelative+file.url}); + } + // clock app checks + if (app.type=="clock") { + var a = fileContents.indexOf("Bangle.loadWidgets()"); + var b = fileContents.indexOf("Bangle.setUI("); + if (a>=0 && b>=0 && a { else { match = fileContents.match(/^\s*require\(\"heatshrink\"\)\.decompress\(\s*atob\(\s*\"([^"]*)\"\s*\)\s*\)\s*$/); if (match) icon = heatshrink.decompress(Buffer.from(match[1], 'base64')); - else ERROR(`JS icon ${file.name} does not match the pattern 'require("heatshrink").decompress(atob("..."))'`); + else ERROR(`JS icon ${file.name} does not match the pattern 'require("heatshrink").decompress(atob("..."))'`, {file:appDirRelative+file.url}); } if (match) { if (icon[0] > 48 || icon[0] < 24 || icon[1] > 48 || icon[1] < 24) { - if (GRANDFATHERED_ICONS.includes(app.id)) WARN(`JS icon ${file.name} should be 48x48px (or slightly under) but is instead ${icon[0]}x${icon[1]}px`); - else ERROR(`JS icon ${file.name} should be 48x48px (or slightly under) but is instead ${icon[0]}x${icon[1]}px`); + if (GRANDFATHERED_ICONS.includes(app.id)) WARN(`JS icon ${file.name} should be 48x48px (or slightly under) but is instead ${icon[0]}x${icon[1]}px`, {file:appDirRelative+file.url}); + else ERROR(`JS icon ${file.name} should be 48x48px (or slightly under) but is instead ${icon[0]}x${icon[1]}px`, {file:appDirRelative+file.url}); } } } }); let dataNames = []; (app.data||[]).forEach((data)=>{ - if (!data.name && !data.wildcard) ERROR(`App ${app.id} has a data file with no name`); + if (!data.name && !data.wildcard) ERROR(`App ${app.id} has a data file with no name`, {file:metadataFile}); if (dataNames.includes(data.name||data.wildcard)) - ERROR(`App ${app.id} data file ${data.name||data.wildcard} is a duplicate`); + ERROR(`App ${app.id} data file ${data.name||data.wildcard} is a duplicate`, {file:metadataFile}); dataNames.push(data.name||data.wildcard) allFiles.push({app: app.id, data: (data.name||data.wildcard)}); if ('name' in data && 'wildcard' in data) - ERROR(`App ${app.id} data file ${data.name} has both name and wildcard`); + ERROR(`App ${app.id} data file ${data.name} has both name and wildcard`, {file:metadataFile}); if (isGlob(data.name)) - ERROR(`App ${app.id} data file name ${data.name} contains wildcards`); + ERROR(`App ${app.id} data file name ${data.name} contains wildcards`, {file:metadataFile}); if (data.wildcard) { if (!isGlob(data.wildcard)) - ERROR(`App ${app.id} data file wildcard ${data.wildcard} does not actually contains wildcard`); + ERROR(`App ${app.id} data file wildcard ${data.wildcard} does not actually contains wildcard`, {file:metadataFile}); if (data.wildcard.replace(/\?|\*/g,'') === '') - ERROR(`App ${app.id} data file wildcard ${data.wildcard} does not contain regular characters`); + ERROR(`App ${app.id} data file wildcard ${data.wildcard} does not contain regular characters`, {file:metadataFile}); else if (data.wildcard.replace(/\?|\*/g,'').length < 3) - WARN(`App ${app.id} data file wildcard ${data.wildcard} is very broad`); + WARN(`App ${app.id} data file wildcard ${data.wildcard} is very broad`, {file:metadataFile}); else if (!data.wildcard.includes(app.id)) - WARN(`App ${app.id} data file wildcard ${data.wildcard} does not include app ID`); + WARN(`App ${app.id} data file wildcard ${data.wildcard} does not include app ID`, {file:metadataFile}); } let char = (data.name||data.wildcard).match(FORBIDDEN_FILE_NAME_CHARS) - if (char) ERROR(`App ${app.id} data file ${data.name||data.wildcard} contains invalid character "${char[0]}"`) + if (char) ERROR(`App ${app.id} data file ${data.name||data.wildcard} contains invalid character "${char[0]}"`, {file:metadataFile}) if ('storageFile' in data && typeof data.storageFile !== 'boolean') - ERROR(`App ${app.id} data file ${data.name||data.wildcard} has non-boolean value for "storageFile"`); + ERROR(`App ${app.id} data file ${data.name||data.wildcard} has non-boolean value for "storageFile"`, {file:metadataFile}); for (const key in data) { if (!DATA_KEYS.includes(key)) - ERROR(`App ${app.id} data file ${data.name||data.wildcard} has unknown property "${key}"`); + ERROR(`App ${app.id} data file ${data.name||data.wildcard} has unknown property "${key}"`, {file:metadataFile}); } }); // prefer "appid.json" over "appid.settings.json" (TODO: change to ERROR once all apps comply?) @@ -256,32 +301,50 @@ apps.forEach((app,appIdx) => { WARN(`App ${app.id} uses data file ${app.id+'.settings.json'}`)*/ // settings files should be listed under data, not storage (TODO: change to ERROR once all apps comply?) if (fileNames.includes(app.id+".settings.json")) - WARN(`App ${app.id} uses storage file ${app.id+'.settings.json'} instead of data file`) + WARN(`App ${app.id} uses storage file ${app.id+'.settings.json'} instead of data file`, {file:metadataFile}) if (fileNames.includes(app.id+".json")) - WARN(`App ${app.id} uses storage file ${app.id+'.json'} instead of data file`) + WARN(`App ${app.id} uses storage file ${app.id+'.json'} instead of data file`, {file:metadataFile}) // warn if storage file matches data file of same app dataNames.forEach(dataName=>{ const glob = globToRegex(dataName) fileNames.forEach(fileName=>{ if (glob.test(fileName)) { - if (isGlob(dataName)) WARN(`App ${app.id} storage file ${fileName} matches data wildcard ${dataName}`) - else WARN(`App ${app.id} storage file ${fileName} is also listed in data`) + if (isGlob(dataName)) WARN(`App ${app.id} storage file ${fileName} matches data wildcard ${dataName}`, {file:metadataFile}) + else WARN(`App ${app.id} storage file ${fileName} is also listed in data`, {file:metadataFile}) } }) }) //console.log(fileNames); - if (isApp && !fileNames.includes(app.id+".app.js")) ERROR(`App ${app.id} has no entrypoint`); - if (isApp && !fileNames.includes(app.id+".img")) ERROR(`App ${app.id} has no JS icon`); - if (app.type=="widget" && !fileNames.includes(app.id+".wid.js")) ERROR(`Widget ${app.id} has no entrypoint`); + if (isApp && !fileNames.includes(app.id+".app.js")) ERROR(`App ${app.id} has no entrypoint`, {file:metadataFile}); + if (isApp && !fileNames.includes(app.id+".img")) ERROR(`App ${app.id} has no JS icon`, {file:metadataFile}); + if (app.type=="widget" && !fileNames.includes(app.id+".wid.js")) ERROR(`Widget ${app.id} has no entrypoint`, {file:metadataFile}); for (const key in app) { - if (!APP_KEYS.includes(key)) ERROR(`App ${app.id} has unknown key ${key}`); + if (!APP_KEYS.includes(key)) ERROR(`App ${app.id} has unknown key ${key}`, {file:metadataFile}); + } + if (app.type && INTERNAL_FILES_IN_APP_TYPE[app.type]) { + INTERNAL_FILES_IN_APP_TYPE[app.type].forEach(fileName => { + if (!fileNames.includes(fileName)) + ERROR(`App ${app.id} should include file named ${fileName} but it doesn't`, {file:metadataFile}); + }); + } + if (app.type=="module" && !app.provides_modules) { + ERROR(`App ${app.id} has type:module but it doesn't have a provides_modules field`, {file:metadataFile}); + } + if (app.provides_modules) { + app.provides_modules.forEach(modulename => { + if (!app.storage.find(s=>s.name==modulename)) + ERROR(`App ${app.id} has provides_modules ${modulename} but it doesn't provide that filename`, {file:metadataFile}); + }); } }); + + // Do not allow files from different apps to collide let fileA + while(fileA=allFiles.pop()) { if (VALID_DUPLICATES.includes(fileA.file)) - return; + break; const nameA = (fileA.file||fileA.data), globA = globToRegex(nameA), typeA = fileA.file?'storage':'data' @@ -291,9 +354,16 @@ while(fileA=allFiles.pop()) { typeB = fileB.file?'storage':'data' if (globA.test(nameB)||globB.test(nameA)) { if (isGlob(nameA)||isGlob(nameB)) - ERROR(`App ${fileB.app} ${typeB} file ${nameB} matches app ${fileA.app} ${typeB} file ${nameA}`) - else if (fileA.app != fileB.app) - WARN(`App ${fileB.app} ${typeB} file ${nameB} is also listed as ${typeA} file for app ${fileA.app}`) + ERROR(`App ${fileB.app} ${typeB} file ${nameB} matches app ${fileA.app} ${typeB} file ${nameA}`); + else if (fileA.app != fileB.app && (!fileA.internal) && (!fileB.internal)) + WARN(`App ${fileB.app} ${typeB} file ${nameB} is also listed as ${typeA} file for app ${fileA.app}`); } }) } + +console.log("=================================="); +console.log(`${errorCount} errors, ${warningCount} warnings`); +console.log("=================================="); +if (errorCount) { + process.exit(1); +} diff --git a/bin/thumbnailer.js b/bin/thumbnailer.js index b6862741a..22cdc27a5 100755 --- a/bin/thumbnailer.js +++ b/bin/thumbnailer.js @@ -1,4 +1,4 @@ -#!/usr/bin/node +#!/usr/bin/env node /* var EMULATOR = "banglejs2"; @@ -6,6 +6,10 @@ var DEVICEID = "BANGLEJS2"; */ var EMULATOR = "banglejs1"; var DEVICEID = "BANGLEJS"; +var SCREENSHOT_DIR = __dirname+"/../screenshots/"; + +var emu = require("./lib/emulator.js"); +var apploader = require("./lib/apploader.js"); var singleAppId; @@ -20,128 +24,66 @@ if (process.argv.length!=3 && process.argv.length!=2) { if (process.argv.length==3) singleAppId = process.argv[2]; -if (!require("fs").existsSync(__dirname + "/../../EspruinoWebIDE")) { - console.log("You need to:"); - console.log(" git clone https://github.com/espruino/EspruinoWebIDE"); - console.log("At the same level as this project"); - process.exit(1); -} - -eval(require("fs").readFileSync(__dirname + "/../../EspruinoWebIDE/emu/emulator_"+EMULATOR+".js").toString()); -eval(require("fs").readFileSync(__dirname + "/../../EspruinoWebIDE/emu/emu_"+EMULATOR+".js").toString()); -eval(require("fs").readFileSync(__dirname + "/../../EspruinoWebIDE/emu/common.js").toString()); - -var SETTINGS = { - pretokenise : true -}; -var Const = { -}; -module = undefined; -eval(require("fs").readFileSync(__dirname + "/../core/lib/espruinotools.js").toString()); -eval(require("fs").readFileSync(__dirname + "/../core/js/utils.js").toString()); -eval(require("fs").readFileSync(__dirname + "/../core/js/appinfo.js").toString()); -var apps = JSON.parse(require("fs").readFileSync(__dirname+"/../apps.json")); - -/* we factory reset ONCE, get this, then we can use it to reset -state quickly for each new app */ -var factoryFlashMemory = new Uint8Array(FLASH_SIZE); -// Log of messages from app -var appLog = ""; // List of apps that errored var erroredApps = []; -jsRXCallback = function() {}; -jsUpdateGfx = function() {}; - function ERROR(s) { console.error(s); process.exit(1); } -function onConsoleOutput(txt) { - appLog += txt + "\n"; -} - function getThumbnail(appId, imageFn) { console.log("Thumbnail for "+appId); - var app = apps.find(a=>a.id==appId); + var app = apploader.apps.find(a=>a.id==appId); if (!app) ERROR(`App ${JSON.stringify(appId)} not found`); if (app.custom) ERROR(`App ${JSON.stringify(appId)} requires HTML customisation`); - return new Promise(resolve => { - AppInfo.getFiles(app, { - fileGetter:function(url) { - console.log(__dirname+"/"+url); - return Promise.resolve(require("fs").readFileSync(__dirname+"/../"+url).toString("binary")); - }, - settings : SETTINGS, - device : { id : DEVICEID } - }).then(files => { - console.log("AppInfo returned");//, files); - flashMemory.set(factoryFlashMemory); - jsTransmitString("reset()\n"); - console.log("Uploading..."); - jsTransmitString("g.clear()\n"); - var command = files.map(f=>f.cmd).join("\n")+"\n"; - command += `load("${appId}.app.js")\n`; - appLog = ""; - jsTransmitString(command); - console.log("Done."); - jsStopIdle(); - - var rgba = new Uint8Array(GFX_WIDTH*GFX_HEIGHT*4); - jsGetGfxContents(rgba); - var rgba32 = new Uint32Array(rgba.buffer); - var firstPixel = rgba32[0]; - var blankImage = rgba32.every(col=>col==firstPixel) - - if (appLog.indexOf("Uncaught")>=0) - erroredApps.push( { id : app.id, log : appLog } ); - - if (!blankImage) { - var Jimp = require("jimp"); - let image = new Jimp(GFX_WIDTH, GFX_HEIGHT, function (err, image) { - if (err) throw err; - let buffer = image.bitmap.data; - buffer.set(rgba); - image.write(imageFn, (err) => { - if (err) throw err; - console.log("Image written as "+imageFn); - resolve(true); - }); - }); - } else { - console.log("Image is empty"); - resolve(false); - } + return apploader.getAppFilesString(app).then(command => { + console.log(`AppInfo returned for ${appId}`);//, files); + emu.factoryReset(); + console.log("Uploading..."); + emu.tx("g.clear()\n"); + command += `load("${appId}.app.js")\n`; + appLog = ""; + emu.tx(command); + console.log("Done."); + emu.tx("Bangle.setLCDMode();clearInterval();clearTimeout();\n"); + emu.stopIdle(); + return emu.writeScreenshot(imageFn, { errorIfBlank : true }).then(() => console.log("X")).catch( err => { + console.log("Error", err); }); }); } var screenshots = []; +apploader.init({ + EMULATOR : EMULATOR, + DEVICEID : DEVICEID +}); // wait until loaded... -setTimeout(function() { - console.log("Loaded..."); - jsInit(); - jsIdle(); - console.log("Factory reset"); - jsTransmitString("Bangle.factoryReset()\n"); - factoryFlashMemory.set(flashMemory); - console.log("Ready!"); - +emu.init({ + EMULATOR : EMULATOR, + DEVICEID : DEVICEID +}).then(function() { if (singleAppId) { - getThumbnail(singleAppId, "screenshots/"+singleAppId+"-"+EMULATOR+".png"); + console.log("Single Screenshot"); + getThumbnail(singleAppId, SCREENSHOT_DIR+singleAppId+"-"+EMULATOR+".png"); return; } - var appList = apps.filter(app => (!app.type || app.type=="clock") && !app.custom); + console.log("Screenshot ALL"); + var appList = apploader.apps.filter(app => (!app.type || app.type=="clock") && !app.custom); appList = appList.filter(app => !app.screenshots && app.supports.includes(DEVICEID)); var promise = Promise.resolve(); appList.forEach(app => { + if (!app.supports.includes(DEVICEID)) { + console.log(`App ${app.id} isn't designed for ${DEVICEID}`); + return; + } promise = promise.then(() => { var imageFile = "screenshots/"+app.id+"-"+EMULATOR+".png"; return getThumbnail(app.id, imageFile).then(ok => { diff --git a/core b/core index c46b4edd2..376824068 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c46b4edd2052d0df37fea41f8839af8175a78ec9 +Subproject commit 376824068d90986c245b46970fd80ccdca44e431 diff --git a/css/main.css b/css/main.css index 96a102119..ceb9fcd17 100644 --- a/css/main.css +++ b/css/main.css @@ -30,7 +30,7 @@ } a.mr-2{ - display: flex; + display: flex; align-items: center; } @@ -102,12 +102,23 @@ a.btn.btn-link.dropdown-toggle { content: url("data:image/svg+xml,%3Csvg fill='rgb(87, 85, 217)' xmlns='http://www.w3.org/2000/svg' viewBox='4 4 40 40' width='1em' height='1em'%3E%3Cpath d='M 8.5 5 C 6.0324991 5 4 7.0324991 4 9.5 L 4 30.5 C 4 32.967501 6.0324991 35 8.5 35 L 17 35 L 17 40 L 13.5 40 A 1.50015 1.50015 0 1 0 13.5 43 L 18.253906 43 A 1.50015 1.50015 0 0 0 18.740234 43 L 29.253906 43 A 1.50015 1.50015 0 0 0 29.740234 43 L 34.5 43 A 1.50015 1.50015 0 1 0 34.5 40 L 31 40 L 31 35 L 39.5 35 C 41.967501 35 44 32.967501 44 30.5 L 44 9.5 C 44 7.0324991 41.967501 5 39.5 5 L 8.5 5 z M 8.5 8 L 39.5 8 C 40.346499 8 41 8.6535009 41 9.5 L 41 30.5 C 41 31.346499 40.346499 32 39.5 32 L 29.746094 32 A 1.50015 1.50015 0 0 0 29.259766 32 L 18.746094 32 A 1.50015 1.50015 0 0 0 18.259766 32 L 8.5 32 C 7.6535009 32 7 31.346499 7 30.5 L 7 9.5 C 7 8.6535009 7.6535009 8 8.5 8 z M 17.5 12 C 16.136406 12 15 13.136406 15 14.5 L 15 25.5 C 15 26.863594 16.136406 28 17.5 28 L 30.5 28 C 31.863594 28 33 26.863594 33 25.5 L 33 14.5 C 33 13.136406 31.863594 12 30.5 12 L 17.5 12 z M 18 18 L 30 18 L 30 25 L 18 25 L 18 18 z M 20 35 L 28 35 L 28 40 L 20 40 L 20 35 z'/%3E%3C/svg%3E"); } .icon.icon-favourite { text-indent: 0px; } /*override spectre*/ +.icon.icon-favourite-active { text-indent: 0px; } /*override spectre*/ .icon.icon-favourite::before { - content: "\02661"; /* 0x2661 = empty heart; 0x2606 = empty star */ + content: url("data:image/svg+xml,%3Csvg fill='rgb(255, 0, 0)' xmlns='http://www.w3.org/2000/svg' viewBox='0 -3 50 47' width='1.5em' height='1.5em'%3E%3Cpath d='M 16.375 9 C 10.117188 9 5 14.054688 5 20.28125 C 5 33.050781 19.488281 39.738281 24.375 43.78125 L 25 44.3125 L 25.625 43.78125 C 30.511719 39.738281 45 33.050781 45 20.28125 C 45 14.054688 39.882813 9 33.625 9 C 30.148438 9 27.085938 10.613281 25 13.0625 C 22.914063 10.613281 19.851563 9 16.375 9 Z M 16.375 11 C 19.640625 11 22.480469 12.652344 24.15625 15.15625 L 25 16.40625 L 25.84375 15.15625 C 27.519531 12.652344 30.359375 11 33.625 11 C 38.808594 11 43 15.144531 43 20.28125 C 43 31.179688 30.738281 37.289063 25 41.78125 C 19.261719 37.289063 7 31.179688 7 20.28125 C 7 15.144531 11.1875 11 16.375 11 Z'/%3E%3C/svg%3E"); } .icon.icon-favourite-active::before { - content: "\02665"; /* 0x2665 = solid heart; 0x2605 = solid star */ + content: url("data:image/svg+xml,%3Csvg fill='rgb(255, 0, 0)' xmlns='http://www.w3.org/2000/svg' viewBox='0 -3 50 47' width='1.5em' height='1.5em'%3E%3Cpath d='M 25 44.296875 L 24.363281 43.769531 C 23.363281 42.941406 22.019531 42.027344 20.46875 40.96875 C 14.308594 36.765625 5 30.414063 5 20.285156 C 5 14.0625 10.097656 9 16.363281 9 C 19.714844 9 22.851563 10.457031 25 12.957031 C 27.148438 10.457031 30.289063 9 33.636719 9 C 39.902344 9 45 14.0625 45 20.285156 C 45 30.414063 35.691406 36.765625 29.53125 40.96875 C 27.976563 42.027344 26.636719 42.941406 25.636719 43.769531 Z'/%3E%3C/svg%3E"); } +.icon.icon-favourite span { + font-size: 50%; + color : #F66; + position:relative; + top:-0.7em; +} +.icon.icon-favourite-active span { + color : white; +} + .icon.icon-interface {text-indent: 0px;} /*override spectre*/ .icon.icon-interface::before { position: absolute; left: 50%; top: 70%; diff --git a/defaultapps_banglejs2.json b/defaultapps_banglejs2.json index 04bd44504..f96f81f60 100644 --- a/defaultapps_banglejs2.json +++ b/defaultapps_banglejs2.json @@ -1 +1 @@ -["boot","launch","antonclk","health","setting","about","widbat","widbt","widlock","widid"] +["boot","launch","antonclk","health","setting","about","alarm","widbat","widbt","widlock","widid"] diff --git a/index.html b/index.html index b141cffc9..cb00d87ab 100644 --- a/index.html +++ b/index.html @@ -88,8 +88,10 @@ @@ -143,6 +145,10 @@ Pretokenise apps before upload (smaller, faster apps) + +
+ Send favourite and installed apps to banglejs.com
+ For 'Sort by Installed/Favourited' functionality (see privacy policy) +
`; showPrompt("Which Bangle.js?",html,{},false); + var usageStats = document.getElementById("usage_stats"); + usageStats.addEventListener("change",event=>{ + console.log("Send Usage Stats "+(event.target.checked?"on":"off")); + SETTINGS.sendUsageStats = event.target.checked; + saveSettings(); + }); htmlToArray(document.querySelectorAll(".devicechooser")).forEach(button => { button.addEventListener("click",event => { - let rememberDevice = document.getElementById("remember_device").checked; - + let rememberDevice = !!document.getElementById("remember_device").checked; let button = event.currentTarget; let deviceId = button.getAttribute("deviceid"); hidePrompt(); @@ -158,7 +206,9 @@ window.addEventListener('load', (event) => { // Button to install all default apps in one go document.getElementById("reinstallall").addEventListener("click",event=>{ var promise = showPrompt("Reinstall","Really re-install all apps?").then(() => { - getInstalledApps().then(installedapps => { + Comms.reset().then(_ => + getInstalledApps() + ).then(installedapps => { console.log(installedapps); var promise = Promise.resolve(); installedapps.forEach(app => { @@ -168,10 +218,12 @@ window.addEventListener('load', (event) => { app = appJSON.find(a => a.id==oldApp.id); if (!app) return console.log(`Ignoring ${oldApp.id} as not found`); - promise = promise.then(() => updateApp(app)); + promise = promise.then(() => updateApp(app, {noReset:true, noFinish:true})); }); return promise; - }).catch(err=>{ + }).then( _ => + Comms.showUploadFinished() + ).catch(err=>{ Progress.hide({sticky:true}); showToast("App re-install failed, "+err,"error"); }); @@ -195,16 +247,25 @@ window.addEventListener('load', (event) => { }); // BLE Compatibility - var selectLang = document.getElementById("settings-ble-compat"); - if (SETTINGS.bleCompat!==undefined) - Puck.increaseMTU = !SETTINGS.bleCompat; - selectLang.addEventListener("change",event=>{ + var selectBLECompat = document.getElementById("settings-ble-compat"); + Puck.increaseMTU = !SETTINGS.bleCompat; + selectBLECompat.checked = !!SETTINGS.bleCompat; + selectBLECompat.addEventListener("change",event=>{ console.log("BLE compatibility mode "+(event.target.checked?"on":"off")); SETTINGS.bleCompat = event.target.checked; Puck.increaseMTU = !SETTINGS.bleCompat; saveSettings(); }); + // Sending usage stats + var selectUsageStats = document.getElementById("settings-usage-stats"); + selectUsageStats.checked = !!SETTINGS.sendUsageStats; + selectUsageStats.addEventListener("change",event=>{ + console.log("Send Usage Stats "+(event.target.checked?"on":"off")); + SETTINGS.sendUsageStats = event.target.checked; + saveSettings(); + }); + // Load language list httpGet("lang/index.json").then(languagesJSON=>{ var languages; diff --git a/typescript/types/globals.d.ts b/modules/.eslintrc.json similarity index 70% rename from typescript/types/globals.d.ts rename to modules/.eslintrc.json index e2da49a0e..d656c2555 100644 --- a/typescript/types/globals.d.ts +++ b/modules/.eslintrc.json @@ -1,12 +1,15 @@ -// TODO all of these globals (copied from eslintrc) need to be typed at some point -/* The typing status is listed on the left of the attribute, e.g.: -status "Attribute" - +{ + "env": { + // TODO: "espruino": false + // TODO: "banglejs": false + }, + "extends": "eslint:recommended", + "globals": { // Methods and Fields at https://banglejs.com/reference "Array": "readonly", "ArrayBuffer": "readonly", "ArrayBufferView": "readonly", -started "Bangle": "readonly", + "Bangle": "readonly", "BluetoothDevice": "readonly", "BluetoothRemoteGATTCharacteristic": "readonly", "BluetoothRemoteGATTServer": "readonly", @@ -22,8 +25,8 @@ started "Bangle": "readonly", "Float64Array": "readonly", "fs": "readonly", "Function": "readonly", -started "Graphics": "readonly", -done "heatshrink": "readonly", + "Graphics": "readonly", + "heatshrink": "readonly", "I2C": "readonly", "Int16Array": "readonly", "Int32Array": "readonly", @@ -109,7 +112,7 @@ done "heatshrink": "readonly", "poke32": "readonly", "poke8": "readonly", "print": "readonly", -started "require": "readonly", + "require": "readonly", "reset": "readonly", "save": "readonly", "Serial1": "readonly", @@ -125,61 +128,36 @@ started "require": "readonly", "trace": "readonly", "VIBRATE": "readonly", // Aliases and not defined at https://banglejs.com/reference -done "g": "readonly", -done "WIDGETS": "readonly" - */ - -// ambient JS definitions - -declare const require: ((module: 'heatshrink') => { - decompress: (compressedString: string) => string; -}) & // TODO add more - ((module: 'otherString') => {}); - -// ambient bangle.js definitions - -declare const Bangle: { - // functions - buzz: (duration?: number, intensity?: number) => Promise; - drawWidgets: () => void; - isCharging: () => boolean; - // events - on(event: 'charging', listener: (charging: boolean) => void): void; - // TODO add more -}; - -declare type Image = { - width: number; - height: number; - bpp?: number; - buffer: ArrayBuffer | string; - transparent?: number; - palette?: Uint16Array; -}; - -declare type GraphicsApi = { - reset: () => GraphicsApi; - flip: () => void; - setColor: (color: string) => GraphicsApi; // TODO we can most likely type color more usefully than this - drawImage: ( - image: string | Image | ArrayBuffer, - xOffset: number, - yOffset: number, - options?: { - rotate?: number; - scale?: number; + "g": "readonly", + "WIDGETS": "readonly" + }, + "parserOptions": { + "ecmaVersion": 11 + }, + "rules": { + "indent": [ + "off", + 2, + { + "SwitchCase": 1 + } + ], + "no-case-declarations": "off", + "no-constant-condition": "off", + "no-delete-var": "off", + "no-empty": "off", + "no-global-assign": "off", + "no-inner-declarations": "off", + "no-octal": "off", + "no-prototype-builtins": "off", + "no-redeclare": "off", + "no-unreachable": "warn", + "no-cond-assign": "warn", + "no-useless-catch": "warn", + // TODO: "no-undef": "warn", + "no-undef": "off", + "no-unused-vars": "off", + "no-useless-escape": "off", + "no-control-regex" : "off" } - ) => GraphicsApi; - // TODO add more -}; - -declare const Graphics: GraphicsApi; -declare const g: GraphicsApi; - -type WidgetArea = 'tl' | 'tr' | 'bl' | 'br'; -declare type Widget = { - area: WidgetArea; - width: number; - draw: (this: { x: number; y: number }) => void; -}; -declare const WIDGETS: { [key: string]: Widget }; +} diff --git a/modules/ClockFace.js b/modules/ClockFace.js index 25b278846..bf64d418a 100644 --- a/modules/ClockFace.js +++ b/modules/ClockFace.js @@ -9,7 +9,7 @@ function ClockFace(options) { if (![ "precision", "init", "draw", "update", - "pause", "resume", + "pause", "resume", "remove", "up", "down", "upDown", "settingsFile", ].includes(k)) throw `Invalid ClockFace option: ${k}`; @@ -27,6 +27,7 @@ function ClockFace(options) { if (options.init) this.init = options.init; if (options.pause) this._pause = options.pause; if (options.resume) this._resume = options.resume; + if (options.remove) this._remove = options.remove; if ((options.up || options.down) && options.upDown) throw "ClockFace up/down and upDown cannot be used together"; if (options.up || options.down) this._upDown = (dir) => { if (dir<0 && options.up) options.up.apply(this); @@ -44,11 +45,20 @@ function ClockFace(options) { ["showDate", "loadWidgets"].forEach(k => { if (this[k]===undefined) this[k] = true; }); + let s = require("Storage").readJSON("setting.json",1)||{}; + if ((global.__FILE__===undefined || global.__FILE__===s.clock) + && s.clockHasWidgets!==this.loadWidgets) { + // save whether we can Fast Load + s.clockHasWidgets = this.loadWidgets; + require("Storage").writeJSON("setting.json", s); + } // use global 24/12-hour setting if not set by clock-settings - if (!('is12Hour' in this)) this.is12Hour = !!(require("Storage").readJSON("setting.json", true) || {})["12hour"]; + if (!('is12Hour' in this)) this.is12Hour = !!(s["12hour"]); } ClockFace.prototype.tick = function() { + "ram" + if (this._removed) return; const time = new Date(); const now = { d: `${time.getFullYear()}-${time.getMonth()}-${time.getDate()}`, @@ -81,19 +91,30 @@ ClockFace.prototype.start = function() { /* Some widgets want to know if we're in a clock or not (like chrono, widget clock, etc). Normally .CLOCK is set by Bangle.setUI('clock') but we want to load widgets so we can check appRect and *then* call setUI. see #1864 */ - Bangle.CLOCK = 1; + Bangle.CLOCK = 1; if (this.loadWidgets) Bangle.loadWidgets(); if (this.init) this.init.apply(this); - if (this._upDown) Bangle.setUI("clockupdown", d=>this._upDown.apply(this,[d])); - else Bangle.setUI("clock"); + const uiRemove = this._remove ? () => this.remove() : undefined; + if (this._upDown) { + Bangle.setUI({ + mode: "clockupdown", + remove: uiRemove, + }, d => this._upDown.apply(this, [d])); + } else { + Bangle.setUI({ + mode: "clock", + remove: uiRemove, + }); + } delete this._last; this.paused = false; this.tick(); - Bangle.on("lcdPower", on => { + this._onLcd = on => { if (on) this.resume(); else this.pause(); - }); + }; + Bangle.on("lcdPower", this._onLcd); }; ClockFace.prototype.pause = function() { @@ -110,6 +131,12 @@ ClockFace.prototype.resume = function() { if (this._resume) this._resume.apply(this); this.tick(); }; +ClockFace.prototype.remove = function() { + this._removed = true; + if (this._timeout) clearTimeout(this._timeout); + Bangle.removeListener("lcdPower", this._onLcd); + if (this._remove) this._remove.apply(this); +}; /** * Force a complete redraw diff --git a/modules/ClockFace.md b/modules/ClockFace.md index b2332c805..f123d38c0 100644 --- a/modules/ClockFace.md +++ b/modules/ClockFace.md @@ -77,6 +77,11 @@ var clock = new ClockFace({ resume: function() { // optional, called when the screen turns on // for example: turn GPS/compass back on }, + remove: function() { // optional, used for Fast Loading + // for example: remove listeners + // Fast Loading will not be used unless this function is present, + // if there is nothing to clean up, you can just leave it empty. + }, up: function() { // optional, up handler }, down: function() { // optional, down handler @@ -208,7 +213,7 @@ let menu = { /*LANG*/"< Back": back, }; require("ClockFace_menu").addSettingsFile(menu, ".settings.json", [ - "showDate", "loadWidgets" + "showDate", "loadWidgets", "powerSave", ]); E.showMenu(menu); diff --git a/modules/ClockFace_menu.js b/modules/ClockFace_menu.js index f2267d9ca..a1dd76fee 100644 --- a/modules/ClockFace_menu.js +++ b/modules/ClockFace_menu.js @@ -11,12 +11,16 @@ exports.addItems = function(menu, callback, items) { const label = { showDate:/*LANG*/"Show date", loadWidgets:/*LANG*/"Load widgets", + powerSave:/*LANG*/"Power saving", }[key]; switch(key) { + // boolean options which default to true case "showDate": case "loadWidgets": - // boolean options, which default to true if (value===undefined) value = true; + // fall through + case "powerSave": + // same for all boolean options: menu[label] = { value: !!value, onchange: v => callback(key, v), diff --git a/modules/Layout.js b/modules/Layout.js index fd5809a93..f8e27b66b 100644 --- a/modules/Layout.js +++ b/modules/Layout.js @@ -13,16 +13,17 @@ function Layout(layout, options) { this._l = this.l = layout; // Do we have >1 physical buttons? - this.physBtns = (process.env.HWVERSION==2) ? 1 : 3; + this.options = options || {}; this.lazy = this.options.lazy || false; - - var btnList; + this.physBtns = 1; + let btnList; if (process.env.HWVERSION!=2) { + this.physBtns = 3; // no touchscreen, find any buttons in 'layout' btnList = []; - function btnRecurser(l) { + function btnRecurser(l) {"ram"; if (l.type=="btn") btnList.push(l); if (l.c) l.c.forEach(btnRecurser); } @@ -37,9 +38,9 @@ function Layout(layout, options) { if (this.options.btns) { var buttons = this.options.btns; - this.b = buttons; if (this.physBtns >= buttons.length) { // enough physical buttons + this.b = buttons; let btnHeight = Math.floor(Bangle.appRect.h / this.physBtns); if (this.physBtns > 2 && buttons.length==1) buttons.unshift({label:""}); // pad so if we have a button in the middle @@ -65,7 +66,7 @@ function Layout(layout, options) { this.setUI(); // recurse over layout doing some fixing up if needed var ll = this; - function recurser(l) { + function recurser(l) {"ram"; // add IDs if (l.id) ll[l.id] = l; // fix type up @@ -82,7 +83,7 @@ Layout.prototype.setUI = function() { let uiSet; if (this.buttons) { // multiple buttons so we'll jus use back/next/select - Bangle.setUI({mode:"updown", back:this.options.back}, dir=>{ + Bangle.setUI({mode:"updown", back:this.options.back, remove:this.options.remove}, dir=>{ var s = this.selectedButton, l=this.buttons.length; if (dir===undefined && this.buttons[s]) return this.buttons[s].cb(); @@ -99,7 +100,7 @@ Layout.prototype.setUI = function() { }); uiSet = true; } - if (this.options.back && !uiSet) Bangle.setUI({mode: "custom", back: this.options.back}); + if ((this.options.back || this.options.remove) && !uiSet) Bangle.setUI({mode: "custom", back: this.options.back, remove: this.options.remove}); // physical buttons -> actual applications if (this.b) { // Handler for button watch events @@ -154,26 +155,25 @@ Layout.prototype.render = function (l) { if (!l) l = this._l; if (this.updateNeeded) this.update(); - function render(l) {"ram" - g.reset(); - if (l.col!==undefined) g.setColor(l.col); - if (l.bgCol!==undefined) g.setBgColor(l.bgCol).clearRect(l.x,l.y,l.x+l.w-1,l.y+l.h-1); + var gfx=g; // define locally, because this is faster + function render(l) {"ram"; + gfx.reset(); + if (l.col!==undefined) gfx.setColor(l.col); + if (l.bgCol!==undefined) gfx.setBgColor(l.bgCol).clearRect(l.x,l.y,l.x+l.w-1,l.y+l.h-1); cb[l.type](l); } var cb = { "":function(){}, - "txt":function(l){ + "txt":function(l){"ram"; if (l.wrap) { - g.setFont(l.font).setFontAlign(0,-1); - var lines = g.wrapString(l.label, l.w); - var y = l.y+((l.h-g.getFontHeight()*lines.length)>>1); - // TODO: on 2v11 we can just render in a single drawString call - lines.forEach((line, i) => g.drawString(line, l.x+(l.w>>1), y+g.getFontHeight()*i)); + var lines = gfx.setFont(l.font).setFontAlign(0,-1).wrapString(l.label, l.w); + var y = l.y+((l.h-gfx.getFontHeight()*lines.length)>>1); + gfx.drawString(lines.join("\n"), l.x+(l.w>>1), y); } else { - g.setFont(l.font).setFontAlign(0,0,l.r).drawString(l.label, l.x+(l.w>>1), l.y+(l.h>>1)); + gfx.setFont(l.font).setFontAlign(0,0,l.r).drawString(l.label, l.x+(l.w>>1), l.y+(l.h>>1)); } - }, "btn":function(l){ + }, "btn":function(l){"ram"; var x = l.x+(0|l.pad), y = l.y+(0|l.pad), w = l.w-(l.pad<<1), h = l.h-(l.pad<<1); var poly = [ @@ -186,27 +186,26 @@ Layout.prototype.render = function (l) { x+4,y+h-1, x,y+h-5, x,y+4 - ], bg = l.selected?g.theme.bgH:g.theme.bg2; - g.setColor(bg).fillPoly(poly).setColor(l.selected ? g.theme.fgH : g.theme.fg2).drawPoly(poly); - if (l.col!==undefined) g.setColor(l.col); - if (l.src) g.setBgColor(bg).drawImage( + ], bg = l.selected?gfx.theme.bgH:gfx.theme.bg2; + gfx.setColor(bg).fillPoly(poly).setColor(l.selected ? gfx.theme.fgH : gfx.theme.fg2).drawPoly(poly); + if (l.col!==undefined) gfx.setColor(l.col); + if (l.src) gfx.setBgColor(bg).drawImage( "function"==typeof l.src?l.src():l.src, l.x + l.w/2, l.y + l.h/2, {scale: l.scale||undefined, rotate: Math.PI*0.5*(l.r||0)} ); - else g.setFont(l.font||"6x8:2").setFontAlign(0,0,l.r).drawString(l.label,l.x+l.w/2,l.y+l.h/2); - }, "img":function(l){ - g.drawImage( + else gfx.setFont(l.font||"6x8:2").setFontAlign(0,0,l.r).drawString(l.label,l.x+l.w/2,l.y+l.h/2); + }, "img":function(l){"ram"; + gfx.drawImage( "function"==typeof l.src?l.src():l.src, l.x + l.w/2, l.y + l.h/2, {scale: l.scale||undefined, rotate: Math.PI*0.5*(l.r||0)} ); - }, "custom":function(l){ - l.render(l); - },"h":function(l) { l.c.forEach(render); }, - "v":function(l) { l.c.forEach(render); } + }, "custom":function(l){"ram"; l.render(l); + }, "h":function(l) { "ram"; l.c.forEach(render); + }, "v":function(l) { "ram"; l.c.forEach(render); } }; if (this.lazy) { @@ -219,7 +218,7 @@ Layout.prototype.render = function (l) { prepareLazyRender(l, rectsToClear, drawList, this.rects, null); for (var h in rectsToClear) delete this.rects[h]; var clearList = Object.keys(rectsToClear).map(k=>rectsToClear[k]).reverse(); // Rects are cleared in reverse order so that the original bg color is restored - for (var r of clearList) g.setBgColor(r.bg).clearRect.apply(g, r); + for (var r of clearList) gfx.setBgColor(r.bg).clearRect.apply(g, r); drawList.forEach(render); } else { // non-lazy render(l); @@ -232,9 +231,8 @@ Layout.prototype.forgetLazyState = function () { Layout.prototype.layout = function (l) { // l = current layout element - // exw,exh = extra width/height available - switch (l.type) { - case "h": { + var cb = { + "h" : function(l) {"ram"; var acc_w = l.x + (0|l.pad); var accfillx = 0; var fillx = l.c && l.c.reduce((a,l)=>a+(0|l.fillx),0); @@ -248,11 +246,10 @@ Layout.prototype.layout = function (l) { c.w = 0|(x - c.x); c.h = 0|(c.filly ? l.h - (l.pad<<1) : c._h); c.y = 0|(l.y + (0|l.pad) + ((1+(0|c.valign))*(l.h-(l.pad<<1)-c.h)>>1)); - if (c.c) this.layout(c); + if (c.c) cb[c.type](c); }); - break; - } - case "v": { + }, + "v" : function(l) {"ram"; var acc_h = l.y + (0|l.pad); var accfilly = 0; var filly = l.c && l.c.reduce((a,l)=>a+(0|l.filly),0); @@ -266,11 +263,11 @@ Layout.prototype.layout = function (l) { c.h = 0|(y - c.y); c.w = 0|(c.fillx ? l.w - (l.pad<<1) : c._w); c.x = 0|(l.x + (0|l.pad) + ((1+(0|c.halign))*(l.w-(l.pad<<1)-c.w)>>1)); - if (c.c) this.layout(c); + if (c.c) cb[c.type](c); }); - break; } - } + }; + cb[l.type](l); }; Layout.prototype.debug = function(l,c) { if (!l) l = this._l; @@ -283,50 +280,51 @@ Layout.prototype.debug = function(l,c) { }; Layout.prototype.update = function() { delete this.updateNeeded; + var gfx=g; // define locally, because this is faster // update sizes - function updateMin(l) {"ram" + function updateMin(l) {"ram"; cb[l.type](l); if (l.r&1) { // rotation var t = l._w;l._w=l._h;l._h=t; } - l._w = 0|Math.max(l._w + (l.pad<<1), 0|l.width); - l._h = 0|Math.max(l._h + (l.pad<<1), 0|l.height); + l._w = Math.max(l._w + (l.pad<<1), 0|l.width); + l._h = Math.max(l._h + (l.pad<<1), 0|l.height); } var cb = { - "txt" : function(l) { + "txt" : function(l) {"ram"; if (l.font.endsWith("%")) - l.font = "Vector"+Math.round(g.getHeight()*l.font.slice(0,-1)/100); + l.font = "Vector"+Math.round(gfx.getHeight()*l.font.slice(0,-1)/100); if (l.wrap) { l._h = l._w = 0; } else { var m = g.setFont(l.font).stringMetrics(l.label); l._w = m.width; l._h = m.height; } - }, "btn": function(l) { + }, "btn": function(l) {"ram"; if (l.font && l.font.endsWith("%")) - l.font = "Vector"+Math.round(g.getHeight()*l.font.slice(0,-1)/100); - var m = l.src?g.imageMetrics("function"==typeof l.src?l.src():l.src):g.setFont(l.font||"6x8:2").stringMetrics(l.label); + l.font = "Vector"+Math.round(gfx.getHeight()*l.font.slice(0,-1)/100); + var m = l.src?gfx.imageMetrics("function"==typeof l.src?l.src():l.src):gfx.setFont(l.font||"6x8:2").stringMetrics(l.label); l._h = 16 + m.height; l._w = 20 + m.width; - }, "img": function(l) { - var m = g.imageMetrics("function"==typeof l.src?l.src():l.src), s=l.scale||1; // get width and height out of image + }, "img": function(l) {"ram"; + var m = gfx.imageMetrics("function"==typeof l.src?l.src():l.src), s=l.scale||1; // get width and height out of image l._w = m.width*s; l._h = m.height*s; - }, "": function(l) { + }, "": function(l) {"ram"; // size should already be set up in width/height l._w = 0; l._h = 0; - }, "custom": function(l) { + }, "custom": function(l) {"ram"; // size should already be set up in width/height l._w = 0; l._h = 0; - }, "h": function(l) { + }, "h": function(l) {"ram"; l.c.forEach(updateMin); l._h = l.c.reduce((a,b)=>Math.max(a,b._h),0); l._w = l.c.reduce((a,b)=>a+b._w,0); if (l.fillx == null && l.c.some(c=>c.fillx)) l.fillx = 1; if (l.filly == null && l.c.some(c=>c.filly)) l.filly = 1; - }, "v": function(l) { + }, "v": function(l) {"ram"; l.c.forEach(updateMin); l._h = l.c.reduce((a,b)=>a+b._h,0); l._w = l.c.reduce((a,b)=>Math.max(a,b._w),0); @@ -337,6 +335,7 @@ Layout.prototype.update = function() { var l = this._l; updateMin(l); + delete cb; if (l.fillx || l.filly) { // fill all l.w = Bangle.appRect.w; l.h = Bangle.appRect.h; diff --git a/modules/Layout.md b/modules/Layout.md index 7a4177957..67db21858 100644 --- a/modules/Layout.md +++ b/modules/Layout.md @@ -59,6 +59,7 @@ layout.render(); - `cb` - a callback function - `cbl` - a callback function for long presses - `back` - a callback function, passed as `back` into Bangle.setUI (which usually adds an icon in the top left) +- `remove` - a cleanup function, passed as `remove` into Bangle.setUI (allows to cleanly remove the app from memory) If automatic lazy rendering is enabled, calls to `layout.render()` will attempt to automatically determine what objects have changed or moved, clear their previous locations, and re-render just those objects. diff --git a/modules/Layout.min.js b/modules/Layout.min.js index 4523c547c..19e60f7a0 100644 --- a/modules/Layout.min.js +++ b/modules/Layout.min.js @@ -1,14 +1,14 @@ -function p(b,k){function d(h){h.id&&(f[h.id]=h);h.type||(h.type="");h.c&&h.c.forEach(d)}this._l=this.l=b;this.physBtns=2==process.env.HWVERSION?1:3;this.options=k||{};this.lazy=this.options.lazy||!1;if(2!=process.env.HWVERSION){var a=[];function h(m){"btn"==m.type&&a.push(m);m.c&&m.c.forEach(h)}h(b);a.length&&(this.physBtns=0,this.buttons=a,this.selectedButton=-1)}if(this.options.btns)if(this.b=b=this.options.btns,this.physBtns>=b.length){let h=Math.floor(Bangle.appRect.h/ -this.physBtns);for(2b.length;)b.push({label:""});this._l.width=g.getWidth()-8;this._l={type:"h",filly:1,c:[this._l,{type:"v",pad:1,filly:1,c:b.map(m=>(m.type="txt",m.font="6x8",m.height=h,m.r=1,m))}]}}else this._l.width=g.getWidth()-32,this._l={type:"h",c:[this._l,{type:"v",c:b.map(h=>(h.type="btn",h.filly=1,h.width=32,h.r=1,h))}]},a&&a.push.apply(a,this._l.c[1].c);this.setUI();var f=this;d(this._l);this.updateNeeded=!0}function r(b, -k,d,a,f){var h=null==b.bgCol?f:g.toColor(b.bgCol);if(h!=f||"txt"==b.type||"btn"==b.type||"img"==b.type||"custom"==b.type){var m=b.c;delete b.c;var c="H"+E.CRC32(E.toJS(b));m&&(b.c=m);delete k[c]||((a[c]=[b.x,b.y,b.x+b.w-1,b.y+b.h-1]).bg=null==f?g.theme.bg:f,d&&(d.push(b),d=null))}if(b.c)for(var l of b.c)r(l,k,d,a,h)}p.prototype.setUI=function(){Bangle.setUI();let b;this.buttons&&(Bangle.setUI({mode:"updown",back:this.options.back},k=>{var d=this.selectedButton,a=this.buttons.length;if(void 0===k&& -this.buttons[d])return this.buttons[d].cb();this.buttons[d]&&(delete this.buttons[d].selected,this.render(this.buttons[d]));d=(d+a+k)%a;this.buttons[d]&&(this.buttons[d].selected=1,this.render(this.buttons[d]));this.selectedButton=d}),b=!0);this.options.back&&!b&&Bangle.setUI({mode:"custom",back:this.options.back});if(this.b){function k(d,a){.75=d.x&&a.y>=d.y&&a.x<=d.x+d.w&&a.y<=d.y+d.h&&(2==a.type&&d.cbl?d.cbl(a):d.cb&&d.cb(a));d.c&&d.c.forEach(f=>k(f,a))}Bangle.touchHandler=(d,a)=>k(this._l,a);Bangle.on("touch",Bangle.touchHandler)}}; -p.prototype.render=function(b){function k(c){"ram";g.reset();void 0!==c.col&&g.setColor(c.col);void 0!==c.bgCol&&g.setBgColor(c.bgCol).clearRect(c.x,c.y,c.x+c.w-1,c.y+c.h-1);d[c.type](c)}b||(b=this._l);this.updateNeeded&&this.update();var d={"":function(){},txt:function(c){if(c.wrap){g.setFont(c.font).setFontAlign(0,-1);var l=g.wrapString(c.label,c.w),e=c.y+(c.h-g.getFontHeight()*l.length>>1);l.forEach((n,q)=>g.drawString(n,c.x+(c.w>>1),e+g.getFontHeight()*q))}else g.setFont(c.font).setFontAlign(0, -0,c.r).drawString(c.label,c.x+(c.w>>1),c.y+(c.h>>1))},btn:function(c){var l=c.x+(0|c.pad),e=c.y+(0|c.pad),n=c.w-(c.pad<<1),q=c.h-(c.pad<<1);l=[l,e+4,l+4,e,l+n-5,e,l+n-1,e+4,l+n-1,e+q-5,l+n-5,e+q-1,l+4,e+q-1,l,e+q-5,l,e+4];e=c.selected?g.theme.bgH:g.theme.bg2;g.setColor(e).fillPoly(l).setColor(c.selected?g.theme.fgH:g.theme.fg2).drawPoly(l);void 0!==c.col&&g.setColor(c.col);c.src?g.setBgColor(e).drawImage("function"==typeof c.src?c.src():c.src,c.x+c.w/2,c.y+c.h/2,{scale:c.scale||void 0,rotate:.5*Math.PI* -(c.r||0)}):g.setFont(c.font||"6x8:2").setFontAlign(0,0,c.r).drawString(c.label,c.x+c.w/2,c.y+c.h/2)},img:function(c){g.drawImage("function"==typeof c.src?c.src():c.src,c.x+c.w/2,c.y+c.h/2,{scale:c.scale||void 0,rotate:.5*Math.PI*(c.r||0)})},custom:function(c){c.render(c)},h:function(c){c.c.forEach(k)},v:function(c){c.c.forEach(k)}};if(this.lazy){this.rects||(this.rects={});var a=this.rects.clone(),f=[];r(b,a,f,this.rects,null);for(var h in a)delete this.rects[h];b=Object.keys(a).map(c=>a[c]).reverse(); -for(var m of b)g.setBgColor(m.bg).clearRect.apply(g,m);f.forEach(k)}else k(b)};p.prototype.forgetLazyState=function(){this.rects={}};p.prototype.layout=function(b){switch(b.type){case "h":var k=b.x+(0|b.pad),d=0,a=b.c&&b.c.reduce((e,n)=>e+(0|n.fillx),0);a||(k+=b.w-b._w>>1,a=1);var f=k;b.c.forEach(e=>{e.x=0|f;k+=e._w;d+=0|e.fillx;f=k+Math.floor(d*(b.w-b._w)/a);e.w=0|f-e.x;e.h=0|(e.filly?b.h-(b.pad<<1):e._h);e.y=0|b.y+(0|b.pad)+((1+(0|e.valign))*(b.h-(b.pad<<1)-e.h)>>1);e.c&&this.layout(e)});break; -case "v":var h=b.y+(0|b.pad),m=0,c=b.c&&b.c.reduce((e,n)=>e+(0|n.filly),0);c||(h+=b.h-b._h>>1,c=1);var l=h;b.c.forEach(e=>{e.y=0|l;h+=e._h;m+=0|e.filly;l=h+Math.floor(m*(b.h-b._h)/c);e.h=0|l-e.y;e.w=0|(e.fillx?b.w-(b.pad<<1):e._w);e.x=0|b.x+(0|b.pad)+((1+(0|e.halign))*(b.w-(b.pad<<1)-e.w)>>1);e.c&&this.layout(e)})}};p.prototype.debug=function(b,k){b||(b=this._l);k=k||1;g.setColor(k&1,k&2,k&4).drawRect(b.x+k-1,b.y+k-1,b.x+b.w-k,b.y+b.h-k);b.pad&&g.drawRect(b.x+b.pad-1,b.y+b.pad-1,b.x+b.w-b.pad,b.y+ -b.h-b.pad);k++;b.c&&b.c.forEach(d=>this.debug(d,k))};p.prototype.update=function(){function b(a){"ram";k[a.type](a);if(a.r&1){var f=a._w;a._w=a._h;a._h=f}a._w=0|Math.max(a._w+(a.pad<<1),0|a.width);a._h=0|Math.max(a._h+(a.pad<<1),0|a.height)}delete this.updateNeeded;var k={txt:function(a){a.font.endsWith("%")&&(a.font="Vector"+Math.round(g.getHeight()*a.font.slice(0,-1)/100));if(a.wrap)a._h=a._w=0;else{var f=g.setFont(a.font).stringMetrics(a.label);a._w=f.width;a._h=f.height}},btn:function(a){a.font&& -a.font.endsWith("%")&&(a.font="Vector"+Math.round(g.getHeight()*a.font.slice(0,-1)/100));var f=a.src?g.imageMetrics("function"==typeof a.src?a.src():a.src):g.setFont(a.font||"6x8:2").stringMetrics(a.label);a._h=16+f.height;a._w=20+f.width},img:function(a){var f=g.imageMetrics("function"==typeof a.src?a.src():a.src),h=a.scale||1;a._w=f.width*h;a._h=f.height*h},"":function(a){a._w=0;a._h=0},custom:function(a){a._w=0;a._h=0},h:function(a){a.c.forEach(b);a._h=a.c.reduce((f,h)=>Math.max(f,h._h),0);a._w= -a.c.reduce((f,h)=>f+h._w,0);null==a.fillx&&a.c.some(f=>f.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(f=>f.filly)&&(a.filly=1)},v:function(a){a.c.forEach(b);a._h=a.c.reduce((f,h)=>f+h._h,0);a._w=a.c.reduce((f,h)=>Math.max(f,h._w),0);null==a.fillx&&a.c.some(f=>f.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(f=>f.filly)&&(a.filly=1)}},d=this._l;b(d);d.fillx||d.filly?(d.w=Bangle.appRect.w,d.h=Bangle.appRect.h,d.x=Bangle.appRect.x,d.y=Bangle.appRect.y):(d.w=d._w,d.h=d._h,d.x=Bangle.appRect.w-d.w>>1,d.y= -Bangle.appRect.y+(Bangle.appRect.h-d.h>>1));this.layout(d)};p.prototype.clear=function(b){b||(b=this._l);g.reset();void 0!==b.bgCol&&g.setBgColor(b.bgCol);g.clearRect(b.x,b.y,b.x+b.w-1,b.y+b.h-1)};exports=p +function p(d,h){function b(e){"ram";e.id&&(a[e.id]=e);e.type||(e.type="");e.c&&e.c.forEach(b)}this._l=this.l=d;this.options=h||{};this.lazy=this.options.lazy||!1;this.physBtns=1;let f;if(2!=process.env.HWVERSION){this.physBtns=3;f=[];function e(l){"ram";"btn"==l.type&&f.push(l);l.c&&l.c.forEach(e)}e(d);f.length&&(this.physBtns=0,this.buttons=f,this.selectedButton=-1)}if(this.options.btns)if(d=this.options.btns,this.physBtns>=d.length){this.b=d;let e=Math.floor(Bangle.appRect.h/this.physBtns); +for(2d.length;)d.push({label:""});this._l.width=g.getWidth()-8;this._l={type:"h",filly:1,c:[this._l,{type:"v",pad:1,filly:1,c:d.map(l=>(l.type="txt",l.font="6x8",l.height=e,l.r=1,l))}]}}else this._l.width=g.getWidth()-32,this._l={type:"h",c:[this._l,{type:"v",c:d.map(e=>(e.type="btn",e.filly=1,e.width=32,e.r=1,e))}]},f&&f.push.apply(f,this._l.c[1].c);this.setUI();var a=this;b(this._l);this.updateNeeded=!0}function t(d,h,b,f,a){var e= +null==d.bgCol?a:g.toColor(d.bgCol);if(e!=a||"txt"==d.type||"btn"==d.type||"img"==d.type||"custom"==d.type){var l=d.c;delete d.c;var k="H"+E.CRC32(E.toJS(d));l&&(d.c=l);delete h[k]||((f[k]=[d.x,d.y,d.x+d.w-1,d.y+d.h-1]).bg=null==a?g.theme.bg:a,b&&(b.push(d),b=null))}if(d.c)for(var c of d.c)t(c,h,b,f,e)}p.prototype.setUI=function(){Bangle.setUI();let d;this.buttons&&(Bangle.setUI({mode:"updown",back:this.options.back,remove:this.options.remove},h=>{var b=this.selectedButton,f=this.buttons.length;if(void 0=== +h&&this.buttons[b])return this.buttons[b].cb();this.buttons[b]&&(delete this.buttons[b].selected,this.render(this.buttons[b]));b=(b+f+h)%f;this.buttons[b]&&(this.buttons[b].selected=1,this.render(this.buttons[b]));this.selectedButton=b}),d=!0);!this.options.back&&!this.options.remove||d||Bangle.setUI({mode:"custom",back:this.options.back,remove:this.options.remove});if(this.b){function h(b,f){.75=b.x&&f.y>=b.y&&f.x<=b.x+b.w&&f.y<=b.y+b.h&&(2==f.type&&b.cbl?b.cbl(f):b.cb&&b.cb(f));b.c&&b.c.forEach(a=>h(a,f))}Bangle.touchHandler=(b,f)=>h(this._l,f);Bangle.on("touch", +Bangle.touchHandler)}};p.prototype.render=function(d){function h(c){"ram";b.reset();void 0!==c.col&&b.setColor(c.col);void 0!==c.bgCol&&b.setBgColor(c.bgCol).clearRect(c.x,c.y,c.x+c.w-1,c.y+c.h-1);f[c.type](c)}d||(d=this._l);this.updateNeeded&&this.update();var b=g,f={"":function(){},txt:function(c){"ram";if(c.wrap){var m=b.setFont(c.font).setFontAlign(0,-1).wrapString(c.label,c.w),n=c.y+(c.h-b.getFontHeight()*m.length>>1);b.drawString(m.join("\n"),c.x+(c.w>>1),n)}else b.setFont(c.font).setFontAlign(0, +0,c.r).drawString(c.label,c.x+(c.w>>1),c.y+(c.h>>1))},btn:function(c){"ram";var m=c.x+(0|c.pad),n=c.y+(0|c.pad),q=c.w-(c.pad<<1),r=c.h-(c.pad<<1);m=[m,n+4,m+4,n,m+q-5,n,m+q-1,n+4,m+q-1,n+r-5,m+q-5,n+r-1,m+4,n+r-1,m,n+r-5,m,n+4];n=c.selected?b.theme.bgH:b.theme.bg2;b.setColor(n).fillPoly(m).setColor(c.selected?b.theme.fgH:b.theme.fg2).drawPoly(m);void 0!==c.col&&b.setColor(c.col);c.src?b.setBgColor(n).drawImage("function"==typeof c.src?c.src():c.src,c.x+c.w/2,c.y+c.h/2,{scale:c.scale||void 0,rotate:.5* +Math.PI*(c.r||0)}):b.setFont(c.font||"6x8:2").setFontAlign(0,0,c.r).drawString(c.label,c.x+c.w/2,c.y+c.h/2)},img:function(c){"ram";b.drawImage("function"==typeof c.src?c.src():c.src,c.x+c.w/2,c.y+c.h/2,{scale:c.scale||void 0,rotate:.5*Math.PI*(c.r||0)})},custom:function(c){"ram";c.render(c)},h:function(c){"ram";c.c.forEach(h)},v:function(c){"ram";c.c.forEach(h)}};if(this.lazy){this.rects||(this.rects={});var a=this.rects.clone(),e=[];t(d,a,e,this.rects,null);for(var l in a)delete this.rects[l];d= +Object.keys(a).map(c=>a[c]).reverse();for(var k of d)b.setBgColor(k.bg).clearRect.apply(g,k);e.forEach(h)}else h(d)};p.prototype.forgetLazyState=function(){this.rects={}};p.prototype.layout=function(d){var h={h:function(b){"ram";var f=b.x+(0|b.pad),a=0,e=b.c&&b.c.reduce((k,c)=>k+(0|c.fillx),0);e||(f+=b.w-b._w>>1,e=1);var l=f;b.c.forEach(k=>{k.x=0|l;f+=k._w;a+=0|k.fillx;l=f+Math.floor(a*(b.w-b._w)/e);k.w=0|l-k.x;k.h=0|(k.filly?b.h-(b.pad<<1):k._h);k.y=0|b.y+(0|b.pad)+((1+(0|k.valign))*(b.h-(b.pad<< +1)-k.h)>>1);if(k.c)h[k.type](k)})},v:function(b){"ram";var f=b.y+(0|b.pad),a=0,e=b.c&&b.c.reduce((k,c)=>k+(0|c.filly),0);e||(f+=b.h-b._h>>1,e=1);var l=f;b.c.forEach(k=>{k.y=0|l;f+=k._h;a+=0|k.filly;l=f+Math.floor(a*(b.h-b._h)/e);k.h=0|l-k.y;k.w=0|(k.fillx?b.w-(b.pad<<1):k._w);k.x=0|b.x+(0|b.pad)+((1+(0|k.halign))*(b.w-(b.pad<<1)-k.w)>>1);if(k.c)h[k.type](k)})}};h[d.type](d)};p.prototype.debug=function(d,h){d||(d=this._l);h=h||1;g.setColor(h&1,h&2,h&4).drawRect(d.x+h-1,d.y+h-1,d.x+d.w-h,d.y+d.h-h); +d.pad&&g.drawRect(d.x+d.pad-1,d.y+d.pad-1,d.x+d.w-d.pad,d.y+d.h-d.pad);h++;d.c&&d.c.forEach(b=>this.debug(b,h))};p.prototype.update=function(){function d(a){"ram";b[a.type](a);if(a.r&1){var e=a._w;a._w=a._h;a._h=e}a._w=Math.max(a._w+(a.pad<<1),0|a.width);a._h=Math.max(a._h+(a.pad<<1),0|a.height)}delete this.updateNeeded;var h=g,b={txt:function(a){"ram";a.font.endsWith("%")&&(a.font="Vector"+Math.round(h.getHeight()*a.font.slice(0,-1)/100));if(a.wrap)a._h=a._w=0;else{var e=g.setFont(a.font).stringMetrics(a.label); +a._w=e.width;a._h=e.height}},btn:function(a){"ram";a.font&&a.font.endsWith("%")&&(a.font="Vector"+Math.round(h.getHeight()*a.font.slice(0,-1)/100));var e=a.src?h.imageMetrics("function"==typeof a.src?a.src():a.src):h.setFont(a.font||"6x8:2").stringMetrics(a.label);a._h=16+e.height;a._w=20+e.width},img:function(a){"ram";var e=h.imageMetrics("function"==typeof a.src?a.src():a.src),l=a.scale||1;a._w=e.width*l;a._h=e.height*l},"":function(a){"ram";a._w=0;a._h=0},custom:function(a){"ram";a._w=0;a._h=0}, +h:function(a){"ram";a.c.forEach(d);a._h=a.c.reduce((e,l)=>Math.max(e,l._h),0);a._w=a.c.reduce((e,l)=>e+l._w,0);null==a.fillx&&a.c.some(e=>e.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(e=>e.filly)&&(a.filly=1)},v:function(a){"ram";a.c.forEach(d);a._h=a.c.reduce((e,l)=>e+l._h,0);a._w=a.c.reduce((e,l)=>Math.max(e,l._w),0);null==a.fillx&&a.c.some(e=>e.fillx)&&(a.fillx=1);null==a.filly&&a.c.some(e=>e.filly)&&(a.filly=1)}},f=this._l;d(f);delete b;f.fillx||f.filly?(f.w=Bangle.appRect.w,f.h=Bangle.appRect.h, +f.x=Bangle.appRect.x,f.y=Bangle.appRect.y):(f.w=f._w,f.h=f._h,f.x=Bangle.appRect.w-f.w>>1,f.y=Bangle.appRect.y+(Bangle.appRect.h-f.h>>1));this.layout(f)};p.prototype.clear=function(d){d||(d=this._l);g.reset();void 0!==d.bgCol&&g.setBgColor(d.bgCol);g.clearRect(d.x,d.y,d.x+d.w-1,d.y+d.h-1)};exports=p \ No newline at end of file diff --git a/modules/README.md b/modules/README.md index 62ce90a97..fcb403bd5 100644 --- a/modules/README.md +++ b/modules/README.md @@ -13,10 +13,29 @@ Development When apps that use these modules are uploaded via the app loader, the module is automatically included in the app's source. However -when developing via the IDE the module won't get pulled in by default. +when developing via the IDE the module won't get pulled in by default +so you may see the error "Module not found" in the IDE when sending code to the Bangle. To fix this you have three options: + +### Change the Web IDE search path to include Bangle.js modules + +This is nice and easy (and the results are the same as if the app was +uploaded via the app loader), however you cannot then make/test changes +to the module. + +* In the IDE, Click the `Settings` icon in the top right +* Click `Communications` and scroll down to `Module URL` +* Now change the module URL from the default of `https://www.espruino.com/modules` +to `https://banglejs.com/apps/modules|https://www.espruino.com/modules` + +The next time you upload your app, the module will automatically be included. + +**Note:** You can optionally use `https://raw.githubusercontent.com/espruino/BangleApps/master/modules|https://www.espruino.com/modules` +as the module URL to pull in modules direct from the development app loader (which could be slightly newer than the ones on https://banglejs.com/apps) + + ### Host your own App Loader and upload from that This is reasonably easy to set up, but it's more difficult to make changes and upload: @@ -26,6 +45,7 @@ This is reasonably easy to set up, but it's more difficult to make changes and u * Refresh and upload your app from the app loader (you can have the IDE connected at the same time so you can see any error messages) + ### Upload the module to the Bangle's internal storage This allows you to develop both the app and module very quickly, but the app is @@ -40,15 +60,4 @@ or the method below: You can now upload the app direct from the IDE. You can even leave a second Web IDE window open (one for the app, one for the module) to allow you to change the module. -### Change the Web IDE search path to include Bangle.js modules -This is nice and easy (and the results are the same as if the app was -uploaded via the app loader), however you cannot then make/test changes -to the module. - -* In the IDE, Click the `Settings` icon in the top right -* Click `Communications` and scroll down to `Module URL` -* Now change the module URL from the default of `https://www.espruino.com/modules` -to `https://banglejs.com/apps/modules|https://www.espruino.com/modules` - -The next time you upload your app, the module will automatically be included. diff --git a/modules/clock_info.js b/modules/clock_info.js new file mode 100644 index 000000000..643a9f6f7 --- /dev/null +++ b/modules/clock_info.js @@ -0,0 +1,317 @@ +/* Module that allows for loading of clock 'info' displays +that can be scrolled through on the clock face. + +`load()` returns an array of menu objects, where each object contains a list of menu items: +* `name` : text to display and identify menu object (e.g. weather) +* `img` : a 24x24px image +* `dynamic` : if `true`, items are not constant but are sorted (e.g. calendar events sorted by date) +* `items` : menu items such as temperature, humidity, wind etc. + +Note that each item is an object with: + +* `item.name` : friendly name to identify an item (e.g. temperature) +* `item.hasRange` : if `true`, `.get` returns `v/min/max` values (for progress bar/guage) +* `item.get` : function that returns an object: + +{ + 'text' // the text to display for this item + 'short' : (optional) a shorter text to display for this item (at most 6 characters) + 'img' // optional: a 24x24px image to display for this item + 'v' // (if hasRange==true) a numerical value + 'min','max' // (if hasRange==true) a minimum and maximum numerical value (if this were to be displayed as a guage) +} + +* `item.show` : called when item should be shown. Enables updates. Call BEFORE 'get' +* `item.hide` : called when item should be hidden. Disables updates. +* `.on('redraw', ...)` : event that is called when 'get' should be called again (only after 'item.show') +* `item.run` : (optional) called if the info screen is tapped - can perform some action. Return true if the caller should feedback the user. + +See the bottom of this file for example usage... + +example.clkinfo.js : + +(function() { + return { + name: "Bangle", + img: atob("GBiBAAD+AAH+AAH+AAH+AAH/AAOHAAYBgAwAwBgwYBgwYBgwIBAwOBAwOBgYIBgMYBgAYAwAwAYBgAOHAAH/AAH+AAH+AAH+AAD+AA==") }), + items: [ + { name : "Item1", + get : () => ({ text : "TextOfItem1", v : 10, min : 0, max : 100, + img : atob("GBiBAAD+AAH+AAH+AAH+AAH/AAOHAAYBgAwAwBgwYBgwYBgwIBAwOBAwOBgYIBgMYBgAYAwAwAYBgAOHAAH/AAH+AAH+AAH+AAD+AA==") + }), + show : () => {}, + hide : () => {} + // run : () => {} optional (called when tapped) + } + ] + }; +}) // must not have a semi-colon! + +*/ + +let storage = require("Storage"); +let stepGoal = undefined; +// Load step goal from health app and pedometer widget +let d = storage.readJSON("health.json", true) || {}; +stepGoal = d != undefined && d.settings != undefined ? d.settings.stepGoal : undefined; +if (stepGoal == undefined) { + d = storage.readJSON("wpedom.json", true) || {}; + stepGoal = d != undefined && d.settings != undefined ? d.settings.goal : 10000; +} + +exports.load = function() { + // info used for drawing... + var hrm = 0; + var alt = "--"; + // callbacks (needed for easy removal of listeners) + function batteryUpdateHandler() { bangleItems[0].emit("redraw"); } + function stepUpdateHandler() { bangleItems[1].emit("redraw"); } + function hrmUpdateHandler(e) { + if (e && e.confidence>60) hrm = Math.round(e.bpm); + bangleItems[2].emit("redraw"); + } + function altUpdateHandler() { + Bangle.getPressure().then(data=>{ + if (!data) return; + alt = Math.round(data.altitude) + "m"; + bangleItems[3].emit("redraw"); + }); + } + // actual menu + var menu = [{ + name: "Bangle", + img: atob("GBiBAAD+AAH+AAH+AAH+AAH/AAOHAAYBgAwAwBgwYBgwYBgwIBAwOBAwOBgYIBgMYBgAYAwAwAYBgAOHAAH/AAH+AAH+AAH+AAD+AA=="), + items: [ + { name : "Battery", + hasRange : true, + get : () => { let v = E.getBattery(); return { + text : v + "%", v : v, min:0, max:100, + img : atob(Bangle.isCharging() ? "GBiBAAABgAADwAAHwAAPgACfAAHOAAPkBgHwDwP4Hwf8Pg/+fB//OD//kD//wD//4D//8D//4B//QB/+AD/8AH/4APnwAHAAACAAAA==" : "GBiBAAAAAAAAAAAAAAAAAAAAAD//+P///IAAAr//Ar//Ar//A7//A7//A7//A7//Ar//AoAAAv///D//+AAAAAAAAAAAAAAAAAAAAA==") + }}, + show : function() { this.interval = setInterval(()=>this.emit('redraw'), 60000); Bangle.on("charging", batteryUpdateHandler); batteryUpdateHandler(); }, + hide : function() { clearInterval(this.interval); delete this.interval; Bangle.removeListener("charging", batteryUpdateHandler); }, + }, + { name : "Steps", + hasRange : true, + get : () => { let v = Bangle.getHealthStatus("day").steps; return { + text : v, v : v, min : 0, max : stepGoal, + img : atob("GBiBAAcAAA+AAA/AAA/AAB/AAB/gAA/g4A/h8A/j8A/D8A/D+AfH+AAH8AHn8APj8APj8AHj4AHg4AADAAAHwAAHwAAHgAAHgAADAA==") + }}, + show : function() { Bangle.on("step", stepUpdateHandler); stepUpdateHandler(); }, + hide : function() { Bangle.removeListener("step", stepUpdateHandler); }, + }, + { name : "HRM", + hasRange : true, + get : () => { return { + text : (hrm||"--") + " bpm", v : hrm, min : 40, max : 200, + img : atob("GBiBAAAAAAAAAAAAAAAAAAAAAADAAADAAAHAAAHjAAHjgAPngH9n/n82/gA+AAA8AAA8AAAcAAAYAAAYAAAAAAAAAAAAAAAAAAAAAA==") + }}, + show : function() { Bangle.setHRMPower(1,"clkinfo"); Bangle.on("HRM", hrmUpdateHandler); hrm = Math.round(Bangle.getHealthStatus().bpm||Bangle.getHealthStatus("last").bpm); hrmUpdateHandler(); }, + hide : function() { Bangle.setHRMPower(0,"clkinfo"); Bangle.removeListener("HRM", hrmUpdateHandler); hrm = 0; }, + } + ], + }]; + var bangleItems = menu[0].items; + + if (Bangle.getPressure){ // Altimeter may not exist + bangleItems.push({ name : "Altitude", + get : () => ({ + text : alt, v : alt, + img : atob("GBiBAAAAAAAAAAAAAAAAAAAAAAACAAAGAAAPAAEZgAOwwAPwQAZgYAwAMBgAGBAACDAADGAABv///////wAAAAAAAAAAAAAAAAAAAA==") + }), + show : function() { this.interval = setInterval(altUpdateHandler, 60000); alt = "--"; altUpdateHandler(); }, + hide : function() { clearInterval(this.interval); delete this.interval; }, + }); + } + + // In case there exists already a menu object b with the same name as the next + // object a, we append the items. Otherwise we add the new object a to the list. + require("Storage").list(/clkinfo.js$/).forEach(fn => { + try{ + var a = eval(require("Storage").read(fn))(); + var b = menu.find(x => x.name === a.name) + if(b) b.items = b.items.concat(a.items); + else menu = menu.concat(a); + } catch(e){ + console.log("Could not load clock info "+E.toJS(fn)) + } + }); + + // return it all! + return menu; +}; + +/** Adds an interactive menu that could be used on a clock face by swiping. +Simply supply the menu data (from .load) and a function to draw the clock info. + +For example: + +let clockInfoItems = require("clock_info").load(); +let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { + x : 20, y: 20, w: 80, h:80, // dimensions of area used for clock_info + draw : (itm, info, options) => { + g.reset().clearRect(options.x, options.y, options.x+options.w-2, options.y+options.h-1); + if (options.focus) g.drawRect(options.x, options.y, options.x+options.w-2, options.y+options.h-1); // show if focused + var midx = options.x+options.w/2; + if (info.img) g.drawImage(info.img, midx-12,options.y+4); + g.setFont("6x8:2").setFontAlign(0,1).drawString(info.text, midx,options.y+44); + } +}); +// then when clock 'unloads': +clockInfoMenu.remove(); +delete clockInfoMenu; + +Then if you need to unload the clock info so it no longer +uses memory or responds to swipes, you can call clockInfoMenu.remove() +and delete clockInfoMenu + +clockInfoMenu is the 'options' parameter, with the following added: + +* `index` : int - which instance number are we? Starts at 0 +* `menuA` : int - index in 'menu' of showing clockInfo item +* `menuB` : int - index in 'menu[menuA].items' of showing clockInfo item +* `remove` : function - remove this clockInfo item +* `redraw` : function - force a redraw +* `focus` : function - bool to show if menu is focused or not + +You can have more than one clock_info at once as well, sfor instance: + +let clockInfoDraw = (itm, info, options) => { + g.reset().setBgColor(options.bg).setColor(options.fg).clearRect(options.x, options.y, options.x+options.w-2, options.y+options.h-1); + if (options.focus) g.drawRect(options.x, options.y, options.x+options.w-2, options.y+options.h-1) + var midx = options.x+options.w/2; + if (info.img) g.drawImage(info.img, midx-12,options.y); + g.setFont("6x15").setFontAlign(0,1).drawString(info.text, midx,options.y+41); +}; +let clockInfoItems = require("clock_info").load(); +let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { x:126, y:24, w:50, h:40, draw : clockInfoDraw, bg : g.theme.bg, fg : g.theme.fg }); +let clockInfoMenu2 = require("clock_info").addInteractive(clockInfoItems, { x:0, y:120, w:50, h:40, draw : clockInfoDraw, bg : bgColor, fg : g.theme.bg}); + +*/ +exports.addInteractive = function(menu, options) { + if (!menu.length || !menu[0].items.length) return; // no infos - can't load a clock_info + if ("function" == typeof options) options = {draw:options}; // backwards compatibility + options.index = 0|exports.loadCount; + exports.loadCount = options.index+1; + options.focus = options.index==0 && options.x===undefined; // focus if we're the first one loaded and no position has been defined + const appName = "default:"+options.index; + + { // load the currently showing clock_infos + let settings = require("Storage").readJSON("clock_info.json",1)||{}; + if (settings[appName]) { + let a = settings[appName].a|0; + let b = settings[appName].b|0; + if (menu[a] && menu[a].items[b]) { // all ok + options.menuA = a; + options.menuB = b; + } + } + } + if (options.menuA===undefined) options.menuA = 0; + if (options.menuB===undefined) options.menuB = Math.min(exports.loadCount, menu[options.menuA].items.length)-1; + function drawItem(itm) { + options.draw(itm, itm.get(), options); + } + function menuShowItem(itm) { + options.redrawHandler = ()=>drawItem(itm); + itm.on('redraw', options.redrawHandler); + itm.uses = (0|itm.uses)+1; + if (itm.uses==1) itm.show(); + itm.emit("redraw"); + } + function menuHideItem(itm) { + itm.removeListener('redraw',options.redrawHandler); + delete options.redrawHandler; + itm.uses--; + if (!itm.uses) + itm.hide(); + } + // handling for swipe between menu items + function swipeHandler(lr,ud){ + if (!options.focus) return; // ignore if we're not focussed + var oldMenuItem; + if (ud) { + if (menu[options.menuA].items.length==1) return; // 1 item - can't move + oldMenuItem = menu[options.menuA].items[options.menuB]; + options.menuB += ud; + if (options.menuB<0) options.menuB = menu[options.menuA].items.length-1; + if (options.menuB>=menu[options.menuA].items.length) options.menuB = 0; + } else if (lr) { + if (menu.length==1) return; // 1 item - can't move + oldMenuItem = menu[options.menuA].items[options.menuB]; + do { + options.menuA += lr; + if (options.menuA<0) options.menuA = menu.length-1; + if (options.menuA>=menu.length) options.menuA = 0; + options.menuB = 0; + //get the next one if the menu is empty + //can happen for dynamic ones (alarms, events) + //in the worst case we come back to 0 + } while(menu[options.menuA].items.length==0); + } + if (oldMenuItem) { + menuHideItem(oldMenuItem); + oldMenuItem.removeAllListeners("draw"); + menuShowItem(menu[options.menuA].items[options.menuB]); + } + // save the currently showing clock_info + let settings = require("Storage").readJSON("clock_info.json",1)||{}; + settings[appName] = {a:options.menuA,b:options.menuB}; + require("Storage").writeJSON("clock_info.json",settings); + } + Bangle.on("swipe",swipeHandler); + var touchHandler; + if (options.x!==undefined && options.y!==undefined && options.w && options.h) { + touchHandler = function(_,e) { + if (e.x(options.x+options.w) || e.y>(options.y+options.h)) { + if (options.focus) { + options.focus=false; + options.redraw(); + } + return; // outside area + } + if (!options.focus) { + options.focus=true; // if not focussed, set focus + options.redraw(); + } else if (menu[options.menuA].items[options.menuB].run) + menu[options.menuA].items[options.menuB].run(); // allow tap on an item to run it (eg home assistant) + else options.focus=true; + }; + Bangle.on("touch",touchHandler); + } + // draw the first item + menuShowItem(menu[options.menuA].items[options.menuB]); + // return an object with info that can be used to remove the info + options.remove = function() { + Bangle.removeListener("swipe",swipeHandler); + if (touchHandler) Bangle.removeListener("touch",touchHandler); + menuHideItem(menu[options.menuA].items[options.menuB]); + exports.loadCount--; + }; + options.redraw = function() { + drawItem(menu[options.menuA].items[options.menuB]); + }; + return options; +}; + +// Code for testing (plots all elements from first list) +/* +g.clear(); +var menu = exports.load(); // or require("clock_info").load() +var items = menu[0].items; +items.forEach((itm,i) => { + var y = i*24; + console.log("Starting", itm.name); + function draw() { + var info = itm.get(); + g.reset().setFont("6x8:2").setFontAlign(-1,0); + g.clearRect(0,y,g.getWidth(),y+23); + g.drawImage(info.img, 0,y); + g.drawString(info.text, 48,y+12); + } + itm.on('redraw', draw); // ensures we redraw when we need to + itm.show(); + draw(); +}); +*/ diff --git a/modules/graphics_utils.js b/modules/graphics_utils.js new file mode 100644 index 000000000..5c08188bc --- /dev/null +++ b/modules/graphics_utils.js @@ -0,0 +1,35 @@ +// draw an arc between radii minR and maxR, and between angles minAngle and maxAngle centered at X,Y. All angles are radians. +exports.fillArc = function(graphics, X, Y, minR, maxR, minAngle, maxAngle, stepAngle) { + var step = stepAngle || 0.2; + var angle = minAngle; + var inside = []; + var outside = []; + var c, s; + while (angle < maxAngle) { + c = Math.cos(angle); + s = Math.sin(angle); + inside.push(X+c*minR); // x + inside.push(Y+s*minR); // y + // outside coordinates are built up in reverse order + outside.unshift(Y+s*maxR); // y + outside.unshift(X+c*maxR); // x + angle += step; + } + c = Math.cos(maxAngle); + s = Math.sin(maxAngle); + inside.push(X+c*minR); + inside.push(Y+s*minR); + outside.unshift(Y+s*maxR); + outside.unshift(X+c*maxR); + + var vertices = inside.concat(outside); + graphics.fillPoly(vertices, true); +} + +exports.degreesToRadians = function(degrees){ + return Math.PI/180 * degrees; +} + +exports.radiansToDegrees = function(radians){ + return 180/Math.PI * degrees; +} \ No newline at end of file diff --git a/apps/sunclock/suncalc.js b/modules/suncalc.js similarity index 75% rename from apps/sunclock/suncalc.js rename to modules/suncalc.js index b1af0a0d9..fe17148e1 100644 --- a/apps/sunclock/suncalc.js +++ b/modules/suncalc.js @@ -1,17 +1,34 @@ -/* Module suncalc.js +/* (c) 2011-2015, Vladimir Agafonkin SunCalc is a JavaScript library for calculating sun/moon position and light phases. https://github.com/mourner/suncalc -PB: Usage: -E.setTimeZone(2); // 1 = MEZ, 2 = MESZ -SunCalc = require("suncalc.js"); -pos = SunCalc.getPosition(Date.now(), 53.3, 10.1); -times = SunCalc.getTimes(Date.now(), 53.3, 10.1); -rise = times.sunrise; // Date object -rise_str = rise.getHours() + ':' + rise.getMinutes(); //hh:mm +Copyright (c) 2014, Vladimir Agafonkin +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list + of conditions and the following disclaimer in the documentation and/or other materials + provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ -var exports={}; + +(function () { 'use strict'; // shortcuts for easier to read formulas @@ -26,6 +43,7 @@ var PI = Math.PI, // sun calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas + // date/time constants and conversions var dayMs = 1000 * 60 * 60 * 24, @@ -33,7 +51,7 @@ var dayMs = 1000 * 60 * 60 * 24, J2000 = 2451545; function toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; } -function fromJulian(j) { return new Date((j + 0.5 - J1970) * dayMs); } // PB: onece removed + 0.5; included it again 4 Jan 2021 +function fromJulian(j) { return new Date((j + 0.5 - J1970) * dayMs); } function toDays(date) { return toJulian(date) - J2000; } @@ -81,9 +99,13 @@ function sunCoords(d) { }; } + +var SunCalc = {}; + + // calculates sun position for a given date and latitude/longitude -exports.getPosition = function (date, lat, lng) { +SunCalc.getPosition = function (date, lat, lng) { var lw = rad * -lng, phi = rad * lat, @@ -93,19 +115,32 @@ exports.getPosition = function (date, lat, lng) { H = siderealTime(d, lw) - c.ra; return { - azimuth: Math.round((azimuth(H, phi, c.dec) / rad + 180) % 360), // PB: converted to deg - altitude: Math.round( altitude(H, phi, c.dec) / rad) // PB: converted to deg + azimuth: azimuth(H, phi, c.dec), + altitude: altitude(H, phi, c.dec) }; }; // sun times configuration (angle, morning name, evening name) -var times = [ - [-0.833, 'sunrise', 'sunset' ] +var times = SunCalc.times = [ + [-0.833, 'sunrise', 'sunset' ], + [ -0.3, 'sunriseEnd', 'sunsetStart' ], + [ -6, 'dawn', 'dusk' ], + [ -12, 'nauticalDawn', 'nauticalDusk'], + [ -18, 'nightEnd', 'night' ], + [ 6, 'goldenHourEnd', 'goldenHour' ] ]; +// adds a custom time to the times config + +SunCalc.addTime = function (angle, riseName, setName) { + times.push([angle, riseName, setName]); +}; + + // calculations for sun times + var J0 = 0.0009; function julianCycle(d, lw) { return Math.round(d - J0 - lw / (2 * PI)); } @@ -128,7 +163,7 @@ function getSetJ(h, lw, phi, dec, n, M, L) { // calculates sun times for a given date, latitude/longitude, and, optionally, // the observer height (in meters) relative to the horizon -exports.getTimes = function (date, lat, lng, height) { +SunCalc.getTimes = function (date, lat, lng, height) { height = height || 0; @@ -189,7 +224,7 @@ function moonCoords(d) { // geocentric ecliptic coordinates of the moon }; } -getMoonPosition = function (date, lat, lng) { +SunCalc.getMoonPosition = function (date, lat, lng) { var lw = rad * -lng, phi = rad * lat, @@ -216,7 +251,7 @@ getMoonPosition = function (date, lat, lng) { // based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/mphase.pro formulas and // Chapter 48 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998. -getMoonIllumination = function (date) { +SunCalc.getMoonIllumination = function (date) { var d = toDays(date || new Date()), s = sunCoords(d), @@ -243,8 +278,8 @@ function hoursLater(date, h) { // calculations for moon rise/set times are based on http://www.stargazing.net/kepler/moonrise.html article -getMoonTimes = function (date, lat, lng, inUTC) { - var t = new Date(date); +SunCalc.getMoonTimes = function (date, lat, lng, inUTC) { + var t = typeof(date) === "object" ? date : new Date(date); if (inUTC) t.setUTCHours(0, 0, 0, 0); else t.setHours(0, 0, 0, 0); @@ -295,4 +330,12 @@ getMoonTimes = function (date, lat, lng, inUTC) { if (!rise && !set) result[ye > 0 ? 'alwaysUp' : 'alwaysDown'] = true; return result; -}; \ No newline at end of file +}; + + +// export as Node module / AMD module / browser variable +if (typeof exports === 'object' && typeof module !== 'undefined') module.exports = SunCalc; +else if (typeof define === 'function' && define.amd) define(SunCalc); +else window.SunCalc = SunCalc; + +}()); diff --git a/modules/wear_detect.js b/modules/wear_detect.js new file mode 100644 index 000000000..9581657cf --- /dev/null +++ b/modules/wear_detect.js @@ -0,0 +1,18 @@ +/** Returns a promise that resolves with whether the Bangle +is worn or not. + +Usage: + +require("wear_detect").isWorn().then(worn => { + console.log(worn ? "is worn" : "not worn"); +}); +*/ +exports.isWorn = function() { + return new Promise(resolve => { + if (Bangle.isCharging()) + return resolve(false); + if (Bangle.getHealthStatus().movement > 124) + return resolve(true); + return resolve(false); + }); +}; diff --git a/modules/widget_utils.js b/modules/widget_utils.js new file mode 100644 index 000000000..154a95f68 --- /dev/null +++ b/modules/widget_utils.js @@ -0,0 +1,148 @@ +/// hide any visible widgets +exports.hide = function() { + exports.cleanup(); + if (!global.WIDGETS) return; + g.reset(); // reset colors + for (var w of global.WIDGETS) { + if (w._draw) return; // already hidden + w._draw = w.draw; + w.draw = () => {}; + w._area = w.area; + w.area = ""; + if (w.x!=undefined) g.clearRect(w.x,w.y,w.x+w.width-1,w.y+23); + } +}; + +/// Show any hidden widgets +exports.show = function() { + exports.cleanup(); + if (!global.WIDGETS) return; + for (var w of global.WIDGETS) { + if (!w._draw) return; // not hidden + w.draw = w._draw; + w.area = w._area; + delete w._draw; + delete w._area; + w.draw(w); + } +}; + +/// Remove any intervals/handlers/etc that we might have added. Does NOT re-show widgets that were hidden +exports.cleanup = function() { + delete exports.autohide; + delete Bangle.appRect; + if (exports.swipeHandler) { + Bangle.removeListener("swipe", exports.swipeHandler); + delete exports.swipeHandler; + } + if (exports.animInterval) { + clearInterval(exports.animInterval); + delete exports.animInterval; + } + if (exports.hideTimeout) { + clearTimeout(exports.hideTimeout); + delete exports.hideTimeout; + } + if (exports.origDraw) { + Bangle.drawWidgets = exports.origDraw; + delete exports.origDraw; + } +} + +/** Put widgets offscreen, and allow them to be swiped +back onscreen with a downwards swipe. Use .show to undo. +First parameter controls automatic hiding time, 0 equals not hiding at all. +Default value is 2000ms until hiding. +Bangle.js 2 only at the moment. On Bangle.js 1 widgets will be hidden permanently. + +Note: On Bangle.js 1 is is possible to draw widgets in an offscreen area of the LCD +and use Bangle.setLCDOffset. However we can't detect a downward swipe so how to +actually make this work needs some thought. +*/ +exports.swipeOn = function(autohide) { + if (process.env.HWVERSION!==2) return exports.hide(); + exports.cleanup(); + if (!global.WIDGETS) return; + exports.autohide=autohide===undefined?2000:autohide; + /* TODO: maybe when widgets are offscreen we don't even + store them in an offscreen buffer? */ + + // force app rect to be fullscreen + Bangle.appRect = { x: 0, y: 0, w: g.getWidth(), h: g.getHeight(), x2: g.getWidth()-1, y2: g.getHeight()-1 }; + // setup offscreen graphics for widgets + let og = Graphics.createArrayBuffer(g.getWidth(),24,16,{msb:true}); + og.theme = g.theme; + og._reset = og.reset; + og.reset = function() { + return this._reset().setColor(g.theme.fg).setBgColor(g.theme.bg); + }; + og.reset().clearRect(0,0,og.getWidth(),og.getHeight()); + let _g = g; + let offset = -24; // where on the screen are we? -24=hidden, 0=full visible + + function queueDraw() { + Bangle.appRect.y = offset+24; + Bangle.appRect.h = 1 + Bangle.appRect.y2 - Bangle.appRect.y; + if (offset>-24) Bangle.setLCDOverlay(og, 0, offset); + else Bangle.setLCDOverlay(); + } + + for (var w of global.WIDGETS) { + if (w._draw) return; // already hidden + w._draw = w.draw; + w.draw = function() { + g=og; + this._draw(this); + g=_g; + if (offset>-24) queueDraw(); + }; + w._area = w.area; + if (w.area.startsWith("b")) + w.area = "t"+w.area.substr(1); + } + + exports.origDraw = Bangle.drawWidgets; + Bangle.drawWidgets = ()=>{ + g=og; + exports.origDraw(); + g=_g; + }; + + function anim(dir, callback) { + if (exports.animInterval) clearInterval(exports.interval); + exports.animInterval = setInterval(function() { + offset += dir; + let stop = false; + if (dir>0 && offset>=0) { // fully down + stop = true; + offset = 0; + } else if (dir<0 && offset<-23) { // fully up + stop = true; + offset = -24; + } + if (stop) { + clearInterval(exports.animInterval); + delete exports.animInterval; + if (callback) callback(); + } + queueDraw(); + }, 50); + } + // On swipe down, animate to show widgets + exports.swipeHandler = function(lr,ud) { + if (exports.hideTimeout) { + clearTimeout(exports.hideTimeout); + delete exports.hideTimeout; + } + let cb; + if (exports.autohide > 0) cb = function() { + exports.hideTimeout = setTimeout(function() { + anim(-4); + }, exports.autohide); + } + if (ud>0 && offset<0) anim(4, cb); + if (ud<0 && offset>-24) anim(-4); + + }; + Bangle.on("swipe", exports.swipeHandler); +}; diff --git a/package-lock.json b/package-lock.json index 878b45cb2..e981abdb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,2913 +1,8 @@ { "name": "BangleApps", "version": "0.0.1", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "BangleApps", - "version": "0.0.1", - "license": "MIT", - "dependencies": { - "acorn": "^7.2.0" - }, - "devDependencies": { - "eslint": "^8.14.0", - "eslint-config-airbnb-base": "^15.0.0", - "eslint-plugin-import": "^2.26.0", - "npm-watch": "^0.11.0" - } - }, - "node_modules/@eslint/eslintrc": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", - "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", - "dev": true, - "dependencies": { - "ajv": "^6.12.4", - "debug": "^4.3.2", - "espree": "^9.3.2", - "globals": "^13.15.0", - "ignore": "^5.2.0", - "import-fresh": "^3.2.1", - "js-yaml": "^4.1.0", - "minimatch": "^3.1.2", - "strip-json-comments": "^3.1.1" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/@humanwhocodes/config-array": { - "version": "0.9.5", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", - "integrity": "sha512-ObyMyWxZiCu/yTisA7uzx81s40xR2fD5Cg/2Kq7G02ajkNubJf6BopgDTmDyc3U7sXpNKM8cYOw7s7Tyr+DnCw==", - "dev": true, - "dependencies": { - "@humanwhocodes/object-schema": "^1.2.1", - "debug": "^4.1.1", - "minimatch": "^3.0.4" - }, - "engines": { - "node": ">=10.10.0" - } - }, - "node_modules/@humanwhocodes/object-schema": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", - "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", - "dev": true - }, - "node_modules/@sindresorhus/is": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", - "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/@szmarczak/http-timer": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", - "integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==", - "dev": true, - "dependencies": { - "defer-to-connect": "^1.0.1" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/@types/json5": { - "version": "0.0.29", - "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", - "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", - "dev": true - }, - "node_modules/abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", - "dev": true - }, - "node_modules/acorn": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", - "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/acorn-jsx": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", - "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "peerDependencies": { - "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" - } - }, - "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/ansi-align": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", - "integrity": "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==", - "dev": true, - "dependencies": { - "string-width": "^4.1.0" - } - }, - "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/anymatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", - "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", - "dev": true, - "dependencies": { - "normalize-path": "^3.0.0", - "picomatch": "^2.0.4" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, - "node_modules/array-includes": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.5.tgz", - "integrity": "sha512-iSDYZMMyTPkiFasVqfuAQnWAYcvO/SeBSCGKePoEthjp4LEMTe4uLc7b025o4jAZpHhihh8xPo99TNWUWWkGDQ==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.4", - "es-abstract": "^1.19.5", - "get-intrinsic": "^1.1.1", - "is-string": "^1.0.7" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/array.prototype.flat": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.0.tgz", - "integrity": "sha512-12IUEkHsAhA4DY5s0FPgNXIdc8VRSqD9Zp78a5au9abH/SOBrsp082JOWFNTjkMozh8mqcdiKuaLGhPeYztxSw==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.2", - "es-shim-unscopables": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true - }, - "node_modules/binary-extensions": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", - "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/boxen": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/boxen/-/boxen-5.1.2.tgz", - "integrity": "sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ==", - "dev": true, - "dependencies": { - "ansi-align": "^3.0.0", - "camelcase": "^6.2.0", - "chalk": "^4.1.0", - "cli-boxes": "^2.2.1", - "string-width": "^4.2.2", - "type-fest": "^0.20.2", - "widest-line": "^3.1.0", - "wrap-ansi": "^7.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, - "dependencies": { - "fill-range": "^7.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/cacheable-request": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", - "integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==", - "dev": true, - "dependencies": { - "clone-response": "^1.0.2", - "get-stream": "^5.1.0", - "http-cache-semantics": "^4.0.0", - "keyv": "^3.0.0", - "lowercase-keys": "^2.0.0", - "normalize-url": "^4.1.0", - "responselike": "^1.0.2" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/cacheable-request/node_modules/get-stream": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", - "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", - "dev": true, - "dependencies": { - "pump": "^3.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/cacheable-request/node_modules/lowercase-keys": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", - "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/call-bind": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", - "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/camelcase": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", - "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/chokidar": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", - "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", - "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ], - "dependencies": { - "anymatch": "~3.1.2", - "braces": "~3.0.2", - "glob-parent": "~5.1.2", - "is-binary-path": "~2.1.0", - "is-glob": "~4.0.1", - "normalize-path": "~3.0.0", - "readdirp": "~3.6.0" - }, - "engines": { - "node": ">= 8.10.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.2" - } - }, - "node_modules/chokidar/node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/ci-info": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", - "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", - "dev": true - }, - "node_modules/cli-boxes": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-2.2.1.tgz", - "integrity": "sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==", - "dev": true, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/clone-response": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", - "integrity": "sha512-yjLXh88P599UOyPTFX0POsd7WxnbsVsGohcwzHOLspIhhpalPw1BcqED8NblyZLKcGrL8dTgMlcaZxV2jAD41Q==", - "dev": true, - "dependencies": { - "mimic-response": "^1.0.0" - } - }, - "node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true - }, - "node_modules/configstore": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz", - "integrity": "sha512-aMKprgk5YhBNyH25hj8wGt2+D52Sw1DRRIzqBwLp2Ya9mFmY8KPvvtvmna8SxVR9JMZ4kzMD68N22vlaRpkeFA==", - "dev": true, - "dependencies": { - "dot-prop": "^5.2.0", - "graceful-fs": "^4.1.2", - "make-dir": "^3.0.0", - "unique-string": "^2.0.0", - "write-file-atomic": "^3.0.0", - "xdg-basedir": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/confusing-browser-globals": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz", - "integrity": "sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==", - "dev": true - }, - "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, - "dependencies": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/crypto-random-string": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", - "integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, - "dependencies": { - "ms": "2.1.2" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/decompress-response": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", - "integrity": "sha512-BzRPQuY1ip+qDonAOz42gRm/pg9F768C+npV/4JOsxRC2sq+Rlk+Q4ZCAsOhnIaMrgarILY+RMUIvMmmX1qAEA==", - "dev": true, - "dependencies": { - "mimic-response": "^1.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "dev": true, - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/deep-is": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", - "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", - "dev": true - }, - "node_modules/defer-to-connect": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz", - "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", - "dev": true - }, - "node_modules/define-properties": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", - "integrity": "sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==", - "dev": true, - "dependencies": { - "has-property-descriptors": "^1.0.0", - "object-keys": "^1.1.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "dev": true, - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/dot-prop": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", - "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", - "dev": true, - "dependencies": { - "is-obj": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/duplexer3": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", - "integrity": "sha512-CEj8FwwNA4cVH2uFCoHUrmojhYh1vmCdOaneKJXwkeY1i9jnlslVo9dx+hQ5Hl9GnH/Bwy/IjxAyOePyPKYnzA==", - "dev": true - }, - "node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true - }, - "node_modules/end-of-stream": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", - "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, - "dependencies": { - "once": "^1.4.0" - } - }, - "node_modules/es-abstract": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz", - "integrity": "sha512-WEm2oBhfoI2sImeM4OF2zE2V3BYdSF+KnSi9Sidz51fQHd7+JuF8Xgcj9/0o+OWeIeIS/MiuNnlruQrJf16GQA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "es-to-primitive": "^1.2.1", - "function-bind": "^1.1.1", - "function.prototype.name": "^1.1.5", - "get-intrinsic": "^1.1.1", - "get-symbol-description": "^1.0.0", - "has": "^1.0.3", - "has-property-descriptors": "^1.0.0", - "has-symbols": "^1.0.3", - "internal-slot": "^1.0.3", - "is-callable": "^1.2.4", - "is-negative-zero": "^2.0.2", - "is-regex": "^1.1.4", - "is-shared-array-buffer": "^1.0.2", - "is-string": "^1.0.7", - "is-weakref": "^1.0.2", - "object-inspect": "^1.12.0", - "object-keys": "^1.1.1", - "object.assign": "^4.1.2", - "regexp.prototype.flags": "^1.4.3", - "string.prototype.trimend": "^1.0.5", - "string.prototype.trimstart": "^1.0.5", - "unbox-primitive": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/es-shim-unscopables": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz", - "integrity": "sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==", - "dev": true, - "dependencies": { - "has": "^1.0.3" - } - }, - "node_modules/es-to-primitive": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", - "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", - "dev": true, - "dependencies": { - "is-callable": "^1.1.4", - "is-date-object": "^1.0.1", - "is-symbol": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/escape-goat": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", - "integrity": "sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint": { - "version": "8.17.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.17.0.tgz", - "integrity": "sha512-gq0m0BTJfci60Fz4nczYxNAlED+sMcihltndR8t9t1evnU/azx53x3t2UHXC/uRjcbvRw/XctpaNygSTcQD+Iw==", - "dev": true, - "dependencies": { - "@eslint/eslintrc": "^1.3.0", - "@humanwhocodes/config-array": "^0.9.2", - "ajv": "^6.10.0", - "chalk": "^4.0.0", - "cross-spawn": "^7.0.2", - "debug": "^4.3.2", - "doctrine": "^3.0.0", - "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.1.1", - "eslint-utils": "^3.0.0", - "eslint-visitor-keys": "^3.3.0", - "espree": "^9.3.2", - "esquery": "^1.4.0", - "esutils": "^2.0.2", - "fast-deep-equal": "^3.1.3", - "file-entry-cache": "^6.0.1", - "functional-red-black-tree": "^1.0.1", - "glob-parent": "^6.0.1", - "globals": "^13.15.0", - "ignore": "^5.2.0", - "import-fresh": "^3.0.0", - "imurmurhash": "^0.1.4", - "is-glob": "^4.0.0", - "js-yaml": "^4.1.0", - "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", - "lodash.merge": "^4.6.2", - "minimatch": "^3.1.2", - "natural-compare": "^1.4.0", - "optionator": "^0.9.1", - "regexpp": "^3.2.0", - "strip-ansi": "^6.0.1", - "strip-json-comments": "^3.1.0", - "text-table": "^0.2.0", - "v8-compile-cache": "^2.0.3" - }, - "bin": { - "eslint": "bin/eslint.js" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint-config-airbnb-base": { - "version": "15.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-15.0.0.tgz", - "integrity": "sha512-xaX3z4ZZIcFLvh2oUNvcX5oEofXda7giYmuplVxoOg5A7EXJMrUyqRgR+mhDhPK8LZ4PttFOBvCYDbX3sUoUig==", - "dev": true, - "dependencies": { - "confusing-browser-globals": "^1.0.10", - "object.assign": "^4.1.2", - "object.entries": "^1.1.5", - "semver": "^6.3.0" - }, - "engines": { - "node": "^10.12.0 || >=12.0.0" - }, - "peerDependencies": { - "eslint": "^7.32.0 || ^8.2.0", - "eslint-plugin-import": "^2.25.2" - } - }, - "node_modules/eslint-import-resolver-node": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz", - "integrity": "sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw==", - "dev": true, - "dependencies": { - "debug": "^3.2.7", - "resolve": "^1.20.0" - } - }, - "node_modules/eslint-import-resolver-node/node_modules/debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", - "dev": true, - "dependencies": { - "ms": "^2.1.1" - } - }, - "node_modules/eslint-module-utils": { - "version": "2.7.3", - "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.3.tgz", - "integrity": "sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==", - "dev": true, - "dependencies": { - "debug": "^3.2.7", - "find-up": "^2.1.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/eslint-module-utils/node_modules/debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", - "dev": true, - "dependencies": { - "ms": "^2.1.1" - } - }, - "node_modules/eslint-plugin-import": { - "version": "2.26.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz", - "integrity": "sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==", - "dev": true, - "dependencies": { - "array-includes": "^3.1.4", - "array.prototype.flat": "^1.2.5", - "debug": "^2.6.9", - "doctrine": "^2.1.0", - "eslint-import-resolver-node": "^0.3.6", - "eslint-module-utils": "^2.7.3", - "has": "^1.0.3", - "is-core-module": "^2.8.1", - "is-glob": "^4.0.3", - "minimatch": "^3.1.2", - "object.values": "^1.1.5", - "resolve": "^1.22.0", - "tsconfig-paths": "^3.14.1" - }, - "engines": { - "node": ">=4" - }, - "peerDependencies": { - "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" - } - }, - "node_modules/eslint-plugin-import/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/eslint-plugin-import/node_modules/doctrine": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", - "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", - "dev": true, - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/eslint-plugin-import/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true - }, - "node_modules/eslint-scope": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", - "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", - "dev": true, - "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^5.2.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/eslint-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", - "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", - "dev": true, - "dependencies": { - "eslint-visitor-keys": "^2.0.0" - }, - "engines": { - "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/mysticatea" - }, - "peerDependencies": { - "eslint": ">=5" - } - }, - "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", - "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/eslint-visitor-keys": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", - "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", - "dev": true, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/espree": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", - "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", - "dev": true, - "dependencies": { - "acorn": "^8.7.1", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.3.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/espree/node_modules/acorn": { - "version": "8.7.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", - "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", - "dev": true, - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/esquery": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", - "integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", - "dev": true, - "dependencies": { - "estraverse": "^5.1.0" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/esrecurse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", - "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", - "dev": true, - "dependencies": { - "estraverse": "^5.2.0" - }, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/estraverse": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", - "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/esutils": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", - "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true - }, - "node_modules/fast-json-stable-stringify": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true - }, - "node_modules/fast-levenshtein": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", - "dev": true - }, - "node_modules/file-entry-cache": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", - "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", - "dev": true, - "dependencies": { - "flat-cache": "^3.0.4" - }, - "engines": { - "node": "^10.12.0 || >=12.0.0" - } - }, - "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, - "dependencies": { - "to-regex-range": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha512-NWzkk0jSJtTt08+FBFMvXoeZnOJD+jTtsRmBYbAIzJdX6l7dLgR7CTubCM5/eDdPUBvLCeVasP1brfVR/9/EZQ==", - "dev": true, - "dependencies": { - "locate-path": "^2.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/flat-cache": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", - "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", - "dev": true, - "dependencies": { - "flatted": "^3.1.0", - "rimraf": "^3.0.2" - }, - "engines": { - "node": "^10.12.0 || >=12.0.0" - } - }, - "node_modules/flatted": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.5.tgz", - "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", - "dev": true - }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true - }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, - "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true - }, - "node_modules/function.prototype.name": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.5.tgz", - "integrity": "sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.0", - "functions-have-names": "^1.2.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/functional-red-black-tree": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", - "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==", - "dev": true - }, - "node_modules/functions-have-names": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", - "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-intrinsic": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz", - "integrity": "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, - "dependencies": { - "pump": "^3.0.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/get-symbol-description": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.0.tgz", - "integrity": "sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/glob-parent": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", - "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.3" - }, - "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/global-dirs": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.0.tgz", - "integrity": "sha512-v8ho2DS5RiCjftj1nD9NmnfaOzTdud7RRnVd9kFNOjqZbISlx5DQ+OrTkywgd0dIt7oFCvKetZSHoHcP3sDdiA==", - "dev": true, - "dependencies": { - "ini": "2.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/globals": { - "version": "13.15.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", - "integrity": "sha512-bpzcOlgDhMG070Av0Vy5Owklpv1I6+j96GhUI7Rh7IzDCKLzboflLrrfqMu8NquDbiR4EOQk7XzJwqVJxicxog==", - "dev": true, - "dependencies": { - "type-fest": "^0.20.2" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/got": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", - "integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", - "dev": true, - "dependencies": { - "@sindresorhus/is": "^0.14.0", - "@szmarczak/http-timer": "^1.1.2", - "cacheable-request": "^6.0.0", - "decompress-response": "^3.3.0", - "duplexer3": "^0.1.4", - "get-stream": "^4.1.0", - "lowercase-keys": "^1.0.1", - "mimic-response": "^1.0.1", - "p-cancelable": "^1.0.0", - "to-readable-stream": "^1.0.0", - "url-parse-lax": "^3.0.0" - }, - "engines": { - "node": ">=8.6" - } - }, - "node_modules/graceful-fs": { - "version": "4.2.10", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", - "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", - "dev": true - }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1" - }, - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/has-bigints": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", - "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/has-property-descriptors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", - "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", - "dev": true, - "dependencies": { - "get-intrinsic": "^1.1.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-tostringtag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", - "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", - "dev": true, - "dependencies": { - "has-symbols": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-yarn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/has-yarn/-/has-yarn-2.1.0.tgz", - "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==", - "dev": true - }, - "node_modules/ignore": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", - "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", - "dev": true, - "engines": { - "node": ">= 4" - } - }, - "node_modules/ignore-by-default": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", - "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", - "dev": true - }, - "node_modules/import-fresh": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", - "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", - "dev": true, - "dependencies": { - "parent-module": "^1.0.0", - "resolve-from": "^4.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/import-lazy": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-2.1.0.tgz", - "integrity": "sha512-m7ZEHgtw69qOGw+jwxXkHlrlIPdTGkyh66zXZ1ajZbxkDBNjSY/LGbmjc7h0s2ELsUDTAhFr55TrPSSqJGPG0A==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/imurmurhash": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", - "dev": true, - "engines": { - "node": ">=0.8.19" - } - }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "dev": true, - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true - }, - "node_modules/ini": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz", - "integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/internal-slot": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz", - "integrity": "sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==", - "dev": true, - "dependencies": { - "get-intrinsic": "^1.1.0", - "has": "^1.0.3", - "side-channel": "^1.0.4" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/is-bigint": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", - "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", - "dev": true, - "dependencies": { - "has-bigints": "^1.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-binary-path": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", - "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, - "dependencies": { - "binary-extensions": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-boolean-object": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", - "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-callable": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz", - "integrity": "sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-ci": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", - "integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==", - "dev": true, - "dependencies": { - "ci-info": "^2.0.0" - }, - "bin": { - "is-ci": "bin.js" - } - }, - "node_modules/is-core-module": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.9.0.tgz", - "integrity": "sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==", - "dev": true, - "dependencies": { - "has": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-date-object": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", - "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", - "dev": true, - "dependencies": { - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-glob": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", - "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, - "dependencies": { - "is-extglob": "^2.1.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-installed-globally": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.4.0.tgz", - "integrity": "sha512-iwGqO3J21aaSkC7jWnHP/difazwS7SFeIqxv6wEtLU8Y5KlzFTjyqcSIT0d8s4+dDhKytsk9PJZ2BkS5eZwQRQ==", - "dev": true, - "dependencies": { - "global-dirs": "^3.0.0", - "is-path-inside": "^3.0.2" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-negative-zero": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", - "integrity": "sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-npm": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-5.0.0.tgz", - "integrity": "sha512-WW/rQLOazUq+ST/bCAVBp/2oMERWLsR7OrKyt052dNDk4DHcDE0/7QSXITlmi+VBcV13DfIbysG3tZJm5RfdBA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, - "engines": { - "node": ">=0.12.0" - } - }, - "node_modules/is-number-object": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", - "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", - "dev": true, - "dependencies": { - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-obj": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", - "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-path-inside": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", - "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-regex": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", - "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-shared-array-buffer": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz", - "integrity": "sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-string": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", - "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", - "dev": true, - "dependencies": { - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-symbol": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", - "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", - "dev": true, - "dependencies": { - "has-symbols": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", - "dev": true - }, - "node_modules/is-weakref": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-weakref/-/is-weakref-1.0.2.tgz", - "integrity": "sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-yarn-global": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz", - "integrity": "sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw==", - "dev": true - }, - "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true - }, - "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, - "node_modules/json-buffer": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", - "integrity": "sha512-CuUqjv0FUZIdXkHPI8MezCnFCdaTAacej1TZYulLoAg1h/PhwkdXFN4V/gzY4g+fMBCOV2xF+rp7t2XD2ns/NQ==", - "dev": true - }, - "node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true - }, - "node_modules/json-stable-stringify-without-jsonify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", - "dev": true - }, - "node_modules/json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, - "dependencies": { - "minimist": "^1.2.0" - }, - "bin": { - "json5": "lib/cli.js" - } - }, - "node_modules/keyv": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", - "integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", - "dev": true, - "dependencies": { - "json-buffer": "3.0.0" - } - }, - "node_modules/latest-version": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", - "integrity": "sha512-weT+r0kTkRQdCdYCNtkMwWXQTMEswKrFBkm4ckQOMVhhqhIMI1UT2hMj+1iigIhgSZm5gTmrRXBNoGUgaTY1xA==", - "dev": true, - "dependencies": { - "package-json": "^6.3.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/levn": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", - "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", - "dev": true, - "dependencies": { - "prelude-ls": "^1.2.1", - "type-check": "~0.4.0" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/locate-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", - "integrity": "sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==", - "dev": true, - "dependencies": { - "p-locate": "^2.0.0", - "path-exists": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/lodash.merge": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true - }, - "node_modules/lowercase-keys": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", - "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "dev": true, - "dependencies": { - "semver": "^6.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/mimic-response": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true - }, - "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, - "node_modules/natural-compare": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", - "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", - "dev": true - }, - "node_modules/nodemon": { - "version": "2.0.16", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.16.tgz", - "integrity": "sha512-zsrcaOfTWRuUzBn3P44RDliLlp263Z/76FPoHFr3cFFkOz0lTPAcIw8dCzfdVIx/t3AtDYCZRCDkoCojJqaG3w==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "chokidar": "^3.5.2", - "debug": "^3.2.7", - "ignore-by-default": "^1.0.1", - "minimatch": "^3.0.4", - "pstree.remy": "^1.1.8", - "semver": "^5.7.1", - "supports-color": "^5.5.0", - "touch": "^3.1.0", - "undefsafe": "^2.0.5", - "update-notifier": "^5.1.0" - }, - "bin": { - "nodemon": "bin/nodemon.js" - }, - "engines": { - "node": ">=8.10.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/nodemon" - } - }, - "node_modules/nodemon/node_modules/debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", - "dev": true, - "dependencies": { - "ms": "^2.1.1" - } - }, - "node_modules/nodemon/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/nodemon/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true, - "bin": { - "semver": "bin/semver" - } - }, - "node_modules/nodemon/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/nopt": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", - "integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==", - "dev": true, - "dependencies": { - "abbrev": "1" - }, - "bin": { - "nopt": "bin/nopt.js" - }, - "engines": { - "node": "*" - } - }, - "node_modules/normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/normalize-url": { - "version": "4.5.1", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz", - "integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/npm-watch": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/npm-watch/-/npm-watch-0.11.0.tgz", - "integrity": "sha512-wAOd0moNX2kSA2FNvt8+7ORwYaJpQ1ZoWjUYdb1bBCxq4nkWuU0IiJa9VpVxrj5Ks+FGXQd62OC/Bjk0aSr+dg==", - "dev": true, - "dependencies": { - "nodemon": "^2.0.7", - "through2": "^4.0.2" - }, - "bin": { - "npm-watch": "cli.js" - } - }, - "node_modules/object-inspect": { - "version": "1.12.2", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", - "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/object.assign": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", - "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.0", - "define-properties": "^1.1.3", - "has-symbols": "^1.0.1", - "object-keys": "^1.1.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/object.entries": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.5.tgz", - "integrity": "sha512-TyxmjUoZggd4OrrU1W66FMDG6CuqJxsFvymeyXI51+vQLN67zYfZseptRge703kKQdo4uccgAKebXFcRCzk4+g==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/object.values": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.5.tgz", - "integrity": "sha512-QUZRW0ilQ3PnPpbNtgdNV1PDbEqLIiSFB3l+EnGtBQ/8SUTLj1PZwtQHABZtLgwpJZTSZhuGLOGk57Drx2IvYg==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/optionator": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", - "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", - "dev": true, - "dependencies": { - "deep-is": "^0.1.3", - "fast-levenshtein": "^2.0.6", - "levn": "^0.4.1", - "prelude-ls": "^1.2.1", - "type-check": "^0.4.0", - "word-wrap": "^1.2.3" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/p-cancelable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", - "integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/p-limit": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", - "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", - "dev": true, - "dependencies": { - "p-try": "^1.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/p-locate": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", - "integrity": "sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==", - "dev": true, - "dependencies": { - "p-limit": "^1.1.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/p-try": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", - "integrity": "sha512-U1etNYuMJoIz3ZXSrrySFjsXQTWOx2/jdi86L+2pRvph/qMKL6sbcCYdH23fqsbm8TH2Gn0OybpT4eSFlCVHww==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/package-json": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/package-json/-/package-json-6.5.0.tgz", - "integrity": "sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==", - "dev": true, - "dependencies": { - "got": "^9.6.0", - "registry-auth-token": "^4.0.0", - "registry-url": "^5.0.0", - "semver": "^6.2.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/parent-module": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", - "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, - "dependencies": { - "callsites": "^3.0.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true - }, - "node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, - "engines": { - "node": ">=8.6" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, - "node_modules/prelude-ls": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", - "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", - "dev": true, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/prepend-http": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", - "integrity": "sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/pstree.remy": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", - "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", - "dev": true - }, - "node_modules/pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, - "dependencies": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "node_modules/punycode": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/pupa": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/pupa/-/pupa-2.1.1.tgz", - "integrity": "sha512-l1jNAspIBSFqbT+y+5FosojNpVpF94nlI+wDUpqP9enwOTfHx9f0gh5nB96vl+6yTpsJsypeNrwfzPrKuHB41A==", - "dev": true, - "dependencies": { - "escape-goat": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "dev": true, - "dependencies": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - }, - "bin": { - "rc": "cli.js" - } - }, - "node_modules/rc/node_modules/ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "dev": true - }, - "node_modules/rc/node_modules/strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/readdirp": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", - "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", - "dev": true, - "dependencies": { - "picomatch": "^2.2.1" - }, - "engines": { - "node": ">=8.10.0" - } - }, - "node_modules/regexp.prototype.flags": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz", - "integrity": "sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "functions-have-names": "^1.2.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/regexpp": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", - "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/mysticatea" - } - }, - "node_modules/registry-auth-token": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-4.2.1.tgz", - "integrity": "sha512-6gkSb4U6aWJB4SF2ZvLb76yCBjcvufXBqvvEx1HbmKPkutswjW1xNVRY0+daljIYRbogN7O0etYSlbiaEQyMyw==", - "dev": true, - "dependencies": { - "rc": "^1.2.8" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/registry-url": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/registry-url/-/registry-url-5.1.0.tgz", - "integrity": "sha512-8acYXXTI0AkQv6RAOjE3vOaIXZkT9wo4LOFbBKYQEEnnMNBpKqdUrI6S4NT0KPIo/WVvJ5tE/X5LF/TQUf0ekw==", - "dev": true, - "dependencies": { - "rc": "^1.2.8" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/resolve": { - "version": "1.22.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz", - "integrity": "sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==", - "dev": true, - "dependencies": { - "is-core-module": "^2.8.1", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - }, - "bin": { - "resolve": "bin/resolve" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/resolve-from": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/responselike": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", - "integrity": "sha512-/Fpe5guzJk1gPqdJLJR5u7eG/gNY4nImjbRDaVWVMRhne55TCmj2i9Q+54PBRfatRC8v/rIiv9BN0pMd9OV5EQ==", - "dev": true, - "dependencies": { - "lowercase-keys": "^1.0.0" - } - }, - "node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true, - "bin": { - "semver": "bin/semver.js" - } - }, - "node_modules/semver-diff": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-3.1.1.tgz", - "integrity": "sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg==", - "dev": true, - "dependencies": { - "semver": "^6.3.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/shebang-command": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", - "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, - "dependencies": { - "shebang-regex": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/shebang-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/side-channel": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", - "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true - }, - "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dev": true, - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, - "node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/string.prototype.trimend": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz", - "integrity": "sha512-I7RGvmjV4pJ7O3kdf+LXFpVfdNOxtCW/2C8f6jNiW4+PQchwxkCDzlk1/7p+Wl4bqFIZeF47qAHXLuHHWKAxog==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.4", - "es-abstract": "^1.19.5" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/string.prototype.trimstart": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.5.tgz", - "integrity": "sha512-THx16TJCGlsN0o6dl2o6ncWUsdgnLRSA23rRE5pyGBw/mLr3Ej/R2LaqCtgP8VNMGZsvMWnf9ooZPyY2bHvUFg==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.4", - "es-abstract": "^1.19.5" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/strip-bom": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/supports-preserve-symlinks-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/text-table": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true - }, - "node_modules/through2": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/through2/-/through2-4.0.2.tgz", - "integrity": "sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==", - "dev": true, - "dependencies": { - "readable-stream": "3" - } - }, - "node_modules/to-readable-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", - "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, - "dependencies": { - "is-number": "^7.0.0" - }, - "engines": { - "node": ">=8.0" - } - }, - "node_modules/touch": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", - "integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", - "dev": true, - "dependencies": { - "nopt": "~1.0.10" - }, - "bin": { - "nodetouch": "bin/nodetouch.js" - } - }, - "node_modules/tsconfig-paths": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz", - "integrity": "sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==", - "dev": true, - "dependencies": { - "@types/json5": "^0.0.29", - "json5": "^1.0.1", - "minimist": "^1.2.6", - "strip-bom": "^3.0.0" - } - }, - "node_modules/type-check": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", - "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", - "dev": true, - "dependencies": { - "prelude-ls": "^1.2.1" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/typedarray-to-buffer": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", - "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", - "dev": true, - "dependencies": { - "is-typedarray": "^1.0.0" - } - }, - "node_modules/unbox-primitive": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", - "integrity": "sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "has-bigints": "^1.0.2", - "has-symbols": "^1.0.3", - "which-boxed-primitive": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/undefsafe": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", - "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", - "dev": true - }, - "node_modules/unique-string": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-2.0.0.tgz", - "integrity": "sha512-uNaeirEPvpZWSgzwsPGtU2zVSTrn/8L5q/IexZmH0eH6SA73CmAA5U4GwORTxQAZs95TAXLNqeLoPPNO5gZfWg==", - "dev": true, - "dependencies": { - "crypto-random-string": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/update-notifier": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-5.1.0.tgz", - "integrity": "sha512-ItnICHbeMh9GqUy31hFPrD1kcuZ3rpxDZbf4KUDavXwS0bW5m7SLbDQpGX3UYr072cbrF5hFUs3r5tUsPwjfHw==", - "dev": true, - "dependencies": { - "boxen": "^5.0.0", - "chalk": "^4.1.0", - "configstore": "^5.0.1", - "has-yarn": "^2.1.0", - "import-lazy": "^2.1.0", - "is-ci": "^2.0.0", - "is-installed-globally": "^0.4.0", - "is-npm": "^5.0.0", - "is-yarn-global": "^0.3.0", - "latest-version": "^5.1.0", - "pupa": "^2.1.1", - "semver": "^7.3.4", - "semver-diff": "^3.1.1", - "xdg-basedir": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/yeoman/update-notifier?sponsor=1" - } - }, - "node_modules/update-notifier/node_modules/semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/uri-js": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", - "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", - "dev": true, - "dependencies": { - "punycode": "^2.1.0" - } - }, - "node_modules/url-parse-lax": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", - "integrity": "sha512-NjFKA0DidqPa5ciFcSrXnAltTtzz84ogy+NebPvfEgAck0+TNg4UJ4IN+fB7zRZfbgUf0syOo9MDxFkDSMuFaQ==", - "dev": true, - "dependencies": { - "prepend-http": "^2.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true - }, - "node_modules/v8-compile-cache": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", - "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", - "dev": true - }, - "node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/which-boxed-primitive": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", - "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", - "dev": true, - "dependencies": { - "is-bigint": "^1.0.1", - "is-boolean-object": "^1.1.0", - "is-number-object": "^1.0.4", - "is-string": "^1.0.5", - "is-symbol": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/widest-line": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", - "integrity": "sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==", - "dev": true, - "dependencies": { - "string-width": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true - }, - "node_modules/write-file-atomic": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", - "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", - "dev": true, - "dependencies": { - "imurmurhash": "^0.1.4", - "is-typedarray": "^1.0.0", - "signal-exit": "^3.0.2", - "typedarray-to-buffer": "^3.1.5" - } - }, - "node_modules/xdg-basedir": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", - "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - } - }, "dependencies": { "@eslint/eslintrc": { "version": "1.3.0", @@ -2943,21 +38,6 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, - "@sindresorhus/is": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", - "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==", - "dev": true - }, - "@szmarczak/http-timer": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", - "integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==", - "dev": true, - "requires": { - "defer-to-connect": "^1.0.1" - } - }, "@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -2979,8 +59,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "requires": {} + "dev": true }, "ajv": { "version": "6.12.6", @@ -2994,15 +73,6 @@ "uri-js": "^4.2.2" } }, - "ansi-align": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", - "integrity": "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==", - "dev": true, - "requires": { - "string-width": "^4.1.0" - } - }, "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -3071,22 +141,6 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, - "boxen": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/boxen/-/boxen-5.1.2.tgz", - "integrity": "sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ==", - "dev": true, - "requires": { - "ansi-align": "^3.0.0", - "camelcase": "^6.2.0", - "chalk": "^4.1.0", - "cli-boxes": "^2.2.1", - "string-width": "^4.2.2", - "type-fest": "^0.20.2", - "widest-line": "^3.1.0", - "wrap-ansi": "^7.0.0" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -3106,38 +160,6 @@ "fill-range": "^7.0.1" } }, - "cacheable-request": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", - "integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==", - "dev": true, - "requires": { - "clone-response": "^1.0.2", - "get-stream": "^5.1.0", - "http-cache-semantics": "^4.0.0", - "keyv": "^3.0.0", - "lowercase-keys": "^2.0.0", - "normalize-url": "^4.1.0", - "responselike": "^1.0.2" - }, - "dependencies": { - "get-stream": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", - "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, - "lowercase-keys": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", - "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", - "dev": true - } - } - }, "call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -3154,12 +176,6 @@ "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true }, - "camelcase": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", - "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", - "dev": true - }, "chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -3197,27 +213,6 @@ } } }, - "ci-info": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", - "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", - "dev": true - }, - "cli-boxes": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-2.2.1.tgz", - "integrity": "sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==", - "dev": true - }, - "clone-response": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", - "integrity": "sha512-yjLXh88P599UOyPTFX0POsd7WxnbsVsGohcwzHOLspIhhpalPw1BcqED8NblyZLKcGrL8dTgMlcaZxV2jAD41Q==", - "dev": true, - "requires": { - "mimic-response": "^1.0.0" - } - }, "color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -3239,20 +234,6 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, - "configstore": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz", - "integrity": "sha512-aMKprgk5YhBNyH25hj8wGt2+D52Sw1DRRIzqBwLp2Ya9mFmY8KPvvtvmna8SxVR9JMZ4kzMD68N22vlaRpkeFA==", - "dev": true, - "requires": { - "dot-prop": "^5.2.0", - "graceful-fs": "^4.1.2", - "make-dir": "^3.0.0", - "unique-string": "^2.0.0", - "write-file-atomic": "^3.0.0", - "xdg-basedir": "^4.0.0" - } - }, "confusing-browser-globals": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz", @@ -3270,12 +251,6 @@ "which": "^2.0.1" } }, - "crypto-random-string": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", - "integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==", - "dev": true - }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3285,33 +260,12 @@ "ms": "2.1.2" } }, - "decompress-response": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", - "integrity": "sha512-BzRPQuY1ip+qDonAOz42gRm/pg9F768C+npV/4JOsxRC2sq+Rlk+Q4ZCAsOhnIaMrgarILY+RMUIvMmmX1qAEA==", - "dev": true, - "requires": { - "mimic-response": "^1.0.0" - } - }, - "deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "dev": true - }, "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, - "defer-to-connect": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz", - "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", - "dev": true - }, "define-properties": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", @@ -3331,36 +285,6 @@ "esutils": "^2.0.2" } }, - "dot-prop": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", - "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", - "dev": true, - "requires": { - "is-obj": "^2.0.0" - } - }, - "duplexer3": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", - "integrity": "sha512-CEj8FwwNA4cVH2uFCoHUrmojhYh1vmCdOaneKJXwkeY1i9jnlslVo9dx+hQ5Hl9GnH/Bwy/IjxAyOePyPKYnzA==", - "dev": true - }, - "emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true - }, - "end-of-stream": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", - "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, - "requires": { - "once": "^1.4.0" - } - }, "es-abstract": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz", @@ -3412,12 +336,6 @@ "is-symbol": "^1.0.2" } }, - "escape-goat": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", - "integrity": "sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==", - "dev": true - }, "escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", @@ -3765,15 +683,6 @@ "has-symbols": "^1.0.3" } }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, "get-symbol-description": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.0.tgz", @@ -3807,15 +716,6 @@ "is-glob": "^4.0.3" } }, - "global-dirs": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.0.tgz", - "integrity": "sha512-v8ho2DS5RiCjftj1nD9NmnfaOzTdud7RRnVd9kFNOjqZbISlx5DQ+OrTkywgd0dIt7oFCvKetZSHoHcP3sDdiA==", - "dev": true, - "requires": { - "ini": "2.0.0" - } - }, "globals": { "version": "13.15.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", @@ -3825,31 +725,6 @@ "type-fest": "^0.20.2" } }, - "got": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", - "integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", - "dev": true, - "requires": { - "@sindresorhus/is": "^0.14.0", - "@szmarczak/http-timer": "^1.1.2", - "cacheable-request": "^6.0.0", - "decompress-response": "^3.3.0", - "duplexer3": "^0.1.4", - "get-stream": "^4.1.0", - "lowercase-keys": "^1.0.1", - "mimic-response": "^1.0.1", - "p-cancelable": "^1.0.0", - "to-readable-stream": "^1.0.0", - "url-parse-lax": "^3.0.0" - } - }, - "graceful-fs": { - "version": "4.2.10", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", - "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", - "dev": true - }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -3895,18 +770,6 @@ "has-symbols": "^1.0.2" } }, - "has-yarn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/has-yarn/-/has-yarn-2.1.0.tgz", - "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==", - "dev": true - }, - "http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==", - "dev": true - }, "ignore": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", @@ -3929,12 +792,6 @@ "resolve-from": "^4.0.0" } }, - "import-lazy": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-2.1.0.tgz", - "integrity": "sha512-m7ZEHgtw69qOGw+jwxXkHlrlIPdTGkyh66zXZ1ajZbxkDBNjSY/LGbmjc7h0s2ELsUDTAhFr55TrPSSqJGPG0A==", - "dev": true - }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -3957,12 +814,6 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, - "ini": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz", - "integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==", - "dev": true - }, "internal-slot": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz", @@ -4008,15 +859,6 @@ "integrity": "sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==", "dev": true }, - "is-ci": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", - "integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==", - "dev": true, - "requires": { - "ci-info": "^2.0.0" - } - }, "is-core-module": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.9.0.tgz", @@ -4041,12 +883,6 @@ "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true }, - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true - }, "is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -4056,28 +892,12 @@ "is-extglob": "^2.1.1" } }, - "is-installed-globally": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.4.0.tgz", - "integrity": "sha512-iwGqO3J21aaSkC7jWnHP/difazwS7SFeIqxv6wEtLU8Y5KlzFTjyqcSIT0d8s4+dDhKytsk9PJZ2BkS5eZwQRQ==", - "dev": true, - "requires": { - "global-dirs": "^3.0.0", - "is-path-inside": "^3.0.2" - } - }, "is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", "integrity": "sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==", "dev": true }, - "is-npm": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-5.0.0.tgz", - "integrity": "sha512-WW/rQLOazUq+ST/bCAVBp/2oMERWLsR7OrKyt052dNDk4DHcDE0/7QSXITlmi+VBcV13DfIbysG3tZJm5RfdBA==", - "dev": true - }, "is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -4093,18 +913,6 @@ "has-tostringtag": "^1.0.0" } }, - "is-obj": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", - "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", - "dev": true - }, - "is-path-inside": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", - "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", - "dev": true - }, "is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -4142,12 +950,6 @@ "has-symbols": "^1.0.2" } }, - "is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", - "dev": true - }, "is-weakref": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-weakref/-/is-weakref-1.0.2.tgz", @@ -4157,12 +959,6 @@ "call-bind": "^1.0.2" } }, - "is-yarn-global": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz", - "integrity": "sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw==", - "dev": true - }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -4178,12 +974,6 @@ "argparse": "^2.0.1" } }, - "json-buffer": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", - "integrity": "sha512-CuUqjv0FUZIdXkHPI8MezCnFCdaTAacej1TZYulLoAg1h/PhwkdXFN4V/gzY4g+fMBCOV2xF+rp7t2XD2ns/NQ==", - "dev": true - }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -4205,24 +995,6 @@ "minimist": "^1.2.0" } }, - "keyv": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", - "integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", - "dev": true, - "requires": { - "json-buffer": "3.0.0" - } - }, - "latest-version": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", - "integrity": "sha512-weT+r0kTkRQdCdYCNtkMwWXQTMEswKrFBkm4ckQOMVhhqhIMI1UT2hMj+1iigIhgSZm5gTmrRXBNoGUgaTY1xA==", - "dev": true, - "requires": { - "package-json": "^6.3.0" - } - }, "levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -4249,36 +1021,6 @@ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, - "lowercase-keys": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", - "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", - "dev": true - }, - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "dev": true, - "requires": { - "semver": "^6.0.0" - } - }, - "mimic-response": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", - "dev": true - }, "minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -4307,21 +1049,21 @@ "dev": true }, "nodemon": { - "version": "2.0.16", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.16.tgz", - "integrity": "sha512-zsrcaOfTWRuUzBn3P44RDliLlp263Z/76FPoHFr3cFFkOz0lTPAcIw8dCzfdVIx/t3AtDYCZRCDkoCojJqaG3w==", + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.20.tgz", + "integrity": "sha512-Km2mWHKKY5GzRg6i1j5OxOHQtuvVsgskLfigG25yTtbyfRGn/GNvIbRyOf1PSCKJ2aT/58TiuUsuOU5UToVViw==", "dev": true, "requires": { "chokidar": "^3.5.2", "debug": "^3.2.7", "ignore-by-default": "^1.0.1", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "pstree.remy": "^1.1.8", "semver": "^5.7.1", + "simple-update-notifier": "^1.0.7", "supports-color": "^5.5.0", "touch": "^3.1.0", - "undefsafe": "^2.0.5", - "update-notifier": "^5.1.0" + "undefsafe": "^2.0.5" }, "dependencies": { "debug": { @@ -4371,12 +1113,6 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, - "normalize-url": { - "version": "4.5.1", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz", - "integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==", - "dev": true - }, "npm-watch": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/npm-watch/-/npm-watch-0.11.0.tgz", @@ -4456,12 +1192,6 @@ "word-wrap": "^1.2.3" } }, - "p-cancelable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", - "integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==", - "dev": true - }, "p-limit": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", @@ -4486,18 +1216,6 @@ "integrity": "sha512-U1etNYuMJoIz3ZXSrrySFjsXQTWOx2/jdi86L+2pRvph/qMKL6sbcCYdH23fqsbm8TH2Gn0OybpT4eSFlCVHww==", "dev": true }, - "package-json": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/package-json/-/package-json-6.5.0.tgz", - "integrity": "sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==", - "dev": true, - "requires": { - "got": "^9.6.0", - "registry-auth-token": "^4.0.0", - "registry-url": "^5.0.0", - "semver": "^6.2.0" - } - }, "parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -4543,69 +1261,18 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, - "prepend-http": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", - "integrity": "sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA==", - "dev": true - }, "pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", "dev": true }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, - "pupa": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/pupa/-/pupa-2.1.1.tgz", - "integrity": "sha512-l1jNAspIBSFqbT+y+5FosojNpVpF94nlI+wDUpqP9enwOTfHx9f0gh5nB96vl+6yTpsJsypeNrwfzPrKuHB41A==", - "dev": true, - "requires": { - "escape-goat": "^2.0.0" - } - }, - "rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "dev": true, - "requires": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - }, - "dependencies": { - "ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "dev": true - }, - "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", - "dev": true - } - } - }, "readable-stream": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", @@ -4643,24 +1310,6 @@ "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", "dev": true }, - "registry-auth-token": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-4.2.1.tgz", - "integrity": "sha512-6gkSb4U6aWJB4SF2ZvLb76yCBjcvufXBqvvEx1HbmKPkutswjW1xNVRY0+daljIYRbogN7O0etYSlbiaEQyMyw==", - "dev": true, - "requires": { - "rc": "^1.2.8" - } - }, - "registry-url": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/registry-url/-/registry-url-5.1.0.tgz", - "integrity": "sha512-8acYXXTI0AkQv6RAOjE3vOaIXZkT9wo4LOFbBKYQEEnnMNBpKqdUrI6S4NT0KPIo/WVvJ5tE/X5LF/TQUf0ekw==", - "dev": true, - "requires": { - "rc": "^1.2.8" - } - }, "resolve": { "version": "1.22.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz", @@ -4678,15 +1327,6 @@ "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true }, - "responselike": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", - "integrity": "sha512-/Fpe5guzJk1gPqdJLJR5u7eG/gNY4nImjbRDaVWVMRhne55TCmj2i9Q+54PBRfatRC8v/rIiv9BN0pMd9OV5EQ==", - "dev": true, - "requires": { - "lowercase-keys": "^1.0.0" - } - }, "rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -4708,15 +1348,6 @@ "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", "dev": true }, - "semver-diff": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-3.1.1.tgz", - "integrity": "sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg==", - "dev": true, - "requires": { - "semver": "^6.3.0" - } - }, "shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -4743,30 +1374,21 @@ "object-inspect": "^1.9.0" } }, - "signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true - }, - "string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "simple-update-notifier": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.0.7.tgz", + "integrity": "sha512-BBKgR84BJQJm6WjWFMHgLVuo61FBDSj1z/xSFUIozqO6wO7ii0JxCqlIud7Enr/+LhlbNI0whErq96P2qHNWew==", "dev": true, "requires": { - "safe-buffer": "~5.2.0" - } - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" + "semver": "~7.0.0" + }, + "dependencies": { + "semver": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", + "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==", + "dev": true + } } }, "string.prototype.trimend": { @@ -4791,6 +1413,15 @@ "es-abstract": "^1.19.5" } }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dev": true, + "requires": { + "safe-buffer": "~5.2.0" + } + }, "strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -4842,12 +1473,6 @@ "readable-stream": "3" } }, - "to-readable-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", - "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", - "dev": true - }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -4893,15 +1518,6 @@ "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true }, - "typedarray-to-buffer": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", - "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", - "dev": true, - "requires": { - "is-typedarray": "^1.0.0" - } - }, "unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -4920,48 +1536,6 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, - "unique-string": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-2.0.0.tgz", - "integrity": "sha512-uNaeirEPvpZWSgzwsPGtU2zVSTrn/8L5q/IexZmH0eH6SA73CmAA5U4GwORTxQAZs95TAXLNqeLoPPNO5gZfWg==", - "dev": true, - "requires": { - "crypto-random-string": "^2.0.0" - } - }, - "update-notifier": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-5.1.0.tgz", - "integrity": "sha512-ItnICHbeMh9GqUy31hFPrD1kcuZ3rpxDZbf4KUDavXwS0bW5m7SLbDQpGX3UYr072cbrF5hFUs3r5tUsPwjfHw==", - "dev": true, - "requires": { - "boxen": "^5.0.0", - "chalk": "^4.1.0", - "configstore": "^5.0.1", - "has-yarn": "^2.1.0", - "import-lazy": "^2.1.0", - "is-ci": "^2.0.0", - "is-installed-globally": "^0.4.0", - "is-npm": "^5.0.0", - "is-yarn-global": "^0.3.0", - "latest-version": "^5.1.0", - "pupa": "^2.1.1", - "semver": "^7.3.4", - "semver-diff": "^3.1.1", - "xdg-basedir": "^4.0.0" - }, - "dependencies": { - "semver": { - "version": "7.3.7", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", - "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - } - } - }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -4971,15 +1545,6 @@ "punycode": "^2.1.0" } }, - "url-parse-lax": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", - "integrity": "sha512-NjFKA0DidqPa5ciFcSrXnAltTtzz84ogy+NebPvfEgAck0+TNg4UJ4IN+fB7zRZfbgUf0syOo9MDxFkDSMuFaQ==", - "dev": true, - "requires": { - "prepend-http": "^2.0.0" - } - }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -5014,61 +1579,17 @@ "is-symbol": "^1.0.3" } }, - "widest-line": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", - "integrity": "sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==", - "dev": true, - "requires": { - "string-width": "^4.0.0" - } - }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "dev": true }, - "wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, - "requires": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - } - }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true - }, - "write-file-atomic": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", - "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", - "dev": true, - "requires": { - "imurmurhash": "^0.1.4", - "is-typedarray": "^1.0.0", - "signal-exit": "^3.0.2", - "typedarray-to-buffer": "^3.1.5" - } - }, - "xdg-basedir": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", - "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", - "dev": true - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true } } } diff --git a/package.json b/package.json index e11e79ae5..08f3a19ce 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "scripts": { "lint-apps": "eslint ./apps --ext .js", - "test": "node bin/sanitycheck.js && eslint ./apps --ext .js", + "test": "node bin/sanitycheck.js && eslint ./apps --ext .js && eslint ./modules --ext .js", "update-local-apps": "./bin/create_apps_json.sh apps.local.json", "local": "npm-watch & npx http-server -a localhost -c-1", "start": "npx http-server -c-1" diff --git a/tests/Layout/bin/runalltests.sh b/tests/Layout/bin/runalltests.sh index 3a7aac50b..2d2985a4f 100755 --- a/tests/Layout/bin/runalltests.sh +++ b/tests/Layout/bin/runalltests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash cd `dirname $0`/.. ls tests/*.js | xargs -I{} bin/runtest.sh {} diff --git a/tests/Layout/bin/runtest.sh b/tests/Layout/bin/runtest.sh index 9bac72283..f6c566d18 100755 --- a/tests/Layout/bin/runtest.sh +++ b/tests/Layout/bin/runtest.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Requires Linux x64 (for ./espruino) # Also imagemagick for display diff --git a/typescript/tsconfig.json b/tsconfig.json similarity index 66% rename from typescript/tsconfig.json rename to tsconfig.json index d36465a01..8da08b8e2 100644 --- a/typescript/tsconfig.json +++ b/tsconfig.json @@ -8,10 +8,16 @@ "noImplicitOverride": true, "noImplicitReturns": true, "noImplicitThis": true, + "noLib": true, "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "noUnusedParameters": true, - "strict": true + "strict": true, + "typeRoots": ["./typescript/types"] }, - "include": ["../apps/**/*", "./**/*"], + "include": ["./**/*"], + "exclude": [ + "**/gpconv.d.ts", + "**/gpconv_bg.wasm.d.ts" + ] } diff --git a/typescript/README.md b/typescript/README.md index 13800aeec..7c1e21abd 100644 --- a/typescript/README.md +++ b/typescript/README.md @@ -1,13 +1,10 @@ -# BangleTS +# Bangle.ts -A generic project setup for compiling apps from Typescript to Bangle.js ready, readable Javascript. -It includes types for _some_ of the modules and globals that are exposed for apps to use. -The goal is to have types for everything, but that will take some time. Feel free to help out by contributing! +A generic project setup for compiling apps from Typescript to +Bangle.js-ready, readable JavaScript. -## Using the types - -All currently typed modules can be found in `/typescript/types.globals.d.ts`. -The typing is an ongoing process. If anything is still missing, you can add it! It will automatically be available in your TS files. +The types are now automatically generated by a script (see +[here](https://github.com/espruino/Espruino/blob/master/TYPESCRIPT.md). ## Compilation @@ -26,4 +23,4 @@ to install the project's build tools, and: npm run build ``` -To build all Typescript apps and widgets. The last command will generate the `app.js` files containing the transpiled code for the BangleJS. +To build all Typescript apps and widgets. The last command will generate the `app.js` files containing the transpiled code for the Bangle.js. diff --git a/typescript/package-lock.json b/typescript/package-lock.json index 52be5f98a..15653acc2 100644 --- a/typescript/package-lock.json +++ b/typescript/package-lock.json @@ -7,10 +7,89 @@ "": { "name": "Bangle.ts", "version": "0.0.1", + "dependencies": { + "node-fetch": "^3.2.10" + }, "devDependencies": { "typescript": "4.5.2" } }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", + "engines": { + "node": ">= 12" + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.2.10", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.10.tgz", + "integrity": "sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA==", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, "node_modules/typescript": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", @@ -23,14 +102,64 @@ "engines": { "node": ">=4.2.0" } + }, + "node_modules/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "engines": { + "node": ">= 8" + } } }, "dependencies": { + "data-uri-to-buffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" + }, + "fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "requires": { + "fetch-blob": "^3.1.2" + } + }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" + }, + "node-fetch": { + "version": "3.2.10", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.10.tgz", + "integrity": "sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA==", + "requires": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + } + }, "typescript": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", "dev": true + }, + "web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" } } } diff --git a/typescript/package.json b/typescript/package.json index 8cd38ce63..9533d77a7 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,13 +1,15 @@ { "name": "Bangle.ts", "description": "Bangle.js Typescript Project Setup and Types", - "author": "Sebastian Di Luzio (https://diluz.io)", + "author": "Sebastian Di Luzio (https://diluz.io) and qucchia (https://github.com/qucchia)", "version": "0.0.1", "devDependencies": { "typescript": "4.5.2" }, "scripts": { - "build": "tsc", - "build:types": "tsc ./types/globals.d.ts" + "build": "tsc" + }, + "dependencies": { + "node-fetch": "^3.2.10" } } diff --git a/typescript/types/main.d.ts b/typescript/types/main.d.ts new file mode 100644 index 000000000..89921972c --- /dev/null +++ b/typescript/types/main.d.ts @@ -0,0 +1,13012 @@ +// NOTE: This file has been automatically generated. + +/// + +// TYPES + +/** + * Menu item that holds a boolean value. + */ +type MenuBooleanItem = { + value: boolean; + format?: (value: boolean) => string; + onchange?: (value: boolean) => void; +}; + +/** + * Menu item that holds a numerical value. + */ +type MenuNumberItem = { + value: number; + format?: (value: number) => string; + onchange?: (value: number) => void; + step?: number; + min?: number; + max?: number; + wrap?: boolean; +}; + +/** + * Options passed to a menu. + */ +type MenuOptions = { + title?: string; + back?: () => void; + selected?: number; + fontHeight?: number; + x?: number; + y?: number; + x2?: number; + y2?: number; + cB?: number; + cF?: number; + cHB?: number; + cHF?: number; + predraw?: (g: Graphics) => void; + preflip?: (g: Graphics, less: boolean, more: boolean) => void; +}; + +/** + * Object containing data about a menu to pass to `E.showMenu`. + */ +type Menu = { + ""?: MenuOptions; + [key: string]: + | MenuOptions + | (() => void) + | MenuBooleanItem + | MenuNumberItem + | { value: string; onchange?: () => void } + | undefined; +}; + +/** + * Menu instance. + */ +type MenuInstance = { + draw: () => void; + move: (n: number) => void; + select: () => void; +}; + +type ImageObject = { + width: number; + height: number; + bpp?: number; + buffer: ArrayBuffer | string; + transparent?: number; + palette?: Uint16Array; +}; + +type Image = string | ImageObject | ArrayBuffer | Graphics; + +type ColorResolvable = number | `#${string}`; + +type FontName = + | "4x4" + | "4x4Numeric" + | "4x5" + | "4x5Numeric" + | "4x8Numeric" + | "5x7Numeric7Seg" + | "5x9Numeric7Seg" + | "6x8" + | "6x12" + | "7x11Numeric7Seg" + | "8x12" + | "8x16" + | "Dennis8" + | "Cherry6x10" + | "Copasectic40x58Numeric" + | "Dylex7x13" + | "HaxorNarrow7x17" + | "Sinclair" + | "Teletext10x18Mode7" + | "Teletext5x9Ascii" + | "Teletext5x9Mode7" + | "Vector"; + +type FontNameWithScaleFactor = + | FontName + | `${FontName}:${number}` + | `${FontName}:${number}x${number}`; + +type Theme = { + fg: number; + bg: number; + fg2: number; + bg2: number; + fgH: number; + bgH: number; + dark: boolean; +}; + +type NRFFilters = { + services?: string[]; + name?: string; + namePrefix?: string; + id?: string; + serviceData?: object; + manufacturerData?: object; +}; + +declare const BTN1: Pin; +declare const BTN2: Pin; +declare const BTN3: Pin; +declare const BTN4: Pin; +declare const BTN5: Pin; + +declare const g: Graphics; + +type WidgetArea = "tl" | "tr" | "bl" | "br"; +type Widget = { + area: WidgetArea; + width: number; + draw: (this: { x: number; y: number }) => void; +}; +declare const WIDGETS: { [key: string]: Widget }; + +type AccelData = { + x: number; + y: number; + z: number; + diff: number; + mag: number; +}; + +type HealthStatus = { + movement: number; + steps: number; + bpm: number; + bpmConfidence: number; +}; + +type CompassData = { + x: number; + y: number; + z: number; + dx: number; + dy: number; + dz: number; + heading: number; +}; + +type GPSFix = { + lat: number; + lon: number; + alt: number; + speed: number; + course: number; + time: Date; + satellites: number; + fix: number; + hdop: number +}; + +type PressureData = { + temperature: number; + pressure: number; + altitude: number; +} + +type TapAxis = -2 | -1 | 0 | 1 | 2; + +type SwipeCallback = (directionLR: -1 | 0 | 1, directionUD?: -1 | 0 | 1) => void; + +type TouchCallback = (button: number, xy?: { x: number, y: number }) => void; + +type DragCallback = (event: { + x: number; + y: number; + dx: number; + dy: number; + b: 1 | 0; +}) => void; + +type LCDMode = + | "direct" + | "doublebuffered" + | "120x120" + | "80x80" + +type BangleOptions = { + wakeOnBTN1: boolean; + wakeOnBTN2: boolean; + wakeOnBTN3: boolean; + wakeOnFaceUp: boolean; + wakeOnTouch: boolean; + wakeOnTwist: boolean; + twistThreshold: number; + twistMaxY: number; + twistTimeout: number; + gestureStartThresh: number; + gestureEndThresh: number; + gestureInactiveCount: number; + gestureMinLength: number; + powerSave: boolean; + lockTimeout: number; + lcdPowerTimeout: number; + backlightTimeout: number; +}; + +interface ArrayLike { + readonly length: number; + readonly [n: number]: T; +} + +type PinMode = + | "analog" + | "input" + | "input_pullup" + | "input_pulldown" + | "output" + | "opendrain" + | "af_output" + | "af_opendrain"; + +type ErrorFlag = + | "FIFO_FULL" + | "BUFFER_FULL" + | "CALLBACK" + | "LOW_MEMORY" + | "MEMORY" + | "UART_OVERFLOW"; + +type Flag = + | "deepSleep" + | "pretokenise" + | "unsafeFlash" + | "unsyncFiles"; + +type Uint8ArrayResolvable = + | number + | string + | Uint8ArrayResolvable[] + | ArrayBuffer + | ArrayBufferView + | { data: Uint8ArrayResolvable, count: number } + | { callback: () => Uint8ArrayResolvable } + +type VariableSizeInformation = { + name: string; + size: number; + more?: VariableSizeInformation; +}; + + +// CLASSES + +/** + * Class containing [micro:bit's](https://www.espruino.com/MicroBit) utility + * functions. + * @url http://www.espruino.com/Reference#Microbit + */ +declare class Microbit { + /** + * The micro:bit's speaker pin + * @returns {Pin} + * @url http://www.espruino.com/Reference#l_Microbit_SPEAKER + */ + static SPEAKER: Pin; + + /** + * The micro:bit's microphone pin + * `MIC_ENABLE` should be set to 1 before using this + * @returns {Pin} + * @url http://www.espruino.com/Reference#l_Microbit_MIC + */ + static MIC: Pin; + + /** + * The micro:bit's microphone enable pin + * @returns {Pin} + * @url http://www.espruino.com/Reference#l_Microbit_MIC_ENABLE + */ + static MIC_ENABLE: Pin; + + /** + * Called when the Micro:bit is moved in a deliberate fashion, and includes data on + * the detected gesture. + * @param {string} event - The event to listen to. + * @param {(gesture: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `gesture` An Int8Array containing the accelerations (X,Y,Z) from the last gesture detected by the accelerometer + * @url http://www.espruino.com/Reference#l_Microbit_gesture + */ + static on(event: "gesture", callback: (gesture: any) => void): void; + + /** + * @returns {any} An Object `{x,y,z}` of magnetometer readings as integers + * @url http://www.espruino.com/Reference#l_Microbit_mag + */ + static mag(): any; + + /** + * @returns {any} An Object `{x,y,z}` of acceleration readings in G + * @url http://www.espruino.com/Reference#l_Microbit_accel + */ + static accel(): any; + + /** + * **Note:** This function is only available on the [BBC micro:bit](/MicroBit) + * board + * Write the given value to the accelerometer + * + * @param {number} addr - Accelerometer address + * @param {number} data - Data to write + * @url http://www.espruino.com/Reference#l_Microbit_accelWr + */ + static accelWr(addr: number, data: number): void; + + /** + * Turn on the accelerometer, and create `Microbit.accel` and `Microbit.gesture` + * events. + * **Note:** The accelerometer is currently always enabled - this code just + * responds to interrupts and reads + * @url http://www.espruino.com/Reference#l_Microbit_accelOn + */ + static accelOn(): void; + + /** + * Turn off events from the accelerometer (started with `Microbit.accelOn`) + * @url http://www.espruino.com/Reference#l_Microbit_accelOff + */ + static accelOff(): void; + + /** + * Play a waveform on the Micro:bit's speaker + * + * @param {any} waveform - An array of data to play (unsigned 8 bit) + * @param {any} samplesPerSecond - The number of samples per second for playback default is 4000 + * @param {any} callback - A function to call when playback is finished + * @url http://www.espruino.com/Reference#l_Microbit_play + */ + static play(waveform: any, samplesPerSecond: any, callback: any): void; + + /** + * Records sound from the micro:bit's onboard microphone and returns the result + * + * @param {any} samplesPerSecond - The number of samples per second for recording - 4000 is recommended + * @param {any} callback - A function to call with the result of recording (unsigned 8 bit ArrayBuffer) + * @param {any} [samples] - [optional] How many samples to record (6000 default) + * @url http://www.espruino.com/Reference#l_Microbit_record + */ + static record(samplesPerSecond: any, callback: any, samples?: any): void; + + +} + +interface MathConstructor { + /** + * @returns {number} The value of E - 2.718281828459045 + * @url http://www.espruino.com/Reference#l_Math_E + */ + E: number; + + /** + * @returns {number} The value of PI - 3.141592653589793 + * @url http://www.espruino.com/Reference#l_Math_PI + */ + PI: number; + + /** + * @returns {number} The natural logarithm of 2 - 0.6931471805599453 + * @url http://www.espruino.com/Reference#l_Math_LN2 + */ + LN2: number; + + /** + * @returns {number} The natural logarithm of 10 - 2.302585092994046 + * @url http://www.espruino.com/Reference#l_Math_LN10 + */ + LN10: number; + + /** + * @returns {number} The base 2 logarithm of e - 1.4426950408889634 + * @url http://www.espruino.com/Reference#l_Math_LOG2E + */ + LOG2E: number; + + /** + * @returns {number} The base 10 logarithm of e - 0.4342944819032518 + * @url http://www.espruino.com/Reference#l_Math_LOG10E + */ + LOG10E: number; + + /** + * @returns {number} The square root of 2 - 1.4142135623730951 + * @url http://www.espruino.com/Reference#l_Math_SQRT2 + */ + SQRT2: number; + + /** + * @returns {number} The square root of 1/2 - 0.7071067811865476 + * @url http://www.espruino.com/Reference#l_Math_SQRT1_2 + */ + SQRT1_2: number; + + /** + * + * @param {number} x - A floating point value + * @returns {number} The absolute value of x (eg, ```Math.abs(2)==2```, but also ```Math.abs(-2)==2```) + * @url http://www.espruino.com/Reference#l_Math_abs + */ + abs(x: number): number; + + /** + * + * @param {number} x - The value to get the arc cosine of + * @returns {number} The arc cosine of x, between 0 and PI + * @url http://www.espruino.com/Reference#l_Math_acos + */ + acos(x: number): number; + + /** + * + * @param {number} x - The value to get the arc sine of + * @returns {number} The arc sine of x, between -PI/2 and PI/2 + * @url http://www.espruino.com/Reference#l_Math_asin + */ + asin(x: number): number; + + /** + * + * @param {number} x - The value to get the arc tangent of + * @returns {number} The arc tangent of x, between -PI/2 and PI/2 + * @url http://www.espruino.com/Reference#l_Math_atan + */ + atan(x: number): number; + + /** + * + * @param {number} y - The Y-part of the angle to get the arc tangent of + * @param {number} x - The X-part of the angle to get the arc tangent of + * @returns {number} The arctangent of Y/X, between -PI and PI + * @url http://www.espruino.com/Reference#l_Math_atan2 + */ + atan2(y: number, x: number): number; + + /** + * + * @param {number} theta - The angle to get the cosine of + * @returns {number} The cosine of theta + * @url http://www.espruino.com/Reference#l_Math_cos + */ + cos(theta: number): number; + + /** + * + * @param {number} x - The value to raise to the power + * @param {number} y - The power x should be raised to + * @returns {number} x raised to the power y (x^y) + * @url http://www.espruino.com/Reference#l_Math_pow + */ + pow(x: number, y: number): number; + + /** + * @returns {number} A random number between 0 and 1 + * @url http://www.espruino.com/Reference#l_Math_random + */ + random(): number; + + /** + * + * @param {number} x - The value to round + * @returns {any} x, rounded to the nearest integer + * @url http://www.espruino.com/Reference#l_Math_round + */ + round(x: number): any; + + /** + * + * @param {number} theta - The angle to get the sine of + * @returns {number} The sine of theta + * @url http://www.espruino.com/Reference#l_Math_sin + */ + sin(theta: number): number; + + /** + * + * @param {number} theta - The angle to get the tangent of + * @returns {number} The tangent of theta + * @url http://www.espruino.com/Reference#l_Math_tan + */ + tan(theta: number): number; + + /** + * + * @param {number} x - The value to take the square root of + * @returns {number} The square root of x + * @url http://www.espruino.com/Reference#l_Math_sqrt + */ + sqrt(x: number): number; + + /** + * + * @param {number} x - The value to round up + * @returns {number} x, rounded upwards to the nearest integer + * @url http://www.espruino.com/Reference#l_Math_ceil + */ + ceil(x: number): number; + + /** + * + * @param {number} x - The value to round down + * @returns {number} x, rounded downwards to the nearest integer + * @url http://www.espruino.com/Reference#l_Math_floor + */ + floor(x: number): number; + + /** + * + * @param {number} x - The value raise E to the power of + * @returns {number} E^x + * @url http://www.espruino.com/Reference#l_Math_exp + */ + exp(x: number): number; + + /** + * + * @param {number} x - The value to take the logarithm (base E) root of + * @returns {number} The log (base E) of x + * @url http://www.espruino.com/Reference#l_Math_log + */ + log(x: number): number; + + /** + * DEPRECATED - Please use `E.clip()` instead. Clip a number to be between min and + * max (inclusive) + * + * @param {number} x - A floating point value to clip + * @param {number} min - The smallest the value should be + * @param {number} max - The largest the value should be + * @returns {number} The value of x, clipped so as not to be below min or above max. + * @url http://www.espruino.com/Reference#l_Math_clip + */ + clip(x: number, min: number, max: number): number; + + /** + * DEPRECATED - This is not part of standard JavaScript libraries + * Wrap a number around if it is less than 0 or greater than or equal to max. For + * instance you might do: ```Math.wrap(angleInDegrees, 360)``` + * + * @param {number} x - A floating point value to wrap + * @param {number} max - The largest the value should be + * @returns {number} The value of x, wrapped so as not to be below min or above max. + * @url http://www.espruino.com/Reference#l_Math_wrap + */ + wrap(x: number, max: number): number; + + /** + * Find the minimum of a series of numbers + * + * @param {any} args - Floating point values to clip + * @returns {number} The minimum of the supplied values + * @url http://www.espruino.com/Reference#l_Math_min + */ + min(...args: any[]): number; + + /** + * Find the maximum of a series of numbers + * + * @param {any} args - Floating point values to clip + * @returns {number} The maximum of the supplied values + * @url http://www.espruino.com/Reference#l_Math_max + */ + max(...args: any[]): number; +} + +interface Math { + +} + +/** + * This is a standard JavaScript class that contains useful Maths routines + * @url http://www.espruino.com/Reference#Math + */ +declare const Math: MathConstructor + +/** + * Class containing an instance of TFMicroInterpreter + * @url http://www.espruino.com/Reference#TFMicroInterpreter + */ +declare class TFMicroInterpreter { + + + /** + * @returns {any} An arraybuffer referencing the input data + * @url http://www.espruino.com/Reference#l_TFMicroInterpreter_getInput + */ + getInput(): ArrayBufferView; + + /** + * @returns {any} An arraybuffer referencing the output data + * @url http://www.espruino.com/Reference#l_TFMicroInterpreter_getOutput + */ + getOutput(): ArrayBufferView; + + /** + * @url http://www.espruino.com/Reference#l_TFMicroInterpreter_invoke + */ + invoke(): void; +} + +/** + * Class containing utility functions for accessing IO on the hexagonal badge + * @url http://www.espruino.com/Reference#Badge + */ +declare class Badge { + /** + * Capacitive sense - the higher the capacitance, the higher the number returned. + * Supply a corner number between 1 and 6, and an integer value will be returned + * that is proportional to the capacitance + * + * @param {number} corner - The corner to use + * @returns {number} Capacitive sense counter + * @url http://www.espruino.com/Reference#l_Badge_capSense + */ + static capSense(corner: number): number; + + /** + * Return an approximate battery percentage remaining based on a normal CR2032 + * battery (2.8 - 2.2v) + * @returns {number} A percentage between 0 and 100 + * @url http://www.espruino.com/Reference#l_Badge_getBatteryPercentage + */ + static getBatteryPercentage(): number; + + /** + * Set the LCD's contrast + * + * @param {number} c - Contrast between 0 and 1 + * @url http://www.espruino.com/Reference#l_Badge_setContrast + */ + static setContrast(c: number): void; + + +} + +/** + * Class containing [Puck.js's](http://www.puck-js.com) utility functions. + * @url http://www.espruino.com/Reference#Puck + */ +declare class Puck { + /** + * Turn on the magnetometer, take a single reading, and then turn it off again. + * An object of the form `{x,y,z}` is returned containing magnetometer readings. + * Due to residual magnetism in the Puck and magnetometer itself, with no magnetic + * field the Puck will not return `{x:0,y:0,z:0}`. + * Instead, it's up to you to figure out what the 'zero value' is for your Puck in + * your location and to then subtract that from the value returned. If you're not + * trying to measure the Earth's magnetic field then it's a good idea to just take + * a reading at startup and use that. + * With the aerial at the top of the board, the `y` reading is vertical, `x` is + * horizontal, and `z` is through the board. + * Readings are in increments of 0.1 micro Tesla (uT). The Earth's magnetic field + * varies from around 25-60 uT, so the reading will vary by 250 to 600 depending on + * location. + * @returns {any} An Object `{x,y,z}` of magnetometer readings as integers + * @url http://www.espruino.com/Reference#l_Puck_mag + */ + static mag(): any; + + /** + * Turn on the magnetometer, take a single temperature reading from the MAG3110 + * chip, and then turn it off again. + * (If the magnetometer is already on, this just returns the last reading obtained) + * `E.getTemperature()` uses the microcontroller's temperature sensor, but this + * uses the magnetometer's. + * The reading obtained is an integer (so no decimal places), but the sensitivity + * is factory trimmed. to 1°C, however the temperature offset isn't - so + * absolute readings may still need calibrating. + * @returns {number} Temperature in degrees C + * @url http://www.espruino.com/Reference#l_Puck_magTemp + */ + static magTemp(): number; + + /** + * Called after `Puck.magOn()` every time magnetometer data is sampled. There is + * one argument which is an object of the form `{x,y,z}` containing magnetometer + * readings as integers (for more information see `Puck.mag()`). + * Check out [the Puck.js page on the + * magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Puck_mag + */ + static on(event: "mag", callback: () => void): void; + + /** + * Only on Puck.js v2.0 + * Called after `Puck.accelOn()` every time accelerometer data is sampled. There is + * one argument which is an object of the form `{acc:{x,y,z}, gyro:{x,y,z}}` + * containing the data. + * The data is as it comes off the accelerometer and is not scaled to 1g. For more + * information see `Puck.accel()` or [the Puck.js page on the + * magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals). + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Puck_accel + */ + static on(event: "accel", callback: () => void): void; + + /** + * Turn the magnetometer on and start periodic sampling. Samples will then cause a + * 'mag' event on 'Puck': + * ``` + * Puck.magOn(); + * Puck.on('mag', function(xyz) { + * console.log(xyz); + * // {x:..., y:..., z:...} + * }); + * // Turn events off with Puck.magOff(); + * ``` + * This call will be ignored if the sampling is already on. + * If given an argument, the sample rate is set (if not, it's at 0.63 Hz). The + * sample rate must be one of the following (resulting in the given power + * consumption): + * * 80 Hz - 900uA + * * 40 Hz - 550uA + * * 20 Hz - 275uA + * * 10 Hz - 137uA + * * 5 Hz - 69uA + * * 2.5 Hz - 34uA + * * 1.25 Hz - 17uA + * * 0.63 Hz - 8uA + * * 0.31 Hz - 8uA + * * 0.16 Hz - 8uA + * * 0.08 Hz - 8uA + * When the battery level drops too low while sampling is turned on, the + * magnetometer may stop sampling without warning, even while other Puck functions + * continue uninterrupted. + * Check out [the Puck.js page on the + * magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information. + * + * @param {number} samplerate - The sample rate in Hz, or undefined + * @url http://www.espruino.com/Reference#l_Puck_magOn + */ + static magOn(samplerate: number): void; + + /** + * Turn the magnetometer off + * @url http://www.espruino.com/Reference#l_Puck_magOff + */ + static magOff(): void; + + /** + * Writes a register on the LIS3MDL / MAX3110 Magnetometer. Can be used for + * configuring advanced functions. + * Check out [the Puck.js page on the + * magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information and links to modules that use this function. + * + * @param {number} reg + * @param {number} data + * @url http://www.espruino.com/Reference#l_Puck_magWr + */ + static magWr(reg: number, data: number): void; + + /** + * Reads a register from the LIS3MDL / MAX3110 Magnetometer. Can be used for + * configuring advanced functions. + * Check out [the Puck.js page on the + * magnetometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information and links to modules that use this function. + * + * @param {number} reg + * @returns {number} + * @url http://www.espruino.com/Reference#l_Puck_magRd + */ + static magRd(reg: number): number; + + /** + * On Puck.js v2.0 this will use the on-board PCT2075TP temperature sensor, but on + * Puck.js the less accurate on-chip Temperature sensor is used. + * @returns {number} Temperature in degrees C + * @url http://www.espruino.com/Reference#l_Puck_getTemperature + */ + static getTemperature(): number; + + /** + * Accepted values are: + * * 1.6 Hz (no Gyro) - 40uA (2v05 and later firmware) + * * 12.5 Hz (with Gyro)- 350uA + * * 26 Hz (with Gyro) - 450 uA + * * 52 Hz (with Gyro) - 600 uA + * * 104 Hz (with Gyro) - 900 uA + * * 208 Hz (with Gyro) - 1500 uA + * * 416 Hz (with Gyro) (not recommended) + * * 833 Hz (with Gyro) (not recommended) + * * 1660 Hz (with Gyro) (not recommended) + * Once `Puck.accelOn()` is called, the `Puck.accel` event will be called each time + * data is received. `Puck.accelOff()` can be called to turn the accelerometer off. + * For instance to light the red LED whenever Puck.js is face up: + * ``` + * Puck.on('accel', function(a) { + * digitalWrite(LED1, a.acc.z > 0); + * }); + * Puck.accelOn(); + * ``` + * Check out [the Puck.js page on the + * accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information. + * + * @param {number} samplerate - The sample rate in Hz, or undefined + * @url http://www.espruino.com/Reference#l_Puck_accelOn + */ + static accelOn(samplerate: number): void; + + /** + * Turn the accelerometer off after it has been turned on by `Puck.accelOn()`. + * Check out [the Puck.js page on the + * accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information. + * @url http://www.espruino.com/Reference#l_Puck_accelOff + */ + static accelOff(): void; + + /** + * Turn on the accelerometer, take a single reading, and then turn it off again. + * The values reported are the raw values from the chip. In normal configuration: + * * accelerometer: full-scale (32768) is 4g, so you need to divide by 8192 to get + * correctly scaled values + * * gyro: full-scale (32768) is 245 dps, so you need to divide by 134 to get + * correctly scaled values + * If taking more than one reading, we'd suggest you use `Puck.accelOn()` and the + * `Puck.accel` event. + * @returns {any} An Object `{acc:{x,y,z}, gyro:{x,y,z}}` of accelerometer/gyro readings + * @url http://www.espruino.com/Reference#l_Puck_accel + */ + static accel(): any; + + /** + * Writes a register on the LSM6DS3TR-C Accelerometer. Can be used for configuring + * advanced functions. + * Check out [the Puck.js page on the + * accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information and links to modules that use this function. + * + * @param {number} reg + * @param {number} data + * @url http://www.espruino.com/Reference#l_Puck_accelWr + */ + static accelWr(reg: number, data: number): void; + + /** + * Reads a register from the LSM6DS3TR-C Accelerometer. Can be used for configuring + * advanced functions. + * Check out [the Puck.js page on the + * accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more + * information and links to modules that use this function. + * + * @param {number} reg + * @returns {number} + * @url http://www.espruino.com/Reference#l_Puck_accelRd + */ + static accelRd(reg: number): number; + + /** + * Transmit the given set of IR pulses - data should be an array of pulse times in + * milliseconds (as `[on, off, on, off, on, etc]`). + * For example `Puck.IR(pulseTimes)` - see http://www.espruino.com/Puck.js+Infrared + * for a full example. + * You can also attach an external LED to Puck.js, in which case you can just + * execute `Puck.IR(pulseTimes, led_cathode, led_anode)` + * It is also possible to just supply a single pin for IR transmission with + * `Puck.IR(pulseTimes, led_anode)` (on 2v05 and above). + * + * @param {any} data - An array of pulse lengths, in milliseconds + * @param {Pin} cathode - (optional) pin to use for IR LED cathode - if not defined, the built-in IR LED is used + * @param {Pin} anode - (optional) pin to use for IR LED anode - if not defined, the built-in IR LED is used + * @url http://www.espruino.com/Reference#l_Puck_IR + */ + static IR(data: any, cathode: Pin, anode: Pin): void; + + /** + * Capacitive sense - the higher the capacitance, the higher the number returned. + * If called without arguments, a value depending on the capacitance of what is + * attached to pin D11 will be returned. If you attach a length of wire to D11, + * you'll be able to see a higher value returned when your hand is near the wire + * than when it is away. + * You can also supply pins to use yourself, however if you do this then the TX pin + * must be connected to RX pin and sense plate via a roughly 1MOhm resistor. + * When not supplying pins, Puck.js uses an internal resistor between D12(tx) and + * D11(rx). + * + * @param {Pin} tx + * @param {Pin} rx + * @returns {number} Capacitive sense counter + * @url http://www.espruino.com/Reference#l_Puck_capSense + */ + static capSense(tx: Pin, rx: Pin): number; + + /** + * Return a light value based on the light the red LED is seeing. + * **Note:** If called more than 5 times per second, the received light value may + * not be accurate. + * @returns {number} A light value from 0 to 1 + * @url http://www.espruino.com/Reference#l_Puck_light + */ + static light(): number; + + /** + * DEPRECATED - Please use `E.getBattery()` instead. + * Return an approximate battery percentage remaining based on a normal CR2032 + * battery (2.8 - 2.2v). + * @returns {number} A percentage between 0 and 100 + * @url http://www.espruino.com/Reference#l_Puck_getBatteryPercentage + */ + static getBatteryPercentage(): number; + + /** + * Run a self-test, and return true for a pass. This checks for shorts between + * pins, so your Puck shouldn't have anything connected to it. + * **Note:** This self-test auto starts if you hold the button on your Puck down + * while inserting the battery, leave it pressed for 3 seconds (while the green LED + * is lit) and release it soon after all LEDs turn on. 5 red blinks is a fail, 5 + * green is a pass. + * If the self test fails, it'll set the Puck.js Bluetooth advertising name to + * `Puck.js !ERR` where ERR is a 3 letter error code. + * @returns {boolean} True if the self-test passed + * @url http://www.espruino.com/Reference#l_Puck_selfTest + */ + static selfTest(): boolean; + + +} + +/** + * This is the File object - it allows you to stream data to and from files (As + * opposed to the `require('fs').readFile(..)` style functions that read an entire + * file). + * To create a File object, you must type ```var fd = + * E.openFile('filepath','mode')``` - see [E.openFile](#l_E_openFile) for more + * information. + * **Note:** If you want to remove an SD card after you have started using it, you + * *must* call `E.unmountSD()` or you may cause damage to the card. + * @url http://www.espruino.com/Reference#File + */ +declare class File { + + + /** + * Close an open file. + * @url http://www.espruino.com/Reference#l_File_close + */ + close(): void; + + /** + * Write data to a file. + * **Note:** By default this function flushes all changes to the SD card, which + * makes it slow (but also safe!). You can use `E.setFlags({unsyncFiles:1})` to + * disable this behaviour and really speed up writes - but then you must be sure to + * close all files you are writing before power is lost or you will cause damage to + * your SD card's filesystem. + * + * @param {any} buffer - A string containing the bytes to write + * @returns {number} the number of bytes written + * @url http://www.espruino.com/Reference#l_File_write + */ + write(buffer: any): number; + + /** + * Read data in a file in byte size chunks + * + * @param {number} length - is an integer specifying the number of bytes to read. + * @returns {any} A string containing the characters that were read + * @url http://www.espruino.com/Reference#l_File_read + */ + read(length: number): any; + + /** + * Skip the specified number of bytes forward in the file + * + * @param {number} nBytes - is a positive integer specifying the number of bytes to skip forwards. + * @url http://www.espruino.com/Reference#l_File_skip + */ + skip(nBytes: number): void; + + /** + * Seek to a certain position in the file + * + * @param {number} nBytes - is an integer specifying the number of bytes to skip forwards. + * @url http://www.espruino.com/Reference#l_File_seek + */ + seek(nBytes: number): void; + + /** + * Pipe this file to a stream (an object with a 'write' method) + * + * @param {any} destination - The destination file/stream that will receive content from the source. + * @param {any} options + * An optional object `{ chunkSize : int=32, end : bool=true, complete : function }` + * chunkSize : The amount of data to pipe from source to destination at a time + * complete : a function to call when the pipe activity is complete + * end : call the 'end' function on the destination when the source is finished + * @url http://www.espruino.com/Reference#l_File_pipe + */ + pipe(destination: any, options: any): void; +} + +/** + * Class containing utility functions for the Seeed WIO LTE board + * @url http://www.espruino.com/Reference#WioLTE + */ +declare class WioLTE { + /** + * Set the WIO's LED + * + * @param {number} red - 0-255, red LED intensity + * @param {number} green - 0-255, green LED intensity + * @param {number} blue - 0-255, blue LED intensity + * @url http://www.espruino.com/Reference#l_WioLTE_LED + */ + static LED(red: number, green: number, blue: number): void; + + /** + * Set the power of Grove connectors, except for `D38` and `D39` which are always + * on. + * + * @param {boolean} onoff - Whether to turn the Grove connectors power on or off (D38/D39 are always powered) + * @url http://www.espruino.com/Reference#l_WioLTE_setGrovePower + */ + static setGrovePower(onoff: boolean): void; + + /** + * Turn power to the WIO's LED on or off. + * Turning the LED on won't immediately display a color - that must be done with + * `WioLTE.LED(r,g,b)` + * + * @param {boolean} onoff - true = on, false = off + * @url http://www.espruino.com/Reference#l_WioLTE_setLEDPower + */ + static setLEDPower(onoff: boolean): void; + + /** + * @returns {any} + * @url http://www.espruino.com/Reference#l_WioLTE_D38 + */ + static D38: any; + + /** + * @returns {any} + * @url http://www.espruino.com/Reference#l_WioLTE_D20 + */ + static D20: any; + + /** + * @returns {any} + * @url http://www.espruino.com/Reference#l_WioLTE_A6 + */ + static A6: any; + + /** + * @returns {any} + * @url http://www.espruino.com/Reference#l_WioLTE_I2C + */ + static I2C: any; + + /** + * @returns {any} + * @url http://www.espruino.com/Reference#l_WioLTE_UART + */ + static UART: any; + + /** + * @returns {any} + * @url http://www.espruino.com/Reference#l_WioLTE_A4 + */ + static A4: any; + + +} + +/** + * Class containing utility functions for + * [Pixl.js](http://www.espruino.com/Pixl.js) + * @url http://www.espruino.com/Reference#Pixl + */ +declare class Pixl { + /** + * DEPRECATED - Please use `E.getBattery()` instead. + * Return an approximate battery percentage remaining based on a normal CR2032 + * battery (2.8 - 2.2v) + * @returns {number} A percentage between 0 and 100 + * @url http://www.espruino.com/Reference#l_Pixl_getBatteryPercentage + */ + static getBatteryPercentage(): number; + + /** + * Set the LCD's contrast + * + * @param {number} c - Contrast between 0 and 1 + * @url http://www.espruino.com/Reference#l_Pixl_setContrast + */ + static setContrast(c: number): void; + + /** + * This function can be used to turn Pixl.js's LCD off or on. + * * With the LCD off, Pixl.js draws around 0.1mA + * * With the LCD on, Pixl.js draws around 0.25mA + * + * @param {boolean} isOn - True if the LCD should be on, false if not + * @url http://www.espruino.com/Reference#l_Pixl_setLCDPower + */ + static setLCDPower(isOn: boolean): void; + + /** + * Writes a command directly to the ST7567 LCD controller + * + * @param {number} c + * @url http://www.espruino.com/Reference#l_Pixl_lcdw + */ + static lcdw(c: number): void; + + /** + * Display a menu on Pixl.js's screen, and set up the buttons to navigate through + * it. + * DEPRECATED: Use `E.showMenu` + * + * @param {any} menu - An object containing name->function mappings to to be used in a menu + * @returns {any} A menu object with `draw`, `move` and `select` functions + * @url http://www.espruino.com/Reference#l_Pixl_menu + */ + static menu(menu: Menu): MenuInstance; + + +} + +/** + * This class exists in order to interface Espruino with fast-moving trigger + * wheels. Trigger wheels are physical discs with evenly spaced teeth cut into + * them, and often with one or two teeth next to each other missing. A sensor sends + * a signal whenever a tooth passed by, and this allows a device to measure not + * only RPM, but absolute position. + * This class is currently in testing - it is NOT AVAILABLE on normal boards. + * @url http://www.espruino.com/Reference#Trig + */ +declare class Trig { + /** + * Get the position of the trigger wheel at the given time (from getTime) + * + * @param {number} time - The time at which to find the position + * @returns {number} The position of the trigger wheel in degrees - as a floating point number + * @url http://www.espruino.com/Reference#l_Trig_getPosAtTime + */ + static getPosAtTime(time: number): number; + + /** + * Initialise the trigger class + * + * @param {Pin} pin - The pin to use for triggering + * @param {any} options - Additional options as an object. defaults are: ```{teethTotal:60,teethMissing:2,minRPM:30,keyPosition:0}``` + * @url http://www.espruino.com/Reference#l_Trig_setup + */ + static setup(pin: Pin, options: any): void; + + /** + * Set a trigger for a certain point in the cycle + * + * @param {number} num - The trigger number (0..7) + * @param {number} pos - The position (in degrees) to fire the trigger at + * @param {any} pins - An array of pins to pulse (max 4) + * @param {number} pulseLength - The time (in msec) to pulse for + * @url http://www.espruino.com/Reference#l_Trig_setTrigger + */ + static setTrigger(num: number, pos: number, pins: any, pulseLength: number): void; + + /** + * Disable a trigger + * + * @param {number} num - The trigger number (0..7) + * @url http://www.espruino.com/Reference#l_Trig_killTrigger + */ + static killTrigger(num: number): void; + + /** + * Get the current state of a trigger + * + * @param {number} num - The trigger number (0..7) + * @returns {any} A structure containing all information about the trigger + * @url http://www.espruino.com/Reference#l_Trig_getTrigger + */ + static getTrigger(num: number): any; + + /** + * Get the RPM of the trigger wheel + * @returns {number} The current RPM of the trigger wheel + * @url http://www.espruino.com/Reference#l_Trig_getRPM + */ + static getRPM(): number; + + /** + * Get the current error flags from the trigger wheel - and zero them + * @returns {number} The error flags + * @url http://www.espruino.com/Reference#l_Trig_getErrors + */ + static getErrors(): number; + + /** + * Get the current error flags from the trigger wheel - and zero them + * @returns {any} An array of error strings + * @url http://www.espruino.com/Reference#l_Trig_getErrorArray + */ + static getErrorArray(): any; + + +} + +/** + * Class containing AES encryption/decryption + * **Note:** This library is currently only included in builds for boards where + * there is space. For other boards there is `crypto.js` which implements SHA1 in + * JS. + * @url http://www.espruino.com/Reference#AES + */ +declare class AES { + /** + * + * @param {any} passphrase - Message to encrypt + * @param {any} key - Key to encrypt message - must be an ArrayBuffer of 128, 192, or 256 BITS + * @param {any} options - An optional object, may specify `{ iv : new Uint8Array(16), mode : 'CBC|CFB|CTR|OFB|ECB' }` + * @returns {any} Returns an ArrayBuffer + * @url http://www.espruino.com/Reference#l_AES_encrypt + */ + static encrypt(passphrase: any, key: any, options: any): ArrayBuffer; + + /** + * + * @param {any} passphrase - Message to decrypt + * @param {any} key - Key to encrypt message - must be an ArrayBuffer of 128, 192, or 256 BITS + * @param {any} options - An optional object, may specify `{ iv : new Uint8Array(16), mode : 'CBC|CFB|CTR|OFB|ECB' }` + * @returns {any} Returns an ArrayBuffer + * @url http://www.espruino.com/Reference#l_AES_decrypt + */ + static decrypt(passphrase: any, key: any, options: any): ArrayBuffer; + + +} + +/** + * This class provides Graphics operations that can be applied to a surface. + * Use Graphics.createXXX to create a graphics object that renders in the way you + * want. See [the Graphics page](https://www.espruino.com/Graphics) for more + * information. + * **Note:** On boards that contain an LCD, there is a built-in 'LCD' object of + * type Graphics. For instance to draw a line you'd type: + * ```LCD.drawLine(0,0,100,100)``` + * @url http://www.espruino.com/Reference#Graphics + */ +declare class Graphics { + /** + * On devices like Pixl.js or HYSTM boards that contain a built-in display this + * will return an instance of the graphics class that can be used to access that + * display. + * Internally, this is stored as a member called `gfx` inside the 'hiddenRoot'. + * @returns {any} An instance of `Graphics` or undefined + * @url http://www.espruino.com/Reference#l_Graphics_getInstance + */ + static getInstance(): Graphics | undefined + + /** + * Create a Graphics object that renders to an Array Buffer. This will have a field + * called 'buffer' that can get used to get at the buffer itself + * + * @param {number} width - Pixels wide + * @param {number} height - Pixels high + * @param {number} bpp - Number of bits per pixel + * @param {any} options + * An object of other options. `{ zigzag : true/false(default), vertical_byte : true/false(default), msb : true/false(default), color_order: 'rgb'(default),'bgr',etc }` + * `zigzag` = whether to alternate the direction of scanlines for rows + * `vertical_byte` = whether to align bits in a byte vertically or not + * `msb` = when bits<8, store pixels most significant bit first, when bits>8, store most significant byte first + * `interleavex` = Pixels 0,2,4,etc are from the top half of the image, 1,3,5,etc from the bottom half. Used for P3 LED panels. + * `color_order` = re-orders the colour values that are supplied via setColor + * @returns {any} The new Graphics object + * @url http://www.espruino.com/Reference#l_Graphics_createArrayBuffer + */ + static createArrayBuffer(width: number, height: number, bpp: number, options?: { zigzag?: boolean, vertical_byte?: boolean, msb?: boolean, color_order?: "rgb" | "rbg" | "brg" | "bgr" | "grb" | "gbr" }): Graphics; + + /** + * Create a Graphics object that renders by calling a JavaScript callback function + * to draw pixels + * + * @param {number} width - Pixels wide + * @param {number} height - Pixels high + * @param {number} bpp - Number of bits per pixel + * @param {any} callback - A function of the form ```function(x,y,col)``` that is called whenever a pixel needs to be drawn, or an object with: ```{setPixel:function(x,y,col),fillRect:function(x1,y1,x2,y2,col)}```. All arguments are already bounds checked. + * @returns {any} The new Graphics object + * @url http://www.espruino.com/Reference#l_Graphics_createCallback + */ + static createCallback(width: number, height: number, bpp: number, callback: ((x: number, y: number, col: number) => void) | { setPixel: (x: number, y: number, col: number) => void; fillRect: (x1: number, y1: number, x2: number, y2: number, col: number) => void }): Graphics; + + /** + * Create a Graphics object that renders to SDL window (Linux-based devices only) + * + * @param {number} width - Pixels wide + * @param {number} height - Pixels high + * @param {number} bpp - Bits per pixel (8,16,24 or 32 supported) + * @returns {any} The new Graphics object + * @url http://www.espruino.com/Reference#l_Graphics_createSDL + */ + static createSDL(width: number, height: number, bpp: number): Graphics; + + /** + * Create a simple Black and White image for use with `Graphics.drawImage`. + * Use as follows: + * ``` + * var img = Graphics.createImage(` + * XXXXXXXXX + * X X + * X X X + * X X X + * X X + * XXXXXXXXX + * `); + * g.drawImage(img, x,y); + * ``` + * If the characters at the beginning and end of the string are newlines, they will + * be ignored. Spaces are treated as `0`, and any other character is a `1` + * + * @param {any} str - A String containing a newline-separated image - space is 0, anything else is 1 + * @returns {any} An Image object that can be used with `Graphics.drawImage` + * @url http://www.espruino.com/Reference#l_Graphics_createImage + */ + static createImage(str: string): ImageObject; + + /** + * Set the current font + * + * @param {number} scale - (optional) If >1 the font will be scaled up by that amount + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setFont6x15 + */ + setFont6x15(scale: number): Graphics; + + /** + * Set the current font + * + * @param {number} scale - (optional) If >1 the font will be scaled up by that amount + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setFont12x20 + */ + setFont12x20(scale: number): Graphics; + + /** + * On instances of graphics that drive a display with an offscreen buffer, calling + * this function will copy the contents of the offscreen buffer to the screen. + * Call this when you have drawn something to Graphics and you want it shown on the + * screen. + * If a display does not have an offscreen buffer, it may not have a `g.flip()` + * method. + * On Bangle.js 1, there are different graphics modes chosen with + * `Bangle.setLCDMode()`. The default mode is unbuffered and in this mode + * `g.flip()` does not affect the screen contents. + * On some devices, this command will attempt to only update the areas of the + * screen that have changed in order to increase speed. If you have accessed the + * `Graphics.buffer` directly then you may need to use `Graphics.flip(true)` to + * force a full update of the screen. + * + * @param {boolean} [all] - [optional] (only on some devices) If `true` then copy all pixels, not just those that have changed. + * @url http://www.espruino.com/Reference#l_Graphics_flip + */ + flip(all?: boolean): void; + + /** + * On Graphics instances with an offscreen buffer, this is an `ArrayBuffer` that + * provides access to the underlying pixel data. + * ``` + * g=Graphics.createArrayBuffer(8,8,8) + * g.drawLine(0,0,7,7) + * print(new Uint8Array(g.buffer)) + * new Uint8Array([ + * 255, 0, 0, 0, 0, 0, 0, 0, + * 0, 255, 0, 0, 0, 0, 0, 0, + * 0, 0, 255, 0, 0, 0, 0, 0, + * 0, 0, 0, 255, 0, 0, 0, 0, + * 0, 0, 0, 0, 255, 0, 0, 0, + * 0, 0, 0, 0, 0, 255, 0, 0, + * 0, 0, 0, 0, 0, 0, 255, 0, + * 0, 0, 0, 0, 0, 0, 0, 255]) + * ``` + * @returns {any} An ArrayBuffer (or not defined on Graphics instances not created with `Graphics.createArrayBuffer`) + * @url http://www.espruino.com/Reference#l_Graphics_buffer + */ + buffer: IsBuffer extends true ? ArrayBuffer : undefined + + /** + * The width of this Graphics instance + * @returns {number} The width of this Graphics instance + * @url http://www.espruino.com/Reference#l_Graphics_getWidth + */ + getWidth(): number; + + /** + * The height of this Graphics instance + * @returns {number} The height of this Graphics instance + * @url http://www.espruino.com/Reference#l_Graphics_getHeight + */ + getHeight(): number; + + /** + * The number of bits per pixel of this Graphics instance + * **Note:** Bangle.js 2 behaves a little differently here. The display is 3 bit, + * so `getBPP` returns 3 and `asBMP`/`asImage`/etc return 3 bit images. However in + * order to allow dithering, the colors returned by `Graphics.getColor` and + * `Graphics.theme` are actually 16 bits. + * @returns {number} The bits per pixel of this Graphics instance + * @url http://www.espruino.com/Reference#l_Graphics_getBPP + */ + getBPP(): number; + + /** + * Reset the state of Graphics to the defaults (e.g. Color, Font, etc) that would + * have been used when Graphics was initialised. + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_reset + */ + reset(): Graphics; + + /** + * Clear the LCD with the Background Color + * + * @param {boolean} [reset] - [optional] If `true`, resets the state of Graphics to the default (eg. Color, Font, etc) as if calling `Graphics.reset` + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_clear + */ + clear(reset?: boolean): Graphics; + + /** + * Fill a rectangular area in the Foreground Color + * On devices with enough memory, you can specify `{x,y,x2,y2,r}` as the first + * argument, which allows you to draw a rounded rectangle. + * + * @param {any} x1 - The left X coordinate OR an object containing `{x,y,x2,y2}` or `{x,y,w,h}` + * @param {number} y1 - The top Y coordinate + * @param {number} x2 - The right X coordinate + * @param {number} y2 - The bottom Y coordinate + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_fillRect + */ + fillRect(x1: number, y1: number, x2: number, y2: number): Graphics; + fillRect(rect: { x: number, y: number, x2: number, y2: number } | { x: number, y: number, w: number, h: number }): Graphics; + + /** + * Fill a rectangular area in the Background Color + * On devices with enough memory, you can specify `{x,y,x2,y2,r}` as the first + * argument, which allows you to draw a rounded rectangle. + * + * @param {any} x1 - The left X coordinate OR an object containing `{x,y,x2,y2}` or `{x,y,w,h}` + * @param {number} y1 - The top Y coordinate + * @param {number} x2 - The right X coordinate + * @param {number} y2 - The bottom Y coordinate + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_clearRect + */ + clearRect(x1: number, y1: number, x2: number, y2: number): Graphics; + clearRect(rect: { x: number, y: number, x2: number, y2: number } | { x: number, y: number, w: number, h: number }): Graphics; + + /** + * Draw an unfilled rectangle 1px wide in the Foreground Color + * + * @param {any} x1 - The left X coordinate OR an object containing `{x,y,x2,y2}` or `{x,y,w,h}` + * @param {number} y1 - The top Y coordinate + * @param {number} x2 - The right X coordinate + * @param {number} y2 - The bottom Y coordinate + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawRect + */ + drawRect(x1: number, y1: number, x2: number, y2: number): Graphics; + drawRect(rect: { x: number, y: number, x2: number, y2: number } | { x: number, y: number, w: number, h: number }): Graphics; + + /** + * Draw a filled circle in the Foreground Color + * + * @param {number} x - The X axis + * @param {number} y - The Y axis + * @param {number} rad - The circle radius + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_fillCircle + */ + fillCircle(x: number, y: number, rad: number): Graphics; + + /** + * Draw an unfilled circle 1px wide in the Foreground Color + * + * @param {number} x - The X axis + * @param {number} y - The Y axis + * @param {number} rad - The circle radius + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawCircle + */ + drawCircle(x: number, y: number, rad: number): Graphics; + + /** + * Draw a circle, centred at (x,y) with radius r in the current foreground color + * + * @param {number} x - Centre x-coordinate + * @param {number} y - Centre y-coordinate + * @param {number} r - Radius + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawCircleAA + */ + drawCircleAA(x: number, y: number, r: number): Graphics; + + /** + * Draw a filled ellipse in the Foreground Color + * + * @param {number} x1 - The left X coordinate + * @param {number} y1 - The top Y coordinate + * @param {number} x2 - The right X coordinate + * @param {number} y2 - The bottom Y coordinate + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_fillEllipse + */ + fillEllipse(x1: number, y1: number, x2: number, y2: number): Graphics; + + /** + * Draw an ellipse in the Foreground Color + * + * @param {number} x1 - The left X coordinate + * @param {number} y1 - The top Y coordinate + * @param {number} x2 - The right X coordinate + * @param {number} y2 - The bottom Y coordinate + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawEllipse + */ + drawEllipse(x1: number, y1: number, x2: number, y2: number): Graphics; + + /** + * Get a pixel's color + * + * @param {number} x - The left + * @param {number} y - The top + * @returns {number} The color + * @url http://www.espruino.com/Reference#l_Graphics_getPixel + */ + getPixel(x: number, y: number): number; + + /** + * Set a pixel's color + * + * @param {number} x - The left + * @param {number} y - The top + * @param {any} col - The color (if `undefined`, the foreground color is useD) + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setPixel + */ + setPixel(x: number, y: number, col?: ColorResolvable): Graphics; + + /** + * Work out the color value to be used in the current bit depth based on the arguments. + * This is used internally by setColor and setBgColor + * ``` + * // 1 bit + * g.toColor(1,1,1) => 1 + * // 16 bit + * g.toColor(1,0,0) => 0xF800 + * ``` + * + * @param {any} r - Red (between 0 and 1) **OR** an integer representing the color in the current bit depth and color order **OR** a hexidecimal color string of the form `'#rrggbb' or `'#rgb'` + * @param {any} g - Green (between 0 and 1) + * @param {any} b - Blue (between 0 and 1) + * @returns {number} The color index represented by the arguments + * @url http://www.espruino.com/Reference#l_Graphics_toColor + */ + toColor(r: number, g: number, b: number): number; + toColor(col: ColorResolvable): number; + + /** + * Blend between two colors, and return the result. + * ``` + * // dark yellow - halfway between red and green + * var col = g.blendColor("#f00","#0f0", 0.5); + * // Get a color 25% brighter than the theme's background colour + * var col = g.blendColor(g.theme.fg,g.theme.bg, 0.75); + * // then... + * g.setColor(col).fillRect(10,10,100,100); + * ``` + * + * @param {any} col_a - Color to blend from (either a single integer color value, or a string) + * @param {any} col_b - Color to blend to (either a single integer color value, or a string) + * @param {any} amt - The amount to blend. 0=col_a, 1=col_b, 0.5=halfway between (and so on) + * @returns {number} The color index represented by the blended colors + * @url http://www.espruino.com/Reference#l_Graphics_blendColor + */ + blendColor(col_a: ColorResolvable, col_b: ColorResolvable, amt: number): number; + + /** + * Set the color to use for subsequent drawing operations. + * If just `r` is specified as an integer, the numeric value will be written directly into a pixel. eg. On a 24 bit `Graphics` instance you set bright blue with either `g.setColor(0,0,1)` or `g.setColor(0x0000FF)`. + * A good shortcut to ensure you get white on all platforms is to use `g.setColor(-1)` + * The mapping is as follows: + * * 32 bit: `r,g,b` => `0xFFrrggbb` + * * 24 bit: `r,g,b` => `0xrrggbb` + * * 16 bit: `r,g,b` => `0brrrrrggggggbbbbb` (RGB565) + * * Other bpp: `r,g,b` => white if `r+g+b > 50%`, otherwise black (use `r` on its own as an integer) + * If you specified `color_order` when creating the `Graphics` instance, `r`,`g` and `b` will be swapped as you specified. + * **Note:** On devices with low flash memory, `r` **must** be an integer representing the color in the current bit depth. It cannot + * be a floating point value, and `g` and `b` are ignored. + * + * @param {any} r - Red (between 0 and 1) **OR** an integer representing the color in the current bit depth and color order **OR** a hexidecimal color string of the form `'#012345'` + * @param {any} [g] - [optional] Green (between 0 and 1) + * @param {any} [b] - [optional] Blue (between 0 and 1) + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setColor + */ + setColor(r: number, g: number, b: number): number; + setColor(col: ColorResolvable): number; + + /** + * Set the background color to use for subsequent drawing operations. + * See `Graphics.setColor` for more information on the mapping of `r`, `g`, and `b` to pixel values. + * **Note:** On devices with low flash memory, `r` **must** be an integer representing the color in the current bit depth. It cannot + * be a floating point value, and `g` and `b` are ignored. + * + * @param {any} r - Red (between 0 and 1) **OR** an integer representing the color in the current bit depth and color order **OR** a hexidecimal color string of the form `'#012345'` + * @param {any} g - Green (between 0 and 1) + * @param {any} b - Blue (between 0 and 1) + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setBgColor + */ + setBgColor(r: number, g: number, b: number): number; + setBgColor(col: ColorResolvable): number; + + /** + * Get the color to use for subsequent drawing operations + * @returns {number} The integer value of the colour + * @url http://www.espruino.com/Reference#l_Graphics_getColor + */ + getColor(): number; + + /** + * Get the background color to use for subsequent drawing operations + * @returns {number} The integer value of the colour + * @url http://www.espruino.com/Reference#l_Graphics_getBgColor + */ + getBgColor(): number; + + /** + * This sets the 'clip rect' that subsequent drawing operations are clipped to sit + * between. + * These values are inclusive - e.g. `g.setClipRect(1,0,5,0)` will ensure that only + * pixel rows 1,2,3,4,5 are touched on column 0. + * **Note:** For maximum flexibility on Bangle.js 1, the values here are not range + * checked. For normal use, X and Y should be between 0 and + * `getWidth()-1`/`getHeight()-1`. + * **Note:** The x/y values here are rotated, so that if `Graphics.setRotation` is + * used they correspond to the coordinates given to the draw functions, *not to the + * physical device pixels*. + * + * @param {number} x1 - Top left X coordinate + * @param {number} y1 - Top left Y coordinate + * @param {number} x2 - Bottom right X coordinate + * @param {number} y2 - Bottom right Y coordinate + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setClipRect + */ + setClipRect(x1: number, y1: number, x2: number, y2: number): Graphics; + + /** + * Make subsequent calls to `drawString` use the built-in 4x6 pixel bitmapped Font + * It is recommended that you use `Graphics.setFont("4x6")` for more flexibility. + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setFontBitmap + */ + setFontBitmap(): Graphics; + + /** + * Make subsequent calls to `drawString` use a Vector Font of the given height. + * It is recommended that you use `Graphics.setFont("Vector", size)` for more + * flexibility. + * + * @param {number} size - The height of the font, as an integer + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setFontVector + */ + setFontVector(size: number): Graphics; + + /** + * Make subsequent calls to `drawString` use a Custom Font of the given height. See + * the [Fonts page](http://www.espruino.com/Fonts) for more information about + * custom fonts and how to create them. + * For examples of use, see the [font + * modules](https://www.espruino.com/Fonts#font-modules). + * **Note:** while you can specify the character code of the first character with + * `firstChar`, the newline character 13 will always be treated as a newline and + * not rendered. + * + * @param {any} bitmap - A column-first, MSB-first, 1bpp bitmap containing the font bitmap + * @param {number} firstChar - The first character in the font - usually 32 (space) + * @param {any} width - The width of each character in the font. Either an integer, or a string where each character represents the width + * @param {number} height - The height as an integer (max 255). Bits 8-15 represent the scale factor (eg. `2<<8` is twice the size). Bits 16-23 represent the BPP (0,1=1 bpp, 2=2 bpp, 4=4 bpp) + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setFontCustom + */ + setFontCustom(bitmap: ArrayBuffer, firstChar: number, width: number | string, height: number): Graphics; + + /** + * Set the alignment for subsequent calls to `drawString` + * + * @param {number} x - X alignment. -1=left (default), 0=center, 1=right + * @param {number} y - Y alignment. -1=top (default), 0=center, 1=bottom + * @param {number} rotation - Rotation of the text. 0=normal, 1=90 degrees clockwise, 2=180, 3=270 + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setFontAlign + */ + setFontAlign(x: -1 | 0 | 1, y?: -1 | 0 | 1, rotation?: 0 | 1 | 2 | 3): Graphics; + + /** + * Set the font by name. Various forms are available: + * * `g.setFont("4x6")` - standard 4x6 bitmap font + * * `g.setFont("Vector:12")` - vector font 12px high + * * `g.setFont("4x6:2")` - 4x6 bitmap font, doubled in size + * * `g.setFont("6x8:2x3")` - 6x8 bitmap font, doubled in width, tripled in height + * You can also use these forms, but they are not recommended: + * * `g.setFont("Vector12")` - vector font 12px high + * * `g.setFont("4x6",2)` - 4x6 bitmap font, doubled in size + * `g.getFont()` will return the current font as a String. + * For a list of available font names, you can use `g.getFonts()`. + * + * @param {any} name - The name of the font to use (if undefined, the standard 4x6 font will be used) + * @param {number} size - The size of the font (or undefined) + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setFont + */ + setFont(name: FontNameWithScaleFactor): Graphics; + setFont(name: FontName, size: number): Graphics; + + /** + * Get the font by name - can be saved and used with `Graphics.setFont`. + * Normally this might return something like `"4x6"`, but if a scale factor is + * specified, a colon and then the size is reported, like "4x6:2" + * **Note:** For custom fonts, `Custom` is currently reported instead of the font + * name. + * @returns {any} Get the name of the current font + * @url http://www.espruino.com/Reference#l_Graphics_getFont + */ + getFont(): FontNameWithScaleFactor | "Custom" + + /** + * Return an array of all fonts currently in the Graphics library. + * **Note:** Vector fonts are specified as `Vector#` where `#` is the font height. + * As there are effectively infinite fonts, just `Vector` is included in the list. + * @returns {any} And array of font names + * @url http://www.espruino.com/Reference#l_Graphics_getFonts + */ + getFonts(): FontName[]; + + /** + * Return the height in pixels of the current font + * @returns {number} The height in pixels of the current font + * @url http://www.espruino.com/Reference#l_Graphics_getFontHeight + */ + getFontHeight(): number; + + /** + * Return the size in pixels of a string of text in the current font + * + * @param {any} str - The string + * @returns {number} The length of the string in pixels + * @url http://www.espruino.com/Reference#l_Graphics_stringWidth + */ + stringWidth(str: string): number; + + /** + * Return the width and height in pixels of a string of text in the current font + * + * @param {any} str - The string + * @returns {any} An object containing `{width,height}` of the string + * @url http://www.espruino.com/Reference#l_Graphics_stringMetrics + */ + stringMetrics(str: string): { width: number, height: number }; + + /** + * Wrap a string to the given pixel width using the current font, and return the + * lines as an array. + * To render within the screen's width you can do: + * ``` + * g.drawString(g.wrapString(text, g.getWidth()).join("\n")), + * ``` + * + * @param {any} str - The string + * @param {number} maxWidth - The width in pixels + * @returns {any} An array of lines that are all less than `maxWidth` + * @url http://www.espruino.com/Reference#l_Graphics_wrapString + */ + wrapString(str: string, maxWidth: number): string[]; + + /** + * Draw a string of text in the current font. + * ``` + * g.drawString("Hello World", 10, 10); + * ``` + * Images may also be embedded inside strings (e.g. to render Emoji or characters + * not in the current font). To do this, just add `0` then the image string ([about + * Images](http://www.espruino.com/Graphics#images-bitmaps)) For example: + * ``` + * g.drawString("Hi \0\7\5\1\x82 D\x17\xC0"); + * // draws: + * // # # # # # + * // # # # + * // ### ## # + * // # # # # # + * // # # ### ##### + * ``` + * + * @param {any} str - The string + * @param {number} x - The X position of the leftmost pixel + * @param {number} y - The Y position of the topmost pixel + * @param {boolean} solid - For bitmap fonts, should empty pixels be filled with the background color? + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawString + */ + drawString(str: string, x: number, y: number, solid?: boolean): Graphics; + + /** + * Draw a line between x1,y1 and x2,y2 in the current foreground color + * + * @param {number} x1 - The left + * @param {number} y1 - The top + * @param {number} x2 - The right + * @param {number} y2 - The bottom + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawLine + */ + drawLine(x1: number, y1: number, x2: number, y2: number): Graphics; + + /** + * Draw a line between x1,y1 and x2,y2 in the current foreground color + * + * @param {number} x1 - The left + * @param {number} y1 - The top + * @param {number} x2 - The right + * @param {number} y2 - The bottom + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawLineAA + */ + drawLineAA(x1: number, y1: number, x2: number, y2: number): Graphics; + + /** + * Draw a line from the last position of `lineTo` or `moveTo` to this position + * + * @param {number} x - X value + * @param {number} y - Y value + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_lineTo + */ + lineTo(x: number, y: number): Graphics; + + /** + * Move the cursor to a position - see lineTo + * + * @param {number} x - X value + * @param {number} y - Y value + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_moveTo + */ + moveTo(x: number, y: number): Graphics; + + /** + * Draw a polyline (lines between each of the points in `poly`) in the current + * foreground color + * **Note:** there is a limit of 64 points (128 XY elements) for polygons + * + * @param {any} poly - An array of vertices, of the form ```[x1,y1,x2,y2,x3,y3,etc]``` + * @param {boolean} closed - Draw another line between the last element of the array and the first + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawPoly + */ + drawPoly(poly: number[], closed?: boolean): Graphics; + + /** + * Draw an **antialiased** polyline (lines between each of the points in `poly`) in + * the current foreground color + * **Note:** there is a limit of 64 points (128 XY elements) for polygons + * + * @param {any} poly - An array of vertices, of the form ```[x1,y1,x2,y2,x3,y3,etc]``` + * @param {boolean} closed - Draw another line between the last element of the array and the first + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawPolyAA + */ + drawPolyAA(poly: number[], closed?: boolean): Graphics; + + /** + * Draw a filled polygon in the current foreground color. + * ``` + * g.fillPoly([ + * 16, 0, + * 31, 31, + * 26, 31, + * 16, 12, + * 6, 28, + * 0, 27 ]); + * ``` + * This fills from the top left hand side of the polygon (low X, low Y) *down to + * but not including* the bottom right. When placed together polygons will align + * perfectly without overdraw - but this will not fill the same pixels as + * `drawPoly` (drawing a line around the edge of the polygon). + * **Note:** there is a limit of 64 points (128 XY elements) for polygons + * + * @param {any} poly - An array of vertices, of the form ```[x1,y1,x2,y2,x3,y3,etc]``` + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_fillPoly + */ + fillPoly(poly: number[]): Graphics; + + /** + * Draw a filled polygon in the current foreground color. + * ``` + * g.fillPolyAA([ + * 16, 0, + * 31, 31, + * 26, 31, + * 16, 12, + * 6, 28, + * 0, 27 ]); + * ``` + * This fills from the top left hand side of the polygon (low X, low Y) *down to + * but not including* the bottom right. When placed together polygons will align + * perfectly without overdraw - but this will not fill the same pixels as + * `drawPoly` (drawing a line around the edge of the polygon). + * **Note:** there is a limit of 64 points (128 XY elements) for polygons + * + * @param {any} poly - An array of vertices, of the form ```[x1,y1,x2,y2,x3,y3,etc]``` + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_fillPolyAA + */ + fillPolyAA(poly: number[]): Graphics; + + /** + * Set the current rotation of the graphics device. + * + * @param {number} rotation - The clockwise rotation. 0 for no rotation, 1 for 90 degrees, 2 for 180, 3 for 270 + * @param {boolean} reflect - Whether to reflect the image + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setRotation + */ + setRotation(rotation: 0 | 1 | 2 | 3, reflect?: boolean): Graphics; + + /** + * Return the width and height in pixels of an image (either Graphics, Image + * Object, Image String or ArrayBuffer). Returns `undefined` if image couldn't be + * decoded. + * `frames` is also included is the image contains more information than you'd + * expect for a single bitmap. In this case the bitmap might be an animation with + * multiple frames + * + * @param {any} str - The string + * @returns {any} An object containing `{width,height,bpp,transparent}` for the image + * @url http://www.espruino.com/Reference#l_Graphics_imageMetrics + */ + imageMetrics(img: Image): { width: number, height: number, bpp: number, transparent: number, frames?: ArrayBuffer[] } | undefined; + + /** + * Image can be: + * * An object with the following fields `{ width : int, height : int, bpp : + * optional int, buffer : ArrayBuffer/String, transparent: optional int, + * palette : optional Uint16Array(2/4/16) }`. bpp = bits per pixel (default is + * 1), transparent (if defined) is the colour that will be treated as + * transparent, and palette is a color palette that each pixel will be looked up + * in first + * * A String where the the first few bytes are: + * `width,height,bpp,[transparent,]image_bytes...`. If a transparent colour is + * specified the top bit of `bpp` should be set. + * * An ArrayBuffer Graphics object (if `bpp<8`, `msb:true` must be set) - this is + * disabled on devices without much flash memory available + * Draw an image at the specified position. + * * If the image is 1 bit, the graphics foreground/background colours will be + * used. + * * If `img.palette` is a Uint16Array or 2/4/16 elements, color data will be + * looked from the supplied palette + * * On Bangle.js, 2 bit images blend from background(0) to foreground(1) colours + * * On Bangle.js, 4 bit images use the Apple Mac 16 color palette + * * On Bangle.js, 8 bit images use the Web Safe 216 color palette + * * Otherwise color data will be copied as-is. Bitmaps are rendered MSB-first + * If `options` is supplied, `drawImage` will allow images to be rendered at any + * scale or angle. If `options.rotate` is set it will center images at `x,y`. + * `options` must be an object of the form: + * ``` + * { + * rotate : float, // the amount to rotate the image in radians (default 0) + * scale : float, // the amount to scale the image up (default 1) + * frame : int // if specified and the image has frames of data + * // after the initial frame, draw one of those frames from the image + * } + * ``` + * For example: + * ``` + * // In the top left of the screen + * g.drawImage(img,0,0); + * // In the top left of the screen, twice as big + * g.drawImage(img,0,0,{scale:2}); + * // In the center of the screen, twice as big, 45 degrees + * g.drawImage(img, g.getWidth()/2, g.getHeight()/2, + * {scale:2, rotate:Math.PI/4}); + * ``` + * + * @param {any} image - An image to draw, either a String or an Object (see below) + * @param {number} x - The X offset to draw the image + * @param {number} y - The Y offset to draw the image + * @param {any} options - options for scaling,rotation,etc (see below) + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawImage + */ + drawImage(image: Image, x: number, y: number, options?: { rotate?: number, scale?: number, frame?: number }): Graphics; + + /** + * Draws multiple images *at once* - which avoids flicker on unbuffered systems + * like Bangle.js. Maximum layer count right now is 4. + * ``` + * layers = [ { + * {x : int, // x start position + * y : int, // y start position + * image : string/object, + * scale : float, // scale factor, default 1 + * rotate : float, // angle in radians + * center : bool // center on x,y? default is top left + * repeat : should this image be repeated (tiled?) + * nobounds : bool // if true, the bounds of the image are not used to work out the default area to draw + * } + * ] + * options = { // the area to render. Defaults to rendering just enough to cover what's requested + * x,y, + * width,height + * } + * ``` + * + * @param {any} layers - An array of objects {x,y,image,scale,rotate,center} (up to 3) + * @param {any} options - options for rendering - see below + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_drawImages + */ + drawImages(layers: { x: number, y: number, image: Image, scale?: number, rotate?: number, center?: boolean, repeat?: boolean, nobounds?: boolean }[], options?: { x: number, y: number, width: number, height: number }): Graphics; + + /** + * Return this Graphics object as an Image that can be used with + * `Graphics.drawImage`. Check out [the Graphics reference + * page](http://www.espruino.com/Graphics#images-bitmaps) for more information on + * images. + * Will return undefined if data can't be allocated for the image. + * The image data itself will be referenced rather than copied if: + * * An image `object` was requested (not `string`) + * * The Graphics instance was created with `Graphics.createArrayBuffer` + * * Is 8 bpp *OR* the `{msb:true}` option was given + * * No other format options (zigzag/etc) were given + * Otherwise data will be copied, which takes up more space and may be quite slow. + * + * @param {any} type - The type of image to return. Either `object`/undefined to return an image object, or `string` to return an image string + * @returns {any} An Image that can be used with `Graphics.drawImage` + * @url http://www.espruino.com/Reference#l_Graphics_asImage + */ + asImage(type?: "object"): ImageObject; + asImage(type: "string"): string; + + /** + * Return the area of the Graphics canvas that has been modified, and optionally + * clear the modified area to 0. + * For instance if `g.setPixel(10,20)` was called, this would return `{x1:10, + * y1:20, x2:10, y2:20}` + * + * @param {boolean} reset - Whether to reset the modified area or not + * @returns {any} An object {x1,y1,x2,y2} containing the modified area, or undefined if not modified + * @url http://www.espruino.com/Reference#l_Graphics_getModified + */ + getModified(reset?: boolean): { x1: number, y1: number, x2: number, y2: number }; + + /** + * Scroll the contents of this graphics in a certain direction. The remaining area + * is filled with the background color. + * Note: This uses repeated pixel reads and writes, so will not work on platforms + * that don't support pixel reads. + * + * @param {number} x - X direction. >0 = to right + * @param {number} y - Y direction. >0 = down + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_scroll + */ + scroll(x: number, y: number): Graphics; + + /** + * Blit one area of the screen (x1,y1 w,h) to another (x2,y2 w,h) + * ``` + * g.blit({ + * x1:0, y1:0, + * w:32, h:32, + * x2:100, y2:100, + * setModified : true // should we set the modified area? + * }); + * ``` + * Note: This uses repeated pixel reads and writes, so will not work on platforms + * that don't support pixel reads. + * + * @param {any} options - options - see below + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_blit + */ + blit(options: { x1: number, y1: number, x2: number, y2: number, w: number, h: number, setModified?: boolean }): Graphics; + + /** + * Create a Windows BMP file from this Graphics instance, and return it as a + * String. + * @returns {any} A String representing the Graphics as a Windows BMP file (or 'undefined' if not possible) + * @url http://www.espruino.com/Reference#l_Graphics_asBMP + */ + asBMP(): string; + + /** + * Create a URL of the form `data:image/bmp;base64,...` that can be pasted into the + * browser. + * The Espruino Web IDE can detect this data on the console and render the image + * inline automatically. + * @returns {any} A String representing the Graphics as a URL (or 'undefined' if not possible) + * @url http://www.espruino.com/Reference#l_Graphics_asURL + */ + asURL(): string; + + /** + * Output this image as a bitmap URL of the form `data:image/bmp;base64,...`. The + * Espruino Web IDE will detect this on the console and will render the image + * inline automatically. + * This is identical to `console.log(g.asURL())` - it is just a convenient function + * for easy debugging and producing screenshots of what is currently in the + * Graphics instance. + * **Note:** This may not work on some bit depths of Graphics instances. It will + * also not work for the main Graphics instance of Bangle.js 1 as the graphics on + * Bangle.js 1 are stored in write-only memory. + * @url http://www.espruino.com/Reference#l_Graphics_dump + */ + dump(): void; + + /** + * Calculate the square area under a Bezier curve. + * x0,y0: start point x1,y1: control point y2,y2: end point + * Max 10 points without start point. + * + * @param {any} arr - An array of three vertices, six enties in form of ```[x0,y0,x1,y1,x2,y2]``` + * @param {any} options - number of points to calulate + * @returns {any} Array with calculated points + * @url http://www.espruino.com/Reference#l_Graphics_quadraticBezier + */ + quadraticBezier(arr: [number, number, number, number, number, number], options?: number): number[]; + + /** + * Transformation can be: + * * An object of the form + * ``` + * { + * x: float, // x offset (default 0) + * y: float, // y offset (default 0) + * scale: float, // scale factor (default 1) + * rotate: float, // angle in radians (default 0) + * } + * ``` + * * A six-element array of the form `[a,b,c,d,e,f]`, which represents the 2D transformation matrix + * ``` + * a c e + * b d f + * 0 0 1 + * ``` + * Apply a transformation to an array of vertices. + * + * @param {any} verts - An array of vertices, of the form ```[x1,y1,x2,y2,x3,y3,etc]``` + * @param {any} transformation - The transformation to apply, either an Object or an Array (see below) + * @returns {any} Array of transformed vertices + * @url http://www.espruino.com/Reference#l_Graphics_transformVertices + */ + transformVertices(arr: number[], transformation: { x?: number, y?: number, scale?: number, rotate?: number } | [number, number, number, number, number, number]): number[]; + + /** + * Returns an object of the form: + * ``` + * { + * fg : 0xFFFF, // foreground colour + * bg : 0, // background colour + * fg2 : 0xFFFF, // accented foreground colour + * bg2 : 0x0007, // accented background colour + * fgH : 0xFFFF, // highlighted foreground colour + * bgH : 0x02F7, // highlighted background colour + * dark : true, // Is background dark (e.g. foreground should be a light colour) + * } + * ``` + * These values can then be passed to `g.setColor`/`g.setBgColor` for example + * `g.setColor(g.theme.fg2)`. When the Graphics instance is reset, the background + * color is automatically set to `g.theme.bg` and foreground is set to + * `g.theme.fg`. + * On Bangle.js these values can be changed by writing updated values to `theme` in + * `settings.js` and reloading the app - or they can be changed temporarily by + * calling `Graphics.setTheme` + * @returns {any} An object containing the current 'theme' (see below) + * @url http://www.espruino.com/Reference#l_Graphics_theme + */ + theme: Theme; + + /** + * Set the global colour scheme. On Bangle.js, this is reloaded from + * `settings.json` for each new app loaded. + * See `Graphics.theme` for the fields that can be provided. For instance you can + * change the background to red using: + * ``` + * g.setTheme({bg:"#f00"}); + * ``` + * + * @param {any} theme - An object of the form returned by `Graphics.theme` + * @returns {any} The instance of Graphics this was called on, to allow call chaining + * @url http://www.espruino.com/Reference#l_Graphics_setTheme + */ + setTheme(theme: { [key in keyof Theme]?: Theme[key] extends number ? ColorResolvable : Theme[key] }): Graphics; +} + +/** + * This class helps to convert URLs into Objects of information ready for + * http.request/get + * @url http://www.espruino.com/Reference#url + */ +declare class url { + /** + * A utility function to split a URL into parts + * This is useful in web servers for instance when handling a request. + * For instance `url.parse("/a?b=c&d=e",true)` returns + * `{"method":"GET","host":"","path":"/a?b=c&d=e","pathname":"/a","search":"?b=c&d=e","port":80,"query":{"b":"c","d":"e"}}` + * + * @param {any} urlStr - A URL to be parsed + * @param {boolean} parseQuery - Whether to parse the query string into an object not (default = false) + * @returns {any} An object containing options for ```http.request``` or ```http.get```. Contains `method`, `host`, `path`, `pathname`, `search`, `port` and `query` + * @url http://www.espruino.com/Reference#l_url_parse + */ + static parse(urlStr: any, parseQuery: boolean): any; + + +} + +/** + * The socket server created by `require('net').createServer` + * @url http://www.espruino.com/Reference#Server + */ +declare class Server { + + + /** + * Start listening for new connections on the given port + * + * @param {number} port - The port to listen on + * @returns {any} The HTTP server instance that 'listen' was called on + * @url http://www.espruino.com/Reference#l_Server_listen + */ + listen(port: number): any; + + /** + * Stop listening for new connections + * @url http://www.espruino.com/Reference#l_Server_close + */ + close(): void; +} + +/** + * An actual socket connection - allowing transmit/receive of TCP data + * @url http://www.espruino.com/Reference#Socket + */ +declare class Socket { + /** + * The 'data' event is called when data is received. If a handler is defined with + * `X.on('data', function(data) { ... })` then it will be called, otherwise data + * will be stored in an internal buffer, where it can be retrieved with `X.read()` + * @param {string} event - The event to listen to. + * @param {(data: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `data` A string containing one or more characters of received data + * @url http://www.espruino.com/Reference#l_Socket_data + */ + static on(event: "data", callback: (data: any) => void): void; + + /** + * Called when the connection closes. + * @param {string} event - The event to listen to. + * @param {(had_error: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `had_error` A boolean indicating whether the connection had an error (use an error event handler to get error details). + * @url http://www.espruino.com/Reference#l_Socket_close + */ + static on(event: "close", callback: (had_error: any) => void): void; + + /** + * There was an error on this socket and it is closing (or wasn't opened in the + * first place). If a "connected" event was issued on this socket then the error + * event is always followed by a close event. The error codes are: + * * -1: socket closed (this is not really an error and will not cause an error + * callback) + * * -2: out of memory (typically while allocating a buffer to hold data) + * * -3: timeout + * * -4: no route + * * -5: busy + * * -6: not found (DNS resolution) + * * -7: max sockets (... exceeded) + * * -8: unsent data (some data could not be sent) + * * -9: connection reset (or refused) + * * -10: unknown error + * * -11: no connection + * * -12: bad argument + * * -13: SSL handshake failed + * * -14: invalid SSL data + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An error object with an error code (a negative integer) and a message. + * @url http://www.espruino.com/Reference#l_Socket_error + */ + static on(event: "error", callback: (details: any) => void): void; + + /** + * An event that is fired when the buffer is empty and it can accept more data to + * send. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Socket_drain + */ + static on(event: "drain", callback: () => void): void; + + /** + * Return how many bytes are available to read. If there is already a listener for + * data, this will always return 0. + * @returns {number} How many bytes are available + * @url http://www.espruino.com/Reference#l_Socket_available + */ + available(): number; + + /** + * Return a string containing characters that have been received + * + * @param {number} chars - The number of characters to read, or undefined/0 for all available + * @returns {any} A string containing the required bytes. + * @url http://www.espruino.com/Reference#l_Socket_read + */ + read(chars: number): any; + + /** + * Pipe this to a stream (an object with a 'write' method) + * + * @param {any} destination - The destination file/stream that will receive content from the source. + * @param {any} options + * An optional object `{ chunkSize : int=32, end : bool=true, complete : function }` + * chunkSize : The amount of data to pipe from source to destination at a time + * complete : a function to call when the pipe activity is complete + * end : call the 'end' function on the destination when the source is finished + * @url http://www.espruino.com/Reference#l_Socket_pipe + */ + pipe(destination: any, options: any): void; + + /** + * This function writes the `data` argument as a string. Data that is passed in + * (including arrays) will be converted to a string with the normal JavaScript + * `toString` method. + * If you wish to send binary data then you need to convert that data directly to a + * String. This can be done with `String.fromCharCode`, however it's often easier + * and faster to use the Espruino-specific `E.toString`, which will read its + * arguments as an array of bytes and convert that to a String: + * ``` + * socket.write(E.toString([0,1,2,3,4,5])); + * ``` + * If you need to send something other than bytes, you can use 'Typed Arrays', or + * even `DataView`: + * ``` + * var d = new DataView(new ArrayBuffer(8)); // 8 byte array buffer + * d.setFloat32(0, 765.3532564); // write float at bytes 0-3 + * d.setInt8(4, 42); // write int8 at byte 4 + * socket.write(E.toString(d.buffer)) + * ``` + * + * @param {any} data - A string containing data to send + * @returns {boolean} For node.js compatibility, returns the boolean false. When the send buffer is empty, a `drain` event will be sent + * @url http://www.espruino.com/Reference#l_Socket_write + */ + write(data: any): boolean; + + /** + * Close this socket - optional data to append as an argument. + * See `Socket.write` for more information about the data argument + * + * @param {any} data - A string containing data to send + * @url http://www.espruino.com/Reference#l_Socket_end + */ + end(data: any): void; +} + +/** + * An actual socket connection - allowing transmit/receive of TCP data + * @url http://www.espruino.com/Reference#dgramSocket + */ +declare class dgramSocket { + /** + * The 'message' event is called when a datagram message is received. If a handler + * is defined with `X.on('message', function(msg) { ... })` then it will be called` + * @param {string} event - The event to listen to. + * @param {(msg: any, rinfo: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `msg` A string containing the received message + * * `rinfo` Sender address,port containing information + * @url http://www.espruino.com/Reference#l_dgramSocket_message + */ + static on(event: "message", callback: (msg: any, rinfo: any) => void): void; + + /** + * Called when the connection closes. + * @param {string} event - The event to listen to. + * @param {(had_error: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `had_error` A boolean indicating whether the connection had an error (use an error event handler to get error details). + * @url http://www.espruino.com/Reference#l_dgramSocket_close + */ + static on(event: "close", callback: (had_error: any) => void): void; + + /** + * + * @param {any} buffer - A string containing message to send + * @param {any} offset - Offset in the passed string where the message starts [optional] + * @param {any} length - Number of bytes in the message [optional] + * @param {any} args - Destination port number, Destination IP address string + * @url http://www.espruino.com/Reference#l_dgramSocket_send + */ + send(buffer: any, offset: any, length: any, ...args: any[]): void; + + /** + * + * @param {number} port - The port to bind at + * @param {any} callback - A function(res) that will be called when the socket is bound. You can then call `res.on('message', function(message, info) { ... })` and `res.on('close', function() { ... })` to deal with the response. + * @returns {any} The dgramSocket instance that 'bind' was called on + * @url http://www.espruino.com/Reference#l_dgramSocket_bind + */ + bind(port: number, callback: any): any; + + /** + * Close the socket + * @url http://www.espruino.com/Reference#l_dgramSocket_close + */ + close(): void; + + /** + * + * @param {any} group - A string containing the group ip to join + * @param {any} ip - A string containing the ip to join with + * @url http://www.espruino.com/Reference#l_dgramSocket_addMembership + */ + addMembership(group: any, ip: any): void; +} + +/** + * An instantiation of a WiFi network adaptor + * @url http://www.espruino.com/Reference#WLAN + */ +declare class WLAN { + + + /** + * Connect to a wireless network + * + * @param {any} ap - Access point name + * @param {any} key - WPA2 key (or undefined for unsecured connection) + * @param {any} callback - Function to call back with connection status. It has one argument which is one of 'connect'/'disconnect'/'dhcp' + * @returns {boolean} True if connection succeeded, false if it didn't. + * @url http://www.espruino.com/Reference#l_WLAN_connect + */ + connect(ap: any, key: any, callback: any): boolean; + + /** + * Completely uninitialise and power down the CC3000. After this you'll have to use + * ```require("CC3000").connect()``` again. + * @url http://www.espruino.com/Reference#l_WLAN_disconnect + */ + disconnect(): void; + + /** + * Completely uninitialise and power down the CC3000, then reconnect to the old + * access point. + * @url http://www.espruino.com/Reference#l_WLAN_reconnect + */ + reconnect(): void; + + /** + * Get the current IP address + * @returns {any} + * @url http://www.espruino.com/Reference#l_WLAN_getIP + */ + getIP(): any; + + /** + * Set the current IP address for get an IP from DHCP (if no options object is + * specified). + * **Note:** Changes are written to non-volatile memory, but will only take effect + * after calling `wlan.reconnect()` + * + * @param {any} options - Object containing IP address options `{ ip : '1,2,3,4', subnet, gateway, dns }`, or do not supply an object in otder to force DHCP. + * @returns {boolean} True on success + * @url http://www.espruino.com/Reference#l_WLAN_setIP + */ + setIP(options: any): boolean; +} + +/** + * Class containing utility functions for the + * [ESP8266](http://www.espruino.com/EspruinoESP8266) + * @url http://www.espruino.com/Reference#ESP8266 + */ +declare class ESP8266 { + /** + * **DEPRECATED** - please use `Wifi.ping` instead. + * Perform a network ping request. The parameter can be either a String or a + * numeric IP address. + * + * @param {any} ipAddr - A string representation of an IP address. + * @param {any} pingCallback - Optional callback function. + * @url http://www.espruino.com/Reference#l_ESP8266_ping + */ + static ping(ipAddr: any, pingCallback: any): void; + + /** + * Perform a hardware reset/reboot of the esp8266. + * @url http://www.espruino.com/Reference#l_ESP8266_reboot + */ + static reboot(): void; + + /** + * At boot time the esp8266's firmware captures the cause of the reset/reboot. This + * function returns this information in an object with the following fields: + * * `reason`: "power on", "wdt reset", "exception", "soft wdt", "restart", "deep + * sleep", or "reset pin" + * * `exccause`: exception cause + * * `epc1`, `epc2`, `epc3`: instruction pointers + * * `excvaddr`: address being accessed + * * `depc`: (?) + * @returns {any} An object with the reset cause information + * @url http://www.espruino.com/Reference#l_ESP8266_getResetInfo + */ + static getResetInfo(): any; + + /** + * Enable or disable the logging of debug information. A value of `true` enables + * debug logging while a value of `false` disables debug logging. Debug output is + * sent to UART1 (gpio2). + * + * @param {boolean} enable - Enable or disable the debug logging. + * @url http://www.espruino.com/Reference#l_ESP8266_logDebug + */ + static logDebug(enable: boolean): void; + + /** + * Set the debug logging mode. It can be disabled (which frees ~1.2KB of heap), + * enabled in-memory only, or in-memory and output to a UART. + * + * @param {number} mode - Debug log mode: 0=off, 1=in-memory only, 2=in-mem and uart0, 3=in-mem and uart1. + * @url http://www.espruino.com/Reference#l_ESP8266_setLog + */ + static setLog(mode: number): void; + + /** + * Prints the contents of the debug log to the console. + * @url http://www.espruino.com/Reference#l_ESP8266_printLog + */ + static printLog(): void; + + /** + * Returns one line from the log or up to 128 characters. + * @url http://www.espruino.com/Reference#l_ESP8266_readLog + */ + static readLog(): void; + + /** + * Dumps info about all sockets to the log. This is for troubleshooting the socket + * implementation. + * @url http://www.espruino.com/Reference#l_ESP8266_dumpSocketInfo + */ + static dumpSocketInfo(): void; + + /** + * **Note:** This is deprecated. Use `E.setClock(80/160)` **Note:** Set the + * operating frequency of the ESP8266 processor. The default is 160Mhz. + * **Warning**: changing the cpu frequency affects the timing of some I/O + * operations, notably of software SPI and I2C, so things may be a bit slower at + * 80Mhz. + * + * @param {any} freq - Desired frequency - either 80 or 160. + * @url http://www.espruino.com/Reference#l_ESP8266_setCPUFreq + */ + static setCPUFreq(freq: any): void; + + /** + * Returns an object that contains details about the state of the ESP8266 with the + * following fields: + * * `sdkVersion` - Version of the SDK. + * * `cpuFrequency` - CPU operating frequency in Mhz. + * * `freeHeap` - Amount of free heap in bytes. + * * `maxCon` - Maximum number of concurrent connections. + * * `flashMap` - Configured flash size&map: '512KB:256/256' .. '4MB:512/512' + * * `flashKB` - Configured flash size in KB as integer + * * `flashChip` - Type of flash chip as string with manufacturer & chip, ex: '0xEF + * 0x4016` + * @returns {any} The state of the ESP8266 + * @url http://www.espruino.com/Reference#l_ESP8266_getState + */ + static getState(): any; + + /** + * **Note:** This is deprecated. Use `require("Flash").getFree()` + * @returns {any} Array of objects with `addr` and `length` properties describing the free flash areas available + * @url http://www.espruino.com/Reference#l_ESP8266_getFreeFlash + */ + static getFreeFlash(): any; + + /** + * + * @param {any} arrayOfData - Array of data to CRC + * @returns {any} 32-bit CRC + * @url http://www.espruino.com/Reference#l_ESP8266_crc32 + */ + static crc32(arrayOfData: any): any; + + /** + * **This function is deprecated.** Please use `require("neopixel").write(pin, + * data)` instead + * + * @param {Pin} pin - Pin for output signal. + * @param {any} arrayOfData - Array of LED data. + * @url http://www.espruino.com/Reference#l_ESP8266_neopixelWrite + */ + static neopixelWrite(pin: Pin, arrayOfData: any): void; + + /** + * Put the ESP8266 into 'deep sleep' for the given number of microseconds, reducing + * power consumption drastically. + * meaning of option values: + * 0 - the 108th Byte of init parameter decides whether RF calibration will be + * performed or not. + * 1 - run RF calibration after waking up. Power consumption is high. + * 2 - no RF calibration after waking up. Power consumption is low. + * 4 - no RF after waking up. Power consumption is the lowest. + * **Note:** unlike normal Espruino boards' 'deep sleep' mode, ESP8266 deep sleep + * actually turns off the processor. After the given number of microseconds have + * elapsed, the ESP8266 will restart as if power had been turned off and then back + * on. *All contents of RAM will be lost*. Connect GPIO 16 to RST to enable wakeup. + * **Special:** 0 microseconds cause sleep forever until external wakeup RST pull + * down occurs. + * + * @param {any} micros - Number of microseconds to sleep. + * @param {any} option - posible values are 0, 1, 2 or 4 + * @url http://www.espruino.com/Reference#l_ESP8266_deepSleep + */ + static deepSleep(micros: any, option: any): void; + + +} + +/** + * An instantiation of an Ethernet network adaptor + * @url http://www.espruino.com/Reference#Ethernet + */ +declare class Ethernet { + + + /** + * Get the current IP address, subnet, gateway and mac address. + * + * @param {any} options - An optional `callback(err, ipinfo)` function to be called back with the IP information. + * @returns {any} + * @url http://www.espruino.com/Reference#l_Ethernet_getIP + */ + getIP(options: any): any; + + /** + * Set the current IP address or get an IP from DHCP (if no options object is + * specified) + * If 'mac' is specified as an option, it must be a string of the form + * `"00:01:02:03:04:05"` The default mac is 00:08:DC:01:02:03. + * + * @param {any} options - Object containing IP address options `{ ip : '1.2.3.4', subnet : '...', gateway: '...', dns:'...', mac:':::::' }`, or do not supply an object in order to force DHCP. + * @param {any} callback - An optional `callback(err)` function to invoke when ip is set. `err==null` on success, or a string on failure. + * @returns {boolean} True on success + * @url http://www.espruino.com/Reference#l_Ethernet_setIP + */ + setIP(options: any, callback: any): boolean; + + /** + * Set hostname allow to set the hosname used during the dhcp request. min 8 and + * max 12 char, best set before calling `eth.setIP()` Default is WIZnet010203, + * 010203 is the default nic as part of the mac. Best to set the hosname before + * calling setIP(). + * + * @param {any} hostname - hostname as string + * @param {any} callback - An optional `callback(err)` function to be called back with null or error text. + * @returns {boolean} True on success + * @url http://www.espruino.com/Reference#l_Ethernet_setHostname + */ + setHostname(hostname: any, callback: any): boolean; + + /** + * Returns the hostname + * + * @param {any} callback - An optional `callback(err,hostname)` function to be called back with the status information. + * @returns {any} + * @url http://www.espruino.com/Reference#l_Ethernet_getHostname + */ + getHostname(callback: any): any; + + /** + * Get the current status of the ethernet device + * + * @param {any} options - An optional `callback(err, status)` function to be called back with the status information. + * @returns {any} + * @url http://www.espruino.com/Reference#l_Ethernet_getStatus + */ + getStatus(options: any): any; +} + +/** + * The HTTP server created by `require('http').createServer` + * @url http://www.espruino.com/Reference#httpSrv + */ +declare class httpSrv { + + + /** + * Start listening for new HTTP connections on the given port + * + * @param {number} port - The port to listen on + * @returns {any} The HTTP server instance that 'listen' was called on + * @url http://www.espruino.com/Reference#l_httpSrv_listen + */ + listen(port: number): any; + + /** + * Stop listening for new HTTP connections + * @url http://www.espruino.com/Reference#l_httpSrv_close + */ + close(): void; +} + +/** + * The HTTP server request + * @url http://www.espruino.com/Reference#httpSRq + */ +declare class httpSRq { + /** + * The 'data' event is called when data is received. If a handler is defined with + * `X.on('data', function(data) { ... })` then it will be called, otherwise data + * will be stored in an internal buffer, where it can be retrieved with `X.read()` + * @param {string} event - The event to listen to. + * @param {(data: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `data` A string containing one or more characters of received data + * @url http://www.espruino.com/Reference#l_httpSRq_data + */ + static on(event: "data", callback: (data: any) => void): void; + + /** + * Called when the connection closes. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_httpSRq_close + */ + static on(event: "close", callback: () => void): void; + + /** + * The headers to sent to the server with this HTTP request. + * @returns {any} An object mapping header name to value + * @url http://www.espruino.com/Reference#l_httpSRq_headers + */ + headers: any; + + /** + * The HTTP method used with this request. Often `"GET"`. + * @returns {any} A string + * @url http://www.espruino.com/Reference#l_httpSRq_method + */ + method: any; + + /** + * The URL requested in this HTTP request, for instance: + * * `"/"` - the main page + * * `"/favicon.ico"` - the web page's icon + * @returns {any} A string representing the URL + * @url http://www.espruino.com/Reference#l_httpSRq_url + */ + url: any; + + /** + * Return how many bytes are available to read. If there is already a listener for + * data, this will always return 0. + * @returns {number} How many bytes are available + * @url http://www.espruino.com/Reference#l_httpSRq_available + */ + available(): number; + + /** + * Return a string containing characters that have been received + * + * @param {number} chars - The number of characters to read, or undefined/0 for all available + * @returns {any} A string containing the required bytes. + * @url http://www.espruino.com/Reference#l_httpSRq_read + */ + read(chars: number): any; + + /** + * Pipe this to a stream (an object with a 'write' method) + * + * @param {any} destination - The destination file/stream that will receive content from the source. + * @param {any} options + * An optional object `{ chunkSize : int=32, end : bool=true, complete : function }` + * chunkSize : The amount of data to pipe from source to destination at a time + * complete : a function to call when the pipe activity is complete + * end : call the 'end' function on the destination when the source is finished + * @url http://www.espruino.com/Reference#l_httpSRq_pipe + */ + pipe(destination: any, options: any): void; +} + +/** + * The HTTP server response + * @url http://www.espruino.com/Reference#httpSRs + */ +declare class httpSRs { + /** + * An event that is fired when the buffer is empty and it can accept more data to + * send. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_httpSRs_drain + */ + static on(event: "drain", callback: () => void): void; + + /** + * Called when the connection closes. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_httpSRs_close + */ + static on(event: "close", callback: () => void): void; + + /** + * The headers to send back along with the HTTP response. + * The default contents are: + * ``` + * { + * "Connection": "close" + * } + * ``` + * @returns {any} An object mapping header name to value + * @url http://www.espruino.com/Reference#l_httpSRs_headers + */ + headers: any; + + /** + * This function writes the `data` argument as a string. Data that is passed in + * (including arrays) will be converted to a string with the normal JavaScript + * `toString` method. For more information about sending binary data see + * `Socket.write` + * + * @param {any} data - A string containing data to send + * @returns {boolean} For node.js compatibility, returns the boolean false. When the send buffer is empty, a `drain` event will be sent + * @url http://www.espruino.com/Reference#l_httpSRs_write + */ + write(data: any): boolean; + + /** + * See `Socket.write` for more information about the data argument + * + * @param {any} data - A string containing data to send + * @url http://www.espruino.com/Reference#l_httpSRs_end + */ + end(data: any): void; + + /** + * Send the given status code and headers. If not explicitly called this will be + * done automatically the first time data is written to the response. + * This cannot be called twice, or after data has already been sent in the + * response. + * + * @param {number} statusCode - The HTTP status code + * @param {any} headers - An object containing the headers + * @url http://www.espruino.com/Reference#l_httpSRs_writeHead + */ + writeHead(statusCode: number, headers: any): void; + + /** + * Set a value to send in the header of this HTTP response. This updates the + * `httpSRs.headers` property. + * Any headers supplied to `writeHead` will overwrite any headers with the same + * name. + * + * @param {any} name - The name of the header as a String + * @param {any} value - The value of the header as a String + * @url http://www.espruino.com/Reference#l_httpSRs_setHeader + */ + setHeader(name: any, value: any): void; +} + +/** + * The HTTP client request, returned by `http.request()` and `http.get()`. + * @url http://www.espruino.com/Reference#httpCRq + */ +declare class httpCRq { + /** + * An event that is fired when the buffer is empty and it can accept more data to + * send. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_httpCRq_drain + */ + static on(event: "drain", callback: () => void): void; + + /** + * An event that is fired if there is an error making the request and the response + * callback has not been invoked. In this case the error event concludes the + * request attempt. The error event function receives an error object as parameter + * with a `code` field and a `message` field. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_httpCRq_error + */ + static on(event: "error", callback: () => void): void; + + /** + * This function writes the `data` argument as a string. Data that is passed in + * (including arrays) will be converted to a string with the normal JavaScript + * `toString` method. For more information about sending binary data see + * `Socket.write` + * + * @param {any} data - A string containing data to send + * @returns {boolean} For node.js compatibility, returns the boolean false. When the send buffer is empty, a `drain` event will be sent + * @url http://www.espruino.com/Reference#l_httpCRq_write + */ + write(data: any): boolean; + + /** + * Finish this HTTP request - optional data to append as an argument + * See `Socket.write` for more information about the data argument + * + * @param {any} data - A string containing data to send + * @url http://www.espruino.com/Reference#l_httpCRq_end + */ + end(data: any): void; +} + +/** + * The HTTP client response, passed to the callback of `http.request()` an + * `http.get()`. + * @url http://www.espruino.com/Reference#httpCRs + */ +declare class httpCRs { + /** + * The 'data' event is called when data is received. If a handler is defined with + * `X.on('data', function(data) { ... })` then it will be called, otherwise data + * will be stored in an internal buffer, where it can be retrieved with `X.read()` + * @param {string} event - The event to listen to. + * @param {(data: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `data` A string containing one or more characters of received data + * @url http://www.espruino.com/Reference#l_httpCRs_data + */ + static on(event: "data", callback: (data: any) => void): void; + + /** + * Called when the connection closes with one `hadError` boolean parameter, which + * indicates whether an error occurred. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_httpCRs_close + */ + static on(event: "close", callback: () => void): void; + + /** + * An event that is fired if there is an error receiving the response. The error + * event function receives an error object as parameter with a `code` field and a + * `message` field. After the error event the close even will also be triggered to + * conclude the HTTP request/response. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_httpCRs_error + */ + static on(event: "error", callback: () => void): void; + + /** + * The headers received along with the HTTP response + * @returns {any} An object mapping header name to value + * @url http://www.espruino.com/Reference#l_httpCRs_headers + */ + headers: any; + + /** + * The HTTP response's status code - usually `"200"` if all went well + * @returns {any} The status code as a String + * @url http://www.espruino.com/Reference#l_httpCRs_statusCode + */ + statusCode: any; + + /** + * The HTTP response's status message - Usually `"OK"` if all went well + * @returns {any} An String Status Message + * @url http://www.espruino.com/Reference#l_httpCRs_statusMessage + */ + statusMessage: any; + + /** + * The HTTP version reported back by the server - usually `"1.1"` + * @returns {any} Th + * @url http://www.espruino.com/Reference#l_httpCRs_httpVersion + */ + httpVersion: any; + + /** + * Return how many bytes are available to read. If there is a 'data' event handler, + * this will always return 0. + * @returns {number} How many bytes are available + * @url http://www.espruino.com/Reference#l_httpCRs_available + */ + available(): number; + + /** + * Return a string containing characters that have been received + * + * @param {number} chars - The number of characters to read, or undefined/0 for all available + * @returns {any} A string containing the required bytes. + * @url http://www.espruino.com/Reference#l_httpCRs_read + */ + read(chars: number): any; + + /** + * Pipe this to a stream (an object with a 'write' method) + * + * @param {any} destination - The destination file/stream that will receive content from the source. + * @param {any} options + * An optional object `{ chunkSize : int=32, end : bool=true, complete : function }` + * chunkSize : The amount of data to pipe from source to destination at a time + * complete : a function to call when the pipe activity is complete + * end : call the 'end' function on the destination when the source is finished + * @url http://www.espruino.com/Reference#l_httpCRs_pipe + */ + pipe(destination: any, options: any): void; +} + +/** + * This class provides functionality to recognise gestures drawn on a touchscreen. + * It is only built into Bangle.js 2. + * Usage: + * ``` + * var strokes = { + * stroke1 : Unistroke.new(new Uint8Array([x1, y1, x2, y2, x3, y3, ...])), + * stroke2 : Unistroke.new(new Uint8Array([x1, y1, x2, y2, x3, y3, ...])), + * stroke3 : Unistroke.new(new Uint8Array([x1, y1, x2, y2, x3, y3, ...])) + * }; + * var r = Unistroke.recognise(strokes,new Uint8Array([x1, y1, x2, y2, x3, y3, ...])) + * print(r); // stroke1/stroke2/stroke3 + * ``` + * @url http://www.espruino.com/Reference#Unistroke + */ +declare class Unistroke { + /** + * Create a new Unistroke based on XY coordinates + * + * @param {any} xy - An array of interleaved XY coordinates + * @returns {any} A string of data representing this unistroke + * @url http://www.espruino.com/Reference#l_Unistroke_new + */ + static new(xy: any): any; + + /** + * Recognise based on an object of named strokes, and a list of XY coordinates + * + * @param {any} strokes - An object of named strokes : `{arrow:..., circle:...}` + * @param {any} xy - An array of interleaved XY coordinates + * @returns {any} The key name of the matched stroke + * @url http://www.espruino.com/Reference#l_Unistroke_recognise + */ + static recognise(strokes: any, xy: any): any; + + +} + +/** + * The NRF class is for controlling functionality of the Nordic nRF51/nRF52 chips. + * Most functionality is related to Bluetooth Low Energy, however there are also + * some functions related to NFC that apply to NRF52-based devices. + * @url http://www.espruino.com/Reference#NRF + */ +declare class NRF { + /** + * @returns {any} An object + * @url http://www.espruino.com/Reference#l_NRF_getSecurityStatus + */ + static getSecurityStatus(): any; + + /** + * @returns {any} An object + * @url http://www.espruino.com/Reference#l_NRF_getAddress + */ + static getAddress(): any; + + /** + * + * @param {any} data - The service (and characteristics) to advertise + * @param {any} options - Optional object containing options + * @url http://www.espruino.com/Reference#l_NRF_setServices + */ + static setServices(data: any, options: any): void; + + /** + * + * @param {any} data - The data to advertise as an object - see below for more info + * @param {any} options - An optional object of options + * @url http://www.espruino.com/Reference#l_NRF_setAdvertising + */ + static setAdvertising(data: any, options: any): void; + + /** + * Called when a host device connects to Espruino. The first argument contains the + * address. + * @param {string} event - The event to listen to. + * @param {(addr: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `addr` The address of the device that has connected + * @url http://www.espruino.com/Reference#l_NRF_connect + */ + static on(event: "connect", callback: (addr: any) => void): void; + + /** + * Called when a host device disconnects from Espruino. + * The most common reason is: + * * 19 - `REMOTE_USER_TERMINATED_CONNECTION` + * * 22 - `LOCAL_HOST_TERMINATED_CONNECTION` + * @param {string} event - The event to listen to. + * @param {(reason: number) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `reason` The reason code reported back by the BLE stack - see Nordic's [`ble_hci.h` file](https://github.com/espruino/Espruino/blob/master/targetlibs/nrf5x_12/components/softdevice/s132/headers/ble_hci.h#L71) for more information + * @url http://www.espruino.com/Reference#l_NRF_disconnect + */ + static on(event: "disconnect", callback: (reason: number) => void): void; + + /** + * Contains updates on the security of the current Bluetooth link. + * See Nordic's `ble_gap_evt_auth_status_t` structure for more information. + * @param {string} event - The event to listen to. + * @param {(status: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `status` An object containing `{auth_status,bonded,lv4,kdist_own,kdist_peer} + * @url http://www.espruino.com/Reference#l_NRF_security + */ + static on(event: "security", callback: (status: any) => void): void; + + /** + * Called with a single byte value when Espruino is set up as a HID device and the + * computer it is connected to sends a HID report back to Espruino. This is usually + * used for handling indications such as the Caps Lock LED. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_NRF_HID + */ + static on(event: "HID", callback: () => void): void; + + /** + * Called with discovered services when discovery is finished + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_NRF_servicesDiscover + */ + static on(event: "servicesDiscover", callback: () => void): void; + + /** + * Called with discovered characteristics when discovery is finished + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_NRF_characteristicsDiscover + */ + static on(event: "characteristicsDiscover", callback: () => void): void; + + /** + * Called when an NFC field is detected + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_NRF_NFCon + */ + static on(event: "NFCon", callback: () => void): void; + + /** + * Called when an NFC field is no longer detected + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_NRF_NFCoff + */ + static on(event: "NFCoff", callback: () => void): void; + + /** + * When NFC is started with `NRF.nfcStart`, this is fired when NFC data is + * received. It doesn't get called if NFC is started with `NRF.nfcURL` or + * `NRF.nfcRaw` + * @param {string} event - The event to listen to. + * @param {(arr: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `arr` An ArrayBuffer containign the received data + * @url http://www.espruino.com/Reference#l_NRF_NFCrx + */ + static on(event: "NFCrx", callback: (arr: any) => void): void; + + /** + * If a device is connected to Espruino, disconnect from it. + * @url http://www.espruino.com/Reference#l_NRF_disconnect + */ + static disconnect(): void; + + /** + * Disable Bluetooth advertising and disconnect from any device that connected to + * Puck.js as a peripheral (this won't affect any devices that Puck.js initiated + * connections to). + * This makes Puck.js undiscoverable, so it can't be connected to. + * Use `NRF.wake()` to wake up and make Puck.js connectable again. + * @url http://www.espruino.com/Reference#l_NRF_sleep + */ + static sleep(): void; + + /** + * Enable Bluetooth advertising (this is enabled by default), which allows other + * devices to discover and connect to Puck.js. + * Use `NRF.sleep()` to disable advertising. + * @url http://www.espruino.com/Reference#l_NRF_wake + */ + static wake(): void; + + /** + * Restart the Bluetooth softdevice (if there is currently a BLE connection, it + * will queue a restart to be done when the connection closes). + * You shouldn't need to call this function in normal usage. However, Nordic's BLE + * softdevice has some settings that cannot be reset. For example there are only a + * certain number of unique UUIDs. Once these are all used the only option is to + * restart the softdevice to clear them all out. + * + * @param {any} callback - An optional function to be called while the softdevice is uninitialised. Use with caution - accessing console/bluetooth will almost certainly result in a crash. + * @url http://www.espruino.com/Reference#l_NRF_restart + */ + static restart(callback: any): void; + + /** + * Get this device's default Bluetooth MAC address. + * For Puck.js, the last 5 characters of this (eg. `ee:ff`) are used in the + * device's advertised Bluetooth name. + * @returns {any} MAC address - a string of the form 'aa:bb:cc:dd:ee:ff' + * @url http://www.espruino.com/Reference#l_NRF_getAddress + */ + static getAddress(): any; + + /** + * Set this device's default Bluetooth MAC address: + * ``` + * NRF.setAddress("ff:ee:dd:cc:bb:aa random"); + * ``` + * Addresses take the form: + * * `"ff:ee:dd:cc:bb:aa"` or `"ff:ee:dd:cc:bb:aa public"` for a public address + * * `"ff:ee:dd:cc:bb:aa random"` for a random static address (the default for + * Espruino) + * This may throw a `INVALID_BLE_ADDR` error if the upper two bits of the address + * don't match the address type. + * To change the address, Espruino must restart the softdevice. It will only do so + * when it is disconnected from other devices. + * + * @param {any} addr - The address to use (as a string) + * @url http://www.espruino.com/Reference#l_NRF_setAddress + */ + static setAddress(addr: any): void; + + /** + * Get the battery level in volts (the voltage that the NRF chip is running off + * of). + * This is the battery level of the device itself - it has nothing to with any + * device that might be connected. + * @returns {number} Battery level in volts + * @url http://www.espruino.com/Reference#l_NRF_getBattery + */ + static getBattery(): number; + + /** + * Change the data that Espruino advertises. + * Data can be of the form `{ UUID : data_as_byte_array }`. The UUID should be a + * [Bluetooth Service + * ID](https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx). + * For example to return battery level at 95%, do: + * ``` + * NRF.setAdvertising({ + * 0x180F : [95] // Service data 0x180F = 95 + * }); + * ``` + * Or you could report the current temperature: + * ``` + * setInterval(function() { + * NRF.setAdvertising({ + * 0x1809 : [Math.round(E.getTemperature())] + * }); + * }, 30000); + * ``` + * If you specify a value for the object key, Service Data is advertised. However + * if you specify `undefined`, the Service UUID is advertised: + * ``` + * NRF.setAdvertising({ + * 0x180D : undefined // Advertise service UUID 0x180D (HRM) + * }); + * ``` + * Service UUIDs can also be supplied in the second argument of `NRF.setServices`, + * but those go in the scan response packet. + * You can also supply the raw advertising data in an array. For example to + * advertise as an Eddystone beacon: + * ``` + * NRF.setAdvertising([0x03, // Length of Service List + * 0x03, // Param: Service List + * 0xAA, 0xFE, // Eddystone ID + * 0x13, // Length of Service Data + * 0x16, // Service Data + * 0xAA, 0xFE, // Eddystone ID + * 0x10, // Frame type: URL + * 0xF8, // Power + * 0x03, // https:// + * 'g','o','o','.','g','l','/','B','3','J','0','O','c'], + * {interval:100}); + * ``` + * (However for Eddystone we'd advise that you use the [Espruino Eddystone + * library](/Puck.js+Eddystone)) + * **Note:** When specifying data as an array, certain advertising options such as + * `discoverable` and `showName` won't have any effect. + * **Note:** The size of Bluetooth LE advertising packets is limited to 31 bytes. + * If you want to advertise more data, consider using an array for `data` (See + * below), or `NRF.setScanResponse`. + * You can even specify an array of arrays or objects, in which case each + * advertising packet will be used in turn - for instance to make your device + * advertise battery level and its name as well as both Eddystone and iBeacon : + * ``` + * NRF.setAdvertising([ + * {0x180F : [Puck.getBatteryPercentage()]}, // normal advertising, with battery % + * require("ble_ibeacon").get(...), // iBeacon + * require("ble_eddystone").get(...), // eddystone + * ], {interval:300}); + * ``` + * `options` is an object, which can contain: + * ``` + * { + * name: "Hello" // The name of the device + * showName: true/false // include full name, or nothing + * discoverable: true/false // general discoverable, or limited - default is limited + * connectable: true/false // whether device is connectable - default is true + * scannable : true/false // whether device can be scanned for scan response packets - default is true + * interval: 600 // Advertising interval in msec, between 20 and 10000 (default is 375ms) + * manufacturer: 0x0590 // IF sending manufacturer data, this is the manufacturer ID + * manufacturerData: [...] // IF sending manufacturer data, this is an array of data + * phy: "1mbps/2mbps/coded" // (NRF52840 only) use the long-range coded phy for transmission (1mbps default) + * } + * ``` + * Setting `connectable` and `scannable` to false gives the lowest power + * consumption as the BLE radio doesn't have to listen after sending advertising. + * **NOTE:** Non-`connectable` advertising can't have an advertising interval less + * than 100ms according to the BLE spec. + * So for instance to set the name of Puck.js without advertising any other data + * you can just use the command: + * ``` + * NRF.setAdvertising({},{name:"Hello"}); + * ``` + * You can also specify 'manufacturer data', which is another form of advertising + * data. We've registered the Manufacturer ID 0x0590 (as Pur3 Ltd) for use with + * *Official Espruino devices* - use it to advertise whatever data you'd like, but + * we'd recommend using JSON. + * For example by not advertising a device name you can send up to 24 bytes of JSON + * on Espruino's manufacturer ID: + * ``` + * var data = {a:1,b:2}; + * NRF.setAdvertising({},{ + * showName:false, + * manufacturer:0x0590, + * manufacturerData:JSON.stringify(data) + * }); + * ``` + * If you're using [EspruinoHub](https://github.com/espruino/EspruinoHub) then it + * will automatically decode this into the folling MQTT topics: + * * `/ble/advertise/ma:c_:_a:dd:re:ss/espruino` -> `{"a":10,"b":15}` + * * `/ble/advertise/ma:c_:_a:dd:re:ss/a` -> `1` + * * `/ble/advertise/ma:c_:_a:dd:re:ss/b` -> `2` + * Note that **you only have 24 characters available for JSON**, so try to use the + * shortest field names possible and avoid floating point values that can be very + * long when converted to a String. + * + * @param {any} data - The service data to advertise as an object - see below for more info + * @param {any} options - An optional object of options + * @url http://www.espruino.com/Reference#l_NRF_setAdvertising + */ + static setAdvertising(data: any, options: any): void; + + /** + * This is just like `NRF.setAdvertising`, except instead of advertising the data, + * it returns the packet that would be advertised as an array. + * + * @param {any} data - The data to advertise as an object + * @param {any} options - An optional object of options + * @returns {any} An array containing the advertising data + * @url http://www.espruino.com/Reference#l_NRF_getAdvertisingData + */ + static getAdvertisingData(data: any, options: any): any; + + /** + * The raw scan response data should be supplied as an array. For example to return + * "Sample" for the device name: + * ``` + * NRF.setScanResponse([0x07, // Length of Data + * 0x09, // Param: Complete Local Name + * 'S', 'a', 'm', 'p', 'l', 'e']); + * ``` + * **Note:** `NRF.setServices(..., {advertise:[ ... ]})` writes advertised services + * into the scan response - so you can't use both `advertise` and `NRF.setServices` + * or one will overwrite the other. + * + * @param {any} data - The data to for the scan response + * @url http://www.espruino.com/Reference#l_NRF_setScanResponse + */ + static setScanResponse(data: any): void; + + /** + * Change the services and characteristics Espruino advertises. + * If you want to **change** the value of a characteristic, you need to use + * `NRF.updateServices()` instead + * To expose some information on Characteristic `ABCD` on service `BCDE` you could + * do: + * ``` + * NRF.setServices({ + * 0xBCDE : { + * 0xABCD : { + * value : "Hello", + * readable : true + * } + * } + * }); + * ``` + * Or to allow the 3 LEDs to be controlled by writing numbers 0 to 7 to a + * characteristic, you can do the following. `evt.data` is an ArrayBuffer. + * ``` + * NRF.setServices({ + * 0xBCDE : { + * 0xABCD : { + * writable : true, + * onWrite : function(evt) { + * digitalWrite([LED3,LED2,LED1], evt.data[0]); + * } + * } + * } + * }); + * ``` + * You can supply many different options: + * ``` + * NRF.setServices({ + * 0xBCDE : { + * 0xABCD : { + * value : "Hello", // optional + * maxLen : 5, // optional (otherwise is length of initial value) + * broadcast : false, // optional, default is false + * readable : true, // optional, default is false + * writable : true, // optional, default is false + * notify : true, // optional, default is false + * indicate : true, // optional, default is false + * description: "My Characteristic", // optional, default is null, + * security: { // optional - see NRF.setSecurity + * read: { // optional + * encrypted: false, // optional, default is false + * mitm: false, // optional, default is false + * lesc: false, // optional, default is false + * signed: false // optional, default is false + * }, + * write: { // optional + * encrypted: true, // optional, default is false + * mitm: false, // optional, default is false + * lesc: false, // optional, default is false + * signed: false // optional, default is false + * } + * }, + * onWrite : function(evt) { // optional + * console.log("Got ", evt.data); // an ArrayBuffer + * }, + * onWriteDesc : function(evt) { // optional - called when the 'cccd' descriptor is written + * // for example this is called when notifications are requested by the client: + * console.log("Notifications enabled = ", evt.data[0]&1); + * } + * } + * // more characteristics allowed + * } + * // more services allowed + * }); + * ``` + * **Note:** UUIDs can be integers between `0` and `0xFFFF`, strings of the form + * `"ABCD"`, or strings of the form `"ABCDABCD-ABCD-ABCD-ABCD-ABCDABCDABCD"` + * `options` can be of the form: + * ``` + * NRF.setServices(undefined, { + * hid : new Uint8Array(...), // optional, default is undefined. Enable BLE HID support + * uart : true, // optional, default is true. Enable BLE UART support + * advertise: [ '180D' ] // optional, list of service UUIDs to advertise + * ancs : true, // optional, Bangle.js-only, enable Apple ANCS support for notifications + * ams : true // optional, Bangle.js-only, enable Apple AMS support for media control + * }); + * ``` + * To enable BLE HID, you must set `hid` to an array which is the BLE report + * descriptor. The easiest way to do this is to use the `ble_hid_controls` or + * `ble_hid_keyboard` modules. + * **Note:** Just creating a service doesn't mean that the service will be + * advertised. It will only be available after a device connects. To advertise, + * specify the UUIDs you wish to advertise in the `advertise` field of the second + * `options` argument. For example this will create and advertise a heart rate + * service: + * ``` + * NRF.setServices({ + * 0x180D: { // heart_rate + * 0x2A37: { // heart_rate_measurement + * notify: true, + * value : [0x06, heartrate], + * } + * } + * }, { advertise: [ '180D' ] }); + * ``` + * You may specify 128 bit UUIDs to advertise, however you may get a `DATA_SIZE` + * exception because there is insufficient space in the Bluetooth LE advertising + * packet for the 128 bit UART UUID as well as the UUID you specified. In this case + * you can add `uart:false` after the `advertise` element to disable the UART, + * however you then be unable to connect to Puck.js's console via Bluetooth. + * If you absolutely require two or more 128 bit UUIDs then you will have to + * specify your own raw advertising data packets with `NRF.setAdvertising` + * **Note:** The services on Espruino can only be modified when there is no device + * connected to it as it requires a restart of the Bluetooth stack. **iOS devices + * will 'cache' the list of services** so apps like NRF Connect may incorrectly + * display the old services even after you have modified them. To fix this, disable + * and re-enable Bluetooth on your iOS device, or use an Android device to run NRF + * Connect. + * **Note:** Not all combinations of security configuration values are valid, the + * valid combinations are: encrypted, encrypted + mitm, lesc, signed, signed + + * mitm. See `NRF.setSecurity` for more information. + * + * @param {any} data - The service (and characteristics) to advertise + * @param {any} options - Optional object containing options + * @url http://www.espruino.com/Reference#l_NRF_setServices + */ + static setServices(data: any, options: any): void; + + /** + * Update values for the services and characteristics Espruino advertises. Only + * services and characteristics previously declared using `NRF.setServices` are + * affected. + * To update the '0xABCD' characteristic in the '0xBCDE' service: + * ``` + * NRF.updateServices({ + * 0xBCDE : { + * 0xABCD : { + * value : "World" + * } + * } + * }); + * ``` + * You can also use 128 bit UUIDs, for example + * `"b7920001-3c1b-4b40-869f-3c0db9be80c6"`. + * To define a service and characteristic and then notify connected clients of a + * change to it when a button is pressed: + * ``` + * NRF.setServices({ + * 0xBCDE : { + * 0xABCD : { + * value : "Hello", + * maxLen : 20, + * notify: true + * } + * } + * }); + * setWatch(function() { + * NRF.updateServices({ + * 0xBCDE : { + * 0xABCD : { + * value : "World!", + * notify: true + * } + * } + * }); + * }, BTN, { repeat:true, edge:"rising", debounce: 50 }); + * ``` + * This only works if the characteristic was created with `notify: true` using + * `NRF.setServices`, otherwise the characteristic will be updated but no + * notification will be sent. + * Also note that `maxLen` was specified. If it wasn't then the maximum length of + * the characteristic would have been 5 - the length of `"Hello"`. + * To indicate (i.e. notify with ACK) connected clients of a change to the '0xABCD' + * characteristic in the '0xBCDE' service: + * ``` + * NRF.updateServices({ + * 0xBCDE : { + * 0xABCD : { + * value : "World", + * indicate: true + * } + * } + * }); + * ``` + * This only works if the characteristic was created with `indicate: true` using + * `NRF.setServices`, otherwise the characteristic will be updated but no + * notification will be sent. + * **Note:** See `NRF.setServices` for more information + * + * @param {any} data - The service (and characteristics) to update + * @url http://www.espruino.com/Reference#l_NRF_updateServices + */ + static updateServices(data: any): void; + + /** + * Start/stop listening for BLE advertising packets within range. Returns a + * `BluetoothDevice` for each advertsing packet. **By default this is not an active + * scan, so Scan Response advertising data is not included (see below)** + * ``` + * // Start scanning + * packets=10; + * NRF.setScan(function(d) { + * packets--; + * if (packets<=0) + * NRF.setScan(); // stop scanning + * else + * console.log(d); // print packet info + * }); + * ``` + * Each `BluetoothDevice` will look a bit like: + * ``` + * BluetoothDevice { + * "id": "aa:bb:cc:dd:ee:ff", // address + * "rssi": -89, // signal strength + * "services": [ "128bit-uuid", ... ], // zero or more service UUIDs + * "data": new Uint8Array([ ... ]).buffer, // ArrayBuffer of returned data + * "serviceData" : { "0123" : [ 1 ] }, // if service data is in 'data', it's extracted here + * "manufacturer" : 0x1234, // if manufacturer data is in 'data', the 16 bit manufacturer ID is extracted here + * "manufacturerData" : new Uint8Array([...]).buffer, // if manufacturer data is in 'data', the data is extracted here as an ArrayBuffer + * "name": "DeviceName" // the advertised device name + * } + * ``` + * You can also supply a set of filters (as described in `NRF.requestDevice`) as a + * second argument, which will allow you to filter the devices you get a callback + * for. This helps to cut down on the time spent processing JavaScript code in + * areas with a lot of Bluetooth advertisements. For example to find only devices + * with the manufacturer data `0x0590` (Espruino's ID) you could do: + * ``` + * NRF.setScan(function(d) { + * console.log(d.manufacturerData); + * }, { filters: [{ manufacturerData:{0x0590:{}} }] }); + * ``` + * You can also specify `active:true` in the second argument to perform active + * scanning (this requests scan response packets) from any devices it finds. + * **Note:** Using a filter in `setScan` filters each advertising packet + * individually. As a result, if you filter based on a service UUID and a device + * advertises with multiple packets (or a scan response when `active:true`) only + * the packets matching the filter are returned. To aggregate multiple packets you + * can use `NRF.findDevices`. + * **Note:** BLE advertising packets can arrive quickly - faster than you'll be + * able to print them to the console. It's best only to print a few, or to use a + * function like `NRF.findDevices(..)` which will collate a list of available + * devices. + * **Note:** Using setScan turns the radio's receive mode on constantly. This can + * draw a *lot* of power (12mA or so), so you should use it sparingly or you can + * run your battery down quickly. + * + * @param {any} callback - The callback to call with received advertising packets, or undefined to stop + * @param {any} options - An optional object `{filters: ...}` (as would be passed to `NRF.requestDevice`) to filter devices by + * @url http://www.espruino.com/Reference#l_NRF_setScan + */ + static setScan(callback: any, options: any): void; + + /** + * This function can be used to quickly filter through Bluetooth devices. + * For instance if you wish to scan for multiple different types of device at the + * same time then you could use `NRF.findDevices` with all the filters you're + * interested in. When scanning is finished you can then use `NRF.filterDevices` to + * pick out just the devices of interest. + * ``` + * // the two types of device we're interested in + * var filter1 = [{serviceData:{"fe95":{}}}]; + * var filter2 = [{namePrefix:"Pixl.js"}]; + * // the following filter will return both types of device + * var allFilters = filter1.concat(filter2); + * // now scan for both types of device, and filter them out afterwards + * NRF.findDevices(function(devices) { + * var devices1 = NRF.filterDevices(devices, filter1); + * var devices2 = NRF.filterDevices(devices, filter2); + * // ... + * }, {filters : allFilters}); + * ``` + * + * @param {any} devices - An array of `BluetoothDevice` objects, from `NRF.findDevices` or similar + * @param {any} filters - A list of filters (as would be passed to `NRF.requestDevice`) to filter devices by + * @returns {any} An array of `BluetoothDevice` objects that match the given filters + * @url http://www.espruino.com/Reference#l_NRF_filterDevices + */ + static filterDevices(devices: any, filters: any): any; + + /** + * Utility function to return a list of BLE devices detected in range. Behind the + * scenes, this uses `NRF.setScan(...)` and collates the results. + * ``` + * NRF.findDevices(function(devices) { + * console.log(devices); + * }, 1000); + * ``` + * prints something like: + * ``` + * [ + * BluetoothDevice { + * "id" : "e7:e0:57:ad:36:a2 random", + * "rssi": -45, + * "services": [ "4567" ], + * "serviceData" : { "0123" : [ 1 ] }, + * "manufacturer" : 1424, + * "manufacturerData" : new Uint8Array([ ... ]).buffer, + * "data": new ArrayBuffer([ ... ]).buffer, + * "name": "Puck.js 36a2" + * }, + * BluetoothDevice { + * "id": "c0:52:3f:50:42:c9 random", + * "rssi": -65, + * "data": new ArrayBuffer([ ... ]), + * "name": "Puck.js 8f57" + * } + * ] + * ``` + * For more information on the structure returned, see `NRF.setScan`. + * If you want to scan only for specific devices you can replace the timeout with + * an object of the form `{filters: ..., timeout : ..., active: bool}` using the + * filters described in `NRF.requestDevice`. For example to search for devices with + * Espruino's `manufacturerData`: + * ``` + * NRF.findDevices(function(devices) { + * ... + * }, {timeout : 2000, filters : [{ manufacturerData:{0x0590:{}} }] }); + * ``` + * You could then use + * [`BluetoothDevice.gatt.connect(...)`](/Reference#l_BluetoothRemoteGATTServer_connect) + * on the device returned to make a connection. + * You can also use [`NRF.connect(...)`](/Reference#l_NRF_connect) on just the `id` + * string returned, which may be useful if you always want to connect to a specific + * device. + * **Note:** Using findDevices turns the radio's receive mode on for 2000ms (or + * however long you specify). This can draw a *lot* of power (12mA or so), so you + * should use it sparingly or you can run your battery down quickly. + * **Note:** The 'data' field contains the data of *the last packet received*. + * There may have been more packets. To get data for each packet individually use + * `NRF.setScan` instead. + * + * @param {any} callback - The callback to call with received advertising packets (as `BluetoothDevice`), or undefined to stop + * @param {any} [options] - [optional] A time in milliseconds to scan for (defaults to 2000), Or an optional object `{filters: ..., timeout : ..., active: bool}` (as would be passed to `NRF.requestDevice`) to filter devices by + * @url http://www.espruino.com/Reference#l_NRF_findDevices + */ + static findDevices(callback: (devices: BluetoothDevice[]) => void, options?: number | { filters?: NRFFilters, timeout?: number, active?: boolean }): void; + + /** + * Start/stop listening for RSSI values on the currently active connection (where + * This device is a peripheral and is being connected to by a 'central' device) + * ``` + * // Start scanning + * NRF.setRSSIHandler(function(rssi) { + * console.log(rssi); // prints -85 (or similar) + * }); + * // Stop Scanning + * NRF.setRSSIHandler(); + * ``` + * RSSI is the 'Received Signal Strength Indication' in dBm + * + * @param {any} callback - The callback to call with the RSSI value, or undefined to stop + * @url http://www.espruino.com/Reference#l_NRF_setRSSIHandler + */ + static setRSSIHandler(callback: any): void; + + /** + * Set the BLE radio transmit power. The default TX power is 0 dBm, and + * + * @param {number} power - Transmit power. Accepted values are -40(nRF52 only), -30(nRF51 only), -20, -16, -12, -8, -4, 0, and 4 dBm. On nRF52840 (eg Bangle.js 2) 5/6/7/8 dBm are available too. Others will give an error code. + * @url http://www.espruino.com/Reference#l_NRF_setTxPower + */ + static setTxPower(power: number): void; + + /** + * **THIS IS DEPRECATED** - please use `NRF.setConnectionInterval` for peripheral + * and `NRF.connect(addr, options)`/`BluetoothRemoteGATTServer.connect(options)` + * for central connections. + * This sets the connection parameters - these affect the transfer speed and power + * usage when the device is connected. + * * When not low power, the connection interval is between 7.5 and 20ms + * * When low power, the connection interval is between 500 and 1000ms + * When low power connection is enabled, transfers of data over Bluetooth will be + * very slow, however power usage while connected will be drastically decreased. + * This will only take effect after the connection is disconnected and + * re-established. + * + * @param {boolean} lowPower - Whether the connection is low power or not + * @url http://www.espruino.com/Reference#l_NRF_setLowPowerConnection + */ + static setLowPowerConnection(lowPower: boolean): void; + + /** + * Enables NFC and starts advertising the given URL. For example: + * ``` + * NRF.nfcURL("http://espruino.com"); + * ``` + * + * @param {any} url - The URL string to expose on NFC, or `undefined` to disable NFC + * @url http://www.espruino.com/Reference#l_NRF_nfcURL + */ + static nfcURL(url: any): void; + + /** + * Enables NFC and with an out of band 16 byte pairing key. + * For example the following will enable out of band pairing on BLE such that the + * device will pair when you tap the phone against it: + * ``` + * var bleKey = [0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00]; + * NRF.on('security',s=>print("security",JSON.stringify(s))); + * NRF.nfcPair(bleKey); + * NRF.setSecurity({oob:bleKey, mitm:true}); + * ``` + * + * @param {any} key - 16 byte out of band key + * @url http://www.espruino.com/Reference#l_NRF_nfcPair + */ + static nfcPair(key: any): void; + + /** + * Enables NFC with a record that will launch the given android app. + * For example: + * ``` + * NRF.nfcAndroidApp("no.nordicsemi.android.nrftoolbox") + * ``` + * + * @param {any} app - The unique identifier of the given Android App + * @url http://www.espruino.com/Reference#l_NRF_nfcAndroidApp + */ + static nfcAndroidApp(app: any): void; + + /** + * Enables NFC and starts advertising with Raw data. For example: + * ``` + * NRF.nfcRaw(new Uint8Array([193, 1, 0, 0, 0, 13, 85, 3, 101, 115, 112, 114, 117, 105, 110, 111, 46, 99, 111, 109])); + * // same as NRF.nfcURL("http://espruino.com"); + * ``` + * + * @param {any} payload - The NFC NDEF message to deliver to the reader + * @url http://www.espruino.com/Reference#l_NRF_nfcRaw + */ + static nfcRaw(payload: any): void; + + /** + * **Advanced NFC Functionality.** If you just want to advertise a URL, use + * `NRF.nfcURL` instead. + * Enables NFC and starts advertising. `NFCrx` events will be fired when data is + * received. + * ``` + * NRF.nfcStart(); + * ``` + * + * @param {any} payload - Optional 7 byte UID + * @returns {any} Internal tag memory (first 10 bytes of tag data) + * @url http://www.espruino.com/Reference#l_NRF_nfcStart + */ + static nfcStart(payload: any): any; + + /** + * **Advanced NFC Functionality.** If you just want to advertise a URL, use + * `NRF.nfcURL` instead. + * Disables NFC. + * ``` + * NRF.nfcStop(); + * ``` + * + * @url http://www.espruino.com/Reference#l_NRF_nfcStop + */ + static nfcStop(): void; + + /** + * **Advanced NFC Functionality.** If you just want to advertise a URL, use + * `NRF.nfcURL` instead. + * Acknowledges the last frame and optionally transmits a response. If payload is + * an array, then a array.length byte nfc frame is sent. If payload is a int, then + * a 4bit ACK/NACK is sent. **Note:** ```nfcSend``` should always be called after + * an ```NFCrx``` event. + * ``` + * NRF.nfcSend(new Uint8Array([0x01, 0x02, ...])); + * // or + * NRF.nfcSend(0x0A); + * // or + * NRF.nfcSend(); + * ``` + * + * @param {any} payload - Optional tx data + * @url http://www.espruino.com/Reference#l_NRF_nfcSend + */ + static nfcSend(payload: any): void; + + /** + * Send a USB HID report. HID must first be enabled with `NRF.setServices({}, {hid: + * hid_report})` + * + * @param {any} data - Input report data as an array + * @param {any} callback - A callback function to be called when the data is sent + * @url http://www.espruino.com/Reference#l_NRF_sendHIDReport + */ + static sendHIDReport(data: any, callback: any): void; + + /** + * Check if Apple Notification Center Service (ANCS) is currently active on the BLE + * connection + * + * @returns {boolean} True if Apple Notification Center Service (ANCS) has been initialised and is active + * @url http://www.espruino.com/Reference#l_NRF_ancsIsActive + */ + static ancsIsActive(): boolean; + + /** + * Send an ANCS action for a specific Notification UID. Corresponds to + * posaction/negaction in the 'ANCS' event that was received + * + * @param {number} uid - The UID of the notification to respond to + * @param {boolean} positive - `true` for positive action, `false` for negative + * @url http://www.espruino.com/Reference#l_NRF_ancsAction + */ + static ancsAction(uid: number, positive: boolean): void; + + /** + * Get ANCS info for a notification, eg: + * + * @param {number} uid - The UID of the notification to get information for + * @returns {any} A `Promise` that is resolved (or rejected) when the connection is complete + * @url http://www.espruino.com/Reference#l_NRF_ancsGetNotificationInfo + */ + static ancsGetNotificationInfo(uid: number): Promise; + + /** + * Get ANCS info for an app (add id is available via `ancsGetNotificationInfo`) + * Promise returns: + * ``` + * { + * "uid" : int, + * "appId" : string, + * "title" : string, + * "subtitle" : string, + * "message" : string, + * "messageSize" : string, + * "date" : string, + * "posAction" : string, + * "negAction" : string, + * "name" : string, + * } + * ``` + * + * @param {any} id - The app ID to get information for + * @returns {any} A `Promise` that is resolved (or rejected) when the connection is complete + * @url http://www.espruino.com/Reference#l_NRF_ancsGetAppInfo + */ + static ancsGetAppInfo(id: any): Promise; + + /** + * Check if Apple Media Service (AMS) is currently active on the BLE connection + * + * @returns {boolean} True if Apple Media Service (AMS) has been initialised and is active + * @url http://www.espruino.com/Reference#l_NRF_amsIsActive + */ + static amsIsActive(): boolean; + + /** + * Get Apple Media Service (AMS) info for the current media player. "playbackinfo" + * returns a concatenation of three comma-separated values: + * - PlaybackState: a string that represents the integer value of the playback + * state: + * - PlaybackStatePaused = 0 + * - PlaybackStatePlaying = 1 + * - PlaybackStateRewinding = 2 + * - PlaybackStateFastForwarding = 3 + * - PlaybackRate: a string that represents the floating point value of the + * playback rate. + * - ElapsedTime: a string that represents the floating point value of the elapsed + * time of the current track, in seconds + * + * @param {any} id - Either 'name', 'playbackinfo' or 'volume' + * @returns {any} A `Promise` that is resolved (or rejected) when the connection is complete + * @url http://www.espruino.com/Reference#l_NRF_amsGetPlayerInfo + */ + static amsGetPlayerInfo(id: any): Promise; + + /** + * Get Apple Media Service (AMS) info for the currently-playing track + * + * @param {any} id - Either 'artist', 'album', 'title' or 'duration' + * @returns {any} A `Promise` that is resolved (or rejected) when the connection is complete + * @url http://www.espruino.com/Reference#l_NRF_amsGetTrackInfo + */ + static amsGetTrackInfo(id: any): Promise; + + /** + * Send an AMS command to an Apple Media Service device to control music playback + * Command is one of play, pause, playpause, next, prev, volup, voldown, repeat, + * shuffle, skipforward, skipback, like, dislike, bookmark + * + * @param {any} id - For example, 'play', 'pause', 'volup' or 'voldown' + * @url http://www.espruino.com/Reference#l_NRF_amsCommand + */ + static amsCommand(id: any): void; + + /** + * Search for available devices matching the given filters. Since we have no UI + * here, Espruino will pick the FIRST device it finds, or it'll call `catch`. + * `options` can have the following fields: + * * `filters` - a list of filters that a device must match before it is returned + * (see below) + * * `timeout` - the maximum time to scan for in milliseconds (scanning stops when + * a match is found. eg. `NRF.requestDevice({ timeout:2000, filters: [ ... ] })` + * * `active` - whether to perform active scanning (requesting 'scan response' + * packets from any devices that are found). eg. `NRF.requestDevice({ active:true, + * filters: [ ... ] })` + * * `phy` - (NRF52840 only) use the long-range coded phy (`"1mbps"` default, can + * be `"1mbps/2mbps/both/coded"`) + * * `extended` - (NRF52840 only) support receiving extended-length advertising + * packets (default=true if phy isn't `"1mbps"`) + * **NOTE:** `timeout` and `active` are not part of the Web Bluetooth standard. + * The following filter types are implemented: + * * `services` - list of services as strings (all of which must match). 128 bit + * services must be in the form '01230123-0123-0123-0123-012301230123' + * * `name` - exact device name + * * `namePrefix` - starting characters of device name + * * `id` - exact device address (`id:"e9:53:86:09:89:99 random"`) (this is + * Espruino-specific, and is not part of the Web Bluetooth spec) + * * `serviceData` - an object containing service characteristics which must all + * match (`serviceData:{"1809":{}}`). Matching of actual service data is not + * supported yet. + * * `manufacturerData` - an object containing manufacturer UUIDs which must all + * match (`manufacturerData:{0x0590:{}}`). Matching of actual manufacturer data + * is not supported yet. + * ``` + * NRF.requestDevice({ filters: [{ namePrefix: 'Puck.js' }] }).then(function(device) { ... }); + * // or + * NRF.requestDevice({ filters: [{ services: ['1823'] }] }).then(function(device) { ... }); + * // or + * NRF.requestDevice({ filters: [{ manufacturerData:{0x0590:{}} }] }).then(function(device) { ... }); + * ``` + * As a full example, to send data to another Puck.js to turn an LED on: + * ``` + * var gatt; + * NRF.requestDevice({ filters: [{ namePrefix: 'Puck.js' }] }).then(function(device) { + * return device.gatt.connect(); + * }).then(function(g) { + * gatt = g; + * return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e"); + * }).then(function(service) { + * return service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e"); + * }).then(function(characteristic) { + * return characteristic.writeValue("LED1.set()\n"); + * }).then(function() { + * gatt.disconnect(); + * console.log("Done!"); + * }); + * ``` + * Or slightly more concisely, using ES6 arrow functions: + * ``` + * var gatt; + * NRF.requestDevice({ filters: [{ namePrefix: 'Puck.js' }]}).then( + * device => device.gatt.connect()).then( + * g => (gatt=g).getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e")).then( + * service => service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e")).then( + * characteristic => characteristic.writeValue("LED1.reset()\n")).then( + * () => { gatt.disconnect(); console.log("Done!"); } ); + * ``` + * Note that you have to keep track of the `gatt` variable so that you can + * disconnect the Bluetooth connection when you're done. + * **Note:** Using a filter in `NRF.requestDevice` filters each advertising packet + * individually. As soon as a matching advertisement is received, + * `NRF.requestDevice` resolves the promise and stops scanning. This means that if + * you filter based on a service UUID and a device advertises with multiple packets + * (or a scan response when `active:true`) only the packet matching the filter is + * returned - you may not get the device's name is that was in a separate packet. + * To aggregate multiple packets you can use `NRF.findDevices`. + * + * @param {any} options - Options used to filter the device to use + * @returns {any} A `Promise` that is resolved (or rejected) when the connection is complete + * @url http://www.espruino.com/Reference#l_NRF_requestDevice + */ + static requestDevice(options?: { filters?: NRFFilters, timeout?: number, active?: boolean, phy?: string, extended?: boolean }): Promise; + + /** + * Connect to a BLE device by MAC address. Returns a promise, the argument of which + * is the `BluetoothRemoteGATTServer` connection. + * ``` + * NRF.connect("aa:bb:cc:dd:ee").then(function(server) { + * // ... + * }); + * ``` + * This has the same effect as calling `BluetoothDevice.gatt.connect` on a + * `BluetoothDevice` requested using `NRF.requestDevice`. It just allows you to + * specify the address directly (without having to scan). + * You can use it as follows - this would connect to another Puck device and turn + * its LED on: + * ``` + * var gatt; + * NRF.connect("aa:bb:cc:dd:ee random").then(function(g) { + * gatt = g; + * return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e"); + * }).then(function(service) { + * return service.getCharacteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e"); + * }).then(function(characteristic) { + * return characteristic.writeValue("LED1.set()\n"); + * }).then(function() { + * gatt.disconnect(); + * console.log("Done!"); + * }); + * ``` + * **Note:** Espruino Bluetooth devices use a type of BLE address known as 'random + * static', which is different to a 'public' address. To connect to an Espruino + * device you'll need to use an address string of the form `"aa:bb:cc:dd:ee + * random"` rather than just `"aa:bb:cc:dd:ee"`. If you scan for devices with + * `NRF.findDevices`/`NRF.setScan` then addresses are already reported in the + * correct format. + * + * @param {any} mac - The MAC address to connect to + * @param {any} options - (Espruino-specific) An object of connection options (see `BluetoothRemoteGATTServer.connect` for full details) + * @returns {any} A `Promise` that is resolved (or rejected) when the connection is complete + * @url http://www.espruino.com/Reference#l_NRF_connect + */ + static connect(mac: any, options: any): Promise; + + /** + * If set to true, whenever a device bonds it will be added to the whitelist. + * When set to false, the whitelist is cleared and newly bonded devices will not be + * added to the whitelist. + * **Note:** This is remembered between `reset()`s but isn't remembered after + * power-on (you'll have to add it to `onInit()`. + * + * @param {boolean} whitelisting - Are we using a whitelist? (default false) + * @url http://www.espruino.com/Reference#l_NRF_setWhitelist + */ + static setWhitelist(whitelisting: boolean): void; + + /** + * When connected, Bluetooth LE devices communicate at a set interval. Lowering the + * interval (eg. more packets/second) means a lower delay when sending data, higher + * bandwidth, but also more power consumption. + * By default, when connected as a peripheral Espruino automatically adjusts the + * connection interval. When connected it's as fast as possible (7.5ms) but when + * idle for over a minute it drops to 200ms. On continued activity (>1 BLE + * operation) the interval is raised to 7.5ms again. + * The options for `interval` are: + * * `undefined` / `"auto"` : (default) automatically adjust connection interval + * * `100` : set min and max connection interval to the same number (between 7.5ms + * and 4000ms) + * * `{minInterval:20, maxInterval:100}` : set min and max connection interval as a + * range + * This configuration is not remembered during a `save()` - you will have to re-set + * it via `onInit`. + * **Note:** If connecting to another device (as Central), you can use an extra + * argument to `NRF.connect` or `BluetoothRemoteGATTServer.connect` to specify a + * connection interval. + * **Note:** This overwrites any changes imposed by the deprecated + * `NRF.setLowPowerConnection` + * + * @param {any} interval - The connection interval to use (see below) + * @url http://www.espruino.com/Reference#l_NRF_setConnectionInterval + */ + static setConnectionInterval(interval: any): void; + + /** + * Sets the security options used when connecting/pairing. This applies to both + * central *and* peripheral mode. + * ``` + * NRF.setSecurity({ + * display : bool // default false, can this device display a passkey + * // - sent via the `BluetoothDevice.passkey` event + * keyboard : bool // default false, can this device enter a passkey + * // - request sent via the `BluetoothDevice.passkeyRequest` event + * bond : bool // default true, Perform bonding + * mitm : bool // default false, Man In The Middle protection + * lesc : bool // default false, LE Secure Connections + * passkey : // default "", or a 6 digit passkey to use + * oob : [0..15] // if specified, Out Of Band pairing is enabled and + * // the 16 byte pairing code supplied here is used + * encryptUart : bool // default false (unless oob or passkey specified) + * // This sets the BLE UART service such that it + * // is encrypted and can only be used from a bonded connection + * }); + * ``` + * **NOTE:** Some combinations of arguments will cause an error. For example + * supplying a passkey without `display:1` is not allowed. If `display:1` is set + * you do not require a physical display, the user just needs to know the passkey + * you supplied. + * For instance, to require pairing and to specify a passkey, use: + * ``` + * NRF.setSecurity({passkey:"123456", mitm:1, display:1}); + * ``` + * However, while most devices will request a passkey for pairing at this point it + * is still possible for a device to connect without requiring one (eg. using the + * 'NRF Connect' app). + * To force a passkey you need to protect each characteristic you define with + * `NRF.setSecurity`. For instance the following code will *require* that the + * passkey `123456` is entered before the characteristic + * `9d020002-bf5f-1d1a-b52a-fe52091d5b12` can be read. + * ``` + * NRF.setSecurity({passkey:"123456", mitm:1, display:1}); + * NRF.setServices({ + * "9d020001-bf5f-1d1a-b52a-fe52091d5b12" : { + * "9d020002-bf5f-1d1a-b52a-fe52091d5b12" : { + * // readable always + * value : "Not Secret" + * }, + * "9d020003-bf5f-1d1a-b52a-fe52091d5b12" : { + * // readable only once bonded + * value : "Secret", + * readable : true, + * security: { + * read: { + * mitm: true, + * encrypted: true + * } + * } + * }, + * "9d020004-bf5f-1d1a-b52a-fe52091d5b12" : { + * // readable always + * // writable only once bonded + * value : "Readable", + * readable : true, + * writable : true, + * onWrite : function(evt) { + * console.log("Wrote ", evt.data); + * }, + * security: { + * write: { + * mitm: true, + * encrypted: true + * } + * } + * } + * } + * }); + * ``` + * **Note:** If `passkey` or `oob` is specified, the Nordic UART service (if + * enabled) will automatically be set to require encryption, but otherwise it is + * open. + * + * @param {any} options - An object containing security-related options (see below) + * @url http://www.espruino.com/Reference#l_NRF_setSecurity + */ + static setSecurity(options: any): void; + + /** + * Return an object with information about the security state of the current + * peripheral connection: + * ``` + * { + * connected // The connection is active (not disconnected). + * encrypted // Communication on this link is encrypted. + * mitm_protected // The encrypted communication is also protected against man-in-the-middle attacks. + * bonded // The peer is bonded with us + * connected_addr // If connected=true, the MAC address of the currently connected device + * } + * ``` + * If there is no active connection, `{connected:false}` will be returned. + * See `NRF.setSecurity` for information about negotiating a secure connection. + * @returns {any} An object + * @url http://www.espruino.com/Reference#l_NRF_getSecurityStatus + */ + static getSecurityStatus(): any; + + /** + * + * @param {boolean} forceRepair - True if we should force repairing even if there is already valid pairing info + * @returns {any} A promise + * @url http://www.espruino.com/Reference#l_NRF_startBonding + */ + static startBonding(forceRepair: boolean): any; + + +} + +/** + * @url http://www.espruino.com/Reference#Bluetooth + */ +declare class Bluetooth { + /** + * @url http://www.espruino.com/Reference#l_Bluetooth_setConsole + */ + static setConsole(): void; + + +} + +/** + * A Web Bluetooth-style device - you can request one using + * `NRF.requestDevice(address)` + * For example: + * ``` + * var gatt; + * NRF.requestDevice({ filters: [{ name: 'Puck.js abcd' }] }).then(function(device) { + * console.log("found device"); + * return device.gatt.connect(); + * }).then(function(g) { + * gatt = g; + * console.log("connected"); + * return gatt.startBonding(); + * }).then(function() { + * console.log("bonded", gatt.getSecurityStatus()); + * gatt.disconnect(); + * }).catch(function(e) { + * console.log("ERROR",e); + * }); + * ``` + * @url http://www.espruino.com/Reference#BluetoothDevice + */ +declare class BluetoothDevice { + /** + * Called when the device gets disconnected. + * To connect and then print `Disconnected` when the device is disconnected, just + * do the following: + * ``` + * var gatt; + * NRF.connect("aa:bb:cc:dd:ee:ff").then(function(gatt) { + * gatt.device.on('gattserverdisconnected', function(reason) { + * console.log("Disconnected ",reason); + * }); + * }); + * ``` + * Or: + * ``` + * var gatt; + * NRF.requestDevice(...).then(function(device) { + * device.on('gattserverdisconnected', function(reason) { + * console.log("Disconnected ",reason); + * }); + * }); + * ``` + * @param {string} event - The event to listen to. + * @param {(reason: number) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `reason` The reason code reported back by the BLE stack - see Nordic's `ble_hci.h` file for more information + * @url http://www.espruino.com/Reference#l_BluetoothDevice_gattserverdisconnected + */ + static on(event: "gattserverdisconnected", callback: (reason: number) => void): void; + + /** + * Called when the device pairs and sends a passkey that Espruino should display. + * For this to be used, you'll have to specify that there's a display using + * `NRF.setSecurity` + * **This is not part of the Web Bluetooth Specification.** It has been added + * specifically for Espruino. + * @param {string} event - The event to listen to. + * @param {(passkey: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `passkey` A 6 character numeric String to be displayed + * @url http://www.espruino.com/Reference#l_BluetoothDevice_passkey + */ + static on(event: "passkey", callback: (passkey: any) => void): void; + + /** + * Called when the device pairs, displays a passkey, and wants Espruino to tell it + * what the passkey was. + * Respond with `BluetoothDevice.sendPasskey()` with a 6 character string + * containing only `0..9`. + * For this to be used, you'll have to specify that there's a keyboard using + * `NRF.setSecurity` + * **This is not part of the Web Bluetooth Specification.** It has been added + * specifically for Espruino. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_BluetoothDevice_passkeyRequest + */ + static on(event: "passkeyRequest", callback: () => void): void; + + /** + * @returns {any} A `BluetoothRemoteGATTServer` for this device + * @url http://www.espruino.com/Reference#l_BluetoothDevice_gatt + */ + gatt: any; + + /** + * @returns {boolean} The last received RSSI (signal strength) for this device + * @url http://www.espruino.com/Reference#l_BluetoothDevice_rssi + */ + rssi: boolean; + + /** + * To be used as a response when the event `BluetoothDevice.sendPasskey` has been + * received. + * **This is not part of the Web Bluetooth Specification.** It has been added + * specifically for Espruino. + * + * @param {any} passkey - A 6 character numeric String to be returned to the device + * @url http://www.espruino.com/Reference#l_BluetoothDevice_sendPasskey + */ + sendPasskey(passkey: any): void; +} + +/** + * Web Bluetooth-style GATT server - get this using `NRF.connect(address)` or + * `NRF.requestDevice(options)` and `response.gatt.connect` + * https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver + * @url http://www.espruino.com/Reference#BluetoothRemoteGATTServer + */ +declare class BluetoothRemoteGATTServer { + + + /** + * Connect to a BLE device - returns a promise, the argument of which is the + * `BluetoothRemoteGATTServer` connection. + * See [`NRF.requestDevice`](/Reference#l_NRF_requestDevice) for usage examples. + * `options` is an optional object containing: + * ``` + * { + * minInterval // min connection interval in milliseconds, 7.5 ms to 4 s + * maxInterval // max connection interval in milliseconds, 7.5 ms to 4 s + * } + * ``` + * By default the interval is 20-200ms (or 500-1000ms if + * `NRF.setLowPowerConnection(true)` was called. During connection Espruino + * negotiates with the other device to find a common interval that can be used. + * For instance calling: + * ``` + * NRF.requestDevice({ filters: [{ namePrefix: 'Pixl.js' }] }).then(function(device) { + * return device.gatt.connect({minInterval:7.5, maxInterval:7.5}); + * }).then(function(g) { + * ``` + * will force the connection to use the fastest connection interval possible (as + * long as the device at the other end supports it). + * **Note:** The Web Bluetooth spec states that if a device hasn't advertised its + * name, when connected to a device the central (in this case Espruino) should + * automatically retrieve the name from the corresponding characteristic (`0x2a00` + * on service `0x1800`). Espruino does not automatically do this. + * + * @param {any} options - (Espruino-specific) An object of connection options (see below) + * @returns {any} A `Promise` that is resolved (or rejected) when the connection is complete + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_connect + */ + connect(options: any): Promise; + + /** + * @returns {boolean} Whether the device is connected or not + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_connected + */ + connected: boolean; + + /** + * @returns {number} The handle to this device (if it is currently connected) - the handle is an internal value used by the Bluetooth Stack + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_handle + */ + handle: number; + + /** + * Disconnect from a previously connected BLE device connected with + * `BluetoothRemoteGATTServer.connect` - this does not disconnect from something + * that has connected to the Espruino. + * **Note:** While `.disconnect` is standard Web Bluetooth, in the spec it returns + * undefined not a `Promise` for implementation reasons. In Espruino we return a + * `Promise` to make it easier to detect when Espruino is free to connect to + * something else. + * @returns {any} A `Promise` that is resolved (or rejected) when the disconnection is complete (non-standard) + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_disconnect + */ + disconnect(): Promise; + + /** + * Start negotiating bonding (secure communications) with the connected device, and + * return a Promise that is completed on success or failure. + * ``` + * var gatt; + * NRF.requestDevice({ filters: [{ name: 'Puck.js abcd' }] }).then(function(device) { + * console.log("found device"); + * return device.gatt.connect(); + * }).then(function(g) { + * gatt = g; + * console.log("connected"); + * return gatt.startBonding(); + * }).then(function() { + * console.log("bonded", gatt.getSecurityStatus()); + * gatt.disconnect(); + * }).catch(function(e) { + * console.log("ERROR",e); + * }); + * ``` + * **This is not part of the Web Bluetooth Specification.** It has been added + * specifically for Espruino. + * + * @param {boolean} forceRePair - If the device is already bonded, re-pair it + * @returns {any} A `Promise` that is resolved (or rejected) when the bonding is complete + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_startBonding + */ + startBonding(forceRePair: boolean): Promise; + + /** + * Return an object with information about the security state of the current + * connection: + * ``` + * { + * connected // The connection is active (not disconnected). + * encrypted // Communication on this link is encrypted. + * mitm_protected // The encrypted communication is also protected against man-in-the-middle attacks. + * bonded // The peer is bonded with us + * } + * ``` + * See `BluetoothRemoteGATTServer.startBonding` for information about negotiating a + * secure connection. + * **This is not part of the Web Bluetooth Specification.** It has been added + * specifically for Puck.js. + * @returns {any} An object + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getSecurityStatus + */ + getSecurityStatus(): any; + + /** + * See `NRF.connect` for usage examples. + * + * @param {any} service - The service UUID + * @returns {any} A `Promise` that is resolved (or rejected) when the primary service is found (the argument contains a `BluetoothRemoteGATTService`) + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getPrimaryService + */ + getPrimaryService(service: any): Promise; + + /** + * @returns {any} A `Promise` that is resolved (or rejected) when the primary services are found (the argument contains an array of `BluetoothRemoteGATTService`) + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getPrimaryServices + */ + getPrimaryServices(): Promise; + + /** + * Start/stop listening for RSSI values on the active GATT connection + * ``` + * // Start listening for RSSI value updates + * gattServer.setRSSIHandler(function(rssi) { + * console.log(rssi); // prints -85 (or similar) + * }); + * // Stop listening + * gattServer.setRSSIHandler(); + * ``` + * RSSI is the 'Received Signal Strength Indication' in dBm + * + * @param {any} callback - The callback to call with the RSSI value, or undefined to stop + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_setRSSIHandler + */ + setRSSIHandler(callback: any): void; +} + +/** + * Web Bluetooth-style GATT service - get this using + * `BluetoothRemoteGATTServer.getPrimaryService(s)` + * https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice + * @url http://www.espruino.com/Reference#BluetoothRemoteGATTService + */ +declare class BluetoothRemoteGATTService { + + + /** + * @returns {any} The `BluetoothDevice` this Service came from + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTService_device + */ + device: any; + + /** + * See `NRF.connect` for usage examples. + * + * @param {any} characteristic - The characteristic UUID + * @returns {any} A `Promise` that is resolved (or rejected) when the characteristic is found (the argument contains a `BluetoothRemoteGATTCharacteristic`) + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTService_getCharacteristic + */ + getCharacteristic(characteristic: any): Promise; + + /** + * @returns {any} A `Promise` that is resolved (or rejected) when the characteristic is found (the argument contains an array of `BluetoothRemoteGATTCharacteristic`) + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTService_getCharacteristics + */ + getCharacteristics(): Promise; +} + +/** + * Web Bluetooth-style GATT characteristic - get this using + * `BluetoothRemoteGATTService.getCharacteristic(s)` + * https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic + * @url http://www.espruino.com/Reference#BluetoothRemoteGATTCharacteristic + */ +declare class BluetoothRemoteGATTCharacteristic { + /** + * Called when a characteristic's value changes, *after* + * `BluetoothRemoteGATTCharacteristic.startNotifications` has been called. + * ``` + * ... + * return service.getCharacteristic("characteristic_uuid"); + * }).then(function(c) { + * c.on('characteristicvaluechanged', function(event) { + * console.log("-> "+event.target.value); + * }); + * return c.startNotifications(); + * }).then(... + * ``` + * The first argument is of the form `{target : + * BluetoothRemoteGATTCharacteristic}`, and + * `BluetoothRemoteGATTCharacteristic.value` will then contain the new value (as a + * DataView). + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_characteristicvaluechanged + */ + static on(event: "characteristicvaluechanged", callback: () => void): void; + + /** + * @returns {any} The `BluetoothRemoteGATTService` this Service came from + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_service + */ + service: any; + + /** + * Write a characteristic's value + * ``` + * var device; + * NRF.connect(device_address).then(function(d) { + * device = d; + * return d.getPrimaryService("service_uuid"); + * }).then(function(s) { + * console.log("Service ",s); + * return s.getCharacteristic("characteristic_uuid"); + * }).then(function(c) { + * return c.writeValue("Hello"); + * }).then(function(d) { + * device.disconnect(); + * }).catch(function() { + * console.log("Something's broken."); + * }); + * ``` + * + * @param {any} data - The data to write + * @returns {any} A `Promise` that is resolved (or rejected) when the characteristic is written + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_writeValue + */ + writeValue(data: any): Promise; + + /** + * Read a characteristic's value, return a promise containing a `DataView` + * ``` + * var device; + * NRF.connect(device_address).then(function(d) { + * device = d; + * return d.getPrimaryService("service_uuid"); + * }).then(function(s) { + * console.log("Service ",s); + * return s.getCharacteristic("characteristic_uuid"); + * }).then(function(c) { + * return c.readValue(); + * }).then(function(d) { + * console.log("Got:", JSON.stringify(d.buffer)); + * device.disconnect(); + * }).catch(function() { + * console.log("Something's broken."); + * }); + * ``` + * @returns {any} A `Promise` that is resolved (or rejected) with a `DataView` when the characteristic is read + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_readValue + */ + readValue(): Promise; + + /** + * Starts notifications - whenever this characteristic's value changes, a + * `characteristicvaluechanged` event is fired and `characteristic.value` will then + * contain the new value as a `DataView`. + * ``` + * var device; + * NRF.connect(device_address).then(function(d) { + * device = d; + * return d.getPrimaryService("service_uuid"); + * }).then(function(s) { + * console.log("Service ",s); + * return s.getCharacteristic("characteristic_uuid"); + * }).then(function(c) { + * c.on('characteristicvaluechanged', function(event) { + * console.log("-> ",event.target.value); // this is a DataView + * }); + * return c.startNotifications(); + * }).then(function(d) { + * console.log("Waiting for notifications"); + * }).catch(function() { + * console.log("Something's broken."); + * }); + * ``` + * For example, to listen to the output of another Puck.js's Nordic Serial port + * service, you can use: + * ``` + * var gatt; + * NRF.connect("pu:ck:js:ad:dr:es random").then(function(g) { + * gatt = g; + * return gatt.getPrimaryService("6e400001-b5a3-f393-e0a9-e50e24dcca9e"); + * }).then(function(service) { + * return service.getCharacteristic("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); + * }).then(function(characteristic) { + * characteristic.on('characteristicvaluechanged', function(event) { + * console.log("RX: "+JSON.stringify(event.target.value.buffer)); + * }); + * return characteristic.startNotifications(); + * }).then(function() { + * console.log("Done!"); + * }); + * ``` + * @returns {any} A `Promise` that is resolved (or rejected) with data when notifications have been added + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_startNotifications + */ + startNotifications(): Promise; + + /** + * Stop notifications (that were requested with + * `BluetoothRemoteGATTCharacteristic.startNotifications`) + * @returns {any} A `Promise` that is resolved (or rejected) with data when notifications have been removed + * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTCharacteristic_stopNotifications + */ + stopNotifications(): Promise; +} + +/** + * Class containing utility functions for the [Bangle.js Smart + * Watch](http://www.espruino.com/Bangle.js) + * @url http://www.espruino.com/Reference#Bangle + */ +declare class Bangle { + /** + * Accelerometer data available with `{x,y,z,diff,mag}` object as a parameter. + * * `x` is X axis (left-right) in `g` + * * `y` is Y axis (up-down) in `g` + * * `z` is Z axis (in-out) in `g` + * * `diff` is difference between this and the last reading in `g` + * * `mag` is the magnitude of the acceleration in `g` + * You can also retrieve the most recent reading with `Bangle.getAccel()`. + * @param {string} event - The event to listen to. + * @param {(xyz: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `xyz` + * @url http://www.espruino.com/Reference#l_Bangle_accel + */ + static on(event: "accel", callback: (xyz: AccelData) => void): void; + + /** + * Called whenever a step is detected by Bangle.js's pedometer. + * @param {string} event - The event to listen to. + * @param {(up: number) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `up` The number of steps since Bangle.js was last reset + * @url http://www.espruino.com/Reference#l_Bangle_step + */ + static on(event: "step", callback: (up: number) => void): void; + + /** + * See `Bangle.getHealthStatus()` for more information. This is used for health + * tracking to allow Bangle.js to record historical exercise data. + * @param {string} event - The event to listen to. + * @param {(info: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `info` An object containing the last 10 minutes health data + * @url http://www.espruino.com/Reference#l_Bangle_health + */ + static on(event: "health", callback: (info: HealthStatus) => void): void; + + /** + * Has the watch been moved so that it is face-up, or not face up? + * @param {string} event - The event to listen to. + * @param {(up: boolean) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `up` `true` if face-up + * @url http://www.espruino.com/Reference#l_Bangle_faceUp + */ + static on(event: "faceUp", callback: (up: boolean) => void): void; + + /** + * This event happens when the watch has been twisted around it's axis - for + * instance as if it was rotated so someone could look at the time. + * To tweak when this happens, see the `twist*` options in `Bangle.setOptions()` + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Bangle_twist + */ + static on(event: "twist", callback: () => void): void; + + /** + * Is the battery charging or not? + * @param {string} event - The event to listen to. + * @param {(charging: boolean) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `charging` `true` if charging + * @url http://www.espruino.com/Reference#l_Bangle_charging + */ + static on(event: "charging", callback: (charging: boolean) => void): void; + + /** + * Magnetometer/Compass data available with `{x,y,z,dx,dy,dz,heading}` object as a + * parameter + * * `x/y/z` raw x,y,z magnetometer readings + * * `dx/dy/dz` readings based on calibration since magnetometer turned on + * * `heading` in degrees based on calibrated readings (will be NaN if magnetometer + * hasn't been rotated around 360 degrees) + * To get this event you must turn the compass on with `Bangle.setCompassPower(1)`. + * You can also retrieve the most recent reading with `Bangle.getCompass()`. + * @param {string} event - The event to listen to. + * @param {(xyz: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `xyz` + * @url http://www.espruino.com/Reference#l_Bangle_mag + */ + static on(event: "mag", callback: (xyz: CompassData) => void): void; + + /** + * Raw NMEA GPS / u-blox data messages received as a string + * To get this event you must turn the GPS on with `Bangle.setGPSPower(1)`. + * @param {string} event - The event to listen to. + * @param {(nmea: any, dataLoss: boolean) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `nmea` A string containing the raw NMEA data from the GPS + * * `dataLoss` This is set to true if some lines of GPS data have previously been lost (eg because system was too busy to queue up a GPS-raw event) + * @url http://www.espruino.com/Reference#l_Bangle_GPS-raw + */ + static on(event: "GPS-raw", callback: (nmea: string, dataLoss: boolean) => void): void; + + /** + * GPS data, as an object. Contains: + * ``` + * { "lat": number, // Latitude in degrees + * "lon": number, // Longitude in degrees + * "alt": number, // altitude in M + * "speed": number, // Speed in kph + * "course": number, // Course in degrees + * "time": Date, // Current Time (or undefined if not known) + * "satellites": 7, // Number of satellites + * "fix": 1 // NMEA Fix state - 0 is no fix + * "hdop": number, // Horizontal Dilution of Precision + * } + * ``` + * If a value such as `lat` is not known because there is no fix, it'll be `NaN`. + * `hdop` is a value from the GPS receiver that gives a rough idea of accuracy of + * lat/lon based on the geometry of the satellites in range. Multiply by 5 to get a + * value in meters. This is just a ballpark estimation and should not be considered + * remotely accurate. + * To get this event you must turn the GPS on with `Bangle.setGPSPower(1)`. + * @param {string} event - The event to listen to. + * @param {(fix: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `fix` An object with fix info (see below) + * @url http://www.espruino.com/Reference#l_Bangle_GPS + */ + static on(event: "GPS", callback: (fix: GPSFix) => void): void; + + /** + * Heat rate data, as an object. Contains: + * ``` + * { "bpm": number, // Beats per minute + * "confidence": number, // 0-100 percentage confidence in the heart rate + * "raw": Uint8Array, // raw samples from heart rate monitor + * } + * ``` + * To get this event you must turn the heart rate monitor on with + * `Bangle.setHRMPower(1)`. + * @param {string} event - The event to listen to. + * @param {(hrm: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `hrm` An object with heart rate info (see below) + * @url http://www.espruino.com/Reference#l_Bangle_HRM + */ + static on(event: "HRM", callback: (hrm: { bpm: number, confidence: number, raw: Uint8Array }) => void): void; + + /** + * Called when heart rate sensor data is available - see `Bangle.setHRMPower(1)`. + * `hrm` is of the form: + * ``` + * { "raw": -1, // raw value from sensor + * "filt": -1, // bandpass-filtered raw value from sensor + * "bpm": 88.9, // last BPM value measured + * "confidence": 0 // confidence in the BPM value + * } + * ``` + * @param {string} event - The event to listen to. + * @param {(hrm: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `hrm` A object containing instant readings from the heart rate sensor + * @url http://www.espruino.com/Reference#l_Bangle_HRM-raw + */ + static on(event: "HRM-raw", callback: (hrm: { raw: number, filt: number, bpm: number, confidence: number }) => void): void; + + /** + * When `Bangle.setBarometerPower(true)` is called, this event is fired containing + * barometer readings. + * Same format as `Bangle.getPressure()` + * @param {string} event - The event to listen to. + * @param {(e: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `e` An object containing `{temperature,pressure,altitude}` + * @url http://www.espruino.com/Reference#l_Bangle_pressure + */ + static on(event: "pressure", callback: (e: PressureData) => void): void; + + /** + * Has the screen been turned on or off? Can be used to stop tasks that are no + * longer useful if nothing is displayed. Also see `Bangle.isLCDOn()` + * @param {string} event - The event to listen to. + * @param {(on: boolean) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `on` `true` if screen is on + * @url http://www.espruino.com/Reference#l_Bangle_lcdPower + */ + static on(event: "lcdPower", callback: (on: boolean) => void): void; + + /** + * Has the screen been locked? Also see `Bangle.isLocked()` + * @param {string} event - The event to listen to. + * @param {(on: boolean) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `on` `true` if screen is locked, `false` if it is unlocked and touchscreen/buttons will work + * @url http://www.espruino.com/Reference#l_Bangle_lock + */ + static on(event: "lock", callback: (on: boolean) => void): void; + + /** + * If the watch is tapped, this event contains information on the way it was + * tapped. + * `dir` reports the side of the watch that was tapped (not the direction it was + * tapped in). + * ``` + * { + * dir : "left/right/top/bottom/front/back", + * double : true/false // was this a double-tap? + * x : -2 .. 2, // the axis of the tap + * y : -2 .. 2, // the axis of the tap + * z : -2 .. 2 // the axis of the tap + * ``` + * @param {string} event - The event to listen to. + * @param {(data: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `data` `{dir, double, x, y, z}` + * @url http://www.espruino.com/Reference#l_Bangle_tap + */ + static on(event: "tap", callback: (data: { dir: "left" | "right" | "top" | "bottom" | "front" | "back", double: boolean, x: TapAxis, y: TapAxis, z: TapAxis }) => void): void; + + /** + * Emitted when a 'gesture' (fast movement) is detected + * @param {string} event - The event to listen to. + * @param {(xyz: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `xyz` An Int8Array of XYZXYZXYZ data + * @url http://www.espruino.com/Reference#l_Bangle_gesture + */ + static on(event: "gesture", callback: (xyz: Int8Array) => void): void; + + /** + * Emitted when a 'gesture' (fast movement) is detected, and a Tensorflow model is + * in storage in the `".tfmodel"` file. + * If a `".tfnames"` file is specified as a comma-separated list of names, it will + * be used to decode `gesture` from a number into a string. + * @param {string} event - The event to listen to. + * @param {(gesture: any, weights: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `gesture` The name of the gesture (if '.tfnames' exists, or the index. 'undefined' if not matching + * * `weights` An array of floating point values output by the model + * @url http://www.espruino.com/Reference#l_Bangle_aiGesture + */ + static on(event: "aiGesture", callback: (gesture: string | undefined, weights: number[]) => void): void; + + /** + * Emitted when a swipe on the touchscreen is detected (a movement from + * left->right, right->left, down->up or up->down) + * Bangle.js 1 is only capable of detecting left/right swipes as it only contains a + * 2 zone touchscreen. + * @param {string} event - The event to listen to. + * @param {(directionLR: number, directionUD: number) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `directionLR` `-1` for left, `1` for right, `0` for up/down + * * `directionUD` `-1` for up, `1` for down, `0` for left/right (Bangle.js 2 only) + * @url http://www.espruino.com/Reference#l_Bangle_swipe + */ + static on(event: "swipe", callback: SwipeCallback): void; + + /** + * Emitted when the touchscreen is pressed + * @param {string} event - The event to listen to. + * @param {(button: number, xy: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `button` `1` for left, `2` for right + * * `xy` Object of form `{x,y}` containing touch coordinates (if the device supports full touch). Clipped to 0..175 (LCD pixel coordinates) on firmware 2v13 and later. + * @url http://www.espruino.com/Reference#l_Bangle_touch + */ + static on(event: "touch", callback: TouchCallback): void; + + /** + * Emitted when the touchscreen is dragged or released + * The touchscreen extends past the edge of the screen and while `x` and `y` + * coordinates are arranged such that they align with the LCD's pixels, if your + * finger goes towards the edge of the screen, `x` and `y` could end up larger than + * 175 (the screen's maximum pixel coordinates) or smaller than 0. Coordinates from + * the `touch` event are clipped. + * @param {string} event - The event to listen to. + * @param {(event: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `event` Object of form `{x,y,dx,dy,b}` containing touch coordinates, difference in touch coordinates, and an integer `b` containing number of touch points (currently 1 or 0) + * @url http://www.espruino.com/Reference#l_Bangle_drag + */ + static on(event: "drag", callback: DragCallback): void; + + /** + * Emitted when the touchscreen is dragged for a large enough distance to count as + * a gesture. + * If Bangle.strokes is defined and populated with data from `Unistroke.new`, the + * `event` argument will also contain a `stroke` field containing the most closely + * matching stroke name. + * For example: + * ``` + * Bangle.strokes = { + * up : Unistroke.new(new Uint8Array([57, 151, ... 158, 137])), + * alpha : Unistroke.new(new Uint8Array([161, 55, ... 159, 161])), + * }; + * Bangle.on('stroke',o=>{ + * print(o.stroke); + * g.clear(1).drawPoly(o.xy); + * }); + * // Might print something like + * { + * "xy": new Uint8Array([149, 50, ... 107, 136]), + * "stroke": "alpha" + * } + * ``` + * @param {string} event - The event to listen to. + * @param {(event: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `event` Object of form `{xy:Uint8Array([x1,y1,x2,y2...])}` containing touch coordinates + * @url http://www.espruino.com/Reference#l_Bangle_stroke + */ + static on(event: "stroke", callback: (event: { xy: Uint8Array, stroke?: string }) => void): void; + + /** + * Emitted at midnight (at the point the `day` health info is reset to 0). + * Can be used for housekeeping tasks that don't want to be run during the day. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Bangle_midnight + */ + static on(event: "midnight", callback: () => void): void; + + /** + * This function can be used to turn Bangle.js's LCD off or on. + * This function resets the Bangle's 'activity timer' (like pressing a button or + * the screen would) so after a time period of inactivity set by + * `Bangle.setLCDTimeout` the screen will turn off. + * If you want to keep the screen on permanently (until apps are changed) you can + * do: + * ``` + * Bangle.setLCDTimeout(0); // turn off the timeout + * Bangle.setLCDPower(1); // keep screen on + * ``` + * **When on full, the LCD draws roughly 40mA.** You can adjust When brightness + * using `Bangle.setLCDBrightness`. + * + * @param {boolean} isOn - True if the LCD should be on, false if not + * @url http://www.espruino.com/Reference#l_Bangle_setLCDPower + */ + static setLCDPower(isOn: boolean): void; + + /** + * This function can be used to adjust the brightness of Bangle.js's display, and + * hence prolong its battery life. + * Due to hardware design constraints, software PWM has to be used which means that + * the display may flicker slightly when Bluetooth is active and the display is not + * at full power. + * **Power consumption** + * * 0 = 7mA + * * 0.1 = 12mA + * * 0.2 = 18mA + * * 0.5 = 28mA + * * 0.9 = 40mA (switching overhead) + * * 1 = 40mA + * + * @param {number} brightness - The brightness of Bangle.js's display - from 0(off) to 1(on full) + * @url http://www.espruino.com/Reference#l_Bangle_setLCDBrightness + */ + static setLCDBrightness(brightness: number): void; + + /** + * This function can be used to change the way graphics is handled on Bangle.js. + * Available options for `Bangle.setLCDMode` are: + * * `Bangle.setLCDMode()` or `Bangle.setLCDMode("direct")` (the default) - The + * drawable area is 240x240 16 bit. Unbuffered, so draw calls take effect + * immediately. Terminal and vertical scrolling work (horizontal scrolling + * doesn't). + * * `Bangle.setLCDMode("doublebuffered")` - The drawable area is 240x160 16 bit, + * terminal and scrolling will not work. `g.flip()` must be called for draw + * operations to take effect. + * * `Bangle.setLCDMode("120x120")` - The drawable area is 120x120 8 bit, + * `g.getPixel`, terminal, and full scrolling work. Uses an offscreen buffer + * stored on Bangle.js, `g.flip()` must be called for draw operations to take + * effect. + * * `Bangle.setLCDMode("80x80")` - The drawable area is 80x80 8 bit, `g.getPixel`, + * terminal, and full scrolling work. Uses an offscreen buffer stored on + * Bangle.js, `g.flip()` must be called for draw operations to take effect. + * You can also call `Bangle.setLCDMode()` to return to normal, unbuffered + * `"direct"` mode. + * + * @param {any} mode - The LCD mode (See below) + * @url http://www.espruino.com/Reference#l_Bangle_setLCDMode + */ + static setLCDMode(mode?: LCDMode): void; + + /** + * The current LCD mode. + * See `Bangle.setLCDMode` for examples. + * @returns {any} The LCD mode as a String + * @url http://www.espruino.com/Reference#l_Bangle_getLCDMode + */ + static getLCDMode(): LCDMode; + + /** + * This can be used to move the displayed memory area up or down temporarily. It's + * used for displaying notifications while keeping the main display contents + * intact. + * + * @param {number} y - The amount of pixels to shift the LCD up or down + * @url http://www.espruino.com/Reference#l_Bangle_setLCDOffset + */ + static setLCDOffset(y: number): void; + + /** + * This function can be used to turn Bangle.js's LCD power saving on or off. + * With power saving off, the display will remain in the state you set it with + * `Bangle.setLCDPower`. + * With power saving on, the display will turn on if a button is pressed, the watch + * is turned face up, or the screen is updated (see `Bangle.setOptions` for + * configuration). It'll turn off automatically after the given timeout. + * **Note:** This function also sets the Backlight and Lock timeout (the time at + * which the touchscreen/buttons start being ignored). To set both separately, use + * `Bangle.setOptions` + * + * @param {number} isOn - The timeout of the display in seconds, or `0`/`undefined` to turn power saving off. Default is 10 seconds. + * @url http://www.espruino.com/Reference#l_Bangle_setLCDTimeout + */ + static setLCDTimeout(isOn: number): void; + + /** + * Set how often the watch should poll for new acceleration/gyro data and kick the + * Watchdog timer. It isn't recommended that you make this interval much larger + * than 1000ms, but values up to 4000ms are allowed. + * Calling this will set `Bangle.setOptions({powerSave: false})` - disabling the + * dynamic adjustment of poll interval to save battery power when Bangle.js is + * stationary. + * + * @param {number} interval - Polling interval in milliseconds (Default is 80ms - 12.5Hz to match accelerometer) + * @url http://www.espruino.com/Reference#l_Bangle_setPollInterval + */ + static setPollInterval(interval: number): void; + + /** + * Set internal options used for gestures, etc... + * * `wakeOnBTN1` should the LCD turn on when BTN1 is pressed? default = `true` + * * `wakeOnBTN2` (Bangle.js 1) should the LCD turn on when BTN2 is pressed? + * default = `true` + * * `wakeOnBTN3` (Bangle.js 1) should the LCD turn on when BTN3 is pressed? + * default = `true` + * * `wakeOnFaceUp` should the LCD turn on when the watch is turned face up? + * default = `false` + * * `wakeOnTouch` should the LCD turn on when the touchscreen is pressed? default + * = `false` + * * `wakeOnTwist` should the LCD turn on when the watch is twisted? default = + * `true` + * * `twistThreshold` How much acceleration to register a twist of the watch strap? + * Can be negative for opposite direction. default = `800` + * * `twistMaxY` Maximum acceleration in Y to trigger a twist (low Y means watch is + * facing the right way up). default = `-800` + * * `twistTimeout` How little time (in ms) must a twist take from low->high + * acceleration? default = `1000` + * * `gestureStartThresh` how big a difference before we consider a gesture + * started? default = `sqr(800)` + * * `gestureEndThresh` how small a difference before we consider a gesture ended? + * default = `sqr(2000)` + * * `gestureInactiveCount` how many samples do we keep after a gesture has ended? + * default = `4` + * * `gestureMinLength` how many samples must a gesture have before we notify about + * it? default = `10` + * * `powerSave` after a minute of not being moved, Bangle.js will change the + * accelerometer poll interval down to 800ms (10x accelerometer samples). On + * movement it'll be raised to the default 80ms. If `Bangle.setPollInterval` is + * used this is disabled, and for it to work the poll interval must be either + * 80ms or 800ms. default = `true`. Setting `powerSave:false` will disable this + * automatic power saving, but will **not** change the poll interval from its + * current value. If you desire a specific interval (e.g. the default 80ms) you + * must set it manually with `Bangle.setPollInterval(80)` after setting + * `powerSave:false`. + * * `lockTimeout` how many milliseconds before the screen locks + * * `lcdPowerTimeout` how many milliseconds before the screen turns off + * * `backlightTimeout` how many milliseconds before the screen's backlight turns + * off + * * `hrmPollInterval` set the requested poll interval (in milliseconds) for the + * heart rate monitor. On Bangle.js 2 only 10,20,40,80,160,200 ms are supported, + * and polling rate may not be exact. The algorithm's filtering is tuned for + * 20-40ms poll intervals, so higher/lower intervals may effect the reliability + * of the BPM reading. + * * `seaLevelPressure` (Bangle.js 2) Normally 1013.25 millibars - this is used for + * calculating altitude with the pressure sensor + * Where accelerations are used they are in internal units, where `8192 = 1g` + * + * @param {any} options + * @url http://www.espruino.com/Reference#l_Bangle_setOptions + */ + static setOptions(options: { [key in keyof BangleOptions]?: BangleOptions[key] }): void; + + /** + * Return the current state of options as set by `Bangle.setOptions` + * @returns {any} The current state of all options + * @url http://www.espruino.com/Reference#l_Bangle_getOptions + */ + static getOptions(): BangleOptions; + + /** + * Also see the `Bangle.lcdPower` event + * @returns {boolean} Is the display on or not? + * @url http://www.espruino.com/Reference#l_Bangle_isLCDOn + */ + static isLCDOn(): boolean; + + /** + * This function can be used to lock or unlock Bangle.js (e.g. whether buttons and + * touchscreen work or not) + * + * @param {boolean} isLocked - `true` if the Bangle is locked (no user input allowed) + * @url http://www.espruino.com/Reference#l_Bangle_setLocked + */ + static setLocked(isLocked: boolean): void; + + /** + * Also see the `Bangle.lock` event + * @returns {boolean} Is the screen locked or not? + * @url http://www.espruino.com/Reference#l_Bangle_isLocked + */ + static isLocked(): boolean; + + /** + * @returns {boolean} Is the battery charging or not? + * @url http://www.espruino.com/Reference#l_Bangle_isCharging + */ + static isCharging(): boolean; + + /** + * Writes a command directly to the ST7735 LCD controller + * + * @param {number} cmd + * @param {any} data + * @url http://www.espruino.com/Reference#l_Bangle_lcdWr + */ + static lcdWr(cmd: number, data: any): void; + + /** + * Set the power to the Heart rate monitor + * When on, data is output via the `HRM` event on `Bangle`: + * ``` + * Bangle.setHRMPower(true, "myapp"); + * Bangle.on('HRM',print); + * ``` + * *When on, the Heart rate monitor draws roughly 5mA* + * + * @param {boolean} isOn - True if the heart rate monitor should be on, false if not + * @param {any} appID - A string with the app's name in, used to ensure one app can't turn off something another app is using + * @returns {boolean} Is HRM on? + * @url http://www.espruino.com/Reference#l_Bangle_setHRMPower + */ + static setHRMPower(isOn: boolean, appID: string): boolean; + + /** + * Is the Heart rate monitor powered? + * Set power with `Bangle.setHRMPower(...);` + * @returns {boolean} Is HRM on? + * @url http://www.espruino.com/Reference#l_Bangle_isHRMOn + */ + static isHRMOn(): boolean; + + /** + * Set the power to the GPS. + * When on, data is output via the `GPS` event on `Bangle`: + * ``` + * Bangle.setGPSPower(true, "myapp"); + * Bangle.on('GPS',print); + * ``` + * *When on, the GPS draws roughly 20mA* + * + * @param {boolean} isOn - True if the GPS should be on, false if not + * @param {any} appID - A string with the app's name in, used to ensure one app can't turn off something another app is using + * @returns {boolean} Is the GPS on? + * @url http://www.espruino.com/Reference#l_Bangle_setGPSPower + */ + static setGPSPower(isOn: boolean, appID: string): boolean; + + /** + * Is the GPS powered? + * Set power with `Bangle.setGPSPower(...);` + * @returns {boolean} Is the GPS on? + * @url http://www.espruino.com/Reference#l_Bangle_isGPSOn + */ + static isGPSOn(): boolean; + + /** + * Get the last available GPS fix info (or `undefined` if GPS is off). + * The fix info received is the same as you'd get from the `Bangle.GPS` event. + * @returns {any} A GPS fix object with `{lat,lon,...}` + * @url http://www.espruino.com/Reference#l_Bangle_getGPSFix + */ + static getGPSFix(): GPSFix; + + /** + * Set the power to the Compass + * When on, data is output via the `mag` event on `Bangle`: + * ``` + * Bangle.setCompassPower(true, "myapp"); + * Bangle.on('mag',print); + * ``` + * *When on, the compass draws roughly 2mA* + * + * @param {boolean} isOn - True if the Compass should be on, false if not + * @param {any} appID - A string with the app's name in, used to ensure one app can't turn off something another app is using + * @returns {boolean} Is the Compass on? + * @url http://www.espruino.com/Reference#l_Bangle_setCompassPower + */ + static setCompassPower(isOn: boolean, appID: string): boolean; + + /** + * Is the compass powered? + * Set power with `Bangle.setCompassPower(...);` + * @returns {boolean} Is the Compass on? + * @url http://www.espruino.com/Reference#l_Bangle_isCompassOn + */ + static isCompassOn(): boolean; + + /** + * Resets the compass minimum/maximum values. Can be used if the compass isn't + * providing a reliable heading any more. + * + * @url http://www.espruino.com/Reference#l_Bangle_resetCompass + */ + static resetCompass(): void; + + /** + * Set the power to the barometer IC. Once enabled, `Bangle.pressure` events are + * fired each time a new barometer reading is available. + * When on, the barometer draws roughly 50uA + * + * @param {boolean} isOn - True if the barometer IC should be on, false if not + * @param {any} appID - A string with the app's name in, used to ensure one app can't turn off something another app is using + * @returns {boolean} Is the Barometer on? + * @url http://www.espruino.com/Reference#l_Bangle_setBarometerPower + */ + static setBarometerPower(isOn: boolean, appID: string): boolean; + + /** + * Is the Barometer powered? + * Set power with `Bangle.setBarometerPower(...);` + * @returns {boolean} Is the Barometer on? + * @url http://www.espruino.com/Reference#l_Bangle_isBarometerOn + */ + static isBarometerOn(): boolean; + + /** + * Returns the current amount of steps recorded by the step counter + * @returns {number} The number of steps recorded by the step counter + * @url http://www.espruino.com/Reference#l_Bangle_getStepCount + */ + static getStepCount(): number; + + /** + * Sets the current value of the step counter + * + * @param {number} count - The value with which to reload the step counter + * @url http://www.espruino.com/Reference#l_Bangle_setStepCount + */ + static setStepCount(count: number): void; + + /** + * Get the most recent Magnetometer/Compass reading. Data is in the same format as + * the `Bangle.on('mag',` event. + * Returns an `{x,y,z,dx,dy,dz,heading}` object + * * `x/y/z` raw x,y,z magnetometer readings + * * `dx/dy/dz` readings based on calibration since magnetometer turned on + * * `heading` in degrees based on calibrated readings (will be NaN if magnetometer + * hasn't been rotated around 360 degrees) + * To get this event you must turn the compass on with `Bangle.setCompassPower(1)`. + * @returns {any} An object containing magnetometer readings (as below) + * @url http://www.espruino.com/Reference#l_Bangle_getCompass + */ + static getCompass(): CompassData; + + /** + * Get the most recent accelerometer reading. Data is in the same format as the + * `Bangle.on('accel',` event. + * * `x` is X axis (left-right) in `g` + * * `y` is Y axis (up-down) in `g` + * * `z` is Z axis (in-out) in `g` + * * `diff` is difference between this and the last reading in `g` (calculated by + * comparing vectors, not magnitudes) + * * `td` is the elapsed + * * `mag` is the magnitude of the acceleration in `g` + * @returns {any} An object containing accelerometer readings (as below) + * @url http://www.espruino.com/Reference#l_Bangle_getAccel + */ + static getAccel(): AccelData & { td: number }; + + /** + * `range` is one of: + * * `undefined` or `'current'` - health data so far in the last 10 minutes is + * returned, + * * `'last'` - health data during the last 10 minutes + * * `'day'` - the health data so far for the day + * `getHealthStatus` returns an object containing: + * * `movement` is the 32 bit sum of all `acc.diff` readings since power on (and + * rolls over). It is the difference in accelerometer values as `g*8192` + * * `steps` is the number of steps during this period + * * `bpm` the best BPM reading from HRM sensor during this period + * * `bpmConfidence` best BPM confidence (0-100%) during this period + * + * @param {any} range - What time period to return data for, see below: + * @returns {any} Returns an object containing various health info + * @url http://www.espruino.com/Reference#l_Bangle_getHealthStatus + */ + static getHealthStatus(range?: "current" | "last" | "day"): HealthStatus; + + /** + * Reads debug info + * @returns {any} + * @url http://www.espruino.com/Reference#l_Bangle_dbg + */ + static dbg(): any; + + /** + * Writes a register on the accelerometer + * + * @param {number} reg + * @param {number} data + * @url http://www.espruino.com/Reference#l_Bangle_accelWr + */ + static accelWr(reg: number, data: number): void; + + /** + * Reads a register from the accelerometer + * **Note:** On Espruino 2v06 and before this function only returns a number (`cnt` + * is ignored). + * + * @param {number} reg + * @param {number} cnt - If specified, returns an array of the given length (max 128). If not (or 0) it returns a number + * @returns {any} + * @url http://www.espruino.com/Reference#l_Bangle_accelRd + */ + static accelRd(reg: number, cnt?: 0): number; + static accelRd(reg: number, cnt: number): number[]; + + /** + * Writes a register on the barometer IC + * + * @param {number} reg + * @param {number} data + * @url http://www.espruino.com/Reference#l_Bangle_barometerWr + */ + static barometerWr(reg: number, data: number): void; + + /** + * Reads a register from the barometer IC + * + * @param {number} reg + * @param {number} cnt - If specified, returns an array of the given length (max 128). If not (or 0) it returns a number + * @returns {any} + * @url http://www.espruino.com/Reference#l_Bangle_barometerRd + */ + static barometerRd(reg: number, cnt?: 0): number; + static barometerRd(reg: number, cnt: number): number[]; + + /** + * Writes a register on the Magnetometer/Compass + * + * @param {number} reg + * @param {number} data + * @url http://www.espruino.com/Reference#l_Bangle_compassWr + */ + static compassWr(reg: number, data: number): void; + + /** + * Read a register on the Magnetometer/Compass + * + * @param {number} reg + * @param {number} cnt - If specified, returns an array of the given length (max 128). If not (or 0) it returns a number + * @returns {any} + * @url http://www.espruino.com/Reference#l_Bangle_compassRd + */ + static compassRd(reg: number, cnt?: 0): number; + static compassRd(reg: number, cnt: number): number[]; + + /** + * Writes a register on the Heart rate monitor + * + * @param {number} reg + * @param {number} data + * @url http://www.espruino.com/Reference#l_Bangle_hrmWr + */ + static hrmWr(reg: number, data: number): void; + + /** + * Read a register on the Heart rate monitor + * + * @param {number} reg + * @param {number} cnt - If specified, returns an array of the given length (max 128). If not (or 0) it returns a number + * @returns {any} + * @url http://www.espruino.com/Reference#l_Bangle_hrmRd + */ + static hrmRd(reg: number, cnt?: 0): number; + static hrmRd(reg: number, cnt: number): number[]; + + /** + * Changes a pin state on the IO expander + * + * @param {number} mask + * @param {number} isOn + * @url http://www.espruino.com/Reference#l_Bangle_ioWr + */ + static ioWr(mask: number, isOn: number): void; + + /** + * Read temperature, pressure and altitude data. A promise is returned which will + * be resolved with `{temperature, pressure, altitude}`. + * If the Barometer has been turned on with `Bangle.setBarometerPower` then this + * will return almost immediately with the reading. If the Barometer is off, + * conversions take between 500-750ms. + * Altitude assumes a sea-level pressure of 1013.25 hPa + * ``` + * Bangle.getPressure().then(d=>{ + * console.log(d); + * // {temperature, pressure, altitude} + * }); + * ``` + * @returns {any} A promise that will be resolved with `{temperature, pressure, altitude}` + * @url http://www.espruino.com/Reference#l_Bangle_getPressure + */ + static getPressure(): PressureData; + + /** + * Perform a Spherical [Web Mercator + * projection](https://en.wikipedia.org/wiki/Web_Mercator_projection) of latitude + * and longitude into `x` and `y` coordinates, which are roughly equivalent to + * meters from `{lat:0,lon:0}`. + * This is the formula used for most online mapping and is a good way to compare + * GPS coordinates to work out the distance between them. + * + * @param {any} latlong - `{lat:..., lon:...}` + * @returns {any} {x:..., y:...} + * @url http://www.espruino.com/Reference#l_Bangle_project + */ + static project(latlong: { lat: number, lon: number }): { x: number, y: number }; + + /** + * Use the piezo speaker to Beep for a certain time period and frequency + * + * @param {number} [time] - [optional] Time in ms (default 200) + * @param {number} [freq] - [optional] Frequency in hz (default 4000) + * @returns {any} A promise, completed when beep is finished + * @url http://www.espruino.com/Reference#l_Bangle_beep + */ + static beep(time?: number, freq?: number): Promise; + + /** + * Use the vibration motor to buzz for a certain time period + * + * @param {number} [time] - [optional] Time in ms (default 200) + * @param {number} [strength] - [optional] Power of vibration from 0 to 1 (Default 1) + * @returns {any} A promise, completed when vibration is finished + * @url http://www.espruino.com/Reference#l_Bangle_buzz + */ + static buzz(time?: number, strength?: number): Promise; + + /** + * Turn Bangle.js off. It can only be woken by pressing BTN1. + * @url http://www.espruino.com/Reference#l_Bangle_off + */ + static off(): void; + + /** + * Turn Bangle.js (mostly) off, but keep the CPU in sleep mode until BTN1 is + * pressed to preserve the RTC (current time). + * @url http://www.espruino.com/Reference#l_Bangle_softOff + */ + static softOff(): void; + + /** + * * On platforms with an LCD of >=8bpp this is 222 x 104 x 2 bits + * * Otherwise it's 119 x 56 x 1 bits + * @returns {any} An image to be used with `g.drawImage` (as a String) + * @url http://www.espruino.com/Reference#l_Bangle_getLogo + */ + static getLogo(): string; + + /** + * Load all widgets from flash Storage. Call this once at the beginning of your + * application if you want any on-screen widgets to be loaded. + * They will be loaded into a global `WIDGETS` array, and can be rendered with + * `Bangle.drawWidgets`. + * @url http://www.espruino.com/Reference#l_Bangle_loadWidgets + */ + static loadWidgets(): void; + + /** + * Draw any onscreen widgets that were loaded with `Bangle.loadWidgets()`. + * Widgets should redraw themselves when something changes - you'll only need to + * call drawWidgets if you decide to clear the entire screen with `g.clear()`. + * @url http://www.espruino.com/Reference#l_Bangle_drawWidgets + */ + static drawWidgets(): void; + + /** + * @url http://www.espruino.com/Reference#l_Bangle_drawWidgets + */ + static drawWidgets(): void; + + /** + * Load the Bangle.js app launcher, which will allow the user to select an + * application to launch. + * @url http://www.espruino.com/Reference#l_Bangle_showLauncher + */ + static showLauncher(): void; + + /** + * This puts Bangle.js into the specified UI input mode, and calls the callback + * provided when there is user input. + * Currently supported interface types are: + * * 'updown' - UI input with upwards motion `cb(-1)`, downwards motion `cb(1)`, + * and select `cb()` + * * Bangle.js 1 uses BTN1/3 for up/down and BTN2 for select + * * Bangle.js 2 uses touchscreen swipe up/down and tap + * * 'leftright' - UI input with left motion `cb(-1)`, right motion `cb(1)`, and + * select `cb()` + * * Bangle.js 1 uses BTN1/3 for left/right and BTN2 for select + * * Bangle.js 2 uses touchscreen swipe left/right and tap/BTN1 for select + * * 'clock' - called for clocks. Sets `Bangle.CLOCK=1` and allows a button to + * start the launcher + * * Bangle.js 1 BTN2 starts the launcher + * * Bangle.js 2 BTN1 starts the launcher + * * 'clockupdown' - called for clocks. Sets `Bangle.CLOCK=1`, allows a button to + * start the launcher, but also provides up/down functionality + * * Bangle.js 1 BTN2 starts the launcher, BTN1/BTN3 call `cb(-1)` and `cb(1)` + * * Bangle.js 2 BTN1 starts the launcher, touchscreen tap in top/bottom right + * hand side calls `cb(-1)` and `cb(1)` + * * `{mode:"custom", ...}` allows you to specify custom handlers for different + * interactions. See below. + * * `undefined` removes all user interaction code + * While you could use setWatch/etc manually, the benefit here is that you don't + * end up with multiple `setWatch` instances, and the actual input method (touch, + * or buttons) is implemented dependent on the watch (Bangle.js 1 or 2) + * **Note:** You can override this function in boot code to change the interaction + * mode with the watch. For instance you could make all clocks start the launcher + * with a swipe by using: + * ``` + * (function() { + * var sui = Bangle.setUI; + * Bangle.setUI = function(mode, cb) { + * if (mode!="clock") return sui(mode,cb); + * sui(); // clear + * Bangle.CLOCK=1; + * Bangle.swipeHandler = Bangle.showLauncher; + * Bangle.on("swipe", Bangle.swipeHandler); + * }; + * })(); + * ``` + * The first argument can also be an object, in which case more options can be + * specified: + * ``` + * Bangle.setUI({ + * mode : "custom", + * back : function() {}, // optional - add a 'back' icon in top-left widget area and call this function when it is pressed + * touch : function(n,e) {}, // optional - handler for 'touch' events + * swipe : function(dir) {}, // optional - handler for 'swipe' events + * drag : function(e) {}, // optional - handler for 'drag' events (Bangle.js 2 only) + * btn : function(n) {}, // optional - handler for 'button' events (n==1 on Bangle.js 2, n==1/2/3 depending on button for Bangle.js 1) + * clock : 0 // optional - if set the behavior of 'clock' mode is added (does not override btn if defined) + * }); + * ``` + * + * @param {any} type - The type of UI input: 'updown', 'leftright', 'clock', 'clockupdown' or undefined to cancel. Can also be an object (see below) + * @param {any} callback - A function with one argument which is the direction + * @url http://www.espruino.com/Reference#l_Bangle_setUI + */ + static setUI(type?: "updown" | "leftright" | "clock" | "clockupdown" | { mode: "custom"; back?: () => void; touch?: TouchCallback; swipe?: SwipeCallback; drag?: DragCallback; btn?: (n: number) => void, clock?: boolean }, callback?: (direction?: -1 | 1) => void): void; + + /** + * @url http://www.espruino.com/Reference#l_Bangle_setUI + */ + static setUI(): void; + + /** + * Erase all storage and reload it with the default contents. + * This is only available on Bangle.js 2.0. On Bangle.js 1.0 you need to use + * `Install Default Apps` under the `More...` tab of http://banglejs.com/apps + * @url http://www.espruino.com/Reference#l_Bangle_factoryReset + */ + static factoryReset(): void; + + /** + * Returns the rectangle on the screen that is currently reserved for the app. + * @returns {any} An object of the form `{x,y,w,h,x2,y2}` + * @url http://www.espruino.com/Reference#l_Bangle_appRect + */ + static appRect: { x: number, y: number, w: number, h: number, x2: number, y2: number }; + + static CLOCK: boolean; + static strokes: undefined | { [key: string]: Unistroke }; +} + +interface DateConstructor { + /** + * Get the number of milliseconds elapsed since 1970 (or on embedded platforms, + * since startup) + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_now + */ + now(): number; + + /** + * Parse a date string and return milliseconds since 1970. Data can be either + * '2011-10-20T14:48:00', '2011-10-20' or 'Mon, 25 Dec 1995 13:30:00 +0430' + * + * @param {any} str - A String + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_parse + */ + parse(str: string): number; + + /** + * Creates a date object + * @constructor + * + * @param {any} args - Either nothing (current time), one numeric argument (milliseconds since 1970), a date string (see `Date.parse`), or [year, month, day, hour, minute, second, millisecond] + * @returns {any} A Date object + * @url http://www.espruino.com/Reference#l_Date_Date + */ + new(): Date; + new(value: number | string): Date; + new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; +} + +interface Date { + /** + * This returns the time-zone offset from UTC, in minutes. + * @returns {number} The difference, in minutes, between UTC and local time + * @url http://www.espruino.com/Reference#l_Date_getTimezoneOffset + */ + getTimezoneOffset(): number; + + /** + * This returns a boolean indicating whether daylight savings time is in effect. + * @returns {number} true if daylight savings time is in effect + * @url http://www.espruino.com/Reference#l_Date_getIsDST + */ + getIsDST(): boolean + + /** + * Return the number of milliseconds since 1970 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getTime + */ + getTime(): number; + + /** + * Return the number of milliseconds since 1970 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_valueOf + */ + valueOf(): number; + + /** + * Set the time/date of this Date class + * + * @param {number} timeValue - the number of milliseconds since 1970 + * @returns {number} the number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setTime + */ + setTime(timeValue: number): number; + + /** + * 0..23 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getHours + */ + getHours(): number; + + /** + * 0..59 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getMinutes + */ + getMinutes(): number; + + /** + * 0..59 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getSeconds + */ + getSeconds(): number; + + /** + * 0..999 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getMilliseconds + */ + getMilliseconds(): number; + + /** + * Day of the week (0=sunday, 1=monday, etc) + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getDay + */ + getDay(): number; + + /** + * Day of the month 1..31 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getDate + */ + getDate(): number; + + /** + * Month of the year 0..11 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getMonth + */ + getMonth(): number; + + /** + * The year, eg. 2014 + * @returns {number} + * @url http://www.espruino.com/Reference#l_Date_getFullYear + */ + getFullYear(): number; + + /** + * 0..23 + * + * @param {number} hoursValue - number of hours, 0..23 + * @param {any} minutesValue - number of minutes, 0..59 + * @param {any} secondsValue - optional - number of seconds, 0..59 + * @param {any} millisecondsValue - optional - number of milliseconds, 0..999 + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setHours + */ + setHours(hoursValue: number, minutesValue?: number, secondsValue?: number, millisecondsValue?: number): number; + + /** + * 0..59 + * + * @param {number} minutesValue - number of minutes, 0..59 + * @param {any} secondsValue - optional - number of seconds, 0..59 + * @param {any} millisecondsValue - optional - number of milliseconds, 0..999 + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setMinutes + */ + setMinutes(minutesValue: number, secondsValue?: number, millisecondsValue?: number): number; + + /** + * 0..59 + * + * @param {number} secondsValue - number of seconds, 0..59 + * @param {any} millisecondsValue - optional - number of milliseconds, 0..999 + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setSeconds + */ + setSeconds(secondsValue: number, millisecondsValue?: number): number; + + /** + * + * @param {number} millisecondsValue - number of milliseconds, 0..999 + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setMilliseconds + */ + setMilliseconds(millisecondsValue: number): number; + + /** + * Day of the month 1..31 + * + * @param {number} dayValue - the day of the month, between 0 and 31 + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setDate + */ + setDate(dayValue: number): number; + + /** + * Month of the year 0..11 + * + * @param {number} yearValue - The month, between 0 and 11 + * @param {any} dayValue - optional - the day, between 0 and 31 + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setMonth + */ + setMonth(yearValue: number, dayValue?: number): number; + + /** + * + * @param {number} yearValue - The full year - eg. 1989 + * @param {any} monthValue - optional - the month, between 0 and 11 + * @param {any} dayValue - optional - the day, between 0 and 31 + * @returns {number} The number of milliseconds since 1970 + * @url http://www.espruino.com/Reference#l_Date_setFullYear + */ + setFullYear(yearValue: number, monthValue?: number, dayValue?: number): number; + + /** + * Converts to a String, eg: `Fri Jun 20 2014 14:52:20 GMT+0000` + * **Note:** This uses whatever timezone was set with `E.setTimeZone()` or + * `E.setDST()` + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_Date_toString + */ + toString(): string; + + /** + * Converts to a String, eg: `Fri, 20 Jun 2014 14:52:20 GMT` + * **Note:** This always assumes a timezone of GMT + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_Date_toUTCString + */ + toUTCString(): string; + + /** + * Converts to a ISO 8601 String, eg: `2014-06-20T14:52:20.123Z` + * **Note:** This always assumes a timezone of GMT + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_Date_toISOString + */ + toISOString(): string; + + /** + * Calls `Date.toISOString` to output this date to JSON + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_Date_toJSON + */ + toJSON(): string; + + /** + * Converts to a ISO 8601 String (with timezone information), eg: + * `2014-06-20T14:52:20.123-0500` + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_Date_toLocalISOString + */ + toLocalISOString(): string; +} + +/** + * The built-in class for handling Dates. + * **Note:** By default the time zone is GMT+0, however you can change the timezone + * using the `E.setTimeZone(...)` function. + * For example `E.setTimeZone(1)` will be GMT+0100 + * *However* if you have daylight savings time set with `E.setDST(...)` then the + * timezone set by `E.setTimeZone(...)` will be _ignored_. + * @url http://www.espruino.com/Reference#Date + */ +declare const Date: DateConstructor + +/** + * This class provides a software-defined OneWire master. It is designed to be + * similar to Arduino's OneWire library. + * @url http://www.espruino.com/Reference#OneWire + */ +declare class OneWire { + /** + * Create a software OneWire implementation on the given pin + * @constructor + * + * @param {Pin} pin - The pin to implement OneWire on + * @returns {any} A OneWire object + * @url http://www.espruino.com/Reference#l_OneWire_OneWire + */ + static new(pin: Pin): any; + + /** + * Perform a reset cycle + * @returns {boolean} True is a device was present (it held the bus low) + * @url http://www.espruino.com/Reference#l_OneWire_reset + */ + reset(): boolean; + + /** + * Select a ROM - always performs a reset first + * + * @param {any} rom - The device to select (get this using `OneWire.search()`) + * @url http://www.espruino.com/Reference#l_OneWire_select + */ + select(rom: any): void; + + /** + * Skip a ROM + * @url http://www.espruino.com/Reference#l_OneWire_skip + */ + skip(): void; + + /** + * Write one or more bytes + * + * @param {any} data - A byte (or array of bytes) to write + * @param {boolean} power - Whether to leave power on after write (default is false) + * @url http://www.espruino.com/Reference#l_OneWire_write + */ + write(data: any, power: boolean): void; + + /** + * Read a byte + * + * @param {any} count - (optional) The amount of bytes to read + * @returns {any} The byte that was read, or a Uint8Array if count was specified and >=0 + * @url http://www.espruino.com/Reference#l_OneWire_read + */ + read(count: any): any; + + /** + * Search for devices + * + * @param {number} command - (Optional) command byte. If not specified (or zero), this defaults to 0xF0. This can could be set to 0xEC to perform a DS18B20 'Alarm Search Command' + * @returns {any} An array of devices that were found + * @url http://www.espruino.com/Reference#l_OneWire_search + */ + search(command: number): any; +} + +interface NumberConstructor { + /** + * @returns {number} Not a Number + * @url http://www.espruino.com/Reference#l_Number_NaN + */ + NaN: number; + + /** + * @returns {number} Maximum representable value + * @url http://www.espruino.com/Reference#l_Number_MAX_VALUE + */ + MAX_VALUE: number; + + /** + * @returns {number} Smallest representable value + * @url http://www.espruino.com/Reference#l_Number_MIN_VALUE + */ + MIN_VALUE: number; + + /** + * @returns {number} Negative Infinity (-1/0) + * @url http://www.espruino.com/Reference#l_Number_NEGATIVE_INFINITY + */ + NEGATIVE_INFINITY: number; + + /** + * @returns {number} Positive Infinity (1/0) + * @url http://www.espruino.com/Reference#l_Number_POSITIVE_INFINITY + */ + POSITIVE_INFINITY: number; + + /** + * Creates a number + * @constructor + * + * @param {any} value - A single value to be converted to a number + * @returns {any} A Number object + * @url http://www.espruino.com/Reference#l_Number_Number + */ + new(...value: any[]): any; +} + +interface Number { + /** + * Format the number as a fixed point number + * + * @param {number} decimalPlaces - A number between 0 and 20 specifying the number of decimal digits after the decimal point + * @returns {any} A string + * @url http://www.espruino.com/Reference#l_Number_toFixed + */ + toFixed(decimalPlaces: number): any; +} + +/** + * This is the built-in JavaScript class for numbers. + * @url http://www.espruino.com/Reference#Number + */ +declare const Number: NumberConstructor + +interface ArrayBufferConstructor { + /** + * Create an Array Buffer object + * @constructor + * + * @param {number} byteLength - The length in Bytes + * @returns {any} An ArrayBuffer object + * @url http://www.espruino.com/Reference#l_ArrayBuffer_ArrayBuffer + */ + new(byteLength: number): ArrayBuffer; +} + +interface ArrayBuffer { + /** + * The length, in bytes, of the `ArrayBuffer` + * @returns {number} The Length in bytes + * @url http://www.espruino.com/Reference#l_ArrayBuffer_byteLength + */ + byteLength: number; +} + +/** + * This is the built-in JavaScript class for array buffers. + * If you want to access arrays of differing types of data you may also find + * `DataView` useful. + * @url http://www.espruino.com/Reference#ArrayBuffer + */ +declare const ArrayBuffer: ArrayBufferConstructor + +/** + * This is the built-in JavaScript class that is the prototype for: + * * [Uint8Array](/Reference#Uint8Array) + * * [UintClamped8Array](/Reference#UintClamped8Array) + * * [Int8Array](/Reference#Int8Array) + * * [Uint16Array](/Reference#Uint16Array) + * * [Int16Array](/Reference#Int16Array) + * * [Uint24Array](/Reference#Uint24Array) (Espruino-specific - not standard JS) + * * [Uint32Array](/Reference#Uint32Array) + * * [Int32Array](/Reference#Int32Array) + * * [Float32Array](/Reference#Float32Array) + * * [Float64Array](/Reference#Float64Array) + * If you want to access arrays of differing types of data you may also find + * `DataView` useful. + * @url http://www.espruino.com/Reference#ArrayBufferView + */ +declare class ArrayBufferView { + + + /** + * The buffer this view references + * @returns {any} An ArrayBuffer object + * @url http://www.espruino.com/Reference#l_ArrayBufferView_buffer + */ + readonly buffer: T; + + /** + * The length, in bytes, of the `ArrayBufferView` + * @returns {number} The Length + * @url http://www.espruino.com/Reference#l_ArrayBufferView_byteLength + */ + readonly byteLength: number; + + /** + * The offset, in bytes, to the first byte of the view within the backing + * `ArrayBuffer` + * @returns {number} The byte Offset + * @url http://www.espruino.com/Reference#l_ArrayBufferView_byteOffset + */ + readonly byteOffset: number; + + /** + * Copy the contents of `array` into this one, mapping `this[x+offset]=array[x];` + * + * @param {any} arr - Floating point index to access + * @param {number} offset - The offset in this array at which to write the values (optional) + * @url http://www.espruino.com/Reference#l_ArrayBufferView_set + */ + set(arr: ArrayLike, offset: number): void + + /** + * Return an array which is made from the following: ```A.map(function) = + * [function(A[0]), function(A[1]), ...]``` + * **Note:** This returns an `ArrayBuffer` of the same type it was called on. To + * get an `Array`, use `Array.map`, e.g. `[].map.call(myArray, x=>x+1)` + * + * @param {any} function - Function used to map one item to another + * @param {any} thisArg - if specified, the function is called with 'this' set to thisArg (optional) + * @returns {any} An array containing the results + * @url http://www.espruino.com/Reference#l_ArrayBufferView_map + */ + map(callbackfn: (value: number, index: number, array: T) => number, thisArg?: any): T; + + /** + * Returns a smaller part of this array which references the same data (it doesn't + * copy it). + * + * @param {number} begin - Element to begin at, inclusive. If negative, this is from the end of the array. The entire array is included if this isn't specified + * @param {any} end - Element to end at, exclusive. If negative, it is relative to the end of the array. If not specified the whole array is included + * @returns {any} An `ArrayBufferView` of the same type as this one, referencing the same data + * @url http://www.espruino.com/Reference#l_ArrayBufferView_subarray + */ + subarray(begin?: number, end?: number): T; + + /** + * Return the index of the value in the array, or `-1` + * + * @param {any} value - The value to check for + * @param {number} startIndex - (optional) the index to search from, or 0 if not specified + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_ArrayBufferView_indexOf + */ + indexOf(value: number, startIndex?: number): number; + + /** + * Return `true` if the array includes the value, `false` otherwise + * + * @param {any} value - The value to check for + * @param {number} startIndex - (optional) the index to search from, or 0 if not specified + * @returns {boolean} `true` if the array includes the value, `false` otherwise + * @url http://www.espruino.com/Reference#l_ArrayBufferView_includes + */ + includes(value: number, startIndex?: number): boolean; + + /** + * Join all elements of this array together into one string, using 'separator' + * between them. e.g. ```[1,2,3].join(' ')=='1 2 3'``` + * + * @param {any} separator - The separator + * @returns {any} A String representing the Joined array + * @url http://www.espruino.com/Reference#l_ArrayBufferView_join + */ + join(separator?: string): string; + + /** + * Do an in-place quicksort of the array + * + * @param {any} var - A function to use to compare array elements (or undefined) + * @returns {any} This array object + * @url http://www.espruino.com/Reference#l_ArrayBufferView_sort + */ + sort(compareFn?: (a: number, b: number) => number): this; + + /** + * Executes a provided function once per array element. + * + * @param {any} function - Function to be executed + * @param {any} thisArg - if specified, the function is called with 'this' set to thisArg (optional) + * @url http://www.espruino.com/Reference#l_ArrayBufferView_forEach + */ + forEach(callbackfn: (value: number, index: number, array: T) => void, thisArg?: any): void; + + /** + * Execute `previousValue=initialValue` and then `previousValue = + * callback(previousValue, currentValue, index, array)` for each element in the + * array, and finally return previousValue. + * + * @param {any} callback - Function used to reduce the array + * @param {any} initialValue - if specified, the initial value to pass to the function + * @returns {any} The value returned by the last function called + * @url http://www.espruino.com/Reference#l_ArrayBufferView_reduce + */ + reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: T) => number, initialValue?: number): number; + + /** + * Fill this array with the given value, for every index `>= start` and `< end` + * + * @param {any} value - The value to fill the array with + * @param {number} start - Optional. The index to start from (or 0). If start is negative, it is treated as length+start where length is the length of the array + * @param {any} end - Optional. The index to end at (or the array length). If end is negative, it is treated as length+end. + * @returns {any} This array + * @url http://www.espruino.com/Reference#l_ArrayBufferView_fill + */ + fill(value: number, start?: number, end?: number): T; + + /** + * Return an array which contains only those elements for which the callback + * function returns 'true' + * + * @param {any} function - Function to be executed + * @param {any} thisArg - if specified, the function is called with 'this' set to thisArg (optional) + * @returns {any} An array containing the results + * @url http://www.espruino.com/Reference#l_ArrayBufferView_filter + */ + filter(predicate: (value: number, index: number, array: T) => any, thisArg?: any): T; + + /** + * Return the array element where `function` returns `true`, or `undefined` if it + * doesn't returns `true` for any element. + * + * @param {any} function - Function to be executed + * @returns {any} The array element where `function` returns `true`, or `undefined` + * @url http://www.espruino.com/Reference#l_ArrayBufferView_find + */ + find(predicate: (value: number, index: number, obj: T) => boolean, thisArg?: any): number | undefined; + + /** + * Return the array element's index where `function` returns `true`, or `-1` if it + * doesn't returns `true` for any element. + * + * @param {any} function - Function to be executed + * @returns {any} The array element's index where `function` returns `true`, or `-1` + * @url http://www.espruino.com/Reference#l_ArrayBufferView_findIndex + */ + findIndex(predicate: (value: number, index: number, obj: T) => boolean, thisArg?: any): number; + + /** + * Reverse the contents of this `ArrayBufferView` in-place + * @returns {any} This array + * @url http://www.espruino.com/Reference#l_ArrayBufferView_reverse + */ + reverse(): T + + /** + * Return a copy of a portion of this array (in a new array). + * **Note:** This currently returns a normal `Array`, not an `ArrayBuffer` + * + * @param {number} start - Start index + * @param {any} end - End index (optional) + * @returns {any} A new array + * @url http://www.espruino.com/Reference#l_ArrayBufferView_slice + */ + slice(start?: number, end?: number): number[]; + + [index: number]: number +} + +interface Uint8ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Uint8Array_Uint8Array + */ + new(length: number): Uint8Array; + new(array: ArrayLike): Uint8Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8Array; +} + +type Uint8Array = ArrayBufferView; + +declare const Uint8Array: Uint8ArrayConstructor + +interface Uint8ClampedArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * Clamped arrays clamp their values to the allowed range, rather than 'wrapping'. + * e.g. after `a[0]=12345;`, `a[0]==255`. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Uint8ClampedArray_Uint8ClampedArray + */ + new(length: number): Uint8ClampedArray; + new(array: ArrayLike): Uint8ClampedArray; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint8ClampedArray; +} + +type Uint8ClampedArray = ArrayBufferView; + +declare const Uint8ClampedArray: Uint8ClampedArrayConstructor + +interface Int8ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Int8Array_Int8Array + */ + new(length: number): Int8Array; + new(array: ArrayLike): Int8Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Int8Array; +} + +type Int8Array = ArrayBufferView; + +declare const Int8Array: Int8ArrayConstructor + +interface Uint16ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Uint16Array_Uint16Array + */ + new(length: number): Uint16Array; + new(array: ArrayLike): Uint16Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint16Array; +} + +type Uint16Array = ArrayBufferView; + +declare const Uint16Array: Uint16ArrayConstructor + +interface Int16ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Int16Array_Int16Array + */ + new(length: number): Int16Array; + new(array: ArrayLike): Int16Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Int16Array; +} + +type Int16Array = ArrayBufferView; + +declare const Int16Array: Int16ArrayConstructor + +/** + * This is the built-in JavaScript class for a typed array of 24 bit unsigned + * integers. + * Instantiate this in order to efficiently store arrays of data (Espruino's normal + * arrays store data in a map, which is inefficient for non-sparse arrays). + * Arrays of this type include all the methods from + * [ArrayBufferView](/Reference#ArrayBufferView) + * @url http://www.espruino.com/Reference#Uint24Array + */ +declare class Uint24Array { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Uint24Array_Uint24Array + */ + static new(length: number): Uint24Array; + static new(array: ArrayLike): Uint24Array; + static new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint24Array; + + +} + +interface Uint32ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Uint32Array_Uint32Array + */ + new(length: number): Uint32Array; + new(array: ArrayLike): Uint32Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Uint32Array; +} + +type Uint32Array = ArrayBufferView; + +declare const Uint32Array: Uint32ArrayConstructor + +interface Int32ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Int32Array_Int32Array + */ + new(length: number): Int32Array; + new(array: ArrayLike): Int32Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Int32Array; +} + +type Int32Array = ArrayBufferView; + +declare const Int32Array: Int32ArrayConstructor + +interface Float32ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Float32Array_Float32Array + */ + new(length: number): Float32Array; + new(array: ArrayLike): Float32Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Float32Array; +} + +type Float32Array = ArrayBufferView; + +declare const Float32Array: Float32ArrayConstructor + +interface Float64ArrayConstructor { + /** + * Create a typed array based on the given input. Either an existing Array Buffer, + * an Integer as a Length, or a simple array. If an `ArrayBufferView` (e.g. + * `Uint8Array` rather than `ArrayBuffer`) is given, it will be completely copied + * rather than referenced. + * @constructor + * + * @param {any} arr - The array or typed array to base this off, or an integer which is the array length + * @param {number} byteOffset - The byte offset in the ArrayBuffer (ONLY IF the first argument was an ArrayBuffer) + * @param {number} length - The length (ONLY IF the first argument was an ArrayBuffer) + * @returns {any} A typed array + * @url http://www.espruino.com/Reference#l_Float64Array_Float64Array + */ + new(length: number): Float64Array; + new(array: ArrayLike): Float64Array; + new(buffer: ArrayBuffer, byteOffset?: number, length?: number): Float64Array; +} + +type Float64Array = ArrayBufferView; + +declare const Float64Array: Float64ArrayConstructor + +interface PromiseConstructor { + /** + * Return a new promise that is resolved when all promises in the supplied array + * are resolved. + * + * @param {any} promises - An array of promises + * @returns {any} A new Promise + * @url http://www.espruino.com/Reference#l_Promise_all + */ + all(promises: Promise[]): Promise; + + /** + * Return a new promise that is already resolved (at idle it'll call `.then`) + * + * @param {any} promises - Data to pass to the `.then` handler + * @returns {any} A new Promise + * @url http://www.espruino.com/Reference#l_Promise_resolve + */ + resolve(promises: T): Promise; + + /** + * Return a new promise that is already rejected (at idle it'll call `.catch`) + * + * @param {any} promises - Data to pass to the `.catch` handler + * @returns {any} A new Promise + * @url http://www.espruino.com/Reference#l_Promise_reject + */ + reject(promises: any): any; + + /** + * Create a new Promise. The executor function is executed immediately (before the + * constructor even returns) and + * @constructor + * + * @param {any} executor - A function of the form `function (resolve, reject)` + * @returns {any} A Promise + * @url http://www.espruino.com/Reference#l_Promise_Promise + */ + new(executor: (resolve: (value: T) => void, reject: (reason?: any) => void) => void): Promise; +} + +interface Promise { + /** + * + * @param {any} onFulfilled - A callback that is called when this promise is resolved + * @param {any} [onRejected] - [optional] A callback that is called when this promise is rejected (or nothing) + * @returns {any} The original Promise + * @url http://www.espruino.com/Reference#l_Promise_then + */ + then(onfulfilled?: ((value: T) => TResult1 | Promise) | undefined | null, onrejected?: ((reason: any) => TResult2 | Promise) | undefined | null): Promise; + + /** + * + * @param {any} onRejected - A callback that is called when this promise is rejected + * @returns {any} The original Promise + * @url http://www.espruino.com/Reference#l_Promise_catch + */ + catch(onRejected: any): any; +} + +/** + * This is the built-in class for ES6 Promises + * @url http://www.espruino.com/Reference#Promise + */ +declare const Promise: PromiseConstructor + +/** + * This class allows use of the built-in SPI ports. Currently it is SPI master + * only. + * @url http://www.espruino.com/Reference#SPI + */ +declare class SPI { + /** + * Try and find an SPI hardware device that will work on this pin (eg. `SPI1`) + * May return undefined if no device can be found. + * + * @param {Pin} pin - A pin to search with + * @returns {any} An object of type `SPI`, or `undefined` if one couldn't be found. + * @url http://www.espruino.com/Reference#l_SPI_find + */ + static find(pin: Pin): any; + + /** + * Create a software SPI port. This has limited functionality (no baud rate), but + * it can work on any pins. + * Use `SPI.setup` to configure this port. + * @constructor + * @returns {any} A SPI object + * @url http://www.espruino.com/Reference#l_SPI_SPI + */ + static new(): any; + + /** + * Set up this SPI port as an SPI Master. + * Options can contain the following (defaults are shown where relevant): + * ``` + * { + * sck:pin, + * miso:pin, + * mosi:pin, + * baud:integer=100000, // ignored on software SPI + * mode:integer=0, // between 0 and 3 + * order:string='msb' // can be 'msb' or 'lsb' + * bits:8 // only available for software SPI + * } + * ``` + * If `sck`,`miso` and `mosi` are left out, they will automatically be chosen. + * However if one or more is specified then the unspecified pins will not be set + * up. + * You can find out which pins to use by looking at [your board's reference + * page](#boards) and searching for pins with the `SPI` marker. Some boards such as + * those based on `nRF52` chips can have SPI on any pins, so don't have specific + * markings. + * The SPI `mode` is between 0 and 3 - see + * http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Clock_polarity_and_phase + * On STM32F1-based parts, you cannot mix AF and non-AF pins (SPI pins are usually + * grouped on the chip - and you can't mix pins from two groups). Espruino will not + * warn you about this. + * + * @param {any} options - An Object containing extra information on initialising the SPI port + * @url http://www.espruino.com/Reference#l_SPI_setup + */ + setup(options: any): void; + + /** + * Send data down SPI, and return the result. Sending an integer will return an + * integer, a String will return a String, and anything else will return a + * Uint8Array. + * Sending multiple bytes in one call to send is preferable as they can then be + * transmitted end to end. Using multiple calls to send() will result in + * significantly slower transmission speeds. + * For maximum speeds, please pass either Strings or Typed Arrays as arguments. + * Note that you can even pass arrays of arrays, like `[1,[2,3,4],5]` + * + * @param {any} data - The data to send - either an Integer, Array, String, or Object of the form `{data: ..., count:#}` + * @param {Pin} nss_pin - An nSS pin - this will be lowered before SPI output and raised afterwards (optional). There will be a small delay between when this is lowered and when sending starts, and also between sending finishing and it being raised. + * @returns {any} The data that was returned + * @url http://www.espruino.com/Reference#l_SPI_send + */ + send(data: any, nss_pin: Pin): any; + + /** + * Write a character or array of characters to SPI - without reading the result + * back. + * For maximum speeds, please pass either Strings or Typed Arrays as arguments. + * + * @param {any} data + * One or more items to write. May be ints, strings, arrays, or special objects (see `E.toUint8Array` for more info). + * If the last argument is a pin, it is taken to be the NSS pin + * @url http://www.espruino.com/Reference#l_SPI_write + */ + write(...data: any[]): void; + + /** + * Send data down SPI, using 4 bits for each 'real' bit (MSB first). This can be + * useful for faking one-wire style protocols + * Sending multiple bytes in one call to send is preferable as they can then be + * transmitted end to end. Using multiple calls to send() will result in + * significantly slower transmission speeds. + * + * @param {any} data - The data to send - either an integer, array, or string + * @param {number} bit0 - The 4 bits to send for a 0 (MSB first) + * @param {number} bit1 - The 4 bits to send for a 1 (MSB first) + * @param {Pin} nss_pin - An nSS pin - this will be lowered before SPI output and raised afterwards (optional). There will be a small delay between when this is lowered and when sending starts, and also between sending finishing and it being raised. + * @url http://www.espruino.com/Reference#l_SPI_send4bit + */ + send4bit(data: any, bit0: number, bit1: number, nss_pin: Pin): void; + + /** + * Send data down SPI, using 8 bits for each 'real' bit (MSB first). This can be + * useful for faking one-wire style protocols + * Sending multiple bytes in one call to send is preferable as they can then be + * transmitted end to end. Using multiple calls to send() will result in + * significantly slower transmission speeds. + * + * @param {any} data - The data to send - either an integer, array, or string + * @param {number} bit0 - The 8 bits to send for a 0 (MSB first) + * @param {number} bit1 - The 8 bits to send for a 1 (MSB first) + * @param {Pin} nss_pin - An nSS pin - this will be lowered before SPI output and raised afterwards (optional). There will be a small delay between when this is lowered and when sending starts, and also between sending finishing and it being raised + * @url http://www.espruino.com/Reference#l_SPI_send8bit + */ + send8bit(data: any, bit0: number, bit1: number, nss_pin: Pin): void; +} + +/** + * This class allows use of the built-in I2C ports. Currently it allows I2C Master + * mode only. + * All addresses are in 7 bit format. If you have an 8 bit address then you need to + * shift it one bit to the right. + * @url http://www.espruino.com/Reference#I2C + */ +declare class I2C { + /** + * Try and find an I2C hardware device that will work on this pin (eg. `I2C1`) + * May return undefined if no device can be found. + * + * @param {Pin} pin - A pin to search with + * @returns {any} An object of type `I2C`, or `undefined` if one couldn't be found. + * @url http://www.espruino.com/Reference#l_I2C_find + */ + static find(pin: Pin): any; + + /** + * Create a software I2C port. This has limited functionality (no baud rate), but + * it can work on any pins. + * Use `I2C.setup` to configure this port. + * @constructor + * @returns {any} An I2C object + * @url http://www.espruino.com/Reference#l_I2C_I2C + */ + static new(): any; + + /** + * Set up this I2C port + * If not specified in options, the default pins are used (usually the lowest + * numbered pins on the lowest port that supports this peripheral) + * + * @param {any} options + * An optional structure containing extra information on initialising the I2C port + * ```{scl:pin, sda:pin, bitrate:100000}``` + * You can find out which pins to use by looking at [your board's reference page](#boards) and searching for pins with the `I2C` marker. Note that 400kHz is the maximum bitrate for most parts. + * @url http://www.espruino.com/Reference#l_I2C_setup + */ + setup(options: any): void; + + /** + * Transmit to the slave device with the given address. This is like Arduino's + * beginTransmission, write, and endTransmission rolled up into one. + * + * @param {any} address - The 7 bit address of the device to transmit to, or an object of the form `{address:12, stop:false}` to send this data without a STOP signal. + * @param {any} data - One or more items to write. May be ints, strings, arrays, or special objects (see `E.toUint8Array` for more info). + * @url http://www.espruino.com/Reference#l_I2C_writeTo + */ + writeTo(address: any, ...data: any[]): void; + + /** + * Request bytes from the given slave device, and return them as a Uint8Array + * (packed array of bytes). This is like using Arduino Wire's requestFrom, + * available and read functions. Sends a STOP + * + * @param {any} address - The 7 bit address of the device to request bytes from, or an object of the form `{address:12, stop:false}` to send this data without a STOP signal. + * @param {number} quantity - The number of bytes to request + * @returns {any} The data that was returned - as a Uint8Array + * @url http://www.espruino.com/Reference#l_I2C_readFrom + */ + readFrom(address: any, quantity: number): Uint8Array; +} + +/** + * This class handles waveforms. In Espruino, a Waveform is a set of data that you + * want to input or output. + * @url http://www.espruino.com/Reference#Waveform + */ +declare class Waveform { + /** + * Create a waveform class. This allows high speed input and output of waveforms. + * It has an internal variable called `buffer` (as well as `buffer2` when + * double-buffered - see `options` below) which contains the data to input/output. + * When double-buffered, a 'buffer' event will be emitted each time a buffer is + * finished with (the argument is that buffer). When the recording stops, a + * 'finish' event will be emitted (with the first argument as the buffer). + * @constructor + * + * @param {number} samples - The number of samples + * @param {any} options - Optional options struct `{doubleBuffer:bool, bits : 8/16}` where: `doubleBuffer` is whether to allocate two buffers or not (default false), and bits is the amount of bits to use (default 8). + * @returns {any} An Waveform object + * @url http://www.espruino.com/Reference#l_Waveform_Waveform + */ + static new(samples: number, options: any): any; + + /** + * Will start outputting the waveform on the given pin - the pin must have + * previously been initialised with analogWrite. If not repeating, it'll emit a + * `finish` event when it is done. + * + * @param {Pin} output - The pin to output on + * @param {number} freq - The frequency to output each sample at + * @param {any} options - Optional options struct `{time:float,repeat:bool}` where: `time` is the that the waveform with start output at, e.g. `getTime()+1` (otherwise it is immediate), `repeat` is a boolean specifying whether to repeat the give sample + * @url http://www.espruino.com/Reference#l_Waveform_startOutput + */ + startOutput(output: Pin, freq: number, options: any): void; + + /** + * Will start inputting the waveform on the given pin that supports analog. If not + * repeating, it'll emit a `finish` event when it is done. + * + * @param {Pin} output - The pin to output on + * @param {number} freq - The frequency to output each sample at + * @param {any} options - Optional options struct `{time:float,repeat:bool}` where: `time` is the that the waveform with start output at, e.g. `getTime()+1` (otherwise it is immediate), `repeat` is a boolean specifying whether to repeat the give sample + * @url http://www.espruino.com/Reference#l_Waveform_startInput + */ + startInput(output: Pin, freq: number, options: any): void; + + /** + * Stop a waveform that is currently outputting + * @url http://www.espruino.com/Reference#l_Waveform_stop + */ + stop(): void; +} + +/** + * This is the built-in class for Pins, such as D0,D1,LED1, or BTN + * You can call the methods on Pin, or you can use Wiring-style functions such as + * digitalWrite + * @url http://www.espruino.com/Reference#Pin + */ +declare class Pin { + /** + * Creates a pin from the given argument (or returns undefined if no argument) + * @constructor + * + * @param {any} value - A value to be converted to a pin. Can be a number, pin, or String. + * @returns {any} A Pin object + * @url http://www.espruino.com/Reference#l_Pin_Pin + */ + static new(value: any): any; + + /** + * Returns the input state of the pin as a boolean. + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset the pin's state to `"input"` + * @returns {boolean} Whether pin is a logical 1 or 0 + * @url http://www.espruino.com/Reference#l_Pin_read + */ + read(): boolean; + + /** + * Sets the output state of the pin to a 1 + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset the pin's state to `"output"` + * @url http://www.espruino.com/Reference#l_Pin_set + */ + set(): void; + + /** + * Sets the output state of the pin to a 0 + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset the pin's state to `"output"` + * @url http://www.espruino.com/Reference#l_Pin_reset + */ + reset(): void; + + /** + * Sets the output state of the pin to the parameter given + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset the pin's state to `"output"` + * + * @param {boolean} value - Whether to set output high (true/1) or low (false/0) + * @url http://www.espruino.com/Reference#l_Pin_write + */ + write(value: boolean): void; + + /** + * Sets the output state of the pin to the parameter given at the specified time. + * **Note:** this **doesn't** change the mode of the pin to an output. To do that, + * you need to use `pin.write(0)` or `pinMode(pin, 'output')` first. + * + * @param {boolean} value - Whether to set output high (true/1) or low (false/0) + * @param {number} time - Time at which to write + * @url http://www.espruino.com/Reference#l_Pin_writeAtTime + */ + writeAtTime(value: boolean, time: number): void; + + /** + * Return the current mode of the given pin. See `pinMode` for more information. + * @returns {any} The pin mode, as a string + * @url http://www.espruino.com/Reference#l_Pin_getMode + */ + getMode(): any; + + /** + * Set the mode of the given pin. See [`pinMode`](#l__global_pinMode) for more + * information on pin modes. + * + * @param {any} mode - The mode - a string that is either 'analog', 'input', 'input_pullup', 'input_pulldown', 'output', 'opendrain', 'af_output' or 'af_opendrain'. Do not include this argument if you want to revert to automatic pin mode setting. + * @url http://www.espruino.com/Reference#l_Pin_mode + */ + mode(mode: any): void; + + /** + * Toggles the state of the pin from off to on, or from on to off. + * **Note:** This method doesn't currently work on the ESP8266 port of Espruino. + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset the pin's state to `"output"` + * @returns {boolean} True if the pin is high after calling the function + * @url http://www.espruino.com/Reference#l_Pin_toggle + */ + toggle(): boolean; + + /** + * Get information about this pin and its capabilities. Of the form: + * ``` + * { + * "port" : "A", // the Pin's port on the chip + * "num" : 12, // the Pin's number + * "in_addr" : 0x..., // (if available) the address of the pin's input address in bit-banded memory (can be used with peek) + * "out_addr" : 0x..., // (if available) the address of the pin's output address in bit-banded memory (can be used with poke) + * "analog" : { ADCs : [1], channel : 12 }, // If analog input is available + * "functions" : { + * "TIM1":{type:"CH1, af:0}, + * "I2C3":{type:"SCL", af:1} + * } + * } + * ``` + * Will return undefined if pin is not valid. + * @returns {any} An object containing information about this pins + * @url http://www.espruino.com/Reference#l_Pin_getInfo + */ + getInfo(): any; +} + +interface DataViewConstructor { + /** + * Create a `DataView` object that can be used to access the data in an + * `ArrayBuffer`. + * ``` + * var b = new ArrayBuffer(8) + * var v = new DataView(b) + * v.setUint16(0,"0x1234") + * v.setUint8(3,"0x56") + * console.log("0x"+v.getUint32(0).toString(16)) + * // prints 0x12340056 + * ``` + * @constructor + * + * @param {any} buffer - The `ArrayBuffer` to base this on + * @param {number} byteOffset - (optional) The offset of this view in bytes + * @param {number} byteLength - (optional) The length in bytes + * @returns {any} A `DataView` object + * @url http://www.espruino.com/Reference#l_DataView_DataView + */ + new(buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): DataView; +} + +interface DataView { + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getFloat32 + */ + getFloat32(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getFloat64 + */ + getFloat64(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getInt8 + */ + getInt8(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getInt16 + */ + getInt16(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getInt32 + */ + getInt32(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getUint8 + */ + getUint8(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getUint16 + */ + getUint16(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_DataView_getUint32 + */ + getUint32(byteOffset: number, littleEndian?: boolean): number; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setFloat32 + */ + setFloat32(byteOffset: number, value: number, littleEndian?: boolean): void; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setFloat64 + */ + setFloat64(byteOffset: number, value: number, littleEndian?: boolean): void; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setInt8 + */ + setInt8(byteOffset: number, value: number, littleEndian?: boolean): void; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setInt16 + */ + setInt16(byteOffset: number, value: number, littleEndian?: boolean): void; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setInt32 + */ + setInt32(byteOffset: number, value: number, littleEndian?: boolean): void; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setUint8 + */ + setUint8(byteOffset: number, value: number, littleEndian?: boolean): void; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setUint16 + */ + setUint16(byteOffset: number, value: number, littleEndian?: boolean): void; + + /** + * + * @param {number} byteOffset - The offset in bytes to read from + * @param {any} value - The value to write + * @param {boolean} littleEndian - (optional) Whether to read in little endian - if false or undefined data is read as big endian + * @url http://www.espruino.com/Reference#l_DataView_setUint32 + */ + setUint32(byteOffset: number, value: number, littleEndian?: boolean): void; +} + +/** + * This class helps + * @url http://www.espruino.com/Reference#DataView + */ +declare const DataView: DataViewConstructor + +/** + * This class allows use of the built-in USARTs + * Methods may be called on the `USB`, `Serial1`, `Serial2`, `Serial3`, `Serial4`, + * `Serial5` and `Serial6` objects. While different processors provide different + * numbers of USARTs, on official Espruino boards you can always rely on at least + * `Serial1` being available + * @url http://www.espruino.com/Reference#Serial + */ +declare class Serial { + /** + * The `data` event is called when data is received. If a handler is defined with + * `X.on('data', function(data) { ... })` then it will be called, otherwise data + * will be stored in an internal buffer, where it can be retrieved with `X.read()` + * @param {string} event - The event to listen to. + * @param {(data: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `data` A string containing one or more characters of received data + * @url http://www.espruino.com/Reference#l_Serial_data + */ + static on(event: "data", callback: (data: any) => void): void; + + /** + * The `framing` event is called when there was activity on the input to the UART + * but the `STOP` bit wasn't in the correct place. This is either because there was + * noise on the line, or the line has been pulled to 0 for a long period of time. + * To enable this, you must initialise Serial with `SerialX.setup(..., { ..., + * errors:true });` + * **Note:** Even though there was an error, the byte will still be received and + * passed to the `data` handler. + * **Note:** This only works on STM32 and NRF52 based devices (eg. all official + * Espruino boards) + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Serial_framing + */ + static on(event: "framing", callback: () => void): void; + + /** + * The `parity` event is called when the UART was configured with a parity bit, and + * this doesn't match the bits that have actually been received. + * To enable this, you must initialise Serial with `SerialX.setup(..., { ..., + * errors:true });` + * **Note:** Even though there was an error, the byte will still be received and + * passed to the `data` handler. + * **Note:** This only works on STM32 and NRF52 based devices (eg. all official + * Espruino boards) + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Serial_parity + */ + static on(event: "parity", callback: () => void): void; + + /** + * Try and find a USART (Serial) hardware device that will work on this pin (eg. + * `Serial1`) + * May return undefined if no device can be found. + * + * @param {Pin} pin - A pin to search with + * @returns {any} An object of type `Serial`, or `undefined` if one couldn't be found. + * @url http://www.espruino.com/Reference#l_Serial_find + */ + static find(pin: Pin): any; + + /** + * Create a software Serial port. This has limited functionality (only low baud + * rates), but it can work on any pins. + * Use `Serial.setup` to configure this port. + * @constructor + * @returns {any} A Serial object + * @url http://www.espruino.com/Reference#l_Serial_Serial + */ + static new(): any; + + /** + * Set this Serial port as the port for the JavaScript console (REPL). + * Unless `force` is set to true, changes in the connection state of the board (for + * instance plugging in USB) will cause the console to change. + * See `E.setConsole` for a more flexible version of this function. + * + * @param {boolean} force - Whether to force the console to this port + * @url http://www.espruino.com/Reference#l_Serial_setConsole + */ + setConsole(force: boolean): void; + + /** + * Setup this Serial port with the given baud rate and options. + * eg. + * ``` + * Serial1.setup(9600,{rx:a_pin, tx:a_pin}); + * ``` + * The second argument can contain: + * ``` + * { + * rx:pin, // Receive pin (data in to Espruino) + * tx:pin, // Transmit pin (data out of Espruino) + * ck:pin, // (default none) Clock Pin + * cts:pin, // (default none) Clear to Send Pin + * bytesize:8, // (default 8)How many data bits - 7 or 8 + * parity:null/'none'/'o'/'odd'/'e'/'even', + * // (default none) Parity bit + * stopbits:1, // (default 1) Number of stop bits to use + * flow:null/undefined/'none'/'xon', // (default none) software flow control + * path:null/undefined/string // Linux Only - the path to the Serial device to use + * errors:false // (default false) whether to forward framing/parity errors + * } + * ``` + * You can find out which pins to use by looking at [your board's reference + * page](#boards) and searching for pins with the `UART`/`USART` markers. + * If not specified in options, the default pins are used for rx and tx (usually + * the lowest numbered pins on the lowest port that supports this peripheral). `ck` + * and `cts` are not used unless specified. + * Note that even after changing the RX and TX pins, if you have called setup + * before then the previous RX and TX pins will still be connected to the Serial + * port as well - until you set them to something else using `digitalWrite` or + * `pinMode`. + * Flow control can be xOn/xOff (`flow:'xon'`) or hardware flow control (receive + * only) if `cts` is specified. If `cts` is set to a pin, the pin's value will be 0 + * when Espruino is ready for data and 1 when it isn't. + * By default, framing or parity errors don't create `framing` or `parity` events + * on the `Serial` object because storing these errors uses up additional storage + * in the queue. If you're intending to receive a lot of malformed data then the + * queue might overflow `E.getErrorFlags()` would return `FIFO_FULL`. However if + * you need to respond to `framing` or `parity` errors then you'll need to use + * `errors:true` when initialising serial. + * On Linux builds there is no default Serial device, so you must specify a path to + * a device - for instance: `Serial1.setup(9600,{path:"/dev/ttyACM0"})` + * You can also set up 'software serial' using code like: + * ``` + * var s = new Serial(); + * s.setup(9600,{rx:a_pin, tx:a_pin}); + * ``` + * However software serial doesn't use `ck`, `cts`, `parity`, `flow` or `errors` + * parts of the initialisation object. + * + * @param {any} baudrate - The baud rate - the default is 9600 + * @param {any} options - An optional structure containing extra information on initialising the serial port - see below. + * @url http://www.espruino.com/Reference#l_Serial_setup + */ + setup(baudrate: any, options: any): void; + + /** + * If the serial (or software serial) device was set up, uninitialise it. + * @url http://www.espruino.com/Reference#l_Serial_unsetup + */ + unsetup(): void; + + /** + * Print a string to the serial port - without a line feed + * **Note:** This function replaces any occurances of `\n` in the string with + * `\r\n`. To avoid this, use `Serial.write`. + * + * @param {any} string - A String to print + * @url http://www.espruino.com/Reference#l_Serial_print + */ + print(string: any): void; + + /** + * Print a line to the serial port with a newline (`\r\n`) at the end of it. + * **Note:** This function converts data to a string first, eg + * `Serial.print([1,2,3])` is equivalent to `Serial.print("1,2,3"). If you'd like + * to write raw bytes, use `Serial.write`. + * + * @param {any} string - A String to print + * @url http://www.espruino.com/Reference#l_Serial_println + */ + println(string: any): void; + + /** + * Write a character or array of data to the serial port + * This method writes unmodified data, eg `Serial.write([1,2,3])` is equivalent to + * `Serial.write("\1\2\3")`. If you'd like data converted to a string first, use + * `Serial.print`. + * + * @param {any} data - One or more items to write. May be ints, strings, arrays, or special objects (see `E.toUint8Array` for more info). + * @url http://www.espruino.com/Reference#l_Serial_write + */ + write(...data: any[]): void; + + /** + * Add data to this device as if it came directly from the input - it will be + * returned via `serial.on('data', ...)`; + * ``` + * Serial1.on('data', function(d) { print("Got",d); }); + * Serial1.inject('Hello World'); + * // prints "Got Hel","Got lo World" (characters can be split over multiple callbacks) + * ``` + * This is most useful if you wish to send characters to Espruino's REPL (console) + * while it is on another device. + * + * @param {any} data - One or more items to write. May be ints, strings, arrays, or special objects (see `E.toUint8Array` for more info). + * @url http://www.espruino.com/Reference#l_Serial_inject + */ + inject(...data: any[]): void; + + /** + * Return how many bytes are available to read. If there is already a listener for + * data, this will always return 0. + * @returns {number} How many bytes are available + * @url http://www.espruino.com/Reference#l_Serial_available + */ + available(): number; + + /** + * Return a string containing characters that have been received + * + * @param {number} chars - The number of characters to read, or undefined/0 for all available + * @returns {any} A string containing the required bytes. + * @url http://www.espruino.com/Reference#l_Serial_read + */ + read(chars: number): any; + + /** + * Pipe this USART to a stream (an object with a 'write' method) + * + * @param {any} destination - The destination file/stream that will receive content from the source. + * @param {any} options + * An optional object `{ chunkSize : int=32, end : bool=true, complete : function }` + * chunkSize : The amount of data to pipe from source to destination at a time + * complete : a function to call when the pipe activity is complete + * end : call the 'end' function on the destination when the source is finished + * @url http://www.espruino.com/Reference#l_Serial_pipe + */ + pipe(destination: any, options: any): void; +} + +/** + * These objects are created from `require("Storage").open` and allow Storage items + * to be read/written. + * The `Storage` library writes into Flash memory (which can only be erased in + * chunks), and unlike a normal filesystem it allocates files in one long + * contiguous area to allow them to be accessed easily from Espruino. + * This presents a challenge for `StorageFile` which allows you to append to a + * file, so instead `StorageFile` stores files in chunks. It uses the last + * character of the filename to denote the chunk number (eg `"foobar\1"`, + * `"foobar\2"`, etc). + * This means that while `StorageFile` files exist in the same area as those from + * `Storage`, they should be read using `Storage.open` (and not `Storage.read`). + * ``` + * f = s.open("foobar","w"); + * f.write("Hell"); + * f.write("o World\n"); + * f.write("Hello\n"); + * f.write("World 2\n"); + * // there's no need to call 'close' + * // then + * f = s.open("foobar","r"); + * f.read(13) // "Hello World\nH" + * f.read(13) // "ello\nWorld 2\n" + * f.read(13) // "Hello World 3" + * f.read(13) // "\n" + * f.read(13) // undefined + * // or + * f = s.open("foobar","r"); + * f.readLine() // "Hello World\n" + * f.readLine() // "Hello\n" + * f.readLine() // "World 2\n" + * f.readLine() // "Hello World 3\n" + * f.readLine() // undefined + * // now get rid of file + * f.erase(); + * ``` + * **Note:** `StorageFile` uses the fact that all bits of erased flash memory are 1 + * to detect the end of a file. As such you should not write character code 255 + * (`"\xFF"`) to these files. + * @url http://www.espruino.com/Reference#StorageFile + */ +declare class StorageFile { + + + /** + * Read 'len' bytes of data from the file, and return a String containing those + * bytes. + * If the end of the file is reached, the String may be smaller than the amount of + * bytes requested, or if the file is already at the end, `undefined` is returned. + * + * @param {number} len - How many bytes to read + * @returns {any} A String, or undefined + * @url http://www.espruino.com/Reference#l_StorageFile_read + */ + read(len: number): string; + + /** + * Read a line of data from the file (up to and including `"\n"`) + * @returns {any} A line of data + * @url http://www.espruino.com/Reference#l_StorageFile_readLine + */ + readLine(): string; + + /** + * Return the length of the current file. + * This requires Espruino to read the file from scratch, which is not a fast + * operation. + * @returns {number} The current length in bytes of the file + * @url http://www.espruino.com/Reference#l_StorageFile_getLength + */ + getLength(): number; + + /** + * Append the given data to a file. You should not attempt to append `"\xFF"` + * (character code 255). + * + * @param {any} data - The data to write. This should not include `'\xFF'` (character code 255) + * @url http://www.espruino.com/Reference#l_StorageFile_write + */ + write(data: string): void; + + /** + * Erase this file + * @url http://www.espruino.com/Reference#l_StorageFile_erase + */ + erase(): void; +} + +interface processConstructor { + /** + * This event is called when an exception gets thrown and isn't caught (eg. it gets + * all the way back to the event loop). + * You can use this for logging potential problems that might occur during + * execution when you might not be able to see what is written to the console, for + * example: + * ``` + * var lastError; + * process.on('uncaughtException', function(e) { + * lastError=e; + * print(e,e.stack?"\n"+e.stack:"") + * }); + * function checkError() { + * if (!lastError) return print("No Error"); + * print(lastError,lastError.stack?"\n"+lastError.stack:"") + * } + * ``` + * **Note:** When this is used, exceptions will cease to be reported on the + * console - which may make debugging difficult! + * @param {string} event - The event to listen to. + * @param {(exception: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `exception` The uncaught exception + * @url http://www.espruino.com/Reference#l_process_uncaughtException + */ + on(event: "uncaughtException", callback: (exception: any) => void): void; + + /** + * Returns the version of Espruino as a String + * @returns {any} The version of Espruino + * @url http://www.espruino.com/Reference#l_process_version + */ + version: any; + + /** + * Returns an Object containing various pre-defined variables. + * * `VERSION` - is the Espruino version + * * `GIT_COMMIT` - is Git commit hash this firmware was built from + * * `BOARD` - the board's ID (eg. `PUCKJS`) + * * `RAM` - total amount of on-chip RAM in bytes + * * `FLASH` - total amount of on-chip flash memory in bytes + * * `SPIFLASH` - (on Bangle.js) total amount of off-chip flash memory in bytes + * * `HWVERSION` - For Puck.js this is the board revision (1, 2, 2.1), or for + * Bangle.js it's 1 or 2 + * * `STORAGE` - memory in bytes dedicated to the `Storage` module + * * `SERIAL` - the serial number of this chip + * * `CONSOLE` - the name of the current console device being used (`Serial1`, + * `USB`, `Bluetooth`, etc) + * * `MODULES` - a list of built-in modules separated by commas + * * `EXPTR` - The address of the `exportPtrs` structure in flash (this includes + * links to built-in functions that compiled JS code needs) + * * `APP_RAM_BASE` - On nRF5x boards, this is the RAM required by the Softdevice + * *if it doesn't exactly match what was allocated*. You can use this to update + * `LD_APP_RAM_BASE` in the `BOARD.py` file + * For example, to get a list of built-in modules, you can use + * `process.env.MODULES.split(',')` + * @returns {any} An object + * @url http://www.espruino.com/Reference#l_process_env + */ + env: any; + + /** + * Run a Garbage Collection pass, and return an object containing information on + * memory usage. + * * `free` : Memory that is available to be used (in blocks) + * * `usage` : Memory that has been used (in blocks) + * * `total` : Total memory (in blocks) + * * `history` : Memory used for command history - that is freed if memory is low. + * Note that this is INCLUDED in the figure for 'free' + * * `gc` : Memory freed during the GC pass + * * `gctime` : Time taken for GC pass (in milliseconds) + * * `blocksize` : Size of a block (variable) in bytes + * * `stackEndAddress` : (on ARM) the address (that can be used with peek/poke/etc) + * of the END of the stack. The stack grows down, so unless you do a lot of + * recursion the bytes above this can be used. + * * `flash_start` : (on ARM) the address of the start of flash memory (usually + * `0x8000000`) + * * `flash_binary_end` : (on ARM) the address in flash memory of the end of + * Espruino's firmware. + * * `flash_code_start` : (on ARM) the address in flash memory of pages that store + * any code that you save with `save()`. + * * `flash_length` : (on ARM) the amount of flash memory this firmware was built + * for (in bytes). **Note:** Some STM32 chips actually have more memory than is + * advertised. + * Memory units are specified in 'blocks', which are around 16 bytes each + * (depending on your device). The actual size is available in `blocksize`. See + * http://www.espruino.com/Performance for more information. + * **Note:** To find free areas of flash memory, see `require('Flash').getFree()` + * + * @param {any} gc - An optional boolean. If `undefined` or `true` Garbage collection is performed, if `false` it is not + * @returns {any} Information about memory usage + * @url http://www.espruino.com/Reference#l_process_memory + */ + memory(gc: any): any; +} + +interface process { + +} + +/** + * This class contains information about Espruino itself + * @url http://www.espruino.com/Reference#process + */ +declare const process: processConstructor + +/** + * Built-in class that caches the modules used by the `require` command + * @url http://www.espruino.com/Reference#Modules + */ +declare class Modules { + /** + * Return an array of module names that have been cached + * @returns {any} An array of module names + * @url http://www.espruino.com/Reference#l_Modules_getCached + */ + static getCached(): any; + + /** + * Remove the given module from the list of cached modules + * + * @param {any} id - The module name to remove + * @url http://www.espruino.com/Reference#l_Modules_removeCached + */ + static removeCached(id: any): void; + + /** + * Remove all cached modules + * @url http://www.espruino.com/Reference#l_Modules_removeAllCached + */ + static removeAllCached(): void; + + /** + * Add the given module to the cache + * + * @param {any} id - The module name to add + * @param {any} sourcecode - The module's sourcecode + * @url http://www.espruino.com/Reference#l_Modules_addCached + */ + static addCached(id: any, sourcecode: any): void; + + +} + +interface StringConstructor { + /** + * Return the character(s) represented by the given character code(s). + * + * @param {any} code - One or more character codes to create a string from (range 0-255). + * @returns {any} The character + * @url http://www.espruino.com/Reference#l_String_fromCharCode + */ + fromCharCode(...code: any[]): any; + + /** + * Create a new String + * @constructor + * + * @param {any} str - A value to turn into a string. If undefined or not supplied, an empty String is created. + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_String_String + */ + new(...str: any[]): any; +} + +interface String { + /** + * Find the length of the string + * @returns {any} The value of the string + * @url http://www.espruino.com/Reference#l_String_length + */ + length: any; + + /** + * Return a single character at the given position in the String. + * + * @param {number} pos - The character number in the string. Negative values return characters from end of string (-1 = last char) + * @returns {any} The character in the string + * @url http://www.espruino.com/Reference#l_String_charAt + */ + charAt(pos: number): any; + + /** + * Return the integer value of a single character at the given position in the + * String. + * Note that this returns 0 not 'NaN' for out of bounds characters + * + * @param {number} pos - The character number in the string. Negative values return characters from end of string (-1 = last char) + * @returns {number} The integer value of a character in the string + * @url http://www.espruino.com/Reference#l_String_charCodeAt + */ + charCodeAt(pos: number): number; + + /** + * Return the index of substring in this string, or -1 if not found + * + * @param {any} substring - The string to search for + * @param {any} fromIndex - Index to search from + * @returns {number} The index of the string, or -1 if not found + * @url http://www.espruino.com/Reference#l_String_indexOf + */ + indexOf(substring: any, fromIndex: any): number; + + /** + * Return the last index of substring in this string, or -1 if not found + * + * @param {any} substring - The string to search for + * @param {any} fromIndex - Index to search from + * @returns {number} The index of the string, or -1 if not found + * @url http://www.espruino.com/Reference#l_String_lastIndexOf + */ + lastIndexOf(substring: any, fromIndex: any): number; + + /** + * Matches an occurrence `subStr` in the string. + * Returns `null` if no match, or: + * ``` + * "abcdef".match("b") == [ + * "b", // array index 0 - the matched string + * index: 1, // the start index of the match + * input: "b" // the input string + * ] + * "abcdefabcdef".match(/bcd/) == [ + * "bcd", index: 1, + * input: "abcdefabcdef" + * ] + * ``` + * 'Global' RegEx matches just return an array of matches (with no indices): + * ``` + * "abcdefabcdef".match(/bcd/g) = [ + * "bcd", + * "bcd" + * ] + * ``` + * + * @param {any} substr - Substring or RegExp to match + * @returns {any} A match array or `null` (see below): + * @url http://www.espruino.com/Reference#l_String_match + */ + match(substr: any): any; + + /** + * Search and replace ONE occurrance of `subStr` with `newSubStr` and return the + * result. This doesn't alter the original string. Regular expressions not + * supported. + * + * @param {any} subStr - The string to search for + * @param {any} newSubStr - The string to replace it with + * @returns {any} This string with `subStr` replaced + * @url http://www.espruino.com/Reference#l_String_replace + */ + replace(subStr: any, newSubStr: any): any; + + /** + * + * @param {number} start - The start character index (inclusive) + * @param {any} end - The end character index (exclusive) + * @returns {any} The part of this string between start and end + * @url http://www.espruino.com/Reference#l_String_substring + */ + substring(start: number, end: any): any; + + /** + * + * @param {number} start - The start character index + * @param {any} len - The number of characters + * @returns {any} Part of this string from start for len characters + * @url http://www.espruino.com/Reference#l_String_substr + */ + substr(start: number, len: any): any; + + /** + * + * @param {number} start - The start character index, if negative it is from the end of the string + * @param {any} end - The end character index, if negative it is from the end of the string, and if omitted it is the end of the string + * @returns {any} Part of this string from start for len characters + * @url http://www.espruino.com/Reference#l_String_slice + */ + slice(start: number, end: any): any; + + /** + * Return an array made by splitting this string up by the separator. eg. + * ```'1,2,3'.split(',')==['1', '2', '3']``` + * Regular Expressions can also be used to split strings, eg. `'1a2b3 + * 4'.split(/[^0-9]/)==['1', '2', '3', '4']`. + * + * @param {any} separator - The separator `String` or `RegExp` to use + * @returns {any} Part of this string from start for len characters + * @url http://www.espruino.com/Reference#l_String_split + */ + split(separator: any): any; + + /** + * + * @returns {any} The lowercase version of this string + * @url http://www.espruino.com/Reference#l_String_toLowerCase + */ + toLowerCase(): any; + + /** + * + * @returns {any} The uppercase version of this string + * @url http://www.espruino.com/Reference#l_String_toUpperCase + */ + toUpperCase(): any; + + /** + * Return a new string with any whitespace (tabs, space, form feed, newline, + * carriage return, etc) removed from the beginning and end. + * @returns {any} A String with Whitespace removed from the beginning and end + * @url http://www.espruino.com/Reference#l_String_trim + */ + trim(): string; + + /** + * Append all arguments to this `String` and return the result. Does not modify the + * original `String`. + * + * @param {any} args - Strings to append + * @returns {any} The result of appending all arguments to this string + * @url http://www.espruino.com/Reference#l_String_concat + */ + concat(...args: any[]): any; + + /** + * + * @param {any} searchString - The string to search for + * @param {number} position - The start character index (or 0 if not defined) + * @returns {boolean} `true` if the given characters are found at the beginning of the string, otherwise, `false`. + * @url http://www.espruino.com/Reference#l_String_startsWith + */ + startsWith(searchString: any, position: number): boolean; + + /** + * + * @param {any} searchString - The string to search for + * @param {any} length - The 'end' of the string - if left off the actual length of the string is used + * @returns {boolean} `true` if the given characters are found at the end of the string, otherwise, `false`. + * @url http://www.espruino.com/Reference#l_String_endsWith + */ + endsWith(searchString: any, length: any): boolean; + + /** + * + * @param {any} substring - The string to search for + * @param {any} fromIndex - The start character index (or 0 if not defined) + * @returns {boolean} `true` if the given characters are in the string, otherwise, `false`. + * @url http://www.espruino.com/Reference#l_String_includes + */ + includes(substring: any, fromIndex: any): boolean; + + /** + * Repeat this string the given number of times. + * + * @param {number} count - An integer with the amount of times to repeat this String + * @returns {any} A string containing repetitions of this string + * @url http://www.espruino.com/Reference#l_String_repeat + */ + repeat(count: number): string; + + /** + * Pad this string at the beginnind to the required number of characters + * ``` + * "Hello".padStart(10) == " Hello" + * "123".padStart(10,".-") == ".-.-.-.123" + * ``` + * + * @param {number} targetLength - The length to pad this string to + * @param {any} [padString] - [optional] The string to pad with, default is `' '` + * @returns {any} A string containing this string padded to the correct length + * @url http://www.espruino.com/Reference#l_String_padStart + */ + padStart(targetLength: number, padString?: any): string; + + /** + * Pad this string at the end to the required number of characters + * ``` + * "Hello".padEnd(10) == "Hello " + * "123".padEnd(10,".-") == "123.-.-.-." + * ``` + * + * @param {number} targetLength - The length to pad this string to + * @param {any} [padString] - [optional] The string to pad with, default is `' '` + * @returns {any} A string containing this string padded to the correct length + * @url http://www.espruino.com/Reference#l_String_padEnd + */ + padEnd(targetLength: number, padString?: any): string; +} + +/** + * This is the built-in class for Text Strings. + * Text Strings in Espruino are not zero-terminated, so you can store zeros in + * them. + * @url http://www.espruino.com/Reference#String + */ +declare const String: StringConstructor + +interface ArrayConstructor { + /** + * Returns true if the provided object is an array + * + * @param {any} var - The variable to be tested + * @returns {boolean} True if var is an array, false if not. + * @url http://www.espruino.com/Reference#l_Array_isArray + */ + isArray(arg: any): arg is any[]; + + /** + * Create an Array. Either give it one integer argument (>=0) which is the length + * of the array, or any number of arguments + * @constructor + * + * @param {any} args - The length of the array OR any number of items to add to the array + * @returns {any} An Array + * @url http://www.espruino.com/Reference#l_Array_Array + */ + new(arrayLength?: number): any[]; + new(arrayLength: number): T[]; + new(...items: T[]): T[]; + (arrayLength?: number): any[]; + (arrayLength: number): T[]; + (...items: T[]): T[]; +} + +interface Array { + /** + * Convert the Array to a string + * + * @param {any} radix - unused + * @returns {any} A String representing the array + * @url http://www.espruino.com/Reference#l_Array_toString + */ + toString(): string; + + /** + * Find the length of the array + * @returns {any} The length of the array + * @url http://www.espruino.com/Reference#l_Array_length + */ + length: number; + + /** + * Return the index of the value in the array, or -1 + * + * @param {any} value - The value to check for + * @param {number} startIndex - (optional) the index to search from, or 0 if not specified + * @returns {any} the index of the value in the array, or -1 + * @url http://www.espruino.com/Reference#l_Array_indexOf + */ + indexOf(value: T, startIndex?: number): number; + + /** + * Return `true` if the array includes the value, `false` otherwise + * + * @param {any} value - The value to check for + * @param {number} startIndex - (optional) the index to search from, or 0 if not specified + * @returns {boolean} `true` if the array includes the value, `false` otherwise + * @url http://www.espruino.com/Reference#l_Array_includes + */ + includes(value: T, startIndex?: number): boolean; + + /** + * Join all elements of this array together into one string, using 'separator' + * between them. e.g. ```[1,2,3].join(' ')=='1 2 3'``` + * + * @param {any} separator - The separator + * @returns {any} A String representing the Joined array + * @url http://www.espruino.com/Reference#l_Array_join + */ + join(separator?: string): string; + + /** + * Push a new value onto the end of this array' + * This is the opposite of `[1,2,3].unshift(0)`, which adds one or more elements to + * the beginning of the array. + * + * @param {any} arguments - One or more arguments to add + * @returns {number} The new size of the array + * @url http://www.espruino.com/Reference#l_Array_push + */ + push(...arguments: T[]): number; + + /** + * Remove and return the value on the end of this array. + * This is the opposite of `[1,2,3].shift()`, which removes an element from the + * beginning of the array. + * @returns {any} The value that is popped off + * @url http://www.espruino.com/Reference#l_Array_pop + */ + pop(): T | undefined; + + /** + * Return an array which is made from the following: ```A.map(function) = + * [function(A[0]), function(A[1]), ...]``` + * + * @param {any} function - Function used to map one item to another + * @param {any} thisArg - if specified, the function is called with 'this' set to thisArg (optional) + * @returns {any} An array containing the results + * @url http://www.espruino.com/Reference#l_Array_map + */ + map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; + + /** + * Executes a provided function once per array element. + * + * @param {any} function - Function to be executed + * @param {any} [thisArg] - [optional] If specified, the function is called with 'this' set to thisArg (optional) + * @url http://www.espruino.com/Reference#l_Array_forEach + */ + forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; + + /** + * Return an array which contains only those elements for which the callback + * function returns 'true' + * + * @param {any} function - Function to be executed + * @param {any} thisArg - if specified, the function is called with 'this' set to thisArg (optional) + * @returns {any} An array containing the results + * @url http://www.espruino.com/Reference#l_Array_filter + */ + filter(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; + filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[]; + + /** + * Return the array element where `function` returns `true`, or `undefined` if it + * doesn't returns `true` for any element. + * ``` + * ["Hello","There","World"].find(a=>a[0]=="T") + * // returns "There" + * ``` + * + * @param {any} function - Function to be executed + * @returns {any} The array element where `function` returns `true`, or `undefined` + * @url http://www.espruino.com/Reference#l_Array_find + */ + find(predicate: (this: void, value: T, index: number, obj: T[]) => value is S): S | undefined; + find(predicate: (value: T, index: number, obj: T[]) => unknown): T | undefined; + + /** + * Return the array element's index where `function` returns `true`, or `-1` if it + * doesn't returns `true` for any element. + * ``` + * ["Hello","There","World"].findIndex(a=>a[0]=="T") + * // returns 1 + * ``` + * + * @param {any} function - Function to be executed + * @returns {any} The array element's index where `function` returns `true`, or `-1` + * @url http://www.espruino.com/Reference#l_Array_findIndex + */ + findIndex(predicate: (value: T, index: number, obj: T[]) => unknown): number; + + /** + * Return 'true' if the callback returns 'true' for any of the elements in the + * array + * + * @param {any} function - Function to be executed + * @param {any} thisArg - if specified, the function is called with 'this' set to thisArg (optional) + * @returns {any} A boolean containing the result + * @url http://www.espruino.com/Reference#l_Array_some + */ + some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean; + + /** + * Return 'true' if the callback returns 'true' for every element in the array + * + * @param {any} function - Function to be executed + * @param {any} thisArg - if specified, the function is called with 'this' set to thisArg (optional) + * @returns {any} A boolean containing the result + * @url http://www.espruino.com/Reference#l_Array_every + */ + every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean; + + /** + * Execute `previousValue=initialValue` and then `previousValue = + * callback(previousValue, currentValue, index, array)` for each element in the + * array, and finally return previousValue. + * + * @param {any} callback - Function used to reduce the array + * @param {any} initialValue - if specified, the initial value to pass to the function + * @returns {any} The value returned by the last function called + * @url http://www.espruino.com/Reference#l_Array_reduce + */ + reduce(callback: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; + + /** + * Both remove and add items to an array + * + * @param {number} index - Index at which to start changing the array. If negative, will begin that many elements from the end + * @param {any} howMany - An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed. + * @param {any} elements - One or more items to add to the array + * @returns {any} An array containing the removed elements. If only one element is removed, an array of one element is returned. + * @url http://www.espruino.com/Reference#l_Array_splice + */ + splice(index: number, howMany?: number, ...elements: T[]): T[]; + + /** + * Remove and return the first element of the array. + * This is the opposite of `[1,2,3].pop()`, which takes an element off the end. + * + * @returns {any} The element that was removed + * @url http://www.espruino.com/Reference#l_Array_shift + */ + shift(): T | undefined; + + /** + * Add one or more items to the start of the array, and return its new length. + * This is the opposite of `[1,2,3].push(4)`, which puts one or more elements on + * the end. + * + * @param {any} elements - One or more items to add to the beginning of the array + * @returns {number} The new array length + * @url http://www.espruino.com/Reference#l_Array_unshift + */ + unshift(...elements: T[]): number; + + /** + * Return a copy of a portion of this array (in a new array) + * + * @param {number} start - Start index + * @param {any} end - End index (optional) + * @returns {any} A new array + * @url http://www.espruino.com/Reference#l_Array_slice + */ + slice(start?: number, end?: number): T[]; + + /** + * Do an in-place quicksort of the array + * + * @param {any} var - A function to use to compare array elements (or undefined) + * @returns {any} This array object + * @url http://www.espruino.com/Reference#l_Array_sort + */ + sort(compareFn?: (a: T, b: T) => number): T[]; + + /** + * Create a new array, containing the elements from this one and any arguments, if + * any argument is an array then those elements will be added. + * + * @param {any} args - Any items to add to the array + * @returns {any} An Array + * @url http://www.espruino.com/Reference#l_Array_concat + */ + concat(...args: (T | T[])[]): T[]; + + /** + * Fill this array with the given value, for every index `>= start` and `< end` + * + * @param {any} value - The value to fill the array with + * @param {number} start - Optional. The index to start from (or 0). If start is negative, it is treated as length+start where length is the length of the array + * @param {any} end - Optional. The index to end at (or the array length). If end is negative, it is treated as length+end. + * @returns {any} This array + * @url http://www.espruino.com/Reference#l_Array_fill + */ + fill(value: T, start: number, end?: number): T[]; + + /** + * Reverse all elements in this array (in place) + * @returns {any} The array, but reversed. + * @url http://www.espruino.com/Reference#l_Array_reverse + */ + reverse(): T[]; + + [index: number]: T +} + +/** + * This is the built-in JavaScript class for arrays. + * Arrays can be defined with ```[]```, ```new Array()```, or ```new + * Array(length)``` + * @url http://www.espruino.com/Reference#Array + */ +declare const Array: ArrayConstructor + +interface ObjectConstructor { + /** + * Return all enumerable keys of the given object + * + * @param {any} object - The object to return keys for + * @returns {any} An array of strings - one for each key on the given object + * @url http://www.espruino.com/Reference#l_Object_keys + */ + keys(object: any): any; + + /** + * Returns an array of all properties (enumerable or not) found directly on a given + * object. + * + * @param {any} object - The Object to return a list of property names for + * @returns {any} An array of the Object's own properties + * @url http://www.espruino.com/Reference#l_Object_getOwnPropertyNames + */ + getOwnPropertyNames(object: any): any; + + /** + * Return all enumerable values of the given object + * + * @param {any} object - The object to return values for + * @returns {any} An array of values - one for each key on the given object + * @url http://www.espruino.com/Reference#l_Object_values + */ + values(object: any): any; + + /** + * Return all enumerable keys and values of the given object + * + * @param {any} object - The object to return values for + * @returns {any} An array of `[key,value]` pairs - one for each key on the given object + * @url http://www.espruino.com/Reference#l_Object_entries + */ + entries(object: any): any; + + /** + * Creates a new object with the specified prototype object and properties. + * properties are currently unsupported. + * + * @param {any} proto - A prototype object + * @param {any} propertiesObject - An object containing properties. NOT IMPLEMENTED + * @returns {any} A new object + * @url http://www.espruino.com/Reference#l_Object_create + */ + create(proto: any, propertiesObject: any): any; + + /** + * Get information on the given property in the object, or undefined + * + * @param {any} obj - The object + * @param {any} name - The name of the property + * @returns {any} An object with a description of the property. The values of writable/enumerable/configurable may not be entirely correct due to Espruino's implementation. + * @url http://www.espruino.com/Reference#l_Object_getOwnPropertyDescriptor + */ + getOwnPropertyDescriptor(obj: any, name: any): any; + + /** + * Add a new property to the Object. 'Desc' is an object with the following fields: + * * `configurable` (bool = false) - can this property be changed/deleted (not + * implemented) + * * `enumerable` (bool = false) - can this property be enumerated (not + * implemented) + * * `value` (anything) - the value of this property + * * `writable` (bool = false) - can the value be changed with the assignment + * operator? + * * `get` (function) - the getter function, or undefined if no getter (only + * supported on some platforms) + * * `set` (function) - the setter function, or undefined if no setter (only + * supported on some platforms) + * **Note:** `configurable`, `enumerable` and `writable` are not implemented and + * will be ignored. + * + * @param {any} obj - An object + * @param {any} name - The name of the property + * @param {any} desc - The property descriptor + * @returns {any} The object, obj. + * @url http://www.espruino.com/Reference#l_Object_defineProperty + */ + defineProperty(obj: any, name: any, desc: any): any; + + /** + * Adds new properties to the Object. See `Object.defineProperty` for more + * information + * + * @param {any} obj - An object + * @param {any} props - An object whose fields represent property names, and whose values are property descriptors. + * @returns {any} The object, obj. + * @url http://www.espruino.com/Reference#l_Object_defineProperties + */ + defineProperties(obj: any, props: any): any; + + /** + * Get the prototype of the given object - this is like writing `object.__proto__` + * but is the 'proper' ES6 way of doing it + * + * @param {any} object - An object + * @returns {any} The prototype + * @url http://www.espruino.com/Reference#l_Object_getPrototypeOf + */ + getPrototypeOf(object: any): any; + + /** + * Set the prototype of the given object - this is like writing `object.__proto__ = + * prototype` but is the 'proper' ES6 way of doing it + * + * @param {any} object - An object + * @param {any} prototype - The prototype to set on the object + * @returns {any} The object passed in + * @url http://www.espruino.com/Reference#l_Object_setPrototypeOf + */ + setPrototypeOf(object: any, prototype: any): any; + + /** + * Appends all keys and values in any subsequent objects to the first object + * **Note:** Unlike the standard ES6 `Object.assign`, this will throw an exception + * if given raw strings, bools or numbers rather than objects. + * + * @param {any} args - The target object, then any items objects to use as sources of keys + * @returns {any} The target object + * @url http://www.espruino.com/Reference#l_Object_assign + */ + assign(...args: any[]): any; + + /** + * Creates an Object from the supplied argument + * @constructor + * + * @param {any} value - A single value to be converted to an object + * @returns {any} An Object + * @url http://www.espruino.com/Reference#l_Object_Object + */ + new(value: any): any; +} + +interface Object { + /** + * Find the length of the object + * @returns {any} The length of the object + * @url http://www.espruino.com/Reference#l_Object_length + */ + length: any; + + /** + * Returns the primitive value of this object. + * @returns {any} The primitive value of this object + * @url http://www.espruino.com/Reference#l_Object_valueOf + */ + valueOf(): any; + + /** + * Convert the Object to a string + * + * @param {any} radix - If the object is an integer, the radix (between 2 and 36) to use. NOTE: Setting a radix does not work on floating point numbers. + * @returns {any} A String representing the object + * @url http://www.espruino.com/Reference#l_Object_toString + */ + toString(radix: any): any; + + /** + * Copy this object completely + * @returns {any} A copy of this Object + * @url http://www.espruino.com/Reference#l_Object_clone + */ + clone(): any; + + /** + * Return true if the object (not its prototype) has the given property. + * NOTE: This currently returns false-positives for built-in functions in + * prototypes + * + * @param {any} name - The name of the property to search for + * @returns {boolean} True if it exists, false if it doesn't + * @url http://www.espruino.com/Reference#l_Object_hasOwnProperty + */ + hasOwnProperty(name: any): boolean; + + /** + * Register an event listener for this object, for instance `Serial1.on('data', + * function(d) {...})`. + * This is the same as Node.js's [EventEmitter](https://nodejs.org/api/events.html) + * but on Espruino the functionality is built into every object: + * * `Object.on` + * * `Object.emit` + * * `Object.removeListener` + * * `Object.removeAllListeners` + * ``` + * var o = {}; // o can be any object... + * // call an arrow function when the 'answer' event is received + * o.on('answer', x => console.log(x)); + * // call a named function when the 'answer' event is received + * function printAnswer(d) { + * console.log("The answer is", d); + * } + * o.on('answer', printAnswer); + * // emit the 'answer' event - functions added with 'on' will be executed + * o.emit('answer', 42); + * // prints: 42 + * // prints: The answer is 42 + * // If you have a named function, it can be removed by name + * o.removeListener('answer', printAnswer); + * // Now 'printAnswer' is removed + * o.emit('answer', 43); + * // prints: 43 + * // Or you can remove all listeners for 'answer' + * o.removeAllListeners('answer') + * // Now nothing happens + * o.emit('answer', 44); + * // nothing printed + * ``` + * + * @param {any} event - The name of the event, for instance 'data' + * @param {any} listener - The listener to call when this event is received + * @url http://www.espruino.com/Reference#l_Object_on + */ + on(event: any, listener: any): void; + + /** + * Call any event listeners that were added to this object with `Object.on`, for + * instance `obj.emit('data', 'Foo')`. + * For more information see `Object.on` + * + * @param {any} event - The name of the event, for instance 'data' + * @param {any} args - Optional arguments + * @url http://www.espruino.com/Reference#l_Object_emit + */ + emit(event: any, ...args: any[]): void; + + /** + * Removes the specified event listener. + * ``` + * function foo(d) { + * console.log(d); + * } + * Serial1.on("data", foo); + * Serial1.removeListener("data", foo); + * ``` + * For more information see `Object.on` + * + * @param {any} event - The name of the event, for instance 'data' + * @param {any} listener - The listener to remove + * @url http://www.espruino.com/Reference#l_Object_removeListener + */ + removeListener(event: any, listener: any): void; + + /** + * Removes all listeners (if `event===undefined`), or those of the specified event. + * ``` + * Serial1.on("data", function(data) { ... }); + * Serial1.removeAllListeners("data"); + * // or + * Serial1.removeAllListeners(); // removes all listeners for all event types + * ``` + * For more information see `Object.on` + * + * @param {any} event - The name of the event, for instance `'data'`. If not specified *all* listeners are removed. + * @url http://www.espruino.com/Reference#l_Object_removeAllListeners + */ + removeAllListeners(event: any): void; +} + +/** + * This is the built-in class for Objects + * @url http://www.espruino.com/Reference#Object + */ +declare const Object: ObjectConstructor + +interface FunctionConstructor { + /** + * Creates a function + * @constructor + * + * @param {any} args - Zero or more arguments (as strings), followed by a string representing the code to run + * @returns {any} A Number object + * @url http://www.espruino.com/Reference#l_Function_Function + */ + new(...args: any[]): any; +} + +interface Function { + /** + * This replaces the function with the one in the argument - while keeping the old + * function's scope. This allows inner functions to be edited, and is used when + * edit() is called on an inner function. + * + * @param {any} newFunc - The new function to replace this function with + * @url http://www.espruino.com/Reference#l_Function_replaceWith + */ + replaceWith(newFunc: any): void; + + /** + * This executes the function with the supplied 'this' argument and parameters + * + * @param {any} this - The value to use as the 'this' argument when executing the function + * @param {any} params - Optional Parameters + * @returns {any} The return value of executing this function + * @url http://www.espruino.com/Reference#l_Function_call + */ + call(this: any, ...params: any[]): any; + + /** + * This executes the function with the supplied 'this' argument and parameters + * + * @param {any} this - The value to use as the 'this' argument when executing the function + * @param {any} args - Optional Array of Arguments + * @returns {any} The return value of executing this function + * @url http://www.espruino.com/Reference#l_Function_apply + */ + apply(this: any, args: any): any; + + /** + * This executes the function with the supplied 'this' argument and parameters + * + * @param {any} this - The value to use as the 'this' argument when executing the function + * @param {any} params - Optional Default parameters that are prepended to the call + * @returns {any} The 'bound' function + * @url http://www.espruino.com/Reference#l_Function_bind + */ + bind(this: any, ...params: any[]): any; +} + +/** + * This is the built-in class for Functions + * @url http://www.espruino.com/Reference#Function + */ +declare const Function: FunctionConstructor + +/** + * This is the built-in JavaScript class for Espruino utility functions. + * @url http://www.espruino.com/Reference#E + */ +declare class E { + /** + * Setup the filesystem so that subsequent calls to `E.openFile` and + * `require('fs').*` will use an SD card on the supplied SPI device and pin. + * It can even work using software SPI - for instance: + * ``` + * // DI/CMD = C7 + * // DO/DAT0 = C8 + * // CK/CLK = C9 + * // CD/CS/DAT3 = C6 + * var spi = new SPI(); + * spi.setup({mosi:C7, miso:C8, sck:C9}); + * E.connectSDCard(spi, C6); + * console.log(require("fs").readdirSync()); + * ``` + * See [the page on File IO](http://www.espruino.com/File+IO) for more information. + * **Note:** We'd strongly suggest you add a pullup resistor from CD/CS pin to + * 3.3v. It is good practise to avoid accidental writes before Espruino is + * initialised, and some cards will not work reliably without one. + * **Note:** If you want to remove an SD card after you have started using it, you + * *must* call `E.unmountSD()` or you may cause damage to the card. + * + * @param {any} spi - The SPI object to use for communication + * @param {Pin} csPin - The pin to use for Chip Select + * @url http://www.espruino.com/Reference#l_E_connectSDCard + */ + static connectSDCard(spi: any, csPin: Pin): void; + + /** + * Unmount the SD card, so it can be removed. If you remove the SD card without + * calling this you may cause corruption, and you will be unable to access another + * SD card until you reset Espruino or call `E.unmountSD()`. + * @url http://www.espruino.com/Reference#l_E_unmountSD + */ + static unmountSD(): void; + + /** + * Open a file + * + * @param {any} path - the path to the file to open. + * @param {any} mode - The mode to use when opening the file. Valid values for mode are 'r' for read, 'w' for write new, 'w+' for write existing, and 'a' for append. If not specified, the default is 'r'. + * @returns {any} A File object + * @url http://www.espruino.com/Reference#l_E_openFile + */ + static openFile(path: any, mode: any): File; + + /** + * Change the parameters used for the flash filesystem. The default address is the + * last 1Mb of 4Mb Flash, 0x300000, with total size of 1Mb. + * Before first use the media needs to be formatted. + * ``` + * fs=require("fs"); + * try { + * fs.readdirSync(); + * } catch (e) { //'Uncaught Error: Unable to mount media : NO_FILESYSTEM' + * console.log('Formatting FS - only need to do once'); + * E.flashFatFS({ format: true }); + * } + * fs.writeFileSync("bang.txt", "This is the way the world ends\nnot with a bang but a whimper.\n"); + * fs.readdirSync(); + * ``` + * This will create a drive of 100 * 4096 bytes at 0x300000. Be careful with the + * selection of flash addresses as you can overwrite firmware! You only need to + * format once, as each will erase the content. + * `E.flashFatFS({ addr:0x300000,sectors:100,format:true });` + * + * @param {any} options + * An optional object `{ addr : int=0x300000, sectors : int=256, format : bool=false }` + * addr : start address in flash + * sectors: number of sectors to use + * format: Format the media + * @returns {boolean} True on success, or false on failure + * @url http://www.espruino.com/Reference#l_E_flashFatFS + */ + static flashFatFS(options: any): boolean; + + /** + * Display a menu on the screen, and set up the buttons to navigate through it. + * Supply an object containing menu items. When an item is selected, the function + * it references will be executed. For example: + * ``` + * var boolean = false; + * var number = 50; + * // First menu + * var mainmenu = { + * "" : { "title" : "-- Main Menu --" }, + * "Backlight On" : function() { LED1.set(); }, + * "Backlight Off" : function() { LED1.reset(); }, + * "Submenu" : function() { E.showMenu(submenu); }, + * "A Boolean" : { + * value : boolean, + * format : v => v?"On":"Off", + * onchange : v => { boolean=v; } + * }, + * "A Number" : { + * value : number, + * min:0,max:100,step:10, + * onchange : v => { number=v; } + * }, + * "Exit" : function() { E.showMenu(); }, // remove the menu + * }; + * // Submenu + * var submenu = { + * "" : { title : "-- SubMenu --", + * back : function() { E.showMenu(mainmenu); } }, + * "One" : undefined, // do nothing + * "Two" : undefined // do nothing + * }; + * // Actually display the menu + * E.showMenu(mainmenu); + * ``` + * The menu will stay onscreen and active until explicitly removed, which you can + * do by calling `E.showMenu()` without arguments. + * See http://www.espruino.com/graphical_menu for more detailed information. + * + * @param {any} menu - An object containing name->function mappings to to be used in a menu + * @returns {any} A menu object with `draw`, `move` and `select` functions + * @url http://www.espruino.com/Reference#l_E_showMenu + */ + static showMenu(menu: Menu): MenuInstance; + static showMenu(): void; + + /** + * A utility function for displaying a full screen message on the screen. + * Draws to the screen and returns immediately. + * ``` + * E.showMessage("These are\nLots of\nLines","My Title") + * ``` + * + * @param {any} message - A message to display. Can include newlines + * @param {any} title - (optional) a title for the message + * @url http://www.espruino.com/Reference#l_E_showMessage + */ + static showMessage(message: string, title?: string): void; + + /** + * Displays a full screen prompt on the screen, with the buttons requested (or + * `Yes` and `No` for defaults). + * When the button is pressed the promise is resolved with the requested values + * (for the `Yes` and `No` defaults, `true` and `false` are returned). + * ``` + * E.showPrompt("Do you like fish?").then(function(v) { + * if (v) print("'Yes' chosen"); + * else print("'No' chosen"); + * }); + * // Or + * E.showPrompt("How many fish\ndo you like?",{ + * title:"Fish", + * buttons : {"One":1,"Two":2,"Three":3} + * }).then(function(v) { + * print("You like "+v+" fish"); + * }); + * ``` + * To remove the prompt, call `E.showPrompt()` with no arguments. + * The second `options` argument can contain: + * ``` + * { + * title: "Hello", // optional Title + * buttons : {"Ok":true,"Cancel":false} // list of button text & return value + * } + * ``` + * + * @param {any} message - A message to display. Can include newlines + * @param {any} options - (optional) an object of options (see below) + * @returns {any} A promise that is resolved when 'Ok' is pressed + * @url http://www.espruino.com/Reference#l_E_showPrompt + */ + static showPrompt(message: string, options?: { title?: string, buttons?: { [key: string]: T } }): Promise; + static showPrompt(): void; + + /** + * Displays a full screen prompt on the screen, with a single 'Ok' button. + * When the button is pressed the promise is resolved. + * ``` + * E.showAlert("Hello").then(function() { + * print("Ok pressed"); + * }); + * // or + * E.showAlert("These are\nLots of\nLines","My Title").then(function() { + * print("Ok pressed"); + * }); + * ``` + * To remove the window, call `E.showAlert()` with no arguments. + * + * @param {any} message - A message to display. Can include newlines + * @param {any} options - (optional) a title for the message + * @returns {any} A promise that is resolved when 'Ok' is pressed + * @url http://www.espruino.com/Reference#l_E_showAlert + */ + static showAlert(message?: string, options?: string): Promise; + + /** + * Called when a notification arrives on an Apple iOS device Bangle.js is connected + * to + * ``` + * { + * event:"add", + * uid:42, + * category:4, + * categoryCnt:42, + * silent:true, + * important:false, + * preExisting:true, + * positive:false, + * negative:true + * } + * ``` + * You can then get more information with something like: + * ``` + * NRF.ancsGetNotificationInfo( event.uid ).then(a=>print("Notify",E.toJS(a))); + * ``` + * @param {string} event - The event to listen to. + * @param {(info: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `info` An object (see below) + * @url http://www.espruino.com/Reference#l_E_ANCS + */ + static on(event: "ANCS", callback: (info: any) => void): void; + + /** + * Called when a media event arrives on an Apple iOS device Bangle.js is connected + * to + * ``` + * { + * id : "artist"/"album"/"title"/"duration", + * value : "Some text", + * truncated : bool // the 'value' was too big to be sent completely + * } + * ``` + * @param {string} event - The event to listen to. + * @param {(info: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `info` An object (see below) + * @url http://www.espruino.com/Reference#l_E_AMS + */ + static on(event: "AMS", callback: (info: any) => void): void; + + /** + * Display a menu on the screen, and set up the buttons to navigate through it. + * Supply an object containing menu items. When an item is selected, the function + * it references will be executed. For example: + * ``` + * var boolean = false; + * var number = 50; + * // First menu + * var mainmenu = { + * "" : { title : "-- Main Menu --" }, // options + * "LED On" : function() { LED1.set(); }, + * "LED Off" : function() { LED1.reset(); }, + * "Submenu" : function() { E.showMenu(submenu); }, + * "A Boolean" : { + * value : boolean, + * format : v => v?"On":"Off", + * onchange : v => { boolean=v; } + * }, + * "A Number" : { + * value : number, + * min:0,max:100,step:10, + * onchange : v => { number=v; } + * }, + * "Exit" : function() { E.showMenu(); }, // remove the menu + * }; + * // Submenu + * var submenu = { + * "" : { title : "-- SubMenu --", + * back : function() { E.showMenu(mainmenu); } }, + * "One" : undefined, // do nothing + * "Two" : undefined // do nothing + * }; + * // Actually display the menu + * E.showMenu(mainmenu); + * ``` + * The menu will stay onscreen and active until explicitly removed, which you can + * do by calling `E.showMenu()` without arguments. + * See http://www.espruino.com/graphical_menu for more detailed information. + * On Bangle.js there are a few additions over the standard `graphical_menu`: + * * The options object can contain: + * * `back : function() { }` - add a 'back' button, with the function called when + * it is pressed + * * (Bangle.js 2) `scroll : int` - an integer specifying how much the initial + * menu should be scrolled by + * * The object returned by `E.showMenu` contains: + * * (Bangle.js 2) `scroller` - the object returned by `E.showScroller` - + * `scroller.scroll` returns the amount the menu is currently scrolled by + * * In the object specified for editable numbers: + * * (Bangle.js 2) the `format` function is called with `format(value)` in the + * main menu, `format(value,1)` when in a scrollable list, or `format(value,2)` + * when in a popup window. + * You can also specify menu items as an array (rather than an Object). This can be + * useful if you have menu items with the same title, or you want to `push` menu + * items onto an array: + * ``` + * var menu = [ + * { title:"Something", onchange:function() { print("selected"); } }, + * { title:"On or Off", value:false, onchange: v => print(v) }, + * { title:"A Value", value:3, min:0, max:10, onchange: v => print(v) }, + * ]; + * menu[""] = { title:"Hello" }; + * E.showMenu(menu); + * ``` + * + * @param {any} menu - An object containing name->function mappings to to be used in a menu + * @returns {any} A menu object with `draw`, `move` and `select` functions + * @url http://www.espruino.com/Reference#l_E_showMenu + */ + static showMenu(menu: Menu): MenuInstance; + static showMenu(): void; + + /** + * A utility function for displaying a full screen message on the screen. + * Draws to the screen and returns immediately. + * ``` + * E.showMessage("These are\nLots of\nLines","My Title") + * ``` + * or to display an image as well as text: + * ``` + * E.showMessage("Lots of text will wrap automatically",{ + * title:"Warning", + * img:atob("FBQBAfgAf+Af/4P//D+fx/n+f5/v+f//n//5//+f//n////3//5/n+P//D//wf/4B/4AH4A=") + * }) + * ``` + * + * @param {any} message - A message to display. Can include newlines + * @param {any} options - (optional) a title for the message, or an object of options `{title:string, img:image_string}` + * @url http://www.espruino.com/Reference#l_E_showMessage + */ + static showMessage(message: string, title?: string | { title?: string, img?: string }): void; + + /** + * Displays a full screen prompt on the screen, with the buttons requested (or + * `Yes` and `No` for defaults). + * When the button is pressed the promise is resolved with the requested values + * (for the `Yes` and `No` defaults, `true` and `false` are returned). + * ``` + * E.showPrompt("Do you like fish?").then(function(v) { + * if (v) print("'Yes' chosen"); + * else print("'No' chosen"); + * }); + * // Or + * E.showPrompt("How many fish\ndo you like?",{ + * title:"Fish", + * buttons : {"One":1,"Two":2,"Three":3} + * }).then(function(v) { + * print("You like "+v+" fish"); + * }); + * // Or + * E.showPrompt("Continue?", { + * title:"Alert", + * img:atob("FBQBAfgAf+Af/4P//D+fx/n+f5/v+f//n//5//+f//n////3//5/n+P//D//wf/4B/4AH4A=")}).then(function(v) { + * if (v) print("'Yes' chosen"); + * else print("'No' chosen"); + * }); + * ``` + * To remove the prompt, call `E.showPrompt()` with no arguments. + * The second `options` argument can contain: + * ``` + * { + * title: "Hello", // optional Title + * buttons : {"Ok":true,"Cancel":false}, // optional list of button text & return value + * img: "image_string" // optional image string to draw + * } + * ``` + * + * @param {any} message - A message to display. Can include newlines + * @param {any} options - (optional) an object of options (see below) + * @returns {any} A promise that is resolved when 'Ok' is pressed + * @url http://www.espruino.com/Reference#l_E_showPrompt + */ + static showPrompt(message: string, options?: { title?: string, buttons?: { [key: string]: T } }): Promise; + static showPrompt(): void; + + /** + * Display a scrollable menu on the screen, and set up the buttons/touchscreen to + * navigate through it and select items. + * Supply an object containing: + * ``` + * { + * h : 24, // height of each menu item in pixels + * c : 10, // number of menu items + * // a function to draw a menu item + * draw : function(idx, rect) { ... } + * // a function to call when the item is selected + * select : function(idx) { ... } + * // optional function to be called when 'back' is tapped + * back : function() { ...} + * } + * ``` + * For example to display a list of numbers: + * ``` + * E.showScroller({ + * h : 40, c : 8, + * draw : (idx, r) => { + * g.setBgColor((idx&1)?"#666":"#999").clearRect(r.x,r.y,r.x+r.w-1,r.y+r.h-1); + * g.setFont("6x8:2").drawString("Item Number\n"+idx,r.x+10,r.y+4); + * }, + * select : (idx) => console.log("You selected ", idx) + * }); + * ``` + * To remove the scroller, just call `E.showScroller()` + * + * @param {any} options - An object containing `{ h, c, draw, select }` (see below) + * @returns {any} A menu object with `draw()` and `drawItem(itemNo)` functions + * @url http://www.espruino.com/Reference#l_E_showScroller + */ + static showScroller(options?: { h: number, c: number, draw: (idx: number, rect: { x: number, y: number, w: number, h: number }) => void, select: (idx: number) => void, back?: () => void }): { draw: () => void, drawItem: (itemNo: number) => void }; + static showScroller(): void; + + /** + * @url http://www.espruino.com/Reference#l_E_showMenu + */ + static showMenu(): void; + + /** + * @url http://www.espruino.com/Reference#l_E_showMenu + */ + static showMenu(): void; + + /** + * @url http://www.espruino.com/Reference#l_E_showPrompt + */ + static showPrompt(): void; + + /** + * @url http://www.espruino.com/Reference#l_E_showScroller + */ + static showScroller(): void; + + /** + * Displays a full screen prompt on the screen, with a single 'Ok' button. + * When the button is pressed the promise is resolved. + * ``` + * E.showAlert("Hello").then(function() { + * print("Ok pressed"); + * }); + * // or + * E.showAlert("These are\nLots of\nLines","My Title").then(function() { + * print("Ok pressed"); + * }); + * ``` + * To remove the window, call `E.showAlert()` with no arguments. + * + * @param {any} message - A message to display. Can include newlines + * @param {any} options - (optional) a title for the message + * @returns {any} A promise that is resolved when 'Ok' is pressed + * @url http://www.espruino.com/Reference#l_E_showAlert + */ + static showAlert(message?: string, options?: string): Promise; + + /** + * This event is called right after the board starts up, and has a similar effect + * to creating a function called `onInit`. + * For example to write `"Hello World"` every time Espruino starts, use: + * ``` + * E.on('init', function() { + * console.log("Hello World!"); + * }); + * ``` + * **Note:** that subsequent calls to `E.on('init', ` will **add** a new handler, + * rather than replacing the last one. This allows you to write modular code - + * something that was not possible with `onInit`. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_E_init + */ + static on(event: "init", callback: () => void): void; + + /** + * This event is called just before the device shuts down for commands such as + * `reset()`, `load()`, `save()`, `E.reboot()` or `Bangle.off()` + * For example to write `"Bye!"` just before shutting down use: + * ``` + * E.on('kill', function() { + * console.log("Bye!"); + * }); + * ``` + * **NOTE:** This event is not called when the device is 'hard reset' - for example + * by removing power, hitting an actual reset button, or via a Watchdog timer + * reset. + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_E_kill + */ + static on(event: "kill", callback: () => void): void; + + /** + * This event is called when an error is created by Espruino itself (rather than JS + * code) which changes the state of the error flags reported by `E.getErrorFlags()` + * This could be low memory, full buffers, UART overflow, etc. `E.getErrorFlags()` + * has a full description of each type of error. + * This event will only be emitted when error flag is set. If the error flag was + * already set nothing will be emitted. To clear error flags so that you do get a + * callback each time a flag is set, call `E.getErrorFlags()`. + * @param {string} event - The event to listen to. + * @param {(errorFlags: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `errorFlags` An array of new error flags, as would be returned by `E.getErrorFlags()`. Error flags that were present before won't be reported. + * @url http://www.espruino.com/Reference#l_E_errorFlag + */ + static on(event: "errorFlag", callback: (errorFlags: ErrorFlag[]) => void): void; + + /** + * This event is called when a full touchscreen device on an Espruino is interacted + * with. + * **Note:** This event is not implemented on Bangle.js because it only has a two + * area touchscreen. + * To use the touchscreen to draw lines, you could do: + * ``` + * var last; + * E.on('touch',t=>{ + * if (last) g.lineTo(t.x, t.y); + * else g.moveTo(t.x, t.y); + * last = t.b; + * }); + * ``` + * @param {string} event - The event to listen to. + * @param {(x: number, y: number, b: number) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `x` X coordinate in display coordinates + * * `y` Y coordinate in display coordinates + * * `b` Touch count - 0 for released, 1 for pressed + * @url http://www.espruino.com/Reference#l_E_touch + */ + static on(event: "touch", callback: (x: number, y: number, b: number) => void): void; + + /** + * Use the microcontroller's internal thermistor to work out the temperature. + * On Puck.js v2.0 this will use the on-board PCT2075TP temperature sensor, but on + * other devices it may not be desperately well calibrated. + * While this is implemented on Espruino boards, it may not be implemented on other + * devices. If so it'll return NaN. + * **Note:** This is not entirely accurate and varies by a few degrees from chip + * to chip. It measures the **die temperature**, so when connected to USB it could + * be reading 10 over degrees C above ambient temperature. When running from + * battery with `setDeepSleep(true)` it is much more accurate though. + * @returns {number} The temperature in degrees C + * @url http://www.espruino.com/Reference#l_E_getTemperature + */ + static getTemperature(): number; + + /** + * Check the internal voltage reference. To work out an actual voltage of an input + * pin, you can use `analogRead(pin)*E.getAnalogVRef()` + * **Note:** This value is calculated by reading the voltage on an internal + * voltage reference with the ADC. It will be slightly noisy, so if you need this + * for accurate measurements we'd recommend that you call this function several + * times and average the results. + * While this is implemented on Espruino boards, it may not be implemented on other + * devices. If so it'll return NaN. + * @returns {number} The voltage (in Volts) that a reading of 1 from `analogRead` actually represents - usually around 3.3v + * @url http://www.espruino.com/Reference#l_E_getAnalogVRef + */ + static getAnalogVRef(): number; + + /** + * ADVANCED: This is a great way to crash Espruino if you're not sure what you are + * doing + * Create a native function that executes the code at the given address, e.g. + * `E.nativeCall(0x08012345,'double (double,double)')(1.1, 2.2)` + * If you're executing a thumb function, you'll almost certainly need to set the + * bottom bit of the address to 1. + * Note it's not guaranteed that the call signature you provide can be used - there + * are limits on the number of arguments allowed. + * When supplying `data`, if it is a 'flat string' then it will be used directly, + * otherwise it'll be converted to a flat string and used. + * + * @param {number} addr - The address in memory of the function (or offset in `data` if it was supplied + * @param {any} sig - The signature of the call, `returnType (arg1,arg2,...)`. Allowed types are `void`,`bool`,`int`,`double`,`Pin`,`JsVar` + * @param {any} data - (Optional) A string containing the function itself. If not supplied then 'addr' is used as an absolute address. + * @returns {any} The native function + * @url http://www.espruino.com/Reference#l_E_nativeCall + */ + static nativeCall(addr: number, sig: string, data?: string): any; + + /** + * Clip a number to be between min and max (inclusive) + * + * @param {number} x - A floating point value to clip + * @param {number} min - The smallest the value should be + * @param {number} max - The largest the value should be + * @returns {number} The value of x, clipped so as not to be below min or above max. + * @url http://www.espruino.com/Reference#l_E_clip + */ + static clip(x: number, min: number, max: number): number; + + /** + * Sum the contents of the given Array, String or ArrayBuffer and return the result + * + * @param {any} arr - The array to sum + * @returns {number} The sum of the given buffer + * @url http://www.espruino.com/Reference#l_E_sum + */ + static sum(arr: string | number[] | ArrayBuffer): number; + + /** + * Work out the variance of the contents of the given Array, String or ArrayBuffer + * and return the result. This is equivalent to `v=0;for (i in arr) + * v+=Math.pow(mean-arr[i],2)` + * + * @param {any} arr - The array to work out the variance for + * @param {number} mean - The mean value of the array + * @returns {number} The variance of the given buffer + * @url http://www.espruino.com/Reference#l_E_variance + */ + static variance(arr: string | number[] | ArrayBuffer, mean: number): number; + + /** + * Convolve arr1 with arr2. This is equivalent to `v=0;for (i in arr1) v+=arr1[i] * + * arr2[(i+offset) % arr2.length]` + * + * @param {any} arr1 - An array to convolve + * @param {any} arr2 - An array to convolve + * @param {number} offset - The mean value of the array + * @returns {number} The variance of the given buffer + * @url http://www.espruino.com/Reference#l_E_convolve + */ + static convolve(arr1: string | number[] | ArrayBuffer, arr2: string | number[] | ArrayBuffer, offset: number): number; + + /** + * Performs a Fast Fourier Transform (FFT) in 32 bit floats on the supplied data + * and writes it back into the original arrays. Note that if only one array is + * supplied, the data written back is the modulus of the complex result + * `sqrt(r*r+i*i)`. + * In order to perform the FFT, there has to be enough room on the stack to + * allocate two arrays of 32 bit floating point numbers - this will limit the + * maximum size of FFT possible to around 1024 items on most platforms. + * **Note:** on the Original Espruino board, FFTs are performed in 64bit arithmetic + * as there isn't space to include the 32 bit maths routines (2x more RAM is + * required). + * + * @param {any} arrReal - An array of real values + * @param {any} arrImage - An array of imaginary values (or if undefined, all values will be taken to be 0) + * @param {boolean} inverse - Set this to true if you want an inverse FFT - otherwise leave as 0 + * @url http://www.espruino.com/Reference#l_E_FFT + */ + static FFT(arrReal: string | number[] | ArrayBuffer, arrImage?: string | number[] | ArrayBuffer, inverse?: boolean): any; + + /** + * Enable the watchdog timer. This will reset Espruino if it isn't able to return + * to the idle loop within the timeout. + * If `isAuto` is false, you must call `E.kickWatchdog()` yourself every so often + * or the chip will reset. + * ``` + * E.enableWatchdog(0.5); // automatic mode + * while(1); // Espruino will reboot because it has not been idle for 0.5 sec + * ``` + * ``` + * E.enableWatchdog(1, false); + * setInterval(function() { + * if (everything_ok) + * E.kickWatchdog(); + * }, 500); + * // Espruino will now reset if everything_ok is false, + * // or if the interval fails to be called + * ``` + * **NOTE:** This is only implemented on STM32 and nRF5x devices (all official + * Espruino boards). + * **NOTE:** On STM32 (Pico, WiFi, Original) with `setDeepSleep(1)` you need to + * explicitly wake Espruino up with an interval of less than the watchdog timeout + * or the watchdog will fire and the board will reboot. You can do this with + * `setInterval("", time_in_milliseconds)`. + * + * @param {number} timeout - The timeout in seconds before a watchdog reset + * @param {any} isAuto - If undefined or true, the watchdog is kicked automatically. If not, you must call `E.kickWatchdog()` yourself + * @url http://www.espruino.com/Reference#l_E_enableWatchdog + */ + static enableWatchdog(timeout: number, isAuto?: boolean): void; + + /** + * Kicks a Watchdog timer set up with `E.enableWatchdog(..., false)`. See + * `E.enableWatchdog` for more information. + * **NOTE:** This is only implemented on STM32 and nRF5x devices (all official + * Espruino boards). + * @url http://www.espruino.com/Reference#l_E_kickWatchdog + */ + static kickWatchdog(): void; + + /** + * Get and reset the error flags. Returns an array that can contain: + * `'FIFO_FULL'`: The receive FIFO filled up and data was lost. This could be state + * transitions for setWatch, or received characters. + * `'BUFFER_FULL'`: A buffer for a stream filled up and characters were lost. This + * can happen to any stream - Serial,HTTP,etc. + * `'CALLBACK'`: A callback (`setWatch`, `setInterval`, `on('data',...)`) caused an + * error and so was removed. + * `'LOW_MEMORY'`: Memory is running low - Espruino had to run a garbage collection + * pass or remove some of the command history + * `'MEMORY'`: Espruino ran out of memory and was unable to allocate some data that + * it needed. + * `'UART_OVERFLOW'` : A UART received data but it was not read in time and was + * lost + * @returns {any} An array of error flags + * @url http://www.espruino.com/Reference#l_E_getErrorFlags + */ + static getErrorFlags(): ErrorFlag[] + + /** + * Get Espruino's interpreter flags that control the way it handles your JavaScript + * code. + * * `deepSleep` - Allow deep sleep modes (also set by setDeepSleep) + * * `pretokenise` - When adding functions, pre-minify them and tokenise reserved + * words + * * `unsafeFlash` - Some platforms stop writes/erases to interpreter memory to + * stop you bricking the device accidentally - this removes that protection + * * `unsyncFiles` - When writing files, *don't* flush all data to the SD card + * after each command (the default is *to* flush). This is much faster, but can + * cause filesystem damage if power is lost without the filesystem unmounted. + * @returns {any} An object containing flag names and their values + * @url http://www.espruino.com/Reference#l_E_getFlags + */ + static getFlags(): { [key in Flag]: boolean } + + /** + * Set the Espruino interpreter flags that control the way it handles your + * JavaScript code. + * Run `E.getFlags()` and check its description for a list of available flags and + * their values. + * + * @param {any} flags - An object containing flag names and boolean values. You need only specify the flags that you want to change. + * @url http://www.espruino.com/Reference#l_E_setFlags + */ + static setFlags(flags: { [key in Flag]?: boolean }): void + + /** + * + * @param {any} source - The source file/stream that will send content. + * @param {any} destination - The destination file/stream that will receive content from the source. + * @param {any} options + * An optional object `{ chunkSize : int=64, end : bool=true, complete : function }` + * chunkSize : The amount of data to pipe from source to destination at a time + * complete : a function to call when the pipe activity is complete + * end : call the 'end' function on the destination when the source is finished + * @url http://www.espruino.com/Reference#l_E_pipe + */ + static pipe(source: any, destination: any, options?: { chunkSize?: number, end?: boolean, complete?: () => void }): void + + /** + * Create an ArrayBuffer from the given string. This is done via a reference, not a + * copy - so it is very fast and memory efficient. + * Note that this is an ArrayBuffer, not a Uint8Array. To get one of those, do: + * `new Uint8Array(E.toArrayBuffer('....'))`. + * + * @param {any} str - The string to convert to an ArrayBuffer + * @returns {any} An ArrayBuffer that uses the given string + * @url http://www.espruino.com/Reference#l_E_toArrayBuffer + */ + static toArrayBuffer(str: string): ArrayBuffer; + + /** + * Returns a 'flat' string representing the data in the arguments, or return + * `undefined` if a flat string cannot be created. + * This creates a string from the given arguments. If an argument is a String or an + * Array, each element is traversed and added as an 8 bit character. If it is + * anything else, it is converted to a character directly. + * In the case where there's one argument which is an 8 bit typed array backed by a + * flat string of the same length, the backing string will be returned without + * doing a copy or other allocation. The same applies if there's a single argument + * which is itself a flat string. + * + * @param {any} args - The arguments to convert to a String + * @returns {any} A String (or `undefined` if a Flat String cannot be created) + * @url http://www.espruino.com/Reference#l_E_toString + */ + static toString(...args: any[]): string | undefined; + + /** + * This creates a Uint8Array from the given arguments. These are handled as + * follows: + * * `Number` -> read as an integer, using the lowest 8 bits + * * `String` -> use each character's numeric value (e.g. + * `String.charCodeAt(...)`) + * * `Array` -> Call itself on each element + * * `ArrayBuffer` or Typed Array -> use the lowest 8 bits of each element + * * `Object`: + * * `{data:..., count: int}` -> call itself `object.count` times, on + * `object.data` + * * `{callback : function}` -> call the given function, call itself on return + * value + * For example: + * ``` + * E.toUint8Array([1,2,3]) + * =new Uint8Array([1, 2, 3]) + * E.toUint8Array([1,{data:2,count:3},3]) + * =new Uint8Array([1, 2, 2, 2, 3]) + * E.toUint8Array("Hello") + * =new Uint8Array([72, 101, 108, 108, 111]) + * E.toUint8Array(["hi",{callback:function() { return [1,2,3] }}]) + * =new Uint8Array([104, 105, 1, 2, 3]) + * ``` + * + * @param {any} args - The arguments to convert to a Uint8Array + * @returns {any} A Uint8Array + * @url http://www.espruino.com/Reference#l_E_toUint8Array + */ + static toUint8Array(...args: Uint8ArrayResolvable[]): Uint8Array; + + /** + * This performs the same basic function as `JSON.stringify`, however + * `JSON.stringify` adds extra characters to conform to the JSON spec which aren't + * required if outputting JS. + * `E.toJS` will also stringify JS functions, whereas `JSON.stringify` ignores + * them. + * For example: + * * `JSON.stringify({a:1,b:2}) == '{"a":1,"b":2}'` + * * `E.toJS({a:1,b:2}) == '{a:1,b:2}'` + * **Note:** Strings generated with `E.toJS` can't be reliably parsed by + * `JSON.parse` - however they are valid JS so will work with `eval` (but this has + * security implications if you don't trust the source of the string). + * On the desktop [JSON5 parsers](https://github.com/json5/json5) will parse the + * strings produced by `E.toJS` without trouble. + * + * @param {any} arg - The JS variable to convert to a string + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_E_toJS + */ + static toJS(arg: any): string; + + /** + * This creates and returns a special type of string, which actually references a + * specific memory address. It can be used in order to use sections of Flash memory + * directly in Espruino (for example to execute code straight from flash memory + * with `eval(E.memoryArea( ... ))`) + * **Note:** This is only tested on STM32-based platforms (Espruino Original and + * Espruino Pico) at the moment. + * + * @param {number} addr - The address of the memory area + * @param {number} len - The length (in bytes) of the memory area + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_E_memoryArea + */ + static memoryArea(addr: number, len: number): string; + + /** + * This writes JavaScript code into Espruino's flash memory, to be executed on + * startup. It differs from `save()` in that `save()` saves the whole state of the + * interpreter, whereas this just saves JS code that is executed at boot. + * Code will be executed before `onInit()` and `E.on('init', ...)`. + * If `alwaysExec` is `true`, the code will be executed even after a call to + * `reset()`. This is useful if you're making something that you want to program, + * but you want some code that is always built in (for instance setting up a + * display or keyboard). + * To remove boot code that has been saved previously, use `E.setBootCode("")` + * **Note:** this removes any code that was previously saved with `save()` + * + * @param {any} code - The code to execute (as a string) + * @param {boolean} alwaysExec - Whether to always execute the code (even after a reset) + * @url http://www.espruino.com/Reference#l_E_setBootCode + */ + static setBootCode(code: string, alwaysExec?: boolean): void; + + /** + * This sets the clock frequency of Espruino's processor. It will return `0` if it + * is unimplemented or the clock speed cannot be changed. + * **Note:** On pretty much all boards, UART, SPI, I2C, PWM, etc will change + * frequency and will need setting up again in order to work. + * ### STM32F4 + * Options is of the form `{ M: int, N: int, P: int, Q: int }` - see the 'Clocks' + * section of the microcontroller's reference manual for what these mean. + * * System clock = 8Mhz * N / ( M * P ) + * * USB clock (should be 48Mhz) = 8Mhz * N / ( M * Q ) + * Optional arguments are: + * * `latency` - flash latency from 0..15 + * * `PCLK1` - Peripheral clock 1 divisor (default: 2) + * * `PCLK2` - Peripheral clock 2 divisor (default: 4) + * The Pico's default is `{M:8, N:336, P:4, Q:7, PCLK1:2, PCLK2:4}`, use `{M:8, + * N:336, P:8, Q:7, PCLK:1, PCLK2:2}` to halve the system clock speed while keeping + * the peripherals running at the same speed (omitting PCLK1/2 will lead to the + * peripherals changing speed too). + * On STM32F4 boards (e.g. Espruino Pico), the USB clock needs to be kept at 48Mhz + * or USB will fail to work. You'll also experience USB instability if the + * processor clock falls much below 48Mhz. + * ### ESP8266 + * Just specify an integer value, either 80 or 160 (for 80 or 160Mhz) + * + * @param {any} options - Platform-specific options for setting clock speed + * @returns {number} The actual frequency the clock has been set to + * @url http://www.espruino.com/Reference#l_E_setClock + */ + static setClock(options: number | { M: number, N: number, P: number, Q: number, latency?: number, PCLK?: number, PCLK2?: number }): number; + + /** + * Changes the device that the JS console (otherwise known as the REPL) is attached + * to. If the console is on a device, that device can be used for programming + * Espruino. + * Rather than calling `Serial.setConsole` you can call + * `E.setConsole("DeviceName")`. + * This is particularly useful if you just want to remove the console. + * `E.setConsole(null)` will make the console completely inaccessible. + * `device` may be `"Serial1"`,`"USB"`,`"Bluetooth"`,`"Telnet"`,`"Terminal"`, any + * other *hardware* `Serial` device, or `null` to disable the console completely. + * `options` is of the form: + * ``` + * { + * force : bool // default false, force the console onto this device so it does not move + * // if false, changes in connection state (e.g. USB/Bluetooth) can move + * // the console automatically. + * } + * ``` + * + * @param {any} device + * @param {any} options - (optional) object of options, see below + * @url http://www.espruino.com/Reference#l_E_setConsole + */ + static setConsole(device: "Serial1" | "USB" | "Bluetooth" | "Telnet" | "Terminal" | Serial | null, options?: { force?: boolean }): void; + + /** + * Returns the current console device - see `E.setConsole` for more information. + * @returns {any} The current console device as a string, or just `null` if the console is null + * @url http://www.espruino.com/Reference#l_E_getConsole + */ + static getConsole(): string | null + + /** + * Reverse the 8 bits in a byte, swapping MSB and LSB. + * For example, `E.reverseByte(0b10010000) == 0b00001001`. + * Note that you can reverse all the bytes in an array with: `arr = + * arr.map(E.reverseByte)` + * + * @param {number} x - A byte value to reverse the bits of + * @returns {number} The byte with reversed bits + * @url http://www.espruino.com/Reference#l_E_reverseByte + */ + static reverseByte(x: number): number; + + /** + * Output the current list of Utility Timer Tasks - for debugging only + * @url http://www.espruino.com/Reference#l_E_dumpTimers + */ + static dumpTimers(): void; + + /** + * Dump any locked variables that aren't referenced from `global` - for debugging + * memory leaks only. + * @url http://www.espruino.com/Reference#l_E_dumpLockedVars + */ + static dumpLockedVars(): void; + + /** + * Dump any locked variables that aren't referenced from `global` - for debugging + * memory leaks only. + * @url http://www.espruino.com/Reference#l_E_dumpFreeList + */ + static dumpFreeList(): void; + + /** + * Show fragmentation. + * * ` ` is free space + * * `#` is a normal variable + * * `L` is a locked variable (address used, cannot be moved) + * * `=` represents data in a Flat String (must be contiguous) + * @url http://www.espruino.com/Reference#l_E_dumpFragmentation + */ + static dumpFragmentation(): void; + + /** + * Dumps a comma-separated list of all allocated variables along with the variables + * they link to. Can be used to visualise where memory is used. + * @url http://www.espruino.com/Reference#l_E_dumpVariables + */ + static dumpVariables(): void; + + /** + * BETA: defragment memory! + * @url http://www.espruino.com/Reference#l_E_defrag + */ + static defrag(): void; + + /** + * Return the number of variable blocks used by the supplied variable. This is + * useful if you're running out of memory and you want to be able to see what is + * taking up most of the available space. + * If `depth>0` and the variable can be recursed into, an array listing all + * property names (including internal Espruino names) and their sizes is returned. + * If `depth>1` there is also a `more` field that inspects the objects' children's + * children. + * For instance `E.getSizeOf(function(a,b) { })` returns `5`. + * But `E.getSizeOf(function(a,b) { }, 1)` returns: + * ``` + * [ + * { + * "name": "a", + * "size": 1 }, + * { + * "name": "b", + * "size": 1 }, + * { + * "name": "\xFFcod", + * "size": 2 } + * ] + * ``` + * In this case setting depth to `2` will make no difference as there are no more + * children to traverse. + * See http://www.espruino.com/Internals for more information + * + * @param {any} v - A variable to get the size of + * @param {number} depth - The depth that detail should be provided for. If depth<=0 or undefined, a single integer will be returned + * @returns {any} Information about the variable size - see below + * @url http://www.espruino.com/Reference#l_E_getSizeOf + */ + static getSizeOf(v: any, depth?: 0): number; + static getSizeOf(v: any, depth: number): VariableSizeInformation; + + /** + * Return the address in memory of the given variable. This can then be used with + * `peek` and `poke` functions. However, changing data in JS variables directly + * (flatAddress=false) will most likely result in a crash. + * This functions exists to allow embedded targets to set up peripherals such as + * DMA so that they write directly to JS variables. + * See http://www.espruino.com/Internals for more information + * + * @param {any} v - A variable to get the address of + * @param {boolean} flatAddress - (boolean) If `true` and a Flat String or Flat ArrayBuffer is supplied, return the address of the data inside it - otherwise 0. If `false` (the default) return the address of the JsVar itself. + * @returns {number} The address of the given variable + * @url http://www.espruino.com/Reference#l_E_getAddressOf + */ + static getAddressOf(v: any, flatAddress: boolean): number; + + /** + * Take each element of the `from` array, look it up in `map` (or call + * `map(value,index)` if it is a function), and write it into the corresponding + * element in the `to` array. + * You can use an array to map: + * ``` + * var a = new Uint8Array([1,2,3,1,2,3]); + * var lut = new Uint8Array([128,129,130,131]); + * E.mapInPlace(a, a, lut); + * // a = [129, 130, 131, 129, 130, 131] + * ``` + * Or `undefined` to pass straight through, or a function to do a normal 'mapping': + * ``` + * var a = new Uint8Array([0x12,0x34,0x56,0x78]); + * var b = new Uint8Array(8); + * E.mapInPlace(a, b, undefined); // straight through + * // b = [0x12,0x34,0x56,0x78,0,0,0,0] + * E.mapInPlace(a, b, (value,index)=>index); // write the index in the first 4 (because a.length==4) + * // b = [0,1,2,3,4,0,0,0] + * E.mapInPlace(a, b, undefined, 4); // 4 bits from 8 bit input -> 2x as many outputs, msb-first + * // b = [1, 2, 3, 4, 5, 6, 7, 8] + * E.mapInPlace(a, b, undefined, -4); // 4 bits from 8 bit input -> 2x as many outputs, lsb-first + * // b = [2, 1, 4, 3, 6, 5, 8, 7] + * E.mapInPlace(a, b, a=>a+2, 4); + * // b = [3, 4, 5, 6, 7, 8, 9, 10] + * var b = new Uint16Array(4); + * E.mapInPlace(a, b, undefined, 12); // 12 bits from 8 bit input, msb-first + * // b = [0x123, 0x456, 0x780, 0] + * E.mapInPlace(a, b, undefined, -12); // 12 bits from 8 bit input, lsb-first + * // b = [0x412, 0x563, 0x078, 0] + * ``` + * + * @param {any} from - An ArrayBuffer to read elements from + * @param {any} to - An ArrayBuffer to write elements too + * @param {any} map - An array or `function(value,index)` to use to map one element to another, or `undefined` to provide no mapping + * @param {number} bits - If specified, the number of bits per element (MSB first) - otherwise use a 1:1 mapping. If negative, use LSB first. + * @url http://www.espruino.com/Reference#l_E_mapInPlace + */ + static mapInPlace(from: ArrayBuffer, to: ArrayBuffer, map?: number[] | ((value: number, index: number) => number) | undefined, bits?: number): void; + + /** + * Search in an Object, Array, or Function + * + * @param {any} haystack - The Array/Object/Function to search + * @param {any} needle - The key to search for + * @param {boolean} returnKey - If true, return the key, else return the value itself + * @returns {any} The value in the Object matching 'needle', or if `returnKey==true` the key's name - or undefined + * @url http://www.espruino.com/Reference#l_E_lookupNoCase + */ + static lookupNoCase(haystack: any[] | object | Function, needle: string, returnKey?: false): any; + static lookupNoCase(haystack: any[] | object | Function, needle: T, returnKey: true): T | undefined; + + /** + * Get the current interpreter state in a text form such that it can be copied to a + * new device + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_E_dumpStr + */ + static dumpStr(): string; + + /** + * Set the seed for the random number generator used by `Math.random()`. + * + * @param {number} v - The 32 bit integer seed to use for the random number generator + * @url http://www.espruino.com/Reference#l_E_srand + */ + static srand(v: number): void; + + /** + * Unlike 'Math.random()' which uses a pseudo-random number generator, this method + * reads from the internal voltage reference several times, XOR-ing and rotating to + * try and make a relatively random value from the noise in the signal. + * @returns {number} A random number + * @url http://www.espruino.com/Reference#l_E_hwRand + */ + static hwRand(): number; + + /** + * Perform a standard 32 bit CRC (Cyclic redundancy check) on the supplied data + * (one byte at a time) and return the result as an unsigned integer. + * + * @param {any} data - Iterable data to perform CRC32 on (each element treated as a byte) + * @returns {any} The CRC of the supplied data + * @url http://www.espruino.com/Reference#l_E_CRC32 + */ + static CRC32(data: any): any; + + /** + * Convert hue, saturation and brightness to red, green and blue (packed into an + * integer if `asArray==false` or an array if `asArray==true`). + * This replaces `Graphics.setColorHSB` and `Graphics.setBgColorHSB`. On devices + * with 24 bit colour it can be used as: `Graphics.setColor(E.HSBtoRGB(h, s, b))` + * You can quickly set RGB items in an Array or Typed Array using + * `array.set(E.HSBtoRGB(h, s, b,true), offset)`, which can be useful with arrays + * used with `require("neopixel").write`. + * + * @param {number} hue - The hue, as a value between 0 and 1 + * @param {number} sat - The saturation, as a value between 0 and 1 + * @param {number} bri - The brightness, as a value between 0 and 1 + * @param {boolean} asArray - If true, return an array of [R,G,B] values betwen 0 and 255 + * @returns {any} A 24 bit number containing bytes representing red, green, and blue `0xBBGGRR`. Or if `asArray` is true, an array `[R,G,B]` + * @url http://www.espruino.com/Reference#l_E_HSBtoRGB + */ + static HSBtoRGB(hue: number, sat: number, bri: number, asArray?: false): number; + static HSBtoRGB(hue: number, sat: number, bri: number, asArray: true): [number, number, number]; + + /** + * Set a password on the console (REPL). When powered on, Espruino will then demand + * a password before the console can be used. If you want to lock the console + * immediately after this you can call `E.lockConsole()` + * To remove the password, call this function with no arguments. + * **Note:** There is no protection against multiple password attempts, so someone + * could conceivably try every password in a dictionary. + * **Note:** This password is stored in memory in plain text. If someone is able to + * execute arbitrary JavaScript code on the device (e.g., you use `eval` on input + * from unknown sources) or read the device's firmware then they may be able to + * obtain it. + * + * @param {any} password - The password - max 20 chars + * @url http://www.espruino.com/Reference#l_E_setPassword + */ + static setPassword(password: string): void; + + /** + * If a password has been set with `E.setPassword()`, this will lock the console so + * the password needs to be entered to unlock it. + * @url http://www.espruino.com/Reference#l_E_lockConsole + */ + static lockConsole(): void; + + /** + * Set the time zone to be used with `Date` objects. + * For example `E.setTimeZone(1)` will be GMT+0100 + * Note that `E.setTimeZone()` will have no effect when daylight savings time rules + * have been set with `E.setDST()`. The timezone value will be stored, but never + * used so long as DST settings are in effect. + * Time can be set with `setTime`. + * + * @param {number} zone - The time zone in hours + * @url http://www.espruino.com/Reference#l_E_setTimeZone + */ + static setTimeZone(zone: number): void; + + /** + * Set the daylight savings time parameters to be used with `Date` objects. + * The parameters are + * - dstOffset: The number of minutes daylight savings time adds to the clock + * (usually 60) - set to 0 to disable DST + * - timezone: The time zone, in minutes, when DST is not in effect - positive east + * of Greenwich + * - startDowNumber: The index of the day-of-week in the month when DST starts - 0 + * for first, 1 for second, 2 for third, 3 for fourth and 4 for last + * - startDow: The day-of-week for the DST start calculation - 0 for Sunday, 6 for + * Saturday + * - startMonth: The number of the month that DST starts - 0 for January, 11 for + * December + * - startDayOffset: The number of days between the selected day-of-week and the + * actual day that DST starts - usually 0 + * - startTimeOfDay: The number of minutes elapsed in the day before DST starts + * - endDowNumber: The index of the day-of-week in the month when DST ends - 0 for + * first, 1 for second, 2 for third, 3 for fourth and 4 for last + * - endDow: The day-of-week for the DST end calculation - 0 for Sunday, 6 for + * Saturday + * - endMonth: The number of the month that DST ends - 0 for January, 11 for + * December + * - endDayOffset: The number of days between the selected day-of-week and the + * actual day that DST ends - usually 0 + * - endTimeOfDay: The number of minutes elapsed in the day before DST ends + * To determine what the `dowNumber, dow, month, dayOffset, timeOfDay` parameters + * should be, start with a sentence of the form "DST starts on the last Sunday of + * March (plus 0 days) at 03:00". Since it's the last Sunday, we have + * startDowNumber = 4, and since it's Sunday, we have startDow = 0. That it is + * March gives us startMonth = 2, and that the offset is zero days, we have + * startDayOffset = 0. The time that DST starts gives us startTimeOfDay = 3*60. + * "DST ends on the Friday before the second Sunday in November at 02:00" would + * give us endDowNumber=1, endDow=0, endMonth=10, endDayOffset=-2 and + * endTimeOfDay=120. + * Using Ukraine as an example, we have a time which is 2 hours ahead of GMT in + * winter (EET) and 3 hours in summer (EEST). DST starts at 03:00 EET on the last + * Sunday in March, and ends at 04:00 EEST on the last Sunday in October. So + * someone in Ukraine might call `E.setDST(60,120,4,0,2,0,180,4,0,9,0,240);` + * Note that when DST parameters are set (i.e. when `dstOffset` is not zero), + * `E.setTimeZone()` has no effect. + * + * @param {any} params - An array containing the settings for DST + * @url http://www.espruino.com/Reference#l_E_setDST + */ + static setDST(dstOffset: number, timezone: number, startDowNumber: number, startDow: number, startMonth: number, startDayOffset: number, startTimeOfDay: number, endDowNumber: number, endDow: number, endMonth: number, endDayOffset: number, endTimeOfDay: number): void + + /** + * Create an object where every field accesses a specific 32 bit address in the + * microcontroller's memory. This is perfect for accessing on-chip peripherals. + * ``` + * // for NRF52 based chips + * var GPIO = E.memoryMap(0x50000000,{OUT:0x504, OUTSET:0x508, OUTCLR:0x50C, IN:0x510, DIR:0x514, DIRSET:0x518, DIRCLR:0x51C}); + * GPIO.DIRSET = 1; // set GPIO0 to output + * GPIO.OUT ^= 1; // toggle the output state of GPIO0 + * ``` + * + * @param {any} baseAddress - The base address (added to every address in `registers`) + * @param {any} registers - An object containing `{name:address}` + * @returns {any} An object where each field is memory-mapped to a register. + * @url http://www.espruino.com/Reference#l_E_memoryMap + */ + static memoryMap(baseAddress: number, registers: { [key in T]: number }): { [key in T]: number }; + + /** + * Provide assembly to Espruino. + * **This function is not part of Espruino**. Instead, it is detected by the + * Espruino IDE (or command-line tools) at upload time and is replaced with machine + * code and an `E.nativeCall` call. + * See [the documentation on the Assembler](http://www.espruino.com/Assembler) for + * more information. + * + * @param {any} callspec - The arguments this assembly takes - e.g. `void(int)` + * @param {any} assemblycode - One of more strings of assembler code + * @url http://www.espruino.com/Reference#l_E_asm + */ + static asm(callspec: string, ...assemblycode: string[]): any; + + /** + * Provides the ability to write C code inside your JavaScript file. + * **This function is not part of Espruino**. Instead, it is detected by the + * Espruino IDE (or command-line tools) at upload time, is sent to our web service + * to be compiled, and is replaced with machine code and an `E.nativeCall` call. + * See [the documentation on Inline C](http://www.espruino.com/InlineC) for more + * information and examples. + * + * @param {any} code - A Templated string of C code + * @url http://www.espruino.com/Reference#l_E_compiledC + */ + static compiledC(code: string): any; + + /** + * Forces a hard reboot of the microcontroller - as close as possible to if the + * reset pin had been toggled. + * **Note:** This is different to `reset()`, which performs a software reset of + * Espruino (resetting the interpreter and pin states, but not all the hardware) + * @url http://www.espruino.com/Reference#l_E_reboot + */ + static reboot(): void; + + /** + * USB HID will only take effect next time you unplug and re-plug your Espruino. If + * you're disconnecting it from power you'll have to make sure you have `save()`d + * after calling this function. + * + * @param {any} opts - An object containing at least reportDescriptor, an array representing the report descriptor. Pass undefined to disable HID. + * @url http://www.espruino.com/Reference#l_E_setUSBHID + */ + static setUSBHID(opts?: { reportDescriptor: any[] }): void; + + /** + * + * @param {any} data - An array of bytes to send as a USB HID packet + * @returns {boolean} 1 on success, 0 on failure + * @url http://www.espruino.com/Reference#l_E_sendUSBHID + */ + static sendUSBHID(data: string | ArrayBuffer | number[]): boolean; + + /** + * In devices that come with batteries, this function returns the battery charge + * percentage as an integer between 0 and 100. + * **Note:** this is an estimation only, based on battery voltage. The temperature + * of the battery (as well as the load being drawn from it at the time + * `E.getBattery` is called) will affect the readings. + * @returns {number} A percentage between 0 and 100 + * @url http://www.espruino.com/Reference#l_E_getBattery + */ + static getBattery(): number; + + /** + * Sets the RTC's prescaler's maximum value. This is the counter that counts up on + * each oscillation of the low speed oscillator. When the prescaler counts to the + * value supplied, one second is deemed to have passed. + * By default this is set to the oscillator's average speed as specified in the + * datasheet, and usually that is fine. However on early [Espruino Pico](/Pico) + * boards the STM32F4's internal oscillator could vary by as much as 15% from the + * value in the datasheet. In that case you may want to alter this value to reflect + * the true RTC speed for more accurate timekeeping. + * To change the RTC's prescaler value to a computed value based on comparing + * against the high speed oscillator, just run the following command, making sure + * it's done a few seconds after the board starts up: + * ``` + * E.setRTCPrescaler(E.getRTCPrescaler(true)); + * ``` + * When changing the RTC prescaler, the RTC 'follower' counters are reset and it + * can take a second or two before readings from getTime are stable again. + * To test, you can connect an input pin to a known frequency square wave and then + * use `setWatch`. If you don't have a frequency source handy, you can check + * against the high speed oscillator: + * ``` + * // connect pin B3 to B4 + * analogWrite(B3, 0.5, {freq:0.5}); + * setWatch(function(e) { + * print(e.time - e.lastTime); + * }, B4, {repeat:true}); + * ``` + * **Note:** This is only used on official Espruino boards containing an STM32 + * microcontroller. Other boards (even those using an STM32) don't use the RTC and + * so this has no effect. + * + * @param {number} prescaler - The amount of counts for one second of the RTC - this is a 15 bit integer value (0..32767) + * @url http://www.espruino.com/Reference#l_E_setRTCPrescaler + */ + static setRTCPrescaler(prescaler: number): void; + + /** + * Gets the RTC's current prescaler value if `calibrate` is undefined or false. + * If `calibrate` is true, the low speed oscillator's speed is calibrated against + * the high speed oscillator (usually +/- 20 ppm) and a suggested value to be fed + * into `E.setRTCPrescaler(...)` is returned. + * See `E.setRTCPrescaler` for more information. + * + * @param {boolean} calibrate - If `false`, the current value. If `true`, the calculated 'correct' value + * @returns {number} The RTC prescaler's current value + * @url http://www.espruino.com/Reference#l_E_getRTCPrescaler + */ + static getRTCPrescaler(calibrate: boolean): number; + + /** + * Decode a UTF8 string. + * * Any decoded character less than 256 gets passed straight through + * * Otherwise if `lookup` is an array and an item with that char code exists in `lookup` then that is used + * * Otherwise if `lookup` is an object and an item with that char code (as lowercase hex) exists in `lookup` then that is used + * * Otherwise `replaceFn(charCode)` is called and the result used if `replaceFn` is a function + * * If `replaceFn` is a string, that is used + * * Or finally if nothing else matches, the character is ignored + * For instance: + * ``` + * let unicodeRemap = { + * 0x20ac:"\u0080", // Euro symbol + * 0x2026:"\u0085", // Ellipsis + * }; + * E.decodeUTF8("UTF-8 Euro: \u00e2\u0082\u00ac", unicodeRemap, '[?]') == "UTF-8 Euro: \u0080" + * ``` + * + * @param {any} str - A string of UTF8-encoded data + * @param {any} lookup - An array containing a mapping of character code -> replacement string + * @param {any} replaceFn - If not in lookup, `replaceFn(charCode)` is called and the result used if it's a function, *or* if it's a string, the string value is used + * @returns {any} A string containing all UTF8 sequences flattened to 8 bits + * @url http://www.espruino.com/Reference#l_E_decodeUTF8 + */ + static decodeUTF8(str: string, lookup: string[], replaceFn: string | ((charCode: number) => string)): string; + + +} + +interface consoleConstructor { + /** + * Print the supplied string(s) to the console + * **Note:** If you're connected to a computer (not a wall adaptor) via USB but + * **you are not running a terminal app** then when you print data Espruino may + * pause execution and wait until the computer requests the data it is trying to + * print. + * + * @param {any} text - One or more arguments to print + * @url http://www.espruino.com/Reference#l_console_log + */ + log(...text: any[]): void; +} + +interface console { + +} + +/** + * An Object that contains functions for writing to the interactive console + * @url http://www.espruino.com/Reference#console + */ +declare const console: consoleConstructor + +interface ErrorConstructor { + /** + * Creates an Error object + * @constructor + * + * @param {any} message - An optional message string + * @returns {any} An Error object + * @url http://www.espruino.com/Reference#l_Error_Error + */ + new(message?: string): Error; +} + +interface Error { + /** + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_Error_toString + */ + toString(): string; +} + +/** + * The base class for runtime errors + * @url http://www.espruino.com/Reference#Error + */ +declare const Error: ErrorConstructor + +interface SyntaxErrorConstructor { + /** + * Creates a SyntaxError object + * @constructor + * + * @param {any} message - An optional message string + * @returns {any} A SyntaxError object + * @url http://www.espruino.com/Reference#l_SyntaxError_SyntaxError + */ + new(message?: string): SyntaxError; +} + +interface SyntaxError { + /** + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_SyntaxError_toString + */ + toString(): string; +} + +/** + * The base class for syntax errors + * @url http://www.espruino.com/Reference#SyntaxError + */ +declare const SyntaxError: SyntaxErrorConstructor + +interface TypeErrorConstructor { + /** + * Creates a TypeError object + * @constructor + * + * @param {any} message - An optional message string + * @returns {any} A TypeError object + * @url http://www.espruino.com/Reference#l_TypeError_TypeError + */ + new(message?: string): TypeError; +} + +interface TypeError { + /** + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_TypeError_toString + */ + toString(): string; +} + +/** + * The base class for type errors + * @url http://www.espruino.com/Reference#TypeError + */ +declare const TypeError: TypeErrorConstructor + +/** + * The base class for internal errors + * @url http://www.espruino.com/Reference#InternalError + */ +declare class InternalError { + /** + * Creates an InternalError object + * @constructor + * + * @param {any} message - An optional message string + * @returns {any} An InternalError object + * @url http://www.espruino.com/Reference#l_InternalError_InternalError + */ + static new(message?: string): InternalError; + + /** + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_InternalError_toString + */ + toString(): string; +} + +interface ReferenceErrorConstructor { + /** + * Creates a ReferenceError object + * @constructor + * + * @param {any} message - An optional message string + * @returns {any} A ReferenceError object + * @url http://www.espruino.com/Reference#l_ReferenceError_ReferenceError + */ + new(message?: string): ReferenceError; +} + +interface ReferenceError { + /** + * @returns {any} A String + * @url http://www.espruino.com/Reference#l_ReferenceError_toString + */ + toString(): string; +} + +/** + * The base class for reference errors - where a variable which doesn't exist has + * been accessed. + * @url http://www.espruino.com/Reference#ReferenceError + */ +declare const ReferenceError: ReferenceErrorConstructor + +interface JSONConstructor { + /** + * Convert the given object into a JSON string which can subsequently be parsed + * with JSON.parse or eval. + * **Note:** This differs from JavaScript's standard `JSON.stringify` in that: + * * The `replacer` argument is ignored + * * Typed arrays like `new Uint8Array(5)` will be dumped as if they were arrays, + * not as if they were objects (since it is more compact) + * + * @param {any} data - The data to be converted to a JSON string + * @param {any} replacer - This value is ignored + * @param {any} space - The number of spaces to use for padding, a string, or null/undefined for no whitespace + * @returns {any} A JSON string + * @url http://www.espruino.com/Reference#l_JSON_stringify + */ + stringify(data: any, replacer: any, space: any): any; + + /** + * Parse the given JSON string into a JavaScript object + * NOTE: This implementation uses eval() internally, and as such it is unsafe as it + * can allow arbitrary JS commands to be executed. + * + * @param {any} string - A JSON string + * @returns {any} The JavaScript object created by parsing the data string + * @url http://www.espruino.com/Reference#l_JSON_parse + */ + parse(string: any): any; +} + +interface JSON { + +} + +/** + * An Object that handles conversion to and from the JSON data interchange format + * @url http://www.espruino.com/Reference#JSON + */ +declare const JSON: JSONConstructor + +interface RegExpConstructor { + /** + * Creates a RegExp object, for handling Regular Expressions + * @constructor + * + * @param {any} regex - A regular expression as a string + * @param {any} flags - Flags for the regular expression as a string + * @returns {any} A RegExp object + * @url http://www.espruino.com/Reference#l_RegExp_RegExp + */ + new(regex: any, flags: any): RegExp; +} + +interface RegExp { + /** + * Test this regex on a string - returns a result array on success, or `null` + * otherwise. + * `/Wo/.exec("Hello World")` will return: + * ``` + * [ + * "Wo", + * "index": 6, + * "input": "Hello World" + * ] + * ``` + * Or with groups `/W(o)rld/.exec("Hello World")` returns: + * ``` + * [ + * "World", + * "o", "index": 6, + * "input": "Hello World" + * ] + * ``` + * + * @param {any} str - A string to match on + * @returns {any} A result array, or null + * @url http://www.espruino.com/Reference#l_RegExp_exec + */ + exec(str: any): any; + + /** + * Test this regex on a string - returns `true` on a successful match, or `false` + * otherwise + * + * @param {any} str - A string to match on + * @returns {boolean} true for a match, or false + * @url http://www.espruino.com/Reference#l_RegExp_test + */ + test(str: any): boolean; +} + +/** + * The built-in class for handling Regular Expressions + * **Note:** Espruino's regular expression parser does not contain all the features + * present in a full ES6 JS engine. However it does contain support for the all the + * basics. + * @url http://www.espruino.com/Reference#RegExp + */ +declare const RegExp: RegExpConstructor + +/** + * This is the built-in class for the Arduino-style pin namings on ST Nucleo boards + * @url http://www.espruino.com/Reference#Nucleo + */ +declare class Nucleo { + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_A0 + */ + static A0: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_A1 + */ + static A1: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_A2 + */ + static A2: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_A3 + */ + static A3: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_A4 + */ + static A4: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_A5 + */ + static A5: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D0 + */ + static D0: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D1 + */ + static D1: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D2 + */ + static D2: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D3 + */ + static D3: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D4 + */ + static D4: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D5 + */ + static D5: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D6 + */ + static D6: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D7 + */ + static D7: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D8 + */ + static D8: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D9 + */ + static D9: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D10 + */ + static D10: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D11 + */ + static D11: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D12 + */ + static D12: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D13 + */ + static D13: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D14 + */ + static D14: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_Nucleo_D15 + */ + static D15: Pin; + + +} + +/** + * This is a built-in class to allow you to use the ESP8266 NodeMCU boards's pin + * namings to access pins. It is only available on ESP8266-based boards. + * @url http://www.espruino.com/Reference#NodeMCU + */ +declare class NodeMCU { + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_A0 + */ + static A0: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D0 + */ + static D0: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D1 + */ + static D1: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D2 + */ + static D2: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D3 + */ + static D3: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D4 + */ + static D4: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D5 + */ + static D5: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D6 + */ + static D6: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D7 + */ + static D7: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D8 + */ + static D8: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D9 + */ + static D9: Pin; + + /** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l_NodeMCU_D10 + */ + static D10: Pin; + + +} + +/** + * Class containing utility functions for the + * [ESP32](http://www.espruino.com/ESP32) + * @url http://www.espruino.com/Reference#ESP32 + */ +declare class ESP32 { + /** + * + * @param {Pin} pin - Pin for Analog read + * @param {number} atten - Attenuate factor + * @url http://www.espruino.com/Reference#l_ESP32_setAtten + */ + static setAtten(pin: Pin, atten: number): void; + + /** + * Perform a hardware reset/reboot of the ESP32. + * @url http://www.espruino.com/Reference#l_ESP32_reboot + */ + static reboot(): void; + + /** + * Put device in deepsleep state for "us" microseconds. + * + * @param {number} us - Sleeptime in us + * @url http://www.espruino.com/Reference#l_ESP32_deepSleep + */ + static deepSleep(us: number): void; + + /** + * Returns an object that contains details about the state of the ESP32 with the + * following fields: + * * `sdkVersion` - Version of the SDK. + * * `freeHeap` - Amount of free heap in bytes. + * * `BLE` - Status of BLE, enabled if true. + * * `Wifi` - Status of Wifi, enabled if true. + * * `minHeap` - Minimum heap, calculated by heap_caps_get_minimum_free_size + * @returns {any} The state of the ESP32 + * @url http://www.espruino.com/Reference#l_ESP32_getState + */ + static getState(): any; + + /** + * + * @param {number} level - which events should be shown (GATTS, GATTC, GAP) + * @url http://www.espruino.com/Reference#l_ESP32_setBLE_Debug + */ + static setBLE_Debug(level: number): void; + + /** + * Switches Bluetooth off/on, removes saved code from Flash, resets the board, and + * on restart creates jsVars depending on available heap (actual additional 1800) + * + * @param {boolean} enable - switches Bluetooth on or off + * @url http://www.espruino.com/Reference#l_ESP32_enableBLE + */ + static enableBLE(enable: boolean): void; + + /** + * Switches Wifi off/on, removes saved code from Flash, resets the board, and on + * restart creates jsVars depending on available heap (actual additional 3900) + * + * @param {boolean} enable - switches Wifi on or off + * @url http://www.espruino.com/Reference#l_ESP32_enableWifi + */ + static enableWifi(enable: boolean): void; + + +} + +/** + * A class to support some simple Queue handling for RTOS queues + * @url http://www.espruino.com/Reference#Queue + */ +declare class Queue { + /** + * Creates a Queue Object + * @constructor + * + * @param {any} queueName - Name of the queue + * @returns {any} A Queue object + * @url http://www.espruino.com/Reference#l_Queue_Queue + */ + static new(queueName: any): any; + + /** + * reads one character from queue, if available + * @url http://www.espruino.com/Reference#l_Queue_read + */ + read(): void; + + /** + * Writes one character to queue + * + * @param {any} char - char to be send + * @url http://www.espruino.com/Reference#l_Queue_writeChar + */ + writeChar(char: any): void; + + /** + * logs list of queues + * @url http://www.espruino.com/Reference#l_Queue_log + */ + log(): void; +} + +/** + * A class to support some simple Task handling for RTOS tasks + * @url http://www.espruino.com/Reference#Task + */ +declare class Task { + /** + * Creates a Task Object + * @constructor + * + * @param {any} taskName - Name of the task + * @returns {any} A Task object + * @url http://www.espruino.com/Reference#l_Task_Task + */ + static new(taskName: any): any; + + /** + * Suspend task, be careful not to suspend Espruino task itself + * @url http://www.espruino.com/Reference#l_Task_suspend + */ + suspend(): void; + + /** + * Resumes a suspended task + * @url http://www.espruino.com/Reference#l_Task_resume + */ + resume(): void; + + /** + * returns name of actual task + * @returns {any} Name of current task + * @url http://www.espruino.com/Reference#l_Task_getCurrent + */ + getCurrent(): any; + + /** + * Sends a binary notify to task + * @url http://www.espruino.com/Reference#l_Task_notify + */ + notify(): void; + + /** + * logs list of tasks + * @url http://www.espruino.com/Reference#l_Task_log + */ + log(): void; +} + +/** + * A class to handle Timer on base of ESP32 Timer + * @url http://www.espruino.com/Reference#Timer + */ +declare class Timer { + /** + * Creates a Timer Object + * @constructor + * + * @param {any} timerName - Timer Name + * @param {number} group - Timer group + * @param {number} index - Timer index + * @param {number} isrIndex - isr (0 = Espruino, 1 = test) + * @returns {any} A Timer Object + * @url http://www.espruino.com/Reference#l_Timer_Timer + */ + static new(timerName: any, group: number, index: number, isrIndex: number): any; + + /** + * Starts a timer + * + * @param {number} duration - duration of timmer in micro secs + * @url http://www.espruino.com/Reference#l_Timer_start + */ + start(duration: number): void; + + /** + * Reschedules a timer, needs to be started at least once + * + * @param {number} duration - duration of timmer in micro secs + * @url http://www.espruino.com/Reference#l_Timer_reschedule + */ + reschedule(duration: number): void; + + /** + * logs list of timers + * @url http://www.espruino.com/Reference#l_Timer_log + */ + log(): void; +} + +interface BooleanConstructor { + /** + * Creates a boolean + * @constructor + * + * @param {any} value - A single value to be converted to a number + * @returns {boolean} A Boolean object + * @url http://www.espruino.com/Reference#l_Boolean_Boolean + */ + new(value: any): boolean; +} + +interface Boolean { + +} + + +declare const Boolean: BooleanConstructor + +// GLOBALS + +/** + * **Note:** This function is only available on the [BBC micro:bit](/MicroBit) + * board + * Show an image on the in-built 5x5 LED screen. + * Image can be: + * * A number where each bit represents a pixel (so 25 bits). eg. `5` or + * `0x1FFFFFF` + * * A string, eg: `show("10001")`. Newlines are ignored, and anything that is not + * a space or `0` is treated as a 1. + * * An array of 4 bytes (more will be ignored), eg `show([1,2,3,0])` + * For instance the following works for images: + * ``` + * show("# #"+ + * " # "+ + * " # "+ + * "# #"+ + * " ### ") + * ``` + * This means you can also use Espruino's graphics library: + * ``` + * var g = Graphics.createArrayBuffer(5,5,1) + * g.drawString("E",0,0) + * show(g.buffer) + * ``` + * + * @param {any} image - The image to show + * @url http://www.espruino.com/Reference#l__global_show + */ +declare function show(image: any): void; + +/** + * **Note:** This function is only available on the [BBC micro:bit](/MicroBit) + * board + * Get the current acceleration of the micro:bit from the on-board accelerometer + * **This is deprecated.** Please use `Microbit.accel` instead. + * @returns {any} An object with x, y, and z fields in it + * @url http://www.espruino.com/Reference#l__global_acceleration + */ +declare function acceleration(): any; + +/** + * **Note:** This function is only available on the [BBC micro:bit](/MicroBit) + * board + * Get the current compass position for the micro:bit from the on-board + * magnetometer + * **This is deprecated.** Please use `Microbit.mag` instead. + * @returns {any} An object with x, y, and z fields in it + * @url http://www.espruino.com/Reference#l__global_compass + */ +declare function compass(): any; + +/** + * The pin connected to the 'A' button. Reads as `1` when pressed, `0` when not + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_BTNA + */ +declare const BTNA: Pin; + +/** + * The pin connected to the 'B' button. Reads as `1` when pressed, `0` when not + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_BTNB + */ +declare const BTNB: Pin; + +/** + * The pin connected to the up button. Reads as `1` when pressed, `0` when not + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_BTNU + */ +declare const BTNU: Pin; + +/** + * The pin connected to the down button. Reads as `1` when pressed, `0` when not + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_BTND + */ +declare const BTND: Pin; + +/** + * The pin connected to the left button. Reads as `1` when pressed, `0` when not + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_BTNL + */ +declare const BTNL: Pin; + +/** + * The pin connected to the right button. Reads as `1` when pressed, `0` when not + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_BTNR + */ +declare const BTNR: Pin; + +/** + * The pin connected to Corner #1 + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_CORNER1 + */ +declare const CORNER1: Pin; + +/** + * The pin connected to Corner #2 + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_CORNER2 + */ +declare const CORNER2: Pin; + +/** + * The pin connected to Corner #3 + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_CORNER3 + */ +declare const CORNER3: Pin; + +/** + * The pin connected to Corner #4 + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_CORNER4 + */ +declare const CORNER4: Pin; + +/** + * The pin connected to Corner #5 + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_CORNER5 + */ +declare const CORNER5: Pin; + +/** + * The pin connected to Corner #6 + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_CORNER6 + */ +declare const CORNER6: Pin; + +/** + * On Puck.js V2 (not v1.0) this is the pin that controls the FET, for high-powered + * outputs. + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_FET + */ +declare const FET: Pin; + +/** + * The pin marked SDA on the Arduino pin footprint. This is connected directly to + * pin A4. + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_SDA + */ +declare const SDA: Pin; + +/** + * The pin marked SDA on the Arduino pin footprint. This is connected directly to + * pin A5. + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_SCL + */ +declare const SCL: Pin; + +/** + * The Bangle.js's vibration motor. + * @returns {Pin} + * @url http://www.espruino.com/Reference#l__global_VIBRATE + */ +declare const VIBRATE: Pin; + +/** + * On most Espruino board there are LEDs, in which case `LED` will be an actual + * Pin. + * On Bangle.js there are no LEDs, so to remain compatible with example code that + * might expect an LED, this is an object that behaves like a pin, but which just + * displays a circle on the display + * @returns {any} A `Pin` object for a fake LED which appears on + * @url http://www.espruino.com/Reference#l__global_LED + */ +declare const LED: any; + +/** + * On most Espruino board there are LEDs, in which case `LED1` will be an actual + * Pin. + * On Bangle.js there are no LEDs, so to remain compatible with example code that + * might expect an LED, this is an object that behaves like a pin, but which just + * displays a circle on the display + * @returns {any} A `Pin` object for a fake LED which appears on + * @url http://www.espruino.com/Reference#l__global_LED1 + */ +declare const LED1: any; + +/** + * On most Espruino board there are LEDs, in which case `LED2` will be an actual + * Pin. + * On Bangle.js there are no LEDs, so to remain compatible with example code that + * might expect an LED, this is an object that behaves like a pin, but which just + * displays a circle on the display + * @returns {any} A `Pin` object for a fake LED which appears on + * @url http://www.espruino.com/Reference#l__global_LED2 + */ +declare const LED2: any; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_MOS1 + */ +declare const MOS1: Pin; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_MOS2 + */ +declare const MOS2: Pin; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_MOS3 + */ +declare const MOS3: Pin; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_MOS4 + */ +declare const MOS4: Pin; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_IOEXT0 + */ +declare const IOEXT0: Pin; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_IOEXT1 + */ +declare const IOEXT1: Pin; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_IOEXT2 + */ +declare const IOEXT2: Pin; + +/** + * @returns {Pin} A Pin + * @url http://www.espruino.com/Reference#l__global_IOEXT3 + */ +declare const IOEXT3: Pin; + +/** + * @returns {number} Not a Number + * @url http://www.espruino.com/Reference#l__global_NaN + */ +declare const NaN: number; + +/** + * @returns {number} Positive Infinity (1/0) + * @url http://www.espruino.com/Reference#l__global_Infinity + */ +declare const Infinity: number; + +/** + * @returns {number} Logic 1 for Arduino compatibility - this is the same as just typing `1` + * @url http://www.espruino.com/Reference#l__global_HIGH + */ +declare const HIGH: 1; + +/** + * @returns {number} Logic 0 for Arduino compatibility - this is the same as just typing `0` + * @url http://www.espruino.com/Reference#l__global_LOW + */ +declare const LOW: 0; + +/** + * A variable containing the arguments given to the function: + * ``` + * function hello() { + * console.log(arguments.length, JSON.stringify(arguments)); + * } + * hello() // 0 [] + * hello("Test") // 1 ["Test"] + * hello(1,2,3) // 3 [1,2,3] + * ``` + * **Note:** Due to the way Espruino works this is doesn't behave exactly the same + * as in normal JavaScript. The length of the arguments array will never be less + * than the number of arguments specified in the function declaration: + * `(function(a){ return arguments.length; })() == 1`. Normal JavaScript + * interpreters would return `0` in the above case. + * @returns {any} An array containing all the arguments given to the function + * @url http://www.espruino.com/Reference#l__global_arguments + */ +declare const arguments: any; + +/** + * Evaluate a string containing JavaScript code + * + * @param {any} code + * @returns {any} The result of evaluating the string + * @url http://www.espruino.com/Reference#l__global_eval + */ +declare function eval(code: any): any; + +/** + * Convert a string representing a number into an integer + * + * @param {any} string + * @param {any} radix - The Radix of the string (optional) + * @returns {any} The integer value of the string (or NaN) + * @url http://www.espruino.com/Reference#l__global_parseInt + */ +declare function parseInt(string: any, radix: any): any; + +/** + * Convert a string representing a number into an float + * + * @param {any} string + * @returns {number} The value of the string + * @url http://www.espruino.com/Reference#l__global_parseFloat + */ +declare function parseFloat(string: any): number; + +/** + * Is the parameter a finite num,ber or not? If needed, the parameter is first + * converted to a number. + * + * @param {any} x + * @returns {boolean} True is the value is a Finite number, false if not. + * @url http://www.espruino.com/Reference#l__global_isFinite + */ +declare function isFinite(x: any): boolean; + +/** + * Whether the x is NaN (Not a Number) or not + * + * @param {any} x + * @returns {boolean} True is the value is NaN, false if not. + * @url http://www.espruino.com/Reference#l__global_isNaN + */ +declare function isNaN(x: any): boolean; + +/** + * Encode the supplied string (or array) into a base64 string + * + * @param {any} binaryData - A string of data to encode + * @returns {any} A base64 encoded string + * @url http://www.espruino.com/Reference#l__global_btoa + */ +declare function btoa(binaryData: any): any; + +/** + * Decode the supplied base64 string into a normal string + * + * @param {any} base64Data - A string of base64 data to decode + * @returns {any} A string containing the decoded data + * @url http://www.espruino.com/Reference#l__global_atob + */ +declare function atob(base64Data: any): any; + +/** + * Convert a string with any character not alphanumeric or `- _ . ! ~ * ' ( )` + * converted to the form `%XY` where `XY` is its hexadecimal representation + * + * @param {any} str - A string to encode as a URI + * @returns {any} A string containing the encoded data + * @url http://www.espruino.com/Reference#l__global_encodeURIComponent + */ +declare function encodeURIComponent(str: any): any; + +/** + * Convert any groups of characters of the form '%ZZ', into characters with hex + * code '0xZZ' + * + * @param {any} str - A string to decode from a URI + * @returns {any} A string containing the decoded data + * @url http://www.espruino.com/Reference#l__global_decodeURIComponent + */ +declare function decodeURIComponent(str: any): any; + +/** + * Load the given module, and return the exported functions and variables. + * For example: + * ``` + * var s = require("Storage"); + * s.write("test", "hello world"); + * print(s.read("test")); + * // prints "hello world" + * ``` + * Check out [the page on Modules](/Modules) for an explanation of what modules are + * and how you can use them. + * + * @param {any} moduleName - A String containing the name of the given module + * @returns {any} The result of evaluating the string + * @url http://www.espruino.com/Reference#l__global_require + */ +declare function require(moduleName: T): Libraries[T]; +declare function require>(moduleName: T): any; + +/** + * Read 8 bits of memory at the given location - DANGEROUS! + * + * @param {number} addr - The address in memory to read + * @param {number} count - (optional) the number of items to read. If >1 a Uint8Array will be returned. + * @returns {any} The value of memory at the given location + * @url http://www.espruino.com/Reference#l__global_peek8 + */ +declare function peek8(addr: number, count?: 1): number; +declare function peek8(addr: number, count: number): Uint8Array; + +/** + * Write 8 bits of memory at the given location - VERY DANGEROUS! + * + * @param {number} addr - The address in memory to write + * @param {any} value - The value to write, or an array of values + * @url http://www.espruino.com/Reference#l__global_poke8 + */ +declare function poke8(addr: number, value: number | number[]): void; + +/** + * Read 16 bits of memory at the given location - DANGEROUS! + * + * @param {number} addr - The address in memory to read + * @param {number} count - (optional) the number of items to read. If >1 a Uint16Array will be returned. + * @returns {any} The value of memory at the given location + * @url http://www.espruino.com/Reference#l__global_peek16 + */ +declare function peek16(addr: number, count?: 1): number; +declare function peek16(addr: number, count: number): Uint8Array; + +/** + * Write 16 bits of memory at the given location - VERY DANGEROUS! + * + * @param {number} addr - The address in memory to write + * @param {any} value - The value to write, or an array of values + * @url http://www.espruino.com/Reference#l__global_poke16 + */ +declare function poke16(addr: number, value: number | number[]): void; + +/** + * Read 32 bits of memory at the given location - DANGEROUS! + * + * @param {number} addr - The address in memory to read + * @param {number} count - (optional) the number of items to read. If >1 a Uint32Array will be returned. + * @returns {any} The value of memory at the given location + * @url http://www.espruino.com/Reference#l__global_peek32 + */ +declare function peek32(addr: number, count?: 1): number; +declare function peek32(addr: number, count: number): Uint8Array; + +/** + * Write 32 bits of memory at the given location - VERY DANGEROUS! + * + * @param {number} addr - The address in memory to write + * @param {any} value - The value to write, or an array of values + * @url http://www.espruino.com/Reference#l__global_poke32 + */ +declare function poke32(addr: number, value: number | number[]): void; + +/** + * Get the analog value of the given pin + * This is different to Arduino which only returns an integer between 0 and 1023 + * However only pins connected to an ADC will work (see the datasheet) + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset pin's state to `"analog"` + * + * @param {Pin} pin + * The pin to use + * You can find out which pins to use by looking at [your board's reference page](#boards) and searching for pins with the `ADC` markers. + * @returns {number} The analog Value of the Pin between 0 and 1 + * @url http://www.espruino.com/Reference#l__global_analogRead + */ +declare function analogRead(pin: Pin): number; + +/** + * Set the analog Value of a pin. It will be output using PWM. + * Objects can contain: + * * `freq` - pulse frequency in Hz, eg. ```analogWrite(A0,0.5,{ freq : 10 });``` - + * specifying a frequency will force PWM output, even if the pin has a DAC + * * `soft` - boolean, If true software PWM is used if hardware is not available. + * * `forceSoft` - boolean, If true software PWM is used even if hardware PWM or a + * DAC is available + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset pin's state to `"output"` + * + * @param {Pin} pin + * The pin to use + * You can find out which pins to use by looking at [your board's reference page](#boards) and searching for pins with the `PWM` or `DAC` markers. + * @param {number} value - A value between 0 and 1 + * @param {any} options + * An object containing options for analog output - see below + * @url http://www.espruino.com/Reference#l__global_analogWrite + */ +declare function analogWrite(pin: Pin, value: number, options?: { freq?: number, soft?: boolean, forceSoft?: boolean }): void; + +/** + * Pulse the pin with the value for the given time in milliseconds. It uses a + * hardware timer to produce accurate pulses, and returns immediately (before the + * pulse has finished). Use `digitalPulse(A0,1,0)` to wait until a previous pulse + * has finished. + * eg. `digitalPulse(A0,1,5);` pulses A0 high for 5ms. + * `digitalPulse(A0,1,[5,2,4]);` pulses A0 high for 5ms, low for 2ms, and high for + * 4ms + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset pin's state to `"output"` + * digitalPulse is for SHORT pulses that need to be very accurate. If you're doing + * anything over a few milliseconds, use setTimeout instead. + * + * @param {Pin} pin - The pin to use + * @param {boolean} value - Whether to pulse high (true) or low (false) + * @param {any} time - A time in milliseconds, or an array of times (in which case a square wave will be output starting with a pulse of 'value') + * @url http://www.espruino.com/Reference#l__global_digitalPulse + */ +declare function digitalPulse(pin: Pin, value: boolean, time: number | number[]): void; + +/** + * Set the digital value of the given pin. + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset pin's state to `"output"` + * If pin argument is an array of pins (eg. `[A2,A1,A0]`) the value argument will + * be treated as an array of bits where the last array element is the least + * significant bit. + * In this case, pin values are set least significant bit first (from the + * right-hand side of the array of pins). This means you can use the same pin + * multiple times, for example `digitalWrite([A1,A1,A0,A0],0b0101)` would pulse A0 + * followed by A1. + * If the pin argument is an object with a `write` method, the `write` method will + * be called with the value passed through. + * + * @param {any} pin - The pin to use + * @param {number} value - Whether to pulse high (true) or low (false) + * @url http://www.espruino.com/Reference#l__global_digitalWrite + */ +declare function digitalWrite(pin: Pin, value: typeof HIGH | typeof LOW): void; + +/** + * Get the digital value of the given pin. + * **Note:** if you didn't call `pinMode` beforehand then this function will also + * reset pin's state to `"input"` + * If the pin argument is an array of pins (eg. `[A2,A1,A0]`) the value returned + * will be an number where the last array element is the least significant bit, for + * example if `A0=A1=1` and `A2=0`, `digitalRead([A2,A1,A0]) == 0b011` + * If the pin argument is an object with a `read` method, the `read` method will be + * called and the integer value it returns passed back. + * + * @param {any} pin - The pin to use + * @returns {number} The digital Value of the Pin + * @url http://www.espruino.com/Reference#l__global_digitalRead + */ +declare function digitalRead(pin: Pin): number; + +/** + * Set the mode of the given pin. + * * `auto`/`undefined` - Don't change state, but allow `digitalWrite`/etc to + * automatically change state as appropriate + * * `analog` - Analog input + * * `input` - Digital input + * * `input_pullup` - Digital input with internal ~40k pull-up resistor + * * `input_pulldown` - Digital input with internal ~40k pull-down resistor + * * `output` - Digital output + * * `opendrain` - Digital output that only ever pulls down to 0v. Sending a + * logical `1` leaves the pin open circuit + * * `opendrain_pullup` - Digital output that pulls down to 0v. Sending a logical + * `1` enables internal ~40k pull-up resistor + * * `af_output` - Digital output from built-in peripheral + * * `af_opendrain` - Digital output from built-in peripheral that only ever pulls + * down to 0v. Sending a logical `1` leaves the pin open circuit + * **Note:** `digitalRead`/`digitalWrite`/etc set the pin mode automatically + * *unless* `pinMode` has been called first. If you want `digitalRead`/etc to set + * the pin mode automatically after you have called `pinMode`, simply call it again + * with no mode argument (`pinMode(pin)`), `auto` as the argument (`pinMode(pin, + * "auto")`), or with the 3rd 'automatic' argument set to true (`pinMode(pin, + * "output", true)`). + * + * @param {Pin} pin - The pin to set pin mode for + * @param {any} mode - The mode - a string that is either 'analog', 'input', 'input_pullup', 'input_pulldown', 'output', 'opendrain', 'af_output' or 'af_opendrain'. Do not include this argument or use 'auto' if you want to revert to automatic pin mode setting. + * @param {boolean} automatic - Optional, default is false. If true, subsequent commands will automatically change the state (see notes below) + * @url http://www.espruino.com/Reference#l__global_pinMode + */ +declare function pinMode(pin: Pin, mode?: PinMode | "auto", automatic?: boolean): void; + +/** + * Return the current mode of the given pin. See `pinMode` for more information on + * returned values. + * + * @param {Pin} pin - The pin to check + * @returns {any} The pin mode, as a string + * @url http://www.espruino.com/Reference#l__global_getPinMode + */ +declare function getPinMode(pin: Pin): PinMode; + +/** + * Shift an array of data out using the pins supplied *least significant bit + * first*, for example: + * ``` + * // shift out to single clk+data + * shiftOut(A0, { clk : A1 }, [1,0,1,0]); + * ``` + * ``` + * // shift out a whole byte (like software SPI) + * shiftOut(A0, { clk : A1, repeat: 8 }, [1,2,3,4]); + * ``` + * ``` + * // shift out via 4 data pins + * shiftOut([A3,A2,A1,A0], { clk : A4 }, [1,2,3,4]); + * ``` + * `options` is an object of the form: + * ``` + * { + * clk : pin, // a pin to use as the clock (undefined = no pin) + * clkPol : bool, // clock polarity - default is 0 (so 1 normally, pulsing to 0 to clock data in) + * repeat : int, // number of clocks per array item + * } + * ``` + * Each item in the `data` array will be output to the pins, with the first pin in + * the array being the MSB and the last the LSB, then the clock will be pulsed in + * the polarity given. + * `repeat` is the amount of times shift data out for each array item. For instance + * we may want to shift 8 bits out through 2 pins - in which case we need to set + * repeat to 4. + * + * @param {any} pins - A pin, or an array of pins to use + * @param {any} options - Options, for instance the clock (see below) + * @param {any} data - The data to shift out (see `E.toUint8Array` for info on the forms this can take) + * @url http://www.espruino.com/Reference#l__global_shiftOut + */ +declare function shiftOut(pins: Pin | Pin[], options: { clk?: Pin, clkPol?: boolean, repeat?: number }, data: Uint8ArrayResolvable): void; + +/** + * Call the function specified when the pin changes. Watches set with `setWatch` + * can be removed using `clearWatch`. + * If the `options` parameter is an object, it can contain the following + * information (all optional): + * ``` + * { + * // Whether to keep producing callbacks, or remove the watch after the first callback + * repeat: true/false(default), + * // Trigger on the rising or falling edge of the signal. Can be a string, or 1='rising', -1='falling', 0='both' + * edge:'rising'(default for built-in buttons)/'falling'/'both'(default for pins), + * // Use software-debouncing to stop multiple calls if a switch bounces + * // This is the time in milliseconds to wait for bounces to subside, or 0 to disable + * debounce:10 (0 is default for pins, 25 is default for built-in buttons), + * // Advanced: If the function supplied is a 'native' function (compiled or assembly) + * // setting irq:true will call that function in the interrupt itself + * irq : false(default) + * // Advanced: If specified, the given pin will be read whenever the watch is called + * // and the state will be included as a 'data' field in the callback + * data : pin + * // Advanced: On Nordic devices, a watch may be 'high' or 'low' accuracy. By default low + * // accuracy is used (which is better for power consumption), but this means that + * // high speed pulses (less than 25us) may not be reliably received. Setting hispeed=true + * // allows for detecting high speed pulses at the expense of higher idle power consumption + * hispeed : true + * } + * ``` + * The `function` callback is called with an argument, which is an object of type + * `{state:bool, time:float, lastTime:float}`. + * * `state` is whether the pin is currently a `1` or a `0` + * * `time` is the time in seconds at which the pin changed state + * * `lastTime` is the time in seconds at which the **pin last changed state**. + * When using `edge:'rising'` or `edge:'falling'`, this is not the same as when + * the function was last called. + * * `data` is included if `data:pin` was specified in the options, and can be + * used for reading in clocked data + * For instance, if you want to measure the length of a positive pulse you could + * use `setWatch(function(e) { console.log(e.time-e.lastTime); }, BTN, { + * repeat:true, edge:'falling' });`. This will only be called on the falling edge + * of the pulse, but will be able to measure the width of the pulse because + * `e.lastTime` is the time of the rising edge. + * Internally, an interrupt writes the time of the pin's state change into a queue + * with the exact time that it happened, and the function supplied to `setWatch` is + * executed only from the main message loop. However, if the callback is a native + * function `void (bool state)` then you can add `irq:true` to options, which will + * cause the function to be called from within the IRQ. When doing this, interrupts + * will happen on both edges and there will be no debouncing. + * **Note:** if you didn't call `pinMode` beforehand then this function will reset + * pin's state to `"input"` + * **Note:** The STM32 chip (used in the [Espruino Board](/EspruinoBoard) and + * [Pico](/Pico)) cannot watch two pins with the same number - eg `A0` and `B0`. + * **Note:** On nRF52 chips (used in Puck.js, Pixl.js, MDBT42Q) `setWatch` disables + * the GPIO output on that pin. In order to be able to write to the pin again you + * need to disable the watch with `clearWatch`. + * + * @param {any} function - A Function or String to be executed + * @param {Pin} pin - The pin to watch + * @param {any} options - If a boolean or integer, it determines whether to call this once (false = default) or every time a change occurs (true). Can be an object of the form `{ repeat: true/false(default), edge:'rising'/'falling'/'both'(default), debounce:10}` - see below for more information. + * @returns {any} An ID that can be passed to clearWatch + * @url http://www.espruino.com/Reference#l__global_setWatch + */ +declare function setWatch(func: ((arg: { state: boolean, time: number, lastTime: number }) => void) | string, pin: Pin, options?: boolean | { repeat?: boolean, edge?: "rising" | "falling" | "both", debounce?: number, irq?: boolean, data?: Pin, hispeed?: boolean }): number; + +/** + * Clear the Watch that was created with setWatch. If no parameter is supplied, all watches will be removed. + * To avoid accidentally deleting all Watches, if a parameter is supplied but is `undefined` then an Exception will be thrown. + * + * @param {any} id - The id returned by a previous call to setWatch. **Only one argument is allowed.** + * @url http://www.espruino.com/Reference#l__global_clearWatch + */ +declare function clearWatch(id: number): void; + +declare const global: { + show: typeof show; + acceleration: typeof acceleration; + compass: typeof compass; + BTNA: typeof BTNA; + BTNB: typeof BTNB; + BTNU: typeof BTNU; + BTND: typeof BTND; + BTNL: typeof BTNL; + BTNR: typeof BTNR; + CORNER1: typeof CORNER1; + CORNER2: typeof CORNER2; + CORNER3: typeof CORNER3; + CORNER4: typeof CORNER4; + CORNER5: typeof CORNER5; + CORNER6: typeof CORNER6; + FET: typeof FET; + SDA: typeof SDA; + SCL: typeof SCL; + VIBRATE: typeof VIBRATE; + LED: typeof LED; + LED1: typeof LED1; + LED2: typeof LED2; + MOS1: typeof MOS1; + MOS2: typeof MOS2; + MOS3: typeof MOS3; + MOS4: typeof MOS4; + IOEXT0: typeof IOEXT0; + IOEXT1: typeof IOEXT1; + IOEXT2: typeof IOEXT2; + IOEXT3: typeof IOEXT3; + NaN: typeof NaN; + Infinity: typeof Infinity; + HIGH: typeof HIGH; + LOW: typeof LOW; + arguments: typeof arguments; + eval: typeof eval; + parseInt: typeof parseInt; + parseFloat: typeof parseFloat; + isFinite: typeof isFinite; + isNaN: typeof isNaN; + btoa: typeof btoa; + atob: typeof atob; + encodeURIComponent: typeof encodeURIComponent; + decodeURIComponent: typeof decodeURIComponent; + require: typeof require; + peek8: typeof peek8; + poke8: typeof poke8; + peek16: typeof peek16; + poke16: typeof poke16; + peek32: typeof peek32; + poke32: typeof poke32; + analogRead: typeof analogRead; + analogWrite: typeof analogWrite; + digitalPulse: typeof digitalPulse; + digitalWrite: typeof digitalWrite; + digitalRead: typeof digitalRead; + pinMode: typeof pinMode; + getPinMode: typeof getPinMode; + shiftOut: typeof shiftOut; + setWatch: typeof setWatch; + clearWatch: typeof clearWatch; + global: typeof global; + setBusyIndicator: typeof setBusyIndicator; + setSleepIndicator: typeof setSleepIndicator; + setDeepSleep: typeof setDeepSleep; + trace: typeof trace; + dump: typeof dump; + load: typeof load; + save: typeof save; + reset: typeof reset; + print: typeof print; + edit: typeof edit; + echo: typeof echo; + getTime: typeof getTime; + setTime: typeof setTime; + getSerial: typeof getSerial; + setInterval: typeof setInterval; + setTimeout: typeof setTimeout; + clearInterval: typeof clearInterval; + clearTimeout: typeof clearTimeout; + changeInterval: typeof changeInterval; + [key: string]: any; +} + +/** + * When Espruino is busy, set the pin specified here high. Set this to undefined to + * disable the feature. + * + * @param {any} pin + * @url http://www.espruino.com/Reference#l__global_setBusyIndicator + */ +declare function setBusyIndicator(pin: any): void; + +/** + * When Espruino is asleep, set the pin specified here low (when it's awake, set it + * high). Set this to undefined to disable the feature. + * Please see http://www.espruino.com/Power+Consumption for more details on this. + * + * @param {any} pin + * @url http://www.espruino.com/Reference#l__global_setSleepIndicator + */ +declare function setSleepIndicator(pin: any): void; + +/** + * Set whether we can enter deep sleep mode, which reduces power consumption to + * around 100uA. This only works on STM32 Espruino Boards (nRF52 boards sleep + * automatically). + * Please see http://www.espruino.com/Power+Consumption for more details on this. + * + * @param {boolean} sleep + * @url http://www.espruino.com/Reference#l__global_setDeepSleep + */ +declare function setDeepSleep(sleep: boolean): void; + +/** + * Output debugging information + * Note: This is not included on boards with low amounts of flash memory, or the + * Espruino board. + * + * @param {any} root - The symbol to output (optional). If nothing is specified, everything will be output + * @url http://www.espruino.com/Reference#l__global_trace + */ +declare function trace(root: any): void; + +/** + * Output current interpreter state in a text form such that it can be copied to a + * new device + * Espruino keeps its current state in RAM (even if the function code is stored in + * Flash). When you type `dump()` it dumps the current state of code in RAM plus + * the hardware state, then if there's code saved in flash it writes "// Code saved + * with E.setBootCode" and dumps that too. + * **Note:** 'Internal' functions are currently not handled correctly. You will + * need to recreate these in the `onInit` function. + * @url http://www.espruino.com/Reference#l__global_dump + */ +declare function dump(): void; + +/** + * Restart and load the program out of flash - this has an effect similar to + * completely rebooting Espruino (power off/power on), but without actually + * performing a full reset of the hardware. + * This command only executes when the Interpreter returns to the Idle state - for + * instance ```a=1;load();a=2;``` will still leave 'a' as undefined (or what it was + * set to in the saved program). + * Espruino will resume from where it was when you last typed `save()`. If you want + * code to be executed right after loading (for instance to initialise devices + * connected to Espruino), add an `init` event handler to `E` with `E.on('init', + * function() { ... your_code ... });`. This will then be automatically executed by + * Espruino every time it starts. + * **If you specify a filename in the argument then that file will be loaded from + * Storage after reset** in much the same way as calling `reset()` then + * `eval(require("Storage").read(filename))` + * + * @param {any} filename - optional: The name of a text JS file to load from Storage after reset + * @url http://www.espruino.com/Reference#l__global_load + */ +declare function load(filename: any): void; + +/** + * Save the state of the interpreter into flash (including the results of calling + * `setWatch`, `setInterval`, `pinMode`, and any listeners). The state will then be + * loaded automatically every time Espruino powers on or is hard-reset. To see what + * will get saved you can call `dump()`. + * **Note:** If you set up intervals/etc in `onInit()` and you have already called + * `onInit` before running `save()`, when Espruino resumes there will be two copies + * of your intervals - the ones from before the save, and the ones from after - + * which may cause you problems. + * For more information about this and other options for saving, please see the + * [Saving code on Espruino](https://www.espruino.com/Saving) page. + * This command only executes when the Interpreter returns to the Idle state - for + * instance ```a=1;save();a=2;``` will save 'a' as 2. + * When Espruino powers on, it will resume from where it was when you typed + * `save()`. If you want code to be executed right after loading (for instance to + * initialise devices connected to Espruino), add a function called `onInit`, or + * add a `init` event handler to `E` with `E.on('init', function() { ... your_code + * ... });`. This will then be automatically executed by Espruino every time it + * starts. + * In order to stop the program saved with this command being loaded automatically, + * check out [the Troubleshooting + * guide](https://www.espruino.com/Troubleshooting#espruino-stopped-working-after-i-typed-save-) + * @url http://www.espruino.com/Reference#l__global_save + */ +declare function save(): void; + +/** + * Reset the interpreter - clear program memory in RAM, and do not load a saved + * program from flash. This does NOT reset the underlying hardware (which allows + * you to reset the device without it disconnecting from USB). + * This command only executes when the Interpreter returns to the Idle state - for + * instance ```a=1;reset();a=2;``` will still leave 'a' as undefined. + * The safest way to do a full reset is to hit the reset button. + * If `reset()` is called with no arguments, it will reset the board's state in RAM + * but will not reset the state in flash. When next powered on (or when `load()` is + * called) the board will load the previously saved code. + * Calling `reset(true)` will cause *all saved code in flash memory to be cleared + * as well*. + * + * @param {boolean} clearFlash - Remove saved code from flash as well + * @url http://www.espruino.com/Reference#l__global_reset + */ +declare function reset(clearFlash: boolean): void; + +/** + * Print the supplied string(s) to the console + * **Note:** If you're connected to a computer (not a wall adaptor) via USB but + * **you are not running a terminal app** then when you print data Espruino may + * pause execution and wait until the computer requests the data it is trying to + * print. + * + * @param {any} text + * @url http://www.espruino.com/Reference#l__global_print + */ +declare function print(...text: any[]): void; + +/** + * Fill the console with the contents of the given function, so you can edit it. + * NOTE: This is a convenience function - it will not edit 'inner functions'. For + * that, you must edit the 'outer function' and re-execute it. + * + * @param {any} funcName - The name of the function to edit (either a string or just the unquoted name) + * @url http://www.espruino.com/Reference#l__global_edit + */ +declare function edit(funcName: any): void; + +/** + * Should Espruino echo what you type back to you? true = yes (Default), false = + * no. When echo is off, the result of executing a command is not returned. + * Instead, you must use 'print' to send output. + * + * @param {boolean} echoOn + * @url http://www.espruino.com/Reference#l__global_echo + */ +declare function echo(echoOn: boolean): void; + +/** + * Return the current system time in Seconds (as a floating point number) + * @returns {number} + * @url http://www.espruino.com/Reference#l__global_getTime + */ +declare function getTime(): number; + +/** + * Set the current system time in seconds (`time` can be a floating point value). + * This is used with `getTime`, the time reported from `setWatch`, as well as when + * using `new Date()`. + * `Date.prototype.getTime()` reports the time in milliseconds, so you can set the + * time to a `Date` object using: + * ``` + * setTime((new Date("Tue, 19 Feb 2019 10:57")).getTime()/1000) + * ``` + * To set the timezone for all new Dates, use `E.setTimeZone(hours)`. + * + * @param {number} time + * @url http://www.espruino.com/Reference#l__global_setTime + */ +declare function setTime(time: number): void; + +/** + * Get the serial number of this board + * @returns {any} The board's serial number + * @url http://www.espruino.com/Reference#l__global_getSerial + */ +declare function getSerial(): any; + +/** + * Call the function (or evaluate the string) specified REPEATEDLY after the + * timeout in milliseconds. + * For instance: + * ``` + * setInterval(function () { + * console.log("Hello World"); + * }, 1000); + * // or + * setInterval('console.log("Hello World");', 1000); + * // both print 'Hello World' every second + * ``` + * You can also specify extra arguments that will be sent to the function when it + * is executed. For example: + * ``` + * setInterval(function (a,b) { + * console.log(a+" "+b); + * }, 1000, "Hello", "World"); + * // prints 'Hello World' every second + * ``` + * If you want to stop your function from being called, pass the number that was + * returned by `setInterval` into the `clearInterval` function. + * **Note:** If `setDeepSleep(true)` has been called and the interval is greater + * than 5 seconds, Espruino may execute the interval up to 1 second late. This is + * because Espruino can only wake from deep sleep every second - and waking early + * would cause Espruino to waste power while it waited for the correct time. + * + * @param {any} function - A Function or String to be executed + * @param {number} timeout - The time between calls to the function (max 3153600000000 = 100 years + * @param {any} args - Optional arguments to pass to the function when executed + * @returns {any} An ID that can be passed to clearInterval + * @url http://www.espruino.com/Reference#l__global_setInterval + */ +declare function setInterval(func: any, timeout: number, ...args: any[]): any; + +/** + * Call the function (or evaluate the string) specified ONCE after the timeout in + * milliseconds. + * For instance: + * ``` + * setTimeout(function () { + * console.log("Hello World"); + * }, 1000); + * // or + * setTimeout('console.log("Hello World");', 1000); + * // both print 'Hello World' after a second + * ``` + * You can also specify extra arguments that will be sent to the function when it + * is executed. For example: + * ``` + * setTimeout(function (a,b) { + * console.log(a+" "+b); + * }, 1000, "Hello", "World"); + * // prints 'Hello World' after 1 second + * ``` + * If you want to stop the function from being called, pass the number that was + * returned by `setTimeout` into the `clearTimeout` function. + * **Note:** If `setDeepSleep(true)` has been called and the interval is greater + * than 5 seconds, Espruino may execute the interval up to 1 second late. This is + * because Espruino can only wake from deep sleep every second - and waking early + * would cause Espruino to waste power while it waited for the correct time. + * + * @param {any} function - A Function or String to be executed + * @param {number} timeout - The time until the function will be executed (max 3153600000000 = 100 years + * @param {any} args - Optional arguments to pass to the function when executed + * @returns {any} An ID that can be passed to clearTimeout + * @url http://www.espruino.com/Reference#l__global_setTimeout + */ +declare function setTimeout(func: any, timeout: number, ...args: any[]): any; + +/** + * Clear the Interval that was created with `setInterval`, for example: + * ```var id = setInterval(function () { print('foo'); }, 1000);``` + * ```clearInterval(id);``` + * If no argument is supplied, all timeouts and intervals are stopped. + * To avoid accidentally deleting all Intervals, if a parameter is supplied but is `undefined` then an Exception will be thrown. + * + * @param {any} id - The id returned by a previous call to setInterval. **Only one argument is allowed.** + * @url http://www.espruino.com/Reference#l__global_clearInterval + */ +declare function clearInterval(...id: any[]): void; + +/** + * Clear the Timeout that was created with `setTimeout`, for example: + * ```var id = setTimeout(function () { print('foo'); }, 1000);``` + * ```clearTimeout(id);``` + * If no argument is supplied, all timeouts and intervals are stopped. + * To avoid accidentally deleting all Timeouts, if a parameter is supplied but is `undefined` then an Exception will be thrown. + * + * @param {any} id - The id returned by a previous call to setTimeout. **Only one argument is allowed.** + * @url http://www.espruino.com/Reference#l__global_clearTimeout + */ +declare function clearTimeout(...id: any[]): void; + +/** + * Change the Interval on a callback created with `setInterval`, for example: + * ```var id = setInterval(function () { print('foo'); }, 1000); // every second``` + * ```changeInterval(id, 1500); // now runs every 1.5 seconds``` + * This takes effect immediately and resets the timeout, so in the example above, + * regardless of when you call `changeInterval`, the next interval will occur + * 1500ms after it. + * + * @param {any} id - The id returned by a previous call to setInterval + * @param {number} time - The new time period in ms + * @url http://www.espruino.com/Reference#l__global_changeInterval + */ +declare function changeInterval(id: any, time: number): void; + +// LIBRARIES + +type Libraries = { + /** + * @url http://www.espruino.com/Reference#tensorflow + */ + tensorflow: { + /** + * + * @param {number} arenaSize - The TensorFlow Arena size + * @param {any} model - The model to use - this should be a flat array/string + * @returns {any} A tensorflow instance + * @url http://www.espruino.com/Reference#l_tensorflow_create + */ + create(arenaSize: number, model: any): TFMicroInterpreter; + } + + /** + * This library handles interfacing with a FAT32 filesystem on an SD card. The API + * is designed to be similar to node.js's - However Espruino does not currently + * support asynchronous file IO, so the functions behave like node.js's xxxxSync + * functions. Versions of the functions with 'Sync' after them are also provided + * for compatibility. + * To use this, you must type ```var fs = require('fs')``` to get access to the + * library + * See [the page on File IO](http://www.espruino.com/File+IO) for more information, + * and for examples on wiring up an SD card if your device doesn't come with one. + * **Note:** If you want to remove an SD card after you have started using it, you + * *must* call `E.unmountSD()` or you may cause damage to the card. + * @url http://www.espruino.com/Reference#fs + */ + fs: { + /** + * List all files in the supplied directory, returning them as an array of strings. + * NOTE: Espruino does not yet support Async file IO, so this function behaves like + * the 'Sync' version. + * + * @param {any} path - The path of the directory to list. If it is not supplied, '' is assumed, which will list the root directory + * @returns {any} An array of filename strings (or undefined if the directory couldn't be listed) + * @url http://www.espruino.com/Reference#l_fs_readdir + */ + readdir(path: any): any; + + /** + * List all files in the supplied directory, returning them as an array of strings. + * + * @param {any} path - The path of the directory to list. If it is not supplied, '' is assumed, which will list the root directory + * @returns {any} An array of filename strings (or undefined if the directory couldn't be listed) + * @url http://www.espruino.com/Reference#l_fs_readdirSync + */ + readdirSync(path: any): any; + + /** + * Write the data to the given file + * NOTE: Espruino does not yet support Async file IO, so this function behaves like + * the 'Sync' version. + * + * @param {any} path - The path of the file to write + * @param {any} data - The data to write to the file + * @returns {boolean} True on success, false on failure + * @url http://www.espruino.com/Reference#l_fs_writeFile + */ + writeFile(path: any, data: any): boolean; + + /** + * Write the data to the given file + * + * @param {any} path - The path of the file to write + * @param {any} data - The data to write to the file + * @returns {boolean} True on success, false on failure + * @url http://www.espruino.com/Reference#l_fs_writeFileSync + */ + writeFileSync(path: any, data: any): boolean; + + /** + * Append the data to the given file, created a new file if it doesn't exist + * NOTE: Espruino does not yet support Async file IO, so this function behaves like + * the 'Sync' version. + * + * @param {any} path - The path of the file to write + * @param {any} data - The data to write to the file + * @returns {boolean} True on success, false on failure + * @url http://www.espruino.com/Reference#l_fs_appendFile + */ + appendFile(path: any, data: any): boolean; + + /** + * Append the data to the given file, created a new file if it doesn't exist + * + * @param {any} path - The path of the file to write + * @param {any} data - The data to write to the file + * @returns {boolean} True on success, false on failure + * @url http://www.espruino.com/Reference#l_fs_appendFileSync + */ + appendFileSync(path: any, data: any): boolean; + + /** + * Read all data from a file and return as a string + * NOTE: Espruino does not yet support Async file IO, so this function behaves like + * the 'Sync' version. + * + * @param {any} path - The path of the file to read + * @returns {any} A string containing the contents of the file (or undefined if the file doesn't exist) + * @url http://www.espruino.com/Reference#l_fs_readFile + */ + readFile(path: any): any; + + /** + * Read all data from a file and return as a string. + * **Note:** The size of files you can load using this method is limited by the + * amount of available RAM. To read files a bit at a time, see the `File` class. + * + * @param {any} path - The path of the file to read + * @returns {any} A string containing the contents of the file (or undefined if the file doesn't exist) + * @url http://www.espruino.com/Reference#l_fs_readFileSync + */ + readFileSync(path: any): any; + + /** + * Delete the given file + * NOTE: Espruino does not yet support Async file IO, so this function behaves like + * the 'Sync' version. + * + * @param {any} path - The path of the file to delete + * @returns {boolean} True on success, or false on failure + * @url http://www.espruino.com/Reference#l_fs_unlink + */ + unlink(path: any): boolean; + + /** + * Delete the given file + * + * @param {any} path - The path of the file to delete + * @returns {boolean} True on success, or false on failure + * @url http://www.espruino.com/Reference#l_fs_unlinkSync + */ + unlinkSync(path: any): boolean; + + /** + * Return information on the given file. This returns an object with the following + * fields: + * size: size in bytes dir: a boolean specifying if the file is a directory or not + * mtime: A Date structure specifying the time the file was last modified + * + * @param {any} path - The path of the file to get information on + * @returns {any} An object describing the file, or undefined on failure + * @url http://www.espruino.com/Reference#l_fs_statSync + */ + statSync(path: any): any; + + /** + * Create the directory + * NOTE: Espruino does not yet support Async file IO, so this function behaves like + * the 'Sync' version. + * + * @param {any} path - The name of the directory to create + * @returns {boolean} True on success, or false on failure + * @url http://www.espruino.com/Reference#l_fs_mkdir + */ + mkdir(path: any): boolean; + + /** + * Create the directory + * + * @param {any} path - The name of the directory to create + * @returns {boolean} True on success, or false on failure + * @url http://www.espruino.com/Reference#l_fs_mkdirSync + */ + mkdirSync(path: any): boolean; + + /** + * + * @param {any} source - The source file/stream that will send content. + * @param {any} destination - The destination file/stream that will receive content from the source. + * @param {any} options + * An optional object `{ chunkSize : int=64, end : bool=true, complete : function }` + * chunkSize : The amount of data to pipe from source to destination at a time + * complete : a function to call when the pipe activity is complete + * end : call the 'end' function on the destination when the source is finished + * @url http://www.espruino.com/Reference#l_fs_pipe + */ + pipe(source: any, destination: any, options: any): void; + } + + /** + * Cryptographic functions + * **Note:** This library is currently only included in builds for boards where + * there is space. For other boards there is `crypto.js` which implements SHA1 in + * JS. + * @url http://www.espruino.com/Reference#crypto + */ + crypto: { + /** + * Class containing AES encryption/decryption + * @returns {any} + * @url http://www.espruino.com/Reference#l_crypto_AES + */ + AES: AES; + + /** + * Performs a SHA1 hash and returns the result as a 20 byte ArrayBuffer. + * **Note:** On some boards (currently only Espruino Original) there isn't space + * for a fully unrolled SHA1 implementation so a slower all-JS implementation is + * used instead. + * + * @param {any} message - The message to apply the hash to + * @returns {any} Returns a 20 byte ArrayBuffer + * @url http://www.espruino.com/Reference#l_crypto_SHA1 + */ + SHA1(message: any): ArrayBuffer; + + /** + * Performs a SHA224 hash and returns the result as a 28 byte ArrayBuffer + * + * @param {any} message - The message to apply the hash to + * @returns {any} Returns a 20 byte ArrayBuffer + * @url http://www.espruino.com/Reference#l_crypto_SHA224 + */ + SHA224(message: any): ArrayBuffer; + + /** + * Performs a SHA256 hash and returns the result as a 32 byte ArrayBuffer + * + * @param {any} message - The message to apply the hash to + * @returns {any} Returns a 20 byte ArrayBuffer + * @url http://www.espruino.com/Reference#l_crypto_SHA256 + */ + SHA256(message: any): ArrayBuffer; + + /** + * Performs a SHA384 hash and returns the result as a 48 byte ArrayBuffer + * + * @param {any} message - The message to apply the hash to + * @returns {any} Returns a 20 byte ArrayBuffer + * @url http://www.espruino.com/Reference#l_crypto_SHA384 + */ + SHA384(message: any): ArrayBuffer; + + /** + * Performs a SHA512 hash and returns the result as a 64 byte ArrayBuffer + * + * @param {any} message - The message to apply the hash to + * @returns {any} Returns a 32 byte ArrayBuffer + * @url http://www.espruino.com/Reference#l_crypto_SHA512 + */ + SHA512(message: any): ArrayBuffer; + + /** + * Password-Based Key Derivation Function 2 algorithm, using SHA512 + * + * @param {any} passphrase - Passphrase + * @param {any} salt - Salt for turning passphrase into a key + * @param {any} options - Object of Options, `{ keySize: 8 (in 32 bit words), iterations: 10, hasher: 'SHA1'/'SHA224'/'SHA256'/'SHA384'/'SHA512' }` + * @returns {any} Returns an ArrayBuffer + * @url http://www.espruino.com/Reference#l_crypto_PBKDF2 + */ + PBKDF2(passphrase: any, salt: any, options: any): ArrayBuffer; + } + + /** + * Library that initialises a network device that calls into JavaScript + * @url http://www.espruino.com/Reference#NetworkJS + */ + NetworkJS: { + /** + * Initialise the network using the callbacks given and return the first argument. + * For instance: + * ``` + * require("NetworkJS").create({ + * create : function(host, port, socketType, options) { + * // Create a socket and return its index, host is a string, port is an integer. + * // If host isn't defined, create a server socket + * console.log("Create",host,port); + * return 1; + * }, + * close : function(sckt) { + * // Close the socket. returns nothing + * }, + * accept : function(sckt) { + * // Accept the connection on the server socket. Returns socket number or -1 if no connection + * return -1; + * }, + * recv : function(sckt, maxLen, socketType) { + * // Receive data. Returns a string (even if empty). + * // If non-string returned, socket is then closed + * return null;//or ""; + * }, + * send : function(sckt, data, socketType) { + * // Send data (as string). Returns the number of bytes sent - 0 is ok. + * // Less than 0 + * return data.length; + * } + * }); + * ``` + * `socketType` is an integer - 2 for UDP, or see SocketType in + * https://github.com/espruino/Espruino/blob/master/libs/network/network.h for more + * information. + * + * @param {any} obj - An object containing functions to access the network device + * @returns {any} The object passed in + * @url http://www.espruino.com/Reference#l_NetworkJS_create + */ + create(obj: any): any; + } + + /** + * This library implements a telnet console for the Espruino interpreter. It + * requires a network connection, e.g. Wifi, and **currently only functions on the + * ESP8266 and on Linux **. It uses port 23 on the ESP8266 and port 2323 on Linux. + * **Note:** To enable on Linux, run `./espruino --telnet` + * @url http://www.espruino.com/Reference#TelnetServer + */ + TelnetServer: { + /** + * + * @param {any} options - Options controlling the telnet console server `{ mode : 'on|off'}` + * @url http://www.espruino.com/Reference#l_TelnetServer_setOptions + */ + setOptions(options: any): void; + } + + /** + * This library allows you to create TCPIP servers and clients + * In order to use this, you will need an extra module to get network connectivity. + * This is designed to be a cut-down version of the [node.js + * library](http://nodejs.org/api/net.html). Please see the [Internet](/Internet) + * page for more information on how to use it. + * @url http://www.espruino.com/Reference#net + */ + net: { + /** + * Create a Server + * When a request to the server is made, the callback is called. In the callback + * you can use the methods on the connection to send data. You can also add + * `connection.on('data',function() { ... })` to listen for received data + * + * @param {any} callback - A `function(connection)` that will be called when a connection is made + * @returns {any} Returns a new Server Object + * @url http://www.espruino.com/Reference#l_net_createServer + */ + createServer(callback: any): Server; + + /** + * Create a TCP socket connection + * + * @param {any} options - An object containing host,port fields + * @param {any} callback - A `function(sckt)` that will be called with the socket when a connection is made. You can then call `sckt.write(...)` to send data, and `sckt.on('data', function(data) { ... })` and `sckt.on('close', function() { ... })` to deal with the response. + * @returns {any} Returns a new net.Socket object + * @url http://www.espruino.com/Reference#l_net_connect + */ + connect(options: any, callback: any): Socket; + } + + /** + * This library allows you to create UDP/DATAGRAM servers and clients + * In order to use this, you will need an extra module to get network connectivity. + * This is designed to be a cut-down version of the [node.js + * library](http://nodejs.org/api/dgram.html). Please see the [Internet](/Internet) + * page for more information on how to use it. + * @url http://www.espruino.com/Reference#dgram + */ + dgram: { + /** + * Create a UDP socket + * + * @param {any} type - Socket type to create e.g. 'udp4'. Or options object { type: 'udp4', reuseAddr: true, recvBufferSize: 1024 } + * @param {any} callback - A `function(sckt)` that will be called with the socket when a connection is made. You can then call `sckt.send(...)` to send data, and `sckt.on('message', function(data) { ... })` and `sckt.on('close', function() { ... })` to deal with the response. + * @returns {any} Returns a new dgram.Socket object + * @url http://www.espruino.com/Reference#l_dgram_createSocket + */ + createSocket(type: any, callback: any): dgramSocket; + } + + /** + * This library allows you to create TCPIP servers and clients using TLS encryption + * In order to use this, you will need an extra module to get network connectivity. + * This is designed to be a cut-down version of the [node.js + * library](http://nodejs.org/api/tls.html). Please see the [Internet](/Internet) + * page for more information on how to use it. + * @url http://www.espruino.com/Reference#tls + */ + tls: { + /** + * Create a socket connection using TLS + * Options can have `ca`, `key` and `cert` fields, which should be the decoded + * content of the certificate. + * ``` + * var options = url.parse("localhost:1234"); + * options.key = atob("MIIJKQ ... OZs08C"); + * options.cert = atob("MIIFi ... Uf93rN+"); + * options.ca = atob("MIIFgDCC ... GosQML4sc="); + * require("tls").connect(options, ... ); + * ``` + * If you have the certificates as `.pem` files, you need to load these files, take + * the information between the lines beginning with `----`, remove the newlines + * from it so you have raw base64, and then feed it into `atob` as above. + * You can also: + * * Just specify the filename (<=100 characters) and it will be loaded and parsed + * if you have an SD card connected. For instance `options.key = "key.pem";` + * * Specify a function, which will be called to retrieve the data. For instance + * `options.key = function() { eeprom.load_my_info(); }; + * For more information about generating and using certificates, see: + * https://engineering.circle.com/https-authorized-certs-with-node-js/ + * (You'll need to use 2048 bit certificates as opposed to 4096 bit shown above) + * + * @param {any} options - An object containing host,port fields + * @param {any} callback - A function(res) that will be called when a connection is made. You can then call `res.on('data', function(data) { ... })` and `res.on('close', function() { ... })` to deal with the response. + * @returns {any} Returns a new net.Socket object + * @url http://www.espruino.com/Reference#l_tls_connect + */ + connect(options: any, callback: any): Socket; + } + + /** + * @url http://www.espruino.com/Reference#CC3000 + */ + CC3000: { + /** + * Initialise the CC3000 and return a WLAN object + * + * @param {any} spi - Device to use for SPI (or undefined to use the default). SPI should be 1,000,000 baud, and set to 'mode 1' + * @param {Pin} cs - The pin to use for Chip Select + * @param {Pin} en - The pin to use for Enable + * @param {Pin} irq - The pin to use for Interrupts + * @returns {any} A WLAN Object + * @url http://www.espruino.com/Reference#l_CC3000_connect + */ + connect(spi: any, cs: Pin, en: Pin, irq: Pin): WLAN; + } + + /** + * Library for communication with the WIZnet Ethernet module + * @url http://www.espruino.com/Reference#WIZnet + */ + WIZnet: { + /** + * Initialise the WIZnet module and return an Ethernet object + * + * @param {any} spi - Device to use for SPI (or undefined to use the default) + * @param {Pin} cs - The pin to use for Chip Select + * @returns {any} An Ethernet Object + * @url http://www.espruino.com/Reference#l_WIZnet_connect + */ + connect(spi: any, cs: Pin): Ethernet; + } + + /** + * The Wifi library is designed to control the Wifi interface. It supports + * functionality such as connecting to wifi networks, getting network information, + * starting an access point, etc. + * It is available on these devices: + * * [Espruino WiFi](http://www.espruino.com/WiFi#using-wifi) + * * [ESP8266](http://www.espruino.com/EspruinoESP8266) + * * [ESP32](http://www.espruino.com/ESP32) + * **Certain features may or may not be implemented on your device** however we + * have documented what is available and what isn't. + * If you're not using one of the devices above, a separate WiFi library is + * provided. For instance: + * * An [ESP8266 connected to an Espruino + * board](http://www.espruino.com/ESP8266#software) + * * An [CC3000 WiFi Module](http://www.espruino.com/CC3000) + * [Other ways of connecting to the + * net](http://www.espruino.com/Internet#related-pages) such as GSM, Ethernet and + * LTE have their own libraries. + * You can use the WiFi library as follows: + * ``` + * var wifi = require("Wifi"); + * wifi.connect("my-ssid", {password:"my-pwd"}, function(ap){ console.log("connected:", ap); }); + * ``` + * On ESP32/ESP8266 if you want the connection to happen automatically at boot, add + * `wifi.save();`. On other platforms, place `wifi.connect` in a function called + * `onInit`. + * @url http://www.espruino.com/Reference#Wifi + */ + Wifi: { + /** + * The 'associated' event is called when an association with an access point has + * succeeded, i.e., a connection to the AP's network has been established. + * On ESP32/ESP8266 there is a `details` parameter which includes: + * * ssid - The SSID of the access point to which the association was established + * * mac - The BSSID/mac address of the access point + * * channel - The wifi channel used (an integer, typ 1..14) + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An object with event details + * @url http://www.espruino.com/Reference#l_Wifi_associated + */ + on(event: "associated", callback: (details: any) => void): void; + + /** + * The 'disconnected' event is called when an association with an access point has + * been lost. + * On ESP32/ESP8266 there is a `details` parameter which includes: + * * ssid - The SSID of the access point from which the association was lost + * * mac - The BSSID/mac address of the access point + * * reason - The reason for the disconnection (string) + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An object with event details + * @url http://www.espruino.com/Reference#l_Wifi_disconnected + */ + on(event: "disconnected", callback: (details: any) => void): void; + + /** + * The 'auth_change' event is called when the authentication mode with the + * associated access point changes. The details include: + * * oldMode - The old auth mode (string: open, wep, wpa, wpa2, wpa_wpa2) + * * newMode - The new auth mode (string: open, wep, wpa, wpa2, wpa_wpa2) + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An object with event details + * @url http://www.espruino.com/Reference#l_Wifi_auth_change + */ + on(event: "auth_change", callback: (details: any) => void): void; + + /** + * The 'dhcp_timeout' event is called when a DHCP request to the connected access + * point fails and thus no IP address could be acquired (or renewed). + * @param {string} event - The event to listen to. + * @param {() => void} callback - A function that is executed when the event occurs. + * @url http://www.espruino.com/Reference#l_Wifi_dhcp_timeout + */ + on(event: "dhcp_timeout", callback: () => void): void; + + /** + * The 'connected' event is called when the connection with an access point is + * ready for traffic. In the case of a dynamic IP address configuration this is + * when an IP address is obtained, in the case of static IP address allocation this + * happens when an association is formed (in that case the 'associated' and + * 'connected' events are fired in rapid succession). + * On ESP32/ESP8266 there is a `details` parameter which includes: + * * ip - The IP address obtained as string + * * netmask - The network's IP range mask as string + * * gw - The network's default gateway as string + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An object with event details + * @url http://www.espruino.com/Reference#l_Wifi_connected + */ + on(event: "connected", callback: (details: any) => void): void; + + /** + * The 'sta_joined' event is called when a station establishes an association (i.e. + * connects) with the esp8266's access point. The details include: + * * mac - The MAC address of the station in string format (00:00:00:00:00:00) + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An object with event details + * @url http://www.espruino.com/Reference#l_Wifi_sta_joined + */ + on(event: "sta_joined", callback: (details: any) => void): void; + + /** + * The 'sta_left' event is called when a station disconnects from the esp8266's + * access point (or its association times out?). The details include: + * * mac - The MAC address of the station in string format (00:00:00:00:00:00) + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An object with event details + * @url http://www.espruino.com/Reference#l_Wifi_sta_left + */ + on(event: "sta_left", callback: (details: any) => void): void; + + /** + * The 'probe_recv' event is called when a probe request is received from some + * station by the esp8266's access point. The details include: + * * mac - The MAC address of the station in string format (00:00:00:00:00:00) + * * rssi - The signal strength in dB of the probe request + * @param {string} event - The event to listen to. + * @param {(details: any) => void} callback - A function that is executed when the event occurs. Its arguments are: + * * `details` An object with event details + * @url http://www.espruino.com/Reference#l_Wifi_probe_recv + */ + on(event: "probe_recv", callback: (details: any) => void): void; + + /** + * Disconnect the wifi station from an access point and disable the station mode. + * It is OK to call `disconnect` to turn off station mode even if no connection + * exists (for example, connection attempts may be failing). Station mode can be + * re-enabled by calling `connect` or `scan`. + * + * @param {any} callback - An optional `callback()` function to be called back on disconnection. The callback function receives no argument. + * @url http://www.espruino.com/Reference#l_Wifi_disconnect + */ + disconnect(callback: any): void; + + /** + * Stop being an access point and disable the AP operation mode. AP mode can be + * re-enabled by calling `startAP`. + * + * @param {any} callback - An optional `callback()` function to be called back on successful stop. The callback function receives no argument. + * @url http://www.espruino.com/Reference#l_Wifi_stopAP + */ + stopAP(callback: any): void; + + /** + * Connect to an access point as a station. If there is an existing connection to + * an AP it is first disconnected if the SSID or password are different from those + * passed as parameters. Put differently, if the passed SSID and password are + * identical to the currently connected AP then nothing is changed. When the + * connection attempt completes the callback function is invoked with one `err` + * parameter, which is NULL if there is no error and a string message if there is + * an error. If DHCP is enabled the callback occurs once an IP addres has been + * obtained, if a static IP is set the callback occurs once the AP's network has + * been joined. The callback is also invoked if a connection already exists and + * does not need to be changed. + * The options properties may contain: + * * `password` - Password string to be used to access the network. + * * `dnsServers` (array of String) - An array of up to two DNS servers in dotted + * decimal format string. + * * `channel` - Wifi channel of the access point (integer, typ 0..14, 0 means any + * channel), only on ESP8266. + * * `bssid` - Mac address of the access point (string, type "00:00:00:00:00:00"), + * only on ESP8266. + * Notes: + * * the options should include the ability to set a static IP and associated + * netmask and gateway, this is a future enhancement. + * * the only error reported in the callback is "Bad password", all other errors + * (such as access point not found or DHCP timeout) just cause connection + * retries. If the reporting of such temporary errors is desired, the caller must + * use its own timeout and the `getDetails().status` field. + * * the `connect` call automatically enabled station mode, it can be disabled + * again by calling `disconnect`. + * + * @param {any} ssid - The access point network id. + * @param {any} options - Connection options (optional). + * @param {any} callback - A `callback(err)` function to be called back on completion. `err` is null on success, or contains an error string on failure. + * @url http://www.espruino.com/Reference#l_Wifi_connect + */ + connect(ssid: any, options: any, callback: any): void; + + /** + * Perform a scan for access points. This will enable the station mode if it is not + * currently enabled. Once the scan is complete the callback function is called + * with an array of APs found, each AP is an object with: + * * `ssid`: SSID string. + * * `mac`: access point MAC address in 00:00:00:00:00:00 format. + * * `authMode`: `open`, `wep`, `wpa`, `wpa2`, or `wpa_wpa2`. + * * `channel`: wifi channel 1..13. + * * `hidden`: true if the SSID is hidden (ESP32/ESP8266 only) + * * `rssi`: signal strength in dB in the range -110..0. + * Notes: + * * in order to perform the scan the station mode is turned on and remains on, use + * Wifi.disconnect() to turn it off again, if desired. + * * only one scan can be in progress at a time. + * + * @param {any} callback - A `callback(err, ap_list)` function to be called back on completion. `err==null` and `ap_list` is an array on success, or `err` is an error string and `ap_list` is undefined on failure. + * @url http://www.espruino.com/Reference#l_Wifi_scan + */ + scan(callback: any): void; + + /** + * Create a WiFi access point allowing stations to connect. If the password is NULL + * or an empty string the access point is open, otherwise it is encrypted. The + * callback function is invoked once the access point is set-up and receives one + * `err` argument, which is NULL on success and contains an error message string + * otherwise. + * The `options` object can contain the following properties. + * * `authMode` - The authentication mode to use. Can be one of "open", "wpa2", + * "wpa", "wpa_wpa2". The default is open (but open access points are not + * recommended). + * * `password` - The password for connecting stations if authMode is not open. + * * `channel` - The channel to be used for the access point in the range 1..13. If + * the device is also connected to an access point as a station then that access + * point determines the channel. + * * `hidden` - The flag if visible or not (0:visible, 1:hidden), default is + * visible. + * Notes: + * * the options should include the ability to set the AP IP and associated + * netmask, this is a future enhancement. + * * the `startAP` call automatically enables AP mode. It can be disabled again by + * calling `stopAP`. + * + * @param {any} ssid - The network id. + * @param {any} options - Configuration options (optional). + * @param {any} callback - Optional `callback(err)` function to be called when the AP is successfully started. `err==null` on success, or an error string on failure. + * @url http://www.espruino.com/Reference#l_Wifi_startAP + */ + startAP(ssid: any, options: any, callback: any): void; + + /** + * Retrieve the current overall WiFi configuration. This call provides general + * information that pertains to both station and access point modes. The getDetails + * and getAPDetails calls provide more in-depth information about the station and + * access point configurations, respectively. The status object has the following + * properties: + * * `station` - Status of the wifi station: `off`, `connecting`, ... + * * `ap` - Status of the wifi access point: `disabled`, `enabled`. + * * `mode` - The current operation mode: `off`, `sta`, `ap`, `sta+ap`. + * * `phy` - Modulation standard configured: `11b`, `11g`, `11n` (the esp8266 docs + * are not very clear, but it is assumed that 11n means b/g/n). This setting + * limits the modulations that the radio will use, it does not indicate the + * current modulation used with a specific access point. + * * `powersave` - Power saving mode: `none` (radio is on all the time), `ps-poll` + * (radio is off between beacons as determined by the access point's DTIM + * setting). Note that in 'ap' and 'sta+ap' modes the radio is always on, i.e., + * no power saving is possible. + * * `savedMode` - The saved operation mode which will be applied at boot time: + * `off`, `sta`, `ap`, `sta+ap`. + * + * @param {any} callback - Optional `callback(status)` function to be called back with the current Wifi status, i.e. the same object as returned directly. + * @returns {any} An object representing the current WiFi status, if available immediately. + * @url http://www.espruino.com/Reference#l_Wifi_getStatus + */ + getStatus(callback: any): any; + + /** + * Sets a number of global wifi configuration settings. All parameters are optional + * and which are passed determines which settings are updated. The settings + * available are: + * * `phy` - Modulation standard to allow: `11b`, `11g`, `11n` (the esp8266 docs + * are not very clear, but it is assumed that 11n means b/g/n). + * * `powersave` - Power saving mode: `none` (radio is on all the time), `ps-poll` + * (radio is off between beacons as determined by the access point's DTIM + * setting). Note that in 'ap' and 'sta+ap' modes the radio is always on, i.e., + * no power saving is possible. + * Note: esp8266 SDK programmers may be missing an "opmode" option to set the + * sta/ap/sta+ap operation mode. Please use connect/scan/disconnect/startAP/stopAP, + * which all set the esp8266 opmode indirectly. + * + * @param {any} settings - An object with the configuration settings to change. + * @url http://www.espruino.com/Reference#l_Wifi_setConfig + */ + setConfig(settings: any): void; + + /** + * Retrieve the wifi station configuration and status details. The details object + * has the following properties: + * * `status` - Details about the wifi station connection, one of `off`, + * `connecting`, `wrong_password`, `no_ap_found`, `connect_fail`, or `connected`. + * The off, bad_password and connected states are stable, the other states are + * transient. The connecting state will either result in connected or one of the + * error states (bad_password, no_ap_found, connect_fail) and the no_ap_found and + * connect_fail states will result in a reconnection attempt after some interval. + * * `rssi` - signal strength of the connected access point in dB, typically in the + * range -110 to 0, with anything greater than -30 being an excessively strong + * signal. + * * `ssid` - SSID of the access point. + * * `password` - the password used to connect to the access point. + * * `authMode` - the authentication used: `open`, `wpa`, `wpa2`, `wpa_wpa2` (not + * currently supported). + * * `savedSsid` - the SSID to connect to automatically at boot time, null if none. + * + * @param {any} callback - An optional `callback(details)` function to be called back with the wifi details, i.e. the same object as returned directly. + * @returns {any} An object representing the wifi station details, if available immediately. + * @url http://www.espruino.com/Reference#l_Wifi_getDetails + */ + getDetails(callback: any): any; + + /** + * Retrieve the current access point configuration and status. The details object + * has the following properties: + * * `status` - Current access point status: `enabled` or `disabled` + * * `stations` - an array of the stations connected to the access point. This + * array may be empty. Each entry in the array is an object describing the + * station which, at a minimum contains `ip` being the IP address of the station. + * * `ssid` - SSID to broadcast. + * * `password` - Password for authentication. + * * `authMode` - the authentication required of stations: `open`, `wpa`, `wpa2`, + * `wpa_wpa2`. + * * `hidden` - True if the SSID is hidden, false otherwise. + * * `maxConn` - Max number of station connections supported. + * * `savedSsid` - the SSID to broadcast automatically at boot time, null if the + * access point is to be disabled at boot. + * + * @param {any} callback - An optional `callback(details)` function to be called back with the current access point details, i.e. the same object as returned directly. + * @returns {any} An object representing the current access point details, if available immediately. + * @url http://www.espruino.com/Reference#l_Wifi_getAPDetails + */ + getAPDetails(callback: any): any; + + /** + * On boards where this is not available, just issue the `connect` commands you + * need to run at startup from an `onInit` function. + * Save the current wifi configuration (station and access point) to flash and + * automatically apply this configuration at boot time, unless `what=="clear"`, in + * which case the saved configuration is cleared such that wifi remains disabled at + * boot. The saved configuration includes: + * * mode (off/sta/ap/sta+ap) + * * SSIDs & passwords + * * phy (11b/g/n) + * * powersave setting + * * DHCP hostname + * + * @param {any} what - An optional parameter to specify what to save, on the esp8266 the two supported values are `clear` and `sta+ap`. The default is `sta+ap` + * @url http://www.espruino.com/Reference#l_Wifi_save + */ + save(what: any): void; + + /** + * Restores the saved Wifi configuration from flash. See `Wifi.save()`. + * @url http://www.espruino.com/Reference#l_Wifi_restore + */ + restore(): void; + + /** + * Return the station IP information in an object as follows: + * * ip - IP address as string (e.g. "192.168.1.5") + * * netmask - The interface netmask as string (ESP8266/ESP32 only) + * * gw - The network gateway as string (ESP8266/ESP32 only) + * * mac - The MAC address as string of the form 00:00:00:00:00:00 + * Note that the `ip`, `netmask`, and `gw` fields are omitted if no connection is established: + * + * @param {any} callback - An optional `callback(err, ipinfo)` function to be called back with the IP information. + * @returns {any} An object representing the station IP information, if available immediately (**ONLY** on ESP8266/ESP32). + * @url http://www.espruino.com/Reference#l_Wifi_getIP + */ + getIP(callback: any): any; + + /** + * Return the access point IP information in an object which contains: + * * ip - IP address as string (typ "192.168.4.1") + * * netmask - The interface netmask as string + * * gw - The network gateway as string + * * mac - The MAC address as string of the form 00:00:00:00:00:00 + * + * @param {any} callback - An optional `callback(err, ipinfo)` function to be called back with the the IP information. + * @returns {any} An object representing the esp8266's Access Point IP information, if available immediately (**ONLY** on ESP8266/ESP32). + * @url http://www.espruino.com/Reference#l_Wifi_getAPIP + */ + getAPIP(callback: any): any; + + /** + * Lookup the hostname and invoke a callback with the IP address as integer + * argument. If the lookup fails, the callback is invoked with a null argument. + * **Note:** only a single hostname lookup can be made at a time, concurrent + * lookups are not supported. + * + * @param {any} hostname - The hostname to lookup. + * @param {any} callback - The `callback(ip)` to invoke when the IP is returned. `ip==null` on failure. + * @url http://www.espruino.com/Reference#l_Wifi_getHostByName + */ + getHostByName(hostname: any, callback: any): void; + + /** + * Returns the hostname announced to the DHCP server and broadcast via mDNS when + * connecting to an access point. + * + * @param {any} callback - An optional `callback(hostname)` function to be called back with the hostname. + * @returns {any} The currently configured hostname, if available immediately. + * @url http://www.espruino.com/Reference#l_Wifi_getHostname + */ + getHostname(callback: any): any; + + /** + * Set the hostname. Depending on implemenation, the hostname is sent with every + * DHCP request and is broadcast via mDNS. The DHCP hostname may be visible in the + * access point and may be forwarded into DNS as hostname.local. If a DHCP lease + * currently exists changing the hostname will cause a disconnect and reconnect in + * order to transmit the change to the DHCP server. The mDNS announcement also + * includes an announcement for the "espruino" service. + * + * @param {any} hostname - The new hostname. + * @param {any} callback - An optional `callback()` function to be called back when the hostname is set + * @url http://www.espruino.com/Reference#l_Wifi_setHostname + */ + setHostname(hostname: any, callback: any): void; + + /** + * Starts the SNTP (Simple Network Time Protocol) service to keep the clock + * synchronized with the specified server. Note that the time zone is really just + * an offset to UTC and doesn't handle daylight savings time. The interval + * determines how often the time server is queried and Espruino's time is + * synchronized. The initial synchronization occurs asynchronously after setSNTP + * returns. + * + * @param {any} server - The NTP server to query, for example, `us.pool.ntp.org` + * @param {any} tz_offset - Local time zone offset in the range -11..13. + * @url http://www.espruino.com/Reference#l_Wifi_setSNTP + */ + setSNTP(server: any, tz_offset: any): void; + + /** + * The `settings` object must contain the following properties. + * * `ip` IP address as string (e.g. "192.168.5.100") + * * `gw` The network gateway as string (e.g. "192.168.5.1") + * * `netmask` The interface netmask as string (e.g. "255.255.255.0") + * + * @param {any} settings - Configuration settings + * @param {any} callback - A `callback(err)` function to invoke when ip is set. `err==null` on success, or a string on failure. + * @url http://www.espruino.com/Reference#l_Wifi_setIP + */ + setIP(settings: any, callback: any): void; + + /** + * The `settings` object must contain the following properties. + * * `ip` IP address as string (e.g. "192.168.5.100") + * * `gw` The network gateway as string (e.g. "192.168.5.1") + * * `netmask` The interface netmask as string (e.g. "255.255.255.0") + * + * @param {any} settings - Configuration settings + * @param {any} callback - A `callback(err)` function to invoke when ip is set. `err==null` on success, or a string on failure. + * @url http://www.espruino.com/Reference#l_Wifi_setAPIP + */ + setAPIP(settings: any, callback: any): void; + + /** + * Issues a ping to the given host, and calls a callback with the time when the + * ping is received. + * + * @param {any} hostname - The host to ping + * @param {any} callback - A `callback(time)` function to invoke when a ping is received + * @url http://www.espruino.com/Reference#l_Wifi_ping + */ + ping(hostname: any, callback: any): void; + + /** + * Switch to using a higher communication speed with the WiFi module. + * * `true` = 921600 baud + * * `false` = 115200 + * * `1843200` (or any number) = use a specific baud rate. * eg. + * `wifi.turbo(true,callback)` or `wifi.turbo(1843200,callback)` + * + * @param {any} enable - true (or a baud rate as a number) to enable, false to disable + * @param {any} callback - A `callback()` function to invoke when turbo mode has been set + * @url http://www.espruino.com/Reference#l_Wifi_turbo + */ + turbo(enable: any, callback: any): void; + } + + /** + * This library allows you to create http servers and make http requests + * In order to use this, you will need an extra module to get network connectivity + * such as the [TI CC3000](/CC3000) or [WIZnet W5500](/WIZnet). + * This is designed to be a cut-down version of the [node.js + * library](http://nodejs.org/api/http.html). Please see the [Internet](/Internet) + * page for more information on how to use it. + * @url http://www.espruino.com/Reference#http + */ + http: { + /** + * Create an HTTP Server + * When a request to the server is made, the callback is called. In the callback + * you can use the methods on the response (`httpSRs`) to send data. You can also + * add `request.on('data',function() { ... })` to listen for POSTed data + * + * @param {any} callback - A function(request,response) that will be called when a connection is made + * @returns {any} Returns a new httpSrv object + * @url http://www.espruino.com/Reference#l_http_createServer + */ + createServer(callback: any): httpSrv; + + /** + * Create an HTTP Request - `end()` must be called on it to complete the operation. + * `options` is of the form: + * ``` + * var options = { + * host: 'example.com', // host name + * port: 80, // (optional) port, defaults to 80 + * path: '/', // path sent to server + * method: 'GET', // HTTP command sent to server (must be uppercase 'GET', 'POST', etc) + * protocol: 'http:', // optional protocol - https: or http: + * headers: { key : value, key : value } // (optional) HTTP headers + * }; + * var req = require("http").request(options, function(res) { + * res.on('data', function(data) { + * console.log("HTTP> "+data); + * }); + * res.on('close', function(data) { + * console.log("Connection closed"); + * }); + * }); + * // You can req.write(...) here if your request requires data to be sent. + * req.end(); // called to finish the HTTP request and get the response + * ``` + * You can easily pre-populate `options` from a URL using `var options = + * url.parse("http://www.example.com/foo.html")` + * There's an example of using [`http.request` for HTTP POST + * here](/Internet#http-post) + * **Note:** if TLS/HTTPS is enabled, options can have `ca`, `key` and `cert` + * fields. See `tls.connect` for more information about these and how to use them. + * + * @param {any} options - An object containing host,port,path,method,headers fields (and also ca,key,cert if HTTPS is enabled) + * @param {any} callback - A function(res) that will be called when a connection is made. You can then call `res.on('data', function(data) { ... })` and `res.on('close', function() { ... })` to deal with the response. + * @returns {any} Returns a new httpCRq object + * @url http://www.espruino.com/Reference#l_http_request + */ + request(options: any, callback: any): httpCRq; + + /** + * Request a webpage over HTTP - a convenience function for `http.request()` that + * makes sure the HTTP command is 'GET', and that calls `end` automatically. + * ``` + * require("http").get("http://pur3.co.uk/hello.txt", function(res) { + * res.on('data', function(data) { + * console.log("HTTP> "+data); + * }); + * res.on('close', function(data) { + * console.log("Connection closed"); + * }); + * }); + * ``` + * See `http.request()` and [the Internet page](/Internet) and ` for more usage + * examples. + * + * @param {any} options - A simple URL, or an object containing host,port,path,method fields + * @param {any} callback - A function(res) that will be called when a connection is made. You can then call `res.on('data', function(data) { ... })` and `res.on('close', function() { ... })` to deal with the response. + * @returns {any} Returns a new httpCRq object + * @url http://www.espruino.com/Reference#l_http_get + */ + get(options: any, callback: any): httpCRq; + } + + /** + * This library provides TV out capability on the Espruino and Espruino Pico. + * See the [Television](/Television) page for more information. + * @url http://www.espruino.com/Reference#tv + */ + tv: { + /** + * This initialises the TV output. Options for PAL are as follows: + * ``` + * var g = require('tv').setup({ type : "pal", + * video : A7, // Pin - SPI MOSI Pin for Video output (MUST BE SPI1) + * sync : A6, // Pin - Timer pin to use for video sync + * width : 384, + * height : 270, // max 270 + * }); + * ``` + * and for VGA: + * ``` + * var g = require('tv').setup({ type : "vga", + * video : A7, // Pin - SPI MOSI Pin for Video output (MUST BE SPI1) + * hsync : A6, // Pin - Timer pin to use for video sync + * vsync : A5, // Pin - pin to use for video sync + * width : 220, + * height : 240, + * repeat : 2, // amount of times to repeat each line + * }); + * ``` + * or + * ``` + * var g = require('tv').setup({ type : "vga", + * video : A7, // Pin - SPI MOSI Pin for Video output (MUST BE SPI1) + * hsync : A6, // Pin - Timer pin to use for video sync + * vsync : A5, // Pin - pin to use for video sync + * width : 220, + * height : 480, + * repeat : 1, // amount of times to repeat each line + * }); + * ``` + * See the [Television](/Television) page for more information. + * + * @param {any} options - Various options for the TV output + * @param {number} width + * @returns {any} A graphics object + * @url http://www.espruino.com/Reference#l_tv_setup + */ + setup(options: any, width: number): any; + } + + /** + * Simple library for compression/decompression using + * [heatshrink](https://github.com/atomicobject/heatshrink), an + * [LZSS](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Storer%E2%80%93Szymanski) + * compression tool. + * Espruino uses heatshrink internally to compress RAM down to fit in Flash memory + * when `save()` is used. This just exposes that functionality. + * Functions here take and return buffers of data. There is no support for + * streaming, so both the compressed and decompressed data must be able to fit in + * memory at the same time. + * @url http://www.espruino.com/Reference#heatshrink + */ + heatshrink: { + /** + * + * @param {any} data - The data to compress + * @returns {any} Returns the result as an ArrayBuffer + * @url http://www.espruino.com/Reference#l_heatshrink_compress + */ + compress(data: any): ArrayBuffer; + + /** + * + * @param {any} data - The data to decompress + * @returns {any} Returns the result as an ArrayBuffer + * @url http://www.espruino.com/Reference#l_heatshrink_decompress + */ + decompress(data: any): ArrayBuffer; + } + + /** + * This library allows you to write to Neopixel/WS281x/APA10x/SK6812 LED strips + * These use a high speed single-wire protocol which needs platform-specific + * implementation on some devices - hence this library to simplify things. + * @url http://www.espruino.com/Reference#neopixel + */ + neopixel: { + /** + * Write to a strip of NeoPixel/WS281x/APA104/APA106/SK6812-style LEDs attached to + * the given pin. + * ``` + * // set just one pixel, red, green, blue + * require("neopixel").write(B15, [255,0,0]); + * ``` + * ``` + * // Produce an animated rainbow over 25 LEDs + * var rgb = new Uint8ClampedArray(25*3); + * var pos = 0; + * function getPattern() { + * pos++; + * for (var i=0;i = T extends U ? never : T; diff --git a/typescript/types/package.json b/typescript/types/package.json new file mode 100644 index 000000000..7259e2ab0 --- /dev/null +++ b/typescript/types/package.json @@ -0,0 +1,5 @@ +{ + "name": "banglejs", + "version": "1.0.0", + "typings": "main.d.ts" +} diff --git a/webtools b/webtools new file mode 160000 index 000000000..2ab71a33d --- /dev/null +++ b/webtools @@ -0,0 +1 @@ +Subproject commit 2ab71a33d69bfda40465174ffe57adb03c21fc42