Skip to content

Commit

Permalink
Merge branch 'bugfix/v4.0.0_alpha5_test' into 4.0-flash-github
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Wang Yu committed Feb 27, 2017
2 parents 1166bba + 0333b73 commit abef93b
Show file tree
Hide file tree
Showing 101 changed files with 7,189 additions and 27,418 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.actionScriptProperties
/bin-debug
/bin-release
/bin-release-temp
Expand Down
10 changes: 5 additions & 5 deletions app/arduinoIDE.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ var ArduinoIDE = {
sketchFilePath
];

app.alert(T('Uploading'));
app.alert({'message':T('Uploading'), 'hasCancel':false});
app.getSerial().close();
var arduinoProcess = spawn(this.getArduinoExecutable(), arduinoCommandArguments);
arduinoProcess.stdout.on('data', function(data) {
app.logToArduinoConsole(data.toString());
});
arduinoProcess.stderr.on('data', function(data) {
app.alert(T('Uploading')+'...'+utils.getProgressCharacter());
app.logToArduinoConsole(data.toString());
app.alert({'message':T('Uploading')+'...'+utils.getProgressCharacter(), 'hasCancel':false});
app.logToArduinoConsole(data);
});
arduinoProcess.on('close', function(code){
if (code == 0) {
app.alert(T('Upload Succeeded'));
app.alert({'message':T('Upload Finish'), 'hasCancel':true});
}
else {
app.alert(T('Upload Failed'));
app.alert({'message':T('Upload Failed'), 'hasCancel':true});
}
app.getSerial().connect(serialPort);
});
Expand Down
9 changes: 7 additions & 2 deletions app/bluetooth.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ function Bluetooth(app){
} else if (_currentBluetooth == '') {
return false;
} else {
return !(bluetoothChildProcess.killed);
if (typeof(name) == 'undefined') { // 直接读取
return !(bluetoothChildProcess.killed);
} else { // 显示
return (name == _currentBluetooth) && (!(bluetoothChildProcess.killed));
}
}
};

Expand Down Expand Up @@ -66,7 +70,8 @@ function Bluetooth(app){
};

