1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""Define constants for firmware touch device MTB tests.""" 6 7 8import sys 9 10sys.path.append('../../bin/input') 11from linux_input import (KEY_D, KEY_M, KEY_X, KEY_Y, KEY_ENTER, KEY_SPACE, 12 KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT) 13 14 15class _ConstantError(AttributeError): 16 """A constant error exception.""" 17 pass 18 19 20class _Constant(object): 21 """This is a constant base class to ensure no rebinding of constants.""" 22 def __setattr__(self, name, value): 23 """Check the attribute assignment. No rebinding is allowed.""" 24 if name in self.__dict__: 25 raise _ConstantError, "Cannot rebind the constant: %s" % name 26 self.__dict__[name] = value 27 28 29"""Define constants classes in alphabetic order below.""" 30 31 32class _Axis(_Constant): 33 """Constants about two axes.""" 34 pass 35AXIS = _Axis() 36AXIS.X = 'x' 37AXIS.Y = 'y' 38AXIS.LIST = [AXIS.X, AXIS.Y] 39 40 41class _DeviceType(_Constant): 42 """Constants about device types.""" 43DEV = _DeviceType() 44DEV.TOUCHPAD = 'touchpad' 45DEV.TOUCHSCREEN = 'touchscreen' 46DEV.DEVICE_TYPE_LIST = list(DEV.__dict__.values()) 47 48 49class _Fuzzy_MF(_Constant): 50 """Constants about fuzzy membership functions.""" 51 pass 52MF = _Fuzzy_MF() 53MF.PI_FUNCTION = 'Pi_Function' 54MF.S_FUNCTION = 'S_Function' 55MF.SINGLETON_FUNCTION = 'Singleton_Function' 56MF.TRAPEZ_FUNCTION = 'Trapez_Function' 57MF.TRIANGLE_FUNCTION = 'Triangle_Function' 58MF.Z_FUNCTION = 'Z_Function' 59 60 61class _GestureVariation(_Constant): 62 """Constants about gesture variations.""" 63 pass 64GV = _GestureVariation() 65# constants about directions 66GV.HORIZONTAL = 'horizontal' 67GV.VERTICAL = 'vertical' 68GV.DIAGONAL = 'diagonal' 69GV.LR = 'left_to_right' 70GV.RL = 'right_to_left' 71GV.TB = 'top_to_bottom' 72GV.BT = 'bottom_to_top' 73GV.CL = 'center_to_left' 74GV.CR = 'center_to_right' 75GV.CT = 'center_to_top' 76GV.CB = 'center_to_bottom' 77GV.CUR = 'center_to_upper_right' 78GV.CUL = 'center_to_upper_left' 79GV.CLR = 'center_to_lower_right' 80GV.CLL = 'center_to_lower_left' 81GV.BLTR = 'bottom_left_to_top_right' 82GV.BRTL = 'bottom_right_to_top_left' 83GV.TRBL = 'top_right_to_bottom_left' 84GV.TLBR = 'top_left_to_bottom_right' 85GV.HORIZONTAL_DIRECTIONS = [GV.HORIZONTAL, GV.LR, GV.RL, GV.CL, GV.CR] 86GV.VERTICAL_DIRECTIONS = [GV.VERTICAL, GV.TB, GV.BT, GV.CT, GV.CB] 87GV.DIAGONAL_DIRECTIONS = [GV.DIAGONAL, GV.BLTR, GV.BRTL, GV.TRBL, GV.TLBR, 88 GV.CUR, GV.CUL, GV.CLR, GV.CLL] 89GV.GESTURE_DIRECTIONS = (GV.HORIZONTAL_DIRECTIONS + GV.VERTICAL_DIRECTIONS + 90 GV.DIAGONAL_DIRECTIONS) 91# constants about locations 92GV.TL = 'top_left' 93GV.TR = 'top_right' 94GV.BL = 'bottom_left' 95GV.BR = 'bottom_right' 96GV.TS = 'top_side' 97GV.BS = 'bottom_side' 98GV.LS = 'left_side' 99GV.RS = 'right_side' 100GV.CENTER = 'center' 101GV.AROUND = 'around' 102GV.GESTURE_LOCATIONS = [GV.TL, GV.TR, GV.BL, GV.BR, GV.TS, GV.BS, GV.LS, GV.RS, 103 GV.CENTER, GV.AROUND] 104# constants about pinch to zoom 105GV.ZOOM_IN = 'zoom_in' 106GV.ZOOM_OUT = 'zoom_out' 107# constants about speed 108GV.SLOW = 'slow' 109GV.NORMAL = 'normal' 110GV.FAST = 'fast' 111GV.FULL_SPEED = 'full_speed' 112GV.GESTURE_SPEED = [GV.SLOW, GV.NORMAL, GV.FAST, GV.FULL_SPEED] 113# constants about noise frequency 114GV.LOW_FREQUENCY = 'low_frequency' 115GV.MED_FREQUENCY = 'med_frequency' 116GV.HIGH_FREQUENCY = 'high_frequency' 117# constants used in the extended frequency sweep. 118# Sweep from 0Hz to 1MHz at an interval of 400Hz for 2500 tests. 119GV.EXTENDED_FREQUENCIES = ['%dHz' % x for x in range(0, 1000000, 400)] 120GV.NOISE_FREQUENCY = [GV.LOW_FREQUENCY, GV.MED_FREQUENCY, GV.HIGH_FREQUENCY] + \ 121 GV.EXTENDED_FREQUENCIES 122# constants about noise waveform 123GV.SQUARE_WAVE = 'square_wave' 124GV.SINE_WAVE = 'sine_wave' 125GV.NOISE_WAVEFORM = [GV.SQUARE_WAVE, GV.SINE_WAVE] 126# constants about noise amplitude 127GV.MAX_AMPLITUDE = 'max_amplitude' 128GV.HALF_AMPLITUDE = 'half_amplitude' 129GV.NOISE_AMPLITUDE = [GV.HALF_AMPLITUDE, GV.MAX_AMPLITUDE] 130# constants about metal finger sizes 131GV.SIZE = 'size' 132size_str = lambda i: GV.SIZE + str(i) 133GV.SIZE0 = size_str(0) 134GV.SIZE1 = size_str(1) 135GV.SIZE2 = size_str(2) 136GV.SIZE3 = size_str(3) 137GV.SIZE4 = size_str(4) 138GV.SIZE5 = size_str(5) 139GV.SIZE6 = size_str(6) 140GV.NUMBER_OF_SIZES = 7 141GV.SIZE_LIST = [size_str(i) for i in range(GV.NUMBER_OF_SIZES)] 142 143 144class _Mode(_Constant): 145 """Constants about gesture playing mode.""" 146 pass 147MODE = _Mode() 148MODE.CALIBRATION = 'calibration' 149MODE.COMPLETE = 'complete' 150MODE.MANUAL = 'manual' 151MODE.NOISE = 'noise' 152MODE.QUICKSTEP = 'quickstep' 153MODE.REPLAY = 'replay' 154MODE.ROBOT = 'robot' 155MODE.ROBOT_SIM = 'robot_sim' 156# GESTURE_PLAY_MODE is a list of all attributes above 157MODE.GESTURE_PLAY_MODE = list(MODE.__dict__.values()) 158 159 160class _MTB(_Constant): 161 """Constants about MTB event format and MTB related constants.""" 162 pass 163MTB = _MTB() 164MTB.EV_TIME = 'EV_TIME' 165MTB.EV_TYPE = 'EV_TYPE' 166MTB.EV_CODE = 'EV_CODE' 167MTB.EV_VALUE = 'EV_VALUE' 168MTB.SYN_REPORT = 'SYN_REPORT' 169MTB.SLOT = 'slot' 170MTB.POINTS = 'points' 171 172 173class _Options(_Constant): 174 """Constants about command line options.""" 175 pass 176OPTIONS = _Options() 177OPTIONS.DEBUG = 'debug' 178OPTIONS.DEVICE = 'system_device' 179OPTIONS.DIR = 'directory' 180OPTIONS.FNGENERATOR = 'function_generator' 181OPTIONS.HELP = 'help' 182OPTIONS.INDIVIDUAL = 'individual' 183OPTIONS.ITERATIONS = 'iterations' 184OPTIONS.METRICS = 'show_metrics' 185OPTIONS.MODE = 'mode' 186OPTIONS.REPLAY = 'replay' 187OPTIONS.RESUME = 'resume' 188OPTIONS.SCORES = 'scores' 189OPTIONS.SIMPLIFIED = 'simplified' 190OPTIONS.SKIP_HTML = 'skip_html' 191OPTIONS.TOUCHSCREEN = 'touchscreen' 192OPTIONS.UPLOAD = 'upload' 193 194 195class _Platform(_Constant): 196 """Constants about chromebook platforms.""" 197 pass 198PLATFORM = _Platform() 199PLATFORM.ALEX = 'alex' 200PLATFORM.LUMPY = 'lumpy' 201PLATFORM.LINK = 'link' 202PLATFORM.LIST = [PLATFORM.ALEX, PLATFORM.LUMPY, PLATFORM.LINK] 203 204 205class _RobotControl(_Constant): 206 """Constants about robot control.""" 207 pass 208RC = _RobotControl() 209RC.PAUSE_TYPE = 'pause_type' 210RC.PROMPT = 'finger_control_prompt' 211# Finger interaction per gesture 212# e.g., the TWO_FINGER_TRACKING gesture requires installing an extra finger 213# once for all variations in the same gesture. 214RC.PER_GESTURE = 'per_gesture' 215# Finger interaction per variation 216# e.g., the FINGER_CROSSING gesture requires putting down and lifting up 217# a metal finger repeatedly per variation. 218RC.PER_VARIATION = 'per_variation' 219 220 221class _TFK(_Constant): 222 """The Test Flow Keypress (TFK) codes for test flow""" 223 pass 224TFK = _TFK() 225TFK.DISCARD = KEY_D 226TFK.EXIT = KEY_X 227TFK.MORE = KEY_M 228TFK.SAVE = KEY_SPACE 229TFK.SAVE2 = KEY_ENTER 230TFK.YES = KEY_Y 231TFK.UP = KEY_UP 232TFK.DOWN = KEY_DOWN 233TFK.LEFT = KEY_LEFT 234TFK.RIGHT = KEY_RIGHT 235TFK.ARROW_KEY_LIST = [TFK.UP, TFK.DOWN, TFK.LEFT, TFK.RIGHT] 236 237 238class _UNIT(_Constant): 239 """Constants about units.""" 240 pass 241UNIT = _UNIT() 242UNIT.PIXEL = 'px' 243UNIT.MM = 'mm' 244 245 246class _Validator(_Constant): 247 """Constants about validator.""" 248 pass 249VAL = _Validator() 250VAL.BEGIN = 'Begin' 251VAL.MIDDLE = 'Middle' 252VAL.END = 'End' 253VAL.BOTH_ENDS = 'BothEnds' 254VAL.WHOLE = 'Whole' 255# SEGMENT_LIST is a list of all attributes above 256VAL.SEGMENT_LIST = list(VAL.__dict__.values()) 257