8 changed files with 233 additions and 69 deletions
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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/>.
|
||||
*/ |
||||
|
||||
#include "AP_Notify/AP_Notify.h" |
||||
#include "ProfiLED.h" |
||||
#include "SRV_Channel/SRV_Channel.h" |
||||
|
||||
// This limit is from the dshot driver rc out groups limit, we need at least one channel for clock
|
||||
#define AP_NOTIFY_ProfiLED_MAX_INSTANCES 3 |
||||
|
||||
#define ProfiLED_LOW 0x33 |
||||
#define ProfiLED_MEDIUM 0x7F |
||||
#define ProfiLED_HIGH 0xFF |
||||
#define ProfiLED_OFF 0x00 |
||||
|
||||
extern const AP_HAL::HAL& hal; |
||||
|
||||
ProfiLED::ProfiLED() : |
||||
SerialLED(ProfiLED_OFF, ProfiLED_HIGH, ProfiLED_MEDIUM, ProfiLED_LOW) |
||||
{ |
||||
} |
||||
|
||||
uint16_t ProfiLED::init_ports() |
||||
{ |
||||
uint16_t mask = 0; |
||||
for (uint16_t i=0; i<AP_NOTIFY_ProfiLED_MAX_INSTANCES; i++) { |
||||
const SRV_Channel::Aux_servo_function_t fn = (SRV_Channel::Aux_servo_function_t)((uint8_t)SRV_Channel::k_ProfiLED_1 + i); |
||||
if (!SRV_Channels::function_assigned(fn)) { |
||||
continue; |
||||
} |
||||
mask |= SRV_Channels::get_output_channel_mask(fn); |
||||
} |
||||
|
||||
if (mask == 0) { |
||||
return 0; |
||||
} |
||||
|
||||
AP_SerialLED *led = AP_SerialLED::get_singleton(); |
||||
if (led == nullptr) { |
||||
return 0; |
||||
} |
||||
|
||||
for (uint16_t chan=0; chan<16; chan++) { |
||||
if ((1U<<chan) & mask) { |
||||
led->set_num_profiled(chan+1, (pNotify->get_led_len())); |
||||
} |
||||
} |
||||
|
||||
return mask; |
||||
} |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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/>.
|
||||
*/ |
||||
#pragma once |
||||
|
||||
#include "RGBLed.h" |
||||
#include "SerialLED.h" |
||||
#include <AP_Common/AP_Common.h> |
||||
|
||||
class ProfiLED: public SerialLED { |
||||
public: |
||||
ProfiLED(); |
||||
|
||||
uint16_t init_ports() override; |
||||
|
||||
}; |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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/>.
|
||||
*/ |
||||
|
||||
#include "AP_Notify/AP_Notify.h" |
||||
#include "SerialLED.h" |
||||
|
||||
extern const AP_HAL::HAL& hal; |
||||
|
||||
SerialLED::SerialLED(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim) : |
||||
RGBLed(led_off, led_bright, led_medium, led_dim) |
||||
{ |
||||
} |
||||
|
||||
bool SerialLED::hw_init() |
||||
{ |
||||
init_ports(); |
||||
hal.scheduler->register_io_process(FUNCTOR_BIND_MEMBER(&SerialLED::timer, void)); |
||||
return true; |
||||
} |
||||
|
||||
void SerialLED::timer() |
||||
{ |
||||
WITH_SEMAPHORE(_sem); |
||||
|
||||
const uint32_t now_ms = AP_HAL::millis(); |
||||
if (now_ms - _last_init_ms >= 1000) { |
||||
_last_init_ms = now_ms; |
||||
enable_mask = init_ports(); |
||||
} |
||||
} |
||||
|
||||
bool SerialLED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) |
||||
{ |
||||
if (enable_mask == 0) { |
||||
// nothing is enabled, no pins set as LED output
|
||||
return true; |
||||
} |
||||
|
||||
AP_SerialLED *led = AP_SerialLED::get_singleton(); |
||||
if (led == nullptr) { |
||||
return false; |
||||
} |
||||
|
||||
for (uint16_t chan=0; chan<16; chan++) { |
||||
if ((1U<<chan) & enable_mask) { |
||||
led->set_RGB(chan+1, -1, red, green, blue); |
||||
} |
||||
} |
||||
|
||||
for (uint16_t chan=0; chan<16; chan++) { |
||||
if ((1U<<chan) & enable_mask) { |
||||
led->send(chan+1); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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/>.
|
||||
*/ |
||||
#pragma once |
||||
|
||||
#include "RGBLed.h" |
||||
#include <AP_Common/AP_Common.h> |
||||
#include <AP_SerialLED/AP_SerialLED.h> |
||||
|
||||
class SerialLED: public RGBLed { |
||||
public: |
||||
SerialLED(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim); |
||||
|
||||
struct { |
||||
uint8_t b; |
||||
uint8_t r; |
||||
uint8_t g; |
||||
} RGB; |
||||
|
||||
virtual uint16_t init_ports() { return 0; }; |
||||
|
||||
protected: |
||||
|
||||
bool hw_init(void) override; |
||||
|
||||
bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override; |
||||
|
||||
private: |
||||
uint16_t enable_mask; |
||||
|
||||
// perdiodic tick to re-init
|
||||
uint32_t _last_init_ms; |
||||
|
||||
// periodic callback
|
||||
void timer(); |
||||
|
||||
HAL_Semaphore _sem; |
||||
}; |
Loading…
Reference in new issue