mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
nrf24l01: throw exception(s) on fatal errors
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
f6ab1fb451
commit
36cbca05bb
@ -25,17 +25,19 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "nrf24l01.h"
|
#include "nrf24l01.h"
|
||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
|
|
||||||
NRF24L01::NRF24L01 (uint8_t cs, uint8_t ce)
|
NRF24L01::NRF24L01 (uint8_t cs, uint8_t ce)
|
||||||
: m_csnPinCtx(cs), m_cePinCtx(ce), m_spi(0)
|
: m_csnPinCtx(cs), m_cePinCtx(ce), m_spi(0)
|
||||||
{
|
{
|
||||||
mraa::init();
|
mraa::init();
|
||||||
init (cs, ce);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -46,6 +48,20 @@ NRF24L01::init (uint8_t chip_select, uint8_t chip_enable) {
|
|||||||
m_ce = chip_enable;
|
m_ce = chip_enable;
|
||||||
m_channel = 99;
|
m_channel = 99;
|
||||||
|
|
||||||
|
m_csnPinCtx = mraa_gpio_init (m_csn);
|
||||||
|
if (m_csnPinCtx == NULL) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init(csn) failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_cePinCtx = mraa_gpio_init (m_ce);
|
||||||
|
if (m_cePinCtx == NULL) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init(ce) failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
error = m_csnPinCtx.dir(mraa::DIR_OUT);
|
error = m_csnPinCtx.dir(mraa::DIR_OUT);
|
||||||
if (error != mraa::SUCCESS) {
|
if (error != mraa::SUCCESS) {
|
||||||
mraa::printError (error);
|
mraa::printError (error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user