This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
112 lines (96 loc) · 3.71 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* eslint-disable no-unused-vars */
import {
displayGetVcpFeature, displaySetVcpFeature, displaySetTableVcpFeature, displayManagerGetByIndex, displayManagerList
} from './ddc_rs.node'
import {
DisplayData, VCPValue, Query
} from './types'
export {
VCPValue, Query, DisplayData, Continuous, NonContinuous, Table, VCPFeatures, QueryType, VCPFeatureCode, VCPValueType
} from './types'
export class Display {
constructor (data: number | DisplayData) {
if (Number.isInteger(data) && !Number.isNaN(data)) {
const index = data as number
data = displayManagerGetByIndex(index)
}
const effectiveData = data as DisplayData
this.index = effectiveData.index
this.backend = effectiveData.backend
if (Object.hasOwn(effectiveData, 'edidData')) this.edidData = effectiveData.edidData
if (Object.hasOwn(effectiveData, 'version')) this.version = effectiveData.version
if (Object.hasOwn(effectiveData, 'mccsVersion')) this.mccsVersion = effectiveData.mccsVersion
this.displayId = effectiveData.displayId
if (Object.hasOwn(effectiveData, 'serial')) this.serial = effectiveData.serial
if (Object.hasOwn(effectiveData, 'serialNumber')) this.serialNumber = effectiveData.serialNumber
if (Object.hasOwn(effectiveData, 'modelId')) this.modelId = effectiveData.modelId
if (Object.hasOwn(effectiveData, 'modelName')) this.modelName = effectiveData.modelName
if (Object.hasOwn(effectiveData, 'manufacturerId')) this.manufacturerId = effectiveData.manufacturerId
if (Object.hasOwn(effectiveData, 'manufactureYear')) this.manufactureYear = effectiveData.manufactureYear
if (Object.hasOwn(effectiveData, 'manufactureWeek')) this.manufactureWeek = effectiveData.manufactureWeek
if (Object.hasOwn(effectiveData, 'capabilities')) this.capabilities = effectiveData.capabilities
}
getVcpFeature (featureCode: number): VCPValue {
return displayGetVcpFeature(this.index, featureCode)
}
setVcpFeature (featureCode: number, value: number) {
displaySetVcpFeature(this.index, featureCode, value)
}
setTableVcpFeature (featureCode: number, data: ArrayBuffer, offset: number) {
displaySetTableVcpFeature(this.index, featureCode, data, offset)
}
readonly index: number
readonly backend: string
readonly edidData?: ArrayBuffer
readonly version?: string
readonly mccsVersion?: string
readonly displayId: string
readonly serial?: number
readonly serialNumber?: string
readonly modelId?: number
readonly modelName?: string
readonly manufacturerId?: string
readonly manufactureYear?: number
readonly manufactureWeek?: number
readonly capabilities?: string
}
export class DisplayManager {
constructor (queries?: Query[] | Query) {
if (Array.isArray(queries)) {
this._queries = queries
} else if (queries === undefined || queries === null) {
this._queries = []
} else {
this._queries = [queries]
}
}
get queries (): Query[] {
return this._queries
}
set queries (queries: Query[]) {
this._queries = queries
}
addQueries (queries?: Query[] | Query): DisplayManager {
let newQueries: Query[]
if (Array.isArray(queries)) {
newQueries = queries
} else if (queries === undefined || queries === null) {
newQueries = []
} else {
newQueries = [queries]
}
this.queries = this.queries.concat(newQueries)
return this
}
static getByIndex (index: number): Display {
const display = displayManagerGetByIndex(index)
return new Display(display)
}
collect (): Display[] {
return displayManagerList(this.queries).map(display => new Display(display))
}
list (): Display[] {
return displayManagerList(this.queries).map(display => new Display(display))
}
private _queries: Query[]
}