|
@ -20,15 +20,13 @@ |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
/**
|
|
|
/*****************************************************************************
|
|
|
****************************************************************************** |
|
|
|
|
|
* @file rotary_encoder.cpp |
|
|
* @file rotary_encoder.cpp |
|
|
* @author LEO / Creality3D |
|
|
* @author LEO / Creality3D |
|
|
* @date 2019/07/06 |
|
|
* @date 2019/07/06 |
|
|
* @version 2.0.1 |
|
|
* @version 2.0.1 |
|
|
* @brief 旋转编码器操作函数 |
|
|
* @brief Rotary encoder functions |
|
|
****************************************************************************** |
|
|
*****************************************************************************/ |
|
|
**/ |
|
|
|
|
|
|
|
|
|
|
|
#include "../../../inc/MarlinConfigPre.h" |
|
|
#include "../../../inc/MarlinConfigPre.h" |
|
|
|
|
|
|
|
@ -47,14 +45,14 @@ |
|
|
|
|
|
|
|
|
ENCODER_Rate EncoderRate; |
|
|
ENCODER_Rate EncoderRate; |
|
|
|
|
|
|
|
|
/*蜂鸣器响*/ |
|
|
// Buzzer
|
|
|
void Encoder_tick(void) { |
|
|
void Encoder_tick(void) { |
|
|
WRITE(BEEPER_PIN, 1); |
|
|
WRITE(BEEPER_PIN, 1); |
|
|
delay(10); |
|
|
delay(10); |
|
|
WRITE(BEEPER_PIN, 0); |
|
|
WRITE(BEEPER_PIN, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*编码器初始化 PB12:Encoder_A PB13:Encoder_B PB14:Encoder_C*/ |
|
|
// Encoder initialization
|
|
|
void Encoder_Configuration(void) { |
|
|
void Encoder_Configuration(void) { |
|
|
#if BUTTON_EXISTS(EN1) |
|
|
#if BUTTON_EXISTS(EN1) |
|
|
SET_INPUT_PULLUP(BTN_EN1); |
|
|
SET_INPUT_PULLUP(BTN_EN1); |
|
@ -70,8 +68,7 @@ void Encoder_Configuration(void) { |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
millis_t next_click_update_ms; |
|
|
// Analyze encoder value and return state
|
|
|
/*接收数据解析 返回值:ENCODER_DIFF_NO,无状态; ENCODER_DIFF_CW,顺时针旋转; ENCODER_DIFF_CCW,逆时针旋转; ENCODER_DIFF_ENTER,按下*/ |
|
|
|
|
|
ENCODER_DiffState Encoder_ReceiveAnalyze(void) { |
|
|
ENCODER_DiffState Encoder_ReceiveAnalyze(void) { |
|
|
const millis_t now = millis(); |
|
|
const millis_t now = millis(); |
|
|
static unsigned char lastEncoderBits; |
|
|
static unsigned char lastEncoderBits; |
|
@ -82,6 +79,7 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) { |
|
|
if (BUTTON_PRESSED(EN1)) newbutton |= 0x01; |
|
|
if (BUTTON_PRESSED(EN1)) newbutton |= 0x01; |
|
|
if (BUTTON_PRESSED(EN2)) newbutton |= 0x02; |
|
|
if (BUTTON_PRESSED(EN2)) newbutton |= 0x02; |
|
|
if (BUTTON_PRESSED(ENC)) { |
|
|
if (BUTTON_PRESSED(ENC)) { |
|
|
|
|
|
static millis_t next_click_update_ms; |
|
|
if (ELAPSED(now, next_click_update_ms)) { |
|
|
if (ELAPSED(now, next_click_update_ms)) { |
|
|
next_click_update_ms = millis() + 300; |
|
|
next_click_update_ms = millis() + 300; |
|
|
Encoder_tick(); |
|
|
Encoder_tick(); |
|
@ -154,22 +152,22 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) { |
|
|
|
|
|
|
|
|
#if PIN_EXISTS(LCD_LED) |
|
|
#if PIN_EXISTS(LCD_LED) |
|
|
|
|
|
|
|
|
/*取低24位有效 24Bit: G7 G6 G5 G4 G3 G2 G1 G0 R7 R6 R5 R4 R3 R2 R1 R0 B7 B6 B5 B4 B3 B2 B1 B0*/ |
|
|
// Take the low 24 valid bits 24Bit: G7 G6 G5 G4 G3 G2 G1 G0 R7 R6 R5 R4 R3 R2 R1 R0 B7 B6 B5 B4 B3 B2 B1 B0
|
|
|
unsigned int LED_DataArray[LED_NUM]; |
|
|
unsigned int LED_DataArray[LED_NUM]; |
|
|
|
|
|
|
|
|
/*LED灯操作*/ |
|
|
// LED light operation
|
|
|
void LED_Action(void) { |
|
|
void LED_Action(void) { |
|
|
LED_Control(RGB_SCALE_WARM_WHITE,0x0F); |
|
|
LED_Control(RGB_SCALE_WARM_WHITE,0x0F); |
|
|
delay(30); |
|
|
delay(30); |
|
|
LED_Control(RGB_SCALE_WARM_WHITE,0x00); |
|
|
LED_Control(RGB_SCALE_WARM_WHITE,0x00); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*LED初始化*/ |
|
|
// LED initialization
|
|
|
void LED_Configuration(void) { |
|
|
void LED_Configuration(void) { |
|
|
SET_OUTPUT(LCD_LED_PIN); |
|
|
SET_OUTPUT(LCD_LED_PIN); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*LED写数据*/ |
|
|
// LED write data
|
|
|
void LED_WriteData(void) { |
|
|
void LED_WriteData(void) { |
|
|
unsigned char tempCounter_LED, tempCounter_Bit; |
|
|
unsigned char tempCounter_LED, tempCounter_Bit; |
|
|
for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) { |
|
|
for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) { |
|
@ -189,7 +187,9 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*LED控制 RGB_Scale:RGB色彩配比 luminance:亮度(0~0xFF)*/ |
|
|
// LED control
|
|
|
|
|
|
// RGB_Scale: RGB color ratio
|
|
|
|
|
|
// luminance: brightness (0~0xFF)
|
|
|
void LED_Control(unsigned char RGB_Scale, unsigned char luminance) { |
|
|
void LED_Control(unsigned char RGB_Scale, unsigned char luminance) { |
|
|
unsigned char temp_Counter; |
|
|
unsigned char temp_Counter; |
|
|
for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) { |
|
|
for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) { |
|
@ -203,7 +203,10 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) { |
|
|
LED_WriteData(); |
|
|
LED_WriteData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*LED渐变控制 RGB_Scale:RGB色彩配比 luminance:亮度(0~0xFF) change_Time:渐变时间(ms)*/ |
|
|
// LED gradient control
|
|
|
|
|
|
// RGB_Scale: RGB color ratio
|
|
|
|
|
|
// luminance: brightness (0~0xFF)
|
|
|
|
|
|
// change_Time: gradient time (ms)
|
|
|
void LED_GraduallyControl(unsigned char RGB_Scale, unsigned char luminance, unsigned int change_Interval) { |
|
|
void LED_GraduallyControl(unsigned char RGB_Scale, unsigned char luminance, unsigned int change_Interval) { |
|
|
unsigned char temp_Counter; |
|
|
unsigned char temp_Counter; |
|
|
unsigned char LED_R_Data[LED_NUM], LED_G_Data[LED_NUM], LED_B_Data[LED_NUM]; |
|
|
unsigned char LED_R_Data[LED_NUM], LED_G_Data[LED_NUM], LED_B_Data[LED_NUM]; |
|
@ -246,6 +249,6 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif |
|
|
#endif // LCD_LED
|
|
|
|
|
|
|
|
|
#endif // DWIN_CREALITY_LCD
|
|
|
#endif // DWIN_CREALITY_LCD
|
|
|