From 33d4c70820af8c2a3f7056d35b2f85a4e6405678 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Wed, 29 Oct 2014 15:13:14 +0900 Subject: [PATCH] Fix touch coordinates on Yoga Tablet 8. --- lib/units/device/plugins/flags.js | 16 +++++++++++++++ lib/units/device/plugins/touch.js | 33 ++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 lib/units/device/plugins/flags.js diff --git a/lib/units/device/plugins/flags.js b/lib/units/device/plugins/flags.js new file mode 100644 index 00000000..3999e387 --- /dev/null +++ b/lib/units/device/plugins/flags.js @@ -0,0 +1,16 @@ +var syrup = require('syrup') + +module.exports = syrup.serial() + .dependency(require('./data')) + .define(function(options, data) { + return { + has: function(flag) { + return data && data.flags && !!data.flags[flag] + } + , get: function(flag, defaultValue) { + return data && data.flags && data.flags[flag] !== void 0 + ? data.flags[flag] + : defaultValue + } + } + }) diff --git a/lib/units/device/plugins/touch.js b/lib/units/device/plugins/touch.js index 13e18f28..267b4094 100644 --- a/lib/units/device/plugins/touch.js +++ b/lib/units/device/plugins/touch.js @@ -14,7 +14,8 @@ module.exports = syrup.serial() .dependency(require('../support/adb')) .dependency(require('../support/router')) .dependency(require('../resources/minitouch')) - .define(function(options, adb, router, minitouch) { + .dependency(require('./flags')) + .define(function(options, adb, router, minitouch, flags) { var log = logger.createLogger('device:plugins:touch') var plugin = Object.create(null) @@ -94,12 +95,34 @@ module.exports = syrup.serial() socket.write(command) } + var getX = function(point) { + return Math.floor(point.x * socket.maxX) + } + + var getY = function(point) { + return Math.floor(point.y * socket.maxY) + } + + switch (flags.get('forceTouchOrigin', 'top left')) { + case 'bottom left': + // So far the only device we've seen exhibiting this behavior + // is Yoga Tablet 8. + log.info('Touch origin is bottom left') + getX = function(point) { + return Math.floor((1 - point.y) * socket.maxX) + } + getY = function(point) { + return Math.floor(point.x * socket.maxY) + } + break + } + plugin.touchDown = function(point) { send(util.format( 'd %s %s %s %s\n' , point.contact - , Math.floor(point.x * socket.maxX) - , Math.floor(point.y * socket.maxY) + , getX(point) + , getY(point) , Math.floor((point.pressure || 0.5) * socket.maxPressure) )) } @@ -108,8 +131,8 @@ module.exports = syrup.serial() send(util.format( 'm %s %s %s %s\n' , point.contact - , Math.floor(point.x * socket.maxX) - , Math.floor(point.y * socket.maxY) + , getX(point) + , getY(point) , Math.floor((point.pressure || 0.5) * socket.maxPressure) )) }