1
0
Fork 0
MaBecker 2019-11-13 18:49:38 +01:00
commit 2e6eb012bb
7 changed files with 134 additions and 56 deletions

View File

@ -23,7 +23,7 @@ Bangle.on('mag', function(m) {
g.fillRect(70,0,170,24);
g.setColor(0xffff);
g.setFontAlign(0,0);
g.drawString((m.heading===undefined)?"---":Math.round(m.heading),120,12);
g.drawString(isNaN(m.heading)?"---":Math.round(m.heading),120,12);
g.setColor(0,0,0);
arrow(oldHeading,0);
arrow(oldHeading+180,0);

View File

@ -39,11 +39,16 @@ function readHRM() {
t.sort();
// average the middle 3
var mid = t.length>>1;
hrm = (t[mid]+t[mid+1]+t[mid+2])/3;
if (mid+2<t.length)
hrm = (t[mid]+t[mid+1]+t[mid+2])/3;
else if (mid<t.length)
hrm = t[mid];
else
hrm = 0;
g.setFontVector(40);
g.setFontAlign(0,0);
g.clearRect(0,0,239,100);
var str = Math.round(hrm);
var str = hrm ? Math.round(hrm) : "?";
var px = 120;
g.drawString(str,px,40);
px += g.stringWidth(str)/2;

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwhC/AH4A/AHeIDC+AC60IC/51ELoIXTCYMIDISLpC/67dxAAJHBYsLhAYKLhgXXHhWAdoQbBApAvhBgYcCAogXkI64XYhDtII/oMUERTyDABJ0FPI4A/AH4A/AGY="))

117
apps/hid-binary-keyboard.js Normal file
View File

@ -0,0 +1,117 @@
/*
Binary search keyboard for typing with
the touchscreen
*/
var storage = require('Storage');
const settings = storage.readJSON('@setting') || { HID: false };
const KEY = {
A : 4 ,
B : 5 ,
C : 6 ,
D : 7 ,
E : 8 ,
F : 9 ,
G : 10,
H : 11,
I : 12,
J : 13,
K : 14,
L : 15,
M : 16,
N : 17,
O : 18,
P : 19,
Q : 20,
R : 21,
S : 22,
T : 23,
U : 24,
V : 25,
W : 26,
X : 27,
Y : 28,
Z : 29,
1 : 30,
2 : 31,
3 : 32,
4 : 33,
5 : 34,
6 : 35,
7 : 36,
8 : 37,
9 : 38,
0 : 39
};
function sendHID(code) {
return new Promise(resolve=>{
NRF.sendHIDReport([2,0,0,code,0,0,0,0,0], () => {
NRF.sendHIDReport([2,0,0,0,0,0,0,0,0], resolve);
});
});
};
function showChars(x,chars) {
var lines = Math.round(Math.sqrt(chars.length)*2);
g.setFontAlign(0,0);
var sy = Math.round(200/lines);
var sx = sy;
g.setFont("Vector", sy-2);
var y = (240 - lines*sy);
var last = 0;
for (var i=0;i<lines;i++) {
var n = Math.round(chars.length*(i+1)/lines);
var xo = x + (120 - sx*(n-last-1))/2;
for (var j=last;j<n;j++)
g.drawString(chars[j], xo + (j-last)*sx, y + sy*i)
last = n;
}
}
function show(chars,callback) {
g.clear();
if (chars.length==1) {
callback(chars);
return;
}
var m = chars.length/2;
charl=chars.slice(0,m);
charr=chars.slice(m);
showChars(0,charl);
showChars(120,charr);
setWatch(() => {
clearWatch();
show(charl,callback);
}, BTN4);
setWatch(() => {
clearWatch();
show(charr,callback);
}, BTN5);
}
function getCharacter() {
return new Promise(resolve => {
show("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",resolve);
});
}
function startKeyboardHID() {
getCharacter().then(ch => {
return sendHID(KEY[ch]);
}).then(startKeyboardHID);
};
if (!settings.HID) {
E.showMessage('HID disabled');
setTimeout(load, 1000);
} else {
startKeyboardHID();
setWatch(() => {
sendHID(44); // space
}, BTN2, {repeat:true});
setWatch(() => {
sendHID(40); // enter
}, BTN3, {repeat:true});
}

View File

@ -0,0 +1,5 @@
{
"name": "Binary Keyboard","type":"app",
"icon": "*hidbkbd",
"src": "-hidbkbd"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

View File

@ -1,50 +0,0 @@
/*
Binary search keyboard for typing with
the touchscreen
*/
function showChars(x,chars) {
var lines = Math.round(Math.sqrt(chars.length)*2);
g.setFontAlign(0,0);
var sy = Math.round(200/lines);
var sx = sy;
g.setFont("Vector", sy-2);
var y = (240 - lines*sy);
var last = 0;
for (var i=0;i<lines;i++) {
var n = Math.round(chars.length*(i+1)/lines);
var xo = x + (120 - sx*(n-last-1))/2;
for (var j=last;j<n;j++)
g.drawString(chars[j], xo + (j-last)*sx, y + sy*i)
last = n;
}
}
function show(chars,callback) {
g.clear();
if (chars.length==1) {
callback(chars);
return;
}
var m = chars.length/2;
charl=chars.slice(0,m);
charr=chars.slice(m);
showChars(0,charl);
showChars(120,charr);
setWatch(() => {
clearWatch();
show(charl,callback);
}, BTN4);
setWatch(() => {
clearWatch();
show(charr,callback);
}, BTN5);
}
function getCharacter() {
return new Promise(resolve => {
show("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",resolve);
});
}
getCharacter().then(print)