11 return this->_watchState;
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));
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();
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));
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();
virtual std::vector< Value > getValues(const std::chrono::nanoseconds timeout) override
getValues performs reading for @timeout. This function is overwriten to allow interruption,...
virtual void stop_reading()
When this is called watcher is paused causing reading to be stopped.
custom_hx711(const int dataPin, const int clockPin, const Value refUnit=1, const Value offset=0, const Rate rate=Rate::HZ_10)
custom_watcher extends HX711 library Watcher. Reason is to get access to the watcher state,...
WatchState get_watch_state()
custom_watcher(HX711::HX711 *hx)