Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
Add M155 support for periodic temperature reporting
Browse files Browse the repository at this point in the history
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<period> [P<sensor>]
     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
  • Loading branch information
phord committed Aug 20, 2018
1 parent 7760ef3 commit 47dfcf1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
36 changes: 35 additions & 1 deletion gcode_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
//?
//? <tt>T:201 B:117</tt>
//?
//? Teacup supports an optional P parameter as a zero-based temperature
//? sensor index to address.
//?

// S<period-seconds> 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)
Expand Down
26 changes: 26 additions & 0 deletions temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 47dfcf1

Please sign in to comment.