diff --git a/apps/activityreminder/ChangeLog b/apps/activityreminder/ChangeLog index d4b5100a2..4edb72aa5 100644 --- a/apps/activityreminder/ChangeLog +++ b/apps/activityreminder/ChangeLog @@ -3,3 +3,4 @@ 0.03: Do not alarm while charging 0.04: Obey system quiet mode 0.05: Battery optimisation, add the pause option, bug fixes +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 diff --git a/apps/activityreminder/README.md b/apps/activityreminder/README.md index 25e2c8d35..0c79b4141 100644 --- a/apps/activityreminder/README.md +++ b/apps/activityreminder/README.md @@ -11,4 +11,5 @@ Different settings can be personalized: - Dismiss delay: Delay added before the next alert if the alert is dismissed. From 5 to 60 min - Pause delay: Same as Dismiss delay but longer (usefull for meetings and such). From 30 to 240 min - Min steps: Minimal amount of steps to count as an activity +- Temp Threshold: Temperature threshold to determine if the watch is worn diff --git a/apps/activityreminder/boot.js b/apps/activityreminder/boot.js index 7c094f521..4ae9548c2 100644 --- a/apps/activityreminder/boot.js +++ b/apps/activityreminder/boot.js @@ -2,17 +2,17 @@ function run() { if (isNotWorn()) return; let now = new Date(); let h = now.getHours(); - let health = Bangle.getHealthStatus("day"); - if (h >= activityreminder_settings.startHour && h < activityreminder_settings.endHour) { + 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 10 secs after the stepsDate + minSteps - cancel all other timers of this app + 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) */ } @@ -24,22 +24,42 @@ function run() { } function isNotWorn() { - // todo in a futur release check temperature and mouvement in a futur release - return Bangle.isCharging(); + 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); + } +}); + const activityreminder = require("activityreminder"); const activityreminder_settings = activityreminder.loadSettings(); if (activityreminder_settings.enabled) { const activityreminder_data = activityreminder.loadData(); if(activityreminder_data.firstLoad){ - activityreminder_data.firstLoad =false; + activityreminder_data.firstLoad = false; activityreminder.saveData(activityreminder_data); } setInterval(run, 60000); /* todo in a futur release increase setInterval time to something that is still sensible (5 mins ?) - add settimer to trigger like 10 secs after the stepsDate + minSteps - cancel all other timers of this app + when we added a settimer */ } + diff --git a/apps/activityreminder/lib.js b/apps/activityreminder/lib.js index 5b7959827..08fffd5f4 100644 --- a/apps/activityreminder/lib.js +++ b/apps/activityreminder/lib.js @@ -8,7 +8,8 @@ exports.loadSettings = function () { maxInnactivityMin: 30, dismissDelayMin: 15, pauseDelayMin: 120, - minSteps: 50 + minSteps: 50, + tempThreshold: 27 }, storage.readJSON("activityreminder.s.json", true) || {}); }; diff --git a/apps/activityreminder/metadata.json b/apps/activityreminder/metadata.json index 15f10f2ed..752c6c101 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.05", + "version":"0.06", "icon": "app.png", "type": "app", "tags": "tool,activity", diff --git a/apps/activityreminder/settings.js b/apps/activityreminder/settings.js index 9dff61f48..f25697de0 100644 --- a/apps/activityreminder/settings.js +++ b/apps/activityreminder/settings.js @@ -55,7 +55,7 @@ }, 'Pause delay': { value: settings.pauseDelayMin, - min: 30, max: 240, + min: 30, max: 240, step: 5, onchange: v => { settings.pauseDelayMin = v; activityreminder.writeSettings(settings); @@ -66,11 +66,20 @@ }, 'Min steps': { value: settings.minSteps, - min: 10, max: 500, + 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); + } } }); }) diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index b00055334..00187fa7c 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -29,3 +29,4 @@ 0.27: New UI! 0.28: Fix bug with alarms not firing when configured to fire only once 0.29: Fix wrong 'dow' handling in new timer if first day of week is Monday +0.30: Fix "Enable All" diff --git a/apps/alarm/app.js b/apps/alarm/app.js index fe0f67dbb..2aff43de2 100644 --- a/apps/alarm/app.js +++ b/apps/alarm/app.js @@ -86,7 +86,8 @@ function showEditAlarmMenu(selectedAlarm, alarmIndex) { const menu = { "": { "title": isNew ? /*LANG*/"New Alarm" : /*LANG*/"Edit Alarm" }, "< Back": () => { - saveAlarm(alarm, alarmIndex, time); + prepareAlarmForSave(alarm, alarmIndex, time); + saveAndReload(); showMainMenu(); }, /*LANG*/"Hour": { @@ -144,7 +145,7 @@ function showEditAlarmMenu(selectedAlarm, alarmIndex) { E.showMenu(menu); } -function saveAlarm(alarm, alarmIndex, time) { +function prepareAlarmForSave(alarm, alarmIndex, time) { alarm.t = require("time_utils").encodeTime(time); alarm.last = alarm.t < require("time_utils").getCurrentTimeMillis() ? new Date().getDate() : 0; @@ -153,8 +154,6 @@ function saveAlarm(alarm, alarmIndex, time) { } else { alarms[alarmIndex] = alarm; } - - saveAndReload(); } function saveAndReload() { @@ -251,7 +250,8 @@ function showEditTimerMenu(selectedTimer, timerIndex) { const menu = { "": { "title": isNew ? /*LANG*/"New Timer" : /*LANG*/"Edit Timer" }, "< Back": () => { - saveTimer(timer, timerIndex, time); + prepareTimerForSave(timer, timerIndex, time); + saveAndReload(); showMainMenu(); }, /*LANG*/"Hours": { @@ -293,7 +293,7 @@ function showEditTimerMenu(selectedTimer, timerIndex) { E.showMenu(menu); } -function saveTimer(timer, timerIndex, time) { +function prepareTimerForSave(timer, timerIndex, time) { timer.timer = require("time_utils").encodeTime(time); timer.t = require("time_utils").getCurrentTimeMillis() + timer.timer; timer.last = 0; @@ -303,8 +303,6 @@ function saveTimer(timer, timerIndex, time) { } else { alarms[timerIndex] = timer; } - - saveAndReload(); } function showAdvancedMenu() { @@ -327,7 +325,16 @@ function enableAll(on) { } else { E.showPrompt(/*LANG*/"Are you sure?", { title: on ? /*LANG*/"Enable All" : /*LANG*/"Disable All" }).then((confirm) => { if (confirm) { - alarms.forEach(alarm => alarm.on = on); + alarms.forEach((alarm, i) => { + alarm.on = on; + if (on) { + if (alarm.timer) { + prepareTimerForSave(alarm, i, require("time_utils").decodeTime(alarm.timer)) + } else { + prepareAlarmForSave(alarm, i, require("time_utils").decodeTime(alarm.t)) + } + } + }); saveAndReload(); showMainMenu(); } else { diff --git a/apps/alarm/metadata.json b/apps/alarm/metadata.json index cac837b5e..3c17ee177 100644 --- a/apps/alarm/metadata.json +++ b/apps/alarm/metadata.json @@ -2,7 +2,7 @@ "id": "alarm", "name": "Alarms & Timers", "shortName": "Alarms", - "version": "0.29", + "version": "0.30", "description": "Set alarms and timers on your Bangle", "icon": "app.png", "tags": "tool,alarm,widget", diff --git a/apps/barclock/ChangeLog b/apps/barclock/ChangeLog index 5df032c4d..197a24738 100644 --- a/apps/barclock/ChangeLog +++ b/apps/barclock/ChangeLog @@ -9,3 +9,5 @@ 0.09: Fix time/date disappearing after fullscreen notification 0.10: Use ClockFace library 0.11: Use ClockFace.is12Hour +0.12: Add settings to hide date,widgets +0.13: Add font setting diff --git a/apps/barclock/README.md b/apps/barclock/README.md index 4b92313c5..ff66a5cbb 100644 --- a/apps/barclock/README.md +++ b/apps/barclock/README.md @@ -4,3 +4,7 @@ A simple digital clock showing seconds as a horizontal bar. | 24hr style | 12hr style | | --- | --- | | ![24-hour bar clock](screenshot.png) | ![12-hour bar clock with meridian](screenshot_pm.png) | + +## Settings +* `Show date`: display date at the bottom of screen +* `Font`: choose between bitmap or vector fonts \ No newline at end of file diff --git a/apps/barclock/clock-bar.js b/apps/barclock/clock-bar.js index 987d41cc6..61ce07dfb 100644 --- a/apps/barclock/clock-bar.js +++ b/apps/barclock/clock-bar.js @@ -51,24 +51,25 @@ function dateText(date) { 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}, // size updated below + {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}, - {height: 40}, - {id: "date", type: "txt", font: "10%", valign: 1}, + 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) { + if (this.is12Hour && locale.hasMeridian) { // Maximum font size = ( - ) / (5chars * 6px) thickness = Math.floor((Bangle.appRect.w-24)/(5*6)); } else { @@ -76,13 +77,23 @@ const ClockFace = require("ClockFace"), thickness = Math.floor(Bangle.appRect.w/(5*6)); } this.layout.bar.height = thickness+1; - this.layout.time.font = "6x8:"+thickness; + 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(); }, 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.layout.date.label = dateText(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(); diff --git a/apps/barclock/metadata.json b/apps/barclock/metadata.json index 7bc61096d..0a0b73778 100644 --- a/apps/barclock/metadata.json +++ b/apps/barclock/metadata.json @@ -1,7 +1,7 @@ { "id": "barclock", "name": "Bar Clock", - "version": "0.11", + "version": "0.13", "description": "A simple digital clock showing seconds as a bar", "icon": "clock-bar.png", "screenshots": [{"url":"screenshot.png"},{"url":"screenshot_pm.png"}], @@ -12,6 +12,10 @@ "allow_emulator": true, "storage": [ {"name":"barclock.app.js","url":"clock-bar.js"}, + {"name":"barclock.settings.js","url":"settings.js"}, {"name":"barclock.img","url":"clock-bar-icon.js","evaluate":true} + ], + "data": [ + {"name":"barclock.settings.json"} ] } diff --git a/apps/barclock/settings.js b/apps/barclock/settings.js new file mode 100644 index 000000000..3e97688a1 --- /dev/null +++ b/apps/barclock/settings.js @@ -0,0 +1,26 @@ +(function(back) { + let s = require('Storage').readJSON("barclock.settings.json", true) || {}; + + function saver(key) { + return value => { + s[key] = value; + require('Storage').writeJSON("barclock.settings.json", s); + } + } + + const fonts = [/*LANG*/"Bitmap",/*LANG*/"Vector"]; + const menu = { + "": {"title": /*LANG*/"Bar Clock"}, + /*LANG*/"< Back": back, + /*LANG*/"Show date": require("ClockFace_menu").showDate(s.showDate, saver('showDate')), + /*LANG*/"Load widgets": require("ClockFace_menu").loadWidgets(s.loadWidgets, saver('loadWidgets')), + /*LANG*/"Font": { + value: s.font|0, + min:0,max:1,wrap:true, + format:v=>fonts[v], + onchange:saver('font'), + }, + }; + + E.showMenu(menu); +}); diff --git a/apps/barcode/ChangeLog b/apps/barcode/ChangeLog new file mode 100644 index 000000000..4f99f15ac --- /dev/null +++ b/apps/barcode/ChangeLog @@ -0,0 +1,9 @@ +0.01: Please forgive me +0.02: Now tells time! +0.03: Interaction +0.04: Shows day of week +0.05: Shows day of month +0.06: Updates every 5 minutes when locked, or when unlock occurs. Also shows nr of steps. +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...) diff --git a/apps/barcode/README.md b/apps/barcode/README.md new file mode 100644 index 000000000..17b365d45 --- /dev/null +++ b/apps/barcode/README.md @@ -0,0 +1,23 @@ +# Barcode clockwatchface + +A scannable EAN-8 compatible clockwatchface for your Bangle 2 + +The format of the bars are + +`||HHmm||MMwc||` + +* Left section: HHmm + * H: Hours + * m: Minutes +* Right section: MM9c + * M: Day of month + * w: Day of week + * c: Calculated EAN-8 digit checksum + +Apart from that + +* The upper left section displays total number of steps per day +* The upper right section displays total number of steps from last boot ("stepuptime") +* The face updates every 5 minutes or on demant by pressing the hardware button + +This clockwathface is aware of theme choice, so it will adapt to Light/Dark themes. diff --git a/apps/barcode/barcode.app.js b/apps/barcode/barcode.app.js new file mode 100644 index 000000000..89419f33c --- /dev/null +++ b/apps/barcode/barcode.app.js @@ -0,0 +1,428 @@ +/* Sizes */ +let checkBarWidth = 10; +let checkBarHeight = 140; + +let digitBarWidth = 14; +let digitBarHeight = 100; + +let textBarWidth = 56; +let textBarHeight = 20; + +let textWidth = 14; +let textHeight = 20; + +/* Offsets */ +var startOffsetX = 17; +var startOffsetY = 30; + +let startBarOffsetX = startOffsetX; +let startBarOffsetY = startOffsetY; + +let upperTextBarLeftOffsetX = startBarOffsetX + checkBarWidth; +let upperTextBarLeftOffsetY = startOffsetY; + +let midBarOffsetX = upperTextBarLeftOffsetX + textBarWidth; +let midBarOffsetY = startOffsetY; + +let upperTextBarRightOffsetX = midBarOffsetX + checkBarWidth; +let upperTextBarRightOffsetY = startOffsetY; + +let endBarOffsetX = upperTextBarRightOffsetX + textBarWidth; +let endBarOffsetY = startOffsetY; + +let leftBarsStartX = startBarOffsetX + checkBarWidth; +let leftBarsStartY = upperTextBarLeftOffsetY + textBarHeight; + +let rightBarsStartX = midBarOffsetX + checkBarWidth; +let rightBarsStartY = upperTextBarRightOffsetY + textBarHeight; + +/* Utilities */ +let stepCount = require("Storage").readJSON("stepCount",1); +if(stepCount === undefined) stepCount = 0; +let intCaster = num => Number(num); + +var drawTimeout; + +function renderWatch(l) { + g.setFont("4x6",2); + + // work out how to display the current time + + var d = new Date(); + var h = d.getHours(), m = d.getMinutes(); + var time = h + ":" + ("0"+m).substr(-2); + //var month = ("0" + (d.getMonth()+1)).slice(-2); + var dayOfMonth = ('0' + d.getDate()).slice(-2); + var dayOfWeek = d.getDay() || 7; + var concatTime = ("0"+h).substr(-2) + ("0"+m).substr(-2) + dayOfMonth + dayOfWeek; + + const chars = String(concatTime).split("").map((concatTime) => { + return Number(concatTime); + }); + const checkSum = calculateChecksum(chars); + concatTime += checkSum; + + drawCheckBar(startBarOffsetX, startBarOffsetY); + + drawLDigit(chars[0], 0, leftBarsStartY); + drawLDigit(chars[1], 1, leftBarsStartY); + drawLDigit(chars[2], 2, leftBarsStartY); + drawLDigit(chars[3], 3, leftBarsStartY); + + g.drawString(getStepCount(), startOffsetX + checkBarWidth + 3, startOffsetY + 4); + g.drawString(concatTime.substring(0,4), startOffsetX + checkBarWidth + 3, startOffsetY + textBarHeight + digitBarHeight + 6); + + drawCheckBar(midBarOffsetX, midBarOffsetY); + + drawRDigit(chars[4], 0, rightBarsStartY); + drawRDigit(chars[5], 1, rightBarsStartY); + drawRDigit(chars[6], 2, rightBarsStartY); + drawRDigit(checkSum, 3, rightBarsStartY); + + g.drawString(Bangle.getStepCount(), midBarOffsetX + checkBarWidth + 3, startOffsetY + 4); + g.drawString(concatTime.substring(4), midBarOffsetX + checkBarWidth + 3, startOffsetY + textBarHeight + digitBarHeight + 6); + + drawCheckBar(endBarOffsetX, endBarOffsetY); + + // schedule a draw for the next minute + if (drawTimeout) { + clearTimeout(drawTimeout); + } + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + layout.render(layout.watch); + }, (1000 * 60 * 5) - (Date.now() % (1000 * 60 * 5))); +} + +function drawLDigit(digit, index, offsetY) { + switch(digit) { + case 0: + drawLZeroWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 1: + drawLOneWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 2: + drawLTwoWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 3: + drawLThreeWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 4: + drawLFourWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 5: + drawLFiveWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 6: + drawLSixWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 7: + drawLSevenWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 8: + drawLEightWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + case 9: + drawLNineWithOffset(leftBarsStartX+(digitBarWidth*index), offsetY); + break; + } +} + +function drawRDigit(digit, index, offsetY) { + switch(digit) { + case 0: + drawRZeroWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 1: + drawROneWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 2: + drawRTwoWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 3: + drawRThreeWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 4: + drawRFourWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 5: + drawRFiveWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 6: + drawRSixWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 7: + drawRSevenWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 8: + drawREightWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + case 9: + drawRNineWithOffset(rightBarsStartX+(digitBarWidth*index), offsetY); + break; + } +} + +/* +LEAN + +01234567890123 + xxxx xx + xx xxxx + xxxxxxxx xx + xx xxxx + xxxx xx + xx xxxxxxxx + xxxxxx xxxx + xxxx xxxxxx + xx xxxx + xxxx xx +*/ +function drawLOneWithOffset(offset, offsetY) { + let barOneX = 4; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("1",offset+3,offsetY+digitHeight+5); +} + +function drawLTwoWithOffset(offset, offsetY) { + let barOneX = 4; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitBarHeight); + //g.drawString("2",offset+3,offsetY+digitHeight+5); +} + +function drawLThreeWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+7+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("3",offset+3,offsetY+digitHeight+5); +} + +function drawLFourWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitBarHeight); + //g.drawString("4",offset+3,offsetY+digitHeight+5); +} + +function drawLFiveWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("5",offset+3,offsetY+digitHeight+5); +} + +function drawLSixWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 6; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+7+offset,offsetY+digitBarHeight); + //g.drawString("6",offset+3,offsetY+digitHeight+5); +} + +function drawLSevenWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+5+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitBarHeight); + //g.drawString("7",offset+3,offsetY+digitHeight+5); +} + +function drawLEightWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 8; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+5+offset,offsetY+digitBarHeight); + //g.drawString("8",offset+3,offsetY+digitHeight+5); +} + +function drawLNineWithOffset(offset, offsetY) { + let barOneX = 6; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitBarHeight); + //g.drawString("9",offset+3,offsetY+digitHeight+5); +} + +function drawLZeroWithOffset(offset, offsetY) { + let barOneX = 6; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("0",offset+3,offsetY+digitHeight+5); +} + + + +/* +REAN + +01234567890123 +xxxx xxxx +xxxx xxxx +xx xx +xx xxxxxx +xx xxxxxx +xx xx +xx xx +xx xx +xxxxxx xx +xxxxxx xx + +*/ +function drawROneWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 8; + g.fillRect(offset+barOneX,offsetY+0,offset+barOneX+3,offsetY+digitBarHeight); + g.fillRect(offset+barTwoX,offsetY+0,offset+barTwoX+3,offsetY+digitBarHeight); + //g.drawString("1",offset+2,offsetY+textHeight+5); +} + +function drawRTwoWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 6; + g.fillRect(offset+barOneX,offsetY+0,offset+barOneX+3,offsetY+digitBarHeight); + g.fillRect(offset+barTwoX,offsetY+0,offset+barTwoX+3,offsetY+digitBarHeight); + //g.drawString("2",offset+2,offsetY+textHeight+5); +} + +function drawRThreeWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("3",offset+2,offsetY+textHeight+5); +} + +function drawRFourWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 4; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+5+offset,offsetY+digitBarHeight); + //g.drawString("4",offset+2,offsetY+textHeight+5); +} + +function drawRFiveWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 6; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+5+offset,offsetY+digitBarHeight); + //g.drawString("5",offset+2,offsetY+textHeight+5); +} + +function drawRSixWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 4; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("6",offset+2,offsetY+textHeight+5); +} + +function drawRSevenWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 8; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("7",offset+2,offsetY+textHeight+5); +} + +function drawREightWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 6; + g.fillRect(offset+barOneX,offsetY+0,offset+barOneX+1,offsetY+digitBarHeight); + g.fillRect(offset+barTwoX,offsetY+0,offset+barTwoX+1,offsetY+digitBarHeight); + //g.drawString("8",offset+2,offsetY+textHeight+5); +} + +function drawRNineWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 8; + g.fillRect(barOneX+offset,offsetY+0,barOneX+5+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("9",offset+2,offsetY+textHeight+5); +} + +function drawRZeroWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+5+offset,offsetY+digitBarHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitBarHeight); + //g.drawString("0",offset+2,offsetY+textHeight+5); +} + +function drawCheckBar(offsetX, offsetY) { + const barOneX = offsetX+2; + const barOneWidth = 1; + const barTwoX = offsetX+6; + const barTwoWidth = 1; + g.fillRect(barOneX,offsetY,barOneX+barOneWidth,offsetY+checkBarHeight); + g.fillRect(barTwoX,offsetY,barTwoX+barTwoWidth,offsetY+checkBarHeight); +} + +function calculateChecksum(digits) { + let oddSum = digits[6] + digits[4] + digits[2] + digits[0]; + let evenSum = digits[5] + digits[3] + digits[1]; + + let checkSum = (10 - ((3 * oddSum + evenSum) % 10)) % 10; + + return checkSum; +} + +function storeStepCount() { + stepCount = Bangle.getStepCount(); + require("Storage").writeJSON("stepCount",stepCount); +} + +function getStepCount() { + let accumulatedSteps = Bangle.getStepCount(); + if(accumulatedSteps <= stepCount) { + return 0; + } + return accumulatedSteps - stepCount; +} + +function resetAtMidnight() { + let now = new Date(); + let night = new Date( + now.getFullYear(), + now.getMonth(), + now.getDate(), // the next day, ... + 23, 58, 0 // ...at 00:00:00 hours +); + let msToMidnight = night.getTime() - now.getTime(); + + setTimeout(function() { + storeStepCount(); // <-- This is the function being called at midnight. + resetAtMidnight(); // Then, reset again next midnight. + }, msToMidnight); +} + +resetAtMidnight(); + +// The layout, referencing the custom renderer +var Layout = require("Layout"); +var layout = new Layout( { + type:"v", c: [ + {type:"custom", render:renderWatch, id:"watch", bgCol:g.theme.bg, fillx:1, filly:1 } + ] +}); + +// Clear the screen once, at startup +g.clear(); +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/barcode.clock.png b/apps/barcode/barcode.clock.png new file mode 100644 index 000000000..7d249cdeb Binary files /dev/null and b/apps/barcode/barcode.clock.png differ diff --git a/apps/barcode/barcode.icon.js b/apps/barcode/barcode.icon.js new file mode 100644 index 000000000..969943e0e --- /dev/null +++ b/apps/barcode/barcode.icon.js @@ -0,0 +1 @@ +E.toArrayBuffer(atob("MDAE///+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifnD6khY+bTIiDTIn8gWq8n+if/////+ifrV6mlp+rXYiFXZr8k4q8r+if/////+if7+///u//79ie7/7//u///+if/////+ifnP6t+378r+ienvyf/K/7v+if/////+ifrfx6/I78j+ibe/+e/W75n+if/////+iee/+t/Z77f+iervyv/r/7v+if//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////")) diff --git a/apps/barcode/barcode.icon.png b/apps/barcode/barcode.icon.png new file mode 100644 index 000000000..43fa77a6f Binary files /dev/null and b/apps/barcode/barcode.icon.png differ diff --git a/apps/barcode/metadata.json b/apps/barcode/metadata.json new file mode 100644 index 000000000..cef267b2b --- /dev/null +++ b/apps/barcode/metadata.json @@ -0,0 +1,16 @@ +{ "id": "barcode", + "name": "Barcode clock", + "shortName":"Barcode clock", + "icon": "barcode.icon.png", + "version":"0.09", + "description": "EAN-8 compatible barcode clock.", + "tags": "barcode,ean,ean-8,watchface,clock,clockface", + "type": "clock", + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"barcode.app.js","url":"barcode.app.js"}, + {"name":"barcode.img","url":"barcode.icon.js","evaluate":true} + ], + "readme":"README.md", + "screenshots": [{"url":"barcode.clock.png"}] +} diff --git a/apps/calendar/ChangeLog b/apps/calendar/ChangeLog index ea8934f84..873f90de6 100644 --- a/apps/calendar/ChangeLog +++ b/apps/calendar/ChangeLog @@ -7,3 +7,4 @@ 0.07: Fix off-by-one-error on previous month 0.08: Do not register as watch, manually start clock on button read start of week from system settings +0.09: Fix scope of let variables diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index fc7e93cf5..f4676fc22 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -16,6 +16,12 @@ const white = "#ffffff"; const red = "#d41706"; const blue = "#0000ff"; const yellow = "#ffff00"; +let bgColor = color4; +let bgColorMonth = color1; +let bgColorDow = color2; +let bgColorWeekend = color3; +let fgOtherMonth = gray1; +let fgSameMonth = white; let settings = require('Storage').readJSON("calendar.json", true) || {}; let startOnSun = ((require("Storage").readJSON("setting.json", true) || {}).firstDayOfWeek || 0) === 0; @@ -27,19 +33,12 @@ if (settings.ndColors === undefined) } if (settings.ndColors === true) { - let bgColor = white; - let bgColorMonth = blue; - let bgColorDow = black; - let bgColorWeekend = yellow; - let fgOtherMonth = blue; - let fgSameMonth = black; -} else { - let bgColor = color4; - let bgColorMonth = color1; - let bgColorDow = color2; - let bgColorWeekend = color3; - let fgOtherMonth = gray1; - let fgSameMonth = white; + bgColor = white; + bgColorMonth = blue; + bgColorDow = black; + bgColorWeekend = yellow; + fgOtherMonth = blue; + fgSameMonth = black; } function getDowLbls(locale) { diff --git a/apps/calendar/metadata.json b/apps/calendar/metadata.json index 5f968b364..65a54c097 100644 --- a/apps/calendar/metadata.json +++ b/apps/calendar/metadata.json @@ -1,7 +1,7 @@ { "id": "calendar", "name": "Calendar", - "version": "0.08", + "version": "0.09", "description": "Simple calendar", "icon": "calendar.png", "screenshots": [{"url":"screenshot_calendar.png"}], diff --git a/apps/calibration/ChangeLog b/apps/calibration/ChangeLog new file mode 100644 index 000000000..0e22605af --- /dev/null +++ b/apps/calibration/ChangeLog @@ -0,0 +1,2 @@ +1.00: New App! +1.01: Use fractional numbers and scale the points to keep working consistently on whole screen diff --git a/apps/calibration/README.md b/apps/calibration/README.md index 37f637d21..ed1a29d9e 100644 --- a/apps/calibration/README.md +++ b/apps/calibration/README.md @@ -6,6 +6,7 @@ A simple calibration app for the touchscreen Once lauched touch the cross that appear on the screen to make another spawn elsewhere. -each new touch on the screen will help to calibrate the offset -of your finger on the screen. After five or more input, press -the button to save the calibration and close the application. \ No newline at end of file +Each new touch on the screen will help to calibrate the offset +of your finger on the screen. After four or more inputs, press +the button to save the calibration and close the application. Quality +of the calibration gets better with every touch on a cross. diff --git a/apps/calibration/app.js b/apps/calibration/app.js index d3823de63..049430d45 100644 --- a/apps/calibration/app.js +++ b/apps/calibration/app.js @@ -1,40 +1,60 @@ class BanglejsApp { constructor() { + this.maxSamples = 16; + this.target = { + xMin: Math.floor(0.1 * g.getWidth()), + xMax: Math.floor(0.9 * g.getWidth()), + yMin: Math.floor(0.1 * g.getHeight()), + yMax: Math.floor(0.9 * g.getHeight()), + }; this.x = 0; this.y = 0; + this.step = 0; this.settings = { - xoffset: 0, - yoffset: 0, + xoffset: [0], + yoffset: [0], + xMaxActual: [this.target.xMax], + yMaxActual: [this.target.yMax], }; } load_settings() { let settings = require('Storage').readJSON('calibration.json', true) || {active: false}; - // do nothing if the calibration is deactivated - if (settings.active === true) { - // cancel the calibration offset - Bangle.on('touch', function(button, xy) { - xy.x += settings.xoffset; - xy.y += settings.yoffset; - }); - } - if (!settings.xoffset) settings.xoffset = 0; - if (!settings.yoffset) settings.yoffset = 0; - console.log('loaded settings:'); console.log(settings); return settings; } - save_settings() { - this.settings.active = true; - this.settings.reload = false; - require('Storage').writeJSON('calibration.json', this.settings); + getMedian(array){ + array.sort(); + let i = Math.floor(array.length/2); + if ( array.length % 2 && array.length > 1 ){ + return (array[i]+array[i+1])/2; + } else { + return array[i]; + } + } - console.log('saved settings:'); - console.log(this.settings); + getMedianSettings(){ + let medianSettings = { + xoffset: this.getMedian(this.settings.xoffset), + yoffset: this.getMedian(this.settings.yoffset) + }; + + medianSettings.xscale = this.target.xMax / (medianSettings.xoffset + this.getMedian(this.settings.xMaxActual)); + medianSettings.yscale = this.target.yMax / (medianSettings.yoffset + this.getMedian(this.settings.yMaxActual)); + return medianSettings; + } + + save_settings() { + let settingsToSave = this.getMedianSettings(); + settingsToSave.active = true; + settingsToSave.reload = false; + require('Storage').writeJSON('calibration.json', settingsToSave); + + console.log('saved settings:', settingsToSave); } explain() { @@ -46,29 +66,78 @@ class BanglejsApp { } drawTarget() { - this.x = 16 + Math.floor(Math.random() * (g.getWidth() - 32)); - this.y = 40 + Math.floor(Math.random() * (g.getHeight() - 80)); + switch (this.step){ + case 0: + this.x = this.target.xMin; + this.y = this.target.yMin; + break; + case 1: + this.x = this.target.xMax; + this.y = this.target.yMin; + break; + case 2: + this.x = this.target.xMin; + this.y = this.target.yMax; + break; + case 3: + this.x = this.target.xMax; + this.y = this.target.yMax; + break; + } - g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24); + g.clearRect(0, 0, g.getWidth(), g.getHeight()); + g.setColor(g.theme.fg); g.drawLine(this.x, this.y - 5, this.x, this.y + 5); g.drawLine(this.x - 5, this.y, this.x + 5, this.y); g.setFont('Vector', 10); - g.drawString('current offset: ' + this.settings.xoffset + ', ' + this.settings.yoffset, 0, 24); + let medianSettings = this.getMedianSettings(); + g.drawString('current offset: ' + medianSettings.xoffset.toFixed(3) + ', ' + medianSettings.yoffset.toFixed(3), 2, (g.getHeight()/2)-6); + g.drawString('current scale: ' + medianSettings.xscale.toFixed(3) + ', ' + medianSettings.yscale.toFixed(3), 2, (g.getHeight()/2)+6); } setOffset(xy) { - this.settings.xoffset = Math.round((this.settings.xoffset + (this.x - Math.floor((this.x + xy.x)/2)))/2); - this.settings.yoffset = Math.round((this.settings.yoffset + (this.y - Math.floor((this.y + xy.y)/2)))/2); + switch (this.step){ + case 0: + this.settings.xoffset.push(this.x - xy.x); + this.settings.yoffset.push(this.y - xy.y); + break; + case 1: + this.settings.xMaxActual.push(xy.x); + this.settings.yoffset.push(this.y - xy.y); + break; + case 2: + this.settings.xoffset.push(this.x - xy.x); + this.settings.yMaxActual.push(xy.y); + break; + case 3: + this.settings.xMaxActual.push(xy.x); + this.settings.yMaxActual.push(xy.y); + break; + } + + for (let c in this.settings){ + if (this.settings[c].length > this.maxSamples) this.settings[c] = this.settings[c].slice(1, this.maxSamples); + } + } + + nextStep() { + this.step++; + if ( this.step == 4 ) this.step = 0; } } E.srand(Date.now()); -Bangle.loadWidgets(); -Bangle.drawWidgets(); calibration = new BanglejsApp(); calibration.load_settings(); +Bangle.disableCalibration = true; + +function touchHandler (btn, xy){ + if (xy) calibration.setOffset(xy); + calibration.nextStep(); + calibration.drawTarget(); +} let modes = { mode : 'custom', @@ -76,10 +145,7 @@ let modes = { calibration.save_settings(this.settings); load(); }, - touch : function(btn, xy) { - calibration.setOffset(xy); - calibration.drawTarget(); - }, + touch : touchHandler, }; Bangle.setUI(modes); calibration.drawTarget(); diff --git a/apps/calibration/boot.js b/apps/calibration/boot.js index 237fb2e0d..03b17a03a 100644 --- a/apps/calibration/boot.js +++ b/apps/calibration/boot.js @@ -1,7 +1,7 @@ let cal_settings = require('Storage').readJSON("calibration.json", true) || {active: false}; Bangle.on('touch', function(button, xy) { // do nothing if the calibration is deactivated - if (cal_settings.active === false) return; + if (cal_settings.active === false || Bangle.disableCalibration) return; // reload the calibration offset at each touch event /!\ bad for the flash memory if (cal_settings.reload === true) { @@ -9,6 +9,6 @@ Bangle.on('touch', function(button, xy) { } // apply the calibration offset - xy.x += cal_settings.xoffset; - xy.y += cal_settings.yoffset; + xy.x = E.clip(Math.round((xy.x + (cal_settings.xoffset || 0)) * (cal_settings.xscale || 1)),0,g.getWidth()); + xy.y = E.clip(Math.round((xy.y + (cal_settings.yoffset || 0)) * (cal_settings.yscale || 1)),0,g.getHeight()); }); diff --git a/apps/calibration/metadata.json b/apps/calibration/metadata.json index 122a2c175..b7a719e1c 100644 --- a/apps/calibration/metadata.json +++ b/apps/calibration/metadata.json @@ -2,7 +2,7 @@ "name": "Touchscreen Calibration", "shortName":"Calibration", "icon": "calibration.png", - "version":"1.00", + "version":"1.01", "description": "A simple calibration app for the touchscreen", "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", diff --git a/apps/cogclock/15x32.png b/apps/cogclock/15x32.png new file mode 100644 index 000000000..0af326e71 Binary files /dev/null and b/apps/cogclock/15x32.png differ diff --git a/apps/cogclock/ChangeLog b/apps/cogclock/ChangeLog new file mode 100644 index 000000000..3158b6116 --- /dev/null +++ b/apps/cogclock/ChangeLog @@ -0,0 +1,2 @@ +0.01: New clock +0.02: Use ClockFace library, add settings diff --git a/apps/cogclock/app.js b/apps/cogclock/app.js new file mode 100644 index 000000000..d24031684 --- /dev/null +++ b/apps/cogclock/app.js @@ -0,0 +1,111 @@ +Graphics.prototype.setFont15x32N = function() { + this.setFontCustom(atob( + // 15x32.png, converted using http://ebfc.mattbrailsford.com/ + "/////oAAAAKAAAACgAAAAoAAAAKAAAACgf//AoEAAQKB//8CgAAAAoAAAAKAAAACgAAAAoAAAAL////+/wAB/oEAAQKBAAECgf//AoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAAC////AgAAAQIAAAH+/w///oEIAAKBCAACgQgAAoEIAAKBCAACgQg/AoEIIQKB+CECgAAhAoAAIQKAACECgAAhAoAAIQL//+H+/w/h/oEIIQKBCCECgQghAoEIIQKBCCECgQghAoEIIQKB+D8CgAAAAoAAAAKAAAACgAAAAoAAAAL////+///gAIAAIACAACAAgAAgAIAAIAD/+CAAAAggAAAIIAAACD/+//gAAoAAAAKAAAACgAAAAoAAAAL////+///h/oAAIQKAACECgAAhAoAAIQKAACECgfghAoEIIQKBCD8CgQgAAoEIAAKBCAACgQgAAoEIAAL/D//+/////oAAAAKAAAACgAAAAoAAAAKAAAACgfg/AoEIIQKBCD8CgQgAAoEIAAKBCAACgQgAAoEIAAL/D//+/wAAAIEAAACBAAAAgQAAAIEAAACBAAAAgQAAAIH///6AAAACgAAAAoAAAAKAAAACgAAAAoAAAAL////+/////oAAAAKAAAACgAAAAoAAAAKAAAACgfg/AoEIIQKB+D8CgAAAAoAAAAKAAAACgAAAAoAAAAL////+///h/oAAIQKAACECgAAhAoAAIQKAACECgfghAoEIIQKB+D8CgAAAAoAAAAKAAAACgAAAAoAAAAL////+" + ), "0".charCodeAt(0), 15, 32); +}; + +/** + * Add coordinates for nth tooth to vertices + * @param {array} poly Array to add points to + * @param {number} n Tooth number + */ +function addTooth(poly, n) { + const + tau = Math.PI*2, arc = tau/clock.teeth, + e = arc*clock.edge, p = arc*clock.point, s = (arc-(e+p))/2; // edge,point,slopes + const sin = Math.sin, cos = Math.cos, + x = clock.x, y = clock.y, + r2 = clock.r2, r3 = clock.r3; + let r = (n-1)*arc+e/2; // rads + poly.push(x+r2*sin(r), y-r2*cos(r)); + r += s; + poly.push(x+r3*sin(r), y-r3*cos(r)); + r += p; + poly.push(x+r3*sin(r), y-r3*cos(r)); + r += s; + poly.push(x+r2*sin(r), y-r2*cos(r)); +} + +/** + * @param {number} n Tooth number to fill (1-based) + * @param col Fill color + */ +function fillTooth(n, col) { + if (!n) return; // easiest to check here + let poly = []; + addTooth(poly, n); + g.setColor(col).fillPoly(poly) + .setColor(g.theme.fg2).drawPoly(poly); // fillPoly colored over the outline +} + +const ClockFace = require("ClockFace"); +const clock = new ClockFace({ + precision: 1, + settingsFile: "cogclock.settings.json", + init: function() { + this.r1 = 84; // inner radius + this.r3 = Math.min(Bangle.appRect.w/2, Bangle.appRect.h/2); // outer radius + this.r2 = (this.r1*3+this.r3*2)/5; + this.teeth = 12; + this.edge = 0.45; + this.point = 0.35; // as fraction of arc + this.x = Bangle.appRect.x+Bangle.appRect.w/2; + this.y = Bangle.appRect.y+Bangle.appRect.h/2; + }, + draw: function(d) { + const x = this.x, y = this.y; + g.setColor(g.theme.bg2).fillCircle(x, y, this.r2) // fill cog + .setColor(g.theme.bg).fillCircle(x, y, this.r1) // clear center + .setColor(g.theme.fg2).drawCircle(x, y, this.r1); // draw inner border + let poly = []; // complete teeth outline + for(let t = 1; t<=this.teeth; t++) { + fillTooth(t, g.theme.bg2); + addTooth(poly, t); + } + g.drawPoly(poly, true); // draw outer border + if (!this.showDate) { + // draw top/bottom rectangles (instead of year/date) + g.reset() + .fillRect(x-30, y-60, x+29, y-33).clearRect(x-28, y-58, x+27, y-33) + .fillRect(x-30, y+60, x+29, y+30).clearRect(x-28, y+58, x+27, y+30); + } + this.tooth = 0; + this.update(d, {s: 1, m: 1, h: 1, d: 1}); + }, + update: function(d, c) { + g.reset(); + const pad2 = num => (num<10 ? "0" : "")+num, + year = d.getFullYear(), + date = pad2(d.getDate())+pad2(d.getMonth()), + time = pad2(d.getHours())+pad2(d.getMinutes()), + tooth = Math.round(d.getSeconds()/60*this.teeth); + const x = this.x, y = this.y; + if (c.m) { + g.setFont("15x32N:2").setFontAlign(0, 0) // center middle + .drawString(time, x, y, true); + } + if (this.showDate) { + if (c.d) { + g.setFont("15x32N").setFontAlign(0, -1) // center top + .drawString(year, x, y+32, true) + .setFont("15x32N").setFontAlign(0, 1) // center bottom + .drawString(date, x, y-32, true); + } + } + + if (tooth!==this.tooth) { + if (tooth>this.tooth) { + for(let t = this.tooth; t<=tooth; t++) { // fill missing teeth + fillTooth(t, g.theme.fg2); + } + } else { + for(let t = this.tooth; t>tooth; t--) { // erase extraneous teeth + fillTooth(t, g.theme.bg2); + } + } + } + this.tooth = tooth; + } +}); +clock.start(); diff --git a/apps/cogclock/icon.js b/apps/cogclock/icon.js new file mode 100644 index 000000000..899cfc7c1 --- /dev/null +++ b/apps/cogclock/icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwhC/ACcikQXpCQUCC4MgBAgqMCQIXEAgQXNBwIDCAggXOABAXLHwQAHMYQXmmczI5oiCBwUjCwIABmQXDEgJ0KCwMwCwMDDAgyGLYoWBgAXBgAYBMZIXEkYWBC4YYBGAh7FFwgHCC4YEBPRIwCFwYXFGAaqHC56oIIwgXFJAbUJLwpgHI4qPDIwpIFR4wWDLwa6BAAQHDVIYYCC/gYCC453MPIR3HU5gADd5bXHC4rvJMAYAECwJeCd5MjGAjVDC4ZHGNARIFGAgNDFw5IJUogwFC4gwBDAhGBBghIFBQhhBbYguEPAweCDAgACCwZACNg5LFXQYsIC5QAFdg4XcCxJHNBwYTEC6A+BJYQEEC5YYBMYhbCCxo0GCaIXbAHgA=")) \ No newline at end of file diff --git a/apps/cogclock/icon.png b/apps/cogclock/icon.png new file mode 100644 index 000000000..8520fcf5d Binary files /dev/null and b/apps/cogclock/icon.png differ diff --git a/apps/cogclock/metadata.json b/apps/cogclock/metadata.json new file mode 100644 index 000000000..40733bcd1 --- /dev/null +++ b/apps/cogclock/metadata.json @@ -0,0 +1,20 @@ +{ + "id": "cogclock", + "name": "Cog Clock", + "version": "0.02", + "description": "A cross-shaped clock inside a cog", + "icon": "icon.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock", + "supports": ["BANGLEJS"], + "allow_emulator": true, + "storage": [ + {"name":"cogclock.app.js","url":"app.js"}, + {"name":"cogclock.settings.js","url":"settings.js"}, + {"name":"cogclock.img","url":"icon.js","evaluate":true} + ], + "data": [ + {"name": "cogclock.settings.json"} + ] +} diff --git a/apps/cogclock/screenshot.png b/apps/cogclock/screenshot.png new file mode 100644 index 000000000..f49709aef Binary files /dev/null and b/apps/cogclock/screenshot.png differ diff --git a/apps/cogclock/settings.js b/apps/cogclock/settings.js new file mode 100644 index 000000000..4eadc32c2 --- /dev/null +++ b/apps/cogclock/settings.js @@ -0,0 +1,19 @@ +(function(back) { + let s = require('Storage').readJSON("cogclock.settings.json", true) || {}; + + function saver(key) { + return value => { + s[key] = value; + require('Storage').writeJSON("cogclock.settings.json", s); + } + } + + const menu = { + "": {"title": /*LANG*/"Cog Clock"}, + /*LANG*/"< Back": back, + /*LANG*/"Show date": require("ClockFace_menu").showDate(s.showDate, saver('showDate')), + /*LANG*/"Load widgets": require("ClockFace_menu").loadWidgets(s.loadWidgets, saver('loadWidgets')), + }; + + E.showMenu(menu); +}); diff --git a/apps/homework/app.js b/apps/homework/app.js index 4ba786690..3d9be31c9 100644 --- a/apps/homework/app.js +++ b/apps/homework/app.js @@ -14,7 +14,7 @@ var nhwmn = { // New homework Menu function newHomeworkMenu() { E.showMessage("Getting subjects..."); - var rawsubjects = require("Storage").read("subjects.txt"); // This code reads out the subjects list and removes the newline character at the end + var rawsubjects = require("Storage").read("homework.subjects.txt"); // This code reads out the subjects list and removes the newline character at the end var splitsubjects = rawsubjects.split(","); var lastItem = splitsubjects[splitsubjects.length - 1]; var thiscurrentsubject; diff --git a/apps/homework/metadata.json b/apps/homework/metadata.json index 2ba1e918f..a46c74dad 100644 --- a/apps/homework/metadata.json +++ b/apps/homework/metadata.json @@ -9,6 +9,10 @@ "supports" : ["BANGLEJS2"], "readme": "README.md", "custom": "subjects.html", + "data": [ + {"name":"homework.txt" }, + {"name":"homework.subjects.txt" } + ], "storage": [ {"name":"homework.app.js","url":"app.js"}, {"name":"homework.img","url":"app-icon.js","evaluate":true} diff --git a/apps/homework/subjects.html b/apps/homework/subjects.html index d3bf7a400..92c3023dd 100644 --- a/apps/homework/subjects.html +++ b/apps/homework/subjects.html @@ -20,9 +20,10 @@ // send finished app (in addition to contents of app.json) sendCustomizedApp({ storage:[ - {name:"subjects.txt"}, + {name:"homework.subjects.txt", url:"subjects.txt", content:app}, ] }); + console.log("Sent homework.subjects.txt!"); }); diff --git a/apps/invader/ChangeLog b/apps/invader/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/invader/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/invader/README.md b/apps/invader/README.md new file mode 100644 index 000000000..7ed98defb --- /dev/null +++ b/apps/invader/README.md @@ -0,0 +1,23 @@ +# App Name + +Invader + +## Usage + +For fun! - I'm creating this demo to learn JavaScript with the Bangle.js 2 + +## Features + +Shoot the Alien, you have three lives + +## Controls + +Touch the lower Left or Right hand sides of the screen to move turret left or right, tap upper Right hand part of screen to fire, tap upper Left hand part of screen to restart + +## Requests + +bkumanchik on Espruino Forums + +## Creator + +Brian Kumanchik 2022 diff --git a/apps/invader/app-icon.js b/apps/invader/app-icon.js new file mode 100644 index 000000000..dc7003c84 --- /dev/null +++ b/apps/invader/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwhHXAH4A/AH4A/AH4AYgAACC/4X/C/YbTFbYv/F/4rTAC4v/F/4vfC5YnPGaYv/F/4vLc7b3TF/4v/F/4v/F/4vTA5YAPE64v/F/4fTa55DXF/4v/AH4A/AH4A/AH4A/AHIA==")) diff --git a/apps/invader/app.js b/apps/invader/app.js new file mode 100644 index 000000000..89e7462f6 --- /dev/null +++ b/apps/invader/app.js @@ -0,0 +1,452 @@ +// Brian Kumanchik +// Started 05-25-22 +// My Invader Demo, for Bangle.js 2, written JavaScript - using Espruino Web IDE + + +// note: resolution is 176x176 + + +// to do: +// upload to official app page +// make invader clock + + + +// - variables ----------------------------------------- +// invader variables +var inv_x = 77; +var inv_y = 20; +var i_anim_delay = 10; // invader animation (and move) delay +var inv_frame = 1; // invader start animation frame +var ix_speed = 6; // march speed +var i_dir = 1; // 1 = right, 0 = left +var been_hit = false; // invader hit state +// - shoot variables +var inv_shot_x = -32; +var inv_shot_y = -32; +var inv_fire_pause = 30; +var inv_fired = false; // invader fired state +// - explode variables +var been_hit = false; // invader hit state +var bx = -32; // blast x +var by = -32; // blast y +var blast_delay = 15; // invader blast delay - pause after explosion +var boom_play = false; + +// turret variables +var tur_x = 77; +var tur_y = 148; +var shot_fired = false; // turret fired state +var sx = -20; // turret shot starting x - off screen +var sy = -20; // turret shot starting y - off screen +var turret_been_hit = false; +var turret_blast_delay = 25; // keep blast active on screen for 60 frames +var turret_exp_frame = 1; // turret explode start animation frame +var turret_anim_delay = 3; // turret explode animation delay +var explosion_play = false; + +// misc variables +var score = 0; // starting score +var lives = 3; // starting lives +var game_state = 0; // game state - 0 = game not started, 1 = game running, 3 = game over +var ang = 0.1; +var start_been_pressed = false; // stops double press on restart +var fire_been_pressed = false; // stops auto fire + +// input(screen controller) variables +var BTNL, BTNR, BTNF, BTNS; // button - left, right, fire, start +var tap = {}; +// use tapping on screen for left, right, fire, start +Bangle.on('drag',e=>tap=e); +BTNL = { read : _=>tap.b && tap.x < 88 && tap.y > 88}; +BTNR = { read : _=>tap.b && tap.x > 88 && tap.y > 88}; +BTNF = { read : _=>tap.b && tap.x > 88 && tap.y < 88}; +BTNS = { read : _=>tap.b && tap.x < 88 && tap.y < 88}; + + +// - sprites ------------------------------------------- +// invader sprites +var invader_a = + require("heatshrink").decompress(atob("hcIwkBiIBBAQoECCQQFBgEQAIMBEhUBDoYWDAYI=")); +var invader_b = + require("heatshrink").decompress(atob("hcIwkBiIBBAQMQAoQEBgISCAYUQAIQAEB4YEBEAgEDAYIA==")); +var boom = + require("heatshrink").decompress(atob("hcJwkBiMQAIURgMQAgIKBAIICFAIMAAwIWBBAYSIEAgrDiA=")); +var inv_shot = + require("heatshrink").decompress(atob("gcFwkBiERiAABAYQ")); + +// turret sprites +var turret = + require("heatshrink").decompress(atob("h8IwkBiIABAYYACgAHFiEABggADCAInFgITBAAgOPA==")); +var tur_exp_a = + require("heatshrink").decompress(atob("h8IwkBiMRiACBAAwJEiAABBQgZCAAkAiAJBBoIUBgIABBgQACDIQ9ECQIA==")); +var tur_exp_b = + require("heatshrink").decompress(atob("h8IwkBiIBBAAUBiADCiMQAwQFDCIYXEB4IABgMAEYQXBiEAAQIQBAoIABDAQUCAAIVBA")); +var shot = + require("heatshrink").decompress(atob("gMDwkBAoIA==")); + + +// function to move and animate invader +function move_anim_inv() { + // invader anim code + i_anim_delay -= 1; + if ((i_anim_delay < 0) && !(been_hit)) { + i_anim_delay = 10; + + inv_frame += 1; + if (inv_frame > 2) { + inv_frame = 1; + } + + // move right + if (i_dir == 1){ + inv_x += ix_speed; + if (inv_x >= 142) { + inv_y += 8; // step down + i_dir = -1; + } + } + + // move left + if (i_dir < 1){ + inv_x -= ix_speed; + if (inv_x <= 10) { + inv_y += 8; // step down + i_dir = 1; + } + } + } +} + + +// function to make invader fire +function invader_fire() { + inv_fire_pause -= 1; + + if (!(inv_fired)) { // so once invader shot is fired it doesn't follow the invader still + inv_shot_x = inv_x + 8; + inv_shot_y = inv_y + 18; + } + + if (inv_fire_pause < 0) { + inv_fired = true; + inv_shot_y += 8; + } +} + + +// function to make turret explode (when hit) then start back in center +function turret_hit() { + if (turret_been_hit) { + if (!(explosion_play)) { + //Bangle.buzz(); + //Bangle.beep(); + } + + explosion_play = true; + turret_anim_delay -= 1; + turret_blast_delay -= 1; + + if (turret_anim_delay < 0) { + turret_exp_frame += 1; + if (turret_exp_frame > 2) { + Bangle.buzz(); + turret_exp_frame = 1; + } + turret_anim_delay = 3; + } + + if (turret_blast_delay < 0) { + turret_blast_delay = 21; + turret_been_hit = false; + explosion_play = false; + tur_x = 77; // reset turret x + tur_y = 148; // reset turret y + } + } +} + + +// function to make invader explode (when hit) then randomly start somewhere else +function invader_hit() { + if (been_hit) { + if (!(boom_play)) { + Bangle.buzz(); + //Bangle.beep(); + } + + inv_shot_x = -32; // hide shot + inv_shot_y = -32; // hide shot + inv_fire_pause = 30; // and reset pause + + boom_play = true; + blast_delay -= 1; + + if (blast_delay < 0) { + blast_delay = 15; + boom_play = false; + been_hit = false; + bx = -32; // move boom off screen (following invader) + by = -32; + // generate a random rounded number between 10 and 142; + inv_x = Math.floor(Math.random() * 142) + 10; + inv_y = 20; // move invader back up after being hit + i_dir = 1; // reset invader direction + } + } +} + + +// - setup stuff --------------------------------------- +function gameStart() { + setInterval(onFrame, 50); +} + + +// - main loop ------------------------------------------------------------- +function onFrame() { + + // game not started state (title screen) *************************** + if(game_state == 0) { + g.clear(); + + + if (!(BTNS.read())) { + start_been_pressed = false; // stops double press on restart + } + + + // draw text during game over state + g.setFont("4x6", 4); // set font and size x 2 + g.setColor(0,1,0); // set color (black) + g.drawString("INVADER", 33, 55); + + + // just animate invader + // invader anim code + i_anim_delay -= 1; + if(i_anim_delay < 0) { + i_anim_delay = 15; + + inv_frame += 1; + if (inv_frame > 2) { + inv_frame = 1; + } + } + + + // draw sprites during game over state + // next 2 line for a rotating invader on the title screen + //ang += 0.1; + //g.drawImage(invader_a, 88, 98, {scale:4, rotate:ang}); + if(inv_frame == 1) { + g.drawImage(invader_a, 88-22, 85, {scale:4}); + } + else if(inv_frame == 2) { + g.drawImage(invader_b, 88-22, 85, {scale:4}); + } + + // reset stuff + if(BTNS.read() && !(start_been_pressed)) { + turret_been_hit = false; + tur_x = 77; // reset turret to center of screen + tur_y = 148; // reset turret y + inv_x = 77; // reset invader to center of screen + inv_y = 20; // reset invader back to top + i_dir = 1; // reset invader direction + lives = 3; // reset lives + score = 0; // reset score + explosion_play = false; + game_state = 1; + turret_blast_delay = 25; + } + + + g.flip(); + } + + + // game over state ************************************************* + if(game_state == 3) { + g.clear(); + + // draw text during game over state + g.setFont("4x6", 2); // set font and size x 2 + g.setColor(0,0,0); // set color (black) + g.drawString("SCORE:" + score ,5, 5); + g.drawString("LIVES:" + lives ,117, 5); + g.drawString("GAME OVER", 52, 80); + + + // draw sprites during game over state + // - invader frame 2 + g.drawImage(invader_b, inv_x, inv_y, {scale:2}); + g.drawImage(tur_exp_b, tur_x, tur_y, {scale:2}); + g.drawImage(inv_shot, inv_shot_x, inv_shot_y, {scale:2}); + + + // reset stuff + if(BTNS.read()) { + //turret_been_hit = false; + //tur_x = 77; // reset turret to center of screen + //tur_y = 148; // reset turret y + //inv_x = 77; // reset invader to center of screen + //inv_y = 20; // reset invader back to top + //i_dir = 1; // reset invader direction + //lives = 3; // reset lives + //score = 0; // reset score + //explosion_play = false; + game_state = 0; + start_been_pressed = true; + //turret_blast_delay = 25; + } + + + g.flip(); + } + + + // not game over state (game running) ****************************** + if(game_state == 1) { + Bangle.setLCDPower(1); // optional - this keeps the watch LCD lit up + g.clear(); + + + if (!(BTNF.read())) { + fire_been_pressed = false; // stops auto fire + } + + + // call function to move and animate invader + move_anim_inv(); + + // call function to make invader fire + invader_fire(); + + + // check input (screen presses) + if(BTNL.read() && tur_x >= 12 && !(turret_been_hit)) { + tur_x -= 6; + } + else if(BTNR.read() && tur_x <= 140 && !(turret_been_hit)) { + tur_x += 6; + } + else if(BTNF.read() && !(turret_been_hit) && !(fire_been_pressed) && !(shot_fired)) { + shot_fired = true; + fire_been_pressed = true; // stops auto fire + sx=tur_x + 12; + sy=tur_y - 7; + } + + + // check for turret shot going off screen before allowing to fire again + if (shot_fired) { + sy -= 8; + if (sy < 22) { + shot_fired = false; + sx = -32; + sy = -32; + } + } + + + // check for invader shot going off screen before allowing to fire again + if (inv_shot_y > 150 + ) { + inv_fired = false; + inv_shot_x = inv_x - 1; + inv_shot_y = inv_y + 7; + inv_fire_pause = 30; + } + + + // check for turret shot and invader collision + if ((sx >= inv_x) && (sx <= inv_x + 20) && (sy <= inv_y + 14)) { + sx = -32; + sy = -32; + been_hit = true; + score += 10; + } + + + // check for invader shot and turret collision + if ((inv_shot_x + 4) >= (tur_x) && (inv_shot_x) <= (tur_x + 24) && (inv_shot_y + 8) >= (tur_y + 6)) { + if (!(turret_been_hit)) { + lives -= 1; + + if (lives == 0) { + game_state = 3; + Bangle.buzz(); + } + turret_been_hit = true; + } + } + + + // - draw sprites ---------------------------------- + // invader sprites + if(!(been_hit)) { + if(inv_frame == 1) { + // - invader frame 1 + g.drawImage(invader_a, inv_x, inv_y, {scale:2}); + } + else if(inv_frame == 2) { + // - invader frame 2 + g.drawImage(invader_b, inv_x, inv_y, {scale:2}); + } + } + else { + // - invader explosion + g.drawImage(boom, inv_x, inv_y, {scale:2}); + } + // - invader shot + if (inv_fired) { + g.drawImage(inv_shot, inv_shot_x, inv_shot_y, {scale:2}); + } + else { + g.drawImage(inv_shot, -32, -32, {scale:2}); + } + + // turret sprites + if(!(turret_been_hit)) { + // - undamaged turret + g.drawImage(turret, tur_x, tur_y, {scale:2}); + } + else { + if(turret_exp_frame == 1) { + // - turret explosion frame 1 + g.drawImage(tur_exp_a, tur_x, tur_y, {scale:2}); + } + else if(turret_exp_frame == 2) { + // - turret explosion frame 2 + g.drawImage(tur_exp_b, tur_x, tur_y, {scale:2}); + } + } + // - turret shot + g.drawImage(shot, sx, sy, {scale:2}); + + + // call function to make invader explode then randomly start somewhere else + invader_hit(); + + + // call function to make turret explode (when hit) then start back in center + turret_hit(); + + + // - draw text ------------------------------------- + g.setFont("4x6", 2); // set font and size x 2 + g.setColor(0,0,0); // set color (black) + g.drawString("SCORE:" + score ,5,5); + g.drawString("LIVES:" + lives ,117,5); + + + g.flip(); + } + +} // end main loop --------------------------------------------------------- + + +gameStart(); + + diff --git a/apps/invader/app.png b/apps/invader/app.png new file mode 100644 index 000000000..3b9f82205 Binary files /dev/null and b/apps/invader/app.png differ diff --git a/apps/invader/metadata.json b/apps/invader/metadata.json new file mode 100644 index 000000000..bb74f5122 --- /dev/null +++ b/apps/invader/metadata.json @@ -0,0 +1,15 @@ +{ "id": "invader", + "name": "Invader", + "shortName":"Invader", + "version":"0.11", + "description": "A Space Invader game-like demo - work in progress", + "icon": "app.png", + "screenshots" : [ { "url":"screenshot_0.png" }, { "url":"screenshot_1.png" }, { "url":"screenshot_2.png" } ], + "tags": "game", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"invader.app.js","url":"app.js"}, + {"name":"invader.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/invader/screenshot.png b/apps/invader/screenshot.png new file mode 100644 index 000000000..ae936f6c7 Binary files /dev/null and b/apps/invader/screenshot.png differ diff --git a/apps/invader/screenshot_0.png b/apps/invader/screenshot_0.png new file mode 100644 index 000000000..804f3e435 Binary files /dev/null and b/apps/invader/screenshot_0.png differ diff --git a/apps/invader/screenshot_1.png b/apps/invader/screenshot_1.png new file mode 100644 index 000000000..14164bc6e Binary files /dev/null and b/apps/invader/screenshot_1.png differ diff --git a/apps/invader/screenshot_2.png b/apps/invader/screenshot_2.png new file mode 100644 index 000000000..5f6ade79c Binary files /dev/null and b/apps/invader/screenshot_2.png differ diff --git a/apps/lcars/ChangeLog b/apps/lcars/ChangeLog index e622feb1f..9a8ac4008 100644 --- a/apps/lcars/ChangeLog +++ b/apps/lcars/ChangeLog @@ -19,4 +19,5 @@ 0.19: Alarms can not go bigger than 100. 0.20: Use alarm for alarm functionality instead of own implementation. 0.21: Add custom theming. -0.22: Fix alarm and add build in function for step counting. \ No newline at end of file +0.22: Fix alarm and add build in function for step counting. +0.23: Add warning for low flash memory diff --git a/apps/lcars/lcars.app.js b/apps/lcars/lcars.app.js index 07ca51fd9..e81c0d6f3 100644 --- a/apps/lcars/lcars.app.js +++ b/apps/lcars/lcars.app.js @@ -147,8 +147,7 @@ var iconCharging = { buffer : require("heatshrink").decompress(atob("23btugAwUBtoICARG0h048eODQYCJ6P/AAUCCJfbo4SDxYRLtEcuPHjlwgoRJ7RnIloUHoYjDAQfAExEAwUIkACEkSAIEYwCBhZKH6EIJI0CJRFHEY0BJRWBSgf//0AJRYSE4BKLj4SE8BKLv4RD/hK/JS2AXY0gXwRKG4cMmACCJQMAg8csEFJQsBAwfasEAm379u0gFbcBfHzgFBz1xMQZKBjY/D0E2+BOChu26yVEEYdww+cgAFCg+cgIfB6RKF4HbgEIkGChEAthfCJQ0eEAIjBBAMxk6GCJQtgtyVBwRKBAQMbHAJKGXIIFCgACBhl54qVG2E+EAJKBJoWAm0WJQ6SCXgdxFgMLJQvYjeAEAUwFIUitEtJQ14NwUHgEwKYZKGwOwNYX7XgWCg3CJQ5rB4MevPnAoPDJRJrCgEG/ECAoNsJRUwoEesIIBiJKI3CVDti/CJRKVDiJHBSo0YsOGjED8AjBcAcIgdhcAXAPIUAcAYIBcA4dBAQUG8BrBgBuCgOwcBEeXIK2BBAIFBgRqBGoYAChq8CcYUE4FbUYOACQsHzgjDgwFBCIImBAQsDtwYD7cAloRI22B86YBw5QBgoRJ7dAgYEDCJaeBJoMcsARMAQNoJIIRE6A")) }; -var iconNoBattery = { - text: "NO BAT", +var iconWarning = { width : 50, height : 50, bpp : 3, transparent : 1, buffer : require("heatshrink").decompress(atob("kmSpIC/AWMyoQIFsmECJFJhMmA4QXByVICIwODAQ4RRFIQGD5JVLkIGDzJqMyAGDph8MiRKGyApEAoZKFyYIDQwMkSQNkQZABBhIIOOJRuEL5gRIAUKACVQMhmUSNYNDQYJTBBwYFByGTkOE5FJWYNMknCAQKYCiaSCpmGochDoSYBhMwTAZrChILBhmEzKPBF4ImBTAREBDoMmEwJVDoYjBycJFgWEJQRuLJQ1kmQCCjJlCBYbjCagaDBwyDBmBuBF4TjJAUQKINBChCDQxZBcZIIQF4NIgEAgKSDiQmEVQKMBoARBAAMCSQLLBVoxqKL4gaCChVCNwoRKOIo4CJIgABBoSMHpIRFgDdJOIJUBCAUJRgJuEAQb+DIIgRIAX4C/ASOQA")) @@ -321,19 +320,21 @@ function drawState(){ if(!isAlarmEnabled()){ var bat = E.getBattery(); + var flash = storage.getFree() / process.env.STORAGE; var current = new Date(); var hours = current.getHours(); - var iconImg = - Bangle.isCharging() ? iconCharging : - bat < 30 ? iconNoBattery : - Bangle.isGPSOn() ? iconSatellite : - hours % 4 == 0 ? iconSaturn : - hours % 4 == 1 ? iconMars : - hours % 4 == 2 ? iconMoon : - iconEarth; - g.drawImage(iconImg, 23, 118); + var iconMsg = + Bangle.isCharging() ? { icon: iconCharging, text: "STATUS" } : + bat < 30 ? { icon: iconWarning, text: "BAT" } : + flash < 0.1 ? { icon: iconWarning, text: "DISK" } : + Bangle.isGPSOn() ? { icon: iconSatellite, text: "STATUS" } : + hours % 4 == 0 ? { icon: iconSaturn, text: "STATUS" } : + hours % 4 == 1 ? { icon: iconMars, text: "STATUS" } : + hours % 4 == 2 ? { icon: iconMoon, text: "STATUS" } : + { icon: iconEarth, text: "STATUS" }; + g.drawImage(iconMsg.icon, 23, 118); g.setColor(cWhite); - g.drawString("STATUS", 23+26, 108); + g.drawString(iconMsg.text, 23+26, 108); } else { // Alarm within symbol g.setColor(color2); diff --git a/apps/lcars/metadata.json b/apps/lcars/metadata.json index 40da1b37f..62a1c67db 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.22", + "version":"0.23", "readme": "README.md", "supports": ["BANGLEJS2"], "description": "Library Computer Access Retrieval System (LCARS) clock.", diff --git a/apps/messages/ChangeLog b/apps/messages/ChangeLog index 53157f0d8..67c2f903a 100644 --- a/apps/messages/ChangeLog +++ b/apps/messages/ChangeLog @@ -51,3 +51,4 @@ 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: Don't turn on the screen after unread timeout expires (#1873) diff --git a/apps/messages/app.js b/apps/messages/app.js index 745f7d208..46f010c0b 100644 --- a/apps/messages/app.js +++ b/apps/messages/app.js @@ -411,19 +411,17 @@ function cancelReloadTimeout() { unreadTimeout = undefined; } - g.clear(); + Bangle.loadWidgets(); Bangle.drawWidgets(); + setTimeout(() => { - var unreadTimeoutSecs = settings.unreadTimeout; - if (unreadTimeoutSecs===undefined) unreadTimeoutSecs=60; - if (unreadTimeoutSecs) - unreadTimeout = setTimeout(function() { - print("Message not seen - reloading"); - load(); - }, unreadTimeoutSecs*1000); + 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}); -},10); // if checkMessages wants to 'load', do that + var newMusic = MESSAGES.some(m => m.id === "music" && m.new); + checkMessages({ clockIfNoMsg: 0, clockIfAllRead: 0, showMsgIfUnread: 1, openMusic: newMusic && settings.openMusic }); +}, 10); // if checkMessages wants to 'load', do that diff --git a/apps/messages/metadata.json b/apps/messages/metadata.json index fd09fdfe4..4bc9f59e4 100644 --- a/apps/messages/metadata.json +++ b/apps/messages/metadata.json @@ -1,7 +1,7 @@ { "id": "messages", "name": "Messages", - "version": "0.38", + "version": "0.39", "description": "App to display notifications from iOS and Gadgetbridge/Android", "icon": "app.png", "type": "app", diff --git a/apps/messages/widget.js b/apps/messages/widget.js index 4b368ffd6..ca02d4f1f 100644 --- a/apps/messages/widget.js +++ b/apps/messages/widget.js @@ -27,7 +27,6 @@ draw:function(recall) { 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(); - Bangle.setLCDPower(1);// turns screen on },hide:function() { delete WIDGETS["messages"].t; delete WIDGETS["messages"].l; diff --git a/apps/sched/ChangeLog b/apps/sched/ChangeLog index e003248a3..5728bf734 100644 --- a/apps/sched/ChangeLog +++ b/apps/sched/ChangeLog @@ -10,3 +10,6 @@ 0.09: Move some functions to new time_utils module 0.10: Default to sched.js if custom js not found 0.11: Fix default dow +0.12: Update default buzz patterns to new values + Improve timer message using formatDuration + Fix wrong fallback for buzz pattern diff --git a/apps/sched/lib.js b/apps/sched/lib.js index 315e4e387..5089ed46c 100644 --- a/apps/sched/lib.js +++ b/apps/sched/lib.js @@ -106,8 +106,8 @@ exports.getSettings = function () { defaultRepeat: false, buzzCount: 10, buzzIntervalMillis: 3000, // 3 seconds - defaultAlarmPattern: "..", - defaultTimerPattern: ".." + defaultAlarmPattern: "::", + defaultTimerPattern: "::" }, require("Storage").readJSON("sched.settings.json", true) || {} ); diff --git a/apps/sched/metadata.json b/apps/sched/metadata.json index 76341a7ad..c8ed3acb8 100644 --- a/apps/sched/metadata.json +++ b/apps/sched/metadata.json @@ -1,7 +1,7 @@ { "id": "sched", "name": "Scheduler", - "version": "0.11", + "version": "0.12", "description": "Scheduling library for alarms and timers", "icon": "app.png", "type": "scheduler", diff --git a/apps/sched/sched.js b/apps/sched/sched.js index f4d1bc9ad..012e8ed35 100644 --- a/apps/sched/sched.js +++ b/apps/sched/sched.js @@ -9,7 +9,7 @@ function showAlarm(alarm) { const settings = require("sched").getSettings(); let msg = ""; - msg += require("time_utils").formatTime(alarm.timer ? alarm.timer : alarm.t); + msg += alarm.timer ? require("time_utils").formatDuration(alarm.timer) : require("time_utils").formatTime(alarm.t); if (alarm.msg) { msg += "\n"+alarm.msg; } else { @@ -50,7 +50,8 @@ function showAlarm(alarm) { Bangle.setLocked(false); } - require("buzz").pattern(alarm.vibrate === undefined ? ".." : alarm.vibrate).then(() => { + const pattern = alarm.vibrate || (alarm.timer ? settings.defaultTimerPattern : settings.defaultAlarmPattern); + require("buzz").pattern(pattern).then(() => { if (buzzCount--) { setTimeout(buzz, settings.buzzIntervalMillis); } else if (alarm.as) { // auto-snooze diff --git a/apps/sched/settings.js b/apps/sched/settings.js index 5ddb4dab2..a2b3a5241 100644 --- a/apps/sched/settings.js +++ b/apps/sched/settings.js @@ -29,7 +29,7 @@ min: 5, max: 30, step: 5, - format: v => v + /*LANG*/" min", + format: v => v + /*LANG*/"m", onchange: v => { settings.defaultSnoozeMillis = v * 60000; require("sched").setSettings(settings); diff --git a/apps/setting/ChangeLog b/apps/setting/ChangeLog index eca2b7938..ea2ecd02b 100644 --- a/apps/setting/ChangeLog +++ b/apps/setting/ChangeLog @@ -50,3 +50,5 @@ UI improvements to Locale and Date & Time menu 0.45: Add calibrate battery option 0.46: Fix regression after making 'calibrate battery' only for Bangle.js 2 +0.47: Allow colors to be translated + Improve "Turn Off" user experience diff --git a/apps/setting/metadata.json b/apps/setting/metadata.json index 183290a85..ce4e5b337 100644 --- a/apps/setting/metadata.json +++ b/apps/setting/metadata.json @@ -1,7 +1,7 @@ { "id": "setting", "name": "Settings", - "version": "0.46", + "version": "0.47", "description": "A menu for setting up Bangle.js", "icon": "settings.png", "tags": "tool,system", diff --git a/apps/setting/settings.js b/apps/setting/settings.js index 150251e7d..39cf6c1d1 100644 --- a/apps/setting/settings.js +++ b/apps/setting/settings.js @@ -252,22 +252,28 @@ function showThemeMenu() { } upd(th); } - let rgb = { - black: "#000", white: "#fff", - red: "#f00", green: "#0f0", blue: "#00f", - cyan: "#0ff", magenta: "#f0f", yellow: "#ff0", - }; - if (!BANGLEJS2) Object.assign(rgb, { + let rgb = {}; + rgb[/*LANG*/'black'] = "#000"; + rgb[/*LANG*/'white'] = "#fff"; + rgb[/*LANG*/'red'] = "#f00"; + rgb[/*LANG*/'green'] = "#0f0"; + rgb[/*LANG*/'blue'] = "#00f"; + rgb[/*LANG*/'cyan'] = "#0ff"; + rgb[/*LANG*/'magenta'] = "#f0f"; + rgb[/*LANG*/'yellow'] = "#ff0"; + if (!BANGLEJS2) { // these would cause dithering, which is not great for e.g. text - orange: "#ff7f00", purple: "#7f00ff", grey: "#7f7f7f", - }); + rgb[/*LANG*/'orange'] = "#ff7f00"; + rgb[/*LANG*/'purple'] = "#7f00ff"; + rgb[/*LANG*/'grey'] = "#7f7f7f"; + } let colors = [], names = []; for(const c in rgb) { names.push(c); colors.push(cl(rgb[c])); } let menu = { - '':{title:'Custom Theme'}, + '':{title:/*LANG*/'Custom Theme'}, "< Back": () => showThemeMenu() }; const labels = { @@ -569,7 +575,25 @@ function showUtilMenu() { } else showUtilMenu(); }); }; - menu[/*LANG*/'Turn Off'] = ()=>{ if (Bangle.softOff) Bangle.softOff(); else Bangle.off() }; + menu[/*LANG*/"Turn Off"] = () => { + E.showPrompt(/*LANG*/"Are you sure? Alarms and timers won't fire", { + title:/*LANG*/"Turn Off" + }).then((confirmed) => { + if (confirmed) { + E.showMessage(/*LANG*/"See you\nlater!", /*LANG*/"Goodbye"); + setTimeout(() => { + // clear the screen so when the user will turn on the watch they'll see + // an empty screen instead of the latest displayed screen + E.showMessage(); + g.clear(true); + + Bangle.softOff ? Bangle.softOff() : Bangle.off(); + }, 2500); + } else { + showUtilMenu(); + } + }); + }; if (Bangle.factoryReset) { menu[/*LANG*/'Factory Reset'] = ()=>{ diff --git a/apps/speedalt2/README.md b/apps/speedalt2/README.md index c124e0c00..a86f787cf 100644 --- a/apps/speedalt2/README.md +++ b/apps/speedalt2/README.md @@ -37,7 +37,7 @@ When the GPS obtains a fix the number of satellites is displayed as 'Sats:nn'. W ## Power Saving -The The GPS Adv Sport app obeys the watch screen off timeouts as a power saving measure. Restore the screen as per any of the colck/watch apps. Use BTN2 to lock the screen on but doing this will use more battery. +The The GPS Adv Sport app obeys the watch screen off timeouts as a power saving measure. Restore the screen as per any of the clock/watch apps. Use BTN2 to lock the screen on but doing this will use more battery. This app will work quite happily on its own but will use the [GPS Setup App](https://banglejs.com/apps/#gps%20setup) if it is installed. You may choose to use the GPS Setup App to gain significantly longer battery life while the GPS is on. Please read the Low Power GPS Setup App Readme to understand what this does. @@ -65,7 +65,7 @@ The Droidscript script file is called : **GPS Adv Sports II.js** 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 runnig 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. ) diff --git a/lang/de_DE.json b/lang/de_DE.json index e0deef7fb..ef22b588f 100644 --- a/lang/de_DE.json +++ b/lang/de_DE.json @@ -20,11 +20,11 @@ "On": "Ein", "Off": "Aus", "Ok": "OK", - "New Timer": "Neue Zeitschaltuhr", + "New Timer": "Neuer Kurzzeitwecker", "(repeat)": "(Wiederholung)", "music": "Musik", - "Keep Msgs": "Msgs behalten", - "circle count": "Kreiszahl", + "Keep Msgs": "Nachrichten behalten", + "circle count": "Anzahl Kreise", "Auto snooze": "Automatisches Schlummern", "week": "Woche", "Heartrate": "Herzfrequenz", @@ -43,7 +43,7 @@ "colorize icon": "Symbol einfärben", "min. confidence": "Mindestvertrauen", "maximum": "maximal", - "distance goal": "Fernziel", + "distance goal": "Entfernungsziel", "Circle": "Kreis", "Yes\ndefinitely": "Ja\ndefinitiv", "TAP right top/bottom": "TAP rechts oben/unten", @@ -52,28 +52,29 @@ "Mark Unread": "Ungelesen markieren", "Delete all messages": "Alle Nachrichten löschen", "Unread timer": "Ungelesener Timer", - "Quiet Mode": "Leiser Modus", + "Quiet Mode": "Stiller Modus", "Utils": "Werkzeuge", "Piezo": "Piezo", "LCD": "LCD", - "Record Run": "Rekordlauf", + "Record Run": "Lauf aufzeichnen", "Apps": "Apps", "Delete All Messages": "Alle Nachrichten löschen", "start&lap/reset, BTN1: EXIT": "Start&Runde/Zurücksetzen, BTN1: EXIT", "No Messages": "Keine Nachrichten", "Bluetooth": "Bluetooth", - "BTNs 1:startlap 2:exit 3:reset": "BTNs 1:startlap 2:exit 3:reset", + "BTNs 1:startlap 2:exit 3:reset": "BTNs 1:Rundenstart 2:Exit 3:Reset", "View Message": "Nachricht anzeigen", "Vector font size": "Vektor-Schriftgröße", - "Light BW": "Licht BW", + "Light BW": "Hell S/W", "BLE": "BLE", "Make Connectable": "Verbindbar machen", "Vibration": "Vibration", - "Foreground": "Vorderseite", - "Customize": "Anpassen", + "Foreground": "Vordergrund", + "Customize": "Individualisieren", + "Custom Theme": "Individueller Stil", "HID": "HID", - "Dark BW": "Dunkel BW", - "Passkey BETA": "Hauptschlüssel BETA", + "Dark BW": "Dunkel S/W", + "Passkey BETA": "Passwort BETA", "Show clocks": "Uhren anzeigen", "Font": "Schriftart", "Launcher Settings": "Launcher-Einstellungen", @@ -82,30 +83,30 @@ "Background 2": "Hintergrund 2", "Foreground 2": "Vordergrund 2", "Add Device": "Gerät hinzufügen", - "Highlight BG": "Hervorhebung BG", + "Highlight BG": "Hervorhebung HG", "Background": "Hintergrund", - "Highlight FG": "Highlight FG", + "Highlight FG": "Hervorhebung VG", "Wake on Touch": "Wecken bei Berührung", "Twist Timeout": "Twist Timeout", "Twist Max Y": "Twist Max Y", - "LCD Timeout": "LCD-Zeitüberschreitung", + "LCD Timeout": "LCD-Leuchtdauer", "LCD Brightness": "LCD-Helligkeit", - "Utilities": "Versorgungsunternehmen", + "Utilities": "Werkzeuge", "Log": "Protokoll", - "Compact Storage": "Kompakte Lagerung", - "Wake on BTN3": "Wake auf BTN3", - "Twist Threshold": "Schwellenwert verdrehen", + "Compact Storage": "Speicherwartung", + "Wake on BTN3": "Aufwachen auf BTN3", + "Twist Threshold": "Twist Schwellenwert", "Remove": "entfernen", "Connect device\nto add to\nwhitelist": "Gerät verbinden\nzum Hinzufügen zur\nWhitelist", "Debug Info": "Debug-Informationen", "Time Zone": "Zeitzone", - "Clock Style": "Uhr Stil", - "Wake on BTN2": "Wake auf BTN2", - "Wake on FaceUp": "Wake on FaceUp", - "Wake on BTN1": "Wake auf BTN1", - "Wake on Twist": "Wake on Twist", - "Connectable": "Anschließbar", - "Second": "Zweite", + "Clock Style": "Uhrenstil", + "Wake on BTN2": "Aufwecken mit BTN2", + "Wake on FaceUp": "Aufwecken mit Display oben", + "Wake on BTN1": "Aufwecken mit BTN1", + "Wake on Twist": "Aufwecken mit Twist", + "Connectable": "Erreichbar", + "Second": "Sekunde", "Minute": "Minute", "Turn Off": "Ausschalten", "No Clocks Found": "Keine Uhren gefunden", @@ -114,10 +115,10 @@ "Reset to Defaults": "Auf Standardwerte zurücksetzen", "Flattening battery - this can take hours.\nLong-press button to cancel": "Entladen der Batterie - dies kann Stunden dauern.\nLanger Tastendruck zum Abbrechen", "Reset Settings": "Einstellungen zurücksetzen", - "Rewrite Settings": "Einstellungen umschreiben", - "Compacting...\nTakes approx\n1 minute": "Verdichten...\nDauert ca.\n1 Minute", - "Stay Connectable": "Anschlussfähig bleiben", - "Storage": "Lagerung", + "Rewrite Settings": "Einstellungen neu schreiben", + "Compacting...\nTakes approx\n1 minute": "Speicherwartung...\nDauert ca.\n1 Minute", + "Stay Connectable": "Erreichbar bleiben", + "Storage": "Speicher", "This will remove everything": "Dadurch wird alles entfernt", "on": "auf", "TIMER": "TIMER", @@ -126,9 +127,10 @@ "Beep": "Piep", "Reset": "Zurücksetzen", "No app has settings": "Keine App hat Einstellungen", + "Day": "Tag", "Month": "Monat", "Reset All": "Alle zurücksetzen", - "Flatten Battery": "Batterie abflachen", + "Flatten Battery": "Batterie entladen", "Right": "Rechts", "Side": "Seite", "Left": "Links", @@ -141,12 +143,12 @@ "Vibrate": "Vibrieren", "Reset all widgets": "Alle Widgets zurücksetzen", "System": "System", - "Alerts": "Warnungen", - "Locale": "Schauplatz", + "Alerts": "Alarme", + "Locale": "Ort", "Whitelist": "Whitelist", "Select Clock": "Uhr auswählen", - "Disable": "Deaktivieren Sie", - "Timer": "Zeitschaltuhr", + "Disable": "Deaktivieren", + "Timer": "Kurzzeitwecker", "Error in settings": "Fehler in den Einstellungen", "Set Time": "Zeit einstellen", "ALARM": "ALARM", @@ -164,7 +166,7 @@ "Music": "Musik", "color": "Farbe", "off": "aus", - "Theme": "Thema", + "Theme": "Stil", "one": "eins", "two": "zwei", "three": "drei", @@ -176,7 +178,22 @@ "nine": "neun", "ten": "zehn", "eleven": "elf", - "twelve": "zwölf" + "twelve": "zwölf", + "Time Format": "Zeitformat", + "Start Week On": "Wochenbeginn", + "Date & Time": "Datum und Zeit", + "Calibrate Battery": "Akku kalibrieren", + "black": "Schwarz", + "white": "Weiß", + "red": "Rot", + "green": "Grün", + "blue": "Blau", + "yellow": "Gelb", + "magenta": "Magenta", + "cyan": "Cyan", + "orange": "Orange", + "purple": "Violett", + "grey": "Grau" }, "alarm": { "//": "App-specific overrides", @@ -189,7 +206,7 @@ "ten past *$1": "zehn nach *$1", "quarter past *$1": "viertel nach *$1", "twenty past *$1": "zwanzig nach *$1", - "twenty five past *$1": "fünf for halb *$2", + "twenty five past *$1": "fünf vor halb *$2", "half past *$1": "halb *$2", "twenty five to *$2": "fünf nach halb *$2", "twenty to *$2": "zwanzig vor *$2", diff --git a/lang/index.json b/lang/index.json index 20ceaab92..474a530ab 100644 --- a/lang/index.json +++ b/lang/index.json @@ -12,6 +12,7 @@ {"code":"tr_TR","name":"Turkish","url":"tr_TR.json"}, {"code":"ru_RU","name":"Russian","url":"ru_RU.json", "disabled":"Characters not in ISO Latin codepage"}, {"code":"pt_PT","name":"Portuguese","url":"pt_PT.json"}, + {"code":"pt_BR","name":"Portuguese Brasil","url":"pt_BR.json"}, {"code":"bg_BG","name":"Bulgarian","url":"bg_BG.json", "disabled":"Characters not in ISO Latin codepage"}, {"code":"da_DA","name":"Danish","url":"da_DA.json"}, {"code":"el_EL","name":"Greek","url":"el_EL.json", "disabled":"Characters not in ISO Latin codepage"}, @@ -23,5 +24,5 @@ {"code":"sk_SK","name":"Slovak","url":"sk_SK.json"}, {"code":"sl_SL","name":"Slovenian","url":"sl_SL.json"}, {"code":"nn_NO","name":"Norwegian (Nynorsk)","url":"nn_NO.json"}, - {"code":"hr_HR","name":"Croatian","url":"hr_HR.json"} + {"code":"hr_HR","name":"Croatian","url":"hr_HR.json"} ] diff --git a/lang/pt_BR.json b/lang/pt_BR.json new file mode 100644 index 000000000..75849ddad --- /dev/null +++ b/lang/pt_BR.json @@ -0,0 +1,167 @@ +{ + "//": "Portuguese Brasil language translations", + "GLOBAL": { + "//": "Translations that apply for all apps", + "New Timer": "Novo Temporizador", + "New Alarm": "Novo Alarme", + "Auto snooze": "Soneca automática", + "week": "semana", + "circle 3": "círculo 3", + "(repeat)": "(repetir)", + "Save": "Salvar", + "Keep Msgs": "Manter Msgs", + "music": "música", + "circle 4": "círculo 4", + "circle 2": "círculo 2", + "circle count": "contagem em círculo", + "circle 1": "círculo 1", + "battery warn": "aviso de bateria", + "show widgets": "exibir widgets", + "data": "dados", + "heartrate": "frequência cardíaca", + "distance goal": "distancia de chegada", + "Circle": "Círculo", + "colorize icon": "colorir ícone", + "min. confidence": "min. confiança", + "minimum": "mínimo", + "maximum": "máximo", + "Heartrate": "Frequência Cardíaca", + "weather circle": "círculo meteorológico", + "step length": "comprimento do passo", + "valid period": "período válido", + "TAP right top/bottom": "TAP superior/inferior direita", + "Vector font size": "Tamanho de letra vectorial", + "Yes\ndefinitely": "Sim\ndefinitivamente", + "BTNs 1:startlap 2:exit 3:reset": "BTNs 1:startlap 2:exit 3:reset", + "STEPS": "ETAPAS", + "Font": "Fonte", + "Show clocks": "Mostrar relógios", + "App Source\nNot found": "Fonte do aplicativo\nNão encontrado", + "Mark Unread": "Marcar como não lido", + "View Message": "Ver Mensagem", + "start&lap/reset, BTN1: EXIT": "start&lap/reset, BTN1: SAÍDA", + "Launcher Settings": "Configurações do Launcher", + "Delete All Messages": "Apagar todas as mensagens", + "Delete all messages": "Apagar todas as mensagens", + "Utils": "Utils", + "LCD": "LCD", + "Apps": "Apps", + "Record Run": "Gravar Corrida", + "No Messages": "Sem Mensagens", + "Unread timer": "Temporizador não visto", + "Are you sure": "Tem certeza", + "Make Connectable": "Habilitar Conexão", + "Piezo": "Piezo", + "Bluetooth": "Bluetooth", + "BLE": "BLE", + "Programmable": "Programável", + "Vibration": "Vibração", + "Quiet Mode": "Modo Silencioso", + "Foreground": "Primeiro plano", + "Passkey BETA": "Senha BETA", + "HID": "HID", + "Light BW": "BW Leve", + "Foreground 2": "Primeiro plano 2", + "Dark BW": "BW Escuro", + "Background": "Plano de Fundo", + "Highlight FG": "Destaque FG", + "Customize": "Personalizar", + "Background 2": "Plano de Fundo 2", + "Wake on BTN3": "Acordar no BTN3", + "Wake on BTN2": "Acordar no BTN2", + "Highlight BG": "Destaque BG", + "LCD Timeout": "Tempo limite do LCD", + "Wake on FaceUp": "Acordar no FaceUp", + "Wake on BTN1": "Acordar no BTN1", + "Wake on Twist": "Acordar ao Balançar", + "Wake on Touch": "Acordar ao Tocar", + "Connect device\nto add to\nwhitelist": "Ligar dispositivo\npara adicionar a\nWhitelist", + "Remove": "Remover", + "Add Device": "Adicionar dispositivo", + "LCD Brightness": "Luminosidade do LCD", + "Twist Max Y": "Max Y do Balanço", + "Utilities": "Utilidades", + "Twist Threshold": "Limiar do Balanço", + "Time Zone": "Fuso horário", + "Twist Timeout": "Timeout do Balanço", + "Clock Style": "Estilo do Relógio", + "Debug Info": "Debug Infos", + "Log": "Logs", + "Storage": "Armazenamento", + "Rewrite Settings": "Re-escrever Configurações", + "Compacting...\nTakes approx\n1 minute": "Compactando...\nLeva aproximadamente\n1 minuto", + "Flatten Battery": "Drenar Bateria", + "Reset Settings": "Resetar Configurações", + "Compact Storage": "Armazenamento compacto", + "Stay Connectable": "Manter Conectavel", + "Turn Off": "Desativar", + "Connectable": "Conectável", + "This will remove everything": "Esta ação irá apagar tudo", + "Date": "Data", + "Month": "Mês", + "Second": "Segundo", + "Minute": "Minuto", + "Flattening battery - this can take hours.\nLong-press button to cancel": "Drenando Bateria - isto pode demorar horas.\nSegure o Botão para Cancelar", + "Reset to Defaults": "Resetar Dispositivo", + "Hour": "Hora", + "No Clocks Found": "Não encontramos nenhum Relogio", + "Right": "Confirmar", + "No app has settings": "Nenhum aplicativo possui configurações", + "App Settings": "Configurações do aplicativo", + "OFF": "DESLIGADO", + "Side": "Lado", + "Left": "Esquerda", + "Sort Order": "Ordem de classificação", + "Widgets": "Widgets", + "Invalid settings": "Configurações inválidas", + "Sleep Phase Alarm": "Alarme da Fase do Sono", + "Alarm": "Alarme", + "Minutes": "Minutos", + "TIMER": "TIMER", + "Hours": "Horário", + "on": "em", + "Reset All": "Resetar tudo", + "Repeat": "Repetir", + "Delete": "Deletar", + "Enabled": "Habilitado", + "Reset all widgets": "Redefinir todos os widgets", + "Reset": "Resetar", + "goal": "meta", + "Message": "Mensagem", + "Beep": "Bip", + "Vibrate": "Vibrar", + "System": "Sistema", + "Alerts": "Alertas", + "Locale": "Localização", + "Set Time": "Tempo Definido", + "Whitelist": "Whitelist", + "Select Clock": "Selecionar Relógio", + "BACK": "VOLTAR", + "Timer": "Temporizador", + "Error in settings": "Erro nas Configurações", + "Disable": "Desativar", + "Factory Reset": "Reset de Fábrica", + "Connected": "Conectado", + "ALARM": "ALARME", + "Sleep": "Dormir", + "Messages": "Mensagens", + "Hide": "Esconder", + "Show": "Mostrar", + "On": "Ativo", + "Ok": "Ok", + "No": "Não", + "Settings": "Configurações", + "steps": "passos", + "back": "voltar", + "Steps": "Passos", + "Year": "Ano", + "Yes": "Sim", + "Loading": "Carregando", + "Music": "Música", + "color": "cor", + "off": "desativado", + "Off": "Desativado", + "Theme": "Tema", + "Back": "Voltar" + } +} diff --git a/modules/ClockFace.js b/modules/ClockFace.js index d6c3a2e66..f8dc33287 100644 --- a/modules/ClockFace.js +++ b/modules/ClockFace.js @@ -10,7 +10,8 @@ function ClockFace(options) { "precision", "init", "draw", "update", "pause", "resume", - "up", "down", "upDown" + "up", "down", "upDown", + "settingsFile", ].includes(k)) throw `Invalid ClockFace option: ${k}`; }); if (!options.draw && !options.update) throw "ClockFace needs at least one of draw() or update() functions"; @@ -33,7 +34,18 @@ function ClockFace(options) { }; if (options.upDown) this._upDown = options.upDown; - this.is12Hour = !!(require("Storage").readJSON("setting.json", 1) || {})["12hour"]; + if (options.settingsFile) { + const settings = (require("Storage").readJSON(options.settingsFile, true) || {}); + Object.keys(settings).forEach(k => { + this[k] = settings[k]; + }); + } + // these default to true + ["showDate", "loadWidgets"].forEach(k => { + if (this[k]===undefined) this[k] = true; + }); + // 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"]; } ClockFace.prototype.tick = function() { @@ -46,7 +58,7 @@ ClockFace.prototype.tick = function() { }; if (!this._last) { g.clear(true); - Bangle.drawWidgets(); + if (global.WIDGETS) Bangle.drawWidgets(); g.reset(); this.draw.apply(this, [time, {d: true, h: true, m: true, s: true}]); } else { @@ -70,7 +82,7 @@ ClockFace.prototype.start = function() { .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.loadWidgets(); + 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"); diff --git a/modules/ClockFace.md b/modules/ClockFace.md index e760c3e74..6b59e68e7 100644 --- a/modules/ClockFace.md +++ b/modules/ClockFace.md @@ -85,6 +85,7 @@ var clock = new ClockFace({ if (dir === -1) // Up else // (dir === 1): Down }, + settingsFile: 'appid.settings.json', // optional, values from file will be applied to `this` }); clock.start(); @@ -110,11 +111,51 @@ clock.start(); ``` + +SettingsFile +------------ +If you use the `settingsFile` option, values from that file are loaded and set +directly on the clock. + +For example: + +```json +// example.settings.json: +{ + "showDate": false, + "foo": 123 +} +``` +```js + var ClockFace = require("ClockFace"); + var clock = new ClockFace({ + draw: function(){/*...*/}, + settingsFile: "example.settings.json", + }); + // now + clock.showDate === false; + clock.foo === 123; + clock.loadWidgets === true; // default when not in settings file + clock.is12Hour === ??; // not in settings file: uses global setting + clock.start(); + +``` + Properties ---------- The following properties are automatically set on the clock: * `is12Hour`: `true` if the "Time Format" setting is set to "12h", `false` for "24h". * `paused`: `true` while the clock is paused. (You don't need to check this inside your `draw()` code) +* `showDate`: `true` (if not overridden through the settings file.) +* `loadWidgets`: `true` (if not overridden through the settings file.) + If set to `false` before calling `start()`, the clock won't call `Bangle.loadWidgets();` for you. + Best is to add a setting for this, but if you never want to load widgets, you could do this: + ```js + var ClockFace = require("ClockFace"); + var clock = new ClockFace({draw: function(){/*...*/}}); + clock.loadWidgets = false; // prevent loading of widgets + clock.start(); + ``` Inside the `draw()`/`update()` function you can access these using `this`: diff --git a/modules/ClockFace_menu.js b/modules/ClockFace_menu.js new file mode 100644 index 000000000..cd99ea39f --- /dev/null +++ b/modules/ClockFace_menu.js @@ -0,0 +1,10 @@ +// boolean options, which default to true +exports.showDate = +exports.loadWidgets = + function(value, callback) { + if (value === undefined) value = true; + return { + value: !!value, + onchange: v=>callback(v), + }; + }; diff --git a/modules/buzz.js b/modules/buzz.js index 488d0228d..aed0e2e7b 100644 --- a/modules/buzz.js +++ b/modules/buzz.js @@ -1,14 +1,33 @@ -/* Call this with a pattern like '.-.', '.. .' or '..' to buzz that pattern -out on the internal vibration motor. use buzz_menu to display a menu -where the patterns can be chosen. */ +/** + * Buzz the passed `pattern` out on the internal vibration motor. + * + * A pattern is a sequence of `.`, `,`, `-`, `:`, `;` and `=` where + * - `.` is one short and weak vibration + * - `,` is one medium and weak vibration + * - `-` is one long and weak vibration + * - `:` is one short and strong vibration + * - `;` is one medium and strong vibration + * - `=` is one long and strong vibration + * + * You can use the `buzz_menu` module to display a menu where some common patterns can be chosen. + * + * @param {string} pattern A string like `.-.`, `..=`, `:.:`, `..`, etc. + * @returns a Promise + */ exports.pattern = pattern => new Promise(resolve => { - function b() { - if (pattern=="") resolve(); + function doBuzz() { + if (pattern == "") resolve(); var c = pattern[0]; pattern = pattern.substr(1); - if (c==".") Bangle.buzz().then(()=>setTimeout(b,100)); - else if (c=="-") Bangle.buzz(500).then(()=>setTimeout(b,100)); - else setTimeout(b,100); + const BUZZ_WEAK = 0.25, BUZZ_STRONG = 1; + const SHORT_MS = 100, MEDIUM_MS = 200, LONG_MS = 500; + if (c == ".") Bangle.buzz(SHORT_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100)); + else if (c == ",") Bangle.buzz(MEDIUM_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100)); + else if (c == "-") Bangle.buzz(LONG_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100)); + else if (c == ":") Bangle.buzz(SHORT_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100)); + else if (c == ";") Bangle.buzz(MEDIUM_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100)); + else if (c == "=") Bangle.buzz(LONG_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100)); + else setTimeout(doBuzz, 100); } - b(); + doBuzz(); }); diff --git a/modules/buzz_menu.js b/modules/buzz_menu.js index c5b41a997..7ca155a2c 100644 --- a/modules/buzz_menu.js +++ b/modules/buzz_menu.js @@ -1,14 +1,19 @@ -/* Display a menu to select from various vibration patterns for use with buzz.js */ - -exports.pattern = function(value, callback) { - var vibPatterns = ["", ".", "..", "-", "--", "-.-", "---"]; +/** + * Display a menu to select from various common vibration patterns for use with buzz.js. + * + * @param {string} value The pre-selected pattern + * @param {*} callback A function called with the user selected pattern + */ +exports.pattern = function (value, callback) { + var patterns = ["", ".", ":", "..", "::", ",", ";", ",,", ";;", "-", "=", "--", "==", "...", ":::", "---", ";;;", "==="]; return { - value: Math.max(0,vibPatterns.indexOf(value)), - min: 0, max: vibPatterns.length-1, - format: v => vibPatterns[v]||/*LANG*/"Off", + value: Math.max(0, patterns.indexOf(value)), + min: 0, + max: patterns.length - 1, + format: v => patterns[v] || /*LANG*/"Off", onchange: v => { - require("buzz").pattern(vibPatterns[v]); - callback(vibPatterns[v]); + require("buzz").pattern(patterns[v]); + callback(patterns[v]); } }; } diff --git a/modules/time_utils.js b/modules/time_utils.js index 5ca153710..6a3ed6faf 100644 --- a/modules/time_utils.js +++ b/modules/time_utils.js @@ -55,7 +55,7 @@ exports.decodeTime = (millis) => { */ exports.formatTime = (value) => { var time = safeTime(typeof value === "object" ? value : exports.decodeTime(value)); - if (time.d != 0) throw "(d)ays not supported here"; + if (time.d != 0) throw "days not supported here"; if (time.h < 0 || time.h > 23) throw "Invalid value: must be 0 <= h <= 23"; if (time.m < 0 || time.m > 59) throw "Invalid value: must be 0 <= m <= 59"; return time.h + ":" + ("0" + time.m).substr(-2); @@ -63,16 +63,19 @@ exports.formatTime = (value) => { /** * @param {object|int} value {d, h, m, s} object or milliseconds - * @returns an human-readable duration string like "3d 1h 10m 45s" + * @param {boolean} compact `true` to remove all whitespaces between the values + * @returns an human-readable duration string like "3d 1h 10m 45s" (or "3d1h10m45s" if `compact` is `true`) */ -exports.formatDuration = (value) => { +exports.formatDuration = (value, compact) => { + compact = compact || false; var duration = ""; var time = safeTime(typeof value === "object" ? value : exports.decodeTime(value)); if (time.d > 0) duration += time.d + "d "; if (time.h > 0) duration += time.h + "h "; if (time.m > 0) duration += time.m + "m "; if (time.s > 0) duration += time.s + "s" - return duration.trim(); + duration = duration.trim() + return compact ? duration.replace(" ", "") : duration; } exports.getCurrentTimeMillis = () => {