Skip to content

Commit ecaaf14

Browse files
committed
Prep 0.4.0. Initial iSpindel support
1 parent 4a87b34 commit ecaaf14

File tree

11 files changed

+36
-62
lines changed

11 files changed

+36
-62
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TEST_FILES = test-status.js \
2727

2828
DESTDIR ?=
2929

30-
PKGVERSION ?= 0.3.2
30+
PKGVERSION ?= 0.4.0
3131

3232
# Where any app files are installed
3333
RUNDIR = /usr/share/brewable

makeself.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
NODEEXE=$(which node)
44
BREWTEMPDIR=`mktemp -d /tmp/brewtemp.XXXXXX` || exit 1
55
TARGET=$(pwd)/brewable
6-
VERSION=0.3.2
6+
VERSION=0.4.0
77

88
echo './node brewableserverbundle.js "$@"' > $BREWTEMPDIR/run.sh
99
chmod a+x $BREWTEMPDIR/run.sh

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"clean": "rm -r build/*"
99
},
1010
"name": "brewable",
11-
"version": "0.3.2",
11+
"version": "0.4.0",
1212
"description": "Nodejs version of brewable",
1313
"main": "src/scripts/brewable.js",
1414
"devDependencies": {

src/scripts/modules/configuration.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import fs from "fs";
22
import mkdirp from "mkdirp";
33
import path from 'path';
4-
var home = require('os').homedir();
4+
import os from 'os';
55

6+
//var home = os.homedir();
67

78
var defaultConfigValues = function() {
89
return {
@@ -19,7 +20,7 @@ var defaultConfigValues = function() {
1920
function Configuration (passed_options) {
2021
var options = passed_options || {};
2122
this._project = options.name || 'brewable';
22-
this._projectConfigDir = path.join(home, this._project);
23+
this._projectConfigDir = path.join(os.homedir(), this._project);
2324
this.topicDirs = ['jobs', 'history', 'archive'];
2425
this._configFileName = path.join(this._projectConfigDir, this._project + '.conf');
2526
this._configuration = {};

src/scripts/modules/cpuinfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(https://sourceforge.net/p/raspberry-gpio-python/code/ci/default/tree/source/cpuinfo.c)
44
*/
55

6-
var fs = require("fs");
6+
import fs from "fs";
77

88
function cpuinfo () {
99
this.possibleHardware = [

src/scripts/modules/ds18b20.js

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ const FUDGE = Symbol();
66
// ds18b20Device object
77
class ds18b20Device {
88
constructor (val) {
9-
//this.name = val;
10-
//this.id = val;
119
this[DSNAME] = val;
12-
this[FUDGE] = parseFloat(0.7);
10+
this[FUDGE] = parseFloat(0.0);
1311

14-
console.log("ds18b20Device constructor() name = " + this.name);
15-
16-
//console.log('New ds18b20Device with id = ' + this.id + ', fudge = ' + this.fudge);
12+
console.log('New ds18b20Device with id = ' + this.id + ', fudge = ' + this.fudge);
1713
}
1814

1915
// Return a list of sensor devices
@@ -36,22 +32,22 @@ class ds18b20Device {
3632
get id () { return this[DSNAME]; }
3733

3834
set fudge (fudgeFactor) {
39-
this[FUDGE] = fudgeFactor;
35+
this[FUDGE] = parseFloat(fudgeFactor);
4036
}
4137
get fudge () {
4238
return this[FUDGE];
4339
}
4440

45-
get temp () {
41+
getTemp () {
4642
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
4743
var data = fs.readFileSync(dpath, 'utf8');
48-
console.log('(ds18b20Device) ' + this.id + ' data = ' + data);
49-
console.log('(ds18b20Device) fudge ' + this.fudge);
50-
console.log('(ds18b20Device) ' + parseFloat(data.split(' ')[20].split('=')[1]) / 1000);
5144
return parseFloat(this.fudge) + parseFloat(data.split(' ')[20].split('=')[1]) / 1000;
5245
}
5346

5447
getTempAsync (callback) {
48+
if (!arguments.length || arguments.length && typeof arguments[0] !== "function") {
49+
return this.getTemp();
50+
}
5551
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
5652
var id = this.id;
5753
var fudge = this.fudge;
@@ -65,31 +61,12 @@ class ds18b20Device {
6561
});
6662
}
6763

64+
get temp () {
65+
return this.getTemp();
66+
}
67+
6868
}
6969
export default ds18b20Device;
7070

7171

72-
/*
73-
ds18b20Device.prototype.getTempAsync = function (callback) {
74-
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
75-
var id = this.id;
76-
var fudge = parseFloat(this.fudge);
77-
fs.readFile(dpath, 'utf8', function (err, data) {
78-
if (err) {
79-
console.log('Error reading device data: ' + dpath);
80-
} else {
81-
var result = parseFloat(fudge) + parseFloat(data.split(' ')[20].split('=')[1]) / 1000;
82-
callback(result, id);
83-
}
84-
});
85-
};
86-
87-
ds18b20Device.prototype.getTemp = function () {
88-
var dpath = '/sys/bus/w1/devices/' + this.id + '/w1_slave';
89-
var data = fs.readFileSync(dpath, 'utf8');
90-
console.log("getTemp(): " + parseFloat(data.split(' ')[20].split('=')[1]) / 1000);
91-
return (parseFloat(this.fudge) +parseFloat(data.split(' ')[20].split('=')[1]) / 1000);
92-
};
93-
*/
94-
9572
/* ex:set ai shiftwidth=2 inputtab=spaces smarttab noautotab: */

src/scripts/modules/fhem.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,13 @@ class fhemDevice {
6666
// Check for existing configuration
6767
var configObj = new Configuration();
6868
var config = configObj.getConfiguration();
69-
console.log("Configurations: " + JSON.stringify(config));
70-
console.log("Configurations: " + Object.keys(config));
71-
console.log("Configurations: " + Object.keys(config.iSpindels));
7269

7370
this.timeout;
7471
for (var i=0;i<config.iSpindels.length;i++) {
75-
console.log("Comparing " + config.iSpindels[i].name + " vs. " + raw.name);
72+
//console.log("Comparing " + config.iSpindels[i].name + " vs. " + raw.name);
7673
if (config.iSpindels[i].name == raw.name) {
7774
this.timeout = 1000 * parseInt(config.iSpindels[i].timeout);
78-
console.log("Comparing was OK");
75+
//console.log("Comparing was OK");
7976
break;
8077
}
8178
}
@@ -192,22 +189,21 @@ class fhemDevice {
192189
60 * 60 * 1000 = 3600000
193190
*/
194191
deviceReaper (caller) {
195-
//console.log("Reaping ... fhemDeviceList length = " + fhemDeviceList.length);
196192
var reap = false;
197193
var i;
198194
for (i=0;i<fhemDeviceList.length;i++) {
199195
if (fhemDeviceList[i].name == caller.name ) {
200196
//console.log("dur: " + (new Date() - new Date(fhemDeviceList[i].stamp)));
201197
//console.log("timeout = " + caller.timeout);
202198
if ((new Date() - new Date(fhemDeviceList[i].stamp)) > caller.timeout ) {
203-
console.log("Planning removal of " + fhemDeviceList[i].name + ", caller = " + caller.name);
199+
//console.log("Planning removal of " + fhemDeviceList[i].name + ", caller = " + caller.name);
204200
reap = true;
205201
}
206202
break;
207203
}
208204
}
209205
if (reap ) {
210-
console.log("Removing " + fhemDeviceList[i].name + ", caller = " + caller.name);
206+
console.log("Reaping " + fhemDeviceList[i].name + ", caller = " + caller.name);
211207
clearInterval(caller.reaper);
212208
fhemDeviceList.splice(i, 1);
213209
}

src/scripts/modules/jobprocessor.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ function JobProcessor(options) {
145145
job_status['running'] = 'recovered';
146146
}
147147

148-
//this.jobSensorIds.forEach( function (sensor, index) {
148+
// Apply fudges to job configuration
149+
var fudges = options.parent.configObj.getConfiguration()['sensorFudgeFactors'];
150+
var keys = Object.keys(fudges);
149151
this.jobSensorIds.forEach( function (sensor) {
152+
for (var sensorKey in keys) {
153+
if (keys[sensorKey] == jSensors[sensor].name) {
154+
console.log("Setting fudge of " + keys[sensorKey] + " to " + fudges[keys[sensorKey]]);
155+
jSensors[sensor].fudge = fudges[keys[sensorKey]];
156+
}
157+
}
150158
job_status['sensors'].push(sensor);
151-
console.log("jobStatus() jSensors: " + JSON.stringify(jSensors));
152-
//job_status[sensor] = jSensors[sensor].getTemp();
153159
job_status[sensor] = jSensors[sensor].temp;
154160
});
155161
console.log("job_status: " + JSON.stringify(job_status));
@@ -210,7 +216,6 @@ JobProcessor.prototype.jobStatus = function (nowTime, obj) {
210216
//obj.jobSensorIds.forEach( function (sensor, index) {
211217
obj.jobSensorIds.forEach( function (sensor) {
212218
job_status['sensors'].push(sensor);
213-
//job_status[sensor] = obj.jobSensors[sensor].getTemp();
214219
job_status[sensor] = obj.jobSensors[sensor].temp;
215220
});
216221
//console.log("job_status: " + JSON.stringify(job_status));
@@ -541,11 +546,8 @@ JobProcessor.prototype.temperatureAdjust = function (target) {
541546
take the first sensor's reading into account at all.
542547
*/
543548
if (this.jobSensorIds.length == 1) {
544-
//temp = this.jobSensors[this.jobSensorIds[0]].getTemp();
545549
temp = this.jobSensors[this.jobSensorIds[0]].temp;
546550
} else if (this.jobSensorIds.length > 1) {
547-
//var temp0 = parseFloat(this.jobSensors[this.jobSensorIds[0]].getTemp());
548-
//var temp1 = parseFloat(this.jobSensors[this.jobSensorIds[1]].getTemp());
549551
var temp0 = parseFloat(this.jobSensors[this.jobSensorIds[0]].temp);
550552
var temp1 = parseFloat(this.jobSensors[this.jobSensorIds[1]].temp);
551553
var mswm = parseFloat(this.parent.configuration['multiSensorMeanWeight']);

src/scripts/modules/jsogpio.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
nodefs internal fs interface).
55
*/
66

7-
//const cpuInfo = require('./cpuinfo');
87
import cpuInfo from './cpuinfo';
9-
var fs = require('fs');
8+
import fs from 'fs';
109

1110

1211
var cpuinfo = new cpuInfo();

src/scripts/modules/requestHandlers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var fs = require("fs");
2-
var path = require('path');
1+
import fs from "fs";
2+
import path from 'path';
33
import { newReading } from './fhem.js';
44

55
function index(response) {

0 commit comments

Comments
 (0)