Skip to content

Commit 78c157e

Browse files
committed
Hardened expressions so they emit an error in the log when an exception occurs. Added reverse bias for ADC processing on ADS1x15
1 parent 306ccb4 commit 78c157e

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

boards/Controller.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,14 @@ export class Feed {
924924
constructor(feed: DeviceFeed) {
925925
this.server = connBroker.findServer(feed.connectionId);
926926
this.feed = feed;
927-
if (typeof feed.payloadExpression !== 'undefined' && feed.payloadExpression.length > 0)
928-
this.translatePayload = new Function('feed', 'value', feed.payloadExpression);
927+
if (typeof feed.payloadExpression !== 'undefined' && feed.payloadExpression.length > 0) {
928+
try {
929+
this.translatePayload = new Function('feed', 'value', feed.payloadExpression);
930+
} catch (err) {
931+
logger.error(`Script error processing payload expression ${err.message}:\n`);
932+
console.log(feed.payloadExpression);
933+
}
934+
}
929935
}
930936
public async send(dev: any) {
931937
try {

gpio/Gpio-Controller.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export class GpioController {
3333
return this;
3434
} catch (err) { logger.error(`Error stopping GPIO controller :${err.message}`); }
3535
}
36-
public reset() {
37-
this.stopAsync();
38-
this.init();
36+
public async reset() {
37+
await this.stopAsync();
38+
await this.init();
3939
}
4040
private translateState(direction: string, state: string) {
4141
switch (state) {

i2c-bus/ads1x15.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export class ads1x15 extends i2cDeviceBase {
314314
// 65355 = max
315315
// 4.096 = pga
316316
// 21,265 / 32,767 * 4.096
317-
let voltage = this.getVoltageFromValue(value, channels[i].pga);
317+
let voltage = this.getVoltageFromValue(value, channels[i].pga, channels[i].reverseBias);
318318
let valElem = this.device.values.channels.find(elem => { return elem.id === channels[i].id });
319319
if (typeof valElem !== 'undefined') {
320320
valElem.value = value;
@@ -367,12 +367,13 @@ export class ads1x15 extends i2cDeviceBase {
367367
// return value;
368368
//}
369369
}
370-
private getVoltageFromValue(value, pga) {
370+
private getVoltageFromValue(value, pga, reverseBias) {
371371
let max = ads1x15.thresholdValues[this.device.options.adcType];
372372
// positive values must be 1 less than max range value (e.g. full scale of 12 bit ADC => 2^(12-1)-1 => -2048 to 2047)
373373
max = value > 0 ? max - 1 : max;
374374
logger.silly(`${this.options.name} Convert Voltage ${value} / ${max} * ${pga} = ${value / max * pga}`);
375-
return value / max * pga; // value / mx = % of scale, scale * pga = Volts
375+
let volts = value / max * pga; // value / mx = % of scale, scale * pga = Volts
376+
return reverseBias ? pga - volts : volts;
376377
}
377378

378379
public async setOptions(opts): Promise<any> {

pages/widgets.js

+1
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,7 @@ $.ui.position.fieldTip = {
40994099
inputAttrs: { style: { width: "5rem" } }
41004100
})
41014101
line = $('<div></div>').appendTo(dlg);
4102+
$('<div></div>').appendTo(dlg).checkbox({ labelText: 'Reverse Bias', binding: 'reverseBias' });
41024103
dataBinder.bind(dlg, channel);
41034104
dlg.css({ overflow: 'visible' });
41044105
},

0 commit comments

Comments
 (0)