7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-08 06:25:30 +00:00

Merge pull request from EEVengers/electron-pipe

Electron pipe
This commit is contained in:
ratanvarghese 2021-03-23 05:24:35 -04:00 committed by GitHub
commit 3f4667d15e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 183 additions and 128 deletions

View File

@ -51,8 +51,8 @@ class Graph extends React.Component<any, any> {
</p>
</div>
<FlexibleXYPlot
yDomain={this.generator.y.getDomain()}
xDomain={this.generator.x.getDomain()}
yDomain={this.props.graph.yDomain}
xDomain={this.props.graph.xDomain}
margin={{right:0, bottom:0}}
>
<HorizontalGridLines

View File

@ -3,23 +3,37 @@ import { connect } from 'react-redux';
import MathOperators from '../../../configuration/enums/mathOperators';
import '../../../css/sidebar/widgets/mathWidget.css';
import { Plumber } from '../../../util/plumber';
class TriggerWidget extends React.Component<any, any> {
toggleMathMode = (mathEnabled: boolean) => {
let w = this.props.mathWidget;
Plumber.getInstance().handleMath(mathEnabled, w.channel1, w.channel2, w.mathOperator);
this.props.dispatch({type: 'math/toggleMathMode', payload: mathEnabled });
this.props.dispatch({type: 'vertical/toggleMathWaveform' });
}
changeChannel1 = (channelNumber: number) => {
let w = this.props.mathWidget;
if(w.channel2 != channelNumber) {
Plumber.getInstance().handleMath(w.mathEnabled, channelNumber, w.channel2, w.mathOperator);
}
this.props.dispatch({type: 'math/changeChannel1', payload: channelNumber });
}
changeChannel2 = (channelNumber: number) => {
let w = this.props.mathWidget;
if(w.channel1 != channelNumber) {
Plumber.getInstance().handleMath(w.mathEnabled, w.channel1, channelNumber, w.mathOperator);
}
this.props.dispatch({type: 'math/changeChannel2', payload: channelNumber });
}
changeOperator = (operator: MathOperators) => {
let w = this.props.mathWidget;
Plumber.getInstance().handleMath(w.mathEnabled, w.channel1, w.channel2, operator);
this.props.dispatch({type: 'math/changeOperator', payload: operator });
}
@ -55,7 +69,7 @@ class TriggerWidget extends React.Component<any, any> {
</button>
</div>
{this.props.mathWidget.mathEnabled === true &&
{this.props.mathWidget.mathEnabled === true &&
<div className="Channel1Title">
Channel 1
</div>

View File

@ -6,6 +6,7 @@ import TriggerType from '../../../configuration/enums/triggerType';
import CMD from '../../../configuration/enums/cmd';
import {Plumber, PlumberArgs} from '../../../util/plumber';
import { setChHelper } from '../../../util/setChHelper';
class TriggerWidget extends React.Component<any, any> {
@ -19,15 +20,12 @@ class TriggerWidget extends React.Component<any, any> {
}
changeChannel = (channelNumber: number) => {
let args: PlumberArgs = {
headCheck: () => true,
bodyCheck: () => true,
cmd: CMD.CMD_SetTriggerCh,
id: 0,
writeData: [channelNumber, 0]
};
Plumber.getInstance().cycle(args);
this.props.dispatch({type: 'trigger/changeChannel', payload: channelNumber})
let chStatus = (this.props.verticalWidget.settings as any[]).map(x => x.status > 0);
let setChState = setChHelper(chStatus[0], chStatus[1], chStatus[2], chStatus[3], channelNumber);
Plumber.getInstance().handleSetchState(setChState);
this.props.dispatch({type: 'vertical/setChannelOrder', payload: setChState.chOrder});
this.props.dispatch({type: 'trigger/changeChannel', payload: channelNumber});
this.props.dispatch({type: 'vertical/changeChannelStatus', payload: channelNumber});
}
// Trigger Type
@ -204,10 +202,11 @@ class TriggerWidget extends React.Component<any, any> {
}
}
function mapStateToProps(state: { triggerWidget: any, settings: any }) {
function mapStateToProps(state: { triggerWidget: any, settings: any, verticalWidget: any }) {
return {
triggerWidget: state.triggerWidget,
settings: state.settings
settings: state.settings,
verticalWidget: state.verticalWidget
};
}

View File

@ -6,7 +6,11 @@ import MeasurementType from '../../../configuration/enums/measurementType';
import ProbeMode from '../../../configuration/enums/probeMode';
import './../../../css/sidebar/widgets/verticalWidget.css';
class VerticalWidget extends React.Component<any, any> {
import { setChHelper } from '../../../util/setChHelper';
import CMD from '../../../configuration/enums/cmd';
import { Plumber, PlumberArgs } from '../../../util/plumber';
class VerticalWidget extends React.Component<any, any> {
// Active Channel
changeChannel = (channelNumber: number) => {
this.props.dispatch({type: 'vertical/changeChannel', payload: channelNumber})
@ -50,6 +54,13 @@ class VerticalWidget extends React.Component<any, any> {
}
changeChannelStatus = (channelNumber: number) => {
let chStatus = (this.props.verticalWidget.settings as any[]).map(x => x.status > 0);
chStatus[channelNumber] = !chStatus[channelNumber];
let triggerCh = this.props.triggerWidget.triggerChannel;
let setChState = setChHelper(chStatus[0], chStatus[1], chStatus[2], chStatus[3], triggerCh);
Plumber.getInstance().handleSetchState(setChState);
this.props.dispatch({type: 'vertical/setChannelOrder', payload: setChState.chOrder})
this.props.dispatch({type: 'trigger/changeChannel', payload: triggerCh});
this.props.dispatch({type: 'vertical/changeChannelStatus', payload: channelNumber});
}
@ -141,25 +152,25 @@ class VerticalWidget extends React.Component<any, any> {
</div>
<div className="VerticalWidgetAdjustBlock-TimePerDivision">
<button
<button
className="MinusButton"
onClick={() => this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].controlMode === ControlMode.Course ? this.decrementTimePerDivision() : this.decrementTimePerDivisionFine()}>
-
</button>
<label
<label
className="AdjustValueBlockTimePerDivision"
style={{color: this.props.settings.colors.channel[this.props.verticalWidget.activeChannel-1]}}
>
{this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].controlMode === ControlMode.Course
{this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].controlMode === ControlMode.Course
&& this.props.verticalWidget.timePerDivision[this.props.verticalWidget.activeChannel-1].course.value.toString()
+ this.props.verticalWidget.timePerDivision[this.props.verticalWidget.activeChannel-1].course.unit.toString() + "/div"}
{this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].controlMode === ControlMode.Fine
&& (this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].probeMode === ProbeMode.x1
{this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].controlMode === ControlMode.Fine
&& (this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].probeMode === ProbeMode.x1
? this.props.verticalWidget.timePerDivision[this.props.verticalWidget.activeChannel-1].fine.value.toString()
: this.props.verticalWidget.timePerDivision[this.props.verticalWidget.activeChannel-1].fine.x10value.toString())
+ this.props.verticalWidget.timePerDivision[this.props.verticalWidget.activeChannel-1].fine.unit.toString() + "/div"}
</label>
<button
<button
className="PlusButton"
onClick={() => this.props.verticalWidget.settings[this.props.verticalWidget.activeChannel-1].controlMode === ControlMode.Course ? this.incrementTimePerDivision() : this.incrementTimePerDivisionFine()}>
+
@ -211,19 +222,19 @@ class VerticalWidget extends React.Component<any, any> {
Offset
</div>
<div className="VerticalWidgetAdjustBlock-VerticalOffset">
<button
<button
className="MinusButton"
onClick={() => this.decrementVerticalOffset()}>
-
</button>
<label
<label
className="AdjustValueBlockVerticalOffset"
style={{color: this.props.settings.colors.channel[this.props.verticalWidget.activeChannel-1]}}
>
{this.props.verticalWidget.verticalOffset[this.props.verticalWidget.activeChannel-1].value}
{this.props.verticalWidget.verticalOffset[this.props.verticalWidget.activeChannel-1].unit}
</label>
<button
<button
className="PlusButton"
onClick={() => this.incrementVerticalOffset()}>
+
@ -258,7 +269,7 @@ class VerticalWidget extends React.Component<any, any> {
Probe Mode
</div>
<div className="VerticalWidgetProbeButtons">
<button
<button
className="x1-Button"
onClick={() => this.changeProbeMode(ProbeMode.x1)}>
<label
@ -267,7 +278,7 @@ class VerticalWidget extends React.Component<any, any> {
x1
</label>
</button>
<button
<button
className="x10-Button"
onClick={() => this.changeProbeMode(ProbeMode.x10)}>
<label
@ -325,10 +336,11 @@ class VerticalWidget extends React.Component<any, any> {
}
}
function mapStateToProps(state: { verticalWidget: any, settings: any }) {
function mapStateToProps(state: { verticalWidget: any, settings: any, triggerWidget: any }) {
return {
verticalWidget: state.verticalWidget,
settings: state.settings
settings: state.settings,
triggerWidget: state.triggerWidget
};
}

View File

@ -3,9 +3,11 @@ import GraphStatus from "../../configuration/enums/graphStatus";
const GraphInitialState = {
currentStatus: GraphStatus.On,
singleMode: false,
xDomain: [0,0],
yDomain: [0,0],
tickCount: 0
xDomain: [0,1000],
yDomain: [-128,128],
tickCount: 0,
voltageDivisions: 10, //TODO: change graph to 8, make this 8
timeDivisons: 10
};
export default GraphInitialState;

View File

@ -19,7 +19,7 @@ const VerticalWidgetInitialState = {
unit: VoltageUnit.MilliVolt
},
index: 6
},
},
{
course: {
value: DefaultValues.x1ProbeValues[6].value,
@ -31,7 +31,7 @@ const VerticalWidgetInitialState = {
unit: VoltageUnit.MilliVolt
},
index: 6
},
},
{
course: {
value: DefaultValues.x1ProbeValues[6].value,
@ -43,7 +43,7 @@ const VerticalWidgetInitialState = {
unit: VoltageUnit.MilliVolt
},
index: 6
},
},
{
course: {
value: DefaultValues.x1ProbeValues[6].value,
@ -92,22 +92,23 @@ const VerticalWidgetInitialState = {
],
verticalOffset: [
{
value: 0,
value: 0,
unit: VoltageUnit.MilliVolt
},
{
value: 0,
value: 0,
unit: VoltageUnit.MilliVolt
},
{
value: 0,
value: 0,
unit: VoltageUnit.MilliVolt
},
{
value: 0,
value: 0,
unit: VoltageUnit.MilliVolt
}
]
],
getDataChannelOrder: [1, 2, 3, 4]
};
export default VerticalWidgetInitialState;

View File

@ -21,6 +21,16 @@ export default function(state = GraphInitialState, action: {type: any, payload:
...state,
tickCount: state.tickCount + 1
}
case "graph/xDomain":
return {
...state,
xDomain: action.payload
}
case "graph/yDomain":
return {
...state,
yDomain: action.payload
}
default:
return state;
}

View File

@ -1,6 +1,6 @@
import MathWidgetInitialState from '../../initialStates/mathWidgetInitialState';
export default function(state = MathWidgetInitialState, action: {type: any, payload: any}) {
export default function(state = MathWidgetInitialState, action: {type: any, payload: any}) {
switch(action.type) {
case "math/toggleMathMode":
return {

View File

@ -55,12 +55,12 @@ export default function(state = VerticalWidgetInitialState, action: {type: any,
tmp[channelIndex].probeMode = action.payload;
tmp2 = state.timePerDivision;
tmp2[channelIndex].course.value = action.payload === ProbeMode.x1
? DefaultValues.x1ProbeValues[state.timePerDivision[channelIndex].index].value
tmp2[channelIndex].course.value = action.payload === ProbeMode.x1
? DefaultValues.x1ProbeValues[state.timePerDivision[channelIndex].index].value
: DefaultValues.x10ProbeValues[state.timePerDivision[channelIndex].index].value;
tmp2[channelIndex].course.unit = action.payload === ProbeMode.x1
? DefaultValues.x1ProbeValues[state.timePerDivision[channelIndex].index].unit
tmp2[channelIndex].course.unit = action.payload === ProbeMode.x1
? DefaultValues.x1ProbeValues[state.timePerDivision[channelIndex].index].unit
: DefaultValues.x10ProbeValues[state.timePerDivision[channelIndex].index].unit;
tmp3 = state.verticalOffset;
@ -81,7 +81,6 @@ export default function(state = VerticalWidgetInitialState, action: {type: any,
settings: tmp
};
case "vertical/changeChannelStatus":
// TODO: Call C and tell them that we want to either start getting or stop receiving data from the channel
tmp = state.settings;
var newTotalChannelsUsed = state.totalChannelsUsed;
@ -121,17 +120,17 @@ export default function(state = VerticalWidgetInitialState, action: {type: any,
tmp = state.timePerDivision;
tmp[channelIndex].index = state.timePerDivision[channelIndex].index - 1;
tmp[channelIndex].course.value = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].value
tmp[channelIndex].course.value = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].value
: DefaultValues.x10ProbeValues[tmp[channelIndex].index].value;
tmp[channelIndex].course.unit = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].unit
tmp[channelIndex].course.unit = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].unit
: DefaultValues.x10ProbeValues[tmp[channelIndex].index].unit;
tmp2 = state.verticalOffset;
tmp2[channelIndex].unit = tmp[channelIndex].course.unit;
return {
return {
...state,
timePerDivision: tmp,
verticalOffset: tmp2
@ -143,17 +142,17 @@ export default function(state = VerticalWidgetInitialState, action: {type: any,
tmp = state.timePerDivision;
tmp[channelIndex].index = state.timePerDivision[channelIndex].index + 1;
tmp[channelIndex].course.value = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].value
tmp[channelIndex].course.value = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].value
: DefaultValues.x10ProbeValues[tmp[channelIndex].index].value;
tmp[channelIndex].course.unit = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].unit
tmp[channelIndex].course.unit = state.settings[channelIndex].probeMode === ProbeMode.x1
? DefaultValues.x1ProbeValues[tmp[channelIndex].index].unit
: DefaultValues.x10ProbeValues[tmp[channelIndex].index].unit;
tmp2 = state.verticalOffset;
tmp2[channelIndex].unit = tmp[channelIndex].course.unit;
return {
return {
...state,
timePerDivision: tmp,
verticalOffset: tmp2
@ -185,6 +184,11 @@ export default function(state = VerticalWidgetInitialState, action: {type: any,
...state,
settings: tmp
}
case "vertical/setChannelOrder":
return {
...state,
getDataChannelOrder: action.payload
}
default:
return state;
}

View File

@ -1,4 +1,6 @@
import CMD from '../configuration/enums/cmd';
import { SetChState } from './setChHelper';
import MathOperators from '../configuration/enums/mathOperators';
export enum SetMathOp {
SetMath_None = 0,
@ -107,8 +109,38 @@ export class Plumber {
}
}
public makeSetMathData(lhsChan: number, rhsChan: number, op: SetMathOp) {
return [lhsChan, rhsChan, op, 0];
public handleSetchState(s: SetChState) {
let setChArgs: PlumberArgs = {
headCheck: () => true,
bodyCheck: () => true,
cmd: CMD.CMD_SetCh,
id: 0,
writeData: [s.setCh, 0]
}
let setTriggerChArgs: PlumberArgs = {
headCheck: () => true,
bodyCheck: () => true,
cmd: CMD.CMD_SetTriggerCh,
id: 0,
writeData: [s.setTriggerCh, 0]
}
this.cycle(setChArgs);
this.cycle(setTriggerChArgs);
}
public handleMath(enable: boolean, lhsChan: number, rhsChan: number, op: MathOperators) {
var protcolOp = 0;
if(enable) {
protcolOp = (op == MathOperators.Addition) ? 1 : 2;
}
let mathArgs: PlumberArgs = {
headCheck: () => true,
bodyCheck: () => true,
cmd: CMD.CMD_SetMath,
id: 0,
writeData: [lhsChan, rhsChan, protcolOp, 0]
}
this.cycle(mathArgs);
}
public decodeGetMinMax(args: PlumberArgs, a: Int8Array) {

View File

@ -1,65 +1,27 @@
import CMD from '../configuration/enums/cmd';
import { PlumberArgs, Plumber, SetMathOp } from './plumber';
class Range {
dataMin: number = 0;
dataMax: number = 0;
constructor(min: number, max: number){
this.dataMin = min;
this.dataMax = max;
}
getDomain() {
return [this.dataMin, this.dataMax];
}
}
import store from '../redux/store';
import { LineSeriesPoint } from 'react-vis';
class TestPoints {
x: Range;
y: Range;
scope_data: any[][] = []; //[ch-1] for channel, [5] for math
scope_data_max_idx = 5;
scope_data: LineSeriesPoint[][] = []; //[ch-1] for channel, [5] for math
getDataMaxCh = 5;
lastX: number = 0;
chCount: number = 4;
doMath: Boolean = true;
rampArgs: PlumberArgs;
setChArgs: PlumberArgs;
setFileArgs: PlumberArgs;
setMathArgs: PlumberArgs;
setChDone: Boolean = false;
setFileDone: Boolean = false;
setMathDone: Boolean = false;
constructor(xRange: number, yRange: number) {
this.x = new Range(0, xRange);
this.y = new Range(-yRange, yRange);
store.dispatch({type: "graph/xDomain", payload: [0, xRange]});
store.dispatch({type: "graph/yDomain", payload: [-yRange, yRange]})
for(var j = 0; j < this.scope_data_max_idx; j++) {
this.scope_data[j] = [];
for(var i = 0; i < 1; i++) {
this.scope_data[j][i] = {x: i, y: 0};
}
let state = store.getState();
for(var j = 0; j < this.getDataMaxCh; j++) {
this.scope_data[j] = [{x: 0, y: 0}];
}
this.rampArgs = {
headCheck: () => true,
bodyCheck: (a, bytesRead, body) => {
var chMax = this.effectiveChCount();
var perChannel = Math.floor(body.length/chMax);
for(var channel = 0; channel < chMax; channel++) {
for(var i = 0; i < perChannel; i++) {
this.scope_data[channel][i] = {x: i, y: body[channel*perChannel + i]};
}
}
return true;
},
cmd: CMD.CMD_GetData1,
id: 0x1F2C,
writeData: [0, 0]
};
this.setChArgs = {
headCheck: () => {
this.setChDone = true;
@ -68,7 +30,7 @@ class TestPoints {
bodyCheck: () => true,
cmd: CMD.CMD_SetCh,
id: 0,
writeData: [this.chCount, 0]
writeData: [state.verticalWidget.getDataChannelOrder.length, 0]
}
this.setFileArgs = {
@ -81,39 +43,58 @@ class TestPoints {
id: 0,
writeData: [74, 0]
}
this.setMathArgs = {
headCheck: () => {
this.setMathDone = true;
return true;
},
bodyCheck: () => true,
cmd: CMD.CMD_SetMath,
id: 0,
writeData: Plumber.getInstance().makeSetMathData(2, 4, SetMathOp.SetMath_Plus)
}
}
mountCalls() {
Plumber.getInstance().cycle(this.setChArgs);
Plumber.getInstance().cycle(this.setFileArgs);
Plumber.getInstance().cycle(this.setMathArgs);
}
update() {
if(this.setChDone && this.setFileDone && this.setMathDone) {
Plumber.getInstance().cycle(this.rampArgs);
if(this.setChDone && this.setFileDone) {
let state = store.getState();
let xLimit = state.graph.xDomain[1];
let doMath = state.mathWidget.mathEnabled as boolean;
let order = state.verticalWidget.getDataChannelOrder as number[];
let args: PlumberArgs = {
headCheck: () => true,
bodyCheck: (a, bytesRead, body) => {
var chMax = (doMath) ? order.length + 1: order.length;
var perChannel = Math.floor(body.length/chMax);
let xOffset = (this.lastX < xLimit) ? this.lastX : 0;
var cppChannel = 0;
for(var uiChannel = 0; uiChannel < this.getDataMaxCh; uiChannel++) {
let mathCh = (uiChannel == this.getDataMaxCh-1) && doMath;
let dataCh = order.includes(uiChannel + 1);
if(mathCh || dataCh) {
for(var i = 0; i < perChannel; i++) {
var x = xOffset + i;
if(x != 0 && !this.scope_data[uiChannel][x-1]) {
//Adding a channel while other channels in middle of screen
//causes an error.
break;
}
let y = body[cppChannel*perChannel + i];
this.scope_data[uiChannel][x] = {x: x, y: y};
}
cppChannel++;
}
}
this.lastX = xOffset + perChannel;
return true;
},
cmd: CMD.CMD_GetData1,
id: 0,
writeData: [0, 0]
};
Plumber.getInstance().cycle(args);
}
}
effectiveChCount() {
return (this.doMath) ? this.chCount + 1: this.chCount;
}
getData() {
var chMax = this.effectiveChCount();
console.log(this.scope_data);
return this.scope_data.slice(0, chMax);
return this.scope_data;
}
}