aboutsummaryrefslogtreecommitdiff
path: root/Marlin/src/gcode/config/M305.cpp
blob: 3e7206aee49d4cc17418a03f49b6a8abcab03071 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
 * Marlin 3D Printer Firmware
 * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
 *
 * Based on Sprinter and grbl.
 * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

#include "../../inc/MarlinConfig.h"

#if HAS_USER_THERMISTORS

#include "../gcode.h"
#include "../../module/temperature.h"

/**
 * M305: Set (or report) custom thermistor parameters
 *
 *   P[index]  Thermistor table index
 *   R[ohms]   Pullup resistor value
 *   T[ohms]   Resistance at 25C
 *   B[beta]   Thermistor "beta" value
 *   C[coeff]  Steinhart-Hart Coefficient 'C'
 *
 *   Format: M305 P[tbl_index] R[pullup_resistor_val] T[therm_25C_resistance] B[therm_beta] C[Steinhart_Hart_C_coeff]
 *
 * Examples: M305 P0 R4700 T100000 B3950 C0.0
 *           M305 P0 R4700
 *           M305 P0 T100000
 *           M305 P0 B3950
 *           M305 P0 C0.0
 */
void GcodeSuite::M305() {
  const int8_t t_index = parser.intval('P', -1);
  const bool do_set = parser.seen("BCRT");

  // A valid P index is required
  if (t_index >= (USER_THERMISTORS) || (do_set && t_index < 0)) {
    SERIAL_ECHO_START();
    SERIAL_ECHOLNPAIR("!Invalid index. (0 <= P <= ", int(USER_THERMISTORS - 1), ")");
  }
  else if (do_set) {
    if (parser.seen('R')) // Pullup resistor value
      if (!thermalManager.set_pull_up_res(t_index, parser.value_float()))
        SERIAL_ECHO_MSG("!Invalid series resistance. (0 < R < 1000000)");

    if (parser.seen('T')) // Resistance at 25C
      if (!thermalManager.set_res25(t_index, parser.value_float()))
        SERIAL_ECHO_MSG("!Invalid 25C resistance. (0 < T < 10000000)");

    if (parser.seen('B')) // Beta value
      if (!thermalManager.set_beta(t_index, parser.value_float()))
        SERIAL_ECHO_MSG("!Invalid beta. (0 < B < 1000000)");

    if (parser.seen('C')) // Steinhart-Hart C coefficient
      if (!thermalManager.set_sh_coeff(t_index, parser.value_float()))
        SERIAL_ECHO_MSG("!Invalid Steinhart-Hart C coeff. (-0.01 < C < +0.01)");
  }                       // If not setting then report parameters
  else if (t_index < 0) { // ...all user thermistors
    LOOP_L_N(i, USER_THERMISTORS)
      thermalManager.log_user_thermistor(i);
  }
  else                    // ...one user thermistor
    thermalManager.log_user_thermistor(t_index);
}

#endif // HAS_USER_THERMISTORS