Skip to content

Commit 555537d

Browse files
committed
Update simulator
1 parent 9c54f65 commit 555537d

10 files changed

Lines changed: 59 additions & 107 deletions

File tree

components/simulator/.bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
"jquery-i18next": "^1.2.0",
2525
"bootstrap-select": "^1.12.1"
2626
},
27-
"_release": "8e255b4ddf",
27+
"_release": "42f475e947",
2828
"_resolution": {
2929
"type": "branch",
3030
"branch": "blockly",
31-
"commit": "8e255b4ddf78475ed3dda4701fb85fa0237935b1"
31+
"commit": "42f475e94747e1efb5f2c72e0698a45bef703428"
3232
},
3333
"_source": "https://git.kingkit.codes/webduino/simulator.git",
3434
"_target": "blockly",

components/simulator/dist/css/bundle-20170214150934.css renamed to components/simulator/dist/css/bundle-20170215172810.css

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="icon" href="webduino.ico" type="image/x-icon"> <link rel="stylesheet" type="text/css" href="/components/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="css/bundle-20170214150934.css"> </head> <body> <nav class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand"> <i class="glyphicon glyphicon-hand-up"></i> <span data-i18n="navbar.brand"></span> </a> </div> <div id="navbar" class="navbar-collapse collapse"> <div class="navbar-left"> <button type="button" class="btn btn-default navbar-btn" v-on:click="historyBack" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.preStep"> <i class="glyphicon glyphicon-chevron-left"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="historyForward" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.nextStep"> <i class="glyphicon glyphicon-chevron-right"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="deleteSomething" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.remove"> <i class="glyphicon glyphicon-remove"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="zoomToFit" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.zoomToFit"> <i class="glyphicon glyphicon-screenshot"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="refresh" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.removeAll"> <i class="glyphicon glyphicon-trash"></i> </button> <button type="button" class="btn btn-default navbar-btn" id="menu-toggle" v-on:click="menuToggle" :disabled="isPlaying" data-i18n="navbar.components"></button> </div> <div class="navbar-right margin-fixed hidden"> <select id="lang" class="selectpicker hidden" data-container="body" data-width="auto"> <option value="en" data-i18n="language.en"></option> <option value="zh-tw" data-i18n="language.zh-tw"></option> <option value="zh-cn" data-i18n="language.zh-cn"></option> </select> <button type="button" class="btn btn-default navbar-btn hidden" :class="{ play: isPlaying, stop: !isPlaying }" v-on:click="engineToggle"> <i class="glyphicon glyphicon-play" v-show="!isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.start"></i> <i class="glyphicon glyphicon-stop" v-show="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.stop"></i> </button> </div> </div> </div> </nav> <div id="wrapper" v-bind:class="{ toggled: isComponentsVisible, dragging: dragging }"> <div id="sidebar"> <div class="container-fluid"> <div class="row components-container" v-html="components"></div> </div> </div> </div> <div class="container-fluid"> <svg id="editArea"> <g class="zoom-container"> <g class="components-area"></g> <g class="path-container"></g> <g class="edit-content"></g> </g> </svg> </div> <div id="myModal" class="modal fade"> <div class="modal-dialog modal-sm" v-on:keydown.stop v-on:keyup.stop v-on:keydown.enter.prevent> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only" data-i18n="propertyModal.close"></span></button> <h4 class="modal-title" data-i18n="propertyModal.title"></h4> </div> <div class="modal-body"> <form role="form"> <div class="form-group"> <label for="property-deviceId" class="control-label" data-i18n="propertyModal.deviceId"></label> <input type="text" class="form-control" id="property-deviceId" v-model="deviceId" v-on:keydown.enter="save" autofocus> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" data-i18n="propertyModal.close"></button> <button type="button" class="btn btn-primary" v-on:click="save" data-i18n="propertyModal.save">Save changes</button> </div> </div> </div> </div> <div id="app"></div> <script src="js/bundle-20170214150934.js"></script> </body>
1+
<!DOCTYPE html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="icon" href="webduino.ico" type="image/x-icon"> <link rel="stylesheet" type="text/css" href="/components/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="css/bundle-20170215172810.css"> </head> <body> <nav class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand"> <i class="glyphicon glyphicon-hand-up"></i> <span data-i18n="navbar.brand"></span> </a> </div> <div id="navbar" class="navbar-collapse collapse"> <div class="navbar-left"> <button type="button" class="btn btn-default navbar-btn" v-on:click="historyBack" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.preStep"> <i class="glyphicon glyphicon-chevron-left"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="historyForward" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.nextStep"> <i class="glyphicon glyphicon-chevron-right"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="deleteSomething" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.remove"> <i class="glyphicon glyphicon-remove"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="zoomToFit" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.zoomToFit"> <i class="glyphicon glyphicon-screenshot"></i> </button> <button type="button" class="btn btn-default navbar-btn" v-on:click="refresh" :disabled="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.removeAll"> <i class="glyphicon glyphicon-trash"></i> </button> <button type="button" class="btn btn-default navbar-btn" id="menu-toggle" v-on:click="menuToggle" :disabled="isPlaying" data-i18n="navbar.components"></button> </div> <div class="navbar-right margin-fixed hidden"> <select id="lang" class="selectpicker hidden" data-container="body" data-width="auto"> <option value="en" data-i18n="language.en"></option> <option value="zh-tw" data-i18n="language.zh-tw"></option> <option value="zh-cn" data-i18n="language.zh-cn"></option> </select> <button type="button" class="btn btn-default navbar-btn hidden" :class="{ play: isPlaying, stop: !isPlaying }" v-on:click="engineToggle"> <i class="glyphicon glyphicon-play" v-show="!isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.start"></i> <i class="glyphicon glyphicon-stop" v-show="isPlaying" data-toggle="tooltip" data-placement="bottom" data-i18n="[data-myTitle]navbar.stop"></i> </button> </div> </div> </div> </nav> <div id="wrapper" v-bind:class="{ toggled: isComponentsVisible, dragging: dragging }"> <div id="sidebar"> <div class="container-fluid"> <div class="row components-container" v-html="components"></div> </div> </div> </div> <div class="container-fluid"> <svg id="editArea"> <g class="zoom-container"> <g class="components-area"></g> <g class="path-container"></g> <g class="edit-content"></g> </g> </svg> </div> <div id="myModal" class="modal fade"> <div class="modal-dialog modal-sm" v-on:keydown.stop v-on:keyup.stop v-on:keydown.enter.prevent> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only" data-i18n="propertyModal.close"></span></button> <h4 class="modal-title" data-i18n="propertyModal.title"></h4> </div> <div class="modal-body"> <form role="form"> <div class="form-group"> <label for="property-deviceId" class="control-label" data-i18n="propertyModal.deviceId"></label> <input type="text" class="form-control" id="property-deviceId" v-model="deviceId" v-on:keydown.enter="save" autofocus> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" data-i18n="propertyModal.close"></button> <button type="button" class="btn btn-primary" v-on:click="save" data-i18n="propertyModal.save">Save changes</button> </div> </div> </div> </div> <div id="app"></div> <script src="js/bundle-20170215172810.js"></script> </body>

