mirror of
https://github.com/QIDITECH/klipper.git
synced 2026-02-02 17:08:41 +03:00
plus4的klipper版本
This commit is contained in:
@@ -28,6 +28,7 @@ struct thermocouple_spi {
|
||||
uint32_t min_value; // Min allowed ADC value
|
||||
uint32_t max_value; // Max allowed ADC value
|
||||
struct spidev_s *spi;
|
||||
uint8_t max_invalid, invalid_count;
|
||||
uint8_t chip_type, flags;
|
||||
};
|
||||
|
||||
@@ -75,11 +76,13 @@ command_query_thermocouple(uint32_t *args)
|
||||
return;
|
||||
spi->min_value = args[3];
|
||||
spi->max_value = args[4];
|
||||
spi->max_invalid = args[5];
|
||||
spi->invalid_count = 0;
|
||||
sched_add_timer(&spi->timer);
|
||||
}
|
||||
DECL_COMMAND(command_query_thermocouple,
|
||||
"query_thermocouple oid=%c clock=%u rest_ticks=%u"
|
||||
" min_value=%u max_value=%u");
|
||||
" min_value=%u max_value=%u max_invalid_count=%c");
|
||||
|
||||
static void
|
||||
thermocouple_respond(struct thermocouple_spi *spi, uint32_t next_begin_time
|
||||
@@ -88,8 +91,13 @@ thermocouple_respond(struct thermocouple_spi *spi, uint32_t next_begin_time
|
||||
sendf("thermocouple_result oid=%c next_clock=%u value=%u fault=%c",
|
||||
oid, next_begin_time, value, fault);
|
||||
/* check the result and stop if below or above allowed range */
|
||||
if (value < spi->min_value || value > spi->max_value)
|
||||
try_shutdown("Thermocouple ADC out of range");
|
||||
if (fault || value < spi->min_value || value > spi->max_value) {
|
||||
spi->invalid_count++;
|
||||
if (spi->invalid_count < spi->max_invalid)
|
||||
return;
|
||||
try_shutdown("Thermocouple reader fault");
|
||||
}
|
||||
spi->invalid_count = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -101,10 +109,7 @@ thermocouple_handle_max31855(struct thermocouple_spi *spi
|
||||
uint32_t value;
|
||||
memcpy(&value, msg, sizeof(value));
|
||||
value = be32_to_cpu(value);
|
||||
thermocouple_respond(spi, next_begin_time, value, 0, oid);
|
||||
// Kill after data send, host decode an error
|
||||
if (value & 0x04)
|
||||
try_shutdown("Thermocouple reader fault");
|
||||
thermocouple_respond(spi, next_begin_time, value, value & 0x07, oid);
|
||||
}
|
||||
|
||||
#define MAX31856_LTCBH_REG 0x0C
|
||||
@@ -142,10 +147,8 @@ thermocouple_handle_max31865(struct thermocouple_spi *spi
|
||||
msg[0] = MAX31865_FAULTSTAT_REG;
|
||||
msg[1] = 0x00;
|
||||
spidev_transfer(spi->spi, 1, 2, msg);
|
||||
thermocouple_respond(spi, next_begin_time, value, msg[1], oid);
|
||||
// Kill after data send, host decode an error
|
||||
if (value & 0x0001)
|
||||
try_shutdown("Thermocouple reader fault");
|
||||
uint8_t fault = (msg[1] & ~0x03) | (value & 0x0001);
|
||||
thermocouple_respond(spi, next_begin_time, value, fault, oid);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -157,10 +160,7 @@ thermocouple_handle_max6675(struct thermocouple_spi *spi
|
||||
uint16_t value;
|
||||
memcpy(&value, msg, sizeof(msg));
|
||||
value = be16_to_cpu(value);
|
||||
thermocouple_respond(spi, next_begin_time, value, 0, oid);
|
||||
// Kill after data send, host decode an error
|
||||
if (value & 0x04)
|
||||
try_shutdown("Thermocouple reader fault");
|
||||
thermocouple_respond(spi, next_begin_time, value, value & 0x06, oid);
|
||||
}
|
||||
|
||||
// task to read thermocouple and send response
|
||||
|
||||
Reference in New Issue
Block a user