26#include <interfaces-impl/gpio_impl.h>
33 unsigned char sckAlternateFunction)
34 : bus(bus), sckPin(sckPin), config(config),
35 sckAlternateFunction(sckAlternateFunction)
58 sckPin.mode(miosix::Mode::OUTPUT);
62 sckPin.mode(miosix::Mode::ALTERNATE);
63 sckPin.alternateFunction(sckAlternateFunction);
65 if (
sample &
static_cast<int32_t
>(0x800000))
66 sample |=
static_cast<uint32_t
>(0xFF) << 24;
68 if (
sample ==
static_cast<int32_t
>(0xFFFFFFFF))
72 static_cast<float>(
sample - offset) * scale};
81 this->scale = value /
sample;
bool selfTest() override
Check if the sensor is working.
float getScale()
Returns the current scale.
static SPIBusConfig getDefaultSPIConfig()
void setScale(float scale)
Simply changes the scale.
void updateOffset(float offset)
Updates the offset by adding it to the current offset.
HX711(SPIBusInterface &bus, miosix::GpioPin sckPin, SPIBusConfig config=getDefaultSPIConfig(), unsigned char sckAlternateFunction=5)
HX711Data sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
void computeScale(float value, float sample)
Calculates the scale value such that the load cell's output matches the given value.
void setOffset(float offset)
Sets the offset to the given value.
bool init() override
Initialize the sensor.
float getOffset()
Return the current offset.
Interface for low level access of a SPI bus as a master.
virtual uint16_t read16()=0
Reads 16 bits from the bus.
virtual uint8_t read()=0
Reads 8 bits from the bus.
virtual void configure(SPIBusConfig config)=0
Configures the bus with the provided configuration parameters.
@ MODE_1
CPOL = 1, CPHA = 0 -> Clock high when idle, sample on first edge.
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.
SPI Bus configuration for a specific slave.
SPI::ClockDivider clockDivider
< Peripheral clock division