...

Source file src/edge-infra.dev/pkg/sds/display/k8s/apis/v1/displayconfig.go

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

     1  package v1
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"edge-infra.dev/pkg/sds/lib/set"
     7  )
     8  
     9  // +kubebuilder:validation:Pattern=`^[A-Z]{3}-\d{1,5}$`
    10  //
    11  // Manufacturer and Product-Code ID, a unique identifier for
    12  // the display, i.e. "<manufacturer-ID>-<product-code>".
    13  type MPID string
    14  
    15  func (mpid *MPID) String() string {
    16  	if mpid == nil {
    17  		return ""
    18  	}
    19  	return string(*mpid)
    20  }
    21  
    22  // DisplayConfig defines the configuration for displays.
    23  type DisplayConfig struct {
    24  	// Maps monitor MPIDs to Display configurations.
    25  	Displays `json:"displays,omitempty"`
    26  	// DPMS configuration
    27  	DPMS *DPMS `json:"dpms,omitempty"`
    28  	// Layout of the displays as slice, ordered left to right.
    29  	Layout `json:"layout,omitempty"`
    30  }
    31  
    32  func (displayConfig *DisplayConfig) MPIDs() []MPID {
    33  	if displayConfig == nil {
    34  		return []MPID{}
    35  	}
    36  	mpids := set.OrderedFromMap(displayConfig.Displays)
    37  	mpids.Add(displayConfig.Layout...)
    38  	return mpids.ToSlice()
    39  }
    40  
    41  type Displays map[MPID]Display
    42  
    43  // Returns the display's MPIDs in sorted order.
    44  func (displays Displays) MPIDs() []MPID {
    45  	if displays == nil {
    46  		return []MPID{}
    47  	}
    48  	mpids := set.OrderedFromMap(displays)
    49  	return mpids.ToSlice()
    50  }
    51  
    52  // Display configures a display's monitor and input devices.
    53  type Display struct {
    54  	// Primary indicates whether this is the primary display.
    55  	*Primary `json:"primary,omitempty"`
    56  	// Orientation of the display, e.g "left" or "inverted".
    57  	Orientation *Orientation `json:"orientation,omitempty"`
    58  	// Resolution is the current resolution of the display.
    59  	*Resolution `json:"resolution,omitempty"`
    60  	// SupportedResolutions are the valid resolutions the
    61  	// display can be configured to use.
    62  	//
    63  	// It is NOT valid to configure this field in the NodeDisplayConfig
    64  	// spec. The resolution of the display can be configured
    65  	// via the Resolution field.
    66  	SupportedResolutions []Resolution `json:"supportedResolutions,omitempty"`
    67  	// InputDeviceMappings are the devices the display maps to.
    68  	InputDeviceMappings []InputDeviceName `json:"inputDeviceMappings,omitempty"`
    69  }
    70  
    71  // Primary indicates whether a display is the primary display.
    72  type Primary bool
    73  
    74  func (display *Display) IsPrimary() bool {
    75  	if display.Primary == nil {
    76  		return false
    77  	}
    78  	return bool(*display.Primary)
    79  }
    80  
    81  func (display *Display) SetPrimary(primary bool) {
    82  	display.Primary = (*Primary)(&primary)
    83  }
    84  
    85  // +kubebuilder:validation:Enum=normal;left;right;inverted
    86  //
    87  // Orientation is the displays orientation, e.g "normal", left", "right" or "inverted".
    88  type Orientation string
    89  
    90  var (
    91  	NormalOrientation   Orientation = "normal"
    92  	LeftOrientation     Orientation = "left"
    93  	RightOrientation    Orientation = "right"
    94  	InvertedOrientation Orientation = "inverted"
    95  )
    96  
    97  func (o *Orientation) String() string {
    98  	if o == nil {
    99  		return ""
   100  	}
   101  	return string(*o)
   102  }
   103  
   104  // Resolution defines the resolution of a display.
   105  type Resolution struct {
   106  	// +kubebuilder:validation:Minimum=0
   107  	//
   108  	// Width of the display in pixels.
   109  	Width int `json:"width"`
   110  	// +kubebuilder:validation:Minimum=0
   111  	//
   112  	// Height of the display in pixels.
   113  	Height int `json:"height"`
   114  }
   115  
   116  func (res *Resolution) String() string {
   117  	if res == nil {
   118  		return ""
   119  	}
   120  	return fmt.Sprintf("%dx%d", res.Width, res.Height)
   121  }
   122  
   123  // InputDeviceName is the name of an input device
   124  type InputDeviceName string
   125  
   126  func (name *InputDeviceName) String() string {
   127  	if name == nil {
   128  		return ""
   129  	}
   130  	return string(*name)
   131  }
   132  
   133  // DPMS describes the DPMS configuration for a display.
   134  type DPMS struct {
   135  	// Enabled indicates whether DPMS is enabled for the node.
   136  	Enabled *bool `json:"enabled,omitempty"`
   137  	// +kubebuilder:validation:Minimum=0
   138  	//
   139  	// BlankTime configures the number of seconds of inactivity
   140  	// before reaching the blank phase of the screen saver.
   141  	BlankTime *int `json:"blankTime,omitempty"`
   142  	// +kubebuilder:validation:Minimum=0
   143  	//
   144  	// StandbyTime configures the number of seconds of inactivity
   145  	// before reaching the standby phase of the DPMS mode.
   146  	StandbyTime *int `json:"standByTime,omitempty"`
   147  	// +kubebuilder:validation:Minimum=0
   148  	//
   149  	// SuspendTime configures the number of seconds of inactivity
   150  	// before reaching the suspend phase of the DPMS mode.
   151  	SuspendTime *int `json:"suspendTime,omitempty"`
   152  	// +kubebuilder:validation:Minimum=0
   153  	//
   154  	// OffTime configures the number of seconds of inactivity
   155  	// before reaching the off phase of the DPMS mode.
   156  	OffTime *int `json:"offTime,omitempty"`
   157  }
   158  
   159  // Layout describes the physical position of displays as their MPIDs
   160  // ordered left to right.
   161  type Layout []MPID
   162  

View as plain text