Merge pull request #29 from XPila/MK3

LCD backlight brightnes pwm control and lcd blinking.
This commit is contained in:
XPila 2017-08-21 17:30:04 +02:00 committed by GitHub
commit 0cd0953559
4 changed files with 75 additions and 10 deletions

View file

@ -269,6 +269,11 @@ extern void homeaxis(int axis);
extern unsigned char fanSpeedSoftPwm; extern unsigned char fanSpeedSoftPwm;
#endif #endif
#if defined(LCD_PWM_PIN) && (LCD_PWM_PIN > -1)
extern unsigned char lcdSoftPwm;
extern unsigned char lcdBlinkDelay;
#endif
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
extern float filament_width_nominal; //holds the theoretical filament diameter ie., 3.00 or 1.75 extern float filament_width_nominal; //holds the theoretical filament diameter ie., 3.00 or 1.75
extern bool filament_sensor; //indicates that filament sensor readings should control extrusion extern bool filament_sensor; //indicates that filament sensor readings should control extrusion

View file

@ -1256,10 +1256,14 @@ void setup()
#if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 #if defined(CONTROLLERFAN_PIN) && (CONTROLLERFAN_PIN > -1)
SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan
#endif #endif
#if defined(LCD_PWM_PIN) && (LCD_PWM_PIN > -1)
SET_OUTPUT(LCD_PWM_PIN); //Set pin used for driver cooling fan
#endif
#ifdef DIGIPOT_I2C #ifdef DIGIPOT_I2C
digipot_i2c_init(); digipot_i2c_init();
#endif #endif
@ -6034,18 +6038,28 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
break; break;
case 3: case 3:
calibrate_z_auto(); if (code_seen('L')) // lcd pwm (0-255)
{
lcdSoftPwm = (int)code_value();
}
if (code_seen('B')) // lcd blink delay (0-255)
{
lcdBlinkDelay = (int)code_value();
}
// calibrate_z_auto();
/* MYSERIAL.print("fsensor_enable()"); /* MYSERIAL.print("fsensor_enable()");
#ifdef PAT9125 #ifdef PAT9125
fsensor_enable(); fsensor_enable();
#endif*/ #endif*/
break; break;
case 4: case 4:
// lcdBlinkDelay = 10;
/* MYSERIAL.print("fsensor_disable()"); /* MYSERIAL.print("fsensor_disable()");
#ifdef PAT9125 #ifdef PAT9125
fsensor_disable(); fsensor_disable();
#endif #endif
break;*/ break;*/
break;
case 5: case 5:
{ {
/* MYSERIAL.print("tmc2130_rd_MSCNT(0)="); /* MYSERIAL.print("tmc2130_rd_MSCNT(0)=");

View file

@ -98,6 +98,9 @@
#ifdef NEWPANEL #ifdef NEWPANEL
#define LCD_PWM_PIN 32 // lcd backlight brightnes pwm control pin
#define LCD_PWM_MAX 0x0f // lcd pwm maximum value (0x07=64Hz, 0x0f=32Hz, 0x1f=16Hz)
#define BEEPER 84 // Beeper on AUX-4 #define BEEPER 84 // Beeper on AUX-4
#define LCD_PINS_RS 82 #define LCD_PINS_RS 82
#define LCD_PINS_ENABLE 61 // !!! changed from 18 (EINY03) #define LCD_PINS_ENABLE 61 // !!! changed from 18 (EINY03)

View file

@ -75,6 +75,11 @@ float current_temperature_bed = 0.0;
unsigned char fanSpeedSoftPwm; unsigned char fanSpeedSoftPwm;
#endif #endif
#if defined(LCD_PWM_PIN) && (LCD_PWM_PIN > -1)
unsigned char lcdSoftPwm = (LCD_PWM_MAX * 2 + 1); //set default value to maximum
unsigned char lcdBlinkDelay = 0; //lcd blinking delay (0 = no blink)
#endif
unsigned char soft_pwm_bed; unsigned char soft_pwm_bed;
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
@ -129,6 +134,12 @@ static volatile bool temp_meas_ready = false;
static unsigned long extruder_autofan_last_check; static unsigned long extruder_autofan_last_check;
#endif #endif
#if defined(LCD_PWM_PIN) && (LCD_PWM_PIN > -1)
static unsigned char soft_pwm_lcd = 0;
static unsigned char lcd_blink_delay = 0;
static bool lcd_blink_on = false;
#endif
#if EXTRUDERS > 3 #if EXTRUDERS > 3
# error Unsupported number of extruders # error Unsupported number of extruders
#elif EXTRUDERS > 2 #elif EXTRUDERS > 2
@ -941,6 +952,11 @@ void tp_init()
#endif #endif
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
#endif
#if defined(LCD_PWM_PIN) && (LCD_PWM_PIN > -1)
soft_pwm_lcd = lcdSoftPwm / 2;
lcd_blink_delay = lcdBlinkDelay;
lcd_blink_on = true;
#endif #endif
#endif #endif
@ -1507,15 +1523,16 @@ ISR(TIMER0_COMPB_vect)
/* /*
* standard PWM modulation * standard PWM modulation
*/ */
if(pwm_count == 0){ if (pwm_count == 0)
{
soft_pwm_0 = soft_pwm[0]; soft_pwm_0 = soft_pwm[0];
if(soft_pwm_0 > 0) { if(soft_pwm_0 > 0)
{
WRITE(HEATER_0_PIN,1); WRITE(HEATER_0_PIN,1);
#ifdef HEATERS_PARALLEL #ifdef HEATERS_PARALLEL
WRITE(HEATER_1_PIN,1); WRITE(HEATER_1_PIN,1);
#endif #endif
} else WRITE(HEATER_0_PIN,0); } else WRITE(HEATER_0_PIN,0);
#if EXTRUDERS > 1 #if EXTRUDERS > 1
soft_pwm_1 = soft_pwm[1]; soft_pwm_1 = soft_pwm[1];
if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1); else WRITE(HEATER_1_PIN,0); if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1); else WRITE(HEATER_1_PIN,0);
@ -1533,12 +1550,35 @@ ISR(TIMER0_COMPB_vect)
if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0);
#endif #endif
} }
if(soft_pwm_0 < pwm_count) { if(soft_pwm_0 < pwm_count)
{
WRITE(HEATER_0_PIN,0); WRITE(HEATER_0_PIN,0);
#ifdef HEATERS_PARALLEL #ifdef HEATERS_PARALLEL
WRITE(HEATER_1_PIN,0); WRITE(HEATER_1_PIN,0);
#endif #endif
} }
#if defined(LCD_PWM_PIN) && (LCD_PWM_PIN > -1)
if ((pwm_count & LCD_PWM_MAX) == 0)
{
if (lcd_blink_delay)
{
lcd_blink_delay--;
if (lcd_blink_delay == 0)
{
lcd_blink_delay = lcdBlinkDelay;
lcd_blink_on = !lcd_blink_on;
}
}
else
{
lcd_blink_delay = lcdBlinkDelay;
lcd_blink_on = true;
}
soft_pwm_lcd = (lcd_blink_on) ? (lcdSoftPwm / 2) : 0;
if (soft_pwm_lcd > 0) WRITE(LCD_PWM_PIN,1); else WRITE(LCD_PWM_PIN,0);
}
#endif
#if EXTRUDERS > 1 #if EXTRUDERS > 1
if(soft_pwm_1 < pwm_count) WRITE(HEATER_1_PIN,0); if(soft_pwm_1 < pwm_count) WRITE(HEATER_1_PIN,0);
#endif #endif
@ -1551,6 +1591,9 @@ ISR(TIMER0_COMPB_vect)
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0);
#endif #endif
#if defined(LCD_PWM_PIN) && (LCD_PWM_PIN > -1)
if (soft_pwm_lcd < (pwm_count & LCD_PWM_MAX)) WRITE(LCD_PWM_PIN,0);
#endif
pwm_count += (1 << SOFT_PWM_SCALE); pwm_count += (1 << SOFT_PWM_SCALE);
pwm_count &= 0x7f; pwm_count &= 0x7f;