components/simulator/dist/js/bundle-20170214150934.js renamed to components/simulator/dist/js/bundle-20170215172810.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/simulator/dist/js/components/arduino-uno.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@
8686
"unoPin-p-gnd1" : "gnd",
8787
"unoPin-p-gnd2" : "gnd",
8888
"unoPin-p-vin" : "vin",
89-
"unoPin-a-0" : "a0",
90-
"unoPin-a-1" : "a1",
91-
"unoPin-a-2" : "a2",
92-
"unoPin-a-3" : "a3",
93-
"unoPin-a-4" : "a4",
94-
"unoPin-a-5" : "a5"
89+
"unoPin-a-0" : "14",
90+
"unoPin-a-1" : "15",
91+
"unoPin-a-2" : "16",
92+
"unoPin-a-3" : "17",
93+
"unoPin-a-4" : "18",
94+
"unoPin-a-5" : "19"
9595
};
9696
return data[name] || name;
9797
};

components/simulator/dist/js/engine/components/Buzzer.js

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
var uiCallback;
55

66
function Buzzer(board, name, signal, gnd) {
7-
window.b = board;
8-
this._name = name;
9-
this._gnd = gnd;
107
this._board = board;
8+
this._name = name;
119
this._signal = signal;
10+
this._gnd = gnd;
1211
this._buf = [];
13-
this.playing = false;
14-
this.ctx = new AudioContext();
12+
this._ctx = new AudioContext();
13+
this._playing = false;
14+
1515
var self = this;
16-
board.on(webduino.BoardEvent.SYSEX_MESSAGE, function (sysex) {
16+
17+
this._board.on(webduino.BoardEvent.SYSEX_MESSAGE, function (sysex) {
1718
var data = sysex.message;
1819
var pin = data[2];
1920
if (data[0] != 4 || data[1] != 7 || pin != self._signal) {
@@ -23,29 +24,11 @@
2324
var time = parseInt(data[5]) * 100;
2425
self._buf.push([freq, time]);
2526
self.play();
26-
//action(self, data.pin);
2727
});
28+
this._board.on(webduino.BoardEvent.BEFOREDISCONNECT, this.destroy.bind(this));
29+
this._board.on(webduino.BoardEvent.ERROR, this.destroy.bind(this));
2830
}
2931

30-
function action(buzzer, pin) {
31-
if (pin._number != buzzer._signal) {
32-
return;
33-
}
34-
var jsonData = {
35-
action: {
36-
id: buzzer._board._options.device,
37-
type: buzzer._board.constructor.name,
38-
connector: [{
39-
name: buzzer._name,
40-
type: "Buzzer",
41-
intensity: pin._value
42-
}]
43-
}
44-
};
45-
uiCallback(jsonData);
46-
}
47-
48-
4932
Buzzer.prototype = Object.create(Buzzer.prototype, {
5033
constructor: { value: Buzzer }
5134
});
@@ -55,29 +38,33 @@
5538
}
5639

5740
Buzzer.prototype.play = function () {
58-
this.osc = this.ctx.createOscillator();
41+
this.osc = this._ctx.createOscillator();
5942
this.osc.type = "triangle";
6043
this.osc.start(0);
6144

62-
if (this.playing) {
45+
if (this._playing) {
6346
return;
6447
}
65-
this.playing = true;
48+
this._playing = true;
6649
var data = this._buf.shift();
6750
var hz = data[0];
6851
var durtime = data[1];
6952
console.log("hz:", hz, ",time:", durtime);
7053
this.osc.frequency.value = hz;
71-
this.osc.connect(this.ctx.destination);
54+
this.osc.connect(this._ctx.destination);
7255
var self = this;
7356
setTimeout(function () {
7457
self.osc.disconnect();
75-
self.playing = false;
58+
self._playing = false;
7659
if (self._buf.length > 0) {
7760
self.play();
7861
}
7962
}, durtime);
8063
}
8164

65+
Buzzer.prototype.destroy = function () {
66+
this._ctx.close();
67+
};
68+
8269
scope.Buzzer = Buzzer;
8370
})(Engine);

components/simulator/dist/js/interact.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
console.log('stop');
2525
try {
2626
$.each(instance, function(idx, info) {
27+
28+
// 清除元件 instance
2729
$.each(info.components, function (idx, comp) {
2830
comp.destroy && (comp.destroy());
2931
});
@@ -44,6 +46,7 @@
4446

4547
components[uiSetting.name] = uiBoard;
4648

49+
// engine 收到訊息後,會執行該方法
4750
engine.action(function (actionJSON) {
4851

4952
console.log("engine callback:", actionJSON);
@@ -108,20 +111,6 @@
108111
components[compId] = comp;
109112
}
110113

111-
if (list[i].type == 'Led') {
112-
console.log("list[i].name", list[i].name);
113-
} else if (list[i].type == 'Btn') {
114-
console.log("Btn list[i].name", list[i].name, list[i]);
115-
} else if (list[i].type == 'RGBLed') {
116-
console.log("list[i].name", list[i].name);
117-
} else if (list[i].type == 'Servo') {
118-
console.log("list[i].name", list[i].name);
119-
} else if (list[i].type == 'Matrix') {
120-
console.log("list[i].name", list[i].name);
121-
} else if (list[i].type == 'UltraSonic') {
122-
console.log("list[i].name", list[i].name);
123-
}
124-
125114
}
126115
});
127116

components/simulator/js/components/arduino-uno.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@
8686
"unoPin-p-gnd1" : "gnd",
8787
"unoPin-p-gnd2" : "gnd",
8888
"unoPin-p-vin" : "vin",
89-
"unoPin-a-0" : "a0",
90-
"unoPin-a-1" : "a1",
91-
"unoPin-a-2" : "a2",
92-
"unoPin-a-3" : "a3",
93-
"unoPin-a-4" : "a4",
94-
"unoPin-a-5" : "a5"
89+
"unoPin-a-0" : "14",
90+
"unoPin-a-1" : "15",
91+
"unoPin-a-2" : "16",
92+
"unoPin-a-3" : "17",
93+
"unoPin-a-4" : "18",
94+
"unoPin-a-5" : "19"
9595
};
9696
return data[name] || name;
9797
};

