Moved LCD calibration to top of menu, and use 12 taps (not 8)

LCD calibration will now error if the calibration is obviously wrong
pull/2735/head^2
Gordon Williams 2023-05-04 12:21:32 +01:00
parent bf82abd104
commit 0e7afd5550
3 changed files with 31 additions and 20 deletions

View File

@ -65,3 +65,5 @@ of 'Select Clock'
0.57: Settings.log = 0,1,2,3 for off,display,log,both 0.57: Settings.log = 0,1,2,3 for off,display,log,both
0.58: On/Off settings items now use checkboxes 0.58: On/Off settings items now use checkboxes
0.59: Preserve BLE whitelist even when disabled 0.59: Preserve BLE whitelist even when disabled
0.60: Moved LCD calibration to top of menu, and use 12 taps (not 8)
LCD calibration will now error if the calibration is obviously wrong

View File

@ -1,7 +1,7 @@
{ {
"id": "setting", "id": "setting",
"name": "Settings", "name": "Settings",
"version": "0.59", "version": "0.60",
"description": "A menu for setting up Bangle.js", "description": "A menu for setting up Bangle.js",
"icon": "settings.png", "icon": "settings.png",
"tags": "tool,system", "tags": "tool,system",

View File

@ -403,6 +403,12 @@ function showLCDMenu() {
const lcdMenu = { const lcdMenu = {
'': { 'title': 'LCD' }, '': { 'title': 'LCD' },
'< Back': ()=>showSystemMenu(), '< Back': ()=>showSystemMenu(),
};
if (BANGLEJS2)
Object.assign(lcdMenu, {
/*LANG*/'Calibrate': () => showTouchscreenCalibration()
});
Object.assign(lcdMenu, {
/*LANG*/'LCD Brightness': { /*LANG*/'LCD Brightness': {
value: settings.brightness, value: settings.brightness,
min: 0.1, min: 0.1,
@ -444,7 +450,7 @@ function showLCDMenu() {
updateOptions(); updateOptions();
} }
} }
}; });
if (!BANGLEJS2) if (!BANGLEJS2)
Object.assign(lcdMenu, { Object.assign(lcdMenu, {
/*LANG*/'Wake on BTN2': { /*LANG*/'Wake on BTN2': {
@ -514,10 +520,7 @@ function showLCDMenu() {
} }
} }
}); });
if (BANGLEJS2)
Object.assign(lcdMenu, {
/*LANG*/'Calibrate': () => showTouchscreenCalibration()
});
return E.showMenu(lcdMenu) return E.showMenu(lcdMenu)
} }
@ -852,17 +855,17 @@ function showTouchscreenCalibration() {
g.drawLine(spot[0]-32,spot[1],spot[0]+32,spot[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.drawLine(spot[0],spot[1]-32,spot[0],spot[1]+32);
g.drawCircle(spot[0],spot[1], 16); g.drawCircle(spot[0],spot[1], 16);
var tapsLeft = (1-currentTry)*4+(4-currentCorner); var tapsLeft = (2-currentTry)*4+(4-currentCorner);
g.setFont("6x8:2").setFontAlign(0,0).drawString(tapsLeft+/*LANG*/" taps\nto go", g.getWidth()/2, g.getHeight()/2); g.setFont("6x8:2").setFontAlign(0,0).drawString(tapsLeft+/*LANG*/" taps\nto go", g.getWidth()/2, g.getHeight()/2);
} }
function calcCalibration() { function calcCalibration() {
g.clear(1); g.clear(1);
// we should now have 4 of each tap in 'pt' // we should now have 6 of each tap in 'pt'
pt.x1 /= 4; pt.x1 /= 6;
pt.y1 /= 4; pt.y1 /= 6;
pt.x2 /= 4; pt.x2 /= 6;
pt.y2 /= 4; pt.y2 /= 6;
// work out final values // work out final values
var calib = { var calib = {
x1 : Math.round(pt.x1 - (pt.x2-pt.x1)*P/(g.getWidth()-P*2)), x1 : Math.round(pt.x1 - (pt.x2-pt.x1)*P/(g.getWidth()-P*2)),
@ -870,6 +873,11 @@ function showTouchscreenCalibration() {
x2 : Math.round(pt.x2 + (pt.x2-pt.x1)*P/(g.getWidth()-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)) y2 : Math.round(pt.y2 + (pt.y2-pt.y1)*P/(g.getHeight()-P*2))
}; };
var dx = calib.x2-calib.x1;
var dy = calib.y2-calib.y1;
if(dx<100 || dx>280 || dy<100 || dy>280) {
g.setFont("6x8:2").setFontAlign(0,0).drawString(/*LANG*/"Out of Range.\nPlease\ntry again", g.getWidth()/2, g.getHeight()/2);
} else {
Bangle.setOptions({ Bangle.setOptions({
touchX1: calib.x1, touchY1: calib.y1, touchX2: calib.x2, touchY2: calib.y2 touchX1: calib.x1, touchY1: calib.y1, touchX2: calib.x2, touchY2: calib.y2
}); });
@ -877,6 +885,7 @@ function showTouchscreenCalibration() {
s.touch = calib; s.touch = calib;
storage.writeJSON("setting.json",s); storage.writeJSON("setting.json",s);
g.setFont("6x8:2").setFontAlign(0,0).drawString(/*LANG*/"Calibrated!", g.getWidth()/2, g.getHeight()/2); g.setFont("6x8:2").setFontAlign(0,0).drawString(/*LANG*/"Calibrated!", g.getWidth()/2, g.getHeight()/2);
}
// now load the main menu again // now load the main menu again
setTimeout(showLCDMenu, 500); setTimeout(showLCDMenu, 500);
} }
@ -897,7 +906,7 @@ function showTouchscreenCalibration() {
if (currentCorner>=corners.length) { if (currentCorner>=corners.length) {
currentCorner = 0; currentCorner = 0;
currentTry++; currentTry++;
if (currentTry==2) { if (currentTry==3) {
Bangle.removeListener('touch', touchHandler); Bangle.removeListener('touch', touchHandler);
return calcCalibration(); return calcCalibration();
} }