Skip to content

Commit abef93b

Browse files
author
Wang Yu
committed
Merge branch 'bugfix/v4.0.0_alpha5_test' into 4.0-flash-github
* bugfix/v4.0.0_alpha5_test: (98 commits) flash打开了arduino模式,菜单需勾选 点击帽子,由js去调用flash接口,flash不再自己改变状态 点击帽子语句块进入Arduino时发送指令通知js勾选菜单 fix 非机器人模块的帽子语句块点击会打开Arduino模式 fix 【上传Arduino】与编码电机有关的语句块上传Arduino失败 fix mbot主板切换不了的问题,原因是新旧版本的mbot命名不统一 打开保存文件时,选择主控板兼容之前保存的文件 将参数修改形式 兼容以前保存的文件 修改提供给flash的接口 优化 选择主控板相关代码 添加不支持的端口弹框提示 修改函数名 给flash提供设置当前的主控板的接口 回退固件版本,更新swf loading_panda.png loading 【上传到Arduino】上传到Arduino过程中,按钮依然可以Cloes 校正arduino log时间格式 修复翻译问题 下拉控件在角色面板上有问题,把小部分功能回退 ... Conflicts: ReadMe.md
2 parents 1166bba + 0333b73 commit abef93b

101 files changed

Lines changed: 7189 additions & 27418 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
*.actionScriptProperties
21
/bin-debug
32
/bin-release
43
/bin-release-temp

app/arduinoIDE.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,22 @@ var ArduinoIDE = {
115115
sketchFilePath
116116
];
117117

118-
app.alert(T('Uploading'));
118+
app.alert({'message':T('Uploading'), 'hasCancel':false});
119119
app.getSerial().close();
120120
var arduinoProcess = spawn(this.getArduinoExecutable(), arduinoCommandArguments);
121121
arduinoProcess.stdout.on('data', function(data) {
122122
app.logToArduinoConsole(data.toString());
123123
});
124124
arduinoProcess.stderr.on('data', function(data) {
125-
app.alert(T('Uploading')+'...'+utils.getProgressCharacter());
126-
app.logToArduinoConsole(data.toString());
125+
app.alert({'message':T('Uploading')+'...'+utils.getProgressCharacter(), 'hasCancel':false});
126+
app.logToArduinoConsole(data);
127127
});
128128
arduinoProcess.on('close', function(code){
129129
if (code == 0) {
130-
app.alert(T('Upload Succeeded'));
130+
app.alert({'message':T('Upload Finish'), 'hasCancel':true});
131131
}
132132
else {
133-
app.alert(T('Upload Failed'));
133+
app.alert({'message':T('Upload Failed'), 'hasCancel':true});
134134
}
135135
app.getSerial().connect(serialPort);
136136
});

app/bluetooth.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ function Bluetooth(app){
2626
} else if (_currentBluetooth == '') {
2727
return false;
2828
} else {
29-
return !(bluetoothChildProcess.killed);
29+
if (typeof(name) == 'undefined') { // 直接读取
30+
return !(bluetoothChildProcess.killed);
31+
} else { // 显示
32+
return (name == _currentBluetooth) && (!(bluetoothChildProcess.killed));
33+
}
3034
}
3135
};
3236

@@ -66,7 +70,8 @@ function Bluetooth(app){
6670
};
6771

