-
Notifications
You must be signed in to change notification settings - Fork 89
/
pigpio.d.ts
1088 lines (962 loc) · 37.2 KB
/
pigpio.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for pigpio 3.0
// Project: https://github.com/fivdi/pigpio
// Definitions by: ManerFan <https://github.com/manerfan>
// erikma <https://github.com/erikma>
// park012241 <https://github.com/park012241>
// Cameron Tacklind <https://github.com/cinderblock>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { EventEmitter } from 'events';
/************************************
* WaveForm
************************************/
export type WaveId = number;
/**
* Name | Command & Data | Description
* ---: | ---: | ---:
* Loop Start | 255 0 | Identify start of a wave block
* Loop Repeat | 255 1 x y | loop x + y*256 times
* Delay | 255 2 x y | delay x + y*256 microseconds
* Loop Forever | 255 3 | loop forever
*/
export type WaveChainCommands = number;
export type GenericWaveStep = {
/**
* an unsigned integer specifying the GPIO number to be turned on.
* 0 means don't change
*/
gpioOn: number;
/**
* an unsigned integer specifying the GPIO number to be turned off.
* 0 means don't change
*/
gpioOff: number;
/**
* an unsigned integer specifying the pulse length in microseconds.
*/
usDelay: number;
};
/**
* Clears all waveforms and any data added by calls to the `waveAdd*` functions.
*/
export function waveClear(): void;
/**
* Starts a new empty waveform.
*
* You wouldn't normally need to call this function as it is automatically called after a waveform is created with the gpioWaveCreate function.
*/
export function waveAddNew(): void;
/**
* @param pulses an array of pulses objects.
*
* Adds a series of pulses to the current waveform. Returns the new total number of pulses in the current waveform.
*
* The pulse objects are built with the following properties:
* - gpioOn - an unsigned integer specifying the GPIO number to be turned on.
* - gpioOff - an unsigned integer specifying the GPIO number to be turned off.
* - usDelay - an unsigned integer specifying the pulse length in microseconds.
*
* If you don't want to change a GPIO you can use 0 as a value for gpioOn or gpioOff.
*
* @example <caption>a pulse that switches GPIO 17 on for 50 microseconds.</caption>
* {
* gpioOn: 17,
* gpioOff: 0,
* usDelay: 50
* }
*
* @example <caption>generates a waveform that starts with a 1µs pulse, then has a 2µs pause, followed by a 3µs pulse and so on.</caption>
*
* import * as pigpio from 'pigpio';
*
* const Gpio = pigpio.Gpio;
*
* const outPin = 17;
*
* const output = new Gpio(outPin, {
* mode: Gpio.OUTPUT
* });
*
* let waveform = [];
*
* for (let x = 0; x < 20; x++) {
* if (x % 2 == 1) {
* waveform.push({ gpioOn: outPin, gpioOff: 0, usDelay: x + 1 });
* } else {
* waveform.push({ gpioOn: 0, gpioOff: outPin, usDelay: x + 1 });
* }
* }
*
* pigpio.waveClear();
*
* pigpio.waveAddGeneric(waveform);
*
* let waveId = pigpio.waveCreate();
*
* if (waveId >= 0) {
* pigpio.waveTxSend(waveId, pigpio.WAVE_MODE_ONE_SHOT);
* }
*
* while (pigpio.waveTxBusy()) {}
*
* pigpio.waveDelete(waveId);
*/
export function waveAddGeneric(pulses: GenericWaveStep[]): void;
/**
* Creates a waveform from added data. Returns a wave id.
* All data previously added with `waveAdd*` methods get cleared.
* @returns waveId
*/
export function waveCreate(): WaveId;
/**
* Deletes a waveform by the given wave id.
* @param waveId The wave id (as returned by waveCreate) to delete
*/
export function waveDelete(waveId: WaveId): void;
/**
* Transmits a waveform. Returns the number of DMA control blocks in the waveform.
*
* The SYNC variants of the waveMode wait for the current waveform to reach the end of a cycle or finish before starting the new waveform.
*
* @warning bad things may happen if you delete the previous waveform before it has been synced to the new waveform.
*
* @note Any hardware PWM started by `hardwarePwmWrite` will be cancelled.
*/
export function waveTxSend(
waveId: WaveId,
waveMode:
| typeof WAVE_MODE_ONE_SHOT
| typeof WAVE_MODE_REPEAT
| typeof WAVE_MODE_ONE_SHOT_SYNC
| typeof WAVE_MODE_REPEAT_SYNC
): void;
/**
* @param chain Array of waves to be transmitted, contains an ordered list of WaveIds and optional command codes and related data.
*
* Transmits a chain of waveforms.
*
* @note Any hardware PWM started by hardwarePwmWrite will be cancelled.
*
* The following command codes are supported:
*
* Name | Command & Data | Description
* ---: | ---: | ---:
* Loop Start | 255 0 | Identify start of a wave block
* Loop Repeat | 255 1 x y | loop x + y*256 times
* Delay | 255 2 x y | delay x + y*256 microseconds
* Loop Forever | 255 3 | loop forever
*
* Each wave is transmitted in the order specified.
* A wave may occur multiple times per chain.
* Blocks of waves may be transmitted multiple times by using the loop commands.
* The block is bracketed by loop start and end commands.
* Loops may be nested.
* Delays between waves may be added with the delay command.
* If present Loop Forever must be the last entry in the chain.
*
* @example <caption>creates a chain containing four simple waves and chains them together using all the above modifiers.</caption>
* import * as pigpio from 'pigpio';
*
* const Gpio = pigpio.Gpio;
*
* const outPin = 17;
* const output = new Gpio(outPin, {
* mode: Gpio.OUTPUT
* });
*
* let firstWaveForm = [{ gpioOn: outPin, gpioOff: 0, usDelay: 10 }, { gpioOn: 0, gpioOff: outPin, usDelay: 10 }];
* let secondWaveForm = [{ gpioOn: outPin, gpioOff: 0, usDelay: 20 }, { gpioOn: 0, gpioOff: outPin, usDelay: 20 }];
* let thirdWaveForm = [{ gpioOn: outPin, gpioOff: 0, usDelay: 30 }, { gpioOn: 0, gpioOff: outPin, usDelay: 30 }];
* let fourthWaveForm = [{ gpioOn: outPin, gpioOff: 0, usDelay: 40 }, { gpioOn: 0, gpioOff: outPin, usDelay: 40 }];
*
* pigpio.waveClear();
* pigpio.waveAddGeneric(firstWaveForm);
* let firstWaveId = pigpio.waveCreate();
*
* pigpio.waveAddGeneric(secondWaveForm);
* let secondWaveId = pigpio.waveCreate();
*
* pigpio.waveAddGeneric(thirdWaveForm);
* let thirdWaveId = pigpio.waveCreate();
*
* pigpio.waveAddGeneric(fourthWaveForm);
* let fourthWaveId = pigpio.waveCreate();
*
* let chain = [
* firstWaveId, // transmits firstWaveId
* secondWaveId, // transmits secondWaveId
* firstWaveId, // transmits again firstWaveId
* 255, 2, 136, 19, // delay for 5000 microseconds (136 + 19 * 256 = 5000)
* 255, 0, // marks the beginning of a new wave
* thirdWaveId, // transmits thirdWaveId
* 255, 1, 30, 0, // repeats the waves since the last beginning mark 30 times (30 + 0 * 256 = 30)
* 255, 0, // marks the beginning of a new wave
* fourthWaveId, // transmits fourthWaveId
* 255, 3 // loops forever until waveTxStop is called
* ];
*
* pigpio.waveChain(chain);
* while (pigpio.waveTxBusy()) {}
*/
export function waveChain(chain: (WaveId | WaveChainCommands)[]): void;
/**
* @returns the current transmitting wave id.
*/
export function waveTxAt(): WaveId;
/**
* @returns 1 if the current waveform is still transmitting, otherwise 0.
*/
export function waveTxBusy(): 1 | 0;
/**
* Aborts the current waveform.
*/
export function waveTxStop(): void;
/**
* @returns the length in microseconds of the current waveform.
*/
export function waveGetMicros(): number;
/**
* @returns the length in microseconds of the longest waveform created since `gpioInitialise` was called.
*/
export function waveGetHighMicros(): number;
/**
* @returns the maximum possible size of a waveform in microseconds.
*/
export function waveGetMaxMicros(): number;
/**
* @returns the length in pulses of the current waveform.
*/
export function waveGetPulses(): number;
/**
* @returns the length in pulses of the longest waveform created since `gpioInitialise` was called.
*/
export function waveGetHighPulses(): number;
/**
* @returns the maximum possible size of a waveform in pulses.
*/
export function waveGetMaxPulses(): number;
/**
* @returns the length in DMA control blocks of the current waveform.
*/
export function waveGetCbs(): number;
/**
* @returns the length in DMA control blocks of the longest waveform created since `gpioInitialise` was called.
*/
export function waveGetHighCbs(): number;
/**
* @returns the maximum possible size of a waveform in DMA control blocks.
*/
export function waveGetMaxCbs(): number;
/**
* The waveform is sent once.
*/
export const WAVE_MODE_ONE_SHOT: 0;
/**
* The waveform cycles repeatedly.
*/
export const WAVE_MODE_REPEAT: 1;
/**
* The waveform is sent once, waiting for the current waveform to finish before starting the new waveform.
*/
export const WAVE_MODE_ONE_SHOT_SYNC: 2;
/**
* The waveform cycles repeatedly, waiting for the current waveform to finish before starting the new waveform.
*/
export const WAVE_MODE_REPEAT_SYNC: 3;
/************************************
* Gpio
************************************/
/**
* General Purpose Input Output
*/
export class Gpio extends EventEmitter {
/**
* Returns a new Gpio object for accessing a GPIO
* @param gpio an unsigned integer specifying the GPIO number
* @param options object (optional)
*/
constructor(
gpio: number,
options?: {
/**
* INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, or ALT5 (optional, no default)
*/
mode?: number;
/**
* PUD_OFF, PUD_DOWN, or PUD_UP (optional, no default)
*/
pullUpDown?: number;
/**
* interrupt edge for inputs. RISING_EDGE, FALLING_EDGE, or EITHER_EDGE (optional, no default)
*/
edge?: number;
/**
* interrupt timeout in milliseconds (optional, defaults to 0 meaning no timeout if edge specified)
*/
timeout?: number;
/**
* boolean specifying whether or not alert events are emitted when the GPIO changes state (optional, default false)
*/
alert?: boolean;
}
);
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
addListener(
event: 'alert',
listener: (level: 0 | 1, tick: number) => void
): this;
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
on(event: 'alert', listener: (level: 0 | 1, tick: number) => void): this;
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
once(event: 'alert', listener: (level: 0 | 1, tick: number) => void): this;
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
prependListener(
event: 'alert',
listener: (level: 0 | 1, tick: number) => void
): this;
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
prependOnceListener(
event: 'alert',
listener: (level: 0 | 1, tick: number) => void
): this;
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
removeListener(
event: 'alert',
listener: (level: 0 | 1, tick: number) => void
): this;
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
listeners(event: 'alert'): ((level: 0 | 1, tick: number) => void)[];
/**
* @param level the GPIO level when the state change occurred, 0 or 1
* @param tick the time stamp of the state change, an unsigned 32 bit integer
* `tick` is the number of microseconds since system boot and it should be accurate to a few microseconds.
*
* As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes.
*
* It's not necessary to worry about wrap around when subtracting one tick from another tick if the JavaScript sign propagating right shift operator >> is used.
*
* @example <caption>Wrong: simply subtracting startTick from endTick prints -4294967294 which isn't the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log(endTick - startTick); // prints -4294967294 which isn't what we want
*
* @example <caption>right shifts both startTick and endTick 0 bits to the right before subtracting prints 2 which is the difference we're looking for</caption>
* const startTick = 0xffffffff; // 2^32-1 or 4294967295, the max unsigned 32 bit integer
* const endTick = 1;
* console.log((endTick >> 0) - (startTick >> 0)); // prints 2 which is what we want
*/
rawListeners(event: 'alert'): ((level: 0 | 1, tick: number) => void)[];
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
addListener(
event: 'interrupt',
listener: (level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void
): this;
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
on(
event: 'interrupt',
listener: (level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void
): this;
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
once(
event: 'interrupt',
listener: (level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void
): this;
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
prependListener(
event: 'interrupt',
listener: (level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void
): this;
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
prependOnceListener(
event: 'interrupt',
listener: (level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void
): this;
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
removeListener(
event: 'interrupt',
listener: (level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void
): this;
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
listeners(
event: 'interrupt'
): ((level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void)[];
/**
* @param level - the GPIO level when the interrupt occurred, 0, 1, or TIMEOUT (2)
* @param tick - the time stamp of the state change, an unsigned 32 bit integer
* You can find more information about ticks in the event `alert`.
*
* Emitted on interrupts.
*
* Interrupts can have an optional timeout.
* The level argument passed to the interrupt event listener will be TIMEOUT (2) if the optional interrupt timeout expires.
*/
rawListeners(
event: 'interrupt'
): ((level: 0 | 1 | typeof Gpio.TIMEOUT, tick: number) => void)[];
/**
* Sets the GPIO mode.
* @param mode INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, or ALT5
*/
mode(mode: number): Gpio;
/**
* Sets or clears the resistor pull type for the GPIO.
* @param pud PUD_OFF, PUD_DOWN, or PUD_UP
*/
pullUpDown(pud: number): Gpio;
/**
* Returns the GPIO mode.
*/
getMode(): number;
/**
* Returns the GPIO level, 0 or 1.
*/
digitalRead(): number;
/**
* Sets the GPIO level to 0 or 1. If PWM or servo pulses are active on the GPIO they are switched off.
* @param level 0 or 1
*/
digitalWrite(level: number): Gpio;
/**
* Sends a trigger pulse to the GPIO. The GPIO is set to level for pulseLen microseconds and then reset to not level.
* @param pulseLen pulse length in microseconds (1 - 100)
* @param level 0 or 1
*/
trigger(pulseLen: number, level: number): Gpio;
/**
* Starts PWM on the GPIO. Returns this.
* @param dutyCycle an unsigned integer >= 0 (off) and <= range (fully on). range defaults to 255.
*/
pwmWrite(dutyCycle: number): Gpio;
/**
* The same to #pwmWrite.
* @param dutyCycle an unsigned integer >= 0 (off) and <= range (fully on). range defaults to 255.
*/
analogWrite(dutyCycle: number): Gpio;
/**
* Starts hardware PWM on the GPIO at the specified frequency and dutyCycle. Frequencies above 30MHz are unlikely to work.
* @param frequency an unsigned integer >= 0 and <= 125000000 (>= 0 and <= 187500000 for the BCM2711)
* @param dutyCycle an unsigned integer >= 0 (off) and <= 1000000 (fully on).
*/
hardwarePwmWrite(frequency: number, dutyCycle: number): Gpio;
/**
* Returns the PWM duty cycle setting on the GPIO.
*/
getPwmDutyCycle(): number;
/**
* Selects the duty cycle range to be used for the GPIO. Subsequent calls to pwmWrite will use a duty cycle between 0 (off) and range (fully on).
* @param range an unsigned integer in the range 25 through 40000
*/
pwmRange(range: number): Gpio;
/**
* Returns the duty cycle range used for the GPIO.
* If hardware PWM is active on the GPIO the reported range will be 1000000.
*/
getPwmRange(): number;
/**
* Returns the real range used for the GPIO.
* If hardware PWM is active on the GPIO the reported real range will be approximately 250M (375M for the BCM2711) divided by the set PWM frequency.
*/
getPwmRealRange(): number;
/**
* Sets the frequency in hertz to be used for the GPIO. Returns this.
* @param frequency an unsigned integer >= 0
*/
pwmFrequency(frequency: number): Gpio;
/**
* Returns the frequency (in hertz) used for the GPIO. The default frequency is 800Hz.
*/
getPwmFrequency(): number;
/**
* Starts servo pulses at 50Hz on the GPIO, 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise)
* @param pulseWidth pulse width in microseconds, an unsigned integer, 0 or a number in the range 500 through 2500
*/
servoWrite(pulseWidth: number): Gpio;
/**
* Returns the servo pulse width setting on the GPIO.
*/
getServoPulseWidth(): number;
/**
* Enables interrupts for the GPI
* @param edge RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
* @param timeout interrupt timeout in milliseconds (optional, defaults to 0 meaning no timeout)
*/
enableInterrupt(edge: number, timeout?: number): Gpio;
/**
* Disables interrupts for the GPIO. Returns this.
*/
disableInterrupt(): Gpio;
/**
* Enables alerts for the GPIO. Returns this.
*/
enableAlert(): Gpio;
/**
* Disables aterts for the GPIO. Returns this.
*/
disableAlert(): Gpio;
/**
* Sets a glitch filter on a GPIO. Returns this.
* @param steady Time, in microseconds, during which the level must be stable. Maximum value: 300000
*/
glitchFilter(steady: number): Gpio;
/*----------------------*
* mode
*----------------------*/
/**
* Indicates that the GPIO is an input.
*/
static INPUT: number;
/**
* Indicates that the GPIO is an output.
*/
static OUTPUT: number;
/**
* Indicates that the GPIO is in alternative mode 0.
*/
static ALT0: number;
/**
* Indicates that the GPIO is in alternative mode 1.
*/
static ALT1: number;
/**
* Indicates that the GPIO is in alternative mode 2.
*/
static ALT2: number;
/**
* Indicates that the GPIO is in alternative mode 03.
*/
static ALT3: number;
/**
* Indicates that the GPIO is in alternative mode 4.
*/
static ALT4: number;
/**
* Indicates that the GPIO is in alternative mode 5.
*/
static ALT5: number;
/*----------------------*
* pud
*----------------------*/
/**
* Niether the pull-up nor the pull-down resistor should be enabled.
*/
static PUD_OFF: number;
/**
* Enable pull-down resistor.
*/
static PUD_DOWN: number;
/**
* Enable pull-up resistor.
*/
static PUD_UP: number;
/*----------------------*
* isr
*----------------------*/
/**
* Indicates that the GPIO fires interrupts on rising edges.
*/
static RISING_EDGE: number;
/**
* Indicates that the GPIO fires interrupts on falling edges.
*/
static FALLING_EDGE: number;
/**
* Indicates that the GPIO fires interrupts on both rising and falling edges.
*/
static EITHER_EDGE: number;
/*----------------------*
* timeout
*----------------------*/
/**
* The level argument passed to an interrupt event listener when an interrupt timeout expires.
*/
static TIMEOUT: number;
/*----------------------*
* gpio numbers
*----------------------*/
/**
* The smallest GPIO number.
*/
static MIN_GPIO: number;
/**
* The largest GPIO number.
*/
static MAX_GPIO: number;
/**
* The largest user GPIO number.
*/
static MAX_USER_GPIO: number;
}
/************************************
* GpioBank
************************************
/**
* Banked General Purpose Input Output
*/
export class GpioBank {
/**
* Returns a new GpioBank object for accessing up to 32 GPIOs as one operation.
* @param bank BANK1 or BANK2 (optional, defaults to BANK1)
*/
constructor(bank?: number);
/**
* Returns the current level of all GPIOs in the bank.
*/
read(): number;
/**
* For each GPIO in the bank, sets the GPIO level to 1 if the corresponding bit in bits is set.
* @param bits a bit mask of the the GPIOs to set to 1
*/
set(bits: number): GpioBank;
/**
* For each GPIO in the bank, sets the GPIO level to 0 if the corresponding bit in bits is set.
* @param bits a bit mask of the the GPIOs to clear or set to 0
*/
clear(bits: number): GpioBank;
/**
* Returns the bank identifier (BANK1 or BANK2.)
*/
bank(): number;
/**
* Identifies bank 1.
*/
static BANK1: number;
/**
* Identifies bank 2.
*/
static BACK2: number;
}
/************************************
* Notifier
************************************
/**
* Notification Stream
*/
export class Notifier {
/**
* Returns a new Notifier object that contains a stream which provides notifications about state changes on any of GPIOs 0 through 31 concurrently.
* @param options Used to configure which GPIOs notifications should be provided for.
*/
constructor(options?: {
/**
* a bit mask indicating the GPIOs of interest, bit0 corresponds to GPIO0, bit1 corresponds to GPIO1, ..., bit31 corresponds to GPIO31.
* If a bit is set, the corresponding GPIO will be monitored for state changes. (optional, no default)
*/
bits: number;
});
/**
* Starts notifications for the GPIOs specified in the bit mask.
* @param bits a bit mask indicating the GPIOs of interest, bit0 corresponds to GPIO0, bit1 corresponds to GPIO1, ..., bit31 corresponds to GPIO31.
* If a bit is set, the corresponding GPIO will be monitored for state changes.
*/
start(bits: number): Notifier;
/**
* Stops notifications. Notifications can be restarted with the start method.
*/
stop(): Notifier;
/**
* Stops notifications and releases resources.
*/
close(): Notifier;
/**
* Returns the notification stream which is a Readable stream.
*/
stream(): NodeJS.ReadableStream;
/**
* The number of bytes occupied by a notification in the notification stream.
*/
static NOTIFICATION_LENGTH: number;
/**
* Indicates a keep alive signal on the stream and is sent once a minute in the absence of other notification activity.
*/
static PI_NTFY_FLAGS_ALIVE: number;
}
/************************************
* Configuration
************************************/
/**
* PI_CLOCK_PWM
*/
export const CLOCK_PWM: number;
/**
* PI_CLOCK_PCM
*/
export const CLOCK_PCM: number;
/**
* Initialize the pigpio package
*/
export function initialize(): void;
/**
* Terminate the pigpio package
*/
export function terminate(): void;