Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temperature sensor #47

Merged
merged 6 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ const {
} = require("electron");
const url = require('url')
const path = require('path')
const sensor = require('node-dht-sensor')
const Store = require('electron-store');
const store = new Store();


const args = process.argv.slice(1);
const dev = args.some(val => val === '--serve');
const big = args.some(val => val === '--big-screen')

let window;
let config;

function createWindow() {
config = store.get("config");
store.onDidChange("config", (newValue, _) => {
config = newValue
})
const {
screen
} = require('electron')
Expand All @@ -26,6 +35,8 @@ function createWindow() {
}
})

config = store.get("config")

if (dev) {
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/node_modules/electron`)
Expand All @@ -41,11 +52,43 @@ function createWindow() {

if (dev) window.webContents.openDevTools();

if (config && config.octodash && config.octodash.temperatureSensor !== null) {
queryTemperatureSensor();
}

window.on('closed', () => {
window = null;
});
}

function queryTemperatureSensor() {
if (process.platform !== "linux") {
sensor.initialize({
test: {
fake: {
temperature: 23.4,
humidity: 54.0
}
}
})
}
sensor.read(config.octodash.temperatureSensor.type, config.octodash.temperatureSensor.gpio, (err, temperature, humidity) => {
if (!err) {
window.webContents.send("temperatureReading", {
temperature: temperature.toFixed(1),
humidity: humidity.toFixed(1)
});
} else {
window.webContents.send("temperatureReading", {
temperature: 0.0,
humidity: 0.0
});
console.log(err);
}
setTimeout(queryTemperatureSensor, config.octoprint.apiInterval)
})
}

app.on('ready', createWindow)

app.on("window-all-closed", () => {
Expand Down
22 changes: 20 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
"output": "package"
},
"linux": {
"target": [{
"target": "deb",
"arch": [
"armv7l",
"arm64"
]
}],
"target": [
{
"target": "deb",
"arch": [
"armv7l",
"arm64"
]
}
],
"category": "Utility"
}
},
Expand Down Expand Up @@ -70,6 +72,8 @@
"ajv": "^6.10.2",
"angular-svg-round-progressbar": "^3.0.1",
"electron-store": "^4.0.0",
"lodash": "^4.17.14",
"node-dht-sensor": "^0.3.0",
"rxjs": "~6.5.2",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
Expand All @@ -80,6 +84,7 @@
"@angular/compiler-cli": "^8.1.1",
"@angular/language-service": "~8.1.1",
"@types/ajv": "^1.0.0",
"@types/lodash": "^4.14.136",
"@types/node": "~12.6.6",
"codelyzer": "^5.0.0",
"electron": "^5.0.7",
Expand Down
8 changes: 7 additions & 1 deletion sample.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"thickness": 0,
"density": 0
},
"touchscreen": true
"octodash": {
"touchscreen": true,
"temperatureSensor": {
"type": 22,
"gpio": 0
}
}
}
}
22 changes: 11 additions & 11 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div *ngIf="configService.config" class="container">
<div *ngIf="configService.valid">
<app-job-status></app-job-status>
<app-printer-status></app-printer-status>
<app-layer-progress></app-layer-progress>
<app-bottom-bar></app-bottom-bar>
</div>
<div *ngIf="!configService.valid">
<app-invalid-config></app-invalid-config>
</div>
<div *ngIf="configService.valid">
<app-job-status></app-job-status>
<app-printer-status></app-printer-status>
<app-layer-progress></app-layer-progress>
<app-bottom-bar></app-bottom-bar>
</div>
<div *ngIf="!configService.valid">
<app-invalid-config></app-invalid-config>
</div>
</div>
<div *ngIf="!configService.config">
<app-no-config></app-no-config>
</div>
<app-no-config></app-no-config>
</div>
16 changes: 9 additions & 7 deletions src/app/bottom-bar/bottom-bar.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<table class="bottom-bar">
<tr>
<td class="bottom-bar__printer-name"> {{ printer.name }} </td>
<td class="bottom-bar__enclosure-temperature"> {{ enclosureTemperature }}°C</td>
<td class="bottom-bar__current-status" [ngClass]="{'bottom-bar__error': printer.status.includes('error')}">
{{ printer.status }} </td>
</tr>
</table>
<tr>
<td class="bottom-bar__printer-name"> {{ printer.name }} </td>
<td class="bottom-bar__enclosure-temperature" *ngIf="enclosureTemperature !== 0.0">
{{ enclosureTemperature }}°C
</td>
<td class="bottom-bar__current-status" [ngClass]="{'bottom-bar__error': printer.status.includes('error')}">
{{ printer.status }} </td>
</tr>
</table>
20 changes: 18 additions & 2 deletions src/app/bottom-bar/bottom-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ export class BottomBarComponent implements OnInit, OnDestroy {
private subscriptions: Subscription = new Subscription();
public printer: Printer;
public enclosureTemperature: number;

private ipc: any;

constructor(private printerStatusService: PrinterStatusService, private configService: ConfigService) {
this.enclosureTemperature = 22.5; // TODO
if (window.require && configService.config.octodash.temperatureSensor !== null) {
try {
this.ipc = window.require('electron').ipcRenderer;
this.ipc.on('temperatureReading', ({ }, temperatureReading: TemperatureReading) => {
this.enclosureTemperature = temperatureReading.temperature;
});
} catch (e) {
console.error(e);
}
} else {
this.enclosureTemperature = 0.0;
}
this.printer = {
name: this.configService.config.printer.name,
status: 'connecting ...'
Expand All @@ -38,3 +49,8 @@ interface Printer {
name: string;
status: string;
}

interface TemperatureReading {
temperature: number;
humidity: number;
}
69 changes: 63 additions & 6 deletions src/app/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ConfigService {
private store: any | undefined;
private validator: Ajv.ValidateFunction;
public valid: boolean;
public update = false;

constructor(private http: HttpClient) {
const ajv = new Ajv({ allErrors: true });
Expand All @@ -36,6 +37,10 @@ export class ConfigService {
}
}

public getRemoteConfig(): Config {
return this.store.get('config');
}

public validate(): boolean {
return this.validator(this.config) ? true : false;
}
Expand Down Expand Up @@ -85,7 +90,19 @@ export interface Config {
octoprint: Octoprint;
printer: Printer;
filament: Filament;
octodash: OctoDash;
// DEPRECATED, will be removed with the next config change
touchscreen?: boolean;
}

interface OctoDash {
touchscreen: boolean;
temperatureSensor: TemperatureSensor | null;
}

interface TemperatureSensor {
type: number;
gpio: number;
}

interface Octoprint {
Expand All @@ -105,13 +122,15 @@ interface Filament {

const schema = {
definitions: {},
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'http://example.com/root.json',
type: 'object',
title: 'The Root Schema',
required: [
'octoprint',
'printer',
'filament'
'filament',
'octodash'
],
properties: {
octoprint: {
Expand All @@ -128,18 +147,18 @@ const schema = {
$id: '#/properties/octoprint/properties/url',
type: 'string',
title: 'The Url Schema',
default: 'http://localhost:5000/api/'
pattern: '^(.*)$'
},
accessToken: {
$id: '#/properties/octoprint/properties/accessToken',
type: 'string',
title: 'The Accesstoken Schema'
title: 'The Accesstoken Schema',
pattern: '^(.*)$'
},
apiInterval: {
$id: '#/properties/octoprint/properties/apiInterval',
type: 'integer',
title: 'The Apiinterval Schema',
default: 2000
title: 'The Apiinterval Schema'
}
}
},
Expand All @@ -154,7 +173,8 @@ const schema = {
name: {
$id: '#/properties/printer/properties/name',
type: 'string',
title: 'The Name Schema'
title: 'The Name Schema',
pattern: '^(.*)$'
}
}
},
Expand All @@ -178,6 +198,43 @@ const schema = {
title: 'The Density Schema'
}
}
},
octodash: {
$id: '#/properties/octodash',
type: 'object',
title: 'The Octodash Schema',
required: [
'touchscreen',
'temperatureSensor'
],
properties: {
touchscreen: {
$id: '#/properties/octodash/properties/touchscreen',
type: 'boolean',
title: 'The Touchscreen Schema'
},
temperatureSensor: {
$id: '#/properties/octodash/properties/temperatureSensor',
type: ['object', 'null'],
title: 'The Temperaturesensor Schema',
required: [
'type',
'gpio'
],
properties: {
type: {
$id: '#/properties/octodash/properties/temperatureSensor/properties/type',
type: 'integer',
title: 'The Type Schema'
},
gpio: {
$id: '#/properties/octodash/properties/temperatureSensor/properties/gpio',
type: 'integer',
title: 'The Gpio Schema'
}
}
}
}
}
}
};
Loading