Queued fan control. Issue #90
This commit is contained in:
parent
21e2bae063
commit
aac7aa3bf0
6 changed files with 29 additions and 22 deletions
|
@ -175,6 +175,7 @@ extern float homing_feedrate[];
|
|||
extern bool axis_relative_modes[];
|
||||
extern float current_position[NUM_AXIS] ;
|
||||
extern float add_homeing[3];
|
||||
extern unsigned char FanSpeed;
|
||||
|
||||
// Handling multiple extruders pins
|
||||
extern uint8_t active_extruder;
|
||||
|
|
|
@ -131,6 +131,7 @@ volatile int extrudemultiply=100; //100->1 200->2
|
|||
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
|
||||
float add_homeing[3]={0,0,0};
|
||||
uint8_t active_extruder = 0;
|
||||
unsigned char FanSpeed=0;
|
||||
|
||||
//===========================================================================
|
||||
//=============================private variables=============================
|
||||
|
@ -145,8 +146,6 @@ static long gcode_N, gcode_LastN;
|
|||
static bool relative_mode = false; //Determines Absolute or Relative Coordinates
|
||||
static bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
|
||||
|
||||
static uint8_t fanpwm=0;
|
||||
|
||||
static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
|
||||
static bool fromsd[BUFSIZE];
|
||||
static int bufindr = 0;
|
||||
|
@ -938,19 +937,14 @@ void process_commands()
|
|||
#if FAN_PIN > -1
|
||||
case 106: //M106 Fan On
|
||||
if (code_seen('S')){
|
||||
WRITE(FAN_PIN,HIGH);
|
||||
fanpwm=constrain(code_value(),0,255);
|
||||
analogWrite(FAN_PIN, fanpwm);
|
||||
FanSpeed=constrain(code_value(),0,255);
|
||||
}
|
||||
else {
|
||||
WRITE(FAN_PIN,HIGH);
|
||||
fanpwm=255;
|
||||
analogWrite(FAN_PIN, fanpwm);
|
||||
FanSpeed=255;
|
||||
}
|
||||
break;
|
||||
case 107: //M107 Fan Off
|
||||
WRITE(FAN_PIN,LOW);
|
||||
analogWrite(FAN_PIN, 0);
|
||||
FanSpeed = 0;
|
||||
break;
|
||||
#endif //FAN_PIN
|
||||
|
||||
|
|
|
@ -418,23 +418,34 @@ void check_axes_activity() {
|
|||
unsigned char y_active = 0;
|
||||
unsigned char z_active = 0;
|
||||
unsigned char e_active = 0;
|
||||
unsigned char fan_speed = 0;
|
||||
unsigned char tail_fan_speed = 0;
|
||||
block_t *block;
|
||||
|
||||
if(block_buffer_tail != block_buffer_head) {
|
||||
uint8_t block_index = block_buffer_tail;
|
||||
tail_fan_speed = block_buffer[block_index].fan_speed;
|
||||
while(block_index != block_buffer_head) {
|
||||
block = &block_buffer[block_index];
|
||||
if(block->steps_x != 0) x_active++;
|
||||
if(block->steps_y != 0) y_active++;
|
||||
if(block->steps_z != 0) z_active++;
|
||||
if(block->steps_e != 0) e_active++;
|
||||
if(block->fan_speed != 0) fan_speed++;
|
||||
block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (FanSpeed != 0) analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed
|
||||
}
|
||||
if((DISABLE_X) && (x_active == 0)) disable_x();
|
||||
if((DISABLE_Y) && (y_active == 0)) disable_y();
|
||||
if((DISABLE_Z) && (z_active == 0)) disable_z();
|
||||
if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); }
|
||||
if((FanSpeed == 0) && (fan_speed ==0)) analogWrite(FAN_PIN, 0);
|
||||
if (FanSpeed != 0 && tail_fan_speed !=0) {
|
||||
analogWrite(FAN_PIN,tail_fan_speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -498,6 +509,8 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
|
|||
// Bail if this is a zero-length block
|
||||
if (block->step_event_count <=dropsegments) { return; };
|
||||
|
||||
block->fan_speed = FanSpeed;
|
||||
|
||||
// Compute direction bits for this block
|
||||
block->direction_bits = 0;
|
||||
if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef struct {
|
|||
unsigned long initial_rate; // The jerk-adjusted step rate at start of block
|
||||
unsigned long final_rate; // The minimal rate at exit
|
||||
unsigned long acceleration_st; // acceleration steps/sec^2
|
||||
unsigned long fan_speed;
|
||||
volatile char busy;
|
||||
} block_t;
|
||||
|
||||
|
|
|
@ -21,9 +21,6 @@
|
|||
/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
|
||||
and Philipp Tiefenbacher. */
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Marlin.h"
|
||||
#include "stepper.h"
|
||||
#include "planner.h"
|
||||
|
@ -303,7 +300,8 @@ ISR(TIMER1_COMPA_vect)
|
|||
counter_y = counter_x;
|
||||
counter_z = counter_x;
|
||||
counter_e = counter_x;
|
||||
step_events_completed = 0;
|
||||
step_events_completed = 0;
|
||||
|
||||
#ifdef Z_LATE_ENABLE
|
||||
if(current_block->steps_z > 0) {
|
||||
enable_z();
|
||||
|
|
|
@ -812,7 +812,7 @@ void MainMenu::showTune()
|
|||
if(force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
|
||||
lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
|
||||
lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
|
||||
}
|
||||
|
||||
if((activeline!=line) )
|
||||
|
@ -823,7 +823,7 @@ void MainMenu::showTune()
|
|||
linechanging=!linechanging;
|
||||
if(linechanging)
|
||||
{
|
||||
encoderpos=fanpwm;
|
||||
encoderpos=FanSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -836,8 +836,8 @@ void MainMenu::showTune()
|
|||
{
|
||||
if(encoderpos<0) encoderpos=0;
|
||||
if(encoderpos>255) encoderpos=255;
|
||||
fanpwm=encoderpos;
|
||||
analogWrite(FAN_PIN, fanpwm);
|
||||
FanSpeed=encoderpos;
|
||||
analogWrite(FAN_PIN, FanSpeed);
|
||||
lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
|
||||
}
|
||||
|
||||
|
@ -1134,7 +1134,7 @@ void MainMenu::showControlTemp()
|
|||
if(force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
|
||||
lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
|
||||
lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
|
||||
}
|
||||
|
||||
if((activeline!=line) )
|
||||
|
@ -1145,7 +1145,7 @@ void MainMenu::showControlTemp()
|
|||
linechanging=!linechanging;
|
||||
if(linechanging)
|
||||
{
|
||||
encoderpos=fanpwm;
|
||||
encoderpos=FanSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1158,8 +1158,8 @@ void MainMenu::showControlTemp()
|
|||
{
|
||||
if(encoderpos<0) encoderpos=0;
|
||||
if(encoderpos>255) encoderpos=255;
|
||||
fanpwm=encoderpos;
|
||||
analogWrite(FAN_PIN, fanpwm);
|
||||
FanSpeed=encoderpos;
|
||||
analogWrite(FAN_PIN, FanSpeed);
|
||||
lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue