Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit 89b5f76

Browse files
makearlgortok
authored andcommitted
Add serial plugin wrapper (#1274)
* Add cordovaSerial plugin wrapper and unit tests * Update README with serial plugin * Add serial to jshint globals
1 parent 876ef68 commit 89b5f76

File tree

3 files changed

+426
-0
lines changed

3 files changed

+426
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ $ bower install ngCordova
9292
- [Push Notifications](https://github.com/phonegap-build/PushPlugin) (**deprecated** - Will be removed in future release)
9393
- [Push Notifications - V5] (https://github.com/phonegap/phonegap-plugin-push)
9494
- [Screenshots](https://github.com/gitawego/cordova-screenshot)
95+
- [Serial](https://github.com/xseignard/cordovarduino)
9596
- [SMS](https://github.com/aharris88/phonegap-sms-plugin)
9697
- [Social Sharing](https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin)
9798
- [Spinner Dialog](https://github.com/Paldom/SpinnerDialog)

src/plugins/serial.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// install : cordova plugin add https://github.com/xseignard/cordovarduino.git
2+
// link : https://github.com/xseignard/cordovarduino
3+
4+
/* globals serial: true */
5+
angular.module('ngCordova.plugins.serial', [])
6+
7+
.factory('$cordovaSerial', ['$q', function ($q) {
8+
9+
var serialService = {};
10+
11+
serialService.requestPermission = function requestPermission(options) {
12+
var q = $q.defer();
13+
14+
serial.requestPermission(options, function success() {
15+
q.resolve();
16+
}, function error(err) {
17+
q.reject(err);
18+
});
19+
20+
return q.promise;
21+
};
22+
23+
serialService.open = function(options) {
24+
var q = $q.defer();
25+
26+
serial.open(options, function success() {
27+
q.resolve();
28+
}, function error(err) {
29+
q.reject(err);
30+
});
31+
32+
return q.promise;
33+
};
34+
35+
serialService.write = function(data) {
36+
var q = $q.defer();
37+
38+
serial.write(data, function success() {
39+
q.resolve();
40+
}, function error(err) {
41+
q.reject(err);
42+
});
43+
44+
return q.promise;
45+
};
46+
47+
serialService.writeHex = function(data) {
48+
var q = $q.defer();
49+
50+
serial.writeHex(data, function success() {
51+
q.resolve();
52+
}, function error(err) {
53+
q.reject(err);
54+
});
55+
56+
return q.promise;
57+
};
58+
59+
serialService.read = function() {
60+
var q = $q.defer();
61+
62+
serial.read(function success(buffer) {
63+
var view = new Uint8Array(buffer);
64+
q.resolve(view);
65+
}, function error(err) {
66+
q.reject(err);
67+
});
68+
69+
return q.promise;
70+
};
71+
72+
serialService.registerReadCallback = function(successCallback, errorCallback) {
73+
serial.registerReadCallback(function success(buffer) {
74+
var view = new Uint8Array(buffer);
75+
successCallback(view);
76+
}, errorCallback);
77+
};
78+
79+
serialService.close = function() {
80+
var q = $q.defer();
81+
82+
serial.close(function success() {
83+
q.resolve();
84+
}, function error(err) {
85+
q.reject(err);
86+
});
87+
88+
return q.promise;
89+
};
90+
91+
return serialService;
92+
}]);

0 commit comments

Comments
 (0)