Skip to content

Commit 14b2b6a

Browse files
committed
Persist BAS output #66. Add toggle for circuit endpoints, fix Smartfan defaults
1 parent e9e99a6 commit 14b2b6a

File tree

8 files changed

+138
-60
lines changed

8 files changed

+138
-60
lines changed

boards/Controller.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,8 @@ export class GpioPin extends ConfigItem {
12901290
}
12911291
public get id(): number { return this.data.id; }
12921292
public set id(val: number) { this.setDataVal('id', val); }
1293+
public get chipId(): number { return this.data.chipId || 0; }
1294+
public set chipId(val: number) { this.setDataVal('chipId', val); }
12931295
public get isActive(): boolean { return utils.makeBool(this.data.isActive); }
12941296
public set isActive(val: boolean) { this.setDataVal('isActive', val); }
12951297
public get headerId(): number { return this.data.headerId; }

connections/njspc.json

+8
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@
388388
{
389389
"binding": "isOn",
390390
"type": "boolean"
391+
},
392+
{
393+
"binding": "toggle",
394+
"type": "boolean"
391395
}
392396
],
393397
"options": [
@@ -415,6 +419,10 @@
415419
{
416420
"binding": "isOn",
417421
"type": "boolean"
422+
},
423+
{
424+
"binding": "toggle",
425+
"type": "boolean"
418426
}
419427
],
420428
"options": [

devices/SequentSmartFan.json

+42-1
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,48 @@
20782078
"verticalAlign": "top"
20792079
}
20802080
},
2081-
"options": [
2081+
"options": [
2082+
{
2083+
"field": {
2084+
"type": "div",
2085+
"style": {
2086+
"display": "block",
2087+
"fontSize": ".8rem"
2088+
}
2089+
},
2090+
"options": [
2091+
{
2092+
"field": {
2093+
"type": "staticField",
2094+
"labelText": "CPU Temp",
2095+
"binding": "values.cpuTemp",
2096+
"dataType": "number",
2097+
"fmtMask": "#,##0.0#",
2098+
"emptyMask": "--.-",
2099+
"units": "°",
2100+
"labelAttrs": {
2101+
"style": {
2102+
"width": "7rem",
2103+
"fontSize": ".8rem",
2104+
"verticalAlign": "middle"
2105+
}
2106+
},
2107+
"style": {
2108+
"fontSize": ".8rem",
2109+
"line-height": "1.2",
2110+
"verticalAlign": "middle"
2111+
}
2112+
}
2113+
},
2114+
{
2115+
"field": {
2116+
"binding": "values.units",
2117+
"type": "span",
2118+
"cssClass": "picSpinner-units picUnits"
2119+
}
2120+
}
2121+
]
2122+
},
20822123
{
20832124
"field": {
20842125
"type": "staticField",

i2c-bus/SequentIO.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export class SequentIO extends i2cDeviceBase {
9191
protected ensureIOChannels(label, type, arr, count) {
9292
try {
9393
for (let i = 1; i <= count; i++) {
94-
if (typeof arr.find(elem => elem.id === i) === 'undefined') arr.push({ id: i, name: `${label} #${i}`, type: type, enabled: false });
94+
let ch = arr.find(elem => elem.id === i);
95+
if (typeof ch === 'undefined') arr.push({ id: i, name: `${label} #${i}`, type: type, enabled: false });
9596
}
9697
arr.sort((a, b) => { return a.id - b.id });
9798
arr.length = count;
@@ -120,6 +121,19 @@ export class SequentIO extends i2cDeviceBase {
120121
public get out0_10(): any[] { return typeof this.outputs.out0_10 === 'undefined' ? this.outputs.out0_10 = [] : this.outputs.out0_10; }
121122
public get outDrain(): any[] { return typeof this.outputs.outDrain === 'undefined' ? this.outputs.outDrain = [] : this.outputs.outDrain; }
122123
public get calibration(): any { return typeof this.calibration === 'undefined' ? this.info.calibration = {} : this.info.calibration; }
124+
protected async initOutputs(outputs: any[], fn: (ord: number, val: number) => void) {
125+
if (typeof fn === 'function') {
126+
for (let i = 0; i < outputs.length; i++) {
127+
let o = outputs[i];
128+
if (o.enabled === true) {
129+
if (typeof o.value === 'number') {
130+
console.log(o);
131+
await fn.apply(this, [o.id, o.value]);
132+
}
133+
}
134+
}
135+
}
136+
}
123137
protected packRS485Port(port): Buffer {
124138
let buffer = Buffer.from([0, 0, 0, 0, 0]);
125139
buffer.writeUInt16LE(port.baud & 0x00FFFF, 0);
@@ -442,6 +456,8 @@ export class SequentMegaIND extends SequentIO {
442456
this.ensureIOChannels('OUT 4-20', '420OUT', this.out4_20, 4);
443457
this.ensureIOChannels('IN Digital', 'DIN', this.inDigital, 4);
444458
this.ensureIOChannels('OUT Open Drain', 'ODOUT', this.outDrain, 4);
459+
await this.initOutputs(this.out0_10, this.set0_10Output);
460+
await this.initOutputs(this.out4_20, this.set4_20Output);
445461
if (this.device.isActive) await this.getRS485Port();
446462
return Promise.resolve(true);
447463
}
@@ -889,6 +905,8 @@ export class SequentMegaBAS extends SequentIO {
889905
// Set up all the I/O channels. We want to create a values data structure for all potential inputs and outputs.
890906
this.ensureIOChannels('IN 0-10', 'AIN', this.in0_10, 8);
891907
this.ensureIOChannels('OUT 0-10', 'AOUT', this.out0_10, 4);
908+
await this.initOutputs(this.out0_10, this.set0_10Output);
909+
892910
if (this.device.isActive) await this.getRS485Port();
893911
return Promise.resolve(true);
894912
}

i2c-bus/SequentSmartFan_v6.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,23 @@ export class SequentSmartFanV6 extends i2cDeviceBase {
295295

296296
protected getCpuTemp(): number {
297297
try {
298+
let cpuTemp: number;
299+
if (typeof this.values.units === 'undefined') this.values.units = this.options.units || 'C';
298300
if (this.i2c.isMock) {
299-
return utils.convert.temperature.convertUnits(72 + (Math.round((5 * Math.random()) * 100) / 100), 'f', this.values.units);
301+
cpuTemp = utils.convert.temperature.convertUnits(72 + (Math.round((5 * Math.random()) * 100) / 100), 'F', this.values.units);
300302
}
301-
if (fs.existsSync('/sys/class/thermal/thermal_zone0/temp')) {
303+
else if (fs.existsSync('/sys/class/thermal/thermal_zone0/temp')) {
302304
let buffer = fs.readFileSync('/sys/class/thermal/thermal_zone0/temp');
303-
let cpuTemp: number;
304305
cpuTemp = utils.convert.temperature.convertUnits(parseInt(buffer.toString().trim(), 10) / 1000, 'C', this.values.units);
306+
}
307+
if (typeof cpuTemp !== 'undefined') {
305308
this.values.cpuTemp = cpuTemp;
306309
let ct = utils.convert.temperature.convertUnits;
307310
this.values.cpuTempF = ct(cpuTemp, this.values.units, 'F');
308311
this.values.cpuTempC = ct(cpuTemp, this.values.units, 'C');
309312
this.values.cpuTempK = ct(cpuTemp, this.values.units, 'K');
310-
311-
return cpuTemp;
312313
}
314+
return cpuTemp;
313315
} catch (err) { logger.error(`${this.device.name} error getting cpu temp: ${err.message}`); }
314316
}
315317

@@ -331,7 +333,7 @@ export class SequentSmartFanV6 extends i2cDeviceBase {
331333
await this.setFanPower(); //not a reading; but set the value and then make sure it is set properly.
332334
await this.getCpuTemp();
333335
await this.getFanPower();
334-
if (this.values.fanPower !== _values.fanPower || this.values.fanPowerFnVal !== _values.fanPowerFnVal) {
336+
if (this.values.fanPower !== _values.fanPower || this.values.fanPowerFnVal !== _values.fanPowerFnVal || this.values.cpuTemp !== _values.cpuTemp) {
335337
webApp.emitToClients('i2cDataValues', { bus: this.i2c.busNumber, address: this.device.address, values: this.values });
336338
}
337339
this.emitFeeds();

0 commit comments

Comments
 (0)