6872
this.createBluetoothChildProcess = function () { // 创建蓝牙子进程,并托管各消息处理函数
69-
bluetoothChildProcess = childProcess.fork(__root_path + '/app/bluetoothChildProcess.js');
73+
var childProcessPath = __dirname + '/bluetoothChildProcess.js';
74+
bluetoothChildProcess = childProcess.fork(childProcessPath);
7075
// 监控所有子进程过来的消息
7176
bluetoothChildProcess.on('message', function (message) {
7277
if (message.method == 'noBluetoothDevices') { // 周围未找到任何蓝牙设备或最后一个蓝牙设备未找到通道

app/bluetoothChildProcess.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ process.on('message', function (message) { // 主进程传过来的消息
7373
});
7474
} else if (message.method == 'writeData') {
7575
bluetoothSerialPort.write(new Buffer(message.data), function(err, bytesWritten) {
76-
if (err) console.log(err);
76+
if (err) {
77+
console.log('蓝牙写数据出错了:');
78+
console.log(err);
79+
}
7780
});
7881
}
7982

app/boards.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* 控制板管理:主控板选择、主控板选中状态
33
*/
4-
var _currentBoardName;
4+
var _currentBoardName; // me/mega_pi_mega2560、me/mbot_uno
55
var _client,_app;
66
function Boards(app){
77
var self = this;
@@ -23,7 +23,12 @@ function Boards(app){
2323
}
2424
this.currentBoardName = function() {
2525
return _currentBoardName;
26-
}
26+
};
27+
// 设置当前的主控板
28+
this.setCurrentBoardName = function (currentBoardName) {
29+
_currentBoardName = currentBoardName;
30+
_app.getMenu().update();
31+
};
2732
//auriga指令集
2833
this.aurigaInstructions = {
2934
bluetooth_mode: [0xff, 0x55, 0x05, 0x00, 0x02, 0x3c, 0x11, 0x00],

app/configuration.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Created by kun on 2/13/17.
3+
* 保存用户配置
4+
*/
5+
const fs = require("fs");
6+
const path = require('path');
7+
8+
var _this, _dir, _file;
9+
var Configuration = function () {
10+
_this = this;
11+
_dir = path.join(__root_path, "/../mblock-setting");
12+
_file = path.resolve(_dir, 'settings.json');
13+
14+
this.read = function () {
15+
if (!fs.existsSync(_file)) {
16+
return {};
17+
}
18+
var res = JSON.parse(fs.readFileSync(_file));
19+
if (!res) return {};
20+
return res;
21+
}
22+
23+
this.get = function (name) {
24+
var result = _this.read();
25+
return result[name];
26+
}
27+
28+
this.mkdirsSync = function(dirpath) {
29+
if (!fs.existsSync(dirpath)) {
30+
var pathtmp;
31+
dirpath.split(path.sep).forEach(function(dirname) {
32+
if (pathtmp) {
33+
pathtmp = path.join(pathtmp, dirname);
34+
} else {
35+
pathtmp = dirname;
36+
}
37+
if ('' === pathtmp) {
38+
pathtmp = '/';
39+
return;
40+
}
41+
42+
if (!fs.existsSync(pathtmp)) {
43+
if (!fs.mkdirSync(pathtmp)) {
44+
return false;
45+
}
46+
}
47+
});
48+
}
49+
return true;
50+
}
51+
52+
this.set = function (name, value) {
53+
var result = _this.read();
54+
result[name] = value;
55+
if (!_this.mkdirsSync(_dir)) {
56+
return;
57+
}
58+
fs.writeFile(_file, JSON.stringify(result), function (err) {
59+
if (err) return;
60+
console.log(_file + ' is saved!');
61+
});
62+
}
63+
}
64+
module.exports = Configuration;

app/emotions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var Emotions = function(app) {
1010
_this = this;
1111
_app = app;
1212
_dir_preset = path.join(__root_path, "/web/flash-core/assets/emotions");
13-
_dir_custom = path.join(__root_path, "/../mblock-emotions");
13+
_dir_custom = path.join(__root_path, "/../mblock-setting/mblock-emotions");
1414
_translator = app.getTranslator();
1515
_client = app.getClient();
1616

@@ -66,7 +66,7 @@ var Emotions = function(app) {
6666
var file = _this.pathfile(filename);
6767
fs.unlink(file, function (err) {
6868
if (err) {
69-
_app.alert(_translator.map('It doesn\'t exist'));
69+
_app.alert(_translator.map("It doesn't exist"));
7070
return;
7171
}
7272
console.log(file + ' is delete!');

app/firmwareUploader.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const utils = require('./utils');
77
var Boards = require('./boards.js');
88
var app = null;
99
var T = null;
10+
var checkUSB, errorStatus;
1011
const boardFirmwareMap = {
1112
'arduino_uno': 'uno.hex',
1213
'arduino_leonardo': 'leonardo.hex',
@@ -21,7 +22,8 @@ const boardFirmwareMap = {
2122
};
2223

2324
const boardDefaultProgramMap = {
24-
'me/mbot_uno': 'mbot_reset.hex',
25+
'me/mbot_uno' : 'mbot_reset.hex',
26+
'me/orion_uno' : 'starter_factory_firmware.hex'
2527
};
2628

2729
var FirmwareUploader = {
@@ -82,10 +84,10 @@ var FirmwareUploader = {
8284
}
8385
return path.join(__root_path, 'tools/arduino');
8486
},
85-
87+
// 是否允许恢复出厂程序,true:允许,false:不允许
8688
allowResetDefaultProgram: function() {
8789
var boardName = app.getBoards().currentBoardName();
88-
if(boardName == 'me/mbot_uno') {
90+
if(boardName == 'me/mbot_uno' || boardName == 'me/orion_uno') {
8991
return true;
9092
}
9193
return false;
@@ -97,15 +99,29 @@ var FirmwareUploader = {
9799
},
98100

99101
resetDefaultProgram: function() {
100-
var boardName = app.getBoards().currentBoardName();
102+
var boardName = app.getBoards().currentBoardName();console.log('版:');console.log(boardName);
101103
this.uploadWithAvrdude(boardDefaultProgramMap[boardName]);
102104
},
103105

106+
/**
107+
* 通过小内存机多次测试刷新固件经验得出超时时间,range最多2分钟,mbot最多20秒
108+
* @param on
109+
* @param callback
110+
*/
111+
uploadingWatchDog: function (on, callback) {
112+
if (!on) return;
113+
// mbot : me/mbot_uno , ranger : me/auriga_mega2560
114+
var boardName = app.getBoards().currentBoardName();
115+
var timeout = ('me/mbot_uno' === boardName) ? 20000 : 120000;
116+
checkUSB = setInterval(function() {
117+
callback();
118+
}, timeout);
119+
},
120+
104121
uploadWithAvrdude: function(hexFileName) {
105122
var serialPort = app.getSerial().currentSerialPort();
106123
var boardName = app.getBoards().currentBoardName();
107124

108-
109125
if(!hexFileName) {
110126
app.alert(T('No firmware available for this type of board'));
111127
return;
@@ -117,30 +133,46 @@ var FirmwareUploader = {
117133

118134
var self = this;
119135
console.log('upgrade firmware');
120-
app.alert({'message':T('Uploading...'), 'hasCancel':false});
136+
app.alert({'message':T('Uploading') + '...', 'hasCancel':false});
121137
var command = self.getArduinoPath() + '/hardware/tools/avr/bin/avrdude';
122138
var args = self.getAvrdudeParameter(serialPort, hexFileName);
123139
app.getSerial().close();
140+
var uploading = false, uploaderSuccess = false;
124141
var avrdude = spawn(command, args, {cwd: __root_path});
125142
avrdude.stdout.on('data', function(data){
126143
});
127144
avrdude.stderr.on('data', function(data){
128-
app.logToArduinoConsole(data.toString());
145+
app.logToArduinoConsole(data);
129146
if(data.toString().indexOf('programmer is not responding')>=0){
130147
avrdude.kill('SIGKILL');
131148
}
132149
app.alert({'message':T('Uploading')+'...'+utils.getProgressCharacter(), 'hasCancel':false});
150+
// 第一次进入上传状态,看门狗启动,超时未完成上传即kill进程
151+
self.uploadingWatchDog(!uploading, function () {
152+
avrdude.kill('SIGKILL');
153+
errorStatus = 'TIMEOUT';
154+
app.alert({'message':T('Hardware communication timeout, please confirm whether the serial connection'), 'hasCancel':true});
155+
clearInterval(checkUSB);
156+
});
157+
158+
uploading = true;
133159
});
134160
avrdude.on('close', function(code){
161+
clearInterval(checkUSB);
162+
if ('TIMEOUT' === errorStatus) {
163+
errorStatus = '';
164+
return;
165+
}
135166
if(code == 0) {
136-
app.alert({'message':T('Upload Succeeded'), 'hasCancel':true});
167+
app.alert({'message':T('Upload Finish'), 'hasCancel':true});
137168
} else {
138169
app.alert({'message':T('Upload Failed'), 'hasCancel':true});
139170
}
140171
avrdude.kill('SIGKILL');
141172
app.getSerial().connect(serialPort);
142173
});
143-
174+
avrdude.on('exit', function (code) {
175+
});
144176
},
145177

146178
}

app/fontSize.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*/
44

55
const{MenuItem} = require('electron') ;
6-
var _client,_size,_app;
6+
const Configuration = require('./configuration.js');
7+
8+
var _client,_size,_app,_configuration;
79
const _fontSize = [
810
{label:"8"},
911
{label:"10"},
@@ -18,6 +20,7 @@ const _fontSize = [
1820
function FontSize(app){
1921
_app = app;
2022
_client = _app.getClient();
23+
_configuration = new Configuration();
2124
var _translator = _app.getTranslator();
2225
var self = this;
2326
this.setFontSize = function (size){
@@ -40,14 +43,26 @@ function FontSize(app){
4043
type:'checkbox',
4144
click:function(item,focusedWindow){
4245
self.setFontSize(item.label);
46+
_configuration.set('setFontSize', item.label);
4347
_app.getMenu().update();
4448
}
4549
})
4650
m.submenu.insert(0,item);
4751
}
4852
return m;
4953
}
50-
this.setFontSize("12");
54+
55+
this.setDefaultSize = function () {
56+
var setSize = _configuration.get('setFontSize');
57+
if (!setSize) {
58+
this.setFontSize("12");
59+
} else {
60+
this.setFontSize(setSize);
61+
}
62+
}
63+
64+
this.setDefaultSize();
65+
// this.setFontSize("12");
5166

5267
}
5368
module.exports = FontSize;

0 commit comments

Comments
 (0)