node.onoff.pas 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. {
  2. This file is part of the Pas2JS run time library.
  3. Copyright (c) 2020 by Michael Van Canneyt
  4. NodeJS onoff module import.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit node.onoff;
  12. {$mode objfpc}
  13. {$modeswitch externalclass}
  14. interface
  15. uses
  16. JS,nodejs;
  17. Type
  18. TGPIOReadCallBack = reference to procedure(err : TJSError; aValue : Byte);
  19. TGPIOWriteCallBack = reference to procedure(err : TJSError);
  20. TNJSGPIO = class external name 'Gpio' (TJSObject)
  21. class var
  22. FAccessible : boolean; external name 'accessible' ;
  23. constructor new (agpio : byte; aDirection : string); overload;
  24. constructor new (agpio : byte; aDirection,aEdge : String); overload;
  25. constructor new (agpio : byte; aDirection,aEdge : string; aOptions : TJSObject); overload;
  26. procedure read; overload;
  27. procedure read(aCallBack : TGPIOReadCallBack); overload;
  28. function readSync : Byte;
  29. procedure write(aValue: Byte); overload;
  30. procedure write(aCallBack : TGPIOWriteCallBack); overload;
  31. procedure writeSync(aValue: Byte);
  32. procedure watch(aCallback : TGPIOReadCallBack);
  33. procedure unwatch(aCallback : TGPIOReadCallBack);
  34. procedure unwatchAll;
  35. function getdirection : string; external name 'direction';
  36. procedure setDirection(aDirection : string);
  37. function getEdge : string; external name 'edge';
  38. procedure setEdge(aEdge : string);
  39. function GetactiveLow : boolean; external name 'activeLow';
  40. procedure setActiveLow(aInvert : Boolean);
  41. procedure unexport;
  42. property Direction : string read getdirection write setdirection;
  43. property Edge : string read GetEdge write SetEdge;
  44. property ActiveLow : Boolean Read getActiveLow write setActiveLow;
  45. class property accessible: boolean Read Faccessible;
  46. const
  47. High = 1;
  48. Low = 0;
  49. end;
  50. TNJSGPIOClass = class of TNJSGPIO;
  51. var
  52. TGPIO : TNJSGPIOClass;
  53. implementation
  54. Type
  55. TNJSOnOffModule = class external name 'Object' (TJSObject)
  56. Gpio : TNJSGPIOClass;
  57. end;
  58. initialization
  59. TGPIO:=TNJSOnOffModule(require('onoff')).Gpio;
  60. end.