Last active
August 29, 2015 14:07
-
-
Save ianjorgensen/4755421657263d745a65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | |
<script type="text/javascript" src="file:///android_asset/js/lib/jquery-1.9.1.js"></script> | |
<!-- Required includes. json2.js may not be required in specific instances. --> | |
<script type="text/javascript" src="file:///android_asset/js/lib/jockey.js"></script> | |
<script type="text/javascript" src="file:///android_asset/js/lib/guid.js"></script> | |
<script type="text/javascript" src="file:///android_asset/js/lib/common.min.js"></script> | |
<script type="text/javascript" src="file:///android_asset/js/usb.js"></script> | |
<script type="text/javascript" src="file:///android_asset/js/app.js"></script> | |
</head> | |
<body> | |
</body> | |
</html>*/ | |
/*app.js*/ | |
var usb = Usb(); | |
Jockey.on('send-opcode', function() { | |
common.step([ | |
function(next) { | |
usb.open(next); | |
}, | |
function(data, next) { | |
usb.write('0x04,0x00', next); | |
}, | |
function(data, next) { | |
Jockey.send('message', {message: data}); | |
} | |
], | |
function(err) { | |
Jockey.send('message', {message: 'error: ' + data}); | |
}); | |
}); | |
/*lib/guid.js*/ | |
var guid = (function() { | |
function s4() { | |
return Math.floor((1 + Math.random()) * 0x10000) | |
.toString(16) | |
.substring(1); | |
} | |
return function() { | |
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + | |
s4() + '-' + s4() + s4() + s4(); | |
}; | |
})(); | |
/*lib/usb.js*/ | |
var Usb = function(options) { | |
var uuid = guid(); | |
return { | |
open: function(callback) { | |
var eventHandlerId = 'openComplete-' + uuid; | |
Jockey.on(eventHandlerId, function(response) { | |
Jockey.off(eventHandlerId); | |
response = JSON.parse(response); | |
callback(response.err); | |
}); | |
Jockey.send('open', {eventHandlerId: eventHandlerId}); | |
}, | |
write: function(message, callback) { | |
var eventHandlerId = 'writeComplete-' + uuid; | |
Jockey.on(eventHandlerId, function(response) { | |
Jockey.off(eventHandlerId); | |
response = JSON.parse(response); | |
callback(response.err); | |
}); | |
Jockey.send('write', {eventHandlerId: eventHandlerId, message: message}); | |
}, | |
read: function(callback) { | |
var eventHandlerId = 'readComplete-' + uuid; | |
Jockey.on(eventHandlerId, function(response) { | |
Jockey.off(eventHandlerId); | |
response = JSON.parse(response); | |
callback(response.err, response.data); | |
}); | |
Jockey.send('read', {eventHandlerId: eventHandlerId}); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment