Setting to turn Bluetooth on and off

master
James M Snell 2019-11-08 09:52:37 -08:00
parent 4d3bcd94a3
commit 75f8f7b86a
3 changed files with 91 additions and 74 deletions

View File

@ -1,8 +1,9 @@
{ {
ble: false, // Bluetooth disabled by default
timeout: 10, // Default LCD timeout in seconds timeout: 10, // Default LCD timeout in seconds
vibrate: true, // Vibration enabled by default. App must support vibrate: true, // Vibration enabled by default. App must support
beep: true, // Beep enabled by default. App must support beep: true, // Beep enabled by default. App must support
timezone: 0, // Set the timezone for the device timezone: 0, // Set the timezone for the device
HID : false, // BLE HID mode, off by default HID: false, // BLE HID mode, off by default
debug: false, // Debug mode disabled by default. App must support debug: false, // Debug mode disabled by default. App must support
} }

View File

@ -1,80 +1,87 @@
(function() { (function() {
var s = require('Storage').readJSON('@setting'); var s = require('Storage').readJSON('@setting');
var adv = { uart: true }; if (s.ble) {
if (s.HID) { var adv = { uart: true };
// Report from https://notes.iopush.net/custom-usb-hid-device-descriptor-media-keyboard/ if (s.HID) {
Bangle.HID = new Uint8Array([ // Report from https://notes.iopush.net/custom-usb-hid-device-descriptor-media-keyboard/
// Keyboard Controls Bangle.HID = new Uint8Array([
0x05, 0x01, // Keyboard Controls
0x09, 0x06, 0x05, 0x01,
0xA1, 0x01, 0x09, 0x06,
0x85, 0x02, 0xA1, 0x01,
0x05, 0x07, 0x85, 0x02,
0x19, 0xe0, 0x05, 0x07,
0x29, 0xe7, 0x19, 0xe0,
0x15, 0x00, 0x29, 0xe7,
0x25, 0x01, 0x15, 0x00,
0x75, 0x01, 0x25, 0x01,
0x95, 0x08, 0x75, 0x01,
0x81, 0x02, 0x95, 0x08,
0x95, 0x01, 0x81, 0x02,
0x75, 0x08, 0x95, 0x01,
0x81, 0x01, 0x75, 0x08,
0x95, 0x05, 0x81, 0x01,
0x75, 0x01, 0x95, 0x05,
0x05, 0x08, 0x75, 0x01,
0x19, 0x01, 0x05, 0x08,
0x29, 0x05, 0x19, 0x01,
0x91, 0x02, 0x29, 0x05,
0x95, 0x01, 0x91, 0x02,
0x75, 0x03, 0x95, 0x01,
0x91, 0x01, 0x75, 0x03,
0x95, 0x06, 0x91, 0x01,
0x75, 0x08, 0x95, 0x06,
0x15, 0x00, 0x75, 0x08,
0x25, 0x73, 0x15, 0x00,
0x05, 0x07, 0x25, 0x73,
0x19, 0x00, 0x05, 0x07,
0x29, 0x73, 0x19, 0x00,
0x81, 0x00, 0x29, 0x73,
0x09, 0x05, 0x81, 0x00,
0x15, 0x00, 0x09, 0x05,
0x26, 0xFF, 0x00, 0x15, 0x00,
0x75, 0x08, 0x26, 0xFF, 0x00,
0x95, 0x02, 0x75, 0x08,
0xB1, 0x02, 0x95, 0x02,
0xC0, 0xB1, 0x02,
0xC0,
// Music Controls // Music Controls
0x05, 0x0C, 0x05, 0x0C,
0x09, 0x01, 0x09, 0x01,
0xA1, 0x01, 0xA1, 0x01,
0x85, 0x01, 0x85, 0x01,
0x15, 0x00, 0x15, 0x00,
0x25, 0x01, 0x25, 0x01,
0x75, 0x01, 0x75, 0x01,
0x95, 0x01, 0x95, 0x01,
0x09, 0xB5, 0x09, 0xB5,
0x81, 0x02, 0x81, 0x02,
0x09, 0xB6, 0x09, 0xB6,
0x81, 0x02, 0x81, 0x02,
0x09, 0xB7, 0x09, 0xB7,
0x81, 0x02, 0x81, 0x02,
0x09, 0xB8, 0x09, 0xB8,
0x81, 0x02, 0x81, 0x02,
0x09, 0xCD, 0x09, 0xCD,
0x81, 0x02, 0x81, 0x02,
0x09, 0xE2, 0x09, 0xE2,
0x81, 0x02, 0x81, 0x02,
0x09, 0xE9, 0x09, 0xE9,
0x81, 0x02, 0x81, 0x02,
0x09, 0xEA, 0x09, 0xEA,
0x81, 0x02, 0x81, 0x02,
0xC0 0xC0
]); ]);
adv.hid = Bangle.HID; adv.hid = Bangle.HID;
}
NRF.setServices(undefined, adv);
try {
NRF.wake();
} catch (e) {}
} else {
NRF.sleep();
} }
NRF.setServices(undefined, adv);
if (!s.vibrate) Bangle.buzz=()=>Promise.resolve(); if (!s.vibrate) Bangle.buzz=()=>Promise.resolve();
if (!s.beep) Bangle.beep=()=>Promise.resolve(); if (!s.beep) Bangle.beep=()=>Promise.resolve();

View File

@ -18,6 +18,7 @@ function updateSettings() {
function resetSettings() { function resetSettings() {
settings = { settings = {
ble: false,
timeout: 10, timeout: 10,
vibrate: true, vibrate: true,
beep: true, beep: true,
@ -39,6 +40,14 @@ const boolFormat = (v) => v ? "On" : "Off";
function showMainMenu() { function showMainMenu() {
const mainmenu = { const mainmenu = {
'': { 'title': 'Settings' }, '': { 'title': 'Settings' },
'BLE': {
value: settings.ble,
format: boolFormat,
onchange: () => {
settings.ble = !settings.ble;
updateSettings();
}
},
'LCD Timeout': { 'LCD Timeout': {
value: settings.timeout, value: settings.timeout,
min: 0, min: 0,