Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advanced misc fans menu (DWIN) + G-Codes #125

Open
wants to merge 30 commits into
base: 2024-December
Choose a base branch
from

Conversation

wlkmanist
Copy link

@wlkmanist wlkmanist commented Apr 17, 2024

Description

  • Adds Auto Fans adjustable temperature thresholds for DWIN display (Extruder, Chamber, Laser cooling fans) and M712 command.
  • Adds all Kickstart options for DWIN display and M711 command.
  • Adds Controller Fan parameters for DWIN display, as existed for 12864 display (M710 command already in Marlin).
  • EN and RU locales.
  • Add one more function to update dwin menu after changing a boolean.
  • Optimized memory (but not radical, matches Marlin code) and may be enabled/disabled via config both "xxx_EDITABLE" and "xxx_MENU" macroses.
  • Fan Settings menu in Advanced Settings

I added features that I can test someway, we can add more variables.
Tested (except RU locale), works fine. Voxelab Aquila GD32F103.

Requirements

DWIN LCD Display. Controllable fans hw configuration (2-pin fans connected someway to the microcontroller, optional).

Benefits

More controls. Totally silent 3d printer with controllable parameters via display and g-code. We can change any misc cooling parts and really fine tune them without recompilation.

Configuration

See the code.
What added, in short (all of that optional):

  • CONTROLLERFAN_SPEED_MAX (uses FAN_MAX_PWM if undefined)
  • FAN_KICKSTART_EDITABLE
  • FAN_KICKSTART_MENU
  • AUTO_FAN_EDITABLE
  • AUTO_FAN_MENU

Also affects:

  • CONTROLLER_FAN_EDITABLE
  • CONTROLLER_FAN_MENU

G-Code

  • M712: Set Extruder Auto Fans settings:
    -- R : Reset to defaults
    -- E : Set Extruder fans temperature threshold
    -- H : Set Chamber fan temperature threshold
    -- C : Set Cooler fan temperature threshold
    -- Examples:
    -- M712 ; Report current Settings
    -- M712 R ; Reset EHC to defaults
    -- M712 E60 ; Set Extruder temp to 60
    -- M712 E50 H30 C18 ; Set Extruder temp to 50, Chamber temp to 30, Cooler temp to 18

  • M711: Set Fan Kickstart settings:
    -- R : Reset to defaults
    -- S[0-255] : Fan speed when fans first start
    -- D : Set Kickstart duration (ms)
    -- E[0|1] : Turn Kickstart feature on or off
    -- Examples:
    -- M711 ; Report current Settings
    -- M711 R ; Reset SDE to defaults
    -- M711 S255 ; Set Kickstart fan speed to 100%
    -- M711 E0 ; Set Kickstart to OFF
    -- M711 E1 S180 D100 ; Set Kickstart to ON, Kickstart fan speed 70%, duration to 100 milliseconds

Issues

Controller fan works for me strange way. Works only 0-127 range (remap to 0-255 is existing in code). >127 it is full speed (with soft pwm value 2) or decreasing to zero (128-255) actual speed (with soft pwm 7 + dither). Added another config parameter to fix that (max pwm). Idk is that a base marlin code or just my specific hardware issue. It is 0-255 range for user in the interface anyway (mapping value to the real pwm value).

We need to test this with another pins (I used BLTouch pins) and with soft pwm = 0, disabled dither. But again, issue can be fixed by user using config or just via display settings or G-code.

Photos

image
image
image

I made it that way on my stock Voxelab Aquila board:
(Custom adapter with just 2x ao3400 smd N-channel mosfets connected to BLTouch pins with some resistors (200ohm gate->pins, 100k gate->gnd) and 24v hook (to stock fan connectors on board). Gave me 2 controllable fans. Code should work with any other solutions.)

IMG_20240330_074751
IMG_20240330_074802
MVIMG_20240330_081103

Signed-off-by: wlkmanist <[email protected]>

 Conflicts:
	Marlin/src/lcd/e3v2/proui/dwin.cpp
…settings

