From 4bd9d3d8e0d5ad34fc6de234709dc8cbedb99662 Mon Sep 17 00:00:00 2001 From: UnchartedBull Date: Tue, 8 Oct 2019 19:46:49 +0200 Subject: [PATCH 1/4] config update + removal of node-dht --- main.js | 32 ------------ package-lock.json | 13 ----- package.json | 1 - src/app/app.service.ts | 50 ++++--------------- src/app/bottom-bar/bottom-bar.component.html | 4 +- src/app/bottom-bar/bottom-bar.component.ts | 18 +++---- src/app/config/config.service.ts | 32 ++++++++++-- .../config/no-config/no-config.component.html | 23 +++------ .../config/no-config/no-config.component.scss | 35 ++----------- .../config/no-config/no-config.component.ts | 38 ++++++++++---- 10 files changed, 88 insertions(+), 158 deletions(-) diff --git a/main.js b/main.js index d5beb85df..746e06837 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,6 @@ 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(); @@ -57,9 +56,6 @@ function createWindow() { window.webContents.openDevTools(); } - if (config && config.octodash && config.octodash.temperatureSensor !== null) { - queryTemperatureSensor(); - } setTimeout(sendVersionInfo, 42 * 1000); window.on('closed', () => { window = null; @@ -72,34 +68,6 @@ function sendVersionInfo() { }) } -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, 10000) - }) -} - app.on('ready', createWindow) app.on("window-all-closed", () => { diff --git a/package-lock.json b/package-lock.json index 48868a7b4..51d8dacca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7817,19 +7817,6 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, - "node-addon-api": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.1.tgz", - "integrity": "sha512-2+DuKodWvwRTrCfKOeR24KIc5unKjOh8mz17NCzVnHWfjAdDqbfbjqh7gUT+BkXBRQM52+xCHciKWonJ3CbJMQ==" - }, - "node-dht-sensor": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/node-dht-sensor/-/node-dht-sensor-0.4.0.tgz", - "integrity": "sha512-wY7Cp5VjVcKj8Nc41j5igFU9DakU87RloRlyPO5y/JOZLBnHmJQBZ+Du6pDJjUtns5jwZnLjd9qQr8mkJls/YA==", - "requires": { - "node-addon-api": "^1.6.3" - } - }, "node-fetch-npm": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/node-fetch-npm/-/node-fetch-npm-2.0.2.tgz", diff --git a/package.json b/package.json index b9442496c..1bbd2bf57 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,6 @@ "hammerjs": "^2.0.8", "lodash": "^4.17.15", "ngx-spinner": "^8.0.3", - "node-dht-sensor": "^0.4.0", "rxjs": "~6.5.3", "tslib": "^1.9.0", "zone.js": "~0.9.1" diff --git a/src/app/app.service.ts b/src/app/app.service.ts index 831b33a8a..2c195e528 100644 --- a/src/app/app.service.ts +++ b/src/app/app.service.ts @@ -14,7 +14,7 @@ export class AppService { private version: string; constructor(private configService: ConfigService, private notificationService: NotificationService, private http: HttpClient) { - if (window.require && configService.config.octodash.temperatureSensor !== null) { + if (window.require) { try { this.ipc = window.require('electron').ipcRenderer; this.ipc.on('versionInformation', ({ }, versionInformation: VersionInformation) => { @@ -27,9 +27,10 @@ export class AppService { } this.updateError = [ - '.printer should have required property \'xySpeed\'', - '.printer should have required property \'zSpeed\'', - '.octodash should have required property \'customActions\'']; + '.octodash.temperatureSensor should have required property \'ambient\'', + '.octodash.temperatureSensor should have required property \'filament1\'', + '.octodash.temperatureSensor should have required property \'filament2\'', + ]; } private checkUpdate(): void { @@ -85,43 +86,14 @@ export class AppService { // If the errors can be automatically fixed return true here public autoFixError(): boolean { const config = this.configService.config; - config.octodash.customActions = [ - { - icon: 'home', - command: 'G28', - color: '#dcdde1' - }, - { - icon: 'ruler-vertical', - command: 'G29', - color: '#44bd32' - }, - { - icon: 'fire-alt', - command: 'M140 S50; M104 S185', - color: '#e1b12c' - }, - { - icon: 'snowflake', - command: 'M140 S0; M104 S0', - color: '#0097e6' - }, - { - icon: 'redo-alt', - command: '[!RELOAD]', - color: '#7f8fa6' - }, - { - icon: 'skull', - command: '[!KILL]', - color: '#e84118' - } - ]; - config.printer.xySpeed = 150; - config.printer.zSpeed = 5; + delete config.octodash.temperatureSensor.gpio; + delete config.octodash.temperatureSensor.type; + config.octodash.temperatureSensor.ambient = null; + config.octodash.temperatureSensor.filament1 = null; + config.octodash.temperatureSensor.filament2 = null; this.configService.saveConfig(config); this.configService.updateConfig(); - return true; + return false; } } diff --git a/src/app/bottom-bar/bottom-bar.component.html b/src/app/bottom-bar/bottom-bar.component.html index 496ac5957..6c1185094 100644 --- a/src/app/bottom-bar/bottom-bar.component.html +++ b/src/app/bottom-bar/bottom-bar.component.html @@ -1,9 +1,9 @@ - diff --git a/src/app/bottom-bar/bottom-bar.component.ts b/src/app/bottom-bar/bottom-bar.component.ts index 6beb1c5e4..53ef465fa 100644 --- a/src/app/bottom-bar/bottom-bar.component.ts +++ b/src/app/bottom-bar/bottom-bar.component.ts @@ -12,21 +12,17 @@ export class BottomBarComponent implements OnInit, OnDestroy { private subscriptions: Subscription = new Subscription(); public printer: Printer; - public enclosureTemperature: number; + public enclosureTemperature: TemperatureReading; private ipc: any; constructor(private printerService: PrinterService, private configService: ConfigService) { - 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); - } + if (true) { + this.enclosureTemperature = { + temperature: 21.8, + humidity: 1 + }; } else { - this.enclosureTemperature = 0.0; + this.enclosureTemperature = null; } this.printer = { name: this.configService.config.printer.name, diff --git a/src/app/config/config.service.ts b/src/app/config/config.service.ts index 47f436b7b..9e9debc71 100644 --- a/src/app/config/config.service.ts +++ b/src/app/config/config.service.ts @@ -169,8 +169,12 @@ interface CustomAction { } interface TemperatureSensor { - type: number; - gpio: number; + ambient: string | null; + filament1: string | null; + filament2: string | null; + // deprecate in next version + type?: number; + gpio?: number; } interface Octoprint { @@ -284,7 +288,29 @@ const schema = { }, temperatureSensor: { $id: '#/properties/octodash/properties/temperatureSensor', - type: ['object', 'null'] + type: 'object', + required: [ + 'ambient', + 'filament1', + 'filament2' + ], + properties: { + ambient: { + $id: '#/properties/octodash/properties/temperatureSensor/properties/ambient', + type: ['string', 'null'], + pattern: '^(.*)$' + }, + filament1: { + $id: '#/properties/octodash/properties/temperatureSensor/properties/filament1', + type: ['string', 'null'], + pattern: '^(.*)$' + }, + filament2: { + $id: '#/properties/octodash/properties/temperatureSensor/properties/filament2', + type: ['string', 'null'], + pattern: '^(.*)$' + }, + } }, customActions: { $id: '#/properties/octodash/properties/customActions', diff --git a/src/app/config/no-config/no-config.component.html b/src/app/config/no-config/no-config.component.html index 1f88b9cc9..3a9605d6c 100644 --- a/src/app/config/no-config/no-config.component.html +++ b/src/app/config/no-config/no-config.component.html @@ -82,22 +82,13 @@ Touchscreen
- Sensor: - Temperature Sensor: - - - - - - - + + +
+ Please enter the name of your temperature sensor as configured in the Enclosure Plugin. Leave empty + if you aren't using a temperature sensor. +
diff --git a/src/app/config/no-config/no-config.component.scss b/src/app/config/no-config/no-config.component.scss index 2749bcc1f..2abe639eb 100644 --- a/src/app/config/no-config/no-config.component.scss +++ b/src/app/config/no-config/no-config.component.scss @@ -123,39 +123,12 @@ } &__3 { - &-gpio { + &-temperature-explanation { + font-size: 3vw; + font-style: italic; + opacity: .7; margin-top: 4vh; } - - &-temperature { - display: block; - - & label { - margin-left: 4vw; - } - - & select { - background-color: transparent; - width: 28vw; - padding: 2.3vh 1.5vw; - border: 2px solid #dcdde1; - border-radius: 4vh; - margin-left: 2vw; - margin-top: 4vh; - } - - &__select-wrapper { - position: relative; - - &::before { - content: "\25BF"; - position: absolute; - right: 2vw; - top: 0; - pointer-events: none; - } - } - } } &__4 { diff --git a/src/app/config/no-config/no-config.component.ts b/src/app/config/no-config/no-config.component.ts index f64c15648..bcd78bcca 100644 --- a/src/app/config/no-config/no-config.component.ts +++ b/src/app/config/no-config/no-config.component.ts @@ -28,7 +28,7 @@ export class NoConfigComponent implements OnInit { this.configUpdate = this.configService.isUpdate(); if (this.configUpdate) { this.config = configService.getRemoteConfig(); - this.config.octoprint.url = this.config.octoprint.url.replace('/api/', ''); + this.revertConfigForUserInput(); } else { this.config = { octoprint: { @@ -48,8 +48,9 @@ export class NoConfigComponent implements OnInit { octodash: { touchscreen: true, temperatureSensor: { - type: 0, - gpio: 0 + ambient: '', + filament1: '', + filament2: '' }, customActions: [ { @@ -116,10 +117,18 @@ export class NoConfigComponent implements OnInit { createConfig() { this.configErrors = []; this.octoprintConnectionError = null; + console.log(this.config); this.config.octoprint.url = `http://${this.urlName}:${this.urlPort}/api/`; - if (this.config.octodash.temperatureSensor.type === 0) { - this.config.octodash.temperatureSensor = null; + if (this.config.octodash.temperatureSensor.ambient === '') { + this.config.octodash.temperatureSensor.ambient = null; } + if (this.config.octodash.temperatureSensor.filament1 === '') { + this.config.octodash.temperatureSensor.filament1 = null; + } + if (this.config.octodash.temperatureSensor.filament2 === '') { + this.config.octodash.temperatureSensor.filament2 = null; + } + console.log(this.config); this.validateConfig(); return true; } @@ -152,16 +161,25 @@ export class NoConfigComponent implements OnInit { decreasePage() { if (this.page === 4) { - this.config.octoprint.url = this.config.octoprint.url.replace('/api/', ''); - this.config.octodash.temperatureSensor = { - type: 0, - gpio: 0 - }; + this.revertConfigForUserInput(); } this.page -= 1; this.changeProgress(); } + private revertConfigForUserInput() { + this.config.octoprint.url = this.config.octoprint.url.replace('/api/', ''); + if (this.config.octodash.temperatureSensor.ambient === null) { + this.config.octodash.temperatureSensor.ambient = ''; + } + if (this.config.octodash.temperatureSensor.filament1 === null) { + this.config.octodash.temperatureSensor.filament1 = ''; + } + if (this.config.octodash.temperatureSensor.filament2 === null) { + this.config.octodash.temperatureSensor.filament2 = ''; + } + } + changeProgress() { document.getElementById('progressBar').style.width = this.page * (20 / this.totalPages) + 'vw'; } From 0025fc92b43da0356b12fca7c3caaa6169da3988 Mon Sep 17 00:00:00 2001 From: UnchartedBull Date: Tue, 8 Oct 2019 19:57:38 +0200 Subject: [PATCH 2/4] remove log statements --- src/app/config/no-config/no-config.component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/config/no-config/no-config.component.ts b/src/app/config/no-config/no-config.component.ts index bcd78bcca..76988c6df 100644 --- a/src/app/config/no-config/no-config.component.ts +++ b/src/app/config/no-config/no-config.component.ts @@ -117,7 +117,6 @@ export class NoConfigComponent implements OnInit { createConfig() { this.configErrors = []; this.octoprintConnectionError = null; - console.log(this.config); this.config.octoprint.url = `http://${this.urlName}:${this.urlPort}/api/`; if (this.config.octodash.temperatureSensor.ambient === '') { this.config.octodash.temperatureSensor.ambient = null; @@ -128,7 +127,6 @@ export class NoConfigComponent implements OnInit { if (this.config.octodash.temperatureSensor.filament2 === '') { this.config.octodash.temperatureSensor.filament2 = null; } - console.log(this.config); this.validateConfig(); return true; } From bcaa314b6da388fc4c278faeb0103a368136be3d Mon Sep 17 00:00:00 2001 From: UnchartedBull Date: Tue, 8 Oct 2019 23:30:41 +0200 Subject: [PATCH 3/4] Retrieving temperature. It does not update though ... --- scripts/install-no-autostart.sh | 1 + scripts/install.sh | 1 + src/app/bottom-bar/bottom-bar.component.ts | 20 ++++---- src/app/config/config.service.ts | 3 ++ src/app/enclosure.service.ts | 49 +++++++++++++++++++ src/app/octoprint-api/settingsAPI.ts | 56 ++++++++++++++++++++++ 6 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 src/app/enclosure.service.ts create mode 100644 src/app/octoprint-api/settingsAPI.ts diff --git a/scripts/install-no-autostart.sh b/scripts/install-no-autostart.sh index fea098ccc..95409dadd 100755 --- a/scripts/install-no-autostart.sh +++ b/scripts/install-no-autostart.sh @@ -5,6 +5,7 @@ dependencies="libgtk-3-0 libnotify4 libnss3 libxss1 libxtst6 xdg-utils libatspi2 echo "Installing OctoPrint Plugins" ~/OctoPrint/venv/bin/pip install -q "https://github.com/OllisGit/OctoPrint-DisplayLayerProgress/releases/latest/download/master.zip" +~/OctoPrint/venv/bin/pip install -q "https://github.com/vitormhenrique/OctoPrint-Enclosure/archive/master.zip" if [[ $* == *--ptg* ]] then ~/OctoPrint/venv/bin/pip install -q "https://github.com/eyal0/OctoPrint-PrintTimeGenius/archive/master.zip" diff --git a/scripts/install.sh b/scripts/install.sh index dc396cc5c..0d87196a0 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -5,6 +5,7 @@ dependencies="libgtk-3-0 libnotify4 libnss3 libxss1 libxtst6 xdg-utils libatspi2 echo "Installing OctoPrint Plugins" ~/OctoPrint/venv/bin/pip install -q "https://github.com/OllisGit/OctoPrint-DisplayLayerProgress/releases/latest/download/master.zip" +~/OctoPrint/venv/bin/pip install -q "https://github.com/vitormhenrique/OctoPrint-Enclosure/archive/master.zip" if [[ $* == *--ptg* ]] then ~/OctoPrint/venv/bin/pip install -q "https://github.com/eyal0/OctoPrint-PrintTimeGenius/archive/master.zip" diff --git a/src/app/bottom-bar/bottom-bar.component.ts b/src/app/bottom-bar/bottom-bar.component.ts index 53ef465fa..0fd0e25b6 100644 --- a/src/app/bottom-bar/bottom-bar.component.ts +++ b/src/app/bottom-bar/bottom-bar.component.ts @@ -2,25 +2,24 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; import { ConfigService } from '../config/config.service'; import { PrinterService, PrinterStatusAPI } from '../printer.service'; import { Subscription } from 'rxjs'; +import { EnclosureService } from '../enclosure.service'; @Component({ selector: 'app-bottom-bar', templateUrl: './bottom-bar.component.html', styleUrls: ['./bottom-bar.component.scss'] }) -export class BottomBarComponent implements OnInit, OnDestroy { +export class BottomBarComponent implements OnDestroy { private subscriptions: Subscription = new Subscription(); public printer: Printer; public enclosureTemperature: TemperatureReading; - private ipc: any; - constructor(private printerService: PrinterService, private configService: ConfigService) { - if (true) { - this.enclosureTemperature = { - temperature: 21.8, - humidity: 1 - }; + constructor(private printerService: PrinterService, private configService: ConfigService, private enclosureService: EnclosureService) { + if (this.configService.getAmbientTemperatureSensorName() !== null) { + this.subscriptions.add(this.enclosureService.getObservable().subscribe((temperatureReading: TemperatureReading) => { + this.enclosureTemperature = temperatureReading; + })); } else { this.enclosureTemperature = null; } @@ -28,9 +27,6 @@ export class BottomBarComponent implements OnInit, OnDestroy { name: this.configService.config.printer.name, status: 'connecting ...' }; - } - - ngOnInit() { this.subscriptions.add(this.printerService.getObservable().subscribe((printerStatus: PrinterStatusAPI) => { this.printer.status = printerStatus.status; })); @@ -46,7 +42,7 @@ interface Printer { status: string; } -interface TemperatureReading { +export interface TemperatureReading { temperature: number; humidity: number; } diff --git a/src/app/config/config.service.ts b/src/app/config/config.service.ts index 9e9debc71..06b4415b5 100644 --- a/src/app/config/config.service.ts +++ b/src/app/config/config.service.ts @@ -147,6 +147,9 @@ export class ConfigService { return this.config.octodash.touchscreen; } + public getAmbientTemperatureSensorName(): string { + return this.config.octodash.temperatureSensor.ambient; + } } export interface Config { diff --git a/src/app/enclosure.service.ts b/src/app/enclosure.service.ts new file mode 100644 index 000000000..db64807e3 --- /dev/null +++ b/src/app/enclosure.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpErrorResponse } from '@angular/common/http'; +import { ConfigService } from './config/config.service'; +import { NotificationService } from './notification/notification.service'; +import { Observable, Observer, timer, Subscription } from 'rxjs'; +import { OctoprintSettingsAPI } from './octoprint-api/settingsAPI'; +import { PrinterStatusAPI } from './printer.service'; +import { shareReplay } from 'rxjs/operators'; +import { TemperatureReading } from './bottom-bar/bottom-bar.component'; + +@Injectable({ + providedIn: 'root' +}) +export class EnclosureService { + + httpGETRequest: Subscription; + observable: Observable; + + constructor(private http: HttpClient, private configService: ConfigService, private notificationService: NotificationService) { + this.observable = new Observable((observer: Observer) => { + // TODO_ Change once plugin gets updated + timer(1200, 30000000).subscribe(_ => { + if (this.httpGETRequest) { + this.httpGETRequest.unsubscribe(); + } + this.httpGETRequest = this.http.get(this.configService.getURL('settings'), this.configService.getHTTPHeaders()).subscribe( + (data: OctoprintSettingsAPI) => { + const enclosureInputs = data.plugins.enclosure.rpi_inputs; + console.log(enclosureInputs); + const ambientTemperatureSensorName = this.configService.getAmbientTemperatureSensorName(); + enclosureInputs.forEach((enclosureInput) => { + if (enclosureInput.label === ambientTemperatureSensorName) { + observer.next({ + temperature: enclosureInput.temp_sensor_temp, + humidity: enclosureInput.temp_sensor_humidity + } as TemperatureReading); + } + }); + }, (error: HttpErrorResponse) => { + this.notificationService.setError('Can\'t retrieve enclosure temperature!', error.message); + }); + }); + }).pipe(shareReplay(1)); + } + + public getObservable(): Observable { + return this.observable; + } +} diff --git a/src/app/octoprint-api/settingsAPI.ts b/src/app/octoprint-api/settingsAPI.ts new file mode 100644 index 000000000..5e7246df5 --- /dev/null +++ b/src/app/octoprint-api/settingsAPI.ts @@ -0,0 +1,56 @@ +export interface OctoprintSettingsAPI { + api: object; + appearance: object; + feature: object; + folder: object; + plugins: OctoprintPluginsAPI; + scripts: object; + serial: object; + server: object; + system: object; + temperature: object; + terminalFilters: object; + webcam: object; +} + +interface OctoprintPluginsAPI { + [index: string]: object; + enclosure: OctoprintEnclosureAPI; +} + +interface OctoprintEnclosureAPI { + debug: boolean; + debug_temperature_log: boolean; + filament_sensor_gcode: string; + gcode_control: boolean; + neopixel_dma: number; + notification_api_key: string; + notifictiion_event_name: string; + notification_provider: string; + notifications: Array; + rpi_inputs: Array; + rpi_outputs: Array; + use_board_pin_number: boolean; + use_fahrenheit: boolean; +} + +interface OctoprintEnclosureInputsAPI { + action_type: string; + controlled_io: string; + controlled_io_set_value: string; + ds18b20_serial: string; + edge: string; + filament_sensor_enabled: boolean; + filament_sensor_timeout: number; + gpio_pin: string; + index_id: number; + input_pull_resistor: string; + input_type: string; + label: string; + printer_action: string; + temp_sensor_address: string; + temp_sensor_humidity: number; + temp_sensor_temp: number; + temp_sensor_type: string; + use_fahrenheit: boolean; +} From ee85f3a3217d23ec83c05d60a92d2dff6314b1ce Mon Sep 17 00:00:00 2001 From: UnchartedBull Date: Tue, 8 Oct 2019 23:52:53 +0200 Subject: [PATCH 4/4] Add build targets for other platforms. Closes 167 --- package.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1bbd2bf57..f3a3b1c14 100644 --- a/package.json +++ b/package.json @@ -28,18 +28,20 @@ "build": { "appId": "octodash", "productName": "OctoDash", - "npmRebuild": false, "directories": { "output": "package" }, "linux": { - "target": [ - { + "target": [{ "target": "deb", "arch": [ "armv7l", - "arm64" + "arm64", + "x64" ] + }, + { + "target": "apk" } ], "category": "Utility"
{{ printer.name }} + - {{ enclosureTemperature }}°C + {{ enclosureTemperature.temperature }}°C {{ printer.status }}