-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcoo.js
75 lines (61 loc) · 2.04 KB
/
qcoo.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(function(ext){
var connected = true;
var notifyConnection = false;
var device = null;
ext._getStatus = function() {
if (!connected){
sendMsg({'proto':'probe'}); // check if host app online
return { status:1, msg:'Disconnected' };
}else{
return { status:2, msg:'Connected' };
}
};
ext._deviceRemoved = function(dev) {
console.log('Device removed');
// Not currently implemented with serial devices
};
var potentialDevices = [];
ext._deviceConnected = function(dev) {
console.log("Device Connected "+dev.id);
};
ext._shutdown = function() {
// TODO: Bring all pins down
if (device) device.close();
if (poller) clearInterval(poller);
device = null;
};
ext.setFaceColor = function(face, colornum){
console.log("Face "+face+" color "+colornum);
sendMsg({'proto':'qcoo','data':'data'});
};
ext.setEffect = function (effect) {
console.log("Effect "+effect);
var data = new Uint8Array([0xF0,0x55,0x04, 0x00, 0x02, 0x05, effect]);
sendMsg({'proto':'qcoo','data':data});
};
function processInput(msg) {
console.log("Input "+msg.proto);
if(msg.proto=='online'){
connected = true;
}
}
function sendMsg(msg){
console.log("send msg: "+msg);
chrome.runtime.sendMessage('bbdbfcgfdibdoeblkggamnpndbgbekcn', msg, processInput)
//chrome.runtime.sendMessage('lohclnpicjahbccciannbegiamdbgeln', msg, processInput)
}
// Block and block menu descriptions
var descriptor = {
blocks: [
[' ', 'Face %d.face color %d', 'setFaceColor','Front','1'],
[' ', 'Run Effect %n','setEffect',1],
],
menus: {
face: ['Front', 'Back','Up','Bottom','Left','Right'],
colornum: ['1','2','3' ]
},
url: 'http://qcoo.cc/'
};
// Register the extension
ScratchExtensions.register('Qcoo', descriptor, ext);
})({});