components/simulator/js/engine/components/Buzzer.js

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
var uiCallback;
55

66
function Buzzer(board, name, signal, gnd) {
7-
window.b = board;
8-
this._name = name;
9-
this._gnd = gnd;
107
this._board = board;
8+
this._name = name;
119
this._signal = signal;
10+
this._gnd = gnd;
1211
this._buf = [];
13-
this.playing = false;
14-
this.ctx = new AudioContext();
12+
this._ctx = new AudioContext();
13+
this._playing = false;
14+
1515
var self = this;
16-
board.on(webduino.BoardEvent.SYSEX_MESSAGE, function (sysex) {
16+
17+
this._board.on(webduino.BoardEvent.SYSEX_MESSAGE, function (sysex) {
1718
var data = sysex.message;
1819
var pin = data[2];
1920
if (data[0] != 4 || data[1] != 7 || pin != self._signal) {
@@ -23,29 +24,11 @@
2324
var time = parseInt(data[5]) * 100;
2425
self._buf.push([freq, time]);
2526
self.play();
26-
//action(self, data.pin);
2727
});
28+
this._board.on(webduino.BoardEvent.BEFOREDISCONNECT, this.destroy.bind(this));
29+
this._board.on(webduino.BoardEvent.ERROR, this.destroy.bind(this));
2830
}
2931

30-
function action(buzzer, pin) {
31-
if (pin._number != buzzer._signal) {
32-
return;
33-
}
34-
var jsonData = {
35-
action: {
36-
id: buzzer._board._options.device,
37-
type: buzzer._board.constructor.name,
38-
connector: [{
39-
name: buzzer._name,
40-
type: "Buzzer",
41-
intensity: pin._value
42-
}]
43-
}
44-
};
45-
uiCallback(jsonData);
46-
}
47-
48-
4932
Buzzer.prototype = Object.create(Buzzer.prototype, {
5033
constructor: { value: Buzzer }
5134
});
@@ -55,29 +38,33 @@
5538
}
5639

5740
Buzzer.prototype.play = function () {
58-
this.osc = this.ctx.createOscillator();
41+
this.osc = this._ctx.createOscillator();
5942
this.osc.type = "triangle";
6043
this.osc.start(0);
6144

62-
if (this.playing) {
45+
if (this._playing) {
6346
return;
6447
}
65-
this.playing = true;
48+
this._playing = true;
6649
var data = this._buf.shift();
6750
var hz = data[0];
6851
var durtime = data[1];
6952
console.log("hz:", hz, ",time:", durtime);
7053
this.osc.frequency.value = hz;
71-
this.osc.connect(this.ctx.destination);
54+
this.osc.connect(this._ctx.destination);
7255
var self = this;
7356
setTimeout(function () {
7457
self.osc.disconnect();
75-
self.playing = false;
58+
self._playing = false;
7659
if (self._buf.length > 0) {
7760
self.play();
7861
}
7962
}, durtime);
8063
}
8164

65+
Buzzer.prototype.destroy = function () {
66+
this._ctx.close();
67+
};
68+
8269
scope.Buzzer = Buzzer;
8370
})(Engine);

components/simulator/js/interact.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
console.log('stop');
2525
try {
2626
$.each(instance, function(idx, info) {
27+
28+
// 清除元件 instance
2729
$.each(info.components, function (idx, comp) {
2830
comp.destroy && (comp.destroy());
2931
});
@@ -44,6 +46,7 @@
4446

4547
components[uiSetting.name] = uiBoard;
4648

49+
// engine 收到訊息後,會執行該方法
4750
engine.action(function (actionJSON) {
4851

4952
console.log("engine callback:", actionJSON);
@@ -108,20 +111,6 @@
108111
components[compId] = comp;
109112
}
110113

111-
if (list[i].type == 'Led') {
112-
console.log("list[i].name", list[i].name);
113-
} else if (list[i].type == 'Btn') {
114-
console.log("Btn list[i].name", list[i].name, list[i]);
115-
} else if (list[i].type == 'RGBLed') {
116-
console.log("list[i].name", list[i].name);
117-
} else if (list[i].type == 'Servo') {
118-
console.log("list[i].name", list[i].name);
119-
} else if (list[i].type == 'Matrix') {
120-
console.log("list[i].name", list[i].name);
121-
} else if (list[i].type == 'UltraSonic') {
122-
console.log("list[i].name", list[i].name);
123-
}
124-
125114
}
126115
});
127116

0 commit comments

Comments
 (0)