From f0b9425f5d8c05025d2d27b9247ef24bab47cbb2 Mon Sep 17 00:00:00 2001 From: Kane Date: Wed, 11 May 2022 11:09:34 +0200 Subject: [PATCH] calibration: app v1.0 added --- apps/calibration/README.md | 11 ++++ apps/calibration/app-icon.js | 1 + apps/calibration/app.js | 85 +++++++++++++++++++++++++++++++ apps/calibration/boot.js | 14 +++++ apps/calibration/calibration.png | Bin 0 -> 451 bytes apps/calibration/metadata.json | 17 +++++++ apps/calibration/settings.js | 23 +++++++++ 7 files changed, 151 insertions(+) create mode 100644 apps/calibration/README.md create mode 100644 apps/calibration/app-icon.js create mode 100644 apps/calibration/app.js create mode 100644 apps/calibration/boot.js create mode 100644 apps/calibration/calibration.png create mode 100644 apps/calibration/metadata.json create mode 100644 apps/calibration/settings.js diff --git a/apps/calibration/README.md b/apps/calibration/README.md new file mode 100644 index 000000000..37f637d21 --- /dev/null +++ b/apps/calibration/README.md @@ -0,0 +1,11 @@ +# Banglejs - Touchscreen calibration +A simple calibration app for the touchscreen + +## Usage + +Once lauched touch the cross that appear on the screen to make +another spawn elsewhere. + +each new touch on the screen will help to calibrate the offset +of your finger on the screen. After five or more input, press +the button to save the calibration and close the application. \ No newline at end of file diff --git a/apps/calibration/app-icon.js b/apps/calibration/app-icon.js new file mode 100644 index 000000000..af66c3f68 --- /dev/null +++ b/apps/calibration/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkB/4AJ+EPBhQXg+BBDCyJaGGR5zIDBoQEL4QYOLYR3GBIouJR5AYBGBILBU5QMGFwgiFX4wwIEI4XGGBAgHd44+HD44XHNw4XWM5IIHCIoXWV5IXICQgXvLxAAKCYYXh5nMC6n8C4PPC5MAAA8PC4ZxBACAXOI653hU5zvJABASEC5PwHI4XcMBIXICIoXXJBAXHCAwXXJBAXHB5AfGC4ygJEAwXGQ5BoIQxoiDBYgXECwIuIBgb5ECIQJFGBQmCC4QHEDBwAFCxoYICx5ZELZoZJFiIXpA=")) \ No newline at end of file diff --git a/apps/calibration/app.js b/apps/calibration/app.js new file mode 100644 index 000000000..d3823de63 --- /dev/null +++ b/apps/calibration/app.js @@ -0,0 +1,85 @@ +class BanglejsApp { + constructor() { + this.x = 0; + this.y = 0; + this.settings = { + xoffset: 0, + yoffset: 0, + }; + } + + load_settings() { + let settings = require('Storage').readJSON('calibration.json', true) || {active: false}; + + // do nothing if the calibration is deactivated + if (settings.active === true) { + // cancel the calibration offset + Bangle.on('touch', function(button, xy) { + xy.x += settings.xoffset; + xy.y += settings.yoffset; + }); + } + if (!settings.xoffset) settings.xoffset = 0; + if (!settings.yoffset) settings.yoffset = 0; + + console.log('loaded settings:'); + console.log(settings); + + return settings; + } + + save_settings() { + this.settings.active = true; + this.settings.reload = false; + require('Storage').writeJSON('calibration.json', this.settings); + + console.log('saved settings:'); + console.log(this.settings); + } + + explain() { + /* + * TODO: + * Present how to use the application + * + */ + } + + drawTarget() { + this.x = 16 + Math.floor(Math.random() * (g.getWidth() - 32)); + this.y = 40 + Math.floor(Math.random() * (g.getHeight() - 80)); + + g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24); + g.drawLine(this.x, this.y - 5, this.x, this.y + 5); + g.drawLine(this.x - 5, this.y, this.x + 5, this.y); + g.setFont('Vector', 10); + g.drawString('current offset: ' + this.settings.xoffset + ', ' + this.settings.yoffset, 0, 24); + } + + setOffset(xy) { + this.settings.xoffset = Math.round((this.settings.xoffset + (this.x - Math.floor((this.x + xy.x)/2)))/2); + this.settings.yoffset = Math.round((this.settings.yoffset + (this.y - Math.floor((this.y + xy.y)/2)))/2); + } +} + + +E.srand(Date.now()); +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +calibration = new BanglejsApp(); +calibration.load_settings(); + +let modes = { + mode : 'custom', + btn : function(n) { + calibration.save_settings(this.settings); + load(); + }, + touch : function(btn, xy) { + calibration.setOffset(xy); + calibration.drawTarget(); + }, +}; +Bangle.setUI(modes); +calibration.drawTarget(); diff --git a/apps/calibration/boot.js b/apps/calibration/boot.js new file mode 100644 index 000000000..237fb2e0d --- /dev/null +++ b/apps/calibration/boot.js @@ -0,0 +1,14 @@ +let cal_settings = require('Storage').readJSON("calibration.json", true) || {active: false}; +Bangle.on('touch', function(button, xy) { + // do nothing if the calibration is deactivated + if (cal_settings.active === false) return; + + // reload the calibration offset at each touch event /!\ bad for the flash memory + if (cal_settings.reload === true) { + cal_settings = require('Storage').readJSON("calibration.json", true); + } + + // apply the calibration offset + xy.x += cal_settings.xoffset; + xy.y += cal_settings.yoffset; +}); diff --git a/apps/calibration/calibration.png b/apps/calibration/calibration.png new file mode 100644 index 0000000000000000000000000000000000000000..3fb44beee035702bc84aa5d10fd313587db3b770 GIT binary patch literal 451 zcmV;!0X+VRP)Px$eMv+?RA_t-b3tR_+0z}XE5OEPe&b>}+WSH4) z&)kKyGZE>oVPwNwnkEAJ;6-;5ZPP=dNg%TYYCIuPB``90;Ss6L^TQRl^p#YPTlGlX>y-RKdp594EpjO_g zhnShuld*jl`XaDm8MV6OSqc!XrGn+%be;l4Yp7tI42lZOB;grrswFgogm)%uo`I1h zo(z back(), + 'Active': { + value: !!settings.active, + format: v => v? "On":"Off", + onchange: v => { + settings.active = v; + writeSettings(); + } + }, + }); +}) \ No newline at end of file