diff --git a/.github/workflows/test-builds.yml b/.github/workflows/test-builds.yml index f7ba348cc0..0030dceb2a 100644 --- a/.github/workflows/test-builds.yml +++ b/.github/workflows/test-builds.yml @@ -39,6 +39,7 @@ jobs: - esp32 - linux_native - mega2560 + - at90usb1286_dfu - teensy31 - teensy35 - teensy41 @@ -95,7 +96,6 @@ jobs: # Non-working environment tests #- at90usb1286_cdc - #- at90usb1286_dfu #- STM32F103CB_malyan #- mks_robin_mini diff --git a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp index ea2936359d..db5e82ec55 100644 --- a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp +++ b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp @@ -84,7 +84,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { card.getSd2Card().readData(sector_buf); // RAM -> USB - if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) { + if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) { card.getSd2Card().readStop(); return CTRL_FAIL; } @@ -120,7 +120,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) { while (nb_sector--) { // USB -> RAM - if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) { + if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) { card.getSd2Card().writeStop(); return CTRL_FAIL; } diff --git a/Marlin/src/HAL/ESP32/i2s.cpp b/Marlin/src/HAL/ESP32/i2s.cpp index 99b2f755e5..e8f3806543 100644 --- a/Marlin/src/HAL/ESP32/i2s.cpp +++ b/Marlin/src/HAL/ESP32/i2s.cpp @@ -184,7 +184,7 @@ int i2s_init() { // Allocate the array of pointers to the buffers dma.buffers = (uint32_t **)malloc(sizeof(uint32_t*) * DMA_BUF_COUNT); - if (dma.buffers == nullptr) return -1; + if (!dma.buffers) return -1; // Allocate each buffer that can be used by the DMA controller for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) { @@ -194,7 +194,7 @@ int i2s_init() { // Allocate the array of DMA descriptors dma.desc = (lldesc_t**) malloc(sizeof(lldesc_t*) * DMA_BUF_COUNT); - if (dma.desc == nullptr) return -1; + if (!dma.desc) return -1; // Allocate each DMA descriptor that will be used by the DMA controller for (int buf_idx = 0; buf_idx < DMA_BUF_COUNT; buf_idx++) { diff --git a/Marlin/src/HAL/ESP32/timers.h b/Marlin/src/HAL/ESP32/timers.h index d722670f33..7d35186b1c 100644 --- a/Marlin/src/HAL/ESP32/timers.h +++ b/Marlin/src/HAL/ESP32/timers.h @@ -24,15 +24,9 @@ #include #include -// Includes needed to get I2S_STEPPER_STREAM. Note that pins.h -// is included in case this header is being included early. -#include "../../inc/MarlinConfig.h" -#include "../../pins/pins.h" - // ------------------------ // Defines // ------------------------ -// #define FORCE_INLINE __attribute__((always_inline)) inline typedef uint64_t hal_timer_t; diff --git a/Marlin/src/HAL/LINUX/HAL.h b/Marlin/src/HAL/LINUX/HAL.h index 2e545e03d6..1c8dbfd4dc 100644 --- a/Marlin/src/HAL/LINUX/HAL.h +++ b/Marlin/src/HAL/LINUX/HAL.h @@ -23,7 +23,7 @@ #define CPU_32_BIT -#define F_CPU 100000000 +#define F_CPU 100000000UL #define SystemCoreClock F_CPU #include #include diff --git a/Marlin/src/HAL/LINUX/eeprom.cpp b/Marlin/src/HAL/LINUX/eeprom.cpp index 967ca851ab..68fff9c433 100644 --- a/Marlin/src/HAL/LINUX/eeprom.cpp +++ b/Marlin/src/HAL/LINUX/eeprom.cpp @@ -40,7 +40,7 @@ size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; } bool PersistentStore::access_start() { const char eeprom_erase_value = 0xFF; FILE * eeprom_file = fopen(filename, "rb"); - if (eeprom_file == nullptr) return false; + if (!eeprom_file) return false; fseek(eeprom_file, 0L, SEEK_END); std::size_t file_size = ftell(eeprom_file); @@ -59,7 +59,7 @@ bool PersistentStore::access_start() { bool PersistentStore::access_finish() { FILE * eeprom_file = fopen(filename, "wb"); - if (eeprom_file == nullptr) return false; + if (!eeprom_file) return false; fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file); fclose(eeprom_file); return true; diff --git a/Marlin/src/HAL/LINUX/hardware/Gpio.h b/Marlin/src/HAL/LINUX/hardware/Gpio.h index 9255ec1dfc..2d9b1f29eb 100644 --- a/Marlin/src/HAL/LINUX/hardware/Gpio.h +++ b/Marlin/src/HAL/LINUX/hardware/Gpio.h @@ -86,10 +86,10 @@ public: GpioEvent::Type evt_type = value > 1 ? GpioEvent::SET_VALUE : value > pin_map[pin].value ? GpioEvent::RISE : value < pin_map[pin].value ? GpioEvent::FALL : GpioEvent::NOP; pin_map[pin].value = value; GpioEvent evt(Clock::nanos(), pin, evt_type); - if (pin_map[pin].cb != nullptr) { + if (pin_map[pin].cb) { pin_map[pin].cb->interrupt(evt); } - if (Gpio::logger != nullptr) Gpio::logger->log(evt); + if (Gpio::logger) Gpio::logger->log(evt); } static uint16_t get(pin_type pin) { @@ -105,8 +105,8 @@ public: if (!valid_pin(pin)) return; pin_map[pin].mode = value; GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM); - if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt); - if (Gpio::logger != nullptr) Gpio::logger->log(evt); + if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt); + if (Gpio::logger) Gpio::logger->log(evt); } static uint8_t getMode(pin_type pin) { @@ -118,8 +118,8 @@ public: if (!valid_pin(pin)) return; pin_map[pin].dir = value; GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD); - if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt); - if (Gpio::logger != nullptr) Gpio::logger->log(evt); + if (pin_map[pin].cb) pin_map[pin].cb->interrupt(evt); + if (Gpio::logger) Gpio::logger->log(evt); } static uint8_t getDir(pin_type pin) { diff --git a/Marlin/src/HAL/SAMD51/HAL.cpp b/Marlin/src/HAL/SAMD51/HAL.cpp index 9f24d30071..d985ef3787 100644 --- a/Marlin/src/HAL/SAMD51/HAL.cpp +++ b/Marlin/src/HAL/SAMD51/HAL.cpp @@ -300,7 +300,7 @@ uint16_t HAL_adc_result; DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE DMA_STEPSEL_SRC // STEPSEL ); - if (descriptor != nullptr) + if (descriptor) descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT; adc0DMAProgram.startJob(); } @@ -337,7 +337,7 @@ uint16_t HAL_adc_result; DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE DMA_STEPSEL_SRC // STEPSEL ); - if (descriptor != nullptr) + if (descriptor) descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT; adc1DMAProgram.startJob(); } diff --git a/Marlin/src/HAL/SAMD51/QSPIFlash.cpp b/Marlin/src/HAL/SAMD51/QSPIFlash.cpp index 307eb3fd45..fc21a1ad8c 100644 --- a/Marlin/src/HAL/SAMD51/QSPIFlash.cpp +++ b/Marlin/src/HAL/SAMD51/QSPIFlash.cpp @@ -35,10 +35,10 @@ uint8_t QSPIFlash::_buf[SFLASH_SECTOR_SIZE]; uint32_t QSPIFlash::_addr = INVALID_ADDR; void QSPIFlash::begin() { - if (_flashBase != nullptr) return; + if (_flashBase) return; _flashBase = new Adafruit_SPIFlashBase(new Adafruit_FlashTransport_QSPI()); - _flashBase->begin(NULL); + _flashBase->begin(nullptr); } size_t QSPIFlash::size() { diff --git a/Marlin/src/HAL/STM32/tft/xpt2046.cpp b/Marlin/src/HAL/STM32/tft/xpt2046.cpp index 921e377a9f..8c8d28f66a 100644 --- a/Marlin/src/HAL/STM32/tft/xpt2046.cpp +++ b/Marlin/src/HAL/STM32/tft/xpt2046.cpp @@ -99,7 +99,7 @@ void XPT2046::Init() { #endif } else { - SPIx.Instance = NULL; + SPIx.Instance = nullptr; SET_INPUT(TOUCH_MISO_PIN); SET_OUTPUT(TOUCH_MOSI_PIN); SET_OUTPUT(TOUCH_SCK_PIN); diff --git a/Marlin/src/HAL/STM32/timers.cpp b/Marlin/src/HAL/STM32/timers.cpp index c0ba19abe5..b708c4bdab 100644 --- a/Marlin/src/HAL/STM32/timers.cpp +++ b/Marlin/src/HAL/STM32/timers.cpp @@ -109,7 +109,7 @@ // Private Variables // ------------------------ -HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL }; +HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { nullptr }; // ------------------------ // Public functions diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index c10dea0eaf..eaf6494dfa 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -124,7 +124,7 @@ void HAL_idletask(); #endif #ifndef digitalPinHasPWM - #define digitalPinHasPWM(P) (PIN_MAP[P].timer_device != nullptr) + #define digitalPinHasPWM(P) !!PIN_MAP[P].timer_device #define NO_COMPILE_TIME_PWM #endif diff --git a/Marlin/src/HAL/STM32F1/SPI.cpp b/Marlin/src/HAL/STM32F1/SPI.cpp index 0452cf6293..ef00b407a8 100644 --- a/Marlin/src/HAL/STM32F1/SPI.cpp +++ b/Marlin/src/HAL/STM32F1/SPI.cpp @@ -656,7 +656,7 @@ static const spi_pins* dev_to_spi_pins(spi_dev *dev) { #if BOARD_NR_SPI >= 3 case RCC_SPI3: return board_spi_pins + 2; #endif - default: return NULL; + default: return nullptr; } } diff --git a/Marlin/src/HAL/STM32F1/fastio.h b/Marlin/src/HAL/STM32F1/fastio.h index e0e2e03a1c..a618fccc57 100644 --- a/Marlin/src/HAL/STM32F1/fastio.h +++ b/Marlin/src/HAL/STM32F1/fastio.h @@ -51,7 +51,7 @@ #define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD) #define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP || _GET_MODE(IO) == GPIO_OUTPUT_OD) -#define PWM_PIN(IO) (PIN_MAP[IO].timer_device != nullptr) +#define PWM_PIN(IO) !!PIN_MAP[IO].timer_device // digitalRead/Write wrappers #define extDigitalRead(IO) digitalRead(IO) diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h index d98e960848..a48f3f79cf 100644 --- a/Marlin/src/HAL/shared/Delay.h +++ b/Marlin/src/HAL/shared/Delay.h @@ -155,7 +155,7 @@ #endif // Delay in nanoseconds -#define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU / 1000000UL) / 1000UL ) +#define DELAY_NS(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL) / 1000UL) // Delay in microseconds -#define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU / 1000000UL) ) +#define DELAY_US(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL)) diff --git a/Marlin/src/feature/caselight.cpp b/Marlin/src/feature/caselight.cpp index 8a128bb12d..0eba102a04 100644 --- a/Marlin/src/feature/caselight.cpp +++ b/Marlin/src/feature/caselight.cpp @@ -28,7 +28,14 @@ CaseLight caselight; -uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS; +#if CASELIGHT_USES_BRIGHTNESS && !defined(CASE_LIGHT_DEFAULT_BRIGHTNESS) + #define CASE_LIGHT_DEFAULT_BRIGHTNESS 0 // For use on PWM pin as non-PWM just sets a default +#endif + +#if CASELIGHT_USES_BRIGHTNESS + uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS; +#endif + bool CaseLight::on = CASE_LIGHT_DEFAULT_ON; #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) @@ -46,21 +53,21 @@ bool CaseLight::on = CASE_LIGHT_DEFAULT_ON; #endif void CaseLight::update(const bool sflag) { - /** - * The brightness_sav (and sflag) is needed because ARM chips ignore - * a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly - * controlled by the PWM module. In order to turn them off the brightness - * level needs to be set to OFF. Since we can't use the PWM register to - * save the last brightness level we need a variable to save it. - */ - static uint8_t brightness_sav; // Save brightness info for restore on "M355 S1" + #if CASELIGHT_USES_BRIGHTNESS + /** + * The brightness_sav (and sflag) is needed because ARM chips ignore + * a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly + * controlled by the PWM module. In order to turn them off the brightness + * level needs to be set to OFF. Since we can't use the PWM register to + * save the last brightness level we need a variable to save it. + */ + static uint8_t brightness_sav; // Save brightness info for restore on "M355 S1" - if (on || !sflag) - brightness_sav = brightness; // Save brightness except for M355 S0 - if (sflag && on) - brightness = brightness_sav; // Restore last brightness for M355 S1 + if (on || !sflag) + brightness_sav = brightness; // Save brightness except for M355 S0 + if (sflag && on) + brightness = brightness_sav; // Restore last brightness for M355 S1 - #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS) const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i; #endif @@ -73,7 +80,7 @@ void CaseLight::update(const bool sflag) { #else // !CASE_LIGHT_USE_NEOPIXEL - #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) + #if CASELIGHT_USES_BRIGHTNESS if (PWM_PIN(CASE_LIGHT_PIN)) analogWrite(pin_t(CASE_LIGHT_PIN), ( #if CASE_LIGHT_MAX_PWM == 255 diff --git a/Marlin/src/feature/caselight.h b/Marlin/src/feature/caselight.h index 9d1e76da26..2198c85f2a 100644 --- a/Marlin/src/feature/caselight.h +++ b/Marlin/src/feature/caselight.h @@ -27,9 +27,15 @@ #include "leds/leds.h" #endif +#if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) || ENABLED(CASE_LIGHT_USE_NEOPIXEL) + #define CASELIGHT_USES_BRIGHTNESS 1 +#endif + class CaseLight { public: - static uint8_t brightness; + #if CASELIGHT_USES_BRIGHTNESS + static uint8_t brightness; + #endif static bool on; static void update(const bool sflag); diff --git a/Marlin/src/feature/password/password.h b/Marlin/src/feature/password/password.h index 3c223b6a82..97c3174557 100644 --- a/Marlin/src/feature/password/password.h +++ b/Marlin/src/feature/password/password.h @@ -31,10 +31,10 @@ public: Password() { is_locked = false; } static void lock_machine(); + static void authentication_check(); #if HAS_LCD_MENU static void access_menu_password(); - static void authentication_check(); static void authentication_done(); static void media_gatekeeper(); diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index 187cfda483..b21b89f68b 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -103,9 +103,11 @@ class TMCMarlin : public TMC, public TMCStorage { inline uint16_t get_microstep_counter() { return TMC::MSCNT(); } #if HAS_STEALTHCHOP - inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); } - inline bool get_stealthChop_status() { return this->en_pwm_mode(); } - inline bool get_stored_stealthChop_status() { return this->stored.stealthChop_enabled; } + inline bool get_stealthChop() { return this->en_pwm_mode(); } + inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); } + inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); } + inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); } #endif #if ENABLED(HYBRID_THRESHOLD) @@ -170,9 +172,11 @@ class TMCMarlin : public TMC220 inline uint16_t get_microstep_counter() { return TMC2208Stepper::MSCNT(); } #if HAS_STEALTHCHOP - inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } - inline bool get_stealthChop_status() { return !this->en_spreadCycle(); } - inline bool get_stored_stealthChop_status() { return this->stored.stealthChop_enabled; } + inline bool get_stealthChop() { return !this->en_spreadCycle(); } + inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); } + inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); } + inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); } #endif #if ENABLED(HYBRID_THRESHOLD) @@ -216,9 +220,11 @@ class TMCMarlin : public TMC220 inline uint16_t get_microstep_counter() { return TMC2209Stepper::MSCNT(); } #if HAS_STEALTHCHOP - inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); } - inline bool get_stealthChop_status() { return !this->en_spreadCycle(); } - inline bool get_stored_stealthChop_status() { return this->stored.stealthChop_enabled; } + inline bool get_stealthChop() { return !this->en_spreadCycle(); } + inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; } + inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); } + inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); } + inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); } #endif #if ENABLED(HYBRID_THRESHOLD) diff --git a/Marlin/src/gcode/feature/caselight/M355.cpp b/Marlin/src/gcode/feature/caselight/M355.cpp index bb6b57f666..12ae5cff1d 100644 --- a/Marlin/src/gcode/feature/caselight/M355.cpp +++ b/Marlin/src/gcode/feature/caselight/M355.cpp @@ -41,10 +41,12 @@ */ void GcodeSuite::M355() { bool didset = false; - if (parser.seenval('P')) { - didset = true; - caselight.brightness = parser.value_byte(); - } + #if CASELIGHT_USES_BRIGHTNESS + if (parser.seenval('P')) { + didset = true; + caselight.brightness = parser.value_byte(); + } + #endif const bool sflag = parser.seenval('S'); if (sflag) { didset = true; @@ -58,8 +60,13 @@ void GcodeSuite::M355() { if (!caselight.on) SERIAL_ECHOLNPGM(STR_OFF); else { - if (!PWM_PIN(CASE_LIGHT_PIN)) SERIAL_ECHOLNPGM(STR_ON); - else SERIAL_ECHOLN(int(caselight.brightness)); + #if CASELIGHT_USES_BRIGHTNESS + if (PWM_PIN(CASE_LIGHT_PIN)) { + SERIAL_ECHOLN(int(caselight.brightness)); + return; + } + #endif + SERIAL_ECHOLNPGM(STR_ON); } } diff --git a/Marlin/src/gcode/feature/trinamic/M569.cpp b/Marlin/src/gcode/feature/trinamic/M569.cpp index e72d03e767..6b379f1190 100644 --- a/Marlin/src/gcode/feature/trinamic/M569.cpp +++ b/Marlin/src/gcode/feature/trinamic/M569.cpp @@ -32,7 +32,7 @@ template void tmc_say_stealth_status(TMC &st) { st.printLabel(); SERIAL_ECHOPGM(" driver mode:\t"); - serialprintPGM(st.get_stealthChop_status() ? PSTR("stealthChop") : PSTR("spreadCycle")); + serialprintPGM(st.get_stealthChop() ? PSTR("stealthChop") : PSTR("spreadCycle")); SERIAL_EOL(); } template diff --git a/Marlin/src/gcode/gcode_d.cpp b/Marlin/src/gcode/gcode_d.cpp index 99968b625a..2fd03144c5 100644 --- a/Marlin/src/gcode/gcode_d.cpp +++ b/Marlin/src/gcode/gcode_d.cpp @@ -181,7 +181,7 @@ // Use a low-level delay that does not rely on interrupts to function // Do not spin forever, to avoid thermal risks if heaters are enabled and // watchdog does not work. - DELAY_US(10000000); + for (int i = 10000; i--;) DELAY_US(1000UL); ENABLE_ISRS(); SERIAL_ECHOLNPGM("FAILURE: Watchdog did not trigger board reset."); } diff --git a/Marlin/src/gcode/host/M115.cpp b/Marlin/src/gcode/host/M115.cpp index 53c5163bba..529b1dd6d0 100644 --- a/Marlin/src/gcode/host/M115.cpp +++ b/Marlin/src/gcode/host/M115.cpp @@ -27,6 +27,10 @@ #include "../../module/motion.h" #endif +#if ENABLED(CASE_LIGHT_ENABLE) + #include "../../feature/caselight.h" +#endif + #if ENABLED(EXTENDED_CAPABILITIES_REPORT) static void cap_line(PGM_P const name, bool ena=false) { SERIAL_ECHOPGM("Cap:"); @@ -102,7 +106,7 @@ void GcodeSuite::M115() { // TOGGLE_LIGHTS (M355) cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE)); - cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, PWM_PIN(CASE_LIGHT_PIN))); + cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, TERN0(CASELIGHT_USES_BRIGHTNESS, TERN(CASE_LIGHT_USE_NEOPIXEL, true, PWM_PIN(CASE_LIGHT_PIN))))); // EMERGENCY_PARSER (M108, M112, M410, M876) cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER)); diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 42b85ca271..17fb084388 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -245,7 +245,7 @@ public: #endif // The code value pointer was set - FORCE_INLINE static bool has_value() { return value_ptr != nullptr; } + FORCE_INLINE static bool has_value() { return !!value_ptr; } // Seen a parameter with a value static inline bool seenval(const char c) { return seen(c) && has_value(); } diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index 6139e3e2b8..f481052cbf 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -180,7 +180,7 @@ bool GCodeQueue::enqueue_one(const char* cmd) { * Return 'true' if any commands were processed. */ bool GCodeQueue::process_injected_command_P() { - if (injected_commands_P == nullptr) return false; + if (!injected_commands_P) return false; char c; size_t i = 0; @@ -480,7 +480,7 @@ void GCodeQueue::get_serial_commands() { if (npos) { - bool M110 = strstr_P(command, PSTR("M110")) != nullptr; + const bool M110 = !!strstr_P(command, PSTR("M110")); if (M110) { char* n2pos = strchr(command + 4, 'N'); diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 9c3407074f..2a85c02428 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2020-10-22" + #define STRING_DISTRIBUTION_DATE "2020-10-27" #endif /** diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 3c7993e375..4b82458398 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -1036,7 +1036,7 @@ void MarlinUI::draw_status_screen() { void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { ui.encoder_direction_normal(); uint8_t n = lcd_put_u8str_ind_P(0, 1, pstr, itemIndex, itemString, LCD_WIDTH - 1); - if (value != nullptr) { + if (value) { lcd_put_wchar(':'); n--; const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space const lcd_uint_t valrow = n < len ? 2 : 1; // Value on the next row if it won't fit diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 83ebe111ae..c21c2ceb58 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() { lcd.setCursor(0, MIDDLE_Y); lcd.write(COLOR_EDIT); lcd_put_u8str_P(pstr); - if (value != nullptr) { + if (value) { lcd.write(':'); lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces lcd.write(' '); // Overwrite char if value gets shorter diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 53a20476e9..0aba49d564 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -423,7 +423,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop if (onpage) lcd_put_u8str_ind_P(0, baseline, pstr, itemIndex, itemString); // If a value is included, print a colon, then print the value right-justified - if (value != nullptr) { + if (value) { lcd_put_wchar(':'); if (extra_row) { // Assume that value is numeric (with no descender) diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index 2599b1ad22..106c18cf06 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -346,7 +346,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u switch (msg) { case U8G_DEV_MSG_INIT: - dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL); + dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr); tftio.Init(); tftio.InitTFT(); diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp index 109d82b2a2..a1d1217d6e 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp @@ -40,6 +40,7 @@ #include "../../../../sd/cardreader.h" #include "../../../../libs/numtostr.h" #include "../../../../MarlinCore.h" + namespace Anycubic { printer_state_t ChironTFT::printer_state; @@ -87,7 +88,7 @@ namespace Anycubic { // Enable levelling and Disable end stops during print // as Z home places nozzle above the bed so we need to allow it past the end stops - injectCommands_P(AC_cmnd_enable_levelling); //M211 S0\n")); + injectCommands_P(AC_cmnd_enable_levelling); // Startup tunes are defined in Tunes.h //PlayTune(BEEPER_PIN, Anycubic_PowerOn, 1); @@ -179,7 +180,7 @@ namespace Anycubic { #endif switch (printer_state) { case AC_printer_pausing: { - if ( (strcmp_P(msg, MARLIN_msg_print_paused) == 0 ) || (strcmp_P(msg, MARLIN_msg_nozzle_parked) == 0 ) ) { + if (strcmp_P(msg, MARLIN_msg_print_paused) == 0 || strcmp_P(msg, MARLIN_msg_nozzle_parked) == 0) { SendtoTFTLN(AC_msg_paused); // enable continue button printer_state = AC_printer_paused; } @@ -189,18 +190,18 @@ namespace Anycubic { case AC_printer_printing: case AC_printer_paused: { // Heater timout, send acknowledgement - if (strcmp_P(msg, MARLIN_msg_heater_timeout) == 0 ) { + if (strcmp_P(msg, MARLIN_msg_heater_timeout) == 0) { pause_state = AC_paused_heater_timed_out; SendtoTFTLN(AC_msg_paused); // enable continue button PlayTune(BEEPER_PIN,Heater_Timedout,1); } // Reheat finished, send acknowledgement - else if (strcmp_P(msg, MARLIN_msg_reheat_done) == 0 ) { + else if (strcmp_P(msg, MARLIN_msg_reheat_done) == 0) { pause_state = AC_paused_idle; SendtoTFTLN(AC_msg_paused); // enable continue button } // Filament Purging, send acknowledgement enter run mode - else if (strcmp_P(msg, MARLIN_msg_filament_purging) == 0 ) { + else if (strcmp_P(msg, MARLIN_msg_filament_purging) == 0) { pause_state = AC_paused_purging_filament; SendtoTFTLN(AC_msg_paused); // enable continue button } @@ -221,14 +222,15 @@ namespace Anycubic { switch (printer_state) { case AC_printer_probing: { // If probing completes ok save the mesh and park - if (strcmp_P(msg, MARLIN_msg_ready) == 0 ) { + // Ignore the custom machine name + if (strcmp_P(msg + strlen(CUSTOM_MACHINE_NAME), MARLIN_msg_ready) == 0) { injectCommands_P(PSTR("M500\nG27")); SendtoTFTLN(AC_msg_probing_complete); printer_state = AC_printer_idle; msg_matched = true; } // If probing fails dont save the mesh raise the probe above the bad point - if (strcmp_P(msg, MARLIN_msg_probing_failed) == 0 ) { + if (strcmp_P(msg, MARLIN_msg_probing_failed) == 0) { PlayTune(BEEPER_PIN, BeepBeepBeeep, 1); injectCommands_P(PSTR("G1 Z50 F500")); SendtoTFTLN(AC_msg_probing_complete); @@ -238,14 +240,14 @@ namespace Anycubic { } break; case AC_printer_printing: { - if (strcmp_P(msg, MARLIN_msg_reheating) == 0 ) { + if (strcmp_P(msg, MARLIN_msg_reheating) == 0) { SendtoTFTLN(AC_msg_paused); // enable continue button msg_matched = true; } } break; case AC_printer_pausing: { - if (strcmp_P(msg, MARLIN_msg_print_paused) == 0 ) { + if (strcmp_P(msg, MARLIN_msg_print_paused) == 0) { SendtoTFTLN(AC_msg_paused); printer_state = AC_printer_paused; pause_state = AC_paused_idle; @@ -254,7 +256,7 @@ namespace Anycubic { } break; case AC_printer_stopping: { - if (strcmp_P(msg, MARLIN_msg_print_aborted) == 0 ) { + if (strcmp_P(msg, MARLIN_msg_print_aborted) == 0) { SendtoTFTLN(AC_msg_stop); printer_state = AC_printer_idle; msg_matched = true; @@ -289,10 +291,10 @@ namespace Anycubic { serialprintPGM(str); #endif while (const char c = pgm_read_byte(str++)) TFTSer.print(c); - } + } void ChironTFT::SendtoTFTLN(PGM_P str = nullptr) { - if (str != nullptr) { + if (str) { #if ACDEBUG(AC_SOME) SERIAL_ECHOPGM("> "); #endif @@ -300,22 +302,22 @@ namespace Anycubic { #if ACDEBUG(AC_SOME) SERIAL_EOL(); #endif - } - TFTSer.println(""); + } + TFTSer.println(""); } bool ChironTFT::ReadTFTCommand() { bool command_ready = false; - while( (TFTSer.available() > 0) && (command_len < MAX_CMND_LEN) ) { + while(TFTSer.available() > 0 && command_len < MAX_CMND_LEN) { panel_command[command_len] = TFTSer.read(); - if(panel_command[command_len] == '\n') { + if (panel_command[command_len] == '\n') { command_ready = true; break; } command_len++; } - if(command_ready) { + if (command_ready) { panel_command[command_len] = 0x00; #if ACDEBUG(AC_ALL) SERIAL_ECHOLNPAIR("< ", panel_command); @@ -333,56 +335,45 @@ namespace Anycubic { } int8_t ChironTFT::Findcmndpos(const char * buff, char q) { - bool found = false; int8_t pos = 0; - do { - if (buff[pos] == q) { - found = true; - break; - } - pos ++; - } while(pos < MAX_CMND_LEN); - if (found) return pos; + do { if (buff[pos] == q) return pos; } while(++pos < MAX_CMND_LEN); return -1; } void ChironTFT::CheckHeaters() { - uint8_t faultDuration = 0; float temp = 0; + uint8_t faultDuration = 0; + float temp = 0; // if the hotend temp is abnormal, confirm state before signalling panel temp = getActualTemp_celsius(E0); - if ( (temp <= HEATER_0_MINTEMP) || (temp >= HEATER_0_MAXTEMP) ) { - do { - faultDuration ++; - if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { - SendtoTFTLN(AC_msg_nozzle_temp_abnormal); - SERIAL_ECHOLNPAIR("Extruder temp abnormal! : ", temp); - break; - } - delay_ms(500); - temp = getActualTemp_celsius(E0); - } while ((temp <= HEATER_0_MINTEMP) || (temp >= HEATER_0_MAXTEMP) ); + while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) { + faultDuration++; + if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { + SendtoTFTLN(AC_msg_nozzle_temp_abnormal); + SERIAL_ECHOLNPAIR("Extruder temp abnormal! : ", temp); + break; + } + delay_ms(500); + temp = getActualTemp_celsius(E0); } - // if the hotbed temp is abnormal, confirm state before signalling panel + // If the hotbed temp is abnormal, confirm state before signaling panel faultDuration = 0; temp = getActualTemp_celsius(BED); - if ( (temp <= BED_MINTEMP) || (temp >= BED_MAXTEMP) ) { - do { - faultDuration ++; - if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { - SendtoTFTLN(AC_msg_nozzle_temp_abnormal); - SERIAL_ECHOLNPAIR_P("Bed temp abnormal! : ", temp); + while (!WITHIN(temp, BED_MINTEMP, BED_MAXTEMP)) { + faultDuration++; + if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) { + SendtoTFTLN(AC_msg_nozzle_temp_abnormal); + SERIAL_ECHOLNPAIR_P("Bed temp abnormal! : ", temp); break; - } - delay_ms(500); - temp = getActualTemp_celsius(E0); - } while ((temp <= BED_MINTEMP) || (temp >= BED_MAXTEMP) ); + } + delay_ms(500); + temp = getActualTemp_celsius(E0); } // Update panel with hotend heater status if (hotend_state != AC_heater_temp_reached) { - if ( WITHIN( getActualTemp_celsius(E0) - getTargetTemp_celsius(E0), -1, 1 ) ) { + if (WITHIN(getActualTemp_celsius(E0) - getTargetTemp_celsius(E0), -1, 1)) { SendtoTFTLN(AC_msg_nozzle_heating_done); hotend_state = AC_heater_temp_reached; } @@ -390,7 +381,7 @@ namespace Anycubic { // Update panel with bed heater status if (hotbed_state != AC_heater_temp_reached) { - if ( WITHIN( getActualTemp_celsius(BED) - getTargetTemp_celsius(BED), -0.5, 0.5 ) ) { + if (WITHIN(getActualTemp_celsius(BED) - getTargetTemp_celsius(BED), -0.5, 0.5)) { SendtoTFTLN(AC_msg_bed_heating_done); hotbed_state = AC_heater_temp_reached; } @@ -398,7 +389,7 @@ namespace Anycubic { } void ChironTFT::SendFileList(int8_t startindex) { - // respond to panel request for 4 files starting at index + // Respond to panel request for 4 files starting at index #if ACDEBUG(AC_INFO) SERIAL_ECHOLNPAIR("## SendFileList ## ", startindex); #endif @@ -408,8 +399,8 @@ namespace Anycubic { } void ChironTFT::SelectFile() { - strncpy(selectedfile,panel_command+4,command_len-4); - selectedfile[command_len-5] = '\0'; + strncpy(selectedfile, panel_command + 4, command_len - 4); + selectedfile[command_len - 5] = '\0'; #if ACDEBUG(AC_FILE) SERIAL_ECHOLNPAIR_F(" Selected File: ",selectedfile); #endif @@ -493,7 +484,6 @@ namespace Anycubic { if (isPrintingFromMedia()) { SendtoTFT(PSTR("A6V ")); TFTSer.println(ui8tostr2(getProgress_percent())); - } else SendtoTFTLN(PSTR("A6V ---")); @@ -552,7 +542,7 @@ namespace Anycubic { } else { if (printer_state == AC_printer_resuming_from_power_outage) - injectCommands_P(PSTR("M1000 C\n")); // Cancel recovery + injectCommands_P(PSTR("M1000 C")); // Cancel recovery SendtoTFTLN(AC_msg_stop); printer_state = AC_printer_idle; } @@ -569,7 +559,7 @@ namespace Anycubic { case 14: { // A14 Start Printing // Allows printer to restart the job if we dont want to recover if (printer_state == AC_printer_resuming_from_power_outage) { - injectCommands_P(PSTR("M1000 C\n")); // Cancel recovery + injectCommands_P(PSTR("M1000 C")); // Cancel recovery printer_state = AC_printer_idle; } #if ACDebugLevel >= 1 @@ -587,8 +577,7 @@ namespace Anycubic { if (printer_state == AC_printer_resuming_from_power_outage) // Need to home here to restore the Z position injectCommands_P(AC_cmnd_power_loss_recovery); - - injectCommands_P(PSTR("M1000\n")); // home and start recovery + injectCommands_P(PSTR("M1000")); // home and start recovery break; case 16: { // A16 Set HotEnd temp A17 S170 @@ -631,10 +620,10 @@ namespace Anycubic { case 21: // A21 Home Axis A21 X if (!isPrinting()) { switch ((char)panel_command[4]) { - case 'X': injectCommands_P(PSTR("G28 X\n")); break; - case 'Y': injectCommands_P(PSTR("G28 Y\n")); break; - case 'Z': injectCommands_P(PSTR("G28 Z\n")); break; - case 'C': injectCommands_P(PSTR("G28\n")); break; + case 'X': injectCommands_P(PSTR("G28 X")); break; + case 'Y': injectCommands_P(PSTR("G28 Y")); break; + case 'Z': injectCommands_P(PSTR("G28 Z")); break; + case 'C': injectCommands_P(PSTR("G28")); break; } } break; @@ -729,7 +718,7 @@ namespace Anycubic { // If the same meshpoint is selected twice in a row, move the head to that ready for adjustment if ((selectedmeshpoint.x == pos.x) && (selectedmeshpoint.y == pos.y)) { if (!isPositionKnown()) - injectCommands_P(PSTR("G28\n")); // home + injectCommands_P(PSTR("G28")); // home if (isPositionKnown()) { #if ACDEBUG(AC_INFO) @@ -769,17 +758,15 @@ namespace Anycubic { switch (panel_command[3]) { case 'C': // Restore and apply original offsets if (!isPrinting()) { - injectCommands_P(PSTR("M501\nM420 S1\n")); - selectedmeshpoint.x = 99; - selectedmeshpoint.y = 99; + injectCommands_P(PSTR("M501\nM420 S1")); + selectedmeshpoint.x = selectedmeshpoint.y = 99; } break; case 'D': // Save Z Offset tables and restore levelling state if (!isPrinting()) { setAxisPosition_mm(1.0,Z); - injectCommands_P(PSTR("M500\n")); - selectedmeshpoint.x = 99; - selectedmeshpoint.y = 99; + injectCommands_P(PSTR("M500")); + selectedmeshpoint.x = selectedmeshpoint.y = 99; } break; case 'G': // Get current offset @@ -790,8 +777,7 @@ namespace Anycubic { TFTSer.println(live_Zoffset); else { TFTSer.println(getZOffset_mm()); - selectedmeshpoint.x = 99; - selectedmeshpoint.y = 99; + selectedmeshpoint.x = selectedmeshpoint.y = 99; } break; case 'S': { // Set offset (adjusts all points by value) @@ -859,8 +845,7 @@ namespace Anycubic { case 34: { // A34 Adjust single mesh point A34 C/S X1 Y1 V123 if (panel_command[3] == 'C') { // Restore original offsets injectCommands_P(PSTR("M501\nM420 S1")); - selectedmeshpoint.x = 99; - selectedmeshpoint.y = 99; + selectedmeshpoint.x = selectedmeshpoint.y = 99; //printer_state = AC_printer_idle; } else { @@ -876,9 +861,10 @@ namespace Anycubic { #endif // Update Meshpoint setMeshPoint(pos,newval); - if ( (printer_state == AC_printer_idle) || (printer_state == AC_printer_probing) ) {//!isPrinting()) { - // if we are at the current mesh point indicated on the panel Move Z pos +/- 0.05mm ( The panel changes the mesh value by +/- 0.05mm on each button press) - if ((selectedmeshpoint.x == pos.x) && (selectedmeshpoint.y == pos.y)) { + if (printer_state == AC_printer_idle || printer_state == AC_printer_probing /*!isPrinting()*/) { + // if we are at the current mesh point indicated on the panel Move Z pos +/- 0.05mm + // (The panel changes the mesh value by +/- 0.05mm on each button press) + if (selectedmeshpoint.x == pos.x && selectedmeshpoint.y == pos.y) { setSoftEndstopState(false); float currZpos = getAxisPosition_mm(Z); #if ACDEBUG(AC_INFO) diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h index 937bdfde33..f5000611a7 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h @@ -88,7 +88,7 @@ #define MARLIN_msg_start_probing PSTR("Probing Point 1/25") #define MARLIN_msg_probing_failed PSTR("Probing Failed") -#define MARLIN_msg_ready PSTR("3D Printer Ready.") +#define MARLIN_msg_ready PSTR(" Ready.") #define MARLIN_msg_print_paused PSTR("Print Paused") #define MARLIN_msg_print_aborted PSTR("Print Aborted") #define MARLIN_msg_extruder_heating PSTR("E Heating...") diff --git a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp index efbc57e68a..2aaa0d0e33 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -218,12 +218,12 @@ void AnycubicTFTClass::OnUserConfirmRequired(const char * const msg) { } float AnycubicTFTClass::CodeValue() { - return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], NULL)); + return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], nullptr)); } bool AnycubicTFTClass::CodeSeen(char code) { TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code); - return (TFTstrchr_pointer != NULL); // Return True if a character was found + return !!TFTstrchr_pointer; // Return True if a character was found } bool AnycubicTFTClass::IsNozzleHomed() { @@ -536,7 +536,7 @@ void AnycubicTFTClass::OnPrintTimerStopped() { } void AnycubicTFTClass::GetCommandFromTFT() { - char *starpos = NULL; + char *starpos = nullptr; while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) { serial3_char = LCD_SERIAL.read(); if (serial3_char == '\n' || @@ -549,10 +549,10 @@ void AnycubicTFTClass::GetCommandFromTFT() { TFTcmdbuffer[TFTbufindw][serial3_count] = 0; // terminate string - if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL)) { + if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != nullptr)) { int16_t a_command; TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A'); - a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL)))); + a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], nullptr)))); #if ENABLED(ANYCUBIC_LCD_DEBUG) if ((a_command > 7) && (a_command != 20)) { // No debugging of status polls, please! @@ -682,8 +682,7 @@ void AnycubicTFTClass::GetCommandFromTFT() { else { SelectedDirectory[0] = 0; - if (starpos != NULL) - *(starpos - 1) = '\0'; + if (starpos) *(starpos - 1) = '\0'; strcpy(SelectedFile, TFTstrchr_pointer + 4); SENDLINE_DBG_PGM_VAL("J20", "TFT Serial Debug: File Selected... J20 ", SelectedFile); // J20 File Selected diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp index 09473c1c26..bee3f74cab 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp @@ -146,9 +146,9 @@ uint16_t FTDI::get_utf8_char_width(utf8_char_t c, font_size_t fs) { int x = 0, y = 0; #ifdef TOUCH_UI_UTF8_WESTERN_CHARSET - WesternCharSet::render_glyph(NULL, x, y, fs, c) || + WesternCharSet::render_glyph(nullptr, x, y, fs, c) || #endif - StandardCharSet::render_glyph(NULL, x, y, fs, c); + StandardCharSet::render_glyph(nullptr, x, y, fs, c); return x; } @@ -165,7 +165,7 @@ */ uint16_t FTDI::get_utf8_text_width(const char *str, font_size_t fs) { - return render_utf8_text(NULL, 0, 0, str, fs); + return render_utf8_text(nullptr, 0, 0, str, fs); } uint16_t FTDI::get_utf8_text_width(progmem_str pstr, font_size_t fs) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp index 3f57124451..11c5f816b0 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp @@ -183,10 +183,9 @@ void SPIFlashStorage::loadPage(uint8_t* buffer) { // Test env // char fname[256]; - // memset(buffer, 0, SPI_FLASH_PageSize); // snprintf(fname, sizeof(fname), "./pages/page-%03d.data", m_currentPage); // FILE *fp = fopen(fname, "rb"); - // if (fp != NULL) { + // if (fp) { // fread(buffer, 1, SPI_FLASH_PageSize, fp); // fclose(fp); // } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp index 68d1993b6f..34168574ec 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp @@ -32,86 +32,47 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * fw_type, *board; //*fw_version; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *fw_type, *board; //*fw_version; -#define ID_A_RETURN 1 +enum { ID_A_RETURN = 1 }; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_A_RETURN: - if (event == LV_EVENT_CLICKED) { - // do nothing - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_about(void) { - lv_obj_t *buttonBack, *label_Back; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ABOUT_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = ABOUT_UI; - } - disp_state = ABOUT_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(ABOUT_UI); // Create an Image button - buttonBack = lv_imgbtn_create(scr, NULL); - - #if 1 - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_A_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif + lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_A_RETURN); + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); #endif - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - // Create a label on the image button - label_Back = lv_label_create(buttonBack, NULL); + lv_obj_t *label_Back = lv_label_create_empty(buttonBack); if (gCfgItems.multiple_language) { lv_label_set_text(label_Back, common_menu.text_back); lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } - //fw_version = lv_label_create(scr, NULL); - //lv_obj_set_style(fw_version, &tft_style_label_rel); - //lv_label_set_text(fw_version, SHORT_BUILD_VERSION); - //lv_obj_align(fw_version, NULL, LV_ALIGN_CENTER, 0, -60); + //fw_version = lv_label_create(scr, SHORT_BUILD_VERSION); + //lv_obj_align(fw_version, nullptr, LV_ALIGN_CENTER, 0, -60); - fw_type = lv_label_create(scr, NULL); - lv_obj_set_style(fw_type, &tft_style_label_rel); - lv_label_set_text(fw_type, "Firmware: Marlin " SHORT_BUILD_VERSION); - lv_obj_align(fw_type, NULL, LV_ALIGN_CENTER, 0, -20); + fw_type = lv_label_create(scr, "Firmware: Marlin " SHORT_BUILD_VERSION); + lv_obj_align(fw_type, nullptr, LV_ALIGN_CENTER, 0, -20); - board = lv_label_create(scr, NULL); - lv_obj_set_style(board, &tft_style_label_rel); - lv_label_set_text(board, "Board: " BOARD_INFO_NAME); - lv_obj_align(board, NULL, LV_ALIGN_CENTER, 0, -60); + board = lv_label_create(scr, "Board: " BOARD_INFO_NAME); + lv_obj_align(board, nullptr, LV_ALIGN_CENTER, 0, -60); } void lv_clear_about() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp index e362e5bff1..ffb6f01579 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_acceleration_settings.cpp @@ -29,414 +29,119 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_ACCE_RETURN 1 -#define ID_ACCE_PRINT 2 -#define ID_ACCE_RETRA 3 -#define ID_ACCE_TRAVEL 4 -#define ID_ACCE_X 5 -#define ID_ACCE_Y 6 -#define ID_ACCE_Z 7 -#define ID_ACCE_E0 8 -#define ID_ACCE_E1 9 -#define ID_ACCE_UP 10 -#define ID_ACCE_DOWN 11 +enum { + ID_ACCE_RETURN = 1, + ID_ACCE_PRINT, + ID_ACCE_RETRA, + ID_ACCE_TRAVEL, + ID_ACCE_X, + ID_ACCE_Y, + ID_ACCE_Z, + ID_ACCE_E0, + ID_ACCE_E1, + ID_ACCE_UP, + ID_ACCE_DOWN +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_ACCE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_acceleration_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_acceleration_settings(); + draw_return_ui(); break; case ID_ACCE_PRINT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = PrintAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = PrintAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_RETRA: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = RetractAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = RetractAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_TRAVEL: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = TravelAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = TravelAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = XAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = XAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = YAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = YAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = ZAcceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = ZAcceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0Acceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = E0Acceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1Acceleration; - lv_clear_acceleration_settings(); - lv_draw_number_key(); - } + value = E1Acceleration; + lv_clear_acceleration_settings(); + lv_draw_number_key(); break; case ID_ACCE_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_acceleration_settings(); - lv_draw_acceleration_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_acceleration_settings(); + lv_draw_acceleration_settings(); break; case ID_ACCE_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_acceleration_settings(); - lv_draw_acceleration_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_acceleration_settings(); + lv_draw_acceleration_settings(); break; } } void lv_draw_acceleration_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *labelPrintText = NULL, *buttonPrintValue = NULL, *labelPrintValue = NULL; - lv_obj_t *labelRetraText = NULL, *buttonRetraValue = NULL, *labelRetraValue = NULL; - lv_obj_t *labelTravelText = NULL, *buttonTravelValue = NULL, *labelTravelValue = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *labelE0Text = NULL, *buttonE0Value = NULL, *labelE0Value = NULL; - lv_obj_t *labelE1Text = NULL, *buttonE1Value = NULL, *labelE1Value = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ACCELERATION_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = ACCELERATION_UI; - } - disp_state = ACCELERATION_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.AccelerationConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(ACCELERATION_UI, machine_menu.AccelerationConfTitle); if (uiCfg.para_ui_page != 1) { + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.acceleration); + lv_screen_menu_item_1_edit(scr, machine_menu.PrintAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_ACCE_PRINT, 0, public_buf_l); - labelPrintText = lv_label_create(scr, NULL); - lv_obj_set_style(labelPrintText, &tft_style_label_rel); - lv_obj_set_pos(labelPrintText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelPrintText, machine_menu.PrintAcceleration); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.retract_acceleration); + lv_screen_menu_item_1_edit(scr, machine_menu.RetractAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_ACCE_RETRA, 1, public_buf_l); - buttonPrintValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonPrintValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonPrintValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonPrintValue, event_handler, ID_ACCE_PRINT, NULL, 0); - lv_btn_set_style(buttonPrintValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonPrintValue, LV_BTN_STYLE_PR, &style_para_value); - labelPrintValue = lv_label_create(buttonPrintValue, NULL); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.travel_acceleration); + lv_screen_menu_item_1_edit(scr, machine_menu.TravelAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_ACCE_TRAVEL, 2, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_ACCE_X, 3, public_buf_l); - labelRetraText = lv_label_create(scr, NULL); - lv_obj_set_style(labelRetraText, &tft_style_label_rel); - lv_obj_set_pos(labelRetraText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelRetraText, machine_menu.RetractAcceleration); - - buttonRetraValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonRetraValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonRetraValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonRetraValue, event_handler, ID_ACCE_RETRA, NULL, 0); - lv_btn_set_style(buttonRetraValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonRetraValue, LV_BTN_STYLE_PR, &style_para_value); - labelRetraValue = lv_label_create(buttonRetraValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelTravelText = lv_label_create(scr, NULL); - lv_obj_set_style(labelTravelText, &tft_style_label_rel); - lv_obj_set_pos(labelTravelText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelTravelText, machine_menu.TravelAcceleration); - - buttonTravelValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonTravelValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonTravelValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonTravelValue, event_handler, ID_ACCE_TRAVEL, NULL, 0); - lv_btn_set_style(buttonTravelValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonTravelValue, LV_BTN_STYLE_PR, &style_para_value); - labelTravelValue = lv_label_create(buttonTravelValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelXText, machine_menu.X_Acceleration); - - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_ACCE_X, NULL, 0); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - labelXValue = lv_label_create(buttonXValue, NULL); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_ACCE_DOWN, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonPrintValue); - lv_group_add_obj(g, buttonRetraValue); - lv_group_add_obj(g, buttonTravelValue); - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_ACCE_DOWN, true); } else { - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelYText, machine_menu.Y_Acceleration); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_ACCE_Y, 0, public_buf_l); - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_ACCE_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - labelYValue = lv_label_create(buttonYValue, NULL); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_ACCE_Z, 1, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E0_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_ACCE_E0, 2, public_buf_l); - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelZText, machine_menu.Z_Acceleration); + sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(1)]); + lv_screen_menu_item_1_edit(scr, machine_menu.E1_Acceleration, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_ACCE_E1, 3, public_buf_l); - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_ACCE_Y, NULL, 0); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_ACCE_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - labelZValue = lv_label_create(buttonZValue, NULL); - - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelE0Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE0Text, &tft_style_label_rel); - lv_obj_set_pos(labelE0Text, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelE0Text, machine_menu.E0_Acceleration); - - buttonE0Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE0Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE0Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_ACCE_Y, NULL, 0); - lv_obj_set_event_cb_mks(buttonE0Value, event_handler, ID_ACCE_E0, NULL, 0); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_PR, &style_para_value); - labelE0Value = lv_label_create(buttonE0Value, NULL); - - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelE1Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE1Text, &tft_style_label_rel); - lv_obj_set_pos(labelE1Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelE1Text, machine_menu.E1_Acceleration); - - buttonE1Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE1Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE1Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_ACCE_Y, NULL, 0); - lv_obj_set_event_cb_mks(buttonE1Value, event_handler, ID_ACCE_E1, NULL, 0); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_PR, &style_para_value); - labelE1Value = lv_label_create(buttonE1Value, NULL); - - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_ACCE_UP, NULL, 0); - //lv_imgbtn_set_src(buttonTurnPage, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - //lv_imgbtn_set_src(buttonTurnPage, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - //lv_imgbtn_set_style(buttonTurnPage, LV_BTN_STATE_PR, &tft_style_label_pre); - //lv_imgbtn_set_style(buttonTurnPage, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_ACCE_UP, true); } - //lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - //lv_btn_set_layout(buttonTurnPage, LV_LAYOUT_OFF); - //labelTurnPage = lv_label_create(buttonTurnPage, NULL); - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create(buttonTurnPage, NULL); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_ACCE_RETURN, NULL, 0); - //lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - //lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - //lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - //lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create(buttonBack, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - //lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - //lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.acceleration); - lv_label_set_text(labelPrintValue, public_buf_l); - lv_obj_align(labelPrintValue, buttonPrintValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.retract_acceleration); - lv_label_set_text(labelRetraValue, public_buf_l); - lv_obj_align(labelRetraValue, buttonRetraValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.travel_acceleration); - lv_label_set_text(labelTravelValue, public_buf_l); - lv_obj_align(labelTravelValue, buttonTravelValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - } - else { - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS]); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), (int)planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(1)]); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_ACCE_RETURN, true); } void lv_clear_acceleration_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp index f81fe6c728..dd6e484921 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_advance_settings.cpp @@ -28,300 +28,62 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_ADVANCE_RETURN 1 -#define ID_PAUSE_POS 2 -#define ID_PAUSE_POS_ARROW 3 -#define ID_WIFI_PARA 4 -#define ID_WIFI_PARA_ARROW 5 -#define ID_FILAMENT_SETTINGS 6 -#define ID_FILAMENT_SETTINGS_ARROW 7 -#define ID_ENCODER_SETTINGS 8 -#define ID_ENCODER_SETTINGS_ARROW 9 +enum { + ID_ADVANCE_RETURN = 1, + ID_PAUSE_POS, + ID_WIFI_PARA, + ID_FILAMENT_SETTINGS, + ID_ENCODER_SETTINGS +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_ADVANCE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - draw_return_ui(); - } + lv_clear_advance_settings(); + draw_return_ui(); break; case ID_PAUSE_POS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_pause_position(); - } - break; - case ID_PAUSE_POS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_pause_position(); - } + lv_clear_advance_settings(); + lv_draw_pause_position(); break; case ID_FILAMENT_SETTINGS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_filament_settings(); - } - break; - case ID_FILAMENT_SETTINGS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_filament_settings(); - } + lv_clear_advance_settings(); + lv_draw_filament_settings(); break; #if ENABLED(USE_WIFI_FUNCTION) case ID_WIFI_PARA: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_wifi_settings(); - } - break; - case ID_WIFI_PARA_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_wifi_settings(); - } + lv_clear_advance_settings(); + lv_draw_wifi_settings(); break; #endif #if HAS_ROTARY_ENCODER case ID_ENCODER_SETTINGS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_encoder_settings(); - } - break; - case ID_ENCODER_SETTINGS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_advance_settings(); - lv_draw_encoder_settings(); - } + lv_clear_advance_settings(); + lv_draw_encoder_settings(); break; #endif } } void lv_draw_advance_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonPausePos, *labelPausePos, *buttonPausePosNarrow; - lv_obj_t *buttonFilamentSettings, *labelFilamentSettings, *buttonFilamentSettingsNarrow; - lv_obj_t * line1,* line2; + scr = lv_screen_create(ADVANCED_UI, machine_menu.AdvancedConfTitle); + + int index = 0; + lv_screen_menu_item(scr, machine_menu.PausePosition, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_PAUSE_POS, index++); + lv_screen_menu_item(scr, machine_menu.FilamentConf, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_FILAMENT_SETTINGS, index++); #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_t *buttonWifiSet,*labelWifiSet,*buttonWifiSetNarrow; + lv_screen_menu_item(scr, machine_menu.WifiSettings, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_WIFI_PARA, index++); #endif #if HAS_ROTARY_ENCODER - lv_obj_t *buttonEcoder,*labelEcoder,*buttonEcoderNarrow; + lv_screen_menu_item(scr, machine_menu.EncoderSettings, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_ENCODER_SETTINGS, index); + index++; #endif - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ADVANCED_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = ADVANCED_UI; - } - disp_state = ADVANCED_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.AdvancedConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonPausePos = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonPausePos, PARA_UI_POS_X, PARA_UI_POS_Y); - lv_obj_set_size(buttonPausePos, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonPausePos, event_handler, ID_PAUSE_POS, NULL, 0); - lv_btn_set_style(buttonPausePos, LV_BTN_STYLE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonPausePos, LV_BTN_STYLE_PR, &tft_style_label_pre); - lv_btn_set_layout(buttonPausePos, LV_LAYOUT_OFF); - labelPausePos = lv_label_create(buttonPausePos, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonPausePos); - #endif - - buttonPausePosNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonPausePosNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonPausePosNarrow, event_handler, ID_PAUSE_POS_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonPausePosNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonPausePosNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonPausePosNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPausePosNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonPausePosNarrow, LV_LAYOUT_OFF); - - line1 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line1, line_points[0]); - - buttonFilamentSettings = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonFilamentSettings, PARA_UI_POS_X, PARA_UI_POS_Y*2); - lv_obj_set_size(buttonFilamentSettings, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonFilamentSettings, event_handler, ID_FILAMENT_SETTINGS, NULL, 0); - lv_btn_set_style(buttonFilamentSettings, LV_BTN_STYLE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonFilamentSettings, LV_BTN_STYLE_PR, &tft_style_label_pre); - lv_btn_set_layout(buttonFilamentSettings, LV_LAYOUT_OFF); - labelFilamentSettings = lv_label_create(buttonFilamentSettings, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonFilamentSettings); - #endif - - buttonFilamentSettingsNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonFilamentSettingsNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y*2 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonFilamentSettingsNarrow, event_handler, ID_FILAMENT_SETTINGS_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonFilamentSettingsNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonFilamentSettingsNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonFilamentSettingsNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonFilamentSettingsNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonFilamentSettingsNarrow, LV_LAYOUT_OFF); - - line2 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line2, line_points[1]); - - #if ENABLED(USE_WIFI_FUNCTION) - - buttonWifiSet = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonWifiSet, PARA_UI_POS_X,PARA_UI_POS_Y*3); - lv_obj_set_size(buttonWifiSet, PARA_UI_SIZE_X,PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonWifiSet, event_handler,ID_WIFI_PARA,NULL,0); - lv_btn_set_style(buttonWifiSet, LV_BTN_STYLE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonWifiSet, LV_BTN_STYLE_PR, &tft_style_label_pre); - lv_btn_set_layout(buttonWifiSet, LV_LAYOUT_OFF); - labelWifiSet = lv_label_create(buttonWifiSet, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonWifiSet); - #endif - - buttonWifiSetNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonWifiSetNarrow,PARA_UI_POS_X+PARA_UI_SIZE_X,PARA_UI_POS_Y*3+PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonWifiSetNarrow, event_handler,ID_WIFI_PARA_ARROW, NULL,0); - lv_imgbtn_set_src(buttonWifiSetNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonWifiSetNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonWifiSetNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonWifiSetNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonWifiSetNarrow, LV_LAYOUT_OFF); - - lv_obj_t * line3 = lv_line_create(scr, NULL); - lv_ex_line(line3,line_points[2]); - - #if HAS_ROTARY_ENCODER - buttonEcoder = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonEcoder, PARA_UI_POS_X,PARA_UI_POS_Y*4); - lv_obj_set_size(buttonEcoder, PARA_UI_SIZE_X,PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonEcoder, event_handler,ID_ENCODER_SETTINGS,NULL,0); - lv_btn_set_style(buttonEcoder, LV_BTN_STYLE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonEcoder, LV_BTN_STYLE_PR, &tft_style_label_pre); - lv_btn_set_layout(buttonEcoder, LV_LAYOUT_OFF); - labelEcoder = lv_label_create(buttonEcoder, NULL); - - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonEcoder); - - buttonEcoderNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonEcoderNarrow,PARA_UI_POS_X+PARA_UI_SIZE_X,PARA_UI_POS_Y*4+PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonEcoderNarrow, event_handler,ID_ENCODER_SETTINGS_ARROW, NULL,0); - lv_imgbtn_set_src(buttonEcoderNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonEcoderNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonEcoderNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonEcoderNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonEcoderNarrow, LV_LAYOUT_OFF); - - lv_obj_t * line4 = lv_line_create(scr, NULL); - lv_ex_line(line4,line_points[3]); - #endif - - #elif HAS_ROTARY_ENCODER - buttonEcoder = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonEcoder, PARA_UI_POS_X,PARA_UI_POS_Y*3); - lv_obj_set_size(buttonEcoder, PARA_UI_SIZE_X,PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonEcoder, event_handler,ID_ENCODER_SETTINGS,NULL,0); - lv_btn_set_style(buttonEcoder, LV_BTN_STYLE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonEcoder, LV_BTN_STYLE_PR, &tft_style_label_pre); - lv_btn_set_layout(buttonEcoder, LV_LAYOUT_OFF); - labelEcoder = lv_label_create(buttonEcoder, NULL); - - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonEcoder); - - buttonEcoderNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonEcoderNarrow,PARA_UI_POS_X+PARA_UI_SIZE_X,PARA_UI_POS_Y*3+PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonEcoderNarrow, event_handler,ID_ENCODER_SETTINGS_ARROW, NULL,0); - lv_imgbtn_set_src(buttonEcoderNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonEcoderNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonEcoderNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonEcoderNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonEcoderNarrow, LV_LAYOUT_OFF); - - lv_obj_t * line3 = lv_line_create(scr, NULL); - lv_ex_line(line3,line_points[2]); - #endif - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_ADVANCE_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelPausePos, machine_menu.PausePosition); - lv_obj_align(labelPausePos, buttonPausePos, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelFilamentSettings, machine_menu.FilamentConf); - lv_obj_align(labelFilamentSettings, buttonFilamentSettings, LV_ALIGN_IN_LEFT_MID, 0, 0); - - #if ENABLED(USE_WIFI_FUNCTION) - lv_label_set_text(labelWifiSet, machine_menu.WifiSettings); - lv_obj_align(labelWifiSet, buttonWifiSet, LV_ALIGN_IN_LEFT_MID,0, 0); - #endif - #if HAS_ROTARY_ENCODER - lv_label_set_text(labelEcoder, machine_menu.EncoderSettings); - lv_obj_align(labelEcoder, buttonEcoder, LV_ALIGN_IN_LEFT_MID,0, 0); - #endif - } - + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_ADVANCE_RETURN, true); } void lv_clear_advance_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp index be2015ed9e..3b39debe57 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_auto_level_offset_settings.cpp @@ -29,167 +29,54 @@ #include "../../../../module/probe.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_OFFSET_RETURN 1 -#define ID_OFFSET_X 2 -#define ID_OFFSET_Y 3 -#define ID_OFFSET_Z 4 +enum { + ID_OFFSET_RETURN = 1, + ID_OFFSET_X, + ID_OFFSET_Y, + ID_OFFSET_Z +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_OFFSET_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_auto_level_offset_settings(); - draw_return_ui(); - } + lv_clear_auto_level_offset_settings(); + draw_return_ui(); break; case ID_OFFSET_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = x_offset; - lv_clear_auto_level_offset_settings(); - lv_draw_number_key(); - } + value = x_offset; + lv_clear_auto_level_offset_settings(); + lv_draw_number_key(); break; case ID_OFFSET_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = y_offset; - lv_clear_auto_level_offset_settings(); - lv_draw_number_key(); - } + value = y_offset; + lv_clear_auto_level_offset_settings(); + lv_draw_number_key(); break; case ID_OFFSET_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = z_offset; - lv_clear_auto_level_offset_settings(); - lv_draw_number_key(); - } + value = z_offset; + lv_clear_auto_level_offset_settings(); + lv_draw_number_key(); break; } } void lv_draw_auto_level_offset_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != NOZZLE_PROBE_OFFSET_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = NOZZLE_PROBE_OFFSET_UI; - } - disp_state = NOZZLE_PROBE_OFFSET_UI; + scr = lv_screen_create(NOZZLE_PROBE_OFFSET_UI, machine_menu.OffsetConfTitle); - scr = lv_obj_create(NULL, NULL); + sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.x, 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Xoffset, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_OFFSET_X, 0, public_buf_l); - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.y, 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Yoffset, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_OFFSET_Y, 1, public_buf_l); - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.OffsetConfTitle); + sprintf_P(public_buf_l, PSTR("%.1f"), probe.offset.z); + lv_screen_menu_item_1_edit(scr, machine_menu.Zoffset, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_OFFSET_Z, 2, public_buf_l); - lv_refr_now(lv_refr_get_disp_refreshing()); - - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelXText, machine_menu.Xoffset); - - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_OFFSET_X, NULL, 0); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - labelXValue = lv_label_create(buttonXValue, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelYText, machine_menu.Yoffset); - - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_OFFSET_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - labelYValue = lv_label_create(buttonYValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelZText, machine_menu.Zoffset); - - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_OFFSET_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - labelZValue = lv_label_create(buttonZValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_OFFSET_RETURN, NULL, 0); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create(buttonBack, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonBack); - } - #endif - - if (gCfgItems.multiple_language) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.x, 0)); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), TERN(HAS_PROBE_XY_OFFSET, probe.offset.y, 0)); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), probe.offset.z); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_OFFSET_RETURN, true); } void lv_clear_auto_level_offset_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp index 6891060274..5f489162b0 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_baby_stepping.cpp @@ -30,294 +30,120 @@ #include "../../../../gcode/gcode.h" #include "../../../../inc/MarlinConfig.h" +#if ENABLED(EEPROM_SETTINGS) + #include "../../../../module/settings.h" +#endif + #if HAS_BED_PROBE #include "../../../../module/probe.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -static lv_obj_t *labelV, *buttonV, * zOffsetText; +static lv_obj_t *labelV, *buttonV, *zOffsetText; -#define ID_BABY_STEP_X_P 1 -#define ID_BABY_STEP_X_N 2 -#define ID_BABY_STEP_Y_P 3 -#define ID_BABY_STEP_Y_N 4 -#define ID_BABY_STEP_Z_P 5 -#define ID_BABY_STEP_Z_N 6 -#define ID_BABY_STEP_DIST 7 -#define ID_BABY_STEP_RETURN 8 +enum { + ID_BABY_STEP_X_P = 1, + ID_BABY_STEP_X_N, + ID_BABY_STEP_Y_P, + ID_BABY_STEP_Y_N, + ID_BABY_STEP_Z_P, + ID_BABY_STEP_Z_N, + ID_BABY_STEP_DIST, + ID_BABY_STEP_RETURN +}; static float babystep_dist=0.01; static uint8_t has_adjust_z = 0; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; char baby_buf[30] = { 0 }; switch (obj->mks_obj_id) { case ID_BABY_STEP_X_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - ZERO(baby_buf); - sprintf_P(baby_buf, PSTR("M290 X%.3f"),babystep_dist); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 X%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_X_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - ZERO(baby_buf); - sprintf_P(baby_buf, PSTR("M290 X%.3f"),((float)0 - babystep_dist)); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 X%.3f"), -babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Y_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - ZERO(baby_buf); - sprintf_P(baby_buf, PSTR("M290 Y%.3f"), babystep_dist); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Y%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Y_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - ZERO(baby_buf); - sprintf_P(baby_buf, PSTR("M290 Y%.3f"),((float)0 - babystep_dist)); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Y%.3f"), -babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Z_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - ZERO(baby_buf); - sprintf_P(baby_buf, PSTR("M290 Z%.3f"), babystep_dist); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Z%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_Z_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - ZERO(baby_buf); - sprintf_P(baby_buf, PSTR("M290 Z%.3f"),((float)0 - babystep_dist)); - gcode.process_subcommands_now_P(PSTR(baby_buf)); - has_adjust_z = 1; - } + sprintf_P(baby_buf, PSTR("M290 Z%.3f"), babystep_dist); + gcode.process_subcommands_now_P(PSTR(baby_buf)); + has_adjust_z = 1; break; case ID_BABY_STEP_DIST: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (abs((int)(100 * babystep_dist)) == 1) - babystep_dist = 0.05; - else if (abs((int)(100 * babystep_dist)) == 5) - babystep_dist = 0.1; - else - babystep_dist = 0.01; - disp_baby_step_dist(); - } - + if (abs((int)(100 * babystep_dist)) == 1) + babystep_dist = 0.05; + else if (abs((int)(100 * babystep_dist)) == 5) + babystep_dist = 0.1; + else + babystep_dist = 0.01; + disp_baby_step_dist(); break; case ID_BABY_STEP_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (has_adjust_z == 1) { - gcode.process_subcommands_now_P(PSTR("M500")); - has_adjust_z = 0; - } - clear_cur_ui(); - draw_return_ui(); + if (has_adjust_z == 1) { + TERN_(EEPROM_SETTINGS, (void)settings.save()); + has_adjust_z = 0; } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_baby_stepping(void) { - lv_obj_t *buttonXI, *buttonXD, *buttonYI, *buttonYD, *buttonZI, *buttonZD, *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != BABY_STEP_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = BABY_STEP_UI; - } - disp_state = BABY_STEP_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - // Create an Image button - buttonXI = lv_imgbtn_create(scr, NULL); - buttonXD = lv_imgbtn_create(scr, NULL); - buttonYI = lv_imgbtn_create(scr, NULL); - buttonYD = lv_imgbtn_create(scr, NULL); - buttonZI = lv_imgbtn_create(scr, NULL); - buttonZD = lv_imgbtn_create(scr, NULL); - buttonV = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonXI, event_handler, ID_BABY_STEP_X_P, NULL, 0); - lv_imgbtn_set_src(buttonXI, LV_BTN_STATE_REL, "F:/bmp_xAdd.bin"); - lv_imgbtn_set_src(buttonXI, LV_BTN_STATE_PR, "F:/bmp_xAdd.bin"); - lv_imgbtn_set_style(buttonXI, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonXI, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if 1 - lv_obj_set_event_cb_mks(buttonXD, event_handler, ID_BABY_STEP_X_N, NULL, 0); - lv_imgbtn_set_src(buttonXD, LV_BTN_STATE_REL, "F:/bmp_xDec.bin"); - lv_imgbtn_set_src(buttonXD, LV_BTN_STATE_PR, "F:/bmp_xDec.bin"); - lv_imgbtn_set_style(buttonXD, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonXD, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonYI, event_handler, ID_BABY_STEP_Y_P, NULL, 0); - lv_imgbtn_set_src(buttonYI, LV_BTN_STATE_REL, "F:/bmp_yAdd.bin"); - lv_imgbtn_set_src(buttonYI, LV_BTN_STATE_PR, "F:/bmp_yAdd.bin"); - lv_imgbtn_set_style(buttonYI, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonYI, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonYD, event_handler, ID_BABY_STEP_Y_N, NULL, 0); - lv_imgbtn_set_src(buttonYD, LV_BTN_STATE_REL, "F:/bmp_yDec.bin"); - lv_imgbtn_set_src(buttonYD, LV_BTN_STATE_PR, "F:/bmp_yDec.bin"); - lv_imgbtn_set_style(buttonYD, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonYD, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonZI, event_handler, ID_BABY_STEP_Z_P, NULL, 0); - lv_imgbtn_set_src(buttonZI, LV_BTN_STATE_REL, "F:/bmp_zAdd.bin"); - lv_imgbtn_set_src(buttonZI, LV_BTN_STATE_PR, "F:/bmp_zAdd.bin"); - lv_imgbtn_set_style(buttonZI, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonZI, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonZD, event_handler, ID_BABY_STEP_Z_N, NULL, 0); - lv_imgbtn_set_src(buttonZD, LV_BTN_STATE_REL, "F:/bmp_zDec.bin"); - lv_imgbtn_set_src(buttonZD, LV_BTN_STATE_PR, "F:/bmp_zDec.bin"); - lv_imgbtn_set_style(buttonZD, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonZD, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonV, event_handler, ID_BABY_STEP_DIST, NULL, 0); - lv_imgbtn_set_style(buttonV, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonV, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_BABY_STEP_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - #endif // if 1 - lv_obj_set_pos(buttonXI, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonYI, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonZI, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - lv_obj_set_pos(buttonV, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonXD, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonYD, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonZD, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonXI, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonXD, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonYI, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonYD, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonZI, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonZD, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonV, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelXI = lv_label_create(buttonXI, NULL); - lv_obj_t *labelXD = lv_label_create(buttonXD, NULL); - lv_obj_t *labelYI = lv_label_create(buttonYI, NULL); - lv_obj_t *labelYD = lv_label_create(buttonYD, NULL); - lv_obj_t *labelZI = lv_label_create(buttonZI, NULL); - lv_obj_t *labelZD = lv_label_create(buttonZD, NULL); - labelV = lv_label_create(buttonV, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelXI, move_menu.x_add); - lv_obj_align(labelXI, buttonXI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelXD, move_menu.x_dec); - lv_obj_align(labelXD, buttonXD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYI, move_menu.y_add); - lv_obj_align(labelYI, buttonYI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYD, move_menu.y_dec); - lv_obj_align(labelYD, buttonYD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZI, move_menu.z_add); - lv_obj_align(labelZI, buttonZI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZD, move_menu.z_dec); - lv_obj_align(labelZD, buttonZD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - + scr = lv_screen_create(BABY_STEP_UI); + lv_big_button_create(scr, "F:/bmp_xAdd.bin", move_menu.x_add, INTERVAL_V, titleHeight, event_handler, ID_BABY_STEP_X_P); + lv_big_button_create(scr, "F:/bmp_xDec.bin", move_menu.x_dec, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_X_N); + lv_big_button_create(scr, "F:/bmp_yAdd.bin", move_menu.y_add, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_BABY_STEP_Y_P); + lv_big_button_create(scr, "F:/bmp_yDec.bin", move_menu.y_dec, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_Y_N); + lv_big_button_create(scr, "F:/bmp_zAdd.bin", move_menu.z_add, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_BABY_STEP_Z_P); + lv_big_button_create(scr, "F:/bmp_zDec.bin", move_menu.z_dec, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_Z_N); + buttonV = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_BABY_STEP_DIST); + labelV = lv_label_create_empty(buttonV); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXI); - lv_group_add_obj(g, buttonXD); - lv_group_add_obj(g, buttonYI); - lv_group_add_obj(g, buttonYD); - lv_group_add_obj(g, buttonZI); - lv_group_add_obj(g, buttonZD); lv_group_add_obj(g, buttonV); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_BABY_STEP_RETURN); + disp_baby_step_dist(); - zOffsetText = lv_label_create(scr, NULL); - lv_obj_set_style(zOffsetText, &tft_style_label_rel); - lv_obj_set_pos(zOffsetText, 290, TITLE_YPOS); + zOffsetText = lv_label_create(scr, 290, TITLE_YPOS, nullptr); disp_z_offset_value(); } void disp_baby_step_dist() { // char buf[30] = {0}; + if ((int)(100 * babystep_dist) == 1) + lv_imgbtn_set_src_both(buttonV, "F:/bmp_baby_move0_01.bin"); + else if ((int)(100 * babystep_dist) == 5) + lv_imgbtn_set_src_both(buttonV, "F:/bmp_baby_move0_05.bin"); + else if ((int)(100 * babystep_dist) == 10) + lv_imgbtn_set_src_both(buttonV, "F:/bmp_baby_move0_1.bin"); - if ((int)(100 * babystep_dist) == 1) { - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_REL, "F:/bmp_baby_move0_01.bin"); - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_PR, "F:/bmp_baby_move0_01.bin"); - } - else if ((int)(100 * babystep_dist) == 5) { - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_REL, "F:/bmp_baby_move0_05.bin"); - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_PR, "F:/bmp_baby_move0_05.bin"); - } - else if ((int)(100 * babystep_dist) == 10) { - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_REL, "F:/bmp_baby_move0_1.bin"); - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_PR, "F:/bmp_baby_move0_1.bin"); - } if (gCfgItems.multiple_language) { if ((int)(100 * babystep_dist) == 1) { lv_label_set_text(labelV, move_menu.step_001mm); @@ -336,9 +162,7 @@ void disp_baby_step_dist() { void disp_z_offset_value() { char buf[20]; - - ZERO(buf); - sprintf_P(buf, PSTR("offset Z: %.3f"), (double)TERN(HAS_BED_PROBE, probe.offset.z, 0)); + sprintf_P(buf, PSTR("offset Z: %.3f"), (float)TERN(HAS_BED_PROBE, probe.offset.z, 0)); lv_label_set_text(zOffsetText, buf); } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp index f9399b8a45..a5100776ac 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp @@ -33,253 +33,144 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *labelStep, *buttonStep, *buttonMov, *buttonExt; static lv_obj_t *labelMov, *labelExt; -static lv_obj_t * printSpeedText; +static lv_obj_t *printSpeedText; -#define ID_C_ADD 1 -#define ID_C_DEC 2 -#define ID_C_MOVE 3 -#define ID_C_EXT 4 -#define ID_C_STEP 5 -#define ID_C_RETURN 6 +enum { + ID_C_ADD = 1, + ID_C_DEC, + ID_C_MOVE, + ID_C_EXT, + ID_C_STEP, + ID_C_RETURN +}; -static uint8_t speedType; +static bool editingFlowrate; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_C_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (!editingFlowrate) { + if (feedrate_percentage < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) + feedrate_percentage += uiCfg.stepPrintSpeed; + else + feedrate_percentage = MAX_EXT_SPEED_PERCENT; } - else if (event == LV_EVENT_RELEASED) { - if (speedType == 0) { - if (feedrate_percentage < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) - feedrate_percentage += uiCfg.stepPrintSpeed; - else - feedrate_percentage = MAX_EXT_SPEED_PERCENT; - } - else if (speedType == 1) { - if (planner.flow_percentage[0] < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) - planner.flow_percentage[0] += uiCfg.stepPrintSpeed; - else - planner.flow_percentage[0] = MAX_EXT_SPEED_PERCENT; - //planner.e_factor[0]= planner.flow_percentage[0]*0.01; - //planner.flow_percentage[1] = planner.flow_percentage[0]; - //planner.e_factor[1]= planner.flow_percentage[1]*0.01; - planner.refresh_e_factor(0); - #if HAS_MULTI_EXTRUDER - planner.flow_percentage[1] = planner.flow_percentage[0]; - planner.refresh_e_factor(1); - #endif - } - disp_print_speed(); + else { + if (planner.flow_percentage[0] < MAX_EXT_SPEED_PERCENT - uiCfg.stepPrintSpeed) + planner.flow_percentage[0] += uiCfg.stepPrintSpeed; + else + planner.flow_percentage[0] = MAX_EXT_SPEED_PERCENT; + //planner.e_factor[0]= planner.flow_percentage[0]*0.01; + //planner.flow_percentage[1] = planner.flow_percentage[0]; + //planner.e_factor[1]= planner.flow_percentage[1]*0.01; + planner.refresh_e_factor(0); + #if HAS_MULTI_EXTRUDER + planner.flow_percentage[1] = planner.flow_percentage[0]; + planner.refresh_e_factor(1); + #endif } + disp_print_speed(); break; case ID_C_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (!editingFlowrate) { + if (feedrate_percentage > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) + feedrate_percentage -= uiCfg.stepPrintSpeed; + else + feedrate_percentage = MIN_EXT_SPEED_PERCENT; } - else if (event == LV_EVENT_RELEASED) { - if (speedType == 0) { - if (feedrate_percentage > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) - feedrate_percentage -= uiCfg.stepPrintSpeed; - else - feedrate_percentage = MIN_EXT_SPEED_PERCENT; - } - else if (speedType == 1) { - if (planner.flow_percentage[0] > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) - planner.flow_percentage[0] -= uiCfg.stepPrintSpeed; - else - planner.flow_percentage[0] = MIN_EXT_SPEED_PERCENT; - //planner.e_factor[0]= planner.flow_percentage[0] * 0.01; - //planner.flow_percentage[1] = planner.flow_percentage[0]; - //planner.e_factor[1]= planner.flow_percentage[1] * 0.01; - planner.refresh_e_factor(0); - #if HAS_MULTI_EXTRUDER - planner.flow_percentage[1] = planner.flow_percentage[0]; - planner.refresh_e_factor(1); - #endif - } - disp_print_speed(); + else { + if (planner.flow_percentage[0] > MIN_EXT_SPEED_PERCENT + uiCfg.stepPrintSpeed) + planner.flow_percentage[0] -= uiCfg.stepPrintSpeed; + else + planner.flow_percentage[0] = MIN_EXT_SPEED_PERCENT; + //planner.e_factor[0]= planner.flow_percentage[0] * 0.01; + //planner.flow_percentage[1] = planner.flow_percentage[0]; + //planner.e_factor[1]= planner.flow_percentage[1] * 0.01; + planner.refresh_e_factor(0); + #if HAS_MULTI_EXTRUDER + planner.flow_percentage[1] = planner.flow_percentage[0]; + planner.refresh_e_factor(1); + #endif } + disp_print_speed(); break; case ID_C_MOVE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - speedType = 0; - disp_speed_type(); - disp_print_speed(); - } + editingFlowrate = false; + disp_speed_type(); + disp_print_speed(); break; case ID_C_EXT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - speedType = 1; - disp_speed_type(); - disp_print_speed(); - } + editingFlowrate = true; + disp_speed_type(); + disp_print_speed(); break; case ID_C_STEP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.stepPrintSpeed == 1) - uiCfg.stepPrintSpeed = 5; - else if (uiCfg.stepPrintSpeed == 5) - uiCfg.stepPrintSpeed = 10; - else - uiCfg.stepPrintSpeed = 1; - disp_speed_step(); - } + if (uiCfg.stepPrintSpeed == 1) + uiCfg.stepPrintSpeed = 5; + else if (uiCfg.stepPrintSpeed == 5) + uiCfg.stepPrintSpeed = 10; + else + uiCfg.stepPrintSpeed = 1; + disp_speed_step(); break; case ID_C_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_change_speed(void) { - lv_obj_t *buttonAdd, *buttonDec; - lv_obj_t *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != CHANGE_SPEED_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = CHANGE_SPEED_UI; - } - disp_state = CHANGE_SPEED_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - + scr = lv_screen_create(CHANGE_SPEED_UI); // Create an Image button - buttonAdd = lv_imgbtn_create(scr, NULL); - buttonDec = lv_imgbtn_create(scr, NULL); - buttonMov = lv_imgbtn_create(scr, NULL); - buttonExt = lv_imgbtn_create(scr, NULL); - buttonStep = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_C_ADD, NULL, 0); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, "F:/bmp_Add.bin"); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, "F:/bmp_Add.bin"); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if 1 - lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_C_DEC, NULL, 0); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, "F:/bmp_Dec.bin"); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, "F:/bmp_Dec.bin"); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonMov, event_handler, ID_C_MOVE, NULL, 0); - lv_imgbtn_set_style(buttonMov, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMov, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonExt, event_handler, ID_C_EXT, NULL, 0); - lv_imgbtn_set_style(buttonExt, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonExt, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonStep, event_handler, ID_C_STEP, NULL, 0); - lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_C_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonMov, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonExt, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonStep, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonMov, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonExt, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonStep, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelAdd = lv_label_create(buttonAdd, NULL); - lv_obj_t *labelDec = lv_label_create(buttonDec, NULL); - labelMov = lv_label_create(buttonMov, NULL); - labelExt = lv_label_create(buttonExt, NULL); - labelStep = lv_label_create(buttonStep, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, speed_menu.add); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, speed_menu.dec); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } + lv_big_button_create(scr, "F:/bmp_Add.bin", speed_menu.add, INTERVAL_V, titleHeight, event_handler, ID_C_ADD); + lv_big_button_create(scr, "F:/bmp_Dec.bin", speed_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_C_DEC); + buttonMov = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_MOVE); + buttonExt = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_EXT); + buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_STEP); + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable) { + lv_group_add_obj(g, buttonMov); + lv_group_add_obj(g, buttonExt); + lv_group_add_obj(g, buttonStep); + } + #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_C_RETURN); + + // Create labels on the image buttons + labelMov = lv_label_create_empty(buttonMov); + labelExt = lv_label_create_empty(buttonExt); + labelStep = lv_label_create_empty(buttonStep); + #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); lv_group_add_obj(g, buttonMov); lv_group_add_obj(g, buttonExt); lv_group_add_obj(g, buttonStep); - lv_group_add_obj(g, buttonBack); } #endif disp_speed_type(); disp_speed_step(); - printSpeedText = lv_label_create(scr, NULL); + printSpeedText = lv_label_create_empty(scr); lv_obj_set_style(printSpeedText, &tft_style_label_rel); disp_print_speed(); } void disp_speed_step() { - if (uiCfg.stepPrintSpeed == 1) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step1_percent.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step1_percent.bin"); - } - else if (uiCfg.stepPrintSpeed == 5) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step5_percent.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step5_percent.bin"); - } - else if (uiCfg.stepPrintSpeed == 10) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step10_percent.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step10_percent.bin"); - } + if (uiCfg.stepPrintSpeed == 1) + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step1_percent.bin"); + else if (uiCfg.stepPrintSpeed == 5) + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step5_percent.bin"); + else if (uiCfg.stepPrintSpeed == 10) + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step10_percent.bin"); + if (gCfgItems.multiple_language) { if (uiCfg.stepPrintSpeed == 1) { lv_label_set_text(labelStep, speed_menu.step_1percent); @@ -301,38 +192,27 @@ void disp_print_speed() { public_buf_l[0] = '\0'; - if (speedType == 0) { // move - strcat(public_buf_l, speed_menu.move_speed); - strcat_P(public_buf_l, PSTR(": ")); - sprintf_P(buf, PSTR("%d%%"), feedrate_percentage); - strcat(public_buf_l, buf); + int16_t val; + const char *lbl; + if (editingFlowrate) { + lbl = speed_menu.extrude_speed; + val = planner.flow_percentage[0]; } - else if (speedType == 1) { // e1 - strcat(public_buf_l, speed_menu.extrude_speed); - strcat_P(public_buf_l, PSTR(": ")); - sprintf_P(buf, PSTR("%d%%"), planner.flow_percentage[0]); - strcat(public_buf_l, buf); + else { + lbl = speed_menu.move_speed; + val = feedrate_percentage; } + strcpy(public_buf_l, lbl); + strcat_P(public_buf_l, PSTR(": ")); + sprintf_P(buf, PSTR("%d%%"), val); + strcat(public_buf_l, buf); lv_label_set_text(printSpeedText, public_buf_l); - lv_obj_align(printSpeedText, NULL, LV_ALIGN_CENTER, 0, -65); + lv_obj_align(printSpeedText, nullptr, LV_ALIGN_CENTER, 0, -65); } void disp_speed_type() { - switch (speedType) { - case 1: - lv_imgbtn_set_src(buttonMov, LV_BTN_STATE_REL, "F:/bmp_mov_changeSpeed.bin"); - lv_imgbtn_set_src(buttonMov, LV_BTN_STATE_PR, "F:/bmp_mov_changeSpeed.bin"); - lv_imgbtn_set_src(buttonExt, LV_BTN_STATE_REL, "F:/bmp_extruct_sel.bin"); - lv_imgbtn_set_src(buttonExt, LV_BTN_STATE_PR, "F:/bmp_extruct_sel.bin"); - break; - - default: - lv_imgbtn_set_src(buttonMov, LV_BTN_STATE_REL, "F:/bmp_mov_sel.bin"); - lv_imgbtn_set_src(buttonMov, LV_BTN_STATE_PR, "F:/bmp_mov_sel.bin"); - lv_imgbtn_set_src(buttonExt, LV_BTN_STATE_REL, "F:/bmp_speed_extruct.bin"); - lv_imgbtn_set_src(buttonExt, LV_BTN_STATE_PR, "F:/bmp_speed_extruct.bin"); - break; - } + lv_imgbtn_set_src_both(buttonMov, editingFlowrate ? "F:/bmp_mov_changeSpeed.bin" : "F:/bmp_mov_sel.bin"); + lv_imgbtn_set_src_both(buttonExt, editingFlowrate ? "F:/bmp_extruct_sel.bin" : "F:/bmp_speed_extruct.bin"); lv_obj_refresh_ext_draw_pad(buttonExt); lv_obj_refresh_ext_draw_pad(buttonMov); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp index 489d8466ce..67ed24d8c0 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp @@ -43,6 +43,10 @@ #include "../../../../gcode/gcode.h" #include "../../../../inc/MarlinConfig.h" +#if ENABLED(EEPROM_SETTINGS) + #include "../../../../module/settings.h" +#endif + #if ENABLED(POWER_LOSS_RECOVERY) #include "../../../../feature/powerloss.h" #endif @@ -51,354 +55,223 @@ #include "../../../../feature/pause.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * tempText1; -static lv_obj_t * filament_bar; +extern lv_group_t *g; +static lv_obj_t *scr, *tempText1, *filament_bar; extern uint8_t sel_id; extern bool once_flag, gcode_preview_over; -extern int upload_result ; +extern int upload_result; extern uint32_t upload_time; extern uint32_t upload_size; -extern uint8_t temperature_change_frequency; +extern bool temps_update_flag; -static void btn_ok_event_cb(lv_obj_t * btn, lv_event_t event) { - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.dialogType == DIALOG_TYPE_PRINT_FILE) { - #if HAS_GCODE_PREVIEW - preview_gcode_prehandle(list_file.file_name[sel_id]); - #endif - reset_print_time(); - start_print_time(); +static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + if (DIALOG_IS(TYPE_PRINT_FILE)) { + #if HAS_GCODE_PREVIEW + preview_gcode_prehandle(list_file.file_name[sel_id]); + #endif + reset_print_time(); + start_print_time(); - uiCfg.print_state = WORKING; - lv_clear_dialog(); - lv_draw_printing(); + uiCfg.print_state = WORKING; + lv_clear_dialog(); + lv_draw_printing(); - #if ENABLED(SDSUPPORT) - if (!gcode_preview_over) { - char *cur_name; - cur_name = strrchr(list_file.file_name[sel_id], '/'); + #if ENABLED(SDSUPPORT) + if (!gcode_preview_over) { + char *cur_name; + cur_name = strrchr(list_file.file_name[sel_id], '/'); - SdFile file, *curDir; - card.endFilePrint(); - const char * const fname = card.diveToFile(true, curDir, cur_name); - if (!fname) return; - if (file.open(curDir, fname, O_READ)) { - gCfgItems.curFilesize = file.fileSize(); - file.close(); - update_spi_flash(); - } - card.openFileRead(cur_name); - if (card.isFileOpen()) { - feedrate_percentage = 100; - //saved_feedrate_percentage = feedrate_percentage; - planner.flow_percentage[0] = 100; - planner.e_factor[0] = planner.flow_percentage[0] * 0.01f; - #if HAS_MULTI_EXTRUDER - planner.flow_percentage[1] = 100; - planner.e_factor[1] = planner.flow_percentage[1] * 0.01f; - #endif - card.startFileprint(); - #if ENABLED(POWER_LOSS_RECOVERY) - recovery.prepare(); - #endif - once_flag = false; - } + SdFile file, *curDir; + card.endFilePrint(); + const char * const fname = card.diveToFile(true, curDir, cur_name); + if (!fname) return; + if (file.open(curDir, fname, O_READ)) { + gCfgItems.curFilesize = file.fileSize(); + file.close(); + update_spi_flash(); + } + card.openFileRead(cur_name); + if (card.isFileOpen()) { + feedrate_percentage = 100; + //saved_feedrate_percentage = feedrate_percentage; + planner.flow_percentage[0] = 100; + planner.e_factor[0] = planner.flow_percentage[0] * 0.01f; + #if HAS_MULTI_EXTRUDER + planner.flow_percentage[1] = 100; + planner.e_factor[1] = planner.flow_percentage[1] * 0.01f; + #endif + card.startFileprint(); + #if ENABLED(POWER_LOSS_RECOVERY) + recovery.prepare(); + #endif + once_flag = false; } - #endif - } - else if (uiCfg.dialogType == DIALOG_TYPE_STOP) { - wait_for_heatup = false; - stop_print_time(); - lv_clear_dialog(); - lv_draw_ready_print(); - - #if ENABLED(SDSUPPORT) - //card.endFilePrint(); - //wait_for_heatup = false; - uiCfg.print_state = IDLE; - card.flag.abort_sd_printing = true; - //queue.clear(); - //quickstop_stepper(); - //print_job_timer.stop(); - //thermalManager.disable_all_heaters(); - - //#if ENABLED(POWER_LOSS_RECOVERY) - // recovery.purge(); - //#endif - //queue.enqueue_now_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0")); - //queue.inject_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0\nM84\nM107")); - #endif - } - else if (uiCfg.dialogType == DIALOG_TYPE_FINISH_PRINT) { - clear_cur_ui(); - lv_draw_ready_print(); - } - #if ENABLED(ADVANCED_PAUSE_FEATURE) - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_WAITING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_INSERT - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEAT - ) { - wait_for_user = false; - } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { - pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; - } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME) { - clear_cur_ui(); - draw_return_ui(); } #endif - else if (uiCfg.dialogType == DIALOG_STORE_EEPROM_TIPS) { - gcode.process_subcommands_now_P(PSTR("M500")); - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_READ_EEPROM_TIPS) { - gcode.process_subcommands_now_P(PSTR("M501")); - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_REVERT_EEPROM_TIPS) { - gcode.process_subcommands_now_P(PSTR("M502")); - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_WIFI_CONFIG_TIPS) { - uiCfg.configWifi = 1; - clear_cur_ui(); - draw_return_ui(); - } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED) { - uiCfg.filament_heat_completed_load = 1; - } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED) { - uiCfg.filament_heat_completed_unload = 1; - } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_COMPLETED - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED - ) { + } + else if (DIALOG_IS(TYPE_STOP)) { + wait_for_heatup = false; + stop_print_time(); + lv_clear_dialog(); + lv_draw_ready_print(); + + #if ENABLED(SDSUPPORT) + //card.endFilePrint(); + //wait_for_heatup = false; + uiCfg.print_state = IDLE; + card.flag.abort_sd_printing = true; + //queue.clear(); + //quickstop_stepper(); + //print_job_timer.stop(); + //thermalManager.disable_all_heaters(); + + //#if ENABLED(POWER_LOSS_RECOVERY) + // recovery.purge(); + //#endif + //queue.enqueue_now_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0")); + //queue.inject_P(PSTR("G91\nG1 Z10\nG90\nG28 X0 Y0\nM84\nM107")); + #endif + } + else if (DIALOG_IS(TYPE_FINISH_PRINT)) { + clear_cur_ui(); + lv_draw_ready_print(); + } + #if ENABLED(ADVANCED_PAUSE_FEATURE) + else if (DIALOG_IS(PAUSE_MESSAGE_WAITING, PAUSE_MESSAGE_INSERT, PAUSE_MESSAGE_HEAT)) + wait_for_user = false; + else if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) + pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; + else if (DIALOG_IS(PAUSE_MESSAGE_RESUME)) { clear_cur_ui(); draw_return_ui(); } + #endif + else if (DIALOG_IS(STORE_EEPROM_TIPS)) { + TERN_(EEPROM_SETTINGS, (void)settings.save()); + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(READ_EEPROM_TIPS)) { + TERN_(EEPROM_SETTINGS, (void)settings.load()); + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(REVERT_EEPROM_TIPS)) { + TERN_(EEPROM_SETTINGS, (void)settings.reset()); + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(WIFI_CONFIG_TIPS)) { + uiCfg.configWifi = 1; + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_LOAD_COMPLETED)) + uiCfg.filament_heat_completed_load = 1; + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) + uiCfg.filament_heat_completed_unload = 1; + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_COMPLETED, TYPE_FILAMENT_UNLOAD_COMPLETED)) { + clear_cur_ui(); + draw_return_ui(); } } -static void btn_cancel_event_cb(lv_obj_t * btn, lv_event_t event) { - if (event == LV_EVENT_CLICKED) { - // nothing to do +static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { + #if ENABLED(ADVANCED_PAUSE_FEATURE) + pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; + #endif } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { - #if ENABLED(ADVANCED_PAUSE_FEATURE) - pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; - #endif - } - else if ((uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED) - ) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak; - clear_cur_ui(); - draw_return_ui(); - } - else if ((uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING) - ) { - queue.enqueue_one_P(PSTR("M410")); - uiCfg.filament_rate = 0; - uiCfg.filament_loading_completed = 0; - uiCfg.filament_unloading_completed = 0; - uiCfg.filament_loading_time_flg = 0; - uiCfg.filament_loading_time_cnt = 0; - uiCfg.filament_unloading_time_flg = 0; - uiCfg.filament_unloading_time_cnt = 0; - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; - clear_cur_ui(); - draw_return_ui(); - } - else { - clear_cur_ui(); - draw_return_ui(); - } + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT, TYPE_FILAMENT_HEAT_LOAD_COMPLETED, TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak; + clear_cur_ui(); + draw_return_ui(); + } + else if (DIALOG_IS(TYPE_FILAMENT_LOADING, TYPE_FILAMENT_UNLOADING)) { + queue.enqueue_one_P(PSTR("M410")); + uiCfg.filament_rate = 0; + uiCfg.filament_loading_completed = 0; + uiCfg.filament_unloading_completed = 0; + uiCfg.filament_loading_time_flg = 0; + uiCfg.filament_loading_time_cnt = 0; + uiCfg.filament_unloading_time_flg = 0; + uiCfg.filament_unloading_time_cnt = 0; + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; + clear_cur_ui(); + draw_return_ui(); + } + else { + clear_cur_ui(); + draw_return_ui(); } } void lv_draw_dialog(uint8_t type) { - - lv_obj_t * btnOk = NULL; - lv_obj_t * btnCancel = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != DIALOG_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = DIALOG_UI; - } - disp_state = DIALOG_UI; - + lv_obj_t *btnOk = nullptr, *btnCancel = nullptr; uiCfg.dialogType = type; + scr = lv_screen_create(DIALOG_UI); - scr = lv_obj_create(NULL, NULL); + lv_obj_t *labelDialog = lv_label_create_empty(scr); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - - static lv_style_t style_btn_rel; // A variable to store the released style - lv_style_copy(&style_btn_rel, &lv_style_plain); // Initialize from a built-in style - style_btn_rel.body.border.color = lv_color_hex3(0x269); - style_btn_rel.body.border.width = 1; - style_btn_rel.body.main_color = lv_color_hex3(0xADF); - style_btn_rel.body.grad_color = lv_color_hex3(0x46B); - style_btn_rel.body.shadow.width = 4; - style_btn_rel.body.shadow.type = LV_SHADOW_BOTTOM; - style_btn_rel.body.radius = LV_RADIUS_CIRCLE; - style_btn_rel.text.color = lv_color_hex3(0xDEF); - style_btn_rel.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); - - static lv_style_t style_btn_pr; // A variable to store the pressed style - lv_style_copy(&style_btn_pr, &style_btn_rel); // Initialize from the released style - style_btn_pr.body.border.color = lv_color_hex3(0x46B); - style_btn_pr.body.main_color = lv_color_hex3(0x8BD); - style_btn_pr.body.grad_color = lv_color_hex3(0x24A); - style_btn_pr.body.shadow.width = 2; - style_btn_pr.text.color = lv_color_hex3(0xBCD); - style_btn_pr.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); - - lv_obj_t *labelDialog = lv_label_create(scr, NULL); - lv_obj_set_style(labelDialog, &tft_style_label_rel); - - if (uiCfg.dialogType == DIALOG_TYPE_FINISH_PRINT || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME) { - btnOk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnOk, BTN_OK_X + 90, BTN_OK_Y); // Set its position - lv_obj_set_size(btnOk, 100, 50); // Set its size - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style - lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style - lv_obj_t *labelOk = lv_label_create(btnOk, NULL); // Add a label to the button + if (DIALOG_IS(TYPE_FINISH_PRINT, PAUSE_MESSAGE_RESUME)) { + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); + lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_WAITING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_INSERT - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEAT - ) { - btnOk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnOk, BTN_OK_X + 90, BTN_OK_Y); // Set its position - lv_obj_set_size(btnOk, 100, 50); // Set its size - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style - lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style - lv_obj_t *labelOk = lv_label_create(btnOk, NULL); // Add a label to the button + else if (DIALOG_IS(PAUSE_MESSAGE_WAITING, PAUSE_MESSAGE_INSERT, PAUSE_MESSAGE_HEAT)) { + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); + lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button lv_label_set_text(labelOk, print_file_dialog_menu.confirm); // Set the labels text } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PAUSING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_CHANGING - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_UNLOAD - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_LOAD - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PURGE - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME - || uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEATING - ) { + else if (DIALOG_IS(PAUSE_MESSAGE_PAUSING, PAUSE_MESSAGE_CHANGING, PAUSE_MESSAGE_UNLOAD, PAUSE_MESSAGE_LOAD, PAUSE_MESSAGE_PURGE, PAUSE_MESSAGE_RESUME, PAUSE_MESSAGE_HEATING)) { // nothing to do } - else if (uiCfg.dialogType == WIFI_ENABLE_TIPS) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_PR, &style_btn_pr); - lv_obj_t *labelCancel = lv_label_create(btnCancel, NULL); + else if (DIALOG_IS(WIFI_ENABLE_TIPS)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); + lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } - else if (uiCfg.dialogType == DIALOG_TRANSFER_NO_DEVICE) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_PR, &style_btn_pr); - lv_obj_t *labelCancel = lv_label_create(btnCancel, NULL); + else if (DIALOG_IS(TRANSFER_NO_DEVICE)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); + lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } #if ENABLED(USE_WIFI_FUNCTION) - else if (uiCfg.dialogType == DIALOG_TYPE_UPLOAD_FILE) { + else if (DIALOG_IS(TYPE_UPLOAD_FILE)) { if (upload_result == 2) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_PR, &style_btn_pr); - lv_obj_t *labelCancel = lv_label_create(btnCancel, NULL); + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); + lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } else if (upload_result == 3) { - btnOk = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnOk, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnOk, 100, 50); - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); - lv_obj_t *labelOk = lv_label_create(btnOk, NULL); + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); + lv_obj_t *labelOk = lv_label_create_empty(btnOk); lv_label_set_text(labelOk, print_file_dialog_menu.confirm); } } - #endif //USE_WIFI_FUNCTION - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT - ) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_PR, &style_btn_pr); - lv_obj_t *labelCancel = lv_label_create(btnCancel, NULL); + #endif + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X+90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); + lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); - tempText1 = lv_label_create(scr, NULL); - lv_obj_set_style(tempText1, &tft_style_label_rel); + tempText1 = lv_label_create_empty(scr); filament_sprayer_temp(); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_COMPLETED - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED - ) { - btnOk = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnOk, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnOk, 100, 50); - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); - lv_obj_t *labelOk = lv_label_create(btnOk, NULL); + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_COMPLETED, TYPE_FILAMENT_UNLOAD_COMPLETED)) { + btnOk = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_ok_event_cb); + lv_obj_t *labelOk = lv_label_create_empty(btnOk); lv_label_set_text(labelOk, print_file_dialog_menu.confirm); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING - ) { - btnCancel = lv_btn_create(scr, NULL); - lv_obj_set_pos(btnCancel, BTN_OK_X+90, BTN_OK_Y); - lv_obj_set_size(btnCancel, 100, 50); - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_REL, &style_btn_rel); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_PR, &style_btn_pr); - lv_obj_t *labelCancel = lv_label_create(btnCancel, NULL); + else if (DIALOG_IS(TYPE_FILAMENT_LOADING, TYPE_FILAMENT_UNLOADING)) { + btnCancel = lv_button_btn_create(scr, BTN_OK_X + 90, BTN_OK_Y, 100, 50, btn_cancel_event_cb); + lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); - filament_bar = lv_bar_create(scr, NULL); + filament_bar = lv_bar_create(scr, nullptr); lv_obj_set_pos(filament_bar, (TFT_WIDTH-400)/2, ((TFT_HEIGHT - titleHeight)-40)/2); lv_obj_set_size(filament_bar, 400, 25); lv_bar_set_style(filament_bar, LV_BAR_STYLE_INDIC, &lv_bar_style_indic); @@ -406,23 +279,13 @@ void lv_draw_dialog(uint8_t type) { lv_bar_set_value(filament_bar, 0, LV_ANIM_ON); } else { - btnOk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnOk, BTN_OK_X, BTN_OK_Y); // Set its position - lv_obj_set_size(btnOk, 100, 50); // Set its size - lv_obj_set_event_cb(btnOk, btn_ok_event_cb); - lv_btn_set_style(btnOk, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style - lv_btn_set_style(btnOk, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style - lv_obj_t *labelOk = lv_label_create(btnOk, NULL); // Add a label to the button + btnOk = lv_button_btn_create(scr, BTN_OK_X, BTN_OK_Y, 100, 50, btn_ok_event_cb); + lv_obj_t *labelOk = lv_label_create_empty(btnOk); // Add a label to the button - btnCancel = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(btnCancel, BTN_CANCEL_X, BTN_CANCEL_Y); // Set its position - lv_obj_set_size(btnCancel, 100, 50); // Set its size - lv_obj_set_event_cb(btnCancel, btn_cancel_event_cb); - lv_btn_set_style(btnCancel, LV_BTN_STYLE_REL, &style_btn_rel); // Set the button's released style - lv_btn_set_style(btnCancel, LV_BTN_STYLE_PR, &style_btn_pr); // Set the button's pressed style - lv_obj_t *labelCancel = lv_label_create(btnCancel, NULL); // Add a label to the button + btnCancel = lv_button_btn_create(scr, BTN_CANCEL_X, BTN_CANCEL_Y, 100, 50, btn_cancel_event_cb); + lv_obj_t *labelCancel = lv_label_create_empty(btnCancel); // Add a label to the button - if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { + if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { lv_label_set_text(labelOk, pause_msg_menu.purgeMore); // Set the labels text lv_label_set_text(labelCancel, pause_msg_menu.continuePrint); } @@ -431,108 +294,103 @@ void lv_draw_dialog(uint8_t type) { lv_label_set_text(labelCancel, print_file_dialog_menu.cancle); } } - if (uiCfg.dialogType == DIALOG_TYPE_PRINT_FILE) { + if (DIALOG_IS(TYPE_PRINT_FILE)) { lv_label_set_text(labelDialog, print_file_dialog_menu.print_file); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); - lv_obj_t *labelFile = lv_label_create(scr, NULL); - lv_obj_set_style(labelFile, &tft_style_label_rel); - - lv_label_set_text(labelFile, list_file.long_name[sel_id]); - lv_obj_align(labelFile, NULL, LV_ALIGN_CENTER, 0, -60); + lv_obj_t *labelFile = lv_label_create(scr, list_file.long_name[sel_id]); + lv_obj_align(labelFile, nullptr, LV_ALIGN_CENTER, 0, -60); } - else if (uiCfg.dialogType == DIALOG_TYPE_STOP) { + else if (DIALOG_IS(TYPE_STOP)) { lv_label_set_text(labelDialog, print_file_dialog_menu.cancle_print); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FINISH_PRINT) { + else if (DIALOG_IS(TYPE_FINISH_PRINT)) { lv_label_set_text(labelDialog, print_file_dialog_menu.print_finish); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PAUSING) { + else if (DIALOG_IS(PAUSE_MESSAGE_PAUSING)) { lv_label_set_text(labelDialog, pause_msg_menu.pausing); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_CHANGING) { + else if (DIALOG_IS(PAUSE_MESSAGE_CHANGING)) { lv_label_set_text(labelDialog, pause_msg_menu.changing); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_UNLOAD) { + else if (DIALOG_IS(PAUSE_MESSAGE_UNLOAD)) { lv_label_set_text(labelDialog, pause_msg_menu.unload); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_WAITING) { + else if (DIALOG_IS(PAUSE_MESSAGE_WAITING)) { lv_label_set_text(labelDialog, pause_msg_menu.waiting); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_INSERT) { + else if (DIALOG_IS(PAUSE_MESSAGE_INSERT)) { lv_label_set_text(labelDialog, pause_msg_menu.insert); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_LOAD) { + else if (DIALOG_IS(PAUSE_MESSAGE_LOAD)) { lv_label_set_text(labelDialog, pause_msg_menu.load); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_PURGE) { + else if (DIALOG_IS(PAUSE_MESSAGE_PURGE)) { lv_label_set_text(labelDialog, pause_msg_menu.purge); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_RESUME) { + else if (DIALOG_IS(PAUSE_MESSAGE_RESUME)) { lv_label_set_text(labelDialog, pause_msg_menu.resume); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEAT) { + else if (DIALOG_IS(PAUSE_MESSAGE_HEAT)) { lv_label_set_text(labelDialog, pause_msg_menu.heat); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_HEATING) { + else if (DIALOG_IS(PAUSE_MESSAGE_HEATING)) { lv_label_set_text(labelDialog, pause_msg_menu.heating); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_PAUSE_MESSAGE_OPTION) { + else if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { lv_label_set_text(labelDialog, pause_msg_menu.option); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_STORE_EEPROM_TIPS) { + else if (DIALOG_IS(STORE_EEPROM_TIPS)) { lv_label_set_text(labelDialog, eeprom_menu.storeTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_READ_EEPROM_TIPS) { + else if (DIALOG_IS(READ_EEPROM_TIPS)) { lv_label_set_text(labelDialog, eeprom_menu.readTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_REVERT_EEPROM_TIPS) { + else if (DIALOG_IS(REVERT_EEPROM_TIPS)) { lv_label_set_text(labelDialog, eeprom_menu.revertTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_WIFI_CONFIG_TIPS) { + else if (DIALOG_IS(WIFI_CONFIG_TIPS)) { lv_label_set_text(labelDialog, machine_menu.wifiConfigTips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == WIFI_ENABLE_TIPS) { + else if (DIALOG_IS(WIFI_ENABLE_TIPS)) { lv_label_set_text(labelDialog, print_file_dialog_menu.wifi_enable_tips); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TRANSFER_NO_DEVICE) { + else if (DIALOG_IS(TRANSFER_NO_DEVICE)) { lv_label_set_text(labelDialog, DIALOG_UPDATE_NO_DEVICE_EN); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } #if ENABLED(USE_WIFI_FUNCTION) - else if (uiCfg.dialogType == DIALOG_TYPE_UPLOAD_FILE) { + else if (DIALOG_IS(TYPE_UPLOAD_FILE)) { if (upload_result == 1) { lv_label_set_text(labelDialog, DIALOG_UPLOAD_ING_EN); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } else if (upload_result == 2) { lv_label_set_text(labelDialog, DIALOG_UPLOAD_ERROR_EN); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } else if (upload_result == 3) { char buf[200]; int _index = 0; - ZERO(buf); - strcpy(buf, DIALOG_UPLOAD_FINISH_EN); _index = strlen(buf); buf[_index] = '\n'; @@ -557,42 +415,41 @@ void lv_draw_dialog(uint8_t type) { sprintf(&buf[_index], " %d KBytes/s\n", (int)(upload_size / upload_time / 1024)); lv_label_set_text(labelDialog, buf); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); - + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } } - #endif //USE_WIFI_FUNCTION - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT) { + #endif // USE_WIFI_FUNCTION + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_load_heat); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_LOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_load_heat_confirm); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT) { + else if (DIALOG_IS(TYPE_FILAMENT_UNLOAD_HEAT)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unload_heat); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unload_heat_confirm); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_LOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_load_completed); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED) { + else if (DIALOG_IS(TYPE_FILAMENT_UNLOAD_COMPLETED)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unload_completed); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -20); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING) { + else if (DIALOG_IS(TYPE_FILAMENT_LOADING)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_loading); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -70); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -70); } - else if (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING) { + else if (DIALOG_IS(TYPE_FILAMENT_UNLOADING)) { lv_label_set_text(labelDialog, filament_menu.filament_dialog_unloading); - lv_obj_align(labelDialog, NULL, LV_ALIGN_CENTER, 0, -70); + lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -70); } #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { @@ -604,28 +461,19 @@ void lv_draw_dialog(uint8_t type) { void filament_sprayer_temp() { char buf[20] = {0}; + sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); - public_buf_l[0] = '\0'; - - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, preheat_menu.ext1); - else - strcat(public_buf_l, preheat_menu.ext2); - sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); - + strcpy(public_buf_l, uiCfg.curSprayerChoose < 1 ? extrude_menu.ext1 : extrude_menu.ext2); strcat_P(public_buf_l, PSTR(": ")); strcat(public_buf_l, buf); lv_label_set_text(tempText1, public_buf_l); - lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50); } void filament_dialog_handle() { - if ((temperature_change_frequency == 1) - && ((uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOAD_HEAT) - || (uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOAD_HEAT)) - ) { + if (temps_update_flag && (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT))) { filament_sprayer_temp(); - temperature_change_frequency = 0; + temps_update_flag = false; } if (uiCfg.filament_heat_completed_load == 1) { uiCfg.filament_heat_completed_load = 0; @@ -634,10 +482,8 @@ void filament_dialog_handle() { planner.synchronize(); uiCfg.filament_loading_time_flg = 1; uiCfg.filament_loading_time_cnt = 0; - ZERO(public_buf_m); - sprintf_P(public_buf_m,PSTR("T%d\nG91\nG1 E%d F%d\nG90"),uiCfg.curSprayerChoose,gCfgItems.filamentchange_load_length,gCfgItems.filamentchange_load_speed); - queue.inject_P(PSTR(public_buf_m)); - //gcode.process_subcommands_now_P(PSTR(public_buf_m)); + sprintf_P(public_buf_m, PSTR("T%d\nG91\nG1 E%d F%d\nG90"), uiCfg.curSprayerChoose, gCfgItems.filamentchange_load_length, gCfgItems.filamentchange_load_speed); + queue.inject(public_buf_m); } if (uiCfg.filament_heat_completed_unload == 1) { uiCfg.filament_heat_completed_unload = 0; @@ -646,9 +492,8 @@ void filament_dialog_handle() { planner.synchronize(); uiCfg.filament_unloading_time_flg = 1; uiCfg.filament_unloading_time_cnt = 0; - ZERO(public_buf_m); - sprintf_P(public_buf_m,PSTR("T%d\nG91\nG1 E-%d F%d\nG90"),uiCfg.curSprayerChoose,gCfgItems.filamentchange_unload_length,gCfgItems.filamentchange_unload_speed); - queue.inject_P(PSTR(public_buf_m)); + sprintf_P(public_buf_m, PSTR("T%d\nG91\nG1 E-%d F%d\nG90"), uiCfg.curSprayerChoose, gCfgItems.filamentchange_unload_length, gCfgItems.filamentchange_unload_speed); + queue.inject(public_buf_m); } if (((abs((int)((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius - gCfgItems.filament_limit_temper)) <= 1) @@ -682,9 +527,8 @@ void filament_dialog_handle() { lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED); } - if ( uiCfg.dialogType == DIALOG_TYPE_FILAMENT_LOADING - || uiCfg.dialogType == DIALOG_TYPE_FILAMENT_UNLOADING - ) lv_filament_setbar(); + if (DIALOG_IS(TYPE_FILAMENT_LOADING, TYPE_FILAMENT_UNLOADING)) + lv_filament_setbar(); } void lv_filament_setbar() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h index dc5adc5ad6..c6f42d90b3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.h @@ -25,52 +25,55 @@ extern "C" { /* C-declarations for C++ */ #endif -#define DIALOG_TYPE_STOP 0 -#define DIALOG_TYPE_PRINT_FILE 1 -#define DIALOG_TYPE_REPRINT_NO_FILE 2 +enum { + DIALOG_TYPE_STOP = 0, + DIALOG_TYPE_PRINT_FILE, + DIALOG_TYPE_REPRINT_NO_FILE, -#define DIALOG_TYPE_M80_FAIL 3 //** -#define DIALOG_TYPE_MESSAGE_ERR1 4 //** + DIALOG_TYPE_M80_FAIL, + DIALOG_TYPE_MESSAGE_ERR1, -#define DIALOG_TYPE_UPDATE_ESP_FIRMARE 5 -#define DIALOG_TYPE_UPDATE_ESP_DATA 6 -#define DIALOG_TYPE_UPLOAD_FILE 7 -#define DIALOG_TYPE_UNBIND 8 + DIALOG_TYPE_UPDATE_ESP_FIRMARE, + DIALOG_TYPE_UPDATE_ESP_DATA, + DIALOG_TYPE_UPLOAD_FILE, + DIALOG_TYPE_UNBIND, -#define DIALOG_TYPE_FILAMENT_LOAD_HEAT 9 -#define DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED 10 -#define DIALOG_TYPE_FILAMENT_LOADING 11 -#define DIALOG_TYPE_FILAMENT_LOAD_COMPLETED 12 -#define DIALOG_TYPE_FILAMENT_UNLOAD_HEAT 13 -#define DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED 14 -#define DIALOG_TYPE_FILAMENT_UNLOADING 15 -#define DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED 16 + DIALOG_TYPE_FILAMENT_LOAD_HEAT, + DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED, + DIALOG_TYPE_FILAMENT_LOADING, + DIALOG_TYPE_FILAMENT_LOAD_COMPLETED, + DIALOG_TYPE_FILAMENT_UNLOAD_HEAT, + DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED, + DIALOG_TYPE_FILAMENT_UNLOADING, + DIALOG_TYPE_FILAMENT_UNLOAD_COMPLETED, -#define DIALOG_TYPE_FILE_LOADING 17 //** + DIALOG_TYPE_FILE_LOADING, -#define DIALOG_TYPE_FILAMENT_NO_PRESS 18 -#define DIALOG_TYPE_FINISH_PRINT 19 + DIALOG_TYPE_FILAMENT_NO_PRESS, + DIALOG_TYPE_FINISH_PRINT, -#define WIFI_ENABLE_TIPS 20 + DIALOG_WIFI_ENABLE_TIPS, -#define DIALOG_PAUSE_MESSAGE_PAUSING 21 -#define DIALOG_PAUSE_MESSAGE_CHANGING 22 -#define DIALOG_PAUSE_MESSAGE_UNLOAD 23 -#define DIALOG_PAUSE_MESSAGE_WAITING 24 -#define DIALOG_PAUSE_MESSAGE_INSERT 25 -#define DIALOG_PAUSE_MESSAGE_LOAD 26 -#define DIALOG_PAUSE_MESSAGE_PURGE 27 -#define DIALOG_PAUSE_MESSAGE_RESUME 28 -#define DIALOG_PAUSE_MESSAGE_HEAT 29 -#define DIALOG_PAUSE_MESSAGE_HEATING 30 -#define DIALOG_PAUSE_MESSAGE_OPTION 31 + DIALOG_PAUSE_MESSAGE_PAUSING, + DIALOG_PAUSE_MESSAGE_CHANGING, + DIALOG_PAUSE_MESSAGE_UNLOAD, + DIALOG_PAUSE_MESSAGE_WAITING, + DIALOG_PAUSE_MESSAGE_INSERT, + DIALOG_PAUSE_MESSAGE_LOAD, + DIALOG_PAUSE_MESSAGE_PURGE, + DIALOG_PAUSE_MESSAGE_RESUME, + DIALOG_PAUSE_MESSAGE_HEAT, + DIALOG_PAUSE_MESSAGE_HEATING, + DIALOG_PAUSE_MESSAGE_OPTION, -#define DIALOG_STORE_EEPROM_TIPS 32 -#define DIALOG_READ_EEPROM_TIPS 33 -#define DIALOG_REVERT_EEPROM_TIPS 34 + DIALOG_STORE_EEPROM_TIPS, + DIALOG_READ_EEPROM_TIPS, + DIALOG_REVERT_EEPROM_TIPS, + + DIALOG_WIFI_CONFIG_TIPS, + DIALOG_TRANSFER_NO_DEVICE +}; -#define DIALOG_WIFI_CONFIG_TIPS 35 -#define DIALOG_TRANSFER_NO_DEVICE 36 #define BTN_OK_X 100 #define BTN_OK_Y 180 #define BTN_CANCEL_X 280 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp index 08fdb007fc..924c69536a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_eeprom_settings.cpp @@ -28,190 +28,48 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_EEPROM_RETURN 1 -#define ID_EEPROM_STORE 2 -#define ID_EEPROM_STORE_ARROW 3 -#define ID_EEPROM_READ 4 -#define ID_EEPROM_READ_ARROW 5 -#define ID_EEPROM_REVERT 6 -#define ID_EEPROM_REVERT_ARROW 7 +enum { + ID_EEPROM_RETURN = 1, + ID_EEPROM_STORE, + ID_EEPROM_STORE_ARROW, + ID_EEPROM_READ, + ID_EEPROM_READ_ARROW, + ID_EEPROM_REVERT, + ID_EEPROM_REVERT_ARROW +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_EEPROM_RETURN: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - draw_return_ui(); - } + lv_clear_eeprom_settings(); + draw_return_ui(); break; case ID_EEPROM_STORE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_STORE_EEPROM_TIPS); - } - break; - case ID_EEPROM_STORE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_STORE_EEPROM_TIPS); - } + lv_clear_eeprom_settings(); + lv_draw_dialog(DIALOG_STORE_EEPROM_TIPS); break; #if 0 case ID_EEPROM_READ: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_READ_EEPROM_TIPS); - } - break; - case ID_EEPROM_READ_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_READ_EEPROM_TIPS); - } + lv_clear_eeprom_settings(); + lv_draw_dialog(DIALOG_READ_EEPROM_TIPS); break; #endif - case ID_EEPROM_REVERT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_REVERT_EEPROM_TIPS); - } - break; - case ID_EEPROM_REVERT_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_eeprom_settings(); - lv_draw_dialog(DIALOG_REVERT_EEPROM_TIPS); - } + lv_clear_eeprom_settings(); + lv_draw_dialog(DIALOG_REVERT_EEPROM_TIPS); break; } } void lv_draw_eeprom_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonStore,*labelStore,*buttonStoreNarrow; - //lv_obj_t *buttonRead,*labelRead,*buttonReadNarrow; - lv_obj_t *buttonRevert, *labelRevert, *buttonRevertNarrow; - lv_obj_t * line1, * line2; //* line3; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != EEPROM_SETTINGS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = EEPROM_SETTINGS_UI; - } - disp_state = EEPROM_SETTINGS_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonRevert = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonRevert, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonRevert, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonRevert, event_handler, ID_EEPROM_REVERT, NULL, 0); - lv_btn_set_style(buttonRevert, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonRevert, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonRevert, LV_LAYOUT_OFF); - labelRevert = lv_label_create(buttonRevert, NULL); /*Add a label to the button*/ - - buttonRevertNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonRevertNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonRevertNarrow, event_handler, ID_EEPROM_REVERT_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonRevertNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonRevertNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonRevertNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonRevertNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonRevertNarrow, LV_LAYOUT_OFF); - - //line3 = lv_line_create(scr, NULL); - //lv_ex_line(line3,line_points[2]); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonStore = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonStore, PARA_UI_POS_X, PARA_UI_POS_Y * 2); /*Set its position*/ - lv_obj_set_size(buttonStore, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonStore, event_handler, ID_EEPROM_STORE, NULL, 0); - lv_btn_set_style(buttonStore, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonStore, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonStore, LV_LAYOUT_OFF); - labelStore = lv_label_create(buttonStore, NULL); /*Add a label to the button*/ - - buttonStoreNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonStoreNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonStoreNarrow, event_handler, ID_EEPROM_STORE_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonStoreNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonStoreNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonStoreNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonStoreNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonStoreNarrow, LV_LAYOUT_OFF); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_EEPROM_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelStore, eeprom_menu.store); - lv_obj_align(labelStore, buttonStore, LV_ALIGN_IN_LEFT_MID,0, 0); - - //lv_label_set_text(labelRead, eeprom_menu.read); - //lv_obj_align(labelRead, buttonRead, LV_ALIGN_IN_LEFT_MID,0, 0); - - lv_label_set_text(labelRevert, eeprom_menu.revert); - lv_obj_align(labelRevert, buttonRevert, LV_ALIGN_IN_LEFT_MID, 0, 0); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonRevert); - lv_group_add_obj(g, buttonStore); - lv_group_add_obj(g, buttonBack); - } - #endif - + scr = lv_screen_create(EEPROM_SETTINGS_UI); + lv_screen_menu_item(scr, eeprom_menu.revert, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_EEPROM_REVERT, 0); + lv_screen_menu_item(scr, eeprom_menu.store, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_EEPROM_STORE, 1); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_EEPROM_RETURN, true); } void lv_clear_eeprom_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp index 1476fe0a74..c9c2d4f28d 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_encoder_settings.cpp @@ -30,108 +30,34 @@ #if BUTTONS_EXIST(EN1, EN2) -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * buttonEncoderState = NULL; -static lv_obj_t *labelEncoderState = NULL; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *buttonEncoderState = nullptr; -#define ID_ENCODER_RETURN 1 -#define ID_ENCODER_STATE 2 +enum { + ID_ENCODER_RETURN = 1, + ID_ENCODER_STATE +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_ENCODER_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_encoder_settings(); - draw_return_ui(); - } + lv_clear_encoder_settings(); + draw_return_ui(); break; case ID_ENCODER_STATE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - gCfgItems.encoder_enable ^= true; - lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_REL, gCfgItems.encoder_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_PR, gCfgItems.encoder_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin"); - lv_label_set_text(labelEncoderState, machine_menu.enable); - update_spi_flash(); - } + gCfgItems.encoder_enable ^= true; + lv_screen_menu_item_onoff_update(buttonEncoderState, gCfgItems.encoder_enable); + update_spi_flash(); break; } } void lv_draw_encoder_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *labelEncoderTips = NULL; - - lv_obj_t * line1 = NULL; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ENCODER_SETTINGS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = ENCODER_SETTINGS_UI; - } - disp_state = ENCODER_SETTINGS_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.EncoderConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - labelEncoderTips = lv_label_create(scr, NULL); - lv_obj_set_style(labelEncoderTips, &tft_style_label_rel); - lv_obj_set_pos(labelEncoderTips, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelEncoderTips, machine_menu.EncoderConfText); - - buttonEncoderState = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonEncoderState, PARA_UI_STATE_POS_X, PARA_UI_POS_Y + PARA_UI_STATE_V); - lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_REL, gCfgItems.encoder_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonEncoderState, LV_BTN_STATE_PR, gCfgItems.encoder_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin"); - - lv_obj_set_event_cb_mks(buttonEncoderState, event_handler, ID_ENCODER_STATE, NULL, 0); - - lv_imgbtn_set_style(buttonEncoderState, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonEncoderState, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonEncoderState, LV_LAYOUT_OFF); - labelEncoderState = lv_label_create(buttonEncoderState, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_ENCODER_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - lv_label_set_text(labelEncoderState, gCfgItems.encoder_enable ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelEncoderState, buttonEncoderState, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonEncoderState); - lv_group_add_obj(g, buttonBack); - } - #endif + scr = lv_screen_create(ENCODER_SETTINGS_UI, machine_menu.EncoderConfTitle); + buttonEncoderState = lv_screen_menu_item_onoff(scr, machine_menu.EncoderConfText, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_ENCODER_STATE, 0, gCfgItems.encoder_enable); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_ENCODER_RETURN, true); } void lv_clear_encoder_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp index 2a20fe39f4..a484f14087 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp @@ -36,41 +36,24 @@ #include "mks_hardware_test.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; void lv_draw_error_message(PGM_P const msg) { #if 0 - static lv_obj_t * message = NULL, *kill_message = NULL, *reset_tips = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ERROR_MESSAGE_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = ERROR_MESSAGE_UI; - } - disp_state = ERROR_MESSAGE_UI; + static lv_obj_t *message = nullptr, *kill_message = nullptr, *reset_tips = nullptr; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(ERROR_MESSAGE_UI, ""); if (msg) { - message = lv_label_create(scr, NULL); - lv_obj_set_style(message, &tft_style_label_rel); - lv_label_set_text(message, msg); - lv_obj_align(message, NULL, LV_ALIGN_CENTER, 0, -50); + message = lv_label_create(scr, msg); + lv_obj_align(message, nullptr, LV_ALIGN_CENTER, 0, -50); } - kill_message = lv_label_create(scr, NULL); - lv_obj_set_style(kill_message, &tft_style_label_rel); - lv_label_set_text(kill_message, "PRINTER HALTED"); - lv_obj_align(kill_message, NULL, LV_ALIGN_CENTER, 0, -10); + kill_message = lv_label_create(scr, "PRINTER HALTED"); + lv_obj_align(kill_message, nullptr, LV_ALIGN_CENTER, 0, -10); - reset_tips = lv_label_create(scr, NULL); - lv_obj_set_style(reset_tips, &tft_style_label_rel); - lv_label_set_text(reset_tips, "Please Reset"); - lv_obj_align(reset_tips, NULL, LV_ALIGN_CENTER, 0, 30); + reset_tips = lv_label_create(scr, "Please Reset"); + lv_obj_align(reset_tips, nullptr, LV_ALIGN_CENTER, 0, 30); lv_task_handler(); #endif diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp index 4bd320b640..6a1c0c4fb3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp @@ -34,274 +34,156 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; -extern lv_group_t* g; -static lv_obj_t * buttoType, *buttonStep, *buttonSpeed; +static lv_obj_t *scr; +extern lv_group_t *g; +static lv_obj_t *buttonType, *buttonStep, *buttonSpeed; static lv_obj_t *labelType; static lv_obj_t *labelStep; static lv_obj_t *labelSpeed; -static lv_obj_t * tempText; -static lv_obj_t * ExtruText; +static lv_obj_t *tempText; +static lv_obj_t *ExtruText; -#define ID_E_ADD 1 -#define ID_E_DEC 2 -#define ID_E_TYPE 3 -#define ID_E_STEP 4 -#define ID_E_SPEED 5 -#define ID_E_RETURN 6 +enum { + ID_E_ADD = 1, + ID_E_DEC, + ID_E_TYPE, + ID_E_STEP, + ID_E_SPEED, + ID_E_RETURN +}; -static int32_t extructAmount; +static int32_t extrudeAmount; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_E_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { - queue.enqueue_now_P(PSTR("G91")); - ZERO(public_buf_l); - sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), uiCfg.extruStep, 60 * uiCfg.extruSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - extructAmount += uiCfg.extruStep; - disp_extru_amount(); - } - } - break; - case ID_E_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { - queue.enqueue_now_P(PSTR("G91")); - ZERO(public_buf_l); - sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), 0 - uiCfg.extruStep, 60 * uiCfg.extruSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - extructAmount -= uiCfg.extruStep; - disp_extru_amount(); - } - } - break; - case ID_E_TYPE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (ENABLED(HAS_MULTI_EXTRUDER)) { - if (uiCfg.curSprayerChoose == 0) { - uiCfg.curSprayerChoose = 1; - queue.inject_P(PSTR("T1")); - } - else { - uiCfg.curSprayerChoose = 0; - queue.inject_P(PSTR("T0")); - } - } - else - uiCfg.curSprayerChoose = 0; - - extructAmount = 0; - disp_hotend_temp(); - disp_ext_type(); + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), uiCfg.extruStep, 60 * uiCfg.extruSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); + extrudeAmount += uiCfg.extruStep; disp_extru_amount(); } break; - case ID_E_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do + case ID_E_DEC: + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= EXTRUDE_MINTEMP) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P((char *)public_buf_l, PSTR("G1 E%d F%d"), 0 - uiCfg.extruStep, 60 * uiCfg.extruSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); + extrudeAmount -= uiCfg.extruStep; + disp_extru_amount(); } - else if (event == LV_EVENT_RELEASED) { - switch (abs(uiCfg.extruStep)) { - case 1: uiCfg.extruStep = 5; break; - case 5: uiCfg.extruStep = 10; break; - case 10: uiCfg.extruStep = 1; break; - default: break; + break; + case ID_E_TYPE: + if (ENABLED(HAS_MULTI_EXTRUDER)) { + if (uiCfg.curSprayerChoose == 0) { + uiCfg.curSprayerChoose = 1; + queue.inject_P(PSTR("T1")); + } + else { + uiCfg.curSprayerChoose = 0; + queue.inject_P(PSTR("T0")); } - disp_ext_step(); } + else + uiCfg.curSprayerChoose = 0; + + extrudeAmount = 0; + disp_hotend_temp(); + disp_ext_type(); + disp_extru_amount(); + break; + case ID_E_STEP: + switch (abs(uiCfg.extruStep)) { + case 1: uiCfg.extruStep = 5; break; + case 5: uiCfg.extruStep = 10; break; + case 10: uiCfg.extruStep = 1; break; + default: break; + } + disp_ext_step(); break; case ID_E_SPEED: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - switch (uiCfg.extruSpeed) { - case 1: uiCfg.extruSpeed = 10; break; - case 10: uiCfg.extruSpeed = 20; break; - case 20: uiCfg.extruSpeed = 1; break; - default: break; - } - disp_ext_speed(); + switch (uiCfg.extruSpeed) { + case 1: uiCfg.extruSpeed = 10; break; + case 10: uiCfg.extruSpeed = 20; break; + case 20: uiCfg.extruSpeed = 1; break; + default: break; } + disp_ext_speed(); break; case ID_E_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_extrusion(void) { - lv_obj_t *buttonAdd, *buttonDec, *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != EXTRUSION_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = EXTRUSION_UI; - } - disp_state = EXTRUSION_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - + scr = lv_screen_create(EXTRUSION_UI); // Create image buttons - buttonAdd = lv_imgbtn_create(scr, NULL); - buttonDec = lv_imgbtn_create(scr, NULL); - buttoType = lv_imgbtn_create(scr, NULL); - buttonStep = lv_imgbtn_create(scr, NULL); - buttonSpeed = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_E_ADD, NULL, 0); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, "F:/bmp_in.bin"); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, "F:/bmp_in.bin"); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_label_rel); + lv_obj_t *buttonAdd = lv_big_button_create(scr, "F:/bmp_in.bin", extrude_menu.in, INTERVAL_V, titleHeight, event_handler, ID_E_ADD); lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW); + lv_big_button_create(scr, "F:/bmp_out.bin", extrude_menu.out, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_E_DEC); - #if 1 - lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_E_DEC, NULL, 0); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, "F:/bmp_out.bin"); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, "F:/bmp_out.bin"); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttoType, event_handler, ID_E_TYPE, NULL, 0); - lv_imgbtn_set_style(buttoType, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttoType, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonStep, event_handler, ID_E_STEP, NULL, 0); - lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonSpeed, event_handler, ID_E_SPEED, NULL, 0); - lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_E_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttoType, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonStep, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonSpeed, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF); - lv_btn_set_layout(buttoType, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonStep, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonSpeed, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelAdd = lv_label_create(buttonAdd, NULL); - lv_obj_t *labelDec = lv_label_create(buttonDec, NULL); - labelType = lv_label_create(buttoType, NULL); - labelStep = lv_label_create(buttonStep, NULL); - labelSpeed = lv_label_create(buttonSpeed, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, extrude_menu.in); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, extrude_menu.out); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } + buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_TYPE); + buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_STEP); + buttonSpeed = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_SPEED); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); - lv_group_add_obj(g, buttoType); + lv_group_add_obj(g, buttonType); lv_group_add_obj(g, buttonStep); lv_group_add_obj(g, buttonSpeed); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_E_RETURN); + + // Create labels on the image buttons + labelType = lv_label_create_empty(buttonType); + labelStep = lv_label_create_empty(buttonStep); + labelSpeed = lv_label_create_empty(buttonSpeed); + disp_ext_type(); disp_ext_step(); disp_ext_speed(); - tempText = lv_label_create(scr, NULL); + tempText = lv_label_create_empty(scr); lv_obj_set_style(tempText, &tft_style_label_rel); disp_hotend_temp(); - ExtruText = lv_label_create(scr, NULL); + ExtruText = lv_label_create_empty(scr); lv_obj_set_style(ExtruText, &tft_style_label_rel); disp_extru_amount(); } void disp_ext_type() { if (uiCfg.curSprayerChoose == 1) { - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru2.bin"); - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru2.bin"); + lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru2.bin"); if (gCfgItems.multiple_language) { lv_label_set_text(labelType, extrude_menu.ext2); - lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } else { - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru1.bin"); - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru1.bin"); + lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin"); if (gCfgItems.multiple_language) { lv_label_set_text(labelType, extrude_menu.ext1); - lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } } void disp_ext_speed() { - if (uiCfg.extruSpeed == 20) { - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_REL, "F:/bmp_speed_high.bin"); - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_PR, "F:/bmp_speed_high.bin"); - } - else if (uiCfg.extruSpeed == 1) { - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_REL, "F:/bmp_speed_slow.bin"); - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_PR, "F:/bmp_speed_slow.bin"); - } - else { - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_REL, "F:/bmp_speed_normal.bin"); - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_PR, "F:/bmp_speed_normal.bin"); - } + if (uiCfg.extruSpeed == 20) + lv_imgbtn_set_src_both(buttonSpeed, "F:/bmp_speed_high.bin"); + else if (uiCfg.extruSpeed == 1) + lv_imgbtn_set_src_both(buttonSpeed, "F:/bmp_speed_slow.bin"); + else + lv_imgbtn_set_src_both(buttonSpeed, "F:/bmp_speed_normal.bin"); if (gCfgItems.multiple_language) { if (uiCfg.extruSpeed == 20) { @@ -321,12 +203,11 @@ void disp_ext_speed() { void disp_hotend_temp() { char buf[20] = {0}; - public_buf_l[0] = '\0'; - strcat(public_buf_l, extrude_menu.temper_text); - sprintf(buf, extrude_menu.temp_value, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); + sprintf(buf, extrude_menu.temp_value, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); + strcpy(public_buf_l, extrude_menu.temper_text); strcat(public_buf_l, buf); lv_label_set_text(tempText, public_buf_l); - lv_obj_align(tempText, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText, nullptr, LV_ALIGN_CENTER, 0, -50); } void disp_extru_amount() { @@ -334,48 +215,26 @@ void disp_extru_amount() { public_buf_l[0] = '\0'; - if (extructAmount < 999 && extructAmount > -99) { - sprintf(buf1, extrude_menu.count_value_mm, extructAmount); - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, extrude_menu.ext1); - else - strcat(public_buf_l, extrude_menu.ext2); - strcat(public_buf_l, buf1); - } - else if (extructAmount < 9999 && extructAmount > -999) { - sprintf(buf1, extrude_menu.count_value_cm, extructAmount / 10); - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, extrude_menu.ext1); - else - strcat(public_buf_l, extrude_menu.ext2); - strcat(public_buf_l, buf1); - } - else { - sprintf(buf1, extrude_menu.count_value_m, extructAmount / 1000); - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, extrude_menu.ext1); - else - strcat(public_buf_l, extrude_menu.ext2); - strcat(public_buf_l, buf1); - } + if (extrudeAmount < 999 && extrudeAmount > -99) + sprintf(buf1, extrude_menu.count_value_mm, extrudeAmount); + else if (extrudeAmount < 9999 && extrudeAmount > -999) + sprintf(buf1, extrude_menu.count_value_cm, extrudeAmount / 10); + else + sprintf(buf1, extrude_menu.count_value_m, extrudeAmount / 1000); + strcat(public_buf_l, uiCfg.curSprayerChoose < 1 ? extrude_menu.ext1 : extrude_menu.ext2); + strcat(public_buf_l, buf1); lv_label_set_text(ExtruText, public_buf_l); - lv_obj_align(ExtruText, NULL, LV_ALIGN_CENTER, 0, -75); + lv_obj_align(ExtruText, nullptr, LV_ALIGN_CENTER, 0, -75); } void disp_ext_step() { - if (uiCfg.extruStep == 1) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step1_mm.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step1_mm.bin"); - } - else if (uiCfg.extruStep == 5) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step5_mm.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step5_mm.bin"); - } - else if (uiCfg.extruStep == 10) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step10_mm.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step10_mm.bin"); - } + if (uiCfg.extruStep == 1) + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step1_mm.bin"); + else if (uiCfg.extruStep == 5) + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step5_mm.bin"); + else if (uiCfg.extruStep == 10) + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step10_mm.bin"); if (gCfgItems.multiple_language) { if (uiCfg.extruStep == 1) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp index 5d7bb335dc..5453bbf86b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp @@ -35,211 +35,72 @@ #include "../../../../gcode/gcode.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t * fanText; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *fanText; -#define ID_F_ADD 1 -#define ID_F_DEC 2 -#define ID_F_HIGH 3 -#define ID_F_MID 4 -#define ID_F_OFF 5 -#define ID_F_RETURN 6 +enum { + ID_F_ADD = 1, + ID_F_DEC, + ID_F_HIGH, + ID_F_MID, + ID_F_OFF, + ID_F_RETURN +}; static uint8_t fanSpeed; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_F_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (fanSpeed + 1 <= 255) { - fanSpeed++; - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); - gcode.process_subcommands_now(public_buf_l); - } + if (fanSpeed + 1 <= 255) { + fanSpeed++; + sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); + gcode.process_subcommands_now(public_buf_l); } break; case ID_F_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (fanSpeed > 0) { + fanSpeed--; + sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); + gcode.process_subcommands_now(public_buf_l); } - else if (event == LV_EVENT_RELEASED) { - if (fanSpeed > 0) { - fanSpeed--; - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed); - gcode.process_subcommands_now(public_buf_l); - } - } - break; case ID_F_HIGH: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - gcode.process_subcommands_now_P(PSTR("M106 S255")); - } + gcode.process_subcommands_now_P(PSTR("M106 S255")); break; case ID_F_MID: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - gcode.process_subcommands_now_P(PSTR("M106 S127")); - } + gcode.process_subcommands_now_P(PSTR("M106 S127")); break; case ID_F_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - gcode.process_subcommands_now_P(PSTR("M107")); - } + gcode.process_subcommands_now_P(PSTR("M107")); break; case ID_F_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_fan(void) { - lv_obj_t *buttonAdd, *buttonDec, *buttonHigh, *buttonMid; - lv_obj_t *buttonOff, *buttonBack; + lv_obj_t *buttonAdd; #if HAS_FAN fanSpeed = thermalManager.fan_speed[0]; #endif - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FAN_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = FAN_UI; - } - disp_state = FAN_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(FAN_UI); // Create an Image button - buttonAdd = lv_imgbtn_create(scr, NULL); - buttonDec = lv_imgbtn_create(scr, NULL); - buttonHigh = lv_imgbtn_create(scr, NULL); - buttonMid = lv_imgbtn_create(scr, NULL); - buttonOff = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_F_ADD, NULL, 0); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, "F:/bmp_Add.bin"); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, "F:/bmp_Add.bin"); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_label_rel); + buttonAdd = lv_big_button_create(scr, "F:/bmp_Add.bin", fan_menu.add, INTERVAL_V, titleHeight, event_handler, ID_F_ADD); lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW); + lv_big_button_create(scr, "F:/bmp_Dec.bin", fan_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_F_DEC); + lv_big_button_create(scr, "F:/bmp_speed255.bin", fan_menu.full, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_HIGH); + lv_big_button_create(scr, "F:/bmp_speed127.bin", fan_menu.half, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_MID); + lv_big_button_create(scr, "F:/bmp_speed0.bin", fan_menu.off, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_OFF); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_RETURN); - #if 1 - lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_F_DEC, NULL, 0); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, "F:/bmp_Dec.bin"); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, "F:/bmp_Dec.bin"); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonHigh, event_handler,ID_F_HIGH, NULL,0); - lv_imgbtn_set_src(buttonHigh, LV_BTN_STATE_REL, "F:/bmp_speed255.bin"); - lv_imgbtn_set_src(buttonHigh, LV_BTN_STATE_PR, "F:/bmp_speed255.bin"); - lv_imgbtn_set_style(buttonHigh, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonHigh, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonMid, event_handler,ID_F_MID, NULL,0); - lv_imgbtn_set_src(buttonMid, LV_BTN_STATE_REL, "F:/bmp_speed127.bin"); - lv_imgbtn_set_src(buttonMid, LV_BTN_STATE_PR, "F:/bmp_speed127.bin"); - lv_imgbtn_set_style(buttonMid, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMid, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonOff, event_handler,ID_F_OFF, NULL,0); - lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_REL, "F:/bmp_speed0.bin"); - lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_PR, "F:/bmp_speed0.bin"); - lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_F_RETURN, NULL,0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - #endif - - lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonHigh, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonMid, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonOff, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonHigh, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonMid, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonOff, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelAdd = lv_label_create(buttonAdd, NULL); - lv_obj_t *labelDec = lv_label_create(buttonDec, NULL); - lv_obj_t *labelHigh = lv_label_create(buttonHigh, NULL); - lv_obj_t *labelMid = lv_label_create(buttonMid, NULL); - lv_obj_t *labelOff = lv_label_create(buttonOff, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, fan_menu.add); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, fan_menu.dec); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHigh, fan_menu.full); - lv_obj_align(labelHigh, buttonHigh, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelMid, fan_menu.half); - lv_obj_align(labelMid, buttonMid, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOff, fan_menu.off); - lv_obj_align(labelOff, buttonOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); - lv_group_add_obj(g, buttonHigh); - lv_group_add_obj(g, buttonMid); - lv_group_add_obj(g, buttonOff); - lv_group_add_obj(g, buttonBack); - } - #endif - - fanText = lv_label_create(scr, NULL); + fanText = lv_label_create_empty(scr); lv_obj_set_style(fanText, &tft_style_label_rel); disp_fan_value(); } @@ -252,7 +113,7 @@ void disp_fan_value() { sprintf_P(buf1, PSTR("%3d"), thermalManager.fan_speed[0]); strcat(public_buf_l, buf1); lv_label_set_text(fanText, public_buf_l); - lv_obj_align(fanText, NULL, LV_ALIGN_CENTER, 0, -65); + lv_obj_align(fanText, nullptr, LV_ALIGN_CENTER, 0, -65); } void lv_clear_fan() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp index 4c9060c6a2..1db11a20e6 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp @@ -32,212 +32,124 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t *buttoType; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *buttonType; static lv_obj_t *labelType; -static lv_obj_t * tempText1; +static lv_obj_t *tempText1; -#define ID_FILAMNT_IN 1 -#define ID_FILAMNT_OUT 2 -#define ID_FILAMNT_TYPE 3 -#define ID_FILAMNT_RETURN 4 +enum { + ID_FILAMNT_IN = 1, + ID_FILAMNT_OUT, + ID_FILAMNT_TYPE, + ID_FILAMNT_RETURN +}; extern feedRate_t feedrate_mm_s; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_FILAMNT_IN: - if (event == LV_EVENT_CLICKED) { - // nothing to do + uiCfg.filament_load_heat_flg = 1; + if ((abs(thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius) <= 1) + || (gCfgItems.filament_limit_temper <= thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); } - else if (event == LV_EVENT_RELEASED) { - uiCfg.filament_load_heat_flg = 1; - if ((abs(thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius) <= 1) - || (gCfgItems.filament_limit_temper <= thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_LOAD_COMPLETED); - } - else { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT); - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); - } + else { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_LOAD_HEAT); + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } } break; case ID_FILAMNT_OUT: - if (event == LV_EVENT_CLICKED) { - // nothing to do + uiCfg.filament_unload_heat_flg=1; + if ((thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > 0) + && ((abs((int)((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) <= 1) + || ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= gCfgItems.filament_limit_temper)) + ) { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); } - else if (event == LV_EVENT_RELEASED) { - uiCfg.filament_unload_heat_flg=1; - if ((thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > 0) - && ((abs((int)((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target - thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius)) <= 1) - || ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius >= gCfgItems.filament_limit_temper)) - ) { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED); - } - else { - lv_clear_filament_change(); - lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT); - if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); - } - filament_sprayer_temp(); + else { + lv_clear_filament_change(); + lv_draw_dialog(DIALOG_TYPE_FILAMENT_UNLOAD_HEAT); + if (thermalManager.temp_hotend[uiCfg.curSprayerChoose].target < gCfgItems.filament_limit_temper) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = gCfgItems.filament_limit_temper; + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } + filament_sprayer_temp(); } break; case ID_FILAMNT_TYPE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_MULTI_EXTRUDER - if (uiCfg.curSprayerChoose == 0) - uiCfg.curSprayerChoose = 1; - else if (uiCfg.curSprayerChoose == 1) - uiCfg.curSprayerChoose = 0; - #endif - disp_filament_type(); - } + #if HAS_MULTI_EXTRUDER + if (uiCfg.curSprayerChoose == 0) + uiCfg.curSprayerChoose = 1; + else if (uiCfg.curSprayerChoose == 1) + uiCfg.curSprayerChoose = 0; + #endif + disp_filament_type(); break; case ID_FILAMNT_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_MULTI_EXTRUDER - if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED) - gcode.process_subcommands_now_P(uiCfg.curSprayerChoose_bak == 1 ? PSTR("T1") : PSTR("T0")); - #endif - feedrate_mm_s = (float)uiCfg.moveSpeed_bak; - if (uiCfg.print_state == PAUSED) - planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak)); - //current_position.e = destination.e = uiCfg.current_e_position_bak; - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; + #if HAS_MULTI_EXTRUDER + if (uiCfg.print_state != IDLE && uiCfg.print_state != REPRINTED) + gcode.process_subcommands_now_P(uiCfg.curSprayerChoose_bak == 1 ? PSTR("T1") : PSTR("T0")); + #endif + feedrate_mm_s = (float)uiCfg.moveSpeed_bak; + if (uiCfg.print_state == PAUSED) + planner.set_e_position_mm((destination.e = current_position.e = uiCfg.current_e_position_bak)); + //current_position.e = destination.e = uiCfg.current_e_position_bak; + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = uiCfg.desireSprayerTempBak; - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_filament_change(void) { - lv_obj_t *buttonIn, *buttonOut; - lv_obj_t *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FILAMENTCHANGE_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = FILAMENTCHANGE_UI; - } - disp_state = FILAMENTCHANGE_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - + scr = lv_screen_create(FILAMENTCHANGE_UI); // Create an Image button - buttonIn = lv_imgbtn_create(scr, NULL); - buttonOut = lv_imgbtn_create(scr, NULL); - buttoType = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonIn, event_handler, ID_FILAMNT_IN, NULL, 0); - lv_imgbtn_set_src(buttonIn, LV_BTN_STATE_REL, "F:/bmp_in.bin"); - lv_imgbtn_set_src(buttonIn, LV_BTN_STATE_PR, "F:/bmp_in.bin"); - lv_imgbtn_set_style(buttonIn, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonIn, LV_BTN_STATE_REL, &tft_style_label_rel); + lv_obj_t *buttonIn = lv_big_button_create(scr, "F:/bmp_in.bin", filament_menu.in, INTERVAL_V, titleHeight, event_handler, ID_FILAMNT_IN); lv_obj_clear_protect(buttonIn, LV_PROTECT_FOLLOW); + lv_big_button_create(scr, "F:/bmp_out.bin", filament_menu.out, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_FILAMNT_OUT); - lv_obj_set_event_cb_mks(buttonOut, event_handler, ID_FILAMNT_OUT, NULL, 0); - lv_imgbtn_set_src(buttonOut, LV_BTN_STATE_REL, "F:/bmp_out.bin"); - lv_imgbtn_set_src(buttonOut, LV_BTN_STATE_PR, "F:/bmp_out.bin"); - lv_imgbtn_set_style(buttonOut, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonOut, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttoType, event_handler, ID_FILAMNT_TYPE, NULL, 0); - lv_imgbtn_set_style(buttoType, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttoType, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_FILAMNT_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_pos(buttonIn, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonOut, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttoType, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonIn, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonOut, LV_LAYOUT_OFF); - lv_btn_set_layout(buttoType, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelIn = lv_label_create(buttonIn, NULL); - lv_obj_t *labelOut = lv_label_create(buttonOut, NULL); - labelType = lv_label_create(buttoType, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelIn, filament_menu.in); - lv_obj_align(labelIn, buttonIn, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOut, filament_menu.out); - lv_obj_align(labelOut, buttonOut, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - + buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_TYPE); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonIn); - lv_group_add_obj(g, buttonOut); - lv_group_add_obj(g, buttoType); - lv_group_add_obj(g, buttonBack); + lv_group_add_obj(g, buttonType); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FILAMNT_RETURN); + + // Create labels on the image buttons + labelType = lv_label_create_empty(buttonType); + disp_filament_type(); - tempText1 = lv_label_create(scr, NULL); + tempText1 = lv_label_create_empty(scr); lv_obj_set_style(tempText1, &tft_style_label_rel); disp_filament_temp(); } void disp_filament_type() { if (uiCfg.curSprayerChoose == 1) { - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru2.bin"); - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru2.bin"); + lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru2.bin"); if (gCfgItems.multiple_language) { lv_label_set_text(labelType, preheat_menu.ext2); - lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } else { - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru1.bin"); - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru1.bin"); + lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin"); if (gCfgItems.multiple_language) { lv_label_set_text(labelType, preheat_menu.ext1); - lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } } @@ -247,16 +159,13 @@ void disp_filament_temp() { public_buf_l[0] = '\0'; - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, preheat_menu.ext1); - else - strcat(public_buf_l, preheat_menu.ext2); + strcat(public_buf_l, uiCfg.curSprayerChoose < 1 ? preheat_menu.ext1 : preheat_menu.ext2); sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); strcat_P(public_buf_l, PSTR(": ")); strcat(public_buf_l, buf); lv_label_set_text(tempText1, public_buf_l); - lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50); } void lv_clear_filament_change() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp index 377c44edb7..2c9c3882f0 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_settings.cpp @@ -28,294 +28,92 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_FILAMENT_SET_RETURN 1 -#define ID_FILAMENT_SET_IN_LENGTH 2 -#define ID_FILAMENT_SET_IN_SPEED 3 -#define ID_FILAMENT_SET_OUT_LENGTH 4 -#define ID_FILAMENT_SET_OUT_SPEED 5 -#define ID_FILAMENT_SET_TEMP 6 -#define ID_FILAMENT_SET_DOWN 12 -#define ID_FILAMENT_SET_UP 13 +enum { + ID_FILAMENT_SET_RETURN = 1, + ID_FILAMENT_SET_IN_LENGTH, + ID_FILAMENT_SET_IN_SPEED, + ID_FILAMENT_SET_OUT_LENGTH, + ID_FILAMENT_SET_OUT_SPEED, + ID_FILAMENT_SET_TEMP, + ID_FILAMENT_SET_DOWN, + ID_FILAMENT_SET_UP +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_FILAMENT_SET_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_filament_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_filament_settings(); + draw_return_ui(); break; case ID_FILAMENT_SET_IN_LENGTH: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = load_length; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = load_length; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_IN_SPEED: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = load_speed; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = load_speed; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_OUT_LENGTH: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = unload_length; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = unload_length; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_OUT_SPEED: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = unload_speed; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = unload_speed; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_TEMP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = filament_temp; - lv_clear_filament_settings(); - lv_draw_number_key(); - } + value = filament_temp; + lv_clear_filament_settings(); + lv_draw_number_key(); break; case ID_FILAMENT_SET_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_filament_settings(); - lv_draw_filament_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_filament_settings(); + lv_draw_filament_settings(); break; case ID_FILAMENT_SET_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_filament_settings(); - lv_draw_filament_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_filament_settings(); + lv_draw_filament_settings(); break; } } void lv_draw_filament_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *labelInLengthText = NULL, *buttonInLengthValue = NULL, *labelInLengthValue = NULL; - lv_obj_t *labelInSpeedText = NULL, *buttonInSpeedValue = NULL, *labelInSpeedValue = NULL; - lv_obj_t *labelOutLengthText = NULL, *buttonOutLengthValue = NULL, *labelOutLengthValue = NULL; - lv_obj_t *labelOutSpeedText = NULL, *buttonOutSpeedValue = NULL, *labelOutSpeedValue = NULL; - lv_obj_t *labelTemperText = NULL, *buttonTemperValue = NULL, *labelTemperValue = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FILAMENT_SETTINGS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = FILAMENT_SETTINGS_UI; - } - disp_state = FILAMENT_SETTINGS_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.FilamentConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(FILAMENT_SETTINGS_UI, machine_menu.FilamentConfTitle); if (uiCfg.para_ui_page != 1) { - labelInLengthText = lv_label_create(scr, NULL); - lv_obj_set_style(labelInLengthText, &tft_style_label_rel); - lv_obj_set_pos(labelInLengthText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelInLengthText, machine_menu.InLength); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_length); + lv_screen_menu_item_1_edit(scr, machine_menu.InLength, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FILAMENT_SET_IN_LENGTH, 0, public_buf_l); - buttonInLengthValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonInLengthValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonInLengthValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonInLengthValue, event_handler, ID_FILAMENT_SET_IN_LENGTH, NULL, 0); - lv_btn_set_style(buttonInLengthValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonInLengthValue, LV_BTN_STYLE_PR, &style_para_value); - labelInLengthValue = lv_label_create(buttonInLengthValue, NULL); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_speed); + lv_screen_menu_item_1_edit(scr, machine_menu.InSpeed, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_FILAMENT_SET_IN_SPEED, 1, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_length); + lv_screen_menu_item_1_edit(scr, machine_menu.OutLength, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_FILAMENT_SET_OUT_LENGTH, 2, public_buf_l); - labelInSpeedText = lv_label_create(scr, NULL); - lv_obj_set_style(labelInSpeedText, &tft_style_label_rel); - lv_obj_set_pos(labelInSpeedText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelInSpeedText, machine_menu.InSpeed); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_speed); + lv_screen_menu_item_1_edit(scr, machine_menu.OutSpeed, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_FILAMENT_SET_OUT_SPEED, 3, public_buf_l); - buttonInSpeedValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonInSpeedValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonInSpeedValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonInSpeedValue, event_handler, ID_FILAMENT_SET_IN_SPEED, NULL, 0); - lv_btn_set_style(buttonInSpeedValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonInSpeedValue, LV_BTN_STYLE_PR, &style_para_value); - labelInSpeedValue = lv_label_create(buttonInSpeedValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelOutLengthText = lv_label_create(scr, NULL); - lv_obj_set_style(labelOutLengthText, &tft_style_label_rel); - lv_obj_set_pos(labelOutLengthText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 6); - lv_label_set_text(labelOutLengthText, machine_menu.OutLength); - - buttonOutLengthValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonOutLengthValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonOutLengthValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonOutLengthValue, event_handler, ID_FILAMENT_SET_OUT_LENGTH, NULL, 0); - lv_btn_set_style(buttonOutLengthValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonOutLengthValue, LV_BTN_STYLE_PR, &style_para_value); - labelOutLengthValue = lv_label_create(buttonOutLengthValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelOutSpeedText = lv_label_create(scr, NULL); - lv_obj_set_style(labelOutSpeedText, &tft_style_label_rel); - lv_obj_set_pos(labelOutSpeedText, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelOutSpeedText, machine_menu.OutSpeed); - - buttonOutSpeedValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonOutSpeedValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonOutSpeedValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonOutSpeedValue, event_handler, ID_FILAMENT_SET_OUT_SPEED, NULL, 0); - lv_btn_set_style(buttonOutSpeedValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonOutSpeedValue, LV_BTN_STYLE_PR, &style_para_value); - labelOutSpeedValue = lv_label_create(buttonOutSpeedValue, NULL); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_FILAMENT_SET_DOWN, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonInLengthValue); - lv_group_add_obj(g, buttonInSpeedValue); - lv_group_add_obj(g, buttonOutLengthValue); - lv_group_add_obj(g, buttonOutSpeedValue); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FILAMENT_SET_DOWN, true); } else { - labelTemperText = lv_label_create(scr, NULL); - lv_obj_set_style(labelTemperText, &tft_style_label_rel); - lv_obj_set_pos(labelTemperText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelTemperText, machine_menu.FilamentTemperature); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filament_limit_temper); + lv_screen_menu_item_1_edit(scr, machine_menu.FilamentTemperature, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FILAMENT_SET_TEMP, 0, public_buf_l); - buttonTemperValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonTemperValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonTemperValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonTemperValue, event_handler, ID_FILAMENT_SET_TEMP, NULL, 0); - lv_btn_set_style(buttonTemperValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonTemperValue, LV_BTN_STYLE_PR, &style_para_value); - labelTemperValue = lv_label_create(buttonTemperValue, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_FILAMENT_SET_UP, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonTemperValue); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FILAMENT_SET_UP, true); } - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create(buttonTurnPage, NULL); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_FILAMENT_SET_RETURN, NULL, 0); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create(buttonBack, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_length); - lv_label_set_text(labelInLengthValue, public_buf_l); - lv_obj_align(labelInLengthValue, buttonInLengthValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_load_speed); - lv_label_set_text(labelInSpeedValue, public_buf_l); - lv_obj_align(labelInSpeedValue, buttonInSpeedValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_length); - lv_label_set_text(labelOutLengthValue, public_buf_l); - lv_obj_align(labelOutLengthValue, buttonOutLengthValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filamentchange_unload_speed); - lv_label_set_text(labelOutSpeedValue, public_buf_l); - lv_obj_align(labelOutSpeedValue, buttonOutSpeedValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - else { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.filament_limit_temper); - lv_label_set_text(labelTemperValue, public_buf_l); - lv_obj_align(labelTemperValue, buttonTemperValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_FILAMENT_SET_RETURN, true); } void lv_clear_filament_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp index c7264f2765..646091bd8b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp @@ -35,212 +35,56 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_H_ALL 1 -#define ID_H_X 2 -#define ID_H_Y 3 -#define ID_H_Z 4 -#define ID_H_RETURN 5 -#define ID_H_OFF_ALL 6 -#define ID_H_OFF_XY 7 +enum { + ID_H_ALL = 1, + ID_H_X, + ID_H_Y, + ID_H_Z, + ID_H_RETURN, + ID_H_OFF_ALL, + ID_H_OFF_XY +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_H_ALL: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28")); - } + queue.inject_P(PSTR("G28")); break; case ID_H_X: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28 X0")); - } + queue.inject_P(PSTR("G28 X0")); break; case ID_H_Y: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28 Y0")); - } + queue.inject_P(PSTR("G28 Y0")); break; case ID_H_Z: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("G28 Z0")); - } + queue.inject_P(PSTR("G28 Z0")); break; case ID_H_OFF_ALL: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("M84")); - } + queue.inject_P(PSTR("M84")); break; case ID_H_OFF_XY: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - queue.inject_P(PSTR("M84 X Y")); - } + queue.inject_P(PSTR("M84 X Y")); break; case ID_H_RETURN: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_home(); - lv_draw_tool(); - } + lv_clear_home(); + lv_draw_tool(); break; } } void lv_draw_home(void) { - lv_obj_t *buttonHomeAll, *buttonHomeX, *buttonHomeY, *buttonHomeZ; - lv_obj_t *buttonBack; - lv_obj_t *buttonOffAll, *buttonOffXY; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != ZERO_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = ZERO_UI; - } - disp_state = ZERO_UI; - - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - // Create image buttons - //buttonWifi = lv_imgbtn_create(scr, NULL); - buttonHomeAll = lv_imgbtn_create(scr, NULL); - buttonHomeX = lv_imgbtn_create(scr, NULL); - //buttonContinue = lv_imgbtn_create(scr, NULL); - buttonHomeY = lv_imgbtn_create(scr, NULL); - buttonHomeZ = lv_imgbtn_create(scr, NULL); - buttonOffAll = lv_imgbtn_create(scr, NULL); - buttonOffXY = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - #if 1 - lv_obj_set_event_cb_mks(buttonHomeAll, event_handler,ID_H_ALL, NULL,0); - lv_imgbtn_set_src(buttonHomeAll, LV_BTN_STATE_REL, "F:/bmp_zeroAll.bin"); - lv_imgbtn_set_src(buttonHomeAll, LV_BTN_STATE_PR, "F:/bmp_zeroAll.bin"); - lv_imgbtn_set_style(buttonHomeAll, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonHomeAll, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonHomeX, event_handler, ID_H_X, NULL, 0); - lv_imgbtn_set_src(buttonHomeX, LV_BTN_STATE_REL, "F:/bmp_zeroX.bin"); - lv_imgbtn_set_src(buttonHomeX, LV_BTN_STATE_PR, "F:/bmp_zeroX.bin"); - lv_imgbtn_set_style(buttonHomeX, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonHomeX, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonHomeY, event_handler, ID_H_Y, NULL, 0); - lv_imgbtn_set_src(buttonHomeY, LV_BTN_STATE_REL, "F:/bmp_zeroY.bin"); - lv_imgbtn_set_src(buttonHomeY, LV_BTN_STATE_PR, "F:/bmp_zeroY.bin"); - lv_imgbtn_set_style(buttonHomeY, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonHomeY, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonHomeZ, event_handler, ID_H_Z, NULL, 0); - lv_imgbtn_set_src(buttonHomeZ, LV_BTN_STATE_REL, "F:/bmp_zeroZ.bin"); - lv_imgbtn_set_src(buttonHomeZ, LV_BTN_STATE_PR, "F:/bmp_zeroZ.bin"); - lv_imgbtn_set_style(buttonHomeZ, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonHomeZ, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonOffAll, event_handler,ID_H_OFF_ALL, NULL,0); - lv_imgbtn_set_src(buttonOffAll, LV_BTN_STATE_REL, "F:/bmp_function1.bin"); - lv_imgbtn_set_src(buttonOffAll, LV_BTN_STATE_PR, "F:/bmp_function1.bin"); - lv_imgbtn_set_style(buttonOffAll, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonOffAll, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonOffXY, event_handler,ID_H_OFF_XY, NULL,0); - lv_imgbtn_set_src(buttonOffXY, LV_BTN_STATE_REL, "F:/bmp_function1.bin"); - lv_imgbtn_set_src(buttonOffXY, LV_BTN_STATE_PR, "F:/bmp_function1.bin"); - lv_imgbtn_set_style(buttonOffXY, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonOffXY, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_H_RETURN, NULL,0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - lv_obj_set_pos(buttonHomeAll, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonHomeX, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonHomeY, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - lv_obj_set_pos(buttonHomeZ, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonOffAll, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonOffXY, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonHomeAll, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonHomeX, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonHomeY, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonHomeZ, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonOffAll, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonOffXY, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelHomeAll = lv_label_create(buttonHomeAll, NULL); - lv_obj_t *labelHomeX = lv_label_create(buttonHomeX, NULL); - lv_obj_t *labelHomeY = lv_label_create(buttonHomeY, NULL); - lv_obj_t *labelHomeZ = lv_label_create(buttonHomeZ, NULL); - lv_obj_t *labelOffAll = lv_label_create(buttonOffAll, NULL); - lv_obj_t *labelOffXY = lv_label_create(buttonOffXY, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelHomeAll, home_menu.home_all); - lv_obj_align(labelHomeAll, buttonHomeAll, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHomeX, home_menu.home_x); - lv_obj_align(labelHomeX, buttonHomeX, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHomeY, home_menu.home_y); - lv_obj_align(labelHomeY, buttonHomeY, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelHomeZ, home_menu.home_z); - lv_obj_align(labelHomeZ, buttonHomeZ, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOffAll, set_menu.motoroff); - lv_obj_align(labelOffAll, buttonOffAll, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOffXY, set_menu.motoroffXY); - lv_obj_align(labelOffXY, buttonOffXY, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonHomeAll); - lv_group_add_obj(g, buttonHomeX); - lv_group_add_obj(g, buttonHomeY); - lv_group_add_obj(g, buttonHomeZ); - lv_group_add_obj(g, buttonOffAll); - lv_group_add_obj(g, buttonOffXY); - lv_group_add_obj(g, buttonBack); - } - #endif + scr = lv_screen_create(ZERO_UI); + lv_big_button_create(scr, "F:/bmp_zeroAll.bin", home_menu.home_all, INTERVAL_V, titleHeight, event_handler, ID_H_ALL); + lv_big_button_create(scr, "F:/bmp_zeroX.bin", home_menu.home_x, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_H_X); + lv_big_button_create(scr, "F:/bmp_zeroY.bin", home_menu.home_y, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_H_Y); + lv_big_button_create(scr, "F:/bmp_zeroZ.bin", home_menu.home_z, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_H_Z); + lv_big_button_create(scr, "F:/bmp_function1.bin", set_menu.motoroff, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_OFF_ALL); + lv_big_button_create(scr, "F:/bmp_function1.bin", set_menu.motoroffXY, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_OFF_XY); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_H_RETURN); } void lv_clear_home() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp index d819aa01f6..cbd028b60a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_homing_sensitivity_settings.cpp @@ -31,220 +31,67 @@ #include "../../../../module/stepper/indirection.h" #include "../../../../feature/tmc_util.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_SENSITIVITY_RETURN 1 -#define ID_SENSITIVITY_X 2 -#define ID_SENSITIVITY_Y 3 -#define ID_SENSITIVITY_Z 4 -#define ID_SENSITIVITY_Z2 5 +enum { + ID_SENSITIVITY_RETURN = 1, + ID_SENSITIVITY_X, + ID_SENSITIVITY_Y, + ID_SENSITIVITY_Z, + ID_SENSITIVITY_Z2 +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_SENSITIVITY_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_homing_sensitivity_settings(); - draw_return_ui(); - } + lv_clear_homing_sensitivity_settings(); + draw_return_ui(); break; case ID_SENSITIVITY_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = x_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = x_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; case ID_SENSITIVITY_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = y_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = y_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; case ID_SENSITIVITY_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = z_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = z_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; #if Z2_SENSORLESS case ID_SENSITIVITY_Z2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = z2_sensitivity; - lv_clear_homing_sensitivity_settings(); - lv_draw_number_key(); - } + value = z2_sensitivity; + lv_clear_homing_sensitivity_settings(); + lv_draw_number_key(); break; #endif } } void lv_draw_homing_sensitivity_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL; - #if Z2_SENSORLESS - lv_obj_t *labelZ2Text = NULL, *buttonZ2Value = NULL, *labelZ2Value = NULL; - lv_obj_t * line4 = NULL; - #endif - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != HOMING_SENSITIVITY_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = HOMING_SENSITIVITY_UI; - } - disp_state = HOMING_SENSITIVITY_UI; + scr = lv_screen_create(HOMING_SENSITIVITY_UI, machine_menu.HomingSensitivityConfTitle); - scr = lv_obj_create(NULL, NULL); + sprintf_P(public_buf_l, PSTR("%d"), TERN(X_SENSORLESS, stepperX.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_SENSITIVITY_X, 0, public_buf_l); - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + sprintf_P(public_buf_l, PSTR("%d"), TERN(Y_SENSORLESS, stepperY.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_SENSITIVITY_Y, 1, public_buf_l); - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.HomingSensitivityConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelXText, machine_menu.X_Sensitivity); - - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_SENSITIVITY_X, NULL, 0); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - labelXValue = lv_label_create(buttonXValue, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonXValue); - #endif - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelYText, machine_menu.Y_Sensitivity); - - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_SENSITIVITY_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - labelYValue = lv_label_create(buttonYValue, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonYValue); - #endif - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelZText, machine_menu.Z_Sensitivity); - - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_SENSITIVITY_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - labelZValue = lv_label_create(buttonZValue, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable == true) lv_group_add_obj(g, buttonZValue); - #endif - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); + sprintf_P(public_buf_l, PSTR("%d"), TERN(Z_SENSORLESS, stepperZ.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_SENSITIVITY_Z, 2, public_buf_l); #if Z2_SENSORLESS - labelZ2Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelZ2Text, &tft_style_label_rel); - lv_obj_set_pos(labelZ2Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelZ2Text, machine_menu.Z2_Sensitivity); - - buttonZ2Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZ2Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonZ2Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZ2Value, event_handler, ID_SENSITIVITY_Z2, NULL, 0); - lv_btn_set_style(buttonZ2Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZ2Value, LV_BTN_STYLE_PR, &style_para_value); - labelZ2Value = lv_label_create(buttonZ2Value, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZ2Value); - #endif - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); + sprintf_P(public_buf_l, PSTR("%d"), TERN(Z2_SENSORLESS, stepperZ2.homing_threshold(), 0)); + lv_screen_menu_item_1_edit(scr, machine_menu.Z2_Sensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_SENSITIVITY_Z2, 3, public_buf_l); #endif - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_SENSITIVITY_RETURN, NULL, 0); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create(buttonBack, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(X_SENSORLESS, stepperX.homing_threshold(), 0)); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(Y_SENSORLESS, stepperY.homing_threshold(), 0)); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(Z_SENSORLESS, stepperZ.homing_threshold(), 0)); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - #if Z2_SENSORLESS - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), TERN(Z2_SENSORLESS, stepperZ2.homing_threshold(), 0)); - lv_label_set_text(labelZ2Value, public_buf_l); - lv_obj_align(labelZ2Value, buttonZ2Value, LV_ALIGN_CENTER, 0, 0); - #endif - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_SENSITIVITY_RETURN, true); } void lv_clear_homing_sensitivity_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp index 65649b793e..f07c2761b6 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_jerk_settings.cpp @@ -29,202 +29,63 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_JERK_RETURN 1 -#define ID_JERK_X 2 -#define ID_JERK_Y 3 -#define ID_JERK_Z 4 -#define ID_JERK_E 5 +enum { + ID_JERK_RETURN = 1, + ID_JERK_X, + ID_JERK_Y, + ID_JERK_Z, + ID_JERK_E +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_JERK_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_jerk_settings(); - draw_return_ui(); - } + lv_clear_jerk_settings(); + draw_return_ui(); break; case ID_JERK_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = XJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = XJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; case ID_JERK_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = YJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = YJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; case ID_JERK_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = ZJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = ZJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; case ID_JERK_E: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = EJerk; - lv_clear_jerk_settings(); - lv_draw_number_key(); - } + value = EJerk; + lv_clear_jerk_settings(); + lv_draw_number_key(); break; } } void lv_draw_jerk_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *labelEText = NULL, *buttonEValue = NULL, *labelEValue = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != JERK_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = JERK_UI; - } - disp_state = JERK_UI; + scr = lv_screen_create(JERK_UI, machine_menu.JerkConfTitle); - scr = lv_obj_create(NULL, NULL); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_JERK_X, 0, public_buf_l); - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_JERK_Y, 1, public_buf_l); - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.JerkConfTitle); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_JERK_Z, 2, public_buf_l); - lv_refr_now(lv_refr_get_disp_refreshing()); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E_Jerk, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_JERK_E, 3, public_buf_l); - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelXText, machine_menu.X_Jerk); - - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_JERK_X, NULL, 0); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - labelXValue = lv_label_create(buttonXValue, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelYText, machine_menu.Y_Jerk); - - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_JERK_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - labelYValue = lv_label_create(buttonYValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelZText, machine_menu.Z_Jerk); - - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_JERK_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - labelZValue = lv_label_create(buttonZValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelEText = lv_label_create(scr, NULL); - lv_obj_set_style(labelEText, &tft_style_label_rel); - lv_obj_set_pos(labelEText, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelEText, machine_menu.E_Jerk); - - buttonEValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonEValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonEValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonEValue, event_handler, ID_JERK_E, NULL, 0); - lv_btn_set_style(buttonEValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonEValue, LV_BTN_STYLE_PR, &style_para_value); - labelEValue = lv_label_create(buttonEValue, NULL); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_JERK_RETURN, NULL, 0); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create(buttonBack, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable == true) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonEValue); - lv_group_add_obj(g, buttonBack); - } - #endif - - if (gCfgItems.multiple_language) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.max_jerk[E_AXIS]); - lv_label_set_text(labelEValue, public_buf_l); - lv_obj_align(labelEValue, buttonEValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_JERK_RETURN, true); } void lv_clear_jerk_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp index 35ad439c6e..acf1d15325 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp @@ -28,8 +28,8 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; #define LV_KB_CTRL_BTN_FLAGS (LV_BTNM_CTRL_NO_REPEAT | LV_BTNM_CTRL_CLICK_TRIG) @@ -72,7 +72,7 @@ static const lv_btnm_ctrl_t kb_ctrl_num_map[] = { 1, 1, 1, 2, 1, 1, 1, 1, 1}; -static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { +static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) { //LV_ASSERT_OBJ(kb, LV_OBJX_NAME); if (event != LV_EVENT_VALUE_CHANGED) return; @@ -84,7 +84,7 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { if (lv_btnm_get_btn_ctrl(kb, btn_id, LV_BTNM_CTRL_NO_REPEAT) && event == LV_EVENT_LONG_PRESSED_REPEAT) return; const char * txt = lv_btnm_get_active_btn_text(kb); - if (txt == NULL) return; + if (!txt) return; // Do the corresponding action according to the text of the button if (strcmp(txt, "abc") == 0) { @@ -104,13 +104,13 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { } else if (strcmp(txt, LV_SYMBOL_CLOSE) == 0) { if (kb->event_cb != lv_kb_def_event_cb) { - //lv_res_t res = lv_event_send(kb, LV_EVENT_CANCEL, NULL); + //lv_res_t res = lv_event_send(kb, LV_EVENT_CANCEL, nullptr); //if (res != LV_RES_OK) return; lv_clear_keyboard(); draw_return_ui(); } else { - lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ + lv_kb_set_ta(kb, nullptr); // De-assign the text area to hide it cursor if needed lv_obj_del(kb); return; } @@ -118,7 +118,7 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { } else if (strcmp(txt, LV_SYMBOL_OK) == 0) { if (kb->event_cb != lv_kb_def_event_cb) { - //lv_res_t res = lv_event_send(kb, LV_EVENT_APPLY, NULL); + //lv_res_t res = lv_event_send(kb, LV_EVENT_APPLY, nullptr); //if (res != LV_RES_OK) return; const char * ret_ta_txt = lv_ta_get_text(ext->ta); switch (keyboard_value) { @@ -134,18 +134,16 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { draw_return_ui(); break; case wifiConfig: - memset((void *)uiCfg.wifi_name, 0, sizeof(uiCfg.wifi_name)); + ZERO(uiCfg.wifi_name); memcpy((void *)uiCfg.wifi_name, wifi_list.wifiName[wifi_list.nameIndex], 32); - memset((void *)uiCfg.wifi_key, 0, sizeof(uiCfg.wifi_key)); + ZERO(uiCfg.wifi_key); memcpy((void *)uiCfg.wifi_key, ret_ta_txt, sizeof(uiCfg.wifi_key)); gCfgItems.wifi_mode_sel = STA_MODEL; package_to_wifi(WIFI_PARA_SET, (char *)0, 0); - memset(public_buf_l,0,sizeof(public_buf_l)); - public_buf_l[0] = 0xA5; public_buf_l[1] = 0x09; public_buf_l[2] = 0x01; @@ -171,14 +169,13 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { default: break; } } - else { - lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ - } + else + lv_kb_set_ta(kb, nullptr); // De-assign the text area to hide it cursor if needed return; } - /*Add the characters to the text area if set*/ - if (ext->ta == NULL) return; + // Add the characters to the text area if set + if (!ext->ta) return; if (strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_ta_add_char(ext->ta, '\n'); @@ -215,21 +212,9 @@ static void lv_kb_event_cb(lv_obj_t * kb, lv_event_t event) { } void lv_draw_keyboard() { - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != KEY_BOARD_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = KEY_BOARD_UI; - } - disp_state = KEY_BOARD_UI; + scr = lv_screen_create(KEY_BOARD_UI, ""); - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - /*Create styles for the keyboard*/ + // Create styles for the keyboard static lv_style_t rel_style, pr_style; lv_style_copy(&rel_style, &lv_style_btn_rel); @@ -244,8 +229,8 @@ void lv_draw_keyboard() { pr_style.body.main_color = lv_color_make(0x72, 0x42, 0x15); pr_style.body.grad_color = lv_color_make(0x6A, 0x3A, 0x0C); - /*Create a keyboard and apply the styles*/ - lv_obj_t *kb = lv_kb_create(scr, NULL); + // Create a keyboard and apply the styles + lv_obj_t *kb = lv_kb_create(scr, nullptr); lv_obj_set_event_cb(kb, lv_kb_event_cb); lv_kb_set_cursor_manage(kb, true); lv_kb_set_style(kb, LV_KB_STYLE_BG, &lv_style_transp_tight); @@ -258,9 +243,9 @@ void lv_draw_keyboard() { } #endif - /*Create a text area. The keyboard will write here*/ - lv_obj_t *ta = lv_ta_create(scr, NULL); - lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); + // Create a text area. The keyboard will write here + lv_obj_t *ta = lv_ta_create(scr, nullptr); + lv_obj_align(ta, nullptr, LV_ALIGN_IN_TOP_MID, 0, 10); if (keyboard_value == gcodeCommand) { get_gcode_command(AUTO_LEVELING_COMMAND_ADDR,(uint8_t *)public_buf_m); public_buf_m[sizeof(public_buf_m)-1] = 0; @@ -270,7 +255,7 @@ void lv_draw_keyboard() { lv_ta_set_text(ta, ""); } - /*Assign the text area to the keyboard*/ + // Assign the text area to the keyboard lv_kb_set_ta(kb, ta); } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp index 4cd2cab72f..8f7279f5dd 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_language.cpp @@ -33,147 +33,98 @@ #include "../../../../inc/MarlinConfig.h" #include -//static lv_obj_t *buttonMoveZ,*buttonTest,*buttonZ0,*buttonStop,*buttonReturn; - -#define ID_CN 1 -#define ID_T_CN 2 -#define ID_EN 3 -#define ID_RU 4 -#define ID_ES 5 -#define ID_FR 6 -#define ID_IT 7 -#define ID_L_RETURN 8 +enum { + ID_CN = 1, + ID_T_CN, + ID_EN, + ID_RU, + ID_ES, + ID_FR, + ID_IT, + ID_L_RETURN +}; #define SELECTED 1 #define UNSELECTED 0 static void disp_language(uint8_t language, uint8_t state); -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *buttonCN, *buttonT_CN, *buttonEN, *buttonRU; -static lv_obj_t *buttonES, *buttonFR, *buttonIT, *buttonBack; +static lv_obj_t *buttonES, *buttonFR, *buttonIT; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_CN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src(buttonCN, LV_BTN_STATE_REL, "F:/bmp_simplified_cn_sel.bin"); - lv_imgbtn_set_src(buttonCN, LV_BTN_STATE_PR, "F:/bmp_simplified_cn_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonCN); - gCfgItems.language = LANG_SIMPLE_CHINESE; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonCN, "F:/bmp_simplified_cn_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonCN); + gCfgItems.language = LANG_SIMPLE_CHINESE; + update_spi_flash(); + disp_language_init(); break; case ID_T_CN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src(buttonT_CN, LV_BTN_STATE_REL, "F:/bmp_traditional_cn_sel.bin"); - lv_imgbtn_set_src(buttonT_CN, LV_BTN_STATE_PR, "F:/bmp_traditional_cn_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonT_CN); - gCfgItems.language = LANG_COMPLEX_CHINESE; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonT_CN, "F:/bmp_traditional_cn_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonT_CN); + gCfgItems.language = LANG_COMPLEX_CHINESE; + update_spi_flash(); + disp_language_init(); break; case ID_EN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src(buttonEN, LV_BTN_STATE_REL, "F:/bmp_english_sel.bin"); - lv_imgbtn_set_src(buttonEN, LV_BTN_STATE_PR, "F:/bmp_english_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonEN); - gCfgItems.language = LANG_ENGLISH; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonEN, "F:/bmp_english_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonEN); + gCfgItems.language = LANG_ENGLISH; + update_spi_flash(); + disp_language_init(); break; case ID_RU: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src(buttonRU, LV_BTN_STATE_REL, "F:/bmp_russian_sel.bin"); - lv_imgbtn_set_src(buttonRU, LV_BTN_STATE_PR, "F:/bmp_russian_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonRU); - gCfgItems.language = LANG_RUSSIAN; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonRU, "F:/bmp_russian_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonRU); + gCfgItems.language = LANG_RUSSIAN; + update_spi_flash(); + disp_language_init(); break; case ID_ES: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src(buttonES, LV_BTN_STATE_REL, "F:/bmp_spanish_sel.bin"); - lv_imgbtn_set_src(buttonES, LV_BTN_STATE_PR, "F:/bmp_spanish_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonES); - gCfgItems.language = LANG_SPANISH; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonES, "F:/bmp_spanish_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonES); + gCfgItems.language = LANG_SPANISH; + update_spi_flash(); + disp_language_init(); break; case ID_FR: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src(buttonFR, LV_BTN_STATE_REL, "F:/bmp_french_sel.bin"); - lv_imgbtn_set_src(buttonFR, LV_BTN_STATE_PR, "F:/bmp_french_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonFR); - gCfgItems.language = LANG_FRENCH; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonFR, "F:/bmp_french_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonFR); + gCfgItems.language = LANG_FRENCH; + update_spi_flash(); + disp_language_init(); break; case ID_IT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - disp_language(gCfgItems.language, UNSELECTED); - lv_imgbtn_set_src(buttonIT, LV_BTN_STATE_REL, "F:/bmp_italy_sel.bin"); - lv_imgbtn_set_src(buttonIT, LV_BTN_STATE_PR, "F:/bmp_italy_sel.bin"); - lv_obj_refresh_ext_draw_pad(buttonIT); - gCfgItems.language = LANG_ITALY; - update_spi_flash(); - disp_language_init(); - } + disp_language(gCfgItems.language, UNSELECTED); + lv_imgbtn_set_src_both(buttonIT, "F:/bmp_italy_sel.bin"); + lv_obj_refresh_ext_draw_pad(buttonIT); + gCfgItems.language = LANG_ITALY; + update_spi_flash(); + disp_language_init(); break; case ID_L_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - - buttonCN = NULL; - buttonT_CN = NULL; - buttonEN = NULL; - buttonRU = NULL; - buttonES = NULL; - buttonFR = NULL; - buttonFR = NULL; - buttonIT = NULL; - buttonBack = NULL; - lv_clear_language(); - lv_draw_set(); - } + buttonCN = nullptr; + buttonT_CN = nullptr; + buttonEN = nullptr; + buttonRU = nullptr; + buttonES = nullptr; + buttonFR = nullptr; + buttonFR = nullptr; + buttonIT = nullptr; + lv_clear_language(); + lv_draw_set(); break; - } } @@ -230,165 +181,25 @@ static void disp_language(uint8_t language, uint8_t state) { strcat_P(public_buf_l, PSTR(".bin")); - lv_obj_set_event_cb_mks(obj, event_handler, id, NULL, 0); - lv_imgbtn_set_src(obj, LV_BTN_STATE_REL, public_buf_l); - lv_imgbtn_set_src(obj, LV_BTN_STATE_PR, public_buf_l); + lv_obj_set_event_cb_mks(obj, event_handler, id, nullptr, 0); + lv_imgbtn_set_src_both(obj, public_buf_l); if (state == UNSELECTED) lv_obj_refresh_ext_draw_pad(obj); } void lv_draw_language(void) { - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LANGUAGE_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = LANGUAGE_UI; - } - disp_state = LANGUAGE_UI; - - scr = lv_obj_create(NULL, NULL); - - // static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - + scr = lv_screen_create(LANGUAGE_UI); // Create image buttons - buttonCN = lv_imgbtn_create(scr, NULL); - buttonT_CN = lv_imgbtn_create(scr, NULL); - buttonEN = lv_imgbtn_create(scr, NULL); - buttonRU = lv_imgbtn_create(scr, NULL); - buttonES = lv_imgbtn_create(scr, NULL); - buttonFR = lv_imgbtn_create(scr, NULL); - buttonIT = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonCN, event_handler, ID_CN, NULL, 0); - lv_imgbtn_set_src(buttonCN, LV_BTN_STATE_REL, "F:/bmp_simplified_cn.bin"); - lv_imgbtn_set_src(buttonCN, LV_BTN_STATE_PR, "F:/bmp_simplified_cn.bin"); - lv_imgbtn_set_style(buttonCN, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonCN, LV_BTN_STATE_REL, &tft_style_label_rel); + buttonCN = lv_big_button_create(scr, "F:/bmp_simplified_cn.bin", language_menu.chinese_s, INTERVAL_V, titleHeight, event_handler, ID_CN); lv_obj_clear_protect(buttonCN, LV_PROTECT_FOLLOW); - - #if 1 - lv_obj_set_event_cb_mks(buttonT_CN, event_handler, ID_T_CN, NULL, 0); - lv_imgbtn_set_src(buttonT_CN, LV_BTN_STATE_REL, "F:/bmp_traditional_cn.bin"); - lv_imgbtn_set_src(buttonT_CN, LV_BTN_STATE_PR, "F:/bmp_traditional_cn.bin"); - lv_imgbtn_set_style(buttonT_CN, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonT_CN, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonEN, event_handler, ID_EN, NULL, 0); - lv_imgbtn_set_src(buttonEN, LV_BTN_STATE_REL, "F:/bmp_english.bin"); - lv_imgbtn_set_src(buttonEN, LV_BTN_STATE_PR, "F:/bmp_english.bin"); - lv_imgbtn_set_style(buttonEN, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonEN, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonRU, event_handler, ID_RU, NULL, 0); - lv_imgbtn_set_src(buttonRU, LV_BTN_STATE_REL, "F:/bmp_russian.bin"); - lv_imgbtn_set_src(buttonRU, LV_BTN_STATE_PR, "F:/bmp_russian.bin"); - lv_imgbtn_set_style(buttonRU, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonRU, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonES, event_handler, ID_ES, NULL, 0); - lv_imgbtn_set_src(buttonES, LV_BTN_STATE_REL, "F:/bmp_spanish.bin"); - lv_imgbtn_set_src(buttonES, LV_BTN_STATE_PR, "F:/bmp_spanish.bin"); - lv_imgbtn_set_style(buttonES, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonES, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonFR, event_handler, ID_FR, NULL, 0); - lv_imgbtn_set_src(buttonFR, LV_BTN_STATE_REL, "F:/bmp_french.bin"); - lv_imgbtn_set_src(buttonFR, LV_BTN_STATE_PR, "F:/bmp_french.bin"); - lv_imgbtn_set_style(buttonFR, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonFR, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonIT, event_handler, ID_IT, NULL, 0); - lv_imgbtn_set_src(buttonIT, LV_BTN_STATE_REL, "F:/bmp_italy.bin"); - lv_imgbtn_set_src(buttonIT, LV_BTN_STATE_PR, "F:/bmp_italy.bin"); - lv_imgbtn_set_style(buttonIT, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonIT, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_L_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - #endif // if 1 - - lv_obj_set_pos(buttonCN, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonT_CN, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonEN, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - lv_obj_set_pos(buttonRU, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonES, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonFR, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonIT, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonCN, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonT_CN, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonEN, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonRU, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonES, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonFR, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonIT, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *label_CN = lv_label_create(buttonCN, NULL); - lv_obj_t *label_T_CN = lv_label_create(buttonT_CN, NULL); - lv_obj_t *label_EN = lv_label_create(buttonEN, NULL); - lv_obj_t *label_RU = lv_label_create(buttonRU, NULL); - lv_obj_t *label_ES = lv_label_create(buttonES, NULL); - lv_obj_t *label_FR = lv_label_create(buttonFR, NULL); - lv_obj_t *label_IT = lv_label_create(buttonIT, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - + buttonT_CN = lv_big_button_create(scr, "F:/bmp_traditional_cn.bin", language_menu.chinese_t, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_CN); + buttonEN = lv_big_button_create(scr, "F:/bmp_english.bin", language_menu.english, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_EN); + buttonRU = lv_big_button_create(scr, "F:/bmp_russian.bin", language_menu.russian, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_RU); + buttonES = lv_big_button_create(scr, "F:/bmp_spanish.bin", language_menu.spanish, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_ES); + buttonFR = lv_big_button_create(scr, "F:/bmp_french.bin", language_menu.french, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FR); + buttonIT = lv_big_button_create(scr, "F:/bmp_italy.bin", language_menu.italy, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_IT); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_L_RETURN); disp_language(gCfgItems.language, SELECTED); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_CN, language_menu.chinese_s); - lv_obj_align(label_CN, buttonCN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_T_CN, language_menu.chinese_t); - lv_obj_align(label_T_CN, buttonT_CN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_EN, language_menu.english); - lv_obj_align(label_EN, buttonEN, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_RU, language_menu.russian); - lv_obj_align(label_RU, buttonRU, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_ES, language_menu.spanish); - lv_obj_align(label_ES, buttonES, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_FR, language_menu.french); - lv_obj_align(label_FR, buttonFR, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_IT, language_menu.italy); - lv_obj_align(label_IT, buttonIT, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonCN); - lv_group_add_obj(g, buttonT_CN); - lv_group_add_obj(g, buttonEN); - lv_group_add_obj(g, buttonRU); - lv_group_add_obj(g, buttonES); - lv_group_add_obj(g, buttonFR); - lv_group_add_obj(g, buttonIT); - lv_group_add_obj(g, buttonBack); - } - #endif } void lv_clear_language() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp index 2f4fe327fd..b1ce90f266 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_level_settings.cpp @@ -28,227 +28,49 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_LEVEL_RETURN 1 -#define ID_LEVEL_POSITION 2 -#define ID_LEVEL_POSITION_ARROW 3 -#define ID_LEVEL_COMMAND 4 -#define ID_LEVEL_COMMAND_ARROW 5 -#define ID_LEVEL_ZOFFSET 6 -#define ID_LEVEL_ZOFFSET_ARROW 7 +enum { + ID_LEVEL_RETURN = 1, + ID_LEVEL_POSITION, + ID_LEVEL_COMMAND, + ID_LEVEL_ZOFFSET +}; - -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_LEVEL_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - draw_return_ui(); - } + lv_clear_level_settings(); + draw_return_ui(); break; case ID_LEVEL_POSITION: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_manual_level_pos_settings(); - } - break; - case ID_LEVEL_POSITION_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_manual_level_pos_settings(); - } + lv_clear_level_settings(); + lv_draw_manual_level_pos_settings(); break; case ID_LEVEL_COMMAND: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - keyboard_value = gcodeCommand; - lv_clear_level_settings(); - lv_draw_keyboard(); - } - break; - case ID_LEVEL_COMMAND_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - keyboard_value = gcodeCommand; - lv_clear_level_settings(); - lv_draw_keyboard(); - } + keyboard_value = gcodeCommand; + lv_clear_level_settings(); + lv_draw_keyboard(); break; #if HAS_BED_PROBE case ID_LEVEL_ZOFFSET: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_auto_level_offset_settings(); - } - break; - case ID_LEVEL_ZOFFSET_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_level_settings(); - lv_draw_auto_level_offset_settings(); - } + lv_clear_level_settings(); + lv_draw_auto_level_offset_settings(); break; #endif } } void lv_draw_level_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonPosition, *labelPosition, *buttonPositionNarrow; - lv_obj_t *buttonCommand, *labelCommand, *buttonCommandNarrow; + scr = lv_screen_create(LEVELING_PARA_UI, machine_menu.LevelingParaConfTitle); + lv_screen_menu_item(scr, machine_menu.LevelingManuPosConf, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_LEVEL_POSITION, 0); + lv_screen_menu_item(scr, machine_menu.LevelingAutoCommandConf, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_LEVEL_COMMAND, 1); #if HAS_BED_PROBE - lv_obj_t *buttonZoffset, *labelZoffset, *buttonZoffsetNarrow; - lv_obj_t * line3; + lv_screen_menu_item(scr, machine_menu.LevelingAutoZoffsetConf, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_LEVEL_ZOFFSET, 2); #endif - lv_obj_t * line1, * line2; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LEVELING_PARA_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = LEVELING_PARA_UI; - } - disp_state = LEVELING_PARA_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.LevelingParaConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - - buttonPosition = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonPosition, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonPosition, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb_mks(buttonPosition, event_handler, ID_LEVEL_POSITION, NULL, 0); - lv_btn_set_style(buttonPosition, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonPosition, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonPosition, LV_LAYOUT_OFF); - labelPosition = lv_label_create(buttonPosition, NULL); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonPosition); - #endif - - buttonPositionNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonPositionNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonPositionNarrow, event_handler, ID_LEVEL_POSITION_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonPositionNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonPositionNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonPositionNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPositionNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonPositionNarrow, LV_LAYOUT_OFF); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonCommand = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonCommand, PARA_UI_POS_X, PARA_UI_POS_Y * 2); - lv_obj_set_size(buttonCommand, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); - lv_obj_set_event_cb_mks(buttonCommand, event_handler, ID_LEVEL_COMMAND, NULL, 0); - lv_btn_set_style(buttonCommand, LV_BTN_STYLE_REL, &tft_style_label_rel); - lv_btn_set_style(buttonCommand, LV_BTN_STYLE_PR, &tft_style_label_pre); - lv_btn_set_layout(buttonCommand, LV_LAYOUT_OFF); - labelCommand = lv_label_create(buttonCommand, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonCommand); - #endif - - buttonCommandNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonCommandNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonCommandNarrow, event_handler, ID_LEVEL_COMMAND_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonCommandNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonCommandNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonCommandNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonCommandNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonCommandNarrow, LV_LAYOUT_OFF); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - #if HAS_BED_PROBE - - buttonZoffset = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonZoffset, PARA_UI_POS_X, PARA_UI_POS_Y * 3); /*Set its position*/ - lv_obj_set_size(buttonZoffset, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb_mks(buttonZoffset, event_handler, ID_LEVEL_ZOFFSET, NULL, 0); - lv_btn_set_style(buttonZoffset, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonZoffset, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonZoffset, LV_LAYOUT_OFF); - labelZoffset = lv_label_create(buttonZoffset, NULL); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZoffset); - #endif - - buttonZoffsetNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonZoffsetNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonZoffsetNarrow, event_handler, ID_LEVEL_ZOFFSET_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonZoffsetNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonZoffsetNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonZoffsetNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonZoffsetNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonZoffsetNarrow, LV_LAYOUT_OFF); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - #endif // HAS_BED_PROBE - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_LEVEL_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelPosition, machine_menu.LevelingManuPosConf); - lv_obj_align(labelPosition, buttonPosition, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelCommand, machine_menu.LevelingAutoCommandConf); - lv_obj_align(labelCommand, buttonCommand, LV_ALIGN_IN_LEFT_MID, 0, 0); - #if HAS_BED_PROBE - lv_label_set_text(labelZoffset, machine_menu.LevelingAutoZoffsetConf); - lv_obj_align(labelZoffset, buttonZoffset, LV_ALIGN_IN_LEFT_MID, 0, 0); - #endif - } - + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_LEVEL_RETURN, true); } void lv_clear_level_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp index b79e84e8cb..5f81d7b369 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_para.cpp @@ -28,256 +28,50 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_PARA_RETURN 1 -#define ID_PARA_MACHINE 2 -#define ID_PARA_MACHINE_ARROW 3 -#define ID_PARA_MOTOR 4 -#define ID_PARA_MOTOR_ARROW 5 -#define ID_PARA_LEVEL 6 -#define ID_PARA_LEVEL_ARROW 7 -#define ID_PARA_ADVANCE 8 -#define ID_PARA_ADVANCE_ARROW 9 +enum { + ID_PARA_RETURN = 1, + ID_PARA_MACHINE, + ID_PARA_MOTOR, + ID_PARA_LEVEL, + ID_PARA_ADVANCE +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_PARA_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - draw_return_ui(); - } + lv_clear_machine_para(); + draw_return_ui(); break; case ID_PARA_MACHINE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_machine_settings(); - } - break; - case ID_PARA_MACHINE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_machine_settings(); - } + lv_clear_machine_para(); + lv_draw_machine_settings(); break; case ID_PARA_MOTOR: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_motor_settings(); - } - break; - case ID_PARA_MOTOR_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_motor_settings(); - } + lv_clear_machine_para(); + lv_draw_motor_settings(); break; case ID_PARA_LEVEL: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_level_settings(); - } - break; - case ID_PARA_LEVEL_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_level_settings(); - } + lv_clear_machine_para(); + lv_draw_level_settings(); break; case ID_PARA_ADVANCE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_advance_settings(); - } - break; - case ID_PARA_ADVANCE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_para(); - lv_draw_advance_settings(); - } + lv_clear_machine_para(); + lv_draw_advance_settings(); break; } } void lv_draw_machine_para(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonMachine, *labelMachine, *buttonMachineNarrow; - lv_obj_t *buttonMotor, *labelMotor, *buttonMotorNarrow; - lv_obj_t *buttonLevel, *labelLevel, *buttonLevelNarrow; - lv_obj_t *buttonAdvance, *labelAdvance, *buttonAdvanceNarrow; - lv_obj_t * line1, * line2, * line3, * line4; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MACHINE_PARA_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = MACHINE_PARA_UI; - } - disp_state = MACHINE_PARA_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonMachine = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonMachine, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonMachine, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonMachine, event_handler, ID_PARA_MACHINE, NULL, 0); - lv_btn_set_style(buttonMachine, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonMachine, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonMachine, LV_LAYOUT_OFF); - labelMachine = lv_label_create(buttonMachine, NULL); /*Add a label to the button*/ - - buttonMachineNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonMachineNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonMachineNarrow, event_handler, ID_PARA_MACHINE_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonMachineNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonMachineNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonMachineNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMachineNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonMachineNarrow, LV_LAYOUT_OFF); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonMotor = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonMotor, PARA_UI_POS_X, PARA_UI_POS_Y * 2); /*Set its position*/ - lv_obj_set_size(buttonMotor, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonMotor, event_handler, ID_PARA_MOTOR, NULL, 0); - lv_btn_set_style(buttonMotor, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonMotor, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonMotor, LV_LAYOUT_OFF); - labelMotor = lv_label_create(buttonMotor, NULL); /*Add a label to the button*/ - - buttonMotorNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonMotorNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonMotorNarrow, event_handler, ID_PARA_MOTOR_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonMotorNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonMotorNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonMotorNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMotorNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonMotorNarrow, LV_LAYOUT_OFF); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - buttonLevel = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonLevel, PARA_UI_POS_X, PARA_UI_POS_Y * 3); /*Set its position*/ - lv_obj_set_size(buttonLevel, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonLevel, event_handler, ID_PARA_LEVEL, NULL, 0); - lv_btn_set_style(buttonLevel, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonLevel, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonLevel, LV_LAYOUT_OFF); - labelLevel = lv_label_create(buttonLevel, NULL); /*Add a label to the button*/ - - buttonLevelNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonLevelNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonLevelNarrow, event_handler, ID_PARA_LEVEL_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonLevelNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonLevelNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonLevelNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonLevelNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonLevelNarrow, LV_LAYOUT_OFF); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonAdvance = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonAdvance, PARA_UI_POS_X, PARA_UI_POS_Y * 4); /*Set its position*/ - lv_obj_set_size(buttonAdvance, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonAdvance, event_handler, ID_PARA_ADVANCE, NULL, 0); - lv_btn_set_style(buttonAdvance, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonAdvance, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonAdvance, LV_LAYOUT_OFF); - labelAdvance = lv_label_create(buttonAdvance, NULL); /*Add a label to the button*/ - - buttonAdvanceNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonAdvanceNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 4 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonAdvanceNarrow, event_handler, ID_PARA_ADVANCE_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonAdvanceNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonAdvanceNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonAdvanceNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonAdvanceNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonAdvanceNarrow, LV_LAYOUT_OFF); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_PARA_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, -2); - - lv_label_set_text(labelMachine, MachinePara_menu.MachineSetting); - lv_obj_align(labelMachine, buttonMachine, LV_ALIGN_IN_LEFT_MID, 0, -3); - - lv_label_set_text(labelMotor, MachinePara_menu.MotorSetting); - lv_obj_align(labelMotor, buttonMotor, LV_ALIGN_IN_LEFT_MID, 0, -3); - - lv_label_set_text(labelLevel, MachinePara_menu.leveling); - lv_obj_align(labelLevel, buttonLevel, LV_ALIGN_IN_LEFT_MID, 0, -3); - - lv_label_set_text(labelAdvance, MachinePara_menu.AdvanceSetting); - lv_obj_align(labelAdvance, buttonAdvance, LV_ALIGN_IN_LEFT_MID, 0, -3); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonMachine); - lv_group_add_obj(g, buttonMotor); - lv_group_add_obj(g, buttonLevel); - lv_group_add_obj(g, buttonAdvance); - lv_group_add_obj(g, buttonBack); - } - #endif - + scr = lv_screen_create(MACHINE_PARA_UI); + lv_screen_menu_item(scr, MachinePara_menu.MachineSetting, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_PARA_MACHINE, 0); + lv_screen_menu_item(scr, MachinePara_menu.MotorSetting, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_PARA_MOTOR, 1); + lv_screen_menu_item(scr, MachinePara_menu.leveling, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_PARA_LEVEL, 2); + lv_screen_menu_item(scr, MachinePara_menu.AdvanceSetting, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_PARA_ADVANCE, 3); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_PARA_RETURN, true); } void lv_clear_machine_para() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp index 930d2639bb..deeb51ab0f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_machine_settings.cpp @@ -28,220 +28,48 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_MACHINE_RETURN 1 -#define ID_MACHINE_ACCELERATION 2 -#define ID_MACHINE_ACCELERATION_ARROW 3 -#define ID_MACHINE_FEEDRATE 4 -#define ID_MACHINE_FEEDRATE_ARROW 5 -#define ID_MACHINE_JERK 6 -#define ID_MACHINE_JERK_ARROW 7 +enum { + ID_MACHINE_RETURN = 1, + ID_MACHINE_ACCELERATION, + ID_MACHINE_FEEDRATE, + ID_MACHINE_JERK +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_MACHINE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - draw_return_ui(); - } + lv_clear_machine_settings(); + draw_return_ui(); break; case ID_MACHINE_ACCELERATION: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_acceleration_settings(); - } - break; - case ID_MACHINE_ACCELERATION_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_acceleration_settings(); - } + lv_clear_machine_settings(); + lv_draw_acceleration_settings(); break; case ID_MACHINE_FEEDRATE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_max_feedrate_settings(); - } + lv_clear_machine_settings(); + lv_draw_max_feedrate_settings(); break; - case ID_MACHINE_FEEDRATE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + #if HAS_CLASSIC_JERK + case ID_MACHINE_JERK: lv_clear_machine_settings(); - lv_draw_max_feedrate_settings(); - } - break; - #if HAS_CLASSIC_JERK - case ID_MACHINE_JERK: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_jerk_settings(); - } - break; - case ID_MACHINE_JERK_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_machine_settings(); - lv_draw_jerk_settings(); - } - break; - #endif + lv_draw_jerk_settings(); + break; + #endif } } void lv_draw_machine_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonAcceleration, *labelAcceleration, *buttonAccelerationNarrow; - lv_obj_t *buttonMaxFeedrate, *labelMaxFeedrate, *buttonMaxFeedrateNarrow; + scr = lv_screen_create(MACHINE_SETTINGS_UI, machine_menu.MachineConfigTitle); + lv_screen_menu_item(scr, machine_menu.AccelerationConf, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MACHINE_ACCELERATION, 0); + lv_screen_menu_item(scr, machine_menu.MaxFeedRateConf, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_MACHINE_FEEDRATE, 1); #if HAS_CLASSIC_JERK - lv_obj_t *buttonJerk, *labelJerk, *buttonJerkNarrow; - #endif - lv_obj_t * line1, * line2; - #if HAS_CLASSIC_JERK - lv_obj_t * line3; - #endif - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MACHINE_SETTINGS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = MACHINE_SETTINGS_UI; - } - disp_state = MACHINE_SETTINGS_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.MachineConfigTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonAcceleration = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(buttonAcceleration, PARA_UI_POS_X, PARA_UI_POS_Y); // Set its position - lv_obj_set_size(buttonAcceleration, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonAcceleration, event_handler, ID_MACHINE_ACCELERATION, NULL, 0); - lv_btn_set_style(buttonAcceleration, LV_BTN_STYLE_REL, &tft_style_label_rel); // Set the button's released style - lv_btn_set_style(buttonAcceleration, LV_BTN_STYLE_PR, &tft_style_label_pre); // Set the button's pressed style - lv_btn_set_layout(buttonAcceleration, LV_LAYOUT_OFF); - labelAcceleration = lv_label_create(buttonAcceleration, NULL); // Add a label to the button - - buttonAccelerationNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonAccelerationNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonAccelerationNarrow, event_handler, ID_MACHINE_ACCELERATION_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonAccelerationNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonAccelerationNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonAccelerationNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonAccelerationNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonAccelerationNarrow, LV_LAYOUT_OFF); - - line1 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line1, line_points[0]); - - buttonMaxFeedrate = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(buttonMaxFeedrate, PARA_UI_POS_X, PARA_UI_POS_Y * 2); // Set its position - lv_obj_set_size(buttonMaxFeedrate, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonMaxFeedrate, event_handler, ID_MACHINE_FEEDRATE, NULL, 0); - lv_btn_set_style(buttonMaxFeedrate, LV_BTN_STYLE_REL, &tft_style_label_rel); // Set the button's released style - lv_btn_set_style(buttonMaxFeedrate, LV_BTN_STYLE_PR, &tft_style_label_pre); // Set the button's pressed style - lv_btn_set_layout(buttonMaxFeedrate, LV_LAYOUT_OFF); - labelMaxFeedrate = lv_label_create(buttonMaxFeedrate, NULL); // Add a label to the button - - buttonMaxFeedrateNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonMaxFeedrateNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonMaxFeedrateNarrow, event_handler, ID_MACHINE_FEEDRATE_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonMaxFeedrateNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonMaxFeedrateNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonMaxFeedrateNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMaxFeedrateNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonMaxFeedrateNarrow, LV_LAYOUT_OFF); - - line2 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line2, line_points[1]); - - #if HAS_CLASSIC_JERK - buttonJerk = lv_btn_create(scr, NULL); // Add a button the current screen - lv_obj_set_pos(buttonJerk, PARA_UI_POS_X, PARA_UI_POS_Y * 3); // Set its position - lv_obj_set_size(buttonJerk, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); // Set its size - //lv_obj_set_event_cb(buttonMotor, event_handler); - lv_obj_set_event_cb_mks(buttonJerk, event_handler, ID_MACHINE_JERK, NULL, 0); - lv_btn_set_style(buttonJerk, LV_BTN_STYLE_REL, &tft_style_label_rel); // Set the button's released style - lv_btn_set_style(buttonJerk, LV_BTN_STYLE_PR, &tft_style_label_pre); // Set the button's pressed style - lv_btn_set_layout(buttonJerk, LV_LAYOUT_OFF); - labelJerk = lv_label_create(buttonJerk, NULL); // Add a label to the button - - buttonJerkNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonJerkNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 3 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonJerkNarrow, event_handler, ID_MACHINE_JERK_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonJerkNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonJerkNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonJerkNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonJerkNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonJerkNarrow, LV_LAYOUT_OFF); - - line3 = lv_line_create(lv_scr_act(), NULL); - lv_ex_line(line3, line_points[2]); - #endif - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_MACHINE_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelAcceleration, machine_menu.AccelerationConf); - lv_obj_align(labelAcceleration, buttonAcceleration, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelMaxFeedrate, machine_menu.MaxFeedRateConf); - lv_obj_align(labelMaxFeedrate, buttonMaxFeedrate, LV_ALIGN_IN_LEFT_MID, 0, 0); - #if HAS_CLASSIC_JERK - lv_label_set_text(labelJerk, machine_menu.JerkConf); - lv_obj_align(labelJerk, buttonJerk, LV_ALIGN_IN_LEFT_MID, 0, 0); - #endif - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAcceleration); - lv_group_add_obj(g, buttonMaxFeedrate); - #if HAS_CLASSIC_JERK - lv_group_add_obj(g, buttonJerk); - #endif - lv_group_add_obj(g, buttonBack); - } + lv_screen_menu_item(scr, machine_menu.JerkConf, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_MACHINE_JERK, 2); #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_MACHINE_RETURN, true); } void lv_clear_machine_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp index f1040ba214..3c8d562913 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp @@ -33,256 +33,100 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_M_POINT1 1 -#define ID_M_POINT2 2 -#define ID_M_POINT3 3 -#define ID_M_POINT4 4 -#define ID_M_POINT5 5 -#define ID_MANUAL_RETURN 6 +enum { + ID_M_POINT1 = 1, + ID_M_POINT2, + ID_M_POINT3, + ID_M_POINT4, + ID_M_POINT5, + ID_MANUAL_RETURN +}; + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; -static void event_handler(lv_obj_t * obj, lv_event_t event) { switch (obj->mks_obj_id) { case ID_M_POINT1: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[0][0], (int)gCfgItems.levelingPos[0][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[0][0], (int)gCfgItems.levelingPos[0][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT2: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[1][0], (int)gCfgItems.levelingPos[1][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[1][0], (int)gCfgItems.levelingPos[1][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT3: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[2][0], (int)gCfgItems.levelingPos[2][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[2][0], (int)gCfgItems.levelingPos[2][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT4: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[3][0], (int)gCfgItems.levelingPos[3][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[3][0], (int)gCfgItems.levelingPos[3][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } break; case ID_M_POINT5: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length == 0) { - if (uiCfg.leveling_first_time) { - queue.enqueue_now_P(PSTR("G28")); - uiCfg.leveling_first_time = 0; - } - - queue.enqueue_now_P(PSTR("G1 Z10")); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[4][0], (int)gCfgItems.levelingPos[4][1]); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G1 Z0")); + if (queue.length == 0) { + if (uiCfg.leveling_first_time) { + queue.enqueue_now_P(PSTR("G28")); + uiCfg.leveling_first_time = 0; } + queue.enqueue_now_P(PSTR("G1 Z10")); + sprintf_P(public_buf_l, PSTR("G1 X%d Y%d"), (int)gCfgItems.levelingPos[4][0], (int)gCfgItems.levelingPos[4][1]); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G1 Z0")); } - break; case ID_MANUAL_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_manualLevel(); - lv_draw_tool(); - } + lv_clear_manualLevel(); + lv_draw_tool(); break; } } void lv_draw_manualLevel(void) { - lv_obj_t *buttonPoint1, *buttonPoint2, *buttonPoint3, *buttonPoint4, *buttonPoint5; - lv_obj_t *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LEVELING_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = LEVELING_UI; - } - disp_state = LEVELING_UI; - - scr = lv_obj_create(NULL, NULL); - - // static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - + scr = lv_screen_create(LEVELING_UI); // Create an Image button - buttonPoint1 = lv_imgbtn_create(scr, NULL); - buttonPoint2 = lv_imgbtn_create(scr, NULL); - buttonPoint3 = lv_imgbtn_create(scr, NULL); - buttonPoint4 = lv_imgbtn_create(scr, NULL); - buttonPoint5 = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonPoint1, event_handler, ID_M_POINT1, NULL, 0); - lv_imgbtn_set_src(buttonPoint1, LV_BTN_STATE_REL, "F:/bmp_leveling1.bin"); - lv_imgbtn_set_src(buttonPoint1, LV_BTN_STATE_PR, "F:/bmp_leveling1.bin"); - lv_imgbtn_set_style(buttonPoint1, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPoint1, LV_BTN_STATE_REL, &tft_style_label_rel); + lv_obj_t *buttonPoint1 = lv_big_button_create(scr, "F:/bmp_leveling1.bin", leveling_menu.position1, INTERVAL_V, titleHeight, event_handler, ID_M_POINT1); lv_obj_clear_protect(buttonPoint1, LV_PROTECT_FOLLOW); - - #if 1 - lv_obj_set_event_cb_mks(buttonPoint2, event_handler, ID_M_POINT2, NULL, 0); - lv_imgbtn_set_src(buttonPoint2, LV_BTN_STATE_REL, "F:/bmp_leveling2.bin"); - lv_imgbtn_set_src(buttonPoint2, LV_BTN_STATE_PR, "F:/bmp_leveling2.bin"); - lv_imgbtn_set_style(buttonPoint2, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPoint2, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonPoint3, event_handler, ID_M_POINT3, NULL, 0); - lv_imgbtn_set_src(buttonPoint3, LV_BTN_STATE_REL, "F:/bmp_leveling3.bin"); - lv_imgbtn_set_src(buttonPoint3, LV_BTN_STATE_PR, "F:/bmp_leveling3.bin"); - lv_imgbtn_set_style(buttonPoint3, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPoint3, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonPoint4, event_handler, ID_M_POINT4, NULL, 0); - lv_imgbtn_set_src(buttonPoint4, LV_BTN_STATE_REL, "F:/bmp_leveling4.bin"); - lv_imgbtn_set_src(buttonPoint4, LV_BTN_STATE_PR, "F:/bmp_leveling4.bin"); - lv_imgbtn_set_style(buttonPoint4, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPoint4, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonPoint5, event_handler, ID_M_POINT5, NULL, 0); - lv_imgbtn_set_src(buttonPoint5, LV_BTN_STATE_REL, "F:/bmp_leveling5.bin"); - lv_imgbtn_set_src(buttonPoint5, LV_BTN_STATE_PR, "F:/bmp_leveling5.bin"); - lv_imgbtn_set_style(buttonPoint5, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPoint5, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_MANUAL_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - lv_obj_set_pos(buttonPoint1, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonPoint2, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonPoint3, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - lv_obj_set_pos(buttonPoint4, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonPoint5, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonPoint1, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonPoint2, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonPoint3, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonPoint4, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonPoint5, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *label_Point1 = lv_label_create(buttonPoint1, NULL); - lv_obj_t *label_Point2 = lv_label_create(buttonPoint2, NULL); - lv_obj_t *label_Point3 = lv_label_create(buttonPoint3, NULL); - lv_obj_t *label_Point4 = lv_label_create(buttonPoint4, NULL); - lv_obj_t *label_Point5 = lv_label_create(buttonPoint5, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Point1, leveling_menu.position1); - lv_obj_align(label_Point1, buttonPoint1, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point2, leveling_menu.position2); - lv_obj_align(label_Point2, buttonPoint2, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point3, leveling_menu.position3); - lv_obj_align(label_Point3, buttonPoint3, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point4, leveling_menu.position4); - lv_obj_align(label_Point4, buttonPoint4, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Point5, leveling_menu.position5); - lv_obj_align(label_Point5, buttonPoint5, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonPoint1); - lv_group_add_obj(g, buttonPoint2); - lv_group_add_obj(g, buttonPoint3); - lv_group_add_obj(g, buttonPoint4); - lv_group_add_obj(g, buttonPoint5); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_leveling2.bin", leveling_menu.position2, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_M_POINT2); + lv_big_button_create(scr, "F:/bmp_leveling3.bin", leveling_menu.position3, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_M_POINT3); + lv_big_button_create(scr, "F:/bmp_leveling4.bin", leveling_menu.position4, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_POINT4); + lv_big_button_create(scr, "F:/bmp_leveling5.bin", leveling_menu.position5, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_POINT5); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_MANUAL_RETURN); } void lv_clear_manualLevel() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp index c27718b31d..6f64badf8b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_manual_level_pos_settings.cpp @@ -29,424 +29,129 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_MANUAL_POS_RETURN 1 -#define ID_MANUAL_POS_X1 2 -#define ID_MANUAL_POS_Y1 3 -#define ID_MANUAL_POS_X2 4 -#define ID_MANUAL_POS_Y2 5 -#define ID_MANUAL_POS_X3 6 -#define ID_MANUAL_POS_Y3 7 -#define ID_MANUAL_POS_X4 8 -#define ID_MANUAL_POS_Y4 9 -#define ID_MANUAL_POS_X5 10 -#define ID_MANUAL_POS_Y5 11 -#define ID_MANUAL_POS_DOWN 12 -#define ID_MANUAL_POS_UP 13 +enum { + ID_MANUAL_POS_RETURN = 1, + ID_MANUAL_POS_X1, + ID_MANUAL_POS_Y1, + ID_MANUAL_POS_X2, + ID_MANUAL_POS_Y2, + ID_MANUAL_POS_X3, + ID_MANUAL_POS_Y3, + ID_MANUAL_POS_X4, + ID_MANUAL_POS_Y4, + ID_MANUAL_POS_X5, + ID_MANUAL_POS_Y5, + ID_MANUAL_POS_DOWN, + ID_MANUAL_POS_UP +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_MANUAL_POS_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_manual_level_pos_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_manual_level_pos_settings(); + draw_return_ui(); break; case ID_MANUAL_POS_X1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x1; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x1; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y1; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y1; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x2; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x2; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y2; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y2; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X3: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x3; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x3; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y3: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y3; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y3; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X4: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_x4; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_x4; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y4: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y4; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y4; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_X5: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y5; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y5; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_Y5: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = level_pos_y5; - lv_clear_manual_level_pos_settings(); - lv_draw_number_key(); - } + value = level_pos_y5; + lv_clear_manual_level_pos_settings(); + lv_draw_number_key(); break; case ID_MANUAL_POS_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_manual_level_pos_settings(); - lv_draw_manual_level_pos_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_manual_level_pos_settings(); + lv_draw_manual_level_pos_settings(); break; case ID_MANUAL_POS_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_manual_level_pos_settings(); - lv_draw_manual_level_pos_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_manual_level_pos_settings(); + lv_draw_manual_level_pos_settings(); break; } } void lv_draw_manual_level_pos_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *labelPoint1Text = NULL, *buttonX1Value = NULL, *labelX1Value = NULL; - lv_obj_t *buttonY1Value = NULL, *labelY1Value = NULL; - lv_obj_t *labelPoint2Text = NULL, *buttonX2Value = NULL, *labelX2Value = NULL; - lv_obj_t *buttonY2Value = NULL, *labelY2Value = NULL; - lv_obj_t *labelPoint3Text = NULL, *buttonX3Value = NULL, *labelX3Value = NULL; - lv_obj_t *buttonY3Value = NULL, *labelY3Value = NULL; - lv_obj_t *labelPoint4Text = NULL, *buttonX4Value = NULL, *labelX4Value = NULL; - lv_obj_t *buttonY4Value = NULL, *labelY4Value = NULL; - lv_obj_t *labelPoint5Text = NULL, *buttonX5Value = NULL, *labelX5Value = NULL; - lv_obj_t *buttonY5Value = NULL, *labelY5Value = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MANUAL_LEVELING_POSIGION_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = MANUAL_LEVELING_POSIGION_UI; - } - disp_state = MANUAL_LEVELING_POSIGION_UI; + char buf2[50]; - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.LevelingParaConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(MANUAL_LEVELING_POSIGION_UI, machine_menu.LevelingParaConfTitle); if (uiCfg.para_ui_page != 1) { - labelPoint1Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelPoint1Text, &tft_style_label_rel); - lv_obj_set_pos(labelPoint1Text, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelPoint1Text, leveling_menu.position1); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[0][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[0][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position1, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MANUAL_POS_Y1, 0, buf2, ID_MANUAL_POS_X1, public_buf_l); - buttonX1Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonX1Value, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonX1Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonX1Value, event_handler, ID_MANUAL_POS_X1, NULL, 0); - lv_btn_set_style(buttonX1Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonX1Value, LV_BTN_STYLE_PR, &style_para_value); - labelX1Value = lv_label_create(buttonX1Value, NULL); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[1][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[1][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position2, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_MANUAL_POS_Y2, 1, buf2, ID_MANUAL_POS_X2, public_buf_l); - buttonY1Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonY1Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonY1Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonY1Value, event_handler, ID_MANUAL_POS_Y1, NULL, 0); - lv_btn_set_style(buttonY1Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonY1Value, LV_BTN_STYLE_PR, &style_para_value); - labelY1Value = lv_label_create(buttonY1Value, NULL); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[2][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[2][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position3, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_MANUAL_POS_Y3, 2, buf2, ID_MANUAL_POS_X3, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[3][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[3][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position4, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_MANUAL_POS_Y4, 3, buf2, ID_MANUAL_POS_X4, public_buf_l); - labelPoint2Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelPoint2Text, &tft_style_label_rel); - lv_obj_set_pos(labelPoint2Text, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelPoint2Text, leveling_menu.position2); - - buttonX2Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonX2Value, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonX2Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonX2Value, event_handler, ID_MANUAL_POS_X2, NULL, 0); - lv_btn_set_style(buttonX2Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonX2Value, LV_BTN_STYLE_PR, &style_para_value); - labelX2Value = lv_label_create(buttonX2Value, NULL); - - buttonY2Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonY2Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonY2Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonY2Value, event_handler, ID_MANUAL_POS_Y2, NULL, 0); - lv_btn_set_style(buttonY2Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonY2Value, LV_BTN_STYLE_PR, &style_para_value); - labelY2Value = lv_label_create(buttonY2Value, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelPoint3Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelPoint3Text, &tft_style_label_rel); - lv_obj_set_pos(labelPoint3Text, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelPoint3Text, leveling_menu.position3); - - buttonX3Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonX3Value, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonX3Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonX3Value, event_handler, ID_MANUAL_POS_X3, NULL, 0); - lv_btn_set_style(buttonX3Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonX3Value, LV_BTN_STYLE_PR, &style_para_value); - labelX3Value = lv_label_create(buttonX3Value, NULL); - - buttonY3Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonY3Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonY3Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonY3Value, event_handler, ID_MANUAL_POS_Y3, NULL, 0); - lv_btn_set_style(buttonY3Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonY3Value, LV_BTN_STYLE_PR, &style_para_value); - labelY3Value = lv_label_create(buttonY3Value, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelPoint4Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelPoint4Text, &tft_style_label_rel); - lv_obj_set_pos(labelPoint4Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelPoint4Text, leveling_menu.position4); - - buttonX4Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonX4Value, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonX4Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonX4Value, event_handler, ID_MANUAL_POS_X4, NULL, 0); - lv_btn_set_style(buttonX4Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonX4Value, LV_BTN_STYLE_PR, &style_para_value); - labelX4Value = lv_label_create(buttonX4Value, NULL); - - buttonY4Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonY4Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonY4Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonY4Value, event_handler, ID_MANUAL_POS_Y4, NULL, 0); - lv_btn_set_style(buttonY4Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonY4Value, LV_BTN_STYLE_PR, &style_para_value); - labelY4Value = lv_label_create(buttonY4Value, NULL); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_MANUAL_POS_DOWN, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonX1Value); - lv_group_add_obj(g, buttonY1Value); - lv_group_add_obj(g, buttonX2Value); - lv_group_add_obj(g, buttonY2Value); - lv_group_add_obj(g, buttonX3Value); - lv_group_add_obj(g, buttonY3Value); - lv_group_add_obj(g, buttonX4Value); - lv_group_add_obj(g, buttonY4Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_MANUAL_POS_DOWN, true); } else { - labelPoint5Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelPoint5Text, &tft_style_label_rel); - lv_obj_set_pos(labelPoint5Text, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelPoint5Text, leveling_menu.position5); + sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[4][0]); + sprintf_P(buf2, PSTR("%d"), gCfgItems.levelingPos[4][1]); + lv_screen_menu_item_2_edit(scr, leveling_menu.position4, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MANUAL_POS_Y5, 0, buf2, ID_MANUAL_POS_X5, public_buf_l); - buttonX5Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonX5Value, PARA_UI_VALUE_POS_X_2, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonX5Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonX5Value, event_handler, ID_MANUAL_POS_X5, NULL, 0); - lv_btn_set_style(buttonX5Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonX5Value, LV_BTN_STYLE_PR, &style_para_value); - labelX5Value = lv_label_create(buttonX5Value, NULL); - - buttonY5Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonY5Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V_2); - lv_obj_set_size(buttonY5Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonY5Value, event_handler, ID_MANUAL_POS_Y5, NULL, 0); - lv_btn_set_style(buttonY5Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonY5Value, LV_BTN_STYLE_PR, &style_para_value); - labelY5Value = lv_label_create(buttonY5Value, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_MANUAL_POS_UP, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonX5Value); - lv_group_add_obj(g, buttonY5Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_MANUAL_POS_UP, true); } - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create(buttonTurnPage, NULL); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_MANUAL_POS_RETURN, NULL, 0); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create(buttonBack, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[0][0]); - lv_label_set_text(labelX1Value, public_buf_l); - lv_obj_align(labelX1Value, buttonX1Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[0][1]); - lv_label_set_text(labelY1Value, public_buf_l); - lv_obj_align(labelY1Value, buttonY1Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[1][0]); - lv_label_set_text(labelX2Value, public_buf_l); - lv_obj_align(labelX2Value, buttonX2Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[1][1]); - lv_label_set_text(labelY2Value, public_buf_l); - lv_obj_align(labelY2Value, buttonY2Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[2][0]); - lv_label_set_text(labelX3Value, public_buf_l); - lv_obj_align(labelX3Value, buttonX3Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[2][1]); - lv_label_set_text(labelY3Value, public_buf_l); - lv_obj_align(labelY3Value, buttonY3Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[3][0]); - lv_label_set_text(labelX4Value, public_buf_l); - lv_obj_align(labelX4Value, buttonX4Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[3][1]); - lv_label_set_text(labelY4Value, public_buf_l); - lv_obj_align(labelY4Value, buttonY4Value, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - else { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[4][0]); - lv_label_set_text(labelX5Value, public_buf_l); - lv_obj_align(labelX5Value, buttonX5Value, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%d"), gCfgItems.levelingPos[4][1]); - lv_label_set_text(labelY5Value, public_buf_l); - lv_obj_align(labelY5Value, buttonY5Value, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_MANUAL_POS_RETURN, true); } void lv_clear_manual_level_pos_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp index 6b43b8257b..60efda8b27 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_max_feedrate_settings.cpp @@ -29,300 +29,92 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_FEED_RETURN 1 -#define ID_FEED_X 2 -#define ID_FEED_Y 3 -#define ID_FEED_Z 4 -#define ID_FEED_E0 5 -#define ID_FEED_E1 6 -#define ID_FEED_DOWN 7 -#define ID_FEED_UP 8 +enum { + ID_FEED_RETURN = 1, + ID_FEED_X, + ID_FEED_Y, + ID_FEED_Z, + ID_FEED_E0, + ID_FEED_E1, + ID_FEED_DOWN, + ID_FEED_UP +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_FEED_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_max_feedrate_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_max_feedrate_settings(); + draw_return_ui(); break; case ID_FEED_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = XMaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = XMaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = YMaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = YMaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = ZMaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = ZMaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0MaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = E0MaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1MaxFeedRate; - lv_clear_max_feedrate_settings(); - lv_draw_number_key(); - } + value = E1MaxFeedRate; + lv_clear_max_feedrate_settings(); + lv_draw_number_key(); break; case ID_FEED_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_max_feedrate_settings(); - lv_draw_max_feedrate_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_max_feedrate_settings(); + lv_draw_max_feedrate_settings(); break; case ID_FEED_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_max_feedrate_settings(); - lv_draw_max_feedrate_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_max_feedrate_settings(); + lv_draw_max_feedrate_settings(); break; } } void lv_draw_max_feedrate_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *labelE0Text = NULL, *buttonE0Value = NULL, *labelE0Value = NULL; - lv_obj_t *labelE1Text = NULL, *buttonE1Value = NULL, *labelE1Value = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MAXFEEDRATE_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = MAXFEEDRATE_UI; - } - disp_state = MAXFEEDRATE_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.MaxFeedRateConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(MAXFEEDRATE_UI, machine_menu.MaxFeedRateConfTitle); if (uiCfg.para_ui_page != 1) { - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelXText, machine_menu.XMaxFeedRate); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.XMaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FEED_X, 0, public_buf_l); - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_FEED_X, NULL, 0); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - lv_btn_set_layout(buttonXValue, LV_LAYOUT_OFF); - labelXValue = lv_label_create(buttonXValue, NULL); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.YMaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_FEED_Y, 1, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.ZMaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_FEED_Z, 2, public_buf_l); - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelYText, machine_menu.YMaxFeedRate); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E0MaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_FEED_E0, 3, public_buf_l); - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_FEED_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - lv_btn_set_layout(buttonYValue, LV_LAYOUT_OFF); - labelYValue = lv_label_create(buttonYValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelZText, machine_menu.ZMaxFeedRate); - - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_FEED_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - lv_btn_set_layout(buttonZValue, LV_LAYOUT_OFF); - labelZValue = lv_label_create(buttonZValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelE0Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE0Text, &tft_style_label_rel); - lv_obj_set_pos(labelE0Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelE0Text, machine_menu.E0MaxFeedRate); - - buttonE0Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE0Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE0Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonE0Value, event_handler, ID_FEED_E0, NULL, 0); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_PR, &style_para_value); - lv_btn_set_layout(buttonE0Value, LV_LAYOUT_OFF); - labelE0Value = lv_label_create(buttonE0Value, NULL); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_FEED_DOWN, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FEED_DOWN, true); } else { - labelE1Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE1Text, &tft_style_label_rel); - lv_obj_set_pos(labelE1Text, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelE1Text, machine_menu.E1MaxFeedRate); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS_N(1)]); + lv_screen_menu_item_1_edit(scr, machine_menu.E1MaxFeedRate, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_FEED_E1, 0, public_buf_l); - buttonE1Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE1Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE1Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonE1Value, event_handler, ID_FEED_E1, NULL, 0); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_PR, &style_para_value); - lv_btn_set_layout(buttonE1Value, LV_LAYOUT_OFF); - labelE1Value = lv_label_create(buttonE1Value, NULL); - - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_FEED_UP, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_FEED_UP, true); } - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create(buttonTurnPage, NULL); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_FEED_RETURN, NULL, 0); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - label_Back = lv_label_create(buttonBack, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS]); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - } - else { - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.max_feedrate_mm_s[E_AXIS_N(1)]); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_FEED_RETURN, true); } void lv_clear_max_feedrate_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp index 1766abf061..61cefd7615 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_motor_settings.cpp @@ -28,309 +28,68 @@ #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_MOTOR_RETURN 1 -#define ID_MOTOR_STEPS 2 -#define ID_MOTOR_STEPS_ARROW 3 -#define ID_MOTOR_TMC_CURRENT 4 -#define ID_MOTOR_TMC_CURRENT_ARROW 5 -#define ID_MOTOR_STEP_MODE 6 -#define ID_MOTOR_STEP_MODE_ARROW 7 -#define ID_HOME_SENSE 8 -#define ID_HOME_SENSE_ARROW 9 +enum { + ID_MOTOR_RETURN = 1, + ID_MOTOR_STEPS, + ID_MOTOR_TMC_CURRENT, + ID_MOTOR_STEP_MODE, + ID_HOME_SENSE +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_MOTOR_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - draw_return_ui(); - } + lv_clear_motor_settings(); + draw_return_ui(); break; case ID_MOTOR_STEPS: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_step_settings(); - } - break; - case ID_MOTOR_STEPS_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_step_settings(); - } + lv_clear_motor_settings(); + lv_draw_step_settings(); break; #if USE_SENSORLESS - case ID_HOME_SENSE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + case ID_HOME_SENSE: lv_clear_motor_settings(); lv_draw_homing_sensitivity_settings(); - } - break; - case ID_HOME_SENSE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_homing_sensitivity_settings(); - } - break; + break; #endif - #if HAS_TRINAMIC_CONFIG - case ID_MOTOR_TMC_CURRENT: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_current_settings(); - } + #if HAS_TRINAMIC_CONFIG + case ID_MOTOR_TMC_CURRENT: + lv_clear_motor_settings(); + lv_draw_tmc_current_settings(); + break; + #if HAS_STEALTHCHOP + case ID_MOTOR_STEP_MODE: + lv_clear_motor_settings(); + lv_draw_tmc_step_mode_settings(); break; - case ID_MOTOR_TMC_CURRENT_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_current_settings(); - } - break; - #if HAS_STEALTHCHOP - case ID_MOTOR_STEP_MODE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_step_mode_settings(); - } - break; - case ID_MOTOR_STEP_MODE_ARROW: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_motor_settings(); - lv_draw_tmc_step_mode_settings(); - } - break; - #endif #endif + #endif } } void lv_draw_motor_settings(void) { - lv_obj_t *buttonBack, *label_Back; - lv_obj_t *buttonSteps, *labelSteps, *buttonStepsNarrow; - lv_obj_t * line1; + int index = 0; + + scr = lv_screen_create(MOTOR_SETTINGS_UI, machine_menu.MotorConfTitle); + lv_screen_menu_item(scr, machine_menu.StepsConf, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_MOTOR_STEPS, index++); #if USE_SENSORLESS - lv_obj_t *buttonSensitivity, *labelSensitivity, *buttonSensitivityNarrow; - lv_obj_t * line2; + lv_screen_menu_item(scr, machine_menu.HomingSensitivityConf, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_HOME_SENSE, index); + index++; #endif #if HAS_TRINAMIC_CONFIG - #if USE_SENSORLESS - lv_obj_t * line3; - #else - lv_obj_t * line2; - #endif - lv_obj_t *buttonTMCcurrent, *labelTMCcurrent, *buttonTMCcurrentNarrow; + lv_screen_menu_item(scr, machine_menu.TMCcurrentConf, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_MOTOR_TMC_CURRENT, index); + index++; #if HAS_STEALTHCHOP - #if USE_SENSORLESS - lv_obj_t * line4; - #else - lv_obj_t * line3; - #endif - lv_obj_t *buttonStepMode, *labelStepMode, *buttonStepModeNarrow; + lv_screen_menu_item(scr, machine_menu.TMCStepModeConf, PARA_UI_POS_X, PARA_UI_POS_Y * (index + 1), event_handler, ID_MOTOR_STEP_MODE, index); + index++; #endif #endif - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MOTOR_SETTINGS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = MOTOR_SETTINGS_UI; - } - disp_state = MOTOR_SETTINGS_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.MotorConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonSteps = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonSteps, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonSteps, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonSteps, event_handler, ID_MOTOR_STEPS, NULL, 0); - lv_btn_set_style(buttonSteps, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonSteps, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonSteps, LV_LAYOUT_OFF); - labelSteps = lv_label_create(buttonSteps, NULL); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonSteps); - #endif - - buttonStepsNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonStepsNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonStepsNarrow, event_handler, ID_MOTOR_STEPS_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonStepsNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonStepsNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonStepsNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonStepsNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonStepsNarrow, LV_LAYOUT_OFF); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - #if USE_SENSORLESS - buttonSensitivity = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonSensitivity, PARA_UI_POS_X, PARA_UI_POS_Y * 2); /*Set its position*/ - lv_obj_set_size(buttonSensitivity, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonSensitivity, event_handler, ID_HOME_SENSE, NULL, 0); - lv_btn_set_style(buttonSensitivity, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonSensitivity, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonSensitivity, LV_LAYOUT_OFF); - labelSensitivity = lv_label_create(buttonSensitivity, NULL); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonSensitivity); - #endif - - buttonSensitivityNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonSensitivityNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, PARA_UI_POS_Y * 2 + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonSensitivityNarrow, event_handler, ID_HOME_SENSE_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonSensitivityNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonSensitivityNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonSensitivityNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonSensitivityNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonSensitivityNarrow, LV_LAYOUT_OFF); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - #endif - - - #if HAS_TRINAMIC_CONFIG - buttonTMCcurrent = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonTMCcurrent, PARA_UI_POS_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 3, PARA_UI_POS_Y * 2)); - lv_obj_set_size(buttonTMCcurrent, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - //lv_obj_set_event_cb(buttonMachine, event_handler); - lv_obj_set_event_cb_mks(buttonTMCcurrent, event_handler, ID_MOTOR_TMC_CURRENT, NULL, 0); - lv_btn_set_style(buttonTMCcurrent, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonTMCcurrent, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonTMCcurrent, LV_LAYOUT_OFF); - labelTMCcurrent = lv_label_create(buttonTMCcurrent, NULL); /*Add a label to the button*/ - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTMCcurrent); - #endif - - buttonTMCcurrentNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonTMCcurrentNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 3, PARA_UI_POS_Y * 2) + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonTMCcurrentNarrow, event_handler, ID_MOTOR_TMC_CURRENT_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonTMCcurrentNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonTMCcurrentNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonTMCcurrentNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonTMCcurrentNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonTMCcurrentNarrow, LV_LAYOUT_OFF); - #if USE_SENSORLESS - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - #else - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - #endif - - #if HAS_STEALTHCHOP - buttonStepMode = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonStepMode, PARA_UI_POS_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 4, PARA_UI_POS_Y * 3)); - lv_obj_set_size(buttonStepMode, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb_mks(buttonStepMode, event_handler, ID_MOTOR_STEP_MODE, NULL, 0); - lv_btn_set_style(buttonStepMode, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonStepMode, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonStepMode, LV_LAYOUT_OFF); - labelStepMode = lv_label_create(buttonStepMode, NULL); /*Add a label to the button*/ - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonStepMode); - #endif - - buttonStepModeNarrow = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonStepModeNarrow, PARA_UI_POS_X + PARA_UI_SIZE_X, TERN(USE_SENSORLESS, PARA_UI_POS_Y * 4, PARA_UI_POS_Y * 3) + PARA_UI_ARROW_V); - lv_obj_set_event_cb_mks(buttonStepModeNarrow, event_handler, ID_MOTOR_STEP_MODE_ARROW, NULL, 0); - lv_imgbtn_set_src(buttonStepModeNarrow, LV_BTN_STATE_REL, "F:/bmp_arrow.bin"); - lv_imgbtn_set_src(buttonStepModeNarrow, LV_BTN_STATE_PR, "F:/bmp_arrow.bin"); - lv_imgbtn_set_style(buttonStepModeNarrow, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonStepModeNarrow, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonStepModeNarrow, LV_LAYOUT_OFF); - - #if USE_SENSORLESS - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - #else - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - #endif - - #endif // HAS_STEALTHCHOP - - #endif // HAS_TRINAMIC_CONFIG - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_MOTOR_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelSteps, machine_menu.StepsConf); - lv_obj_align(labelSteps, buttonSteps, LV_ALIGN_IN_LEFT_MID, 0, 0); - - #if USE_SENSORLESS - lv_label_set_text(labelSensitivity, machine_menu.HomingSensitivityConf); - lv_obj_align(labelSensitivity, buttonSensitivity, LV_ALIGN_IN_LEFT_MID, 0, 0); - #endif - #if HAS_TRINAMIC_CONFIG - lv_label_set_text(labelTMCcurrent, machine_menu.TMCcurrentConf); - lv_obj_align(labelTMCcurrent, buttonTMCcurrent, LV_ALIGN_IN_LEFT_MID, 0, 0); - #if HAS_STEALTHCHOP - lv_label_set_text(labelStepMode, machine_menu.TMCStepModeConf); - lv_obj_align(labelStepMode, buttonStepMode, LV_ALIGN_IN_LEFT_MID, 0, 0); - #endif - #endif - } - + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X + 10, PARA_UI_BACL_POS_Y, event_handler, ID_MOTOR_RETURN, true); } void lv_clear_motor_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp index 8e8302d707..30f2a00422 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp @@ -33,295 +33,121 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *labelV, *buttonV; -#define ID_M_X_P 1 -#define ID_M_X_N 2 -#define ID_M_Y_P 3 -#define ID_M_Y_N 4 -#define ID_M_Z_P 5 -#define ID_M_Z_N 6 -#define ID_M_STEP 7 -#define ID_M_RETURN 8 +enum { + ID_M_X_P = 1, + ID_M_X_N, + ID_M_Y_P, + ID_M_Y_N, + ID_M_Z_P, + ID_M_Z_N, + ID_M_STEP, + ID_M_RETURN +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_M_X_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_one_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 X%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_one_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_one_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 X%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_one_P(PSTR("G90")); } break; case ID_M_X_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 X-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 X-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Y_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Y%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Y%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Y_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Y-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Y-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Z_P: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Z%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Z%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_Z_N: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (queue.length <= (BUFSIZE - 3)) { - ZERO(public_buf_l); - queue.enqueue_now_P(PSTR("G91")); - sprintf_P(public_buf_l, PSTR("G1 Z-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); - queue.enqueue_one_now(public_buf_l); - queue.enqueue_now_P(PSTR("G90")); - } + if (queue.length <= (BUFSIZE - 3)) { + queue.enqueue_now_P(PSTR("G91")); + sprintf_P(public_buf_l, PSTR("G1 Z-%3.1f F%d"), uiCfg.move_dist, uiCfg.moveSpeed); + queue.enqueue_one_now(public_buf_l); + queue.enqueue_now_P(PSTR("G90")); } break; case ID_M_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (abs(10 * (int)uiCfg.move_dist) == 100) - uiCfg.move_dist = 0.1; - else - uiCfg.move_dist *= (float)10; - - disp_move_dist(); - } - + if (abs(10 * (int)uiCfg.move_dist) == 100) + uiCfg.move_dist = 0.1; + else + uiCfg.move_dist *= (float)10; + disp_move_dist(); break; case ID_M_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_move_motor(void) { - lv_obj_t *buttonXI, *buttonXD, *buttonYI, *buttonYD, *buttonZI, *buttonZD, *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != MOVE_MOTOR_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = MOVE_MOTOR_UI; - } - disp_state = MOVE_MOTOR_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - // Create an Image button - buttonXI = lv_imgbtn_create(scr, NULL); - buttonXD = lv_imgbtn_create(scr, NULL); - buttonYI = lv_imgbtn_create(scr, NULL); - buttonYD = lv_imgbtn_create(scr, NULL); - buttonZI = lv_imgbtn_create(scr, NULL); - buttonZD = lv_imgbtn_create(scr, NULL); - buttonV = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonXI, event_handler, ID_M_X_P, NULL, 0); - lv_imgbtn_set_src(buttonXI, LV_BTN_STATE_REL, "F:/bmp_xAdd.bin"); - lv_imgbtn_set_src(buttonXI, LV_BTN_STATE_PR, "F:/bmp_xAdd.bin"); - lv_imgbtn_set_style(buttonXI, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonXI, LV_BTN_STATE_REL, &tft_style_label_rel); + scr = lv_screen_create(MOVE_MOTOR_UI); + lv_obj_t *buttonXI = lv_big_button_create(scr, "F:/bmp_xAdd.bin", move_menu.x_add, INTERVAL_V, titleHeight, event_handler, ID_M_X_P); lv_obj_clear_protect(buttonXI, LV_PROTECT_FOLLOW); + lv_big_button_create(scr, "F:/bmp_xDec.bin", move_menu.x_dec, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_X_N); + lv_big_button_create(scr, "F:/bmp_yAdd.bin", move_menu.y_add, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_M_Y_P); + lv_big_button_create(scr, "F:/bmp_yDec.bin", move_menu.y_dec, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Y_N); + lv_big_button_create(scr, "F:/bmp_zAdd.bin", move_menu.z_add, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_M_Z_P); + lv_big_button_create(scr, "F:/bmp_zDec.bin", move_menu.z_dec, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_Z_N); - #if 1 - lv_obj_set_event_cb_mks(buttonXD, event_handler, ID_M_X_N, NULL, 0); - lv_imgbtn_set_src(buttonXD, LV_BTN_STATE_REL, "F:/bmp_xDec.bin"); - lv_imgbtn_set_src(buttonXD, LV_BTN_STATE_PR, "F:/bmp_xDec.bin"); - lv_imgbtn_set_style(buttonXD, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonXD, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonYI, event_handler, ID_M_Y_P, NULL, 0); - lv_imgbtn_set_src(buttonYI, LV_BTN_STATE_REL, "F:/bmp_yAdd.bin"); - lv_imgbtn_set_src(buttonYI, LV_BTN_STATE_PR, "F:/bmp_yAdd.bin"); - lv_imgbtn_set_style(buttonYI, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonYI, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonYD, event_handler, ID_M_Y_N, NULL, 0); - lv_imgbtn_set_src(buttonYD, LV_BTN_STATE_REL, "F:/bmp_yDec.bin"); - lv_imgbtn_set_src(buttonYD, LV_BTN_STATE_PR, "F:/bmp_yDec.bin"); - lv_imgbtn_set_style(buttonYD, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonYD, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonZI, event_handler, ID_M_Z_P, NULL, 0); - lv_imgbtn_set_src(buttonZI, LV_BTN_STATE_REL, "F:/bmp_zAdd.bin"); - lv_imgbtn_set_src(buttonZI, LV_BTN_STATE_PR, "F:/bmp_zAdd.bin"); - lv_imgbtn_set_style(buttonZI, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonZI, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonZD, event_handler, ID_M_Z_N, NULL, 0); - lv_imgbtn_set_src(buttonZD, LV_BTN_STATE_REL, "F:/bmp_zDec.bin"); - lv_imgbtn_set_src(buttonZD, LV_BTN_STATE_PR, "F:/bmp_zDec.bin"); - lv_imgbtn_set_style(buttonZD, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonZD, LV_BTN_STATE_REL, &tft_style_label_rel); - - //lv_obj_set_event_cb_mks(buttonV, event_handler,ID_T_MORE,"bmp_More.bin",0); - lv_obj_set_event_cb_mks(buttonV, event_handler, ID_M_STEP, NULL, 0); - lv_imgbtn_set_style(buttonV, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonV, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_M_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif // if 1 - - lv_obj_set_pos(buttonXI, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonYI, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonZI, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - lv_obj_set_pos(buttonV, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonXD, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonYD, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonZD, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonXI, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonXD, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonYI, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonYD, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonZI, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonZD, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonV, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelXI = lv_label_create(buttonXI, NULL); - lv_obj_t *labelXD = lv_label_create(buttonXD, NULL); - lv_obj_t *labelYI = lv_label_create(buttonYI, NULL); - lv_obj_t *labelYD = lv_label_create(buttonYD, NULL); - lv_obj_t *labelZI = lv_label_create(buttonZI, NULL); - lv_obj_t *labelZD = lv_label_create(buttonZD, NULL); - labelV = lv_label_create(buttonV, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelXI, move_menu.x_add); - lv_obj_align(labelXI, buttonXI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelXD, move_menu.x_dec); - lv_obj_align(labelXD, buttonXD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYI, move_menu.y_add); - lv_obj_align(labelYI, buttonYI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelYD, move_menu.y_dec); - lv_obj_align(labelYD, buttonYD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZI, move_menu.z_add); - lv_obj_align(labelZI, buttonZI, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelZD, move_menu.z_dec); - lv_obj_align(labelZD, buttonZD, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } + // button with image and label changed dinamycally by disp_move_dist + buttonV = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_M_STEP); + labelV = lv_label_create_empty(buttonV); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXI); - lv_group_add_obj(g, buttonXD); - lv_group_add_obj(g, buttonYI); - lv_group_add_obj(g, buttonYD); - lv_group_add_obj(g, buttonZI); - lv_group_add_obj(g, buttonZD); lv_group_add_obj(g, buttonV); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_M_RETURN); + disp_move_dist(); } void disp_move_dist() { // char buf[30] = {0}; - if ((int)(10 * uiCfg.move_dist) == 1) { - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_REL, "F:/bmp_step_move0_1.bin"); - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_PR, "F:/bmp_step_move0_1.bin"); - } - else if ((int)(10 * uiCfg.move_dist) == 10) { - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_REL, "F:/bmp_step_move1.bin"); - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_PR, "F:/bmp_step_move1.bin"); - } - else if ((int)(10 * uiCfg.move_dist) == 100) { - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_REL, "F:/bmp_step_move10.bin"); - lv_imgbtn_set_src(buttonV, LV_BTN_STATE_PR, "F:/bmp_step_move10.bin"); - } + if ((int)(10 * uiCfg.move_dist) == 1) + lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move0_1.bin"); + else if ((int)(10 * uiCfg.move_dist) == 10) + lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move1.bin"); + else if ((int)(10 * uiCfg.move_dist) == 100) + lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move10.bin"); + if (gCfgItems.multiple_language) { if ((int)(10 * uiCfg.move_dist) == 1) { lv_label_set_text(labelV, move_menu.step_01mm); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp index 585c2fa75e..0989b95f82 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_number_key.cpp @@ -49,30 +49,32 @@ #include "../../../../module/probe.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t *buttonValue = NULL; -static lv_obj_t *labelValue = NULL; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *buttonValue = nullptr; +static lv_obj_t *labelValue = nullptr; -static char key_value[11] = {0}; -static uint8_t cnt = 0; -static char point_flg = 1; +static char key_value[11] = { 0 }; +static uint8_t cnt = 0; +static bool point_flag = true; -#define ID_NUM_KEY1 1 -#define ID_NUM_KEY2 2 -#define ID_NUM_KEY3 3 -#define ID_NUM_KEY4 4 -#define ID_NUM_KEY5 5 -#define ID_NUM_KEY6 6 -#define ID_NUM_KEY7 7 -#define ID_NUM_KEY8 8 -#define ID_NUM_KEY9 9 -#define ID_NUM_KEY0 10 -#define ID_NUM_BACK 11 -#define ID_NUM_RESET 12 -#define ID_NUM_CONFIRM 13 -#define ID_NUM_POINT 14 -#define ID_NUM_NAGETIVE 15 +enum { + ID_NUM_KEY1 = 1, + ID_NUM_KEY2, + ID_NUM_KEY3, + ID_NUM_KEY4, + ID_NUM_KEY5, + ID_NUM_KEY6, + ID_NUM_KEY7, + ID_NUM_KEY8, + ID_NUM_KEY9, + ID_NUM_KEY0, + ID_NUM_BACK, + ID_NUM_RESET, + ID_NUM_CONFIRM, + ID_NUM_POINT, + ID_NUM_NEGATIVE +}; static void disp_key_value() { char *temp; @@ -80,8 +82,6 @@ static void disp_key_value() { float milliamps; #endif - ZERO(public_buf_m); - switch (value) { case PrintAcceleration: sprintf_P(public_buf_m, PSTR("%.1f"), planner.settings.acceleration); @@ -289,14 +289,11 @@ static void disp_key_value() { #endif break; } - ZERO(key_value); + strcpy(key_value, public_buf_m); cnt = strlen(key_value); temp = strchr(key_value, '.'); - if (temp) - point_flg = 0; - else - point_flg = 1; + point_flag = !temp; lv_label_set_text(labelValue, key_value); lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); @@ -540,409 +537,208 @@ static void set_value_confirm() { gcode.process_subcommands_now_P(PSTR("M500")); } -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_NUM_KEY1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'1'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'1'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY2: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'2'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'2'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY3: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'3'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'3'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY4: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'4'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'4'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY5: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'5'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'5'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY6: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'6'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'6'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY7: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'7'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'7'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY8: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'8'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'8'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY9: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'9'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'9'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_KEY0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt <= 10) { - key_value[cnt] = (char)'0'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt <= 10) { + key_value[cnt] = (char)'0'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_BACK: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt > 0) - cnt--; - if (key_value[cnt] == (char)'.') point_flg = 1; - key_value[cnt] = (char)'\0'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - } + if (cnt > 0) cnt--; + if (key_value[cnt] == (char)'.') point_flag = true; + key_value[cnt] = (char)'\0'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); break; case ID_NUM_RESET: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - ZERO(key_value); - cnt = 0; - key_value[cnt] = (char)'0'; - point_flg = 1; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - } + ZERO(key_value); + cnt = 0; + key_value[cnt] = (char)'0'; + point_flag = true; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); break; case ID_NUM_POINT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if ((cnt != 0) && (point_flg == 1)) { - point_flg = 0; - key_value[cnt] = (char)'.'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + if (cnt != 0 && point_flag) { + point_flag = false; + key_value[cnt] = (char)'.'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; - case ID_NUM_NAGETIVE: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (cnt == 0) { - key_value[cnt] = (char)'-'; - lv_label_set_text(labelValue, key_value); - lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); - cnt++; - } + case ID_NUM_NEGATIVE: + if (cnt == 0) { + key_value[cnt] = (char)'-'; + lv_label_set_text(labelValue, key_value); + lv_obj_align(labelValue, buttonValue, LV_ALIGN_CENTER, 0, 0); + cnt++; } break; case ID_NUM_CONFIRM: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - last_disp_state = NUMBER_KEY_UI; - if (strlen(key_value) != 0) - set_value_confirm(); - lv_clear_number_key(); - draw_return_ui(); - } + last_disp_state = NUMBER_KEY_UI; + if (strlen(key_value) != 0) set_value_confirm(); + lv_clear_number_key(); + draw_return_ui(); break; } } void lv_draw_number_key(void) { - lv_obj_t *NumberKey_1 = NULL, *NumberKey_2 = NULL, *NumberKey_3 = NULL, *NumberKey_4 = NULL, *NumberKey_5 = NULL; - lv_obj_t *NumberKey_6 = NULL, *NumberKey_7 = NULL, *NumberKey_8 = NULL, *NumberKey_9 = NULL, *NumberKey_0 = NULL; - lv_obj_t *KeyPoint = NULL, *KeyConfirm = NULL, *KeyReset = NULL, *KeyBack = NULL; - lv_obj_t *Minus = NULL; - lv_obj_t *labelKey_1 = NULL, *labelKey_2 = NULL, *labelKey_3 = NULL, *labelKey_4 = NULL, *labelKey_5 = NULL; - lv_obj_t *labelKey_6 = NULL, *labelKey_7 = NULL, *labelKey_8 = NULL, *labelKey_9 = NULL, *labelKey_0 = NULL; - lv_obj_t *labelKeyPoint = NULL, *labelKeyConfirm = NULL, *labelKeyReset = NULL, *labelKeyBack = NULL; - lv_obj_t *labelMinus = NULL; + scr = lv_screen_create(NUMBER_KEY_UI, ""); - buttonValue = NULL; - labelValue = NULL; + buttonValue = lv_btn_create(scr, 92, 40, 296, 40, event_handler, ID_NUM_KEY1, &style_num_text); + labelValue = lv_label_create_empty(buttonValue); - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != NUMBER_KEY_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = NUMBER_KEY_UI; - } - disp_state = NUMBER_KEY_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - //lv_obj_t * title = lv_label_create(scr, NULL); - //lv_obj_set_style(title, &tft_style_label_rel); - //lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS); - //lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonValue = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonValue, 92, 40); /*Set its position*/ - lv_obj_set_size(buttonValue, 296, 40); - lv_obj_set_event_cb_mks(buttonValue, event_handler, ID_NUM_KEY1, NULL, 0); - lv_btn_set_style(buttonValue, LV_BTN_STYLE_REL, &style_num_text); /*Set the button's released style*/ - lv_btn_set_style(buttonValue, LV_BTN_STYLE_PR, &style_num_text); /*Set the button's pressed style*/ - //lv_btn_set_layout(buttonValue, LV_LAYOUT_OFF); - labelValue = lv_label_create(buttonValue, NULL); /*Add a label to the button*/ - - NumberKey_1 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_1, 92, 90); /*Set its position*/ - lv_obj_set_size(NumberKey_1, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_1, event_handler, ID_NUM_KEY1, NULL, 0); - lv_btn_set_style(NumberKey_1, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_1, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_1, LV_LAYOUT_OFF); - labelKey_1 = lv_label_create(NumberKey_1, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_1 = lv_btn_create(scr, 92, 90, 68, 40, event_handler, ID_NUM_KEY1, &style_num_key_pre); + lv_obj_t *labelKey_1 = lv_label_create_empty(NumberKey_1); lv_label_set_text(labelKey_1, machine_menu.key_1); lv_obj_align(labelKey_1, NumberKey_1, LV_ALIGN_CENTER, 0, 0); - NumberKey_2 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_2, 168, 90); /*Set its position*/ - lv_obj_set_size(NumberKey_2, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_2, event_handler, ID_NUM_KEY2, NULL, 0); - lv_btn_set_style(NumberKey_2, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_2, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_2, LV_LAYOUT_OFF); - labelKey_2 = lv_label_create(NumberKey_2, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_2 = lv_btn_create(scr, 168, 90, 68, 40, event_handler, ID_NUM_KEY2, &style_num_key_pre); + lv_obj_t *labelKey_2 = lv_label_create_empty(NumberKey_2); lv_label_set_text(labelKey_2, machine_menu.key_2); lv_obj_align(labelKey_2, NumberKey_2, LV_ALIGN_CENTER, 0, 0); - NumberKey_3 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_3, 244, 90); /*Set its position*/ - lv_obj_set_size(NumberKey_3, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_3, event_handler, ID_NUM_KEY3, NULL, 0); - lv_btn_set_style(NumberKey_3, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_3, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_3, LV_LAYOUT_OFF); - labelKey_3 = lv_label_create(NumberKey_3, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_3 = lv_btn_create(scr, 244, 90, 68, 40, event_handler, ID_NUM_KEY3, &style_num_key_pre); + lv_obj_t *labelKey_3 = lv_label_create_empty(NumberKey_3); lv_label_set_text(labelKey_3, machine_menu.key_3); lv_obj_align(labelKey_3, NumberKey_3, LV_ALIGN_CENTER, 0, 0); - NumberKey_4 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_4, 92, 140); /*Set its position*/ - lv_obj_set_size(NumberKey_4, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_4, event_handler, ID_NUM_KEY4, NULL, 0); - lv_btn_set_style(NumberKey_4, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_4, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_4, LV_LAYOUT_OFF); - labelKey_4 = lv_label_create(NumberKey_4, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_4 = lv_btn_create(scr, 92, 140, 68, 40, event_handler, ID_NUM_KEY4, &style_num_key_pre); + lv_obj_t *labelKey_4 = lv_label_create_empty(NumberKey_4); lv_label_set_text(labelKey_4, machine_menu.key_4); lv_obj_align(labelKey_4, NumberKey_4, LV_ALIGN_CENTER, 0, 0); - NumberKey_5 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_5, 168, 140); /*Set its position*/ - lv_obj_set_size(NumberKey_5, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_5, event_handler, ID_NUM_KEY5, NULL, 0); - lv_btn_set_style(NumberKey_5, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_5, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_5, LV_LAYOUT_OFF); - labelKey_5 = lv_label_create(NumberKey_5, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_5 = lv_btn_create(scr, 168, 140, 68, 40, event_handler, ID_NUM_KEY5, &style_num_key_pre); + lv_obj_t *labelKey_5 = lv_label_create_empty(NumberKey_5); lv_label_set_text(labelKey_5, machine_menu.key_5); lv_obj_align(labelKey_5, NumberKey_5, LV_ALIGN_CENTER, 0, 0); - NumberKey_6 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_6, 244, 140); /*Set its position*/ - lv_obj_set_size(NumberKey_6, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_6, event_handler, ID_NUM_KEY6, NULL, 0); - lv_btn_set_style(NumberKey_6, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_6, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_6, LV_LAYOUT_OFF); - labelKey_6 = lv_label_create(NumberKey_6, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_6 = lv_btn_create(scr, 244, 140, 68, 40, event_handler, ID_NUM_KEY6, &style_num_key_pre); + lv_obj_t *labelKey_6 = lv_label_create_empty(NumberKey_6); lv_label_set_text(labelKey_6, machine_menu.key_6); lv_obj_align(labelKey_6, NumberKey_6, LV_ALIGN_CENTER, 0, 0); - NumberKey_7 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_7, 92, 190); /*Set its position*/ - lv_obj_set_size(NumberKey_7, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_7, event_handler, ID_NUM_KEY7, NULL, 0); - lv_btn_set_style(NumberKey_7, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_7, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_7, LV_LAYOUT_OFF); - labelKey_7 = lv_label_create(NumberKey_7, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_7 = lv_btn_create(scr, 92, 190, 68, 40, event_handler, ID_NUM_KEY7, &style_num_key_pre); + lv_obj_t *labelKey_7 = lv_label_create_empty(NumberKey_7); lv_label_set_text(labelKey_7, machine_menu.key_7); lv_obj_align(labelKey_7, NumberKey_7, LV_ALIGN_CENTER, 0, 0); - NumberKey_8 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_8, 168, 190); /*Set its position*/ - lv_obj_set_size(NumberKey_8, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_8, event_handler, ID_NUM_KEY8, NULL, 0); - lv_btn_set_style(NumberKey_8, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_8, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_8, LV_LAYOUT_OFF); - labelKey_8 = lv_label_create(NumberKey_8, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_8 = lv_btn_create(scr, 168, 190, 68, 40, event_handler, ID_NUM_KEY8, &style_num_key_pre); + lv_obj_t *labelKey_8 = lv_label_create_empty(NumberKey_8); lv_label_set_text(labelKey_8, machine_menu.key_8); lv_obj_align(labelKey_8, NumberKey_8, LV_ALIGN_CENTER, 0, 0); - NumberKey_9 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_9, 244, 190); /*Set its position*/ - lv_obj_set_size(NumberKey_9, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_9, event_handler, ID_NUM_KEY9, NULL, 0); - lv_btn_set_style(NumberKey_9, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_9, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_9, LV_LAYOUT_OFF); - labelKey_9 = lv_label_create(NumberKey_9, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_9 = lv_btn_create(scr, 244, 190, 68, 40, event_handler, ID_NUM_KEY9, &style_num_key_pre); + lv_obj_t *labelKey_9 = lv_label_create_empty(NumberKey_9); lv_label_set_text(labelKey_9, machine_menu.key_9); lv_obj_align(labelKey_9, NumberKey_9, LV_ALIGN_CENTER, 0, 0); - NumberKey_0 = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(NumberKey_0, 92, 240); /*Set its position*/ - lv_obj_set_size(NumberKey_0, 68, 40); - lv_obj_set_event_cb_mks(NumberKey_0, event_handler, ID_NUM_KEY0, NULL, 0); - lv_btn_set_style(NumberKey_0, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(NumberKey_0, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(NumberKey_0, LV_LAYOUT_OFF); - labelKey_0 = lv_label_create(NumberKey_0, NULL); /*Add a label to the button*/ + lv_obj_t *NumberKey_0 = lv_btn_create(scr, 92, 240, 68, 40, event_handler, ID_NUM_KEY0, &style_num_key_pre); + lv_obj_t *labelKey_0 = lv_label_create_empty(NumberKey_0); lv_label_set_text(labelKey_0, machine_menu.key_0); lv_obj_align(labelKey_0, NumberKey_0, LV_ALIGN_CENTER, 0, 0); - KeyBack = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyBack, 320, 90); /*Set its position*/ - lv_obj_set_size(KeyBack, 68, 40); - lv_obj_set_event_cb_mks(KeyBack, event_handler, ID_NUM_BACK, NULL, 0); - lv_btn_set_style(KeyBack, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyBack, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyBack, LV_LAYOUT_OFF); - labelKeyBack = lv_label_create(KeyBack, NULL); /*Add a label to the button*/ + lv_obj_t *KeyBack = lv_btn_create(scr, 320, 90, 68, 40, event_handler, ID_NUM_BACK, &style_num_key_pre); + lv_obj_t *labelKeyBack = lv_label_create_empty(KeyBack); lv_label_set_text(labelKeyBack, machine_menu.key_back); lv_obj_align(labelKeyBack, KeyBack, LV_ALIGN_CENTER, 0, 0); - KeyReset = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyReset, 320, 140); /*Set its position*/ - lv_obj_set_size(KeyReset, 68, 40); - lv_obj_set_event_cb_mks(KeyReset, event_handler, ID_NUM_RESET, NULL, 0); - lv_btn_set_style(KeyReset, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyReset, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyReset, LV_LAYOUT_OFF); - labelKeyReset = lv_label_create(KeyReset, NULL); /*Add a label to the button*/ + lv_obj_t *KeyReset = lv_btn_create(scr, 320, 140, 68, 40, event_handler, ID_NUM_RESET, &style_num_key_pre); + lv_obj_t *labelKeyReset = lv_label_create_empty(KeyReset); lv_label_set_text(labelKeyReset, machine_menu.key_reset); lv_obj_align(labelKeyReset, KeyReset, LV_ALIGN_CENTER, 0, 0); - KeyConfirm = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyConfirm, 320, 190); /*Set its position*/ - lv_obj_set_size(KeyConfirm, 68, 90); - lv_obj_set_event_cb_mks(KeyConfirm, event_handler, ID_NUM_CONFIRM, NULL, 0); - lv_btn_set_style(KeyConfirm, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyConfirm, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyConfirm, LV_LAYOUT_OFF); - labelKeyConfirm = lv_label_create(KeyConfirm, NULL); /*Add a label to the button*/ + lv_obj_t *KeyConfirm = lv_btn_create(scr, 320, 190, 68, 90, event_handler, ID_NUM_CONFIRM, &style_num_key_pre); + lv_obj_t *labelKeyConfirm = lv_label_create_empty(KeyConfirm); lv_label_set_text(labelKeyConfirm, machine_menu.key_confirm); lv_obj_align(labelKeyConfirm, KeyConfirm, LV_ALIGN_CENTER, 0, 0); - KeyPoint = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(KeyPoint, 244, 240); /*Set its position*/ - lv_obj_set_size(KeyPoint, 68, 40); - lv_obj_set_event_cb_mks(KeyPoint, event_handler, ID_NUM_POINT, NULL, 0); - lv_btn_set_style(KeyPoint, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(KeyPoint, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(KeyPoint, LV_LAYOUT_OFF); - labelKeyPoint = lv_label_create(KeyPoint, NULL); /*Add a label to the button*/ + lv_obj_t *KeyPoint = lv_btn_create(scr, 244, 240, 68, 40, event_handler, ID_NUM_POINT, &style_num_key_pre); + lv_obj_t *labelKeyPoint = lv_label_create_empty(KeyPoint); lv_label_set_text(labelKeyPoint, machine_menu.key_point); lv_obj_align(labelKeyPoint, KeyPoint, LV_ALIGN_CENTER, 0, 0); - Minus = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(Minus, 168, 240); /*Set its position*/ - lv_obj_set_size(Minus, 68, 40); - lv_obj_set_event_cb_mks(Minus, event_handler, ID_NUM_NAGETIVE, NULL, 0); - lv_btn_set_style(Minus, LV_BTN_STYLE_REL, &style_num_key_pre); /*Set the button's released style*/ - lv_btn_set_style(Minus, LV_BTN_STYLE_PR, &style_num_key_rel); /*Set the button's pressed style*/ - //lv_btn_set_layout(Minus, LV_LAYOUT_OFF); - labelMinus = lv_label_create(Minus, NULL); /*Add a label to the button*/ + lv_obj_t *Minus = lv_btn_create(scr, 168, 240, 68, 40, event_handler, ID_NUM_NEGATIVE, &style_num_key_pre); + lv_obj_t *labelMinus = lv_label_create_empty(Minus); lv_label_set_text(labelMinus, machine_menu.negative); lv_obj_align(labelMinus, Minus, LV_ALIGN_CENTER, 0, 0); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp index 6ee5ac88c0..07df598d8f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp @@ -35,329 +35,163 @@ #include "../../../../sd/cardreader.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_O_PRE_HEAT 1 -#define ID_O_EXTRUCT 2 -#define ID_O_MOV 3 -#define ID_O_FILAMENT 4 -#define ID_O_SPEED 5 -#define ID_O_RETURN 6 -#define ID_O_FAN 7 -#define ID_O_POWER_OFF 8 -#define ID_O_BABY_STEP 9 +enum { + ID_O_PRE_HEAT = 1, + ID_O_EXTRUCT, + ID_O_MOV, + ID_O_FILAMENT, + ID_O_SPEED, + ID_O_RETURN, + ID_O_FAN, + ID_O_POWER_OFF, + ID_O_BABY_STEP +}; static lv_obj_t *label_PowerOff; static lv_obj_t *buttonPowerOff; extern feedRate_t feedrate_mm_s; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_O_PRE_HEAT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_preHeat(); - } + lv_clear_operation(); + lv_draw_preHeat(); break; case ID_O_EXTRUCT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_extrusion(); - } + lv_clear_operation(); + lv_draw_extrusion(); break; case ID_O_MOV: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_move_motor(); - } + lv_clear_operation(); + lv_draw_move_motor(); break; case ID_O_FILAMENT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_MULTI_EXTRUDER - uiCfg.curSprayerChoose_bak = active_extruder; + #if HAS_MULTI_EXTRUDER + uiCfg.curSprayerChoose_bak = active_extruder; + #endif + if (uiCfg.print_state == WORKING) { + #if ENABLED(SDSUPPORT) + card.pauseSDPrint(); + stop_print_time(); + uiCfg.print_state = PAUSING; #endif - if (uiCfg.print_state == WORKING) { - #if ENABLED(SDSUPPORT) - card.pauseSDPrint(); - stop_print_time(); - uiCfg.print_state = PAUSING; - #endif - } - uiCfg.moveSpeed_bak = (uint16_t)feedrate_mm_s; - uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[active_extruder].target; - lv_clear_operation(); - lv_draw_filament_change(); } + uiCfg.moveSpeed_bak = (uint16_t)feedrate_mm_s; + uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[active_extruder].target; + lv_clear_operation(); + lv_draw_filament_change(); break; case ID_O_FAN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_fan(); - } + lv_clear_operation(); + lv_draw_fan(); break; case ID_O_SPEED: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_change_speed(); - } + lv_clear_operation(); + lv_draw_change_speed(); break; case ID_O_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; case ID_O_POWER_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (gCfgItems.finish_power_off) { + gCfgItems.finish_power_off = false; + lv_imgbtn_set_src_both(buttonPowerOff, "F:/bmp_manual_off.bin"); + lv_label_set_text(label_PowerOff, printing_more_menu.manual); } - else if (event == LV_EVENT_RELEASED) { - if (gCfgItems.finish_power_off) { - gCfgItems.finish_power_off = false; - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_manual_off.bin"); - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_manual_off.bin"); - lv_label_set_text(label_PowerOff, printing_more_menu.manual); - } - else { - gCfgItems.finish_power_off = true; - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_auto_off.bin"); - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_auto_off.bin"); - lv_label_set_text(label_PowerOff, printing_more_menu.auto_close); - } - lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - lv_obj_refresh_ext_draw_pad(label_PowerOff); - update_spi_flash(); + else { + gCfgItems.finish_power_off = true; + lv_imgbtn_set_src_both(buttonPowerOff, "F:/bmp_auto_off.bin"); + lv_label_set_text(label_PowerOff, printing_more_menu.auto_close); } + lv_obj_align(label_PowerOff, buttonPowerOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_refresh_ext_draw_pad(label_PowerOff); + update_spi_flash(); break; case ID_O_BABY_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_operation(); - lv_draw_baby_stepping(); - } + lv_clear_operation(); + lv_draw_baby_stepping(); break; } } void lv_draw_operation(void) { - lv_obj_t *buttonPreHeat = NULL, *buttonExtrusion = NULL, *buttonSpeed = NULL; - lv_obj_t *buttonBack = NULL, *buttonFan = NULL; - lv_obj_t *labelPreHeat = NULL, *labelExtrusion = NULL; - lv_obj_t *label_Back = NULL, *label_Speed = NULL, *label_Fan = NULL; - lv_obj_t *buttonMove = NULL, *label_Move = NULL; - lv_obj_t *buttonBabyStep = NULL, *label_BabyStep = NULL; - lv_obj_t *buttonFilament = NULL, *label_Filament = NULL; + lv_obj_t *buttonExtrusion = nullptr, *buttonSpeed = nullptr, + *buttonBack = nullptr, + *labelPreHeat = nullptr, *labelExtrusion = nullptr, + *label_Back = nullptr, *label_Speed = nullptr, *label_Fan = nullptr, + *buttonMove = nullptr, *label_Move = nullptr, + *buttonBabyStep = nullptr, *label_BabyStep = nullptr, + *label_Filament = nullptr; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != OPERATE_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = OPERATE_UI; - } - disp_state = OPERATE_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(OPERATE_UI); // Create image buttons - buttonPreHeat = lv_imgbtn_create(scr, NULL); - buttonFilament = lv_imgbtn_create(scr, NULL); - buttonFan = lv_imgbtn_create(scr, NULL); - buttonPowerOff = lv_imgbtn_create(scr, NULL); + lv_obj_t *buttonPreHeat = lv_imgbtn_create(scr, "F:/bmp_temp.bin", INTERVAL_V, titleHeight, event_handler, ID_O_PRE_HEAT); + lv_obj_t *buttonFilament = lv_imgbtn_create(scr, "F:/bmp_filamentchange.bin", BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_O_FILAMENT); + lv_obj_t *buttonFan = lv_imgbtn_create(scr, "F:/bmp_fan.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_O_FAN); + buttonPowerOff = lv_imgbtn_create(scr, gCfgItems.finish_power_off ? "F:/bmp_auto_off.bin" : "F:/bmp_manual_off.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_O_POWER_OFF); + + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable) { + lv_group_add_obj(g, buttonPreHeat); + lv_group_add_obj(g, buttonFilament); + lv_group_add_obj(g, buttonFan); + lv_group_add_obj(g, buttonPowerOff); + } + #endif + if (uiCfg.print_state != WORKING) { - buttonExtrusion = lv_imgbtn_create(scr, NULL); - buttonMove = lv_imgbtn_create(scr, NULL); - } - else { - buttonSpeed = lv_imgbtn_create(scr, NULL); - buttonBabyStep = lv_imgbtn_create(scr, NULL); - } - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonPreHeat, event_handler, ID_O_PRE_HEAT, NULL, 0); - lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_REL, "F:/bmp_temp.bin"); - lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_PR, "F:/bmp_temp.bin"); - lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonFilament, event_handler, ID_O_FILAMENT, NULL, 0); - lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_REL, "F:/bmp_filamentchange.bin"); - lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_PR, "F:/bmp_filamentchange.bin"); - lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if 1 - lv_obj_set_event_cb_mks(buttonFan, event_handler, ID_O_FAN, NULL, 0); - lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_REL, "F:/bmp_fan.bin"); - lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_PR, "F:/bmp_fan.bin"); - lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_REL, &tft_style_label_rel); - - if (gCfgItems.finish_power_off) { - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_auto_off.bin"); - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_auto_off.bin"); - } - else { - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_REL, "F:/bmp_manual_off.bin"); - lv_imgbtn_set_src(buttonPowerOff, LV_BTN_STATE_PR, "F:/bmp_manual_off.bin"); - } - lv_obj_set_event_cb_mks(buttonPowerOff, event_handler, ID_O_POWER_OFF, NULL, 0); - lv_imgbtn_set_style(buttonPowerOff, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPowerOff, LV_BTN_STATE_REL, &tft_style_label_rel); - + buttonExtrusion = lv_imgbtn_create(scr, "F:/bmp_extrude_opr.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_O_EXTRUCT); + buttonMove = lv_imgbtn_create(scr, "F:/bmp_move_opr.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_O_MOV); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonPreHeat); - lv_group_add_obj(g, buttonFilament); - lv_group_add_obj(g, buttonFan); - lv_group_add_obj(g, buttonPowerOff); + lv_group_add_obj(g, buttonExtrusion); + lv_group_add_obj(g, buttonMove); } #endif + } + else { + buttonSpeed = lv_imgbtn_create(scr, "F:/bmp_speed.bin", INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_O_SPEED); + buttonBabyStep = lv_imgbtn_create(scr, "F:/bmp_mov.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_O_BABY_STEP); + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable) { + lv_group_add_obj(g, buttonSpeed); + lv_group_add_obj(g, buttonBabyStep); + } + #endif + } - if (uiCfg.print_state != WORKING) { - lv_obj_set_event_cb_mks(buttonExtrusion, event_handler, ID_O_EXTRUCT, NULL, 0); - lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_REL, "F:/bmp_extrude_opr.bin"); - lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_PR, "F:/bmp_extrude_opr.bin"); - lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonMove, event_handler, ID_O_MOV, NULL, 0); - lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_REL, "F:/bmp_move_opr.bin"); - lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_PR, "F:/bmp_move_opr.bin"); - lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonExtrusion); - lv_group_add_obj(g, buttonMove); - } - #endif - } - else { - lv_obj_set_event_cb_mks(buttonSpeed, event_handler, ID_O_SPEED, NULL, 0); - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_REL, "F:/bmp_speed.bin"); - lv_imgbtn_set_src(buttonSpeed, LV_BTN_STATE_PR, "F:/bmp_speed.bin"); - lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonSpeed, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBabyStep, event_handler, ID_O_BABY_STEP, NULL, 0); - lv_imgbtn_set_src(buttonBabyStep, LV_BTN_STATE_REL, "F:/bmp_mov.bin"); - lv_imgbtn_set_src(buttonBabyStep, LV_BTN_STATE_PR, "F:/bmp_mov.bin"); - lv_imgbtn_set_style(buttonBabyStep, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBabyStep, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonSpeed); - lv_group_add_obj(g, buttonBabyStep); - } - #endif - } - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_O_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif // if 1 + buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_O_RETURN); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); #endif - lv_obj_set_pos(buttonPreHeat, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonFilament, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonFan, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - lv_obj_set_pos(buttonPowerOff, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - - if (uiCfg.print_state != WORKING) { - /* - lv_obj_set_pos(buttonFilament,INTERVAL_V,BTN_Y_PIXEL+INTERVAL_H+titleHeight); - } else { - */ - lv_obj_set_pos(buttonExtrusion, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonMove, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - } - else { - lv_obj_set_pos(buttonSpeed, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBabyStep, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - } - - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - // Create labels on the image buttons - lv_btn_set_layout(buttonPreHeat, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonFan, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonPowerOff, LV_LAYOUT_OFF); + labelPreHeat = lv_label_create_empty(buttonPreHeat); + label_Filament = lv_label_create_empty(buttonFilament); + label_Fan = lv_label_create_empty(buttonFan); + label_PowerOff = lv_label_create_empty(buttonPowerOff); if (uiCfg.print_state != WORKING) { /* - lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF); + label_Filament = lv_label_create_empty(buttonFilament); } else { */ - lv_btn_set_layout(buttonExtrusion, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonMove, LV_LAYOUT_OFF); + labelExtrusion = lv_label_create_empty(buttonExtrusion); + label_Move = lv_label_create_empty(buttonMove); } else { - lv_btn_set_layout(buttonSpeed, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBabyStep, LV_LAYOUT_OFF); + label_Speed = lv_label_create_empty(buttonSpeed); + label_BabyStep = lv_label_create_empty(buttonBabyStep); } - - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - labelPreHeat = lv_label_create(buttonPreHeat, NULL); - label_Filament = lv_label_create(buttonFilament, NULL); - label_Fan = lv_label_create(buttonFan, NULL); - label_PowerOff = lv_label_create(buttonPowerOff, NULL); - - if (uiCfg.print_state != WORKING) { - /* - label_Filament = lv_label_create(buttonFilament, NULL); - } else { - */ - labelExtrusion = lv_label_create(buttonExtrusion, NULL); - label_Move = lv_label_create(buttonMove, NULL); - } - else { - label_Speed = lv_label_create(buttonSpeed, NULL); - label_BabyStep = lv_label_create(buttonBabyStep, NULL); - } - label_Back = lv_label_create(buttonBack, NULL); + label_Back = lv_label_create_empty(buttonBack); if (gCfgItems.multiple_language) { lv_label_set_text(labelPreHeat, operation_menu.temp); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp index d1c3a4a795..a324aef793 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_pause_position.cpp @@ -29,167 +29,54 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_PAUSE_RETURN 1 -#define ID_PAUSE_X 2 -#define ID_PAUSE_Y 3 -#define ID_PAUSE_Z 4 +enum { + ID_PAUSE_RETURN = 1, + ID_PAUSE_X, + ID_PAUSE_Y, + ID_PAUSE_Z +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_PAUSE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_pause_position(); - draw_return_ui(); - } + lv_clear_pause_position(); + draw_return_ui(); break; case ID_PAUSE_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = pause_pos_x; - lv_clear_pause_position(); - lv_draw_number_key(); - } + value = pause_pos_x; + lv_clear_pause_position(); + lv_draw_number_key(); break; case ID_PAUSE_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = pause_pos_y; - lv_clear_pause_position(); - lv_draw_number_key(); - } + value = pause_pos_y; + lv_clear_pause_position(); + lv_draw_number_key(); break; case ID_PAUSE_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = pause_pos_z; - lv_clear_pause_position(); - lv_draw_number_key(); - } + value = pause_pos_z; + lv_clear_pause_position(); + lv_draw_number_key(); break; } } void lv_draw_pause_position(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; + scr = lv_screen_create(PAUSE_POS_UI, machine_menu.PausePosText); - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != PAUSE_POS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = PAUSE_POS_UI; - } - disp_state = PAUSE_POS_UI; + sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosX); + lv_screen_menu_item_1_edit(scr, machine_menu.xPos, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_PAUSE_X, 0, public_buf_l); - scr = lv_obj_create(NULL, NULL); + sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosY); + lv_screen_menu_item_1_edit(scr, machine_menu.yPos, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_PAUSE_Y, 1, public_buf_l); - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosZ); + lv_screen_menu_item_1_edit(scr, machine_menu.zPos, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_PAUSE_Z, 2, public_buf_l); - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.PausePosText); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelXText, machine_menu.xPos); - - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_PAUSE_X, NULL, 0); - labelXValue = lv_label_create(buttonXValue, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelYText, machine_menu.yPos); - - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_PAUSE_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - labelYValue = lv_label_create(buttonYValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelZText, machine_menu.zPos); - - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_PAUSE_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - labelZValue = lv_label_create(buttonZValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_PAUSE_RETURN, NULL, 0); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosX); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosY); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), gCfgItems.pausePosZ); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonBack); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_PAUSE_RETURN, true); } void lv_clear_pause_position() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp index b08c9bd947..0e869e67c4 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_preHeat.cpp @@ -33,276 +33,157 @@ #include "../../../../module/temperature.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; extern lv_group_t* g; -static lv_obj_t *buttoType, *buttonStep; +static lv_obj_t *buttonType, *buttonStep; static lv_obj_t *labelType; static lv_obj_t *labelStep; -static lv_obj_t * tempText1; +static lv_obj_t *tempText1; -#define ID_P_ADD 1 -#define ID_P_DEC 2 -#define ID_P_TYPE 3 -#define ID_P_STEP 4 -#define ID_P_OFF 5 -#define ID_P_RETURN 6 +enum { + ID_P_ADD = 1, + ID_P_DEC, + ID_P_TYPE, + ID_P_STEP, + ID_P_OFF, + ID_P_RETURN +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_P_ADD: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target += uiCfg.stepHeat; - if (uiCfg.curSprayerChoose == 0) { - if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); - } + if (uiCfg.curTempType == 0) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target += uiCfg.stepHeat; + if (uiCfg.curSprayerChoose == 0) { + if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_0_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); } - #if !defined(SINGLENOZZLE) && HAS_MULTI_EXTRUDER - else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); - } - #endif - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } - #if HAS_HEATED_BED - else { - thermalManager.temp_bed.target += uiCfg.stepHeat; - if ((int)thermalManager.temp_bed.target > BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) { - thermalManager.temp_bed.target = (float)BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1); - } - thermalManager.start_watching_bed(); + #if !defined(SINGLENOZZLE) && HAS_MULTI_EXTRUDER + else if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > (HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1))) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)HEATER_1_MAXTEMP - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1); } #endif - disp_desire_temp(); + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } + #if HAS_HEATED_BED + else { + thermalManager.temp_bed.target += uiCfg.stepHeat; + if ((int)thermalManager.temp_bed.target > BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) { + thermalManager.temp_bed.target = (float)BED_MAXTEMP - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1); + } + thermalManager.start_watching_bed(); + } + #endif + disp_desire_temp(); break; case ID_P_DEC: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > uiCfg.stepHeat) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target -= uiCfg.stepHeat; - } - else { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)0; - } - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); - } - #if HAS_HEATED_BED - else { - if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat) { - thermalManager.temp_bed.target -= uiCfg.stepHeat; - } - else { - thermalManager.temp_bed.target = (float)0; - } - thermalManager.start_watching_bed(); - } - #endif - disp_desire_temp(); - } + if (uiCfg.curTempType == 0) { + if ((int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target > uiCfg.stepHeat) + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target -= uiCfg.stepHeat; + else + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = 0; + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); + } + #if HAS_HEATED_BED + else { + if ((int)thermalManager.temp_bed.target > uiCfg.stepHeat) + thermalManager.temp_bed.target -= uiCfg.stepHeat; + else + thermalManager.temp_bed.target = 0; + + thermalManager.start_watching_bed(); + } + #endif + disp_desire_temp(); break; case ID_P_TYPE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - if (ENABLED(HAS_MULTI_EXTRUDER)) { - if (uiCfg.curSprayerChoose == 0) { - uiCfg.curSprayerChoose = 1; - } - else if (uiCfg.curSprayerChoose == 1) { - if (TEMP_SENSOR_BED != 0) { - uiCfg.curTempType = 1; - } - else { - uiCfg.curTempType = 0; - uiCfg.curSprayerChoose = 0; - } - } + if (uiCfg.curTempType == 0) { + if (ENABLED(HAS_MULTI_EXTRUDER)) { + if (uiCfg.curSprayerChoose == 0) { + uiCfg.curSprayerChoose = 1; } - else if (uiCfg.curSprayerChoose == 0) { - if (TEMP_SENSOR_BED != 0) + else if (uiCfg.curSprayerChoose == 1) { + if (TEMP_SENSOR_BED != 0) { uiCfg.curTempType = 1; - else - uiCfg.curTempType = 0; + } + else { + uiCfg.curTempType = 0; + uiCfg.curSprayerChoose = 0; + } } } - else if (uiCfg.curTempType == 1) { - uiCfg.curSprayerChoose = 0; - uiCfg.curTempType = 0; + else if (uiCfg.curSprayerChoose == 0) { + if (TEMP_SENSOR_BED != 0) + uiCfg.curTempType = 1; + else + uiCfg.curTempType = 0; } - disp_temp_type(); } + else if (uiCfg.curTempType == 1) { + uiCfg.curSprayerChoose = 0; + uiCfg.curTempType = 0; + } + disp_temp_type(); break; case ID_P_STEP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - switch (uiCfg.stepHeat) { - case 1: uiCfg.stepHeat = 5; break; - case 5: uiCfg.stepHeat = 10; break; - case 10: uiCfg.stepHeat = 1; break; - default: break; - } - disp_step_heat(); + switch (uiCfg.stepHeat) { + case 1: uiCfg.stepHeat = 5; break; + case 5: uiCfg.stepHeat = 10; break; + case 10: uiCfg.stepHeat = 1; break; + default: break; } + disp_step_heat(); break; case ID_P_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (uiCfg.curTempType == 0) { + thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = 0; + thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); } - else if (event == LV_EVENT_RELEASED) { - if (uiCfg.curTempType == 0) { - thermalManager.temp_hotend[uiCfg.curSprayerChoose].target = (float)0; - thermalManager.start_watching_hotend(uiCfg.curSprayerChoose); + #if HAS_HEATED_BED + else { + thermalManager.temp_bed.target = 0; + thermalManager.start_watching_bed(); } - #if HAS_HEATED_BED - else { - thermalManager.temp_bed.target = (float)0; - thermalManager.start_watching_bed(); - } - #endif - disp_desire_temp(); - } + #endif + disp_desire_temp(); break; case ID_P_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - draw_return_ui(); - } + clear_cur_ui(); + draw_return_ui(); break; } } void lv_draw_preHeat(void) { - lv_obj_t *buttonAdd, *buttonDec; - lv_obj_t *buttonOff, *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != PRE_HEAT_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = PRE_HEAT_UI; - } - disp_state = PRE_HEAT_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(PRE_HEAT_UI); // Create image buttons - buttonAdd = lv_imgbtn_create(scr, NULL); - buttonDec = lv_imgbtn_create(scr, NULL); - buttoType = lv_imgbtn_create(scr, NULL); - buttonStep = lv_imgbtn_create(scr, NULL); - buttonOff = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); + lv_big_button_create(scr, "F:/bmp_Add.bin", preheat_menu.add, INTERVAL_V, titleHeight, event_handler, ID_P_ADD); + lv_big_button_create(scr, "F:/bmp_Dec.bin", preheat_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_DEC); - lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_P_ADD, NULL, 0); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, "F:/bmp_Add.bin"); - lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, "F:/bmp_Add.bin"); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW); - - #if 1 - lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_P_DEC, NULL, 0); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, "F:/bmp_Dec.bin"); - lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, "F:/bmp_Dec.bin"); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttoType, event_handler, ID_P_TYPE, NULL, 0); - lv_imgbtn_set_style(buttoType, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttoType, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonStep, event_handler, ID_P_STEP, NULL, 0); - lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonStep, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonOff, event_handler, ID_P_OFF, NULL, 0); - lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_REL, "F:/bmp_speed0.bin"); - lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_PR, "F:/bmp_speed0.bin"); - lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_P_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttoType, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonStep, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonOff, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF); - lv_btn_set_layout(buttoType, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonStep, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonOff, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelAdd = lv_label_create(buttonAdd, NULL); - lv_obj_t *labelDec = lv_label_create(buttonDec, NULL); - labelType = lv_label_create(buttoType, NULL); - labelStep = lv_label_create(buttonStep, NULL); - lv_obj_t *labelOff = lv_label_create(buttonOff, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelAdd, preheat_menu.add); - lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelDec, preheat_menu.dec); - lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelOff, preheat_menu.off); - lv_obj_align(labelOff, buttonOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } + buttonType = lv_imgbtn_create(scr, nullptr, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_TYPE); + buttonStep = lv_imgbtn_create(scr, nullptr, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_STEP); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonAdd); - lv_group_add_obj(g, buttonDec); - lv_group_add_obj(g, buttoType); + lv_group_add_obj(g, buttonType); lv_group_add_obj(g, buttonStep); - lv_group_add_obj(g, buttonOff); - lv_group_add_obj(g, buttonBack); } #endif + lv_big_button_create(scr, "F:/bmp_speed0.bin", preheat_menu.off, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_OFF); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_P_RETURN); + + // Create labels on the image buttons + labelType = lv_label_create_empty(buttonType); + labelStep = lv_label_create_empty(buttonStep); + disp_temp_type(); disp_step_heat(); - tempText1 = lv_label_create(scr, NULL); + tempText1 = lv_label_create_empty(scr); lv_obj_set_style(tempText1, &tft_style_label_rel); disp_desire_temp(); } @@ -310,29 +191,26 @@ void lv_draw_preHeat(void) { void disp_temp_type() { if (uiCfg.curTempType == 0) { if (uiCfg.curSprayerChoose == 1) { - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru2.bin"); - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru2.bin"); + lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru2.bin"); if (gCfgItems.multiple_language) { lv_label_set_text(labelType, preheat_menu.ext2); - lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } else { - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_extru1.bin"); - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_extru1.bin"); + lv_imgbtn_set_src_both(buttonType, "F:/bmp_extru1.bin"); if (gCfgItems.multiple_language) { lv_label_set_text(labelType, preheat_menu.ext1); - lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } } else { - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_REL, "F:/bmp_bed.bin"); - lv_imgbtn_set_src(buttoType, LV_BTN_STATE_PR, "F:/bmp_bed.bin"); + lv_imgbtn_set_src_both(buttonType, "F:/bmp_bed.bin"); if (gCfgItems.multiple_language) { lv_label_set_text(labelType, preheat_menu.hotbed); - lv_obj_align(labelType, buttoType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(labelType, buttonType, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } } @@ -343,10 +221,7 @@ void disp_desire_temp() { public_buf_l[0] = '\0'; if (uiCfg.curTempType == 0) { - if (uiCfg.curSprayerChoose < 1) - strcat(public_buf_l, preheat_menu.ext1); - else - strcat(public_buf_l, preheat_menu.ext2); + strcat(public_buf_l, uiCfg.curSprayerChoose < 1 ? preheat_menu.ext1 : preheat_menu.ext2); sprintf(buf, preheat_menu.value_state, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].celsius, (int)thermalManager.temp_hotend[uiCfg.curSprayerChoose].target); } #if HAS_HEATED_BED @@ -358,21 +233,18 @@ void disp_desire_temp() { strcat_P(public_buf_l, PSTR(": ")); strcat(public_buf_l, buf); lv_label_set_text(tempText1, public_buf_l); - lv_obj_align(tempText1, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_align(tempText1, nullptr, LV_ALIGN_CENTER, 0, -50); } void disp_step_heat() { if (uiCfg.stepHeat == 1) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step1_degree.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step1_degree.bin"); + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step1_degree.bin"); } else if (uiCfg.stepHeat == 5) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step5_degree.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step5_degree.bin"); + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step5_degree.bin"); } else if (uiCfg.stepHeat == 10) { - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_REL, "F:/bmp_step10_degree.bin"); - lv_imgbtn_set_src(buttonStep, LV_BTN_STATE_PR, "F:/bmp_step10_degree.bin"); + lv_imgbtn_set_src_both(buttonStep, "F:/bmp_step10_degree.bin"); } if (gCfgItems.multiple_language) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp index d92943a37c..cfd06cf09f 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp @@ -33,15 +33,17 @@ #include "../../../../sd/cardreader.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; extern lv_group_t* g; static lv_obj_t *buttonPageUp, *buttonPageDown, *buttonBack, *buttonGcode[FILE_BTN_CNT], *labelPageUp[FILE_BTN_CNT], *buttonText[FILE_BTN_CNT]; -#define ID_P_UP 7 -#define ID_P_DOWN 8 -#define ID_P_RETURN 9 +enum { + ID_P_UP = 7, + ID_P_DOWN, + ID_P_RETURN +}; int8_t curDirLever = 0; LIST_FILE list_file; @@ -74,38 +76,21 @@ uint8_t sel_id = 0; const uint16_t nr = SD_ORDER(i, fileCnt); card.getfilename_sorted(nr); - if (card.flag.filenameIsDir) { - //SERIAL_ECHOLN(card.longest_filename); - list_file.IsFolder[valid_name_cnt] = 1; - } - else { - //SERIAL_ECHOLN(card.longFilename); - list_file.IsFolder[valid_name_cnt] = 0; - } + list_file.IsFolder[valid_name_cnt] = card.flag.filenameIsDir; + strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath); + strcat_P(list_file.file_name[valid_name_cnt], PSTR("/")); + strcat(list_file.file_name[valid_name_cnt], card.filename); + strcpy(list_file.long_name[valid_name_cnt], card.longest_filename()); - #if 1 - // - memset(list_file.file_name[valid_name_cnt], 0, strlen(list_file.file_name[valid_name_cnt])); - strcpy(list_file.file_name[valid_name_cnt], list_file.curDirPath); - strcat_P(list_file.file_name[valid_name_cnt], PSTR("/")); - strcat(list_file.file_name[valid_name_cnt], card.filename); - // - memset(list_file.long_name[valid_name_cnt], 0, strlen(list_file.long_name[valid_name_cnt])); - if (card.longFilename[0] == 0) - strncpy(list_file.long_name[valid_name_cnt], card.filename, strlen(card.filename)); - else - strncpy(list_file.long_name[valid_name_cnt], card.longFilename, strlen(card.longFilename)); - - valid_name_cnt++; - if (valid_name_cnt == 1) - dir_offset[curDirLever].cur_page_first_offset = list_file.Sd_file_offset; - if (valid_name_cnt >= FILE_NUM) { - dir_offset[curDirLever].cur_page_last_offset = list_file.Sd_file_offset; - list_file.Sd_file_offset++; - break; - } + valid_name_cnt++; + if (valid_name_cnt == 1) + dir_offset[curDirLever].cur_page_first_offset = list_file.Sd_file_offset; + if (valid_name_cnt >= FILE_NUM) { + dir_offset[curDirLever].cur_page_last_offset = list_file.Sd_file_offset; list_file.Sd_file_offset++; - #endif + break; + } + list_file.Sd_file_offset++; } list_file.Sd_file_cnt++; } @@ -115,125 +100,105 @@ uint8_t sel_id = 0; #endif // SDSUPPORT -uint8_t have_pre_pic(char *path) { +bool have_pre_pic(char *path) { #if ENABLED(SDSUPPORT) char *ps1, *ps2, *cur_name = strrchr(path, '/'); - card.openFileRead(cur_name); card.read(public_buf, 512); ps1 = strstr((char *)public_buf, ";simage:"); card.read(public_buf, 512); ps2 = strstr((char *)public_buf, ";simage:"); - if (ps1 || ps2) { - card.closefile(); - return 1; - } card.closefile(); + if (ps1 || ps2) return true; #endif - return 0; + return false; } -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; uint8_t i, file_count = 0; //switch (obj->mks_obj_id) //{ if (obj->mks_obj_id == ID_P_UP) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (dir_offset[curDirLever].curPage > 0) { - // 2015.05.19 - list_file.Sd_file_cnt = 0; + if (dir_offset[curDirLever].curPage > 0) { + // 2015.05.19 + list_file.Sd_file_cnt = 0; - if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM) - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM; + if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM) + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - if (file_count != 0) { - dir_offset[curDirLever].curPage--; - lv_clear_print_file(); - disp_gcode_icon(file_count); - } + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif + if (file_count != 0) { + dir_offset[curDirLever].curPage--; + lv_clear_print_file(); + disp_gcode_icon(file_count); } } } else if (obj->mks_obj_id == ID_P_DOWN) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (dir_offset[curDirLever].cur_page_last_offset > 0) { - list_file.Sd_file_cnt = 0; - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - if (file_count != 0) { - dir_offset[curDirLever].curPage++; - lv_clear_print_file(); - disp_gcode_icon(file_count); - } - if (file_count < FILE_NUM) - dir_offset[curDirLever].cur_page_last_offset = 0; + if (dir_offset[curDirLever].cur_page_last_offset > 0) { + list_file.Sd_file_cnt = 0; + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1; + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif + if (file_count != 0) { + dir_offset[curDirLever].curPage++; + lv_clear_print_file(); + disp_gcode_icon(file_count); } + if (file_count < FILE_NUM) + dir_offset[curDirLever].cur_page_last_offset = 0; } } else if (obj->mks_obj_id == ID_P_RETURN) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (curDirLever > 0) { - int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/'); - if (ch) { - *ch = 0; - #if ENABLED(SDSUPPORT) - card.cdup(); - #endif - dir_offset[curDirLever].curPage = 0; - dir_offset[curDirLever].cur_page_first_offset = 0; - dir_offset[curDirLever].cur_page_last_offset = 0; - curDirLever--; - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - lv_clear_print_file(); - disp_gcode_icon(file_count); - } - } - else { + if (curDirLever > 0) { + int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/'); + if (ch) { + *ch = 0; + #if ENABLED(SDSUPPORT) + card.cdup(); + #endif + dir_offset[curDirLever].curPage = 0; + dir_offset[curDirLever].cur_page_first_offset = 0; + dir_offset[curDirLever].cur_page_last_offset = 0; + curDirLever--; + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif lv_clear_print_file(); - lv_draw_ready_print(); + disp_gcode_icon(file_count); } } + else { + lv_clear_print_file(); + lv_draw_ready_print(); + } } else { for (i = 0; i < FILE_BTN_CNT; i++) { if (obj->mks_obj_id == (i + 1)) { - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - if (list_file.file_name[i][0] != 0) { - if (list_file.IsFolder[i] == 1) { - ZERO(list_file.curDirPath); - strcpy(list_file.curDirPath, list_file.file_name[i]); - curDirLever++; - list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; - #if ENABLED(SDSUPPORT) - file_count = search_file(); - #endif - lv_clear_print_file(); - disp_gcode_icon(file_count); - } - else { - sel_id = i; - lv_clear_print_file(); - lv_draw_dialog(DIALOG_TYPE_PRINT_FILE); - } - break; + if (list_file.file_name[i][0] != 0) { + if (list_file.IsFolder[i]) { + strcpy(list_file.curDirPath, list_file.file_name[i]); + curDirLever++; + list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset; + #if ENABLED(SDSUPPORT) + file_count = search_file(); + #endif + lv_clear_print_file(); + disp_gcode_icon(file_count); } + else { + sel_id = i; + lv_clear_print_file(); + lv_draw_dialog(DIALOG_TYPE_PRINT_FILE); + } + break; } } } @@ -249,11 +214,11 @@ void lv_draw_print_file(void) { } disp_state = PRINT_FILE_UI; - curDirLever = 0; + curDirLever = 0; dir_offset[curDirLever].curPage = 0; list_file.Sd_file_offset = 0; - list_file.Sd_file_cnt = 0; + list_file.Sd_file_cnt = 0; ZERO(dir_offset); ZERO(list_file.IsFolder); @@ -266,9 +231,9 @@ void lv_draw_print_file(void) { #endif disp_gcode_icon(file_count); - //lv_obj_t *labelPageUp = lv_label_create(buttonPageUp, NULL); - //lv_obj_t *labelPageDown = lv_label_create(buttonPageDown, NULL); - //lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); + //lv_obj_t *labelPageUp = lv_label_create_empty(buttonPageUp); + //lv_obj_t *labelPageDown = lv_label_create_empty(buttonPageDown); + //lv_obj_t *label_Back = lv_label_create_empty(buttonBack); /* if (gCfgItems.multiple_language) { @@ -287,55 +252,14 @@ static char test_public_buf_l[40]; void disp_gcode_icon(uint8_t file_num) { uint8_t i; - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(MAIN_UI, ""); // Create image buttons - buttonPageUp = lv_imgbtn_create(scr, NULL); - buttonPageDown = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonPageUp, event_handler, ID_P_UP, NULL, 0); - lv_imgbtn_set_src(buttonPageUp, LV_BTN_STATE_REL, "F:/bmp_pageUp.bin"); - lv_imgbtn_set_src(buttonPageUp, LV_BTN_STATE_PR, "F:/bmp_pageUp.bin"); - lv_imgbtn_set_style(buttonPageUp, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPageUp, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if 1 - lv_obj_set_event_cb_mks(buttonPageDown, event_handler, ID_P_DOWN, NULL, 0); - lv_imgbtn_set_src(buttonPageDown, LV_BTN_STATE_REL, "F:/bmp_pageDown.bin"); - lv_imgbtn_set_src(buttonPageDown, LV_BTN_STATE_PR, "F:/bmp_pageDown.bin"); - lv_imgbtn_set_style(buttonPageDown, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPageDown, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_P_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - lv_obj_set_pos(buttonPageUp, OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonPageDown, OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL + INTERVAL_H); - lv_obj_set_pos(buttonBack, OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL * 2 + INTERVAL_H * 2); + buttonPageUp = lv_imgbtn_create(scr, "F:/bmp_pageUp.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_P_UP); + buttonPageDown = lv_imgbtn_create(scr, "F:/bmp_pageDown.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL + INTERVAL_H, event_handler, ID_P_DOWN); + buttonBack = lv_imgbtn_create(scr, "F:/bmp_back.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL * 2 + INTERVAL_H * 2, event_handler, ID_P_RETURN); // Create labels on the image buttons - lv_btn_set_layout(buttonPageUp, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonPageDown, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - for (i = 0; i < FILE_BTN_CNT; i++) { /* if (seq) { @@ -350,28 +274,24 @@ void disp_gcode_icon(uint8_t file_num) { if (i >= file_num) break; #ifdef TFT35 - buttonGcode[i] = lv_imgbtn_create(scr, NULL); + buttonGcode[i] = lv_imgbtn_create(scr, nullptr); - lv_imgbtn_set_style(buttonGcode[i], LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonGcode[i], LV_BTN_STATE_REL, &tft_style_label_rel); + lv_imgbtn_use_label_style(buttonGcode[i]); lv_obj_clear_protect(buttonGcode[i], LV_PROTECT_FOLLOW); lv_btn_set_layout(buttonGcode[i], LV_LAYOUT_OFF); ZERO(public_buf_m); - cutFileName((char *)list_file.long_name[i], 16, 8, (char *)public_buf_m); + cutFileName((char *)list_file.long_name[i], 16, 8, (char *)public_buf_m); - if (list_file.IsFolder[i] == 1) { - lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), NULL, 0); - lv_imgbtn_set_src(buttonGcode[i], LV_BTN_STATE_REL, "F:/bmp_dir.bin"); - lv_imgbtn_set_src(buttonGcode[i], LV_BTN_STATE_PR, "F:/bmp_dir.bin"); + if (list_file.IsFolder[i]) { + lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), nullptr, 0); + lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_dir.bin"); if (i < 3) lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight); else lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1), BTN_Y_PIXEL + INTERVAL_H + titleHeight); - labelPageUp[i] = lv_label_create(buttonGcode[i], NULL); - lv_obj_set_style(labelPageUp[i], &tft_style_label_rel); - lv_label_set_text(labelPageUp[i], public_buf_m); + labelPageUp[i] = lv_label_create(buttonGcode[i], public_buf_m); lv_obj_align(labelPageUp[i], buttonGcode[i], LV_ALIGN_IN_BOTTOM_MID, 0, -5); } else { @@ -379,61 +299,48 @@ void disp_gcode_icon(uint8_t file_num) { //lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), list_file.file_name[i], 1); - ZERO(test_public_buf_l); - strcat(test_public_buf_l,"S:"); - strcat(test_public_buf_l,list_file.file_name[i]); - char *temp = strstr(test_public_buf_l,".GCO"); - if (temp) { strcpy(temp,".bin"); } - lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), NULL, 0); - lv_imgbtn_set_src(buttonGcode[i], LV_BTN_STATE_REL, test_public_buf_l); - lv_imgbtn_set_src(buttonGcode[i], LV_BTN_STATE_PR, test_public_buf_l); + strcpy(test_public_buf_l, "S:"); + strcat(test_public_buf_l, list_file.file_name[i]); + char *temp = strstr(test_public_buf_l, ".GCO"); + if (temp) strcpy(temp, ".bin"); + lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), nullptr, 0); + lv_imgbtn_set_src_both(buttonGcode[i], test_public_buf_l); if (i < 3) { lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1) + FILE_PRE_PIC_X_OFFSET, titleHeight + FILE_PRE_PIC_Y_OFFSET); - buttonText[i] = lv_btn_create(scr, NULL); + buttonText[i] = lv_btn_create(scr, nullptr); //lv_obj_set_event_cb(buttonText[i], event_handler); - lv_btn_set_style(buttonText[i], LV_BTN_STATE_PR, &tft_style_label_pre); - lv_btn_set_style(buttonText[i], LV_BTN_STATE_REL, &tft_style_label_rel); - //lv_obj_set_style(buttonText[i], &tft_style_label_pre); - //lv_obj_set_style(buttonText[i], &tft_style_label_rel); + lv_btn_use_label_style(buttonText[i]); lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW); lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF); - //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),NULL,0); + //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),nullptr, 0); lv_obj_set_pos(buttonText[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1) + FILE_PRE_PIC_X_OFFSET, titleHeight + FILE_PRE_PIC_Y_OFFSET + 100); lv_obj_set_size(buttonText[i], 100, 40); } else { lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1) + FILE_PRE_PIC_X_OFFSET, BTN_Y_PIXEL + INTERVAL_H + titleHeight + FILE_PRE_PIC_Y_OFFSET); - buttonText[i] = lv_btn_create(scr, NULL); + buttonText[i] = lv_btn_create(scr, nullptr); //lv_obj_set_event_cb(buttonText[i], event_handler); - lv_btn_set_style(buttonText[i], LV_BTN_STATE_PR, &tft_style_label_pre); - lv_btn_set_style(buttonText[i], LV_BTN_STATE_REL, &tft_style_label_rel); - - //lv_imgbtn_set_style(buttonText[i], LV_BTN_STATE_REL, &tft_style_label_rel); + lv_btn_use_label_style(buttonText[i]); lv_obj_clear_protect(buttonText[i], LV_PROTECT_FOLLOW); lv_btn_set_layout(buttonText[i], LV_LAYOUT_OFF); - //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),NULL,0); + //lv_obj_set_event_cb_mks(buttonText[i], event_handler,(i+10),nullptr, 0); lv_obj_set_pos(buttonText[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1) + FILE_PRE_PIC_X_OFFSET, BTN_Y_PIXEL + INTERVAL_H + titleHeight + FILE_PRE_PIC_Y_OFFSET + 100); lv_obj_set_size(buttonText[i], 100, 40); } - labelPageUp[i] = lv_label_create(buttonText[i], NULL); - lv_obj_set_style(labelPageUp[i], &tft_style_label_rel); - lv_label_set_text(labelPageUp[i], public_buf_m); + labelPageUp[i] = lv_label_create(buttonText[i], public_buf_m); lv_obj_align(labelPageUp[i], buttonText[i], LV_ALIGN_IN_BOTTOM_MID, 0, 0); } else { - lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), NULL, 0); - lv_imgbtn_set_src(buttonGcode[i], LV_BTN_STATE_REL, "F:/bmp_file.bin"); - lv_imgbtn_set_src(buttonGcode[i], LV_BTN_STATE_PR, "F:/bmp_file.bin"); + lv_obj_set_event_cb_mks(buttonGcode[i], event_handler, (i + 1), nullptr, 0); + lv_imgbtn_set_src_both(buttonGcode[i], "F:/bmp_file.bin"); if (i < 3) lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * i + INTERVAL_V * (i + 1), titleHeight); else lv_obj_set_pos(buttonGcode[i], BTN_X_PIXEL * (i - 3) + INTERVAL_V * ((i - 3) + 1), BTN_Y_PIXEL + INTERVAL_H + titleHeight); - labelPageUp[i] = lv_label_create(buttonGcode[i], NULL); - lv_obj_set_style(labelPageUp[i], &tft_style_label_rel); - lv_label_set_text(labelPageUp[i], public_buf_m); + labelPageUp[i] = lv_label_create(buttonGcode[i], public_buf_m); lv_obj_align(labelPageUp[i], buttonGcode[i], LV_ALIGN_IN_BOTTOM_MID, 0, -5); } } @@ -549,7 +456,7 @@ void lv_gcode_file_seek(uint32_t pos) { card.setIndex(pos); } -void cutFileName(char *path, int len, int bytePerLine, char *outStr) { +void cutFileName(char *path, int len, int bytePerLine, char *outStr) { #if _LFN_UNICODE TCHAR *tmpFile; TCHAR *strIndex1 = 0, *strIndex2 = 0, *beginIndex; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h index 083b3d9acf..94786ab070 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.h @@ -43,7 +43,7 @@ typedef struct { char file_name[FILE_NUM][SHORT_NEME_LEN * MAX_DIR_LEVEL + 1]; char curDirPath[SHORT_NEME_LEN * MAX_DIR_LEVEL + 1]; char long_name[FILE_NUM][SHORT_NEME_LEN * 2 + 1]; - char IsFolder[FILE_NUM]; + bool IsFolder[FILE_NUM]; char Sd_file_cnt; char sd_file_index; char Sd_file_offset; @@ -55,7 +55,7 @@ extern void lv_draw_print_file(void); extern uint32_t lv_open_gcode_file(char *path); extern void lv_gcode_file_read(uint8_t *data_buf); extern void lv_close_gcode_file(); -extern void cutFileName(char *path, int len, int bytePerLine, char *outStr); +extern void cutFileName(char *path, int len, int bytePerLine, char *outStr); extern int ascii2dec_test(char *ascii); extern void lv_clear_print_file(); extern void lv_gcode_file_seek(uint32_t pos); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp index 6481061800..7614f1e99d 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp @@ -46,93 +46,74 @@ #include "../../../marlinui.h" #endif -extern lv_group_t * g; -static lv_obj_t * scr; -static lv_obj_t *labelExt1, * labelFan, * labelZpos, * labelTime; -TERN_(HAS_MULTI_EXTRUDER, static lv_obj_t *labelExt2;) -static lv_obj_t *labelPause, * labelStop, * labelOperat; -static lv_obj_t * bar1, *bar1ValueText; -static lv_obj_t * buttonPause, *buttonOperat, *buttonStop; +extern lv_group_t *g; +static lv_obj_t *scr; +static lv_obj_t *labelExt1, *labelFan, *labelZpos, *labelTime; +static lv_obj_t *labelPause, *labelStop, *labelOperat; +static lv_obj_t *bar1, *bar1ValueText; +static lv_obj_t *buttonPause, *buttonOperat, *buttonStop; + +TERN_(HAS_MULTI_EXTRUDER, static lv_obj_t *labelExt2); #if HAS_HEATED_BED static lv_obj_t* labelBed; #endif -#define ID_PAUSE 1 -#define ID_STOP 2 -#define ID_OPTION 3 +enum { + ID_PAUSE = 1, + ID_STOP, + ID_OPTION +}; bool once_flag; // = false extern bool flash_preview_begin, default_preview_flg, gcode_preview_over; extern uint32_t To_pre_view; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + if (gcode_preview_over) return; switch (obj->mks_obj_id) { case ID_PAUSE: - if (event == LV_EVENT_CLICKED) { - // nothing to do + if (uiCfg.print_state == WORKING) { + // #if ENABLED(PARK_HEAD_ON_PAUSE) + // queue.inject_P(PSTR("M25 P\nM24")); + #if ENABLED(SDSUPPORT) + // queue.inject_P(PSTR("M25\nG91\nG1 Z10\nG90")); + card.pauseSDPrint(); + stop_print_time(); + uiCfg.print_state = PAUSING; + #endif + lv_imgbtn_set_src_both(buttonPause, "F:/bmp_resume.bin"); + lv_label_set_text(labelPause, printing_menu.resume); + lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); } - else if (event == LV_EVENT_RELEASED) { - if (!gcode_preview_over) { - if (uiCfg.print_state == WORKING) { - // #if ENABLED(PARK_HEAD_ON_PAUSE) - // queue.inject_P(PSTR("M25 P\nM24")); - #if ENABLED(SDSUPPORT) - // queue.inject_P(PSTR("M25\nG91\nG1 Z10\nG90")); - card.pauseSDPrint(); - stop_print_time(); - uiCfg.print_state = PAUSING; - #endif - lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_REL, "F:/bmp_resume.bin"); - lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_PR, "F:/bmp_resume.bin"); - lv_label_set_text(labelPause, printing_menu.resume); - lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); - } - else if (uiCfg.print_state == PAUSED) { - uiCfg.print_state = RESUMING; - lv_imgbtn_set_src(obj, LV_BTN_STATE_REL, "F:/bmp_pause.bin"); - lv_imgbtn_set_src(obj, LV_BTN_STATE_PR, "F:/bmp_pause.bin"); - lv_label_set_text(labelPause, printing_menu.pause); - lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); - } - #if ENABLED(POWER_LOSS_RECOVERY) - else if (uiCfg.print_state == REPRINTING) { - uiCfg.print_state = REPRINTED; - lv_imgbtn_set_src(obj, LV_BTN_STATE_REL, "F:/bmp_pause.bin"); - lv_imgbtn_set_src(obj, LV_BTN_STATE_PR, "F:/bmp_pause.bin"); - lv_label_set_text(labelPause, printing_menu.pause); - lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); - // recovery.resume(); - print_time.minutes = recovery.info.print_job_elapsed / 60; - print_time.seconds = recovery.info.print_job_elapsed % 60; - print_time.hours = print_time.minutes / 60; - } - #endif + else if (uiCfg.print_state == PAUSED) { + uiCfg.print_state = RESUMING; + lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin"); + lv_label_set_text(labelPause, printing_menu.pause); + lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); + } + #if ENABLED(POWER_LOSS_RECOVERY) + else if (uiCfg.print_state == REPRINTING) { + uiCfg.print_state = REPRINTED; + lv_imgbtn_set_src_both(obj, "F:/bmp_pause.bin"); + lv_label_set_text(labelPause, printing_menu.pause); + lv_obj_align(labelPause, buttonPause, LV_ALIGN_CENTER, 30, 0); + // recovery.resume(); + print_time.minutes = recovery.info.print_job_elapsed / 60; + print_time.seconds = recovery.info.print_job_elapsed % 60; + print_time.hours = print_time.minutes / 60; } - } + #endif break; case ID_STOP: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (!gcode_preview_over) { - lv_clear_printing(); - lv_draw_dialog(DIALOG_TYPE_STOP); - } - } + lv_clear_printing(); + lv_draw_dialog(DIALOG_TYPE_STOP); break; case ID_OPTION: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - if (!gcode_preview_over) { - lv_clear_printing(); - lv_draw_operation(); - } - } + lv_clear_printing(); + lv_draw_operation(); break; } } @@ -140,81 +121,40 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { void lv_draw_printing(void) { disp_state_stack._disp_index = 0; ZERO(disp_state_stack._disp_state); - disp_state_stack._disp_state[disp_state_stack._disp_index] = PRINTING_UI; - - disp_state = PRINTING_UI; - - scr = lv_obj_create(NULL, NULL); - - // static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(PRINTING_UI); // Create image buttons - lv_obj_t *buttonExt1 = lv_img_create(scr, NULL); - #if HAS_MULTI_EXTRUDER - lv_obj_t *buttonExt2 = lv_img_create(scr, NULL); - #endif - #if HAS_HEATED_BED - lv_obj_t *buttonBedstate = lv_img_create(scr, NULL); - #endif - lv_obj_t *buttonFanstate = lv_img_create(scr, NULL); - lv_obj_t *buttonTime = lv_img_create(scr, NULL); - lv_obj_t *buttonZpos = lv_img_create(scr, NULL); - buttonPause = lv_imgbtn_create(scr, NULL); - buttonStop = lv_imgbtn_create(scr, NULL); - buttonOperat = lv_imgbtn_create(scr, NULL); - + lv_obj_t *buttonExt1 = lv_img_create(scr, nullptr); lv_img_set_src(buttonExt1, "F:/bmp_ext1_state.bin"); - #if 1 - #if HAS_MULTI_EXTRUDER - lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin"); - #endif - #if HAS_HEATED_BED - lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin"); - #endif + lv_obj_set_pos(buttonExt1, 205, 136); - lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin"); + #if HAS_MULTI_EXTRUDER + lv_obj_t *buttonExt2 = lv_img_create(scr, nullptr); + lv_img_set_src(buttonExt2, "F:/bmp_ext2_state.bin"); + lv_obj_set_pos(buttonExt2, 350, 136); + #endif - lv_img_set_src(buttonTime, "F:/bmp_time_state.bin"); + #if HAS_HEATED_BED + lv_obj_t *buttonBedstate = lv_img_create(scr, nullptr); + lv_img_set_src(buttonBedstate, "F:/bmp_bed_state.bin"); + lv_obj_set_pos(buttonBedstate, 205, 186); + #endif - lv_img_set_src(buttonZpos, "F:/bmp_zpos_state.bin"); + lv_obj_t *buttonFanstate = lv_img_create(scr, nullptr); + lv_img_set_src(buttonFanstate, "F:/bmp_fan_state.bin"); + lv_obj_set_pos(buttonFanstate, 350, 186); - if (uiCfg.print_state == WORKING) { - lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_REL, "F:/bmp_pause.bin"); - lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_PR, "F:/bmp_pause.bin"); - } - else { - lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_REL, "F:/bmp_resume.bin"); - lv_imgbtn_set_src(buttonPause, LV_BTN_STATE_PR, "F:/bmp_resume.bin"); - } + lv_obj_t *buttonTime = lv_img_create(scr, nullptr); + lv_img_set_src(buttonTime, "F:/bmp_time_state.bin"); + lv_obj_set_pos(buttonTime, 205, 86); - lv_obj_set_event_cb_mks(buttonPause, event_handler, ID_PAUSE, NULL, 0); - lv_imgbtn_set_style(buttonPause, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPause, LV_BTN_STATE_REL, &tft_style_label_rel); + lv_obj_t *buttonZpos = lv_img_create(scr, nullptr); + lv_img_set_src(buttonZpos, "F:/bmp_zpos_state.bin"); + lv_obj_set_pos(buttonZpos, 350, 86); - lv_obj_set_event_cb_mks(buttonStop, event_handler, ID_STOP, NULL, 0); - lv_imgbtn_set_src(buttonStop, LV_BTN_STATE_REL, "F:/bmp_stop.bin"); - lv_imgbtn_set_src(buttonStop, LV_BTN_STATE_PR, "F:/bmp_stop.bin"); - lv_imgbtn_set_style(buttonStop, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonStop, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonOperat, event_handler, ID_OPTION, NULL, 0); - lv_imgbtn_set_src(buttonOperat, LV_BTN_STATE_REL, "F:/bmp_operate.bin"); - lv_imgbtn_set_src(buttonOperat, LV_BTN_STATE_PR, "F:/bmp_operate.bin"); - lv_imgbtn_set_style(buttonOperat, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonOperat, LV_BTN_STATE_REL, &tft_style_label_rel); - - #endif // if 1 + buttonPause = lv_imgbtn_create(scr, uiCfg.print_state == WORKING ? "F:/bmp_pause.bin" : "F:/bmp_resume.bin", 5, 240, event_handler, ID_PAUSE); + buttonStop = lv_imgbtn_create(scr, "F:/bmp_stop.bin", 165, 240, event_handler, ID_STOP); + buttonOperat = lv_imgbtn_create(scr, "F:/bmp_operate.bin", 325, 240, event_handler, ID_OPTION); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { @@ -224,71 +164,37 @@ void lv_draw_printing(void) { } #endif - lv_obj_set_pos(buttonExt1, 205, 136); - - #if HAS_MULTI_EXTRUDER - lv_obj_set_pos(buttonExt2, 350, 136); - #endif - - #if HAS_HEATED_BED - lv_obj_set_pos(buttonBedstate, 205, 186); - #endif - - lv_obj_set_pos(buttonFanstate, 350, 186); - lv_obj_set_pos(buttonTime, 205, 86); - lv_obj_set_pos(buttonZpos, 350, 86); - lv_obj_set_pos(buttonPause, 5, 240); - lv_obj_set_pos(buttonStop, 165, 240); - lv_obj_set_pos(buttonOperat, 325, 240); - // Create labels on the image buttons //lv_btn_set_layout(buttonExt1, LV_LAYOUT_OFF); //#if HAS_MULTI_EXTRUDER - //lv_btn_set_layout(buttonExt2, LV_LAYOUT_OFF); + // lv_btn_set_layout(buttonExt2, LV_LAYOUT_OFF); //#endif //#if HAS_HEATED_BED - //lv_btn_set_layout(buttonBedstate, LV_LAYOUT_OFF); + // lv_btn_set_layout(buttonBedstate, LV_LAYOUT_OFF); //#endif //lv_btn_set_layout(buttonFanstate, LV_LAYOUT_OFF); //lv_btn_set_layout(buttonTime, LV_LAYOUT_OFF); //lv_btn_set_layout(buttonZpos, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonPause, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonStop, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonOperat, LV_LAYOUT_OFF); - labelExt1 = lv_label_create(scr, NULL); - lv_obj_set_style(labelExt1, &tft_style_label_rel); - lv_obj_set_pos(labelExt1, 250, 146); + labelExt1 = lv_label_create(scr, 250, 146, nullptr); #if HAS_MULTI_EXTRUDER - labelExt2 = lv_label_create(scr, NULL); - lv_obj_set_style(labelExt2, &tft_style_label_rel); - lv_obj_set_pos(labelExt2, 395, 146); + labelExt2 = lv_label_create(scr, 395, 146, nullptr); #endif #if HAS_HEATED_BED - labelBed = lv_label_create(scr, NULL); - lv_obj_set_style(labelBed, &tft_style_label_rel); - lv_obj_set_pos(labelBed, 250, 196); + labelBed = lv_label_create(scr, 250, 196, nullptr); #endif - labelFan = lv_label_create(scr, NULL); - lv_obj_set_style(labelFan, &tft_style_label_rel); - lv_obj_set_pos(labelFan, 395, 196); + labelFan = lv_label_create(scr, 395, 196, nullptr); + labelTime = lv_label_create(scr, 250, 96, nullptr); + labelZpos = lv_label_create(scr, 395, 96, nullptr); - labelTime = lv_label_create(scr, NULL); - lv_obj_set_style(labelTime, &tft_style_label_rel); - lv_obj_set_pos(labelTime, 250, 96); - - labelZpos = lv_label_create(scr, NULL); - lv_obj_set_style(labelZpos, &tft_style_label_rel); - lv_obj_set_pos(labelZpos, 395, 96); - - labelPause = lv_label_create(buttonPause, NULL); - labelStop = lv_label_create(buttonStop, NULL); - labelOperat = lv_label_create(buttonOperat, NULL); + labelPause = lv_label_create_empty(buttonPause); + labelStop = lv_label_create_empty(buttonStop); + labelOperat = lv_label_create_empty(buttonOperat); if (gCfgItems.multiple_language) { lv_label_set_text(labelPause, uiCfg.print_state == WORKING ? printing_menu.pause : printing_menu.resume); @@ -301,13 +207,13 @@ void lv_draw_printing(void) { lv_obj_align(labelOperat, buttonOperat, LV_ALIGN_CENTER, 20, 0); } - bar1 = lv_bar_create(scr, NULL); + bar1 = lv_bar_create(scr, nullptr); lv_obj_set_pos(bar1, 205, 36); lv_obj_set_size(bar1, 270, 40); lv_bar_set_style(bar1, LV_BAR_STYLE_INDIC, &lv_bar_style_indic); lv_bar_set_anim_time(bar1, 1000); lv_bar_set_value(bar1, 0, LV_ANIM_ON); - bar1ValueText = lv_label_create(bar1, NULL); + bar1ValueText = lv_label_create_empty(bar1); lv_label_set_text(bar1ValueText,"0%"); lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0); @@ -319,12 +225,10 @@ void lv_draw_printing(void) { } void disp_ext_temp() { - ZERO(public_buf_l); sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[0].celsius, (int)thermalManager.temp_hotend[0].target); lv_label_set_text(labelExt1, public_buf_l); #if HAS_MULTI_EXTRUDER - ZERO(public_buf_l); sprintf(public_buf_l, printing_menu.temp1, (int)thermalManager.temp_hotend[1].celsius, (int)thermalManager.temp_hotend[1].target); lv_label_set_text(labelExt2, public_buf_l); #endif @@ -332,20 +236,17 @@ void disp_ext_temp() { void disp_bed_temp() { #if HAS_HEATED_BED - ZERO(public_buf_l); sprintf(public_buf_l, printing_menu.bed_temp, (int)thermalManager.temp_bed.celsius, (int)thermalManager.temp_bed.target); lv_label_set_text(labelBed, public_buf_l); #endif } void disp_fan_speed() { - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("%3d"), thermalManager.fan_speed[0]); lv_label_set_text(labelFan, public_buf_l); } void disp_print_time() { - ZERO(public_buf_l); #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME) const uint32_t r = ui.get_remaining_time(); sprintf_P(public_buf_l, PSTR("%02d:%02d R"), r / 3600, (r % 3600) / 60); @@ -356,7 +257,6 @@ void disp_print_time() { } void disp_fan_Zpos() { - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("%.3f"), current_position[Z_AXIS]); lv_label_set_text(labelZpos, public_buf_l); } @@ -396,7 +296,6 @@ void setProBarRate() { if (disp_state == PRINTING_UI) { lv_bar_set_value(bar1, rate, LV_ANIM_ON); - ZERO(public_buf_l); sprintf_P(public_buf_l, "%d%%", rate); lv_label_set_text(bar1ValueText,public_buf_l); lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h index b7d464e4f0..466efe01cb 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.h @@ -25,14 +25,16 @@ extern "C" { /* C-declarations for C++ */ #endif -#define IDLE 0 -#define WORKING 1 -#define PAUSING 2 -#define PAUSED 3 -#define REPRINTING 4 -#define REPRINTED 5 -#define RESUMING 6 -#define STOP 7 +enum { + IDLE, + WORKING, + PAUSING, + PAUSED, + REPRINTING, + REPRINTED, + RESUMING, + STOP +}; extern void lv_draw_printing(void); extern void lv_clear_printing(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp index 276e8fb551..cee02cc47a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp @@ -41,46 +41,33 @@ #include -//static lv_obj_t *buttonPrint,*buttonTool,*buttonSet; +//static lv_obj_t *buttonPrint, *buttonTool, *buttonSet; extern lv_group_t* g; -static lv_obj_t * scr; +static lv_obj_t *scr; #if ENABLED(MKS_TEST) uint8_t curent_disp_ui = 0; #endif -#define ID_TOOL 1 -#define ID_SET 2 -#define ID_PRINT 3 +enum { + ID_TOOL = 1, + ID_SET, + ID_PRINT +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_TOOL: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - - lv_clear_ready_print(); - lv_draw_tool(); - } + lv_clear_ready_print(); + lv_draw_tool(); break; case ID_SET: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_ready_print(); - lv_draw_set(); - } + lv_clear_ready_print(); + lv_draw_set(); break; case ID_PRINT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_ready_print(); - lv_draw_print_file(); - } + lv_clear_ready_print(); + lv_draw_print_file(); break; } } @@ -112,22 +99,18 @@ void disp_det_error() { lv_obj_t *e1, *e2, *e3, *bed; void mks_disp_test() { char buf[30] = {0}; - //lv_obj_t *label_tool2 = lv_label_create(scr, NULL); - //lv_obj_set_pos(label_tool,20,50); - ZERO(buf); + //lv_obj_t *label_tool2 = lv_label_create_empty(scr); + //lv_obj_set_pos(label_tool, 20, 50); sprintf_P(buf, PSTR("e1:%d"), (int)thermalManager.temp_hotend[0].celsius); lv_label_set_text(e1, buf); #if HAS_MULTI_HOTEND - ZERO(buf); sprintf_P(buf, PSTR("e2:%d"), (int)thermalManager.temp_hotend[1].celsius); lv_label_set_text(e2, buf); #endif - //ZERO(buf); //sprintf_P(buf, PSTR("e3:%d"), (int)thermalManager.temp_hotend[2].celsius); //lv_label_set_text(e3, buf); #if HAS_HEATED_BED - ZERO(buf); sprintf_P(buf, PSTR("bed:%d"), (int)thermalManager.temp_bed.celsius); lv_label_set_text(bed, buf); #endif @@ -135,95 +118,75 @@ void mks_disp_test() { void lv_draw_ready_print(void) { char buf[30] = {0}; - lv_obj_t *buttonPrint, *buttonTool, *buttonSet; + lv_obj_t *buttonTool; disp_state_stack._disp_index = 0; ZERO(disp_state_stack._disp_state); - disp_state_stack._disp_state[disp_state_stack._disp_index] = PRINT_READY_UI; - - disp_state = PRINT_READY_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - //lv_obj_set_hidden(scr,true); - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(PRINT_READY_UI, ""); + //lv_obj_set_hidden(scr, true); if (mks_test_flag == 0x1E) { - //lv_obj_t * title = lv_label_create(scr, NULL); - //lv_obj_set_style(title, &tft_style_label_rel); - //lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS); - //lv_label_set_text(title, creat_title_text()); + //(void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); // Create image buttons - //buttonPrint = lv_imgbtn_create(scr, NULL); - buttonTool = lv_imgbtn_create(scr, NULL); - //buttonSet = lv_imgbtn_create(scr, NULL); - - #if 1 - lv_obj_set_event_cb_mks(buttonTool, event_handler, ID_TOOL, NULL, 0); - lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_REL, "F:/bmp_tool.bin"); - lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_PR, "F:/bmp_tool.bin"); - lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif + //buttonPrint = lv_imgbtn_create(scr, nullptr); + buttonTool = lv_imgbtn_create(scr, "F:/bmp_tool.bin", event_handler, ID_TOOL); lv_obj_set_pos(buttonTool, 360, 180); - //lv_obj_set_pos(buttonSet,180,90); - //lv_obj_set_pos(buttonPrint,340,90); - //lv_obj_set_pos(buttonTool,SIMPLE_FIRST_PAGE_GRAP+1,(TFT_HEIGHT-BTN_Y_PIXEL)/2+2); - //lv_obj_set_pos(buttonSet,BTN_X_PIXEL+SIMPLE_FIRST_PAGE_GRAP*2+1,(TFT_HEIGHT-BTN_Y_PIXEL)/2+2); - //lv_obj_set_pos(buttonPrint,BTN_X_PIXEL*2+SIMPLE_FIRST_PAGE_GRAP*3+1,(TFT_HEIGHT-BTN_Y_PIXEL)/2+2); + //buttonSet = lv_imgbtn_create(scr, nullptr); + //lv_obj_set_pos(buttonSet, 180, 90); + //lv_obj_set_pos(buttonPrint, 340, 90); + + //lv_obj_set_pos(buttonTool, SIMPLE_FIRST_PAGE_GRAP+1, (TFT_HEIGHT-BTN_Y_PIXEL)/2+2); + //lv_obj_set_pos(buttonSet, BTN_X_PIXEL+SIMPLE_FIRST_PAGE_GRAP*2+1, (TFT_HEIGHT-BTN_Y_PIXEL)/2+2); + //lv_obj_set_pos(buttonPrint, BTN_X_PIXEL*2+SIMPLE_FIRST_PAGE_GRAP*3+1, (TFT_HEIGHT-BTN_Y_PIXEL)/2+2); // Create labels on the image buttons //lv_btn_set_layout(buttonPrint, LV_LAYOUT_OFF); //lv_btn_set_layout(buttonSet, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonTool, LV_LAYOUT_OFF); - //lv_obj_t *label_print = lv_label_create(buttonPrint, NULL); - //lv_obj_t *label_set = lv_label_create(buttonSet, NULL); - lv_obj_t *label_tool = lv_label_create(buttonTool, NULL); + //lv_obj_t *label_print = lv_label_create_empty(buttonPrint); + //lv_obj_t *label_set = lv_label_create_empty(buttonSet); + lv_obj_t *label_tool = lv_label_create_empty(buttonTool); if (gCfgItems.multiple_language) { //lv_label_set_text(label_print, main_menu.print); - //lv_obj_align(label_print, buttonPrint, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); + //lv_obj_align(label_print, buttonPrint, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); //lv_label_set_text(label_set, main_menu.set); - //lv_obj_align(label_set, buttonSet, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); + //lv_obj_align(label_set, buttonSet, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - //lv_label_set_style(label_tool,LV_BTN_STATE_PR,&tft_style_label_pre); - //lv_label_set_style(label_tool,LV_BTN_STATE_REL,&tft_style_label_rel); + //lv_label_set_style(label_tool, LV_BTN_STATE_PR, &tft_style_label_pre); + //lv_label_set_style(label_tool, LV_BTN_STATE_REL, &tft_style_label_rel); lv_label_set_text(label_tool, main_menu.tool); lv_obj_align(label_tool, buttonTool, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } #if 1 - e1 = lv_label_create(scr, NULL); + e1 = lv_label_create_empty(scr); lv_obj_set_pos(e1, 20, 20); sprintf_P(buf, PSTR("e1: %d"), (int)thermalManager.temp_hotend[0].celsius); lv_label_set_text(e1, buf); #if HAS_MULTI_HOTEND - e2 = lv_label_create(scr, NULL); + e2 = lv_label_create_empty(scr); lv_obj_set_pos(e2, 20, 45); sprintf_P(buf, PSTR("e1: %d"), (int)thermalManager.temp_hotend[1].celsius); lv_label_set_text(e2, buf); #endif - //e3 = lv_label_create(scr, NULL); - //lv_obj_set_pos(e3,20,70); + //e3 = lv_label_create_empty(scr); + //lv_obj_set_pos(e3, 20, 70); //sprintf_P(buf, PSTR("e1: %d"), (int)thermalManager.temp_hotend[2].celsius); //lv_label_set_text(e3, buf); #if HAS_HEATED_BED - bed = lv_label_create(scr, NULL); + bed = lv_label_create_empty(scr); lv_obj_set_pos(bed, 20, 95); sprintf_P(buf, PSTR("bed: %d"), (int)thermalManager.temp_bed.celsius); lv_label_set_text(bed, buf); #endif - limit_info = lv_label_create(scr, NULL); + limit_info = lv_label_create_empty(scr); lv_style_copy(&limit_style, &lv_style_scr); limit_style.body.main_color.full = 0X0000; @@ -234,7 +197,7 @@ void lv_draw_ready_print(void) { lv_obj_set_pos(limit_info, 20, 120); lv_label_set_text(limit_info, " "); - det_info = lv_label_create(scr, NULL); + det_info = lv_label_create_empty(scr); lv_style_copy(&det_style, &lv_style_scr); det_style.body.main_color.full = 0X0000; @@ -248,55 +211,9 @@ void lv_draw_ready_print(void) { } else { - // Create an Image button - buttonTool = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonTool, 20, 90); - lv_obj_set_event_cb_mks(buttonTool, event_handler, ID_TOOL, NULL, 0); - lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_REL, "F:/bmp_tool.bin"); - lv_imgbtn_set_src(buttonTool, LV_BTN_STATE_PR, "F:/bmp_tool.bin"); - lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonTool, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_obj_t *label_tool = lv_label_create(buttonTool, NULL); - lv_btn_set_layout(buttonTool, LV_LAYOUT_OFF); - - buttonSet = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonSet, 180, 90); - lv_obj_set_event_cb_mks(buttonSet, event_handler, ID_SET, NULL, 0); - lv_imgbtn_set_src(buttonSet, LV_BTN_STATE_REL, "F:/bmp_set.bin"); - lv_imgbtn_set_src(buttonSet, LV_BTN_STATE_PR, "F:/bmp_set.bin"); - lv_imgbtn_set_style(buttonSet, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonSet, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_obj_t *label_set = lv_label_create(buttonSet, NULL); - lv_btn_set_layout(buttonSet, LV_LAYOUT_OFF); - - buttonPrint = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonPrint, 340, 90); - lv_obj_set_event_cb_mks(buttonPrint, event_handler, ID_PRINT, NULL, 0); - lv_imgbtn_set_src(buttonPrint, LV_BTN_STATE_REL, "F:/bmp_printing.bin"); - lv_imgbtn_set_src(buttonPrint, LV_BTN_STATE_PR, "F:/bmp_printing.bin"); - lv_imgbtn_set_style(buttonPrint, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPrint, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_obj_t *label_print = lv_label_create(buttonPrint, NULL); - lv_btn_set_layout(buttonPrint, LV_LAYOUT_OFF); - - if (gCfgItems.multiple_language) { - lv_label_set_text(label_print, main_menu.print); - lv_obj_align(label_print, buttonPrint, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_set, main_menu.set); - lv_obj_align(label_set, buttonSet, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_tool, main_menu.tool); - lv_obj_align(label_tool, buttonTool, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable == true) { - lv_group_add_obj(g, buttonTool); - lv_group_add_obj(g, buttonSet); - lv_group_add_obj(g, buttonPrint); - } - #endif + lv_big_button_create(scr, "F:/bmp_tool.bin", main_menu.tool, 20, 90, event_handler, ID_TOOL); + lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET); + lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT); } } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp index d23fe40182..b2211e5631 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_set.cpp @@ -37,100 +37,58 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" -static lv_obj_t * scr; +static lv_obj_t *scr; extern lv_group_t* g; -#define ID_S_WIFI 1 -#define ID_S_FAN 2 -#define ID_S_ABOUT 3 -#define ID_S_CONTINUE 4 -#define ID_S_MOTOR_OFF 5 -#define ID_S_LANGUAGE 6 -#define ID_S_MACHINE_PARA 7 -#define ID_S_EEPROM_SET 8 -#define ID_S_RETURN 9 +enum { + ID_S_WIFI = 1, + ID_S_FAN, + ID_S_ABOUT, + ID_S_CONTINUE, + ID_S_MOTOR_OFF, + ID_S_LANGUAGE, + ID_S_MACHINE_PARA, + ID_S_EEPROM_SET, + ID_S_RETURN +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; #if ENABLED(USE_WIFI_FUNCTION) char buf[6] = { 0 }; #endif switch (obj->mks_obj_id) { - case ID_S_FAN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_fan(); - } + lv_clear_set(); + lv_draw_fan(); break; case ID_S_ABOUT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_about(); - } - break; - case ID_S_CONTINUE: - + lv_clear_set(); + lv_draw_about(); break; + case ID_S_CONTINUE: break; case ID_S_MOTOR_OFF: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if HAS_SUICIDE - suicide(); - #else - queue.enqueue_now_P(PSTR("M84")); - #endif - } + TERN(HAS_SUICIDE, suicide(), queue.enqueue_now_P(PSTR("M84"))); break; case ID_S_LANGUAGE: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_language(); - } + lv_clear_set(); + lv_draw_language(); break; case ID_S_MACHINE_PARA: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_machine_para(); - } + lv_clear_set(); + lv_draw_machine_para(); break; case ID_S_EEPROM_SET: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_eeprom_settings(); - } + lv_clear_set(); + lv_draw_eeprom_settings(); break; case ID_S_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_set(); - lv_draw_ready_print(); - } + lv_clear_set(); + lv_draw_ready_print(); break; + #if ENABLED(USE_WIFI_FUNCTION) case ID_S_WIFI: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { if (gCfgItems.wifi_mode_sel == STA_MODEL) { if (wifi_link_state == WIFI_CONNECTED) { last_disp_state = SET_UI; @@ -153,7 +111,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { else { last_disp_state = SET_UI; lv_clear_set(); - lv_draw_dialog(WIFI_ENABLE_TIPS); + lv_draw_dialog(DIALOG_WIFI_ENABLE_TIPS); } } } @@ -162,223 +120,25 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { lv_clear_set(); lv_draw_wifi(); } - } - break; + break; #endif } } void lv_draw_set(void) { - lv_obj_t *buttonFan, *buttonAbout; - lv_obj_t *buMotorOff, *buttonBack; + scr = lv_screen_create(SET_UI); + lv_big_button_create(scr, "F:/bmp_eeprom_settings.bin", set_menu.eepromSet, INTERVAL_V, titleHeight, event_handler, ID_S_EEPROM_SET); + lv_big_button_create(scr, "F:/bmp_fan.bin", set_menu.fan, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_S_FAN); + lv_big_button_create(scr, "F:/bmp_about.bin", set_menu.about, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_S_ABOUT); + lv_big_button_create(scr, ENABLED(HAS_SUICIDE) ? "F:/bmp_manual_off.bin" : "F:/bmp_function1.bin", set_menu.TERN(HAS_SUICIDE, shutdown, motoroff), BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_S_MOTOR_OFF); + lv_big_button_create(scr, "F:/bmp_machine_para.bin", set_menu.machine_para, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_MACHINE_PARA); #if HAS_LANG_SELECT_SCREEN - lv_obj_t *buttonLanguage; - #endif - lv_obj_t *buttonMachinePara; - lv_obj_t *buttonEepromSet; - #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_t *buttonWifi; - #endif - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != SET_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = SET_UI; - } - disp_state = SET_UI; - - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - // Create image buttons - buttonEepromSet = lv_imgbtn_create(scr, NULL); - //buttonWifi = lv_imgbtn_create(scr, NULL); - buttonFan = lv_imgbtn_create(scr, NULL); - buttonAbout = lv_imgbtn_create(scr, NULL); - //buttonContinue = lv_imgbtn_create(scr, NULL); - buMotorOff = lv_imgbtn_create(scr, NULL); - buttonMachinePara = lv_imgbtn_create(scr, NULL); - #if HAS_LANG_SELECT_SCREEN - buttonLanguage = lv_imgbtn_create(scr, NULL); + lv_big_button_create(scr, "F:/bmp_language.bin", set_menu.language, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_LANGUAGE); #endif #if ENABLED(USE_WIFI_FUNCTION) - buttonWifi = lv_imgbtn_create(scr, NULL); - #endif - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonEepromSet, event_handler, ID_S_EEPROM_SET, NULL, 0); - lv_imgbtn_set_src(buttonEepromSet, LV_BTN_STATE_REL, "F:/bmp_eeprom_settings.bin"); - lv_imgbtn_set_src(buttonEepromSet, LV_BTN_STATE_PR, "F:/bmp_eeprom_settings.bin"); - lv_imgbtn_set_style(buttonEepromSet, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonEepromSet, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if 1 - lv_obj_set_event_cb_mks(buttonFan, event_handler, ID_S_FAN, NULL, 0); - lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_REL, "F:/bmp_fan.bin"); - lv_imgbtn_set_src(buttonFan, LV_BTN_STATE_PR, "F:/bmp_fan.bin"); - lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonFan, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonAbout, event_handler, ID_S_ABOUT, NULL, 0); - lv_imgbtn_set_src(buttonAbout, LV_BTN_STATE_REL, "F:/bmp_about.bin"); - lv_imgbtn_set_src(buttonAbout, LV_BTN_STATE_PR, "F:/bmp_about.bin"); - lv_imgbtn_set_style(buttonAbout, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonAbout, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buMotorOff, event_handler, ID_S_MOTOR_OFF, NULL, 0); - - #if HAS_SUICIDE - lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_REL, "F:/bmp_manual_off.bin"); - lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_PR, "F:/bmp_manual_off.bin"); - #else - lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_REL, "F:/bmp_function1.bin"); - lv_imgbtn_set_src(buMotorOff, LV_BTN_STATE_PR, "F:/bmp_function1.bin"); - #endif - lv_imgbtn_set_style(buMotorOff, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buMotorOff, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonMachinePara, event_handler, ID_S_MACHINE_PARA, NULL, 0); - lv_imgbtn_set_src(buttonMachinePara, LV_BTN_STATE_REL, "F:/bmp_machine_para.bin"); - lv_imgbtn_set_src(buttonMachinePara, LV_BTN_STATE_PR, "F:/bmp_machine_para.bin"); - lv_imgbtn_set_style(buttonMachinePara, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMachinePara, LV_BTN_STATE_REL, &tft_style_label_rel); - - #if HAS_LANG_SELECT_SCREEN - lv_obj_set_event_cb_mks(buttonLanguage, event_handler, ID_S_LANGUAGE, NULL, 0); - lv_imgbtn_set_src(buttonLanguage, LV_BTN_STATE_REL, "F:/bmp_language.bin"); - lv_imgbtn_set_src(buttonLanguage, LV_BTN_STATE_PR, "F:/bmp_language.bin"); - lv_imgbtn_set_style(buttonLanguage, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonLanguage, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_set_event_cb_mks(buttonWifi, event_handler,ID_S_WIFI,NULL,0); - lv_imgbtn_set_src(buttonWifi, LV_BTN_STATE_REL, "F:/bmp_wifi.bin"); - lv_imgbtn_set_src(buttonWifi, LV_BTN_STATE_PR, "F:/bmp_wifi.bin"); - lv_imgbtn_set_style(buttonWifi, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonWifi, LV_BTN_STATE_REL, &tft_style_label_rel); - #endif - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_S_RETURN,NULL , 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - #endif // if 1 - - /*lv_obj_set_pos(buttonWifi,INTERVAL_V,titleHeight); - lv_obj_set_pos(buttonFan,BTN_X_PIXEL+INTERVAL_V*2,titleHeight); - lv_obj_set_pos(buttonAbout,BTN_X_PIXEL*2+INTERVAL_V*3,titleHeight); - lv_obj_set_pos(buttonContinue,BTN_X_PIXEL*3+INTERVAL_V*4,titleHeight); - lv_obj_set_pos(buMotorOff,INTERVAL_V, BTN_Y_PIXEL+INTERVAL_H+titleHeight); - lv_obj_set_pos(buttonLanguage,BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight); - lv_obj_set_pos(buttonBack,BTN_X_PIXEL*3+INTERVAL_V*4, BTN_Y_PIXEL+INTERVAL_H+titleHeight);*/ - - //lv_obj_set_pos(buttonWifi,INTERVAL_V,titleHeight); - lv_obj_set_pos(buttonEepromSet, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonFan, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonAbout, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - //lv_obj_set_pos(buttonContinue,BTN_X_PIXEL*3+INTERVAL_V*4,titleHeight); - lv_obj_set_pos(buMotorOff, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - - lv_obj_set_pos(buttonMachinePara, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - #if HAS_LANG_SELECT_SCREEN - lv_obj_set_pos(buttonLanguage, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - #endif - #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_set_pos(buttonWifi,BTN_X_PIXEL*2+INTERVAL_V*3,BTN_Y_PIXEL+INTERVAL_H+titleHeight); - #endif - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - /// Create labels on the buttons - //lv_btn_set_layout(buttonWifi, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonEepromSet, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonFan, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonAbout, LV_LAYOUT_OFF); - //lv_btn_set_layout(buttonContinue, LV_LAYOUT_OFF); - lv_btn_set_layout(buMotorOff, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonMachinePara, LV_LAYOUT_OFF); - #if HAS_LANG_SELECT_SCREEN - lv_btn_set_layout(buttonLanguage, LV_LAYOUT_OFF); - #endif - #if ENABLED(USE_WIFI_FUNCTION) - lv_btn_set_layout(buttonWifi, LV_LAYOUT_OFF); - #endif - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - //lv_obj_t *labelWifi= lv_label_create(buttonWifi, NULL); - lv_obj_t *label_EepromSet = lv_label_create(buttonEepromSet, NULL); - lv_obj_t *labelFan = lv_label_create(buttonFan, NULL); - lv_obj_t *label_About = lv_label_create(buttonAbout, NULL); - //lv_obj_t *label_Continue = lv_label_create(buttonContinue, NULL); - lv_obj_t *label_MotorOff = lv_label_create(buMotorOff, NULL); - lv_obj_t *label_MachinePara = lv_label_create(buttonMachinePara, NULL); - #if HAS_LANG_SELECT_SCREEN - lv_obj_t *label_Language = lv_label_create(buttonLanguage, NULL); - #endif - #if ENABLED(USE_WIFI_FUNCTION) - lv_obj_t *label_Wifi = lv_label_create(buttonWifi, NULL); - #endif - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - - lv_label_set_text(label_EepromSet, set_menu.eepromSet); - lv_obj_align(label_EepromSet, buttonEepromSet, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelFan, set_menu.fan); - lv_obj_align(labelFan, buttonFan, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_About, set_menu.about); - lv_obj_align(label_About, buttonAbout, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - //lv_label_set_text(label_Continue, set_menu.breakpoint); - //lv_obj_align(label_Continue, buttonContinue, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - lv_label_set_text(label_MotorOff, set_menu.TERN(HAS_SUICIDE, shutdown, motoroff)); - lv_obj_align(label_MotorOff, buMotorOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_MachinePara, set_menu.machine_para); - lv_obj_align(label_MachinePara, buttonMachinePara, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - #if HAS_LANG_SELECT_SCREEN - lv_label_set_text(label_Language, set_menu.language); - lv_obj_align(label_Language, buttonLanguage, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - #endif - - #if ENABLED(USE_WIFI_FUNCTION) - lv_label_set_text(label_Wifi, set_menu.wifi); - lv_obj_align(label_Wifi, buttonWifi, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - #endif - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonEepromSet); - lv_group_add_obj(g, buttonFan); - lv_group_add_obj(g, buttonAbout); - lv_group_add_obj(g, buMotorOff); - lv_group_add_obj(g, buttonMachinePara); - lv_group_add_obj(g, buttonLanguage); - #if ENABLED(USE_WIFI_FUNCTION) - lv_group_add_obj(g, buttonWifi); - #endif - lv_group_add_obj(g, buttonBack); - } + lv_big_button_create(scr, "F:/bmp_wifi.bin", set_menu.wifi, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_WIFI); #endif + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_S_RETURN); } void lv_clear_set() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp index ff45fba461..022c4d30f9 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_step_settings.cpp @@ -29,293 +29,92 @@ #include "../../../../module/planner.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_STEP_RETURN 1 -#define ID_STEP_X 2 -#define ID_STEP_Y 3 -#define ID_STEP_Z 4 -#define ID_STEP_E0 5 -#define ID_STEP_E1 6 -#define ID_STEP_DOWN 7 -#define ID_STEP_UP 8 +enum { + ID_STEP_RETURN = 1, + ID_STEP_X, + ID_STEP_Y, + ID_STEP_Z, + ID_STEP_E0, + ID_STEP_E1, + ID_STEP_DOWN, + ID_STEP_UP +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_STEP_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_step_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_step_settings(); + draw_return_ui(); break; case ID_STEP_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Xstep; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = Xstep; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Ystep; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = Ystep; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Zstep; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = Zstep; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0step; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = E0step; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1step; - lv_clear_step_settings(); - lv_draw_number_key(); - } + value = E1step; + lv_clear_step_settings(); + lv_draw_number_key(); break; case ID_STEP_UP: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_step_settings(); - lv_draw_step_settings(); - } + uiCfg.para_ui_page = 0; + lv_clear_step_settings(); + lv_draw_step_settings(); break; case ID_STEP_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_step_settings(); - lv_draw_step_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_step_settings(); + lv_draw_step_settings(); break; } } void lv_draw_step_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *labelE0Text = NULL, *buttonE0Value = NULL, *labelE0Value = NULL; - lv_obj_t *labelE1Text = NULL, *buttonE1Value = NULL, *labelE1Value = NULL; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != STEPS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = STEPS_UI; - } - disp_state = STEPS_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.StepsConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(STEPS_UI, machine_menu.StepsConfTitle); if (uiCfg.para_ui_page != 1) { - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelXText, machine_menu.X_Steps); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[X_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Steps, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_STEP_X, 0, public_buf_l); - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_STEP_X, NULL, 0); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - labelXValue = lv_label_create(buttonXValue, NULL); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Y_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Steps, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_STEP_Y, 1, public_buf_l); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Z_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Steps, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_STEP_Z, 2, public_buf_l); - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelYText, machine_menu.Y_Steps); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS]); + lv_screen_menu_item_1_edit(scr, machine_menu.E0_Steps, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_STEP_E0, 3, public_buf_l); - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_STEP_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - labelYValue = lv_label_create(buttonYValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelZText, machine_menu.Z_Steps); - - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_STEP_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - labelZValue = lv_label_create(buttonZValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelE0Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE0Text, &tft_style_label_rel); - lv_obj_set_pos(labelE0Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelE0Text, machine_menu.E0_Steps); - - buttonE0Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE0Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE0Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonE0Value, event_handler, ID_STEP_E0, NULL, 0); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_PR, &style_para_value); - labelE0Value = lv_label_create(buttonE0Value, NULL); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_STEP_DOWN, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_STEP_DOWN, true); } else { - labelE1Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE1Text, &tft_style_label_rel); - lv_obj_set_pos(labelE1Text, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelE1Text, machine_menu.E1_Steps); + sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS_N(1)]); + lv_screen_menu_item_1_edit(scr, machine_menu.E1_Steps, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_STEP_E1, 0, public_buf_l); - buttonE1Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE1Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE1Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonE1Value, event_handler, ID_STEP_E1, NULL, 0); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_PR, &style_para_value); - labelE1Value = lv_label_create(buttonE1Value, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_STEP_UP, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_STEP_UP, true); } - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create(buttonTurnPage, NULL); - - buttonBack = lv_btn_create(scr, NULL); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_STEP_RETURN, NULL, 0); - label_Back = lv_label_create(buttonBack, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[X_AXIS]); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Y_AXIS]); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[Z_AXIS]); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS]); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - } - else { - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), planner.settings.axis_steps_per_mm[E_AXIS_N(1)]); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_STEP_RETURN, true); } void lv_clear_step_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp index b19048f1c0..aaf3073e3d 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_current_settings.cpp @@ -30,350 +30,130 @@ #include "../../../../feature/tmc_util.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_TMC_CURRENT_RETURN 1 -#define ID_TMC_CURRENT_X 2 -#define ID_TMC_CURRENT_Y 3 -#define ID_TMC_CURRENT_Z 4 -#define ID_TMC_CURRENT_E0 5 -#define ID_TMC_CURRENT_E1 6 -#define ID_TMC_CURRENT_DOWN 7 -#define ID_TMC_CURRENT_UP 8 +enum { + ID_TMC_CURRENT_RETURN = 1, + ID_TMC_CURRENT_X, + ID_TMC_CURRENT_Y, + ID_TMC_CURRENT_Z, + ID_TMC_CURRENT_E0, + ID_TMC_CURRENT_E1, + ID_TMC_CURRENT_DOWN, + ID_TMC_CURRENT_UP +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_TMC_CURRENT_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_current_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_tmc_current_settings(); + draw_return_ui(); break; + #if AXIS_IS_TMC(X) case ID_TMC_CURRENT_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = Xcurrent; - lv_clear_tmc_current_settings(); - lv_draw_number_key(); - } + value = Xcurrent; + lv_clear_tmc_current_settings(); + lv_draw_number_key(); break; #endif - #if AXIS_IS_TMC(Y) - case ID_TMC_CURRENT_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + case ID_TMC_CURRENT_Y: value = Ycurrent; lv_clear_tmc_current_settings(); lv_draw_number_key(); - } - break; + break; #endif - #if AXIS_IS_TMC(Z) - case ID_TMC_CURRENT_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { + case ID_TMC_CURRENT_Z: value = Zcurrent; lv_clear_tmc_current_settings(); lv_draw_number_key(); - } - break; + break; #endif - #if AXIS_IS_TMC(E0) case ID_TMC_CURRENT_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E0current; - lv_clear_tmc_current_settings(); - lv_draw_number_key(); - } + value = E0current; + lv_clear_tmc_current_settings(); + lv_draw_number_key(); break; #endif - #if AXIS_IS_TMC(E1) case ID_TMC_CURRENT_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - value = E1current; - lv_clear_tmc_current_settings(); - lv_draw_number_key(); - } + value = E1current; + lv_clear_tmc_current_settings(); + lv_draw_number_key(); break; #endif - case ID_TMC_CURRENT_UP: - if (event == LV_EVENT_CLICKED) { - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_current_settings(); - lv_draw_tmc_current_settings(); - } + case ID_TMC_CURRENT_UP: + uiCfg.para_ui_page = 0; + lv_clear_tmc_current_settings(); + lv_draw_tmc_current_settings(); break; case ID_TMC_CURRENT_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_tmc_current_settings(); - lv_draw_tmc_current_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_tmc_current_settings(); + lv_draw_tmc_current_settings(); break; } } void lv_draw_tmc_current_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *labelXText = NULL, *buttonXValue = NULL, *labelXValue = NULL; - lv_obj_t *labelYText = NULL, *buttonYValue = NULL, *labelYValue = NULL; - lv_obj_t *labelZText = NULL, *buttonZValue = NULL, *labelZValue = NULL; - lv_obj_t *labelE0Text = NULL, *buttonE0Value = NULL, *labelE0Value = NULL; + scr = lv_screen_create(TMC_CURRENT_UI, machine_menu.TmcCurrentConfTitle); - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - //#if AXIS_IS_TMC(E1) - lv_obj_t *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *labelE1Text = NULL, *buttonE1Value = NULL, *labelE1Value = NULL; - //#endif float milliamps; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TMC_CURRENT_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = TMC_CURRENT_UI; - } - disp_state = TMC_CURRENT_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.TmcCurrentConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - if (uiCfg.para_ui_page != 1) { - labelXText = lv_label_create(scr, NULL); - lv_obj_set_style(labelXText, &tft_style_label_rel); - lv_obj_set_pos(labelXText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelXText, machine_menu.X_Current); - - buttonXValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonXValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonXValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonXValue, event_handler, ID_TMC_CURRENT_X, NULL, 0); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonXValue, LV_BTN_STYLE_PR, &style_para_value); - labelXValue = lv_label_create(buttonXValue, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - labelYText = lv_label_create(scr, NULL); - lv_obj_set_style(labelYText, &tft_style_label_rel); - lv_obj_set_pos(labelYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); - lv_label_set_text(labelYText, machine_menu.Y_Current); - - buttonYValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonYValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonYValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonYValue, event_handler, ID_TMC_CURRENT_Y, NULL, 0); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonYValue, LV_BTN_STYLE_PR, &style_para_value); - labelYValue = lv_label_create(buttonYValue, NULL); - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - labelZText = lv_label_create(scr, NULL); - lv_obj_set_style(labelZText, &tft_style_label_rel); - lv_obj_set_pos(labelZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - lv_label_set_text(labelZText, machine_menu.Z_Current); - - buttonZValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonZValue, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonZValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonZValue, event_handler, ID_TMC_CURRENT_Z, NULL, 0); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonZValue, LV_BTN_STYLE_PR, &style_para_value); - labelZValue = lv_label_create(buttonZValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - labelE0Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE0Text, &tft_style_label_rel); - lv_obj_set_pos(labelE0Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelE0Text, machine_menu.E0_Current); - - buttonE0Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE0Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE0Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonE0Value, event_handler, ID_TMC_CURRENT_E0, NULL, 0); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE0Value, LV_BTN_STYLE_PR, &style_para_value); - labelE0Value = lv_label_create(buttonE0Value, NULL); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonXValue); - lv_group_add_obj(g, buttonYValue); - lv_group_add_obj(g, buttonZValue); - lv_group_add_obj(g, buttonE0Value); - } + #if AXIS_IS_TMC(X) + milliamps = stepperX.getMilliamps(); + #else + milliamps = -1; #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.X_Current, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_CURRENT_X, 0, public_buf_l); - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); + #if AXIS_IS_TMC(Y) + milliamps = stepperY.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.Y_Current, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_TMC_CURRENT_Y, 1, public_buf_l); - //#if AXIS_IS_TMC(E1) - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_CURRENT_DOWN, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); + #if AXIS_IS_TMC(Z) + milliamps = stepperZ.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.Z_Current, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_TMC_CURRENT_Z, 2, public_buf_l); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTurnPage); - #endif - //#endif + #if AXIS_IS_TMC(E0) + milliamps = stepperE0.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.E0_Current, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_TMC_CURRENT_E0, 3, public_buf_l); + + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_CURRENT_DOWN, true); } else { - //#if AXIS_IS_TMC(E1) - labelE1Text = lv_label_create(scr, NULL); - lv_obj_set_style(labelE1Text, &tft_style_label_rel); - lv_obj_set_pos(labelE1Text, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelE1Text, machine_menu.E1_Current); + #if AXIS_IS_TMC(E1) + milliamps = stepperE1.getMilliamps(); + #else + milliamps = -1; + #endif + sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); + lv_screen_menu_item_1_edit(scr, machine_menu.E1_Current, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_CURRENT_E1, 0, public_buf_l); - buttonE1Value = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonE1Value, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V); - lv_obj_set_size(buttonE1Value, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonE1Value, event_handler, ID_TMC_CURRENT_E1, NULL, 0); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonE1Value, LV_BTN_STYLE_PR, &style_para_value); - labelE1Value = lv_label_create(buttonE1Value, NULL); - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_CURRENT_UP, NULL, 0); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonTurnPage, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonE1Value); - lv_group_add_obj(g, buttonTurnPage); - } - #endif - //#endif + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_CURRENT_UP, true); } - //#if AXIS_IS_TMC(E1) - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_obj_set_size(buttonTurnPage, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - labelTurnPage = lv_label_create(buttonTurnPage, NULL); - //#endif - buttonBack = lv_btn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_TMC_CURRENT_RETURN, NULL, 0); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_REL, &style_para_back); - lv_btn_set_style(buttonBack, LV_BTN_STYLE_PR, &style_para_back); - - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); - #endif - - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_obj_set_size(buttonBack, PARA_UI_BACK_BTN_X_SIZE, PARA_UI_BACK_BTN_Y_SIZE); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - //#if AXIS_IS_TMC(E1) - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - //#endif - #if AXIS_IS_TMC(X) - milliamps = stepperX.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelXValue, public_buf_l); - lv_obj_align(labelXValue, buttonXValue, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_IS_TMC(Y) - milliamps = stepperY.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelYValue, public_buf_l); - lv_obj_align(labelYValue, buttonYValue, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_IS_TMC(Z) - milliamps = stepperZ.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelZValue, public_buf_l); - lv_obj_align(labelZValue, buttonZValue, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_IS_TMC(E0) - milliamps = stepperE0.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelE0Value, public_buf_l); - lv_obj_align(labelE0Value, buttonE0Value, LV_ALIGN_CENTER, 0, 0); - } - else { - //#if AXIS_IS_TMC(E1) - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - #if AXIS_IS_TMC(E1) - milliamps = stepperE1.getMilliamps(); - #else - milliamps = -1; - #endif - ZERO(public_buf_l); - sprintf_P(public_buf_l, PSTR("%.1f"), milliamps); - lv_label_set_text(labelE1Value, public_buf_l); - lv_obj_align(labelE1Value, buttonE1Value, LV_ALIGN_CENTER, 0, 0); - //#endif - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); - } + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_TMC_CURRENT_RETURN, true); } void lv_clear_tmc_current_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp index 04087f632e..53d7e35382 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_tmc_step_mode_settings.cpp @@ -28,549 +28,122 @@ #include "../../../../module/stepper/indirection.h" #include "../../../../feature/tmc_util.h" -#include "../../../../gcode/gcode.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +#if ENABLED(EEPROM_SETTINGS) + #include "../../../../module/settings.h" +#endif -#define ID_TMC_MODE_RETURN 1 -#define ID_TMC_MODE_X 2 -#define ID_TMC_MODE_Y 3 -#define ID_TMC_MODE_Z 4 -#define ID_TMC_MODE_E0 5 -#define ID_TMC_MODE_E1 6 -#define ID_TMC_MODE_DOWN 7 -#define ID_TMC_MODE_UP 8 +extern lv_group_t *g; +static lv_obj_t *scr; -static lv_obj_t *labelXState = NULL, *labelYState = NULL, *labelZState = NULL, *labelE0State = NULL; -static lv_obj_t *buttonXState = NULL, *buttonYState = NULL, *buttonZState = NULL, *buttonE0State = NULL; +enum { + ID_TMC_MODE_RETURN = 1, + ID_TMC_MODE_X, + ID_TMC_MODE_Y, + ID_TMC_MODE_Z, + ID_TMC_MODE_E0, + ID_TMC_MODE_E1, + ID_TMC_MODE_DOWN, + ID_TMC_MODE_UP +}; + +static lv_obj_t *buttonXState = nullptr, *buttonYState = nullptr, *buttonZState = nullptr, *buttonE0State = nullptr; //#if AXIS_HAS_STEALTHCHOP(E1) - static lv_obj_t *labelE1State = NULL, *buttonE1State = NULL; + static lv_obj_t *buttonE1State = nullptr; //#endif -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + + auto toggle_chop = [&](auto &stepper, auto &button) { + const bool isena = stepper.toggle_stepping_mode(); + lv_screen_menu_item_onoff_update(button, isena); + TERN_(EEPROM_SETTINGS, (void)settings.save()); + }; + switch (obj->mks_obj_id) { case ID_TMC_MODE_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_step_mode_settings(); - draw_return_ui(); - } + uiCfg.para_ui_page = 0; + lv_clear_tmc_step_mode_settings(); + draw_return_ui(); break; #if AXIS_HAS_STEALTHCHOP(X) case ID_TMC_MODE_X: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperX.stored.stealthChop_enabled) { - stepperX.stored.stealthChop_enabled = false; - stepperX.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - lv_label_set_text(labelXState, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - // gcode.process_subcommands_now_P(PSTR("M500")); - } - else { - stepperX.stored.stealthChop_enabled = true; - stepperX.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - lv_label_set_text(labelXState, machine_menu.enable); - // gcode.process_subcommands_now_P(PSTR("M500")); - } - gcode.process_subcommands_now_P(PSTR("M500")); - } + toggle_chop(stepperX, buttonXState); break; - #endif // if AXIS_HAS_STEALTHCHOP(X) - + #endif #if AXIS_HAS_STEALTHCHOP(Y) case ID_TMC_MODE_Y: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperY.stored.stealthChop_enabled) { - stepperY.stored.stealthChop_enabled = false; - stepperY.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - lv_label_set_text(labelYState, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - else { - stepperY.stored.stealthChop_enabled = true; - stepperY.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - lv_label_set_text(labelYState, machine_menu.enable); - } - gcode.process_subcommands_now_P(PSTR("M500")); - } + toggle_chop(stepperY, buttonYState); break; - #endif // if AXIS_HAS_STEALTHCHOP(Y) - + #endif #if AXIS_HAS_STEALTHCHOP(Z) case ID_TMC_MODE_Z: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperZ.stored.stealthChop_enabled) { - stepperZ.stored.stealthChop_enabled = false; - stepperZ.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - lv_label_set_text(labelZState, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - else { - stepperZ.stored.stealthChop_enabled = true; - stepperZ.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - lv_label_set_text(labelZState, machine_menu.enable); - } - gcode.process_subcommands_now_P(PSTR("M500")); - } + toggle_chop(stepperZ, buttonZState); break; - #endif // if AXIS_HAS_STEALTHCHOP(Z) - + #endif #if AXIS_HAS_STEALTHCHOP(E0) case ID_TMC_MODE_E0: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperE0.stored.stealthChop_enabled) { - stepperE0.stored.stealthChop_enabled = false; - stepperE0.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - lv_label_set_text(labelE0State, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - else { - stepperE0.stored.stealthChop_enabled = true; - stepperE0.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - lv_label_set_text(labelE0State, machine_menu.enable); - } - gcode.process_subcommands_now_P(PSTR("M500")); - } + toggle_chop(stepperE0, buttonE0State); break; - #endif // if AXIS_HAS_STEALTHCHOP(E0) - + #endif #if AXIS_HAS_STEALTHCHOP(E1) case ID_TMC_MODE_E1: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (stepperE1.stored.stealthChop_enabled) { - stepperE1.stored.stealthChop_enabled = false; - stepperE1.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - lv_label_set_text(labelE1State, machine_menu.disable); - //lv_obj_align(labelXState, buttonE1State, LV_ALIGN_IN_LEFT_MID,0, 0); - } - else { - stepperE1.stored.stealthChop_enabled = true; - stepperE1.refresh_stepping_mode(); - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - lv_label_set_text(labelE1State, machine_menu.enable); - } - gcode.process_subcommands_now_P(PSTR("M500")); - } + toggle_chop(stepperE1, buttonE1State); break; - #endif // if AXIS_HAS_STEALTHCHOP(E1) - case ID_TMC_MODE_UP: - if (event == LV_EVENT_CLICKED) { + #endif - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 0; - lv_clear_tmc_step_mode_settings(); - lv_draw_tmc_step_mode_settings(); - } + case ID_TMC_MODE_UP: + uiCfg.para_ui_page = 0; + lv_clear_tmc_step_mode_settings(); + lv_draw_tmc_step_mode_settings(); break; case ID_TMC_MODE_DOWN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.para_ui_page = 1; - lv_clear_tmc_step_mode_settings(); - lv_draw_tmc_step_mode_settings(); - } + uiCfg.para_ui_page = 1; + lv_clear_tmc_step_mode_settings(); + lv_draw_tmc_step_mode_settings(); break; } } void lv_draw_tmc_step_mode_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL; - lv_obj_t *buttonXText = NULL, *labelXText = NULL; - lv_obj_t *buttonYText = NULL, *labelYText = NULL; - lv_obj_t *buttonZText = NULL, *labelZText = NULL; - lv_obj_t *buttonE0Text = NULL, *labelE0Text = NULL; + buttonXState = buttonYState = buttonZState = buttonE0State = buttonE1State = nullptr; - lv_obj_t * line1 = NULL, * line2 = NULL, * line3 = NULL, * line4 = NULL; - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_obj_t *buttonTurnPage = NULL, *labelTurnPage = NULL; - lv_obj_t *buttonE1Text = NULL, *labelE1Text = NULL; - //#endif + scr = lv_screen_create(TMC_MODE_UI, machine_menu.TmcStepModeConfTitle); - labelXState = NULL; - buttonXState = NULL; - labelYState = NULL; - buttonYState = NULL; - labelZState = NULL; - buttonZState = NULL; - labelE0State = NULL; - buttonE0State = NULL; - //#if AXIS_HAS_STEALTHCHOP(E1) - labelE1State = NULL; - buttonE1State = NULL; - //#endif - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TMC_MODE_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = TMC_MODE_UI; - } - disp_state = TMC_MODE_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, machine_menu.TmcStepModeConfTitle); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - if (uiCfg.para_ui_page != 1) { - buttonXText = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonXText, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonXText, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb(buttonXText, event_handler); - lv_btn_set_style(buttonXText, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonXText, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonXText, LV_LAYOUT_OFF); - labelXText = lv_label_create(buttonXText, NULL); /*Add a label to the button*/ - - buttonXState = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonXState, PARA_UI_STATE_POS_X, PARA_UI_POS_Y + PARA_UI_STATE_V); - #if AXIS_HAS_STEALTHCHOP(X) - if (stepperX.get_stealthChop_status()) { - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - } - else { - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - } - #else - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonXState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - #endif - lv_obj_set_event_cb_mks(buttonXState, event_handler, ID_TMC_MODE_X, NULL, 0); - - lv_imgbtn_set_style(buttonXState, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonXState, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonXState, LV_LAYOUT_OFF); - labelXState = lv_label_create(buttonXState, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonXState); - #endif - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonYText = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonYText, PARA_UI_POS_X, PARA_UI_POS_Y * 2); /*Set its position*/ - lv_obj_set_size(buttonYText, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb(buttonYText, event_handler); - lv_btn_set_style(buttonYText, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonYText, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonYText, LV_LAYOUT_OFF); - labelYText = lv_label_create(buttonYText, NULL); /*Add a label to the button*/ - - buttonYState = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonYState, PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_STATE_V); - #if AXIS_HAS_STEALTHCHOP(Y) - if (stepperY.get_stealthChop_status()) { - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - } - else { - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - } - #else - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonYState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - #endif - lv_obj_set_event_cb_mks(buttonYState, event_handler, ID_TMC_MODE_Y, NULL, 0); - - lv_imgbtn_set_style(buttonYState, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonYState, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonYState, LV_LAYOUT_OFF); - labelYState = lv_label_create(buttonYState, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonYState); - #endif - - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2, line_points[1]); - - buttonZText = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonZText, PARA_UI_POS_X, PARA_UI_POS_Y * 3); /*Set its position*/ - lv_obj_set_size(buttonZText, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb(buttonZText, event_handler); - lv_btn_set_style(buttonZText, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonZText, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonZText, LV_LAYOUT_OFF); - labelZText = lv_label_create(buttonZText, NULL); /*Add a label to the button*/ - - buttonZState = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonZState, PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_STATE_V); - #if AXIS_HAS_STEALTHCHOP(Z) - if (stepperZ.get_stealthChop_status()) { - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - } - else { - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - } - #else - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonZState, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - #endif - lv_obj_set_event_cb_mks(buttonZState, event_handler, ID_TMC_MODE_Z, NULL, 0); - lv_imgbtn_set_style(buttonZState, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonZState, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonZState, LV_LAYOUT_OFF); - labelZState = lv_label_create(buttonZState, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonZState); - #endif - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3, line_points[2]); - - buttonE0Text = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonE0Text, PARA_UI_POS_X, PARA_UI_POS_Y * 4); /*Set its position*/ - lv_obj_set_size(buttonE0Text, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb(buttonE0Text, event_handler); - lv_btn_set_style(buttonE0Text, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonE0Text, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonE0Text, LV_LAYOUT_OFF); - labelE0Text = lv_label_create(buttonE0Text, NULL); /*Add a label to the button*/ - - buttonE0State = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonE0State, PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_STATE_V); - #if AXIS_HAS_STEALTHCHOP(E0) - if (stepperE0.get_stealthChop_status()) { - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - } - else { - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - } - #else - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonE0State, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - #endif - - lv_obj_set_event_cb_mks(buttonE0State, event_handler, ID_TMC_MODE_E0, NULL, 0); - - lv_imgbtn_set_style(buttonE0State, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonE0State, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonE0State, LV_LAYOUT_OFF); - labelE0State = lv_label_create(buttonE0State, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonE0State); - #endif - - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4, line_points[3]); - - //#if AXIS_HAS_STEALTHCHOP(E1) - buttonTurnPage = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_MODE_DOWN, NULL, 0); - lv_imgbtn_set_src(buttonTurnPage, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonTurnPage, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonTurnPage, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonTurnPage, LV_BTN_STATE_REL, &tft_style_label_rel); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonTurnPage); - #endif - //#endif - } - else { - //#if AXIS_HAS_STEALTHCHOP(E1) - buttonE1Text = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonE1Text, PARA_UI_POS_X, PARA_UI_POS_Y); /*Set its position*/ - lv_obj_set_size(buttonE1Text, PARA_UI_VALUE_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ - lv_obj_set_event_cb(buttonE1Text, event_handler); - lv_btn_set_style(buttonE1Text, LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonE1Text, LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonE1Text, LV_LAYOUT_OFF); - labelE1Text = lv_label_create(buttonE1Text, NULL); /*Add a label to the button*/ - - buttonE1State = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonE1State, PARA_UI_STATE_POS_X, PARA_UI_POS_Y + PARA_UI_STATE_V); - #if AXIS_HAS_STEALTHCHOP(E1) - if (stepperE1.get_stealthChop_status()) { - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - } - else { - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - } - #else - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonE1State, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - #endif - lv_obj_set_event_cb_mks(buttonE1State, event_handler, ID_TMC_MODE_E1, NULL, 0); - lv_imgbtn_set_style(buttonE1State, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonE1State, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonE1State, LV_LAYOUT_OFF); - labelE1State = lv_label_create(buttonE1State, NULL); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonE1State); - #endif - - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1, line_points[0]); - - buttonTurnPage = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonTurnPage, event_handler, ID_TMC_MODE_UP, NULL, 0); - lv_imgbtn_set_src(buttonTurnPage, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonTurnPage, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonTurnPage, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonTurnPage, LV_BTN_STATE_REL, &tft_style_label_rel); - //#endif - } - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_obj_set_pos(buttonTurnPage, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_btn_set_layout(buttonTurnPage, LV_LAYOUT_OFF); - labelTurnPage = lv_label_create(buttonTurnPage, NULL); - //#endif - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_TMC_MODE_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); + bool stealth_X = false, stealth_Y = false, stealth_Z = false, stealth_E0 = false, stealth_E1 = false; + #if AXIS_HAS_STEALTHCHOP(X) + stealth_X = stepperX.get_stealthChop(); + #endif + #if AXIS_HAS_STEALTHCHOP(Y) + stealth_Y = stepperY.get_stealthChop(); + #endif + #if AXIS_HAS_STEALTHCHOP(Z) + stealth_Z = stepperZ.get_stealthChop(); + #endif + #if AXIS_HAS_STEALTHCHOP(E0) + stealth_E0 = stepperE0.get_stealthChop(); + #endif + #if AXIS_HAS_STEALTHCHOP(E1) + stealth_E1 = stepperE1.get_stealthChop(); #endif - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - if (uiCfg.para_ui_page != 1) { - lv_label_set_text(labelXText, machine_menu.X_StepMode); - lv_obj_align(labelXText, buttonXText, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelYText, machine_menu.Y_StepMode); - lv_obj_align(labelYText, buttonYText, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelZText, machine_menu.Z_StepMode); - lv_obj_align(labelZText, buttonZText, LV_ALIGN_IN_LEFT_MID, 0, 0); - - lv_label_set_text(labelE0Text, machine_menu.E0_StepMode); - lv_obj_align(labelE0Text, buttonE0Text, LV_ALIGN_IN_LEFT_MID, 0, 0); - - #if AXIS_HAS_STEALTHCHOP(X) - if (stepperX.get_stealthChop_status()) - lv_label_set_text(labelXState, machine_menu.enable); - else - lv_label_set_text(labelXState, machine_menu.disable); - #else - lv_label_set_text(labelXState, machine_menu.disable); - #endif - lv_obj_align(labelXState, buttonXState, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_HAS_STEALTHCHOP(Y) - if (stepperY.get_stealthChop_status()) - lv_label_set_text(labelYState, machine_menu.enable); - else - lv_label_set_text(labelYState, machine_menu.disable); - #else - lv_label_set_text(labelYState, machine_menu.disable); - #endif - lv_obj_align(labelYState, buttonYState, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_HAS_STEALTHCHOP(Z) - if (stepperZ.get_stealthChop_status()) - lv_label_set_text(labelZState, machine_menu.enable); - else - lv_label_set_text(labelZState, machine_menu.disable); - #else - lv_label_set_text(labelZState, machine_menu.disable); - #endif - lv_obj_align(labelZState, buttonZState, LV_ALIGN_CENTER, 0, 0); - - #if AXIS_HAS_STEALTHCHOP(E0) - if (stepperE0.get_stealthChop_status()) - lv_label_set_text(labelE0State, machine_menu.enable); - else - lv_label_set_text(labelE0State, machine_menu.disable); - #else - lv_label_set_text(labelE0State, machine_menu.disable); - #endif - lv_obj_align(labelE0State, buttonE0State, LV_ALIGN_CENTER, 0, 0); - - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_label_set_text(labelTurnPage, machine_menu.next); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - //#endif - } - else { - //#if AXIS_HAS_STEALTHCHOP(E1) - lv_label_set_text(labelE1Text, machine_menu.E1_StepMode); - lv_obj_align(labelE1Text, buttonE1Text, LV_ALIGN_IN_LEFT_MID, 0, 0); - #if AXIS_HAS_STEALTHCHOP(E1) - if (stepperE1.get_stealthChop_status()) - lv_label_set_text(labelE1State, machine_menu.enable); - else - lv_label_set_text(labelE1State, machine_menu.disable); - #else - lv_label_set_text(labelE1State, machine_menu.disable); - #endif - lv_obj_align(labelE1State, buttonE1State, LV_ALIGN_CENTER, 0, 0); - - lv_label_set_text(labelTurnPage, machine_menu.previous); - lv_obj_align(labelTurnPage, buttonTurnPage, LV_ALIGN_CENTER, 0, 0); - //#endif - } - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); + if (uiCfg.para_ui_page != 1) { + buttonXState = lv_screen_menu_item_onoff(scr, machine_menu.X_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_MODE_X, 0, stealth_X); + buttonYState = lv_screen_menu_item_onoff(scr, machine_menu.Y_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 2, event_handler, ID_TMC_MODE_Y, 1, stealth_Y); + buttonZState = lv_screen_menu_item_onoff(scr, machine_menu.Z_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 3, event_handler, ID_TMC_MODE_Z, 2, stealth_Z); + buttonE0State = lv_screen_menu_item_onoff(scr, machine_menu.E0_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y * 4, event_handler, ID_TMC_MODE_E0, 2, stealth_E0); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.next, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_MODE_DOWN, true); } + else { + buttonE1State = lv_screen_menu_item_onoff(scr, machine_menu.E1_StepMode, PARA_UI_POS_X, PARA_UI_POS_Y, event_handler, ID_TMC_MODE_E1, 0, stealth_E1); + lv_big_button_create(scr, "F:/bmp_back70x40.bin", machine_menu.previous, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_TMC_MODE_UP, true); + } + + lv_big_button_create(scr, "F:/bmp_back70x40.bin", common_menu.text_back, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_TMC_MODE_RETURN, true); } void lv_clear_tmc_step_mode_settings() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp index b6ef6e64da..3a9d78741a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_tool.cpp @@ -34,244 +34,79 @@ #include "../../../../module/temperature.h" #include "../../../../inc/MarlinConfig.h" -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; -#define ID_T_PRE_HEAT 1 -#define ID_T_EXTRUCT 2 -#define ID_T_MOV 3 -#define ID_T_HOME 4 -#define ID_T_LEVELING 5 -#define ID_T_FILAMENT 6 -#define ID_T_MORE 7 -#define ID_T_RETURN 8 +enum { + ID_T_PRE_HEAT = 1, + ID_T_EXTRUCT, + ID_T_MOV, + ID_T_HOME, + ID_T_LEVELING, + ID_T_FILAMENT, + ID_T_MORE, + ID_T_RETURN +}; #if ENABLED(MKS_TEST) extern uint8_t curent_disp_ui; #endif -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_T_PRE_HEAT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_preHeat(); - } + lv_clear_tool(); + lv_draw_preHeat(); break; case ID_T_EXTRUCT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_extrusion(); - } + lv_clear_tool(); + lv_draw_extrusion(); break; case ID_T_MOV: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_move_motor(); - } + lv_clear_tool(); + lv_draw_move_motor(); break; case ID_T_HOME: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_tool(); - lv_draw_home(); - } + lv_clear_tool(); + lv_draw_home(); break; case ID_T_LEVELING: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - #if ENABLED(AUTO_BED_LEVELING_BILINEAR) - //queue.enqueue_one_P(PSTR("G28")); - //queue.enqueue_one_P(PSTR("G29")); - get_gcode_command(AUTO_LEVELING_COMMAND_ADDR,(uint8_t *)public_buf_m); - public_buf_m[sizeof(public_buf_m)-1] = 0; - queue.inject_P(PSTR(public_buf_m)); - #else - uiCfg.leveling_first_time = 1; - lv_clear_tool(); - lv_draw_manualLevel(); - #endif - } + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + //queue.enqueue_one_P(PSTR("G28")); + //queue.enqueue_one_P(PSTR("G29")); + get_gcode_command(AUTO_LEVELING_COMMAND_ADDR,(uint8_t *)public_buf_m); + public_buf_m[sizeof(public_buf_m)-1] = 0; + queue.inject_P(PSTR(public_buf_m)); + #else + uiCfg.leveling_first_time = 1; + lv_clear_tool(); + lv_draw_manualLevel(); + #endif break; case ID_T_FILAMENT: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[uiCfg.curSprayerChoose].target; - lv_clear_tool(); - lv_draw_filament_change(); - } + uiCfg.desireSprayerTempBak = thermalManager.temp_hotend[uiCfg.curSprayerChoose].target; + lv_clear_tool(); + lv_draw_filament_change(); break; case ID_T_MORE: break; case ID_T_RETURN: - if (event == LV_EVENT_CLICKED) { - // nothing to do - } - else if (event == LV_EVENT_RELEASED) { - TERN_(MKS_TEST, curent_disp_ui = 1); - lv_clear_tool(); - lv_draw_ready_print(); - } + TERN_(MKS_TEST, curent_disp_ui = 1); + lv_clear_tool(); + lv_draw_ready_print(); break; } } void lv_draw_tool(void) { - lv_obj_t *buttonPreHeat, *buttonExtrusion, *buttonMove, *buttonHome, *buttonLevel; - lv_obj_t *buttonFilament; - lv_obj_t *buttonBack; - - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != TOOL_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = TOOL_UI; - } - disp_state = TOOL_UI; - - scr = lv_obj_create(NULL, NULL); - - //static lv_style_t tool_style; - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - // Create image buttons - buttonPreHeat = lv_imgbtn_create(scr, NULL); - buttonExtrusion = lv_imgbtn_create(scr, NULL); - buttonMove = lv_imgbtn_create(scr, NULL); - buttonHome = lv_imgbtn_create(scr, NULL); - buttonLevel = lv_imgbtn_create(scr, NULL); - buttonFilament = lv_imgbtn_create(scr, NULL); - //buttonMore = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonPreHeat, event_handler, ID_T_PRE_HEAT, NULL, 0); - lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_REL, "F:/bmp_preHeat.bin"); - lv_imgbtn_set_src(buttonPreHeat, LV_BTN_STATE_PR, "F:/bmp_preHeat.bin"); - lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonPreHeat, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonExtrusion, event_handler, ID_T_EXTRUCT, NULL, 0); - lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_REL, "F:/bmp_extruct.bin"); - lv_imgbtn_set_src(buttonExtrusion, LV_BTN_STATE_PR, "F:/bmp_extruct.bin"); - lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonExtrusion, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonMove, event_handler, ID_T_MOV, NULL, 0); - lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_REL, "F:/bmp_mov.bin"); - lv_imgbtn_set_src(buttonMove, LV_BTN_STATE_PR, "F:/bmp_mov.bin"); - lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonMove, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonHome, event_handler, ID_T_HOME, NULL, 0); - lv_imgbtn_set_src(buttonHome, LV_BTN_STATE_REL, "F:/bmp_zero.bin"); - lv_imgbtn_set_src(buttonHome, LV_BTN_STATE_PR, "F:/bmp_zero.bin"); - lv_imgbtn_set_style(buttonHome, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonHome, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonLevel, event_handler, ID_T_LEVELING, NULL, 0); - lv_imgbtn_set_src(buttonLevel, LV_BTN_STATE_REL, "F:/bmp_leveling.bin"); - lv_imgbtn_set_src(buttonLevel, LV_BTN_STATE_PR, "F:/bmp_leveling.bin"); - lv_imgbtn_set_style(buttonLevel, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonLevel, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonFilament, event_handler,ID_T_FILAMENT,NULL,0); - lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_REL, "F:/bmp_filamentchange.bin"); - lv_imgbtn_set_src(buttonFilament, LV_BTN_STATE_PR, "F:/bmp_filamentchange.bin"); - lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonFilament, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_T_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_pos(buttonPreHeat, INTERVAL_V, titleHeight); - lv_obj_set_pos(buttonExtrusion, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight); - lv_obj_set_pos(buttonMove, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight); - lv_obj_set_pos(buttonHome, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight); - lv_obj_set_pos(buttonLevel, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - lv_obj_set_pos(buttonFilament,BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight); - //lv_obj_set_pos(buttonMore,BTN_X_PIXEL*2+INTERVAL_V*3, BTN_Y_PIXEL+INTERVAL_H+titleHeight); - lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight); - - // Create labels on the image buttons - lv_btn_set_layout(buttonPreHeat, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonExtrusion, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonMove, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonHome, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonLevel, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonFilament, LV_LAYOUT_OFF); - //lv_btn_set_layout(buttonMore, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - - lv_obj_t *labelPreHeat = lv_label_create(buttonPreHeat, NULL); - lv_obj_t *labelExtrusion = lv_label_create(buttonExtrusion, NULL); - lv_obj_t *label_Move = lv_label_create(buttonMove, NULL); - lv_obj_t *label_Home = lv_label_create(buttonHome, NULL); - lv_obj_t *label_Level = lv_label_create(buttonLevel, NULL); - lv_obj_t *label_Filament = lv_label_create(buttonFilament, NULL); - //lv_obj_t *label_More = lv_label_create(buttonMore, NULL); - lv_obj_t *label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.multiple_language) { - lv_label_set_text(labelPreHeat, tool_menu.preheat); - lv_obj_align(labelPreHeat, buttonPreHeat, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(labelExtrusion, tool_menu.extrude); - lv_obj_align(labelExtrusion, buttonExtrusion, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Move, tool_menu.move); - lv_obj_align(label_Move, buttonMove, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Home, tool_menu.home); - lv_obj_align(label_Home, buttonHome, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Level, tool_menu.TERN(AUTO_BED_LEVELING_BILINEAR, autoleveling, leveling)); - lv_obj_align(label_Level, buttonLevel, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Filament, tool_menu.filament); - lv_obj_align(label_Filament, buttonFilament, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - //lv_label_set_text(label_More, tool_menu.more); - //lv_obj_align(label_More, buttonMore, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - - lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); - } - #if HAS_ROTARY_ENCODER - if (gCfgItems.encoder_enable) { - lv_group_add_obj(g, buttonPreHeat); - lv_group_add_obj(g, buttonExtrusion); - lv_group_add_obj(g, buttonMove); - lv_group_add_obj(g, buttonHome); - lv_group_add_obj(g, buttonLevel); - lv_group_add_obj(g, buttonFilament); - lv_group_add_obj(g, buttonBack); - } - #endif + scr = lv_screen_create(TOOL_UI); + lv_big_button_create(scr, "F:/bmp_preHeat.bin", tool_menu.preheat, INTERVAL_V, titleHeight, event_handler, ID_T_PRE_HEAT); + lv_big_button_create(scr, "F:/bmp_extruct.bin", tool_menu.extrude, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_EXTRUCT); + lv_big_button_create(scr, "F:/bmp_mov.bin", tool_menu.move, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_T_MOV); + lv_big_button_create(scr, "F:/bmp_zero.bin", tool_menu.home, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_T_HOME); + lv_big_button_create(scr, "F:/bmp_leveling.bin", tool_menu.TERN(AUTO_BED_LEVELING_BILINEAR, autoleveling, leveling), INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_T_LEVELING); + lv_big_button_create(scr, "F:/bmp_filamentchange.bin", tool_menu.filament, BTN_X_PIXEL+INTERVAL_V*2,BTN_Y_PIXEL+INTERVAL_H+titleHeight, event_handler,ID_T_FILAMENT); + lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_T_RETURN); } void lv_clear_tool() { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp index 1f21136668..50c49999af 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -61,13 +61,14 @@ uint32_t To_pre_view; bool gcode_preview_over, flash_preview_begin, default_preview_flg; uint32_t size = 809; uint16_t row; -uint8_t temperature_change_frequency; +bool temps_update_flag; uint8_t printing_rate_update_flag; extern bool once_flag; extern uint8_t sel_id; extern uint8_t public_buf[512]; extern uint8_t bmp_public_buf[17 * 1024]; +extern lv_group_t *g; extern void LCD_IO_WriteData(uint16_t RegValue); @@ -282,6 +283,9 @@ lv_style_t style_para_back; lv_style_t lv_bar_style_indic; +lv_style_t style_btn_pr; +lv_style_t style_btn_rel; + void tft_style_init() { lv_style_copy(&tft_style_scr, &lv_style_scr); tft_style_scr.body.main_color = LV_COLOR_BACKGROUND; @@ -399,6 +403,25 @@ void tft_style_init() { style_para_back.text.color = LV_COLOR_WHITE; style_para_back.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); + lv_style_copy(&style_btn_rel, &lv_style_plain); + style_btn_rel.body.border.color = lv_color_hex3(0x269); + style_btn_rel.body.border.width = 1; + style_btn_rel.body.main_color = lv_color_hex3(0xADF); + style_btn_rel.body.grad_color = lv_color_hex3(0x46B); + style_btn_rel.body.shadow.width = 4; + style_btn_rel.body.shadow.type = LV_SHADOW_BOTTOM; + style_btn_rel.body.radius = LV_RADIUS_CIRCLE; + style_btn_rel.text.color = lv_color_hex3(0xDEF); + style_btn_rel.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); + + lv_style_copy(&style_btn_pr, &style_btn_rel); + style_btn_pr.body.border.color = lv_color_hex3(0x46B); + style_btn_pr.body.main_color = lv_color_hex3(0x8BD); + style_btn_pr.body.grad_color = lv_color_hex3(0x24A); + style_btn_pr.body.shadow.width = 2; + style_btn_pr.text.color = lv_color_hex3(0xBCD); + style_btn_pr.text.font = &TERN(HAS_SPI_FLASH_FONT, gb2312_puhui32, lv_font_roboto_22); + lv_style_copy(&lv_bar_style_indic, &lv_style_pretty_color); lv_bar_style_indic.text.color = lv_color_hex3(0xADF); lv_bar_style_indic.image.color = lv_color_hex3(0xADF); @@ -421,7 +444,6 @@ void titleText_cat(char *str, int strSize, char *addPart) { char *getDispText(int index) { - ZERO(public_buf_l); switch (disp_state_stack._disp_state[index]) { case PRINT_READY_UI: @@ -926,30 +948,30 @@ void print_time_run() { } void GUI_RefreshPage() { - if ((systick_uptime_millis % 1000) == 0) temperature_change_frequency = 1; - if ((systick_uptime_millis % 3000) == 0) printing_rate_update_flag = 1; + if ((systick_uptime_millis % 1000) == 0) temps_update_flag = true; + if ((systick_uptime_millis % 3000) == 0) printing_rate_update_flag = true; switch (disp_state) { case MAIN_UI: //lv_draw_ready_print(); break; case EXTRUSION_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_hotend_temp(); } break; case PRE_HEAT_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_desire_temp(); } break; case PRINT_READY_UI: /* if (gCfgItems.display_style == 2) { - if (temperature_change_frequency) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_restro_state(); } } @@ -959,8 +981,8 @@ void GUI_RefreshPage() { case PRINT_FILE_UI: break; case PRINTING_UI: - if (temperature_change_frequency) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_ext_temp(); disp_bed_temp(); disp_fan_speed(); @@ -968,15 +990,15 @@ void GUI_RefreshPage() { disp_fan_Zpos(); } if (printing_rate_update_flag || marlin_state == MF_SD_COMPLETE) { - printing_rate_update_flag = 0; + printing_rate_update_flag = false; if (!gcode_preview_over) setProBarRate(); } break; case OPERATE_UI: /* - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_temp_operate(); } @@ -986,16 +1008,16 @@ void GUI_RefreshPage() { case PAUSE_UI: /* - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_temp_pause(); } */ break; case FAN_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_fan_value(); } break; @@ -1003,14 +1025,12 @@ void GUI_RefreshPage() { case MOVE_MOTOR_UI: /* if (mksReprint.mks_printer_state == MKS_IDLE) { - if ((z_high_count==1)&&(temper_error_flg != 1)) { + if (z_high_count == 1 && temper_error_flg != 1) { z_high_count = 0; - { - memset((char *)gCfgItems.move_z_coordinate, ' ', sizeof(gCfgItems.move_z_coordinate)); - GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); - sprintf_P((char *)gCfgItems.move_z_coordinate, PSTR("Z: %.3f"), current_position[Z_AXIS]); - GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); - } + memset((char *)gCfgItems.move_z_coordinate, ' ', sizeof(gCfgItems.move_z_coordinate)); + GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); + sprintf_P((char *)gCfgItems.move_z_coordinate, PSTR("Z: %.3f"), current_position[Z_AXIS]); + GUI_DispStringAt((const char *)gCfgItems.move_z_coordinate, 380, TITLE_YPOS); } } */ @@ -1018,9 +1038,9 @@ void GUI_RefreshPage() { #if ENABLED(USE_WIFI_FUNCTION) case WIFI_UI: - if (temperature_change_frequency == 1) { + if (temps_update_flag) { disp_wifi_state(); - temperature_change_frequency = 0; + temps_update_flag = false; } break; #endif @@ -1030,8 +1050,8 @@ void GUI_RefreshPage() { break; case FILAMENTCHANGE_UI: - if (temperature_change_frequency) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_filament_temp(); } break; @@ -1046,9 +1066,9 @@ void GUI_RefreshPage() { break; case WIFI_LIST_UI: #if ENABLED(USE_WIFI_FUNCTION) - if (printing_rate_update_flag == 1) { + if (printing_rate_update_flag) { disp_wifi_list(); - printing_rate_update_flag = 0; + printing_rate_update_flag = false; } #endif break; @@ -1103,8 +1123,8 @@ void GUI_RefreshPage() { #endif case BABY_STEP_UI: - if (temperature_change_frequency == 1) { - temperature_change_frequency = 0; + if (temps_update_flag) { + temps_update_flag = false; disp_z_offset_value(); } break; @@ -1577,6 +1597,253 @@ void draw_return_ui() { } } +// Set the same image for both Released and Pressed +void lv_imgbtn_set_src_both(lv_obj_t *imgbtn, const void *src) { + lv_imgbtn_set_src(imgbtn, LV_BTN_STATE_REL, src); + lv_imgbtn_set_src(imgbtn, LV_BTN_STATE_PR, src); +} + +// Use label style for the image button +void lv_imgbtn_use_label_style(lv_obj_t *imgbtn) { + lv_imgbtn_set_style(imgbtn, LV_BTN_STATE_REL, &tft_style_label_rel); + lv_imgbtn_set_style(imgbtn, LV_BTN_STATE_PR, &tft_style_label_pre); +} + +// Use label style for the button +void lv_btn_use_label_style(lv_obj_t *btn) { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &tft_style_label_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &tft_style_label_pre); +} + +// Use button style for the button +void lv_btn_use_button_style(lv_obj_t *btn) { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, &style_btn_rel); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &style_btn_pr); +} + +// Use a single style for both Released and Pressed +void lv_btn_set_style_both(lv_obj_t *btn, lv_style_t *style) { + lv_btn_set_style(btn, LV_BTN_STYLE_REL, style); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, style); +} + +// Create a screen +lv_obj_t* lv_screen_create(DISP_STATE newScreenType, const char* title) { + lv_obj_t *scr = lv_obj_create(nullptr, nullptr); + lv_obj_set_style(scr, &tft_style_scr); + lv_scr_load(scr); + lv_obj_clean(scr); + + // breadcrumbs + if (disp_state_stack._disp_state[disp_state_stack._disp_index] != newScreenType) { + disp_state_stack._disp_index++; + disp_state_stack._disp_state[disp_state_stack._disp_index] = newScreenType; + } + disp_state = newScreenType; + lv_refr_now(lv_refr_get_disp_refreshing()); + + // title + lv_obj_t *titleLabel = nullptr; + if (!title) + titleLabel = lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text()); + else if (title[0] != '\0') + titleLabel = lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, title); + if (titleLabel) + lv_obj_set_style(titleLabel, &tft_style_label_rel); + + return scr; +} + +// Create an empty label +lv_obj_t* lv_label_create_empty(lv_obj_t *par) { + return lv_label_create(par, (lv_obj_t*)nullptr); +} + +// Create a label with style and text +lv_obj_t* lv_label_create(lv_obj_t *par, const char *text) { + lv_obj_t *label = lv_label_create_empty(par); + if (text) lv_label_set_text(label, text); + return label; +} + +// Create a label with style, position, and text +lv_obj_t* lv_label_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, const char *text) { + lv_obj_t *label = lv_label_create(par, text); + lv_obj_set_pos(label, x, y); + return label; +} + +// Create a button with callback, ID, and Style. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/, lv_style_t *style/*=&style_para_value*/) { + lv_obj_t *btn = lv_btn_create(par, nullptr); + if (id) + lv_obj_set_event_cb_mks(btn, cb, id, nullptr, 0); + else + lv_obj_set_event_cb(btn, cb); + lv_btn_set_style_both(btn, style); + return btn; +} + +// Create a button with callback and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_btn_create(par, cb, id, nullptr); + lv_btn_use_label_style(btn); + return btn; +} + +// Create a button with callback and ID, with button style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_btn_create(par, cb, id, nullptr); + lv_btn_use_button_style(btn); + return btn; +} + +// Create a button with position, size, callback, ID, and style. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id, lv_style_t *style) { + lv_obj_t *btn = lv_btn_create(par, cb, id, style); + lv_obj_set_pos(btn, x, y); + lv_obj_set_size(btn, w, h); + return btn; +} + +// Create a button with position, size, callback, and ID. Style set to style_para_value. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_btn_create(par, x, y, w, h, cb, id, &style_para_value); + return btn; +} + +// Create a button with position, size, callback, and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_label_btn_create(par, cb, id); + lv_obj_set_pos(btn, x, y); + lv_obj_set_size(btn, w, h); + return btn; +} + +// Create a button with position, size, callback, and ID, with label style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_button_btn_create(par, cb, id); + lv_obj_set_pos(btn, x, y); + lv_obj_set_size(btn, w, h); + return btn; +} + +// Create a button with callback and ID. Style set to style_para_back. +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_event_cb_t cb, const int id/*=0*/) { + return lv_btn_create(par, cb, id, &style_para_back); +} +// Create a button with position, size, callback, and ID. Style set to style_para_back. +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_btn_create_back(par, cb, id); + lv_obj_set_pos(btn, x, y); + lv_obj_set_size(btn, w, h); + return btn; +} + +// Create an image button with image, callback, and ID. Use label style. +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_imgbtn_create(par, nullptr); + if (img) lv_imgbtn_set_src_both(btn, img); + if (id) + lv_obj_set_event_cb_mks(btn, cb, id, nullptr, 0); + else + lv_obj_set_event_cb(btn, cb); + lv_imgbtn_use_label_style(btn); + lv_btn_set_layout(btn, LV_LAYOUT_OFF); + return btn; +} + +// Create an image button with image, position, callback, and ID. Use label style. +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id/*=0*/) { + lv_obj_t *btn = lv_imgbtn_create(par, img, cb, id); + lv_obj_set_pos(btn, x, y); + return btn; +} + +lv_obj_t* lv_big_button_create(lv_obj_t *par, const char *img, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, bool centerLabel) { + lv_obj_t *btn = lv_imgbtn_create(par, img, cb, id); + lv_obj_set_pos(btn, x, y); + lv_obj_t *label = lv_label_create_empty(btn); + if (gCfgItems.multiple_language) { + lv_label_set_text(label, text); + if (centerLabel) + lv_obj_align(label, btn, LV_ALIGN_CENTER, 0, 0); + else + lv_obj_align(label, btn, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); + } + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable == true) + lv_group_add_obj(g, btn); + #endif + return btn; +} + +lv_obj_t* lv_screen_menu_item(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, bool drawArrow) { + lv_obj_t *btn = lv_btn_create(par, nullptr); /*Add a button the current screen*/ + lv_obj_set_pos(btn, x, y); /*Set its position*/ + lv_obj_set_size(btn, PARA_UI_SIZE_X, PARA_UI_SIZE_Y); /*Set its size*/ + if (id > -1) lv_obj_set_event_cb_mks(btn, cb, id, nullptr, 0); + lv_btn_use_label_style(btn); + lv_btn_set_layout(btn, LV_LAYOUT_OFF); + lv_obj_t *label = lv_label_create_empty(btn); /*Add a label to the button*/ + if (gCfgItems.multiple_language) { + lv_label_set_text(label, text); + lv_obj_align(label, btn, LV_ALIGN_IN_LEFT_MID, 0, 0); + } + #if HAS_ROTARY_ENCODER + if (gCfgItems.encoder_enable == true) { + lv_group_add_obj(g, btn); + } + #endif + + if (drawArrow) (void)lv_imgbtn_create(par, "F:/bmp_arrow.bin", x + PARA_UI_SIZE_X, y + PARA_UI_ARROW_V, cb, id); + + lv_obj_t *line1 = lv_line_create(par, nullptr); + lv_ex_line(line1, line_points[index]); + + return btn; +} + +lv_obj_t* lv_screen_menu_item_1_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue) { + lv_obj_t* btn = lv_screen_menu_item(par, text, x, y, cb, -1, index, false); + lv_obj_t* btnValue = lv_btn_create(par, PARA_UI_VALUE_POS_X, y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, cb, id); + lv_obj_t* labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, editValue); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + return btn; +} + +lv_obj_t* lv_screen_menu_item_2_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue, const int idEdit2, const char *editValue2) { + lv_obj_t* btn = lv_screen_menu_item(par, text, x, y, cb, -1, index, false); + + lv_obj_t* btnValue = lv_btn_create(par, PARA_UI_VALUE_POS_X_2, y + PARA_UI_VALUE_V_2, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, cb, idEdit2); + lv_obj_t* labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, editValue2); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + + btnValue = lv_btn_create(par, PARA_UI_VALUE_POS_X, y + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, cb, id); + labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, editValue); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + + return btn; +} + +lv_obj_t* lv_screen_menu_item_onoff(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const bool curValue) { + lv_screen_menu_item(par, text, x, y, cb, -1, index, false); + lv_obj_t* btnValue = lv_imgbtn_create(par, curValue ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, y + PARA_UI_STATE_V, cb, id); + lv_obj_t* labelValue = lv_label_create_empty(btnValue); + lv_label_set_text(labelValue, curValue ? machine_menu.enable : machine_menu.disable); + lv_obj_align(labelValue, btnValue, LV_ALIGN_CENTER, 0, 0); + return btnValue; +} + +void lv_screen_menu_item_onoff_update(lv_obj_t *btn, const bool curValue) { + lv_imgbtn_set_src_both(btn, curValue ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin"); + lv_label_set_text((lv_obj_t*)btn->child_ll.head, curValue ? machine_menu.enable : machine_menu.disable); +} + + #if ENABLED(SDSUPPORT) void sd_detection() { @@ -1590,11 +1857,11 @@ void draw_return_ui() { #endif -void lv_ex_line(lv_obj_t * line, lv_point_t *points) { +void lv_ex_line(lv_obj_t *line, lv_point_t *points) { // Copy the previous line and apply the new style lv_line_set_points(line, points, 2); // Set the points lv_line_set_style(line, LV_LINE_STYLE_MAIN, &style_line); - lv_obj_align(line, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); + lv_obj_align(line, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0); } extern volatile uint32_t systick_uptime_millis; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h index 00faedac4e..3e3a4073d3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h @@ -198,10 +198,10 @@ typedef struct { } CFG_ITMES; typedef struct { - uint8_t curTempType : 1, - curSprayerChoose : 3, - stepHeat : 4; - uint8_t leveling_first_time : 1, + uint8_t curTempType:1, + curSprayerChoose:3, + stepHeat:4; + uint8_t leveling_first_time:1, para_ui_page:1, configWifi:1, command_send:1, @@ -425,6 +425,8 @@ extern lv_style_t style_sel_text; extern lv_style_t style_para_value; extern lv_style_t style_para_back; extern lv_style_t lv_bar_style_indic; +extern lv_style_t style_btn_pr; +extern lv_style_t style_btn_rel; extern lv_point_t line_points[4][2]; @@ -447,8 +449,78 @@ extern void gCfg_to_spiFlah(); extern void print_time_count(); extern void LV_TASK_HANDLER(); -extern void lv_ex_line(lv_obj_t * line, lv_point_t *points); +extern void lv_ex_line(lv_obj_t *line, lv_point_t *points); #ifdef __cplusplus } /* C-declarations for C++ */ #endif + +// Set the same image for both Released and Pressed +void lv_imgbtn_set_src_both(lv_obj_t *imgbtn, const void *src); + +// Set label styles for Released and Pressed +void lv_imgbtn_use_label_style(lv_obj_t *imgbtn); + +// Set label styles for Released and Pressed +void lv_btn_use_label_style(lv_obj_t *btn); + +// Set the same style for both Released and Pressed +void lv_btn_set_style_both(lv_obj_t *btn, lv_style_t *style); + +// Create a screen +lv_obj_t* lv_screen_create(DISP_STATE newScreenType, const char* title = nullptr); + +// Create an empty label +lv_obj_t* lv_label_create_empty(lv_obj_t *par); + +// Create a label with style and text +lv_obj_t* lv_label_create(lv_obj_t *par, const char *text); + +// Create a label with style, position, and text +lv_obj_t* lv_label_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, const char *text); + +// Create a button with callback, ID, and Style. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id, lv_style_t *style=&style_para_value); + +// Create a button with callback and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id=0); + +// Create a button with callback and ID, with button style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, ID, and style. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id, lv_style_t *style); + +// Create a button with position, size, callback, and ID. Style set to style_para_value. +lv_obj_t* lv_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, and ID, with label style. +lv_obj_t* lv_label_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, and ID, with button style. +lv_obj_t* lv_button_btn_create(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create a button with callback and ID. Style set to style_para_back. +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_event_cb_t cb, const int id=0); + +// Create a button with position, size, callback, and ID. Style set to style_para_back. +lv_obj_t* lv_btn_create_back(lv_obj_t *par, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, lv_event_cb_t cb, const int id=0); + +// Create an image button with image, callback, and ID. Use label style. +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_event_cb_t cb, const int id=0); + +// Create an image button with image, position, callback, and ID. Use label style. +lv_obj_t* lv_imgbtn_create(lv_obj_t *par, const char *img, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id=0); + +// Create a big image button with a label, follow the LVGL UI standard. +lv_obj_t* lv_big_button_create(lv_obj_t *par, const char *img, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, bool centerLabel = false); + +// Create a menu item, follow the LVGL UI standard. +lv_obj_t* lv_screen_menu_item(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, bool drawArrow = true); +lv_obj_t* lv_screen_menu_item_1_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue); +lv_obj_t* lv_screen_menu_item_2_edit(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const char *editValue, const int idEdit2, const char *editValue2); +lv_obj_t* lv_screen_menu_item_onoff(lv_obj_t *par, const char *text, lv_coord_t x, lv_coord_t y, lv_event_cb_t cb, const int id, const int index, const bool curValue); +void lv_screen_menu_item_onoff_update(lv_obj_t *btn, const bool curValue); + +#define _DIA_1(T) (uiCfg.dialogType == DIALOG_##T) +#define DIALOG_IS(V...) DO(DIA,||,V) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp index ce158ef7fb..313abd4545 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi.cpp @@ -30,171 +30,113 @@ #include "draw_ui.h" -extern lv_group_t * g; +extern lv_group_t *g; static lv_obj_t *scr, *wifi_name_text, *wifi_key_text, *wifi_state_text, *wifi_ip_text; -#define ID_W_RETURN 1 -#define ID_W_CLOUD 2 -#define ID_W_RECONNECT 3 +enum { + ID_W_RETURN = 1, + ID_W_CLOUD, + ID_W_RECONNECT +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_W_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - lv_draw_set(); - } - break; + clear_cur_ui(); + lv_draw_set(); + break; case ID_W_CLOUD: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - //clear_cur_ui(); - //draw_return_ui(); - } - break; + //clear_cur_ui(); + //draw_return_ui(); + break; case ID_W_RECONNECT: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - lv_draw_wifi_list(); - } - break; + clear_cur_ui(); + lv_draw_wifi_list(); + break; } } void lv_draw_wifi(void) { - lv_obj_t *buttonBack=NULL,*label_Back=NULL; - lv_obj_t *buttonCloud=NULL,*label_Cloud=NULL; - lv_obj_t *buttonReconnect=NULL,*label_Reconnect=NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_UI; - } - disp_state = WIFI_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); + scr = lv_screen_create(WIFI_UI); // Create an Image button - buttonBack = lv_imgbtn_create(scr, NULL); - if (gCfgItems.wifi_mode_sel == STA_MODEL) { - //buttonCloud = lv_imgbtn_create(scr, NULL); - buttonReconnect = lv_imgbtn_create(scr, NULL); - } - - lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_W_RETURN, NULL,0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); + lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_W_RETURN); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack); #endif + lv_obj_t *label_Back = lv_label_create_empty(buttonBack); - lv_obj_set_pos(buttonBack,BTN_X_PIXEL*3+INTERVAL_V*4, BTN_Y_PIXEL+INTERVAL_H+titleHeight); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); + lv_obj_t *buttonReconnect = nullptr, *label_Reconnect = nullptr; if (gCfgItems.wifi_mode_sel == STA_MODEL) { - lv_obj_set_event_cb_mks(buttonReconnect, event_handler,ID_W_RECONNECT, NULL,0); - lv_imgbtn_set_src(buttonReconnect, LV_BTN_STATE_REL, "F:/bmp_wifi.bin"); - lv_imgbtn_set_src(buttonReconnect, LV_BTN_STATE_PR, "F:/bmp_wifi.bin"); - lv_imgbtn_set_style(buttonReconnect, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonReconnect, LV_BTN_STATE_REL, &tft_style_label_rel); + buttonReconnect = lv_imgbtn_create(scr, nullptr); + + lv_obj_set_event_cb_mks(buttonReconnect, event_handler, ID_W_RECONNECT, nullptr, 0); + lv_imgbtn_set_src_both(buttonReconnect, "F:/bmp_wifi.bin"); + lv_imgbtn_use_label_style(buttonReconnect); #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonReconnect); #endif - lv_obj_set_pos(buttonReconnect,BTN_X_PIXEL*2+INTERVAL_V*3, BTN_Y_PIXEL+INTERVAL_H+titleHeight); + lv_obj_set_pos(buttonReconnect, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight); lv_btn_set_layout(buttonReconnect, LV_LAYOUT_OFF); - } - label_Back = lv_label_create(buttonBack, NULL); - - if (gCfgItems.wifi_mode_sel == STA_MODEL) { - //label_Cloud = lv_label_create(buttonCloud, NULL); - label_Reconnect = lv_label_create(buttonReconnect, NULL); + label_Reconnect = lv_label_create_empty(buttonReconnect); } if (gCfgItems.multiple_language) { lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); if (gCfgItems.wifi_mode_sel == STA_MODEL) { - //lv_label_set_text(label_Cloud, common_menu.text_back); - //lv_obj_align(label_Cloud, buttonCloud, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); - lv_label_set_text(label_Reconnect, wifi_menu.reconnect); - lv_obj_align(label_Reconnect, buttonReconnect, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET); + lv_obj_align(label_Reconnect, buttonReconnect, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET); } } - wifi_ip_text = lv_label_create(scr, NULL); + wifi_ip_text = lv_label_create_empty(scr); lv_obj_set_style(wifi_ip_text, &tft_style_label_rel); - - wifi_name_text = lv_label_create(scr, NULL); + wifi_name_text = lv_label_create_empty(scr); lv_obj_set_style(wifi_name_text, &tft_style_label_rel); - - wifi_key_text = lv_label_create(scr, NULL); + wifi_key_text = lv_label_create_empty(scr); lv_obj_set_style(wifi_key_text, &tft_style_label_rel); - - wifi_state_text = lv_label_create(scr, NULL); + wifi_state_text = lv_label_create_empty(scr); lv_obj_set_style(wifi_state_text, &tft_style_label_rel); disp_wifi_state(); } void disp_wifi_state() { - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.ip); - strcat(public_buf_m,ipPara.ip_addr); + strcpy(public_buf_m, wifi_menu.ip); + strcat(public_buf_m, ipPara.ip_addr); lv_label_set_text(wifi_ip_text, public_buf_m); - lv_obj_align(wifi_ip_text, NULL, LV_ALIGN_CENTER,0, -100); + lv_obj_align(wifi_ip_text, nullptr, LV_ALIGN_CENTER, 0, -100); - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.wifi); - strcat(public_buf_m,wifiPara.ap_name); + strcpy(public_buf_m, wifi_menu.wifi); + strcat(public_buf_m, wifiPara.ap_name); lv_label_set_text(wifi_name_text, public_buf_m); - lv_obj_align(wifi_name_text, NULL, LV_ALIGN_CENTER,0, -70); + lv_obj_align(wifi_name_text, nullptr, LV_ALIGN_CENTER, 0, -70); if (wifiPara.mode == AP_MODEL) { - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.key); - strcat(public_buf_m,wifiPara.keyCode); + strcpy(public_buf_m, wifi_menu.key); + strcat(public_buf_m, wifiPara.keyCode); lv_label_set_text(wifi_key_text, public_buf_m); - lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER,0, -40); + lv_obj_align(wifi_key_text, nullptr, LV_ALIGN_CENTER, 0, -40); - memset(public_buf_m, 0, sizeof(public_buf_m)); - strcpy(public_buf_m,wifi_menu.state_ap); + strcpy(public_buf_m, wifi_menu.state_ap); if (wifi_link_state == WIFI_CONNECTED) - strcat(public_buf_m,wifi_menu.connected); + strcat(public_buf_m, wifi_menu.connected); else if (wifi_link_state == WIFI_NOT_CONFIG) - strcat(public_buf_m,wifi_menu.disconnected); + strcat(public_buf_m, wifi_menu.disconnected); else - strcat(public_buf_m,wifi_menu.exception); + strcat(public_buf_m, wifi_menu.exception); lv_label_set_text(wifi_state_text, public_buf_m); - lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER,0, -10); + lv_obj_align(wifi_state_text, nullptr, LV_ALIGN_CENTER, 0, -10); } else { - ZERO(public_buf_m); strcpy(public_buf_m, wifi_menu.state_sta); if (wifi_link_state == WIFI_CONNECTED) strcat(public_buf_m, wifi_menu.connected); @@ -203,10 +145,10 @@ void disp_wifi_state() { else strcat(public_buf_m, wifi_menu.exception); lv_label_set_text(wifi_state_text, public_buf_m); - lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER,0, -40); + lv_obj_align(wifi_state_text, nullptr, LV_ALIGN_CENTER, 0, -40); lv_label_set_text(wifi_key_text, ""); - lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER,0, -10); + lv_obj_align(wifi_key_text, nullptr, LV_ALIGN_CENTER, 0, -10); } } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp index 2680194868..c826e36d42 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_list.cpp @@ -39,61 +39,48 @@ WIFI_LIST wifi_list; list_menu_def list_menu; -extern lv_group_t * g; -static lv_obj_t * scr; +extern lv_group_t *g; +static lv_obj_t *scr; static lv_obj_t *buttonWifiN[NUMBER_OF_PAGE]; -static lv_obj_t *lableWifiText[NUMBER_OF_PAGE]; -static lv_obj_t *lablePageText; +static lv_obj_t *labelWifiText[NUMBER_OF_PAGE]; +static lv_obj_t *labelPageText; -#define ID_WL_RETURN 11 -#define ID_WL_DOWN 12 +#define ID_WL_RETURN 11 +#define ID_WL_DOWN 12 + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; -static void event_handler(lv_obj_t * obj, lv_event_t event) { if (obj->mks_obj_id == ID_WL_RETURN) { - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - clear_cur_ui(); - lv_draw_set(); - } + clear_cur_ui(); + lv_draw_set(); } else if (obj->mks_obj_id == ID_WL_DOWN) { - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (wifi_list.getNameNum > 0) { - if ((wifi_list.nameIndex + NUMBER_OF_PAGE) >= wifi_list.getNameNum) { - wifi_list.nameIndex = 0; - wifi_list.currentWifipage = 1; - } - else { - wifi_list.nameIndex += NUMBER_OF_PAGE; - wifi_list.currentWifipage++; - } - disp_wifi_list(); + if (wifi_list.getNameNum > 0) { + if ((wifi_list.nameIndex + NUMBER_OF_PAGE) >= wifi_list.getNameNum) { + wifi_list.nameIndex = 0; + wifi_list.currentWifipage = 1; } + else { + wifi_list.nameIndex += NUMBER_OF_PAGE; + wifi_list.currentWifipage++; + } + disp_wifi_list(); } } else { for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) { if (obj->mks_obj_id == i + 1) { - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (wifi_list.getNameNum != 0) { - const bool do_wifi = wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[wifi_list.nameIndex + i]) == 0; - wifi_list.nameIndex += i; - last_disp_state = WIFI_LIST_UI; - lv_clear_wifi_list(); - if (do_wifi) - lv_draw_wifi(); - else { - keyboard_value = wifiConfig; - lv_draw_keyboard(); - } + if (wifi_list.getNameNum != 0) { + const bool do_wifi = wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[wifi_list.nameIndex + i]) == 0; + wifi_list.nameIndex += i; + last_disp_state = WIFI_LIST_UI; + lv_clear_wifi_list(); + if (do_wifi) + lv_draw_wifi(); + else { + keyboard_value = wifiConfig; + lv_draw_keyboard(); } } } @@ -102,57 +89,14 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { } void lv_draw_wifi_list(void) { - lv_obj_t *buttonBack = NULL, *buttonDown = NULL; + scr = lv_screen_create(WIFI_LIST_UI); - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_LIST_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_LIST_UI; - } - disp_state = WIFI_LIST_UI; - - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS); - lv_label_set_text(title, creat_title_text()); - - lv_refr_now(lv_refr_get_disp_refreshing()); - - buttonDown = lv_imgbtn_create(scr, NULL); - buttonBack = lv_imgbtn_create(scr, NULL); - - lv_obj_set_event_cb_mks(buttonDown, event_handler,ID_WL_DOWN,NULL,0); - lv_imgbtn_set_src(buttonDown, LV_BTN_STATE_REL, "F:/bmp_pageDown.bin"); - lv_imgbtn_set_src(buttonDown, LV_BTN_STATE_PR, "F:/bmp_pageDown.bin"); - lv_imgbtn_set_style(buttonDown, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonDown, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_WL_RETURN,NULL,0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - - lv_obj_set_pos(buttonDown,OTHER_BTN_XPIEL*3+INTERVAL_V*4,titleHeight+OTHER_BTN_YPIEL+INTERVAL_H); - lv_obj_set_pos(buttonBack,OTHER_BTN_XPIEL*3+INTERVAL_V*4,titleHeight+OTHER_BTN_YPIEL*2+INTERVAL_H*2); - - lv_btn_set_layout(buttonDown, LV_LAYOUT_OFF); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); + lv_obj_t *buttonDown = lv_imgbtn_create(scr, "F:/bmp_pageDown.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL + INTERVAL_H, event_handler, ID_WL_DOWN); + lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_back.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + (OTHER_BTN_YPIEL + INTERVAL_H) * 2, event_handler, ID_WL_RETURN); for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) { - buttonWifiN[i] = lv_btn_create(scr, NULL); /*Add a button the current screen*/ - lv_obj_set_pos(buttonWifiN[i], 0,NAME_BTN_Y*i+10+titleHeight); /*Set its position*/ - lv_obj_set_size(buttonWifiN[i], NAME_BTN_X,NAME_BTN_Y); /*Set its size*/ - lv_obj_set_event_cb_mks(buttonWifiN[i], event_handler,(i+1),NULL,0); - lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/ - lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/ - lv_btn_set_layout(buttonWifiN[i], LV_LAYOUT_OFF); - lableWifiText[i] = lv_label_create(buttonWifiN[i], NULL); + buttonWifiN[i] = lv_label_btn_create(scr, 0, NAME_BTN_Y * i + 10 + titleHeight, NAME_BTN_X, NAME_BTN_Y, event_handler, i + 1); + labelWifiText[i] = lv_label_create_empty(buttonWifiN[i]); #if HAS_ROTARY_ENCODER uint8_t j = 0; if (gCfgItems.encoder_enable) { @@ -162,16 +106,17 @@ void lv_draw_wifi_list(void) { #endif } - lablePageText = lv_label_create(scr, NULL); - lv_obj_set_style(lablePageText, &tft_style_label_rel); + labelPageText = lv_label_create_empty(scr); + lv_obj_set_style(labelPageText, &tft_style_label_rel); wifi_list.nameIndex = 0; wifi_list.currentWifipage = 1; if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode == STA_MODEL) { - memset(wifi_list.wifiConnectedName, 0, sizeof(&wifi_list.wifiConnectedName)); + ZERO(wifi_list.wifiConnectedName); memcpy(wifi_list.wifiConnectedName, wifiPara.ap_name, sizeof(wifi_list.wifiConnectedName)); } + #if HAS_ROTARY_ENCODER if (gCfgItems.encoder_enable) { lv_group_add_obj(g, buttonDown); @@ -187,33 +132,29 @@ void disp_wifi_list(void) { uint8_t i, j; sprintf((char *)tmpStr, list_menu.file_pages, wifi_list.currentWifipage, wifi_list.getPage); - lv_label_set_text(lablePageText, (const char *)tmpStr); - lv_obj_align(lablePageText, NULL, LV_ALIGN_CENTER, 50, -100); + lv_label_set_text(labelPageText, (const char *)tmpStr); + lv_obj_align(labelPageText, nullptr, LV_ALIGN_CENTER, 50, -100); for (i = 0; i < NUMBER_OF_PAGE; i++) { - memset(tmpStr, 0, sizeof(tmpStr)); + ZERO(tmpStr); j = wifi_list.nameIndex + i; if (j >= wifi_list.getNameNum) { - lv_label_set_text(lableWifiText[i], (const char *)tmpStr); - lv_obj_align(lableWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0); + lv_label_set_text(labelWifiText[i], (const char *)tmpStr); + lv_obj_align(labelWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0); } else { - lv_label_set_text(lableWifiText[i], (char const *)wifi_list.wifiName[j]); - lv_obj_align(lableWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0); + lv_label_set_text(labelWifiText[i], (char const *)wifi_list.wifiName[j]); + lv_obj_align(labelWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0); - if (wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[j]) == 0) { - lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, &style_sel_text); - } - else { - lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, &tft_style_label_rel); - } + const bool btext = (wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[j]) == 0); + lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, btext ? &style_sel_text : &tft_style_label_rel); } } } void wifi_scan_handle() { - if (uiCfg.dialogType != WIFI_ENABLE_TIPS || uiCfg.command_send != 1) return; + if (!DIALOG_IS(WIFI_ENABLE_TIPS) || uiCfg.command_send != 1) return; last_disp_state = DIALOG_UI; lv_clear_dialog(); if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode != AP_MODEL) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp index 81a5f5c3be..441720df82 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_settings.cpp @@ -30,248 +30,139 @@ #include "draw_ui.h" -extern lv_group_t * g; -static lv_obj_t *scr, *labelModelValue = NULL, *buttonModelValue = NULL, *labelCloudValue = NULL; +extern lv_group_t *g; +static lv_obj_t *scr, *labelModelValue = nullptr, *buttonModelValue = nullptr, *labelCloudValue = nullptr; -#define ID_WIFI_RETURN 1 -#define ID_WIFI_MODEL 2 -#define ID_WIFI_NAME 3 -#define ID_WIFI_PASSWORD 4 -#define ID_WIFI_CLOUD 5 -#define ID_WIFI_CONFIG 6 +enum { + ID_WIFI_RETURN = 1, + ID_WIFI_MODEL, + ID_WIFI_NAME, + ID_WIFI_PASSWORD, + ID_WIFI_CLOUD, + ID_WIFI_CONFIG +}; -static void event_handler(lv_obj_t * obj, lv_event_t event) { +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_WIFI_RETURN: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_wifi_settings(); - draw_return_ui(); - } - break; + lv_clear_wifi_settings(); + draw_return_ui(); + break; case ID_WIFI_MODEL: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (gCfgItems.wifi_mode_sel == AP_MODEL) { - gCfgItems.wifi_mode_sel = STA_MODEL; - lv_label_set_text(labelModelValue, WIFI_STA_TEXT); - lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER,0, 0); - update_spi_flash(); - } - else { - gCfgItems.wifi_mode_sel = AP_MODEL; - lv_label_set_text(labelModelValue, WIFI_AP_TEXT); - lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER,0, 0); - update_spi_flash(); - } - } - break; - case ID_WIFI_NAME: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - keyboard_value = wifiName; - lv_clear_wifi_settings(); - lv_draw_keyboard(); - } - break; - case ID_WIFI_PASSWORD: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - keyboard_value=wifiPassWord; - lv_clear_wifi_settings(); - lv_draw_keyboard(); - } - break; - case ID_WIFI_CLOUD: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - if (gCfgItems.cloud_enable) { - gCfgItems.cloud_enable = false; - lv_obj_set_event_cb_mks(obj, event_handler,ID_WIFI_CLOUD,"bmp_disable.bin",0); - lv_label_set_text(labelCloudValue, machine_menu.disable); + if (gCfgItems.wifi_mode_sel == AP_MODEL) { + gCfgItems.wifi_mode_sel = STA_MODEL; + lv_label_set_text(labelModelValue, WIFI_STA_TEXT); + lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); update_spi_flash(); } else { - gCfgItems.cloud_enable = true; - lv_obj_set_event_cb_mks(obj, event_handler,ID_WIFI_CLOUD,"bmp_enable.bin",0); - lv_label_set_text(labelCloudValue, machine_menu.enable); + gCfgItems.wifi_mode_sel = AP_MODEL; + lv_label_set_text(labelModelValue, WIFI_AP_TEXT); + lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); update_spi_flash(); } - } - break; + break; + case ID_WIFI_NAME: + keyboard_value = wifiName; + lv_clear_wifi_settings(); + lv_draw_keyboard(); + break; + case ID_WIFI_PASSWORD: + keyboard_value = wifiPassWord; + lv_clear_wifi_settings(); + lv_draw_keyboard(); + break; + case ID_WIFI_CLOUD: + if (gCfgItems.cloud_enable) { + gCfgItems.cloud_enable = false; + lv_obj_set_event_cb_mks(obj, event_handler, ID_WIFI_CLOUD, "bmp_disable.bin", 0); + lv_label_set_text(labelCloudValue, machine_menu.disable); + } + else { + gCfgItems.cloud_enable = true; + lv_obj_set_event_cb_mks(obj, event_handler, ID_WIFI_CLOUD, "bmp_enable.bin", 0); + lv_label_set_text(labelCloudValue, machine_menu.enable); + } + update_spi_flash(); + break; case ID_WIFI_CONFIG: - if (event == LV_EVENT_CLICKED) { - - } - else if (event == LV_EVENT_RELEASED) { - lv_clear_wifi_settings(); - lv_draw_dialog(DIALOG_WIFI_CONFIG_TIPS); - } - break; + lv_clear_wifi_settings(); + lv_draw_dialog(DIALOG_WIFI_CONFIG_TIPS); + break; } } void lv_draw_wifi_settings(void) { - lv_obj_t *buttonBack = NULL, *label_Back = NULL, *buttonConfig = NULL, *labelConfig = NULL; - lv_obj_t *labelModelText = NULL; - lv_obj_t *labelNameText = NULL, *buttonNameValue = NULL, *labelNameValue = NULL; - lv_obj_t *labelPassWordText = NULL, *buttonPassWordValue = NULL, *labelPassWordValue = NULL; - lv_obj_t *labelCloudText = NULL, *buttonCloudValue = NULL; - lv_obj_t * line1 = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_SETTINGS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_SETTINGS_UI; - } - disp_state = WIFI_SETTINGS_UI; + scr = lv_screen_create(WIFI_SETTINGS_UI, machine_menu.WifiConfTitle); - scr = lv_obj_create(NULL, NULL); + lv_obj_t *labelModelText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y + 10, machine_menu.wifiMode); - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); + lv_obj_t *buttonModelValue = lv_imgbtn_create(scr, "F:/bmp_blank_sel.bin", PARA_UI_VALUE_POS_X, PARA_UI_POS_Y + PARA_UI_VALUE_V, event_handler, ID_WIFI_MODEL); + lv_btn_set_style_both(buttonModelValue, &style_para_value_pre); + labelModelValue = lv_label_create_empty(buttonModelValue); - lv_obj_t * title = lv_label_create(scr, NULL); - lv_obj_set_style(title, &tft_style_label_rel); - lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS); - lv_label_set_text(title, machine_menu.WifiConfTitle); + lv_obj_t *line1 = lv_line_create(scr, nullptr); + lv_ex_line(line1, line_points[0]); - lv_refr_now(lv_refr_get_disp_refreshing()); + lv_obj_t *labelNameText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10, nullptr); + lv_obj_t *buttonNameValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 2 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_WIFI_NAME); + lv_obj_t *labelNameValue = lv_label_create_empty(buttonNameValue); - labelModelText = lv_label_create(scr, NULL); - lv_obj_set_style(labelModelText, &tft_style_label_rel); - lv_obj_set_pos(labelModelText, PARA_UI_POS_X, PARA_UI_POS_Y + 10); - lv_label_set_text(labelModelText, machine_menu.wifiMode); + lv_obj_t *line2 = lv_line_create(scr, nullptr); + lv_ex_line(line2, line_points[1]); - buttonModelValue = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonModelValue,PARA_UI_VALUE_POS_X,PARA_UI_POS_Y+PARA_UI_VALUE_V); - lv_obj_set_event_cb_mks(buttonModelValue, event_handler,ID_WIFI_MODEL, NULL,0); - lv_imgbtn_set_src(buttonModelValue, LV_BTN_STATE_REL, "F:/bmp_blank_sel.bin"); - lv_imgbtn_set_src(buttonModelValue, LV_BTN_STATE_PR, "F:/bmp_blank_sel.bin"); - lv_imgbtn_set_style(buttonModelValue, LV_BTN_STATE_PR, &style_para_value_pre); - lv_imgbtn_set_style(buttonModelValue, LV_BTN_STATE_REL, &style_para_value_pre); - lv_btn_set_layout(buttonModelValue, LV_LAYOUT_OFF); - labelModelValue = lv_label_create(buttonModelValue, NULL); + lv_obj_t *labelPassWordText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10, nullptr); + lv_obj_t *buttonPassWordValue = lv_btn_create(scr, PARA_UI_VALUE_POS_X, PARA_UI_POS_Y * 3 + PARA_UI_VALUE_V, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE, event_handler, ID_WIFI_PASSWORD); + lv_obj_t *labelPassWordValue = lv_label_create_empty(buttonPassWordValue); - line1 = lv_line_create(scr, NULL); - lv_ex_line(line1,line_points[0]); + lv_obj_t *line3 = lv_line_create(scr, nullptr); + lv_ex_line(line3, line_points[2]); - labelNameText = lv_label_create(scr, NULL); - lv_obj_set_style(labelNameText, &tft_style_label_rel); - lv_obj_set_pos(labelNameText, PARA_UI_POS_X, PARA_UI_POS_Y * 2 + 10); + lv_obj_t *labelCloudText = lv_label_create(scr, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10, machine_menu.wifiCloud); + lv_obj_t *buttonCloudValue = lv_imgbtn_create(scr, gCfgItems.cloud_enable ? "F:/bmp_enable.bin" : "F:/bmp_disable.bin", PARA_UI_STATE_POS_X, PARA_UI_POS_Y * 4 + PARA_UI_STATE_V, event_handler, ID_WIFI_CLOUD); + labelCloudValue = lv_label_create_empty(buttonCloudValue); - buttonNameValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonNameValue,PARA_UI_VALUE_POS_X,PARA_UI_POS_Y*2+PARA_UI_VALUE_V); - lv_obj_set_size(buttonNameValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonNameValue, event_handler,ID_WIFI_NAME, NULL,0); - lv_btn_set_style(buttonNameValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonNameValue, LV_BTN_STYLE_PR, &style_para_value); - labelNameValue = lv_label_create(buttonNameValue, NULL); + lv_obj_t *line4 = lv_line_create(scr, nullptr); + lv_ex_line(line4, line_points[3]); - line2 = lv_line_create(scr, NULL); - lv_ex_line(line2,line_points[1]); + lv_obj_t *buttonConfig = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y, event_handler, ID_WIFI_CONFIG); + lv_obj_t *labelConfig = lv_label_create_empty(buttonConfig); - labelPassWordText = lv_label_create(scr, NULL); - lv_obj_set_style(labelPassWordText, &tft_style_label_rel); - lv_obj_set_pos(labelPassWordText, PARA_UI_POS_X, PARA_UI_POS_Y * 3 + 10); - - buttonPassWordValue = lv_btn_create(scr, NULL); - lv_obj_set_pos(buttonPassWordValue,PARA_UI_VALUE_POS_X,PARA_UI_POS_Y*3+PARA_UI_VALUE_V); - lv_obj_set_size(buttonPassWordValue, PARA_UI_VALUE_BTN_X_SIZE, PARA_UI_VALUE_BTN_Y_SIZE); - lv_obj_set_event_cb_mks(buttonPassWordValue, event_handler,ID_WIFI_PASSWORD, NULL,0); - lv_btn_set_style(buttonPassWordValue, LV_BTN_STYLE_REL, &style_para_value); - lv_btn_set_style(buttonPassWordValue, LV_BTN_STYLE_PR, &style_para_value); - labelPassWordValue = lv_label_create(buttonPassWordValue, NULL); - - line3 = lv_line_create(scr, NULL); - lv_ex_line(line3,line_points[2]); - - labelCloudText = lv_label_create(scr, NULL); - lv_obj_set_style(labelCloudText, &tft_style_label_rel); - lv_obj_set_pos(labelCloudText, PARA_UI_POS_X, PARA_UI_POS_Y * 4 + 10); - lv_label_set_text(labelCloudText, machine_menu.wifiCloud); - - buttonCloudValue = lv_imgbtn_create(scr, NULL); - lv_obj_set_pos(buttonCloudValue,PARA_UI_STATE_POS_X,PARA_UI_POS_Y*4+PARA_UI_STATE_V); - if (gCfgItems.cloud_enable) { - lv_imgbtn_set_src(buttonCloudValue, LV_BTN_STATE_REL, "F:/bmp_enable.bin"); - lv_imgbtn_set_src(buttonCloudValue, LV_BTN_STATE_PR, "F:/bmp_enable.bin"); - } - else { - lv_imgbtn_set_src(buttonCloudValue, LV_BTN_STATE_REL, "F:/bmp_disable.bin"); - lv_imgbtn_set_src(buttonCloudValue, LV_BTN_STATE_PR, "F:/bmp_disable.bin"); - } - lv_obj_set_event_cb_mks(buttonCloudValue, event_handler,ID_WIFI_CLOUD, NULL,0); - lv_imgbtn_set_style(buttonCloudValue, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonCloudValue, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_btn_set_layout(buttonCloudValue, LV_LAYOUT_OFF); - labelCloudValue = lv_label_create(buttonCloudValue, NULL); - - line4 = lv_line_create(scr, NULL); - lv_ex_line(line4,line_points[3]); - - buttonConfig = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonConfig, event_handler,ID_WIFI_CONFIG, NULL,0); - lv_imgbtn_set_src(buttonConfig, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonConfig, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonConfig, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonConfig, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_obj_set_pos(buttonConfig, PARA_UI_TURN_PAGE_POS_X, PARA_UI_TURN_PAGE_POS_Y); - lv_btn_set_layout(buttonConfig, LV_LAYOUT_OFF); - labelConfig = lv_label_create(buttonConfig, NULL); - - buttonBack = lv_imgbtn_create(scr, NULL); - lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_WIFI_RETURN, NULL, 0); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back70x40.bin"); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre); - lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel); - lv_obj_set_pos(buttonBack, PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y); - lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF); - label_Back = lv_label_create(buttonBack, NULL); + lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_back70x40.bin", PARA_UI_BACL_POS_X, PARA_UI_BACL_POS_Y, event_handler, ID_WIFI_RETURN); + lv_obj_t *label_Back = lv_label_create_empty(buttonBack); if (gCfgItems.multiple_language) { if (gCfgItems.wifi_mode_sel == AP_MODEL) { lv_label_set_text(labelModelValue, WIFI_AP_TEXT); - lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER,0, 0); + lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); } else { lv_label_set_text(labelModelValue, WIFI_STA_TEXT); - lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER,0, 0); + lv_obj_align(labelModelValue, buttonModelValue, LV_ALIGN_CENTER, 0, 0); } - memset(public_buf_m,0,sizeof(public_buf_m)); - strcat(public_buf_m,machine_menu.wifiName); - strcat(public_buf_m,(const char *)uiCfg.wifi_name); - lv_label_set_text(labelNameText,public_buf_m); + strcat(public_buf_m, machine_menu.wifiName); + strcat(public_buf_m, (const char *)uiCfg.wifi_name); + lv_label_set_text(labelNameText, public_buf_m); - lv_label_set_text(labelNameValue,machine_menu.wifiEdit); - lv_obj_align(labelNameValue, buttonNameValue, LV_ALIGN_CENTER,0, 0); + lv_label_set_text(labelNameValue, machine_menu.wifiEdit); + lv_obj_align(labelNameValue, buttonNameValue, LV_ALIGN_CENTER, 0, 0); - memset(public_buf_m,0,sizeof(public_buf_m)); - strcat(public_buf_m,machine_menu.wifiPassWord); - strcat(public_buf_m,(const char *)uiCfg.wifi_key); - lv_label_set_text(labelPassWordText,public_buf_m); + strcat(public_buf_m, machine_menu.wifiPassWord); + strcat(public_buf_m, (const char *)uiCfg.wifi_key); + lv_label_set_text(labelPassWordText, public_buf_m); - lv_label_set_text(labelPassWordValue,machine_menu.wifiEdit); - lv_obj_align(labelPassWordValue, buttonPassWordValue, LV_ALIGN_CENTER,0, 0); + lv_label_set_text(labelPassWordValue, machine_menu.wifiEdit); + lv_obj_align(labelPassWordValue, buttonPassWordValue, LV_ALIGN_CENTER, 0, 0); lv_label_set_text(labelCloudValue, gCfgItems.cloud_enable ? machine_menu.enable : machine_menu.disable); - lv_obj_align(labelCloudValue, buttonCloudValue, LV_ALIGN_CENTER,0, 0); + lv_obj_align(labelCloudValue, buttonCloudValue, LV_ALIGN_CENTER, 0, 0); - lv_label_set_text(labelConfig,machine_menu.wifiConfig); - lv_obj_align(labelConfig, buttonConfig, LV_ALIGN_CENTER,0, 0); + lv_label_set_text(labelConfig, machine_menu.wifiConfig); + lv_obj_align(labelConfig, buttonConfig, LV_ALIGN_CENTER, 0, 0); lv_label_set_text(label_Back, common_menu.text_back); - lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER,0, 0); + lv_obj_align(label_Back, buttonBack, LV_ALIGN_CENTER, 0, 0); } #if HAS_ROTARY_ENCODER diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp index 059656bbb5..a9e5624996 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_wifi_tips.cpp @@ -30,50 +30,34 @@ #include "draw_ui.h" -static lv_obj_t * scr; +static lv_obj_t *scr; TIPS_TYPE wifi_tips_type; TIPS_DISP tips_disp; tips_menu_def tips_menu; void lv_draw_wifi_tips(void) { - static lv_obj_t * text_tips,*wifi_name; + static lv_obj_t *text_tips,*wifi_name; - if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_TIPS_UI) { - disp_state_stack._disp_index++; - disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_TIPS_UI; - } - disp_state = WIFI_TIPS_UI; + scr = lv_screen_create(WIFI_TIPS_UI, ""); - scr = lv_obj_create(NULL, NULL); - - lv_obj_set_style(scr, &tft_style_scr); - lv_scr_load(scr); - lv_obj_clean(scr); - lv_refr_now(lv_refr_get_disp_refreshing()); - - text_tips = lv_label_create(scr, NULL); - lv_obj_set_style(text_tips, &tft_style_label_rel); - - wifi_name = lv_label_create(scr, NULL); - lv_obj_set_style(wifi_name, &tft_style_label_rel); + wifi_name = lv_label_create(scr, (const char *)wifi_list.wifiName[wifi_list.nameIndex]); + lv_obj_align(wifi_name, nullptr, LV_ALIGN_CENTER, 0, -20); + text_tips = lv_label_create_empty(scr); if (wifi_tips_type == TIPS_TYPE_JOINING) { lv_label_set_text(text_tips, tips_menu.joining); - lv_obj_align(text_tips, NULL, LV_ALIGN_CENTER,0, -60); + lv_obj_align(text_tips, nullptr, LV_ALIGN_CENTER, 0, -60); } else if (wifi_tips_type == TIPS_TYPE_TAILED_JOIN) { lv_label_set_text(text_tips, tips_menu.failedJoin); - lv_obj_align(text_tips, NULL, LV_ALIGN_CENTER,0, -60); + lv_obj_align(text_tips, nullptr, LV_ALIGN_CENTER, 0, -60); } else if (wifi_tips_type == TIPS_TYPE_WIFI_CONECTED) { lv_label_set_text(text_tips, tips_menu.wifiConected); - lv_obj_align(text_tips, NULL, LV_ALIGN_CENTER,0, -60); + lv_obj_align(text_tips, nullptr, LV_ALIGN_CENTER, 0, -60); } - lv_label_set_text(wifi_name, (const char *)wifi_list.wifiName[wifi_list.nameIndex]); - lv_obj_align(wifi_name, NULL, LV_ALIGN_CENTER,0, -20); - tips_disp.timer = TIPS_TIMER_START; tips_disp.timer_count = 0; } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp b/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp index 856d645e9e..fbc8192ffb 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/gb2312_puhui16.cpp @@ -62,7 +62,7 @@ static const uint8_t * __user_font_get_bitmap(const lv_font_t * font, uint32_t u memcpy(&__g_xbf_hd, p, sizeof(x_header_t)); } if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min) - return NULL; + return nullptr; uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4; uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4); if (p_pos[0] != 0) { @@ -72,7 +72,7 @@ static const uint8_t * __user_font_get_bitmap(const lv_font_t * font, uint32_t u //return __user_font_getdata(pos+2, gdsc->box_w*__g_xbf_hd.bpp/8); return __user_font_getdata(pos + 2, sizeof(__g_font_buf)); } - return NULL; + return nullptr; } static bool __user_font_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { @@ -81,7 +81,7 @@ static bool __user_font_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_ memcpy(&__g_xbf_hd, p, sizeof(x_header_t)); } if (unicode_letter > __g_xbf_hd.max || unicode_letter < __g_xbf_hd.min) - return NULL; + return false; uint32_t unicode_offset = sizeof(x_header_t) + (unicode_letter - __g_xbf_hd.min) * 4; uint32_t *p_pos = (uint32_t *)__user_font_getdata(unicode_offset, 4); if (p_pos[0] != 0) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp index bc329aa82b..06d6ca6b72 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp @@ -637,7 +637,7 @@ void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor } } -//static lv_obj_t * scr_test; +//static lv_obj_t *scr_test; void disp_assets_update() { SPI_TFT.LCD_clear(0x0000); disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp b/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp index e6c30b30f8..edd90848d5 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp @@ -58,13 +58,11 @@ void printer_state_polling() { if (gCfgItems.pausePosZ != (float)-1) { gcode.process_subcommands_now_P(PSTR("G91")); - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 Z%.1f"), gCfgItems.pausePosZ); gcode.process_subcommands_now(public_buf_l); gcode.process_subcommands_now_P(PSTR("G90")); } if (gCfgItems.pausePosX != (float)-1 && gCfgItems.pausePosY != (float)-1) { - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 X%.1f Y%.1f"), gCfgItems.pausePosX, gCfgItems.pausePosY); gcode.process_subcommands_now(public_buf_l); } @@ -88,13 +86,11 @@ void printer_state_polling() { if (uiCfg.print_state == RESUMING) { if (IS_SD_PAUSED()) { if (gCfgItems.pausePosX != (float)-1 && gCfgItems.pausePosY != (float)-1) { - ZERO(public_buf_m); sprintf_P(public_buf_m, PSTR("G1 X%.1f Y%.1f"), uiCfg.current_x_position_bak, uiCfg.current_y_position_bak); gcode.process_subcommands_now(public_buf_m); } if (gCfgItems.pausePosZ != (float)-1) { gcode.process_subcommands_now_P(PSTR("G91")); - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 Z-%.1f"), gCfgItems.pausePosZ); gcode.process_subcommands_now(public_buf_l); gcode.process_subcommands_now_P(PSTR("G90")); @@ -109,7 +105,6 @@ void printer_state_polling() { } #if ENABLED(POWER_LOSS_RECOVERY) if (uiCfg.print_state == REPRINTED) { - ZERO(public_buf_m); #if HAS_HOTEND HOTEND_LOOP() { const int16_t et = recovery.info.target_temperature[e]; @@ -128,7 +123,6 @@ void printer_state_polling() { #if 0 // Move back to the saved XY char str_1[16], str_2[16]; - ZERO(public_buf_m); sprintf_P(public_buf_m, PSTR("G1 X%s Y%s F2000"), dtostrf(recovery.info.current_position.x, 1, 3, str_1), dtostrf(recovery.info.current_position.y, 1, 3, str_2) @@ -137,7 +131,6 @@ void printer_state_polling() { if (gCfgItems.pause_reprint && gCfgItems.pausePosZ != -1.0f) { gcode.process_subcommands_now_P(PSTR("G91")); - ZERO(public_buf_l); sprintf_P(public_buf_l, PSTR("G1 Z-%.1f"), gCfgItems.pausePosZ); gcode.process_subcommands_now(public_buf_l); gcode.process_subcommands_now_P(PSTR("G90")); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index 6143037c2b..2f1ec48b44 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -99,7 +99,7 @@ void SysTick_Callback() { uiCfg.filament_unloading_time_cnt = 0; uiCfg.filament_unloading_time_flg = 0; uiCfg.filament_unloading_completed = 1; - uiCfg.filament_rate = 100; + uiCfg.filament_rate = 100; } } } @@ -133,7 +133,7 @@ void tft_lvgl_init() { lv_init(); - lv_disp_buf_init(&disp_buf, bmp_public_buf, NULL, LV_HOR_RES_MAX * 18); /*Initialize the display buffer*/ + lv_disp_buf_init(&disp_buf, bmp_public_buf, nullptr, LV_HOR_RES_MAX * 18); /*Initialize the display buffer*/ lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ @@ -199,7 +199,6 @@ void tft_lvgl_init() { uiCfg.print_state = REPRINTING; - ZERO(public_buf_m); strncpy(public_buf_m, recovery.info.sd_filename, sizeof(public_buf_m)); card.printLongPath(public_buf_m); @@ -216,15 +215,14 @@ void tft_lvgl_init() { } void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) { - uint16_t i, width, height; - - width = area->x2 - area->x1 + 1; - height = area->y2 - area->y1 + 1; + uint16_t width = area->x2 - area->x1 + 1, + height = area->y2 - area->y1 + 1; SPI_TFT.setWindow((uint16_t)area->x1, (uint16_t)area->y1, width, height); - for (i = 0; i < height; i++) { + + for (uint16_t i = 0; i < height; i++) SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width); - } + lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ W25QXX.init(SPI_QUARTER_SPEED); @@ -310,10 +308,9 @@ extern uint8_t currentFlashPage; uint32_t pic_read_base_addr = 0, pic_read_addr_offset = 0; lv_fs_res_t spi_flash_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) { static char last_path_name[30]; - if (strcasecmp(last_path_name,path) != 0) { + if (strcasecmp(last_path_name, path) != 0) { pic_read_base_addr = lv_get_pic_addr((uint8_t *)path); - ZERO(last_path_name); - strcpy(last_path_name,path); + strcpy(last_path_name, path); } else { W25QXX.init(SPI_QUARTER_SPEED); @@ -362,11 +359,10 @@ uint32_t sd_read_base_addr = 0,sd_read_addr_offset = 0; lv_fs_res_t sd_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) { //cur_namefff = strrchr(path, '/'); char name_buf[100]; - ZERO(name_buf); - strcat(name_buf,"/"); - strcat(name_buf,path); - char *temp = strstr(name_buf,".bin"); - if (temp) { strcpy(temp,".GCO"); } + *name_buf = '/'; + strcpy(name_buf + 1, path); + char *temp = strstr(name_buf, ".bin"); + if (temp) strcpy(temp, ".GCO"); sd_read_base_addr = lv_open_gcode_file((char *)name_buf); sd_read_addr_offset = sd_read_base_addr; if (sd_read_addr_offset == 0) return LV_FS_RES_NOT_EX; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifiSerial.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifiSerial.cpp index 6e15deffae..16b65c7ea3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifiSerial.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifiSerial.cpp @@ -53,7 +53,7 @@ WifiSerial::WifiSerial(usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) { /* F1 MCUs have no GPIO_AFR[HL], so turn off PWM if there's a conflict * on this GPIO bit. */ static void disable_timer_if_necessary(timer_dev *dev, uint8 ch) { - if (dev != nullptr) timer_set_mode(dev, ch, TIMER_DISABLED); + if (dev) timer_set_mode(dev, ch, TIMER_DISABLED); } #elif STM32_MCU_SERIES == STM32_SERIES_F2 || STM32_MCU_SERIES == STM32_SERIES_F4 #define disable_timer_if_necessary(dev, ch) ((void)0) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp index 087a3b2110..097263a655 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp @@ -260,7 +260,7 @@ void WriteByteSlip(uint8_t b) { // Wait for a data packet to be returned. If the body of the packet is // non-zero length, return an allocated buffer indirectly containing the // data and return the data length. Note that if the pointer for returning -// the data buffer is NULL, the response is expected to be two bytes of zero. +// the data buffer is nullptr, the response is expected to be two bytes of zero. // // If an error occurs, return a negative value. Otherwise, return the number // of bytes in the response (or zero if the response was not the standard "two bytes of zero"). @@ -533,12 +533,8 @@ EspUploadResult flashFinish(signed char reboot) { // Compute the checksum of a block of data uint16_t checksum(const uint8_t *data, uint16_t dataLen, uint16_t cksum) { - if (data != NULL) { - while (dataLen--) { - cksum ^= (uint16_t)*data++; - } - } - return(cksum); + if (data) while (dataLen--) cksum ^= (uint16_t)*data++; + return cksum; } EspUploadResult flashWriteBlock(uint16_t flashParmVal, uint16_t flashParmMask) { diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index 8151828a08..33b5d5458e 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -610,7 +610,7 @@ namespace ExtUI { caselight.update_enabled(); } - #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) + #if CASELIGHT_USES_BRIGHTNESS float getCaseLightBrightness_percent() { return ui8_to_percent(caselight.brightness); } void setCaseLightBrightness_percent(const float value) { caselight.brightness = map(constrain(value, 0, 100), 0, 100, 0, 255); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 487678eccf..0a87965721 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -337,6 +337,10 @@ void MarlinUI::init() { SET_INPUT_PULLUP(BTN_ENC); #endif + #if BUTTON_EXISTS(ENC_EN) + SET_INPUT_PULLUP(BTN_ENC_EN); + #endif + #if BUTTON_EXISTS(BACK) SET_INPUT_PULLUP(BTN_BACK); #endif @@ -804,6 +808,14 @@ millis_t next_lcd_update_ms; millis_t MarlinUI::return_to_status_ms = 0; #endif +inline bool can_encode() { + #if BUTTON_EXISTS(ENC_EN) + return !BUTTON_PRESSED(ENC_EN); // Update position only when ENC_EN is HIGH + #else + return true; + #endif +} + void MarlinUI::update() { static uint16_t max_display_update_time = 0; @@ -957,7 +969,8 @@ void MarlinUI::update() { #endif // ENCODER_RATE_MULTIPLIER - encoderPosition += (encoderDiff * encoderMultiplier) / epps; + if (can_encode()) encoderPosition += (encoderDiff * encoderMultiplier) / epps; + encoderDiff = 0; } @@ -1175,7 +1188,7 @@ void MarlinUI::update() { if (BUTTON_PRESSED(EN2)) newbutton |= EN_B; #endif #if BUTTON_EXISTS(ENC) - if (BUTTON_PRESSED(ENC)) newbutton |= EN_C; + if (can_encode() && BUTTON_PRESSED(ENC)) newbutton |= EN_C; #endif #if BUTTON_EXISTS(BACK) if (BUTTON_PRESSED(BACK)) newbutton |= EN_D; diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 5d67410351..cd94927049 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -129,7 +129,7 @@ void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) { if (ui.should_draw()) draw_edit_screen(strfunc(ui.encoderPosition + minEditValue)); if (ui.lcd_clicked || (liveEdit && ui.should_draw())) { - if (editValue != nullptr) loadfunc(editValue, ui.encoderPosition + minEditValue); + if (editValue) loadfunc(editValue, ui.encoderPosition + minEditValue); if (callbackFunc && (liveEdit || ui.lcd_clicked)) (*callbackFunc)(); if (ui.use_click()) ui.goto_previous_screen(); } diff --git a/Marlin/src/lcd/menu/menu_led.cpp b/Marlin/src/lcd/menu/menu_led.cpp index 386a4d799a..d9540592d0 100644 --- a/Marlin/src/lcd/menu/menu_led.cpp +++ b/Marlin/src/lcd/menu/menu_led.cpp @@ -105,7 +105,7 @@ #if ENABLED(CASE_LIGHT_MENU) #include "../../feature/caselight.h" - #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) + #if CASELIGHT_USES_BRIGHTNESS void menu_case_light() { START_MENU(); BACK_ITEM(MSG_CONFIGURATION); diff --git a/Marlin/src/lcd/tft/canvas.cpp b/Marlin/src/lcd/tft/canvas.cpp index f6a5046b8d..061f078b92 100644 --- a/Marlin/src/lcd/tft/canvas.cpp +++ b/Marlin/src/lcd/tft/canvas.cpp @@ -79,7 +79,7 @@ void CANVAS::AddText(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, ui void CANVAS::AddImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors) { uint16_t *data = (uint16_t *)Images[image].data; - if (data == NULL) return; + if (!data) return; uint16_t image_width = Images[image].width, image_height = Images[image].height; diff --git a/Marlin/src/lcd/tft/tft_image.cpp b/Marlin/src/lcd/tft/tft_image.cpp index 27749cb7f3..8f8b610699 100644 --- a/Marlin/src/lcd/tft/tft_image.cpp +++ b/Marlin/src/lcd/tft/tft_image.cpp @@ -23,7 +23,7 @@ #include "tft_image.h" #include -const tImage NoLogo = { (void *)NULL, 0, 0, NOCOLORS }; +const tImage NoLogo = { nullptr, 0, 0, NOCOLORS }; const tImage MarlinLogo112x38x1 = { (void *)marlin_logo_112x38x1, 112, 38, GREYSCALE1 }; const tImage MarlinLogo228x255x2 = { (void *)marlin_logo_228x255x2, 228, 255, GREYSCALE2 }; diff --git a/Marlin/src/lcd/tft/tft_queue.cpp b/Marlin/src/lcd/tft/tft_queue.cpp index e77afaf716..e178a59a2d 100644 --- a/Marlin/src/lcd/tft/tft_queue.cpp +++ b/Marlin/src/lcd/tft/tft_queue.cpp @@ -30,19 +30,19 @@ uint8_t TFT_Queue::queue[]; uint8_t *TFT_Queue::end_of_queue = queue; -uint8_t *TFT_Queue::current_task = NULL; -uint8_t *TFT_Queue::last_task = NULL; +uint8_t *TFT_Queue::current_task = nullptr; +uint8_t *TFT_Queue::last_task = nullptr; void TFT_Queue::reset() { tft.abort(); end_of_queue = queue; - current_task = NULL; - last_task = NULL; + current_task = nullptr; + last_task = nullptr; } void TFT_Queue::async() { - if (current_task == NULL) return; + if (!current_task) return; queueTask_t *task = (queueTask_t *)current_task; // Check IO busy status @@ -63,7 +63,7 @@ void TFT_Queue::async() { } void TFT_Queue::finish_sketch() { - if (last_task == NULL) return; + if (!last_task) return; queueTask_t *task = (queueTask_t *)last_task; if (task->state == TASK_STATE_SKETCH) { @@ -71,7 +71,7 @@ void TFT_Queue::finish_sketch() { task->nextTask = end_of_queue; task->state = TASK_STATE_READY; - if (current_task == NULL) current_task = (uint8_t *)task; + if (!current_task) current_task = (uint8_t *)task; } } @@ -184,7 +184,7 @@ void TFT_Queue::fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui task->state = TASK_STATE_READY; task->type = TASK_FILL; - if (current_task == NULL) current_task = (uint8_t *)task; + if (!current_task) current_task = (uint8_t *)task; } void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) { @@ -195,7 +195,7 @@ void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) task->state = TASK_STATE_SKETCH; task->type = TASK_CANVAS; - task->nextTask = NULL; + task->nextTask = nullptr; end_of_queue += sizeof(queueTask_t); parametersCanvas_t *task_parameters = (parametersCanvas_t *)end_of_queue; @@ -207,7 +207,7 @@ void TFT_Queue::canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) task_parameters->height = height; task_parameters->count = 0; - if (current_task == NULL) current_task = (uint8_t *)task; + if (!current_task) current_task = (uint8_t *)task; } void TFT_Queue::set_background(uint16_t color) { diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index 663ed97c36..b707596bb3 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -42,7 +42,7 @@ void TFT_String::set_font(const uint8_t *font) { font_header = (font_t *)font; uint32_t glyph; - for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = NULL; + for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = nullptr; DEBUG_ECHOLNPAIR("Format: ", font_header->Format); DEBUG_ECHOLNPAIR("BBXWidth: ", font_header->BBXWidth); diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 3e0945b227..93f8f64a2d 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -119,9 +119,8 @@ void Touch::idle() { NOMORE(y, current_control->y + current_control->height); touch(current_control); } - else { - current_control = NULL; - } + else + current_control = nullptr; } else { for (i = 0; i < controls_count; i++) { @@ -133,7 +132,7 @@ void Touch::idle() { } } - if (current_control == NULL) + if (!current_control) touch_time = last_touch_ms; } x = _x; @@ -141,7 +140,7 @@ void Touch::idle() { } else { x = y = 0; - current_control = NULL; + current_control = nullptr; touch_time = 0; touch_control_type = NONE; time_to_hold = 0; diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index 339c26cca2..45eab34665 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -452,7 +452,7 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu 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*/) { uint16_t line = 1; - if (string == NULL) line++; + if (!string) line++; menu_line(line++); tft_string.set(pref); diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index b67e041349..1003f32e7c 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -457,7 +457,7 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu 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*/) { uint16_t line = 1; - if (string == NULL) line++; + if (!string) line++; menu_line(line++); tft_string.set(pref); @@ -945,7 +945,7 @@ static void drawBtn(int x, int y, const char* label, int32_t data, MarlinImage i tft.add_image(0, 0, imgBtn52Rounded, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY); // TODO: Make an add_text() taking a font arg - if (label != NULL) { + if (label) { tft_string.set(label); tft_string.trim(); tft.add_text(tft_string.center(width), height / 2 - tft_string.font_height() / 2, bgColor, tft_string); diff --git a/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp b/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp index 3f0f828cd7..073a7ed0b6 100644 --- a/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp +++ b/Marlin/src/libs/heatshrink/heatshrink_decoder.cpp @@ -89,7 +89,7 @@ heatshrink_decoder *heatshrink_decoder_alloc(uint16_t input_buffer_size, uint8_t size_t buffers_sz = (1 << window_sz2) + input_buffer_size; size_t sz = sizeof(heatshrink_decoder) + buffers_sz; heatshrink_decoder *hsd = HEATSHRINK_MALLOC(sz); - if (hsd == nullptr) return nullptr; + if (!hsd) return nullptr; hsd->input_buffer_size = input_buffer_size; hsd->window_sz2 = window_sz2; hsd->lookahead_sz2 = lookahead_sz2; @@ -124,7 +124,7 @@ void heatshrink_decoder_reset(heatshrink_decoder *hsd) { /* Copy SIZE bytes into the decoder's input buffer, if it will fit. */ HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd, uint8_t *in_buf, size_t size, size_t *input_size) { - if (hsd == nullptr || in_buf == nullptr || input_size == nullptr) + if (!hsd || !in_buf || !input_size) return HSDR_SINK_ERROR_NULL; size_t rem = HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(hsd) - hsd->input_size; @@ -160,7 +160,7 @@ static HSD_state st_backref_count_lsb(heatshrink_decoder *hsd); static HSD_state st_yield_backref(heatshrink_decoder *hsd, output_info *oi); HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, uint8_t *out_buf, size_t out_buf_size, size_t *output_size) { - if (hsd == nullptr || out_buf == nullptr || output_size == nullptr) + if (!hsd || !out_buf || !output_size) return HSDR_POLL_ERROR_NULL; *output_size = 0; @@ -351,7 +351,7 @@ static uint16_t get_bits(heatshrink_decoder *hsd, uint8_t count) { } HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd) { - if (hsd == nullptr) { return HSDR_FINISH_ERROR_NULL; } + if (!hsd) return HSDR_FINISH_ERROR_NULL; switch (hsd->state) { case HSDS_TAG_BIT: return hsd->input_size == 0 ? HSDR_FINISH_DONE : HSDR_FINISH_MORE; diff --git a/Marlin/src/libs/vector_3.cpp b/Marlin/src/libs/vector_3.cpp index 75a30aef82..fd93ba09ad 100644 --- a/Marlin/src/libs/vector_3.cpp +++ b/Marlin/src/libs/vector_3.cpp @@ -141,7 +141,7 @@ matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) { } void matrix_3x3::debug(PGM_P const title) { - if (title != nullptr) { + if (title) { serialprintPGM(title); SERIAL_EOL(); } diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 9ed78efd63..d01486a80d 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -137,9 +137,8 @@ void M710_report(const bool forReplay); #endif -#if ENABLED(CASE_LIGHT_ENABLE) && DISABLED(CASE_LIGHT_NO_BRIGHTNESS) +#if ENABLED(CASE_LIGHT_ENABLE) #include "../feature/caselight.h" - #define HAS_CASE_LIGHT_BRIGHTNESS 1 #endif #if ENABLED(PASSWORD_FEATURE) @@ -422,9 +421,9 @@ typedef struct SettingsDataStruct { #endif // - // HAS_CASE_LIGHT_BRIGHTNESS + // CASELIGHT_USES_BRIGHTNESS // - #if HAS_CASE_LIGHT_BRIGHTNESS + #if CASELIGHT_USES_BRIGHTNESS uint8_t caselight_brightness; // M355 P #endif @@ -503,7 +502,7 @@ void MarlinSettings::postprocess() { TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk()); - TERN_(HAS_CASE_LIGHT_BRIGHTNESS, caselight.update_brightness()); + TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.update_brightness()); // Refresh steps_to_mm with the reciprocal of axis_steps_per_mm // and init stepper.count[], planner.position[] with current_position @@ -1214,60 +1213,60 @@ void MarlinSettings::postprocess() { #if HAS_STEALTHCHOP #if AXIS_HAS_STEALTHCHOP(X) - tmc_stealth_enabled.X = stepperX.get_stored_stealthChop_status(); + tmc_stealth_enabled.X = stepperX.get_stored_stealthChop(); #endif #if AXIS_HAS_STEALTHCHOP(Y) - tmc_stealth_enabled.Y = stepperY.get_stored_stealthChop_status(); + tmc_stealth_enabled.Y = stepperY.get_stored_stealthChop(); #endif #if AXIS_HAS_STEALTHCHOP(Z) - tmc_stealth_enabled.Z = stepperZ.get_stored_stealthChop_status(); + tmc_stealth_enabled.Z = stepperZ.get_stored_stealthChop(); #endif #if AXIS_HAS_STEALTHCHOP(X2) - tmc_stealth_enabled.X2 = stepperX2.get_stored_stealthChop_status(); + tmc_stealth_enabled.X2 = stepperX2.get_stored_stealthChop(); #endif #if AXIS_HAS_STEALTHCHOP(Y2) - tmc_stealth_enabled.Y2 = stepperY2.get_stored_stealthChop_status(); + tmc_stealth_enabled.Y2 = stepperY2.get_stored_stealthChop(); #endif #if AXIS_HAS_STEALTHCHOP(Z2) - tmc_stealth_enabled.Z2 = stepperZ2.get_stored_stealthChop_status(); + tmc_stealth_enabled.Z2 = stepperZ2.get_stored_stealthChop(); #endif #if AXIS_HAS_STEALTHCHOP(Z3) - tmc_stealth_enabled.Z3 = stepperZ3.get_stored_stealthChop_status(); + tmc_stealth_enabled.Z3 = stepperZ3.get_stored_stealthChop(); #endif #if AXIS_HAS_STEALTHCHOP(Z4) - tmc_stealth_enabled.Z4 = stepperZ4.get_stored_stealthChop_status(); + tmc_stealth_enabled.Z4 = stepperZ4.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS #if AXIS_HAS_STEALTHCHOP(E0) - tmc_stealth_enabled.E0 = stepperE0.get_stored_stealthChop_status(); + tmc_stealth_enabled.E0 = stepperE0.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS > 1 #if AXIS_HAS_STEALTHCHOP(E1) - tmc_stealth_enabled.E1 = stepperE1.get_stored_stealthChop_status(); + tmc_stealth_enabled.E1 = stepperE1.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS > 2 #if AXIS_HAS_STEALTHCHOP(E2) - tmc_stealth_enabled.E2 = stepperE2.get_stored_stealthChop_status(); + tmc_stealth_enabled.E2 = stepperE2.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS > 3 #if AXIS_HAS_STEALTHCHOP(E3) - tmc_stealth_enabled.E3 = stepperE3.get_stored_stealthChop_status(); + tmc_stealth_enabled.E3 = stepperE3.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS > 4 #if AXIS_HAS_STEALTHCHOP(E4) - tmc_stealth_enabled.E4 = stepperE4.get_stored_stealthChop_status(); + tmc_stealth_enabled.E4 = stepperE4.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS > 5 #if AXIS_HAS_STEALTHCHOP(E5) - tmc_stealth_enabled.E5 = stepperE5.get_stored_stealthChop_status(); + tmc_stealth_enabled.E5 = stepperE5.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS > 6 #if AXIS_HAS_STEALTHCHOP(E6) - tmc_stealth_enabled.E6 = stepperE6.get_stored_stealthChop_status(); + tmc_stealth_enabled.E6 = stepperE6.get_stored_stealthChop(); #endif #if MAX_EXTRUDERS > 7 #if AXIS_HAS_STEALTHCHOP(E7) - tmc_stealth_enabled.E7 = stepperE7.get_stored_stealthChop_status(); + tmc_stealth_enabled.E7 = stepperE7.get_stored_stealthChop(); #endif #endif // MAX_EXTRUDERS > 7 #endif // MAX_EXTRUDERS > 6 @@ -1385,7 +1384,7 @@ void MarlinSettings::postprocess() { // // Case Light Brightness // - #if HAS_CASE_LIGHT_BRIGHTNESS + #if CASELIGHT_USES_BRIGHTNESS EEPROM_WRITE(caselight.brightness); #endif @@ -2259,7 +2258,7 @@ void MarlinSettings::postprocess() { // // Case Light Brightness // - #if HAS_CASE_LIGHT_BRIGHTNESS + #if CASELIGHT_USES_BRIGHTNESS _FIELD_TEST(caselight_brightness); EEPROM_READ(caselight.brightness); #endif @@ -2597,7 +2596,7 @@ void MarlinSettings::reset() { // // Case Light Brightness // - TERN_(HAS_CASE_LIGHT_BRIGHTNESS, caselight.brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS); + TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS); // // TOUCH_SCREEN_CALIBRATION @@ -3671,17 +3670,17 @@ void MarlinSettings::reset() { #if HAS_STEALTHCHOP CONFIG_ECHO_HEADING("Driver stepping mode:"); #if AXIS_HAS_STEALTHCHOP(X) - const bool chop_x = stepperX.get_stored_stealthChop_status(); + const bool chop_x = stepperX.get_stored_stealthChop(); #else constexpr bool chop_x = false; #endif #if AXIS_HAS_STEALTHCHOP(Y) - const bool chop_y = stepperY.get_stored_stealthChop_status(); + const bool chop_y = stepperY.get_stored_stealthChop(); #else constexpr bool chop_y = false; #endif #if AXIS_HAS_STEALTHCHOP(Z) - const bool chop_z = stepperZ.get_stored_stealthChop_status(); + const bool chop_z = stepperZ.get_stored_stealthChop(); #else constexpr bool chop_z = false; #endif @@ -3695,17 +3694,17 @@ void MarlinSettings::reset() { } #if AXIS_HAS_STEALTHCHOP(X2) - const bool chop_x2 = stepperX2.get_stored_stealthChop_status(); + const bool chop_x2 = stepperX2.get_stored_stealthChop(); #else constexpr bool chop_x2 = false; #endif #if AXIS_HAS_STEALTHCHOP(Y2) - const bool chop_y2 = stepperY2.get_stored_stealthChop_status(); + const bool chop_y2 = stepperY2.get_stored_stealthChop(); #else constexpr bool chop_y2 = false; #endif #if AXIS_HAS_STEALTHCHOP(Z2) - const bool chop_z2 = stepperZ2.get_stored_stealthChop_status(); + const bool chop_z2 = stepperZ2.get_stored_stealthChop(); #else constexpr bool chop_z2 = false; #endif @@ -3719,36 +3718,36 @@ void MarlinSettings::reset() { } #if AXIS_HAS_STEALTHCHOP(Z3) - if (stepperZ3.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("I2 Z"), true); } + if (stepperZ3.get_stored_stealthChop()) { say_M569(forReplay, PSTR("I2 Z"), true); } #endif #if AXIS_HAS_STEALTHCHOP(Z4) - if (stepperZ4.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("I3 Z"), true); } + if (stepperZ4.get_stored_stealthChop()) { say_M569(forReplay, PSTR("I3 Z"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E0) - if (stepperE0.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T0 E"), true); } + if (stepperE0.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T0 E"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E1) - if (stepperE1.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T1 E"), true); } + if (stepperE1.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T1 E"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E2) - if (stepperE2.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T2 E"), true); } + if (stepperE2.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T2 E"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E3) - if (stepperE3.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T3 E"), true); } + if (stepperE3.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T3 E"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E4) - if (stepperE4.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T4 E"), true); } + if (stepperE4.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T4 E"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E5) - if (stepperE5.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T5 E"), true); } + if (stepperE5.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T5 E"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E6) - if (stepperE6.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T6 E"), true); } + if (stepperE6.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T6 E"), true); } #endif #if AXIS_HAS_STEALTHCHOP(E7) - if (stepperE7.get_stored_stealthChop_status()) { say_M569(forReplay, PSTR("T7 E"), true); } + if (stepperE7.get_stored_stealthChop()) { say_M569(forReplay, PSTR("T7 E"), true); } #endif #endif // HAS_STEALTHCHOP diff --git a/Marlin/src/module/stepper/trinamic.h b/Marlin/src/module/stepper/trinamic.h index 7ae2a276db..9f7445e4fd 100644 --- a/Marlin/src/module/stepper/trinamic.h +++ b/Marlin/src/module/stepper/trinamic.h @@ -144,7 +144,7 @@ void reset_trinamic_drivers(); #if HAS_X2_ENABLE && AXIS_IS_TMC(X2) extern TMC_CLASS(X2, X) stepperX2; #ifndef CHOPPER_TIMING_X2 - #define CHOPPER_TIMING_X2 CHOPPER_TIMING_E + #define CHOPPER_TIMING_X2 CHOPPER_TIMING_X #endif static constexpr chopper_timing_t chopper_timing_X2 = CHOPPER_TIMING_X2; #if ENABLED(SOFTWARE_DRIVER_ENABLE) @@ -161,7 +161,7 @@ void reset_trinamic_drivers(); #if HAS_Y2_ENABLE && AXIS_IS_TMC(Y2) extern TMC_CLASS(Y2, Y) stepperY2; #ifndef CHOPPER_TIMING_Y2 - #define CHOPPER_TIMING_Y2 CHOPPER_TIMING_E + #define CHOPPER_TIMING_Y2 CHOPPER_TIMING_Y #endif static constexpr chopper_timing_t chopper_timing_Y2 = CHOPPER_TIMING_Y2; #if ENABLED(SOFTWARE_DRIVER_ENABLE) @@ -178,7 +178,7 @@ void reset_trinamic_drivers(); #if HAS_Z2_ENABLE && AXIS_IS_TMC(Z2) extern TMC_CLASS(Z2, Z) stepperZ2; #ifndef CHOPPER_TIMING_Z2 - #define CHOPPER_TIMING_Z2 CHOPPER_TIMING_E + #define CHOPPER_TIMING_Z2 CHOPPER_TIMING_Z #endif static constexpr chopper_timing_t chopper_timing_Z2 = CHOPPER_TIMING_Z2; #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Z2) @@ -195,7 +195,7 @@ void reset_trinamic_drivers(); #if HAS_Z3_ENABLE && AXIS_IS_TMC(Z3) extern TMC_CLASS(Z3, Z) stepperZ3; #ifndef CHOPPER_TIMING_Z3 - #define CHOPPER_TIMING_Z3 CHOPPER_TIMING_E + #define CHOPPER_TIMING_Z3 CHOPPER_TIMING_Z #endif static constexpr chopper_timing_t chopper_timing_Z3 = CHOPPER_TIMING_Z3; #if ENABLED(SOFTWARE_DRIVER_ENABLE) @@ -212,7 +212,7 @@ void reset_trinamic_drivers(); #if HAS_Z4_ENABLE && AXIS_IS_TMC(Z4) extern TMC_CLASS(Z4, Z) stepperZ4; #ifndef CHOPPER_TIMING_Z4 - #define CHOPPER_TIMING_Z4 CHOPPER_TIMING_E + #define CHOPPER_TIMING_Z4 CHOPPER_TIMING_Z #endif static constexpr chopper_timing_t chopper_timing_Z4 = CHOPPER_TIMING_Z4; #if ENABLED(SOFTWARE_DRIVER_ENABLE) diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h index f2afc23bc2..2b8682aac7 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -399,6 +399,11 @@ #define LCD_PINS_D5 P1_21 #define LCD_PINS_D6 P1_22 #define LCD_PINS_D7 P1_23 + + #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) + #define BTN_ENC_EN LCD_PINS_D7 // Detect the presence of the encoder + #endif + #endif #endif // !FYSETC_MINI_12864 diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h index 675d4b7262..0e75aa4a37 100644 --- a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h +++ b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h @@ -141,7 +141,7 @@ // Pins for DOGM SPI LCD Support #define DOGLCD_A0 26 #define DOGLCD_CS 24 -#define DOGLCD_MOSI -1 +#define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 #define BTN_EN1 23 diff --git a/Marlin/src/pins/mega/pins_GT2560_REV_A.h b/Marlin/src/pins/mega/pins_GT2560_REV_A.h index f481db2b96..2db030804c 100644 --- a/Marlin/src/pins/mega/pins_GT2560_REV_A.h +++ b/Marlin/src/pins/mega/pins_GT2560_REV_A.h @@ -116,6 +116,20 @@ #define DOGLCD_CS 21 #define BTN_EN1 40 #define BTN_EN2 42 + #elif ENABLED(FYSETC_MINI_12864) + // Disconnect EXP2-1 and EXP2-2, otherwise future firmware upload won't work. + #define DOGLCD_A0 20 + #define DOGLCD_CS 17 + + #define NEOPIXEL_PIN 21 + #define BTN_EN1 42 + #define BTN_EN2 40 + + #define LCD_RESET_PIN 16 + + #define DEFAULT_LCD_CONTRAST 220 + + #define LCD_BACKLIGHT_PIN -1 #else #define LCD_PINS_RS 20 #define LCD_PINS_ENABLE 17 diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h index 3a380def74..4f3397b98d 100644 --- a/Marlin/src/pins/pins.h +++ b/Marlin/src/pins/pins.h @@ -21,9 +21,9 @@ */ #pragma once -#include "../core/boards.h" - /** + * File: pins/pins.h + * * Include pins definitions * * Pins numbering schemes: @@ -318,7 +318,7 @@ #elif MB(AZTEEG_X1) #include "sanguino/pins_AZTEEG_X1.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p #elif MB(ZMIB_V2) - #include "sanguino/pins_ZMIB_V2.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p + #include "sanguino/pins_ZMIB_V2.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p // // Other ATmega644P, ATmega644, ATmega1284P @@ -783,852 +783,7 @@ #endif -// Define certain undefined pins -#ifndef X_MS1_PIN - #define X_MS1_PIN -1 -#endif -#ifndef X_MS2_PIN - #define X_MS2_PIN -1 -#endif -#ifndef X_MS3_PIN - #define X_MS3_PIN -1 -#endif -#ifndef Y_MS1_PIN - #define Y_MS1_PIN -1 -#endif -#ifndef Y_MS2_PIN - #define Y_MS2_PIN -1 -#endif -#ifndef Y_MS3_PIN - #define Y_MS3_PIN -1 -#endif -#ifndef Z_MS1_PIN - #define Z_MS1_PIN -1 -#endif -#ifndef Z_MS2_PIN - #define Z_MS2_PIN -1 -#endif -#ifndef Z_MS3_PIN - #define Z_MS3_PIN -1 -#endif -#ifndef E0_MS1_PIN - #define E0_MS1_PIN -1 -#endif -#ifndef E0_MS2_PIN - #define E0_MS2_PIN -1 -#endif -#ifndef E0_MS3_PIN - #define E0_MS3_PIN -1 -#endif -#ifndef E1_MS1_PIN - #define E1_MS1_PIN -1 -#endif -#ifndef E1_MS2_PIN - #define E1_MS2_PIN -1 -#endif -#ifndef E1_MS3_PIN - #define E1_MS3_PIN -1 -#endif -#ifndef E2_MS1_PIN - #define E2_MS1_PIN -1 -#endif -#ifndef E2_MS2_PIN - #define E2_MS2_PIN -1 -#endif -#ifndef E2_MS3_PIN - #define E2_MS3_PIN -1 -#endif -#ifndef E3_MS1_PIN - #define E3_MS1_PIN -1 -#endif -#ifndef E3_MS2_PIN - #define E3_MS2_PIN -1 -#endif -#ifndef E3_MS3_PIN - #define E3_MS3_PIN -1 -#endif -#ifndef E4_MS1_PIN - #define E4_MS1_PIN -1 -#endif -#ifndef E4_MS2_PIN - #define E4_MS2_PIN -1 -#endif -#ifndef E4_MS3_PIN - #define E4_MS3_PIN -1 -#endif -#ifndef E5_MS1_PIN - #define E5_MS1_PIN -1 -#endif -#ifndef E5_MS2_PIN - #define E5_MS2_PIN -1 -#endif -#ifndef E5_MS3_PIN - #define E5_MS3_PIN -1 -#endif -#ifndef E6_MS1_PIN - #define E6_MS1_PIN -1 -#endif -#ifndef E6_MS2_PIN - #define E6_MS2_PIN -1 -#endif -#ifndef E6_MS3_PIN - #define E6_MS3_PIN -1 -#endif -#ifndef E7_MS1_PIN - #define E7_MS1_PIN -1 -#endif -#ifndef E7_MS2_PIN - #define E7_MS2_PIN -1 -#endif -#ifndef E7_MS3_PIN - #define E7_MS3_PIN -1 -#endif - -#ifndef E0_STEP_PIN - #define E0_STEP_PIN -1 -#endif -#ifndef E0_DIR_PIN - #define E0_DIR_PIN -1 -#endif -#ifndef E0_ENABLE_PIN - #define E0_ENABLE_PIN -1 -#endif -#ifndef E1_STEP_PIN - #define E1_STEP_PIN -1 -#endif -#ifndef E1_DIR_PIN - #define E1_DIR_PIN -1 -#endif -#ifndef E1_ENABLE_PIN - #define E1_ENABLE_PIN -1 -#endif -#ifndef E2_STEP_PIN - #define E2_STEP_PIN -1 -#endif -#ifndef E2_DIR_PIN - #define E2_DIR_PIN -1 -#endif -#ifndef E2_ENABLE_PIN - #define E2_ENABLE_PIN -1 -#endif -#ifndef E3_STEP_PIN - #define E3_STEP_PIN -1 -#endif -#ifndef E3_DIR_PIN - #define E3_DIR_PIN -1 -#endif -#ifndef E3_ENABLE_PIN - #define E3_ENABLE_PIN -1 -#endif -#ifndef E4_STEP_PIN - #define E4_STEP_PIN -1 -#endif -#ifndef E4_DIR_PIN - #define E4_DIR_PIN -1 -#endif -#ifndef E4_ENABLE_PIN - #define E4_ENABLE_PIN -1 -#endif -#ifndef E5_STEP_PIN - #define E5_STEP_PIN -1 -#endif -#ifndef E5_DIR_PIN - #define E5_DIR_PIN -1 -#endif -#ifndef E5_ENABLE_PIN - #define E5_ENABLE_PIN -1 -#endif -#ifndef E6_STEP_PIN - #define E6_STEP_PIN -1 -#endif -#ifndef E6_DIR_PIN - #define E6_DIR_PIN -1 -#endif -#ifndef E6_ENABLE_PIN - #define E6_ENABLE_PIN -1 -#endif -#ifndef E7_STEP_PIN - #define E7_STEP_PIN -1 -#endif -#ifndef E7_DIR_PIN - #define E7_DIR_PIN -1 -#endif -#ifndef E7_ENABLE_PIN - #define E7_ENABLE_PIN -1 -#endif - // -// Destroy unused CS pins +// Post-process pins according to configured settings // -#if !AXIS_HAS_SPI(X) - #undef X_CS_PIN -#endif -#if !AXIS_HAS_SPI(Y) - #undef Y_CS_PIN -#endif -#if !AXIS_HAS_SPI(Z) - #undef Z_CS_PIN -#endif -#if E_STEPPERS && !AXIS_HAS_SPI(E0) - #undef E0_CS_PIN -#endif -#if E_STEPPERS > 1 && !AXIS_HAS_SPI(E1) - #undef E1_CS_PIN -#endif -#if E_STEPPERS > 2 && !AXIS_HAS_SPI(E2) - #undef E2_CS_PIN -#endif -#if E_STEPPERS > 3 && !AXIS_HAS_SPI(E3) - #undef E3_CS_PIN -#endif -#if E_STEPPERS > 4 && !AXIS_HAS_SPI(E4) - #undef E4_CS_PIN -#endif -#if E_STEPPERS > 5 && !AXIS_HAS_SPI(E5) - #undef E5_CS_PIN -#endif -#if E_STEPPERS > 6 && !AXIS_HAS_SPI(E6) - #undef E6_CS_PIN -#endif -#if E_STEPPERS > 7 && !AXIS_HAS_SPI(E7) - #undef E7_CS_PIN -#endif - -#ifndef X_CS_PIN - #define X_CS_PIN -1 -#endif -#ifndef Y_CS_PIN - #define Y_CS_PIN -1 -#endif -#ifndef Z_CS_PIN - #define Z_CS_PIN -1 -#endif -#ifndef E0_CS_PIN - #define E0_CS_PIN -1 -#endif -#ifndef E1_CS_PIN - #define E1_CS_PIN -1 -#endif -#ifndef E2_CS_PIN - #define E2_CS_PIN -1 -#endif -#ifndef E3_CS_PIN - #define E3_CS_PIN -1 -#endif -#ifndef E4_CS_PIN - #define E4_CS_PIN -1 -#endif -#ifndef E5_CS_PIN - #define E5_CS_PIN -1 -#endif -#ifndef E6_CS_PIN - #define E6_CS_PIN -1 -#endif -#ifndef E7_CS_PIN - #define E7_CS_PIN -1 -#endif - -#ifndef FAN_PIN - #define FAN_PIN -1 -#endif -#define FAN0_PIN FAN_PIN -#ifndef FAN1_PIN - #define FAN1_PIN -1 -#endif -#ifndef FAN2_PIN - #define FAN2_PIN -1 -#endif -#ifndef CONTROLLER_FAN_PIN - #define CONTROLLER_FAN_PIN -1 -#endif - -#ifndef FANMUX0_PIN - #define FANMUX0_PIN -1 -#endif -#ifndef FANMUX1_PIN - #define FANMUX1_PIN -1 -#endif -#ifndef FANMUX2_PIN - #define FANMUX2_PIN -1 -#endif - -#ifndef HEATER_0_PIN - #define HEATER_0_PIN -1 -#endif -#ifndef HEATER_1_PIN - #define HEATER_1_PIN -1 -#endif -#ifndef HEATER_2_PIN - #define HEATER_2_PIN -1 -#endif -#ifndef HEATER_3_PIN - #define HEATER_3_PIN -1 -#endif -#ifndef HEATER_4_PIN - #define HEATER_4_PIN -1 -#endif -#ifndef HEATER_5_PIN - #define HEATER_5_PIN -1 -#endif -#ifndef HEATER_6_PIN - #define HEATER_6_PIN -1 -#endif -#ifndef HEATER_7_PIN - #define HEATER_7_PIN -1 -#endif -#ifndef HEATER_BED_PIN - #define HEATER_BED_PIN -1 -#endif - -#ifndef TEMP_0_PIN - #define TEMP_0_PIN -1 -#endif -#ifndef TEMP_1_PIN - #define TEMP_1_PIN -1 -#endif -#ifndef TEMP_2_PIN - #define TEMP_2_PIN -1 -#endif -#ifndef TEMP_3_PIN - #define TEMP_3_PIN -1 -#endif -#ifndef TEMP_4_PIN - #define TEMP_4_PIN -1 -#endif -#ifndef TEMP_5_PIN - #define TEMP_5_PIN -1 -#endif -#ifndef TEMP_6_PIN - #define TEMP_6_PIN -1 -#endif -#ifndef TEMP_7_PIN - #define TEMP_7_PIN -1 -#endif -#ifndef TEMP_BED_PIN - #define TEMP_BED_PIN -1 -#endif - -#ifndef SD_DETECT_PIN - #define SD_DETECT_PIN -1 -#endif -#ifndef SDPOWER_PIN - #define SDPOWER_PIN -1 -#endif -#ifndef SDSS - #define SDSS -1 -#endif -#ifndef LED_PIN - #define LED_PIN -1 -#endif -#if DISABLED(PSU_CONTROL) || !defined(PS_ON_PIN) - #undef PS_ON_PIN - #define PS_ON_PIN -1 -#endif -#ifndef KILL_PIN - #define KILL_PIN -1 -#endif -#ifndef SUICIDE_PIN - #define SUICIDE_PIN -1 -#endif -#ifndef SUICIDE_PIN_INVERTING - #define SUICIDE_PIN_INVERTING false -#endif - -#ifndef NUM_SERVO_PLUGS - #define NUM_SERVO_PLUGS 4 -#endif - -// -// Assign endstop pins for boards with only 3 connectors -// -#ifdef X_STOP_PIN - #if X_HOME_DIR < 0 - #define X_MIN_PIN X_STOP_PIN - #ifndef X_MAX_PIN - #define X_MAX_PIN -1 - #endif - #else - #define X_MAX_PIN X_STOP_PIN - #ifndef X_MIN_PIN - #define X_MIN_PIN -1 - #endif - #endif -#elif X_HOME_DIR < 0 - #define X_STOP_PIN X_MIN_PIN -#else - #define X_STOP_PIN X_MAX_PIN -#endif - -#ifdef Y_STOP_PIN - #if Y_HOME_DIR < 0 - #define Y_MIN_PIN Y_STOP_PIN - #ifndef Y_MAX_PIN - #define Y_MAX_PIN -1 - #endif - #else - #define Y_MAX_PIN Y_STOP_PIN - #ifndef Y_MIN_PIN - #define Y_MIN_PIN -1 - #endif - #endif -#elif Y_HOME_DIR < 0 - #define Y_STOP_PIN Y_MIN_PIN -#else - #define Y_STOP_PIN Y_MAX_PIN -#endif - -#ifdef Z_STOP_PIN - #if Z_HOME_DIR < 0 - #define Z_MIN_PIN Z_STOP_PIN - #ifndef Z_MAX_PIN - #define Z_MAX_PIN -1 - #endif - #else - #define Z_MAX_PIN Z_STOP_PIN - #ifndef Z_MIN_PIN - #define Z_MIN_PIN -1 - #endif - #endif -#elif Z_HOME_DIR < 0 - #define Z_STOP_PIN Z_MIN_PIN -#else - #define Z_STOP_PIN Z_MAX_PIN -#endif - -// -// Disable unused endstop / probe pins -// -#if !HAS_CUSTOM_PROBE_PIN - #undef Z_MIN_PROBE_PIN - #define Z_MIN_PROBE_PIN -1 -#endif - -#if DISABLED(USE_XMAX_PLUG) - #undef X_MAX_PIN - #define X_MAX_PIN -1 -#endif - -#if DISABLED(USE_YMAX_PLUG) - #undef Y_MAX_PIN - #define Y_MAX_PIN -1 -#endif - -#if DISABLED(USE_ZMAX_PLUG) - #undef Z_MAX_PIN - #define Z_MAX_PIN -1 -#endif - -#if DISABLED(USE_XMIN_PLUG) - #undef X_MIN_PIN - #define X_MIN_PIN -1 -#endif - -#if DISABLED(USE_YMIN_PLUG) - #undef Y_MIN_PIN - #define Y_MIN_PIN -1 -#endif - -#if DISABLED(USE_ZMIN_PLUG) - #undef Z_MIN_PIN - #define Z_MIN_PIN -1 -#endif - -#if HAS_FILAMENT_SENSOR - #define FIL_RUNOUT1_PIN FIL_RUNOUT_PIN -#else - #undef FIL_RUNOUT_PIN - #undef FIL_RUNOUT1_PIN -#endif - -#ifndef LCD_PINS_D4 - #define LCD_PINS_D4 -1 -#endif - -#if HAS_MARLINUI_HD44780 || TOUCH_UI_ULTIPANEL - #ifndef LCD_PINS_D5 - #define LCD_PINS_D5 -1 - #endif - #ifndef LCD_PINS_D6 - #define LCD_PINS_D6 -1 - #endif - #ifndef LCD_PINS_D7 - #define LCD_PINS_D7 -1 - #endif -#endif - -/** - * Auto-Assignment for Dual X, Dual Y, Multi-Z Steppers - * - * By default X2 is assigned to the next open E plug - * on the board, then in order, Y2, Z2, Z3. These can be - * overridden in Configuration.h or Configuration_adv.h. - */ - -#define __PEXI(p,q) PIN_EXISTS(E##p##_##q) -#define _PEXI(p,q) __PEXI(p,q) -#define __EPIN(p,q) E##p##_##q##_PIN -#define _EPIN(p,q) __EPIN(p,q) -#define DIAG_REMAPPED(p,q) (PIN_EXISTS(q) && _EPIN(p##_E_INDEX, DIAG) == q##_PIN) - -// The X2 axis, if any, should be the next open extruder port -#define X2_E_INDEX E_STEPPERS - -#if EITHER(DUAL_X_CARRIAGE, X_DUAL_STEPPER_DRIVERS) - #ifndef X2_STEP_PIN - #define X2_STEP_PIN _EPIN(X2_E_INDEX, STEP) - #define X2_DIR_PIN _EPIN(X2_E_INDEX, DIR) - #define X2_ENABLE_PIN _EPIN(X2_E_INDEX, ENABLE) - #if X2_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(X2_STEP) - #error "No E stepper plug left for X2!" - #endif - #endif - #ifndef X2_MS1_PIN - #define X2_MS1_PIN _EPIN(X2_E_INDEX, MS1) - #endif - #ifndef X2_MS2_PIN - #define X2_MS2_PIN _EPIN(X2_E_INDEX, MS2) - #endif - #ifndef X2_MS3_PIN - #define X2_MS3_PIN _EPIN(X2_E_INDEX, MS3) - #endif - #if AXIS_HAS_SPI(X2) && !defined(X2_CS_PIN) - #define X2_CS_PIN _EPIN(X2_E_INDEX, CS) - #endif - #if AXIS_HAS_UART(X2) - #ifndef X2_SERIAL_TX_PIN - #define X2_SERIAL_TX_PIN _EPIN(X2_E_INDEX, SERIAL_TX) - #endif - #ifndef X2_SERIAL_RX_PIN - #define X2_SERIAL_RX_PIN _EPIN(X2_E_INDEX, SERIAL_RX) - #endif - #endif - - // - // Auto-assign pins for stallGuard sensorless homing - // - #if defined(X2_STALL_SENSITIVITY) && ENABLED(X_DUAL_ENDSTOPS) && _PEXI(X2_E_INDEX, DIAG) - #define X2_DIAG_PIN _EPIN(X2_E_INDEX, DIAG) - #if DIAG_REMAPPED(X2, X_MIN) // If already remapped in the pins file... - #define X2_USE_ENDSTOP _XMIN_ - #elif DIAG_REMAPPED(X2, Y_MIN) - #define X2_USE_ENDSTOP _YMIN_ - #elif DIAG_REMAPPED(X2, Z_MIN) - #define X2_USE_ENDSTOP _ZMIN_ - #elif DIAG_REMAPPED(X2, X_MAX) - #define X2_USE_ENDSTOP _XMAX_ - #elif DIAG_REMAPPED(X2, Y_MAX) - #define X2_USE_ENDSTOP _YMAX_ - #elif DIAG_REMAPPED(X2, Z_MAX) - #define X2_USE_ENDSTOP _ZMAX_ - #else // Otherwise use the driver DIAG_PIN directly - #define _X2_USE_ENDSTOP(P) _E##P##_DIAG_ - #define X2_USE_ENDSTOP _X2_USE_ENDSTOP(X2_E_INDEX) - #endif - #undef X2_DIAG_PIN - #endif - - #define Y2_E_INDEX INCREMENT(X2_E_INDEX) -#else - #define Y2_E_INDEX X2_E_INDEX -#endif - -#ifndef X2_CS_PIN - #define X2_CS_PIN -1 -#endif -#ifndef X2_MS1_PIN - #define X2_MS1_PIN -1 -#endif -#ifndef X2_MS2_PIN - #define X2_MS2_PIN -1 -#endif -#ifndef X2_MS3_PIN - #define X2_MS3_PIN -1 -#endif - -// The Y2 axis, if any, should be the next open extruder port -#if ENABLED(Y_DUAL_STEPPER_DRIVERS) - #ifndef Y2_STEP_PIN - #define Y2_STEP_PIN _EPIN(Y2_E_INDEX, STEP) - #define Y2_DIR_PIN _EPIN(Y2_E_INDEX, DIR) - #define Y2_ENABLE_PIN _EPIN(Y2_E_INDEX, ENABLE) - #if Y2_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Y2_STEP) - #error "No E stepper plug left for Y2!" - #endif - #endif - #ifndef Y2_MS1_PIN - #define Y2_MS1_PIN _EPIN(Y2_E_INDEX, MS1) - #endif - #ifndef Y2_MS2_PIN - #define Y2_MS2_PIN _EPIN(Y2_E_INDEX, MS2) - #endif - #ifndef Y2_MS3_PIN - #define Y2_MS3_PIN _EPIN(Y2_E_INDEX, MS3) - #endif - #if AXIS_HAS_SPI(Y2) && !defined(Y2_CS_PIN) - #define Y2_CS_PIN _EPIN(Y2_E_INDEX, CS) - #endif - #if AXIS_HAS_UART(Y2) - #ifndef Y2_SERIAL_TX_PIN - #define Y2_SERIAL_TX_PIN _EPIN(Y2_E_INDEX, SERIAL_TX) - #endif - #ifndef Y2_SERIAL_RX_PIN - #define Y2_SERIAL_RX_PIN _EPIN(Y2_E_INDEX, SERIAL_RX) - #endif - #endif - #if defined(Y2_STALL_SENSITIVITY) && ENABLED(Y_DUAL_ENDSTOPS) && _PEXI(Y2_E_INDEX, DIAG) - #define Y2_DIAG_PIN _EPIN(Y2_E_INDEX, DIAG) - #if DIAG_REMAPPED(Y2, X_MIN) - #define Y2_USE_ENDSTOP _XMIN_ - #elif DIAG_REMAPPED(Y2, Y_MIN) - #define Y2_USE_ENDSTOP _YMIN_ - #elif DIAG_REMAPPED(Y2, Z_MIN) - #define Y2_USE_ENDSTOP _ZMIN_ - #elif DIAG_REMAPPED(Y2, X_MAX) - #define Y2_USE_ENDSTOP _XMAX_ - #elif DIAG_REMAPPED(Y2, Y_MAX) - #define Y2_USE_ENDSTOP _YMAX_ - #elif DIAG_REMAPPED(Y2, Z_MAX) - #define Y2_USE_ENDSTOP _ZMAX_ - #else - #define _Y2_USE_ENDSTOP(P) _E##P##_DIAG_ - #define Y2_USE_ENDSTOP _Y2_USE_ENDSTOP(Y2_E_INDEX) - #endif - #undef Y2_DIAG_PIN - #endif - #define Z2_E_INDEX INCREMENT(Y2_E_INDEX) -#else - #define Z2_E_INDEX Y2_E_INDEX -#endif - -#ifndef Y2_CS_PIN - #define Y2_CS_PIN -1 -#endif -#ifndef Y2_MS1_PIN - #define Y2_MS1_PIN -1 -#endif -#ifndef Y2_MS2_PIN - #define Y2_MS2_PIN -1 -#endif -#ifndef Y2_MS3_PIN - #define Y2_MS3_PIN -1 -#endif - -// The Z2 axis, if any, should be the next open extruder port -#if NUM_Z_STEPPER_DRIVERS >= 2 - #ifndef Z2_STEP_PIN - #define Z2_STEP_PIN _EPIN(Z2_E_INDEX, STEP) - #define Z2_DIR_PIN _EPIN(Z2_E_INDEX, DIR) - #define Z2_ENABLE_PIN _EPIN(Z2_E_INDEX, ENABLE) - #if Z2_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Z2_STEP) - #error "No E stepper plug left for Z2!" - #endif - #endif - #ifndef Z2_MS1_PIN - #define Z2_MS1_PIN _EPIN(Z2_E_INDEX, MS1) - #endif - #ifndef Z2_MS2_PIN - #define Z2_MS2_PIN _EPIN(Z2_E_INDEX, MS2) - #endif - #ifndef Z2_MS3_PIN - #define Z2_MS3_PIN _EPIN(Z2_E_INDEX, MS3) - #endif - #if AXIS_HAS_SPI(Z2) && !defined(Z2_CS_PIN) - #define Z2_CS_PIN _EPIN(Z2_E_INDEX, CS) - #endif - #if AXIS_HAS_UART(Z2) - #ifndef Z2_SERIAL_TX_PIN - #define Z2_SERIAL_TX_PIN _EPIN(Z2_E_INDEX, SERIAL_TX) - #endif - #ifndef Z2_SERIAL_RX_PIN - #define Z2_SERIAL_RX_PIN _EPIN(Z2_E_INDEX, SERIAL_RX) - #endif - #endif - #if defined(Z2_STALL_SENSITIVITY) && ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 2 && _PEXI(Z2_E_INDEX, DIAG) - #define Z2_DIAG_PIN _EPIN(Z2_E_INDEX, DIAG) - #if DIAG_REMAPPED(Z2, X_MIN) - #define Z2_USE_ENDSTOP _XMIN_ - #elif DIAG_REMAPPED(Z2, Y_MIN) - #define Z2_USE_ENDSTOP _YMIN_ - #elif DIAG_REMAPPED(Z2, Z_MIN) - #define Z2_USE_ENDSTOP _ZMIN_ - #elif DIAG_REMAPPED(Z2, X_MAX) - #define Z2_USE_ENDSTOP _XMAX_ - #elif DIAG_REMAPPED(Z2, Y_MAX) - #define Z2_USE_ENDSTOP _YMAX_ - #elif DIAG_REMAPPED(Z2, Z_MAX) - #define Z2_USE_ENDSTOP _ZMAX_ - #else - #define _Z2_USE_ENDSTOP(P) _E##P##_DIAG_ - #define Z2_USE_ENDSTOP _Z2_USE_ENDSTOP(Z2_E_INDEX) - #endif - #undef Z2_DIAG_PIN - #endif - #define Z3_E_INDEX INCREMENT(Z2_E_INDEX) -#else - #define Z3_E_INDEX Z2_E_INDEX -#endif - -#ifndef Z2_CS_PIN - #define Z2_CS_PIN -1 -#endif -#ifndef Z2_MS1_PIN - #define Z2_MS1_PIN -1 -#endif -#ifndef Z2_MS2_PIN - #define Z2_MS2_PIN -1 -#endif -#ifndef Z2_MS3_PIN - #define Z2_MS3_PIN -1 -#endif - -#if NUM_Z_STEPPER_DRIVERS >= 3 - #ifndef Z3_STEP_PIN - #define Z3_STEP_PIN _EPIN(Z3_E_INDEX, STEP) - #define Z3_DIR_PIN _EPIN(Z3_E_INDEX, DIR) - #define Z3_ENABLE_PIN _EPIN(Z3_E_INDEX, ENABLE) - #if Z3_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Z3_STEP) - #error "No E stepper plug left for Z3!" - #endif - #endif - #if AXIS_HAS_SPI(Z3) - #ifndef Z3_CS_PIN - #define Z3_CS_PIN _EPIN(Z3_E_INDEX, CS) - #endif - #endif - #ifndef Z3_MS1_PIN - #define Z3_MS1_PIN _EPIN(Z3_E_INDEX, MS1) - #endif - #ifndef Z3_MS2_PIN - #define Z3_MS2_PIN _EPIN(Z3_E_INDEX, MS2) - #endif - #ifndef Z3_MS3_PIN - #define Z3_MS3_PIN _EPIN(Z3_E_INDEX, MS3) - #endif - #if AXIS_HAS_UART(Z3) - #ifndef Z3_SERIAL_TX_PIN - #define Z3_SERIAL_TX_PIN _EPIN(Z3_E_INDEX, SERIAL_TX) - #endif - #ifndef Z3_SERIAL_RX_PIN - #define Z3_SERIAL_RX_PIN _EPIN(Z3_E_INDEX, SERIAL_RX) - #endif - #endif - #if defined(Z3_STALL_SENSITIVITY) && ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3 && _PEXI(Z3_E_INDEX, DIAG) - #define Z3_DIAG_PIN _EPIN(Z3_E_INDEX, DIAG) - #if DIAG_REMAPPED(Z3, X_MIN) - #define Z3_USE_ENDSTOP _XMIN_ - #elif DIAG_REMAPPED(Z3, Y_MIN) - #define Z3_USE_ENDSTOP _YMIN_ - #elif DIAG_REMAPPED(Z3, Z_MIN) - #define Z3_USE_ENDSTOP _ZMIN_ - #elif DIAG_REMAPPED(Z3, X_MAX) - #define Z3_USE_ENDSTOP _XMAX_ - #elif DIAG_REMAPPED(Z3, Y_MAX) - #define Z3_USE_ENDSTOP _YMAX_ - #elif DIAG_REMAPPED(Z3, Z_MAX) - #define Z3_USE_ENDSTOP _ZMAX_ - #else - #define _Z3_USE_ENDSTOP(P) _E##P##_DIAG_ - #define Z3_USE_ENDSTOP _Z3_USE_ENDSTOP(Z3_E_INDEX) - #endif - #undef Z3_DIAG_PIN - #endif - #define Z4_E_INDEX INCREMENT(Z3_E_INDEX) -#endif - -#ifndef Z3_CS_PIN - #define Z3_CS_PIN -1 -#endif -#ifndef Z3_MS1_PIN - #define Z3_MS1_PIN -1 -#endif -#ifndef Z3_MS2_PIN - #define Z3_MS2_PIN -1 -#endif -#ifndef Z3_MS3_PIN - #define Z3_MS3_PIN -1 -#endif - -#if NUM_Z_STEPPER_DRIVERS >= 4 - #ifndef Z4_STEP_PIN - #define Z4_STEP_PIN _EPIN(Z4_E_INDEX, STEP) - #define Z4_DIR_PIN _EPIN(Z4_E_INDEX, DIR) - #define Z4_ENABLE_PIN _EPIN(Z4_E_INDEX, ENABLE) - #if Z4_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Z4_STEP) - #error "No E stepper plug left for Z4!" - #endif - #endif - #if AXIS_HAS_SPI(Z4) - #ifndef Z4_CS_PIN - #define Z4_CS_PIN _EPIN(Z4_E_INDEX, CS) - #endif - #endif - #ifndef Z4_MS1_PIN - #define Z4_MS1_PIN _EPIN(Z4_E_INDEX, MS1) - #endif - #ifndef Z4_MS2_PIN - #define Z4_MS2_PIN _EPIN(Z4_E_INDEX, MS2) - #endif - #ifndef Z4_MS3_PIN - #define Z4_MS3_PIN _EPIN(Z4_E_INDEX, MS3) - #endif - #if AXIS_HAS_UART(Z4) - #ifndef Z4_SERIAL_TX_PIN - #define Z4_SERIAL_TX_PIN _EPIN(Z4_E_INDEX, SERIAL_TX) - #endif - #ifndef Z4_SERIAL_RX_PIN - #define Z4_SERIAL_RX_PIN _EPIN(Z4_E_INDEX, SERIAL_RX) - #endif - #endif - #if defined(Z4_STALL_SENSITIVITY) && ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4 && _PEXI(Z4_E_INDEX, DIAG) - #define Z4_DIAG_PIN _EPIN(Z4_E_INDEX, DIAG) - #if DIAG_REMAPPED(Z4, X_MIN) - #define Z4_USE_ENDSTOP _XMIN_ - #elif DIAG_REMAPPED(Z4, Y_MIN) - #define Z4_USE_ENDSTOP _YMIN_ - #elif DIAG_REMAPPED(Z4, Z_MIN) - #define Z4_USE_ENDSTOP _ZMIN_ - #elif DIAG_REMAPPED(Z4, X_MAX) - #define Z4_USE_ENDSTOP _XMAX_ - #elif DIAG_REMAPPED(Z4, Y_MAX) - #define Z4_USE_ENDSTOP _YMAX_ - #elif DIAG_REMAPPED(Z4, Z_MAX) - #define Z4_USE_ENDSTOP _ZMAX_ - #else - #define _Z4_USE_ENDSTOP(P) _E##P##_DIAG_ - #define Z4_USE_ENDSTOP _Z4_USE_ENDSTOP(Z4_E_INDEX) - #endif - #undef Z4_DIAG_PIN - #endif -#endif - -#ifndef Z4_CS_PIN - #define Z4_CS_PIN -1 -#endif -#ifndef Z4_MS1_PIN - #define Z4_MS1_PIN -1 -#endif -#ifndef Z4_MS2_PIN - #define Z4_MS2_PIN -1 -#endif -#ifndef Z4_MS3_PIN - #define Z4_MS3_PIN -1 -#endif - -#if HAS_MARLINUI_U8GLIB - #if !defined(ST7920_DELAY_1) && defined(BOARD_ST7920_DELAY_1) - #define ST7920_DELAY_1 BOARD_ST7920_DELAY_1 - #endif - #if !defined(ST7920_DELAY_2) && defined(BOARD_ST7920_DELAY_2) - #define ST7920_DELAY_2 BOARD_ST7920_DELAY_2 - #endif - #if !defined(ST7920_DELAY_3) && defined(BOARD_ST7920_DELAY_3) - #define ST7920_DELAY_3 BOARD_ST7920_DELAY_3 - #endif -#else - #undef ST7920_DELAY_1 - #undef ST7920_DELAY_2 - #undef ST7920_DELAY_3 -#endif - -#undef HAS_FREE_AUX2_PINS -#undef DIAG_REMAPPED +#include "pins_postprocess.h" diff --git a/Marlin/src/pins/pinsDebug_list.h b/Marlin/src/pins/pinsDebug_list.h index 704f2a487f..cf839e2abd 100644 --- a/Marlin/src/pins/pinsDebug_list.h +++ b/Marlin/src/pins/pinsDebug_list.h @@ -147,6 +147,9 @@ #if defined(BTN_EN2) && BTN_EN2 >= 0 REPORT_NAME_DIGITAL(__LINE__, BTN_EN2) #endif +#if defined(BTN_ENC_EN) && BTN_ENC_EN >= 0 + REPORT_NAME_DIGITAL(__LINE__, BTN_ENC_EN) +#endif #if defined(BTN_ENC) && BTN_ENC >= 0 REPORT_NAME_DIGITAL(__LINE__, BTN_ENC) #endif diff --git a/Marlin/src/pins/pins_postprocess.h b/Marlin/src/pins/pins_postprocess.h new file mode 100644 index 0000000000..fdf9f095cb --- /dev/null +++ b/Marlin/src/pins/pins_postprocess.h @@ -0,0 +1,877 @@ +/** + * 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 . + * + */ +#pragma once + +// +// File: pins/pins_postprocess.h +// Post-process pins according to configured settings +// + +// Define certain undefined pins +#ifndef X_MS1_PIN + #define X_MS1_PIN -1 +#endif +#ifndef X_MS2_PIN + #define X_MS2_PIN -1 +#endif +#ifndef X_MS3_PIN + #define X_MS3_PIN -1 +#endif +#ifndef Y_MS1_PIN + #define Y_MS1_PIN -1 +#endif +#ifndef Y_MS2_PIN + #define Y_MS2_PIN -1 +#endif +#ifndef Y_MS3_PIN + #define Y_MS3_PIN -1 +#endif +#ifndef Z_MS1_PIN + #define Z_MS1_PIN -1 +#endif +#ifndef Z_MS2_PIN + #define Z_MS2_PIN -1 +#endif +#ifndef Z_MS3_PIN + #define Z_MS3_PIN -1 +#endif +#ifndef E0_MS1_PIN + #define E0_MS1_PIN -1 +#endif +#ifndef E0_MS2_PIN + #define E0_MS2_PIN -1 +#endif +#ifndef E0_MS3_PIN + #define E0_MS3_PIN -1 +#endif +#ifndef E1_MS1_PIN + #define E1_MS1_PIN -1 +#endif +#ifndef E1_MS2_PIN + #define E1_MS2_PIN -1 +#endif +#ifndef E1_MS3_PIN + #define E1_MS3_PIN -1 +#endif +#ifndef E2_MS1_PIN + #define E2_MS1_PIN -1 +#endif +#ifndef E2_MS2_PIN + #define E2_MS2_PIN -1 +#endif +#ifndef E2_MS3_PIN + #define E2_MS3_PIN -1 +#endif +#ifndef E3_MS1_PIN + #define E3_MS1_PIN -1 +#endif +#ifndef E3_MS2_PIN + #define E3_MS2_PIN -1 +#endif +#ifndef E3_MS3_PIN + #define E3_MS3_PIN -1 +#endif +#ifndef E4_MS1_PIN + #define E4_MS1_PIN -1 +#endif +#ifndef E4_MS2_PIN + #define E4_MS2_PIN -1 +#endif +#ifndef E4_MS3_PIN + #define E4_MS3_PIN -1 +#endif +#ifndef E5_MS1_PIN + #define E5_MS1_PIN -1 +#endif +#ifndef E5_MS2_PIN + #define E5_MS2_PIN -1 +#endif +#ifndef E5_MS3_PIN + #define E5_MS3_PIN -1 +#endif +#ifndef E6_MS1_PIN + #define E6_MS1_PIN -1 +#endif +#ifndef E6_MS2_PIN + #define E6_MS2_PIN -1 +#endif +#ifndef E6_MS3_PIN + #define E6_MS3_PIN -1 +#endif +#ifndef E7_MS1_PIN + #define E7_MS1_PIN -1 +#endif +#ifndef E7_MS2_PIN + #define E7_MS2_PIN -1 +#endif +#ifndef E7_MS3_PIN + #define E7_MS3_PIN -1 +#endif + +#ifndef E0_STEP_PIN + #define E0_STEP_PIN -1 +#endif +#ifndef E0_DIR_PIN + #define E0_DIR_PIN -1 +#endif +#ifndef E0_ENABLE_PIN + #define E0_ENABLE_PIN -1 +#endif +#ifndef E1_STEP_PIN + #define E1_STEP_PIN -1 +#endif +#ifndef E1_DIR_PIN + #define E1_DIR_PIN -1 +#endif +#ifndef E1_ENABLE_PIN + #define E1_ENABLE_PIN -1 +#endif +#ifndef E2_STEP_PIN + #define E2_STEP_PIN -1 +#endif +#ifndef E2_DIR_PIN + #define E2_DIR_PIN -1 +#endif +#ifndef E2_ENABLE_PIN + #define E2_ENABLE_PIN -1 +#endif +#ifndef E3_STEP_PIN + #define E3_STEP_PIN -1 +#endif +#ifndef E3_DIR_PIN + #define E3_DIR_PIN -1 +#endif +#ifndef E3_ENABLE_PIN + #define E3_ENABLE_PIN -1 +#endif +#ifndef E4_STEP_PIN + #define E4_STEP_PIN -1 +#endif +#ifndef E4_DIR_PIN + #define E4_DIR_PIN -1 +#endif +#ifndef E4_ENABLE_PIN + #define E4_ENABLE_PIN -1 +#endif +#ifndef E5_STEP_PIN + #define E5_STEP_PIN -1 +#endif +#ifndef E5_DIR_PIN + #define E5_DIR_PIN -1 +#endif +#ifndef E5_ENABLE_PIN + #define E5_ENABLE_PIN -1 +#endif +#ifndef E6_STEP_PIN + #define E6_STEP_PIN -1 +#endif +#ifndef E6_DIR_PIN + #define E6_DIR_PIN -1 +#endif +#ifndef E6_ENABLE_PIN + #define E6_ENABLE_PIN -1 +#endif +#ifndef E7_STEP_PIN + #define E7_STEP_PIN -1 +#endif +#ifndef E7_DIR_PIN + #define E7_DIR_PIN -1 +#endif +#ifndef E7_ENABLE_PIN + #define E7_ENABLE_PIN -1 +#endif + +// +// Destroy unused CS pins +// +#if !AXIS_HAS_SPI(X) + #undef X_CS_PIN +#endif +#if !AXIS_HAS_SPI(Y) + #undef Y_CS_PIN +#endif +#if !AXIS_HAS_SPI(Z) + #undef Z_CS_PIN +#endif +#if E_STEPPERS && !AXIS_HAS_SPI(E0) + #undef E0_CS_PIN +#endif +#if E_STEPPERS > 1 && !AXIS_HAS_SPI(E1) + #undef E1_CS_PIN +#endif +#if E_STEPPERS > 2 && !AXIS_HAS_SPI(E2) + #undef E2_CS_PIN +#endif +#if E_STEPPERS > 3 && !AXIS_HAS_SPI(E3) + #undef E3_CS_PIN +#endif +#if E_STEPPERS > 4 && !AXIS_HAS_SPI(E4) + #undef E4_CS_PIN +#endif +#if E_STEPPERS > 5 && !AXIS_HAS_SPI(E5) + #undef E5_CS_PIN +#endif +#if E_STEPPERS > 6 && !AXIS_HAS_SPI(E6) + #undef E6_CS_PIN +#endif +#if E_STEPPERS > 7 && !AXIS_HAS_SPI(E7) + #undef E7_CS_PIN +#endif + +#ifndef X_CS_PIN + #define X_CS_PIN -1 +#endif +#ifndef Y_CS_PIN + #define Y_CS_PIN -1 +#endif +#ifndef Z_CS_PIN + #define Z_CS_PIN -1 +#endif +#ifndef E0_CS_PIN + #define E0_CS_PIN -1 +#endif +#ifndef E1_CS_PIN + #define E1_CS_PIN -1 +#endif +#ifndef E2_CS_PIN + #define E2_CS_PIN -1 +#endif +#ifndef E3_CS_PIN + #define E3_CS_PIN -1 +#endif +#ifndef E4_CS_PIN + #define E4_CS_PIN -1 +#endif +#ifndef E5_CS_PIN + #define E5_CS_PIN -1 +#endif +#ifndef E6_CS_PIN + #define E6_CS_PIN -1 +#endif +#ifndef E7_CS_PIN + #define E7_CS_PIN -1 +#endif + +#ifndef FAN_PIN + #define FAN_PIN -1 +#endif +#define FAN0_PIN FAN_PIN +#ifndef FAN1_PIN + #define FAN1_PIN -1 +#endif +#ifndef FAN2_PIN + #define FAN2_PIN -1 +#endif +#ifndef CONTROLLER_FAN_PIN + #define CONTROLLER_FAN_PIN -1 +#endif + +#ifndef FANMUX0_PIN + #define FANMUX0_PIN -1 +#endif +#ifndef FANMUX1_PIN + #define FANMUX1_PIN -1 +#endif +#ifndef FANMUX2_PIN + #define FANMUX2_PIN -1 +#endif + +#ifndef HEATER_0_PIN + #define HEATER_0_PIN -1 +#endif +#ifndef HEATER_1_PIN + #define HEATER_1_PIN -1 +#endif +#ifndef HEATER_2_PIN + #define HEATER_2_PIN -1 +#endif +#ifndef HEATER_3_PIN + #define HEATER_3_PIN -1 +#endif +#ifndef HEATER_4_PIN + #define HEATER_4_PIN -1 +#endif +#ifndef HEATER_5_PIN + #define HEATER_5_PIN -1 +#endif +#ifndef HEATER_6_PIN + #define HEATER_6_PIN -1 +#endif +#ifndef HEATER_7_PIN + #define HEATER_7_PIN -1 +#endif +#ifndef HEATER_BED_PIN + #define HEATER_BED_PIN -1 +#endif + +#ifndef TEMP_0_PIN + #define TEMP_0_PIN -1 +#endif +#ifndef TEMP_1_PIN + #define TEMP_1_PIN -1 +#endif +#ifndef TEMP_2_PIN + #define TEMP_2_PIN -1 +#endif +#ifndef TEMP_3_PIN + #define TEMP_3_PIN -1 +#endif +#ifndef TEMP_4_PIN + #define TEMP_4_PIN -1 +#endif +#ifndef TEMP_5_PIN + #define TEMP_5_PIN -1 +#endif +#ifndef TEMP_6_PIN + #define TEMP_6_PIN -1 +#endif +#ifndef TEMP_7_PIN + #define TEMP_7_PIN -1 +#endif +#ifndef TEMP_BED_PIN + #define TEMP_BED_PIN -1 +#endif + +#ifndef SD_DETECT_PIN + #define SD_DETECT_PIN -1 +#endif +#ifndef SDPOWER_PIN + #define SDPOWER_PIN -1 +#endif +#ifndef SDSS + #define SDSS -1 +#endif +#ifndef LED_PIN + #define LED_PIN -1 +#endif +#if DISABLED(PSU_CONTROL) || !defined(PS_ON_PIN) + #undef PS_ON_PIN + #define PS_ON_PIN -1 +#endif +#ifndef KILL_PIN + #define KILL_PIN -1 +#endif +#ifndef SUICIDE_PIN + #define SUICIDE_PIN -1 +#endif +#ifndef SUICIDE_PIN_INVERTING + #define SUICIDE_PIN_INVERTING false +#endif + +#ifndef NUM_SERVO_PLUGS + #define NUM_SERVO_PLUGS 4 +#endif + +// +// Assign endstop pins for boards with only 3 connectors +// +#ifdef X_STOP_PIN + #if X_HOME_DIR < 0 + #define X_MIN_PIN X_STOP_PIN + #ifndef X_MAX_PIN + #define X_MAX_PIN -1 + #endif + #else + #define X_MAX_PIN X_STOP_PIN + #ifndef X_MIN_PIN + #define X_MIN_PIN -1 + #endif + #endif +#elif X_HOME_DIR < 0 + #define X_STOP_PIN X_MIN_PIN +#else + #define X_STOP_PIN X_MAX_PIN +#endif + +#ifdef Y_STOP_PIN + #if Y_HOME_DIR < 0 + #define Y_MIN_PIN Y_STOP_PIN + #ifndef Y_MAX_PIN + #define Y_MAX_PIN -1 + #endif + #else + #define Y_MAX_PIN Y_STOP_PIN + #ifndef Y_MIN_PIN + #define Y_MIN_PIN -1 + #endif + #endif +#elif Y_HOME_DIR < 0 + #define Y_STOP_PIN Y_MIN_PIN +#else + #define Y_STOP_PIN Y_MAX_PIN +#endif + +#ifdef Z_STOP_PIN + #if Z_HOME_DIR < 0 + #define Z_MIN_PIN Z_STOP_PIN + #ifndef Z_MAX_PIN + #define Z_MAX_PIN -1 + #endif + #else + #define Z_MAX_PIN Z_STOP_PIN + #ifndef Z_MIN_PIN + #define Z_MIN_PIN -1 + #endif + #endif +#elif Z_HOME_DIR < 0 + #define Z_STOP_PIN Z_MIN_PIN +#else + #define Z_STOP_PIN Z_MAX_PIN +#endif + +// +// Disable unused endstop / probe pins +// +#if !HAS_CUSTOM_PROBE_PIN + #undef Z_MIN_PROBE_PIN + #define Z_MIN_PROBE_PIN -1 +#endif + +#if DISABLED(USE_XMAX_PLUG) + #undef X_MAX_PIN + #define X_MAX_PIN -1 +#endif + +#if DISABLED(USE_YMAX_PLUG) + #undef Y_MAX_PIN + #define Y_MAX_PIN -1 +#endif + +#if DISABLED(USE_ZMAX_PLUG) + #undef Z_MAX_PIN + #define Z_MAX_PIN -1 +#endif + +#if DISABLED(USE_XMIN_PLUG) + #undef X_MIN_PIN + #define X_MIN_PIN -1 +#endif + +#if DISABLED(USE_YMIN_PLUG) + #undef Y_MIN_PIN + #define Y_MIN_PIN -1 +#endif + +#if DISABLED(USE_ZMIN_PLUG) + #undef Z_MIN_PIN + #define Z_MIN_PIN -1 +#endif + +#if HAS_FILAMENT_SENSOR + #define FIL_RUNOUT1_PIN FIL_RUNOUT_PIN +#else + #undef FIL_RUNOUT_PIN + #undef FIL_RUNOUT1_PIN +#endif + +#ifndef LCD_PINS_D4 + #define LCD_PINS_D4 -1 +#endif + +#if HAS_MARLINUI_HD44780 || TOUCH_UI_ULTIPANEL + #ifndef LCD_PINS_D5 + #define LCD_PINS_D5 -1 + #endif + #ifndef LCD_PINS_D6 + #define LCD_PINS_D6 -1 + #endif + #ifndef LCD_PINS_D7 + #define LCD_PINS_D7 -1 + #endif +#endif + +/** + * Auto-Assignment for Dual X, Dual Y, Multi-Z Steppers + * + * By default X2 is assigned to the next open E plug + * on the board, then in order, Y2, Z2, Z3. These can be + * overridden in Configuration.h or Configuration_adv.h. + */ + +#define __PEXI(p,q) PIN_EXISTS(E##p##_##q) +#define _PEXI(p,q) __PEXI(p,q) +#define __EPIN(p,q) E##p##_##q##_PIN +#define _EPIN(p,q) __EPIN(p,q) +#define DIAG_REMAPPED(p,q) (PIN_EXISTS(q) && _EPIN(p##_E_INDEX, DIAG) == q##_PIN) + +// The X2 axis, if any, should be the next open extruder port +#define X2_E_INDEX E_STEPPERS + +#if EITHER(DUAL_X_CARRIAGE, X_DUAL_STEPPER_DRIVERS) + #ifndef X2_STEP_PIN + #define X2_STEP_PIN _EPIN(X2_E_INDEX, STEP) + #define X2_DIR_PIN _EPIN(X2_E_INDEX, DIR) + #define X2_ENABLE_PIN _EPIN(X2_E_INDEX, ENABLE) + #if X2_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(X2_STEP) + #error "No E stepper plug left for X2!" + #endif + #endif + #ifndef X2_MS1_PIN + #define X2_MS1_PIN _EPIN(X2_E_INDEX, MS1) + #endif + #ifndef X2_MS2_PIN + #define X2_MS2_PIN _EPIN(X2_E_INDEX, MS2) + #endif + #ifndef X2_MS3_PIN + #define X2_MS3_PIN _EPIN(X2_E_INDEX, MS3) + #endif + #if AXIS_HAS_SPI(X2) && !defined(X2_CS_PIN) + #define X2_CS_PIN _EPIN(X2_E_INDEX, CS) + #endif + #if AXIS_HAS_UART(X2) + #ifndef X2_SERIAL_TX_PIN + #define X2_SERIAL_TX_PIN _EPIN(X2_E_INDEX, SERIAL_TX) + #endif + #ifndef X2_SERIAL_RX_PIN + #define X2_SERIAL_RX_PIN _EPIN(X2_E_INDEX, SERIAL_RX) + #endif + #endif + + // + // Auto-assign pins for stallGuard sensorless homing + // + #if defined(X2_STALL_SENSITIVITY) && ENABLED(X_DUAL_ENDSTOPS) && _PEXI(X2_E_INDEX, DIAG) + #define X2_DIAG_PIN _EPIN(X2_E_INDEX, DIAG) + #if DIAG_REMAPPED(X2, X_MIN) // If already remapped in the pins file... + #define X2_USE_ENDSTOP _XMIN_ + #elif DIAG_REMAPPED(X2, Y_MIN) + #define X2_USE_ENDSTOP _YMIN_ + #elif DIAG_REMAPPED(X2, Z_MIN) + #define X2_USE_ENDSTOP _ZMIN_ + #elif DIAG_REMAPPED(X2, X_MAX) + #define X2_USE_ENDSTOP _XMAX_ + #elif DIAG_REMAPPED(X2, Y_MAX) + #define X2_USE_ENDSTOP _YMAX_ + #elif DIAG_REMAPPED(X2, Z_MAX) + #define X2_USE_ENDSTOP _ZMAX_ + #else // Otherwise use the driver DIAG_PIN directly + #define _X2_USE_ENDSTOP(P) _E##P##_DIAG_ + #define X2_USE_ENDSTOP _X2_USE_ENDSTOP(X2_E_INDEX) + #endif + #undef X2_DIAG_PIN + #endif + + #define Y2_E_INDEX INCREMENT(X2_E_INDEX) +#else + #define Y2_E_INDEX X2_E_INDEX +#endif + +#ifndef X2_CS_PIN + #define X2_CS_PIN -1 +#endif +#ifndef X2_MS1_PIN + #define X2_MS1_PIN -1 +#endif +#ifndef X2_MS2_PIN + #define X2_MS2_PIN -1 +#endif +#ifndef X2_MS3_PIN + #define X2_MS3_PIN -1 +#endif + +// The Y2 axis, if any, should be the next open extruder port +#if ENABLED(Y_DUAL_STEPPER_DRIVERS) + #ifndef Y2_STEP_PIN + #define Y2_STEP_PIN _EPIN(Y2_E_INDEX, STEP) + #define Y2_DIR_PIN _EPIN(Y2_E_INDEX, DIR) + #define Y2_ENABLE_PIN _EPIN(Y2_E_INDEX, ENABLE) + #if Y2_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Y2_STEP) + #error "No E stepper plug left for Y2!" + #endif + #endif + #ifndef Y2_MS1_PIN + #define Y2_MS1_PIN _EPIN(Y2_E_INDEX, MS1) + #endif + #ifndef Y2_MS2_PIN + #define Y2_MS2_PIN _EPIN(Y2_E_INDEX, MS2) + #endif + #ifndef Y2_MS3_PIN + #define Y2_MS3_PIN _EPIN(Y2_E_INDEX, MS3) + #endif + #if AXIS_HAS_SPI(Y2) && !defined(Y2_CS_PIN) + #define Y2_CS_PIN _EPIN(Y2_E_INDEX, CS) + #endif + #if AXIS_HAS_UART(Y2) + #ifndef Y2_SERIAL_TX_PIN + #define Y2_SERIAL_TX_PIN _EPIN(Y2_E_INDEX, SERIAL_TX) + #endif + #ifndef Y2_SERIAL_RX_PIN + #define Y2_SERIAL_RX_PIN _EPIN(Y2_E_INDEX, SERIAL_RX) + #endif + #endif + #if defined(Y2_STALL_SENSITIVITY) && ENABLED(Y_DUAL_ENDSTOPS) && _PEXI(Y2_E_INDEX, DIAG) + #define Y2_DIAG_PIN _EPIN(Y2_E_INDEX, DIAG) + #if DIAG_REMAPPED(Y2, X_MIN) + #define Y2_USE_ENDSTOP _XMIN_ + #elif DIAG_REMAPPED(Y2, Y_MIN) + #define Y2_USE_ENDSTOP _YMIN_ + #elif DIAG_REMAPPED(Y2, Z_MIN) + #define Y2_USE_ENDSTOP _ZMIN_ + #elif DIAG_REMAPPED(Y2, X_MAX) + #define Y2_USE_ENDSTOP _XMAX_ + #elif DIAG_REMAPPED(Y2, Y_MAX) + #define Y2_USE_ENDSTOP _YMAX_ + #elif DIAG_REMAPPED(Y2, Z_MAX) + #define Y2_USE_ENDSTOP _ZMAX_ + #else + #define _Y2_USE_ENDSTOP(P) _E##P##_DIAG_ + #define Y2_USE_ENDSTOP _Y2_USE_ENDSTOP(Y2_E_INDEX) + #endif + #undef Y2_DIAG_PIN + #endif + #define Z2_E_INDEX INCREMENT(Y2_E_INDEX) +#else + #define Z2_E_INDEX Y2_E_INDEX +#endif + +#ifndef Y2_CS_PIN + #define Y2_CS_PIN -1 +#endif +#ifndef Y2_MS1_PIN + #define Y2_MS1_PIN -1 +#endif +#ifndef Y2_MS2_PIN + #define Y2_MS2_PIN -1 +#endif +#ifndef Y2_MS3_PIN + #define Y2_MS3_PIN -1 +#endif + +// The Z2 axis, if any, should be the next open extruder port +#if NUM_Z_STEPPER_DRIVERS >= 2 + #ifndef Z2_STEP_PIN + #define Z2_STEP_PIN _EPIN(Z2_E_INDEX, STEP) + #define Z2_DIR_PIN _EPIN(Z2_E_INDEX, DIR) + #define Z2_ENABLE_PIN _EPIN(Z2_E_INDEX, ENABLE) + #if Z2_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Z2_STEP) + #error "No E stepper plug left for Z2!" + #endif + #endif + #ifndef Z2_MS1_PIN + #define Z2_MS1_PIN _EPIN(Z2_E_INDEX, MS1) + #endif + #ifndef Z2_MS2_PIN + #define Z2_MS2_PIN _EPIN(Z2_E_INDEX, MS2) + #endif + #ifndef Z2_MS3_PIN + #define Z2_MS3_PIN _EPIN(Z2_E_INDEX, MS3) + #endif + #if AXIS_HAS_SPI(Z2) && !defined(Z2_CS_PIN) + #define Z2_CS_PIN _EPIN(Z2_E_INDEX, CS) + #endif + #if AXIS_HAS_UART(Z2) + #ifndef Z2_SERIAL_TX_PIN + #define Z2_SERIAL_TX_PIN _EPIN(Z2_E_INDEX, SERIAL_TX) + #endif + #ifndef Z2_SERIAL_RX_PIN + #define Z2_SERIAL_RX_PIN _EPIN(Z2_E_INDEX, SERIAL_RX) + #endif + #endif + #if defined(Z2_STALL_SENSITIVITY) && ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 2 && _PEXI(Z2_E_INDEX, DIAG) + #define Z2_DIAG_PIN _EPIN(Z2_E_INDEX, DIAG) + #if DIAG_REMAPPED(Z2, X_MIN) + #define Z2_USE_ENDSTOP _XMIN_ + #elif DIAG_REMAPPED(Z2, Y_MIN) + #define Z2_USE_ENDSTOP _YMIN_ + #elif DIAG_REMAPPED(Z2, Z_MIN) + #define Z2_USE_ENDSTOP _ZMIN_ + #elif DIAG_REMAPPED(Z2, X_MAX) + #define Z2_USE_ENDSTOP _XMAX_ + #elif DIAG_REMAPPED(Z2, Y_MAX) + #define Z2_USE_ENDSTOP _YMAX_ + #elif DIAG_REMAPPED(Z2, Z_MAX) + #define Z2_USE_ENDSTOP _ZMAX_ + #else + #define _Z2_USE_ENDSTOP(P) _E##P##_DIAG_ + #define Z2_USE_ENDSTOP _Z2_USE_ENDSTOP(Z2_E_INDEX) + #endif + #undef Z2_DIAG_PIN + #endif + #define Z3_E_INDEX INCREMENT(Z2_E_INDEX) +#else + #define Z3_E_INDEX Z2_E_INDEX +#endif + +#ifndef Z2_CS_PIN + #define Z2_CS_PIN -1 +#endif +#ifndef Z2_MS1_PIN + #define Z2_MS1_PIN -1 +#endif +#ifndef Z2_MS2_PIN + #define Z2_MS2_PIN -1 +#endif +#ifndef Z2_MS3_PIN + #define Z2_MS3_PIN -1 +#endif + +#if NUM_Z_STEPPER_DRIVERS >= 3 + #ifndef Z3_STEP_PIN + #define Z3_STEP_PIN _EPIN(Z3_E_INDEX, STEP) + #define Z3_DIR_PIN _EPIN(Z3_E_INDEX, DIR) + #define Z3_ENABLE_PIN _EPIN(Z3_E_INDEX, ENABLE) + #if Z3_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Z3_STEP) + #error "No E stepper plug left for Z3!" + #endif + #endif + #if AXIS_HAS_SPI(Z3) + #ifndef Z3_CS_PIN + #define Z3_CS_PIN _EPIN(Z3_E_INDEX, CS) + #endif + #endif + #ifndef Z3_MS1_PIN + #define Z3_MS1_PIN _EPIN(Z3_E_INDEX, MS1) + #endif + #ifndef Z3_MS2_PIN + #define Z3_MS2_PIN _EPIN(Z3_E_INDEX, MS2) + #endif + #ifndef Z3_MS3_PIN + #define Z3_MS3_PIN _EPIN(Z3_E_INDEX, MS3) + #endif + #if AXIS_HAS_UART(Z3) + #ifndef Z3_SERIAL_TX_PIN + #define Z3_SERIAL_TX_PIN _EPIN(Z3_E_INDEX, SERIAL_TX) + #endif + #ifndef Z3_SERIAL_RX_PIN + #define Z3_SERIAL_RX_PIN _EPIN(Z3_E_INDEX, SERIAL_RX) + #endif + #endif + #if defined(Z3_STALL_SENSITIVITY) && ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3 && _PEXI(Z3_E_INDEX, DIAG) + #define Z3_DIAG_PIN _EPIN(Z3_E_INDEX, DIAG) + #if DIAG_REMAPPED(Z3, X_MIN) + #define Z3_USE_ENDSTOP _XMIN_ + #elif DIAG_REMAPPED(Z3, Y_MIN) + #define Z3_USE_ENDSTOP _YMIN_ + #elif DIAG_REMAPPED(Z3, Z_MIN) + #define Z3_USE_ENDSTOP _ZMIN_ + #elif DIAG_REMAPPED(Z3, X_MAX) + #define Z3_USE_ENDSTOP _XMAX_ + #elif DIAG_REMAPPED(Z3, Y_MAX) + #define Z3_USE_ENDSTOP _YMAX_ + #elif DIAG_REMAPPED(Z3, Z_MAX) + #define Z3_USE_ENDSTOP _ZMAX_ + #else + #define _Z3_USE_ENDSTOP(P) _E##P##_DIAG_ + #define Z3_USE_ENDSTOP _Z3_USE_ENDSTOP(Z3_E_INDEX) + #endif + #undef Z3_DIAG_PIN + #endif + #define Z4_E_INDEX INCREMENT(Z3_E_INDEX) +#endif + +#ifndef Z3_CS_PIN + #define Z3_CS_PIN -1 +#endif +#ifndef Z3_MS1_PIN + #define Z3_MS1_PIN -1 +#endif +#ifndef Z3_MS2_PIN + #define Z3_MS2_PIN -1 +#endif +#ifndef Z3_MS3_PIN + #define Z3_MS3_PIN -1 +#endif + +#if NUM_Z_STEPPER_DRIVERS >= 4 + #ifndef Z4_STEP_PIN + #define Z4_STEP_PIN _EPIN(Z4_E_INDEX, STEP) + #define Z4_DIR_PIN _EPIN(Z4_E_INDEX, DIR) + #define Z4_ENABLE_PIN _EPIN(Z4_E_INDEX, ENABLE) + #if Z4_E_INDEX >= MAX_EXTRUDERS || !PIN_EXISTS(Z4_STEP) + #error "No E stepper plug left for Z4!" + #endif + #endif + #if AXIS_HAS_SPI(Z4) + #ifndef Z4_CS_PIN + #define Z4_CS_PIN _EPIN(Z4_E_INDEX, CS) + #endif + #endif + #ifndef Z4_MS1_PIN + #define Z4_MS1_PIN _EPIN(Z4_E_INDEX, MS1) + #endif + #ifndef Z4_MS2_PIN + #define Z4_MS2_PIN _EPIN(Z4_E_INDEX, MS2) + #endif + #ifndef Z4_MS3_PIN + #define Z4_MS3_PIN _EPIN(Z4_E_INDEX, MS3) + #endif + #if AXIS_HAS_UART(Z4) + #ifndef Z4_SERIAL_TX_PIN + #define Z4_SERIAL_TX_PIN _EPIN(Z4_E_INDEX, SERIAL_TX) + #endif + #ifndef Z4_SERIAL_RX_PIN + #define Z4_SERIAL_RX_PIN _EPIN(Z4_E_INDEX, SERIAL_RX) + #endif + #endif + #if defined(Z4_STALL_SENSITIVITY) && ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4 && _PEXI(Z4_E_INDEX, DIAG) + #define Z4_DIAG_PIN _EPIN(Z4_E_INDEX, DIAG) + #if DIAG_REMAPPED(Z4, X_MIN) + #define Z4_USE_ENDSTOP _XMIN_ + #elif DIAG_REMAPPED(Z4, Y_MIN) + #define Z4_USE_ENDSTOP _YMIN_ + #elif DIAG_REMAPPED(Z4, Z_MIN) + #define Z4_USE_ENDSTOP _ZMIN_ + #elif DIAG_REMAPPED(Z4, X_MAX) + #define Z4_USE_ENDSTOP _XMAX_ + #elif DIAG_REMAPPED(Z4, Y_MAX) + #define Z4_USE_ENDSTOP _YMAX_ + #elif DIAG_REMAPPED(Z4, Z_MAX) + #define Z4_USE_ENDSTOP _ZMAX_ + #else + #define _Z4_USE_ENDSTOP(P) _E##P##_DIAG_ + #define Z4_USE_ENDSTOP _Z4_USE_ENDSTOP(Z4_E_INDEX) + #endif + #undef Z4_DIAG_PIN + #endif +#endif + +#ifndef Z4_CS_PIN + #define Z4_CS_PIN -1 +#endif +#ifndef Z4_MS1_PIN + #define Z4_MS1_PIN -1 +#endif +#ifndef Z4_MS2_PIN + #define Z4_MS2_PIN -1 +#endif +#ifndef Z4_MS3_PIN + #define Z4_MS3_PIN -1 +#endif + +#if HAS_MARLINUI_U8GLIB + #if !defined(ST7920_DELAY_1) && defined(BOARD_ST7920_DELAY_1) + #define ST7920_DELAY_1 BOARD_ST7920_DELAY_1 + #endif + #if !defined(ST7920_DELAY_2) && defined(BOARD_ST7920_DELAY_2) + #define ST7920_DELAY_2 BOARD_ST7920_DELAY_2 + #endif + #if !defined(ST7920_DELAY_3) && defined(BOARD_ST7920_DELAY_3) + #define ST7920_DELAY_3 BOARD_ST7920_DELAY_3 + #endif +#else + #undef ST7920_DELAY_1 + #undef ST7920_DELAY_2 + #undef ST7920_DELAY_3 +#endif + +#undef HAS_FREE_AUX2_PINS +#undef DIAG_REMAPPED diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index 33ec27ddba..6d87e6b14f 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -94,7 +94,7 @@ // #define CONTROLLER_FAN_PIN PD6 // BOARD FAN #define FAN_PIN PG13 // FAN -#define FAN_PIN_2 PG14 +#define FAN2_PIN PG14 // // Misc diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index 990d33b759..bdce235841 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -103,7 +103,7 @@ // #define CONTROLLER_FAN_PIN PD6 // BOARD FAN #define FAN_PIN PG13 // FAN -#define FAN_PIN_2 PG14 +#define FAN2_PIN PG14 // // Misc diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 86dab41121..7f2ae61aae 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -171,7 +171,7 @@ // Shared FSMC Configs #if HAS_FSMC_TFT - #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h + #define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 #define FSMC_CS_PIN PD7 // NE4 diff --git a/Marlin/src/pins/stm32f7/pins_NUCLEO_F767ZI.h b/Marlin/src/pins/stm32f7/pins_NUCLEO_F767ZI.h index 0a00e03612..90dcfc46e4 100644 --- a/Marlin/src/pins/stm32f7/pins_NUCLEO_F767ZI.h +++ b/Marlin/src/pins/stm32f7/pins_NUCLEO_F767ZI.h @@ -57,9 +57,8 @@ * TIM14 - TEMP_TIMER (Marlin) * */ -#define STEP_TIMER 4 -#define TEMP_TIMER 14 - +#define STEP_TIMER 4 +#define TEMP_TIMER 14 /** * These pin assignments are arbitrary and intending for testing purposes. @@ -78,7 +77,7 @@ * GND | · · | PD2 (SERVO0_PIN) PB4 | · · | PF12 (LCD_RS) * GND | · · | PG2  ̄ ̄ ̄ * VIN | · · | PG3 -_*  ̄ ̄ ̄ _CN10 + *  ̄ ̄ ̄ _CN10 * AVDD | · · | PF13 (BTN_EN1) * _CN9_ AGND | · · | PE9 (BTN_EN2) * (TEMP_0) PA3 | · · | PD7 GND | · · | PE11 (BTN_ENC) @@ -152,13 +151,13 @@ _*  ̄ ̄ ̄ _CN10 // // Heaters / Fans // -#define HEATER_0_PIN PA15 // PWM Capable, TIM2_CH1 -#define HEATER_BED_PIN PB3 // PWM Capable, TIM2_CH2 +#define HEATER_0_PIN PA15 // PWM Capable, TIM2_CH1 +#define HEATER_BED_PIN PB3 // PWM Capable, TIM2_CH2 #ifndef FAN_PIN - #define FAN_PIN PB10 // PWM Capable, TIM2_CH3 + #define FAN_PIN PB10 // PWM Capable, TIM2_CH3 #endif -#define FAN1_PIN PB11 // PWM Capable, TIM2_CH4 +#define FAN1_PIN PB11 // PWM Capable, TIM2_CH4 #ifndef E0_AUTO_FAN_PIN #define E0_AUTO_FAN_PIN FAN1_PIN @@ -167,8 +166,8 @@ _*  ̄ ̄ ̄ _CN10 // // Servos // -#define SERVO0_PIN PB4 // PWM Capable, TIM3_CH1 -#define SERVO1_PIN PB5 // PWM Capable, TIM3_CH2 +#define SERVO0_PIN PB4 // PWM Capable, TIM3_CH1 +#define SERVO1_PIN PB5 // PWM Capable, TIM3_CH2 // SPI for external SD Card (Not entirely sure this will work) #define SCK_PIN PA5 @@ -177,13 +176,13 @@ _*  ̄ ̄ ̄ _CN10 #define SS_PIN PA4 #define SDSS PA4 -#define LED_PIN LED_BLUE +#define LED_PIN LED_BLUE // // LCD / Controller // #if IS_RRD_FG_SC - #define BEEPER_PIN PC7 // LCD_BEEPER + #define BEEPER_PIN PC7 // LCD_BEEPER #define BTN_ENC PE11 // BTN_ENC #define SD_DETECT_PIN PD14 #define LCD_PINS_RS PF12 // LCD_RS @@ -193,7 +192,7 @@ _*  ̄ ̄ ̄ _CN10 // #define LCD_PINS_D6 // #define LCD_PINS_D7 #define BTN_EN1 PF13 // BTN_EN1 - #define BTN_EN2 PE9 // BTN_EN2 + #define BTN_EN2 PE9 // BTN_EN2 #define BOARD_ST7920_DELAY_1 DELAY_NS(125) #define BOARD_ST7920_DELAY_2 DELAY_NS(63) diff --git a/Marlin/src/sd/SdBaseFile.cpp b/Marlin/src/sd/SdBaseFile.cpp index 2bc9f96e8c..46ed9372ab 100644 --- a/Marlin/src/sd/SdBaseFile.cpp +++ b/Marlin/src/sd/SdBaseFile.cpp @@ -21,12 +21,12 @@ */ #if __GNUC__ > 8 - // The NXP platform updated GCC from 7.2.1 to 9.2.1 - // and this new warning apparently can be ignored. #pragma GCC diagnostic ignored "-Waddress-of-packed-member" #endif /** + * sd/SdBaseFile.cpp + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdBaseFile.h b/Marlin/src/sd/SdBaseFile.h index 13a1be863d..2f7dfb9f3b 100644 --- a/Marlin/src/sd/SdBaseFile.h +++ b/Marlin/src/sd/SdBaseFile.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief SdBaseFile class - */ - -/** + * sd/SdBaseFile.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFatConfig.h b/Marlin/src/sd/SdFatConfig.h index 2e03a4181f..8f0596c5dd 100644 --- a/Marlin/src/sd/SdFatConfig.h +++ b/Marlin/src/sd/SdFatConfig.h @@ -22,7 +22,8 @@ #pragma once /** - * SdFatConfig.h + * sd/SdFatConfig.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFatStructs.h b/Marlin/src/sd/SdFatStructs.h index 484d4e50c6..ac81f1d64e 100644 --- a/Marlin/src/sd/SdFatStructs.h +++ b/Marlin/src/sd/SdFatStructs.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief FAT file structures - */ - -/** + * sd/SdFatStructs.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFatUtil.cpp b/Marlin/src/sd/SdFatUtil.cpp index e2c467c5b6..7d9f33dc50 100644 --- a/Marlin/src/sd/SdFatUtil.cpp +++ b/Marlin/src/sd/SdFatUtil.cpp @@ -21,6 +21,8 @@ */ /** + * sd/SdFatUtil.cpp + * * Arduino SdFat Library * Copyright (c) 2008 by William Greiman * diff --git a/Marlin/src/sd/SdFatUtil.h b/Marlin/src/sd/SdFatUtil.h index 7afed2ede0..f1bb65747e 100644 --- a/Marlin/src/sd/SdFatUtil.h +++ b/Marlin/src/sd/SdFatUtil.h @@ -22,6 +22,8 @@ #pragma once /** + * sd/SdFatUtil.h + * * Arduino SdFat Library * Copyright (c) 2008 by William Greiman * diff --git a/Marlin/src/sd/SdFile.cpp b/Marlin/src/sd/SdFile.cpp index c82fe2c5ed..cba67e2bba 100644 --- a/Marlin/src/sd/SdFile.cpp +++ b/Marlin/src/sd/SdFile.cpp @@ -21,6 +21,8 @@ */ /** + * sd/SdFile.cpp + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdFile.h b/Marlin/src/sd/SdFile.h index 52c8f1f0db..17256b47c8 100644 --- a/Marlin/src/sd/SdFile.h +++ b/Marlin/src/sd/SdFile.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief SdFile class - */ - -/** + * sd/SdFile.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * @@ -42,7 +39,7 @@ * \class SdFile * \brief SdBaseFile with Print. */ -class SdFile : public SdBaseFile/*, public Print*/ { +class SdFile : public SdBaseFile { public: SdFile() {} SdFile(const char* name, uint8_t oflag); diff --git a/Marlin/src/sd/SdVolume.cpp b/Marlin/src/sd/SdVolume.cpp index 63731f728c..e262c8867a 100644 --- a/Marlin/src/sd/SdVolume.cpp +++ b/Marlin/src/sd/SdVolume.cpp @@ -21,6 +21,8 @@ */ /** + * sd/SdVolume.cpp + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/SdVolume.h b/Marlin/src/sd/SdVolume.h index 1ffa888468..2d57c681c4 100644 --- a/Marlin/src/sd/SdVolume.h +++ b/Marlin/src/sd/SdVolume.h @@ -22,11 +22,8 @@ #pragma once /** - * \file - * \brief SdVolume class - */ - -/** + * sd/SdVolume.h + * * Arduino SdFat Library * Copyright (c) 2009 by William Greiman * diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index b809b2c10f..a633440ff6 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -639,7 +639,7 @@ bool CardReader::fileExists(const char * const path) { selectByName(*diveDir, fname); diveDir->close(); } - return fname != nullptr; + return !!fname; } // @@ -684,7 +684,7 @@ void CardReader::write_command(char * const buf) { char* end = buf + strlen(buf) - 1; file.writeError = false; - if ((npos = strchr(buf, 'N')) != nullptr) { + if ((npos = strchr(buf, 'N'))) { begin = strchr(npos, ' ') + 1; end = strchr(npos, '*') - 1; } diff --git a/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp b/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp index 8a989157b4..f26e82b9c7 100644 --- a/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp +++ b/Marlin/src/sd/usb_flashdrive/lib-uhs2/Usb.cpp @@ -22,7 +22,10 @@ * Web : https://www.circuitsathome.com * e-mail : support@circuitsathome.com */ -/* USB functions */ + +// +// USB functions supporting Flash Drive +// #include "../../../inc/MarlinConfigPre.h" @@ -35,7 +38,7 @@ static uint8_t usb_task_state; /* constructor */ USB::USB() : bmHubPre(0) { - usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; //set up state machine + usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; // Set up state machine init(); } @@ -45,13 +48,8 @@ void USB::init() { bmHubPre = 0; } -uint8_t USB::getUsbTaskState() { - return usb_task_state; -} - -void USB::setUsbTaskState(uint8_t state) { - usb_task_state = state; -} +uint8_t USB::getUsbTaskState() { return usb_task_state; } +void USB::setUsbTaskState(uint8_t state) { usb_task_state = state; } EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) { UsbDevice *p = addrPool.GetUsbDevicePtr(addr); @@ -70,9 +68,11 @@ EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) { return nullptr; } -/* set device table entry */ - -/* each device is different and has different number of endpoints. This function plugs endpoint record structure, defined in application, to devtable */ +/** + * Set device table entry + * Each device is different and has different number of endpoints. + * This function plugs endpoint record structure, defined in application, to devtable + */ uint8_t USB::setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr) { if (!eprecord_ptr) return USB_ERROR_INVALID_ARGUMENT; @@ -112,7 +112,7 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l USBTRACE2(" NAK Limit: ", nak_limit); USBTRACE("\r\n"); */ - regWr(rPERADDR, addr); //set peripheral address + regWr(rPERADDR, addr); // Set peripheral address uint8_t mode = regRd(rMODE); @@ -121,8 +121,6 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l //Serial.print("\r\nLS: "); //Serial.println(p->lowspeed, HEX); - - // Set bmLOWSPEED and bmHUBPRE in case of low-speed device, reset them otherwise regWr(rMODE, (p->lowspeed) ? mode | bmLOWSPEED | bmHubPre : mode & ~(bmHUBPRE | bmLOWSPEED)); @@ -133,11 +131,10 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l /* depending on request. Actual requests are defined as inlines */ /* return codes: */ /* 00 = success */ - /* 01-0f = non-zero HRSLT */ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBReadParser *p) { - bool direction = false; //request direction, IN or OUT + bool direction = false; // Request direction, IN or OUT uint8_t rcode; SETUP_PKT setup_pkt; @@ -157,15 +154,15 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque setup_pkt.wIndex = wInd; setup_pkt.wLength = total; - bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); //transfer to setup packet FIFO + bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); // Transfer to setup packet FIFO - rcode = dispatchPkt(tokSETUP, ep, nak_limit); //dispatch packet + rcode = dispatchPkt(tokSETUP, ep, nak_limit); // Dispatch packet if (rcode) return rcode; // Return HRSLT if not zero - if (dataptr != nullptr) { //data stage, if present - if (direction) { //IN transfer + if (dataptr) { // Data stage, if present + if (direction) { // IN transfer uint16_t left = total; - pep->bmRcvToggle = 1; //bmRCVTOG1; + pep->bmRcvToggle = 1; // BmRCVTOG1; while (left) { // Bytes read into buffer @@ -174,7 +171,7 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque rcode = InTransfer(pep, nak_limit, &read, dataptr); if (rcode == hrTOGERR) { - // yes, we flip it wrong here so that next time it is actually correct! + // Yes, we flip it wrong here so that next time it is actually correct! pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; continue; } @@ -189,21 +186,21 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque if (read < nbytes) break; } } - else { //OUT transfer - pep->bmSndToggle = 1; //bmSNDTOG1; + else { // OUT transfer + pep->bmSndToggle = 1; // BmSNDTOG1; rcode = OutTransfer(pep, nak_limit, nbytes, dataptr); } - if (rcode) return rcode; // return error + if (rcode) return rcode; // Return error } // Status stage - return dispatchPkt((direction) ? tokOUTHS : tokINHS, ep, nak_limit); //GET if direction + return dispatchPkt((direction) ? tokOUTHS : tokINHS, ep, nak_limit); // GET if direction } -/* IN transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ -/* Keep sending INs and writes data to memory area pointed by 'data' */ - -/* rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, - fe USB xfer timeout */ +/** + * IN transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes. + * Keep sending INs and writes data to memory area pointed by 'data' + * rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, fe = USB xfer timeout + */ uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) { EpInfo *pep = nullptr; uint16_t nak_limit = 0; @@ -227,29 +224,29 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui uint8_t maxpktsize = pep->maxPktSize; *nbytesptr = 0; - regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value + regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); // Set toggle value - // use a 'break' to exit this loop + // Use a 'break' to exit this loop for (;;) { - rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS. + rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); // IN packet to EP-'endpoint'. Function takes care of NAKS. if (rcode == hrTOGERR) { - // yes, we flip it wrong here so that next time it is actually correct! + // Yes, we flip it wrong here so that next time it is actually correct! pep->bmRcvToggle = (regRd(rHRSL) & bmRCVTOGRD) ? 0 : 1; - regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value + regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); // Set toggle value continue; } if (rcode) { //printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode); - break; //should be 0, indicating ACK. Else return error code. + break; // Should be 0, indicating ACK. Else return error code. } /* check for RCVDAVIRQ and generate error if not present */ /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */ if ((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) { //printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n"); - rcode = 0xF0; //receive error + rcode = 0xF0; // Receive error break; } - pktsize = regRd(rRCVBC); //number of received bytes + pktsize = regRd(rRCVBC); // Number of received bytes //printf("Got %i bytes \r\n", pktsize); // This would be OK, but... //assert(pktsize <= nbytes); @@ -266,7 +263,7 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data); regWr(rHIRQ, bmRCVDAVIRQ); // Clear the IRQ & free the buffer - *nbytesptr += pktsize; // add this packet's byte count to total transfer length + *nbytesptr += pktsize; // Add this packet's byte count to total transfer length /* The transfer is complete under two conditions: */ /* 1. The device sent a short packet (L.T. maxPacketSize) */ @@ -284,10 +281,11 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui return rcode; } -/* OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ -/* Handles NAK bug per Maxim Application Note 4000 for single buffer transfer */ - -/* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */ +/** + * OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. + * Handles NAK bug per Maxim Application Note 4000 for single buffer transfer + * rcode 0 if no errors. rcode 01-0f is relayed from HRSL + */ uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) { EpInfo *pep = nullptr; uint16_t nak_limit = 0; @@ -300,7 +298,7 @@ uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dat uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data) { uint8_t rcode = hrSUCCESS, retry_count; - uint8_t *data_p = data; //local copy of the data pointer + uint8_t *data_p = data; // Local copy of the data pointer uint16_t bytes_tosend, nak_count; uint16_t bytes_left = nbytes; @@ -311,17 +309,17 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT; - regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value + regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); // Set toggle value while (bytes_left) { retry_count = 0; nak_count = 0; bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left; - bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO - regWr(rSNDBC, bytes_tosend); //set number of bytes - regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet - while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ - regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ + bytesWr(rSNDFIFO, bytes_tosend, data_p); // Filling output FIFO + regWr(rSNDBC, bytes_tosend); // Set number of bytes + regWr(rHXFR, (tokOUT | pep->epAddr)); // Dispatch packet + while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); // Wait for the completion IRQ + regWr(rHIRQ, bmHXFRDNIRQ); // Clear IRQ rcode = (regRd(rHRSL) & 0x0F); while (rcode && ((int32_t)((uint32_t)millis() - timeout) < 0L)) { @@ -330,18 +328,18 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 nak_count++; if (nak_limit && (nak_count == nak_limit)) goto breakout; - //return ( rcode); + //return rcode; break; case hrTIMEOUT: retry_count++; if (retry_count == USB_RETRY_LIMIT) goto breakout; - //return ( rcode); + //return rcode; break; case hrTOGERR: - // yes, we flip it wrong here so that next time it is actually correct! + // Yes, we flip it wrong here so that next time it is actually correct! pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; - regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value + regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); // Set toggle value break; default: goto breakout; @@ -351,26 +349,27 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 regWr(rSNDBC, 0); regWr(rSNDFIFO, *data_p); regWr(rSNDBC, bytes_tosend); - regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet - while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ - regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ + regWr(rHXFR, (tokOUT | pep->epAddr)); // Dispatch packet + while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); // Wait for the completion IRQ + regWr(rHIRQ, bmHXFRDNIRQ); // Clear IRQ rcode = (regRd(rHRSL) & 0x0F); - } // while rcode && .... + } // While rcode && .... bytes_left -= bytes_tosend; data_p += bytes_tosend; - } // while bytes_left... + } // While bytes_left... breakout: - pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; //bmSNDTOG1 : bmSNDTOG0; //update toggle - return ( rcode); //should be 0 in all cases + pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; // BmSNDTOG1 : bmSNDTOG0; // Update toggle + return ( rcode); // Should be 0 in all cases } -/* dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty */ -/* If NAK, tries to re-send up to nak_limit times */ -/* If nak_limit == 0, do not count NAKs, exit after timeout */ -/* If bus timeout, re-sends up to USB_RETRY_LIMIT times */ - -/* return codes 0x00-0x0F are HRSLT( 0x00 being success ), 0xFF means timeout */ +/** + * Dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty + * If NAK, tries to re-send up to nak_limit times + * If nak_limit == 0, do not count NAKs, exit after timeout + * If bus timeout, re-sends up to USB_RETRY_LIMIT times + * return codes 0x00-0x0F are HRSLT( 0x00 being success ), 0xFF means timeout + */ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT; uint8_t tmpdata; @@ -380,29 +379,28 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { while ((int32_t)((uint32_t)millis() - timeout) < 0L) { #if defined(ESP8266) || defined(ESP32) - yield(); // needed in order to reset the watchdog timer on the ESP8266 + yield(); // Needed in order to reset the watchdog timer on the ESP8266 #endif - regWr(rHXFR, (token | ep)); //launch the transfer + regWr(rHXFR, (token | ep)); // Launch the transfer rcode = USB_ERROR_TRANSFER_TIMEOUT; - while ((int32_t)((uint32_t)millis() - timeout) < 0L) { //wait for transfer completion + while ((int32_t)((uint32_t)millis() - timeout) < 0L) { // Wait for transfer completion #if defined(ESP8266) || defined(ESP32) - yield(); // needed to reset the watchdog timer on the ESP8266 + yield(); // Needed to reset the watchdog timer on the ESP8266 #endif tmpdata = regRd(rHIRQ); if (tmpdata & bmHXFRDNIRQ) { - regWr(rHIRQ, bmHXFRDNIRQ); //clear the interrupt + regWr(rHIRQ, bmHXFRDNIRQ); // Clear the interrupt rcode = 0x00; break; } - } // while millis() < timeout + } // While millis() < timeout - //if (rcode != 0x00) //exit if timeout - // return ( rcode); + //if (rcode != 0x00) return rcode; // Exit if timeout - rcode = (regRd(rHRSL) & 0x0F); //analyze transfer result + rcode = (regRd(rHRSL) & 0x0F); // Analyze transfer result switch (rcode) { case hrNAK: @@ -419,12 +417,12 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { return (rcode); } - } // while timeout > millis() + } // While timeout > millis() return rcode; } -/* USB main task. Performs enumeration/cleanup */ -void USB::Task() { //USB state machine +// USB main task. Performs enumeration/cleanup +void USB::Task() { // USB state machine uint8_t rcode; uint8_t tmpdata; static uint32_t delay = 0; @@ -437,19 +435,19 @@ void USB::Task() { //USB state machine /* modify USB task state if Vbus changed */ switch (tmpdata) { - case SE1: //illegal state + case SE1: // Illegal state usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL; lowspeed = false; break; - case SE0: //disconnected + case SE0: // Disconnected if ((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED) usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE; lowspeed = false; break; case LSHOST: lowspeed = true; - //intentional fallthrough - case FSHOST: //attached + // Intentional fallthrough + case FSHOST: // Attached if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) { delay = (uint32_t)millis() + USB_SETTLE_DELAY; usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE; @@ -470,31 +468,31 @@ void USB::Task() { //USB state machine usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE; break; - case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: //just sit here + case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: // Just sit here break; - case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here + case USB_DETACHED_SUBSTATE_ILLEGAL: // Just sit here break; - case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device + case USB_ATTACHED_SUBSTATE_SETTLE: // Settle time for just attached device if ((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE; - else break; // don't fall through + else break; // Don't fall through case USB_ATTACHED_SUBSTATE_RESET_DEVICE: - regWr(rHCTL, bmBUSRST); //issue bus reset + regWr(rHCTL, bmBUSRST); // Issue bus reset usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE; break; case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE: if ((regRd(rHCTL) & bmBUSRST) == 0) { - tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation + tmpdata = regRd(rMODE) | bmSOFKAENAB; // Start SOF generation regWr(rMODE, tmpdata); usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF; - //delay = (uint32_t)millis() + 20; //20ms wait after reset per USB spec + //delay = (uint32_t)millis() + 20; // 20ms wait after reset per USB spec } break; - case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order + case USB_ATTACHED_SUBSTATE_WAIT_SOF: // Todo: change check order if (regRd(rHIRQ) & bmFRAMEIRQ) { - //when first SOF received _and_ 20ms has passed we can continue + // When first SOF received _and_ 20ms has passed we can continue /* - if (delay < (uint32_t)millis()) //20ms passed + if (delay < (uint32_t)millis()) // 20ms passed usb_task_state = USB_STATE_CONFIGURING; */ usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET; @@ -503,7 +501,7 @@ void USB::Task() { //USB state machine break; case USB_ATTACHED_SUBSTATE_WAIT_RESET: if ((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING; - else break; // don't fall through + else break; // Don't fall through case USB_STATE_CONFIGURING: //Serial.print("\r\nConf.LS: "); @@ -565,11 +563,11 @@ again: if (rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) { if (parent == 0) { // Send a bus reset on the root interface. - regWr(rHCTL, bmBUSRST); //issue bus reset - delay(102); // delay 102ms, compensate for clock inaccuracy. + regWr(rHCTL, bmBUSRST); // Issue bus reset + delay(102); // Delay 102ms, compensate for clock inaccuracy. } else { - // reset parent port + // Reset parent port devConfig[parent]->ResetHubPort(port); } } @@ -592,11 +590,11 @@ again: // Issue a bus reset, because the device may be in a limbo state if (parent == 0) { // Send a bus reset on the root interface. - regWr(rHCTL, bmBUSRST); //issue bus reset - delay(102); // delay 102ms, compensate for clock inaccuracy. + regWr(rHCTL, bmBUSRST); // Issue bus reset + delay(102); // Delay 102ms, compensate for clock inaccuracy. } else { - // reset parent port + // Reset parent port devConfig[parent]->ResetHubPort(port); } } @@ -623,19 +621,19 @@ again: * 4: set address * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail * 6: while (configurations) { - * for (each configuration) { - * for (each driver) { - * 6a: Ask device if it likes configuration. Returns 0 on OK. - * If successful, the driver configured device. - * The driver now owns the endpoints, and takes over managing them. - * The following will need codes: - * Everything went well, instance consumed, exit with success. - * Instance already in use, ignore it, try next driver. - * Not a supported device, ignore it, try next driver. - * Not a supported configuration for this device, ignore it, try next driver. - * Could not configure device, fatal, exit with fail. - * } - * } + * for (each configuration) { + * for (each driver) { + * 6a: Ask device if it likes configuration. Returns 0 on OK. + * If successful, the driver configured device. + * The driver now owns the endpoints, and takes over managing them. + * The following will need codes: + * Everything went well, instance consumed, exit with success. + * Instance already in use, ignore it, try next driver. + * Not a supported device, ignore it, try next driver. + * Not a supported configuration for this device, ignore it, try next driver. + * Could not configure device, fatal, exit with fail. + * } + * } * } * 7: for (each driver) { * 7a: Ask device if it knows this VID/PID. Acts exactly like 6a, but using VID/PID @@ -671,7 +669,7 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to - // avoid toggle inconsistence + // Avoid toggle inconsistence p->epinfo = &epInfo; @@ -687,7 +685,7 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { return rcode; } - // to-do? + // To-do? // Allocate new address according to device class //bAddress = addrPool.AllocAddress(parent, false, port); @@ -698,11 +696,11 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { // Qualify with subclass too. // // VID/PID & class tests default to false for drivers not yet ported - // subclass defaults to true, so you don't have to define it if you don't have to. + // Subclass defaults to true, so you don't have to define it if you don't have to. // for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) { - if (!devConfig[devConfigIndex]) continue; // no driver - if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed + if (!devConfig[devConfigIndex]) continue; // No driver + if (devConfig[devConfigIndex]->GetAddress()) continue; // Consumed if (devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) { rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed); if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED) @@ -712,20 +710,20 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { if (devConfigIndex < USB_NUMDEVICES) return rcode; - // blindly attempt to configure + // Blindly attempt to configure for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) { if (!devConfig[devConfigIndex]) continue; - if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed + if (devConfig[devConfigIndex]->GetAddress()) continue; // Consumed if (devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) continue; // If this is true it means it must have returned USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED above rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed); //printf("ERROR ENUMERATING %2.2x\r\n", rcode); if (!(rcode == USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED || rcode == USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE)) { - // in case of an error dev_index should be reset to 0 - // in order to start from the very beginning the - // next time the program gets here + // In case of an error dev_index should be reset to 0 + // in order to start from the very beginning the + // next time the program gets here //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE) - // devConfigIndex = 0; + //devConfigIndex = 0; return rcode; } } @@ -744,20 +742,22 @@ uint8_t USB::ReleaseDevice(uint8_t addr) { return 0; } -#if 1 //!defined(USB_METHODS_INLINE) -//get device descriptor - +// Get device descriptor uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) { return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, nullptr); } -//get configuration descriptor +// Get configuration descriptor uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) { return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, nbytes, dataptr, nullptr); } -/* Requests Configuration Descriptor. Sends two Get Conf Descr requests. The first one gets the total length of all descriptors, then the second one requests this - total length. The length of the first request can be shorter ( 4 bytes ), however, there are devices which won't work unless this length is set to 9 */ +/** + * Requests Configuration Descriptor. Sends two Get Conf Descr requests. + * The first one gets the total length of all descriptors, then the second one requests this + * total length. The length of the first request can be shorter (4 bytes), however, there are + * devices which won't work unless this length is set to 9. + */ uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p) { const uint8_t bufSize = 64; uint8_t buf[bufSize]; @@ -773,25 +773,23 @@ uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, total, bufSize, buf, p); } -//get string descriptor - +// Get string descriptor uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, uint16_t langid, uint8_t* dataptr) { return ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, ns, ns, dataptr, nullptr); } -//set address +// Set address uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) { uint8_t rcode = ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr); - //delay(2); //per USB 2.0 sect.9.2.6.3 + //delay(2); // Per USB 2.0 sect.9.2.6.3 delay(300); // Older spec says you should wait at least 200ms return rcode; //return ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr); } -//set configuration +// Set configuration uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) { return ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, 0x0000, nullptr, nullptr); } -#endif // defined(USB_METHODS_INLINE) #endif // USB_FLASH_DRIVE_SUPPORT diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.h b/buildroot/share/PlatformIO/scripts/common-dependencies.h index c96907bb3f..f5b36c407e 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.h +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.h @@ -37,7 +37,9 @@ // Feature checks for SR_LCD_3W_NL #elif EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) #define USES_LIQUIDTWI2 -#elif ANY(HAS_MARLINUI_HD44780, LCD_I2C_TYPE_PCF8575, LCD_I2C_TYPE_PCA8574, SR_LCD_2W_NL, LCM1602) +#elif ENABLED(LCD_I2C_TYPE_PCA8574) + #define USES_LIQUIDCRYSTAL_I2C +#elif ANY(HAS_MARLINUI_HD44780, LCD_I2C_TYPE_PCF8575, SR_LCD_2W_NL , LCM1602) #define USES_LIQUIDCRYSTAL #endif diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index 4b4bba6258..b9cefeab7c 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -208,7 +208,8 @@ def search_compiler(): for filepath in os.listdir(pathdir): if not filepath.endswith(gcc): continue - + # Use entire path to not rely on env PATH + filepath = os.path.sep.join([pathdir, filepath]) # Cache the g++ path to no search always if os.path.exists(ENV_BUILD_PATH): blab('Caching g++ for current env') diff --git a/buildroot/tests/mks_robin_nano35-tests b/buildroot/tests/mks_robin_nano35-tests index ce98f563b9..d67fa516b8 100644 --- a/buildroot/tests/mks_robin_nano35-tests +++ b/buildroot/tests/mks_robin_nano35-tests @@ -53,5 +53,17 @@ opt_disable TFT_INTERFACE_FSMC TFT_RES_320x240 opt_enable TFT_INTERFACE_SPI TFT_RES_480x320 exec_test $1 $2 "MKS Robin v2 nano New Color UI 480x320 SPI" +# +# MKS Robin v2 nano LVGL SPI + TMC +# (Robin v2 nano has no FSMC interface) +# +use_example_configs Mks/Robin +opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 +opt_disable TFT_INTERFACE_FSMC TFT_COLOR_UI TOUCH_SCREEN TFT_RES_320x240 +opt_enable TFT_INTERFACE_SPI TFT_LVGL_UI TFT_RES_480x320 +opt_set X_DRIVER_TYPE TMC2209 +opt_set Y_DRIVER_TYPE TMC2209 +exec_test $1 $2 "MKS Robin v2 nano LVGL SPI + TMC" + # cleanup restore_configs diff --git a/platformio.ini b/platformio.ini index 326dca172f..3e565e6c4e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -222,6 +222,7 @@ NEOPIXEL_LED = Adafruit NeoPixel@1.5.0 src_filter=+ MAX6675_IS_MAX31865 = Adafruit MAX31865 library@~1.1.0 USES_LIQUIDCRYSTAL = LiquidCrystal@1.5.0 +USES_LIQUIDCRYSTAL_I2C = marcoschwartz/LiquidCrystal_I2C@1.1.4 USES_LIQUIDTWI2 = LiquidTWI2@1.2.7 HAS_WIRED_LCD = src_filter=+ HAS_MARLINUI_HD44780 = src_filter=+ @@ -560,7 +561,7 @@ build_unflags = -g -ggdb platform = teensy extends = common_avr8 board = at90usb1286 -lib_ignore = ${env:common_avr8.lib_ignore} Teensy_ADC +lib_ignore = ${env:common_avr8.lib_ignore}, Teensy_ADC, NativeEthernet # # AT90USB1286 boards using DFU bootloader