mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 12:53:21 +02:00
Refactor origin swap code to be a bit more traditional. I don't like overriding functions unless necessary.
This commit is contained in:
@@ -95,34 +95,38 @@ 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
|
||||
}
|
||||
// Usually the touch origin is the same as the display's origin,
|
||||
// but sometimes it might not be.
|
||||
var getters = (function(origin) {
|
||||
log.info('Touch origin is %s', origin)
|
||||
return {
|
||||
'top left': {
|
||||
x: function(point) {
|
||||
return Math.floor(point.x * socket.maxX)
|
||||
}
|
||||
, y: function(point) {
|
||||
return Math.floor(point.y * socket.maxY)
|
||||
}
|
||||
}
|
||||
// So far the only device we've seen exhibiting this behavior
|
||||
// is Yoga Tablet 8.
|
||||
, 'bottom left': {
|
||||
x: function(point) {
|
||||
return Math.floor((1 - point.y) * socket.maxX)
|
||||
},
|
||||
y: function(point) {
|
||||
return Math.floor(point.x * socket.maxY)
|
||||
}
|
||||
}
|
||||
}[origin]
|
||||
})(flags.get('forceTouchOrigin', 'top left'))
|
||||
|
||||
plugin.touchDown = function(point) {
|
||||
send(util.format(
|
||||
'd %s %s %s %s\n'
|
||||
, point.contact
|
||||
, getX(point)
|
||||
, getY(point)
|
||||
, getters.x(point)
|
||||
, getters.y(point)
|
||||
, Math.floor((point.pressure || 0.5) * socket.maxPressure)
|
||||
))
|
||||
}
|
||||
@@ -131,8 +135,8 @@ module.exports = syrup.serial()
|
||||
send(util.format(
|
||||
'm %s %s %s %s\n'
|
||||
, point.contact
|
||||
, getX(point)
|
||||
, getY(point)
|
||||
, getters.x(point)
|
||||
, getters.y(point)
|
||||
, Math.floor((point.pressure || 0.5) * socket.maxPressure)
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user