- Added FAN_KICKSTART_EDITABLE (Enable M711 configurable settings (320 bytes of flash))
- Added FAN_KICKSTART_MENU     (Enable the Fan Kickstart submenu  (384 bytes of flash))
- Improved Controller fan scaling
- Dynamic menu update at auto or enable parameter changed
- Kickstart saves parameters to EEPROM
- M711: Set Fan Kickstart settings:
-- R         : Reset to defaults
-- S[0-255]  : Fan speed when fans first start
-- D         : Set Kickstart duration (ms)
-- E[0|1]    : Turn Kickstart feature on or off
-- Examples:
--  M711                   ; Report current Settings
--  M711 R                 ; Reset SDE to defaults
--  M711 S255              ; Set Kickstart fan speed to 100%
--  M711 E0                ; Set Kickstart to OFF
--  M711 E1 S180 D100      ; Set Kickstart to ON, Kickstart fan speed 70%, duration to 100 milliseconds

Signed-off-by: wlkmanist <[email protected]>

 Conflicts:
	Marlin/src/lcd/e3v2/proui/dwin.cpp
Signed-off-by: wlkmanist <[email protected]>

 Conflicts:
	Marlin/Configuration_adv.h
Signed-off-by: wlkmanist <[email protected]>

 Conflicts:
	Marlin/Configuration_adv.h
- Added AUTO_FAN_EDITABLE (Enable M712 configurable settings      (320 bytes of flash))
- Added AUTO_FAN_MENU     (Enable the Extruder Auto Fans submenu  (104 bytes of flash))
- Auto Fans saves parameters to EEPROM
- M712: Set Extruder Auto Fans settings:
--  R         : Reset to defaults
--  E         : Set Extruder fans temperature threshold
--  H         : Set Chamber fan temperature threshold
--  C         : Set Cooler fan temperature threshold
-- Examples:
--   M712                   ; Report current Settings
--   M712 R                 ; Reset EHC to defaults
--   M712 E60               ; Set Extruder temp to 60
--   M712 E50 H30 C18       ; Set Extruder temp to 50, Chamber temp to 30, Cooler temp to 18

Signed-off-by: wlkmanist <[email protected]>

 Conflicts:
	Marlin/src/lcd/e3v2/proui/dwin.cpp
Signed-off-by: wlkmanist <[email protected]>

 Conflicts:
	Marlin/Configuration_adv.h
Signed-off-by: wlkmanist <[email protected]>

 Conflicts:
	Marlin/src/lcd/e3v2/proui/dwin.cpp
@wlkmanist wlkmanist changed the title Adv fan menu Add advanced misc fans menu (DWIN) + G-Codes Apr 17, 2024
@classicrocker883
Copy link
Owner

this is a very thought out PR, have you also made one over @ MarlinFirmware?

so a few things if you can help me understand...
is the hw required to replace BL-Touch bed probe? so auto bed leveling cannot be used? or are there other options to make this work?

and how does this work? im not familiar with it. so the fan speed changes based on temperature?
and what fans exactly? part cooling fan and hotend fan, both? seperately or at same time?

I'd like to make a few suggestions, like instead of adding seperate files under src/feature, merge them into controllerfan.cpp/.h. same for under src/gcode/feature/controllerfan, to group M711/M712.cpp with M710.cpp.
or you can put them all in one file and call it M710-M712.cpp

this way, settings.cpp doesnt have to be changed and it will fall under controllerFan_settings
you can incorporate it within class ControllerFan and struct, or make Kickstart and Autofans a subclass of it.

what do you think?

Signed-off-by: wlkmanist <[email protected]>
@wlkmanist
Copy link
Author

wlkmanist commented Apr 18, 2024

this is a very thought out PR, have you also made one over @ MarlinFirmware?

No. I need to check if it uses any ProUI functions.

so a few things if you can help me understand... is the hw required to replace BL-Touch bed probe? so auto bed leveling cannot be used? or are there other options to make this work?

Any available pins can be used if the board have not controllable fan ports without modification (boards like a creality 4.2.2 just have extruder fan connected to 24v and controller fan in parallel with nozzle fan. BTT SKR boards, as I know, have controllable fan ports). BL-Touch can be used (I just made a modular solution for that connector). You can set pins in config or xxx_pins.h. I was not changed any Marlin pins code, it is work as before.

and how does this work? im not familiar with it. so the fan speed changes based on temperature? and what fans exactly? part cooling fan and hotend fan, both? seperately or at same time?

