Navio: GPIO driver command fix and update ifdefs

This commit is contained in:
Hidenori
2016-07-19 11:00:49 -04:00
committed by Lorenz Meier
parent 3049b9af01
commit ff647e7bc8
4 changed files with 23 additions and 17 deletions
+16 -6
View File
@@ -145,10 +145,10 @@ int navio_gpio_main(int argc, char *argv[])
}
if (!strcmp(argv[1], "start")) {
PX4_WARN("gpio should only be started directly for debugging");
if (gpio != nullptr && gpio->isMapped()) {
PX4_WARN("already mapped");
/* this is not an error */
return 0;
}
@@ -156,13 +156,14 @@ int navio_gpio_main(int argc, char *argv[])
if (gpio == nullptr) {
PX4_ERR("alloc failed");
return -1;
return 1;
}
int ret = gpio->start();
if (ret != 0) {
PX4_ERR("start failed");
return 1;
}
return 0;
@@ -170,12 +171,16 @@ int navio_gpio_main(int argc, char *argv[])
if (!strcmp(argv[1], "stop")) {
if (gpio == nullptr || gpio->isMapped()) {
PX4_WARN("not mapped");
/* this is not an error */
if (gpio == nullptr) {
PX4_WARN("gpio not started from navio_gpio");
return 0;
}
if (!gpio->isMapped()) {
PX4_WARN("not mapped");
return 1;
}
gpio->stop();
delete gpio;
@@ -185,7 +190,12 @@ int navio_gpio_main(int argc, char *argv[])
}
if (!strcmp(argv[1], "status")) {
if (gpio != nullptr && gpio->isMapped()) {
if (gpio == nullptr) {
PX4_WARN("gpio not started from navio_gpio");
return 0;
}
if (gpio->isMapped()) {
PX4_INFO("mapped");
} else {
+4 -8
View File
@@ -86,13 +86,10 @@ namespace navio_gpio
class Gpio
{
public:
Gpio() :
_isMapped(false)
{
}
Gpio()
{ }
~Gpio()
{
}
{ }
int start();
int stop();
@@ -102,7 +99,7 @@ public:
bool gpioread(uint32_t pinset);
void gpiowrite(uint32_t pinset, bool value);
bool isMapped() { return _isMapped; }
bool isMapped() { return _gpio_map != nullptr; }
private:
void atomic_modify(uint32_t addr,
@@ -111,7 +108,6 @@ private:
unsigned int value);
void *_gpio_map;
bool _isMapped;
SyncObj m_lock;
};