Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use incomplete clock sync for SPI temperature; always warn #303

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion klippy/clocksync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, math
import logging, math, traceback

RTT_AGE = 0.000010 / (60.0 * 60.0)
DECAY = 1.0 / 30.0
Expand Down Expand Up @@ -237,10 +237,18 @@ def connect_file(self, serial, pace=False):

# clock frequency conversions
def print_time_to_clock(self, print_time):
if self.clock_adj[1] == 1.0:
logging.warning("Clock not yet synchronized, clock is untrustworthy")
for line in traceback.format_stack():
logging.warning(line.strip())
adjusted_offset, adjusted_freq = self.clock_adj
return int((print_time - adjusted_offset) * adjusted_freq)

def clock_to_print_time(self, clock):
if self.clock_adj[1] == 1.0:
logging.warning("Clock not yet synchronized, print time is untrustworthy")
for line in traceback.format_stack():
logging.warning(line.strip())
adjusted_offset, adjusted_freq = self.clock_adj
return clock / adjusted_freq + adjusted_offset

Expand Down
9 changes: 9 additions & 0 deletions klippy/extras/spi_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ def __init__(self, config, chip_type, config_cmd=None, spi_mode=1):
self.mcu = mcu = self.spi.get_mcu()
# Reader chip configuration
self.oid = oid = mcu.create_oid()
self.printer.register_event_handler(
"klippy:connect", self._handle_connect
)
mcu.register_response(
self._handle_spi_response, "thermocouple_result", oid
)
self._is_connected = False
mcu.register_config_callback(self._build_config)

def setup_minmax(self, min_temp, max_temp):
Expand All @@ -48,6 +52,9 @@ def setup_callback(self, cb):
def get_report_time_delta(self):
return REPORT_TIME

def _handle_connect(self):
self._is_connected = True

def _build_config(self):
self.mcu.add_config_cmd(
"config_thermocouple oid=%u spi_oid=%u thermocouple_type=%s"
Expand Down Expand Up @@ -76,6 +83,8 @@ def _build_config(self):
)

def _handle_spi_response(self, params):
if not self._is_connected:
return
if params["fault"]:
self.handle_fault(params["value"], params["fault"])
return
Expand Down
Loading