@@ -294,13 +294,80 @@ struct SetStatusBarState {
294294 }
295295};
296296
297+ struct SetPressureState {
298+ /*
299+ * M120- SetPressureState set state of pressure control (target pressure,
300+ * current pressure)
301+ * */
302+ double pressure = 0 ;
303+ uint32_t duration_s = 0 ;
304+ double ramp_rate = 0 ;
305+ bool vent_after = false ;
306+ bool start_pump = false ;
307+
308+ using ParseResult = std::optional<SetPressureState>;
309+ static constexpr auto prefix = std::array{' M' , ' 1' , ' 2' , ' 0' , ' ' };
310+ static constexpr const char * response = " M120 OK\n " ;
311+
312+ using StartArg = Arg<uint8_t , ' S' >;
313+ using PressureArg = Arg<uint16_t , ' P' >;
314+ using DurationArg = Arg<uint32_t , ' D' >;
315+ using RampArg = Arg<uint16_t , ' R' >;
316+ using VentArg = Arg<uint8_t , ' V' >;
317+
318+ template <typename InputIt, typename Limit>
319+ requires std::forward_iterator<InputIt> &&
320+ std::sized_sentinel_for<Limit, InputIt>
321+ static auto parse (const InputIt& input, Limit limit)
322+ -> std::pair<ParseResult, InputIt> {
323+ auto res =
324+ gcode::SingleParser<StartArg, PressureArg, DurationArg, RampArg,
325+ VentArg>::parse_gcode (input, limit, prefix);
326+ if (!res.first .has_value ()) {
327+ return std::make_pair (ParseResult (), input);
328+ }
329+
330+ auto ret = SetPressureState{.pressure = 0.0 ,
331+ .duration_s = 0 ,
332+ .ramp_rate = 0.0 ,
333+ .vent_after = false ,
334+ .start_pump = false };
335+
336+ auto arguments = res.first .value ();
337+ if (std::get<0 >(arguments).present ) {
338+ ret.start_pump = static_cast <bool >(std::get<0 >(arguments).value );
339+ }
340+ if (std::get<1 >(arguments).present ) {
341+ ret.pressure = static_cast <double >(std::get<1 >(arguments).value );
342+ }
343+ if (std::get<2 >(arguments).present ) {
344+ ret.duration_s =
345+ static_cast <uint32_t >(std::get<2 >(arguments).value );
346+ }
347+ if (std::get<3 >(arguments).present ) {
348+ ret.ramp_rate = static_cast <double >(std::get<3 >(arguments).value );
349+ }
350+ if (std::get<4 >(arguments).present ) {
351+ ret.vent_after = static_cast <bool >(std::get<4 >(arguments).value );
352+ }
353+ return std::make_pair (ret, res.second );
354+ }
355+
356+ template <typename InputIt, typename InLimit>
357+ requires std::forward_iterator<InputIt> &&
358+ std::sized_sentinel_for<InputIt, InLimit>
359+ static auto write_response_into (InputIt buf, InLimit limit) -> InputIt {
360+ return write_string_to_iterpair (buf, limit, response);
361+ }
362+ };
363+
297364struct GetPressureState {
298365 /*
299- * M120 - GetPressureState get state of pressure control (target pressure,
366+ * M121 - GetPressureState get state of pressure control (target pressure,
300367 * current pressure)
301368 * */
302369 using ParseResult = std::optional<GetPressureState>;
303- static constexpr auto prefix = std::array{' M' , ' 1' , ' 2' , ' 0 ' };
370+ static constexpr auto prefix = std::array{' M' , ' 1' , ' 2' , ' 1 ' };
304371
305372 template <typename InputIt, typename InLimit>
306373 requires std::forward_iterator<InputIt> &&
@@ -309,7 +376,7 @@ struct GetPressureState {
309376 double target_pressure,
310377 double current_pressure) -> InputIt {
311378 int res = 0 ;
312- res = snprintf (&*buf, (limit - buf), " M120 T:%d C:%d OK\n " ,
379+ res = snprintf (&*buf, (limit - buf), " M121 T:%d C:%d OK\n " ,
313380 target_pressure, current_pressure);
314381 if (res <= 0 ) {
315382 return buf;
@@ -332,12 +399,64 @@ struct GetPressureState {
332399 }
333400};
334401
402+ struct SetPumpState {
403+ /*
404+ * M122- SetPumpState set state of pump control (start pump, target rpm,
405+ * on/off)
406+ * */
407+ std::optional<double > target_rpm = 0 ;
408+ std::optional<uint8_t > duty_cycle = 0 ;
409+ bool start_pump = false ;
410+
411+ using ParseResult = std::optional<SetPumpState>;
412+ static constexpr auto prefix = std::array{' M' , ' 1' , ' 2' , ' 2' , ' ' };
413+ static constexpr const char * response = " M122 OK\n " ;
414+
415+ using StartArg = Arg<float , ' S' >;
416+ using RPMArg = Arg<uint16_t , ' R' >;
417+ using DutyArg = Arg<uint8_t , ' D' >;
418+
419+ template <typename InputIt, typename Limit>
420+ requires std::forward_iterator<InputIt> &&
421+ std::sized_sentinel_for<Limit, InputIt>
422+ static auto parse (const InputIt& input, Limit limit)
423+ -> std::pair<ParseResult, InputIt> {
424+ auto res = gcode::SingleParser<StartArg, RPMArg, DutyArg>::parse_gcode (
425+ input, limit, prefix);
426+ if (!res.first .has_value ()) {
427+ return std::make_pair (ParseResult (), input);
428+ }
429+
430+ auto ret =
431+ SetPumpState{.target_rpm = 0 , .duty_cycle = 0 , .start_pump = false };
432+
433+ auto arguments = res.first .value ();
434+ if (std::get<0 >(arguments).present ) {
435+ ret.start_pump = static_cast <bool >(std::get<0 >(arguments).value );
436+ }
437+ if (std::get<1 >(arguments).present ) {
438+ ret.target_rpm = static_cast <double >(std::get<1 >(arguments).value );
439+ }
440+ if (std::get<2 >(arguments).present ) {
441+ ret.duty_cycle = static_cast <uint8_t >(std::get<2 >(arguments).value );
442+ }
443+ return std::make_pair (ret, res.second );
444+ }
445+
446+ template <typename InputIt, typename InLimit>
447+ requires std::forward_iterator<InputIt> &&
448+ std::sized_sentinel_for<InputIt, InLimit>
449+ static auto write_response_into (InputIt buf, InLimit limit) -> InputIt {
450+ return write_string_to_iterpair (buf, limit, response);
451+ }
452+ };
453+
335454struct GetPumpState {
336455 /*
337- * M121 - GetPumpState state of the pump (target rpm, current rpm, etc)
456+ * M123 - GetPumpState state of the pump (target rpm, current rpm, etc)
338457 * */
339458 using ParseResult = std::optional<GetPumpState>;
340- static constexpr auto prefix = std::array{' M' , ' 1' , ' 2' , ' 1 ' };
459+ static constexpr auto prefix = std::array{' M' , ' 1' , ' 2' , ' 3 ' };
341460
342461 template <typename InputIt, typename InLimit>
343462 requires std::forward_iterator<InputIt> &&
@@ -346,7 +465,7 @@ struct GetPumpState {
346465 double target_rpm, double current_rpm)
347466 -> InputIt {
348467 int res = 0 ;
349- res = snprintf (&*buf, (limit - buf), " M121 T:%d C:%d OK\n " , target_rpm,
468+ res = snprintf (&*buf, (limit - buf), " M123 T:%d C:%d OK\n " , target_rpm,
350469 current_rpm);
351470 if (res <= 0 ) {
352471 return buf;
0 commit comments