🎨 Consolidate Ender-3 V2 DWIN common code (#22778)
This commit is contained in:
committed by
Scott Lahteine
parent
5b593da04d
commit
e705a7724e
@ -138,7 +138,7 @@ constexpr uint16_t MROWS = TROWS - 1, // Last Row Index
|
||||
|
||||
// Value Init
|
||||
HMI_value_t HMI_ValueStruct;
|
||||
HMI_Flag_t HMI_flag{0};
|
||||
HMI_flag_t HMI_flag{0};
|
||||
|
||||
millis_t dwin_heat_time = 0;
|
||||
|
||||
@ -470,7 +470,7 @@ void Draw_Back_First(const bool is_sel=true) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, T &valref) {
|
||||
inline bool Apply_Encoder(const EncoderState &encoder_diffState, T &valref) {
|
||||
if (encoder_diffState == ENCODER_DIFF_CW)
|
||||
valref += EncoderRate.encoderMoveValue;
|
||||
else if (encoder_diffState == ENCODER_DIFF_CCW)
|
||||
@ -593,7 +593,7 @@ void DWIN_Draw_Label(const uint8_t row, const __FlashStringHelper *title) {
|
||||
DWIN_Draw_Label(row, (char*)title);
|
||||
}
|
||||
|
||||
void DWIN_Draw_Signed_Float(uint8_t size, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value) {
|
||||
void DWIN_Draw_Signed_Float(uint8_t size, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, int32_t value) {
|
||||
DWIN_Draw_String(true, size, Color_White, bColor, x - 8, y, value < 0 ? F("-") : F(" "));
|
||||
DWIN_Draw_FloatValue(true, true, 0, size, Color_White, bColor, iNum, fNum, x, y, value < 0 ? -value : value);
|
||||
}
|
||||
@ -607,7 +607,7 @@ void Draw_Edit_Integer4(const uint8_t row, const uint16_t value, const bool acti
|
||||
}
|
||||
|
||||
void Draw_Edit_Float3(const uint8_t row, const uint16_t value, const bool active=false) {
|
||||
DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, active ? Select_Color : Color_Bg_Black, 3, UNITFDIGITS, 220 - UNITFDIGITS * 8, EBASE(row), value);
|
||||
DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, active ? Select_Color : Color_Bg_Black, 3, UNITFDIGITS, 220 - UNITFDIGITS * 8, EBASE(row), (int32_t)value);
|
||||
}
|
||||
|
||||
void Draw_Edit_Signed_Float2(const uint8_t row, const float value, const bool active=false) {
|
||||
@ -1292,11 +1292,11 @@ void Goto_MainMenu() {
|
||||
TERN(HAS_ONESTEP_LEVELING, ICON_Leveling, ICON_StartInfo)();
|
||||
}
|
||||
|
||||
inline ENCODER_DiffState get_encoder_state() {
|
||||
inline EncoderState get_encoder_state() {
|
||||
static millis_t Encoder_ms = 0;
|
||||
const millis_t ms = millis();
|
||||
if (PENDING(ms, Encoder_ms)) return ENCODER_DIFF_NO;
|
||||
const ENCODER_DiffState state = Encoder_ReceiveAnalyze();
|
||||
const EncoderState state = Encoder_ReceiveAnalyze();
|
||||
if (state != ENCODER_DIFF_NO) Encoder_ms = ms + ENCODER_WAIT_MS;
|
||||
return state;
|
||||
}
|
||||
@ -1317,7 +1317,7 @@ void HMI_Move_Done(const AxisEnum axis) {
|
||||
}
|
||||
|
||||
void HMI_Move_X() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_X_scaled)) {
|
||||
Draw_Edit_Float3(1, HMI_ValueStruct.Move_X_scaled);
|
||||
@ -1331,7 +1331,7 @@ void HMI_Move_X() {
|
||||
}
|
||||
|
||||
void HMI_Move_Y() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Y_scaled)) {
|
||||
Draw_Edit_Float3(2, HMI_ValueStruct.Move_Y_scaled);
|
||||
@ -1345,7 +1345,7 @@ void HMI_Move_Y() {
|
||||
}
|
||||
|
||||
void HMI_Move_Z() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Z_scaled)) {
|
||||
Draw_Edit_Float3(3, HMI_ValueStruct.Move_Z_scaled);
|
||||
@ -1362,7 +1362,7 @@ void HMI_Move_Z() {
|
||||
|
||||
void HMI_Move_E() {
|
||||
static float last_E_scaled = 0;
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_E_scaled)) {
|
||||
last_E_scaled = HMI_ValueStruct.Move_E_scaled;
|
||||
@ -1383,7 +1383,7 @@ void HMI_Move_Z() {
|
||||
bool printer_busy() { return planner.movesplanned() || printingIsActive(); }
|
||||
|
||||
void HMI_Zoffset() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
uint8_t zoff_line;
|
||||
switch (HMI_ValueStruct.show_mode) {
|
||||
@ -1416,7 +1416,7 @@ void HMI_Move_Z() {
|
||||
#if HAS_HOTEND
|
||||
|
||||
void HMI_ETemp() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
uint8_t temp_line;
|
||||
switch (HMI_ValueStruct.show_mode) {
|
||||
@ -1458,7 +1458,7 @@ void HMI_Move_Z() {
|
||||
#if HAS_HEATED_BED
|
||||
|
||||
void HMI_BedTemp() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
uint8_t bed_line;
|
||||
switch (HMI_ValueStruct.show_mode) {
|
||||
@ -1500,7 +1500,7 @@ void HMI_Move_Z() {
|
||||
#if HAS_PREHEAT && HAS_FAN
|
||||
|
||||
void HMI_FanSpeed() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
uint8_t fan_line;
|
||||
switch (HMI_ValueStruct.show_mode) {
|
||||
@ -1541,7 +1541,7 @@ void HMI_Move_Z() {
|
||||
#endif // HAS_PREHEAT && HAS_FAN
|
||||
|
||||
void HMI_PrintSpeed() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.print_speed)) {
|
||||
checkkey = Tune;
|
||||
@ -1559,7 +1559,7 @@ void HMI_PrintSpeed() {
|
||||
#define LAST_AXIS TERN(HAS_HOTEND, E_AXIS, Z_AXIS)
|
||||
|
||||
void HMI_MaxFeedspeedXYZE() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Max_Feedspeed)) {
|
||||
checkkey = MaxSpeed;
|
||||
@ -1578,7 +1578,7 @@ void HMI_MaxFeedspeedXYZE() {
|
||||
}
|
||||
|
||||
void HMI_MaxAccelerationXYZE() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Max_Acceleration)) {
|
||||
checkkey = MaxAcceleration;
|
||||
@ -1599,7 +1599,7 @@ void HMI_MaxAccelerationXYZE() {
|
||||
#if HAS_CLASSIC_JERK
|
||||
|
||||
void HMI_MaxJerkXYZE() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Max_Jerk_scaled)) {
|
||||
checkkey = MaxJerk;
|
||||
@ -1620,7 +1620,7 @@ void HMI_MaxAccelerationXYZE() {
|
||||
#endif // HAS_CLASSIC_JERK
|
||||
|
||||
void HMI_StepXYZE() {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Max_Step_scaled)) {
|
||||
checkkey = Step;
|
||||
@ -1816,8 +1816,6 @@ void HMI_SDCardInit() { card.cdroot(); }
|
||||
|
||||
void MarlinUI::refresh() { /* Nothing to see here */ }
|
||||
|
||||
#define ICON_Folder ICON_More
|
||||
|
||||
#if ENABLED(SCROLL_LONG_FILENAMES)
|
||||
|
||||
char shift_name[LONG_FILENAME_LENGTH + 1];
|
||||
@ -2077,7 +2075,7 @@ void Draw_Print_File_Menu() {
|
||||
|
||||
// Main Process
|
||||
void HMI_MainMenu() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
if (encoder_diffState == ENCODER_DIFF_CW) {
|
||||
@ -2137,7 +2135,7 @@ void HMI_MainMenu() {
|
||||
|
||||
// Select (and Print) File
|
||||
void HMI_SelectFile() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
|
||||
const uint16_t hasUpDir = !card.flag.workDirIsRoot;
|
||||
|
||||
@ -2257,7 +2255,7 @@ void HMI_SelectFile() {
|
||||
|
||||
// Printing
|
||||
void HMI_Printing() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
if (HMI_flag.done_confirm_flag) {
|
||||
@ -2335,7 +2333,7 @@ void HMI_Printing() {
|
||||
|
||||
// Pause and Stop window
|
||||
void HMI_PauseOrStop() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
if (encoder_diffState == ENCODER_DIFF_CW)
|
||||
@ -2417,7 +2415,7 @@ void Item_Adv_HomeOffsets(const uint8_t row) {
|
||||
Item_AreaCopy(1, 76, 102, 87, row); // "Set Home Offsets"
|
||||
#endif
|
||||
}
|
||||
Draw_Menu_Line(row, ICON_HomeOff);
|
||||
Draw_Menu_Line(row, ICON_HomeOffset);
|
||||
Draw_More_Icon(row);
|
||||
}
|
||||
|
||||
@ -2434,7 +2432,7 @@ void Item_Adv_HomeOffsets(const uint8_t row) {
|
||||
say_probe_offs_en(row);
|
||||
#endif
|
||||
}
|
||||
Draw_Menu_Line(row, ICON_ProbeOff);
|
||||
Draw_Menu_Line(row, ICON_ProbeOffset);
|
||||
Draw_More_Icon(row);
|
||||
}
|
||||
|
||||
@ -2529,12 +2527,12 @@ void Item_HomeOffs_X(const uint8_t row) {
|
||||
}
|
||||
else {
|
||||
#ifdef USE_STRING_TITLES
|
||||
Draw_Menu_LineF(row, ICON_HomeOffX, GET_TEXT_F(MSG_HOME_OFFSET_X));
|
||||
Draw_Menu_LineF(row, ICON_HomeOffsetX, GET_TEXT_F(MSG_HOME_OFFSET_X));
|
||||
#else
|
||||
say_home_offs_en(row); say_x_en(75, row); // "Home Offset X"
|
||||
#endif
|
||||
}
|
||||
Draw_Menu_Line(row, ICON_HomeOff);
|
||||
Draw_Menu_Line(row, ICON_HomeOffset);
|
||||
Draw_Edit_Signed_Float3(row, HMI_ValueStruct.Home_OffX_scaled);
|
||||
}
|
||||
|
||||
@ -2544,12 +2542,12 @@ void Item_HomeOffs_Y(const uint8_t row) {
|
||||
}
|
||||
else {
|
||||
#ifdef USE_STRING_TITLES
|
||||
Draw_Menu_LineF(row, ICON_HomeOffY, GET_TEXT_F(MSG_HOME_OFFSET_Y));
|
||||
Draw_Menu_LineF(row, ICON_HomeOffsetY, GET_TEXT_F(MSG_HOME_OFFSET_Y));
|
||||
#else
|
||||
say_home_offs_en(row); say_y_en(75, row); // "Home Offset X"
|
||||
#endif
|
||||
}
|
||||
Draw_Menu_Line(row, ICON_HomeOff);
|
||||
Draw_Menu_Line(row, ICON_HomeOffset);
|
||||
Draw_Edit_Signed_Float3(row, HMI_ValueStruct.Home_OffY_scaled);
|
||||
}
|
||||
|
||||
@ -2559,12 +2557,12 @@ void Item_HomeOffs_Z(const uint8_t row) {
|
||||
}
|
||||
else {
|
||||
#ifdef USE_STRING_TITLES
|
||||
Draw_Menu_LineF(row, ICON_HomeOffZ, GET_TEXT_F(MSG_HOME_OFFSET_Z));
|
||||
Draw_Menu_LineF(row, ICON_HomeOffsetZ, GET_TEXT_F(MSG_HOME_OFFSET_Z));
|
||||
#else
|
||||
say_home_offs_en(row); say_z_en(75, row); // "Home Offset Z"
|
||||
#endif
|
||||
}
|
||||
Draw_Menu_Line(row, ICON_HomeOff);
|
||||
Draw_Menu_Line(row, ICON_HomeOffset);
|
||||
Draw_Edit_Signed_Float3(row, HMI_ValueStruct.Home_OffZ_scaled);
|
||||
}
|
||||
|
||||
@ -2602,8 +2600,8 @@ void Draw_HomeOff_Menu() {
|
||||
DWIN_Frame_TitleCopy(124, 431, 91, 12); // "Probe Offsets"
|
||||
#endif
|
||||
#ifdef USE_STRING_TITLES
|
||||
Draw_Menu_LineF(1, ICON_ProbeOffX, GET_TEXT_F(MSG_ZPROBE_XOFFSET)); // Probe X Offset
|
||||
Draw_Menu_LineF(2, ICON_ProbeOffY, GET_TEXT_F(MSG_ZPROBE_YOFFSET)); // Probe Y Offset
|
||||
Draw_Menu_LineF(1, ICON_ProbeOffsetX, GET_TEXT_F(MSG_ZPROBE_XOFFSET)); // Probe X Offset
|
||||
Draw_Menu_LineF(2, ICON_ProbeOffsetY, GET_TEXT_F(MSG_ZPROBE_YOFFSET)); // Probe Y Offset
|
||||
#else
|
||||
say_probe_offs_en(1); say_x_en(75, 1); // "Probe Offset X"
|
||||
say_probe_offs_en(2); say_y_en(75, 2); // "Probe Offset Y"
|
||||
@ -2615,6 +2613,7 @@ void Draw_HomeOff_Menu() {
|
||||
|
||||
if (select_item.now != CASE_BACK) Draw_Menu_Cursor(select_item.now);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include "../../../libs/buzzer.h"
|
||||
@ -2633,7 +2632,7 @@ void HMI_AudioFeedback(const bool success=true) {
|
||||
|
||||
// Prepare
|
||||
void HMI_Prepare() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -2847,7 +2846,7 @@ void Draw_Temperature_Menu() {
|
||||
|
||||
// Control
|
||||
void HMI_Control() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -2932,28 +2931,25 @@ void HMI_Control() {
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
|
||||
#if HAS_ONESTEP_LEVELING
|
||||
|
||||
// Leveling
|
||||
void HMI_Leveling() {
|
||||
Popup_Window_Leveling();
|
||||
DWIN_UpdateLCD();
|
||||
queue.inject_P(PSTR("G28O\nG29"));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Axis Move
|
||||
void HMI_AxisMove() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
||||
// popup window resume
|
||||
if (HMI_flag.ETempTooLow_flag) {
|
||||
if (HMI_flag.cold_flag) {
|
||||
if (encoder_diffState == ENCODER_DIFF_ENTER) {
|
||||
HMI_flag.ETempTooLow_flag = false;
|
||||
HMI_flag.cold_flag = false;
|
||||
HMI_ValueStruct.Move_E_scaled = current_position.e * MINUNITMULT;
|
||||
Draw_Move_Menu();
|
||||
Draw_Edit_Float3(1, HMI_ValueStruct.Move_X_scaled);
|
||||
@ -3003,7 +2999,7 @@ void HMI_AxisMove() {
|
||||
case 4: // Extruder
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
||||
if (thermalManager.tooColdToExtrude(0)) {
|
||||
HMI_flag.ETempTooLow_flag = true;
|
||||
HMI_flag.cold_flag = true;
|
||||
Popup_Window_ETempTooLow();
|
||||
DWIN_UpdateLCD();
|
||||
return;
|
||||
@ -3022,7 +3018,7 @@ void HMI_AxisMove() {
|
||||
|
||||
// TemperatureID
|
||||
void HMI_Temperature() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3449,7 +3445,7 @@ void Draw_Steps_Menu() {
|
||||
|
||||
// Motion
|
||||
void HMI_Motion() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3497,7 +3493,7 @@ void HMI_Motion() {
|
||||
|
||||
// Advanced Settings
|
||||
void HMI_AdvSet() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3594,7 +3590,7 @@ void HMI_AdvSet() {
|
||||
|
||||
// Home Offset
|
||||
void HMI_HomeOff() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3633,7 +3629,7 @@ void HMI_AdvSet() {
|
||||
}
|
||||
|
||||
void HMI_HomeOffN(const AxisEnum axis, float &posScaled, const_float_t lo, const_float_t hi) {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
if (Apply_Encoder(encoder_diffState, posScaled)) {
|
||||
@ -3654,9 +3650,10 @@ void HMI_AdvSet() {
|
||||
#endif // HAS_HOME_OFFSET
|
||||
|
||||
#if HAS_ONESTEP_LEVELING
|
||||
|
||||
// Probe Offset
|
||||
void HMI_ProbeOff() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3689,7 +3686,7 @@ void HMI_AdvSet() {
|
||||
}
|
||||
|
||||
void HMI_ProbeOffN(float &posScaled, float &offset_ref) {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
if (Apply_Encoder(encoder_diffState, posScaled)) {
|
||||
@ -3710,7 +3707,7 @@ void HMI_AdvSet() {
|
||||
|
||||
// Info
|
||||
void HMI_Info() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
if (encoder_diffState == ENCODER_DIFF_ENTER) {
|
||||
#if HAS_ONESTEP_LEVELING
|
||||
@ -3727,7 +3724,7 @@ void HMI_Info() {
|
||||
|
||||
// Tune
|
||||
void HMI_Tune() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3813,7 +3810,7 @@ void HMI_Tune() {
|
||||
|
||||
// PLA Preheat
|
||||
void HMI_PLAPreheatSetting() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3869,7 +3866,7 @@ void HMI_Tune() {
|
||||
|
||||
// ABS Preheat
|
||||
void HMI_ABSPreheatSetting() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3927,7 +3924,7 @@ void HMI_Tune() {
|
||||
|
||||
// Max Speed
|
||||
void HMI_MaxSpeed() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3956,7 +3953,7 @@ void HMI_MaxSpeed() {
|
||||
|
||||
// Max Acceleration
|
||||
void HMI_MaxAcceleration() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -3986,7 +3983,7 @@ void HMI_MaxAcceleration() {
|
||||
#if HAS_CLASSIC_JERK
|
||||
// Max Jerk
|
||||
void HMI_MaxJerk() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -4016,7 +4013,7 @@ void HMI_MaxAcceleration() {
|
||||
|
||||
// Step
|
||||
void HMI_Step() {
|
||||
ENCODER_DiffState encoder_diffState = get_encoder_state();
|
||||
EncoderState encoder_diffState = get_encoder_state();
|
||||
if (encoder_diffState == ENCODER_DIFF_NO) return;
|
||||
|
||||
// Avoid flicker by updating only the previous menu
|
||||
@ -4172,7 +4169,7 @@ void EachMomentUpdate() {
|
||||
DWIN_UpdateLCD();
|
||||
|
||||
while (recovery_flag) {
|
||||
ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
||||
if (encoder_diffState != ENCODER_DIFF_NO) {
|
||||
if (encoder_diffState == ENCODER_DIFF_ENTER) {
|
||||
recovery_flag = false;
|
||||
|
@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
#include "rotary_encoder.h"
|
||||
#include "../common/encoder.h"
|
||||
#include "../../../libs/BL24CXX.h"
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
@ -144,24 +144,21 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
uint8_t language;
|
||||
bool pause_flag:1;
|
||||
bool pause_action:1;
|
||||
bool print_finish:1;
|
||||
bool pause_flag:1; // printing is paused
|
||||
bool pause_action:1; // flag a pause action
|
||||
bool print_finish:1; // print was finished
|
||||
bool select_flag:1; // Popup button selected
|
||||
bool home_flag:1; // homing in course
|
||||
bool heat_flag:1; // 0: heating done 1: during heating
|
||||
bool done_confirm_flag:1;
|
||||
bool select_flag:1;
|
||||
bool home_flag:1;
|
||||
bool heat_flag:1; // 0: heating done 1: during heating
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
||||
bool ETempTooLow_flag:1;
|
||||
#endif
|
||||
#if HAS_LEVELING
|
||||
bool leveling_offset_flag:1;
|
||||
bool cold_flag:1;
|
||||
#endif
|
||||
AxisEnum feedspeed_axis, acc_axis, jerk_axis, step_axis;
|
||||
} HMI_Flag_t;
|
||||
} HMI_flag_t;
|
||||
|
||||
extern HMI_value_t HMI_ValueStruct;
|
||||
extern HMI_Flag_t HMI_flag;
|
||||
extern HMI_flag_t HMI_flag;
|
||||
|
||||
#if HAS_HOTEND || HAS_HEATED_BED
|
||||
// Popup message window
|
||||
|
@ -35,94 +35,13 @@
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
#include <string.h> // for memset
|
||||
|
||||
//#define DEBUG_OUT 1
|
||||
#include "../../../core/debug_out.h"
|
||||
|
||||
// Make sure DWIN_SendBuf is large enough to hold the largest string plus draw command and tail.
|
||||
// Assume the narrowest (6 pixel) font and 2-byte gb2312-encoded characters.
|
||||
uint8_t DWIN_SendBuf[11 + DWIN_WIDTH / 6 * 2] = { 0xAA };
|
||||
uint8_t DWIN_BufTail[4] = { 0xCC, 0x33, 0xC3, 0x3C };
|
||||
uint8_t databuf[26] = { 0 };
|
||||
uint8_t receivedType;
|
||||
|
||||
int recnum = 0;
|
||||
|
||||
inline void DWIN_Byte(size_t &i, const uint16_t bval) {
|
||||
DWIN_SendBuf[++i] = bval;
|
||||
}
|
||||
|
||||
inline void DWIN_Word(size_t &i, const uint16_t wval) {
|
||||
DWIN_SendBuf[++i] = wval >> 8;
|
||||
DWIN_SendBuf[++i] = wval & 0xFF;
|
||||
}
|
||||
|
||||
inline void DWIN_Long(size_t &i, const uint32_t lval) {
|
||||
DWIN_SendBuf[++i] = (lval >> 24) & 0xFF;
|
||||
DWIN_SendBuf[++i] = (lval >> 16) & 0xFF;
|
||||
DWIN_SendBuf[++i] = (lval >> 8) & 0xFF;
|
||||
DWIN_SendBuf[++i] = lval & 0xFF;
|
||||
}
|
||||
|
||||
inline void DWIN_String(size_t &i, char * const string) {
|
||||
const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, strlen(string));
|
||||
memcpy(&DWIN_SendBuf[i+1], string, len);
|
||||
i += len;
|
||||
}
|
||||
|
||||
inline void DWIN_String(size_t &i, const __FlashStringHelper * string) {
|
||||
if (!string) return;
|
||||
const size_t len = strlen_P((PGM_P)string); // cast it to PGM_P, which is basically const char *, and measure it using the _P version of strlen.
|
||||
if (len == 0) return;
|
||||
memcpy(&DWIN_SendBuf[i+1], string, len);
|
||||
i += len;
|
||||
}
|
||||
|
||||
// Send the data in the buffer and the packet end
|
||||
inline void DWIN_Send(size_t &i) {
|
||||
++i;
|
||||
LOOP_L_N(n, i) { LCD_SERIAL.write(DWIN_SendBuf[n]); delayMicroseconds(1); }
|
||||
LOOP_L_N(n, 4) { LCD_SERIAL.write(DWIN_BufTail[n]); delayMicroseconds(1); }
|
||||
}
|
||||
|
||||
/*-------------------------------------- System variable function --------------------------------------*/
|
||||
|
||||
// Handshake (1: Success, 0: Fail)
|
||||
bool DWIN_Handshake(void) {
|
||||
#ifndef LCD_BAUDRATE
|
||||
#define LCD_BAUDRATE 115200
|
||||
#endif
|
||||
LCD_SERIAL.begin(LCD_BAUDRATE);
|
||||
const millis_t serial_connect_timeout = millis() + 1000UL;
|
||||
while (!LCD_SERIAL.connected() && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
||||
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x00);
|
||||
DWIN_Send(i);
|
||||
|
||||
while (LCD_SERIAL.available() > 0 && recnum < (signed)sizeof(databuf)) {
|
||||
databuf[recnum] = LCD_SERIAL.read();
|
||||
// ignore the invalid data
|
||||
if (databuf[0] != FHONE) { // prevent the program from running.
|
||||
if (recnum > 0) {
|
||||
recnum = 0;
|
||||
ZERO(databuf);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
delay(10);
|
||||
recnum++;
|
||||
}
|
||||
|
||||
return ( recnum >= 3
|
||||
&& databuf[0] == FHONE
|
||||
&& databuf[1] == '\0'
|
||||
&& databuf[2] == 'O'
|
||||
&& databuf[3] == 'K' );
|
||||
}
|
||||
|
||||
void DWIN_Startup(void) {
|
||||
void DWIN_Startup() {
|
||||
DEBUG_ECHOPGM("\r\nDWIN handshake ");
|
||||
delay(750); // Delay here or init later in the boot process
|
||||
if (DWIN_Handshake()) DEBUG_ECHOLNPGM("ok."); else DEBUG_ECHOLNPGM("error.");
|
||||
@ -133,255 +52,14 @@ void DWIN_Startup(void) {
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
// Set the backlight luminance
|
||||
// luminance: (0x00-0xFF)
|
||||
void DWIN_Backlight_SetLuminance(const uint8_t luminance) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x30);
|
||||
DWIN_Byte(i, _MAX(luminance, 0x1F));
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Set screen display direction
|
||||
// dir: 0=0°, 1=90°, 2=180°, 3=270°
|
||||
void DWIN_Frame_SetDir(uint8_t dir) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x34);
|
||||
DWIN_Byte(i, 0x5A);
|
||||
DWIN_Byte(i, 0xA5);
|
||||
DWIN_Byte(i, dir);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Update display
|
||||
void DWIN_UpdateLCD(void) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x3D);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
/*---------------------------------------- Drawing functions ----------------------------------------*/
|
||||
|
||||
// Clear screen
|
||||
// color: Clear screen color
|
||||
void DWIN_Frame_Clear(const uint16_t color) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x01);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Draw a point
|
||||
// width: point width 0x01-0x0F
|
||||
// height: point height 0x01-0x0F
|
||||
// x,y: upper left point
|
||||
void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x02);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Byte(i, width);
|
||||
DWIN_Byte(i, height);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Draw a line
|
||||
// color: Line segment color
|
||||
// xStart/yStart: Start point
|
||||
// xEnd/yEnd: End point
|
||||
void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x03);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Word(i, xStart);
|
||||
DWIN_Word(i, yStart);
|
||||
DWIN_Word(i, xEnd);
|
||||
DWIN_Word(i, yEnd);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Draw a rectangle
|
||||
// mode: 0=frame, 1=fill, 2=XOR fill
|
||||
// color: Rectangle color
|
||||
// xStart/yStart: upper left point
|
||||
// xEnd/yEnd: lower right point
|
||||
void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color,
|
||||
uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x05);
|
||||
DWIN_Byte(i, mode);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Word(i, xStart);
|
||||
DWIN_Word(i, yStart);
|
||||
DWIN_Word(i, xEnd);
|
||||
DWIN_Word(i, yEnd);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Move a screen area
|
||||
// mode: 0, circle shift; 1, translation
|
||||
// dir: 0=left, 1=right, 2=up, 3=down
|
||||
// dis: Distance
|
||||
// color: Fill color
|
||||
// xStart/yStart: upper left point
|
||||
// xEnd/yEnd: bottom right point
|
||||
void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
|
||||
uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x09);
|
||||
DWIN_Byte(i, (mode << 7) | dir);
|
||||
DWIN_Word(i, dis);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Word(i, xStart);
|
||||
DWIN_Word(i, yStart);
|
||||
DWIN_Word(i, xEnd);
|
||||
DWIN_Word(i, yEnd);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
/*---------------------------------------- Text related functions ----------------------------------------*/
|
||||
|
||||
// Draw a string
|
||||
// widthAdjust: true=self-adjust character width; false=no adjustment
|
||||
// bShow: true=display background color; false=don't display background color
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// x/y: Upper-left coordinate of the string
|
||||
// *string: The string
|
||||
void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, char *string) {
|
||||
uint8_t widthAdjust = 0;
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x11);
|
||||
// Bit 7: widthAdjust
|
||||
// Bit 6: bShow
|
||||
// Bit 5-4: Unused (0)
|
||||
// Bit 3-0: size
|
||||
DWIN_Byte(i, (widthAdjust * 0x80) | (bShow * 0x40) | size);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Word(i, bColor);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_String(i, string);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Draw a positive integer
|
||||
// bShow: true=display background color; false=don't display background color
|
||||
// zeroFill: true=zero fill; false=no zero fill
|
||||
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// iNum: Number of digits
|
||||
// x/y: Upper-left coordinate
|
||||
// value: Integer value
|
||||
void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
|
||||
uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x14);
|
||||
// Bit 7: bshow
|
||||
// Bit 6: 1 = signed; 0 = unsigned number;
|
||||
// Bit 5: zeroFill
|
||||
// Bit 4: zeroMode
|
||||
// Bit 3-0: size
|
||||
DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Word(i, bColor);
|
||||
DWIN_Byte(i, iNum);
|
||||
DWIN_Byte(i, 0); // fNum
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
#if 0
|
||||
for (char count = 0; count < 8; count++) {
|
||||
DWIN_Byte(i, value);
|
||||
value >>= 8;
|
||||
if (!(value & 0xFF)) break;
|
||||
}
|
||||
#else
|
||||
// Write a big-endian 64 bit integer
|
||||
const size_t p = i + 1;
|
||||
for (char count = 8; count--;) { // 7..0
|
||||
++i;
|
||||
DWIN_SendBuf[p + count] = value;
|
||||
value >>= 8;
|
||||
}
|
||||
#endif
|
||||
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Draw a floating point number
|
||||
// bShow: true=display background color; false=don't display background color
|
||||
// zeroFill: true=zero fill; false=no zero fill
|
||||
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// iNum: Number of whole digits
|
||||
// fNum: Number of decimal digits
|
||||
// x/y: Upper-left point
|
||||
// value: Float value
|
||||
void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
|
||||
uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value) {
|
||||
//uint8_t *fvalue = (uint8_t*)&value;
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x14);
|
||||
DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
|
||||
DWIN_Word(i, color);
|
||||
DWIN_Word(i, bColor);
|
||||
DWIN_Byte(i, iNum);
|
||||
DWIN_Byte(i, fNum);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Long(i, value);
|
||||
/*
|
||||
DWIN_Byte(i, fvalue[3]);
|
||||
DWIN_Byte(i, fvalue[2]);
|
||||
DWIN_Byte(i, fvalue[1]);
|
||||
DWIN_Byte(i, fvalue[0]);
|
||||
*/
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
/*---------------------------------------- Picture related functions ----------------------------------------*/
|
||||
|
||||
// Draw JPG and cached in #0 virtual display area
|
||||
// id: Picture ID
|
||||
void DWIN_JPG_ShowAndCache(const uint8_t id) {
|
||||
size_t i = 0;
|
||||
DWIN_Word(i, 0x2200);
|
||||
DWIN_Byte(i, id);
|
||||
DWIN_Send(i); // AA 23 00 00 00 00 08 00 01 02 03 CC 33 C3 3C
|
||||
}
|
||||
|
||||
// Draw an Icon
|
||||
// libID: Icon library ID
|
||||
// picID: Icon ID
|
||||
// x/y: Upper-left point
|
||||
void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y) {
|
||||
NOMORE(x, DWIN_WIDTH - 1);
|
||||
NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x23);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Byte(i, 0x80 | libID);
|
||||
//DWIN_Byte(i, libID);
|
||||
DWIN_Byte(i, picID);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Unzip the JPG picture to a virtual display area
|
||||
// n: Cache index
|
||||
// id: Picture ID
|
||||
void DWIN_JPG_CacheToN(uint8_t n, uint8_t id) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x25);
|
||||
DWIN_Byte(i, n);
|
||||
DWIN_Byte(i, id);
|
||||
DWIN_Send(i);
|
||||
DWIN_ICON_Show(true, false, false, libID, picID, x, y);
|
||||
}
|
||||
|
||||
// Copy area from virtual display area to current screen
|
||||
@ -389,8 +67,7 @@ void DWIN_JPG_CacheToN(uint8_t n, uint8_t id) {
|
||||
// xStart/yStart: Upper-left of virtual area
|
||||
// xEnd/yEnd: Lower-right of virtual area
|
||||
// x/y: Screen paste point
|
||||
void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
|
||||
uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y) {
|
||||
void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x27);
|
||||
DWIN_Byte(i, 0x80 | cacheID);
|
||||
@ -403,73 +80,4 @@ void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Animate a series of icons
|
||||
// animID: Animation ID; 0x00-0x0F
|
||||
// animate: true on; false off;
|
||||
// libID: Icon library ID
|
||||
// picIDs: Icon starting ID
|
||||
// picIDe: Icon ending ID
|
||||
// x/y: Upper-left point
|
||||
// interval: Display time interval, unit 10mS
|
||||
void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs, uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval) {
|
||||
NOMORE(x, DWIN_WIDTH - 1);
|
||||
NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x28);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
// Bit 7: animation on or off
|
||||
// Bit 6: start from begin or end
|
||||
// Bit 5-4: unused (0)
|
||||
// Bit 3-0: animID
|
||||
DWIN_Byte(i, (animate * 0x80) | 0x40 | animID);
|
||||
DWIN_Byte(i, libID);
|
||||
DWIN_Byte(i, picIDs);
|
||||
DWIN_Byte(i, picIDe);
|
||||
DWIN_Byte(i, interval);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Animation Control
|
||||
// state: 16 bits, each bit is the state of an animation id
|
||||
void DWIN_ICON_AnimationControl(uint16_t state) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x29);
|
||||
DWIN_Word(i, state);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
/*---------------------------------------- Memory functions ----------------------------------------*/
|
||||
// The LCD has an additional 32KB SRAM and 16KB Flash
|
||||
|
||||
// Data can be written to the sram and save to one of the jpeg page files
|
||||
|
||||
// Write Data Memory
|
||||
// command 0x31
|
||||
// Type: Write memory selection; 0x5A=SRAM; 0xA5=Flash
|
||||
// Address: Write data memory address; 0x000-0x7FFF for SRAM; 0x000-0x3FFF for Flash
|
||||
// Data: data
|
||||
//
|
||||
// Flash writing returns 0xA5 0x4F 0x4B
|
||||
|
||||
// Read Data Memory
|
||||
// command 0x32
|
||||
// Type: Read memory selection; 0x5A=SRAM; 0xA5=Flash
|
||||
// Address: Read data memory address; 0x000-0x7FFF for SRAM; 0x000-0x3FFF for Flash
|
||||
// Length: leangth of data to read; 0x01-0xF0
|
||||
//
|
||||
// Response:
|
||||
// Type, Address, Length, Data
|
||||
|
||||
// Write Picture Memory
|
||||
// Write the contents of the 32KB SRAM data memory into the designated image memory space
|
||||
// Issued: 0x5A, 0xA5, PIC_ID
|
||||
// Response: 0xA5 0x4F 0x4B
|
||||
//
|
||||
// command 0x33
|
||||
// 0x5A, 0xA5
|
||||
// PicId: Picture Memory location, 0x00-0x0F
|
||||
//
|
||||
// Flash writing returns 0xA5 0x4F 0x4B
|
||||
|
||||
#endif // DWIN_CREALITY_LCD
|
||||
|
@ -29,335 +29,22 @@
|
||||
* @brief 迪文屏控制操作函数
|
||||
********************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RECEIVED_NO_DATA 0x00
|
||||
#define RECEIVED_SHAKE_HAND_ACK 0x01
|
||||
|
||||
#define FHONE 0xAA
|
||||
|
||||
#define DWIN_SCROLL_UP 2
|
||||
#define DWIN_SCROLL_DOWN 3
|
||||
|
||||
#define DWIN_WIDTH 272
|
||||
#define DWIN_HEIGHT 480
|
||||
|
||||
// Picture ID
|
||||
#define Language_English 1
|
||||
#define Language_Chinese 2
|
||||
|
||||
// ICON ID
|
||||
#define ICON 7 // Icon set file 7.ICO
|
||||
|
||||
#define ICON_LOGO 0
|
||||
#define ICON_Print_0 1
|
||||
#define ICON_Print_1 2
|
||||
#define ICON_Prepare_0 3
|
||||
#define ICON_Prepare_1 4
|
||||
#define ICON_Control_0 5
|
||||
#define ICON_Control_1 6
|
||||
#define ICON_Leveling_0 7
|
||||
#define ICON_Leveling_1 8
|
||||
#define ICON_HotendTemp 9
|
||||
#define ICON_BedTemp 10
|
||||
#define ICON_Speed 11
|
||||
#define ICON_Zoffset 12
|
||||
#define ICON_Back 13
|
||||
#define ICON_File 14
|
||||
#define ICON_PrintTime 15
|
||||
#define ICON_RemainTime 16
|
||||
#define ICON_Setup_0 17
|
||||
#define ICON_Setup_1 18
|
||||
#define ICON_Pause_0 19
|
||||
#define ICON_Pause_1 20
|
||||
#define ICON_Continue_0 21
|
||||
#define ICON_Continue_1 22
|
||||
#define ICON_Stop_0 23
|
||||
#define ICON_Stop_1 24
|
||||
#define ICON_Bar 25
|
||||
#define ICON_More 26
|
||||
|
||||
#define ICON_Axis 27
|
||||
#define ICON_CloseMotor 28
|
||||
#define ICON_Homing 29
|
||||
#define ICON_SetHome 30
|
||||
#define ICON_PLAPreheat 31
|
||||
#define ICON_ABSPreheat 32
|
||||
#define ICON_Cool 33
|
||||
#define ICON_Language 34
|
||||
|
||||
#define ICON_MoveX 35
|
||||
#define ICON_MoveY 36
|
||||
#define ICON_MoveZ 37
|
||||
#define ICON_Extruder 38
|
||||
|
||||
#define ICON_Temperature 40
|
||||
#define ICON_Motion 41
|
||||
#define ICON_WriteEEPROM 42
|
||||
#define ICON_ReadEEPROM 43
|
||||
#define ICON_ResumeEEPROM 44
|
||||
#define ICON_Info 45
|
||||
|
||||
#define ICON_SetEndTemp 46
|
||||
#define ICON_SetBedTemp 47
|
||||
#define ICON_FanSpeed 48
|
||||
#define ICON_SetPLAPreheat 49
|
||||
#define ICON_SetABSPreheat 50
|
||||
|
||||
#define ICON_MaxSpeed 51
|
||||
#define ICON_MaxAccelerated 52
|
||||
#define ICON_MaxJerk 53
|
||||
#define ICON_Step 54
|
||||
#define ICON_PrintSize 55
|
||||
#define ICON_Version 56
|
||||
#define ICON_Contact 57
|
||||
#define ICON_StockConfiguraton 58
|
||||
#define ICON_MaxSpeedX 59
|
||||
#define ICON_MaxSpeedY 60
|
||||
#define ICON_MaxSpeedZ 61
|
||||
#define ICON_MaxSpeedE 62
|
||||
#define ICON_MaxAccX 63
|
||||
#define ICON_MaxAccY 64
|
||||
#define ICON_MaxAccZ 65
|
||||
#define ICON_MaxAccE 66
|
||||
#define ICON_MaxSpeedJerkX 67
|
||||
#define ICON_MaxSpeedJerkY 68
|
||||
#define ICON_MaxSpeedJerkZ 69
|
||||
#define ICON_MaxSpeedJerkE 70
|
||||
#define ICON_StepX 71
|
||||
#define ICON_StepY 72
|
||||
#define ICON_StepZ 73
|
||||
#define ICON_StepE 74
|
||||
#define ICON_Setspeed 75
|
||||
#define ICON_SetZOffset 76
|
||||
#define ICON_Rectangle 77
|
||||
#define ICON_BLTouch 78
|
||||
#define ICON_TempTooLow 79
|
||||
#define ICON_AutoLeveling 80
|
||||
#define ICON_TempTooHigh 81
|
||||
#define ICON_NoTips_C 82
|
||||
#define ICON_NoTips_E 83
|
||||
#define ICON_Continue_C 84
|
||||
#define ICON_Continue_E 85
|
||||
#define ICON_Cancel_C 86
|
||||
#define ICON_Cancel_E 87
|
||||
#define ICON_Confirm_C 88
|
||||
#define ICON_Confirm_E 89
|
||||
#define ICON_Info_0 90
|
||||
#define ICON_Info_1 91
|
||||
|
||||
#define ICON_AdvSet ICON_Language
|
||||
#define ICON_HomeOff ICON_AdvSet
|
||||
#define ICON_HomeOffX ICON_StepX
|
||||
#define ICON_HomeOffY ICON_StepY
|
||||
#define ICON_HomeOffZ ICON_StepZ
|
||||
#define ICON_ProbeOff ICON_AdvSet
|
||||
#define ICON_ProbeOffX ICON_StepX
|
||||
#define ICON_ProbeOffY ICON_StepY
|
||||
#define ICON_PIDNozzle ICON_SetEndTemp
|
||||
#define ICON_PIDbed ICON_SetBedTemp
|
||||
|
||||
/**
|
||||
* 3-.0:The font size, 0x00-0x09, corresponds to the font size below:
|
||||
* 0x00=6*12 0x01=8*16 0x02=10*20 0x03=12*24 0x04=14*28
|
||||
* 0x05=16*32 0x06=20*40 0x07=24*48 0x08=28*56 0x09=32*64
|
||||
*/
|
||||
#define font6x12 0x00
|
||||
#define font8x16 0x01
|
||||
#define font10x20 0x02
|
||||
#define font12x24 0x03
|
||||
#define font14x28 0x04
|
||||
#define font16x32 0x05
|
||||
#define font20x40 0x06
|
||||
#define font24x48 0x07
|
||||
#define font28x56 0x08
|
||||
#define font32x64 0x09
|
||||
#include "../common/dwin_api.h"
|
||||
#include "../common/dwin_set.h"
|
||||
#include "../common/dwin_font.h"
|
||||
#include "../common/dwin_color.h"
|
||||
|
||||
#define DWIN_FONT_MENU font10x20
|
||||
#define DWIN_FONT_STAT font10x20
|
||||
#define DWIN_FONT_HEAD font10x20
|
||||
#define DWIN_FONT_ALERT font14x28
|
||||
|
||||
// Color
|
||||
#define Color_White 0xFFFF
|
||||
#define Color_Yellow 0xFF0F
|
||||
#define Color_Error_Red 0xB000 // Error!
|
||||
#define Color_Bg_Red 0xF00F // Red background color
|
||||
#define Color_Bg_Window 0x31E8 // Popup background color
|
||||
#define Color_Bg_Blue 0x1125 // Dark blue background color
|
||||
#define Color_Bg_Black 0x0841 // Black background color
|
||||
#define Color_IconBlue 0x45FA // Lighter blue that matches icons/accents
|
||||
#define Popup_Text_Color 0xD6BA // Popup font background color
|
||||
#define Line_Color 0x3A6A // Split line color
|
||||
#define Rectangle_Color 0xEE2F // Blue square cursor color
|
||||
#define Percent_Color 0xFE29 // Percentage color
|
||||
#define BarFill_Color 0x10E4 // Fill color of progress bar
|
||||
#define Select_Color 0x33BB // Selected color
|
||||
|
||||
/*-------------------------------------- System variable function --------------------------------------*/
|
||||
|
||||
// Handshake (1: Success, 0: Fail)
|
||||
bool DWIN_Handshake(void);
|
||||
|
||||
// Common DWIN startup
|
||||
void DWIN_Startup(void);
|
||||
|
||||
// Set the backlight luminance
|
||||
// luminance: (0x00-0xFF)
|
||||
void DWIN_Backlight_SetLuminance(const uint8_t luminance);
|
||||
|
||||
// Set screen display direction
|
||||
// dir: 0=0°, 1=90°, 2=180°, 3=270°
|
||||
void DWIN_Frame_SetDir(uint8_t dir);
|
||||
|
||||
// Update display
|
||||
void DWIN_UpdateLCD(void);
|
||||
|
||||
/*---------------------------------------- Drawing functions ----------------------------------------*/
|
||||
|
||||
// Clear screen
|
||||
// color: Clear screen color
|
||||
void DWIN_Frame_Clear(const uint16_t color);
|
||||
|
||||
// Draw a point
|
||||
// color: point color
|
||||
// width: point width 0x01-0x0F
|
||||
// height: point height 0x01-0x0F
|
||||
// x,y: upper left point
|
||||
void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y);
|
||||
|
||||
// Draw a line
|
||||
// color: Line segment color
|
||||
// xStart/yStart: Start point
|
||||
// xEnd/yEnd: End point
|
||||
void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
|
||||
|
||||
// Draw a Horizontal line
|
||||
// color: Line segment color
|
||||
// xStart/yStart: Start point
|
||||
// xLength: Line Length
|
||||
inline void DWIN_Draw_HLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xLength) {
|
||||
DWIN_Draw_Line(color, xStart, yStart, xStart + xLength - 1, yStart);
|
||||
}
|
||||
|
||||
// Draw a Vertical line
|
||||
// color: Line segment color
|
||||
// xStart/yStart: Start point
|
||||
// yLength: Line Length
|
||||
inline void DWIN_Draw_VLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t yLength) {
|
||||
DWIN_Draw_Line(color, xStart, yStart, xStart, yStart + yLength - 1);
|
||||
}
|
||||
|
||||
// Draw a rectangle
|
||||
// mode: 0=frame, 1=fill, 2=XOR fill
|
||||
// color: Rectangle color
|
||||
// xStart/yStart: upper left point
|
||||
// xEnd/yEnd: lower right point
|
||||
void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
|
||||
|
||||
// Draw a box
|
||||
// mode: 0=frame, 1=fill, 2=XOR fill
|
||||
// color: Rectangle color
|
||||
// xStart/yStart: upper left point
|
||||
// xSize/ySize: box size
|
||||
inline void DWIN_Draw_Box(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xSize, uint16_t ySize) {
|
||||
DWIN_Draw_Rectangle(mode, color, xStart, yStart, xStart + xSize - 1, yStart + ySize - 1);
|
||||
}
|
||||
|
||||
// Move a screen area
|
||||
// mode: 0, circle shift; 1, translation
|
||||
// dir: 0=left, 1=right, 2=up, 3=down
|
||||
// dis: Distance
|
||||
// color: Fill color
|
||||
// xStart/yStart: upper left point
|
||||
// xEnd/yEnd: bottom right point
|
||||
void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
|
||||
uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
|
||||
|
||||
/*---------------------------------------- Text related functions ----------------------------------------*/
|
||||
|
||||
// Draw a string
|
||||
// bShow: true=display background color; false=don't display background color
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// x/y: Upper-left coordinate of the string
|
||||
// *string: The string
|
||||
void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, char *string);
|
||||
|
||||
class __FlashStringHelper;
|
||||
|
||||
inline void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const __FlashStringHelper *title) {
|
||||
DWIN_Draw_String(bShow, size, color, bColor, x, y, (char *)title);
|
||||
}
|
||||
|
||||
// Draw a positive integer
|
||||
// bShow: true=display background color; false=don't display background color
|
||||
// zeroFill: true=zero fill; false=no zero fill
|
||||
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// iNum: Number of digits
|
||||
// x/y: Upper-left coordinate
|
||||
// value: Integer value
|
||||
void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
|
||||
uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value);
|
||||
|
||||
// Draw a floating point number
|
||||
// bShow: true=display background color; false=don't display background color
|
||||
// zeroFill: true=zero fill; false=no zero fill
|
||||
// zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// iNum: Number of whole digits
|
||||
// fNum: Number of decimal digits
|
||||
// x/y: Upper-left point
|
||||
// value: Float value
|
||||
void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
|
||||
uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value);
|
||||
|
||||
/*---------------------------------------- Picture related functions ----------------------------------------*/
|
||||
|
||||
// Draw JPG and cached in #0 virtual display area
|
||||
// id: Picture ID
|
||||
void DWIN_JPG_ShowAndCache(const uint8_t id);
|
||||
|
||||
// Draw an Icon
|
||||
// libID: Icon library ID
|
||||
// picID: Icon ID
|
||||
// x/y: Upper-left point
|
||||
void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
|
||||
|
||||
// Unzip the JPG picture to a virtual display area
|
||||
// n: Cache index
|
||||
// id: Picture ID
|
||||
void DWIN_JPG_CacheToN(uint8_t n, uint8_t id);
|
||||
|
||||
// Unzip the JPG picture to virtual display area #1
|
||||
// id: Picture ID
|
||||
inline void DWIN_JPG_CacheTo1(uint8_t id) { DWIN_JPG_CacheToN(1, id); }
|
||||
|
||||
// Copy area from virtual display area to current screen
|
||||
// cacheID: virtual area number
|
||||
// xStart/yStart: Upper-left of virtual area
|
||||
// xEnd/yEnd: Lower-right of virtual area
|
||||
// x/y: Screen paste point
|
||||
void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
|
||||
uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
|
||||
|
||||
// Animate a series of icons
|
||||
// animID: Animation ID up to 16
|
||||
// animate: animation on or off
|
||||
// libID: Icon library ID
|
||||
// picIDs: Icon starting ID
|
||||
// picIDe: Icon ending ID
|
||||
// x/y: Upper-left point
|
||||
// interval: Display time interval, unit 10mS
|
||||
void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs,
|
||||
uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval);
|
||||
|
||||
// Animation Control
|
||||
// state: 16 bits, each bit is the state of an animation id
|
||||
void DWIN_ICON_AnimationControl(uint16_t state);
|
||||
void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
|
||||
|
@ -1,263 +0,0 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*****************************************************************************
|
||||
* @file lcd/e3v2/creality/rotary_encoder.cpp
|
||||
* @author LEO / Creality3D
|
||||
* @date 2019/07/06
|
||||
* @version 2.0.1
|
||||
* @brief Rotary encoder functions
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(DWIN_CREALITY_LCD)
|
||||
|
||||
#include "rotary_encoder.h"
|
||||
#include "../../buttons.h"
|
||||
|
||||
#include "../../../MarlinCore.h"
|
||||
#include "../../../HAL/shared/Delay.h"
|
||||
|
||||
#if HAS_BUZZER
|
||||
#include "../../../libs/buzzer.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef ENCODER_PULSES_PER_STEP
|
||||
#define ENCODER_PULSES_PER_STEP 4
|
||||
#endif
|
||||
|
||||
ENCODER_Rate EncoderRate;
|
||||
|
||||
// Buzzer
|
||||
void Encoder_tick() {
|
||||
#if PIN_EXISTS(BEEPER)
|
||||
WRITE(BEEPER_PIN, HIGH);
|
||||
delay(10);
|
||||
WRITE(BEEPER_PIN, LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Encoder initialization
|
||||
void Encoder_Configuration() {
|
||||
#if BUTTON_EXISTS(EN1)
|
||||
SET_INPUT_PULLUP(BTN_EN1);
|
||||
#endif
|
||||
#if BUTTON_EXISTS(EN2)
|
||||
SET_INPUT_PULLUP(BTN_EN2);
|
||||
#endif
|
||||
#if BUTTON_EXISTS(ENC)
|
||||
SET_INPUT_PULLUP(BTN_ENC);
|
||||
#endif
|
||||
#if PIN_EXISTS(BEEPER)
|
||||
SET_OUTPUT(BEEPER_PIN);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Analyze encoder value and return state
|
||||
ENCODER_DiffState Encoder_ReceiveAnalyze() {
|
||||
const millis_t now = millis();
|
||||
static uint8_t lastEncoderBits;
|
||||
uint8_t newbutton = 0;
|
||||
static signed char temp_diff = 0;
|
||||
|
||||
ENCODER_DiffState temp_diffState = ENCODER_DIFF_NO;
|
||||
if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
|
||||
if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
|
||||
if (BUTTON_PRESSED(ENC)) {
|
||||
static millis_t next_click_update_ms;
|
||||
if (ELAPSED(now, next_click_update_ms)) {
|
||||
next_click_update_ms = millis() + 300;
|
||||
Encoder_tick();
|
||||
#if PIN_EXISTS(LCD_LED)
|
||||
//LED_Action();
|
||||
#endif
|
||||
const bool was_waiting = wait_for_user;
|
||||
wait_for_user = false;
|
||||
return was_waiting ? ENCODER_DIFF_NO : ENCODER_DIFF_ENTER;
|
||||
}
|
||||
else return ENCODER_DIFF_NO;
|
||||
}
|
||||
if (newbutton != lastEncoderBits) {
|
||||
switch (newbutton) {
|
||||
case ENCODER_PHASE_0:
|
||||
if (lastEncoderBits == ENCODER_PHASE_3) temp_diff++;
|
||||
else if (lastEncoderBits == ENCODER_PHASE_1) temp_diff--;
|
||||
break;
|
||||
case ENCODER_PHASE_1:
|
||||
if (lastEncoderBits == ENCODER_PHASE_0) temp_diff++;
|
||||
else if (lastEncoderBits == ENCODER_PHASE_2) temp_diff--;
|
||||
break;
|
||||
case ENCODER_PHASE_2:
|
||||
if (lastEncoderBits == ENCODER_PHASE_1) temp_diff++;
|
||||
else if (lastEncoderBits == ENCODER_PHASE_3) temp_diff--;
|
||||
break;
|
||||
case ENCODER_PHASE_3:
|
||||
if (lastEncoderBits == ENCODER_PHASE_2) temp_diff++;
|
||||
else if (lastEncoderBits == ENCODER_PHASE_0) temp_diff--;
|
||||
break;
|
||||
}
|
||||
lastEncoderBits = newbutton;
|
||||
}
|
||||
|
||||
if (ABS(temp_diff) >= ENCODER_PULSES_PER_STEP) {
|
||||
#if ENABLED(REVERSE_ENCODER_DIRECTION)
|
||||
if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CCW;
|
||||
else temp_diffState = ENCODER_DIFF_CW;
|
||||
#else
|
||||
if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CW;
|
||||
else temp_diffState = ENCODER_DIFF_CCW;
|
||||
#endif
|
||||
|
||||
#if ENABLED(ENCODER_RATE_MULTIPLIER)
|
||||
|
||||
millis_t ms = millis();
|
||||
int32_t encoderMultiplier = 1;
|
||||
|
||||
// if must encoder rati multiplier
|
||||
if (EncoderRate.enabled) {
|
||||
const float abs_diff = ABS(temp_diff),
|
||||
encoderMovementSteps = abs_diff / (ENCODER_PULSES_PER_STEP);
|
||||
if (EncoderRate.lastEncoderTime) {
|
||||
// Note that the rate is always calculated between two passes through the
|
||||
// loop and that the abs of the temp_diff value is tracked.
|
||||
const float encoderStepRate = encoderMovementSteps / float(ms - EncoderRate.lastEncoderTime) * 1000;
|
||||
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
|
||||
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
|
||||
#if ENCODER_5X_STEPS_PER_SEC
|
||||
else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoderMultiplier = 5;
|
||||
#endif
|
||||
}
|
||||
EncoderRate.lastEncoderTime = ms;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
constexpr int32_t encoderMultiplier = 1;
|
||||
|
||||
#endif
|
||||
|
||||
// EncoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
|
||||
EncoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
|
||||
if (EncoderRate.encoderMoveValue < 0) EncoderRate.encoderMoveValue = -EncoderRate.encoderMoveValue;
|
||||
|
||||
temp_diff = 0;
|
||||
}
|
||||
return temp_diffState;
|
||||
}
|
||||
|
||||
#if PIN_EXISTS(LCD_LED)
|
||||
|
||||
// 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
|
||||
uint16_t LED_DataArray[LED_NUM];
|
||||
|
||||
// LED light operation
|
||||
void LED_Action() {
|
||||
LED_Control(RGB_SCALE_WARM_WHITE,0x0F);
|
||||
delay(30);
|
||||
LED_Control(RGB_SCALE_WARM_WHITE,0x00);
|
||||
}
|
||||
|
||||
// LED initialization
|
||||
void LED_Configuration() {
|
||||
SET_OUTPUT(LCD_LED_PIN);
|
||||
}
|
||||
|
||||
// LED write data
|
||||
void LED_WriteData() {
|
||||
uint8_t tempCounter_LED, tempCounter_Bit;
|
||||
for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) {
|
||||
for (tempCounter_Bit = 0; tempCounter_Bit < 24; tempCounter_Bit++) {
|
||||
if (LED_DataArray[tempCounter_LED] & (0x800000 >> tempCounter_Bit)) {
|
||||
LED_DATA_HIGH;
|
||||
DELAY_NS(300);
|
||||
LED_DATA_LOW;
|
||||
DELAY_NS(200);
|
||||
}
|
||||
else {
|
||||
LED_DATA_HIGH;
|
||||
LED_DATA_LOW;
|
||||
DELAY_NS(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LED control
|
||||
// RGB_Scale: RGB color ratio
|
||||
// luminance: brightness (0~0xFF)
|
||||
void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance) {
|
||||
for (uint8_t i = 0; i < LED_NUM; i++) {
|
||||
LED_DataArray[i] = 0;
|
||||
switch (RGB_Scale) {
|
||||
case RGB_SCALE_R10_G7_B5: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 5/10; break;
|
||||
case RGB_SCALE_R10_G7_B4: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 4/10; break;
|
||||
case RGB_SCALE_R10_G8_B7: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 8/10) << 16 | luminance * 7/10; break;
|
||||
}
|
||||
}
|
||||
LED_WriteData();
|
||||
}
|
||||
|
||||
// LED gradient control
|
||||
// RGB_Scale: RGB color ratio
|
||||
// luminance: brightness (0~0xFF)
|
||||
// change_Time: gradient time (ms)
|
||||
void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval) {
|
||||
struct { uint8_t g, r, b; } led_data[LED_NUM];
|
||||
for (uint8_t i = 0; i < LED_NUM; i++) {
|
||||
switch (RGB_Scale) {
|
||||
case RGB_SCALE_R10_G7_B5:
|
||||
led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 5/10 };
|
||||
break;
|
||||
case RGB_SCALE_R10_G7_B4:
|
||||
led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 4/10 };
|
||||
break;
|
||||
case RGB_SCALE_R10_G8_B7:
|
||||
led_data[i] = { luminance * 8/10, luminance * 10/10, luminance * 7/10 };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct { bool g, r, b; } led_flag = { false, false, false };
|
||||
for (uint8_t i = 0; i < LED_NUM; i++) {
|
||||
while (1) {
|
||||
const uint8_t g = uint8_t(LED_DataArray[i] >> 16),
|
||||
r = uint8_t(LED_DataArray[i] >> 8),
|
||||
b = uint8_t(LED_DataArray[i]);
|
||||
if (g == led_data[i].g) led_flag.g = true;
|
||||
else LED_DataArray[i] += (g > led_data[i].g) ? -0x010000 : 0x010000;
|
||||
if (r == led_data[i].r) led_flag.r = true;
|
||||
else LED_DataArray[i] += (r > led_data[i].r) ? -0x000100 : 0x000100;
|
||||
if (b == led_data[i].b) led_flag.b = true;
|
||||
else LED_DataArray[i] += (b > led_data[i].b) ? -0x000001 : 0x000001;
|
||||
LED_WriteData();
|
||||
if (led_flag.r && led_flag.g && led_flag.b) break;
|
||||
delay(change_Interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LCD_LED
|
||||
|
||||
#endif // DWIN_CREALITY_LCD
|
@ -1,94 +0,0 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/*****************************************************************************
|
||||
* @file lcd/e3v2/creality/rotary_encoder.h
|
||||
* @author LEO / Creality3D
|
||||
* @date 2019/07/06
|
||||
* @version 2.0.1
|
||||
* @brief Rotary encoder functions
|
||||
****************************************************************************/
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
/*********************** Encoder Set ***********************/
|
||||
|
||||
typedef struct {
|
||||
bool enabled = false;
|
||||
int encoderMoveValue = 0;
|
||||
millis_t lastEncoderTime = 0;
|
||||
} ENCODER_Rate;
|
||||
|
||||
extern ENCODER_Rate EncoderRate;
|
||||
|
||||
typedef enum {
|
||||
ENCODER_DIFF_NO = 0, // no state
|
||||
ENCODER_DIFF_CW = 1, // clockwise rotation
|
||||
ENCODER_DIFF_CCW = 2, // counterclockwise rotation
|
||||
ENCODER_DIFF_ENTER = 3 // click
|
||||
} ENCODER_DiffState;
|
||||
|
||||
// Encoder initialization
|
||||
void Encoder_Configuration();
|
||||
|
||||
// Analyze encoder value and return state
|
||||
ENCODER_DiffState Encoder_ReceiveAnalyze();
|
||||
|
||||
/*********************** Encoder LED ***********************/
|
||||
|
||||
#if PIN_EXISTS(LCD_LED)
|
||||
|
||||
#define LED_NUM 4
|
||||
#define LED_DATA_HIGH WRITE(LCD_LED_PIN, 1)
|
||||
#define LED_DATA_LOW WRITE(LCD_LED_PIN, 0)
|
||||
|
||||
#define RGB_SCALE_R10_G7_B5 1
|
||||
#define RGB_SCALE_R10_G7_B4 2
|
||||
#define RGB_SCALE_R10_G8_B7 3
|
||||
#define RGB_SCALE_NEUTRAL_WHITE RGB_SCALE_R10_G7_B5
|
||||
#define RGB_SCALE_WARM_WHITE RGB_SCALE_R10_G7_B4
|
||||
#define RGB_SCALE_COOL_WHITE RGB_SCALE_R10_G8_B7
|
||||
|
||||
extern unsigned int LED_DataArray[LED_NUM];
|
||||
|
||||
// LED light operation
|
||||
void LED_Action();
|
||||
|
||||
// LED initialization
|
||||
void LED_Configuration();
|
||||
|
||||
// LED write data
|
||||
void LED_WriteData();
|
||||
|
||||
// LED control
|
||||
// RGB_Scale: RGB color ratio
|
||||
// luminance: brightness (0~0xFF)
|
||||
void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance);
|
||||
|
||||
// LED gradient control
|
||||
// RGB_Scale: RGB color ratio
|
||||
// luminance: brightness (0~0xFF)
|
||||
// change_Time: gradient time (ms)
|
||||
void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval);
|
||||
|
||||
#endif // LCD_LED
|
Reference in New Issue
Block a user