mirror of
https://github.com/andreili/klipper.git
synced 2025-08-23 19:34:06 +02:00
sensor_hx71x: Update Sensors to report to load_cell_probe
Signed-off-by: Gareth Farrington <gareth@waves.ky>
This commit is contained in:
parent
42c9031c81
commit
69507a0354
@ -96,6 +96,7 @@ class ADS1220:
|
|||||||
self.printer, self._process_batch, self._start_measurements,
|
self.printer, self._process_batch, self._start_measurements,
|
||||||
self._finish_measurements, UPDATE_INTERVAL)
|
self._finish_measurements, UPDATE_INTERVAL)
|
||||||
# Command Configuration
|
# Command Configuration
|
||||||
|
self.attach_probe_cmd = None
|
||||||
mcu.add_config_cmd(
|
mcu.add_config_cmd(
|
||||||
"config_ads1220 oid=%d spi_oid=%d data_ready_pin=%s"
|
"config_ads1220 oid=%d spi_oid=%d data_ready_pin=%s"
|
||||||
% (self.oid, self.spi.get_oid(), self.data_ready_pin))
|
% (self.oid, self.spi.get_oid(), self.data_ready_pin))
|
||||||
@ -108,6 +109,8 @@ class ADS1220:
|
|||||||
cmdqueue = self.spi.get_command_queue()
|
cmdqueue = self.spi.get_command_queue()
|
||||||
self.query_ads1220_cmd = self.mcu.lookup_command(
|
self.query_ads1220_cmd = self.mcu.lookup_command(
|
||||||
"query_ads1220 oid=%c rest_ticks=%u", cq=cmdqueue)
|
"query_ads1220 oid=%c rest_ticks=%u", cq=cmdqueue)
|
||||||
|
self.attach_probe_cmd = self.mcu.lookup_command(
|
||||||
|
"ads1220_attach_load_cell_probe oid=%c load_cell_probe_oid=%c")
|
||||||
self.ffreader.setup_query_command("query_ads1220_status oid=%c",
|
self.ffreader.setup_query_command("query_ads1220_status oid=%c",
|
||||||
oid=self.oid, cq=cmdqueue)
|
oid=self.oid, cq=cmdqueue)
|
||||||
|
|
||||||
@ -126,6 +129,9 @@ class ADS1220:
|
|||||||
def add_client(self, callback):
|
def add_client(self, callback):
|
||||||
self.batch_bulk.add_client(callback)
|
self.batch_bulk.add_client(callback)
|
||||||
|
|
||||||
|
def attach_load_cell_probe(self, load_cell_probe_oid):
|
||||||
|
self.attach_probe_cmd.send([self.oid, load_cell_probe_oid])
|
||||||
|
|
||||||
# Measurement decoding
|
# Measurement decoding
|
||||||
def _convert_samples(self, samples):
|
def _convert_samples(self, samples):
|
||||||
adc_factor = 1. / (1 << 23)
|
adc_factor = 1. / (1 << 23)
|
||||||
|
@ -53,6 +53,7 @@ class HX71xBase:
|
|||||||
self._finish_measurements, UPDATE_INTERVAL)
|
self._finish_measurements, UPDATE_INTERVAL)
|
||||||
# Command Configuration
|
# Command Configuration
|
||||||
self.query_hx71x_cmd = None
|
self.query_hx71x_cmd = None
|
||||||
|
self.attach_probe_cmd = None
|
||||||
mcu.add_config_cmd(
|
mcu.add_config_cmd(
|
||||||
"config_hx71x oid=%d gain_channel=%d dout_pin=%s sclk_pin=%s"
|
"config_hx71x oid=%d gain_channel=%d dout_pin=%s sclk_pin=%s"
|
||||||
% (self.oid, self.gain_channel, self.dout_pin, self.sclk_pin))
|
% (self.oid, self.gain_channel, self.dout_pin, self.sclk_pin))
|
||||||
@ -64,10 +65,13 @@ class HX71xBase:
|
|||||||
def _build_config(self):
|
def _build_config(self):
|
||||||
self.query_hx71x_cmd = self.mcu.lookup_command(
|
self.query_hx71x_cmd = self.mcu.lookup_command(
|
||||||
"query_hx71x oid=%c rest_ticks=%u")
|
"query_hx71x oid=%c rest_ticks=%u")
|
||||||
|
self.attach_probe_cmd = self.mcu.lookup_command(
|
||||||
|
"hx71x_attach_load_cell_probe oid=%c load_cell_probe_oid=%c")
|
||||||
self.ffreader.setup_query_command("query_hx71x_status oid=%c",
|
self.ffreader.setup_query_command("query_hx71x_status oid=%c",
|
||||||
oid=self.oid,
|
oid=self.oid,
|
||||||
cq=self.mcu.alloc_command_queue())
|
cq=self.mcu.alloc_command_queue())
|
||||||
|
|
||||||
|
|
||||||
def get_mcu(self):
|
def get_mcu(self):
|
||||||
return self.mcu
|
return self.mcu
|
||||||
|
|
||||||
@ -83,6 +87,9 @@ class HX71xBase:
|
|||||||
def add_client(self, callback):
|
def add_client(self, callback):
|
||||||
self.batch_bulk.add_client(callback)
|
self.batch_bulk.add_client(callback)
|
||||||
|
|
||||||
|
def attach_load_cell_probe(self, load_cell_probe_oid):
|
||||||
|
self.attach_probe_cmd.send([self.oid, load_cell_probe_oid])
|
||||||
|
|
||||||
# Measurement decoding
|
# Measurement decoding
|
||||||
def _convert_samples(self, samples):
|
def _convert_samples(self, samples):
|
||||||
adc_factor = 1. / (1 << 23)
|
adc_factor = 1. / (1 << 23)
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
#include "sched.h" // sched_add_timer
|
#include "sched.h" // sched_add_timer
|
||||||
#include "sensor_bulk.h" // sensor_bulk_report
|
#include "sensor_bulk.h" // sensor_bulk_report
|
||||||
|
#include "load_cell_probe.h" // load_cell_probe_report_sample
|
||||||
#include "spicmds.h" // spidev_transfer
|
#include "spicmds.h" // spidev_transfer
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ struct ads1220_adc {
|
|||||||
struct spidev_s *spi;
|
struct spidev_s *spi;
|
||||||
uint8_t pending_flag, data_count;
|
uint8_t pending_flag, data_count;
|
||||||
struct sensor_bulk sb;
|
struct sensor_bulk sb;
|
||||||
|
struct load_cell_probe *lce;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flag types
|
// Flag types
|
||||||
@ -94,6 +96,11 @@ ads1220_read_adc(struct ads1220_adc *ads1220, uint8_t oid)
|
|||||||
if (counts & 0x800000)
|
if (counts & 0x800000)
|
||||||
counts |= 0xFF000000;
|
counts |= 0xFF000000;
|
||||||
|
|
||||||
|
// endstop is optional, report if enabled and no errors
|
||||||
|
if (ads1220->lce) {
|
||||||
|
load_cell_probe_report_sample(ads1220->lce, counts);
|
||||||
|
}
|
||||||
|
|
||||||
add_sample(ads1220, oid, counts);
|
add_sample(ads1220, oid, counts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +118,15 @@ command_config_ads1220(uint32_t *args)
|
|||||||
DECL_COMMAND(command_config_ads1220, "config_ads1220 oid=%c"
|
DECL_COMMAND(command_config_ads1220, "config_ads1220 oid=%c"
|
||||||
" spi_oid=%c data_ready_pin=%u");
|
" spi_oid=%c data_ready_pin=%u");
|
||||||
|
|
||||||
|
void
|
||||||
|
ads1220_attach_load_cell_probe(uint32_t *args) {
|
||||||
|
uint8_t oid = args[0];
|
||||||
|
struct ads1220_adc *ads1220 = oid_lookup(oid, command_config_ads1220);
|
||||||
|
ads1220->lce = load_cell_probe_oid_lookup(args[1]);
|
||||||
|
}
|
||||||
|
DECL_COMMAND(ads1220_attach_load_cell_probe,
|
||||||
|
"ads1220_attach_load_cell_probe oid=%c load_cell_probe_oid=%c");
|
||||||
|
|
||||||
// start/stop capturing ADC data
|
// start/stop capturing ADC data
|
||||||
void
|
void
|
||||||
command_query_ads1220(uint32_t *args)
|
command_query_ads1220(uint32_t *args)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
#include "sched.h" // sched_add_timer
|
#include "sched.h" // sched_add_timer
|
||||||
#include "sensor_bulk.h" // sensor_bulk_report
|
#include "sensor_bulk.h" // sensor_bulk_report
|
||||||
|
#include "load_cell_probe.h" // load_cell_probe_report_sample
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ struct hx71x_adc {
|
|||||||
struct gpio_in dout; // pin used to receive data from the hx71x
|
struct gpio_in dout; // pin used to receive data from the hx71x
|
||||||
struct gpio_out sclk; // pin used to generate clock for the hx71x
|
struct gpio_out sclk; // pin used to generate clock for the hx71x
|
||||||
struct sensor_bulk sb;
|
struct sensor_bulk sb;
|
||||||
|
struct load_cell_probe *lce;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -175,6 +177,11 @@ hx71x_read_adc(struct hx71x_adc *hx71x, uint8_t oid)
|
|||||||
counts = hx71x->last_error;
|
counts = hx71x->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// probe is optional, report if enabled
|
||||||
|
if (hx71x->last_error == 0 && hx71x->lce) {
|
||||||
|
load_cell_probe_report_sample(hx71x->lce, counts);
|
||||||
|
}
|
||||||
|
|
||||||
// Add measurement to buffer
|
// Add measurement to buffer
|
||||||
add_sample(hx71x, oid, counts, false);
|
add_sample(hx71x, oid, counts, false);
|
||||||
}
|
}
|
||||||
@ -198,6 +205,15 @@ command_config_hx71x(uint32_t *args)
|
|||||||
DECL_COMMAND(command_config_hx71x, "config_hx71x oid=%c gain_channel=%c"
|
DECL_COMMAND(command_config_hx71x, "config_hx71x oid=%c gain_channel=%c"
|
||||||
" dout_pin=%u sclk_pin=%u");
|
" dout_pin=%u sclk_pin=%u");
|
||||||
|
|
||||||
|
void
|
||||||
|
hx71x_attach_load_cell_probe(uint32_t *args) {
|
||||||
|
uint8_t oid = args[0];
|
||||||
|
struct hx71x_adc *hx71x = oid_lookup(oid, command_config_hx71x);
|
||||||
|
hx71x->lce = load_cell_probe_oid_lookup(args[1]);
|
||||||
|
}
|
||||||
|
DECL_COMMAND(hx71x_attach_load_cell_probe, "hx71x_attach_load_cell_probe oid=%c"
|
||||||
|
" load_cell_probe_oid=%c");
|
||||||
|
|
||||||
// start/stop capturing ADC data
|
// start/stop capturing ADC data
|
||||||
void
|
void
|
||||||
command_query_hx71x(uint32_t *args)
|
command_query_hx71x(uint32_t *args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user