-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpfio.cc
55 lines (45 loc) · 1.71 KB
/
pfio.cc
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
#include <node.h>
#include <v8.h>
#include <libpiface-1.0/pfio.h>
using namespace v8;
void PfioInit(const v8::FunctionCallbackInfo<v8::Value>& args) {
pfio_init();
}
void PfioDeinit(const v8::FunctionCallbackInfo<v8::Value>& args) {
pfio_deinit();
}
void PfioDigitalRead(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
uint8_t pin = Integer::New(isolate, args[0]->IntegerValue())->Value();
uint8_t val = pfio_digital_read(pin);
args.GetReturnValue().Set(val);
}
void PfioDigitalWrite(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
uint8_t pin = Integer::New(isolate, args[0]->IntegerValue())->Value();
uint8_t val = Integer::New(isolate, args[1]->IntegerValue())->Value();
pfio_digital_write(pin, val);
}
void PfioReadInput(const v8::FunctionCallbackInfo<v8::Value>& args) {
uint8_t val = pfio_read_input();
args.GetReturnValue().Set(val);
}
void PfioReadOutput(const v8::FunctionCallbackInfo<v8::Value>& args) {
uint8_t val = pfio_read_output();
args.GetReturnValue().Set(val);
}
void PfioWriteOutput(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
uint8_t val = Integer::New(isolate, args[0]->IntegerValue())->Value();
pfio_write_output(val);
}
void init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "init", PfioInit);
NODE_SET_METHOD(exports, "deinit", PfioDeinit);
NODE_SET_METHOD(exports, "digital_read", PfioDigitalRead);
NODE_SET_METHOD(exports, "digital_write", PfioDigitalWrite);
NODE_SET_METHOD(exports, "read_input", PfioReadInput);
NODE_SET_METHOD(exports, "read_output", PfioReadOutput);
NODE_SET_METHOD(exports, "write_output", PfioWriteOutput);
}
NODE_MODULE(pfio, init);