hx711: updated sensor block and formatting

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu
2015-03-25 14:08:06 -07:00
parent df302ff5db
commit 72c957e700
3 changed files with 65 additions and 65 deletions

View File

@ -1,26 +1,24 @@
/*
*
* Author: Rafael da Mata Neri <rafael.neri@gmail.com>
* 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
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* 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.
*/
* Author: Rafael da Mata Neri <rafael.neri@gmail.com>
* 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
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* 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 <fstream>
#include <unistd.h>
@ -40,22 +38,22 @@ struct HX711Exception : public std::exception {
HX711::HX711(uint8_t data, uint8_t sck, uint8_t gain) {
mraa_result_t error = MRAA_SUCCESS;
this->m_dataPinCtx = mraa_gpio_init(data);
if (this->m_dataPinCtx == NULL) {
throw HX711Exception ("Couldn't initilize DATA pin.");
}
this->m_sckPinCtx = mraa_gpio_init(sck);
if (this->m_sckPinCtx == NULL) {
throw HX711Exception ("Couldn't initilize CLOCK pin.");
}
error = mraa_gpio_dir (this->m_dataPinCtx, MRAA_GPIO_IN);
if (error != MRAA_SUCCESS) {
throw HX711Exception ("Couldn't set direction for DATA pin.");
}
error = mraa_gpio_dir (this->m_sckPinCtx, MRAA_GPIO_OUT);
if (error != MRAA_SUCCESS) {
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() {
mraa_result_t error = MRAA_SUCCESS;
error = mraa_gpio_close (this->m_dataPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close (this->m_sckPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
@ -80,9 +78,9 @@ HX711::~HX711() {
unsigned long HX711::read() {
unsigned long Count = 0;
while (mraa_gpio_read(this->m_dataPinCtx));
for (int i=0; i<GAIN; i++)
{
mraa_gpio_write(this->m_sckPinCtx, 1);