123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "Tcodes.h"
- #include "AutoDeplete.h"
- #include "Marlin.h"
- #include "language.h"
- #include "messages.h"
- #include "mmu2.h"
- #include "stepper.h"
- #include "ultralcd.h"
- #include <avr/pgmspace.h>
- #include <ctype.h>
- #include <stdint.h>
- #include <stdio.h>
- static const char duplicate_Tcode_ignored[] PROGMEM = "Duplicate T-code ignored.";
- inline bool IsInvalidTCode(char *const s, uint8_t i) {
- return ((s[i] < '0' || s[i] > '4') && s[i] != '?' && s[i] != 'x' && s[i] != 'c');
- }
- inline void TCodeInvalid() {
- SERIAL_ECHOLNPGM("Invalid T code.");
- }
- struct SChooseFromMenu {
- uint8_t slot:7;
- uint8_t loadToNozzle:1;
- inline constexpr SChooseFromMenu(uint8_t slot, bool loadToNozzle):slot(slot), loadToNozzle(loadToNozzle){}
- inline constexpr SChooseFromMenu():slot(0), loadToNozzle(false) { }
- };
- SChooseFromMenu TCodeChooseFromMenu() {
- if (MMU2::mmu2.Enabled()) {
- return SChooseFromMenu( choose_menu_P(_T(MSG_CHOOSE_FILAMENT), _T(MSG_FILAMENT)), true );
- } else {
- return SChooseFromMenu( choose_menu_P(_T(MSG_CHOOSE_EXTRUDER), _T(MSG_EXTRUDER)), false );
- }
- }
- void TCodes(char *const strchr_pointer, uint8_t codeValue) {
- uint8_t index = 1;
- for ( ; strchr_pointer[index] == ' ' || strchr_pointer[index] == '\t'; index++)
- ;
- strchr_pointer[index] = tolower(strchr_pointer[index]);
- if (IsInvalidTCode(strchr_pointer, index)){
- TCodeInvalid();
- } else if (strchr_pointer[index] == 'x'){
-
- if (MMU2::mmu2.Enabled()) {
- MMU2::mmu2.tool_change(strchr_pointer[index], choose_menu_P(_T(MSG_CHOOSE_EXTRUDER), _T(MSG_EXTRUDER)));
- }
- } else if (strchr_pointer[index] == 'c'){
-
- if (MMU2::mmu2.Enabled()) {
- MMU2::mmu2.tool_change(strchr_pointer[index], MMU2::mmu2.get_current_tool());
- }
- } else {
- SChooseFromMenu selectedSlot;
- selectedSlot.slot = codeValue;
- st_synchronize();
- if (MMU2::mmu2.Enabled()) {
- if (selectedSlot.slot == MMU2::mmu2.get_current_tool()){
-
- puts_P(duplicate_Tcode_ignored);
- } else {
- #if defined(MMU_HAS_CUTTER) && defined(MMU_ALWAYS_CUT)
- if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t *)EEPROM_MMU_CUTTER_ENABLED)) {
- mmu_command(MmuCmd::K0 + selectedSlot);
- manage_response(true, true, MMU_UNLOAD_MOVE);
- }
- #endif
- if (selectedSlot.loadToNozzle){
- MMU2::mmu2.load_filament_to_nozzle(selectedSlot.slot);
- } else {
- MMU2::mmu2.tool_change(selectedSlot.slot);
- }
- }
- } else {
- if (selectedSlot.slot >= EXTRUDERS) {
- SERIAL_ECHO_START;
- SERIAL_ECHO('T');
- SERIAL_ECHOLN(selectedSlot.slot + '0');
- SERIAL_ECHOLNRPGM(_n("Invalid extruder"));
- } else {
- SERIAL_ECHO_START;
- SERIAL_ECHORPGM(_n("Active Extruder: "));
- SERIAL_ECHOLN(active_extruder + '0');
- }
- }
- }
- }
|