upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
hx711.hpp
1 /*
2  * Author: Rafael da Mata Neri <rafael.neri@gmail.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #pragma once
23 
24 #include <unistd.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <string.h>
28 #include <mraa/gpio.h>
29 
30 namespace upm {
56  class HX711 {
57  public:
66  HX711(int data, int sck, uint8_t gain = 128);
67 
71  ~HX711();
72 
78  unsigned long read();
79 
86  void setGain(uint8_t gain = 128);
87 
93  unsigned long readAverage(uint8_t times = 10);
94 
100  double getValue(uint8_t times = 10);
101 
107  float getUnits(uint8_t times = 1);
108 
113  void tare(uint8_t times = 10);
114 
120  void setScale(float scale = 1.f);
121  private:
122  mraa_gpio_context m_sckPinCtx; // Power Down and Serial Clock Input Pin
123  mraa_gpio_context m_dataPinCtx; // Serial Data Output Pin
124 
125  uint8_t GAIN; // amplification factor
126  unsigned long OFFSET; // used for tare weight
127  float SCALE; // used to return weight in grams, kg, ounces, whatever
128 
129 
135  void setOffset(long offset = 0);
136  };
137 
138 }
void setGain(uint8_t gain=128)
Definition: hx711.cxx:100
unsigned long read()
Definition: hx711.cxx:77
void setScale(float scale=1.f)
Definition: hx711.cxx:138
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
double getValue(uint8_t times=10)
Definition: hx711.cxx:125
HX711(int data, int sck, uint8_t gain=128)
Definition: hx711.cxx:33
unsigned long readAverage(uint8_t times=10)
Definition: hx711.cxx:117
float getUnits(uint8_t times=1)
Definition: hx711.cxx:129
API for the HX711 Analog-to-Digital Converter.
Definition: hx711.hpp:56
~HX711()
Definition: hx711.cxx:63
void tare(uint8_t times=10)
Definition: hx711.cxx:133