Skip to content

Commit d955871

Browse files
authored
Fix (#20)
2 parents df62c3b + d40a3c3 commit d955871

File tree

10 files changed

+61
-48
lines changed

10 files changed

+61
-48
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "xcontroller-app",
33
"private": true,
4-
"version": "0.2.0",
4+
"version": "0.2.1",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "xcontroller-app"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "3D printer controller program written in Rust and Typescript."
55
authors = ["J040M"]
66
edition = "2021"

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"productName": "xcontroller-app",
2020
"mainBinaryName": "xcontroller-app",
21-
"version": "0.2.0",
21+
"version": "0.2.1",
2222
"identifier": "io.j040m.xcontrollerapp",
2323
"plugins": {},
2424
"app": {

src/components/main/control.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export default defineComponent({
9595
sendMovementCommand(command: Axis | string): void {
9696
switch (command) {
9797
case 'extrude':
98-
printer.moveAxis('e', '+', this.extruderValue);
98+
printer.moveAxis('e0', '+', this.extruderValue);
9999
break;
100100
case 'retract':
101-
printer.moveAxis('e', '-', this.extruderValue);
101+
printer.moveAxis('e0', '-', this.extruderValue);
102102
break;
103103
case 'x+':
104104
case 'y+':

src/init/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const wsClient = new WebSocketConnector()
1919
* @TODO Not the way I like to have this, but it's a start
2020
*/
2121
const newPrinter = new Printer({
22+
uuid: '',
2223
status: false,
2324
name: '',
2425
url: '',
@@ -27,7 +28,8 @@ const newPrinter = new Printer({
2728
x: 0,
2829
y: 0,
2930
z: 0,
30-
e: 0
31+
e0: 0,
32+
e1: 0
3133
},
3234
//Default dimensions
3335
dimensions: {

src/init/test/storage.test.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/types/printer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface PrinterCommands {
1515
setFanSpeed(speed: number): void
1616
}
1717

18-
type Axis = 'x' | 'y' | 'z' | 'e'
18+
type Axis = 'x' | 'y' | 'z' | 'e0' | 'e1'
1919
type State = 'idle' | 'printing' | 'paused' | 'stopped' | 'error'
2020

2121
interface PrintStatus {
@@ -35,7 +35,8 @@ interface AxisPositions {
3535
x: number
3636
y: number
3737
z: number
38-
e: number
38+
e0: number
39+
e1: number
3940
}
4041

4142
interface PrinterProfile {

src/utils/printer.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { wsClient } from "../init/client";
2-
import { Axis, AxisPositions, PrinterProfile, PrinterCommands } from "../types/printer";
3-
import { eventBus } from "./eventbus";
4-
51
/**
2+
* @file Printer.ts
63
* Class representing a 3D printer instance
74
* Handles printer control commands and state management
85
* Using the verifyConnection() decorator to verify the connection
96
*/
7+
8+
import { wsClient } from "../init/client";
9+
import { Axis, AxisPositions, PrinterProfile, PrinterCommands } from "../types/printer";
10+
import { eventBus } from "./eventbus";
11+
1012
export default class Printer implements PrinterCommands {
1113
/** Stores current printer configuration and state */
1214
printerInfo: PrinterProfile
@@ -87,9 +89,6 @@ export default class Printer implements PrinterCommands {
8789
message_type: 'GCommand',
8890
message: 'G29'
8991
})
90-
91-
// TODO: This is not really necessary, is it!?
92-
this.autoHome()
9392
}
9493

9594
/**
@@ -112,19 +111,27 @@ export default class Printer implements PrinterCommands {
112111
const current_position = this.axisPositions[axis]
113112
let new_position = direction === '+' ? current_position + distance : current_position - distance
114113

115-
// Check for printer limits to avoid crusing things
116-
if (new_position < 0) new_position = 0
117-
else if (axis !== 'e' && new_position > this.printerInfo.dimensions[axis]) {
118-
new_position = this.printerInfo.dimensions[axis]
114+
// Check for printer limits to avoid crusing things (only for X, Y, Z)
115+
if (axis !== 'e0' && axis !== 'e1') {
116+
if (new_position < 0) new_position = 0
117+
else if (new_position > this.printerInfo.dimensions[axis]) {
118+
new_position = this.printerInfo.dimensions[axis]
119+
}
119120
}
120121

121122
// Check for hotend temperature before moving
122-
if (axis === 'e' && (Math.abs(this.printerInfo.temperatures.e0 - this.printerInfo.temperatures.e0_set) > 3
123+
if (axis === 'e0' && (Math.abs(this.printerInfo.temperatures.e0 - this.printerInfo.temperatures.e0_set) > 3
123124
|| this.printerInfo.temperatures.e0 < this.hotendMinTemp)) {
124125
console.error('Extruder temp very different from target temp')
125126
return
126127
}
127128

129+
if (axis === 'e1' && (Math.abs(this.printerInfo.temperatures.e1 - this.printerInfo.temperatures.e1_set) > 3
130+
|| this.printerInfo.temperatures.e1 < this.hotendMinTemp)) {
131+
console.error('Extruder temp very different from target temp')
132+
return
133+
}
134+
128135
wsClient.sendCommand({
129136
message_type: 'GCommand',
130137
message: `G1 ${axis}${new_position}`.toUpperCase()

src/utils/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { StorageTypes } from '../types/storage'
66
*/
77
export default class PrinterStorage {
88

9-
private storageItemsList: StorageTypes[] = ['PrinterProfiles', 'HeatingProfiles', 'Locale', 'Theme']
9+
public storageItemsList: StorageTypes[] = ['PrinterProfiles', 'HeatingProfiles', 'Locale', 'Theme']
1010

1111
constructor() {
1212
this.initStorage()

src/utils/tests/storage.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, it, expect, beforeEach } from 'vitest';
2+
import PrinterStorage from '../storage';
3+
4+
describe('initStorage', () => {
5+
beforeEach(() => {
6+
localStorage.clear();
7+
});
8+
9+
it('should create default storage items if they do not exist', () => {
10+
const storage = new PrinterStorage();
11+
12+
storage.storageItemsList.forEach((item: string) => {
13+
expect(localStorage.getItem(item)).toBe('[]');
14+
});
15+
});
16+
17+
it('should not overwrite existing storage items', () => {
18+
const storage = new PrinterStorage();
19+
20+
localStorage.setItem('PrinterProfiles', '[{"name":"Profile1"}]');
21+
22+
storage.storageItemsList.forEach((item: string) => {
23+
if (item !== 'PrinterProfiles') {
24+
expect(localStorage.getItem(item)).toBe('[]');
25+
} else {
26+
expect(localStorage.getItem(item)).toBe('[{"name":"Profile1"}]');
27+
}
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)