I am added ~3 independed features:
Auto fans (extruder fan (that on coldend), heated chamber fan, laser cooling) just have now user controlled variable to set a temp threshold. Above that threshold specified fan turns on (that behavor existed before and setup was only via config). For example, nozzle > 50°, radiator fan enables, below that threshold it disables.
Controller fan logic already in Marlin, I am just added a menu to the dwin lcd. For now it functions very simple: steppers enabled - then fan(s) turned on, steppers disabled - fan(s) turns off after specified timeout. Thats auto mode. With manual mode you can set a static fan speed.
Kickstart options was implemented in Marlin, but only with 2 macroses and setup only via config. I added variables, menu, enable/disable boolean and so on. Kickstart works for all fans (and laser) that Marlin defines like a fan. It helps starting any fan at lower speeds.

I'd like to make a few suggestions, like instead of adding seperate files under src/feature, merge them into controllerfan.cpp/.h. same for under src/gcode/feature/controllerfan, to group M711/M712.cpp with M710.cpp. or you can put them all in one file and call it M710-M712.cpp

this way, settings.cpp doesnt have to be changed and it will fall under controllerFan_settings you can incorporate it within class ControllerFan and struct, or make Kickstart and Autofans a subclass of it.

Maybe, but that features are really independend, doing different things and can work without each other and with different hw build. G-code cpp files may be combined, I think, but not the others as it will be more difficult to understand the code. But may be I am wrong. I will look at the code later.

what do you think?

Overall, that code works for me around three weeks and made my printer really comfortable without any disadvantages. Also code may be near to complete disabled via config. I will continue adding more functionals as this, but now it is usable and stable as I can test.

@wlkmanist
Copy link
Author

wlkmanist commented Apr 19, 2024

this is a very thought out PR, have you also made one over @ MarlinFirmware?

No, I can't. There is some different code (at least in dwin.cpp), and I can't test it after merging this. But it can be ported someway.

and how does this work?
You can try Kickstart feature even with stock board without any hw modification, how it feels and how it works.

This PR is ready to merge if we don't need even more controllable Auto Fans now, that will require more memory if that features is enabled (I will do that later with more free time).

I am thinking about nozzle fan cooldown speed + temp threshold feature (will be useful when used 3d printed cooling shroud near nozzle, prevents melting it) that will override minimum (if min = 0) speed while hotend above temp threshold but heater is disabled.

I can also add Auto Fans speed variables that will work instead of EXTRUDER_AUTO_FAN_SPEED, CHAMBER_AUTO_FAN_SPEED and COOLER_AUTO_FAN_SPEED if AUTO_FAN_EDITABLE is enabled.

What do you think about this?

this way, settings.cpp doesnt have to be changed and it will fall under controllerFan_settings

Is it necessary to leave settings.cpp as is? Or you mean that it is better to store settings just in one struct someway?

@classicrocker883
Copy link
Owner

I am thinking about nozzle fan cooldown speed + temp threshold feature (will be useful when used 3d printed cooling shroud near nozzle, prevents melting it) that will override minimum (if min = 0) speed while hotend above temp threshold but heater is disabled.

this would be good, while temp is still hot fans still on.
take a look at this code in proui/dwin.cpp

