Skip to content

Commit

Permalink
Improved printstats screen
Browse files Browse the repository at this point in the history
  • Loading branch information
freakydude committed Nov 29, 2023
1 parent 665ace2 commit 4357340
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_modules
docs
scripts
src-tauri/target
build
build
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules
.env
.env.*
!.env.example
/src-tauri/target

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

#COPY package*.json ./

#RUN npm install && npm install --save-dev @tauri-apps/cli
#RUN npm install && npm install --save-dev @tauri-apps/cli

#COPY . .

Expand All @@ -26,6 +26,6 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
#VOLUME [ "/app/src-tauri/target/release/bundle/deb/" ]

VOLUME [ "/app"]
CMD npm install && npm install --save-dev @tauri-apps/cli && npm run tauri build
CMD npm install && npm install --save-dev @tauri-apps/cli && npm run tauri build

#CMD npm run tauri build
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ And yes, help and improve if you find something.

- To use another url, use the commandline parameters

```bash
```
-h <Moonraker-HTTP-URL> eg. `http://192.168.1.1/`
-w <Moonraker-Websocket-URL> eg. `ws://192.168.1.1/websocket`
```

- To start in fullscreen mode

```bash
```
-f
```

Expand Down
27 changes: 25 additions & 2 deletions src/lib/commons/Values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class Values {
public stepsBaby = writable(0.05);
public stepsExtrusion = writable(10);
public stepsExtrusionSpeed = writable(3);
public fileMetadata = writable<IFileMetadata | null>(null);
public largestAbsoluteThumbnailPath = writable('');

public constructor(moonrakerClient: MoonrakerClient) {
// super();
Expand All @@ -23,13 +25,14 @@ export class Values {
this.clock = this.createClock();
}

public async getFileMetadata(filename: string): Promise<IFileMetadata | null> {
public async getFileMetadata(relativeFilename: string): Promise<IFileMetadata | null> {
const requestMetadata = new JsonRpcRequest({
method: 'server.files.metadata',
params: {
filename: filename
filename: relativeFilename
}
});

const response = await client.sendRequest(requestMetadata);
let metadata: IFileMetadata | null = null;

Expand All @@ -42,6 +45,26 @@ export class Values {
return metadata;
}

public async getThumbnails(relativeFilename: string): Promise<IThumbnail[] | null> {
const request = new JsonRpcRequest({
method: 'server.files.thumbnails',
params: {
filename: relativeFilename
}
});

const response = await client.sendRequest(request);
let thumbnails: IThumbnail[] | null = null;

if (response.error === undefined) {
thumbnails = response.result as IThumbnail[];
} else {
console.warn('getThumbnails.response.error: ', response.error);
}

return thumbnails;
}

public async getLargestAbsoluteThumbnailPath(moonrakerApi: URL, thumbnails: IThumbnail[]): Promise<string> {
let path = '';

Expand Down
9 changes: 5 additions & 4 deletions src/lib/moonraker/MoonrakerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,14 @@ export class MoonrakerClient extends EventTarget {
}
if (print_stats.info !== undefined) {
const info = print_stats.info;
if (info?.current_layer !== undefined) {
if (info.current_layer !== undefined) {
// console.log('print_stats.info: ', print_stats.info);
// console.log('print_stats.info.current_layer: ', print_stats.info?.current_layer);
this.printStats.Info.CurrentLayer.set(info?.current_layer);
this.printStats.Info.CurrentLayer.set(info.current_layer);
}
if (info?.total_layer !== undefined) {
if (info.total_layer !== undefined) {
// console.log('print_stats.info.total_layer: ', print_stats.info?.total_layer);
this.printStats.Info.TotalLayer.set(info?.total_layer);
this.printStats.Info.TotalLayer.set(info.total_layer);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/moonraker/modules/PrintStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class PrintStats {
}

export class Info {
public TotalLayer = writable(0);
public CurrentLayer = writable(0);
public TotalLayer = writable<number | null>(null);
public CurrentLayer = writable<number | null>(null);
}
38 changes: 22 additions & 16 deletions src/lib/moonraker/types/IFileMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import type { IThumbnail } from './IThumbnail';

export interface IFileMetadata {
print_start_time: null;
job_id: null;
size: number;
modified: number;
slicer: string;
slicer_version: string;
layer_height: number;
first_layer_height: number;
object_height: number;
filament_total: number;
estimated_time: number;
thumbnails: IThumbnail[];
first_layer_bed_temp: number;
first_layer_extr_temp: number;
gcode_start_byte: number;
gcode_end_byte: number;
filename: string;
estimated_time: number; // 12771
filament_name: string; // "Geeetech PLA N0.4"
filament_total: number; // 19084
filament_type: string; // "PLA"
filament_weight_total: number; // 56.96
filename: string; // "swx2-led-light v8_prusa_PLA_L0.2_F0.97_S80.gcode"
first_layer_bed_temp: number; // 65
first_layer_extr_temp: number; // 210
first_layer_height: number; // 0.2
gcode_end_byte: number; //6482519
gcode_start_byte: number; // 67056
job_id: string; // "000088"
layer_count: number; // 85
layer_height: number; // 0.2
modified: number; // 1701163957.4757094
nozzle_diameter: number; // 0.4
object_height: number; // 17
print_start_time: number; // 1701269472.5509927
size: number; // 6494120
slicer: string; // "PrusaSlicer"
slicer_version: string; // "2.7.0+win64"
uuid: string; // "7cfa8f87-13e4-4578-9ac7-e79296a2b279"
}
2 changes: 1 addition & 1 deletion src/lib/moonraker/types/INotifyStatusUpdateParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export interface INotifyStatusUpdateParams {
display_status: IProgress;
motion_report: IMotionReport;
configfile: IConfigFile;
quadGantryLevel: IQuadGantryLevel
quadGantryLevel: IQuadGantryLevel;
}
19 changes: 18 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import '../app.css';
import { goto } from '$app/navigation';
import { bootParams, client, moonraker } from '$lib/base.svelte';
import { bootParams, client, moonraker, values } from '$lib/base.svelte';
import { onMount } from 'svelte';
import { getMatches } from '@tauri-apps/api/cli';
import { appWindow } from '@tauri-apps/api/window';
Expand All @@ -15,6 +15,8 @@
let klippyState = moonraker.klippyState.state;
let isFullscreen = bootParams.fullscreen;
let wsUrl = bootParams.moonrakerWs;
let apiUrl = bootParams.moonrakerApi;
let loadedFile = moonraker.printStats.Filename;
let interval: NodeJS.Timeout;
$: {
Expand All @@ -39,6 +41,21 @@
$: {
appWindow.setFullscreen($isFullscreen);
}
async function updateMetadata(relativeFilename: string) {
console.log('loadedFile', relativeFilename);
if (relativeFilename !== '') {
let fileMeta = await values.getFileMetadata(relativeFilename);
console.log('fileMeta', fileMeta);
values.fileMetadata.set(fileMeta);
if (fileMeta !== null) {
values.largestAbsoluteThumbnailPath.set(await values.getLargestAbsoluteThumbnailPath($apiUrl, fileMeta.thumbnails));
}
}
}
$: updateMetadata($loadedFile);
</script>

<div class="flex h-screen w-screen">
Expand Down
Loading

0 comments on commit 4357340

Please sign in to comment.