replace navio_gpio with linux_gpio

Signed-off-by: Nicolae Rosia <nicolae.rosia@gmail.com>
This commit is contained in:
Nicolae Rosia
2017-05-18 23:09:44 +02:00
committed by Lorenz Meier
parent 3d77102653
commit 4af7036a8a
12 changed files with 383 additions and 591 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ px4_add_module(
navio_rgbled.cpp
DEPENDS
platforms__common
drivers__navio_gpio
drivers__linux_gpio
lib__led
)
+78 -39
View File
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2016 PX4 Development Team. All rights reserved.
* Copyright (c) 2016 - 2017 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -36,17 +36,8 @@
#include "navio_rgbled.h"
#define GPIO_LED_CNF (GPIO_CNF_OUTPUT)
#define GPIO_LED_R (GPIO_PIN4)
#define GPIO_LED_G (GPIO_PIN27)
#define GPIO_LED_B (GPIO_PIN6)
#define RGBLED_BASE_DEVICE_PATH "/dev/rgbled"
// inverted
#define LED_ON 0
#define LED_OFF 1
using namespace DriverFramework;
@@ -56,6 +47,9 @@ RGBLED::RGBLED(const char *name)
RGBLED_BASE_DEVICE_PATH,
DeviceBusType_UNKNOWN,
0)
, _gpioR(4)
, _gpioG(27)
, _gpioB(6)
{
};
@@ -75,11 +69,47 @@ int RGBLED::start()
return res;
}
_gpio.start();
res = _gpioR.exportPin();
_gpio.configgpio(GPIO_LED_CNF | GPIO_LED_R);
_gpio.configgpio(GPIO_LED_CNF | GPIO_LED_G);
_gpio.configgpio(GPIO_LED_CNF | GPIO_LED_B);
if (res != 0) {
PX4_ERR("red led: failed to export");
goto cleanup;
}
res = _gpioR.setDirection(LinuxGPIO::Direction::OUT);
if (res != 0) {
PX4_ERR("red led: failed to set direction");
goto cleanup;
}
res = _gpioG.exportPin();
if (res != 0) {
PX4_ERR("green led: failed to export");
goto cleanup;
}
res = _gpioG.setDirection(LinuxGPIO::Direction::OUT);
if (res != 0) {
PX4_ERR("green led: failed to set direction");
goto cleanup;
}
res = _gpioB.exportPin();
if (res != 0) {
PX4_ERR("blue led: failed to export");
goto cleanup;
}
res = _gpioB.setDirection(LinuxGPIO::Direction::OUT);
if (res != 0) {
PX4_ERR("blue led: failed to set direction");
goto cleanup;
}
// update at fixed interval
DevObj::setSampleInterval(_led_controller.maximum_update_interval());
@@ -91,6 +121,13 @@ int RGBLED::start()
return res;
}
return res;
cleanup:
_gpioR.unexportPin();
_gpioG.unexportPin();
_gpioB.unexportPin();
return res;
}
@@ -98,7 +135,9 @@ int RGBLED::stop()
{
int res;
_gpio.stop();
_gpioR.unexportPin();
_gpioG.unexportPin();
_gpioB.unexportPin();
res = DevObj::stop();
@@ -123,52 +162,52 @@ void RGBLED::_measure()
if (_led_controller.update(led_control_data) == 1) {
switch (led_control_data.leds[0].color) {
case led_control_s::COLOR_RED:
_gpio.gpiowrite(GPIO_LED_R, LED_ON);
_gpio.gpiowrite(GPIO_LED_G, LED_OFF);
_gpio.gpiowrite(GPIO_LED_B, LED_OFF);
_gpioR.writeValue(LinuxGPIO::Value::LOW);
_gpioG.writeValue(LinuxGPIO::Value::HIGH);
_gpioB.writeValue(LinuxGPIO::Value::HIGH);
break;
case led_control_s::COLOR_GREEN:
_gpio.gpiowrite(GPIO_LED_R, LED_OFF);
_gpio.gpiowrite(GPIO_LED_G, LED_ON);
_gpio.gpiowrite(GPIO_LED_B, LED_OFF);
_gpioR.writeValue(LinuxGPIO::Value::HIGH);
_gpioG.writeValue(LinuxGPIO::Value::LOW);
_gpioB.writeValue(LinuxGPIO::Value::HIGH);
break;
case led_control_s::COLOR_BLUE:
_gpio.gpiowrite(GPIO_LED_R, LED_OFF);
_gpio.gpiowrite(GPIO_LED_G, LED_OFF);
_gpio.gpiowrite(GPIO_LED_B, LED_ON);
_gpioR.writeValue(LinuxGPIO::Value::HIGH);
_gpioG.writeValue(LinuxGPIO::Value::HIGH);
_gpioB.writeValue(LinuxGPIO::Value::LOW);
break;
case led_control_s::COLOR_AMBER: //make it the same as yellow
case led_control_s::COLOR_YELLOW:
_gpio.gpiowrite(GPIO_LED_R, LED_ON);
_gpio.gpiowrite(GPIO_LED_G, LED_ON);
_gpio.gpiowrite(GPIO_LED_B, LED_OFF);
_gpioR.writeValue(LinuxGPIO::Value::LOW);
_gpioG.writeValue(LinuxGPIO::Value::LOW);
_gpioB.writeValue(LinuxGPIO::Value::HIGH);
break;
case led_control_s::COLOR_PURPLE:
_gpio.gpiowrite(GPIO_LED_R, LED_ON);
_gpio.gpiowrite(GPIO_LED_G, LED_OFF);
_gpio.gpiowrite(GPIO_LED_B, LED_ON);
_gpioR.writeValue(LinuxGPIO::Value::LOW);
_gpioG.writeValue(LinuxGPIO::Value::HIGH);
_gpioB.writeValue(LinuxGPIO::Value::LOW);
break;
case led_control_s::COLOR_CYAN:
_gpio.gpiowrite(GPIO_LED_R, LED_OFF);
_gpio.gpiowrite(GPIO_LED_G, LED_ON);
_gpio.gpiowrite(GPIO_LED_B, LED_ON);
_gpioR.writeValue(LinuxGPIO::Value::HIGH);
_gpioG.writeValue(LinuxGPIO::Value::LOW);
_gpioB.writeValue(LinuxGPIO::Value::LOW);
break;
case led_control_s::COLOR_WHITE:
_gpio.gpiowrite(GPIO_LED_R, LED_ON);
_gpio.gpiowrite(GPIO_LED_G, LED_ON);
_gpio.gpiowrite(GPIO_LED_B, LED_ON);
_gpioR.writeValue(LinuxGPIO::Value::LOW);
_gpioG.writeValue(LinuxGPIO::Value::LOW);
_gpioB.writeValue(LinuxGPIO::Value::LOW);
break;
default: // led_control_s::COLOR_OFF
_gpio.gpiowrite(GPIO_LED_R, LED_OFF);
_gpio.gpiowrite(GPIO_LED_G, LED_OFF);
_gpio.gpiowrite(GPIO_LED_B, LED_OFF);
_gpioR.writeValue(LinuxGPIO::Value::HIGH);
_gpioG.writeValue(LinuxGPIO::Value::HIGH);
_gpioB.writeValue(LinuxGPIO::Value::HIGH);
break;
}
}
+6 -8
View File
@@ -32,16 +32,12 @@
****************************************************************************/
#pragma once
#include "DevObj.hpp"
#include "navio_gpio.h"
#include <drivers/linux_gpio/linux_gpio.h>
#include <DevObj.hpp>
#include <lib/led/led.h>
using namespace navio_gpio;
class RGBLED : public DevObj
class RGBLED : public DriverFramework::DevObj
{
public:
RGBLED(const char *name);
@@ -55,5 +51,7 @@ protected:
private:
LedController _led_controller;
Gpio _gpio;
LinuxGPIO _gpioR;
LinuxGPIO _gpioG;
LinuxGPIO _gpioB;
};