Skip to content

Commit

Permalink
Fix/remove node dht sensor (#188)
Browse files Browse the repository at this point in the history
* config update + removal of node-dht

* remove log statements

* Retrieving temperature. It does not update though ...

* Add build targets for other platforms. Closes 167
  • Loading branch information
UnchartedBull committed Oct 8, 2019
1 parent 1b26692 commit ace6f9b
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 169 deletions.
32 changes: 0 additions & 32 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand All @@ -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", () => {
Expand Down
13 changes: 0 additions & 13 deletions package-lock.json

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

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -80,7 +82,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"
Expand Down
1 change: 1 addition & 0 deletions scripts/install-no-autostart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
~/OctoPrint/venv/bin/pip install -q "https://github.com/marian42/octoprint-preheat/archive/master.zip"
if [[ $* == *--ptg* ]]
then
Expand Down
1 change: 1 addition & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
~/OctoPrint/venv/bin/pip install -q "https://github.com/marian42/octoprint-preheat/archive/master.zip"
if [[ $* == *--ptg* ]]
then
Expand Down
50 changes: 11 additions & 39 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/app/bottom-bar/bottom-bar.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<table class="bottom-bar">
<tr>
<td class="bottom-bar__printer-name"> {{ printer.name }} </td>
<td class="bottom-bar__enclosure-temperature" *ngIf="enclosureTemperature !== 0.0">
<td class="bottom-bar__enclosure-temperature" *ngIf="enclosureTemperature">
<img src="assets/thermometer.svg" class="bottom-bar__enclosure-temperature-icon" />
{{ enclosureTemperature }}°C
{{ enclosureTemperature.temperature }}°C
</td>
<td class="bottom-bar__current-status" [ngClass]="{'bottom-bar__error': printer.status.includes('error')}">
{{ printer.status }} </td>
Expand Down
28 changes: 10 additions & 18 deletions src/app/bottom-bar/bottom-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,31 @@ 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: number;
private ipc: any;
public enclosureTemperature: TemperatureReading;

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);
}
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 = 0.0;
this.enclosureTemperature = null;
}
this.printer = {
name: this.configService.config.printer.name,
status: 'connecting ...'
};
}

ngOnInit() {
this.subscriptions.add(this.printerService.getObservable().subscribe((printerStatus: PrinterStatusAPI) => {
this.printer.status = printerStatus.status;
}));
Expand All @@ -50,7 +42,7 @@ interface Printer {
status: string;
}

interface TemperatureReading {
export interface TemperatureReading {
temperature: number;
humidity: number;
}
35 changes: 32 additions & 3 deletions src/app/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export class ConfigService {
return this.config.octodash.touchscreen;
}

public getAmbientTemperatureSensorName(): string {
return this.config.octodash.temperatureSensor.ambient;
}
}

export interface Config {
Expand All @@ -169,8 +172,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 {
Expand Down Expand Up @@ -284,7 +291,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',
Expand Down
23 changes: 7 additions & 16 deletions src/app/config/no-config/no-config.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,13 @@
</span> Touchscreen
</div>
<div class="no-config__3-temperature">
<span *ngIf="config.octodash.temperatureSensor.type !== 0">Sensor:</span>
<span *ngIf="config.octodash.temperatureSensor.type === 0">Temperature Sensor:</span>
<span class="no-config__select-wrapper">
<select [(ngModel)]="config.octodash.temperatureSensor.type" name="temperatureSensorType">
<option [ngValue]="0">None</option>
<option [ngValue]="11">DHT11</option>
<option [ngValue]="22">DHT22</option>
<option [ngValue]="22">AM2302</option>
</select>
</span>
<span *ngIf="config.octodash.temperatureSensor.type !== 0">
<label for="filamentDensity" class="no-config__input-label-small">GPIO:</label>
<input type="number" id="filamentDensity"
class="no-config__3-gpio no-config__input no-config__input-small" name="filamentDensity"
step="1" min="0" [(ngModel)]="config.octodash.temperatureSensor.gpio" required>
</span>
<label for="ambientTemperatureSensor" class="no-config__input-label-small">Sensor Name:</label>
<input type="string" id="ambientTemperatureSensor" class="no-config__input"
[(ngModel)]="config.octodash.temperatureSensor.ambient" name="ambientTemperatureSensor" required>
<div class="no-config__3-temperature-explanation">
Please enter the name of your temperature sensor as configured in the Enclosure Plugin. Leave empty
if you aren't using a temperature sensor.
</div>
</div>
</form>
</div>
Expand Down
35 changes: 4 additions & 31 deletions src/app/config/no-config/no-config.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit ace6f9b

Please sign in to comment.