Extends HX711 library AdvancedHX711. Custom implementations for value reading, so it can be observed and iterrupted.
More...
#include <custom_hx711.h>
|
| custom_hx711 (const int dataPin, const int clockPin, const Value refUnit=1, const Value offset=0, const Rate rate=Rate::HZ_10) |
|
virtual std::vector< Value > | getValues (const std::chrono::nanoseconds timeout) override |
| getValues performs reading for @timeout. This function is overwriten to allow interruption, however is no longer used in favor of getValues that can be observed More...
|
|
virtual std::vector< Value > | getValues (const std::size_t samples) override |
| getValues performs reading until @samples is reached. This function is overwriten to allow interruption, however is no longer used in favor of getValues that can be observed More...
|
|
virtual std::vector< Value > | getValues (const std::chrono::nanoseconds timeout, std::vector< Value > **watchdog) |
| getValues performs reading for @timeout. This function allows observing ongoing measuring thourgh @watchdong More...
|
|
virtual std::vector< Value > | getValues (const std::size_t samples, std::vector< Value > **watchdog) |
| getValues performs reading until @samples is reached. This function allows observing ongoing measuring thourgh @watchdong More...
|
|
virtual void | stop_reading () |
| When this is called watcher is paused causing reading to be stopped. More...
|
|
Extends HX711 library AdvancedHX711. Custom implementations for value reading, so it can be observed and iterrupted.
Definition at line 27 of file custom_hx711.h.
◆ custom_hx711()
custom_hx711::custom_hx711 |
( |
const int |
dataPin, |
|
|
const int |
clockPin, |
|
|
const Value |
refUnit = 1 , |
|
|
const Value |
offset = 0 , |
|
|
const Rate |
rate = Rate::HZ_10 |
|
) |
| |
Calls parent constructor
Definition at line 14 of file custom_hx711.cpp.
custom_watcher extends HX711 library Watcher. Reason is to get access to the watcher state,...
◆ getValues() [1/4]
std::vector< Value > custom_hx711::getValues |
( |
const std::chrono::nanoseconds |
timeout | ) |
|
|
overridevirtual |
getValues performs reading for @timeout. This function is overwriten to allow interruption, however is no longer used in favor of getValues that can be observed
- Parameters
-
timeout | for how long reading is preformed |
- Returns
- std::vector<Value> measured values
Definition at line 30 of file custom_hx711.cpp.
32 using namespace std::chrono;
34 this->
_wx->values.clear();
37 std::vector<Value> vals;
38 const auto endTime = steady_clock::now() + timeout;
42 if(steady_clock::now() >= endTime) {
51 if(!this->
_wx->values.empty()) {
53 this->
_wx->valuesLock.lock();
54 while(!this->
_wx->values.empty()) {
55 vals.push_back(this->
_wx->values.pop());
57 this->
_wx->valuesLock.unlock();
63 std::this_thread::yield();
64 Utility::sleep(milliseconds(1));
WatchState get_watch_state()
◆ getValues() [2/4]
std::vector< Value > custom_hx711::getValues |
( |
const std::chrono::nanoseconds |
timeout, |
|
|
std::vector< Value > ** |
watchdog |
|
) |
| |
|
virtual |
getValues performs reading for @timeout. This function allows observing ongoing measuring thourgh @watchdong
- Parameters
-
timeout | for how long reading is preformed |
watchdog | is a vector of values, that id periodically filled and emptied during measuring to allow measuring observation |
- Returns
- std::vector<Value> measured values
Definition at line 116 of file custom_hx711.cpp.
117 using namespace std::chrono;
119 this->
_wx->values.clear();
122 std::vector<Value> vals;
124 const auto endTime = steady_clock::now() + timeout;
128 if(steady_clock::now() >= endTime) {
137 if(!this->
_wx->values.empty()) {
139 this->
_wx->valuesLock.lock();
140 while(!this->
_wx->values.empty()) {
141 vals.push_back(this->
_wx->values.pop());
143 this->
_wx->valuesLock.unlock();
149 std::this_thread::yield();
150 Utility::sleep(milliseconds(1));
◆ getValues() [3/4]
std::vector< Value > custom_hx711::getValues |
( |
const std::size_t |
samples | ) |
|
|
overridevirtual |
getValues performs reading until @samples is reached. This function is overwriten to allow interruption, however is no longer used in favor of getValues that can be observed
- Parameters
-
- Returns
- std::vector<Value> measured values.
Definition at line 70 of file custom_hx711.cpp.
72 using namespace std::chrono;
75 throw std::range_error(
"samples must be at least 1");
78 this->
_wx->values.clear();
81 std::vector<Value> vals;
82 vals.reserve(samples);
85 while(vals.size() < samples) {
88 while(this->
_wx->values.empty() && this->_wx->
get_watch_state() != WatchState::PAUSE) {
89 std::this_thread::yield();
90 Utility::sleep(milliseconds(1));
98 this->
_wx->valuesLock.lock();
102 while(!this->
_wx->values.empty() && vals.size() < samples) {
103 vals.push_back(this->
_wx->values.pop());
106 this->
_wx->valuesLock.unlock();
◆ getValues() [4/4]
std::vector< Value > custom_hx711::getValues |
( |
const std::size_t |
samples, |
|
|
std::vector< Value > ** |
watchdog |
|
) |
| |
|
virtual |
getValues performs reading until @samples is reached. This function allows observing ongoing measuring thourgh @watchdong
- Parameters
-
timeout | for how long reading is preformed |
watchdog | is a vector of values, that id periodically filled and emptied during measuring to allow measuring observation |
- Returns
- std::vector<Value> measured values
Definition at line 155 of file custom_hx711.cpp.
156 using namespace std::chrono;
159 throw std::range_error(
"samples must be at least 1");
162 this->
_wx->values.clear();
165 std::vector<Value> vals;
167 vals.reserve(samples);
170 while(vals.size() < samples) {
173 while(this->
_wx->values.empty() && this->_wx->
get_watch_state() != WatchState::PAUSE) {
174 std::this_thread::yield();
175 Utility::sleep(milliseconds(1));
183 this->
_wx->valuesLock.lock();
187 while(!this->
_wx->values.empty() && vals.size() < samples) {
188 vals.push_back(this->
_wx->values.pop());
191 this->
_wx->valuesLock.unlock();
◆ stop_reading()
void custom_hx711::stop_reading |
( |
| ) |
|
|
virtual |
When this is called watcher is paused causing reading to be stopped.
Definition at line 26 of file custom_hx711.cpp.
◆ _wx
The documentation for this class was generated from the following files: