From a874d5838c1dee5a5dfb4e71844d961506dd29e9 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 25 Mar 2020 11:05:33 +0000 Subject: [PATCH] Added vibrate as beep workaround --- apps.json | 6 +++--- apps/boot/ChangeLog | 1 + apps/boot/boot0.js | 14 +++++++++++++- apps/mmonday/ChangeLog | 1 + apps/mmonday/manic-monday.js | 22 +++++++++++++++++----- apps/setting/ChangeLog | 1 + apps/setting/settings-default.json | 2 +- apps/setting/settings.js | 18 ++++++++++-------- 8 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 apps/mmonday/ChangeLog diff --git a/apps.json b/apps.json index 2754bb195..d5b079f7a 100644 --- a/apps.json +++ b/apps.json @@ -2,7 +2,7 @@ { "id": "boot", "name": "Bootloader", "icon": "bootloader.png", - "version":"0.10", + "version":"0.11", "description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings", "tags": "tool,system", "type":"bootloader", @@ -92,7 +92,7 @@ { "id": "setting", "name": "Settings", "icon": "settings.png", - "version":"0.06", + "version":"0.07", "description": "A menu for setting up Bangle.js", "tags": "tool,system", "storage": [ @@ -575,7 +575,7 @@ { "id": "mmonday", "name": "Manic Monday Tone", "icon": "manic-monday-icon.png", - "version":"0.01", + "version":"0.02", "description": "The Bangles make a comeback", "tags": "sound", "storage": [ diff --git a/apps/boot/ChangeLog b/apps/boot/ChangeLog index 093f017b2..3bd9ec71c 100644 --- a/apps/boot/ChangeLog +++ b/apps/boot/ChangeLog @@ -8,3 +8,4 @@ 0.09: Only check GPS for time after a fresh boot 0.10: Stop users calling save() (fix #125) If Debug info is set to 'show' don't move to Terminal if connected! +0.11: Added vibrate as beep workaround diff --git a/apps/boot/boot0.js b/apps/boot/boot0.js index cb8d49ba0..ad8ccb312 100644 --- a/apps/boot/boot0.js +++ b/apps/boot/boot0.js @@ -20,7 +20,19 @@ if (s.blerepl===false) { // If not programmable, force terminal off Bluetooth if (s.ble===false && !NRF.getSecurityStatus().connected) NRF.sleep(); // Set time, vibrate, beep, etc if (!s.vibrate) Bangle.buzz=Promise.resolve; -if (!s.beep) Bangle.beep=Promise.resolve; +if (s.beep===false) Bangle.beep=Promise.resolve; +else if (s.beep=="vib") Bangle.beep = function (time, freq) { + return new Promise(function(resolve) { + if ((0|freq)<=0) freq=4000; + if ((0|time)<=0) time=200; + if (time>5000) time=5000; + analogWrite(D13,0.1,{freq:freq}); + setTimeout(function() { + digitalWrite(D13,0); + resolve(); + }, time); + }); +}; Bangle.setLCDTimeout(s.timeout); if (!s.timeout) Bangle.setLCDPower(1); E.setTimeZone(s.timezone); diff --git a/apps/mmonday/ChangeLog b/apps/mmonday/ChangeLog new file mode 100644 index 000000000..1b5f725c4 --- /dev/null +++ b/apps/mmonday/ChangeLog @@ -0,0 +1 @@ +0.02: Added vibrate as beep workaround diff --git a/apps/mmonday/manic-monday.js b/apps/mmonday/manic-monday.js index a2245e7e7..c949fafbf 100644 --- a/apps/mmonday/manic-monday.js +++ b/apps/mmonday/manic-monday.js @@ -1,12 +1,23 @@ // made using https://www.espruino.com/Making+Music // Manic Monday tone by The Bangles -var SPEAKER_PIN = D18; - -function freq(f) { - if (f===0) digitalWrite(SPEAKER_PIN, 0); - else analogWrite(SPEAKER_PIN, 0.5, {freq: f}); +var s = require('Storage').readJSON('setting.json',1)||{}; +/* Normally we'd just use Bangle.beep which works automatically +but because we're going lower level we need to account for the +different pin. */ +if (s.beep=="vib") { + function freq(f) { + if (f===0) digitalWrite(D13, 0); + else analogWrite(D13, 0.1, {freq: f}); + } +} else { + function freq(f) { + if (f===0) digitalWrite(D18, 0); + else analogWrite(D18, 0.5, {freq: f}); + } } + + freq(1000); freq(1500); freq(0); @@ -39,6 +50,7 @@ var tune = "aggffefed"; var pos = 0; setWatch(() => { + pos = 0; var playing = setInterval(step, 500); if(playing === 0) clearInterval(playing); }, BTN1); diff --git a/apps/setting/ChangeLog b/apps/setting/ChangeLog index 1485d5c12..d29a312d0 100644 --- a/apps/setting/ChangeLog +++ b/apps/setting/ChangeLog @@ -3,3 +3,4 @@ 0.04: Add setting to disable log messages 0.05: Fix Settings json 0.06: Remove distance setting as there's a separate app for Locale now +0.07: Added vibrate as beep workaround diff --git a/apps/setting/settings-default.json b/apps/setting/settings-default.json index 2fa66cbdd..0800593cb 100644 --- a/apps/setting/settings-default.json +++ b/apps/setting/settings-default.json @@ -4,7 +4,7 @@ log: false, // Do log messages appear on screen? timeout: 10, // Default LCD timeout in seconds vibrate: true, // Vibration enabled by default. App must support - beep: true, // Beep enabled by default. App must support + beep: "vib", // Beep enabled by default. App must support timezone: 0, // Set the timezone for the device HID : false, // BLE HID mode, off by default clock: null, // a string for the default clock's name diff --git a/apps/setting/settings.js b/apps/setting/settings.js index 49af98318..9d5fa2775 100644 --- a/apps/setting/settings.js +++ b/apps/setting/settings.js @@ -16,7 +16,7 @@ function resetSettings() { log: false, // Do log messages appear on screen? timeout: 10, // Default LCD timeout in seconds vibrate: true, // Vibration enabled by default. App must support - beep: true, // Beep enabled by default. App must support + beep: "vib", // Beep enabled by default. App must support timezone: 0, // Set the timezone for the device HID : false, // BLE HID mode, off by default clock: null, // a string for the default clock's name @@ -32,6 +32,8 @@ if (!settings) resetSettings(); const boolFormat = v => v ? "On" : "Off"; function showMainMenu() { + var beepV = [ false,true,"vib" ]; + var beepN = [ "Off","Piezo","Vibrate" ]; const mainmenu = { '': { 'title': 'Settings' }, 'Make Connectable': makeConnectable, @@ -71,14 +73,14 @@ function showMainMenu() { } }, 'Beep': { - value: settings.beep, - format: boolFormat, - onchange: () => { - settings.beep = !settings.beep; + value: 0|beepV.indexOf(settings.beep), + min:0,max:2, + format: v=>beepN[v], + onchange: v => { + settings.beep = beepV[v]; + if (v==1) { analogWrite(D18,0.5,{freq:2000});setTimeout(()=>D18.reset(),200) } // piezo + else if (v==2) { analogWrite(D13,0.1,{freq:2000});setTimeout(()=>D13.reset(),200) } // vibrate updateSettings(); - if (settings.beep) { - Bangle.beep(1); - } } }, 'Vibration': {