From 329012a4614e65d3126c2dc41ac8227806dc3b28 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. It's a thing Marlin does and Octorprint needs to see it before it will use M155. Usage: M155 S [P] S specifies the period in seconds to report the temperatures P optionally specifies which sensor to report S0 disables automatic reporting Omitting the P field reports on all sensors --- clock.c | 2 ++ gcode_process.c | 36 +++++++++++++++++++++++++++++++++++- temp.c | 28 ++++++++++++++++++++++++++++ temp.h | 3 +++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/clock.c b/clock.c index 081b1f9c0..3a83f9b4c 100644 --- a/clock.c +++ b/clock.c @@ -95,6 +95,8 @@ static void clock_250ms(void) { temp_residency_tick(); + temp_periodic_print(); + if (temp_waiting()) { serial_writestr_P(PSTR("Waiting for target temp\n")); wait_for_temp = 1; diff --git a/gcode_process.c b/gcode_process.c index 90c634311..bc55fdf7f 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -702,7 +702,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: @@ -848,6 +853,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..c3ecc6910 100644 --- a/temp.c +++ b/temp.c @@ -108,6 +108,13 @@ static struct { static uint8_t wait_for_temp = 0; +// How often to report temperature automatically +static uint8_t periodic_seconds; +static temp_sensor_t periodic_index; + +// Count time between temperature reports +static uint8_t periodic_timer; + /// Set up temp sensors. void temp_init() { temp_sensor_t i; @@ -626,6 +633,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_seconds = secs; + periodic_index = index; + periodic_timer = secs; +} + +/// send temperatures to the host periodically. +/// Called once per second from clock.c +void temp_periodic_print() { + if (periodic_seconds == 0) + return; + if (--periodic_timer != 0) + return; + + temp_print(periodic_index); + periodic_timer = periodic_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);