update code base to Marlin 2.0.9.2
This commit is contained in:
7
Marlin/src/lcd/e3v2/README.md
Normal file
7
Marlin/src/lcd/e3v2/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# DWIN for Creality Ender 3 v2
|
||||
|
||||
Marlin's Ender 3 v2 support requires the `DWIN_SET` included with the Ender 3 V2 [example configuration](https://github.com/MarlinFirmware/Configurations/tree/bugfix-2.0.x/config/examples/Creality/Ender-3%20V2).
|
||||
|
||||
## Easy Install
|
||||
|
||||
Copy the `DWIN_SET` folder onto a Micro-SD card and insert the card into the slot on the DWIN screen. Cycle the machine and wait for the screen to go from blue to orange. Turn the machine off and remove the SD card. When you turn on the machine the screen will display a "Creality" loading screen.
|
431
Marlin/src/lcd/e3v2/common/dwin_api.cpp
Normal file
431
Marlin/src/lcd/e3v2/common/dwin_api.cpp
Normal file
@@ -0,0 +1,431 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/>.
|
||||
*
|
||||
*/
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
|
||||
|
||||
#include "dwin_api.h"
|
||||
#include "dwin_set.h"
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#include <string.h> // for memset
|
||||
|
||||
uint8_t DWIN_SendBuf[11 + DWIN_WIDTH / 6 * 2] = { 0xAA };
|
||||
uint8_t DWIN_BufTail[4] = { 0xCC, 0x33, 0xC3, 0x3C };
|
||||
uint8_t databuf[26] = { 0 };
|
||||
|
||||
// Send the data in the buffer plus the packet tail
|
||||
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() {
|
||||
static int recnum = 0;
|
||||
#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' );
|
||||
}
|
||||
|
||||
#if HAS_LCD_BRIGHTNESS
|
||||
// Set LCD backlight (from DWIN Enhanced)
|
||||
// brightness: 0x00-0xFF
|
||||
void DWIN_LCD_Brightness(const uint8_t brightness) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x30);
|
||||
DWIN_Byte(i, brightness);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
#endif
|
||||
|
||||
// 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() {
|
||||
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
|
||||
// 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) {
|
||||
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
|
||||
// rlimit: To limit the drawn string length
|
||||
void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit/*=0xFFFF*/) {
|
||||
constexpr 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_Text(i, string, rlimit);
|
||||
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, uint32_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, int32_t 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);
|
||||
}
|
||||
|
||||
// Draw a floating point number
|
||||
// value: positive unscaled 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, float value) {
|
||||
const int32_t val = round(value * POW(10, fNum));
|
||||
DWIN_Draw_FloatValue(bShow, zeroFill, zeroMode, size, color, bColor, iNum, fNum, x, y, val);
|
||||
}
|
||||
|
||||
/*---------------------------------------- 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
|
||||
// IBD: The icon background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
|
||||
// BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
|
||||
// BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
|
||||
// libID: Icon library ID
|
||||
// picID: Icon ID
|
||||
// x/y: Upper-left point
|
||||
void DWIN_ICON_Show(bool IBD, bool BIR, bool BFI, 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, (IBD << 7) | (BIR << 6) | (BFI << 5) | libID);
|
||||
DWIN_Byte(i, picID);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Draw an Icon from SRAM
|
||||
// IBD: The icon background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
|
||||
// BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
|
||||
// BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
|
||||
// x/y: Upper-left point
|
||||
// addr: SRAM address
|
||||
void DWIN_ICON_Show(bool IBD, bool BIR, bool BFI, uint16_t x, uint16_t y, uint16_t addr) {
|
||||
NOMORE(x, DWIN_WIDTH - 1);
|
||||
NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x24);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Byte(i, (IBD << 7) | (BIR << 6) | (BFI << 5) | 0x00);
|
||||
DWIN_Word(i, addr);
|
||||
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);
|
||||
}
|
||||
|
||||
// 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 saved 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 // HAS_DWIN_E3V2 || IS_DWIN_MARLINUI
|
264
Marlin/src/lcd/e3v2/common/dwin_api.h
Normal file
264
Marlin/src/lcd/e3v2/common/dwin_api.h
Normal file
@@ -0,0 +1,264 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#ifndef DWIN_WIDTH
|
||||
#define DWIN_WIDTH 272
|
||||
#endif
|
||||
#ifndef DWIN_HEIGHT
|
||||
#define DWIN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
#define RECEIVED_NO_DATA 0x00
|
||||
#define RECEIVED_SHAKE_HAND_ACK 0x01
|
||||
|
||||
#define FHONE 0xAA
|
||||
|
||||
#define DWIN_SCROLL_UP 2
|
||||
#define DWIN_SCROLL_DOWN 3
|
||||
|
||||
// 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.
|
||||
extern uint8_t DWIN_SendBuf[11 + DWIN_WIDTH / 6 * 2];
|
||||
extern uint8_t DWIN_BufTail[4];
|
||||
extern uint8_t databuf[26];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Send the data in the buffer plus the packet tail
|
||||
void DWIN_Send(size_t &i);
|
||||
|
||||
inline void DWIN_Text(size_t &i, const char * const string, uint16_t rlimit=0xFFFF) {
|
||||
if (!string) return;
|
||||
const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, _MIN(strlen(string), rlimit));
|
||||
if (len == 0) return;
|
||||
memcpy(&DWIN_SendBuf[i+1], string, len);
|
||||
i += len;
|
||||
}
|
||||
|
||||
inline void DWIN_Text(size_t &i, FSTR_P string, uint16_t rlimit=0xFFFF) {
|
||||
if (!string) return;
|
||||
const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, _MIN(rlimit, strlen_P((PGM_P)string))); // cast to PGM_P (const char*) measure with strlen_P.
|
||||
if (len == 0) return;
|
||||
memcpy_P(&DWIN_SendBuf[i+1], string, len);
|
||||
i += len;
|
||||
}
|
||||
|
||||
/*-------------------------------------- System variable function --------------------------------------*/
|
||||
|
||||
// Handshake (1: Success, 0: Fail)
|
||||
bool DWIN_Handshake();
|
||||
|
||||
// DWIN startup
|
||||
void DWIN_Startup();
|
||||
|
||||
#if HAS_LCD_BRIGHTNESS
|
||||
// Set the backlight brightness
|
||||
// brightness: (0x00-0xFF)
|
||||
void DWIN_LCD_Brightness(const uint8_t brightness);
|
||||
#endif
|
||||
|
||||
// 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();
|
||||
|
||||
/*---------------------------------------- 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
|
||||
// rlimit: For draw less chars than string length use rlimit
|
||||
void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit=0xFFFF);
|
||||
|
||||
inline void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, FSTR_P title) {
|
||||
// Note that this won't work on AVR, only 32-bit systems!
|
||||
DWIN_Draw_String(bShow, size, color, bColor, x, y, FTOP(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, uint32_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, int32_t value);
|
||||
|
||||
// Draw a floating point number
|
||||
// value: positive unscaled 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, float 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);
|
||||
|
||||
// Draw an Icon
|
||||
// IBD: The icon background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
|
||||
// BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
|
||||
// BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
|
||||
// libID: Icon library ID
|
||||
// picID: Icon ID
|
||||
// x/y: Upper-left point
|
||||
void DWIN_ICON_Show(bool IBD, bool BIR, bool BFI, uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
|
||||
|
||||
// Draw an Icon from SRAM
|
||||
// IBD: The icon background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
|
||||
// BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
|
||||
// BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
|
||||
// x/y: Upper-left point
|
||||
// addr: SRAM address
|
||||
void DWIN_ICON_Show(bool IBD, bool BIR, bool BFI, uint16_t x, uint16_t y, uint16_t addr);
|
||||
|
||||
// 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); }
|
||||
|
||||
// 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);
|
44
Marlin/src/lcd/e3v2/common/dwin_color.h
Normal file
44
Marlin/src/lcd/e3v2/common/dwin_color.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
// Extended and default UI Colors
|
||||
#define RGB(R,G,B) (R << 11) | (G << 5) | (B) // R,B: 0..31; G: 0..63
|
||||
#define GetRColor(color) ((color >> 11) & 0x1F)
|
||||
#define GetGColor(color) ((color >> 5) & 0x3F)
|
||||
#define GetBColor(color) ((color >> 0) & 0x1F)
|
||||
|
||||
#define Color_White 0xFFFF
|
||||
#define Color_Yellow RGB(0x1F,0x3F,0x00)
|
||||
#define Color_Red RGB(0x1F,0x00,0x00)
|
||||
#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
|
38
Marlin/src/lcd/e3v2/common/dwin_font.h
Normal file
38
Marlin/src/lcd/e3v2/common/dwin_font.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
/**
|
||||
* 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
|
138
Marlin/src/lcd/e3v2/common/dwin_set.h
Normal file
138
Marlin/src/lcd/e3v2/common/dwin_set.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
// Picture ID
|
||||
#define Language_English 1
|
||||
#define Language_Chinese 2
|
||||
|
||||
#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_StockConfiguration 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_Folder ICON_More
|
||||
#define ICON_AdvSet ICON_Language
|
||||
#define ICON_HomeOffset ICON_AdvSet
|
||||
#define ICON_HomeOffsetX ICON_StepX
|
||||
#define ICON_HomeOffsetY ICON_StepY
|
||||
#define ICON_HomeOffsetZ ICON_StepZ
|
||||
#define ICON_ProbeOffset ICON_AdvSet
|
||||
#define ICON_ProbeOffsetX ICON_StepX
|
||||
#define ICON_ProbeOffsetY ICON_StepY
|
||||
#define ICON_ProbeOffsetZ ICON_StepZ
|
||||
#define ICON_PIDNozzle ICON_SetEndTemp
|
||||
#define ICON_PIDbed ICON_SetBedTemp
|
259
Marlin/src/lcd/e3v2/common/encoder.cpp
Normal file
259
Marlin/src/lcd/e3v2/common/encoder.cpp
Normal file
@@ -0,0 +1,259 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/common/encoder.cpp
|
||||
* @brief Rotary encoder functions
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_DWIN_E3V2
|
||||
|
||||
#include "encoder.h"
|
||||
#include "../../buttons.h"
|
||||
|
||||
#include "../../../MarlinCore.h"
|
||||
#include "../../marlinui.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;
|
||||
|
||||
// TODO: Replace with ui.quick_feedback
|
||||
void Encoder_tick() {
|
||||
#if PIN_EXISTS(BEEPER)
|
||||
if (ui.buzzer_enabled) {
|
||||
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); // TODO: Use buzzer.h which already inits this
|
||||
#endif
|
||||
}
|
||||
|
||||
// Analyze encoder value and return state
|
||||
EncoderState Encoder_ReceiveAnalyze() {
|
||||
const millis_t now = millis();
|
||||
static uint8_t lastEncoderBits;
|
||||
uint8_t newbutton = 0;
|
||||
static signed char temp_diff = 0;
|
||||
|
||||
EncoderState 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
|
||||
if (!ui.backlight) ui.refresh_brightness();
|
||||
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 (temp_diff > 0) temp_diffState = TERN(REVERSE_ENCODER_DIRECTION, ENCODER_DIFF_CCW, ENCODER_DIFF_CW);
|
||||
else temp_diffState = TERN(REVERSE_ENCODER_DIRECTION, ENCODER_DIFF_CW, ENCODER_DIFF_CCW);
|
||||
|
||||
#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 // HAS_DWIN_E3V2
|
91
Marlin/src/lcd/e3v2/common/encoder.h
Normal file
91
Marlin/src/lcd/e3v2/common/encoder.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/common/encoder.h
|
||||
* @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
|
||||
} EncoderState;
|
||||
|
||||
// Encoder initialization
|
||||
void Encoder_Configuration();
|
||||
|
||||
// Analyze encoder value and return state
|
||||
EncoderState 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
|
4299
Marlin/src/lcd/e3v2/creality/dwin.cpp
Normal file
4299
Marlin/src/lcd/e3v2/creality/dwin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
253
Marlin/src/lcd/e3v2/creality/dwin.h
Normal file
253
Marlin/src/lcd/e3v2/creality/dwin.h
Normal file
@@ -0,0 +1,253 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
/**
|
||||
* DWIN by Creality3D
|
||||
*/
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
#include "../common/encoder.h"
|
||||
#include "../../../libs/BL24CXX.h"
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ANY(HAS_HOTEND, HAS_HEATED_BED, HAS_FAN) && PREHEAT_COUNT
|
||||
#define HAS_PREHEAT 1
|
||||
#if PREHEAT_COUNT < 2
|
||||
#error "Creality DWIN requires two material preheat presets."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum processID : uint8_t {
|
||||
// Process ID
|
||||
MainMenu,
|
||||
SelectFile,
|
||||
Prepare,
|
||||
Control,
|
||||
Leveling,
|
||||
PrintProcess,
|
||||
AxisMove,
|
||||
TemperatureID,
|
||||
Motion,
|
||||
Info,
|
||||
Tune,
|
||||
#if HAS_PREHEAT
|
||||
PLAPreheat,
|
||||
ABSPreheat,
|
||||
#endif
|
||||
MaxSpeed,
|
||||
MaxSpeed_value,
|
||||
MaxAcceleration,
|
||||
MaxAcceleration_value,
|
||||
MaxJerk,
|
||||
MaxJerk_value,
|
||||
Step,
|
||||
Step_value,
|
||||
HomeOff,
|
||||
HomeOffX,
|
||||
HomeOffY,
|
||||
HomeOffZ,
|
||||
|
||||
// Last Process ID
|
||||
Last_Prepare,
|
||||
|
||||
// Advance Settings
|
||||
AdvSet,
|
||||
ProbeOff,
|
||||
ProbeOffX,
|
||||
ProbeOffY,
|
||||
|
||||
// Back Process ID
|
||||
Back_Main,
|
||||
Back_Print,
|
||||
|
||||
// Date variable ID
|
||||
Move_X,
|
||||
Move_Y,
|
||||
Move_Z,
|
||||
#if HAS_HOTEND
|
||||
Extruder,
|
||||
ETemp,
|
||||
#endif
|
||||
Homeoffset,
|
||||
#if HAS_HEATED_BED
|
||||
BedTemp,
|
||||
#endif
|
||||
#if HAS_FAN
|
||||
FanSpeed,
|
||||
#endif
|
||||
PrintSpeed,
|
||||
|
||||
// Window ID
|
||||
Print_window,
|
||||
Popup_Window
|
||||
};
|
||||
|
||||
extern uint8_t checkkey;
|
||||
extern float zprobe_zoffset;
|
||||
extern char print_filename[16];
|
||||
|
||||
extern millis_t dwin_heat_time;
|
||||
|
||||
typedef struct {
|
||||
#if HAS_HOTEND
|
||||
celsius_t E_Temp = 0;
|
||||
#endif
|
||||
#if HAS_HEATED_BED
|
||||
celsius_t Bed_Temp = 0;
|
||||
#endif
|
||||
#if HAS_FAN
|
||||
int16_t Fan_speed = 0;
|
||||
#endif
|
||||
int16_t print_speed = 100;
|
||||
float Max_Feedspeed = 0;
|
||||
float Max_Acceleration = 0;
|
||||
float Max_Jerk_scaled = 0;
|
||||
float Max_Step_scaled = 0;
|
||||
float Move_X_scaled = 0;
|
||||
float Move_Y_scaled = 0;
|
||||
float Move_Z_scaled = 0;
|
||||
#if HAS_HOTEND
|
||||
float Move_E_scaled = 0;
|
||||
#endif
|
||||
float offset_value = 0;
|
||||
int8_t show_mode = 0; // -1: Temperature control 0: Printing temperature
|
||||
float Home_OffX_scaled = 0;
|
||||
float Home_OffY_scaled = 0;
|
||||
float Home_OffZ_scaled = 0;
|
||||
float Probe_OffX_scaled = 0;
|
||||
float Probe_OffY_scaled = 0;
|
||||
} HMI_value_t;
|
||||
|
||||
#define DWIN_CHINESE 123
|
||||
#define DWIN_ENGLISH 0
|
||||
|
||||
typedef struct {
|
||||
uint8_t language;
|
||||
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;
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
||||
bool cold_flag:1;
|
||||
#endif
|
||||
AxisEnum feedspeed_axis, acc_axis, jerk_axis, step_axis;
|
||||
} HMI_flag_t;
|
||||
|
||||
extern HMI_value_t HMI_ValueStruct;
|
||||
extern HMI_flag_t HMI_flag;
|
||||
|
||||
#if HAS_HOTEND || HAS_HEATED_BED
|
||||
// Popup message window
|
||||
void DWIN_Popup_Temperature(const bool toohigh);
|
||||
#endif
|
||||
|
||||
#if HAS_HOTEND
|
||||
void Popup_Window_ETempTooLow();
|
||||
#endif
|
||||
|
||||
void Popup_Window_Resume();
|
||||
void Popup_Window_Home(const bool parking=false);
|
||||
void Popup_Window_Leveling();
|
||||
|
||||
void Goto_PrintProcess();
|
||||
void Goto_MainMenu();
|
||||
|
||||
// Variable control
|
||||
void HMI_Move_X();
|
||||
void HMI_Move_Y();
|
||||
void HMI_Move_Z();
|
||||
void HMI_Move_E();
|
||||
|
||||
void HMI_Zoffset();
|
||||
|
||||
#if HAS_HOTEND
|
||||
void HMI_ETemp();
|
||||
#endif
|
||||
#if HAS_HEATED_BED
|
||||
void HMI_BedTemp();
|
||||
#endif
|
||||
#if HAS_FAN
|
||||
void HMI_FanSpeed();
|
||||
#endif
|
||||
|
||||
void HMI_PrintSpeed();
|
||||
|
||||
void HMI_MaxFeedspeedXYZE();
|
||||
void HMI_MaxAccelerationXYZE();
|
||||
void HMI_MaxJerkXYZE();
|
||||
void HMI_StepXYZE();
|
||||
void HMI_SetLanguageCache();
|
||||
|
||||
void update_variable();
|
||||
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);
|
||||
|
||||
// SD Card
|
||||
void HMI_SDCardInit();
|
||||
void HMI_SDCardUpdate();
|
||||
|
||||
// Main Process
|
||||
void Icon_print(bool value);
|
||||
void Icon_control(bool value);
|
||||
void Icon_temperature(bool value);
|
||||
void Icon_leveling(bool value);
|
||||
|
||||
// Other
|
||||
void Draw_Status_Area(const bool with_update); // Status Area
|
||||
void HMI_StartFrame(const bool with_update); // Prepare the menu view
|
||||
void HMI_MainMenu(); // Main process screen
|
||||
void HMI_SelectFile(); // File page
|
||||
void HMI_Printing(); // Print page
|
||||
void HMI_Prepare(); // Prepare page
|
||||
void HMI_Control(); // Control page
|
||||
void HMI_Leveling(); // Level the page
|
||||
void HMI_AxisMove(); // Axis movement menu
|
||||
void HMI_Temperature(); // Temperature menu
|
||||
void HMI_Motion(); // Sports menu
|
||||
void HMI_Info(); // Information menu
|
||||
void HMI_Tune(); // Adjust the menu
|
||||
|
||||
#if HAS_PREHEAT
|
||||
void HMI_PLAPreheatSetting(); // PLA warm-up setting
|
||||
void HMI_ABSPreheatSetting(); // ABS warm-up setting
|
||||
#endif
|
||||
|
||||
void HMI_MaxSpeed(); // Maximum speed submenu
|
||||
void HMI_MaxAcceleration(); // Maximum acceleration submenu
|
||||
void HMI_MaxJerk(); // Maximum jerk speed submenu
|
||||
void HMI_Step(); // Transmission ratio
|
||||
|
||||
void HMI_Init();
|
||||
void DWIN_Update();
|
||||
void EachMomentUpdate();
|
||||
void DWIN_HandleScreen();
|
||||
void DWIN_StatusChanged(const char *text);
|
||||
void DWIN_StatusChanged_P(PGM_P const pstr);
|
||||
|
||||
inline void DWIN_StartHoming() { HMI_flag.home_flag = true; }
|
||||
|
||||
void DWIN_CompletedHoming();
|
||||
void DWIN_CompletedLeveling();
|
83
Marlin/src/lcd/e3v2/creality/dwin_lcd.cpp
Normal file
83
Marlin/src/lcd/e3v2/creality/dwin_lcd.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* 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/dwin_lcd.cpp
|
||||
* @author LEO / Creality3D
|
||||
* @date 2019/07/18
|
||||
* @version 2.0.1
|
||||
* @brief DWIN screen control functions
|
||||
********************************************************************************/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(DWIN_CREALITY_LCD)
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
|
||||
//#define DEBUG_OUT 1
|
||||
#include "../../../core/debug_out.h"
|
||||
|
||||
/*-------------------------------------- System variable function --------------------------------------*/
|
||||
|
||||
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.");
|
||||
DWIN_Frame_SetDir(1);
|
||||
#if DISABLED(SHOW_BOOTSCREEN)
|
||||
DWIN_Frame_Clear(Color_Bg_Black); // MarlinUI handles the bootscreen so just clear here
|
||||
#endif
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
/*---------------------------------------- Picture related functions ----------------------------------------*/
|
||||
|
||||
// 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) {
|
||||
DWIN_ICON_Show(true, false, false, libID, picID, x, y);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x27);
|
||||
DWIN_Byte(i, 0x80 | cacheID);
|
||||
DWIN_Word(i, xStart);
|
||||
DWIN_Word(i, yStart);
|
||||
DWIN_Word(i, xEnd);
|
||||
DWIN_Word(i, yEnd);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
#endif // DWIN_CREALITY_LCD
|
50
Marlin/src/lcd/e3v2/creality/dwin_lcd.h
Normal file
50
Marlin/src/lcd/e3v2/creality/dwin_lcd.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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 dwin_lcd.h
|
||||
* @author LEO / Creality3D
|
||||
* @date 2019/07/18
|
||||
* @version 2.0.1
|
||||
* @brief 迪文屏控制操作函数
|
||||
********************************************************************************/
|
||||
|
||||
#define DWIN_WIDTH 272
|
||||
#define DWIN_HEIGHT 480
|
||||
|
||||
#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
|
||||
|
||||
// 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);
|
3645
Marlin/src/lcd/e3v2/enhanced/dwin.cpp
Normal file
3645
Marlin/src/lcd/e3v2/enhanced/dwin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
280
Marlin/src/lcd/e3v2/enhanced/dwin.h
Normal file
280
Marlin/src/lcd/e3v2/enhanced/dwin.h
Normal file
@@ -0,0 +1,280 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
/**
|
||||
* DWIN UI Enhanced implementation
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* Version: 3.6.3
|
||||
* Date: 2021/09/08
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
#include "dwinui.h"
|
||||
#include "../common/encoder.h"
|
||||
#include "../../../libs/BL24CXX.h"
|
||||
|
||||
#if ANY(HAS_HOTEND, HAS_HEATED_BED, HAS_FAN) && PREHEAT_COUNT
|
||||
#define HAS_PREHEAT 1
|
||||
#if PREHEAT_COUNT < 2
|
||||
#error "Creality DWIN requires two material preheat presets."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ANY(AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT) && DISABLED(PROBE_MANUALLY)
|
||||
#define HAS_ONESTEP_LEVELING 1
|
||||
#endif
|
||||
|
||||
#if !HAS_BED_PROBE && ENABLED(BABYSTEPPING)
|
||||
#define JUST_BABYSTEP 1
|
||||
#endif
|
||||
|
||||
#if ANY(BABYSTEPPING, HAS_BED_PROBE, HAS_WORKSPACE_OFFSET)
|
||||
#define HAS_ZOFFSET_ITEM 1
|
||||
#endif
|
||||
|
||||
static constexpr size_t eeprom_data_size = 64;
|
||||
|
||||
enum processID : uint8_t {
|
||||
// Process ID
|
||||
MainMenu,
|
||||
Menu,
|
||||
SetInt,
|
||||
SetPInt,
|
||||
SetIntNoDraw,
|
||||
SetFloat,
|
||||
SetPFloat,
|
||||
SelectFile,
|
||||
PrintProcess,
|
||||
PrintDone,
|
||||
Info,
|
||||
|
||||
// Popup Windows
|
||||
Homing,
|
||||
Leveling,
|
||||
PauseOrStop,
|
||||
FilamentPurge,
|
||||
WaitResponse,
|
||||
Locked,
|
||||
NothingToDo,
|
||||
};
|
||||
|
||||
enum pidresult_t : uint8_t {
|
||||
PID_BAD_EXTRUDER_NUM,
|
||||
PID_TEMP_TOO_HIGH,
|
||||
PID_TUNING_TIMEOUT,
|
||||
PID_EXTR_START,
|
||||
PID_BED_START,
|
||||
PID_DONE
|
||||
};
|
||||
|
||||
#define DWIN_CHINESE 123
|
||||
#define DWIN_ENGLISH 0
|
||||
|
||||
typedef struct {
|
||||
int8_t Color[3]; // Color components
|
||||
int8_t Preheat = 0; // Material Select 0: PLA, 1: ABS, 2: Custom
|
||||
AxisEnum axis = X_AXIS; // Axis Select
|
||||
int32_t MaxValue = 0; // Auxiliar max integer/scaled float value
|
||||
int32_t MinValue = 0; // Auxiliar min integer/scaled float value
|
||||
int8_t dp = 0; // Auxiliar decimal places
|
||||
int32_t Value = 0; // Auxiliar integer / scaled float value
|
||||
int16_t *P_Int = nullptr; // Auxiliar pointer to 16 bit integer variable
|
||||
float *P_Float = nullptr; // Auxiliar pointer to float variable
|
||||
void (*Apply)() = nullptr; // Auxiliar apply function
|
||||
void (*LiveUpdate)() = nullptr; // Auxiliar live update function
|
||||
} HMI_value_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t Background_Color = Def_Background_Color;
|
||||
uint16_t Cursor_color = Def_Cursor_color;
|
||||
uint16_t TitleBg_color = Def_TitleBg_color;
|
||||
uint16_t TitleTxt_color = Def_TitleTxt_color;
|
||||
uint16_t Text_Color = Def_Text_Color;
|
||||
uint16_t Selected_Color = Def_Selected_Color;
|
||||
uint16_t SplitLine_Color = Def_SplitLine_Color;
|
||||
uint16_t Highlight_Color = Def_Highlight_Color;
|
||||
uint16_t StatusBg_Color = Def_StatusBg_Color;
|
||||
uint16_t StatusTxt_Color = Def_StatusTxt_Color;
|
||||
uint16_t PopupBg_color = Def_PopupBg_color;
|
||||
uint16_t PopupTxt_Color = Def_PopupTxt_Color;
|
||||
uint16_t AlertBg_Color = Def_AlertBg_Color;
|
||||
uint16_t AlertTxt_Color = Def_AlertTxt_Color;
|
||||
uint16_t PercentTxt_Color = Def_PercentTxt_Color;
|
||||
uint16_t Barfill_Color = Def_Barfill_Color;
|
||||
uint16_t Indicator_Color = Def_Indicator_Color;
|
||||
uint16_t Coordinate_Color = Def_Coordinate_Color;
|
||||
#if HAS_HOTEND
|
||||
int16_t HotendPidT = PREHEAT_1_TEMP_HOTEND;
|
||||
int16_t PidCycles = 10;
|
||||
#endif
|
||||
#ifdef PREHEAT_1_TEMP_BED
|
||||
int16_t BedPidT = PREHEAT_1_TEMP_BED;
|
||||
#endif
|
||||
#if ENABLED(PREVENT_COLD_EXTRUSION)
|
||||
int16_t ExtMinT = EXTRUDE_MINTEMP;
|
||||
#endif
|
||||
} HMI_data_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t language;
|
||||
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 lock_flag:1; // 0: lock called from AdvSet 1: lock called from Tune
|
||||
} HMI_flag_t;
|
||||
|
||||
extern HMI_value_t HMI_value;
|
||||
extern HMI_flag_t HMI_flag;
|
||||
extern HMI_data_t HMI_data;
|
||||
extern uint8_t checkkey;
|
||||
extern millis_t dwin_heat_time;
|
||||
|
||||
// Popup windows
|
||||
void DWIN_Popup_Confirm(uint8_t icon, const char * const msg1, const char * const msg2);
|
||||
#if HAS_HOTEND || HAS_HEATED_BED
|
||||
void DWIN_Popup_Temperature(const bool toohigh);
|
||||
#endif
|
||||
#if HAS_HOTEND
|
||||
void Popup_Window_ETempTooLow();
|
||||
#endif
|
||||
void Popup_Window_Resume();
|
||||
|
||||
// SD Card
|
||||
void HMI_SDCardInit();
|
||||
void HMI_SDCardUpdate();
|
||||
|
||||
// Other
|
||||
void Goto_PrintProcess();
|
||||
void Goto_Main_Menu();
|
||||
void Draw_Select_Highlight(const bool sel);
|
||||
void Draw_Status_Area(const bool with_update); // Status Area
|
||||
void Draw_Main_Area(); // Redraw main area;
|
||||
void DWIN_Redraw_screen(); // Redraw all screen elements
|
||||
void HMI_StartFrame(const bool with_update); // Prepare the menu view
|
||||
void HMI_MainMenu(); // Main process screen
|
||||
void HMI_SelectFile(); // File page
|
||||
void HMI_Printing(); // Print page
|
||||
void HMI_ReturnScreen(); // Return to previous screen before popups
|
||||
void ApplyExtMinT();
|
||||
void HMI_SetLanguageCache(); // Set the languaje image cache
|
||||
|
||||
void HMI_Init();
|
||||
void HMI_Popup();
|
||||
void HMI_SaveProcessID(const uint8_t id);
|
||||
void HMI_AudioFeedback(const bool success=true);
|
||||
void EachMomentUpdate();
|
||||
void update_variable();
|
||||
void DWIN_HandleScreen();
|
||||
void DWIN_Update();
|
||||
void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char *text);
|
||||
void DWIN_StatusChanged(const char * const text);
|
||||
void DWIN_StatusChanged_P(PGM_P const text);
|
||||
void DWIN_StartHoming();
|
||||
void DWIN_CompletedHoming();
|
||||
#if HAS_MESH
|
||||
void DWIN_MeshUpdate(const int8_t xpos, const int8_t ypos, const float zval);
|
||||
#endif
|
||||
void DWIN_MeshLevelingStart();
|
||||
void DWIN_CompletedLeveling();
|
||||
void DWIN_PidTuning(pidresult_t result);
|
||||
void DWIN_Print_Started(const bool sd = false);
|
||||
void DWIN_Print_Finished();
|
||||
#if HAS_FILAMENT_SENSOR
|
||||
void DWIN_FilamentRunout(const uint8_t extruder);
|
||||
#endif
|
||||
void DWIN_Progress_Update();
|
||||
void DWIN_Print_Header(const char *text);
|
||||
void DWIN_SetColorDefaults();
|
||||
void DWIN_StoreSettings(char *buff);
|
||||
void DWIN_LoadSettings(const char *buff);
|
||||
void DWIN_SetDataDefaults();
|
||||
void DWIN_RebootScreen();
|
||||
|
||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||
void Draw_Popup_FilamentPurge();
|
||||
void DWIN_Popup_FilamentPurge();
|
||||
void HMI_FilamentPurge();
|
||||
#endif
|
||||
|
||||
// Utility and extensions
|
||||
void HMI_LockScreen();
|
||||
void DWIN_LockScreen(const bool flag = true);
|
||||
#if HAS_MESH
|
||||
void DWIN_MeshViewer();
|
||||
#endif
|
||||
|
||||
// HMI user control functions
|
||||
void HMI_Menu();
|
||||
void HMI_SetInt();
|
||||
void HMI_SetPInt();
|
||||
void HMI_SetIntNoDraw();
|
||||
void HMI_SetFloat();
|
||||
void HMI_SetPFloat();
|
||||
|
||||
// Menu drawing functions
|
||||
void Draw_Control_Menu();
|
||||
void Draw_AdvancedSettings_Menu();
|
||||
void Draw_Prepare_Menu();
|
||||
void Draw_Move_Menu();
|
||||
void Draw_LevBedCorners_Menu();
|
||||
#if HAS_HOME_OFFSET
|
||||
void Draw_HomeOffset_Menu();
|
||||
#endif
|
||||
#if HAS_BED_PROBE
|
||||
void Draw_ProbeSet_Menu();
|
||||
#endif
|
||||
#if HAS_FILAMENT_SENSOR
|
||||
void Draw_FilSet_Menu();
|
||||
#endif
|
||||
void Draw_SelectColors_Menu();
|
||||
void Draw_GetColor_Menu();
|
||||
void Draw_Tune_Menu();
|
||||
void Draw_Motion_Menu();
|
||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||
void Draw_FilamentMan_Menu();
|
||||
#endif
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
void Draw_ManualMesh_Menu();
|
||||
#endif
|
||||
#if HAS_HOTEND
|
||||
void Draw_Preheat1_Menu();
|
||||
void Draw_Preheat2_Menu();
|
||||
void Draw_Preheat3_Menu();
|
||||
void Draw_HotendPID_Menu();
|
||||
#endif
|
||||
void Draw_Temperature_Menu();
|
||||
void Draw_MaxSpeed_Menu();
|
||||
void Draw_MaxAccel_Menu();
|
||||
#if HAS_CLASSIC_JERK
|
||||
void Draw_MaxJerk_Menu();
|
||||
#endif
|
||||
void Draw_Steps_Menu();
|
||||
#if HAS_HEATED_BED
|
||||
void Draw_BedPID_Menu();
|
||||
#endif
|
||||
#if EITHER(HAS_BED_PROBE, BABYSTEPPING)
|
||||
void Draw_ZOffsetWiz_Menu();
|
||||
#endif
|
160
Marlin/src/lcd/e3v2/enhanced/dwin_lcd.cpp
Normal file
160
Marlin/src/lcd/e3v2/enhanced/dwin_lcd.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* DWIN UI Enhanced implementation
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* Version: 3.6.3
|
||||
* Date: 2021/09/08
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(DWIN_CREALITY_LCD_ENHANCED)
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
|
||||
/*---------------------------------------- Picture related functions ----------------------------------------*/
|
||||
|
||||
// Display QR code
|
||||
// The size of the QR code is (46*QR_Pixel)*(46*QR_Pixel) dot matrix
|
||||
// QR_Pixel: The pixel size occupied by each point of the QR code: 0x01-0x0F (1-16)
|
||||
// (Nx, Ny): The coordinates of the upper left corner displayed by the QR code
|
||||
// str: multi-bit data
|
||||
void DWIN_Draw_QR(uint8_t QR_Pixel, uint16_t x, uint16_t y, char *string) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x21);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Byte(i, QR_Pixel);
|
||||
DWIN_Text(i, string);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Draw an Icon with transparent background
|
||||
// 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) {
|
||||
DWIN_ICON_Show(false, false, true, libID, picID, x, y);
|
||||
}
|
||||
|
||||
// Copy area from current virtual display area to current screen
|
||||
// xStart/yStart: Upper-left of virtual area
|
||||
// xEnd/yEnd: Lower-right of virtual area
|
||||
// x/y: Screen paste point
|
||||
void DWIN_Frame_AreaCopy(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, 0x26);
|
||||
DWIN_Word(i, xStart);
|
||||
DWIN_Word(i, yStart);
|
||||
DWIN_Word(i, xEnd);
|
||||
DWIN_Word(i, yEnd);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Copy area from virtual display area to current screen
|
||||
// IBD: background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
|
||||
// BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
|
||||
// BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
|
||||
// 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(bool IBD, bool BIR, bool BFI, 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, (IBD & 1) << 7 | (BIR & 1) << 6 | (BFI & 1) << 5 | cacheID);
|
||||
DWIN_Word(i, xStart);
|
||||
DWIN_Word(i, yStart);
|
||||
DWIN_Word(i, xEnd);
|
||||
DWIN_Word(i, yEnd);
|
||||
DWIN_Word(i, x);
|
||||
DWIN_Word(i, y);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
// Copy area from virtual display area to current screen with transparent background
|
||||
// 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) {
|
||||
DWIN_Frame_AreaCopy(false, false, true, cacheID, xStart, yStart, xEnd, yEnd, x, y);
|
||||
}
|
||||
|
||||
// Write buffer data to the SRAM or Flash
|
||||
// mem: 0x5A=32KB SRAM, 0xA5=16KB Flash
|
||||
// addr: start address
|
||||
// length: Bytes to write
|
||||
// data: address of the buffer with data
|
||||
void DWIN_WriteToMem(uint8_t mem, uint16_t addr, uint16_t length, uint8_t *data) {
|
||||
const uint8_t max_size = 128;
|
||||
uint16_t pending = length;
|
||||
uint16_t to_send;
|
||||
uint16_t indx;
|
||||
uint8_t block = 0;
|
||||
|
||||
while (pending > 0) {
|
||||
indx = block * max_size;
|
||||
to_send = _MIN(pending, max_size);
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x31);
|
||||
DWIN_Byte(i, mem);
|
||||
DWIN_Word(i, addr + indx); // start address of the data block
|
||||
++i;
|
||||
LOOP_L_N(j, i) { LCD_SERIAL.write(DWIN_SendBuf[j]); delayMicroseconds(1); } // Buf header
|
||||
for (uint16_t j = indx; j <= indx + to_send - 1; j++) LCD_SERIAL.write(*(data + j)); delayMicroseconds(1); // write block of data
|
||||
LOOP_L_N(j, 4) { LCD_SERIAL.write(DWIN_BufTail[j]); delayMicroseconds(1); }
|
||||
block++;
|
||||
pending -= to_send;
|
||||
}
|
||||
}
|
||||
|
||||
// Write the contents of the 32KB SRAM data memory into the designated image memory space.
|
||||
// picID: Picture memory space location, 0x00-0x0F, each space is 32Kbytes
|
||||
void DWIN_SRAMToPic(uint8_t picID) {
|
||||
size_t i = 0;
|
||||
DWIN_Byte(i, 0x33);
|
||||
DWIN_Byte(i, 0x5A);
|
||||
DWIN_Byte(i, 0xA5);
|
||||
DWIN_Byte(i, picID);
|
||||
DWIN_Send(i);
|
||||
}
|
||||
|
||||
//--------------------------Test area -------------------------
|
||||
|
||||
//void DWIN_ReadSRAM(uint16_t addr, uint8_t length, const char * const data) {
|
||||
// size_t i = 0;
|
||||
// DWIN_Byte(i, 0x32);
|
||||
// DWIN_Byte(i, 0x5A); // 0x5A Read from SRAM - 0xA5 Read from Flash
|
||||
// DWIN_Word(i, addr); // 0x0000 to 0x7FFF
|
||||
// const size_t len = _MIN(0xF0, length);
|
||||
// DWIN_Byte(i, len);
|
||||
// DWIN_Send(i);
|
||||
//}
|
||||
|
||||
#endif // DWIN_CREALITY_LCD_ENHANCED
|
83
Marlin/src/lcd/e3v2/enhanced/dwin_lcd.h
Normal file
83
Marlin/src/lcd/e3v2/enhanced/dwin_lcd.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
/**
|
||||
* DWIN UI Enhanced implementation
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* Version: 3.6.3
|
||||
* Date: 2021/09/08
|
||||
*/
|
||||
|
||||
#include "../common/dwin_api.h"
|
||||
|
||||
// Display QR code
|
||||
// The size of the QR code is (46*QR_Pixel)*(46*QR_Pixel) dot matrix
|
||||
// QR_Pixel: The pixel size occupied by each point of the QR code: 0x01-0x0F (1-16)
|
||||
// (Nx, Ny): The coordinates of the upper left corner displayed by the QR code
|
||||
// str: multi-bit data
|
||||
void DWIN_Draw_QR(uint8_t QR_Pixel, uint16_t x, uint16_t y, char *string);
|
||||
|
||||
inline void DWIN_Draw_QR(uint8_t QR_Pixel, uint16_t x, uint16_t y, FSTR_P title) {
|
||||
DWIN_Draw_QR(QR_Pixel, x, y, (char *)title);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Copy area from current virtual display area to current screen
|
||||
// xStart/yStart: Upper-left of virtual area
|
||||
// xEnd/yEnd: Lower-right of virtual area
|
||||
// x/y: Screen paste point
|
||||
void DWIN_Frame_AreaCopy(uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
|
||||
|
||||
// Copy area from virtual display area to current screen
|
||||
// IBD: background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
|
||||
// BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
|
||||
// BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
|
||||
// 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(bool IBD, bool BIR, bool BFI, uint8_t cacheID, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
|
||||
|
||||
// Write buffer data to the SRAM or Flash
|
||||
// mem: 0x5A=32KB SRAM, 0xA5=16KB Flash
|
||||
// addr: start address
|
||||
// length: Bytes to write
|
||||
// data: address of the buffer with data
|
||||
void DWIN_WriteToMem(uint8_t mem, uint16_t addr, uint16_t length, uint8_t *data);
|
||||
|
||||
// Write the contents of the 32KB SRAM data memory into the designated image memory space.
|
||||
// picID: Picture memory space location, 0x00-0x0F, each space is 32Kbytes
|
||||
void DWIN_SRAMToPic(uint8_t picID);
|
453
Marlin/src/lcd/e3v2/enhanced/dwinui.cpp
Normal file
453
Marlin/src/lcd/e3v2/enhanced/dwinui.cpp
Normal file
@@ -0,0 +1,453 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* DWIN UI Enhanced implementation
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* Version: 3.6.3
|
||||
* Date: 2021/09/08
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(DWIN_CREALITY_LCD_ENHANCED)
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
#include "dwin_lcd.h"
|
||||
#include "dwinui.h"
|
||||
|
||||
//#define DEBUG_OUT 1
|
||||
#include "../../../core/debug_out.h"
|
||||
|
||||
uint8_t MenuItemTotal = 0;
|
||||
uint8_t MenuItemCount = 0;
|
||||
MenuItemClass** MenuItems = nullptr;
|
||||
MenuClass *CurrentMenu = nullptr;
|
||||
MenuClass *PreviousMenu = nullptr;
|
||||
|
||||
xy_int_t DWINUI::cursor = { 0 };
|
||||
uint16_t DWINUI::pencolor = Color_White;
|
||||
uint16_t DWINUI::textcolor = Def_Text_Color;
|
||||
uint16_t DWINUI::backcolor = Def_Background_Color;
|
||||
uint8_t DWINUI::font = font8x16;
|
||||
|
||||
void (*DWINUI::onCursorErase)(uint8_t line)=nullptr;
|
||||
void (*DWINUI::onCursorDraw)(uint8_t line)=nullptr;
|
||||
void (*DWINUI::onTitleDraw)(TitleClass* title)=nullptr;
|
||||
void (*DWINUI::onMenuDraw)(MenuClass* menu)=nullptr;
|
||||
|
||||
void DWINUI::init() {
|
||||
DEBUG_ECHOPGM("\r\nDWIN handshake ");
|
||||
delay(750); // Delay here or init later in the boot process
|
||||
const bool success = DWIN_Handshake();
|
||||
if (success) DEBUG_ECHOLNPGM("ok."); else DEBUG_ECHOLNPGM("error.");
|
||||
DWIN_Frame_SetDir(1);
|
||||
TERN(SHOW_BOOTSCREEN,,DWIN_Frame_Clear(Color_Bg_Black));
|
||||
DWIN_UpdateLCD();
|
||||
cursor.x = 0;
|
||||
cursor.y = 0;
|
||||
pencolor = Color_White;
|
||||
textcolor = Def_Text_Color;
|
||||
backcolor = Def_Background_Color;
|
||||
font = font8x16;
|
||||
}
|
||||
|
||||
// Set text/number font
|
||||
void DWINUI::setFont(uint8_t cfont) {
|
||||
font = cfont;
|
||||
}
|
||||
|
||||
// Get font character width
|
||||
uint8_t DWINUI::fontWidth(uint8_t cfont) {
|
||||
switch (cfont) {
|
||||
case font6x12 : return 6;
|
||||
case font8x16 : return 8;
|
||||
case font10x20: return 10;
|
||||
case font12x24: return 12;
|
||||
case font14x28: return 14;
|
||||
case font16x32: return 16;
|
||||
case font20x40: return 20;
|
||||
case font24x48: return 24;
|
||||
case font28x56: return 28;
|
||||
case font32x64: return 32;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Get font character heigh
|
||||
uint8_t DWINUI::fontHeight(uint8_t cfont) {
|
||||
switch (cfont) {
|
||||
case font6x12 : return 12;
|
||||
case font8x16 : return 16;
|
||||
case font10x20: return 20;
|
||||
case font12x24: return 24;
|
||||
case font14x28: return 28;
|
||||
case font16x32: return 32;
|
||||
case font20x40: return 40;
|
||||
case font24x48: return 48;
|
||||
case font28x56: return 56;
|
||||
case font32x64: return 64;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Get screen x coodinates from text column
|
||||
uint16_t DWINUI::ColToX(uint8_t col) {
|
||||
return col * fontWidth(font);
|
||||
}
|
||||
|
||||
// Get screen y coodinates from text row
|
||||
uint16_t DWINUI::RowToY(uint8_t row) {
|
||||
return row * fontHeight(font);
|
||||
}
|
||||
|
||||
// Set text/number color
|
||||
void DWINUI::SetColors(uint16_t fgcolor, uint16_t bgcolor) {
|
||||
textcolor = fgcolor;
|
||||
backcolor = bgcolor;
|
||||
}
|
||||
void DWINUI::SetTextColor(uint16_t fgcolor) {
|
||||
textcolor = fgcolor;
|
||||
}
|
||||
void DWINUI::SetBackgroundColor(uint16_t bgcolor) {
|
||||
backcolor = bgcolor;
|
||||
}
|
||||
|
||||
// Moves cursor to point
|
||||
// x: abscissa of the display
|
||||
// y: ordinate of the display
|
||||
// point: xy coordinate
|
||||
void DWINUI::MoveTo(int16_t x, int16_t y) {
|
||||
cursor.x = x;
|
||||
cursor.y = y;
|
||||
}
|
||||
void DWINUI::MoveTo(xy_int_t point) {
|
||||
cursor = point;
|
||||
}
|
||||
|
||||
// Moves cursor relative to the actual position
|
||||
// x: abscissa of the display
|
||||
// y: ordinate of the display
|
||||
// point: xy coordinate
|
||||
void DWINUI::MoveBy(int16_t x, int16_t y) {
|
||||
cursor.x += x;
|
||||
cursor.y += y;
|
||||
}
|
||||
void DWINUI::MoveBy(xy_int_t point) {
|
||||
cursor += point;
|
||||
}
|
||||
|
||||
// Draw a Centered string using DWIN_WIDTH
|
||||
void DWINUI::Draw_CenteredString(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t y, const char * const string) {
|
||||
const int8_t x = _MAX(0U, DWIN_WIDTH - strlen_P(string) * fontWidth(size)) / 2 - 1;
|
||||
DWIN_Draw_String(bShow, size, color, bColor, x, y, string);
|
||||
}
|
||||
|
||||
// Draw a char at cursor position
|
||||
void DWINUI::Draw_Char(const char c) {
|
||||
const char string[2] = { c, 0};
|
||||
DWIN_Draw_String(false, font, textcolor, backcolor, cursor.x, cursor.y, string, 1);
|
||||
MoveBy(fontWidth(font), 0);
|
||||
}
|
||||
|
||||
// Draw a string at cursor position
|
||||
// color: Character color
|
||||
// *string: The string
|
||||
// rlimit: For draw less chars than string length use rlimit
|
||||
void DWINUI::Draw_String(const char * const string, uint16_t rlimit) {
|
||||
DWIN_Draw_String(false, font, textcolor, backcolor, cursor.x, cursor.y, string, rlimit);
|
||||
MoveBy(strlen(string) * fontWidth(font), 0);
|
||||
}
|
||||
void DWINUI::Draw_String(uint16_t color, const char * const string, uint16_t rlimit) {
|
||||
DWIN_Draw_String(false, font, color, backcolor, cursor.x, cursor.y, string, rlimit);
|
||||
MoveBy(strlen(string) * fontWidth(font), 0);
|
||||
}
|
||||
|
||||
// Draw a signed 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
|
||||
// bColor: Background color
|
||||
// iNum: Number of whole digits
|
||||
// fNum: Number of decimal digits
|
||||
// x/y: Upper-left point
|
||||
// value: Float value
|
||||
void DWINUI::Draw_Signed_Float(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, float value) {
|
||||
DWIN_Draw_FloatValue(bShow, zeroFill, zeroMode, size, color, bColor, iNum, fNum, x, y, value < 0 ? -value : value);
|
||||
DWIN_Draw_String(bShow, size, color, bColor, x - 6, y, value < 0 ? F("-") : F(" "));
|
||||
}
|
||||
|
||||
// Draw a circle
|
||||
// color: circle color
|
||||
// x: the abscissa of the center of the circle
|
||||
// y: ordinate of the center of the circle
|
||||
// r: circle radius
|
||||
void DWINUI::Draw_Circle(uint16_t color, uint16_t x, uint16_t y, uint8_t r) {
|
||||
int a = 0, b = 0;
|
||||
while (a <= b) {
|
||||
b = SQRT(sq(r) - sq(a));
|
||||
if (a == 0) b--;
|
||||
DWIN_Draw_Point(color, 1, 1, x + a, y + b); // Draw some sector 1
|
||||
DWIN_Draw_Point(color, 1, 1, x + b, y + a); // Draw some sector 2
|
||||
DWIN_Draw_Point(color, 1, 1, x + b, y - a); // Draw some sector 3
|
||||
DWIN_Draw_Point(color, 1, 1, x + a, y - b); // Draw some sector 4
|
||||
DWIN_Draw_Point(color, 1, 1, x - a, y - b); // Draw some sector 5
|
||||
DWIN_Draw_Point(color, 1, 1, x - b, y - a); // Draw some sector 6
|
||||
DWIN_Draw_Point(color, 1, 1, x - b, y + a); // Draw some sector 7
|
||||
DWIN_Draw_Point(color, 1, 1, x - a, y + b); // Draw some sector 8
|
||||
a++;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a circle filled with color
|
||||
// bcolor: fill color
|
||||
// x: the abscissa of the center of the circle
|
||||
// y: ordinate of the center of the circle
|
||||
// r: circle radius
|
||||
void DWINUI::Draw_FillCircle(uint16_t bcolor, uint16_t x,uint16_t y,uint8_t r) {
|
||||
int a = 0, b = 0;
|
||||
while (a <= b) {
|
||||
b = SQRT(sq(r) - sq(a)); // b=sqrt(r*r-a*a);
|
||||
if (a == 0) b--;
|
||||
DWIN_Draw_Line(bcolor, x-b,y-a,x+b,y-a);
|
||||
DWIN_Draw_Line(bcolor, x-a,y-b,x+a,y-b);
|
||||
DWIN_Draw_Line(bcolor, x-b,y+a,x+b,y+a);
|
||||
DWIN_Draw_Line(bcolor, x-a,y+b,x+a,y+b);
|
||||
a++;
|
||||
}
|
||||
}
|
||||
|
||||
// Color Interpolator
|
||||
// val : Interpolator minv..maxv
|
||||
// minv : Minimum value
|
||||
// maxv : Maximum value
|
||||
// color1 : Start color
|
||||
// color2 : End color
|
||||
uint16_t DWINUI::ColorInt(int16_t val, int16_t minv, int16_t maxv, uint16_t color1, uint16_t color2) {
|
||||
uint8_t B,G,R;
|
||||
float n;
|
||||
n = (float)(val-minv)/(maxv-minv);
|
||||
R = (1-n)*GetRColor(color1) + n*GetRColor(color2);
|
||||
G = (1-n)*GetGColor(color1) + n*GetGColor(color2);
|
||||
B = (1-n)*GetBColor(color1) + n*GetBColor(color2);
|
||||
return RGB(R,G,B);
|
||||
}
|
||||
|
||||
// Color Interpolator through Red->Yellow->Green->Blue
|
||||
// val : Interpolator minv..maxv
|
||||
// minv : Minimum value
|
||||
// maxv : Maximum value
|
||||
uint16_t DWINUI::RainbowInt(int16_t val, int16_t minv, int16_t maxv) {
|
||||
uint8_t B,G,R;
|
||||
const uint8_t maxB = 28;
|
||||
const uint8_t maxR = 28;
|
||||
const uint8_t maxG = 38;
|
||||
const int16_t limv = _MAX(abs(minv), abs(maxv));
|
||||
float n;
|
||||
if (minv>=0) {
|
||||
n = (float)(val-minv)/(maxv-minv);
|
||||
} else {
|
||||
n = (float)val/limv;
|
||||
}
|
||||
n = _MIN(1, n);
|
||||
n = _MAX(-1, n);
|
||||
if (n < 0) {
|
||||
R = 0;
|
||||
G = (1+n)*maxG;
|
||||
B = (-n)*maxB;
|
||||
} else if (n < 0.5) {
|
||||
R = maxR*n*2;
|
||||
G = maxG;
|
||||
B = 0;
|
||||
} else {
|
||||
R = maxR;
|
||||
G = maxG*(1-n);
|
||||
B = 0;
|
||||
}
|
||||
return RGB(R,G,B);
|
||||
}
|
||||
|
||||
// Draw a checkbox
|
||||
// Color: frame color
|
||||
// bColor: Background color
|
||||
// x/y: Upper-left point
|
||||
// mode : 0 : unchecked, 1 : checked
|
||||
void DWINUI::Draw_Checkbox(uint16_t color, uint16_t bcolor, uint16_t x, uint16_t y, bool checked=false) {
|
||||
DWIN_Draw_String(true, font8x16, color, bcolor, x + 4, y, checked ? F("x") : F(" "));
|
||||
DWIN_Draw_Rectangle(0, color, x + 2, y + 2, x + 17, y + 17);
|
||||
}
|
||||
|
||||
// Clear Menu by filling the menu area with background color
|
||||
void DWINUI::ClearMenuArea() {
|
||||
DWIN_Draw_Rectangle(1, backcolor, 0, TITLE_HEIGHT, DWIN_WIDTH - 1, STATUS_Y - 1);
|
||||
}
|
||||
|
||||
void DWINUI::MenuItemsClear() {
|
||||
if (MenuItems == nullptr) return;
|
||||
for (uint8_t i = 0; i < MenuItemCount; i++) delete MenuItems[i];
|
||||
delete[] MenuItems;
|
||||
MenuItems = nullptr;
|
||||
MenuItemCount = 0;
|
||||
MenuItemTotal = 0;
|
||||
}
|
||||
|
||||
void DWINUI::MenuItemsPrepare(uint8_t totalitems) {
|
||||
MenuItemsClear();
|
||||
MenuItemTotal = totalitems;
|
||||
MenuItems = new MenuItemClass*[totalitems];
|
||||
}
|
||||
|
||||
MenuItemClass* DWINUI::MenuItemsAdd(MenuItemClass* menuitem) {
|
||||
if (MenuItemCount < MenuItemTotal) {
|
||||
MenuItems[MenuItemCount] = menuitem;
|
||||
menuitem->pos = MenuItemCount++;
|
||||
return menuitem;
|
||||
}
|
||||
else {
|
||||
delete menuitem;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Title Class ==============================================================*/
|
||||
|
||||
TitleClass Title;
|
||||
|
||||
void TitleClass::draw() {
|
||||
if (DWINUI::onTitleDraw != nullptr) (*DWINUI::onTitleDraw)(this);
|
||||
}
|
||||
|
||||
void TitleClass::SetCaption(const char * const title) {
|
||||
frameid = 0;
|
||||
if ( caption == title ) return;
|
||||
const uint8_t len = _MIN(sizeof(caption) - 1, strlen(title));
|
||||
memcpy(&caption[0], title, len);
|
||||
caption[len] = '\0';
|
||||
}
|
||||
|
||||
void TitleClass::ShowCaption(const char * const title) {
|
||||
SetCaption(title);
|
||||
draw();
|
||||
}
|
||||
|
||||
void TitleClass::SetFrame(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||
caption[0] = '\0';
|
||||
frameid = id;
|
||||
frame = { x1, y1, x2, y2 };
|
||||
}
|
||||
|
||||
void TitleClass::SetFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
SetFrame(1, x, y, x + w - 1, y + h - 1);
|
||||
}
|
||||
|
||||
void TitleClass::FrameCopy(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||
SetFrame(id, x1, y1, x2, y2);
|
||||
draw();
|
||||
}
|
||||
|
||||
void TitleClass::FrameCopy(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
FrameCopy(1, x, y, x + w - 1, y + h - 1);
|
||||
}
|
||||
|
||||
/* Menu Class ===============================================================*/
|
||||
|
||||
MenuClass::MenuClass() {
|
||||
selected = 0;
|
||||
topline = 0;
|
||||
}
|
||||
|
||||
void MenuClass::draw() {
|
||||
MenuTitle.draw();
|
||||
if (DWINUI::onMenuDraw != nullptr) (*DWINUI::onMenuDraw)(this);
|
||||
for (uint8_t i = 0; i < MenuItemCount; i++)
|
||||
MenuItems[i]->draw(i - topline);
|
||||
if (DWINUI::onCursorDraw != nullptr) DWINUI::onCursorDraw(line());
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
void MenuClass::onScroll(bool dir) {
|
||||
int8_t sel = selected;
|
||||
if (dir) sel++; else sel--;
|
||||
LIMIT(sel, 0, MenuItemCount - 1);
|
||||
if (sel != selected) {
|
||||
if (DWINUI::onCursorErase != nullptr) DWINUI::onCursorErase(line());
|
||||
if ((sel - topline) == TROWS) {
|
||||
DWIN_Frame_AreaMove(1, DWIN_SCROLL_UP, MLINE, DWINUI::backcolor, 0, TITLE_HEIGHT + 1, DWIN_WIDTH, STATUS_Y - 1);
|
||||
topline++;
|
||||
MenuItems[sel]->draw(TROWS - 1);
|
||||
}
|
||||
if ((sel < topline)) {
|
||||
DWIN_Frame_AreaMove(1, DWIN_SCROLL_DOWN, MLINE, DWINUI::backcolor, 0, TITLE_HEIGHT + 1, DWIN_WIDTH, STATUS_Y - 1);
|
||||
topline--;
|
||||
MenuItems[sel]->draw(0);
|
||||
}
|
||||
selected = sel;
|
||||
if (DWINUI::onCursorDraw != nullptr) DWINUI::onCursorDraw(line());
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuClass::onClick() {
|
||||
if (MenuItems[selected]->onClick != nullptr) (*MenuItems[selected]->onClick)();
|
||||
}
|
||||
|
||||
MenuItemClass *MenuClass::SelectedItem() {
|
||||
return MenuItems[selected];
|
||||
}
|
||||
|
||||
/* MenuItem Class ===========================================================*/
|
||||
|
||||
MenuItemClass::MenuItemClass(uint8_t cicon, const char * const text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)()) {
|
||||
icon = cicon;
|
||||
onClick = onclick;
|
||||
onDraw = ondraw;
|
||||
const uint8_t len = _MIN(sizeof(caption) - 1, strlen(text));
|
||||
memcpy(&caption[0], text, len);
|
||||
caption[len] = '\0';
|
||||
}
|
||||
|
||||
MenuItemClass::MenuItemClass(uint8_t cicon, uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)()) {
|
||||
icon = cicon;
|
||||
onClick = onclick;
|
||||
onDraw = ondraw;
|
||||
caption[0] = '\0';
|
||||
frameid = id;
|
||||
frame = { x1, y1, x2, y2 };
|
||||
}
|
||||
|
||||
void MenuItemClass::SetFrame(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||
caption[0] = '\0';
|
||||
frameid = id;
|
||||
frame = { x1, y1, x2, y2 };
|
||||
}
|
||||
|
||||
void MenuItemClass::draw(int8_t line) {
|
||||
if (line < 0 || line >= TROWS) return;
|
||||
if (onDraw != nullptr) (*onDraw)(this, line);
|
||||
};
|
||||
|
||||
MenuItemPtrClass::MenuItemPtrClass(uint8_t cicon, const char * const text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)(), void* val) : MenuItemClass(cicon, text, ondraw, onclick) {
|
||||
value = val;
|
||||
};
|
||||
|
||||
#endif // DWIN_CREALITY_LCD_ENHANCED
|
485
Marlin/src/lcd/e3v2/enhanced/dwinui.h
Normal file
485
Marlin/src/lcd/e3v2/enhanced/dwinui.h
Normal file
@@ -0,0 +1,485 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
/**
|
||||
* DWIN UI Enhanced implementation
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* Version: 3.6.3
|
||||
* Date: 2021/09/08
|
||||
*/
|
||||
|
||||
#include "../../../core/types.h"
|
||||
#include "dwin_lcd.h"
|
||||
#include "../common/dwin_set.h"
|
||||
#include "../common/dwin_font.h"
|
||||
#include "../common/dwin_color.h"
|
||||
|
||||
// Extra Icons
|
||||
#define ICON_Brightness ICON_Motion
|
||||
#define ICON_Cancel ICON_StockConfiguration
|
||||
#define ICON_CustomPreheat ICON_SetEndTemp
|
||||
#define ICON_Error ICON_TempTooHigh
|
||||
#define ICON_ExtrudeMinT ICON_HotendTemp
|
||||
#define ICON_FilLoad ICON_WriteEEPROM
|
||||
#define ICON_FilMan ICON_ResumeEEPROM
|
||||
#define ICON_FilSet ICON_ResumeEEPROM
|
||||
#define ICON_FilUnload ICON_ReadEEPROM
|
||||
#define ICON_Flow ICON_StepE
|
||||
#define ICON_LevBed ICON_SetEndTemp
|
||||
#define ICON_Lock ICON_Cool
|
||||
#define ICON_ManualMesh ICON_HotendTemp
|
||||
#define ICON_MeshNext ICON_Axis
|
||||
#define ICON_MeshSave ICON_WriteEEPROM
|
||||
#define ICON_MeshViewer ICON_HotendTemp
|
||||
#define ICON_MoveZ0 ICON_HotendTemp
|
||||
#define ICON_Park ICON_Motion
|
||||
#define ICON_PIDcycles ICON_ResumeEEPROM
|
||||
#define ICON_PIDValue ICON_Contact
|
||||
#define ICON_ProbeSet ICON_SetEndTemp
|
||||
#define ICON_ProbeTest ICON_SetEndTemp
|
||||
#define ICON_Pwrlossr ICON_Motion
|
||||
#define ICON_Reboot ICON_ResumeEEPROM
|
||||
#define ICON_Runout ICON_MaxAccE
|
||||
#define ICON_Scolor ICON_MaxSpeed
|
||||
#define ICON_SetCustomPreheat ICON_SetEndTemp
|
||||
#define ICON_Sound ICON_Cool
|
||||
|
||||
// Default UI Colors
|
||||
#define Def_Background_Color Color_Bg_Black
|
||||
#define Def_Cursor_color Rectangle_Color
|
||||
#define Def_TitleBg_color Color_Bg_Blue
|
||||
#define Def_TitleTxt_color Color_White
|
||||
#define Def_Text_Color Color_White
|
||||
#define Def_Selected_Color Select_Color
|
||||
#define Def_SplitLine_Color Line_Color
|
||||
#define Def_Highlight_Color Color_White
|
||||
#define Def_StatusBg_Color RGB(0,20,20)
|
||||
#define Def_StatusTxt_Color Color_Yellow
|
||||
#define Def_PopupBg_color Color_Bg_Window
|
||||
#define Def_PopupTxt_Color Popup_Text_Color
|
||||
#define Def_AlertBg_Color Color_Bg_Red
|
||||
#define Def_AlertTxt_Color Color_Yellow
|
||||
#define Def_PercentTxt_Color Percent_Color
|
||||
#define Def_Barfill_Color BarFill_Color
|
||||
#define Def_Indicator_Color Color_White
|
||||
#define Def_Coordinate_Color Color_White
|
||||
|
||||
// UI element defines and constants
|
||||
#define DWIN_FONT_MENU font8x16
|
||||
#define DWIN_FONT_STAT font10x20
|
||||
#define DWIN_FONT_HEAD font10x20
|
||||
#define DWIN_FONT_ALERT font10x20
|
||||
#define STATUS_Y 354
|
||||
#define LCD_WIDTH (DWIN_WIDTH / 8)
|
||||
|
||||
constexpr uint16_t TITLE_HEIGHT = 30, // Title bar height
|
||||
MLINE = 53, // Menu line height
|
||||
TROWS = (STATUS_Y - TITLE_HEIGHT) / MLINE, // Total rows
|
||||
MROWS = TROWS - 1, // Other-than-Back
|
||||
ICOX = 26, // Menu item icon X position
|
||||
LBLX = 60, // Menu item label X position
|
||||
VALX = 210, // Menu item value X position
|
||||
MENU_CHR_W = 8, MENU_CHR_H = 16, // Menu font 8x16
|
||||
STAT_CHR_W = 10;
|
||||
|
||||
// Menuitem Y position
|
||||
#define MYPOS(L) (TITLE_HEIGHT + MLINE * (L))
|
||||
|
||||
// Menuitem caption Offset
|
||||
#define CAPOFF ((MLINE - MENU_CHR_H) / 2)
|
||||
|
||||
// Menuitem caption Y position
|
||||
#define MBASE(L) (MYPOS(L) + CAPOFF)
|
||||
|
||||
// Create and add a MenuItem object to the menu array
|
||||
#define ADDMENUITEM(V...) DWINUI::MenuItemsAdd(new MenuItemClass(V))
|
||||
#define ADDMENUITEM_P(V...) DWINUI::MenuItemsAdd(new MenuItemPtrClass(V))
|
||||
|
||||
typedef struct { uint16_t left, top, right, bottom; } rect_t;
|
||||
typedef struct { uint16_t x, y, w, h; } frame_rect_t;
|
||||
|
||||
class TitleClass {
|
||||
public:
|
||||
char caption[32] = "";
|
||||
uint8_t frameid = 0;
|
||||
rect_t frame = {0};
|
||||
void draw();
|
||||
void SetCaption(const char * const title);
|
||||
inline void SetCaption(FSTR_P title) { SetCaption((char *)title); }
|
||||
void ShowCaption(const char * const title);
|
||||
inline void ShowCaption(FSTR_P title) { ShowCaption((char *)title); }
|
||||
void SetFrame(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
void SetFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void FrameCopy(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
void FrameCopy(uint16_t x, uint16_t y, uint16_t h, uint16_t v);
|
||||
};
|
||||
extern TitleClass Title;
|
||||
|
||||
class MenuItemClass {
|
||||
protected:
|
||||
public:
|
||||
uint8_t pos = 0;
|
||||
uint8_t icon = 0;
|
||||
char caption[32] = "";
|
||||
uint8_t frameid = 0;
|
||||
rect_t frame = {0};
|
||||
void (*onDraw)(MenuItemClass* menuitem, int8_t line) = nullptr;
|
||||
void (*onClick)() = nullptr;
|
||||
MenuItemClass() {};
|
||||
MenuItemClass(uint8_t cicon, const char * const text=nullptr, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr);
|
||||
MenuItemClass(uint8_t cicon, FSTR_P text = nullptr, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr) : MenuItemClass(cicon, FTOP(text), ondraw, onclick){}
|
||||
MenuItemClass(uint8_t cicon, uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr);
|
||||
void SetFrame(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
virtual ~MenuItemClass(){};
|
||||
virtual void draw(int8_t line);
|
||||
};
|
||||
|
||||
class MenuItemPtrClass: public MenuItemClass {
|
||||
public:
|
||||
void *value = nullptr;
|
||||
using MenuItemClass::MenuItemClass;
|
||||
MenuItemPtrClass(uint8_t cicon, const char * const text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)(), void* val);
|
||||
MenuItemPtrClass(uint8_t cicon, FSTR_P text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)(), void* val) : MenuItemPtrClass(cicon, FTOP(text), ondraw, onclick, val){}
|
||||
};
|
||||
|
||||
class MenuClass {
|
||||
public:
|
||||
int8_t topline = 0;
|
||||
int8_t selected = 0;
|
||||
TitleClass MenuTitle;
|
||||
MenuClass();
|
||||
virtual ~MenuClass(){};
|
||||
inline int8_t line() { return selected - topline; };
|
||||
inline int8_t line(uint8_t pos) {return pos - topline; };
|
||||
void draw();
|
||||
void onScroll(bool dir);
|
||||
void onClick();
|
||||
MenuItemClass* SelectedItem();
|
||||
};
|
||||
extern MenuClass *CurrentMenu;
|
||||
|
||||
namespace DWINUI {
|
||||
extern xy_int_t cursor;
|
||||
extern uint16_t pencolor;
|
||||
extern uint16_t textcolor;
|
||||
extern uint16_t backcolor;
|
||||
extern uint8_t font;
|
||||
|
||||
extern void (*onCursorErase)(uint8_t line);
|
||||
extern void (*onCursorDraw)(uint8_t line);
|
||||
extern void (*onTitleDraw)(TitleClass* title);
|
||||
extern void (*onMenuDraw)(MenuClass* menu);
|
||||
|
||||
// DWIN LCD Initialization
|
||||
void init();
|
||||
|
||||
// Set text/number font
|
||||
void setFont(uint8_t cfont);
|
||||
|
||||
// Get font character width
|
||||
uint8_t fontWidth(uint8_t cfont);
|
||||
|
||||
// Get font character heigh
|
||||
uint8_t fontHeight(uint8_t cfont);
|
||||
|
||||
// Get screen x coodinates from text column
|
||||
uint16_t ColToX(uint8_t col);
|
||||
|
||||
// Get screen y coodinates from text row
|
||||
uint16_t RowToY(uint8_t row);
|
||||
|
||||
// Set text/number color
|
||||
void SetColors(uint16_t fgcolor, uint16_t bgcolor);
|
||||
void SetTextColor(uint16_t fgcolor);
|
||||
void SetBackgroundColor(uint16_t bgcolor);
|
||||
|
||||
// Moves cursor to point
|
||||
// x: abscissa of the display
|
||||
// y: ordinate of the display
|
||||
// point: xy coordinate
|
||||
void MoveTo(int16_t x, int16_t y);
|
||||
void MoveTo(xy_int_t point);
|
||||
|
||||
// Moves cursor relative to the actual position
|
||||
// x: abscissa of the display
|
||||
// y: ordinate of the display
|
||||
// point: xy coordinate
|
||||
void MoveBy(int16_t x, int16_t y);
|
||||
void MoveBy(xy_int_t point);
|
||||
|
||||
// Draw a line from the cursor to xy position
|
||||
// color: Line segment color
|
||||
// x/y: End point
|
||||
inline void LineTo(uint16_t color, uint16_t x, uint16_t y) {
|
||||
DWIN_Draw_Line(color, cursor.x, cursor.y, x, y);
|
||||
}
|
||||
inline void LineTo(uint16_t x, uint16_t y) {
|
||||
DWIN_Draw_Line(pencolor, cursor.x, cursor.y, x, y);
|
||||
}
|
||||
|
||||
// Draw an Icon with transparent background from the library ICON
|
||||
// icon: Icon ID
|
||||
// x/y: Upper-left point
|
||||
inline void Draw_Icon(uint8_t icon, uint16_t x, uint16_t y) {
|
||||
DWIN_ICON_Show(ICON, icon, x, y);
|
||||
}
|
||||
|
||||
// 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
|
||||
inline void Draw_Int(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, long value) {
|
||||
DWIN_Draw_IntValue(bShow, zeroFill, zeroMode, size, color, bColor, iNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Int(uint8_t iNum, long value) {
|
||||
DWIN_Draw_IntValue(false, true, 0, font, textcolor, backcolor, iNum, cursor.x, cursor.y, value);
|
||||
MoveBy(iNum * fontWidth(font), 0);
|
||||
}
|
||||
inline void Draw_Int(uint8_t iNum, uint16_t x, uint16_t y, long value) {
|
||||
DWIN_Draw_IntValue(false, true, 0, font, textcolor, backcolor, iNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Int(uint16_t color, uint8_t iNum, uint16_t x, uint16_t y, long value) {
|
||||
DWIN_Draw_IntValue(false, true, 0, font, color, backcolor, iNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Int(uint16_t color, uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, long value) {
|
||||
DWIN_Draw_IntValue(true, true, 0, font, color, bColor, iNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Int(uint8_t size, uint16_t color, uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, long value) {
|
||||
DWIN_Draw_IntValue(true, true, 0, size, color, bColor, iNum, x, y, 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
|
||||
inline void Draw_Float(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, float value) {
|
||||
DWIN_Draw_FloatValue(bShow, zeroFill, zeroMode, size, color, bColor, iNum, fNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Float(uint8_t iNum, uint8_t fNum, float value) {
|
||||
DWIN_Draw_FloatValue(false, true, 0, font, textcolor, backcolor, iNum, fNum, cursor.x, cursor.y, value);
|
||||
MoveBy((iNum + fNum + 1) * fontWidth(font), 0);
|
||||
}
|
||||
inline void Draw_Float(uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
DWIN_Draw_FloatValue(false, true, 0, font, textcolor, backcolor, iNum, fNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Float(uint16_t color, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
DWIN_Draw_FloatValue(false, true, 0, font, color, backcolor, iNum, fNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Float(uint16_t color, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
DWIN_Draw_FloatValue(true, true, 0, font, color, bColor, iNum, fNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Float(uint8_t size, uint16_t color, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
DWIN_Draw_FloatValue(true, true, 0, size, color, bColor, iNum, fNum, x, y, value);
|
||||
}
|
||||
|
||||
// Draw a signed 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
|
||||
// bColor: Background color
|
||||
// iNum: Number of whole digits
|
||||
// fNum: Number of decimal digits
|
||||
// x/y: Upper-left point
|
||||
// value: Float value
|
||||
void Draw_Signed_Float(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, float value);
|
||||
inline void Draw_Signed_Float(uint8_t iNum, uint8_t fNum, float value) {
|
||||
Draw_Signed_Float(false, true, 0, font, textcolor, backcolor, iNum, fNum, cursor.x, cursor.y, value);
|
||||
MoveBy((iNum + fNum + 1) * fontWidth(font), 0);
|
||||
}
|
||||
inline void Draw_Signed_Float(uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
Draw_Signed_Float(false, true, 0, font, textcolor, backcolor, iNum, fNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Signed_Float(uint8_t size, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
Draw_Signed_Float(false, true, 0, size, textcolor, backcolor, iNum, fNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Signed_Float(uint16_t color, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
Draw_Signed_Float(true, true, 0, font, color, bColor, iNum, fNum, x, y, value);
|
||||
}
|
||||
inline void Draw_Signed_Float(uint8_t size, uint16_t color, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value) {
|
||||
Draw_Signed_Float(true, true, 0, size, color, bColor, iNum, fNum, x, y, value);
|
||||
}
|
||||
|
||||
// Draw a char at cursor position
|
||||
void Draw_Char(const char c);
|
||||
|
||||
// Draw a string at cursor position
|
||||
// color: Character color
|
||||
// *string: The string
|
||||
// rlimit: For draw less chars than string length use rlimit
|
||||
void Draw_String(const char * const string, uint16_t rlimit = 0xFFFF);
|
||||
void Draw_String(uint16_t color, const char * const string, uint16_t rlimit = 0xFFFF);
|
||||
|
||||
// Draw a string
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// x/y: Upper-left coordinate of the string
|
||||
// *string: The string
|
||||
inline void Draw_String(uint16_t x, uint16_t y, const char * const string) {
|
||||
DWIN_Draw_String(false, font, textcolor, backcolor, x, y, string);
|
||||
}
|
||||
inline void Draw_String(uint16_t x, uint16_t y, FSTR_P title) {
|
||||
DWIN_Draw_String(false, font, textcolor, backcolor, x, y, (char *)title);
|
||||
}
|
||||
inline void Draw_String(uint16_t color, uint16_t x, uint16_t y, const char * const string) {
|
||||
DWIN_Draw_String(false, font, color, backcolor, x, y, string);
|
||||
}
|
||||
inline void Draw_String(uint16_t color, uint16_t x, uint16_t y, FSTR_P title) {
|
||||
DWIN_Draw_String(false, font, color, backcolor, x, y, (char *)title);
|
||||
}
|
||||
inline void Draw_String(uint16_t color, uint16_t bgcolor, uint16_t x, uint16_t y, const char * const string) {
|
||||
DWIN_Draw_String(true, font, color, bgcolor, x, y, string);
|
||||
}
|
||||
inline void Draw_String(uint16_t color, uint16_t bgcolor, uint16_t x, uint16_t y, FSTR_P title) {
|
||||
DWIN_Draw_String(true, font, color, bgcolor, x, y, (char *)title);
|
||||
}
|
||||
inline void Draw_String(uint8_t size, uint16_t color, uint16_t bgcolor, uint16_t x, uint16_t y, const char * const string) {
|
||||
DWIN_Draw_String(true, size, color, bgcolor, x, y, string);
|
||||
}
|
||||
inline void Draw_String(uint8_t size, uint16_t color, uint16_t bgcolor, uint16_t x, uint16_t y, FSTR_P title) {
|
||||
DWIN_Draw_String(true, size, color, bgcolor, x, y, (char *)title);
|
||||
}
|
||||
|
||||
// Draw a centered string using DWIN_WIDTH
|
||||
// bShow: true=display background color; false=don't display background color
|
||||
// size: Font size
|
||||
// color: Character color
|
||||
// bColor: Background color
|
||||
// y: Upper coordinate of the string
|
||||
// *string: The string
|
||||
void Draw_CenteredString(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t y, const char * const string);
|
||||
inline void Draw_CenteredString(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t y, FSTR_P title) {
|
||||
Draw_CenteredString(bShow, size, color, bColor, y, (char *)title);
|
||||
}
|
||||
inline void Draw_CenteredString(uint16_t color, uint16_t bcolor, uint16_t y, const char * const string) {
|
||||
Draw_CenteredString(true, font, color, bcolor, y, string);
|
||||
}
|
||||
inline void Draw_CenteredString(uint8_t size, uint16_t color, uint16_t y, const char * const string) {
|
||||
Draw_CenteredString(false, size, color, backcolor, y, string);
|
||||
}
|
||||
inline void Draw_CenteredString(uint8_t size, uint16_t color, uint16_t y, FSTR_P title) {
|
||||
Draw_CenteredString(false, size, color, backcolor, y, (char *)title);
|
||||
}
|
||||
inline void Draw_CenteredString(uint16_t color, uint16_t y, const char * const string) {
|
||||
Draw_CenteredString(false, font, color, backcolor, y, string);
|
||||
}
|
||||
inline void Draw_CenteredString(uint16_t color, uint16_t y, FSTR_P title) {
|
||||
Draw_CenteredString(false, font, color, backcolor, y, (char *)title);
|
||||
}
|
||||
inline void Draw_CenteredString(uint16_t y, const char * const string) {
|
||||
Draw_CenteredString(false, font, textcolor, backcolor, y, string);
|
||||
}
|
||||
inline void Draw_CenteredString(uint16_t y, FSTR_P title) {
|
||||
Draw_CenteredString(false, font, textcolor, backcolor, y, (char *)title);
|
||||
}
|
||||
|
||||
// Draw a circle
|
||||
// Color: circle color
|
||||
// x: abscissa of the center of the circle
|
||||
// y: ordinate of the center of the circle
|
||||
// r: circle radius
|
||||
void Draw_Circle(uint16_t color, uint16_t x,uint16_t y,uint8_t r);
|
||||
inline void Draw_Circle(uint16_t color, uint8_t r) {
|
||||
Draw_Circle(color, cursor.x, cursor.y, r);
|
||||
}
|
||||
|
||||
// Draw a checkbox
|
||||
// Color: frame color
|
||||
// bColor: Background color
|
||||
// x/y: Upper-left point
|
||||
// checked : 0 : unchecked, 1 : checked
|
||||
void Draw_Checkbox(uint16_t color, uint16_t bcolor, uint16_t x, uint16_t y, bool checked);
|
||||
inline void Draw_Checkbox(uint16_t x, uint16_t y, bool checked=false) {
|
||||
Draw_Checkbox(textcolor, backcolor, x, y, checked);
|
||||
}
|
||||
|
||||
// Color Interpolator
|
||||
// val : Interpolator minv..maxv
|
||||
// minv : Minimum value
|
||||
// maxv : Maximum value
|
||||
// color1 : Start color
|
||||
// color2 : End color
|
||||
uint16_t ColorInt(int16_t val, int16_t minv, int16_t maxv, uint16_t color1, uint16_t color2);
|
||||
|
||||
// -------------------------- Extra -------------------------------//
|
||||
|
||||
// Draw a circle filled with color
|
||||
// bcolor: fill color
|
||||
// x: abscissa of the center of the circle
|
||||
// y: ordinate of the center of the circle
|
||||
// r: circle radius
|
||||
void Draw_FillCircle(uint16_t bcolor, uint16_t x,uint16_t y,uint8_t r);
|
||||
inline void Draw_FillCircle(uint16_t bcolor, uint8_t r) {
|
||||
Draw_FillCircle(bcolor, cursor.x, cursor.y, r);
|
||||
}
|
||||
|
||||
// Color Interpolator through Red->Yellow->Green->Blue
|
||||
// val : Interpolator minv..maxv
|
||||
// minv : Minimum value
|
||||
// maxv : Maximum value
|
||||
uint16_t RainbowInt(int16_t val, int16_t minv, int16_t maxv);
|
||||
|
||||
// Write buffer data to the SRAM
|
||||
// addr: SRAM start address 0x0000-0x7FFF
|
||||
// length: Bytes to write
|
||||
// data: address of the buffer with data
|
||||
inline void WriteToSRAM(uint16_t addr, uint16_t length, uint8_t *data) {
|
||||
DWIN_WriteToMem(0x5A, addr, length, data);
|
||||
}
|
||||
|
||||
// Write buffer data to the Flash
|
||||
// addr: Flash start address 0x0000-0x3FFF
|
||||
// length: Bytes to write
|
||||
// data: address of the buffer with data
|
||||
inline void WriteToFlash(uint16_t addr, uint16_t length, uint8_t *data) {
|
||||
DWIN_WriteToMem(0xA5, addr, length, data);
|
||||
}
|
||||
|
||||
// Clear Menu by filling the area with background color
|
||||
// Area (0, TITLE_HEIGHT, DWIN_WIDTH, STATUS_Y - 1)
|
||||
void ClearMenuArea();
|
||||
|
||||
// Clear MenuItems array and free MenuItems elements
|
||||
void MenuItemsClear();
|
||||
|
||||
// Prepare MenuItems array
|
||||
void MenuItemsPrepare(uint8_t totalitems);
|
||||
|
||||
// Add elements to the MenuItems array
|
||||
MenuItemClass* MenuItemsAdd(MenuItemClass* menuitem);
|
||||
|
||||
};
|
75
Marlin/src/lcd/e3v2/enhanced/lockscreen.cpp
Normal file
75
Marlin/src/lcd/e3v2/enhanced/lockscreen.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* DWIN UI Enhanced implementation
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* Version: 3.6.3
|
||||
* Date: 2021/09/08
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(DWIN_CREALITY_LCD_ENHANCED)
|
||||
|
||||
#include "../../../core/types.h"
|
||||
#include "dwin_lcd.h"
|
||||
#include "dwinui.h"
|
||||
#include "dwin.h"
|
||||
#include "lockscreen.h"
|
||||
|
||||
LockScreenClass lockScreen;
|
||||
|
||||
uint8_t LockScreenClass::lock_pos = 0;
|
||||
bool LockScreenClass::unlocked = false;
|
||||
|
||||
void LockScreenClass::init() {
|
||||
lock_pos = 0;
|
||||
unlocked = false;
|
||||
draw();
|
||||
}
|
||||
|
||||
void LockScreenClass::draw() {
|
||||
Title.SetCaption(PSTR("Lock Screen"));
|
||||
DWINUI::ClearMenuArea();
|
||||
DWINUI::Draw_Icon(ICON_LOGO, 71, 120); // CREALITY logo
|
||||
DWINUI::Draw_CenteredString(Color_White, 180, F("Printer is Locked,"));
|
||||
DWINUI::Draw_CenteredString(Color_White, 200, F("Scroll to unlock."));
|
||||
DWINUI::Draw_CenteredString(Color_White, 240, F("-> | <-"));
|
||||
DWIN_Draw_Box(1, HMI_data.Barfill_Color, 0, 260, DWIN_WIDTH, 20);
|
||||
DWIN_Draw_VLine(Color_Yellow, lock_pos * DWIN_WIDTH / 255, 260, 20);
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
void LockScreenClass::onEncoder(EncoderState encoder_diffState) {
|
||||
switch (encoder_diffState) {
|
||||
case ENCODER_DIFF_CW: lock_pos += 8; break;
|
||||
case ENCODER_DIFF_CCW: lock_pos -= 8; break;
|
||||
case ENCODER_DIFF_ENTER: unlocked = (lock_pos == 128); break;
|
||||
default: break;
|
||||
}
|
||||
DWIN_Draw_Box(1, HMI_data.Barfill_Color, 0, 260, DWIN_WIDTH, 20);
|
||||
DWIN_Draw_VLine(Color_Yellow, lock_pos * DWIN_WIDTH / 255, 260, 20);
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
#endif // DWIN_CREALITY_LCD_ENHANCED
|
45
Marlin/src/lcd/e3v2/enhanced/lockscreen.h
Normal file
45
Marlin/src/lcd/e3v2/enhanced/lockscreen.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
/**
|
||||
* DWIN UI Enhanced implementation
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* Version: 3.6.3
|
||||
* Date: 2021/09/08
|
||||
*/
|
||||
|
||||
#include "../common/encoder.h"
|
||||
#include <stdint.h>
|
||||
|
||||
class LockScreenClass {
|
||||
private:
|
||||
static bool unlocked;
|
||||
static uint8_t lock_pos;
|
||||
public:
|
||||
static void init();
|
||||
static void onEncoder(EncoderState encoder_diffState);
|
||||
static void draw();
|
||||
static inline bool isUnlocked() { return unlocked; }
|
||||
};
|
||||
|
||||
extern LockScreenClass lockScreen;
|
75
Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp
Normal file
75
Marlin/src/lcd/e3v2/enhanced/meshviewer.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* DWIN Mesh Viewer
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* version: 2.5
|
||||
* Date: 2021/09/27
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if BOTH(DWIN_CREALITY_LCD_ENHANCED, HAS_MESH)
|
||||
|
||||
#include "meshviewer.h"
|
||||
|
||||
#include "../../../core/types.h"
|
||||
#include "../../marlinui.h"
|
||||
#include "dwin_lcd.h"
|
||||
#include "dwinui.h"
|
||||
#include "dwin.h"
|
||||
#include "../../../feature/bedlevel/bedlevel.h"
|
||||
|
||||
MeshViewerClass MeshViewer;
|
||||
|
||||
void MeshViewerClass::Draw() {
|
||||
const int8_t mx = 30, my = 30; // Margins
|
||||
const int16_t stx = (DWIN_WIDTH - 2 * mx) / (GRID_MAX_POINTS_X - 1), // Steps
|
||||
sty = (DWIN_WIDTH - 2 * my) / (GRID_MAX_POINTS_Y - 1);
|
||||
int8_t zmesh[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], maxz =-127, minz = 127;
|
||||
#define px(xp) (mx + (xp) * stx)
|
||||
#define py(yp) (30 + DWIN_WIDTH - my - (yp) * sty)
|
||||
#define rm(z) ((((z) - minz) * 10 / _MAX(1, (maxz - minz))) + 10)
|
||||
#define DrawMeshValue(xp, yp, zv) DWINUI::Draw_Signed_Float(font6x12, 1, 2, px(xp) - 12, py(yp) - 6, zv)
|
||||
#define DrawMeshHLine(yp) DWIN_Draw_HLine(HMI_data.SplitLine_Color, px(0), py(yp), DWIN_WIDTH - 2 * mx)
|
||||
#define DrawMeshVLine(xp) DWIN_Draw_VLine(HMI_data.SplitLine_Color, px(xp), py(GRID_MAX_POINTS_Y - 1), DWIN_WIDTH - 2 * my)
|
||||
GRID_LOOP(x, y) {
|
||||
const float v = Z_VALUES(x,y) * 100;
|
||||
zmesh[x][y] = v;
|
||||
NOLESS(maxz, v);
|
||||
NOMORE(minz, v);
|
||||
}
|
||||
Title.ShowCaption(F("Mesh viewer"));
|
||||
DWINUI::ClearMenuArea();
|
||||
DWINUI::Draw_Icon(ICON_Continue_E, 86, 305);
|
||||
DWIN_Draw_Rectangle(0, HMI_data.SplitLine_Color, px(0), py(0), px(GRID_MAX_POINTS_X - 1), py(GRID_MAX_POINTS_Y - 1));
|
||||
LOOP_S_L_N(x, 1, GRID_MAX_POINTS_X - 1) DrawMeshVLine(x);
|
||||
LOOP_S_L_N(y, 1, GRID_MAX_POINTS_Y - 1) DrawMeshHLine(y);
|
||||
LOOP_L_N(y, GRID_MAX_POINTS_Y) {
|
||||
watchdog_refresh();
|
||||
LOOP_L_N(x, GRID_MAX_POINTS_X) {
|
||||
uint16_t color = DWINUI::RainbowInt(zmesh[x][y], _MIN(-5, minz), _MAX(5, maxz));
|
||||
DWINUI::Draw_FillCircle(color, px(x), py(y), rm(zmesh[x][y]));
|
||||
DrawMeshValue(x, y, Z_VALUES(x,y));
|
||||
}
|
||||
}
|
||||
char str_1[6], str_2[6] = "";
|
||||
ui.status_printf_P(0, PSTR("Mesh minZ: %s, maxZ: %s"),
|
||||
dtostrf((float)minz / 100, 1, 2, str_1),
|
||||
dtostrf((float)maxz / 100, 1, 2, str_2)
|
||||
);
|
||||
}
|
||||
|
||||
#endif // DWIN_CREALITY_LCD_ENHANCED && HAS_MESH
|
28
Marlin/src/lcd/e3v2/enhanced/meshviewer.h
Normal file
28
Marlin/src/lcd/e3v2/enhanced/meshviewer.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* DWIN Mesh Viewer
|
||||
* Author: Miguel A. Risco-Castillo
|
||||
* version: 2.5
|
||||
* Date: 2021/09/27
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class MeshViewerClass {
|
||||
public:
|
||||
void Draw();
|
||||
};
|
||||
|
||||
extern MeshViewerClass MeshViewer;
|
7
Marlin/src/lcd/e3v2/jyersui/README.md
Normal file
7
Marlin/src/lcd/e3v2/jyersui/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# DWIN for Creality Ender 3 v2
|
||||
|
||||
Marlin's Ender 3 v2 support requires the `DWIN_SET` included with the Ender 3 V2 [example configuration](https://github.com/MarlinFirmware/Configurations/tree/bugfix-2.0.x/config/examples/Creality/Ender-3%20V2).
|
||||
|
||||
## Easy Install
|
||||
|
||||
Copy the `DWIN_SET` folder onto a Micro-SD card and insert the card into the slot on the DWIN screen. Cycle the machine and wait for the screen to go from blue to orange. Turn the machine off and remove the SD card. When you turn on the machine the screen will display a "Creality" loading screen.
|
5049
Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Normal file
5049
Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
243
Marlin/src/lcd/e3v2/jyersui/dwin.h
Normal file
243
Marlin/src/lcd/e3v2/jyersui/dwin.h
Normal file
@@ -0,0 +1,243 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
/**
|
||||
* lcd/e3v2/jyersui/dwin.h
|
||||
*/
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
#include "../common/dwin_set.h"
|
||||
#include "../common/dwin_font.h"
|
||||
#include "../common/dwin_color.h"
|
||||
#include "../common/encoder.h"
|
||||
#include "../../../libs/BL24CXX.h"
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
//#define DWIN_CREALITY_LCD_CUSTOM_ICONS
|
||||
|
||||
enum processID : uint8_t {
|
||||
Main, Print, Menu, Value, Option, File, Popup, Confirm, Wait
|
||||
};
|
||||
|
||||
enum PopupID : uint8_t {
|
||||
Pause, Stop, Resume, SaveLevel, ETemp, ConfFilChange, PurgeMore, MeshSlot,
|
||||
Level, Home, MoveWait, Heating, FilLoad, FilChange, TempWarn, Runout, PIDWait, Resuming, ManualProbing,
|
||||
FilInsert, HeaterTime, UserInput, LevelError, InvalidMesh, UI, Complete
|
||||
};
|
||||
|
||||
enum menuID : uint8_t {
|
||||
MainMenu,
|
||||
Prepare,
|
||||
Move,
|
||||
HomeMenu,
|
||||
ManualLevel,
|
||||
ZOffset,
|
||||
Preheat,
|
||||
ChangeFilament,
|
||||
Control,
|
||||
TempMenu,
|
||||
PID,
|
||||
HotendPID,
|
||||
BedPID,
|
||||
Preheat1,
|
||||
Preheat2,
|
||||
Preheat3,
|
||||
Preheat4,
|
||||
Preheat5,
|
||||
Motion,
|
||||
HomeOffsets,
|
||||
MaxSpeed,
|
||||
MaxAcceleration,
|
||||
MaxJerk,
|
||||
Steps,
|
||||
Visual,
|
||||
ColorSettings,
|
||||
Advanced,
|
||||
ProbeMenu,
|
||||
Info,
|
||||
Leveling,
|
||||
LevelManual,
|
||||
LevelView,
|
||||
MeshViewer,
|
||||
LevelSettings,
|
||||
ManualMesh,
|
||||
UBLMesh,
|
||||
InfoMain,
|
||||
Tune,
|
||||
PreheatHotend
|
||||
};
|
||||
|
||||
// Custom icons
|
||||
#if ENABLED(DWIN_CREALITY_LCD_CUSTOM_ICONS)
|
||||
// index of every custom icon should be >= CUSTOM_ICON_START
|
||||
#define CUSTOM_ICON_START ICON_Checkbox_F
|
||||
#define ICON_Checkbox_F 200
|
||||
#define ICON_Checkbox_T 201
|
||||
#define ICON_Fade 202
|
||||
#define ICON_Mesh 203
|
||||
#define ICON_Tilt 204
|
||||
#define ICON_Brightness 205
|
||||
#define ICON_AxisD 249
|
||||
#define ICON_AxisBR 250
|
||||
#define ICON_AxisTR 251
|
||||
#define ICON_AxisBL 252
|
||||
#define ICON_AxisTL 253
|
||||
#define ICON_AxisC 254
|
||||
#else
|
||||
#define ICON_Fade ICON_Version
|
||||
#define ICON_Mesh ICON_Version
|
||||
#define ICON_Tilt ICON_Version
|
||||
#define ICON_Brightness ICON_Version
|
||||
#define ICON_AxisD ICON_Axis
|
||||
#define ICON_AxisBR ICON_Axis
|
||||
#define ICON_AxisTR ICON_Axis
|
||||
#define ICON_AxisBL ICON_Axis
|
||||
#define ICON_AxisTL ICON_Axis
|
||||
#define ICON_AxisC ICON_Axis
|
||||
#endif
|
||||
|
||||
enum colorID : uint8_t {
|
||||
Default, White, Green, Cyan, Blue, Magenta, Red, Orange, Yellow, Brown, Black
|
||||
};
|
||||
|
||||
#define Custom_Colors 10
|
||||
#define Color_Aqua RGB(0x00,0x3F,0x1F)
|
||||
#define Color_Light_White 0xBDD7
|
||||
#define Color_Green RGB(0x00,0x3F,0x00)
|
||||
#define Color_Light_Green 0x3460
|
||||
#define Color_Cyan 0x07FF
|
||||
#define Color_Light_Cyan 0x04F3
|
||||
#define Color_Blue 0x015F
|
||||
#define Color_Light_Blue 0x3A6A
|
||||
#define Color_Magenta 0xF81F
|
||||
#define Color_Light_Magenta 0x9813
|
||||
#define Color_Light_Red 0x8800
|
||||
#define Color_Orange 0xFA20
|
||||
#define Color_Light_Orange 0xFBC0
|
||||
#define Color_Light_Yellow 0x8BE0
|
||||
#define Color_Brown 0xCC27
|
||||
#define Color_Light_Brown 0x6204
|
||||
#define Color_Black 0x0000
|
||||
#define Color_Grey 0x18E3
|
||||
#define Check_Color 0x4E5C // Check-box check color
|
||||
#define Confirm_Color 0x34B9
|
||||
#define Cancel_Color 0x3186
|
||||
|
||||
class CrealityDWINClass {
|
||||
public:
|
||||
static constexpr size_t eeprom_data_size = 48;
|
||||
static struct EEPROM_Settings { // use bit fields to save space, max 48 bytes
|
||||
bool time_format_textual : 1;
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
uint8_t tilt_grid_size : 3;
|
||||
#endif
|
||||
uint16_t corner_pos : 10;
|
||||
uint8_t cursor_color : 4;
|
||||
uint8_t menu_split_line : 4;
|
||||
uint8_t menu_top_bg : 4;
|
||||
uint8_t menu_top_txt : 4;
|
||||
uint8_t highlight_box : 4;
|
||||
uint8_t progress_percent : 4;
|
||||
uint8_t progress_time : 4;
|
||||
uint8_t status_bar_text : 4;
|
||||
uint8_t status_area_text : 4;
|
||||
uint8_t coordinates_text : 4;
|
||||
uint8_t coordinates_split_line : 4;
|
||||
} eeprom_settings;
|
||||
|
||||
static constexpr const char * const color_names[11] = { "Default", "White", "Green", "Cyan", "Blue", "Magenta", "Red", "Orange", "Yellow", "Brown", "Black" };
|
||||
static constexpr const char * const preheat_modes[3] = { "Both", "Hotend", "Bed" };
|
||||
|
||||
static void Clear_Screen(uint8_t e=3);
|
||||
static void Draw_Float(float value, uint8_t row, bool selected=false, uint8_t minunit=10);
|
||||
static void Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected=false, bool color=false);
|
||||
static uint16_t GetColor(uint8_t color, uint16_t original, bool light=false);
|
||||
static void Draw_Checkbox(uint8_t row, bool value);
|
||||
static void Draw_Title(const char * title);
|
||||
static void Draw_Menu_Item(uint8_t row, uint8_t icon=0, const char * const label1=nullptr, const char * const label2=nullptr, bool more=false, bool centered=false);
|
||||
static void Draw_Menu(uint8_t menu, uint8_t select=0, uint8_t scroll=0);
|
||||
static void Redraw_Menu(bool lastprocess=true, bool lastselection=false, bool lastmenu=false);
|
||||
static void Redraw_Screen();
|
||||
|
||||
static void Main_Menu_Icons();
|
||||
static void Draw_Main_Menu(uint8_t select=0);
|
||||
static void Print_Screen_Icons();
|
||||
static void Draw_Print_Screen();
|
||||
static void Draw_Print_Filename(const bool reset=false);
|
||||
static void Draw_Print_ProgressBar();
|
||||
#if ENABLED(USE_M73_REMAINING_TIME)
|
||||
static void Draw_Print_ProgressRemain();
|
||||
#endif
|
||||
static void Draw_Print_ProgressElapsed();
|
||||
static void Draw_Print_confirm();
|
||||
static void Draw_SD_Item(uint8_t item, uint8_t row);
|
||||
static void Draw_SD_List(bool removed=false);
|
||||
static void Draw_Status_Area(bool icons=false);
|
||||
static void Draw_Popup(PGM_P const line1, PGM_P const line2, PGM_P const line3, uint8_t mode, uint8_t icon=0);
|
||||
static void Popup_Select();
|
||||
static void Update_Status_Bar(bool refresh=false);
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
static void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7);
|
||||
static void Set_Mesh_Viewer_Status();
|
||||
#endif
|
||||
|
||||
static const char * Get_Menu_Title(uint8_t menu);
|
||||
static uint8_t Get_Menu_Size(uint8_t menu);
|
||||
static void Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw=true);
|
||||
|
||||
static void Popup_Handler(PopupID popupid, bool option = false);
|
||||
static void Confirm_Handler(PopupID popupid);
|
||||
|
||||
static void Main_Menu_Control();
|
||||
static void Menu_Control();
|
||||
static void Value_Control();
|
||||
static void Option_Control();
|
||||
static void File_Control();
|
||||
static void Print_Screen_Control();
|
||||
static void Popup_Control();
|
||||
static void Confirm_Control();
|
||||
|
||||
static void Setup_Value(float value, float min, float max, float unit, uint8_t type);
|
||||
static void Modify_Value(float &value, float min, float max, float unit, void (*f)()=nullptr);
|
||||
static void Modify_Value(uint8_t &value, float min, float max, float unit, void (*f)()=nullptr);
|
||||
static void Modify_Value(uint16_t &value, float min, float max, float unit, void (*f)()=nullptr);
|
||||
static void Modify_Value(int16_t &value, float min, float max, float unit, void (*f)()=nullptr);
|
||||
static void Modify_Value(uint32_t &value, float min, float max, float unit, void (*f)()=nullptr);
|
||||
static void Modify_Value(int8_t &value, float min, float max, float unit, void (*f)()=nullptr);
|
||||
static void Modify_Option(uint8_t value, const char * const * options, uint8_t max);
|
||||
|
||||
static void Update_Status(const char * const text);
|
||||
static void Start_Print(bool sd);
|
||||
static void Stop_Print();
|
||||
static void Update();
|
||||
static void State_Update();
|
||||
static void Screen_Update();
|
||||
static void AudioFeedback(const bool success=true);
|
||||
static void Save_Settings(char *buff);
|
||||
static void Load_Settings(const char *buff);
|
||||
static void Reset_Settings();
|
||||
};
|
||||
|
||||
extern CrealityDWINClass CrealityDWIN;
|
64
Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp
Normal file
64
Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/jyersui/dwin_lcd.cpp
|
||||
* @brief DWIN screen control functions
|
||||
********************************************************************************/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
|
||||
/*-------------------------------------- System variable function --------------------------------------*/
|
||||
|
||||
void DWIN_Startup() {}
|
||||
|
||||
/*---------------------------------------- Drawing functions ----------------------------------------*/
|
||||
|
||||
// Draw the degree (°) symbol
|
||||
// Color: color
|
||||
// x/y: Upper-left coordinate of the first pixel
|
||||
void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y) {
|
||||
DWIN_Draw_Point(Color, 1, 1, x + 1, y);
|
||||
DWIN_Draw_Point(Color, 1, 1, x + 2, y);
|
||||
DWIN_Draw_Point(Color, 1, 1, x, y + 1);
|
||||
DWIN_Draw_Point(Color, 1, 1, x + 3, y + 1);
|
||||
DWIN_Draw_Point(Color, 1, 1, x, y + 2);
|
||||
DWIN_Draw_Point(Color, 1, 1, x + 3, y + 2);
|
||||
DWIN_Draw_Point(Color, 1, 1, x + 1, y + 3);
|
||||
DWIN_Draw_Point(Color, 1, 1, x + 2, y + 3);
|
||||
}
|
||||
|
||||
/*---------------------------------------- Picture related functions ----------------------------------------*/
|
||||
|
||||
// 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) {
|
||||
DWIN_ICON_Show(true, false, false, libID, picID, x, y);
|
||||
}
|
||||
|
||||
#endif // DWIN_CREALITY_LCD_JYERSUI
|
34
Marlin/src/lcd/e3v2/jyersui/dwin_lcd.h
Normal file
34
Marlin/src/lcd/e3v2/jyersui/dwin_lcd.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/jyersui/dwin_lcd.h
|
||||
* @brief DWIN screen control functions
|
||||
********************************************************************************/
|
||||
|
||||
#include "../common/dwin_api.h"
|
||||
|
||||
// Draw the degree (°) symbol
|
||||
// Color: color
|
||||
// x/y: Upper-left coordinate of the first pixel
|
||||
void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y);
|
62
Marlin/src/lcd/e3v2/marlinui/dwin_lcd.cpp
Normal file
62
Marlin/src/lcd/e3v2/marlinui/dwin_lcd.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/marlinui/dwin_lcd.cpp
|
||||
* @brief DWIN screen control functions
|
||||
********************************************************************************/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if IS_DWIN_MARLINUI
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#include "dwin_lcd.h"
|
||||
#include <string.h> // for memset
|
||||
|
||||
//#define DEBUG_OUT 1
|
||||
#include "../../../core/debug_out.h"
|
||||
|
||||
/*-------------------------------------- System variable function --------------------------------------*/
|
||||
|
||||
void DWIN_Startup() {
|
||||
DEBUG_ECHOPGM("\r\nDWIN handshake ");
|
||||
delay(750); // Delay here or init later in the boot process
|
||||
const bool success = DWIN_Handshake();
|
||||
if (success) DEBUG_ECHOLNPGM("ok."); else DEBUG_ECHOLNPGM("error.");
|
||||
DWIN_Frame_SetDir(TERN(DWIN_MARLINUI_LANDSCAPE, 0, 1));
|
||||
DWIN_Frame_Clear(Color_Bg_Black); // MarlinUI handles the bootscreen so just clear here
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
/*---------------------------------------- Picture related functions ----------------------------------------*/
|
||||
|
||||
// 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) {
|
||||
DWIN_ICON_Show(true, false, false, libID, picID, x, y);
|
||||
}
|
||||
|
||||
#endif // IS_DWIN_MARLINUI
|
85
Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h
Normal file
85
Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/marlinui/dwin_lcd.h
|
||||
* @brief DWIN screen control functions
|
||||
********************************************************************************/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(DWIN_MARLINUI_LANDSCAPE)
|
||||
#define DWIN_WIDTH 480
|
||||
#define DWIN_HEIGHT 272
|
||||
#endif
|
||||
|
||||
#include "../common/dwin_api.h"
|
||||
|
||||
// Picture ID
|
||||
#define DWIN_Boot_Horiz 0
|
||||
#define DWIN_Boot_Vert 1
|
||||
#define DWIN_MarlinUI_Assets 2
|
||||
|
||||
// ICON ID
|
||||
#define BOOT_ICON 3 // Icon set file 3.ICO
|
||||
#define ICON 4 // Icon set file 4.ICO
|
||||
|
||||
// MarlinUI Boot Icons from Set 3
|
||||
#define ICON_MarlinBoot 0
|
||||
#define ICON_OpenSource 1
|
||||
#define ICON_GitHubURL 2
|
||||
#define ICON_MarlinURL 3
|
||||
#define ICON_Copyright 4
|
||||
|
||||
// MarlinUI Icons from Set 4
|
||||
#define ICON_LOGO_Marlin 0
|
||||
#define ICON_HotendOff 1
|
||||
#define ICON_HotendOn 2
|
||||
#define ICON_BedOff 3
|
||||
#define ICON_BedOn 4
|
||||
#define ICON_Fan0 5
|
||||
#define ICON_Fan1 6
|
||||
#define ICON_Fan2 7
|
||||
#define ICON_Fan3 8
|
||||
#define ICON_Halted 9
|
||||
#define ICON_Question 10
|
||||
#define ICON_Alert 11
|
||||
#define ICON_RotateCW 12
|
||||
#define ICON_RotateCCW 13
|
||||
#define ICON_UpArrow 14
|
||||
#define ICON_DownArrow 15
|
||||
#define ICON_BedLine 16
|
||||
|
||||
#include "../common/dwin_font.h"
|
||||
|
||||
#define DWIN_FONT_MENU font10x20
|
||||
#define DWIN_FONT_STAT font14x28
|
||||
#define DWIN_FONT_ALERT font14x28
|
||||
|
||||
#include "../common/dwin_color.h"
|
||||
|
||||
#define Color_Bg_Heading 0x3344 // Static Heading
|
||||
|
||||
// Character matrix width x height
|
||||
//#define LCD_WIDTH ((DWIN_WIDTH) / 8)
|
||||
//#define LCD_HEIGHT ((DWIN_HEIGHT) / 12)
|
180
Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp
Normal file
180
Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if IS_DWIN_MARLINUI
|
||||
|
||||
#include "dwin_string.h"
|
||||
//#include "../../fontutils.h"
|
||||
|
||||
uint8_t DWIN_String::data[];
|
||||
uint16_t DWIN_String::span;
|
||||
uint8_t DWIN_String::len;
|
||||
|
||||
void DWIN_String::set() {
|
||||
//*data = 0x00;
|
||||
memset(data, 0x00, sizeof(data));
|
||||
span = 0;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
uint8_t read_byte(uint8_t *byte) { return *byte; }
|
||||
|
||||
/**
|
||||
* Add a string, applying substitutions for the following characters:
|
||||
*
|
||||
* = displays '0'....'10' for indexes 0 - 10
|
||||
* ~ displays '1'....'11' for indexes 0 - 10
|
||||
* * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
|
||||
*/
|
||||
void DWIN_String::add(uint8_t *string, const int8_t index, uint8_t *itemString/*=nullptr*/) {
|
||||
wchar_t wchar;
|
||||
|
||||
while (*string) {
|
||||
string = get_utf8_value_cb(string, read_byte, &wchar);
|
||||
if (wchar > 255) wchar |= 0x0080;
|
||||
uint8_t ch = uint8_t(wchar & 0x00FF);
|
||||
|
||||
if (ch == '=' || ch == '~' || ch == '*') {
|
||||
if (index >= 0) {
|
||||
int8_t inum = index + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
|
||||
if (ch == '*') add_character('E');
|
||||
if (inum >= 10) { add_character('0' + (inum / 10)); inum %= 10; }
|
||||
add_character('0' + inum);
|
||||
}
|
||||
else {
|
||||
add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (ch == '$' && itemString) {
|
||||
add(itemString);
|
||||
continue;
|
||||
}
|
||||
|
||||
add_character(ch);
|
||||
}
|
||||
eol();
|
||||
}
|
||||
|
||||
void DWIN_String::add(uint8_t *string, uint8_t max_len) {
|
||||
wchar_t wchar;
|
||||
while (*string && max_len) {
|
||||
string = get_utf8_value_cb(string, read_byte, &wchar);
|
||||
/*
|
||||
if (wchar > 255) wchar |= 0x0080;
|
||||
uint8_t ch = uint8_t(wchar & 0x00FF);
|
||||
add_character(ch);
|
||||
*/
|
||||
add(wchar);
|
||||
max_len--;
|
||||
}
|
||||
eol();
|
||||
}
|
||||
|
||||
void DWIN_String::add(wchar_t character) {
|
||||
int ret;
|
||||
size_t idx = 0;
|
||||
dwin_charmap_t pinval;
|
||||
dwin_charmap_t *copy_address = nullptr;
|
||||
pinval.uchar = character;
|
||||
pinval.idx = -1;
|
||||
|
||||
// For 8-bit ASCII just print the single character
|
||||
char str[] = { '?', 0 };
|
||||
if (character < 255) {
|
||||
str[0] = (char)character;
|
||||
}
|
||||
else {
|
||||
copy_address = nullptr;
|
||||
ret = pf_bsearch_r((void *)g_dwin_charmap_device, COUNT(g_dwin_charmap_device), pf_bsearch_cb_comp_dwinmap_pgm, (void *)&pinval, &idx);
|
||||
if (ret >= 0) {
|
||||
copy_address = (dwin_charmap_t*)(g_dwin_charmap_device + idx);
|
||||
}
|
||||
else {
|
||||
ret = pf_bsearch_r((void *)g_dwin_charmap_common, COUNT(g_dwin_charmap_common), pf_bsearch_cb_comp_dwinmap_pgm, (void *)&pinval, &idx);
|
||||
if (ret >= 0)
|
||||
copy_address = (dwin_charmap_t*)(g_dwin_charmap_common + idx);
|
||||
}
|
||||
if (ret >= 0) {
|
||||
dwin_charmap_t localval;
|
||||
memcpy_P(&localval, copy_address, sizeof(localval));
|
||||
str[0] = localval.idx;
|
||||
str[1] = localval.idx2;
|
||||
}
|
||||
}
|
||||
if (str[0]) add_character(str[0]);
|
||||
if (str[1]) add_character(str[1]);
|
||||
}
|
||||
|
||||
void DWIN_String::add_character(const uint8_t character) {
|
||||
if (len < MAX_STRING_LENGTH) {
|
||||
data[len] = character;
|
||||
len++;
|
||||
//span += glyph(character)->DWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void DWIN_String::rtrim(const uint8_t character) {
|
||||
while (len) {
|
||||
if (data[len - 1] == 0x20 || data[len - 1] == character) {
|
||||
len--;
|
||||
//span -= glyph(data[length])->DWidth;
|
||||
eol();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DWIN_String::ltrim(const uint8_t character) {
|
||||
uint16_t i, j;
|
||||
for (i = 0; (i < len) && (data[i] == 0x20 || data[i] == character); i++) {
|
||||
//span -= glyph(data[i])->DWidth;
|
||||
}
|
||||
if (i == 0) return;
|
||||
for (j = 0; i < len; data[j++] = data[i++]);
|
||||
len = j;
|
||||
eol();
|
||||
}
|
||||
|
||||
void DWIN_String::trim(const uint8_t character) {
|
||||
rtrim(character);
|
||||
ltrim(character);
|
||||
}
|
||||
|
||||
/* return v1 - v2 */
|
||||
int dwin_charmap_compare(dwin_charmap_t *v1, dwin_charmap_t *v2) {
|
||||
return (v1->uchar < v2->uchar) ? -1 : (v1->uchar > v2->uchar) ? 1 : 0;
|
||||
}
|
||||
|
||||
int pf_bsearch_cb_comp_dwinmap_pgm(void *userdata, size_t idx, void * data_pin) {
|
||||
dwin_charmap_t localval;
|
||||
dwin_charmap_t *p_dwin_charmap = (dwin_charmap_t *)userdata;
|
||||
memcpy_P(&localval, p_dwin_charmap + idx, sizeof(localval));
|
||||
return dwin_charmap_compare(&localval, (dwin_charmap_t *)data_pin);
|
||||
}
|
||||
|
||||
DWIN_String dwin_string;
|
||||
|
||||
#endif // IS_DWIN_MARLINUI
|
1006
Marlin/src/lcd/e3v2/marlinui/dwin_string.h
Normal file
1006
Marlin/src/lcd/e3v2/marlinui/dwin_string.h
Normal file
File diff suppressed because it is too large
Load Diff
191
Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp
Normal file
191
Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* lcd/e3v2/marlinui/lcdprint_dwin.cpp
|
||||
*
|
||||
* Due to DWIN hardware limitations simplified characters are used
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if IS_DWIN_MARLINUI
|
||||
|
||||
#include "lcdprint_dwin.h"
|
||||
#include "dwin_lcd.h"
|
||||
#include "dwin_string.h"
|
||||
|
||||
#include "../../marlinui.h"
|
||||
#include "../../../MarlinCore.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
cursor_t cursor;
|
||||
|
||||
extern dwin_font_t dwin_font;
|
||||
|
||||
void lcd_moveto_xy(const lcd_uint_t x, const lcd_uint_t y) { cursor.x = x; cursor.y = y; }
|
||||
|
||||
void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
|
||||
lcd_moveto_xy(col * dwin_font.width, row * (dwin_font.height + EXTRA_ROW_HEIGHT) + EXTRA_ROW_HEIGHT / 2);
|
||||
}
|
||||
|
||||
inline void lcd_advance_cursor(const uint8_t len=1) { cursor.x += len * dwin_font.width; }
|
||||
|
||||
void lcd_put_int(const int i) {
|
||||
// TODO: Draw an int at the cursor position, advance the cursor
|
||||
}
|
||||
|
||||
int lcd_put_dwin_string() {
|
||||
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
|
||||
lcd_advance_cursor(dwin_string.length());
|
||||
return dwin_string.length();
|
||||
}
|
||||
|
||||
// return < 0 on error
|
||||
// return the advanced cols
|
||||
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
|
||||
dwin_string.set(c);
|
||||
dwin_string.truncate(max_length);
|
||||
// Draw the char(s) at the cursor and advance the cursor
|
||||
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
|
||||
lcd_advance_cursor(dwin_string.length());
|
||||
return dwin_string.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Draw a UTF-8 string
|
||||
*
|
||||
* @param utf8_str : the UTF-8 string
|
||||
* @param cb_read_byte : the callback function to read one byte from the utf8_str (from RAM or ROM)
|
||||
* @param max_length : the pixel length of the string allowed (or number of slots in HD44780)
|
||||
*
|
||||
* @return the number of pixels advanced
|
||||
*
|
||||
* Draw a UTF-8 string
|
||||
*/
|
||||
static int lcd_put_u8str_max_cb(const char * utf8_str, uint8_t (*cb_read_byte)(uint8_t * str), pixel_len_t max_length) {
|
||||
uint8_t *p = (uint8_t *)utf8_str;
|
||||
dwin_string.set();
|
||||
while (dwin_string.length() < max_length) {
|
||||
wchar_t ch = 0;
|
||||
p = get_utf8_value_cb(p, cb_read_byte, &ch);
|
||||
if (!ch) break;
|
||||
dwin_string.add(ch);
|
||||
}
|
||||
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
|
||||
lcd_advance_cursor(dwin_string.length());
|
||||
return dwin_string.length();
|
||||
}
|
||||
|
||||
int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
|
||||
return lcd_put_u8str_max_cb(utf8_str, read_byte_ram, max_length);
|
||||
}
|
||||
|
||||
int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
|
||||
return lcd_put_u8str_max_cb(utf8_str_P, read_byte_rom, max_length);
|
||||
}
|
||||
|
||||
lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const inStr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
|
||||
dwin_string.set();
|
||||
dwin_string.add((uint8_t*)pstr, ind, (uint8_t*)inStr);
|
||||
dwin_string.truncate(maxlen);
|
||||
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
|
||||
lcd_advance_cursor(dwin_string.length());
|
||||
return dwin_string.length();
|
||||
}
|
||||
|
||||
#if ENABLED(DEBUG_LCDPRINT)
|
||||
|
||||
int test_dwin_charmap(dwin_charmap_t *data, size_t size, char *name, char flg_show_contents) {
|
||||
int ret;
|
||||
size_t idx = 0;
|
||||
dwin_charmap_t preval = { 0, 0, 0 };
|
||||
dwin_charmap_t pinval = { 0, 0, 0 };
|
||||
char flg_error = 0;
|
||||
|
||||
int i;
|
||||
|
||||
TRACE("Test %s\n", name);
|
||||
|
||||
for (i = 0; i < size; i ++) {
|
||||
memcpy_P(&pinval, &(data[i]), sizeof(pinval));
|
||||
|
||||
if (flg_show_contents) {
|
||||
#if 1
|
||||
TRACE("[% 4d] % 6" PRIu32 "(0x%04" PRIX32 ") --> 0x%02X,0x%02X%s\n", i, pinval.uchar, pinval.uchar, (unsigned int)(pinval.idx), (unsigned int)(pinval.idx2), (preval.uchar < pinval.uchar?"":" <--- ERROR"));
|
||||
#else
|
||||
TRACE("[% 4d]", i);
|
||||
TRACE("% 6" PRIu32 "(0x%04" PRIX32 "),", pinval.uchar, pinval.uchar);
|
||||
TRACE("0x%02X,", (unsigned int)(pinval.idx));
|
||||
TRACE("0x%02X,", (unsigned int)(pinval.idx2));
|
||||
TRACE("%s", (preval.uchar < pinval.uchar?"":" <--- ERROR"));
|
||||
#endif
|
||||
}
|
||||
if (preval.uchar >= pinval.uchar) {
|
||||
flg_error = 1;
|
||||
//TRACE("Error: out of order in array %s: idx=%d, val=%d(0x%x)\n", name, i, pinval.uchar, pinval.uchar);
|
||||
//return -1;
|
||||
}
|
||||
memcpy(&preval, &pinval, sizeof(pinval));
|
||||
|
||||
ret = pf_bsearch_r((void *)data, size, pf_bsearch_cb_comp_dwinmap_pgm, (void *)&pinval, &idx);
|
||||
if (ret < 0) {
|
||||
flg_error = 1;
|
||||
TRACE("Error: not found item in array %s: idx=%d, val=%d(0x%x)\n", name, i, pinval.uchar, pinval.uchar);
|
||||
//return -1;
|
||||
}
|
||||
if (idx != i) {
|
||||
flg_error = 1;
|
||||
TRACE("Error: wrong index found item in array %s: idx=%d, val=%d(0x%x)\n", name, i, pinval.uchar, pinval.uchar);
|
||||
//return -1;
|
||||
}
|
||||
}
|
||||
if (flg_error) {
|
||||
TRACE("\nError: in array %s\n\n", name);
|
||||
return -1;
|
||||
}
|
||||
TRACE("\nPASS array %s\n\n", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_dwin_charmap_all() {
|
||||
int flg_error = 0;
|
||||
if (test_dwin_charmap(g_dwin_charmap_device, COUNT(g_dwin_charmap_device), "g_dwin_charmap_device", 0) < 0) {
|
||||
flg_error = 1;
|
||||
test_dwin_charmap(g_dwin_charmap_device, COUNT(g_dwin_charmap_device), "g_dwin_charmap_device", 1);
|
||||
}
|
||||
if (test_dwin_charmap(g_dwin_charmap_common, COUNT(g_dwin_charmap_common), "g_dwin_charmap_common", 0) < 0) {
|
||||
flg_error = 1;
|
||||
test_dwin_charmap(g_dwin_charmap_common, COUNT(g_dwin_charmap_common), "g_dwin_charmap_common", 1);
|
||||
}
|
||||
if (flg_error) {
|
||||
TRACE("\nFAILED in dwin tests!\n");
|
||||
return -1;
|
||||
}
|
||||
TRACE("\nPASS in dwin tests.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // DEBUG_LCDPRINT
|
||||
|
||||
#endif // IS_DWIN_MARLINUI
|
30
Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.h
Normal file
30
Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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
|
||||
|
||||
#include "../../lcdprint.h"
|
||||
|
||||
typedef struct { int16_t x, y; } cursor_t;
|
||||
extern cursor_t cursor;
|
||||
|
||||
int lcd_put_dwin_string();
|
||||
void lcd_moveto_xy(const lcd_uint_t, const lcd_uint_t);
|
146
Marlin/src/lcd/e3v2/marlinui/marlinui_dwin.h
Normal file
146
Marlin/src/lcd/e3v2/marlinui/marlinui_dwin.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* lcd/e3v2/marlinui/lcdprint_dwin.h
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
#include "dwin_lcd.h"
|
||||
|
||||
typedef uint16_t dwin_coord_t; // Screen can be pretty big
|
||||
typedef uint16_t lcd_uint_t;
|
||||
typedef int16_t lcd_int_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t index, width, height;
|
||||
uint16_t fg, bg;
|
||||
bool solid;
|
||||
} dwin_font_t;
|
||||
|
||||
extern dwin_font_t dwin_font;
|
||||
|
||||
// Only Western languages support big / small fonts
|
||||
//#if DISABLED(DISPLAY_CHARSET_ISO10646_1)
|
||||
// #undef USE_BIG_EDIT_FONT
|
||||
// #undef USE_SMALL_INFOFONT
|
||||
//#endif
|
||||
|
||||
#if ENABLED(USE_BIG_EDIT_FONT)
|
||||
#define DWIN_FONT_EDIT font10x20
|
||||
#else
|
||||
#define DWIN_FONT_EDIT font8x16
|
||||
#endif
|
||||
|
||||
#define DWIN_FONT_INFO font8x16
|
||||
|
||||
#if DWIN_FONT_MENU == font6x12
|
||||
#define MENU_FONT_WIDTH 6
|
||||
#define MENU_FONT_ASCENT 10
|
||||
#define MENU_FONT_DESCENT 2
|
||||
#elif DWIN_FONT_MENU == font8x16
|
||||
#define MENU_FONT_WIDTH 8
|
||||
#define MENU_FONT_ASCENT 13
|
||||
#define MENU_FONT_DESCENT 3
|
||||
#elif DWIN_FONT_MENU == font10x20
|
||||
#define MENU_FONT_WIDTH 10
|
||||
#define MENU_FONT_ASCENT 16
|
||||
#define MENU_FONT_DESCENT 4
|
||||
#endif
|
||||
#define MENU_FONT_HEIGHT (MENU_FONT_ASCENT + MENU_FONT_DESCENT)
|
||||
|
||||
#define EXTRA_ROW_HEIGHT 8
|
||||
#define MENU_LINE_HEIGHT (MENU_FONT_HEIGHT + EXTRA_ROW_HEIGHT)
|
||||
|
||||
#if DWIN_FONT_EDIT == font6x12
|
||||
#define EDIT_FONT_WIDTH 6
|
||||
#define EDIT_FONT_ASCENT 10
|
||||
#define EDIT_FONT_DESCENT 2
|
||||
#elif DWIN_FONT_EDIT == font8x16
|
||||
#define EDIT_FONT_WIDTH 8
|
||||
#define EDIT_FONT_ASCENT 13
|
||||
#define EDIT_FONT_DESCENT 3
|
||||
#elif DWIN_FONT_EDIT == font10x20
|
||||
#define EDIT_FONT_WIDTH 10
|
||||
#define EDIT_FONT_ASCENT 16
|
||||
#define EDIT_FONT_DESCENT 4
|
||||
#endif
|
||||
#define EDIT_FONT_HEIGHT (EDIT_FONT_ASCENT + EDIT_FONT_DESCENT)
|
||||
|
||||
#if DWIN_FONT_INFO == font6x12
|
||||
#define INFO_FONT_WIDTH 6
|
||||
#define INFO_FONT_ASCENT 10
|
||||
#define INFO_FONT_DESCENT 2
|
||||
#elif DWIN_FONT_INFO == font8x16
|
||||
#define INFO_FONT_WIDTH 8
|
||||
#define INFO_FONT_ASCENT 13
|
||||
#define INFO_FONT_DESCENT 3
|
||||
#elif DWIN_FONT_INFO == font10x20
|
||||
#define INFO_FONT_WIDTH 10
|
||||
#define INFO_FONT_ASCENT 16
|
||||
#define INFO_FONT_DESCENT 4
|
||||
#endif
|
||||
#define INFO_FONT_HEIGHT (INFO_FONT_ASCENT + INFO_FONT_DESCENT)
|
||||
|
||||
#if DWIN_FONT_STAT == font6x12
|
||||
#define STAT_FONT_WIDTH 6
|
||||
#define STAT_FONT_ASCENT 10
|
||||
#define STAT_FONT_DESCENT 2
|
||||
#elif DWIN_FONT_STAT == font8x16
|
||||
#define STAT_FONT_WIDTH 8
|
||||
#define STAT_FONT_ASCENT 13
|
||||
#define STAT_FONT_DESCENT 3
|
||||
#elif DWIN_FONT_STAT == font10x20
|
||||
#define STAT_FONT_WIDTH 10
|
||||
#define STAT_FONT_ASCENT 16
|
||||
#define STAT_FONT_DESCENT 4
|
||||
#elif DWIN_FONT_STAT == font12x24
|
||||
#define STAT_FONT_WIDTH 12
|
||||
#define STAT_FONT_ASCENT 19
|
||||
#define STAT_FONT_DESCENT 5
|
||||
#elif DWIN_FONT_STAT == font14x28
|
||||
#define STAT_FONT_WIDTH 14
|
||||
#define STAT_FONT_ASCENT 22
|
||||
#define STAT_FONT_DESCENT 6
|
||||
#elif DWIN_FONT_STAT == font16x32
|
||||
#define STAT_FONT_WIDTH 16
|
||||
#define STAT_FONT_ASCENT 26
|
||||
#define STAT_FONT_DESCENT 6
|
||||
#elif DWIN_FONT_STAT == font20x40
|
||||
#define STAT_FONT_WIDTH 20
|
||||
#define STAT_FONT_ASCENT 32
|
||||
#define STAT_FONT_DESCENT 8
|
||||
#elif DWIN_FONT_STAT == font24x48
|
||||
#define STAT_FONT_WIDTH 24
|
||||
#define STAT_FONT_ASCENT 38
|
||||
#define STAT_FONT_DESCENT 10
|
||||
#elif DWIN_FONT_STAT == font28x56
|
||||
#define STAT_FONT_WIDTH 28
|
||||
#define STAT_FONT_ASCENT 44
|
||||
#define STAT_FONT_DESCENT 12
|
||||
#elif DWIN_FONT_STAT == font32x64
|
||||
#define STAT_FONT_WIDTH 32
|
||||
#define STAT_FONT_ASCENT 50
|
||||
#define STAT_FONT_DESCENT 14
|
||||
#endif
|
||||
#define STAT_FONT_HEIGHT (STAT_FONT_ASCENT + STAT_FONT_DESCENT)
|
599
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Normal file
599
Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Normal file
@@ -0,0 +1,599 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if IS_DWIN_MARLINUI
|
||||
|
||||
#include "marlinui_dwin.h"
|
||||
#include "dwin_lcd.h"
|
||||
#include "dwin_string.h"
|
||||
|
||||
//#include "../../lcdprint.h"
|
||||
#include "lcdprint_dwin.h"
|
||||
#include "../../fontutils.h"
|
||||
#include "../../../libs/numtostr.h"
|
||||
#include "../../marlinui.h"
|
||||
|
||||
#include "../../../sd/cardreader.h"
|
||||
#include "../../../module/motion.h"
|
||||
#include "../../../module/temperature.h"
|
||||
#include "../../../module/printcounter.h"
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
#include "../../../libs/duration_t.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
#include "../../../feature/bedlevel/bedlevel.h"
|
||||
#endif
|
||||
|
||||
// DWIN printing specifies the font on each string operation
|
||||
// but we'll make the font modal for Marlin
|
||||
dwin_font_t dwin_font = { font8x16, 8, 16, Color_White, Color_Bg_Black, true };
|
||||
void MarlinUI::set_font(const uint8_t font_nr) {
|
||||
if (font_nr != dwin_font.index) {
|
||||
dwin_font.index = font_nr;
|
||||
uint8_t w, h;
|
||||
switch (font_nr) {
|
||||
default:
|
||||
case font6x12: w = 6; h = 12; break;
|
||||
case font8x16: w = 8; h = 16; break;
|
||||
case font10x20: w = 10; h = 20; break;
|
||||
case font12x24: w = 12; h = 24; break;
|
||||
case font14x28: w = 14; h = 28; break;
|
||||
case font16x32: w = 16; h = 32; break;
|
||||
case font20x40: w = 20; h = 40; break;
|
||||
case font24x48: w = 24; h = 48; break;
|
||||
case font28x56: w = 28; h = 56; break;
|
||||
case font32x64: w = 32; h = 64; break;
|
||||
}
|
||||
dwin_font.width = w;
|
||||
dwin_font.height = h;
|
||||
// TODO: Array with dimensions, auto fit menu items,
|
||||
// update char width / height of the screen based on
|
||||
// new (fixed-width) font size.
|
||||
}
|
||||
}
|
||||
|
||||
// This display is always detected
|
||||
bool MarlinUI::detected() { return true; }
|
||||
|
||||
// Initialize or re-initialize the LCD
|
||||
void MarlinUI::init_lcd() {
|
||||
DWIN_Startup();
|
||||
|
||||
// Load the assets JPG (currently just the status screen 'icon')
|
||||
DWIN_JPG_CacheTo1(DWIN_MarlinUI_Assets);
|
||||
}
|
||||
|
||||
// This LCD should clear where it will draw anew
|
||||
void MarlinUI::clear_lcd() {
|
||||
DWIN_ICON_AnimationControl(0x0000); // disable all icon animations
|
||||
DWIN_Frame_Clear(Color_Bg_Black);
|
||||
DWIN_UpdateLCD();
|
||||
|
||||
did_first_redraw = false;
|
||||
}
|
||||
|
||||
#if ENABLED(SHOW_BOOTSCREEN)
|
||||
|
||||
void MarlinUI::show_bootscreen() {
|
||||
clear_lcd();
|
||||
dwin_string.set(F(SHORT_BUILD_VERSION));
|
||||
|
||||
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
|
||||
#define LOGO_CENTER ((LCD_PIXEL_WIDTH) / 2)
|
||||
#define INFO_CENTER LOGO_CENTER
|
||||
#define VERSION_Y 330
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, LOGO_CENTER - 174 / 2, 280);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, LOGO_CENTER - 180 / 2, 420);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, LOGO_CENTER - 100 / 2, 440);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, LOGO_CENTER - 126 / 2, 460);
|
||||
#else
|
||||
#define LOGO_CENTER (280 / 2)
|
||||
#define INFO_CENTER ((LCD_PIXEL_WIDTH) - 200 / 2)
|
||||
#define VERSION_Y 84
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, INFO_CENTER - 174 / 2, 60);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, INFO_CENTER - 180 / 2, 130);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, INFO_CENTER - 100 / 2, 152);
|
||||
DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, INFO_CENTER - 126 / 2, 200);
|
||||
#endif
|
||||
|
||||
DWIN_Draw_String(false, font10x20, Color_Yellow, Color_Bg_Black, INFO_CENTER - (dwin_string.length() * 10) / 2, VERSION_Y, S(dwin_string.string()));
|
||||
DWIN_UpdateLCD();
|
||||
}
|
||||
|
||||
void MarlinUI::bootscreen_completion(const millis_t sofar) {
|
||||
if ((BOOTSCREEN_TIMEOUT) > sofar) safe_delay((BOOTSCREEN_TIMEOUT) - sofar);
|
||||
clear_lcd();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// The kill screen is displayed for unrecoverable conditions
|
||||
void MarlinUI::draw_kill_screen() {
|
||||
set_font(DWIN_FONT_ALERT);
|
||||
DWIN_Frame_Clear(Color_Bg_Black);
|
||||
dwin_font.fg = Color_Error_Red;
|
||||
dwin_font.solid = false;
|
||||
DWIN_Draw_Rectangle(1, Color_Bg_Window, 20, 20, LCD_PIXEL_WIDTH - 20, LCD_PIXEL_HEIGHT - 20);
|
||||
// make the frame a few pixels thick
|
||||
DWIN_Draw_Rectangle(0, Color_Yellow, 20, 20, LCD_PIXEL_WIDTH - 20, LCD_PIXEL_HEIGHT - 20);
|
||||
DWIN_Draw_Rectangle(0, Color_Yellow, 21, 21, LCD_PIXEL_WIDTH - 21, LCD_PIXEL_HEIGHT - 21);
|
||||
DWIN_Draw_Rectangle(0, Color_Yellow, 22, 22, LCD_PIXEL_WIDTH - 22, LCD_PIXEL_HEIGHT - 22);
|
||||
|
||||
uint8_t cx = (LCD_PIXEL_WIDTH / dwin_font.width / 2),
|
||||
cy = (LCD_PIXEL_HEIGHT / dwin_font.height / 2);
|
||||
|
||||
#if ENABLED(DWIN_MARLINUI_LANDSCAPE)
|
||||
cx += (96 / 2 / dwin_font.width);
|
||||
DWIN_ICON_Show(ICON, ICON_Halted, 40, (LCD_PIXEL_HEIGHT - 96) / 2);
|
||||
#else
|
||||
DWIN_ICON_Show(ICON, ICON_Halted, (LCD_PIXEL_WIDTH - 96) / 2, 40);
|
||||
#endif
|
||||
|
||||
uint8_t slen = utf8_strlen(status_message);
|
||||
lcd_moveto(cx - (slen / 2), cy - 1);
|
||||
lcd_put_u8str(status_message);
|
||||
|
||||
slen = utf8_strlen(S(GET_TEXT_F(MSG_HALTED)));
|
||||
lcd_moveto(cx - (slen / 2), cy);
|
||||
lcd_put_u8str_P((const char*)GET_TEXT_F(MSG_HALTED));
|
||||
|
||||
slen = utf8_strlen(S(GET_TEXT_F(MSG_HALTED)));
|
||||
lcd_moveto(cx - (slen / 2), cy + 1);
|
||||
lcd_put_u8str_P((const char*)GET_TEXT_F(MSG_HALTED));
|
||||
}
|
||||
|
||||
//
|
||||
// Status Message
|
||||
//
|
||||
void MarlinUI::draw_status_message(const bool blink) {
|
||||
set_font(DWIN_FONT_STAT);
|
||||
dwin_font.solid = true;
|
||||
dwin_font.fg = Color_White;
|
||||
dwin_font.bg = Color_Bg_Black;
|
||||
lcd_moveto_xy(0, LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1);
|
||||
|
||||
constexpr uint8_t max_status_chars = (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH);
|
||||
|
||||
auto status_changed = []{
|
||||
static uint16_t old_hash = 0x0000;
|
||||
uint16_t hash = 0x0000;
|
||||
for (uint8_t i = 0; i < MAX_MESSAGE_LENGTH; i++) {
|
||||
const char c = ui.status_message[i];
|
||||
if (!c) break;
|
||||
hash = ((hash << 1) | (hash >> 15)) ^ c;
|
||||
}
|
||||
const bool hash_changed = hash != old_hash;
|
||||
old_hash = hash;
|
||||
return hash_changed || !ui.did_first_redraw;
|
||||
};
|
||||
|
||||
#if ENABLED(STATUS_MESSAGE_SCROLLING)
|
||||
static bool last_blink = false;
|
||||
|
||||
// Get the UTF8 character count of the string
|
||||
uint8_t slen = utf8_strlen(status_message);
|
||||
|
||||
// If the string fits into the LCD, just print it and do not scroll it
|
||||
if (slen <= max_status_chars) {
|
||||
|
||||
if (status_changed()) {
|
||||
|
||||
// The string isn't scrolling and may not fill the screen
|
||||
lcd_put_u8str(status_message);
|
||||
|
||||
// Fill the rest with spaces
|
||||
while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
|
||||
}
|
||||
}
|
||||
else {
|
||||
// String is larger than the available line space
|
||||
|
||||
// Get a pointer to the next valid UTF8 character
|
||||
// and the string remaining length
|
||||
uint8_t rlen;
|
||||
const char *stat = status_and_len(rlen);
|
||||
lcd_put_u8str_max(stat, max_status_chars);
|
||||
|
||||
// If the string doesn't completely fill the line...
|
||||
if (rlen < max_status_chars) {
|
||||
lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
|
||||
uint8_t chars = max_status_chars - rlen; // Amount of space left in characters
|
||||
if (--chars) { // Draw a second dot if there's space
|
||||
lcd_put_wchar('.');
|
||||
if (--chars)
|
||||
lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
|
||||
}
|
||||
}
|
||||
|
||||
if (last_blink != blink) {
|
||||
last_blink = blink;
|
||||
advance_status_scroll();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
UNUSED(blink);
|
||||
|
||||
if (status_changed()) {
|
||||
// Get the UTF8 character count of the string
|
||||
uint8_t slen = utf8_strlen(status_message);
|
||||
|
||||
// Just print the string to the LCD
|
||||
lcd_put_u8str_max(status_message, max_status_chars);
|
||||
|
||||
// Fill the rest with spaces if there are missing spaces
|
||||
while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#if HAS_LCD_BRIGHTNESS
|
||||
void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_MENU
|
||||
|
||||
#include "../../menu/menu.h"
|
||||
|
||||
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
||||
|
||||
void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
|
||||
|
||||
dwin_font.solid = false;
|
||||
dwin_font.fg = Color_White;
|
||||
dwin_string.set("E");
|
||||
dwin_string.add('1' + extruder);
|
||||
dwin_string.add(' ');
|
||||
dwin_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
|
||||
dwin_string.add('/');
|
||||
if (get_blink() || !thermalManager.heater_idle[thermalManager.idle_index_for_id(extruder)].timed_out)
|
||||
dwin_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
|
||||
else
|
||||
dwin_string.add(PSTR(" "));
|
||||
|
||||
lcd_moveto(LCD_WIDTH - dwin_string.length(), row);
|
||||
lcd_put_dwin_string();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Set the colors for a menu item based on whether it is selected
|
||||
static bool mark_as_selected(const uint8_t row, const bool sel, const bool is_static=false) {
|
||||
const dwin_coord_t y = row * (MENU_LINE_HEIGHT) + 1;
|
||||
if (y >= LCD_PIXEL_HEIGHT) return false;
|
||||
|
||||
if (is_static && sel)
|
||||
DWIN_Draw_Box(1, Color_Bg_Heading, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
|
||||
else {
|
||||
#if ENABLED(MENU_HOLLOW_FRAME)
|
||||
DWIN_Draw_Box(1, Color_Bg_Black, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
|
||||
if (sel) DWIN_Draw_Box(0, Select_Color, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
|
||||
#else
|
||||
DWIN_Draw_Box(1, sel ? Select_Color : Color_Bg_Black, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Draw a static line of text in the same idiom as a menu item
|
||||
|
||||
void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
|
||||
// Call mark_as_selected to draw a bigger selection box
|
||||
// and draw the text without a background
|
||||
if (mark_as_selected(row, (bool)(style & SS_INVERT), true)) {
|
||||
ui.set_font(DWIN_FONT_MENU);
|
||||
dwin_font.solid = false;
|
||||
dwin_font.fg = Color_White;
|
||||
|
||||
dwin_string.set();
|
||||
const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0,
|
||||
vlen = vstr ? utf8_strlen(vstr) : 0;
|
||||
if (style & SS_CENTER) {
|
||||
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
|
||||
while (--pad) dwin_string.add(' ');
|
||||
}
|
||||
|
||||
if (plen) dwin_string.add((uint8_t*)pstr, itemIndex, (uint8_t*)itemString);
|
||||
if (vlen) dwin_string.add((uint8_t*)vstr);
|
||||
if (style & SS_CENTER) {
|
||||
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
|
||||
while (--pad) dwin_string.add(' ');
|
||||
}
|
||||
|
||||
lcd_moveto(1, row);
|
||||
lcd_put_dwin_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a generic menu item
|
||||
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char, const char post_char) {
|
||||
if (mark_as_selected(row, sel)) {
|
||||
ui.set_font(DWIN_FONT_MENU);
|
||||
dwin_font.solid = false;
|
||||
dwin_font.fg = Color_White;
|
||||
|
||||
dwin_string.set(pstr, itemIndex, itemString);
|
||||
|
||||
pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length();
|
||||
while (--n > 1) dwin_string.add(' ');
|
||||
|
||||
dwin_string.add(post_char);
|
||||
|
||||
lcd_moveto(1, row);
|
||||
lcd_put_dwin_string();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw a menu item with an editable value
|
||||
//
|
||||
void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
|
||||
if (mark_as_selected(row, sel)) {
|
||||
ui.set_font(DWIN_FONT_MENU);
|
||||
dwin_font.solid = false;
|
||||
dwin_font.fg = Color_White;
|
||||
|
||||
const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen(S(data)));
|
||||
|
||||
dwin_string.set(pstr, itemIndex, itemString);
|
||||
if (vallen) dwin_string.add(':');
|
||||
|
||||
lcd_moveto(1, row);
|
||||
lcd_put_dwin_string();
|
||||
|
||||
if (vallen) {
|
||||
dwin_font.fg = Color_Yellow;
|
||||
dwin_string.set(data);
|
||||
lcd_moveto(LCD_WIDTH - vallen - 1, row);
|
||||
lcd_put_dwin_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draw an edit screen with label and current value
|
||||
//
|
||||
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
|
||||
ui.encoder_direction_normal();
|
||||
|
||||
const dwin_coord_t labellen = utf8_strlen_P(pstr), vallen = utf8_strlen(value);
|
||||
|
||||
dwin_string.set();
|
||||
dwin_string.add((uint8_t*)pstr, itemIndex);
|
||||
if (vallen) dwin_string.add(':'); // If a value is included, add a colon
|
||||
|
||||
// Assume the label is alpha-numeric (with a descender)
|
||||
const uint16_t row = (LCD_HEIGHT / 2) - 1;
|
||||
|
||||
dwin_font.fg = Color_White;
|
||||
dwin_font.solid = true;
|
||||
lcd_moveto((LCD_WIDTH - labellen + !!vallen) / 2, row);
|
||||
lcd_put_dwin_string();
|
||||
|
||||
// If a value is included, print the value in larger text below the label
|
||||
if (vallen) {
|
||||
dwin_string.set();
|
||||
dwin_string.add(value);
|
||||
|
||||
const dwin_coord_t by = (row * MENU_LINE_HEIGHT) + MENU_FONT_HEIGHT + EXTRA_ROW_HEIGHT / 2;
|
||||
DWIN_Draw_String(true, font16x32, Color_Yellow, Color_Bg_Black, (LCD_PIXEL_WIDTH - vallen * 16) / 2, by, S(dwin_string.string()));
|
||||
|
||||
extern screenFunc_t _manual_move_func_ptr;
|
||||
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
|
||||
|
||||
const dwin_coord_t slider_length = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_LANDSCAPE, 120, 20),
|
||||
slider_height = 16,
|
||||
slider_x = (LCD_PIXEL_WIDTH - slider_length) / 2,
|
||||
slider_y = by + 32 + 4,
|
||||
amount = ui.encoderPosition * slider_length / maxEditValue;
|
||||
|
||||
DWIN_Draw_Rectangle(1, Color_Bg_Window, slider_x - 1, slider_y - 1, slider_x - 1 + slider_length + 2 - 1, slider_y - 1 + slider_height + 2 - 1);
|
||||
if (amount > 0)
|
||||
DWIN_Draw_Box(1, BarFill_Color, slider_x, slider_y, amount, slider_height);
|
||||
if (amount < slider_length)
|
||||
DWIN_Draw_Box(1, Color_Bg_Black, slider_x + amount, slider_y, slider_length - amount, slider_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void draw_boxed_string(const bool yesopt, PGM_P const pstr, const bool inv) {
|
||||
const uint8_t len = utf8_strlen_P(pstr),
|
||||
mar = TERN(DWIN_MARLINUI_PORTRAIT, 1, 4),
|
||||
col = yesopt ? LCD_WIDTH - mar - len : mar,
|
||||
row = (LCD_HEIGHT >= 8 ? LCD_HEIGHT / 2 + 3 : LCD_HEIGHT - 1);
|
||||
lcd_moveto(col, row);
|
||||
DWIN_Draw_Box(1, inv ? Select_Color : Color_Bg_Black, cursor.x - dwin_font.width, cursor.y + 1, dwin_font.width * (len + 2), dwin_font.height + 2);
|
||||
lcd_put_u8str_P(col, row, pstr);
|
||||
}
|
||||
|
||||
void MenuItem_confirm::draw_select_screen(
|
||||
PGM_P const yes, PGM_P const no, const bool yesno,
|
||||
PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
|
||||
) {
|
||||
ui.set_font(DWIN_FONT_MENU);
|
||||
dwin_font.solid = false;
|
||||
dwin_font.fg = Color_White;
|
||||
ui.draw_select_screen_prompt(pref, string, suff);
|
||||
draw_boxed_string(false, no, !yesno);
|
||||
draw_boxed_string(true, yes, yesno);
|
||||
}
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
|
||||
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
|
||||
if (mark_as_selected(row, sel)) {
|
||||
dwin_string.set();
|
||||
|
||||
uint8_t maxlen = LCD_WIDTH - 1;
|
||||
if (isDir) {
|
||||
dwin_string.add(LCD_STR_FOLDER " ");
|
||||
maxlen -= 2;
|
||||
}
|
||||
|
||||
dwin_string.add((uint8_t*)ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
|
||||
uint8_t n = maxlen - dwin_string.length();
|
||||
while (n > 0) { dwin_string.add(' '); --n; }
|
||||
lcd_moveto(1, row);
|
||||
lcd_put_dwin_string();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SDSUPPORT
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
|
||||
/**
|
||||
* UBL LCD "radar" map data
|
||||
*/
|
||||
#define MAP_UPPER_LEFT_CORNER_X 5 // These probably should be moved to the .h file But for now,
|
||||
#define MAP_UPPER_LEFT_CORNER_Y 5 // it is easier to play with things having them here
|
||||
#define MAP_MAX_PIXELS_X 262 // 272 - 10
|
||||
#define MAP_MAX_PIXELS_Y 262
|
||||
|
||||
void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
|
||||
// Scale the box pixels appropriately
|
||||
dwin_coord_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
|
||||
y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
|
||||
|
||||
pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
|
||||
pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
|
||||
|
||||
x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
|
||||
y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
|
||||
|
||||
// Clear the Mesh Map
|
||||
|
||||
// First draw the bigger box in White so we have a border around the mesh map box
|
||||
DWIN_Draw_Rectangle(1, Color_White, x_offset - 2, y_offset - 2, x_offset + 2 + x_map_pixels, y_offset + 2 + y_map_pixels);
|
||||
// Now actually clear the mesh map box
|
||||
DWIN_Draw_Rectangle(1, Color_Bg_Black, x_offset, y_offset, x_offset + x_map_pixels, y_offset + y_map_pixels);
|
||||
|
||||
// Fill in the Specified Mesh Point
|
||||
|
||||
const uint8_t y_plot_inv = (GRID_MAX_POINTS_Y - 1) - y_plot; // The origin is typically in the lower right corner. We need to
|
||||
// invert the Y to get it to plot in the right location.
|
||||
|
||||
const dwin_coord_t by = y_offset + y_plot_inv * pixels_per_y_mesh_pnt;
|
||||
DWIN_Draw_Rectangle(1, Select_Color,
|
||||
x_offset + (x_plot * pixels_per_x_mesh_pnt), by,
|
||||
x_offset + (x_plot * pixels_per_x_mesh_pnt) + pixels_per_x_mesh_pnt, by + pixels_per_y_mesh_pnt
|
||||
);
|
||||
|
||||
// Display Mesh Point Locations
|
||||
const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
|
||||
dwin_coord_t y = y_offset + pixels_per_y_mesh_pnt / 2;
|
||||
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
|
||||
for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
|
||||
DWIN_Draw_Point(Color_White, 1, 1, x, y);
|
||||
|
||||
// Put Relevant Text on Display
|
||||
|
||||
// Show X and Y positions at top of screen
|
||||
dwin_font.fg = Color_White;
|
||||
dwin_font.solid = true;
|
||||
const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
|
||||
lpos = pos.asLogical();
|
||||
|
||||
lcd_moveto(
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, 1),
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
|
||||
);
|
||||
lcd_put_u8str_P(X_LBL);
|
||||
lcd_put_u8str(ftostr52(lpos.x));
|
||||
lcd_moveto(
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, 1),
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, 3, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
|
||||
);
|
||||
lcd_put_u8str_P(Y_LBL);
|
||||
lcd_put_u8str(ftostr52(lpos.y));
|
||||
|
||||
// Print plot position
|
||||
dwin_string.set("(");
|
||||
dwin_string.add(i8tostr3rj(x_plot));
|
||||
dwin_string.add(",");
|
||||
dwin_string.add(i8tostr3rj(y_plot));
|
||||
dwin_string.add(")");
|
||||
lcd_moveto(
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 2, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
|
||||
);
|
||||
lcd_put_dwin_string();
|
||||
|
||||
// Show the location value
|
||||
dwin_string.set(Z_LBL);
|
||||
if (!isnan(Z_VALUES_ARR[x_plot][y_plot]))
|
||||
dwin_string.add(ftostr43sign(Z_VALUES_ARR[x_plot][y_plot]));
|
||||
else
|
||||
dwin_string.add(PSTR(" -----"));
|
||||
lcd_moveto(
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
|
||||
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
|
||||
);
|
||||
lcd_put_dwin_string();
|
||||
}
|
||||
|
||||
#endif // AUTO_BED_LEVELING_UBL
|
||||
|
||||
#if ANY(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY, BABYSTEP_GFX_OVERLAY)
|
||||
|
||||
void _lcd_zoffset_overlay_gfx(const float zvalue) {
|
||||
// Determine whether the user is raising or lowering the nozzle.
|
||||
static int8_t dir;
|
||||
static float old_zvalue;
|
||||
if (zvalue != old_zvalue) {
|
||||
dir = zvalue ? zvalue < old_zvalue ? -1 : 1 : 0;
|
||||
old_zvalue = zvalue;
|
||||
}
|
||||
|
||||
const int rot_up = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCCW, ICON_RotateCW),
|
||||
rot_down = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCW, ICON_RotateCCW);
|
||||
|
||||
const int nozzle = (LCD_PIXEL_WIDTH / 2) - 20;
|
||||
|
||||
// Draw a representation of the nozzle
|
||||
DWIN_Draw_Box(1, Color_Bg_Black, nozzle + 3, 8, 48, 52); // 'clear' the area where the nozzle is drawn in case it was moved up/down
|
||||
DWIN_ICON_Show(ICON, ICON_HotendOff, nozzle + 3, 10 - dir);
|
||||
DWIN_ICON_Show(ICON, ICON_BedLine, nozzle, 10 + 36);
|
||||
|
||||
// Draw cw/ccw indicator and up/down arrows
|
||||
const int arrow_y = LCD_PIXEL_HEIGHT / 2 - 24;
|
||||
DWIN_ICON_Show(ICON, ICON_DownArrow, 0, arrow_y - dir);
|
||||
DWIN_ICON_Show(ICON, rot_down, 48, arrow_y);
|
||||
|
||||
DWIN_ICON_Show(ICON, ICON_UpArrow, LCD_PIXEL_WIDTH - 10 - (48*2), arrow_y - dir);
|
||||
DWIN_ICON_Show(ICON, rot_up, LCD_PIXEL_WIDTH - 10 - 48, arrow_y);
|
||||
}
|
||||
|
||||
#endif // BABYSTEP_ZPROBE_GFX_OVERLAY || MESH_EDIT_GFX_OVERLAY
|
||||
|
||||
#endif // HAS_LCD_MENU
|
||||
|
||||
#endif // IS_DWIN_MARLINUI
|
391
Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp
Normal file
391
Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp
Normal file
@@ -0,0 +1,391 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if IS_DWIN_MARLINUI
|
||||
|
||||
#include "marlinui_dwin.h"
|
||||
#include "dwin_lcd.h"
|
||||
#include "dwin_string.h"
|
||||
#include "lcdprint_dwin.h"
|
||||
|
||||
#include "../../fontutils.h"
|
||||
#include "../../../libs/numtostr.h"
|
||||
#include "../../marlinui.h"
|
||||
|
||||
#include "../../../sd/cardreader.h"
|
||||
#include "../../../module/motion.h"
|
||||
#include "../../../module/temperature.h"
|
||||
#include "../../../module/printcounter.h"
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
#include "../../../libs/duration_t.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(LCD_SHOW_E_TOTAL)
|
||||
#include "../../../MarlinCore.h" // for printingIsActive
|
||||
#endif
|
||||
|
||||
#define STATUS_HEATERS_X 15
|
||||
#define STATUS_HEATERS_Y 56
|
||||
#define STATUS_HEATERS_XSPACE 64
|
||||
#define STATUS_FAN_WIDTH 48
|
||||
#define STATUS_FAN_HEIGHT 48
|
||||
#define STATUS_FAN_Y STATUS_HEATERS_Y + 22
|
||||
#define STATUS_CHR_WIDTH 14
|
||||
#define STATUS_CHR_HEIGHT 28
|
||||
|
||||
//
|
||||
// Before homing, blink '123' <-> '???'.
|
||||
// Homed but unknown... '123' <-> ' '.
|
||||
// Homed and known, display constantly.
|
||||
//
|
||||
FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink, const uint16_t x, const uint16_t y) {
|
||||
uint8_t vallen = utf8_strlen(value);
|
||||
|
||||
if (!ui.did_first_redraw) {
|
||||
dwin_string.set();
|
||||
dwin_string.add('X' + axis);
|
||||
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (vallen * 14 - 14) / 2, y + 2, S(dwin_string.string()));
|
||||
}
|
||||
|
||||
dwin_string.set();
|
||||
if (blink)
|
||||
dwin_string.add(value);
|
||||
else {
|
||||
if (!TEST(axis_homed, axis))
|
||||
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
|
||||
else {
|
||||
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
|
||||
if (!TEST(axis_trusted, axis))
|
||||
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
|
||||
else
|
||||
#endif
|
||||
dwin_string.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
// For E_TOTAL there may be some characters to cover up
|
||||
if (BOTH(DWIN_MARLINUI_PORTRAIT, LCD_SHOW_E_TOTAL) && axis == X_AXIS)
|
||||
dwin_string.add(" ");
|
||||
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
|
||||
}
|
||||
|
||||
#if ENABLED(LCD_SHOW_E_TOTAL)
|
||||
|
||||
FORCE_INLINE void _draw_e_value(const_float_t value, const uint16_t x, const uint16_t y) {
|
||||
const uint8_t scale = value >= 100000.0f ? 10 : 1; // show cm after 99,999mm
|
||||
|
||||
if (!ui.did_first_redraw) {
|
||||
// Extra spaces so we don't have to clear the 'Y' label separately
|
||||
dwin_string.set("E ");
|
||||
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (4 * 14 / 2) - 7, y + 2, S(dwin_string.string()));
|
||||
}
|
||||
|
||||
dwin_string.set(ui16tostr5rj(value / scale));
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
|
||||
|
||||
// Extra spaces so we don't have to clear out the Y value separately
|
||||
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x + (5 * 14), y + 32, S(scale == 1 ? "mm " : "cm "));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// Fan Icon and Percentage
|
||||
//
|
||||
FORCE_INLINE void _draw_fan_status(const uint16_t x, const uint16_t y) {
|
||||
const uint16_t fanx = (4 * STATUS_CHR_WIDTH - STATUS_FAN_WIDTH) / 2;
|
||||
const uint8_t fan_pct = thermalManager.scaledFanSpeedPercent(0);
|
||||
const bool fan_on = !!fan_pct;
|
||||
if (fan_on) {
|
||||
DWIN_ICON_Animation(0, fan_on, ICON, ICON_Fan0, ICON_Fan3, x + fanx, y, 25);
|
||||
dwin_string.set(i8tostr3rj(fan_pct));
|
||||
dwin_string.add('%');
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
|
||||
}
|
||||
else {
|
||||
DWIN_ICON_Show(ICON, ICON_Fan0, x + fanx, y);
|
||||
dwin_string.set(PSTR(" "));
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
|
||||
}
|
||||
}
|
||||
|
||||
#if HOTENDS > 2
|
||||
#define HOTEND_STATS 3
|
||||
#elif HOTENDS > 1
|
||||
#define HOTEND_STATS 2
|
||||
#elif HAS_HOTEND
|
||||
#define HOTEND_STATS 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Draw a single heater icon with current and target temperature, at the given XY
|
||||
*/
|
||||
FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x, const uint16_t y) {
|
||||
|
||||
#if HAS_HOTEND
|
||||
static celsius_t old_temp[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500),
|
||||
old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500);
|
||||
static bool old_on[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, false);
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
static celsius_t old_bed_temp = 500, old_bed_target = 500;
|
||||
static bool old_bed_on = false;
|
||||
#endif
|
||||
|
||||
#if HAS_HOTEND && HAS_HEATED_BED
|
||||
const bool isBed = heater < 0;
|
||||
const float tc = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)),
|
||||
tt = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater));
|
||||
const uint8_t ta = isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater);
|
||||
const bool c_draw = tc != (isBed ? old_bed_temp : old_temp[heater]),
|
||||
t_draw = tt != (isBed ? old_bed_target : old_target[heater]),
|
||||
i_draw = ta != (isBed ? old_bed_on : old_on[heater]);
|
||||
if (isBed) { old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta; }
|
||||
else { old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta; }
|
||||
#elif HAS_HOTEND
|
||||
constexpr bool isBed = false;
|
||||
const float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
|
||||
const uint8_t ta = thermalManager.isHeatingHotend(heater);
|
||||
const bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
|
||||
old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta;
|
||||
#elif HAS_HEATED_BED
|
||||
constexpr bool isBed = true;
|
||||
const float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
|
||||
const uint8_t ta = thermalManager.isHeatingBed();
|
||||
const bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
|
||||
old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
|
||||
#endif
|
||||
|
||||
if (!ui.did_first_redraw || t_draw) {
|
||||
dwin_string.set(i16tostr3rj(tt + 0.5));
|
||||
dwin_string.add(LCD_STR_DEGREE);
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string()));
|
||||
}
|
||||
|
||||
if (!ui.did_first_redraw || i_draw)
|
||||
DWIN_ICON_Show(ICON, (isBed ? ICON_BedOff : ICON_HotendOff) + ta, x, y + STATUS_CHR_HEIGHT + 2);
|
||||
|
||||
if (!ui.did_first_redraw || c_draw) {
|
||||
dwin_string.set(i16tostr3rj(tc + 0.5));
|
||||
dwin_string.add(LCD_STR_DEGREE);
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 70, S(dwin_string.string()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the current "feed rate" percentage preceded by the >> character
|
||||
*/
|
||||
FORCE_INLINE void _draw_feedrate_status(const char *value, uint16_t x, uint16_t y) {
|
||||
if (!ui.did_first_redraw) {
|
||||
dwin_string.set(LCD_STR_FEEDRATE);
|
||||
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
|
||||
}
|
||||
|
||||
dwin_string.set(value);
|
||||
dwin_string.add(PSTR("%"));
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 14, y, S(dwin_string.string()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the MarlinUI Status Screen for Ender 3 V2
|
||||
*/
|
||||
void MarlinUI::draw_status_screen() {
|
||||
const bool blink = get_blink();
|
||||
|
||||
// Draw elements that never change
|
||||
if (!ui.did_first_redraw) {
|
||||
// Logo/Status Icon
|
||||
#define STATUS_LOGO_WIDTH 128
|
||||
#define STATUS_LOGO_HEIGHT 40
|
||||
DWIN_ICON_Show(ICON, ICON_LOGO_Marlin, (LCD_PIXEL_WIDTH - (STATUS_LOGO_WIDTH)) / 2, ((STATUS_HEATERS_Y - 4) - (STATUS_LOGO_HEIGHT)) / 2);
|
||||
|
||||
// Draw a frame around the x/y/z values
|
||||
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
|
||||
DWIN_Draw_Rectangle(0, Select_Color, 0, 193, LCD_PIXEL_WIDTH, 260);
|
||||
#else
|
||||
//DWIN_Draw_Rectangle(0, Select_Color, LCD_PIXEL_WIDTH - 106, 50, LCD_PIXEL_WIDTH - 1, 230);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t hx = STATUS_HEATERS_X;
|
||||
#if HAS_HOTEND
|
||||
_draw_heater_status(H_E0, hx, STATUS_HEATERS_Y);
|
||||
hx += STATUS_HEATERS_XSPACE;
|
||||
#endif
|
||||
#if HAS_MULTI_HOTEND
|
||||
_draw_heater_status(H_E1, hx, STATUS_HEATERS_Y);
|
||||
hx += STATUS_HEATERS_XSPACE;
|
||||
#endif
|
||||
#if HAS_HEATED_BED
|
||||
_draw_heater_status(H_BED, hx, STATUS_HEATERS_Y);
|
||||
#endif
|
||||
|
||||
#if HAS_FAN
|
||||
// Fan display, pinned to the right side
|
||||
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
|
||||
_draw_fan_status(LCD_PIXEL_WIDTH - STATUS_CHR_WIDTH * 4, STATUS_FAN_Y);
|
||||
#else
|
||||
_draw_fan_status(212, STATUS_FAN_Y);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Axis values
|
||||
const xyz_pos_t lpos = current_position.asLogical();
|
||||
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive()); UNUSED(show_e_total);
|
||||
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
|
||||
constexpr int16_t cpy = 195;
|
||||
if (show_e_total) {
|
||||
TERN_(LCD_SHOW_E_TOTAL, _draw_e_value(e_move_accumulator, 6, cpy));
|
||||
}
|
||||
else {
|
||||
_draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink, 6, cpy);
|
||||
TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink, 95, cpy));
|
||||
}
|
||||
TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, 165, cpy));
|
||||
#else
|
||||
constexpr int16_t cpx = LCD_PIXEL_WIDTH - 104;
|
||||
_draw_axis_value(X_AXIS, ftostr52sp(lpos.x), blink, cpx, STATUS_HEATERS_Y);
|
||||
TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr52sp(lpos.y), blink, cpx, STATUS_HEATERS_Y + 59));
|
||||
TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, cpx, STATUS_HEATERS_Y + 118));
|
||||
#endif
|
||||
|
||||
// Feedrate
|
||||
static uint16_t old_fp = 0;
|
||||
if (!ui.did_first_redraw || old_fp != feedrate_percentage) {
|
||||
old_fp = feedrate_percentage;
|
||||
_draw_feedrate_status(i16tostr3rj(feedrate_percentage),
|
||||
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
|
||||
5, 290
|
||||
#else
|
||||
294, STATUS_HEATERS_Y
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Elapsed time
|
||||
//
|
||||
char buffer[14];
|
||||
duration_t time;
|
||||
|
||||
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
|
||||
|
||||
// Portrait mode only shows one value at a time, and will rotate if ROTATE_PROGRESS_DISPLAY
|
||||
dwin_string.set();
|
||||
char prefix = ' ';
|
||||
#if ENABLED(SHOW_REMAINING_TIME)
|
||||
if (TERN1(ROTATE_PROGRESS_DISPLAY, blink) && print_job_timer.isRunning()) {
|
||||
time = get_remaining_time();
|
||||
prefix = 'R';
|
||||
}
|
||||
else
|
||||
#endif
|
||||
time = print_job_timer.duration();
|
||||
|
||||
time.toDigital(buffer);
|
||||
dwin_string.add(prefix);
|
||||
dwin_string.add(buffer);
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, (LCD_PIXEL_WIDTH - ((dwin_string.length() + 1) * 14)), 290, S(dwin_string.string()));
|
||||
|
||||
#else
|
||||
|
||||
// landscape mode shows both elapsed and remaining (if SHOW_REMAINING_TIME)
|
||||
time = print_job_timer.duration();
|
||||
time.toDigital(buffer);
|
||||
dwin_string.set(" ");
|
||||
dwin_string.add(buffer);
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 280, 100, S(dwin_string.string()));
|
||||
|
||||
#if ENABLED(LCD_SHOW_E_TOTAL)
|
||||
if (show_e_total && TERN1(SHOW_REMAINING_TIME, !blink)) { // if SHOW_REMAINING_TIME is also
|
||||
const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // show cm after 99,000mm
|
||||
|
||||
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 249, 135, S("E"));
|
||||
dwin_string.set(ui16tostr5rj(e_move_accumulator * escale));
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 263, 135, S(dwin_string.string()));
|
||||
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 333, 135, S(escale==1 ? "mm" : "cm"));
|
||||
}
|
||||
#endif
|
||||
#if ENABLED(SHOW_REMAINING_TIME)
|
||||
if (!show_e_total || blink) {
|
||||
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 249, 135, S(" R "));
|
||||
time = get_remaining_time();
|
||||
time.toDigital(buffer);
|
||||
dwin_string.set(buffer);
|
||||
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 291, 135, S(dwin_string.string()));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// Progress Bar
|
||||
//
|
||||
constexpr int16_t pb_margin = 5, pb_left = pb_margin, pb_height = 60,
|
||||
pb_right = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_PORTRAIT, 0, 107) - pb_margin,
|
||||
pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 230),
|
||||
pb_top = pb_bottom - pb_height,
|
||||
pb_width = pb_right - pb_left;
|
||||
|
||||
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
|
||||
|
||||
if (!ui.did_first_redraw)
|
||||
DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
|
||||
|
||||
static uint16_t old_solid = 50;
|
||||
const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
|
||||
const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
|
||||
|
||||
if (p_draw) {
|
||||
//if (pb_solid)
|
||||
DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
|
||||
|
||||
//if (pb_solid < old_solid)
|
||||
DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
|
||||
|
||||
#if ENABLED(SHOW_SD_PERCENT)
|
||||
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
|
||||
dwin_string.add(PSTR("%"));
|
||||
DWIN_Draw_String(
|
||||
false, font16x32, Percent_Color, Color_Bg_Black,
|
||||
pb_left + (pb_width - dwin_string.length() * 16) / 2,
|
||||
pb_top + (pb_height - 32) / 2,
|
||||
S(dwin_string.string())
|
||||
);
|
||||
#endif
|
||||
|
||||
old_solid = pb_solid;
|
||||
}
|
||||
|
||||
//
|
||||
// Status Message
|
||||
//
|
||||
draw_status_message(blink);
|
||||
|
||||
ui.did_first_redraw = true;
|
||||
}
|
||||
|
||||
#endif // IS_DWIN_MARLINUI
|
Reference in New Issue
Block a user