mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Fix touch coordinates on Yoga Tablet 8.
This commit is contained in:
parent
758e43e2e8
commit
33d4c70820
2 changed files with 44 additions and 5 deletions
16
lib/units/device/plugins/flags.js
Normal file
16
lib/units/device/plugins/flags.js
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
})
|
|
@ -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)
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue