mirror of
https://github.com/eclipse/upm.git
synced 2025-03-28 03:10:06 +03:00
hx711: remove custom exception and use a standard one
Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
66d688bc90
commit
97e7f74a8f
@ -24,39 +24,37 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdexcept>
|
||||||
#include "hx711.h"
|
#include "hx711.h"
|
||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct HX711Exception : public std::exception {
|
|
||||||
std::string message;
|
|
||||||
HX711Exception (std::string msg) : message (msg) { }
|
|
||||||
~HX711Exception () throw () { }
|
|
||||||
const char* what() const throw () { return message.c_str(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
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 std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": Couldn't initialize 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 std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": Couldn't initialize 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 std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": 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 std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": Couldn't set direction for CLOCK pin.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setGain(gain);
|
this->setGain(gain);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user