Skip to content

Commit 3694509

Browse files
committed
Merge pull request #301 from parallaxinc/ignore-echo
Implement echo toggle functionality
2 parents 30a6dae + bf05045 commit 3694509

File tree

9 files changed

+110
-2
lines changed

9 files changed

+110
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"@phated/redux-create-store": "^0.3.0",
11-
"bs2-serial": "^0.14.1",
11+
"bs2-serial": "^0.15.0",
1212
"codemirror": "^4.13.0",
1313
"frylord": "^0.7.4",
1414
"holovisor": "^0.2.0",

src/console-store.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
const createStore = require('@phated/redux-create-store');
1010

1111
const reducers = {
12+
echo: require('./reducers/echo'),
1213
rxtx: require('./reducers/rxtx')
1314
};
1415

src/constants/action-types.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const actionTypes = {
44
SHOW_OVERLAY: 'SHOW_OVERLAY',
55
HIDE_OVERLAY: 'HIDE_OVERLAY',
66
DELETE_PROJECT_CONFIRM: 'DELETE_PROJECT_CONFIRM',
7+
ECHO_ON: 'ECHO_ON',
8+
ECHO_OFF: 'ECHO_OFF',
79
RX_ON: 'RX_ON',
810
RX_OFF: 'RX_OFF',
911
TX_ON: 'TX_ON',

src/creators/echo-off.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const {
4+
ECHO_OFF
5+
} = require('../constants/action-types');
6+
7+
function echoOff(){
8+
return {
9+
type: ECHO_OFF,
10+
payload: {}
11+
};
12+
}
13+
14+
module.exports = echoOff;

src/creators/echo-on.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const {
4+
ECHO_ON
5+
} = require('../constants/action-types');
6+
7+
function echoOn(){
8+
return {
9+
type: ECHO_ON,
10+
payload: {}
11+
};
12+
}
13+
14+
module.exports = echoOn;

src/creators/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const creators = {
2222
transmit: require('./transmit'),
2323
updateDuration: require('./update-duration'),
2424
clearTransmission: require('./clear-transmission'),
25+
echoOn: require('./echo-on'),
26+
echoOff: require('./echo-off'),
2527
// device creators
2628
connect: require('./connect'),
2729
disconnect: require('./disconnect'),

src/plugins/handlers.js

+18
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,26 @@ function handlers(app, opts, done){
482482
txOn();
483483
}
484484

485+
function toggleEcho(){
486+
const { device } = store.getState();
487+
const { echo } = consoleStore.getState();
488+
const { selected, connected } = device;
489+
if(echo){
490+
consoleStore.dispatch(creators.echoOff());
491+
}else{
492+
consoleStore.dispatch(creators.echoOn());
493+
}
494+
if(selected && connected){
495+
const board = app.getBoard(selected);
496+
board.setEcho(!echo);
497+
}
498+
}
499+
485500
function download() {
486501
const { device } = store.getState();
487502
const { selected } = device;
488503
const { filename, content } = workspace.getState();
504+
const { echo } = consoleStore.getState();
489505

490506
if(!selected){
491507
return;
@@ -514,6 +530,7 @@ function handlers(app, opts, done){
514530
board.removeListener('progress', onProgress);
515531
resetDownloadProgress();
516532
connect();
533+
board.setEcho(echo);
517534
hideOverlay();
518535
});
519536
}
@@ -653,6 +670,7 @@ function handlers(app, opts, done){
653670
reloadDevices,
654671
selectDevice,
655672
download,
673+
toggleEcho,
656674
enableAutoDownload,
657675
disableAutoDownload
658676
});

src/plugins/rxtx.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ const styles = {
3232
float: 'right',
3333
paddingTop: '3px'
3434
},
35+
echo: {
36+
display: 'inline-block',
37+
paddingTop: '3px',
38+
paddingLeft: '16px'
39+
},
40+
echoOn: {
41+
color: '#000000'
42+
},
43+
echoOff: {
44+
color: '#888888'
45+
},
3546
rx: {
3647
backgroundColor: blue
3748
},
@@ -45,13 +56,15 @@ function applyStyles(el, stylesToApply){
4556
}
4657

4758
function rxtxBar(app, opts, done){
59+
const { toggleEcho } = app.handlers;
4860

4961
let bottomBar;
5062
let rx;
5163
let tx;
64+
let echoContainer, echoLabel;
5265

5366
function onConsoleChange(){
54-
const { rxtx } = consoleStore.getState();
67+
const { rxtx, echo } = consoleStore.getState();
5568
const { flashRx, flashTx } = rxtx;
5669

5770
if(flashRx){
@@ -65,6 +78,14 @@ function rxtxBar(app, opts, done){
6578
} else {
6679
tx.style.backgroundColor = styles.indicator.backgroundColor;
6780
}
81+
82+
if(echo){
83+
applyStyles(echoContainer, styles.echoOn);
84+
echoLabel.nodeValue = 'Echo On';
85+
}else{
86+
applyStyles(echoContainer, styles.echoOff);
87+
echoLabel.nodeValue = 'Echo Off';
88+
}
6889
}
6990

7091
app.view('editor', function(el, cb){
@@ -73,6 +94,16 @@ function rxtxBar(app, opts, done){
7394
bottomBar = document.createElement('div');
7495
applyStyles(bottomBar, styles.bar);
7596

97+
echoContainer = document.createElement('span');
98+
applyStyles(echoContainer, styles.echo);
99+
applyStyles(echoContainer, styles.echoOff);
100+
bottomBar.appendChild(echoContainer);
101+
102+
echoLabel = document.createTextNode('Echo Off');
103+
echoContainer.appendChild(echoLabel);
104+
105+
echoContainer.addEventListener('click', toggleEcho, false);
106+
76107
const rxtxContainer = document.createElement('span');
77108
applyStyles(rxtxContainer, styles.rxtx);
78109
bottomBar.appendChild(rxtxContainer);

src/reducers/echo.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
/*
4+
Don't include this in the index.js because it is used only
5+
for the console-store
6+
*/
7+
8+
const {
9+
ECHO_OFF,
10+
ECHO_ON
11+
} = require('../constants/action-types');
12+
13+
const initial = false;
14+
15+
function echo(state = initial, { type }){
16+
switch(type){
17+
case ECHO_OFF:
18+
return false;
19+
case ECHO_ON:
20+
return true;
21+
default:
22+
return state;
23+
}
24+
}
25+
26+
module.exports = echo;

0 commit comments

Comments
 (0)