diff --git a/apps/setting/ChangeLog b/apps/setting/ChangeLog index 9b88f0073..a11995dd4 100644 --- a/apps/setting/ChangeLog +++ b/apps/setting/ChangeLog @@ -54,3 +54,4 @@ Improve "Turn Off" user experience 0.48: Allow reading custom themes from files 0.49: Now reloads settings properly after 'Calibrate Battery' +0.50: Add Bangle.js 2 touchscreen calibration - for 2v16 or 2v15 cutting edge builds diff --git a/apps/setting/README.md b/apps/setting/README.md index 657b96f71..abf968f62 100644 --- a/apps/setting/README.md +++ b/apps/setting/README.md @@ -33,6 +33,7 @@ This is Bangle.js's settings menu * On Bangle.js 2 when locked the touchscreen is turned off to save power. Because of this, `Wake on Touch` actually uses the accelerometer, and you need to actually tap the display to wake Bangle.js. * **Twist X** these options adjust the sensitivity of `Wake on Twist` to ensure Bangle.js wakes up with just the right amount of wrist movement. +* **Calibrate** on Bangle.js 2, pop up a screen allowing you to calibrate the touchscreen (calibration only works on 2v16 or 2v15 cutting edge builds) ## Locale diff --git a/apps/setting/metadata.json b/apps/setting/metadata.json index d209eafc3..c114e9daf 100644 --- a/apps/setting/metadata.json +++ b/apps/setting/metadata.json @@ -1,7 +1,7 @@ { "id": "setting", "name": "Settings", - "version": "0.49", + "version": "0.50", "description": "A menu for setting up Bangle.js", "icon": "settings.png", "tags": "tool,system", diff --git a/apps/setting/settings.js b/apps/setting/settings.js index 77e3fdd87..36af93a8a 100644 --- a/apps/setting/settings.js +++ b/apps/setting/settings.js @@ -491,6 +491,10 @@ function showLCDMenu() { } } }); + if (BANGLEJS2) + Object.assign(lcdMenu, { + /*LANG*/'Calibrate': () => showTouchscreenCalibration() + }); return E.showMenu(lcdMenu) } @@ -774,4 +778,85 @@ function showAppSettings(app) { } } +function showTouchscreenCalibration() { + Bangle.setUI(); + // disable touchscreen calibration (passed coords right through) + Bangle.setOptions({touchX1: 0, touchY1: 0, touchX2: g.getWidth(), touchY2: g.getHeight() }); + + var P = 32; + var corners = [ + [P,P], + [g.getWidth()-P,P], + [g.getWidth()-P,g.getHeight()-P], + [P,g.getHeight()-P], + ]; + var currentCorner = 0; + var currentTry = 0; + var pt = { + x1 : 0, y1 : 0, x2 : 0, y2 : 0 + }; + + function showTapSpot() { + var spot = corners[currentCorner]; + g.clear(1); + g.drawLine(spot[0]-32,spot[1],spot[0]+32,spot[1]); + g.drawLine(spot[0],spot[1]-32,spot[0],spot[1]+32); + g.drawCircle(spot[0],spot[1], 16); + var tapsLeft = (1-currentTry)*4+(4-currentCorner); + g.setFont("6x8:2").setFontAlign(0,0).drawString(tapsLeft+" taps\nto go", g.getWidth()/2, g.getHeight()/2); + } + + function calcCalibration() { + g.clear(1); + // we should now have 4 of each tap in 'pt' + pt.x1 /= 4; + pt.y1 /= 4; + pt.x2 /= 4; + pt.y2 /= 4; + // work out final values + var calib = { + x1 : Math.round(pt.x1 - (pt.x2-pt.x1)*P/(g.getWidth()-P*2)), + y1 : Math.round(pt.y1 - (pt.y2-pt.y1)*P/(g.getHeight()-P*2)), + x2 : Math.round(pt.x2 + (pt.x2-pt.x1)*P/(g.getWidth()-P*2)), + y2 : Math.round(pt.y2 + (pt.y2-pt.y1)*P/(g.getHeight()-P*2)) + }; + Bangle.setOptions({ + touchX1: calib.x1, touchY1: calib.y1, touchX2: calib.x2, touchY2: calib.y2 + }); + var s = require("Storage").readJSON("setting.json",1)||{}; + s.touch = calib; + require("Storage").writeJSON("setting.json",s); + g.setFont("6x8:2").setFontAlign(0,0).drawString("Calibrated!", g.getWidth()/2, g.getHeight()/2); + // now load the main menu again + setTimeout(showLCDMenu, 500); + } + + function touchHandler(_,e) { + var spot = corners[currentCorner]; + // store averages + if (spot[0]*2 < g.getWidth()) + pt.x1 += e.x; + else + pt.x2 += e.x; + if (spot[1]*2 < g.getHeight()) + pt.y1 += e.y; + else + pt.y2 += e.y; + // go to next corner + currentCorner++; + if (currentCorner>=corners.length) { + currentCorner = 0; + currentTry++; + if (currentTry==2) { + Bangle.removeListener('touch', touchHandler); + return calcCalibration(); + } + } + showTapSpot(); + } + Bangle.on('touch', touchHandler); + + showTapSpot(); +} + showMainMenu();