Apply more HAS_MULTI_6675

This commit is contained in:
Scott Lahteine 2020-11-09 01:37:17 -06:00
parent c47ca8db10
commit 4fddc5ce02

View file

@ -83,7 +83,9 @@
#endif #endif
#endif #endif
#define MAX6675_SEPARATE_SPI (EITHER(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675) && PINS_EXIST(MAX6675_SCK, MAX6675_DO)) #if EITHER(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675) && PINS_EXIST(MAX6675_SCK, MAX6675_DO)
#define MAX6675_SEPARATE_SPI 1
#endif
#if MAX6675_SEPARATE_SPI #if MAX6675_SEPARATE_SPI
#include "../libs/private_spi.h" #include "../libs/private_spi.h"
@ -2226,16 +2228,12 @@ void Temperature::disable_all_heaters() {
#define THERMOCOUPLE_MAX_ERRORS 15 #define THERMOCOUPLE_MAX_ERRORS 15
#endif #endif
int Temperature::read_max6675( int Temperature::read_max6675(TERN_(HAS_MULTI_6675, const uint8_t hindex/*=0*/)) {
#if COUNT_6675 > 1 #if HAS_MULTI_6675
const uint8_t hindex
#endif
) {
#if COUNT_6675 == 1
constexpr uint8_t hindex = 0;
#else
// Needed to return the correct temp when this is called too soon // Needed to return the correct temp when this is called too soon
static uint16_t max6675_temp_previous[COUNT_6675] = { 0 }; static uint16_t max6675_temp_previous[COUNT_6675] = { 0 };
#else
constexpr uint8_t hindex = 0;
#endif #endif
static uint8_t max6675_errors[COUNT_6675] = { 0 }; static uint8_t max6675_errors[COUNT_6675] = { 0 };
@ -2263,26 +2261,19 @@ void Temperature::disable_all_heaters() {
static millis_t next_max6675_ms[COUNT_6675] = { 0 }; static millis_t next_max6675_ms[COUNT_6675] = { 0 };
millis_t ms = millis(); millis_t ms = millis();
if (PENDING(ms, next_max6675_ms[hindex])) if (PENDING(ms, next_max6675_ms[hindex]))
return int( return int(TERN(HAS_MULTI_6675, max6675_temp_previous[hindex], max6675_temp));
#if COUNT_6675 == 1
max6675_temp
#else
max6675_temp_previous[hindex] // Need to return the correct previous value
#endif
);
next_max6675_ms[hindex] = ms + MAX6675_HEAT_INTERVAL; next_max6675_ms[hindex] = ms + MAX6675_HEAT_INTERVAL;
#if COUNT_6675 == 1 && MAX6675_IS_MAX31865 #if MAX6675_IS_MAX31865
max6675_temp = int(max31865_0.temperature(MAX31865_SENSOR_OHMS_0, MAX31865_CALIBRATION_OHMS_0)); max6675_temp = int(
#endif #if HAS_MULTI_6675
hindex ? max31865_1.temperature(MAX31865_SENSOR_OHMS_1, MAX31865_CALIBRATION_OHMS_1)
#if COUNT_6675 > 1 && MAX6675_IS_MAX31865 : max31865_0.temperature(MAX31865_SENSOR_OHMS_0, MAX31865_CALIBRATION_OHMS_0)
#if hindex == 0 #else
max6675_temp = int(max31865_0.temperature(MAX31865_SENSOR_OHMS_0, MAX31865_CALIBRATION_OHMS_0)); max31865_0.temperature(MAX31865_SENSOR_OHMS_0, MAX31865_CALIBRATION_OHMS_0)
#elif hindex == 1
max6675_temp = int(max31865_1.temperature(MAX31865_SENSOR_OHMS_1, MAX31865_CALIBRATION_OHMS_1));
#endif #endif
);
#endif #endif
// //
@ -2293,7 +2284,7 @@ void Temperature::disable_all_heaters() {
spiInit(MAX6675_SPEED_BITS); spiInit(MAX6675_SPEED_BITS);
#endif #endif
#if COUNT_6675 > 1 #if HAS_MULTI_6675
#define WRITE_MAX6675(V) do{ switch (hindex) { case 1: WRITE(MAX6675_SS2_PIN, V); break; default: WRITE(MAX6675_SS_PIN, V); } }while(0) #define WRITE_MAX6675(V) do{ switch (hindex) { case 1: WRITE(MAX6675_SS2_PIN, V); break; default: WRITE(MAX6675_SS_PIN, V); } }while(0)
#define SET_OUTPUT_MAX6675() do{ switch (hindex) { case 1: SET_OUTPUT(MAX6675_SS2_PIN); break; default: SET_OUTPUT(MAX6675_SS_PIN); } }while(0) #define SET_OUTPUT_MAX6675() do{ switch (hindex) { case 1: SET_OUTPUT(MAX6675_SS2_PIN); break; default: SET_OUTPUT(MAX6675_SS_PIN); } }while(0)
#elif HEATER_1_USES_MAX6675 #elif HEATER_1_USES_MAX6675
@ -2312,28 +2303,13 @@ void Temperature::disable_all_heaters() {
// Read a big-endian temperature value // Read a big-endian temperature value
max6675_temp = 0; max6675_temp = 0;
for (uint8_t i = sizeof(max6675_temp); i--;) { for (uint8_t i = sizeof(max6675_temp); i--;) {
max6675_temp |= ( max6675_temp |= TERN(MAX6675_SEPARATE_SPI, max6675_spi.receive(), spiRec());
#if MAX6675_SEPARATE_SPI
max6675_spi.receive()
#else
spiRec()
#endif
);
if (i > 0) max6675_temp <<= 8; // shift left if not the last byte if (i > 0) max6675_temp <<= 8; // shift left if not the last byte
} }
WRITE_MAX6675(HIGH); // disable TT_MAX6675 WRITE_MAX6675(HIGH); // disable TT_MAX6675
uint8_t fault = 1; const uint8_t fault = TERN0(MAX6675_IS_MAX31865, TERN_(HAS_MULTI_6675, hindex ? max31865_1.readFault() :) max31865_0.readFault());
#if COUNT_6675 == 1 && MAX6675_IS_MAX31865
fault = max31865_0.readFault();
#elif MAX6675_IS_MAX31865
#if hindex == 0
fault = max31865_0.readFault();
#elif hindex == 1
fault = max31865_1.readFault();
#endif
#endif
if (DISABLED(IGNORE_THERMOCOUPLE_ERRORS) && (max6675_temp & MAX6675_ERROR_MASK) && fault) { if (DISABLED(IGNORE_THERMOCOUPLE_ERRORS) && (max6675_temp & MAX6675_ERROR_MASK) && fault) {
max6675_errors[hindex] += 1; max6675_errors[hindex] += 1;
@ -2364,15 +2340,7 @@ void Temperature::disable_all_heaters() {
else if (fault & MAX31865_FAULT_OVUV) else if (fault & MAX31865_FAULT_OVUV)
SERIAL_ECHOLNPGM("Under/Over voltage"); SERIAL_ECHOLNPGM("Under/Over voltage");
#if COUNT_6675 == 1 TERN_(HAS_MULTI_6675, hindex ? max31865_1.clearFault() :) max31865_0.clearFault();
max31865_0.clearFault();
#else
#if hindex == 0
max31865_0.clearFault();
#elif hindex == 1
max31865_1.clearFault();
#endif
#endif
} }
#else #else
SERIAL_ECHOLNPGM("MAX6675"); SERIAL_ECHOLNPGM("MAX6675");
@ -2380,7 +2348,7 @@ void Temperature::disable_all_heaters() {
// Thermocouple open // Thermocouple open
max6675_temp = 4 * ( max6675_temp = 4 * (
#if COUNT_6675 > 1 #if HAS_MULTI_6675
hindex ? HEATER_1_MAX6675_TMAX : HEATER_0_MAX6675_TMAX hindex ? HEATER_1_MAX6675_TMAX : HEATER_0_MAX6675_TMAX
#else #else
TERN(HEATER_1_USES_MAX6675, HEATER_1_MAX6675_TMAX, HEATER_0_MAX6675_TMAX) TERN(HEATER_1_USES_MAX6675, HEATER_1_MAX6675_TMAX, HEATER_0_MAX6675_TMAX)
@ -2399,9 +2367,7 @@ void Temperature::disable_all_heaters() {
if (max6675_temp & 0x00002000) max6675_temp |= 0xFFFFC000; // Support negative temperature if (max6675_temp & 0x00002000) max6675_temp |= 0xFFFFC000; // Support negative temperature
#endif #endif
#if COUNT_6675 > 1 TERN_(HAS_MULTI_6675, max6675_temp_previous[hindex] = max6675_temp);
max6675_temp_previous[hindex] = max6675_temp;
#endif
return int(max6675_temp); return int(max6675_temp);
} }