From 47dfcf1a44d8fad4edac2b23cb894f98b961365c Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Sat, 4 Aug 2018 15:29:02 -0700 Subject: [PATCH] Add M155 support for periodic temperature reporting M155 turns on automatic periodic temperature reporting. Enables live temperature reporting while waiting for temps (M119) and during normal gcode processing without depending on M105 requests from the host. Also add "cap: AUTOREPORT_TEMP" capability report to M115. Octoprint relies on this feature to determine if M155 is supported. Perhaps this is a bug in Octoprint since M115 "cap" reporting is optional. Usage: M155 S [P] S specifies the period in seconds to report the temperatures P optionally specifies a 0-based sensor index to report S0 disables automatic reporting Omitting the P field reports on all sensors Example: M155 S5 Causes Teacup to send a temperature report for all sensors every 5 seconds. Ref: https://reprap.org/wiki/Firmware_Capabilities_Protocol --- clock.c | 1 + gcode_process.c | 36 +++++++++++++++++++++++++++++++++++- temp.c | 26 ++++++++++++++++++++++++++ temp.h | 3 +++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/clock.c b/clock.c index 081b1f9c0..06ea57499 100644 --- a/clock.c +++ b/clock.c @@ -94,6 +94,7 @@ static void clock_250ms(void) { #endif temp_residency_tick(); + temp_periodic_print(); if (temp_waiting()) { serial_writestr_P(PSTR("Waiting for target temp\n")); diff --git a/gcode_process.c b/gcode_process.c index c202246e2..d670f7150 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -644,7 +644,12 @@ void process_gcode_command() { //? FIRMWARE_NAME:Teacup FIRMWARE_URL:http://github.com/traumflug/Teacup_Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 TEMP_SENSOR_COUNT:1 HEATER_COUNT:1 //? - sersendf_P(PSTR("FIRMWARE_NAME:Teacup FIRMWARE_URL:http://github.com/traumflug/Teacup_Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:%d TEMP_SENSOR_COUNT:%d HEATER_COUNT:%d\n"), 1, NUM_TEMP_SENSORS, NUM_HEATERS); + sersendf_P(PSTR("FIRMWARE_NAME:Teacup " + "FIRMWARE_URL:http://github.com/traumflug/Teacup_Firmware/ " + "PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:%d " + "TEMP_SENSOR_COUNT:%d HEATER_COUNT:%d\n" + "cap:AUTOREPORT_TEMP:%d\n"), + 1, NUM_TEMP_SENSORS, NUM_HEATERS, 1); break; case 116: @@ -790,6 +795,35 @@ void process_gcode_command() { #endif break; + case 155: + //? --- M155: Report Temperature(s) Periodically --- + //? + //? Example: M155 Sn + //? + //? turns on periodic reporting of the temperatures of the current + //? extruder and the build base in degrees Celsius. The reporting + //? interval is given in seconds as the S parameter. Use S0 to disable + //? periodic temperature reporting. The reporting format is the same + //? as for M105, except there is no "ok" at the start of each report. + //? For example, the line sent to the host periodically looks like + //? + //? T:201 B:117 + //? + //? Teacup supports an optional P parameter as a zero-based temperature + //? sensor index to address. + //? + + // S is required + if ( ! next_target.seen_S) + break; + #ifdef ENFORCE_ORDER + queue_wait(); + #endif + if ( ! next_target.seen_P) + next_target.P = TEMP_SENSOR_none; + temp_periodic_config(next_target.S, next_target.P); + break; + case 220: //? --- M220: Set speed factor override percentage --- if ( ! next_target.seen_S) diff --git a/temp.c b/temp.c index 10ac04eec..9e36a1fb9 100644 --- a/temp.c +++ b/temp.c @@ -108,6 +108,11 @@ static struct { static uint8_t wait_for_temp = 0; +// Automatic temperature report period (AUTOREPORT_TEMP) +static uint8_t periodic_temp_seconds; +static temp_sensor_t periodic_temp_index; +static uint8_t periodic_temp_timer; + /// Set up temp sensors. void temp_init() { temp_sensor_t i; @@ -626,6 +631,27 @@ static void single_temp_print(temp_sensor_t index) { #endif } +/// set parameters for periodic temperature reporting +/// \param secs reporting interval in seconds; 0 to disable reporting +/// \param index sensor to report +void temp_periodic_config(uint8_t secs, temp_sensor_t index) { + periodic_temp_seconds = secs; + periodic_temp_index = index; + periodic_temp_timer = secs; +} + +/// send temperatures to the host periodically. +/// Called once per second from clock.c +void temp_periodic_print() { + if (periodic_temp_seconds == 0) + return; + if (--periodic_temp_timer != 0) + return; + + temp_print(periodic_temp_index); + periodic_temp_timer = periodic_temp_seconds; +} + /// send temperatures to host /// \param index sensor value to send void temp_print(temp_sensor_t index) { diff --git a/temp.h b/temp.h index f5fec4692..ed0c3836a 100644 --- a/temp.h +++ b/temp.h @@ -40,6 +40,9 @@ void temp_heater_tick(void); void temp_residency_tick(void); +void temp_periodic_config(uint8_t secs, temp_sensor_t index); +void temp_periodic_print(void); + uint8_t temp_achieved(void); void temp_set_wait(void);