Skip to content

Commit

Permalink
Made ModelObject.wrapModelProperty static
Browse files Browse the repository at this point in the history
Added new state.configErr key
  • Loading branch information
chrishamm committed Jan 31, 2023
1 parent 8dabd41 commit c0fe377
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@duet3d/objectmodel",
"version": "3.5.0-beta.22",
"version": "3.5.0-beta.24",
"description": "TypeScript implementation of the Duet3D Object Model",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/ModelObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ export abstract class ModelObject implements IModelObject {
* @param key Property key of the derived class
* @param constructor Constructor for creating new elements
*/
protected wrapModelProperty<K extends keyof this, T extends IModelObject>(key: K, constructor: { new(): T }): void {
let propertyValue: any = this[key];
Object.defineProperty(this, key, {
static wrapModelProperty<S extends IModelObject, K extends keyof S, T extends IModelObject>(self: S, key: K, constructor: { new(): T }): void {
let propertyValue: any = self[key];
Object.defineProperty(self, key, {
get() { return propertyValue; },
set(newValue) {
if (newValue === null) {
Expand Down
12 changes: 6 additions & 6 deletions src/boards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export class DirectDisplay extends ModelObject {
export class Board extends ModelObject {
constructor() {
super();
this.wrapModelProperty("accelerometer", Accelerometer);
this.wrapModelProperty("closedLoop", ClosedLoop);
this.wrapModelProperty("directDisplay", DirectDisplay);
this.wrapModelProperty("mcuTemp", MinMaxCurrent);
this.wrapModelProperty("v12", MinMaxCurrent);
this.wrapModelProperty("vIn", MinMaxCurrent);
ModelObject.wrapModelProperty(this, "accelerometer", Accelerometer);
ModelObject.wrapModelProperty(this, "closedLoop", ClosedLoop);
ModelObject.wrapModelProperty(this, "directDisplay", DirectDisplay);
ModelObject.wrapModelProperty(this, "mcuTemp", MinMaxCurrent);
ModelObject.wrapModelProperty(this, "v12", MinMaxCurrent);
ModelObject.wrapModelProperty(this, "vIn", MinMaxCurrent);
}

accelerometer: Accelerometer | null = null;
Expand Down
4 changes: 2 additions & 2 deletions src/job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class TimesLeft extends ModelObject {
export class Job extends ModelObject {
constructor() {
super();
this.wrapModelProperty("build", Build);
this.wrapModelProperty("file", GCodeFileInfo);
ModelObject.wrapModelProperty(this, "build", Build);
ModelObject.wrapModelProperty(this, "file", GCodeFileInfo);
}

build: Build = new Build();
Expand Down
2 changes: 1 addition & 1 deletion src/move/Extruder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ExtruderNonlinear extends ModelObject {
export class Extruder extends ModelObject {
constructor() {
super();
this.wrapModelProperty("driver", DriverId);
ModelObject.wrapModelProperty(this, "driver", DriverId);
}

acceleration: number = 500;
Expand Down
4 changes: 2 additions & 2 deletions src/move/MoveCompensation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export enum MoveCompensationType {
export class MoveCompensation extends ModelObject {
constructor() {
super();
this.wrapModelProperty("liveGrid", ProbeGrid);
this.wrapModelProperty("meshDeviation", MoveDeviations);
ModelObject.wrapModelProperty(this, "liveGrid", ProbeGrid);
ModelObject.wrapModelProperty(this, "meshDeviation", MoveDeviations);
}
fadeHeight: number | null = null;
file: string | null = null;
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/FilamentMonitors/LaserFilamentMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class LaserFilamentMonitorConfigured extends ModelObject {
export class LaserFilamentMonitor extends FilamentMonitorBase {
constructor() {
super(FilamentMonitorType.laser);
this.wrapModelProperty("calibrated", LaserFilamentMonitorCalibrated);
ModelObject.wrapModelProperty(this, "calibrated", LaserFilamentMonitorCalibrated);
}

calibrated: LaserFilamentMonitorCalibrated | null = new LaserFilamentMonitorCalibrated();
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/FilamentMonitors/PulsedFilamentMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PulsedFilamentMonitorConfigured extends ModelObject {
export class PulsedFilamentMonitor extends FilamentMonitorBase {
constructor() {
super(FilamentMonitorType.pulsed);
this.wrapModelProperty("calibrated", PulsedFilamentMonitorCalibrated);
ModelObject.wrapModelProperty(this, "calibrated", PulsedFilamentMonitorCalibrated);
}

calibrated: PulsedFilamentMonitorCalibrated | null = new PulsedFilamentMonitorCalibrated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class RotatingMagnetFilamentMonitorConfigured extends ModelObject {
export class RotatingMagnetFilamentMonitor extends FilamentMonitorBase {
constructor() {
super(FilamentMonitorType.rotatingMagnet);
this.wrapModelProperty("calibrated", RotatingMagnetFilamentMonitorCalibrated);
ModelObject.wrapModelProperty(this, "calibrated", RotatingMagnetFilamentMonitorCalibrated);
}

calibrated: RotatingMagnetFilamentMonitorCalibrated | null = new RotatingMagnetFilamentMonitorCalibrated();
Expand Down
12 changes: 10 additions & 2 deletions src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export class BeepRequest extends ModelObject {
frequency: number = 0;
}

export class ConfigErr extends ModelObject {
file: string | null = null;
line: number = -1;
message: string = "";
}

export class GpOutputPort extends ModelObject {
freq: number = 0;
pwm: number = 0;
Expand All @@ -30,12 +36,14 @@ export enum MachineMode {
export class State extends ModelObject {
constructor() {
super();
this.wrapModelProperty("beep", BeepRequest);
this.wrapModelProperty("messageBox", MessageBox);
ModelObject.wrapModelProperty(this, "beep", BeepRequest);
ModelObject.wrapModelProperty(this, "configErr", ConfigErr);
ModelObject.wrapModelProperty(this, "messageBox", MessageBox);
}
atxPower: boolean | null = null;
atxPowerPort: string | null = null;
beep: BeepRequest | null = null;
configErr: ConfigErr | null = null;
currentTool: number = -1;
deferredPowerDown: boolean | null = null;
displayMessage: string = "";
Expand Down

0 comments on commit c0fe377

Please sign in to comment.