Translate encoder comments
This commit is contained in:
parent
e48b283e39
commit
5e3d051b6a
@ -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 Rotary encoder functions
|
||||||
* @brief 旋转编码器操作函数
|
*****************************************************************************/
|
||||||
******************************************************************************
|
|
||||||
**/
|
|
||||||
|
|
||||||
#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
|
||||||
|
@ -21,15 +21,13 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/**
|
/*****************************************************************************
|
||||||
******************************************************************************
|
|
||||||
* @file rotary_encoder.h
|
* @file rotary_encoder.h
|
||||||
* @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/MarlinConfig.h"
|
#include "../../../inc/MarlinConfig.h"
|
||||||
#include "../../../MarlinCore.h"
|
#include "../../../MarlinCore.h"
|
||||||
@ -54,19 +52,18 @@ typedef struct {
|
|||||||
extern ENCODER_Rate EncoderRate;
|
extern ENCODER_Rate EncoderRate;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENCODER_DIFF_NO = 0,
|
ENCODER_DIFF_NO = 0, // no state
|
||||||
ENCODER_DIFF_CW = 1,
|
ENCODER_DIFF_CW = 1, // clockwise rotation
|
||||||
ENCODER_DIFF_CCW = 2,
|
ENCODER_DIFF_CCW = 2, // counterclockwise rotation
|
||||||
ENCODER_DIFF_ENTER = 3
|
ENCODER_DIFF_ENTER = 3 // click
|
||||||
} ENCODER_DiffState;
|
} ENCODER_DiffState;
|
||||||
|
|
||||||
/*编码器初始化 PB12:Encoder_A PB13:Encoder_B PB14:Encoder_C*/
|
// Encoder initialization
|
||||||
void Encoder_Configuration(void);
|
void Encoder_Configuration(void);
|
||||||
|
|
||||||
/*接收数据解析 返回值:ENCODER_DIFF_NO,无状态; ENCODER_DIFF_CW,顺时针旋转; ENCODER_DIFF_CCW,逆时针旋转; ENCODER_DIFF_ENTER,按下*/
|
// Analyze encoder value and return state
|
||||||
ENCODER_DiffState Encoder_ReceiveAnalyze(void);
|
ENCODER_DiffState Encoder_ReceiveAnalyze(void);
|
||||||
|
|
||||||
|
|
||||||
/*********************** Encoder LED ***********************/
|
/*********************** Encoder LED ***********************/
|
||||||
|
|
||||||
#if PIN_EXISTS(LCD_LED)
|
#if PIN_EXISTS(LCD_LED)
|
||||||
@ -78,28 +75,30 @@ ENCODER_DiffState Encoder_ReceiveAnalyze(void);
|
|||||||
#define RGB_SCALE_R10_G7_B5 1
|
#define RGB_SCALE_R10_G7_B5 1
|
||||||
#define RGB_SCALE_R10_G7_B4 2
|
#define RGB_SCALE_R10_G7_B4 2
|
||||||
#define RGB_SCALE_R10_G8_B7 3
|
#define RGB_SCALE_R10_G8_B7 3
|
||||||
#define RGB_SCALE_NEUTRAL_WHITE RGB_SCALE_R10_G7_B5 //正白
|
#define RGB_SCALE_NEUTRAL_WHITE RGB_SCALE_R10_G7_B5
|
||||||
#define RGB_SCALE_WARM_WHITE RGB_SCALE_R10_G7_B4 //暖白
|
#define RGB_SCALE_WARM_WHITE RGB_SCALE_R10_G7_B4
|
||||||
#define RGB_SCALE_COOL_WHITE RGB_SCALE_R10_G8_B7 //冷白
|
#define RGB_SCALE_COOL_WHITE RGB_SCALE_R10_G8_B7
|
||||||
|
|
||||||
extern unsigned int LED_DataArray[LED_NUM];
|
extern unsigned int LED_DataArray[LED_NUM];
|
||||||
|
|
||||||
/*状态LED初始化*/
|
// LED light operation
|
||||||
void STATE_LED_Configuration(void);
|
|
||||||
|
|
||||||
/*LED灯操作*/
|
|
||||||
void LED_Action(void);
|
void LED_Action(void);
|
||||||
|
|
||||||
/*LED初始化*/
|
// LED initialization
|
||||||
void LED_Configuration(void);
|
void LED_Configuration(void);
|
||||||
|
|
||||||
/*LED写数据*/
|
// LED write data
|
||||||
void LED_WriteData(void);
|
void LED_WriteData(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);
|
||||||
|
|
||||||
/*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);
|
||||||
|
|
||||||
#endif
|
#endif // LCD_LED
|
||||||
|
Loading…
Reference in New Issue
Block a user