123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- #pragma once
- #include "mmu2_protocol_logic.h"
- struct E_Step;
- namespace MMU2 {
- static constexpr uint8_t MAX_RETRIES = 3U;
- struct xyz_pos_t {
- float xyz[3];
- xyz_pos_t()=default;
- };
- enum : uint8_t {
- FILAMENT_UNKNOWN = 0xffU
- };
- struct Version {
- uint8_t major, minor, build;
- };
- class MMU2 {
- public:
- MMU2();
-
-
- void Start();
-
-
- void Stop();
-
-
-
-
-
-
-
-
- enum class xState : uint_fast8_t {
- Active,
- Connecting,
- Stopped
- };
-
- inline xState State() const { return state; }
-
-
- inline bool Enabled()const { return State() == xState::Active; }
-
- enum ResetForm : uint8_t {
- Software = 0,
- ResetPin = 1,
- CutThePower = 2
- };
-
- enum SavedState: uint8_t {
- None = 0,
- ParkExtruder = 1,
- Cooldown = 2,
- CooldownPending = 4,
- };
-
- enum ReportErrorSource: uint8_t {
- ErrorSourcePrinter = 0,
- ErrorSourceMMU = 1,
- };
-
-
- void Reset(ResetForm level);
-
-
- void PowerOff();
-
-
- void PowerOn();
-
-
-
- bool ReadRegister(uint8_t address);
-
-
-
-
- bool WriteRegister(uint8_t address, uint16_t data);
-
-
-
- void mmu_loop();
-
-
-
- bool tool_change(uint8_t index);
-
-
- bool tool_change(char code, uint8_t slot);
-
-
-
- bool unload();
-
-
- bool load_filament(uint8_t index);
-
-
-
- bool load_filament_to_nozzle(uint8_t index);
-
-
- bool eject_filament(uint8_t index, bool recover);
-
-
-
- bool cut_filament(uint8_t index);
-
- void get_statistics();
-
-
-
-
- bool load_to_extruder(uint8_t index);
-
- uint8_t get_current_tool() const;
-
- uint8_t get_tool_change_tool() const;
- bool set_filament_type(uint8_t index, uint8_t type);
-
-
- void Button(uint8_t index);
-
-
- void Home(uint8_t mode);
-
- inline bool FindaDetectsFilament()const { return logic.FindaPressed(); }
- inline uint16_t TotalFailStatistics()const { return logic.FailStatistics(); }
-
- inline ErrorCode MMUCurrentErrorCode() const { return logic.Error(); }
-
-
- Version GetMMUFWVersion()const {
- if( State() == xState::Active ){
- return { logic.MmuFwVersionMajor(), logic.MmuFwVersionMinor(), logic.MmuFwVersionRevision() };
- } else {
- return { 0, 0, 0};
- }
- }
-
- bool is_mmu_error_monitor_active;
-
- bool MMU_PRINT_SAVED() const { return mmu_print_saved != SavedState::None; }
-
- bool RetryIfPossible(uint16_t ec);
-
-
- void DecrementRetryAttempts();
- private:
-
- void ResetRetryAttempts();
-
- void ResetX0();
-
-
- void TriggerResetPin();
-
-
-
- void PowerCycle();
-
-
- void StopKeepPowered();
-
-
- void manage_response(const bool move_axes, const bool turn_off_nozzle);
-
-
-
-
- StepStatus LogicStep();
-
- void filament_ramming();
- void execute_extruder_sequence(const E_Step *sequence, uint8_t steps);
-
-
-
- void ReportError(ErrorCode ec, uint8_t res);
-
-
- void ReportProgress(ProgressCode pc);
-
-
-
- void OnMMUProgressMsg(ProgressCode pc);
-
- void OnMMUProgressMsgChanged(ProgressCode pc);
-
- void OnMMUProgressMsgSame(ProgressCode pc);
-
-
- void SaveAndPark(bool move_axes, bool turn_off_nozzle);
-
- void ResumeHotendTemp();
-
- void ResumeUnpark();
-
- void CheckUserInput();
-
-
-
- void CheckFINDARunout();
-
-
-
-
- bool WaitForMMUReady();
- ProtocolLogic logic;
- uint8_t extruder;
- uint8_t tool_change_extruder;
- xyz_pos_t resume_position;
- int16_t resume_hotend_temp;
-
- ProgressCode lastProgressCode = ProgressCode::OK;
- ErrorCode lastErrorCode = ErrorCode::MMU_NOT_RESPONDING;
- Buttons lastButton = Buttons::NoButton;
- StepStatus logicStepLastStatus;
-
- enum xState state;
- uint8_t mmu_print_saved;
- bool loadFilamentStarted;
- bool unloadFilamentStarted;
-
- friend struct LoadingToNozzleRAII;
-
-
- bool loadingToNozzle;
-
- bool inAutoRetry;
- uint8_t retryAttempts;
- };
- extern MMU2 mmu2;
- }
|