Skip to content

Commit

Permalink
Logic analyser UI improved, recording added (fossasia#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pipe-Runner authored and mariobehling committed Aug 31, 2019
1 parent 5599b4d commit d7796bb
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 37 deletions.
3 changes: 3 additions & 0 deletions background_tasks/playback.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
case 'FETCH_ROB_ARM':
ipcRenderer.send('FETCH_ROB_ARM');
break;
case 'FETCH_LA':
ipcRenderer.send('FETCH_LA');
break;
case 'DATA_WRITING_STATUS':
ipcRenderer.send('DATA_WRITING_STATUS', parsedJSON);
break;
Expand Down
4 changes: 4 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ ipcMain.on('DATA_WRITING_STATUS', (event, args) => {
ipcMain.on('FETCH_ROB_ARM', (event, args) => {
mainWindow.webContents.send('FETCH_ROB_ARM', args);
});

ipcMain.on('FETCH_LA', (event, args) => {
mainWindow.webContents.send('FETCH_LA', args);
});
21 changes: 21 additions & 0 deletions scripts/playback_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import time
import json
from playback_robot import PlaybackRobot
from playback_la import LA

playbackRobot = PlaybackRobot()
la = LA()


def main():
Expand All @@ -18,6 +20,11 @@ def main():
print(json.dumps(output))
sys.stdout.flush()

if command == 'SAVE_DATA_LA':
output = {'type': 'FETCH_LA'}
print(json.dumps(output))
sys.stdout.flush()

if command == 'WRITE_ROB_ARM':
servo1 = parsed_stream_data['servo1']
servo2 = parsed_stream_data['servo2']
Expand All @@ -26,6 +33,20 @@ def main():
data_path = parsed_stream_data['dataPath']
playbackRobot.write(data_path, servo1, servo2, servo3, servo4)

if command == 'WRITE_LA':
la_1_voltage = parsed_stream_data['LA1Voltage']
la_2_voltage = parsed_stream_data['LA2Voltage']
la_3_voltage = parsed_stream_data['LA3Voltage']
la_4_voltage = parsed_stream_data['LA4Voltage']
la_1_time = parsed_stream_data['LA1Time']
la_2_time = parsed_stream_data['LA2Time']
la_3_time = parsed_stream_data['LA3Time']
la_4_time = parsed_stream_data['LA4Time']
number_of_channels = parsed_stream_data['numberOfChannels']
data_path = parsed_stream_data['dataPath']
la.write(data_path, number_of_channels, la_1_voltage, la_1_time,
la_2_voltage, la_2_time, la_3_voltage, la_3_time, la_4_voltage, la_4_time,)

if command == 'KILL':
exit()

Expand Down
29 changes: 29 additions & 0 deletions scripts/playback_la.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import time
import datetime
import sys
import json


class LA:
def write(self, data_path, number_of_channels, la_1_voltage, la_1_time,
la_2_voltage, la_2_time, la_3_voltage, la_3_time, la_4_voltage, la_4_time):
file_name = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S:000")
file_pointed = open(data_path + '/' + file_name + '.csv', "w+")
file_pointed.write("%s, %s \n\n" % (
'LogicAnalyzer', str(datetime.datetime.now())))
file_pointed.write(
"Number of Channels, Voltage 1, Time 1, Voltage 2, Time 2, Voltage 3, Time 3, Voltage 4, Time 4\n")
file_pointed.write(
"%s, %s, %s, %s, %s, %s, %s, %s, %s\n" % (
str(number_of_channels),
' '.join(map(str, la_1_voltage)), ' '.join(
map(str, la_1_time)),
' '.join(map(str, la_2_voltage)), ' '.join(
map(str, la_2_time)),
' '.join(map(str, la_3_voltage)), ' '.join(
map(str, la_3_time)),
' '.join(map(str, la_4_voltage)), ' '.join(map(str, la_4_time)),))
file_pointed.close()
print(json.dumps({'type': 'DATA_WRITING_STATUS',
'message': 'Data saved', }))
sys.stdout.flush()
9 changes: 7 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ThemeProvider } from 'styled-components';
import Appshell from './components/Appshell';
import Home from './screen/Home';
import Oscilloscope from './screen/Oscilloscope';
import LogicAnalyser from './screen/LogicAnalyser';
import LogicAnalyzer from './screen/LogicAnalyzer';
import PowerSource from './screen/PowerSource';
import WaveGenerator from './screen/WaveGenerator';
import Multimeter from './screen/Multimeter';
Expand Down Expand Up @@ -207,7 +207,12 @@ class App extends Component {
/>
)}
/>
<Route path="/logicanalyser" component={LogicAnalyser} />
<Route
path="/logicanalyzer"
render={props => (
<LogicAnalyzer {...props} dataPath={dataPath} />
)}
/>
<Route
path="/powersource/:filePath?"
render={props => (
Expand Down
18 changes: 18 additions & 0 deletions src/components/Appshell/Appshell.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ const Appshell = ({
<SaveIcon />
</IconButton>
);
case '/logicanalyzer':
return (
<IconButton
className={classes.iconButton}
size="medium"
disabled={!device.isConnected}
onClick={() => {
loadBalancer.start(ipcRenderer, 'playback');
setTimeout(() => {
loadBalancer.sendData(ipcRenderer, 'playback', {
command: 'SAVE_DATA_LA',
});
}, 500);
}}
>
<SaveIcon />
</IconButton>
);
case '/multimeter':
return isWriting ? (
<IconButton
Expand Down
8 changes: 4 additions & 4 deletions src/components/Icons/PSLabIcons.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import OscilloscopeSvg from '../../resources/oscilloscope.svg';
import LogicAnalyserSvg from '../../resources/logic_analyzer.svg';
import LogicAnalyzerSvg from '../../resources/logic_analyzer.svg';
import PowerSourceSvg from '../../resources/power_source.svg';
import WaveGeneratorSvg from '../../resources/wave_generator.svg';
import MultimeterSvg from '../../resources/multimeter.svg';
import SensorsSvg from '../../resources/sensors.svg';
import OscilloscopeRedSvg from '../../resources/oscilloscope_red.svg';
import LogicAnalyserRedSvg from '../../resources/logic_analyzer_red.svg';
import LogicAnalyzerRedSvg from '../../resources/logic_analyzer_red.svg';
import PowerSourceRedSvg from '../../resources/power_source_red.svg';
import WaveGeneratorRedSvg from '../../resources/wave_generator_red.svg';
import MultimeterRedSvg from '../../resources/multimeter_red.svg';
Expand All @@ -24,14 +24,14 @@ export const OscilloscopeIcon = ({ size, color }) => {
);
};

export const LogicAnalyserIcon = ({ size, color }) => {
export const LogicAnalyzerIcon = ({ size, color }) => {
return (
<img
style={{
height: size,
width: 'auto',
}}
src={color === 'red' ? LogicAnalyserRedSvg : LogicAnalyserSvg}
src={color === 'red' ? LogicAnalyzerRedSvg : LogicAnalyzerSvg}
/>
);
};
Expand Down
9 changes: 4 additions & 5 deletions src/screen/Home/components/Tabs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';
import { Settings as SettingIcon, TabRounded } from '@material-ui/icons';
import { Scrollbars } from 'react-custom-scrollbars';
import InstrumentCard from './InstrumentCard';
import { TabsContainer, TabsWrapper, TabsRow } from './Tabs.styles';
import {
OscilloscopeIcon,
LogicAnalyserIcon,
LogicAnalyzerIcon,
WaveGeneratorIcon,
PowerSourceIcon,
MultimeterIcon,
Expand All @@ -25,10 +24,10 @@ const Tabs = () => {
redirectPath={'/oscilloscope'}
/>
<InstrumentCard
icon={<LogicAnalyserIcon size={'10em'} />}
title={'Logic Analyser'}
icon={<LogicAnalyzerIcon size={'10em'} />}
title={'Logic Analyzer'}
description={'Captures and displays signals from digital systems'}
redirectPath={'/logicanalyser'}
redirectPath={'/logicanalyzer'}
/>
</TabsWrapper>
</TabsRow>
Expand Down
6 changes: 3 additions & 3 deletions src/screen/LoggedData/LoggedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@material-ui/icons';
import {
OscilloscopeIcon,
LogicAnalyserIcon,
LogicAnalyzerIcon,
WaveGeneratorIcon,
PowerSourceIcon,
MultimeterIcon,
Expand Down Expand Up @@ -133,8 +133,8 @@ class LoggedData extends Component {
switch (device) {
case 'Oscilloscope':
return <OscilloscopeIcon color="red" size={'2em'} />;
case 'LogicAnalyser':
return <LogicAnalyserIcon color="red" size={'2em'} />;
case 'LogicAnalyzer':
return <LogicAnalyzerIcon color="red" size={'2em'} />;
case 'WaveGenerator':
return <WaveGeneratorIcon color="red" size={'2em'} />;
case 'PowerSource':
Expand Down
3 changes: 0 additions & 3 deletions src/screen/LogicAnalyser/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const electron = window.require('electron');
const { ipcRenderer } = electron;
const loadBalancer = window.require('electron-load-balancer');

class LogicAnalyser extends Component {
class LogicAnalyzer extends Component {
constructor(props) {
super(props);
this.state = {
Expand Down Expand Up @@ -212,6 +212,7 @@ class LogicAnalyser extends Component {
isReading={isReading}
numberOfChannels={numberOfChannels}
toggleRead={this.toggleRead}
dataPath={this.props.dataPath}
/>
}
/>
Expand All @@ -226,4 +227,4 @@ const mapStateToProps = state => ({
export default connect(
mapStateToProps,
null,
)(LogicAnalyser);
)(LogicAnalyzer);
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import React from 'react';
import ReadIcon from '@material-ui/icons/PlayCircleFilled';
import StopIcon from '@material-ui/icons/PauseCircleFilled';
import RecordIcon from '@material-ui/icons/RadioButtonChecked';
import { Button } from '@material-ui/core';
import { withStyles } from '@material-ui/core/styles';
import { ButtonWrapper } from './ActionButtons.styles';
Expand All @@ -19,24 +16,11 @@ const ActionButtons = ({ isConnected, isReading, toggleRead, classes }) => {
fullWidth={true}
variant="contained"
size="large"
color="default"
disabled={!isConnected}
onClick={toggleRead}
style={{ color: '#d32f2f' }}
>
{isReading ? (
<StopIcon style={{ fontSize: 20 }} />
) : (
<ReadIcon style={{ fontSize: 20 }} />
)}
</Button>
<Button
className={classes.buttonMargin}
fullWidth={true}
variant="contained"
size="large"
color="default"
>
<RecordIcon style={{ fontSize: 20 }} />
{isReading ? <b>ANALYZING</b> : <b>ANALYZE</b>}
</Button>
</ButtonWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { GraphWrapper, ProgressWrapper } from './Settings.styles';

const electron = window.require('electron');
const { ipcRenderer } = electron;
const loadBalancer = window.require('electron-load-balancer');

class Graph extends Component {
constructor(props) {
Expand Down Expand Up @@ -58,10 +59,32 @@ class Graph extends Component {
toggleRead();
}
});

ipcRenderer.on('FETCH_LA', (event, args) => {
const { LA1Data, LA2Data, LA3Data, LA4Data } = this.state;
const { dataPath, numberOfChannels } = this.props;
loadBalancer.sendData(ipcRenderer, 'playback', {
command: 'WRITE_LA',
LA1Voltage: LA1Data ? LA1Data.map(item => item.voltage) : [],
LA1Time: LA1Data ? LA1Data.map(item => item.time) : [],
LA2Voltage: LA2Data ? LA2Data.map(item => item.voltage) : [],
LA2Time: LA2Data ? LA2Data.map(item => item.time) : [],
LA3Voltage: LA3Data ? LA3Data.map(item => item.voltage) : [],
LA3Time: LA3Data ? LA3Data.map(item => item.time) : [],
LA4Voltage: LA4Data ? LA4Data.map(item => item.voltage) : [],
LA4Time: LA4Data ? LA4Data.map(item => item.time) : [],
numberOfChannels,
dataPath,
});
setTimeout(() => {
loadBalancer.stop(ipcRenderer, 'playback');
}, 500);
});
}

componentWillUnmount() {
ipcRenderer.removeAllListeners('LA_DATA');
ipcRenderer.removeAllListeners('FETCH_LA');
}

render() {
Expand Down
3 changes: 3 additions & 0 deletions src/screen/LogicAnalyzer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import LogicAnalyzer from './LogicAnalyzer';

export default LogicAnalyzer;

0 comments on commit d7796bb

Please sign in to comment.