UNPKG

weblab-instrument

Version:
225 lines (221 loc) 6.62 kB
const propMethod = require('../dev/propMethod.js'); function MathObj() { this.temp = 0; this.disp = 'OFF'; this.type = 'dual'; this.dual = { source1: 'CH1', source2: 'CH2', operator: 'PLUS', position: '0', scale: '1', }; this.fft = { source: 'CH1', window: 'RECTANGULAR', horPosition: '0', horScale: '1', verPosition: '0', verScale: '1', mag: 'LINEAR', }; } MathObj.prototype.cmdHandler = { MathDisp: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.disp = res.toString(); return true; }, setHelper(mathObj, arg) { mathObj.disp = arg; return true; }, }, MathType: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.type = res.toString(); return true; }, setHelper(mathObj, arg) { mathObj.type = arg; return true; }, }, MathDualSour1: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.dual.source1 = res.toString(); return true; }, setHelper(mathObj, arg) { mathObj.dual.source1 = arg; return true; }, }, MathDualSour2: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.dual.source2 = res.toString(); return true; }, setHelper(mathObj, arg) { mathObj.dual.source2 = arg; return true; }, }, MathDualOper: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.dual.operator = res.toString(); return true; }, setHelper(mathObj, arg) { mathObj.dual.operator = arg; return true; }, }, MathDualScale: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.dual.scale = res.toString(); return true; }, setHelper(mathObj, arg, cb) { mathObj.dual.scale = arg.toString(); if (mathObj.temp != parseFloat(arg)) { if (typeof cb === 'function') { cb(['-500', `${mathObj.temp.toExponential()} argument does not accepte set to near one ${arg}`]); } return false; } return true; }, }, MathDualPos: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.dual.position = res.toString(); return true; }, setHelper(mathObj, arg, cb) { mathObj.dual.position = arg.toString(); if (mathObj.temp != parseFloat(arg)) { if (typeof cb === 'function') { cb(['-500', `${mathObj.temp.toExponential()} argument does not accepte set to near one ${arg}`]); } return false; } return true; }, }, MathFftSource: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.fft.source = res.toString(); return true; }, setHelper(mathObj, arg) { mathObj.fft.source = arg; return true; }, }, MathFftMag: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.fft.mag = res.toString(); return true; }, setHelper(mathObj, arg) { mathObj.fft.mag = arg; return true; }, }, MathFftWin: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.fft.window = res.toString(); return true; }, setHelper(mathObj, arg) { // console.log(MathObj); mathObj.fft.window = arg; return true; }, }, MathFftVerPos: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.fft.verPosition = res.toString(); return true; }, setHelper(mathObj, arg, cb) { mathObj.fft.verPosition = arg.toString(); if (mathObj.temp != parseFloat(arg)) { if (typeof cb === 'function') { cb(['-500', `${mathObj.temp.toExponential()} argument does not accepte set to near one ${arg}`]); } return false; } return true; }, }, MathFftVerScale: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.fft.verScale = res.toString(); return true; }, setHelper(mathObj, arg, cb) { mathObj.fft.verScale = arg.toString(); if (mathObj.temp != parseFloat(arg)) { if (typeof cb === 'function') { cb(['-500', `${mathObj.temp.toExponential()} argument does not accepte set to near one ${arg}`]); } return false; } return true; }, }, MathFftHorPos: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.fft.horPosition = res.toString(); return true; }, setHelper(mathObj, arg, cb) { mathObj.fft.horPosition = arg.toString(); if (mathObj.temp != parseFloat(arg)) { if (typeof cb === 'function') { cb(['-500', `${mathObj.temp.toExponential()} argument does not accepte set to near one ${arg}`]); } return false; } return true; }, }, MathFftHorScale: { getHandler(mathObj, res) { res = res.slice(0, -1); mathObj.fft.horScale = res.toString(); return true; }, setHelper(mathObj, arg, cb) { mathObj.fft.horScale = arg.toString(); if (mathObj.temp != parseFloat(arg)) { if (typeof cb === 'function') { cb(['-500', `${mathObj.temp.toExponential()} argument does not accepte set to near one ${arg}`]); } return false; } return true; }, }, }; exports.initMathObj = function initMathObj(id) { const mathCmd = new MathObj(); // mathCmd.cmdHandler=cmdHandler; mathCmd.prop = propMethod.CreatMethod.call(this, id); return mathCmd; };