...

Source file src/edge-infra.dev/pkg/sds/display/k8s/apis/v2/defaults.go

Documentation: edge-infra.dev/pkg/sds/display/k8s/apis/v2

     1  package v2
     2  
     3  import (
     4  	"regexp"
     5  )
     6  
     7  var (
     8  	dpmsDisabled = false
     9  	zeroSeconds  = 0
    10  )
    11  
    12  // Configures the default display configuration to be passed
    13  // into displayConfig.GenerateDefaultDisplayConfig(DefaultConfig,inputDevices).
    14  type DefaultConfig struct {
    15  	// The default display configuration that will be applied
    16  	// to each display.
    17  	Display Display
    18  	// Mapping of pre-defined display configurations for displays
    19  	// we know need additional configuration. Most often this
    20  	// consists of known input device mappings.
    21  	KnownDisplays map[MPID]KnownDisplayDefaults
    22  	// The default DPMS configuration.
    23  	DPMS *DPMS
    24  }
    25  
    26  type KnownDisplayDefaults struct {
    27  	InputDevicePatterns []string
    28  }
    29  
    30  // The default display configuration:
    31  //   - All displays have normal orientation.
    32  //   - Known display input device mapping regex strings are configured (known device details listed in comments).
    33  //   - DPMS is disabled.
    34  var Defaults = DefaultConfig{
    35  	Display: Display{
    36  		Orientation: &NormalOrientation,
    37  	},
    38  	KnownDisplays: map[MPID]KnownDisplayDefaults{
    39  		"ACR-2199": {
    40  			// Weida Hi-Tech                CoolTouchR System
    41  			// Weida Hi-Tech                CoolTouchR System            Mouse
    42  			InputDevicePatterns: []string{
    43  				"Weida Hi-Tech\\s+CoolTouchR System\\s+.*",
    44  			},
    45  		},
    46  		"ELO-4098": {
    47  			// Elo Touch Solutions Elo Touch Solutions Pcap USB Interface
    48  			InputDevicePatterns: []string{
    49  				"Elo Touch Solutions Elo Touch Solutions Pcap USB Interface",
    50  			},
    51  		},
    52  		"ELO-5705": {
    53  			// Atmel Atmel maXTouch Digitizer
    54  			// Elo TouchSystems, Inc. Elo TouchSystems 2700 IntelliTouch(r) USB
    55  			InputDevicePatterns: []string{
    56  				"Atmel Atmel maXTouch Digitizer",
    57  				"Elo TouchSystems, Inc\\. Elo TouchSystems 2700.*",
    58  			},
    59  		},
    60  		"ELO-5911": {
    61  			// Elo TouchSystems, Inc. Elo TouchSystems 2700 IntelliTouch(r) USB Touchmonitor Interface
    62  			InputDevicePatterns: []string{
    63  				"Elo TouchSystems, Inc\\. Elo TouchSystems 2700.*",
    64  			},
    65  		},
    66  		"ELO-8816": {
    67  			// Elo Touch                     2270L pCAP HID
    68  			// Elo Touch                     2270L pCAP HID           Mouse
    69  			InputDevicePatterns: []string{
    70  				"Elo Touch\\s+2270L pCAP HID\\s+.*",
    71  			},
    72  		},
    73  		"NCR-22800": {
    74  			// eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00
    75  			// eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00 UNKNOWN
    76  			InputDevicePatterns: []string{
    77  				"eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
    78  			},
    79  		},
    80  		"NCR-22805": {
    81  			// eGalax Inc. eGalaxTouch EXC3188-0556-04.00.00
    82  			InputDevicePatterns: []string{
    83  				"eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
    84  			},
    85  		},
    86  		"NCR-22888": {
    87  			// eGalax Inc. eGalaxTouch EXC3189-2506-09.00.00.00
    88  			// eGalax Inc. eGalaxTouch EXC3189-2506-09.00.00.00 Mouse
    89  			// Advanced Silicon S.A. CoolTouch® System
    90  			InputDevicePatterns: []string{
    91  				"eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
    92  				"Advanced Silicon S\\.A\\. CoolTouch® System",
    93  			},
    94  		},
    95  		"NCR-22917": {
    96  			// eGalax Inc. eGalaxTouch EXC3188-0556-04.00.00
    97  			InputDevicePatterns: []string{
    98  				"eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
    99  			},
   100  		},
   101  		// CX7ii
   102  		"NCR-30578": {
   103  			// eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146
   104  			// eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse
   105  			// eGalax Inc. eGalaxTouch P81X84 A0U4 v00_T3 k4.26.145
   106  			// eGalax Inc. eGalaxTouch P81X84 A0U4 v00_T3 k4.26.145 Mouse
   107  			// eGalax Inc. eGalaxTouch P81X84 A0RF v00_T1 k4.18.204
   108  			// eGalax Inc. eGalaxTouch P81X84 A0RF v00_T1 k4.18.204 Mouse
   109  			InputDevicePatterns: []string{
   110  				"eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*",
   111  			},
   112  		},
   113  		"TGC-18464": {
   114  			// Elo TouchSystems Inc. Elo TouchSystems CarrollTouch 4500U
   115  			InputDevicePatterns: []string{
   116  				"Elo TouchSystems Inc\\. Elo TouchSystems CarrollTouch.*",
   117  			},
   118  		},
   119  		"VSC-23866": {
   120  			// iSolution multitouch
   121  			// iSolution multitouch Mouse
   122  			InputDevicePatterns: []string{
   123  				"iSolution multitouch.*",
   124  			},
   125  		},
   126  		"WNX-22": {
   127  			// Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse
   128  			InputDevicePatterns: []string{
   129  				"Beijing IRTOUCH SYSTEMS Co\\.,LtD IRTOUCH InfraRed TouchScreen.*",
   130  			},
   131  		},
   132  		"WNX-30022": {
   133  			// eGalax Inc. eGalaxTouch P80H84 0716 v00T3 k03_216
   134  			// eGalax Inc. eGalaxTouch P80H84 0716 v00T3 k03_216 Mouse
   135  			InputDevicePatterns: []string{
   136  				"eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*",
   137  			},
   138  		},
   139  		"WNX-30028": {
   140  			// eGalax Inc. eGalaxTouch P80H84 0789 v01 k4.10.139
   141  			// eGalax Inc. eGalaxTouch P80H84 0789 v01 k4.10.139 UNKNOWN
   142  			InputDevicePatterns: []string{
   143  				"eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*",
   144  			},
   145  		},
   146  		"WNX-32": {
   147  			// Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse
   148  			InputDevicePatterns: []string{
   149  				"Beijing IRTOUCH SYSTEMS Co\\.,LtD IRTOUCH InfraRed TouchScreen.*",
   150  			},
   151  		},
   152  	},
   153  	DPMS: &DPMS{
   154  		Enabled:     &dpmsDisabled,
   155  		BlankTime:   &zeroSeconds,
   156  		StandbyTime: &zeroSeconds,
   157  		SuspendTime: &zeroSeconds,
   158  		OffTime:     &zeroSeconds,
   159  	},
   160  }
   161  
   162  // Applies the default configuration to the display config.
   163  //
   164  // Merges the default display with each of the displays in the display config.
   165  //
   166  // For any display where a display with matching MPID exists in the default
   167  // known displays, their configurations are merged together.
   168  //
   169  // Sets the first display in the layout as the primary display. If there is
   170  // no layout, the first display will be primary.
   171  //
   172  // DPMS is overwritten with the default DPMS configuration.
   173  func (a *DisplayConfig) GenerateDefaultDisplayConfig(defaults DefaultConfig, inputDevices []InputDeviceName) (*DisplayConfig, error) {
   174  	result := a.DeepCopy()
   175  
   176  	if err := applyDefaultDisplay(result, defaults.Display); err != nil {
   177  		return nil, err
   178  	}
   179  
   180  	applyKnownDisplays(result, inputDevices, defaults)
   181  
   182  	applyDefaultPrimary(result)
   183  
   184  	result.DPMS = defaults.DPMS
   185  
   186  	return result, nil
   187  }
   188  
   189  func applyDefaultDisplay(displayConfig *DisplayConfig, defaultDisplay Display) error {
   190  	for dp, display := range displayConfig.Displays {
   191  		display, err := display.Merge(defaultDisplay)
   192  		if err != nil {
   193  			return err
   194  		}
   195  		displayConfig.Displays[dp] = *display
   196  	}
   197  	return nil
   198  }
   199  
   200  func applyKnownDisplays(displayConfig *DisplayConfig, inputDevices []InputDeviceName, defaults DefaultConfig) {
   201  	for mpid, defaultDisplay := range defaults.KnownDisplays {
   202  		regexps := compileRegexStrings(defaultDisplay.InputDevicePatterns)
   203  		for idx, display := range displayConfig.Displays {
   204  			if display.MPID != nil && *display.MPID == mpid {
   205  				display.InputDeviceMappings = matchInputsToDefaultDevicesRegex(inputDevices, regexps)
   206  				displayConfig.Displays[idx] = display
   207  			}
   208  		}
   209  	}
   210  }
   211  
   212  func compileRegexStrings(regexStrings []string) []*regexp.Regexp {
   213  	regexps := []*regexp.Regexp{}
   214  	for _, pattern := range regexStrings {
   215  		r, _ := regexp.Compile(pattern)
   216  		regexps = append(regexps, r)
   217  	}
   218  	return regexps
   219  }
   220  
   221  func matchInputsToDefaultDevicesRegex(inputDevices []InputDeviceName, defaultDevicesRegexps []*regexp.Regexp) []InputDeviceName {
   222  	matchedDevices := []InputDeviceName{}
   223  	for _, r := range defaultDevicesRegexps {
   224  		for _, inputDevice := range inputDevices {
   225  			if r.MatchString(string(inputDevice)) {
   226  				matchedDevices = append(matchedDevices, inputDevice)
   227  			}
   228  		}
   229  	}
   230  	return matchedDevices
   231  }
   232  
   233  func applyDefaultPrimary(displayConfig *DisplayConfig) {
   234  	if len(displayConfig.Displays) == 0 {
   235  		return
   236  	}
   237  
   238  	primary := displayConfig.Displays[0].DisplayPort
   239  	if len(displayConfig.Layout) > 0 {
   240  		primary = displayConfig.Layout[0]
   241  	}
   242  
   243  	displayConfig.Displays = setPrimaryDisplay(primary, displayConfig.Displays)
   244  }
   245  
   246  func setPrimaryDisplay(primary DisplayPort, displays Displays) Displays {
   247  	for idx, display := range displays {
   248  		display.SetPrimary(display.DisplayPort == primary)
   249  		displays[idx] = display
   250  	}
   251  	return displays
   252  }
   253  

View as plain text