mirror of https://github.com/espruino/BangleApps
massive rewrite with really heavy inspiration from music control app
parent
fc6d6aa4bb
commit
b58069fba1
|
@ -2,58 +2,51 @@ var storage = require('Storage');
|
|||
|
||||
const settings = storage.readJSON('setting.json',1) || { HID: false };
|
||||
|
||||
// hidcontrol module selective and manual import :
|
||||
report = new Uint8Array([
|
||||
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
|
||||
0x09, 0x01, // USAGE (Consumer Control)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
// -------------------- common global items
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||
0x75, 0x01, // REPORT_SIZE (1) - each field occupies 1 bit
|
||||
// -------------------- misc bits
|
||||
0x95, 0x05, // REPORT_COUNT (5)
|
||||
0x09, 0xb5, // USAGE (Scan Next Track)
|
||||
0x09, 0xb6, // USAGE (Scan Previous Track)
|
||||
0x09, 0xb7, // USAGE (Stop)
|
||||
0x09, 0xcd, // USAGE (Play/Pause)
|
||||
0x09, 0xe2, // USAGE (Mute)
|
||||
0x81, 0x06, // INPUT (Data,Var,Rel) - relative inputs
|
||||
// -------------------- volume up/down bits
|
||||
0x95, 0x02, // REPORT_COUNT (2)
|
||||
0x09, 0xe9, // USAGE (Volume Up)
|
||||
0x09, 0xea, // USAGE (Volume Down)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs) - absolute inputs
|
||||
// -------------------- padding bit
|
||||
0x95, 0x01, // REPORT_COUNT (1)
|
||||
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
|
||||
0xc0 // END_COLLECTION
|
||||
]);
|
||||
function p(c,cb) { NRF.sendHIDReport(c, function() { NRF.sendHIDReport(0, cb) }); }
|
||||
volumeUp = function(cb) { p(0x80,cb) };
|
||||
//end of manual selective import
|
||||
|
||||
NRF.setServices(undefined, { hid : report });
|
||||
|
||||
g.clear();
|
||||
E.showMessage('BTN2 to trigger','camTrigger');
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
var sendHid, camShot, profile;
|
||||
|
||||
if (settings.HID) {
|
||||
NRF.setServices(undefined, { hid : report });
|
||||
shotTrigger = function() {volumeUp();};
|
||||
profile = 'camShutter';
|
||||
sendHid = function (code, cb) {
|
||||
try {
|
||||
NRF.sendHIDReport([1,code], () => {
|
||||
NRF.sendHIDReport([1,0], () => {
|
||||
if (cb) cb();
|
||||
});
|
||||
});
|
||||
} catch(e) {
|
||||
print(e);
|
||||
}
|
||||
};
|
||||
camShot = function (cb) { sendHid(0x80, cb); };
|
||||
} else {
|
||||
E.showMessage('HID disabled');
|
||||
setTimeout(load, 1000);
|
||||
}
|
||||
|
||||
setWatch(function(e){
|
||||
E.showMessage('capture');
|
||||
Bangle.beep();
|
||||
shotTrigger();
|
||||
function drawApp() {
|
||||
g.clear();
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
E.showMessage('BTN2 to trigger','camTrigger');
|
||||
},BTN2,{ repeat:true, edge:'falling' });
|
||||
g.setFont("6x8",2);
|
||||
g.setFontAlign(0,0);
|
||||
g.drawString(profile, 120, 120);
|
||||
const d = g.getWidth() - 18;
|
||||
|
||||
function c(a) {
|
||||
return {
|
||||
width: 8,
|
||||
height: a.length,
|
||||
bpp: 1,
|
||||
buffer: (new Uint8Array(a)).buffer
|
||||
};
|
||||
}
|
||||
|
||||
g.drawImage(c([0,8,12,14,255,14,12,8]),d,116);
|
||||
}
|
||||
|
||||
if (camShot) {
|
||||
setWatch(function(e) {
|
||||
E.showMessage('camShot !');
|
||||
setTimeout(drawApp, 1000);
|
||||
camShot(() => {});
|
||||
}, BTN2, { edge:"falling",repeat:true,debounce:50});
|
||||
|
||||
drawApp();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue