From 2133c443728f7ed9a1764697551f1d5ff4a42a42 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Mon, 13 Dec 2021 14:39:58 +0000 Subject: Added support for M957 --- src/FilamentMonitors/FilamentMonitor.cpp | 4 +--- src/GCodes/GCodes.h | 1 + src/GCodes/GCodes2.cpp | 8 ++++++-- src/GCodes/GCodes3.cpp | 33 +++++++++++++++++++++++++++++++- src/Heating/LocalHeater.cpp | 3 +-- src/Platform/Event.cpp | 12 +++++++++++- src/Platform/Event.h | 5 ++++- src/Platform/Platform.cpp | 2 +- src/Version.h | 2 +- 9 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/FilamentMonitors/FilamentMonitor.cpp b/src/FilamentMonitors/FilamentMonitor.cpp index 9cf6b686..9c2d15e2 100644 --- a/src/FilamentMonitors/FilamentMonitor.cpp +++ b/src/FilamentMonitors/FilamentMonitor.cpp @@ -335,9 +335,7 @@ bool FilamentMonitor::IsValid(size_t extruderNumber) const noexcept } else { - va_list dummy; - Event::AddEvent(EventType::filament_error, (uint16_t)fst.ToBaseType(), extruder, CanInterface::GetCanAddress(), "", dummy); -// gCodes.FilamentError(extruder, fst); + Event::AddEvent(EventType::filament_error, (uint16_t)fst.ToBaseType(), extruder, CanInterface::GetCanAddress(), ""); } } } diff --git a/src/GCodes/GCodes.h b/src/GCodes/GCodes.h index 093c1511..af4eebbe 100644 --- a/src/GCodes/GCodes.h +++ b/src/GCodes/GCodes.h @@ -473,6 +473,7 @@ private: GCodeResult SendI2c(GCodeBuffer& gb, const StringRef &reply) THROWS(GCodeException); // Handle M260 GCodeResult ReceiveI2c(GCodeBuffer& gb, const StringRef &reply) THROWS(GCodeException); // Handle M261 GCodeResult WaitForPin(GCodeBuffer& gb, const StringRef &reply) THROWS(GCodeException); // Handle M577 + GCodeResult RaiseEvent(GCodeBuffer& gb, const StringRef &reply) THROWS(GCodeException); // Handle M957 #if HAS_WIFI_NETWORKING || HAS_AUX_DEVICES || HAS_MASS_STORAGE || HAS_SBC_INTERFACE GCodeResult UpdateFirmware(GCodeBuffer& gb, const StringRef &reply) THROWS(GCodeException); // Handle M997 diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index dee5ea47..40400a87 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -4515,15 +4515,19 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx #endif #if SUPPORT_ACCELEROMETERS - case 955: + case 955: // configure accelerometer result = Accelerometers::ConfigureAccelerometer(gb, reply); break; - case 956: + case 956: // start accelerometer result = Accelerometers::StartAccelerometer(gb, reply); break; #endif + case 957: // raise event + result = RaiseEvent(gb, reply); + break; + #if HAS_WIFI_NETWORKING || HAS_AUX_DEVICES || HAS_MASS_STORAGE || HAS_SBC_INTERFACE case 997: // Perform firmware update result = UpdateFirmware(gb, reply); diff --git a/src/GCodes/GCodes3.cpp b/src/GCodes/GCodes3.cpp index 0db8487a..c534b5bc 100644 --- a/src/GCodes/GCodes3.cpp +++ b/src/GCodes/GCodes3.cpp @@ -1868,7 +1868,38 @@ bool GCodes::ProcessWholeLineComment(GCodeBuffer& gb, const StringRef& reply) TH return true; } -// Process and event. The autoPauseGCode buffer calls this when there is a new event to be processed. +// Handle M957 +GCodeResult GCodes::RaiseEvent(GCodeBuffer& gb, const StringRef &reply) THROWS(GCodeException) +{ + String temp; + gb.MustSee('E'); + gb.GetQuotedString(temp.GetRef(), false); + const EventType et(temp.c_str()); + if (!et.IsValid()) + { + reply.copy("Invalid event type"); + return GCodeResult::error; + } + + const unsigned int devNum = gb.GetLimitedUIValue('D', 256); + const unsigned int param = (gb.Seen('P')) ? gb.GetUIValue() : 0; + const unsigned int boardAddress = (gb.Seen('B')) ? gb.GetUIValue() : CanInterface::GetCanAddress(); + temp.Clear(); + if (gb.Seen('S')) + { + gb.GetQuotedString(temp.GetRef(), true); + } + + const bool added = Event::AddEvent(et, param, boardAddress, devNum, "%s", temp.c_str()); + if (added) + { + return GCodeResult::ok; + } + reply.copy("a similar event is already queued"); + return GCodeResult::warning; +} + +// Process an event. The autoPauseGCode buffer calls this when there is a new event to be processed. // This is a separate function because it allocates strings on the stack. void GCodes::ProcessEvent(GCodeBuffer& gb) noexcept { diff --git a/src/Heating/LocalHeater.cpp b/src/Heating/LocalHeater.cpp index 4f21b246..fbc3be32 100644 --- a/src/Heating/LocalHeater.cpp +++ b/src/Heating/LocalHeater.cpp @@ -933,10 +933,9 @@ void LocalHeater::RaiseHeaterFault(HeaterFaultType type, const char *_ecv_array else #endif { - Event::AddEvent(EventType::heater_fault, (uint16_t)type, GetHeaterNumber(), CanInterface::GetCanAddress(), format, vargs); + Event::AddEventV(EventType::heater_fault, (uint16_t)type, GetHeaterNumber(), CanInterface::GetCanAddress(), format, vargs); } va_end(vargs); -// reprap.GetGCodes().HandleHeaterFault(); } } diff --git a/src/Platform/Event.cpp b/src/Platform/Event.cpp index 825caf03..4757bbe8 100644 --- a/src/Platform/Event.cpp +++ b/src/Platform/Event.cpp @@ -18,9 +18,19 @@ inline Event::Event(Event *_ecv_null pnext, EventType et, uint16_t p_param, uint text.vprintf(format, vargs); } +// Queue an event, or release it if we have a similar event pending already. Returns true if the event was added, false if it was released. +/*static*/ bool Event::AddEvent(EventType et, uint16_t p_param, CanAddress p_ba, uint8_t devNum, const char *_ecv_array format, ...) noexcept +{ + va_list vargs; + va_start(vargs, format); + const bool ret = AddEventV(et, p_param, p_ba, devNum, format, vargs); + va_end(vargs); + return ret; +} + // Queue an event unless we have a similar event pending already. Returns true if the event was added. // The event list is held in priority order, lowest numbered (highest priority) events first. -/*static*/ bool Event::AddEvent(EventType et, uint16_t p_param, uint8_t devNum, CanAddress p_ba, const char *_ecv_array format, va_list vargs) noexcept +/*static*/ bool Event::AddEventV(EventType et, uint16_t p_param, uint8_t devNum, CanAddress p_ba, const char *_ecv_array format, va_list vargs) noexcept { // Search for similar events already pending or being processed. // An event is 'similar' if it has the same type, device number and parameter even if the text is different. diff --git a/src/Platform/Event.h b/src/Platform/Event.h index 3f10b4af..edeb12b2 100644 --- a/src/Platform/Event.h +++ b/src/Platform/Event.h @@ -43,7 +43,10 @@ public: static MessageType GetTextDescription(const StringRef& str) noexcept; // Queue an event, or release it if we have a similar event pending already. Returns true if the event was added, false if it was released. - static bool AddEvent(EventType et, uint16_t p_param, CanAddress p_ba, uint8_t devNum, const char *_ecv_array format, va_list vargs) noexcept; + static bool AddEvent(EventType et, uint16_t p_param, CanAddress p_ba, uint8_t devNum, const char *_ecv_array format, ...) noexcept; + + // Queue an event, or release it if we have a similar event pending already. Returns true if the event was added, false if it was released. + static bool AddEventV(EventType et, uint16_t p_param, CanAddress p_ba, uint8_t devNum, const char *_ecv_array format, va_list vargs) noexcept; // Get the highest priority event if there is one start processing it static bool StartProcessing() noexcept; diff --git a/src/Platform/Platform.cpp b/src/Platform/Platform.cpp index 7e32200b..cda05c8e 100644 --- a/src/Platform/Platform.cpp +++ b/src/Platform/Platform.cpp @@ -1162,7 +1162,7 @@ void Platform::Spin() noexcept # endif if (eventOnStallDrivers.Intersects(mask)) { - Event::AddEvent(EventType::driver_stall, 0, CanInterface::GetCanAddress(), nextDriveToPoll, "", va_list()); + Event::AddEvent(EventType::driver_stall, 0, CanInterface::GetCanAddress(), nextDriveToPoll, ""); } else if (logOnStallDrivers.Intersects(mask)) { diff --git a/src/Version.h b/src/Version.h index 7ad8e8df..fa5b9479 100644 --- a/src/Version.h +++ b/src/Version.h @@ -10,7 +10,7 @@ #ifndef VERSION // Note: the complete VERSION string must be in standard version number format and must not contain spaces! This is so that DWC can parse it. -# define MAIN_VERSION "3.4.0beta6+2" +# define MAIN_VERSION "3.4.0beta6+3" # ifdef USE_CAN0 # define VERSION_SUFFIX "(CAN0)" # else -- cgit v1.2.3