mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
hx711: updated sensor block and formatting
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
df302ff5db
commit
72c957e700
@ -1,26 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Author: Rafael da Mata Neri <rafael.neri@gmail.com>
|
||||||
* Author: Rafael da Mata Neri <rafael.neri@gmail.com>
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
*
|
||||||
*
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
*
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* the Software without restriction, including without limitation the rights to
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
* the Software without restriction, including without limitation the rights to
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* subject to the following conditions:
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
*
|
||||||
* subject to the following conditions:
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
*
|
* copies or substantial portions of the Software.
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
*
|
||||||
* copies or substantial portions of the Software.
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
*
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
*/
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -40,22 +38,22 @@ struct HX711Exception : public std::exception {
|
|||||||
|
|
||||||
HX711::HX711(uint8_t data, uint8_t sck, uint8_t gain) {
|
HX711::HX711(uint8_t data, uint8_t sck, uint8_t gain) {
|
||||||
mraa_result_t error = MRAA_SUCCESS;
|
mraa_result_t error = MRAA_SUCCESS;
|
||||||
|
|
||||||
this->m_dataPinCtx = mraa_gpio_init(data);
|
this->m_dataPinCtx = mraa_gpio_init(data);
|
||||||
if (this->m_dataPinCtx == NULL) {
|
if (this->m_dataPinCtx == NULL) {
|
||||||
throw HX711Exception ("Couldn't initilize DATA pin.");
|
throw HX711Exception ("Couldn't initilize DATA pin.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_sckPinCtx = mraa_gpio_init(sck);
|
this->m_sckPinCtx = mraa_gpio_init(sck);
|
||||||
if (this->m_sckPinCtx == NULL) {
|
if (this->m_sckPinCtx == NULL) {
|
||||||
throw HX711Exception ("Couldn't initilize CLOCK pin.");
|
throw HX711Exception ("Couldn't initilize CLOCK pin.");
|
||||||
}
|
}
|
||||||
|
|
||||||
error = mraa_gpio_dir (this->m_dataPinCtx, MRAA_GPIO_IN);
|
error = mraa_gpio_dir (this->m_dataPinCtx, MRAA_GPIO_IN);
|
||||||
if (error != MRAA_SUCCESS) {
|
if (error != MRAA_SUCCESS) {
|
||||||
throw HX711Exception ("Couldn't set direction for DATA pin.");
|
throw HX711Exception ("Couldn't set direction for DATA pin.");
|
||||||
}
|
}
|
||||||
|
|
||||||
error = mraa_gpio_dir (this->m_sckPinCtx, MRAA_GPIO_OUT);
|
error = mraa_gpio_dir (this->m_sckPinCtx, MRAA_GPIO_OUT);
|
||||||
if (error != MRAA_SUCCESS) {
|
if (error != MRAA_SUCCESS) {
|
||||||
throw HX711Exception ("Couldn't set direction for CLOCK pin.");
|
throw HX711Exception ("Couldn't set direction for CLOCK pin.");
|
||||||
@ -66,12 +64,12 @@ HX711::HX711(uint8_t data, uint8_t sck, uint8_t gain) {
|
|||||||
|
|
||||||
HX711::~HX711() {
|
HX711::~HX711() {
|
||||||
mraa_result_t error = MRAA_SUCCESS;
|
mraa_result_t error = MRAA_SUCCESS;
|
||||||
|
|
||||||
error = mraa_gpio_close (this->m_dataPinCtx);
|
error = mraa_gpio_close (this->m_dataPinCtx);
|
||||||
if (error != MRAA_SUCCESS) {
|
if (error != MRAA_SUCCESS) {
|
||||||
mraa_result_print(error);
|
mraa_result_print(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
error = mraa_gpio_close (this->m_sckPinCtx);
|
error = mraa_gpio_close (this->m_sckPinCtx);
|
||||||
if (error != MRAA_SUCCESS) {
|
if (error != MRAA_SUCCESS) {
|
||||||
mraa_result_print(error);
|
mraa_result_print(error);
|
||||||
@ -80,9 +78,9 @@ HX711::~HX711() {
|
|||||||
|
|
||||||
unsigned long HX711::read() {
|
unsigned long HX711::read() {
|
||||||
unsigned long Count = 0;
|
unsigned long Count = 0;
|
||||||
|
|
||||||
while (mraa_gpio_read(this->m_dataPinCtx));
|
while (mraa_gpio_read(this->m_dataPinCtx));
|
||||||
|
|
||||||
for (int i=0; i<GAIN; i++)
|
for (int i=0; i<GAIN; i++)
|
||||||
{
|
{
|
||||||
mraa_gpio_write(this->m_sckPinCtx, 1);
|
mraa_gpio_write(this->m_sckPinCtx, 1);
|
||||||
|
@ -1,29 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
*
|
* Author: Rafael da Mata Neri <rafael.neri@gmail.com>
|
||||||
* Author: Rafael da Mata Neri <rafael.neri@gmail.com>
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
*
|
||||||
*
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
*
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* the Software without restriction, including without limitation the rights to
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
* the Software without restriction, including without limitation the rights to
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* subject to the following conditions:
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
*
|
||||||
* subject to the following conditions:
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
*
|
* copies or substantial portions of the Software.
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
*
|
||||||
* copies or substantial portions of the Software.
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
*
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
*/
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -35,17 +32,25 @@ namespace upm {
|
|||||||
/**
|
/**
|
||||||
* @brief HX711 24bit ADC library
|
* @brief HX711 24bit ADC library
|
||||||
* @defgroup hx711 libupm-hx711
|
* @defgroup hx711 libupm-hx711
|
||||||
|
* @ingroup generic gpio electric
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @library hx711
|
||||||
|
* @sensor hx711
|
||||||
|
* @comname HX711 24bit Analog-to-Digital Converter
|
||||||
|
* @type electric
|
||||||
|
* @man generic
|
||||||
|
* @web http://www.dfrobot.com/image/data/SEN0160/hx711_english.pdf
|
||||||
|
* @con gpio
|
||||||
|
*
|
||||||
* @brief C++ API for HX711
|
* @brief C++ API for HX711
|
||||||
*
|
*
|
||||||
* [HX711](http://www.dfrobot.com/image/data/SEN0160/hx711_english.pdf) is
|
* The HX711 is a precision 24-bit analog-to-digital converter (ADC)
|
||||||
* a precision 24-bit analog- to-digital converter (ADC) designed for weigh
|
* designed for weigh scales and industrial control applications to
|
||||||
* scales and industrial control applications to interface directly with a
|
* interface directly with a bridge sensor. This module was tested on
|
||||||
* bridge sensor. This module was tested on the Intel Galileo Gen2.
|
* the Intel Galileo Gen2.
|
||||||
*
|
*
|
||||||
* @ingroup hx711 hx711
|
|
||||||
* @snippet hx711.cxx Interesting
|
* @snippet hx711.cxx Interesting
|
||||||
* @image html hx711.jpeg
|
* @image html hx711.jpeg
|
||||||
*/
|
*/
|
||||||
@ -66,7 +71,6 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
~HX711();
|
~HX711();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the chip to be ready and returns a reading
|
* Waits for the chip to be ready and returns a reading
|
||||||
*
|
*
|
||||||
@ -110,7 +114,7 @@ namespace upm {
|
|||||||
void tare(uint8_t times = 10);
|
void tare(uint8_t times = 10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the SCALE value
|
* Set the SCALE value
|
||||||
* This value is used to convert the raw data to "human readable" data (measure units)
|
* This value is used to convert the raw data to "human readable" data (measure units)
|
||||||
* @param scale value obtained via calibration
|
* @param scale value obtained via calibration
|
||||||
*/
|
*/
|
||||||
@ -118,14 +122,14 @@ namespace upm {
|
|||||||
private:
|
private:
|
||||||
mraa_gpio_context m_sckPinCtx; // Power Down and Serial Clock Input Pin
|
mraa_gpio_context m_sckPinCtx; // Power Down and Serial Clock Input Pin
|
||||||
mraa_gpio_context m_dataPinCtx; // Serial Data Output Pin
|
mraa_gpio_context m_dataPinCtx; // Serial Data Output Pin
|
||||||
|
|
||||||
uint8_t GAIN; // amplification factor
|
uint8_t GAIN; // amplification factor
|
||||||
unsigned long OFFSET; // used for tare weight
|
unsigned long OFFSET; // used for tare weight
|
||||||
float SCALE; // used to return weight in grams, kg, ounces, whatever
|
float SCALE; // used to return weight in grams, kg, ounces, whatever
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the OFFSET value
|
* Set the OFFSET value
|
||||||
* The value that's subtracted from the actual reading (tare weight)
|
* The value that's subtracted from the actual reading (tare weight)
|
||||||
* @param scale value obtained via calibration
|
* @param scale value obtained via calibration
|
||||||
*/
|
*/
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
//! [Interesting]
|
|
||||||
%module jsupm_hx711
|
%module jsupm_hx711
|
||||||
%include "../upm.i"
|
%include "../upm.i"
|
||||||
|
|
||||||
@ -7,4 +6,3 @@
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
%include "hx711.h"
|
%include "hx711.h"
|
||||||
//! [Interesting]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user