1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.robot.com.sun.glass.ui.monocle.input.devices;
  27 
  28 import test.robot.com.sun.glass.ui.monocle.TestApplication;
  29 import test.robot.com.sun.glass.ui.monocle.UInput;
  30 import org.junit.Assume;
  31 
  32 /**
  33  * SingleTouchDevice2 sends ABS_X and ABS_Y events. It uses BTN_TOUCH to notify
  34  * presses and releases. It does not send ABS_X or ABS_Y if that coordinate has
  35  * not changed.
  36  */
  37 public class SingleTouchDevice2 extends TestTouchDevice {
  38 
  39     public SingleTouchDevice2() {
  40         super(1);
  41     }
  42 
  43     @Override
  44     public void create() {
  45         Assume.assumeTrue(TestApplication.isMonocle());
  46         ui = new UInput();
  47         ui.processLine("OPEN");
  48         ui.processLine("EVBIT EV_SYN");
  49         ui.processLine("EVBIT EV_KEY");
  50         ui.processLine("KEYBIT BTN_TOUCH");
  51         ui.processLine("EVBIT EV_ABS");
  52         ui.processLine("ABSBIT ABS_X");
  53         ui.processLine("ABSBIT ABS_Y");
  54         ui.processLine("ABSMIN ABS_X 0");
  55         ui.processLine("ABSMAX ABS_X 4095");
  56         ui.processLine("ABSMIN ABS_Y 0");
  57         ui.processLine("ABSMAX ABS_Y 4095");
  58         ui.processLine("PROPBIT INPUT_PROP_POINTER");
  59         ui.processLine("PROPBIT INPUT_PROP_DIRECT");
  60         ui.processLine("PROPERTY ID_INPUT_TOUCHSCREEN 1");
  61         ui.processLine("CREATE");
  62         setAbsScale(4096, 4096);
  63     }
  64 
  65     @Override
  66     public int addPoint(double x, double y) {
  67         int p = super.addPoint(x, y);
  68         ui.processLine("EV_KEY BTN_TOUCH 1");
  69         ui.processLine("EV_ABS ABS_X " + transformedXs[p]);
  70         ui.processLine("EV_ABS ABS_Y " + transformedYs[p]);
  71         return p;
  72     }
  73 
  74     @Override
  75     public void removePoint(int p) {
  76         super.removePoint(p);
  77         ui.processLine("EV_KEY BTN_TOUCH 0");
  78     }
  79 
  80     @Override
  81     public void setPoint(int p, double x, double y) {
  82         int oldX = transformedXs[p];
  83         int oldY = transformedYs[p];
  84         super.setPoint(p, x, y);
  85         // if neither X nor Y have changed, we send X
  86         if (oldX != transformedXs[p] || oldY == transformedYs[p]) {
  87             ui.processLine("EV_ABS ABS_X " + transformedXs[p]);
  88         }
  89         if (oldY != transformedYs[p]) {
  90             ui.processLine("EV_ABS ABS_Y " + transformedYs[p]);
  91         }
  92     }
  93 
  94     @Override
  95     public void resendStateAndSync() {
  96         if (points[0]) {
  97             ui.processLine("EV_ABS ABS_X " + transformedXs[0]);
  98             ui.processLine("EV_ABS ABS_Y " + transformedYs[0]);
  99         }
 100         sync();
 101     }
 102 
 103 }