void update_variable() {
    const celsius_t bc = thermalManager.wholeDegBed(),
                    bt = thermalManager.degTargetBed();
    // if bed is near target, heating, or if degrees > 44, ICON indicates hot
    if (thermalManager.degBedNear(bt) || thermalManager.isHeatingBed() || (bc > 44)) {
      DWIN_Draw_Box(1, HMI_data.Background_Color, 9, 416, 20, 20);
      DWINUI::Draw_Icon(ICON_BedTemp, 9, 416);
    }

you can use this as an example, basically, if hotend/bed is heating, or above a certain temp, the ICON changes. you may have noticed this when printing. the ICON's change when hot/cool. you can use similar code for controlling fan speeds if that helps you out.

I can also add Auto Fans speed variables that will work instead of EXTRUDER_AUTO_FAN_SPEED, CHAMBER_AUTO_FAN_SPEED and COOLER_AUTO_FAN_SPEED if AUTO_FAN_EDITABLE is enabled.

so instead of making it one fan speed, it can vary depending on the temperature?


here is what I do not understand, the hotend fan is on all the time, so the board would use PWM to adjust the speed? or how would it work using a PIN? so this works the same way for the nozzle/part cooling fan when printing?

@wlkmanist
Copy link
Author

wlkmanist commented Apr 20, 2024

so instead of making it one fan speed, it can vary depending on the temperature?

No, it is 2 states for that fans: on and off. That variables sets speeds for "on" state. Fans enabed after reaching its temperature threshold. This is Marlin behavour, I am not going to change that because variable Auto Fans speeds having only downsides. We always need maximum possible cooling for the extruder radiator fan and probably for laser too. But in some rare hardware build scenarios changing maximum speed may be useful, or maybe for chamber fan (espesially with g-code).

But it would be possible to change semi-dynamically that speeds using any slicer software that would support this gcodes (that feaure is not implemented yet).

here is what I do not understand, the hotend fan is on all the time, so the board would use PWM to adjust the speed?

Hotend fan is on only after hotend thermistor temp is above specified fan threshold, speeds are on and off, non adjustable automatically. PWM works, under the hood for speeds that non 0 and non 255.

or how would it work using a PIN? so this works the same way for the nozzle/part cooling fan when printing?

It can be connected with the same hardware schematic like a nozzle/part cooling fan. PIN allows that fan to be controllable, it controls the mosfet of connected fan circuit, like a nozzle fan. You specify the pins corresponding your connection/board in config like it was before this PR and magic works.

@classicrocker883
Copy link
Owner

I have yet to fully look through this PR. I would like to make a couple changes. the thing is this is not for the average user because of the hardware modifications needed, right?

I see you have a jumper wire connected to the driver for E stepper motor and DIO pin. is that so you can enable UART? or is that also needed for the fans

@wlkmanist
Copy link
Author

wlkmanist commented May 6, 2024

the thing is this is not for the average user because of the hardware modifications needed, right?

For some boards modifications don't needed. For stock Aquila and Creality boards - yes. But I don't modified my board for fans, I just made an adapter that connects to my board. It is not as hard as connecting BLTouch to the board.

I see you have a jumper wire connected to the driver for E stepper motor and DIO pin. is that so you can enable UART? or is that also needed for the fans

It is UART for E driver. Now I made UART for all drivers:
MVIMG_20240420_033211

For fans I also made custom pcb, that not tested yet. It is much more complex than DIY solution, but should work pretty much the same. Connects to debug pins:
IMG_20240506_212004_568

@wlkmanist
Copy link
Author

I would like to make a couple changes.

What kind of changes?

@classicrocker883
Copy link
Owner

the changes I'd make is to combine the features, like autofans.cpp, M711.cpp with controllerfan. so instead of having its own file and folder. I would leave the Gcode files, but put them in the same folder as M710.cpp

@classicrocker883 classicrocker883 changed the base branch from 2024-April to 2024-May May 13, 2024 04:20
@classicrocker883 classicrocker883 added the enhancement New feature or request label Aug 7, 2024
Copy link

This pull request has had no activity in the last 60 days. Please update your branch.

@github-actions github-actions bot added the Stale Been awhile, will be closing soon. label Oct 13, 2024
@classicrocker883 classicrocker883 changed the base branch from 2024-May to 2024-December December 28, 2024 08:16
Copy link
Owner

@classicrocker883 classicrocker883 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been adjusting this PR to merge with the more current branch, one question is this:

void ResetMenu(MenuClass* &menu) {
  if (menu) {
    menu->topline = 0;
    menu->selected = 0;
  }
}

void InvalidateMenu() {
  ResetMenu(CurrentMenu);
  CurrentMenu = nullptr;
}

void PrepareRefreshMenu() {
  if (CurrentMenu) CurrentMenu->topline = 0;
  CurrentMenu = nullptr;
}

PrepareRefreshMenu() is new/added. would it work the same to just use InvalidateMenu() in place??

@wlkmanist
Copy link
Author

wlkmanist commented Dec 28, 2024

I've been adjusting this PR to merge with the more current branch, one question is this:

void ResetMenu(MenuClass* &menu) {
  if (menu) {
    menu->topline = 0;
    menu->selected = 0;
  }
}

void InvalidateMenu() {
  ResetMenu(CurrentMenu);
  CurrentMenu = nullptr;
}

void PrepareRefreshMenu() {
  if (CurrentMenu) CurrentMenu->topline = 0;
  CurrentMenu = nullptr;
}

PrepareRefreshMenu() is new/added. would it work the same to just use InvalidateMenu() in place??

I don't remember right now, but probably no, if I added a new function here. This function should be for refreshing menu after a boolean/checkbox menu variable changed to hide "disabled" functionals. So, current menu index will be the same after that value changed.

@github-actions github-actions bot removed the Stale Been awhile, will be closing soon. label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants