2013-08-13 23:51:22 -03:00
|
|
|
/*
|
2013-08-29 00:13:09 -03:00
|
|
|
ToshibaLED PX4 driver
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-08-13 23:51:22 -03:00
|
|
|
*/
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2013-08-13 23:51:22 -03:00
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
|
|
|
#include "ToshibaLED_PX4.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-05-31 01:49:38 -03:00
|
|
|
#include <px4_defines.h>
|
2013-08-29 00:13:09 -03:00
|
|
|
#include <drivers/drv_rgbled.h>
|
2013-08-13 23:51:22 -03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2013-08-29 00:13:09 -03:00
|
|
|
bool ToshibaLED_PX4::hw_init()
|
2013-08-13 23:51:22 -03:00
|
|
|
{
|
|
|
|
// open the rgb led device
|
2015-02-13 04:21:24 -04:00
|
|
|
_rgbled_fd = open(RGBLED0_DEVICE_PATH, 0);
|
2013-08-29 00:13:09 -03:00
|
|
|
if (_rgbled_fd == -1) {
|
2015-02-13 04:21:24 -04:00
|
|
|
hal.console->printf("Unable to open " RGBLED0_DEVICE_PATH);
|
2013-08-29 00:13:09 -03:00
|
|
|
return false;
|
2013-08-13 23:51:22 -03:00
|
|
|
}
|
2013-10-08 00:55:10 -03:00
|
|
|
ioctl(_rgbled_fd, RGBLED_SET_MODE, (unsigned long)RGBLED_MODE_ON);
|
2014-08-20 18:31:53 -03:00
|
|
|
last.v = 0;
|
|
|
|
next.v = 0;
|
2015-05-24 20:24:11 -03:00
|
|
|
hal.scheduler->register_io_process(FUNCTOR_BIND_MEMBER(&ToshibaLED_PX4::update_timer, void));
|
2013-08-29 00:13:09 -03:00
|
|
|
return true;
|
2013-08-13 23:51:22 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// set_rgb - set color as a combination of red, green and blue values
|
2013-08-29 00:13:09 -03:00
|
|
|
bool ToshibaLED_PX4::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
|
2013-08-13 23:51:22 -03:00
|
|
|
{
|
2014-08-20 18:31:53 -03:00
|
|
|
union rgb_value v;
|
|
|
|
v.r = red;
|
|
|
|
v.g = green;
|
|
|
|
v.b = blue;
|
|
|
|
// this does an atomic 32 bit update
|
|
|
|
next.v = v.v;
|
2014-01-23 19:40:39 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToshibaLED_PX4::update_timer(void)
|
|
|
|
{
|
2014-08-20 18:31:53 -03:00
|
|
|
if (last.v == next.v) {
|
2014-01-23 19:40:39 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-08-29 00:13:09 -03:00
|
|
|
rgbled_rgbset_t v;
|
2014-08-20 18:31:53 -03:00
|
|
|
union rgb_value newv;
|
|
|
|
newv.v = next.v;
|
|
|
|
v.red = newv.r;
|
|
|
|
v.green = newv.g;
|
|
|
|
v.blue = newv.b;
|
2013-08-13 23:51:22 -03:00
|
|
|
|
2014-01-23 19:40:39 -04:00
|
|
|
ioctl(_rgbled_fd, RGBLED_SET_RGB, (unsigned long)&v);
|
2013-08-13 23:51:22 -03:00
|
|
|
|
2014-08-20 18:31:53 -03:00
|
|
|
last.v = next.v;
|
2014-01-23 19:40:39 -04:00
|
|
|
}
|
2013-08-13 23:51:22 -03:00
|
|
|
|
2013-08-29 00:13:09 -03:00
|
|
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_PX4
|