Skip to content

Commit ed10673

Browse files
committed
Merge pull request #63 from parallaxinc/serial-output-data
communicate with BS2 over serial, add output pane for data, clear data on download - closes #47, closes #48, closes #49
2 parents 2cdb5af + 389fd58 commit ed10673

File tree

5 files changed

+74
-19
lines changed

5 files changed

+74
-19
lines changed

client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ var plugins = [
3030
}
3131
},
3232
{
33-
register: require('./plugins/sidebar'),
33+
register: require('./plugins/editor'),
3434
options: {
35-
defaultProject: 'new-project'
35+
initial: ''
3636
}
3737
},
3838
{
39-
register: require('./plugins/editor'),
39+
register: require('./plugins/sidebar'),
4040
options: {
41-
initial: ''
41+
defaultProject: 'new-project'
4242
}
4343
}
4444
];

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "test"
88
},
99
"dependencies": {
10-
"bs2-serial": "^0.2.0",
10+
"bs2-serial": "^0.3.0",
1111
"codemirror": "^4.13.0",
1212
"frylord": "^0.5.0",
1313
"holovisor": "^0.2.0",
@@ -19,6 +19,7 @@
1919
"react-style": "^0.4.0",
2020
"skrim": "0.0.3",
2121
"snacks": "^0.2.0",
22+
"through2": "^0.6.5",
2223
"when": "^3.7.2"
2324
},
2425
"devDependencies": {

plugins/editor/index.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,38 @@ var CodeMirror = require('codemirror');
99
function editor(app, opts, done){
1010

1111
var codeEditor;
12+
var outputConsole;
1213

1314
var space = app.workspace;
1415

16+
function output(text){
17+
if(outputConsole){
18+
outputConsole.innerHTML += text;
19+
outputConsole.scrollTop = outputConsole.scrollHeight;
20+
}
21+
}
22+
23+
function clearOutput(){
24+
if(outputConsole){
25+
outputConsole.innerHTML = '';
26+
}
27+
}
28+
29+
output.clear = clearOutput;
30+
31+
app.expose('logger', output);
32+
1533
app.view('editor', function(el, cb){
1634
console.log('editor render');
1735

1836
if(!codeEditor){
19-
codeEditor = CodeMirror(el, {
37+
let editorContainer = document.createElement('div');
38+
editorContainer.style.display = 'flex';
39+
editorContainer.style.flex = '1';
40+
editorContainer.style.flexDirection = 'column';
41+
el.appendChild(editorContainer);
42+
43+
codeEditor = CodeMirror(editorContainer, {
2044
value: space.current.deref(),
2145
mode: 'javascript',
2246
theme: 'neo',
@@ -36,6 +60,17 @@ function editor(app, opts, done){
3660
});
3761
}
3862

63+
if(!outputConsole){
64+
outputConsole = document.createElement('pre');
65+
outputConsole.style.height = '200px';
66+
outputConsole.style.boxShadow = 'inset 0 5px 10px -5px rgba(0, 0, 0, 0.26)';
67+
outputConsole.style.backgroundColor = 'white';
68+
outputConsole.style.padding = '10px';
69+
outputConsole.style.overflow = 'auto';
70+
outputConsole.style.whiteSpace = 'pre-wrap';
71+
el.appendChild(outputConsole);
72+
}
73+
3974
cb();
4075
});
4176

plugins/sidebar/file-operations.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const when = require('when');
43
const React = require('react');
4+
const through = require('through2');
55
const { Menu, MainButton, ChildButton } = require('react-mfb-iceddev');
66

77
require('react-mfb-iceddev/mfb.css');
@@ -12,8 +12,12 @@ const DeleteConfirmOverlay = require('./overlays/delete-confirm');
1212

1313
const styles = require('./styles');
1414

15+
let boards = {};
16+
1517
const FileOperations = React.createClass({
1618
handleError: function(err){
19+
// leaving this in for better debugging of errors
20+
console.log(err);
1721
const toast = this.props.toast;
1822

1923
toast.show(err.message, { style: styles.errorToast });
@@ -67,24 +71,38 @@ const FileOperations = React.createClass({
6771
download: function(devicePath){
6872
const toast = this.props.toast;
6973
const space = this.props.workspace;
74+
const logger = this.props.logger;
7075
const overlay = this.props.overlay;
71-
const programmer = this.props.programmer;
76+
const Board = this.props.Board;
7277
const name = space.filename.deref();
78+
const source = space.current.deref();
7379

7480
if(!devicePath){
7581
return;
7682
}
7783

78-
programmer.compile({ source: space.current.deref() })
79-
.then(function(memory){
80-
var options = {
81-
path: devicePath,
82-
board: 'bs2',
83-
memory: memory
84-
};
84+
const boardOpts = {
85+
path: devicePath,
86+
revision: 'bs2',
87+
readAfterProgram: true
88+
};
89+
90+
let board;
91+
if(boards[devicePath]){
92+
board = boards[devicePath];
93+
} else {
94+
board = boards[devicePath] = new Board(boardOpts);
95+
}
96+
97+
const log = through(function(chunk, enc, cb){
98+
logger(chunk.toString());
99+
cb(null, chunk);
100+
});
85101

86-
return programmer.bootload(options);
87-
})
102+
board.compile(source)
103+
.tap(() => logger.clear())
104+
.then((memory) => board.bootload(memory))
105+
.then(() => board.read().pipe(log))
88106
.tap(() => toast.clear())
89107
.tap(() => this.handleSuccess(`'${name}' downloaded successfully`))
90108
.catch(this.handleError)

plugins/sidebar/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function sidebar(app, opts, done){
1515
const toast = app.toast;
1616
const overlay = app.overlay;
1717
const userConfig = app.userConfig;
18-
const programmer = app.bs2serial;
18+
const Board = app.bs2serial;
19+
const logger = app.logger;
1920

2021
app.view('sidebar', function(el, cb){
2122
console.log('sidebar render');
@@ -28,7 +29,7 @@ function sidebar(app, opts, done){
2829
<ListItem icon="folder" disableRipple>{space.cwd.deref()}</ListItem>
2930
{directory.map((file) => <File key={file.get('name')} workspace={space} filename={file.get('name')} temp={file.get('temp')} />)}
3031
</FileList>
31-
<FileOperations workspace={space} overlay={overlay} toast={toast} programmer={programmer} />
32+
<FileOperations workspace={space} overlay={overlay} toast={toast} Board={Board} logger={logger} />
3233
</Sidebar>
3334
);
3435

0 commit comments

Comments
 (0)