diff --git a/README.md b/README.md index 0fcb78608..2d0b54a7d 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,9 @@ easily distinguish between file types, we use the following: * `stuff.info` is JSON that describes an app - this is auto-generated by the App Loader * `stuff.img` is an image -* `stuff.app.js` is JS code +* `stuff.app.js` is JS code for applications * `stuff.wid.js` is JS code for widgets +* `stuff.boot.js` is JS code that automatically gets run at boot time * `stuff.json` is used for JSON settings for an app ## Developing your own app diff --git a/apps.json b/apps.json index 268a81a68..9abf37b87 100644 --- a/apps.json +++ b/apps.json @@ -2,7 +2,7 @@ { "id": "boot", "name": "Bootloader", "icon": "bootloader.png", - "version":"0.11", + "version":"0.13", "description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings", "tags": "tool,system", "type":"bootloader", @@ -12,6 +12,31 @@ ], "sortorder" : -10 }, + { "id": "moonphase", + "name": "Moonphase", + "icon": "app.png", + "version":"0.01", + "description": "Shows current moon phase. Currently only with fixed coordinates (northern hemisphere).", + "tags": "", + "allow_emulator":true, + "storage": [ + {"name":"moonphase.app.js","url":"app.js"}, + {"name":"moonphase.img","url":"app-icon.js","evaluate":true} + ] + }, + { "id": "daysl", + "name": "Days left", + "icon": "app.png", + "version":"0.01", + "description": "Shows you the days left until a certain date. Date can be set with a settings app and is written to a file.", + "tags": "", + "allow_emulator":false, + "storage": [ + {"name":"daysl.app.js","url":"app.js"}, + {"name":"daysl.img","url":"app-icon.js","evaluate":true}, + {"name":"daysl.wid.js","url":"widget.js"} + ] + }, { "id": "launch", "name": "Default Launcher", "shortName":"Launcher", @@ -106,11 +131,12 @@ "name": "Default Alarm", "shortName":"Alarms", "icon": "app.png", - "version":"0.04", + "version":"0.05", "description": "Set and respond to alarms", "tags": "tool,alarm,widget", "storage": [ {"name":"alarm.app.js","url":"app.js"}, + {"name":"alarm.boot.js","url":"boot.js"}, {"name":"alarm.js","url":"alarm.js"}, {"name":"alarm.json","content":"[]"}, {"name":"alarm.img","url":"app-icon.js","evaluate":true}, @@ -133,7 +159,7 @@ { "id": "aclock", "name": "Analog Clock", "icon": "clock-analog.png", - "version":"0.02", + "version":"0.10", "description": "An Analog Clock", "tags": "clock", "type":"clock", @@ -355,8 +381,8 @@ { "id": "swatch", "name": "Stopwatch", "icon": "stopwatch.png", - "version":"0.01", - "description": "Simple stopwatch with Lap Time recording", + "version":"0.03", + "description": "Simple stopwatch with Lap Time logging to a JSON file", "tags": "health", "allow_emulator":true, "storage": [ @@ -508,6 +534,19 @@ {"name":"sclock.img","url":"clock-simple-icon.js","evaluate":true} ] }, + { "id": "dclock", + "name": "Dev Clock", + "icon": "clock-dev.png", + "version":"0.09", + "description": "A Digital Clock including timestamp (tst), beats(@), days in current month (dm) and days since new moon (l)", + "tags": "clock", + "type":"clock", + "allow_emulator":true, + "storage": [ + {"name":"dclock.app.js","url":"clock-dev.js"}, + {"name":"dclock.img","url":"clock-dev-icon.js","evaluate":true} + ] + }, { "id": "gesture", "name": "Gesture Test", "icon": "gesture.png", @@ -790,7 +829,7 @@ "id": "pipboy", "name": "Pipboy", "icon": "app.png", - "version": "0.01", + "version": "0.02", "description": "Pipboy themed clock", "tags": "clock", "type":"clock", @@ -824,10 +863,25 @@ {"name":"widid.wid.js","url":"widget.js"} ] }, + { + "id": "grocery", + "name": "Grocery", + "icon": "grocery.png", + "version":"0.01", + "description": "Simple grocery list - Display a list of product and track if you already put them in your cart.", + "tags": "tool,outdoors", + "type": "app", + "custom":"grocery.html", + "storage": [ + {"name":"grocery"}, + {"name":"grocery.app.js"}, + {"name":"grocery.img","url":"grocery-icon.js","evaluate":true} + ] + }, { "id": "marioclock", "name": "Mario Clock", "icon": "marioclock.png", - "version":"0.01", + "version":"0.03", "description": "Animated Mario clock, jumps to change the time!", "tags": "clock,mario,retro", "type": "clock", @@ -838,17 +892,41 @@ ] }, { "id": "cliock", - "name": "Commandline-Clock", - "shortName":"CLI-Clock", - "icon": "app.png", - "version":"0.07", - "description": "Simple CLI-Styled Clock", - "tags": "clock,cli,command,bash,shell", - "type":"clock", - "allow_emulator":true, - "storage": [ - {"name":"cliock.app.js","url":"app.js"}, - {"name":"cliock.img","url":"app-icon.js","evaluate":true} - ] -} + "name": "Commandline-Clock", + "shortName":"CLI-Clock", + "icon": "app.png", + "version":"0.07", + "description": "Simple CLI-Styled Clock", + "tags": "clock,cli,command,bash,shell", + "type":"clock", + "allow_emulator":true, + "storage": [ + {"name":"cliock.app.js","url":"app.js"}, + {"name":"cliock.img","url":"app-icon.js","evaluate":true} + ] + }, + { "id": "widver", + "name": "Firmware Version Widget", + "icon": "widget.png", + "version":"0.01", + "description": "Display the version of the installed firmware in the top widget section.", + "tags": "widget,tool,system", + "type":"widget", + "storage": [ + {"name":"widver.wid.js","url":"widget.js"} + ] + }, + { "id": "barclock", + "name": "Bar Clock", + "icon": "clock-bar.png", + "version":"0.02", + "description": "A simple digital clock showing seconds as a bar", + "tags": "clock", + "type":"clock", + "allow_emulator":true, + "storage": [ + {"name":"barclock.app.js","url":"clock-bar.js"}, + {"name":"barclock.img","url":"clock-bar-icon.js","evaluate":true} + ] + } ] diff --git a/apps/aclock/ChangeLog b/apps/aclock/ChangeLog index 7819dbe2a..a179800be 100644 --- a/apps/aclock/ChangeLog +++ b/apps/aclock/ChangeLog @@ -1 +1,7 @@ 0.02: Modified for use with new bootloader and firmware +0.03: add hour ticks, remove timers +0.04: add day-date display +0.07: make date and face bigger +0.08: make dots bigger and date more readable +0.09: center date, remove box around it, internal refactor to remove redundant code. +0.10: remove debug, refactor seconds to show elapsed secs each time app is displayed diff --git a/apps/aclock/clock-analog.js b/apps/aclock/clock-analog.js index 67061af52..419ed0933 100644 --- a/apps/aclock/clock-analog.js +++ b/apps/aclock/clock-analog.js @@ -1,94 +1,146 @@ -const p = Math.PI/2; -const PRad = Math.PI/180; +let g; +let Bangle; -let intervalRefMin = null; -let intervalRefSec = null; +// http://forum.espruino.com/conversations/345155/#comment15172813 +const locale = require('locale'); +const p = Math.PI / 2; +const pRad = Math.PI / 180; +const faceWidth = 100; // watch face radius +let timer = null; +let currentDate = new Date(); +const centerPx = g.getWidth() / 2; -let minuteDate = new Date(); -let secondDate = new Date(); +const seconds = (angle) => { + const a = angle * pRad; + const x = centerPx + Math.sin(a) * faceWidth; + const y = centerPx - Math.cos(a) * faceWidth; -function seconds(angle, r) { - const a = angle*PRad; - const x = 120+Math.sin(a)*r; - const y = 120-Math.cos(a)*r; - g.fillRect(x-1,y-1,x+1,y+1); -} -function hand(angle, r1,r2) { - const a = angle*PRad; + // if 15 degrees, make hour marker larger + const radius = (angle % 15) ? 2 : 4; + g.fillCircle(x, y, radius); +}; + +const hand = (angle, r1, r2) => { + const a = angle * pRad; const r3 = 3; - g.fillPoly([ - 120+Math.sin(a)*r1, - 120-Math.cos(a)*r1, - 120+Math.sin(a+p)*r3, - 120-Math.cos(a+p)*r3, - 120+Math.sin(a)*r2, - 120-Math.cos(a)*r2, - 120+Math.sin(a-p)*r3, - 120-Math.cos(a-p)*r3]); -} -function drawAll() { + g.fillPoly([ + Math.round(centerPx + Math.sin(a) * r1), + Math.round(centerPx - Math.cos(a) * r1), + Math.round(centerPx + Math.sin(a + p) * r3), + Math.round(centerPx - Math.cos(a + p) * r3), + Math.round(centerPx + Math.sin(a) * r2), + Math.round(centerPx - Math.cos(a) * r2), + Math.round(centerPx + Math.sin(a - p) * r3), + Math.round(centerPx - Math.cos(a - p) * r3) + ]); +}; + +const drawAll = () => { g.clear(); - secondDate = minuteDate = new Date(); + currentDate = new Date(); // draw hands first onMinute(); // draw seconds - g.setColor(0,0,0.6); - for (let i=0;i<60;i++) - seconds(360*i/60, 90); + const currentSec = currentDate.getSeconds(); + // draw all secs + + for (let i = 0; i < 60; i++) { + if (i > currentSec) { + g.setColor(0, 0, 0.6); + } else { + g.setColor(0.3, 0.3, 1); + } + seconds((360 * i) / 60); + } onSecond(); -} +}; -function onSecond() { - g.setColor(0,0,0.6); - seconds(360*secondDate.getSeconds()/60, 90); - g.setColor(1,0,0); - secondDate = new Date(); - seconds(360*secondDate.getSeconds()/60, 90); - g.setColor(1,1,1); +const resetSeconds = () => { + g.setColor(0, 0, 0.6); + for (let i = 0; i < 60; i++) { + seconds((360 * i) / 60); + } +}; -} +const onSecond = () => { + g.setColor(0.3, 0.3, 1); + seconds((360 * currentDate.getSeconds()) / 60); + if (currentDate.getSeconds() === 59) { + resetSeconds(); + onMinute(); + } + g.setColor(1, 0.7, 0.2); + currentDate = new Date(); + seconds((360 * currentDate.getSeconds()) / 60); + g.setColor(1, 1, 1); +}; -function onMinute() { - g.setColor(0,0,0); - hand(360*(minuteDate.getHours() + (minuteDate.getMinutes()/60))/12, -10, 50); - hand(360*minuteDate.getMinutes()/60, -10, 82); - minuteDate = new Date(); - g.setColor(1,1,1); - hand(360*(minuteDate.getHours() + (minuteDate.getMinutes()/60))/12, -10, 50); - hand(360*minuteDate.getMinutes()/60, -10, 82); - if(minuteDate.getHours() >= 0 && minuteDate.getMinutes() === 0) { +const drawDate = () => { + g.reset(); + g.setColor(1, 0, 0); + g.setFont('6x8', 2); + + const dayString = locale.dow(currentDate, true); + // pad left date + const dateString = (currentDate.getDate() < 10) ? '0' : '' + currentDate.getDate().toString(); + const dateDisplay = `${dayString}-${dateString}`; + // console.log(`${dayString}|${dateString}`); + // center date + const l = (g.getWidth() - g.stringWidth(dateDisplay)) / 2; + const t = centerPx + 37; + g.drawString(dateDisplay, l, t); + // console.log(l, t); +}; +const onMinute = () => { + if (currentDate.getHours() === 0 && currentDate.getMinutes() === 0) { + g.clear(); + resetSeconds(); + } + // clear existing hands + g.setColor(0, 0, 0); + // Hour + hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35); + // Minute + hand((360 * currentDate.getMinutes()) / 60, -8, faceWidth - 10); + + // get new date, then draw new hands + currentDate = new Date(); + g.setColor(1, 0.9, 0.9); + // Hour + hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35); + g.setColor(1, 1, 0.9); + // Minute + hand((360 * currentDate.getMinutes()) / 60, -8, faceWidth - 10); + if (currentDate.getHours() >= 0 && currentDate.getMinutes() === 0) { Bangle.buzz(); } -} + drawDate(); +}; -function clearTimers() { - if(intervalRefMin) {clearInterval(intervalRefMin);} - if(intervalRefSec) {clearInterval(intervalRefSec);} -} +const startTimers = () => { + timer = setInterval(onSecond, 1000); +}; -function startTimers() { - minuteDate = new Date(); - secondDate = new Date(); - intervalRefSec = setInterval(onSecond,1000); - intervalRefMin = setInterval(onMinute,60*1000); - drawAll(); -} - -Bangle.on('lcdPower',function(on) { +Bangle.on('lcdPower', (on) => { if (on) { - g.clear(); - Bangle.drawWidgets(); + // g.clear(); + drawAll(); startTimers(); - }else { - clearTimers(); + Bangle.drawWidgets(); + } else { + if (timer) { + clearInterval(timer); + } } }); g.clear(); +resetSeconds(); +startTimers(); +drawAll(); Bangle.loadWidgets(); Bangle.drawWidgets(); -drawAll(); -startTimers(); + // Show launcher when middle button pressed -setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"}); +setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" }); diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index 67feb024f..be3c1513c 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -2,3 +2,4 @@ 0.02: Fix issues with alarm scheduling 0.03: More alarm scheduling issues 0.04: Tweaks for variable size widget system +0.05: Add alarm.boot.js and move code from the bootloader diff --git a/apps/alarm/boot.js b/apps/alarm/boot.js new file mode 100644 index 000000000..709703bdd --- /dev/null +++ b/apps/alarm/boot.js @@ -0,0 +1,24 @@ +// check for alarms +(function() { + var alarms = require('Storage').readJSON('alarm.json',1)||[]; + var time = new Date(); + var active = alarms.filter(a=>a.on&&(a.last!=time.getDate())); + if (active.length) { + active = active.sort((a,b)=>a.hr-b.hr); + var hr = time.getHours()+(time.getMinutes()/60)+(time.getSeconds()/3600); + if (!require('Storage').read("alarm.js")) { + console.log("No alarm app!"); + require('Storage').write('alarm.json',"[]") + } else { + var t = 3600000*(active[0].hr-hr); + if (t<1000) t=1000; + /* execute alarm at the correct time. We avoid execing immediately + since this code will get called AGAIN when alarm.js is loaded. alarm.js + will then clearInterval() to get rid of this call so it can proceed + normally. */ + setTimeout(function() { + load("alarm.js"); + },t); + } + } +})() diff --git a/apps/barclock/ChangeLog b/apps/barclock/ChangeLog new file mode 100644 index 000000000..a8d2f5485 --- /dev/null +++ b/apps/barclock/ChangeLog @@ -0,0 +1,2 @@ +0.01: Created Bar Clock +0.02: Apply locale, 12-hour setting diff --git a/apps/barclock/clock-bar-icon.js b/apps/barclock/clock-bar-icon.js new file mode 100644 index 000000000..29bf0f481 --- /dev/null +++ b/apps/barclock/clock-bar-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwgJC/AD8Mgfwh/AhgFFngHBOIM8AovMDIXA5gFFDoUAmYjDAocMSoMz/4FF//P/g1CAopTLDAIABwAFGAH4AfA")) diff --git a/apps/barclock/clock-bar.js b/apps/barclock/clock-bar.js new file mode 100644 index 000000000..5ab9c433e --- /dev/null +++ b/apps/barclock/clock-bar.js @@ -0,0 +1,127 @@ +/* jshint esversion: 6 */ +/** + * A simple digital clock showing seconds as a bar + **/ +{ + // Check settings for what type our clock should be + const is12Hour = (require('Storage').readJSON('setting.json', 1) || {})['12hour'] + const 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 timeFont = '6x8' + const timeFontSize = (is12Hour && locale.hasMeridian) ? 6 : 8 + const ampmFontSize = 2 + const dateFont = 'Vector' + const dateFontSize = 20 + + const screenSize = g.getWidth() + const screenCenter = screenSize / 2 + + const timeY = screenCenter + const barY = 155 // just below time + const barThickness = 6 // matches time digit size + const dateY = screenSize - dateFontSize // at bottom of screen + + const SECONDS_PER_MINUTE = 60 + + + function timeText(date) { + if (!is12Hour) { + return {time: locale.time(date, true), ampm: ''} + } + const meridian = locale.meridian(date) + const hours = date.getHours() + if (hours === 0) { + date.setHours(12) + } else if (hours > 12) { + date.setHours(hours - 12) + } + return {time: locale.time(date, true), ampm: meridian} + } + + function dateText(date) { + const dayName = locale.dow(date, true), + month = locale.month(date, true), + day = date.getDate() + return `${dayName} ` + (locale.dayFirst ? `${day} ${month}` : `${month} ${day}`) + } + + function drawDateTime(date) { + const timeTexts = timeText(date) + g.setFontAlign(0, 0) // centered + g.setFont(timeFont, timeFontSize) + g.drawString(timeTexts.time, screenCenter, timeY, true) + if (timeTexts.ampm !== '') { + g.setFontAlign(1, -1) + g.setFont(timeFont, ampmFontSize) + g.drawString(timeTexts.ampm, + // at right edge of screen , aligned with time bottom + (screenSize - ampmFontSize * 2), (timeY + timeFontSize - ampmFontSize), + true) + } + + g.setFontAlign(0, 0) // centered + g.setFont(dateFont, dateFontSize) + g.drawString(dateText(date), screenCenter, dateY, true) + } + + function drawBar(date) { + const seconds = date.getSeconds() + if (seconds === 0) return; // zero-size rect stills draws one line of pixels + const fraction = seconds / SECONDS_PER_MINUTE + g.fillRect(0, barY, fraction * screenSize, barY + barThickness) + } + function eraseBar() { + const color = g.getColor() + g.setColor(g.getBgColor()) + g.fillRect(0, barY, screenSize, barY + barThickness) + g.setColor(color) + } + + let lastSeconds + function tick() { + g.reset() + const date = new Date() + const seconds = date.getSeconds() + if (lastSeconds > seconds) { + // new minute + eraseBar() + drawDateTime(date) + } + drawBar(date) + + lastSeconds = seconds + } + + let iTick + function start() { + lastSeconds = 99 // force redraw + tick() + iTick = setInterval(tick, 1000) + } + function stop() { + if (iTick) { + clearInterval(iTick) + iTick = undefined + } + } + + // clean app screen + g.clear() + Bangle.loadWidgets() + Bangle.drawWidgets() + // Show launcher when middle button pressed + setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: 'falling'}) + + Bangle.on('lcdPower', function (on) { + on ? start() : stop() + }) + start() +} diff --git a/apps/barclock/clock-bar.png b/apps/barclock/clock-bar.png new file mode 100644 index 000000000..a580cae69 Binary files /dev/null and b/apps/barclock/clock-bar.png differ diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index 3bd9ec71c..17023a8dc 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -9,3 +9,6 @@ 0.10: Stop users calling save() (fix #125) If Debug info is set to 'show' don't move to Terminal if connected! 0.11: Added vibrate as beep workaround +0.12: Add an event on BTN2 to open launcher when no clock detected (fix #147) +0.13: Now automatically load *.boot.js at startup + Move alarm code into alarm.boot.js diff --git a/apps/boot/boot0.js b/apps/boot/boot0.js index ad8ccb312..729b7aaf2 100644 --- a/apps/boot/boot0.js +++ b/apps/boot/boot0.js @@ -39,25 +39,7 @@ E.setTimeZone(s.timezone); delete s; // stop users doing bad things! global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); } -// check for alarms -var alarms = require('Storage').readJSON('alarm.json',1)||[]; -var time = new Date(); -var active = alarms.filter(a=>a.on&&(a.last!=time.getDate())); -if (active.length) { - active = active.sort((a,b)=>a.hr-b.hr); - var hr = time.getHours()+(time.getMinutes()/60)+(time.getSeconds()/3600); - if (!require('Storage').read("alarm.js")) { - console.log("No alarm app!"); - require('Storage').write('alarm.json',"[]") - } else { - var t = 3600000*(active[0].hr-hr); - if (t<1000) t=1000; - /* execute alarm at the correct time. We avoid execing immediately - since this code will get called AGAIN when alarm.js is loaded. alarm.js - will then clearInterval() to get rid of this call so it can proceed - normally. */ - setTimeout(function() { - load("alarm.js"); - },t); - } -} +// Load *.boot.js files +var clockApps = require('Storage').list(/\.boot\.js/).map(bootFile=>{ + eval(require('Storage').read(bootFile)); +}); diff --git a/apps/boot/bootloader.js b/apps/boot/bootloader.js index febc4fc19..76d655671 100644 --- a/apps/boot/bootloader.js +++ b/apps/boot/bootloader.js @@ -12,7 +12,11 @@ if (!settings.welcomed && require("Storage").read("welcome.js")!==undefined) { clockApp = require("Storage").read(clockApps[0].src); delete clockApps; } - if (!clockApp) clockApp='E.showMessage("No Clock Found")'; + if (!clockApp) clockApp=`E.showMessage("No Clock Found"); + setWatch(() => { + Bangle.showLauncher(); + }, BTN2, {repeat:false,edge:"falling"});) + `; delete settings; // check to see if our clock is wrong - if it is use GPS time if ((new Date()).getFullYear()==1970) { diff --git a/apps/daysl/ChangeLog b/apps/daysl/ChangeLog new file mode 100644 index 000000000..4c21f3ace --- /dev/null +++ b/apps/daysl/ChangeLog @@ -0,0 +1 @@ +0.01: New Widget! diff --git a/apps/daysl/app-icon.js b/apps/daysl/app-icon.js new file mode 100644 index 000000000..485478c58 --- /dev/null +++ b/apps/daysl/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwMB//D/4CgwHDFYPDgICBAoQCB/4CKADmAAgcBIARCCAqQAXF/4v24CtDgYFR")) \ No newline at end of file diff --git a/apps/daysl/app.js b/apps/daysl/app.js new file mode 100644 index 000000000..56f85e615 --- /dev/null +++ b/apps/daysl/app.js @@ -0,0 +1,67 @@ +g.clear(); +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +const storage = require('Storage'); +let settings; + +function updateSettings() { + storage.write('daysleft.json', settings); +} + +function resetSettings() { + settings = { + day : 17, + month : 6, + year: 1981 + }; + updateSettings(); +} + +settings = storage.readJSON('daysleft.json',1); +if (!settings) resetSettings(); + +function showMenu() { + const datemenu = { + '': { + 'title': 'Set Date', + 'predraw': function() { + datemenu.Date.value = settings.day; + datemenu.Month.value = settings.month; + datemenu.Year.value = settings.year; + } + }, + 'Day': { + value: settings.day, + min: 1, + max: 31, + step: 1, + onchange: v => { + settings.day = v; + updateSettings(); + } + }, + 'Month': { + value: settings.month, + min: 1, + max: 12, + step: 1, + onchange: v => { + settings.month = v; + updateSettings(); + } + }, + 'Year': { + value: settings.year, + step: 1, + onchange: v => { + settings.year = v; + updateSettings(); + } + } + }; + datemenu['-Exit-'] = ()=>{load();}; + return E.showMenu(datemenu); +} + +showMenu(); \ No newline at end of file diff --git a/apps/daysl/app.png b/apps/daysl/app.png new file mode 100644 index 000000000..703e5c366 Binary files /dev/null and b/apps/daysl/app.png differ diff --git a/apps/daysl/widget.js b/apps/daysl/widget.js new file mode 100644 index 000000000..5a3c170c2 --- /dev/null +++ b/apps/daysl/widget.js @@ -0,0 +1,33 @@ +const storage = require('Storage'); +let settings; + +function updateSettings() { + storage.write('daysleft.json', settings); + } + + function resetSettings() { + settings = { + day : 17, + month : 6, + year: 1981 + }; + updateSettings(); + } + + settings = storage.readJSON('daysleft.json',1); + if (!settings) resetSettings(); + + var dd = settings.day+1, + mm = settings.month-1, + yy = settings.year; + + const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds + const targetDate = new Date(yy, mm, dd); + const today = new Date(); + const diffDays = Math.round(Math.abs((targetDate - today) / oneDay)); + +WIDGETS["daysl"]={area:"tl",width:40,draw:function(){ + + g.setFont("6x8", 1); + g.drawString(diffDays,this.x+12,this.y+12); +}}; \ No newline at end of file diff --git a/apps/dclock/ChangeLog b/apps/dclock/ChangeLog new file mode 100644 index 000000000..edf7da4c2 --- /dev/null +++ b/apps/dclock/ChangeLog @@ -0,0 +1,9 @@ +0.01: branched from simple clock and added seconds +0.02: add timestamp (tst) +0.03: fix timestamp round to whole number +0.04: add iso datetime and move day of the week (d) / month names (m) +0.05: add beats (@) +0.06: tidy up +0.07: add days in current month (md) and days since new moon (l) +0.08: update icon +0.09: Use localised month and day of the week from locale diff --git a/apps/dclock/clock-dev-icon.js b/apps/dclock/clock-dev-icon.js new file mode 100644 index 000000000..f36dcaee3 --- /dev/null +++ b/apps/dclock/clock-dev-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkEIf4A5/8wgf/AwUB/8gh/zA4QMCl/xA4cAichgIaBiEDgMgmECDQMAkMA+EgiYvDkQJBkcQgMQDwMggUiiECG4MikEBmQWCgURiEREQIXBCIMxkIIBAoMSiQ4BGoIABKgPykRSBI4JfC+c/iARBl8zmBfEAAUvIgIAUkbAtgalB+ADDBIKSBHgUgmYJCAAa6BmCoBAYMiBIMRC4UQmEAAoQvFmUDAYUSmcxWIKMBEQKrBOw0yh8wmcyj4nBIYQDB+cwBAQA/ABUxgUDkBqBgchkMiiUikMRgSOBkR3BkEhC4MgiQHBiADBC4UQAYMRiUxkECAAITBC4MSiUQF4MTiQTBBAIDBkcCiMxkUTAYIvCAH4A/AH4AKiIPPgMxiESgUQgECgMBdAMiiUgC48ikUBiEBiIXDGQURiIbBF48RkAvCEwIvCkERgQMBRHpDBOoRhBNoJOBJIkiKYMjgcTOoMhLQMQmMDDIMjQQInEC4MhiUSkQHCC4MAkAXCiUjiZ5UiR5jLwLaBAQJ1BAgIAMCgMxMwMgkciAoMjC5pqBRwPxCoMiiUyGBsgiBBBiESVAKzBf+YACA==")) \ No newline at end of file diff --git a/apps/dclock/clock-dev.js b/apps/dclock/clock-dev.js new file mode 100644 index 000000000..d2c08726a --- /dev/null +++ b/apps/dclock/clock-dev.js @@ -0,0 +1,112 @@ +var locale = require("locale"); +/* jshint esversion: 6 */ +const timeFontSize = 4; +const dateFontSize = 3; +const smallFontSize = 2; +const font = "6x8"; + +const xyCenter = g.getWidth() / 2; +const yposTime = 50; +const yposDate = 85; +const yposTst = 115; +const yposDml = 170; +const yposDayMonth = 195; +const yposGMT = 220; + +// Check settings for what type our clock should be +var is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]; + +function getUTCTime(d) { + return d.toUTCString().split(' ')[4].split(':').map(function(d){return Number(d)}); +} + +function drawSimpleClock() { + // get date + var d = new Date(); + var da = d.toString().split(" "); + var dutc = getUTCTime(d); + + g.reset(); // default draw styles + // drawSting centered + g.setFontAlign(0, 0); + + // draw time + var time = da[4].split(":"); + var hours = time[0], + minutes = time[1], + seconds = time[2]; + + var meridian = ""; + if (is12Hour) { + hours = parseInt(hours,10); + meridian = "AM"; + if (hours == 0) { + hours = 12; + meridian = "AM"; + } else if (hours >= 12) { + meridian = "PM"; + if (hours>12) hours -= 12; + } + hours = (" "+hours).substr(-2); + } + + // Time + g.setFont(font, timeFontSize); + g.drawString(`${hours}:${minutes}:${seconds}`, xyCenter, yposTime, true); + g.setFont(font, smallFontSize); + g.drawString(meridian, xyCenter + 102, yposTime + 10, true); + + // Date String + g.setFont(font, dateFontSize); + g.drawString(`${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`, xyCenter, yposDate, true); + + // Timestamp + var tst = Math.round(d.getTime()); + g.setFont(font, smallFontSize); + g.drawString(`tst:${tst}`, xyCenter, yposTst, true); + + //Days in month + var dom = new Date(d.getFullYear(), d.getMonth()+1, 0).getDate(); + + //Days since full moon + var knownnew = new Date(2020,02,24,09,28,0); + + // Get millisecond difference and divide down to cycles + var cycles = (d.getTime()-knownnew.getTime())/1000/60/60/24/29.53; + + // Multiply decimal component back into days since new moon + var sincenew = (cycles % 1)*29.53; + + // Draw days in month and sime since new moon + g.setFont(font, smallFontSize); + g.drawString(`md:${dom} l:${sincenew.toFixed(2)}`, xyCenter, yposDml, true); + + // draw Month name, Day of the week and beats + var beats = Math.floor((((dutc[0] + 1) % 24) + dutc[1] / 60 + dutc[2] / 3600) * 1000 / 24); + g.setFont(font, smallFontSize); + g.drawString(`m:${locale.month(d,true)} d:${locale.dow(d,true)} @${beats}`, xyCenter, yposDayMonth, true); + + // draw gmt + var gmt = da[5]; + g.setFont(font, smallFontSize); + g.drawString(gmt, xyCenter, yposGMT, true); +} + +// handle switch display on by pressing BTN1 +Bangle.on('lcdPower', function(on) { + if (on) drawSimpleClock(); +}); + +// clean app screen +g.clear(); +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +// refesh every 100 milliseconds +setInterval(drawSimpleClock, 100); + +// draw now +drawSimpleClock(); + +// Show launcher when middle button pressed +setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"}); \ No newline at end of file diff --git a/apps/dclock/clock-dev.png b/apps/dclock/clock-dev.png new file mode 100644 index 000000000..0cfbff44c Binary files /dev/null and b/apps/dclock/clock-dev.png differ diff --git a/apps/gbridge/PROTOCOL.md b/apps/gbridge/PROTOCOL.md new file mode 100644 index 000000000..1fd0ddb4a --- /dev/null +++ b/apps/gbridge/PROTOCOL.md @@ -0,0 +1,178 @@ +# Watch -> Phone + +## show toast + +``` +{ "t": "info", "msg": "message" } +``` + +t can be one of "info", "warn", "error" + +## report battery level + +``` +{ "t": "status", "bat": 30, "volt": 30 } +``` + +* bat is in range 0 to 100 +* volt is optional and should be greater than 0 + +## find phone + +``` +{ "t": "findPhone", "n": true } +``` + +n is an boolean and toggles the find phone function + +## control music player + +``` +{ "t": "music", "n": "play" } +``` + +n can be one of "play", "pause", "playpause", "next", "previous", "volumeup", "volumedown", "forward", "rewind" + +## control phone call + +``` +{ "t": "call", "n": "accept"} +``` + +n can be one of "accept", "end", "incoming", "outcoming", "reject", "start", "ignore" + +## react to notifications + +Send a response to a notification from phone + +``` +{ + "t": "notify", + "n": "dismiss", + "id": 2, + "tel": "+491234", + "msg": "message", +} +``` + +* n can be one of "dismiss", "dismiss all", "open", "mute", "reply" +* id, tel and message are optional + +# Phone -> Watch + +## show notification + +``` +{ + "t": "notify", + "id": 2, + "src": "app", + "title": "titel", + "subject": "subject", + "body": "message body", + "sender": "sender", + "tel": "+491234" + } +``` + +## notification deleted + +This event is send when the user skipped a notification + +``` +{ "t": "notify-", "id": 2 } +``` + +## set alarm + +``` +{ + "t": "alarm", + "d": [ + { "h": 13, "m": 37 }, + { "h": 8, "m": 0 } + ] +} +``` + +## call state changed + +``` +{ + "t": "call", + "cmd": "accept", + "name": "name", + "number": "+491234" +} +``` + +cmd can be one of "", "undefined", "accept", "incoming", "outgoing", "reject", "start", "end" + +## music state changed + +``` +{ + "t": "musicstate", + "state": "play", + "position": 40, + "shuffle": 0, + "repeat": 1 +} +``` + +## set music info + +``` +{ + "t": "musicinfo", + "artist": "artist", + "album": "album", + "track": "track", + "dur": 1, + "c": 2, + "n" 3 +} +``` + +* dur is the duration of the track +* c is the track count +* n is the track number + +## find device + +``` +{ + "t": "find", + "n": true +} +``` + +n toggles find device functionality + +## set constant vibration + +``` +{ + "t": "vibrate", + "n": 2 +} +``` + +n is the intensity + +## send weather + +``` +{ + "t": "weather", + "temp": 10, + "hum": 71, + "txt": "condition", + "wind": 13, + "loc": "location" +} +``` + +* hum is the humidity +* txt is the weather condition +* loc is the location diff --git a/apps/gpsrec/interface.html b/apps/gpsrec/interface.html index b87d75b3c..bc8dc48e1 100644 --- a/apps/gpsrec/interface.html +++ b/apps/gpsrec/interface.html @@ -5,32 +5,9 @@
- - + + + + diff --git a/apps/grocery/grocery.png b/apps/grocery/grocery.png new file mode 100644 index 000000000..93a29a4a6 Binary files /dev/null and b/apps/grocery/grocery.png differ diff --git a/apps/heart/interface.html b/apps/heart/interface.html index c2f115564..177e2cdfb 100644 --- a/apps/heart/interface.html +++ b/apps/heart/interface.html @@ -5,32 +5,9 @@
- - - - - - - + + + + diff --git a/appinfo.js b/js/appinfo.js similarity index 78% rename from appinfo.js rename to js/appinfo.js index 151227f45..613d15379 100644 --- a/appinfo.js +++ b/js/appinfo.js @@ -27,14 +27,19 @@ var AppInfo = { // then map each file to a command to load into storage fileContents.forEach(storageFile => { // format ready for Espruino - var js; if (storageFile.evaluate) { - js = storageFile.content.trim(); + let js = storageFile.content.trim(); if (js.endsWith(";")) js = js.slice(0,-1); - } else - js = toJS(storageFile.content); - storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`; + storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${js});`; + } else { + let code = storageFile.content; + // write code in chunks, in case it is too big to fit in RAM (fix #157) + var CHUNKSIZE = 4096; + storageFile.cmd = `\x10require('Storage').write(${toJS(storageFile.name)},${toJS(code.substr(0,CHUNKSIZE))},0,${code.length});`; + for (var i=CHUNKSIZE;i reject(err)); diff --git a/comms.js b/js/comms.js similarity index 76% rename from comms.js rename to js/comms.js index de2c328b3..05b94ffde 100644 --- a/comms.js +++ b/js/comms.js @@ -147,5 +147,50 @@ readFile : (file) => { }); }); }); +}, +readStorageFile : (filename) => { // StorageFiles are different to normal storage entries + return new Promise((resolve,reject) => { + // Use "\xFF" to signal end of file (can't occur in files anyway) + var fileContent = ""; + var fileSize = undefined; + var connection = Puck.getConnection(); + connection.received = ""; + connection.cb = function(d) { + var finished = false; + var eofIndex = d.indexOf("\xFF"); + if (eofIndex>=0) { + finished = true; + d = d.substr(0,eofIndex); + } + fileContent += d; + if (fileSize === undefined) { + var newLineIdx = fileContent.indexOf("\n"); + if (newLineIdx>=0) { + fileSize = parseInt(fileContent.substr(0,newLineIdx)); + console.log("File size is "+fileSize); + fileContent = fileContent.substr(newLineIdx+1); + } + } else { + showProgress(undefined,100*fileContent.length / (fileSize||1000000)); + } + if (finished) { + hideProgress(); + connection.received = ""; + connection.cb = undefined; + resolve(fileContent); + } + }; + console.log(`Reading StorageFile ${JSON.stringify(filename)}`); + connection.write(`\x03\x10(function() { + var f = require("Storage").open(${JSON.stringify(filename)},"r"); + Bluetooth.println(f.getLength()); + var l = f.readLine(); + while (l!==undefined) { Bluetooth.print(l); l = f.readLine(); } + Bluetooth.print("\xFF"); + })()\n`,() => { + showProgress(`Reading ${JSON.stringify(filename)}`,0); + console.log(`StorageFile read started...`); + }); + }); } }; diff --git a/index.js b/js/index.js similarity index 96% rename from index.js rename to js/index.js index d08d98cba..b21fc907d 100644 --- a/index.js +++ b/js/index.js @@ -229,6 +229,14 @@ function handleAppInterface(app) { id : msg.id }); }); + } else if (msg.type=="readstoragefile") { + Comms.readStorageFile(msg.data/*filename*/).then(function(result) { + iwin.postMessage({ + type : "readstoragefilersp", + data : result, + id : msg.id + }); + }); } }, false); iwin.postMessage({type:"init"}); @@ -343,22 +351,9 @@ function refreshLibrary() { }); } else if (icon.classList.contains("icon-menu")) { // custom HTML update - if (app.custom) { - icon.classList.remove("icon-menu"); - icon.classList.add("loading"); - handleCustomApp(app).then((appJSON) => { - if (appJSON) appsInstalled.push(appJSON); - showToast(app.name+" Uploaded!", "success"); - icon.classList.remove("loading"); - icon.classList.add("icon-delete"); - refreshMyApps(); - refreshLibrary(); - }).catch(err => { - showToast("Customise failed, "+err, "error"); - icon.classList.remove("loading"); - icon.classList.add("icon-menu"); - }); - } + icon.classList.remove("icon-menu"); + icon.classList.add("loading"); + customApp(app); } else if (icon.classList.contains("icon-delete")) { // Remove app icon.classList.remove("icon-delete"); @@ -393,9 +388,23 @@ function removeApp(app) { }); } +function customApp(app) { + return handleCustomApp(app).then((appJSON) => { + if (appJSON) appsInstalled.push(appJSON); + showToast(app.name+" Uploaded!", "success"); + refreshMyApps(); + refreshLibrary(); + }).catch(err => { + showToast("Customise failed, "+err, "error"); + refreshMyApps(); + refreshLibrary(); + }); +} + function updateApp(app) { + if (app.custom) return customApp(app); showProgress(`Upgrading ${app.name}`,undefined,"sticky"); - Comms.removeApp(app).then(()=>{ + return Comms.removeApp(app).then(()=>{ showToast(app.name+" removed successfully. Updating...",); appsInstalled = appsInstalled.filter(a=>a.id!=app.id); return Comms.uploadApp(app); @@ -408,10 +417,13 @@ function updateApp(app) { }, err=>{ hideProgress("sticky"); showToast(app.name+" update failed, "+err,"error"); + refreshMyApps(); + refreshLibrary(); }); } + function appNameToApp(appName) { var app = appJSON.find(app=>app.id==appName); if (app) return app; diff --git a/utils.js b/js/utils.js similarity index 100% rename from utils.js rename to js/utils.js diff --git a/lib/interface.js b/lib/interface.js index 6156759b4..414c9d7fb 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -3,10 +3,21 @@ be used from within BangleApps See: README.md / `apps.json`: `interface` element -This exposes a 'Puck' object like the puck.js library, -and calls `onInit` when it's ready. `Puck` can be used -for sending/receiving data to the correctly connected +This exposes a 'Puck' object (a simple version of +https://github.com/espruino/EspruinoWebTools/blob/master/puck.js) +and calls `onInit` when it's ready. `Puck` can be used for +sending/receiving data to the correctly connected device with Puck.eval/write. + +Puck.write(data,callback) +Puck.eval(data,callback) + +There is also: + +Util.readStorageFile(filename,callback) +Util.eraseStorageFile(filename,callback) +Util.showModal(title) +Util.hideModal() */ var __id = 0, __idlookup = []; var Puck = { @@ -20,11 +31,48 @@ var Puck = { window.postMessage({type:"write",data:data,id:__id}); } }; + +var Util = { + readStorageFile : function(filename,callback) { + __id++; + __idlookup[__id] = callback; + window.postMessage({type:"readstoragefile",data:filename,id:__id}); + }, + eraseStorageFile : function(filename,callback) { + Puck.write(`\x10require("Storage").open(${JSON.stringify(filename)}","r").erase()\n`,callback); + }, + showModal : function(title) { + if (!Util.domModal) { + Util.domModal = document.createElement('div'); + Util.domModal.id = "status-modal"; + Util.domModal.classList.add("modal"); + Util.domModal.classList.add("active"); + Util.domModal.innerHTML = ` + `; + document.body.appendChild(Util.domModal); + } + Util.domModal.querySelector(".content").innerHTML = title; + Util.domModal.classList.add("active"); + }, + hideModal : function() { + if (!Util.domModal) return; + Util.domModal.classList.remove("active"); + } +}; window.addEventListener("message", function(event) { var msg = event.data; if (msg.type=="init") { onInit(); - } else if (msg.type=="evalrsp" || msg.type=="writersp") { + } else if (msg.type=="evalrsp" || msg.type=="writersp"|| msg.type=="readstoragefilersp") { var cb = __idlookup[msg.id]; delete __idlookup[msg.id]; cb(msg.data);