mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Add cordovarduino
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/// <reference path="cordovarduino.d.ts"/>
|
||||
|
||||
serial.requestPermission(function success() {}, function error() {});
|
||||
serial.open({}, function success() {}, function error() {});
|
||||
serial.write('data_string', function success() {}, function error() {});
|
||||
serial.read(function success() {}, function error() {});
|
||||
serial.registerReadCallback(
|
||||
function success(data:any) {
|
||||
var view = new Uint8Array(data);
|
||||
console.log(view);
|
||||
},
|
||||
function error() {
|
||||
new Error("Failed to register read callback");
|
||||
});
|
||||
serial.close(function success() {}, function error() {});
|
||||
|
||||
var errorCallback = function (message:string) {
|
||||
alert('Error: ' + message);
|
||||
};
|
||||
|
||||
serial.requestPermission(
|
||||
function (successMessage:string) {
|
||||
serial.open(
|
||||
{baudRate: 9600},
|
||||
function (successMessage:string) {
|
||||
serial.write(
|
||||
'1',
|
||||
function (successMessage:string) {
|
||||
alert(successMessage);
|
||||
},
|
||||
errorCallback
|
||||
);
|
||||
},
|
||||
errorCallback
|
||||
);
|
||||
},
|
||||
errorCallback
|
||||
);
|
||||
Vendored
+84
@@ -0,0 +1,84 @@
|
||||
// Type definitions for Cordovarduino plugin.
|
||||
// Project: https://github.com/stereolux/cordovarduino
|
||||
// Definitions by: Hendrik Maus <hendrik@aidentailor.net>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module Cordovardunio {
|
||||
interface Serial {
|
||||
/**
|
||||
* Request permission to interact with the serial port.
|
||||
*
|
||||
* @param successCallback Function to call on success
|
||||
* @param errorCallback Function to call on error
|
||||
*/
|
||||
requestPermission(successCallback:Function, errorCallback:Function): void;
|
||||
|
||||
/**
|
||||
* Open a connection.
|
||||
*
|
||||
* @param opts SerialOptions object
|
||||
* @param successCallback Function to call on success
|
||||
* @param errorCallback Function to call on error
|
||||
*/
|
||||
open(opts:SerialOptions, successCallback:Function, errorCallback:Function): void
|
||||
|
||||
/**
|
||||
* Write to the serial port.
|
||||
*
|
||||
* @param data String data to write to serial port
|
||||
* @param successCallback Function to call on success
|
||||
* @param errorCallback Function to call on error
|
||||
*/
|
||||
write(data:string, successCallback:Function, errorCallback:Function): void;
|
||||
|
||||
/**
|
||||
* Read from the serial port.
|
||||
*
|
||||
* @param successCallback Function to call on success
|
||||
* @param errorCallback Function to call on error
|
||||
*/
|
||||
read(successCallback:Function, errorCallback:Function): void;
|
||||
|
||||
/**
|
||||
* Close connection.
|
||||
*
|
||||
* @param successCallback Function to call on success
|
||||
* @param errorCallback Function to call on error
|
||||
*/
|
||||
close(successCallback:Function, errorCallback:Function): void;
|
||||
|
||||
/**
|
||||
* Register a callback for the driver reading incoming data from the serial device
|
||||
*
|
||||
* @param successCallback Function to call on success
|
||||
* @param errorCallback Function to call on error
|
||||
*/
|
||||
registerReadCallback(successCallback:Function, errorCallback:Function): void;
|
||||
}
|
||||
|
||||
interface SerialOptions {
|
||||
/**
|
||||
* @defaultValue 9600
|
||||
*/
|
||||
baudRate?: number;
|
||||
|
||||
/**
|
||||
* @defaultValue 8
|
||||
*/
|
||||
dataBits?: number;
|
||||
|
||||
/**
|
||||
* @defaultValue 1
|
||||
*/
|
||||
stopBits?: number;
|
||||
|
||||
/**
|
||||
* @defaultValue 0
|
||||
*/
|
||||
parity?: number;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Plugin will be surfaced as window.serial
|
||||
declare var serial:Cordovardunio.Serial;
|
||||
Reference in New Issue
Block a user