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

UI->Plumber: SetCh, SetTriggerCh

This commit is contained in:
Ratan Varghese 2021-03-23 03:57:17 -04:00
parent f69668ef4c
commit f854d7dd1a
6 changed files with 104 additions and 67 deletions
Software/waveview/src

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

@ -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

@ -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,5 @@
import CMD from '../configuration/enums/cmd';
import { SetChState } from './setChHelper';
export enum SetMathOp {
SetMath_None = 0,
@ -107,6 +108,25 @@ export class Plumber {
}
}
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 makeSetMathData(lhsChan: number, rhsChan: number, op: SetMathOp) {
return [lhsChan, rhsChan, op, 0];
}

View File

@ -5,10 +5,7 @@ import { LineSeriesPoint } from 'react-vis';
class TestPoints {
scope_data: LineSeriesPoint[][] = []; //[ch-1] for channel, [5] for math
scope_data_max_idx = 5;
chCount: number = 4;
doMath: Boolean = true;
getDataMaxCh = 5;
lastX: number = 0;
setChArgs: PlumberArgs;
@ -22,7 +19,8 @@ class TestPoints {
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++) {
let state = store.getState();
for(var j = 0; j < this.getDataMaxCh; j++) {
this.scope_data[j] = [{x: 0, y: 0}];
}
@ -34,7 +32,7 @@ class TestPoints {
bodyCheck: () => true,
cmd: CMD.CMD_SetCh,
id: 0,
writeData: [this.chCount, 0]
writeData: [state.verticalWidget.getDataChannelOrder.length, 0]
}
this.setFileArgs = {
@ -63,20 +61,28 @@ class TestPoints {
mountCalls() {
Plumber.getInstance().cycle(this.setChArgs);
Plumber.getInstance().cycle(this.setFileArgs);
Plumber.getInstance().cycle(this.setMathArgs);
//Plumber.getInstance().cycle(this.setMathArgs);
}
update() {
if(this.setChDone && this.setFileDone && this.setMathDone) {
let state = store.getState();
let xLimit = state.graph.xDomain[1];
if(this.setChDone && this.setFileDone /*&& this.setMathDone*/) {
let args: PlumberArgs = {
headCheck: () => true,
bodyCheck: (a, bytesRead, body) => {
var chMax = this.effectiveChCount();
let state = store.getState();
let xLimit = state.graph.xDomain[1];
let doMath = state.mathWidget.mathEnabled as boolean;
let order = state.verticalWidget.getDataChannelOrder as number[];
var chMax = (doMath) ? order.length + 1: order.length;
var perChannel = Math.floor(body.length/chMax);
let xOffset = (this.lastX < xLimit) ? this.lastX : 0;
for(var channel = 0; channel < chMax; channel++) {
for(var channel = 0; channel < this.getDataMaxCh; channel++) {
let mathCh = (channel == this.getDataMaxCh-1) && doMath;
let dataCh = order.includes(channel + 1);
if(!mathCh && !dataCh) {
continue;
}
for(var i = 0; i < perChannel; i++) {
let x = xOffset + i;
let y = body[channel*perChannel + i];
@ -95,13 +101,8 @@ class TestPoints {
}
}
effectiveChCount() {
return (this.doMath) ? this.chCount + 1: this.chCount;
}
getData() {
var chMax = this.effectiveChCount();
return this.scope_data.slice(0, chMax);
return this.scope_data;
}
}