From 09ea6fdec265c31d5e087ab0ae8d3f1e88fe1ae3 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 13 Nov 2019 17:22:23 +0000 Subject: [PATCH] added binary text keyboard --- apps.json | 11 +++ apps/hid-binary-keyboard-icon.js | 1 + apps/hid-binary-keyboard.js | 117 +++++++++++++++++++++++++++++++ apps/hid-binary-keyboard.json | 5 ++ apps/hid-binary-keyboard.png | Bin 0 -> 506 bytes testing/binary-keyboard.js | 50 ------------- 6 files changed, 134 insertions(+), 50 deletions(-) create mode 100644 apps/hid-binary-keyboard-icon.js create mode 100644 apps/hid-binary-keyboard.js create mode 100644 apps/hid-binary-keyboard.json create mode 100644 apps/hid-binary-keyboard.png delete mode 100644 testing/binary-keyboard.js diff --git a/apps.json b/apps.json index abe88464d..fdf154b48 100644 --- a/apps.json +++ b/apps.json @@ -235,6 +235,17 @@ {"name":"*hidkbd","url":"hid-keyboard-icon.js","evaluate":true} ] }, + { "id": "hidbkbd", + "name": "Binary Bluetooth Keyboard", + "icon": "hid-binary-keyboard.png", + "description": "Enable HID in settings, pair with your phone/PC, then type messages using the onscreen keyboard by tapping repeatedly on the key you want", + "tags": "bluetooth", + "storage": [ + {"name":"+hidbkbd","url":"hid-binary-keyboard.json"}, + {"name":"-hidbkbd","url":"hid-binary-keyboard.js"}, + {"name":"*hidbkbd","url":"hid-binary-keyboard-icon.js","evaluate":true} + ] + }, { "id": "animals", "name": "Animals Game", "icon": "animals.png", diff --git a/apps/hid-binary-keyboard-icon.js b/apps/hid-binary-keyboard-icon.js new file mode 100644 index 000000000..ca63665de --- /dev/null +++ b/apps/hid-binary-keyboard-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwhC/AH4A/AHeIDC+AC60IC/51ELoIXTCYMIDISLpC/67dxAAJHBYsLhAYKLhgXXHhWAdoQbBApAvhBgYcCAogXkI64XYhDtII/oMUERTyDABJ0FPI4A/AH4A/AGY=")) diff --git a/apps/hid-binary-keyboard.js b/apps/hid-binary-keyboard.js new file mode 100644 index 000000000..6c595ff8e --- /dev/null +++ b/apps/hid-binary-keyboard.js @@ -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 { + 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}); +} diff --git a/apps/hid-binary-keyboard.json b/apps/hid-binary-keyboard.json new file mode 100644 index 000000000..e2059a9c2 --- /dev/null +++ b/apps/hid-binary-keyboard.json @@ -0,0 +1,5 @@ +{ + "name": "Binary Keyboard","type":"app", + "icon": "*hidbkbd", + "src": "-hidbkbd" +} diff --git a/apps/hid-binary-keyboard.png b/apps/hid-binary-keyboard.png new file mode 100644 index 0000000000000000000000000000000000000000..19aec3c05b794809eae76077da580c604f981c42 GIT binary patch literal 506 zcmV&(fVX&)lQkODWP$9~zxmoIHO8{0cs!=+0aVFEEh#Mnrn((KgzLy9_SD2DG(jJL z3I|bZO2&XUKHDM4D1e5Nj#`(pC+T~t5!-mw=rtjwp?QeAhgX1$@V)Pie4-Gx(<@u9h&#<}y zF?fK0uBMk4iY^|k$Ef}R5M|re1l#|CCV=Os>T_EIY#V3*c&N&?T9lDwa%>^I;HB#ld_5-jY=EeDzG8vfqF+kTfoZ wlBVcqp}4rSP|^YlrR)v36mmEm4o6w@0yuf5j`FMk(f|Me07*qoM6N<$g18aoQvd(} literal 0 HcmV?d00001 diff --git a/testing/binary-keyboard.js b/testing/binary-keyboard.js deleted file mode 100644 index 3b68179a4..000000000 --- a/testing/binary-keyboard.js +++ /dev/null @@ -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 { - clearWatch(); - show(charl,callback); - }, BTN4); - setWatch(() => { - clearWatch(); - show(charr,callback); - }, BTN5); -} - -function getCharacter() { - return new Promise(resolve => { - show("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",resolve); - }); -} - -getCharacter().then(print) \ No newline at end of file