28 #include "pico/time.h"
29 #include "../include/scale.h"
30 #include "../include/scale_adaptor.h"
31 #include "../include/util.h"
43 const int32_t ref_unit,
44 const int32_t offset) {
47 assert(adaptor != NULL);
48 assert(ref_unit != 0);
59 const double*
const raw,
60 double*
const normalised) {
64 assert(normalised != NULL);
85 for(
size_t i = 0; i < len; ++i) {
100 const uint timeout) {
109 const absolute_time_t end = make_timeout_time_us(timeout);
124 diff = absolute_time_diff_us(get_absolute_time(), end);
138 arr[(*len) - 1] = val;
214 const int32_t refBackup = sc->
ref_unit;
222 sc->
offset = (int32_t)round(val);
void mass_init(mass_t *const m, const mass_unit_t unit, const double val)
Initialises a mass_t with the given unit and value.
bool scale_zero(scale_t *const sc, const scale_options_t *const opt)
Zeros the scale (tare) by adjusting its offset from 0 according to the given options....
bool scale_weight(scale_t *const sc, mass_t *const m, const scale_options_t *const opt)
Obtains a weight from the scale according to the given options. Returns true if the operation succeed...
bool scale_get_values_samples(scale_t *const sc, int32_t *const arr, const size_t len)
Fills arr with len number of samples from the scale. Returns true if the operation succeeded.
void scale_options_get_default(scale_options_t *const opt)
Fill options will default values.
bool scale_read(scale_t *const sc, double *const val, const scale_options_t *const opt)
Obtains a value from the scale according to the given options. Returns true if the operation succeede...
void scale_init(scale_t *const sc, scale_adaptor_t *const adaptor, const mass_unit_t unit, const int32_t ref_unit, const int32_t offset)
Initialise the scale with a hx711_t.
bool scale_normalise(const scale_t *const sc, const double *const raw, double *const normalised)
Adjusts a raw value to a normalised value according to the scale's reference unit and offset....
bool scale_get_values_timeout(scale_t *const sc, int32_t *const arr, const size_t arrlen, size_t *const len, const uint timeout)
Fills arr with as many number of samples as possible up to the timeout. Returns true if the operation...
static const scale_options_t SCALE_DEFAULT_OPTIONS
bool(* get_value)(struct scale_adaptor *const sa, int32_t *const value)
Function pointer to function.
bool(* get_value_timeout)(struct scale_adaptor *const sa, int32_t *const value, const uint timeout)
Function pointer to function.
scale_adaptor_t * _adaptor
void util_median(int32_t *const arr, const size_t len, double *const med)
Calculates the median value from an array of signed 32-bit integers.
void util_average(const int32_t *const arr, const size_t len, double *const avg)
Calculates the average value from an array of signed 32-bit integers.