Skip to content

Commit

Permalink
ConfigGen: Improve fan comments
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Jun 11, 2024
1 parent fc32add commit 69bdefc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe('server', async () => {
const sectionIndex = debugLines.findIndex((l) => l.includes('[heater_fan toolhead_cooling_fan]'));
const commentIndex = debugLines
.slice(sectionIndex > -1 ? sectionIndex : 0)
.findIndex((l) => l.includes('# 2-pin fan connected to the toolboard on T0 (toolboard_t0)'));
.findIndex((l) => l.includes(`# 2-pin fan connected to 2-pin header on T0 (EBB42 v1.2) - input voltage pwm`));
const pinIndex = debugLines
.slice(sectionIndex > -1 ? sectionIndex : 0)
.findIndex((l) => l.includes('pin: toolboard_t0:PA1'));
Expand All @@ -376,7 +376,7 @@ describe('server', async () => {
const sectionIndex = debugLines.findIndex((l) => l.includes('[fan]'));
const commentIndex = debugLines
.slice(sectionIndex > -1 ? sectionIndex : 0)
.findIndex((l) => l.includes('# 4-pin fan connected to the toolboard on T0 (toolboard_t0)'));
.findIndex((l) => l.includes(`# 4-pin fan connected to 2-pin header on T0 (EBB42 v1.2) - digital pwm`));
const pinIndex = debugLines
.slice(sectionIndex > -1 ? sectionIndex : 0)
.findIndex((l) => l.includes('pin: !toolboard_t0:PA0'));
Expand Down
37 changes: 23 additions & 14 deletions src/server/helpers/config-generation/toolhead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PrinterAxis } from '@/zods/motion';
import { PrinterConfiguration } from '@/zods/printer-configuration';
import type { RenderPinsFn } from '@/server/helpers/klipper-config';
import { getLogger } from '@/server/helpers/logger';
import { Board } from '@/zods/boards';

export class ToolheadGenerator<IsToolboard extends boolean> extends ToolheadHelper<IsToolboard> {
private toolboardPins: PinMapZodFromBoard<IsToolboard, false> | null;
Expand Down Expand Up @@ -307,7 +308,7 @@ export class ToolheadGenerator<IsToolboard extends boolean> extends ToolheadHelp
result.push(extruder.trim());
return result.join('\n');
}
public renderPartFan(multipleToolheadPartFans: boolean = false) {
public renderPartFan(multipleToolheadPartFans: boolean = false, controlboard: Board) {
let result: string[] = [];
if (multipleToolheadPartFans) {
const fanName = `part_fan_${this.getShortToolName()}`;
Expand All @@ -318,18 +319,18 @@ export class ToolheadGenerator<IsToolboard extends boolean> extends ToolheadHelp
switch (this.getPartFan().id) {
case '2pin':
this.requireControlboardPin('fan_part_cooling_pin');
result.push(`# 2-pin fan connected to the controller board`);
result.push(`# 2-pin fan connected to 2-pin header on ${controlboard.name} - input voltage pwm`);
result.push(`pin: ${this.controlboardPins?.fan_part_cooling_pin}`);
break;
case '4pin':
this.requireControlboardPin('fan_part_cooling_pin');
result.push(`# 4-pin fan connected to the controller board`);
result.push(`# 4-pin fan connected to 2-pin header on ${controlboard.name} - digital pwm`);
result.push(`pin: !${this.controlboardPins?.fan_part_cooling_pin}`);
result.push(`cycle_time: 0.00004`);
break;
case '4pin-dedicated':
this.requireControlboardPin('4p_fan_part_cooling_pin');
result.push(`# 4-pin fan connected to a dedicated 4-pin fan header on the controller board`);
result.push(`# 4-pin fan connected to 4-pin header on ${controlboard.name} - digital pwm`);
result.push(`pin: ${this.controlboardPins?.['4p_fan_part_cooling_pin']}`);
result.push(`cycle_time: 0.00004`);
if (this.controlboardPins?.['4p_fan_part_cooling_tach_pin'] != null) {
Expand All @@ -339,19 +340,23 @@ export class ToolheadGenerator<IsToolboard extends boolean> extends ToolheadHelp
break;
case '2pin-toolboard':
this.requireToolboardPin('fan_part_cooling_pin');
result.push(`# 2-pin fan connected to the toolboard on T${this.getTool()} (${this.getToolboardName()})`);
result.push(
`# 2-pin fan connected to 2-pin header on T${this.getTool()} (${this.getToolboard()?.name}) - input voltage pwm`,
);
result.push(`pin: ${this.getPinPrefix()}${this.toolboardPins?.fan_part_cooling_pin}`);
break;
case '4pin-toolboard':
this.requireToolboardPin('fan_part_cooling_pin');
result.push(`# 4-pin fan connected to the toolboard on T${this.getTool()} (${this.getToolboardName()})`);
result.push(
`# 4-pin fan connected to 2-pin header on T${this.getTool()} (${this.getToolboard()?.name}) - digital pwm`,
);
result.push(`pin: !${this.getPinPrefix()}${this.toolboardPins?.fan_part_cooling_pin}`);
result.push(`cycle_time: 0.00004`);
break;
case '4pin-dedicated-toolboard':
this.requireToolboardPin('4p_fan_part_cooling_pin');
result.push(
`# 4-pin fan connected to a dedicated 4-pin fan header on the toolboard on T${this.getTool()} (${this.getToolboardName()})`,
`# 4-pin fan connected to 4-pin header on T${this.getTool()} (${this.getToolboard()?.name}) - digital pwm`,
);
result.push(`pin: ${this.getPinPrefix()}${this.toolboardPins?.['4p_fan_part_cooling_pin']}`);
result.push(`cycle_time: 0.00004`);
Expand All @@ -365,26 +370,26 @@ export class ToolheadGenerator<IsToolboard extends boolean> extends ToolheadHelp
}
return result.join('\n');
}
public renderHotendFan() {
public renderHotendFan(controlboard: Board) {
let result: string[] = [
`[heater_fan toolhead_cooling_fan${this.getTool() > 0 ? `_${this.getShortToolName()}` : ''}]`,
`heater: ${this.getExtruderAxis().toLocaleLowerCase()}`,
];
switch (this.getHotendFan().id) {
case '2pin':
this.requireControlboardPin('fan_toolhead_cooling_pin');
result.push(`# 2-pin fan connected to the controller board`);
result.push(`# 2-pin fan connected to 2-pin header on ${controlboard.name} - input voltage pwm`);
result.push(`pin: ${this.controlboardPins?.fan_toolhead_cooling_pin}`);
break;
case '4pin':
this.requireControlboardPin('fan_toolhead_cooling_pin');
result.push(`# 4-pin fan connected to the controller board`);
result.push(`# 4-pin fan connected to 2-pin header on ${controlboard.name} - digital pwm`);
result.push(`pin: !${this.controlboardPins?.fan_toolhead_cooling_pin}`);
result.push(`cycle_time: 0.00004`);
break;
case '4pin-dedicated':
this.requireControlboardPin('4p_toolhead_cooling_tach_pin');
result.push(`# 4-pin fan connected to a dedicated 4-pin fan header on the controller board`);
result.push(`# 4-pin fan connected to 4-pin header on ${controlboard.name} - digital pwm`);
result.push(`pin: ${this.controlboardPins?.['4p_toolhead_cooling_tach_pin']}`);
result.push(`cycle_time: 0.00004`);
if (this.controlboardPins?.['4p_toolhead_cooling_tach_pin'] != null) {
Expand All @@ -394,19 +399,23 @@ export class ToolheadGenerator<IsToolboard extends boolean> extends ToolheadHelp
break;
case '2pin-toolboard':
this.requireToolboardPin('fan_toolhead_cooling_pin');
result.push(`# 2-pin fan connected to the toolboard on T${this.getTool()} (${this.getToolboardName()})`);
result.push(
`# 2-pin fan connected to 2-pin header on T${this.getTool()} (${this.getToolboard()?.name}) - input voltage pwm`,
);
result.push(`pin: ${this.getPinPrefix()}${this.toolboardPins?.fan_toolhead_cooling_pin}`);
break;
case '4pin-toolboard':
this.requireToolboardPin('fan_toolhead_cooling_pin');
result.push(`# 4-pin fan connected to the toolboard on T${this.getTool()} (${this.getToolboardName()})`);
result.push(
`# 4-pin fan connected to 2-pin header on T${this.getTool()} (${this.getToolboard()?.name}) - digital pwm`,
);
result.push(`pin: !${this.getPinPrefix()}${this.toolboardPins?.fan_toolhead_cooling_pin}`);
result.push(`cycle_time: 0.00004`);
break;
case '4pin-dedicated-toolboard':
this.requireToolboardPin('4p_toolhead_cooling_pin');
result.push(
`# 4-pin fan connected to a dedicated 4-pin fan header on the toolboard on T${this.getTool()} (${this.getToolboardName()})`,
`# 4-pin fan connected to 4-pin header on T${this.getTool()} (${this.getToolboard()?.name}) - digital pwm`,
);
result.push(`pin: ${this.getPinPrefix()}${this.toolboardPins?.['4p_toolhead_cooling_pin']}`);
result.push(`cycle_time: 0.00004`);
Expand Down
10 changes: 5 additions & 5 deletions src/server/helpers/klipper-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,18 +1049,18 @@ export const constructKlipperConfigHelpers = async (
switch (config.controllerFan.id) {
case '2pin':
utils.requireControlboardPin('fan_controller_board_pin');
result.push(`# 2-pin fan connected to the controller board`);
result.push(`# 2-pin fan connected to 2-pin header on ${config.controlboard.name} - input voltage pwm`);
result.push(`pin: ${utils.getControlboardPins().fan_controller_board_pin}`);
break;
case '4pin':
utils.requireControlboardPin('fan_controller_board_pin');
result.push(`# 4-pin fan connected to the controller board`);
result.push(`# 4-pin fan connected to 2-pin header on ${config.controlboard.name} - digital pwm`);
result.push(`pin: !${utils.getControlboardPins().fan_controller_board_pin}`);
result.push(`cycle_time: 0.00004`);
break;
case '4pin-dedicated':
utils.requireControlboardPin('4p_controller_board_pin');
result.push(`# 4-pin fan connected to a dedicated 4-pin fan header on the controller board`);
result.push(`# 4-pin fan connected to 4-pin header on ${config.controlboard.name} - digital pwm`);
result.push(`pin: ${utils.getControlboardPins()['4p_controller_board_pin']}`);
result.push(`cycle_time: 0.00004`);
if (utils.getControlboardPins()['4p_controller_board_tach_pin'] != null) {
Expand Down Expand Up @@ -1089,7 +1089,7 @@ export const constructKlipperConfigHelpers = async (
result.push(
utils
.getToolheads()
.map((th) => th.renderPartFan(multipleToolheadPartFans))
.map((th) => th.renderPartFan(multipleToolheadPartFans, config.controlboard))
.join('\n'),
);
// Hotend fan
Expand All @@ -1098,7 +1098,7 @@ export const constructKlipperConfigHelpers = async (
result.push(
utils
.getToolheads()
.map((th) => th.renderHotendFan())
.map((th) => th.renderHotendFan(config.controlboard))
.join('\n'),
);
// Controller fan
Expand Down

0 comments on commit 69bdefc

Please sign in to comment.