-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.d.ts
153 lines (137 loc) · 4.68 KB
/
index.d.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
declare module 'node-libgpiod' {
/**
* Chip instances represent GPIO chips (each with a fixed number of
* GPIO lines) on the Linux host. The number of GPIO chips depends on
* the hardware available.
*/
declare class Chip {
/**
* Constructs a new Chip instance by its chip number.
*
* @param chipNumber the number of the GPIO chip
* @throws error if the chip cannot be opened
*/
constructor(chipNumber: number);
/**
* Constructs a new Chip instance by its device name or full device path.
*
* @param deviceNameOrPath the device name or full device path of the GPIO chip
* @throws error if the chip cannot be opened
*/
constructor(deviceNameOrPath: string);
/**
* Returns the number of GPIO lines available (reserved or not) on the GPIO chip.
*/
getNumberOfLines(): number;
/**
* Returns the GPIO chip name as represented by the kernel.
*/
getChipName(): string;
/**
* Returns the GPIO chip label as represented by the kernel.
*/
getChipLabel(): string;
}
/**
* Line instances represent direct access to a specific GPIO line on
* the Linux host. Those lines can be reserved as input or output.
*/
declare class Line {
/**
* Constructs a new Line instance for the given chip and line offset.
*
* @param chip the parent gpio chip
* @param offset the line offset
* @throws error if the line cannot be opened
*/
constructor(chip: Chip, offset: number);
/**
* Returns the line offset of this Line instance for the assigned GPIO chip.
*
* @throws error if the line offset cannot be read
*/
getLineOffset(): number;
/**
* Returns the line name as represented by the kernel. The name is either a
* valid string, or undefined if not set.
*
* @throws error if the line name cannot be read
*/
getLineName(): string | undefined;
/**
* Returns the line consumer as represented by the kernel. This consumer is
* either a valid string, or undefined if not set.
*
* @throws error if the line consumer cannot be read
*/
getLineConsumer(): string | undefined;
/**
* Returns the state value of the line as off (0) or on (1).
* @throws error if the line is not reserved
*/
getValue(): 0 | 1;
/**
* Sets the state of the line to either on or off. Setting the same state as
* current, nothing happens.
*
* @param value the new state of the output line (0 = off, 1 = on)
* @throws error if the line is not reserved as an output
*/
setValue(value: 0 | 1): void;
/**
* Releases a previously created reservation. If the line is not reserved at
* the time of calling this method, nothing happens.
*/
release(): void;
/**
* Reserves the current line as an output. It is possible to pass a defaultValue,
* which defines the base state of the line (off or on). If not given, the default
* state is off.
*
* In addition, a consumer name can be given to assign a name to the reservation.
*
* @param defaultValue an optional default value (0 = off, 1 = on)
* @param consumer an optional consumer name to assign to the reservation
* @throws error if the line is already reserved
*/
requestOutputMode(defaultValue?: 0 | 1, consumer?: string): void;
/**
* Reserves the current line as an input.
*
* A consumer name can be given to assign a name to the reservation.
*
* @param consumer an optional consumer name to assign to the reservation
* @throws error if the line is already reserved
*/
requestInputMode(consumer?: string): void;
/**
* Reserves the current line as an input with Flags.
*
* A consumer name can be given to assign a name to the reservation.
*
* @param consumer an optional consumer name to assign to the reservation
* @param flags GPIOD_LINE_REQUEST_FLAG_xxxx as defined in gpiod.h
* @throws error if the line is already reserved
*/
requestInputModeFlags(consumer?: string, flags?: number): void;
}
/**
* LineFlags
* Those flags where introduced in libgpiod 1.5 and allows to fine tune how
* line should behave.
*/
declare type LineFlags = {
GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN: 1;
GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE: 2;
GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW: 4;
GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE: 8;
GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN: 16;
GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP: 32;
};
/**
* Returns true if the libgpiod functionality is available in
* the current execution environment, otherwise false (for example
* in non-Linux development environments).
*/
declare function available(): boolean;
}