Skip to content

Commit

Permalink
Persist BAS output #66. Add toggle for circuit endpoints, fix Smartfa…
Browse files Browse the repository at this point in the history
…n defaults
  • Loading branch information
rstrouse committed Jun 8, 2024
1 parent e9e99a6 commit 14b2b6a
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 60 deletions.
2 changes: 2 additions & 0 deletions boards/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,8 @@ export class GpioPin extends ConfigItem {
}
public get id(): number { return this.data.id; }
public set id(val: number) { this.setDataVal('id', val); }
public get chipId(): number { return this.data.chipId || 0; }
public set chipId(val: number) { this.setDataVal('chipId', val); }
public get isActive(): boolean { return utils.makeBool(this.data.isActive); }
public set isActive(val: boolean) { this.setDataVal('isActive', val); }
public get headerId(): number { return this.data.headerId; }
Expand Down
8 changes: 8 additions & 0 deletions connections/njspc.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@
{
"binding": "isOn",
"type": "boolean"
},
{
"binding": "toggle",
"type": "boolean"
}
],
"options": [
Expand Down Expand Up @@ -415,6 +419,10 @@
{
"binding": "isOn",
"type": "boolean"
},
{
"binding": "toggle",
"type": "boolean"
}
],
"options": [
Expand Down
43 changes: 42 additions & 1 deletion devices/SequentSmartFan.json
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,48 @@
"verticalAlign": "top"
}
},
"options": [
"options": [
{
"field": {
"type": "div",
"style": {
"display": "block",
"fontSize": ".8rem"
}
},
"options": [
{
"field": {
"type": "staticField",
"labelText": "CPU Temp",
"binding": "values.cpuTemp",
"dataType": "number",
"fmtMask": "#,##0.0#",
"emptyMask": "--.-",
"units": "°",
"labelAttrs": {
"style": {
"width": "7rem",
"fontSize": ".8rem",
"verticalAlign": "middle"
}
},
"style": {
"fontSize": ".8rem",
"line-height": "1.2",
"verticalAlign": "middle"
}
}
},
{
"field": {
"binding": "values.units",
"type": "span",
"cssClass": "picSpinner-units picUnits"
}
}
]
},
{
"field": {
"type": "staticField",
Expand Down
20 changes: 19 additions & 1 deletion i2c-bus/SequentIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export class SequentIO extends i2cDeviceBase {
protected ensureIOChannels(label, type, arr, count) {
try {
for (let i = 1; i <= count; i++) {
if (typeof arr.find(elem => elem.id === i) === 'undefined') arr.push({ id: i, name: `${label} #${i}`, type: type, enabled: false });
let ch = arr.find(elem => elem.id === i);
if (typeof ch === 'undefined') arr.push({ id: i, name: `${label} #${i}`, type: type, enabled: false });
}
arr.sort((a, b) => { return a.id - b.id });
arr.length = count;
Expand Down Expand Up @@ -120,6 +121,19 @@ export class SequentIO extends i2cDeviceBase {
public get out0_10(): any[] { return typeof this.outputs.out0_10 === 'undefined' ? this.outputs.out0_10 = [] : this.outputs.out0_10; }
public get outDrain(): any[] { return typeof this.outputs.outDrain === 'undefined' ? this.outputs.outDrain = [] : this.outputs.outDrain; }
public get calibration(): any { return typeof this.calibration === 'undefined' ? this.info.calibration = {} : this.info.calibration; }
protected async initOutputs(outputs: any[], fn: (ord: number, val: number) => void) {
if (typeof fn === 'function') {
for (let i = 0; i < outputs.length; i++) {
let o = outputs[i];
if (o.enabled === true) {
if (typeof o.value === 'number') {
console.log(o);
await fn.apply(this, [o.id, o.value]);
}
}
}
}
}
protected packRS485Port(port): Buffer {
let buffer = Buffer.from([0, 0, 0, 0, 0]);
buffer.writeUInt16LE(port.baud & 0x00FFFF, 0);
Expand Down Expand Up @@ -442,6 +456,8 @@ export class SequentMegaIND extends SequentIO {
this.ensureIOChannels('OUT 4-20', '420OUT', this.out4_20, 4);
this.ensureIOChannels('IN Digital', 'DIN', this.inDigital, 4);
this.ensureIOChannels('OUT Open Drain', 'ODOUT', this.outDrain, 4);
await this.initOutputs(this.out0_10, this.set0_10Output);
await this.initOutputs(this.out4_20, this.set4_20Output);
if (this.device.isActive) await this.getRS485Port();
return Promise.resolve(true);
}
Expand Down Expand Up @@ -889,6 +905,8 @@ export class SequentMegaBAS extends SequentIO {
// Set up all the I/O channels. We want to create a values data structure for all potential inputs and outputs.
this.ensureIOChannels('IN 0-10', 'AIN', this.in0_10, 8);
this.ensureIOChannels('OUT 0-10', 'AOUT', this.out0_10, 4);
await this.initOutputs(this.out0_10, this.set0_10Output);

if (this.device.isActive) await this.getRS485Port();
return Promise.resolve(true);
}
Expand Down
14 changes: 8 additions & 6 deletions i2c-bus/SequentSmartFan_v6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,23 @@ export class SequentSmartFanV6 extends i2cDeviceBase {

protected getCpuTemp(): number {
try {
let cpuTemp: number;
if (typeof this.values.units === 'undefined') this.values.units = this.options.units || 'C';
if (this.i2c.isMock) {
return utils.convert.temperature.convertUnits(72 + (Math.round((5 * Math.random()) * 100) / 100), 'f', this.values.units);
cpuTemp = utils.convert.temperature.convertUnits(72 + (Math.round((5 * Math.random()) * 100) / 100), 'F', this.values.units);
}
if (fs.existsSync('/sys/class/thermal/thermal_zone0/temp')) {
else if (fs.existsSync('/sys/class/thermal/thermal_zone0/temp')) {
let buffer = fs.readFileSync('/sys/class/thermal/thermal_zone0/temp');
let cpuTemp: number;
cpuTemp = utils.convert.temperature.convertUnits(parseInt(buffer.toString().trim(), 10) / 1000, 'C', this.values.units);
}
if (typeof cpuTemp !== 'undefined') {
this.values.cpuTemp = cpuTemp;
let ct = utils.convert.temperature.convertUnits;
this.values.cpuTempF = ct(cpuTemp, this.values.units, 'F');
this.values.cpuTempC = ct(cpuTemp, this.values.units, 'C');
this.values.cpuTempK = ct(cpuTemp, this.values.units, 'K');

return cpuTemp;
}
return cpuTemp;
} catch (err) { logger.error(`${this.device.name} error getting cpu temp: ${err.message}`); }
}

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

0 comments on commit 14b2b6a

Please sign in to comment.