7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-22 17:43:44 +00:00

UI->Plumber: Min/Max

This commit is contained in:
Ratan Varghese 2021-03-21 22:53:53 -04:00
parent 1e95d6ae37
commit eb50447a9a
3 changed files with 99 additions and 28 deletions
Software/waveview/src
components/sidebar/widgets
redux/reducers/widgets
util

View File

@ -3,7 +3,54 @@ import { connect } from 'react-redux';
import MathType from '../../../configuration/enums/mathType';
import './../../../css/sidebar/widgets/measurementsWidget.css';
import {Plumber, PlumberArgs, CMD} from '../../../util/plumber';
class MeasurementsWidget extends React.Component<any, any> {
timerID: number = 0;
componentDidMount() {
this.timerID = window.setInterval(
() => {
if(!this.props.graph.singleMode) {
this.update();
}
},
1000
);
}
update() {
//TODO: unit analysis
let channels = this.props.measurementsWidget.displayChannel as boolean[];
let channelNum = channels.map(v => v ? 1 : 0) as number[];
if(channelNum.reduce((a, b) => a + b) == 0) {
return; //Don't bother C if we don't need to.
}
let maxArgs: PlumberArgs = {
headCheck: () => true,
bodyCheck: (args, bytesRead, body) => {
let decoded = Plumber.getInstance().decodeGetMinMax(args, body);
this.props.dispatch({type: 'measurements/setMax', payload: decoded });
return true;
},
cmd: CMD.CMD_GetMax,
id: 0,
writeData: channelNum
}
let minArgs: PlumberArgs = {
headCheck: () => true,
bodyCheck: (args, bytesRead, body) => {
let decoded = Plumber.getInstance().decodeGetMinMax(args, body);
this.props.dispatch({type: 'measurements/setMin', payload: decoded });
return true;
},
cmd: CMD.CMD_GetMin,
id: 0,
writeData: channelNum
}
Plumber.getInstance().cycle(maxArgs);
Plumber.getInstance().cycle(minArgs);
}
measureChannel = (channelNumber: number) => {
this.props.dispatch({type: 'measurements/selectChannel', payload: channelNumber });
@ -58,31 +105,31 @@ class MeasurementsWidget extends React.Component<any, any> {
</button>
</div>
{this.props.measurementsWidget.displayChannel[0] === true &&
{this.props.measurementsWidget.displayChannel[0] === true &&
<div className="Channel1Measurements-Title">
CH1 Measurements
</div>
}
{this.props.measurementsWidget.displayChannel[0] === true &&
{this.props.measurementsWidget.displayChannel[0] === true &&
<div className="Channel1Measurements">
<label
<label
className="Channel1-MaxLabel"
style={{color: this.props.settings.colors.channel[0]}}>
{MathType.Max}
</label>
<label
<label
className="Channel1-MaxValue"
style={{color: this.props.settings.colors.channel[0]}}>
{this.props.measurementsWidget.max[0].value}
{this.props.measurementsWidget.max[0].unit}
</label>
<div className="ClearBlock"></div>
<label
<label
className="Channel1-MinLabel"
style={{color: this.props.settings.colors.channel[0]}}>
{MathType.Min}
</label>
<label
<label
className="Channel1-MinValue"
style={{color: this.props.settings.colors.channel[0]}}>
{this.props.measurementsWidget.min[0].value}
@ -92,31 +139,31 @@ class MeasurementsWidget extends React.Component<any, any> {
</div>
}
{this.props.measurementsWidget.displayChannel[1] === true &&
{this.props.measurementsWidget.displayChannel[1] === true &&
<div className="Channel2Measurements-Title">
CH2 Measurements
</div>
}
{this.props.measurementsWidget.displayChannel[1] === true &&
{this.props.measurementsWidget.displayChannel[1] === true &&
<div className="Channel2Measurements">
<label
<label
className="Channel2-MaxLabel"
style={{color: this.props.settings.colors.channel[1]}}>
{MathType.Max}
</label>
<label
<label
className="Channel2-MaxValue"
style={{color: this.props.settings.colors.channel[1]}}>
{this.props.measurementsWidget.max[1].value}
{this.props.measurementsWidget.max[1].unit}
</label>
<div className="ClearBlock"></div>
<label
<label
className="Channel2-MinLabel"
style={{color: this.props.settings.colors.channel[1]}}>
{MathType.Min}
</label>
<label
<label
className="Channel2-MinValue"
style={{color: this.props.settings.colors.channel[1]}}>
{this.props.measurementsWidget.min[1].value}
@ -126,31 +173,31 @@ class MeasurementsWidget extends React.Component<any, any> {
</div>
}
{this.props.measurementsWidget.displayChannel[2] === true &&
{this.props.measurementsWidget.displayChannel[2] === true &&
<div className="Channel3Measurements-Title">
CH3 Measurements
</div>
}
{this.props.measurementsWidget.displayChannel[2] === true &&
{this.props.measurementsWidget.displayChannel[2] === true &&
<div className="Channel3Measurements">
<label
<label
className="Channel3-MaxLabel"
style={{color: this.props.settings.colors.channel[2]}}>
{MathType.Max}
</label>
<label
<label
className="Channel3-MaxValue"
style={{color: this.props.settings.colors.channel[2]}}>
{this.props.measurementsWidget.max[2].value}
{this.props.measurementsWidget.max[2].unit}
</label>
<div className="ClearBlock"></div>
<label
<label
className="Channel3-MinLabel"
style={{color: this.props.settings.colors.channel[2]}}>
{MathType.Min}
</label>
<label
<label
className="Channel3-MinValue"
style={{color: this.props.settings.colors.channel[2]}}>
{this.props.measurementsWidget.min[2].value}
@ -160,31 +207,31 @@ class MeasurementsWidget extends React.Component<any, any> {
</div>
}
{this.props.measurementsWidget.displayChannel[3] === true &&
{this.props.measurementsWidget.displayChannel[3] === true &&
<div className="Channel4Measurements-Title">
CH4 Measurements
</div>
}
{this.props.measurementsWidget.displayChannel[3] === true &&
{this.props.measurementsWidget.displayChannel[3] === true &&
<div className="Channel4Measurements">
<label
<label
className="Channel4-MaxLabel"
style={{color: this.props.settings.colors.channel[3]}}>
{MathType.Max}
</label>
<label
<label
className="Channel4-MaxValue"
style={{color: this.props.settings.colors.channel[3]}}>
{this.props.measurementsWidget.max[3].value}
{this.props.measurementsWidget.max[3].unit}
</label>
<div className="ClearBlock"></div>
<label
<label
className="Channel4-MinLabel"
style={{color: this.props.settings.colors.channel[3]}}>
{MathType.Min}
</label>
<label
<label
className="Channel4-MinValue"
style={{color: this.props.settings.colors.channel[3]}}>
{this.props.measurementsWidget.min[3].value}
@ -199,10 +246,11 @@ class MeasurementsWidget extends React.Component<any, any> {
}
}
function mapStateToProps(state: { measurementsWidget: any, settings: any }) {
function mapStateToProps(state: { measurementsWidget: any, settings: any, graph: any }) {
return {
measurementsWidget: state.measurementsWidget,
settings: state.settings
settings: state.settings,
graph: state.graph
};
}

View File

@ -1,6 +1,7 @@
import MeasurementsWidgetInitialState from '../../initialStates/measurementsWidgetInitialState';
import { MaxMinResult } from '../../../util/plumber';
export default function(state = MeasurementsWidgetInitialState, action: {type: any, payload: any}) {
export default function(state = MeasurementsWidgetInitialState, action: {type: any, payload: any}) {
var tmp;
switch(action.type) {
@ -12,6 +13,28 @@ export default function(state = MeasurementsWidgetInitialState, action: {type: a
...state,
displayChannel: tmp
};
case "measurements/setMax":
//TODO: unit analysis
let setMaxPayload = action.payload as MaxMinResult[];
tmp = state.max
for(let maxItem of setMaxPayload) {
tmp[maxItem.ch - 1].value = maxItem.y;
}
return {
...state,
max: tmp
}
case "measurements/setMin":
//TODO: unit analysis
let setMinPayload = action.payload as MaxMinResult[];
tmp = state.min
for(let minItem of setMinPayload) {
tmp[minItem.ch - 1].value = minItem.y;
}
return {
...state,
min: tmp
}
default:
return state;
}

View File

@ -84,7 +84,7 @@ class TestConf {
else {
Plumber.getInstance().cycle(this.setWinArgs);
}*/
Plumber.getInstance().cycle(this.getMinArgs);
//Plumber.getInstance().cycle(this.getMinArgs);
}
}