Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Anycubic shared code (MarlinFirmware#25690)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and EvilGremlin committed May 17, 2023
1 parent b4f4285 commit 3241433
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 716 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

/**
* lcd/extui/anycubic_vyper/Tunes.cpp
* lcd/extui/anycubic/Tunes.cpp
*/

/***********************************************************************
Expand All @@ -31,28 +31,23 @@

#include "../../../inc/MarlinConfigPre.h"

#if ENABLED(ANYCUBIC_LCD_VYPER)
#if EITHER(ANYCUBIC_LCD_CHIRON, ANYCUBIC_LCD_VYPER)

#include "Tunes.h"
#include "../../../libs/buzzer.h"
#include "../ui_api.h"

namespace Anycubic {

void PlayTune(const uint8_t beeperPin, const uint16_t *tune, const uint8_t speed=1) {
uint8_t pos = 1;
uint16_t wholenotelen = tune[0] / speed;
do {
uint16_t freq = tune[pos];
uint16_t notelen = wholenotelen / tune[pos + 1];

::tone(beeperPin, freq, notelen);
ExtUI::delay_ms(notelen);
pos += 2;

if (pos >= MAX_TUNE_LENGTH) break;
} while (tune[pos] != n_END);
void PlayTune(const uint16_t *tune, const uint8_t speed=1) {
const uint16_t wholenotelen = tune[0] / speed;
for (uint8_t pos = 1; pos < MAX_TUNE_LENGTH; pos += 2) {
const uint16_t freq = tune[pos];
if (freq == n_END) break;
BUZZ(freq, wholenotelen / tune[pos + 1]);
}
}

}

#endif // ANYCUBIC_LCD_VYPER
#endif // ANYCUBIC_LCD_CHIRON || ANYCUBIC_LCD_VYPER
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#pragma once

/**
* lcd/extui/anycubic_vyper/Tunes.h
* lcd/extui/anycubic/Tunes.h
*/

/**************************************************************************
Expand All @@ -41,127 +41,23 @@

#define MAX_TUNE_LENGTH 128

// Special notes!
#define n_P 0 // silence or pause
#define n_END 10000 // end of tune marker

// Note duration divisors
#define l_T1 1
#define l_T2 2
#define l_T3 3
#define l_T4 4
#define l_T8 8
#define l_T16 16
enum { l_T1=1, l_T2 =2, l_T3=3, l_T4 =4, l_T8=8, l_T16=16 };

// Note Frequency
#define n_C0 16
#define n_CS0 17
#define n_D0 18
#define n_DS0 19
#define n_E0 21
#define n_F0 22
#define n_FS0 23
#define n_G0 25
#define n_GS0 26
#define n_A0 28
#define n_AS0 29
#define n_B0 31
#define n_C1 33
#define n_CS1 35
#define n_D1 37
#define n_DS1 39
#define n_E1 41
#define n_F1 44
#define n_FS1 46
#define n_G1 49
#define n_GS1 52
#define n_A1 55
#define n_AS1 58
#define n_B1 62
#define n_C2 65
#define n_CS2 69
#define n_D2 73
#define n_DS2 78
#define n_E2 82
#define n_F2 87
#define n_FS2 93
#define n_G2 98
#define n_GS2 104
#define n_A2 110
#define n_AS2 117
#define n_B2 123
#define n_C3 131
#define n_CS3 139
#define n_D3 147
#define n_DS3 156
#define n_E3 165
#define n_F3 175
#define n_FS3 185
#define n_G3 196
#define n_GS3 208
#define n_A3 220
#define n_AS3 233
#define n_B3 247
#define n_C4 262
#define n_CS4 277
#define n_D4 294
#define n_DS4 311
#define n_E4 330
#define n_F4 349
#define n_FS4 370
#define n_G4 392
#define n_GS4 415
#define n_A4 440
#define n_AS4 466
#define n_B4 494
#define n_C5 523
#define n_CS5 554
#define n_D5 587
#define n_DS5 622
#define n_E5 659
#define n_F5 698
#define n_FS5 740
#define n_G5 784
#define n_GS5 831
#define n_A5 880
#define n_AS5 932
#define n_B5 988
#define n_C6 1047
#define n_CS6 1109
#define n_D6 1175
#define n_DS6 1245
#define n_E6 1319
#define n_F6 1397
#define n_FS6 1480
#define n_G6 1568
#define n_GS6 1661
#define n_A6 1760
#define n_AS6 1865
#define n_B6 1976
#define n_C7 2093
#define n_CS7 2217
#define n_D7 2349
#define n_DS7 2489
#define n_E7 2637
#define n_F7 2794
#define n_FS7 2960
#define n_G7 3136
#define n_GS7 3322
#define n_A7 3520
#define n_AS7 3729
#define n_B7 3951
#define n_C8 4186
#define n_CS8 4435
#define n_D8 4699
#define n_DS8 4978
#define n_E8 5274
#define n_F8 5587
#define n_FS8 5920
#define n_G8 6272
#define n_GS8 6645
#define n_A8 7040
#define n_AS8 7459
#define n_B8 7902
enum {
n_P = 0, // silence or pause
n_C0= 16, n_CS0= 17, n_D0= 18, n_DS0= 19, n_E0= 21, n_F0= 22, n_FS0= 23, n_G0= 25, n_GS0= 26, n_A0= 28, n_AS0= 29, n_B0= 31,
n_C1= 33, n_CS1= 35, n_D1= 37, n_DS1= 39, n_E1= 41, n_F1= 44, n_FS1= 46, n_G1= 49, n_GS1= 52, n_A1= 55, n_AS1= 58, n_B1= 62,
n_C2= 65, n_CS2= 69, n_D2= 73, n_DS2= 78, n_E2= 82, n_F2= 87, n_FS2= 93, n_G2= 98, n_GS2= 104, n_A2= 110, n_AS2= 117, n_B2= 123,
n_C3= 131, n_CS3= 139, n_D3= 147, n_DS3= 156, n_E3= 165, n_F3= 175, n_FS3= 185, n_G3= 196, n_GS3= 208, n_A3= 220, n_AS3= 233, n_B3= 247,
n_C4= 262, n_CS4= 277, n_D4= 294, n_DS4= 311, n_E4= 330, n_F4= 349, n_FS4= 370, n_G4= 392, n_GS4= 415, n_A4= 440, n_AS4= 466, n_B4= 494,
n_C5= 523, n_CS5= 554, n_D5= 587, n_DS5= 622, n_E5= 659, n_F5= 698, n_FS5= 740, n_G5= 784, n_GS5= 831, n_A5= 880, n_AS5= 932, n_B5= 988,
n_C6=1047, n_CS6=1109, n_D6=1175, n_DS6=1245, n_E6=1319, n_F6=1397, n_FS6=1480, n_G6=1568, n_GS6=1661, n_A6=1760, n_AS6=1865, n_B6=1976,
n_C7=2093, n_CS7=2217, n_D7=2349, n_DS7=2489, n_E7=2637, n_F7=2794, n_FS7=2960, n_G7=3136, n_GS7=3322, n_A7=3520, n_AS7=3729, n_B7=3951,
n_C8=4186, n_CS8=4435, n_D8=4699, n_DS8=4978, n_E8=5274, n_F8=5587, n_FS8=5920, n_G8=6272, n_GS8=6645, n_A8=7040, n_AS8=7459, n_B8=7902,
n_END=10000 // end of tune marker
};

namespace Anycubic {

Expand Down Expand Up @@ -194,8 +90,7 @@ namespace Anycubic {
const uint16_t Anycubic_PowerOn[] = {
1000,
n_F7,l_T8, n_P,l_T8, n_C7,l_T8, n_P,l_T8, n_D7,l_T8, n_P,l_T8,
n_E7,l_T8, n_P,l_T8, n_D7,l_T4, n_P,l_T4, n_G7,l_T4, n_P,l_T4,
n_A7,l_T2, n_P,l_T1,
n_E7,l_T8, n_P,l_T8, n_D7,l_T4, n_P,l_T4,
n_END
};

Expand Down
138 changes: 138 additions & 0 deletions Marlin/src/lcd/extui/anycubic/common_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

/**
* lcd/extui/anycubic/common_defs.h
*/

#include "../../../inc/MarlinConfigPre.h"

#define ACDEBUGLEVEL 0 // 0: off, 255: all levels enabled

#if ACDEBUGLEVEL
// Bit-masks for selective debug:
enum ACDebugMask : uint8_t {
AC_INFO = 1,
AC_ACTION = 2,
AC_FILE = 4,
AC_PANEL = 8,
AC_MARLIN = 16,
AC_SOME = 32,
AC_ALL = 64
};
#define ACDEBUG(mask) ( ((mask) & ACDEBUGLEVEL) == mask ) // Debug flag macro
#else
#define ACDEBUG(mask) false
#endif

#define TFTSer LCD_SERIAL // Serial interface for TFT panel now uses marlinserial
#define MAX_FOLDER_DEPTH 4 // Limit folder depth TFT has a limit for the file path
#define MAX_CMND_LEN 16 * MAX_FOLDER_DEPTH // Maximum Length for a Panel command
#define MAX_PATH_LEN 16 * MAX_FOLDER_DEPTH // Maximum number of characters in a SD file path

#define AC_HEATER_FAULT_VALIDATION_TIME 5 // number of 1/2 second loops before signalling a heater fault
#define AC_LOWEST_MESHPOINT_VAL Z_PROBE_LOW_POINT // The lowest value you can set for a single mesh point offset

// TFT panel commands
#define AC_msg_sd_card_inserted F("J00")
#define AC_msg_sd_card_removed F("J01")
#define AC_msg_no_sd_card F("J02")
#define AC_msg_usb_connected F("J03")
#define AC_msg_print_from_sd_card F("J04")
#define AC_msg_pause F("J05")
#define AC_msg_nozzle_heating F("J06")
#define AC_msg_nozzle_heating_done F("J07")
#define AC_msg_bed_heating F("J08")
#define AC_msg_bed_heating_done F("J09")
#define AC_msg_nozzle_temp_abnormal F("J10")
#define AC_msg_kill_lcd F("J11")
#define AC_msg_ready F("J12")
#define AC_msg_low_nozzle_temp F("J13")
#define AC_msg_print_complete F("J14")
#define AC_msg_filament_out_alert F("J15")
#define AC_msg_stop F("J16")
#define AC_msg_main_board_has_reset F("J17")
#define AC_msg_paused F("J18")
#define AC_msg_j19_unknown F("J19")
#define AC_msg_sd_file_open_success F("J20")
#define AC_msg_sd_file_open_failed F("J21")
#define AC_msg_level_monitor_finished F("J22")
#define AC_msg_filament_out_block F("J23")
#define AC_msg_probing_not_allowed F("J24")
#define AC_msg_probing_complete F("J25")
#define AC_msg_start_probing F("J26")
#define AC_msg_version F("J27")

// TFT panel messages
#define MARLIN_msg_start_probing PSTR("Probing Point 1/25")
#define MARLIN_msg_probing_failed PSTR("Probing Failed")
#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...")
#define MARLIN_msg_bed_heating PSTR("Bed Heating...")

#define MARLIN_msg_nozzle_parked PSTR("Nozzle Parked")
#define MARLIN_msg_heater_timeout PSTR("Heater Timeout")
#define MARLIN_msg_reheating PSTR("Reheating...")
#define MARLIN_msg_reheat_done PSTR("Reheat finished.")
#define MARLIN_msg_filament_purging PSTR("Filament Purging...")

#define MARLIN_msg_special_pause PSTR("PB") // AnyCubic

#define AC_cmnd_auto_unload_filament F("M701") // Marlin unload routine
#define AC_cmnd_auto_load_filament F("M702 M0 PB") // AnyCubic: Marlin load routine, pause for user to clean nozzle

#define AC_cmnd_manual_load_filament F("M83\nG1 E50 F700\nM82") // replace the manual panel commands with something a little faster
#define AC_cmnd_manual_unload_filament F("M83\nG1 E-50 F1200\nM82")
#define AC_cmnd_enable_leveling F("M420SV")
#define AC_cmnd_power_loss_recovery F("G28XYR5\nG28Z") // Lift, home X and Y then home Z when in 'safe' position

namespace Anycubic {

enum heater_state_t : uint8_t {
AC_heater_off,
AC_heater_temp_set,
AC_heater_temp_reached
};

enum timer_event_t : uint8_t {
AC_timer_started,
AC_timer_paused,
AC_timer_stopped
};

enum media_event_t : uint8_t {
AC_media_inserted,
AC_media_removed,
AC_media_error
};

enum file_menu_t : uint8_t {
AC_menu_file,
AC_menu_command,
AC_menu_change_to_file,
AC_menu_change_to_command
};

} // Anycubic
Loading

0 comments on commit 3241433

Please sign in to comment.