| 478 | } |
| 479 | |
| 480 | function startConsumer() { |
| 481 | var touchConsumer = new TouchConsumer({ |
| 482 | // Usually the touch origin is the same as the display's origin, |
| 483 | // but sometimes it might not be. |
| 484 | origin: (function(origin) { |
| 485 | log.info('Touch origin is %s', origin) |
| 486 | return { |
| 487 | 'top left': { |
| 488 | x: function(point) { |
| 489 | return point.x |
| 490 | } |
| 491 | , y: function(point) { |
| 492 | return point.y |
| 493 | } |
| 494 | } |
| 495 | // So far the only device we've seen exhibiting this behavior |
| 496 | // is Yoga Tablet 8. |
| 497 | , 'bottom left': { |
| 498 | x: function(point) { |
| 499 | return 1 - point.y |
| 500 | } |
| 501 | , y: function(point) { |
| 502 | return point.x |
| 503 | } |
| 504 | } |
| 505 | }[origin] |
| 506 | })(flags.get('forceTouchOrigin', 'top left')) |
| 507 | }) |
| 508 | |
| 509 | var startListener, errorListener |
| 510 | |
| 511 | return new Promise(function(resolve, reject) { |
| 512 | touchConsumer.on('start', startListener = function() { |
| 513 | resolve(touchConsumer) |
| 514 | }) |
| 515 | |
| 516 | touchConsumer.on('error', errorListener = reject) |
| 517 | |
| 518 | touchConsumer.start() |
| 519 | }) |
| 520 | .finally(function() { |
| 521 | touchConsumer.removeListener('start', startListener) |
| 522 | touchConsumer.removeListener('error', errorListener) |
| 523 | }) |
| 524 | } |
| 525 | |
| 526 | return startConsumer() |
| 527 | .then(function(touchConsumer) { |