فهرست منبع

* node onoff module for GPIO control on raspberry

michael 5 سال پیش
والد
کامیت
c581dece39
1فایلهای تغییر یافته به همراه55 افزوده شده و 0 حذف شده
  1. 55 0
      packages/nodejs/nodejsonoff.pas

+ 55 - 0
packages/nodejs/nodejsonoff.pas

@@ -0,0 +1,55 @@
+unit nodejsonoff;
+
+{$mode objfpc}
+{$modeswitch externalclass}
+
+interface
+
+uses
+  JS,nodejs;
+
+Type
+  TGPIOReadCallBack = reference to procedure(err : TJSError; aValue : Byte);
+  TGPIOWriteCallBack = reference to procedure(err : TJSError);
+
+  TNJSGPIO = class external name 'Gpio' (TJSObject)
+    class var
+      FAccessible : boolean; external name 'accessible' ;
+    constructor new (agpio : byte; aDirection : string); overload;
+    constructor new (agpio : byte; aDirection,aEdge : String); overload;
+    constructor new (agpio : byte; aDirection,aEdge : string; aOptions : TJSObject); overload;
+    procedure read; overload;
+    procedure read(aCallBack : TGPIOReadCallBack); overload;
+    function readSync : Byte;
+    procedure write(aValue: Byte); overload;
+    procedure write(aCallBack : TGPIOWriteCallBack); overload;
+    procedure writeSync(aValue: Byte);
+    procedure watch(aCallback : TGPIOReadCallBack);
+    procedure unwatch(aCallback : TGPIOReadCallBack);
+    procedure unwatchAll;
+    function getdirection : string; external name 'direction';
+    procedure setDirection(aDirection : string);
+    function getEdge : string; external name 'edge';
+    procedure setEdge(aEdge : string);
+    function GetactiveLow : boolean; external name 'activeLow';
+    procedure setActiveLow(aInvert : Boolean);
+    procedure unexport;
+    property Direction : string read getdirection write setdirection;
+    property Edge : string read GetEdge write SetEdge;
+    property ActiveLow : Boolean Read getActiveLow write setActiveLow;
+    class property accessible: boolean Read Faccessible;
+  const
+    High = 1;
+    Low = 0;
+  end;
+  TNJSGPIOClass = class of TNJSGPIO;
+
+var
+  GPIO : TNJSGPIOClass;
+
+implementation
+
+initialization
+  gpio:=TNJSGPIOClass(require('onoff'));
+end.
+