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 import java.util.HashMap; 33 import java.util.Map; 34 35 /** 36 * Dell P2714 touch screen monitor. 37 * 38 * DellP2714TDevice sends ABS_MT_POSITION_X and ABS_MT_POSITION_Y 39 * events per each touch-point. 40 * ABS_X & ABS_Y events are being sent only once per touch-event 41 * and are equal to ABS_MT_POSITION_X and ABS_MT_POSITION_Y of first touch-point. 42 * It uses BTN_TOUCH to notify presses and releases. 43 * It doesn't send "EV_SYN SYN_MT_REPORT" events, and also no events on coordinate 44 * that has not changed. It sends tracking IDs for touch points and uses slots. 45 */ 46 public class DellP2714TDevice extends TestTouchDevice { 47 48 private int currentSlot = 0; 49 private Map<Integer, Integer> slotsToPoints = new HashMap<>(); 50 private Map<Integer, Integer> pointsToSlots = new HashMap<>(); 51 private boolean BTN_TOUCH_1_sent = false; 52 private int firstPointAbsX = 0; 53 private int firstPointAbsY = 0; 54 private int firstTouchPointId = 0; 55 private boolean absXUpdated = false; 56 private boolean absYUpdated = false; 57 58 public DellP2714TDevice() { 59 super(10); 60 } 61 62 @Override 63 public void create() { 64 Assume.assumeTrue(TestApplication.isMonocle()); 65 ui = new UInput(); 66 ui.processLine("OPEN"); 67 ui.processLine("EVBIT EV_SYN"); 68 ui.processLine("EVBIT EV_KEY"); 69 ui.processLine("KEYBIT BTN_TOUCH"); 70 ui.processLine("EVBIT EV_ABS"); 71 ui.processLine("ABSBIT ABS_X"); 72 ui.processLine("ABSBIT ABS_Y"); 73 ui.processLine("ABSMIN ABS_X 0"); 74 ui.processLine("ABSMAX ABS_X 32767"); 75 ui.processLine("ABSMIN ABS_Y 0"); 76 ui.processLine("ABSMAX ABS_Y 32767"); 77 ui.processLine("ABSBIT ABS_MT_SLOT"); 78 ui.processLine("ABSMIN ABS_MT_SLOT 0"); 79 ui.processLine("ABSMAX ABS_MT_SLOT 9"); 80 ui.processLine("ABSBIT ABS_MT_POSITION_X"); 81 ui.processLine("ABSBIT ABS_MT_POSITION_Y"); 82 ui.processLine("ABSMIN ABS_MT_POSITION_X 0"); 83 ui.processLine("ABSMAX ABS_MT_POSITION_X 32767"); 84 ui.processLine("ABSMIN ABS_MT_POSITION_Y 0"); 85 ui.processLine("ABSMAX ABS_MT_POSITION_Y 32767"); 86 ui.processLine("ABSBIT ABS_MT_TRACKING_ID"); 87 ui.processLine("ABSMIN ABS_MT_TRACKING_ID 0"); 88 ui.processLine("ABSMAX ABS_MT_TRACKING_ID 65535"); 89 ui.processLine("PROPBIT INPUT_PROP_DIRECT"); 90 ui.processLine("PROPERTY ID_INPUT_TOUCHSCREEN 1"); 91 ui.processLine("BUS 0x3"); 92 ui.processLine("VENDOR 0x2149"); 93 ui.processLine("PRODUCT 0x270b"); 94 ui.processLine("VERSION 0x110"); 95 ui.processLine("CREATE"); 96 setAbsScale(32768, 32768); 97 } 98 99 @Override 100 public int addPoint(double x, double y) { 101 int p = super.addPoint(x, y); 102 int slot = -1; 103 for (int i = 0; i < points.length; i++) { 104 if (!slotsToPoints.containsKey(i)) { 105 slot = i; 106 break; 107 } 108 } 109 if (slot == -1) { 110 throw new IllegalStateException("No free slot"); 111 } 112 if (currentSlot != slot) { 113 ui.processLine("EV_ABS ABS_MT_SLOT " + slot); 114 currentSlot = slot; 115 } 116 slotsToPoints.put(slot, p); 117 pointsToSlots.put(p, slot); 118 ui.processLine("EV_ABS ABS_MT_TRACKING_ID " + getID(p)); 119 ui.processLine("EV_ABS ABS_MT_POSITION_X " + transformedXs[p]); 120 ui.processLine("EV_ABS ABS_MT_POSITION_Y " + transformedYs[p]); 121 if (pressedPoints == 1) { 122 firstPointAbsX = transformedXs[p]; 123 firstPointAbsY = transformedYs[p]; 124 firstTouchPointId = getID(p); 125 absXUpdated = true; 126 absYUpdated = true; 127 } 128 return p; 129 } 130 131 private int selectSlotForPoint(int p) { 132 int slot = pointsToSlots.get(p); 133 if (slot != currentSlot) { 134 ui.processLine("EV_ABS ABS_MT_SLOT " + slot); 135 currentSlot = slot; 136 } 137 return currentSlot; 138 } 139 140 @Override 141 public void removePoint(int p) { 142 super.removePoint(p); 143 int slot = selectSlotForPoint(p); 144 pointsToSlots.remove(p); 145 slotsToPoints.remove(slot); 146 ui.processLine("EV_ABS ABS_MT_TRACKING_ID -1"); 147 if (pressedPoints == 0) { 148 ui.processLine("EV_KEY BTN_TOUCH 0"); 149 BTN_TOUCH_1_sent = false; 150 absXUpdated = false; 151 absYUpdated = false; 152 } 153 } 154 155 @Override 156 public void setPoint(int p, double x, double y) { 157 int oldX = transformedXs[p]; 158 int oldY = transformedYs[p]; 159 super.setPoint(p, x, y); 160 if (oldX != transformedXs[p]) { 161 selectSlotForPoint(p); 162 ui.processLine("EV_ABS ABS_MT_POSITION_X " + transformedXs[p]); 163 if (firstTouchPointId == getID(p)) { 164 firstPointAbsX = transformedXs[p]; 165 absXUpdated = true; 166 } 167 } 168 if (oldY != transformedYs[p]) { 169 selectSlotForPoint(p); 170 ui.processLine("EV_ABS ABS_MT_POSITION_Y " + transformedYs[p]); 171 if (firstTouchPointId == getID(p)) { 172 firstPointAbsY = transformedYs[p]; 173 absYUpdated = true; 174 } 175 } 176 } 177 178 @Override 179 public void sync() { 180 if ((pressedPoints > 0) && (!BTN_TOUCH_1_sent)) { 181 ui.processLine("EV_KEY BTN_TOUCH 1"); 182 BTN_TOUCH_1_sent = true; 183 } 184 if (absXUpdated) { 185 ui.processLine("EV_ABS ABS_X " + firstPointAbsX); 186 absXUpdated = false; 187 } 188 if (absYUpdated) { 189 ui.processLine("EV_ABS ABS_Y " + firstPointAbsY); 190 absYUpdated = false; 191 } 192 super.sync(); 193 } 194 }