-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New feature: digital output for controlling lighting with HAL #2675
New feature: digital output for controlling lighting with HAL #2675
Conversation
it's connected with #296 |
Would you belive I wanted to do it more than a year ago? |
src/main/fc/rc_modes.h
Outdated
@@ -56,6 +56,7 @@ typedef enum { | |||
BOXCAMERA1 = 29, | |||
BOXCAMERA2 = 30, | |||
BOXCAMERA3 = 31, | |||
BOXLIGHTS = 32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already is BOXLLIGHTS = 13,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a mode in case somebody wants to use RGB and standard lighting at the same time but I can modify the code to use the LLIGHTS mode without a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLIGHTS are not used, it's not connected with RGB LEDs at all. You mistake it with BOXLEDLOW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BOXLLIGHTS
stands for Landing Lights
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Now using old unused BOXLLIGHTS IDs.
src/main/fc/fc_msp_box.c
Outdated
@@ -70,6 +70,7 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = { | |||
{ BOXCAMERA1, "CAMERA CONTROL 1;", 39 }, | |||
{ BOXCAMERA2, "CAMERA CONTROL 2;", 40 }, | |||
{ BOXCAMERA3, "CAMERA CONTROL 3;", 41 }, | |||
{ BOXLIGHTS, "LIGHTS;", 42 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ BOXLLIGHTS, "LLIGHTS;", 16 },
I believe it :) |
I suppose we can skip abstraction for now. |
Why not use WS2812 LEDStrip as the lighting for fixedwing? |
@Linjieqiang because with digital output you can connect and drive everything. Like 10W LED or IR emitter or anything else |
src/main/io/lights.c
Outdated
return(true); | ||
} else | ||
return(false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use standard 4 space indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I need to change my auto-indentation settings for iNav it is not the same I use for other projects.
src/main/fc/fc_tasks.c
Outdated
@@ -314,6 +315,9 @@ void fcTasksInit(void) | |||
setTaskEnabled(TASK_SERIAL, true); | |||
#ifdef BEEPER | |||
setTaskEnabled(TASK_BEEPER, true); | |||
#endif | |||
#ifdef LIGHTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be #ifdef USE_LIGHTS
- the USE_
prefix is used for this type of build flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I didn't because it is not only a flag it is used to define the pin to use. Maybe best to use two flags: USE_LIGHTS
and LIGHTS_PIN
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Macros to use are now USE_LIGHTS
, USE_FAILSAFE_LIGHTS
and LIGHTS_PIN
.
src/main/fc/fc_tasks.c
Outdated
.taskName = "LIGHTS", | ||
.taskFunc = lightsUpdate, | ||
.desiredPeriod = TASK_PERIOD_HZ(100), // 100 Hz | ||
.staticPriority = TASK_PRIORITY_MEDIUM, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
priority should be low.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I used the same priority as the buzzer/beeper because it is also used to flash lights on failsafe. Maybe the buzzer/beeper priority can be set to LOW too ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Task priority is now LOW.
Good stuff. However I'm not sure if this should be called |
Arduplane calls it relay switches |
@martinbudden I called it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed a few things to think about.
[TASK_LIGHTS] = { | ||
.taskName = "LIGHTS", | ||
.taskFunc = lightsUpdate, | ||
.desiredPeriod = TASK_PERIOD_HZ(100), // 100 Hz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't 100Hz an overkill? Do we want to update light status 100 times per second? I think 10Hz whould be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is needed for the failsafe lights flashing code. As the default I set pulses the lights 100ms every second. It is what I use to keep battery usage low in case the model is lost and a long time is needed to find it. If we set it to 10Hz it won't be possible as it will make the lights either not light up or light up 100ms or 200ms each cycle depending on the time variability between task runs. The task priority is set to LOW it shouldn't be a problem.
src/main/drivers/lights_hal.c
Outdated
@@ -0,0 +1,30 @@ | |||
#include "drivers/lights_hal.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the name lights_hal
. We use _hal
suffix in drivers that depend on ST's HAL library. This is clearly not the case. Maybe use lights_io
name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you like. I thought it would be appropriate as it is already used for WS2811 lights: light_ws2811strip_hal.c
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly my case - light_ws2811strip_hal.c
is driver designed to work with ST's HAL library. That's why we have light_ws2811strip_stdperiph.c
next to is (using ST's StdPeriph library). We don't depend on ST's CPU-support libraries, so let's rename.
src/main/io/lights.c
Outdated
void lightsUpdate(timeUs_t currentTimeUs) | ||
{ | ||
UNUSED(currentTimeUs); | ||
#ifdef USE_FAILSAFE_LIGHTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we have USE_FAILSAFE_LIGHTS
? Why not make it a config option rather than compile-time option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it would not be a setting changed often but you are right it would be better as a run-time setting. I will change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. This PR has been tested and should be ready to merge.
…d failsafe_lights_flash_on_time minimums
Heh, I was proposing something similar back in 2015 :) |
This PR adds the possibility to control lighting with a digital output.
USE_LIGHTS
macro (example on PIKOBLX to use the PWM5 output:#define LIGHTS_PIN PA1
)USE_LIGHTS
macro is not definedfailsafe_lights
setting and flashing on time and period can be configured with thefailsafe_lights_flash_period
andfailsafe_lights_flash_on_time
settings (unit: milliseconds).LIGHTS
flight mode.Example application (don't forget the current limiting resistor(s) if you are using LEDs which don't have built-in current limiting):