Skyward boardcore
Loading...
Searching...
No Matches
HX711.h
Go to the documentation of this file.
1/* Copyright (c) 2022 Skyward Experimental Rocketry
2 * Author: Alberto Nidasio
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
26#include <sensors/Sensor.h>
27
28#include "HX711Data.h"
29
30namespace Boardcore
31{
32
54class HX711 : public Sensor<HX711Data>
55{
56public:
57 HX711(SPIBusInterface& bus, miosix::GpioPin sckPin,
59 unsigned char sckAlternateFunction = 5);
60
62
63 bool init() override;
64
65 bool selfTest() override;
66
77 void computeScale(float value, float sample);
78
82 void computeScale(float value);
83
89 void setScale(float scale);
90
94 float getScale();
95
101 void setOffset(float offset);
102
108 void updateOffset(float offset);
109
113 float getOffset();
114
115protected:
116 HX711Data sampleImpl() override;
117
118private:
119 SPIBusInterface& bus;
120 miosix::GpioPin sckPin;
121 const SPIBusConfig config;
122 unsigned char sckAlternateFunction;
123
124 float scale = 1;
125 int32_t offset = 0;
126};
127
128} // namespace Boardcore
Load cell transducer.
Definition HX711.h:55
bool selfTest() override
Check if the sensor is working.
Definition HX711.cpp:49
float getScale()
Returns the current scale.
Definition HX711.cpp:88
static SPIBusConfig getDefaultSPIConfig()
Definition HX711.cpp:39
void setScale(float scale)
Simply changes the scale.
Definition HX711.cpp:86
void updateOffset(float offset)
Updates the offset by adding it to the current offset.
Definition HX711.cpp:92
HX711Data sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
Definition HX711.cpp:51
void computeScale(float value, float sample)
Calculates the scale value such that the load cell's output matches the given value.
Definition HX711.cpp:75
void setOffset(float offset)
Sets the offset to the given value.
Definition HX711.cpp:90
bool init() override
Initialize the sensor.
Definition HX711.cpp:47
float getOffset()
Return the current offset.
Definition HX711.cpp:94
Interface for low level access of a SPI bus as a master.
Base sensor class with has to be extended by any sensor driver.
Definition Sensor.h:91
Driver for the VN100S IMU.
SPI Bus configuration for a specific slave.