this.createBluetoothChildProcess = function () { // 创建蓝牙子进程,并托管各消息处理函数
bluetoothChildProcess = childProcess.fork(__root_path + '/app/bluetoothChildProcess.js');
var childProcessPath = __dirname + '/bluetoothChildProcess.js';
bluetoothChildProcess = childProcess.fork(childProcessPath);
// 监控所有子进程过来的消息
bluetoothChildProcess.on('message', function (message) {
if (message.method == 'noBluetoothDevices') { // 周围未找到任何蓝牙设备或最后一个蓝牙设备未找到通道
Expand Down
5 changes: 4 additions & 1 deletion app/bluetoothChildProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ process.on('message', function (message) { // 主进程传过来的消息
});
} else if (message.method == 'writeData') {
bluetoothSerialPort.write(new Buffer(message.data), function(err, bytesWritten) {
if (err) console.log(err);
if (err) {
console.log('蓝牙写数据出错了:');
console.log(err);
}
});
}

Expand Down
9 changes: 7 additions & 2 deletions app/boards.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* 控制板管理:主控板选择、主控板选中状态
*/
var _currentBoardName;
var _currentBoardName; // me/mega_pi_mega2560、me/mbot_uno
var _client,_app;
function Boards(app){
var self = this;
Expand All @@ -23,7 +23,12 @@ function Boards(app){
}
this.currentBoardName = function() {
return _currentBoardName;
}
};
// 设置当前的主控板
this.setCurrentBoardName = function (currentBoardName) {
_currentBoardName = currentBoardName;
_app.getMenu().update();
};
//auriga指令集
this.aurigaInstructions = {
bluetooth_mode: [0xff, 0x55, 0x05, 0x00, 0x02, 0x3c, 0x11, 0x00],
Expand Down
64 changes: 64 additions & 0 deletions app/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Created by kun on 2/13/17.
* 保存用户配置
*/
const fs = require("fs");
const path = require('path');

var _this, _dir, _file;
var Configuration = function () {
_this = this;
_dir = path.join(__root_path, "/../mblock-setting");
_file = path.resolve(_dir, 'settings.json');

this.read = function () {
if (!fs.existsSync(_file)) {
return {};
}
var res = JSON.parse(fs.readFileSync(_file));
if (!res) return {};
return res;
}

this.get = function (name) {
var result = _this.read();
return result[name];
}

this.mkdirsSync = function(dirpath) {
if (!fs.existsSync(dirpath)) {
var pathtmp;
dirpath.split(path.sep).forEach(function(dirname) {
if (pathtmp) {
pathtmp = path.join(pathtmp, dirname);
} else {
pathtmp = dirname;
}
if ('' === pathtmp) {
pathtmp = '/';
return;
}

if (!fs.existsSync(pathtmp)) {
if (!fs.mkdirSync(pathtmp)) {
return false;
}
}
});
}
return true;
}

this.set = function (name, value) {
var result = _this.read();
result[name] = value;
if (!_this.mkdirsSync(_dir)) {
return;
}
fs.writeFile(_file, JSON.stringify(result), function (err) {
if (err) return;
console.log(_file + ' is saved!');
});
}
}
module.exports = Configuration;
4 changes: 2 additions & 2 deletions app/emotions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Emotions = function(app) {
_this = this;
_app = app;
_dir_preset = path.join(__root_path, "/web/flash-core/assets/emotions");
_dir_custom = path.join(__root_path, "/../mblock-emotions");
_dir_custom = path.join(__root_path, "/../mblock-setting/mblock-emotions");
_translator = app.getTranslator();
_client = app.getClient();

Expand Down Expand Up @@ -66,7 +66,7 @@ var Emotions = function(app) {
var file = _this.pathfile(filename);
fs.unlink(file, function (err) {
if (err) {
_app.alert(_translator.map('It doesn\'t exist'));
_app.alert(_translator.map("It doesn't exist"));
return;
}
console.log(file + ' is delete!');
Expand Down
50 changes: 41 additions & 9 deletions app/firmwareUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const utils = require('./utils');
var Boards = require('./boards.js');
var app = null;
var T = null;
var checkUSB, errorStatus;
const boardFirmwareMap = {
'arduino_uno': 'uno.hex',
'arduino_leonardo': 'leonardo.hex',
Expand All @@ -21,7 +22,8 @@ const boardFirmwareMap = {
};

const boardDefaultProgramMap = {
'me/mbot_uno': 'mbot_reset.hex',
'me/mbot_uno' : 'mbot_reset.hex',
'me/orion_uno' : 'starter_factory_firmware.hex'
};

var FirmwareUploader = {
Expand Down Expand Up @@ -82,10 +84,10 @@ var FirmwareUploader = {
}
return path.join(__root_path, 'tools/arduino');
},

// 是否允许恢复出厂程序,true:允许,false:不允许
allowResetDefaultProgram: function() {
var boardName = app.getBoards().currentBoardName();
if(boardName == 'me/mbot_uno') {
if(boardName == 'me/mbot_uno' || boardName == 'me/orion_uno') {
return true;
}
return false;
Expand All @@ -97,15 +99,29 @@ var FirmwareUploader = {
},

resetDefaultProgram: function() {
var boardName = app.getBoards().currentBoardName();
var boardName = app.getBoards().currentBoardName();console.log('版:');console.log(boardName);
this.uploadWithAvrdude(boardDefaultProgramMap[boardName]);
},

/**
* 通过小内存机多次测试刷新固件经验得出超时时间,range最多2分钟,mbot最多20秒
* @param on
* @param callback
*/
uploadingWatchDog: function (on, callback) {
if (!on) return;
// mbot : me/mbot_uno , ranger : me/auriga_mega2560
var boardName = app.getBoards().currentBoardName();
var timeout = ('me/mbot_uno' === boardName) ? 20000 : 120000;
checkUSB = setInterval(function() {
callback();
}, timeout);
},

uploadWithAvrdude: function(hexFileName) {
var serialPort = app.getSerial().currentSerialPort();
var boardName = app.getBoards().currentBoardName();


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

var self = this;
console.log('upgrade firmware');
app.alert({'message':T('Uploading...'), 'hasCancel':false});
app.alert({'message':T('Uploading') + '...', 'hasCancel':false});
var command = self.getArduinoPath() + '/hardware/tools/avr/bin/avrdude';
var args = self.getAvrdudeParameter(serialPort, hexFileName);
app.getSerial().close();
var uploading = false, uploaderSuccess = false;
var avrdude = spawn(command, args, {cwd: __root_path});
avrdude.stdout.on('data', function(data){
});
avrdude.stderr.on('data', function(data){
app.logToArduinoConsole(data.toString());
app.logToArduinoConsole(data);
if(data.toString().indexOf('programmer is not responding')>=0){
avrdude.kill('SIGKILL');
}
app.alert({'message':T('Uploading')+'...'+utils.getProgressCharacter(), 'hasCancel':false});
// 第一次进入上传状态,看门狗启动,超时未完成上传即kill进程
self.uploadingWatchDog(!uploading, function () {
avrdude.kill('SIGKILL');
errorStatus = 'TIMEOUT';
app.alert({'message':T('Hardware communication timeout, please confirm whether the serial connection'), 'hasCancel':true});
clearInterval(checkUSB);
});

uploading = true;
});
avrdude.on('close', function(code){
clearInterval(checkUSB);
if ('TIMEOUT' === errorStatus) {
errorStatus = '';
return;
}
if(code == 0) {
app.alert({'message':T('Upload Succeeded'), 'hasCancel':true});
app.alert({'message':T('Upload Finish'), 'hasCancel':true});
} else {
app.alert({'message':T('Upload Failed'), 'hasCancel':true});
}
avrdude.kill('SIGKILL');
app.getSerial().connect(serialPort);
});

avrdude.on('exit', function (code) {
});
},

}
Expand Down
19 changes: 17 additions & 2 deletions app/fontSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
*/

const{MenuItem} = require('electron') ;
var _client,_size,_app;
const Configuration = require('./configuration.js');

var _client,_size,_app,_configuration;
const _fontSize = [
{label:"8"},
{label:"10"},
Expand All @@ -18,6 +20,7 @@ const _fontSize = [
function FontSize(app){
_app = app;
_client = _app.getClient();
_configuration = new Configuration();
var _translator = _app.getTranslator();
var self = this;
this.setFontSize = function (size){
Expand All @@ -40,14 +43,26 @@ function FontSize(app){
type:'checkbox',
click:function(item,focusedWindow){
self.setFontSize(item.label);
_configuration.set('setFontSize', item.label);
_app.getMenu().update();
}
})
m.submenu.insert(0,item);
}
return m;
}
this.setFontSize("12");

this.setDefaultSize = function () {
var setSize = _configuration.get('setFontSize');
if (!setSize) {
this.setFontSize("12");
} else {
this.setFontSize(setSize);
}
}

this.setDefaultSize();
// this.setFontSize("12");

}
module.exports = FontSize;
Loading

0 comments on commit abef93b

Please sign in to comment.