-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SITL: add support for simulated GPIO LEDs
- Loading branch information
1 parent
3d0f738
commit 59add49
Showing
11 changed files
with
457 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "SIM_config.h" | ||
|
||
#if AP_SIM_GPIO_LED_2_ENABLED | ||
|
||
#include "SIM_GPIO_LED_2.h" | ||
|
||
#include <SITL/SITL.h> | ||
|
||
using namespace SITL; | ||
|
||
void GPIO_LED_2::init() | ||
{ | ||
leds.init(); | ||
} | ||
|
||
void GPIO_LED_2::update(const class Aircraft &aircraft) | ||
{ | ||
if (!init_done) { | ||
init(); | ||
init_done = true; | ||
} | ||
|
||
const uint16_t pin_mask = AP::sitl()->pin_mask.get(); | ||
const bool new_led_states[2] { | ||
((pin_mask & uint16_t((1U<<LED_A_PIN))) != 0), | ||
((pin_mask & uint16_t((1U<<LED_B_PIN))) != 0) | ||
}; | ||
|
||
leds.set_state(new_led_states); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Simulator for GPIO-based "Board LEDs" | ||
./Tools/autotest/sim_vehicle.py -v ArduCopter --gdb --debug --rgbled | ||
reboot | ||
*/ | ||
|
||
|
||
#include "SIM_config.h" | ||
|
||
#if AP_SIM_GPIO_LED_2_ENABLED | ||
|
||
#include "SIM_LED_n.h" | ||
|
||
namespace SITL { | ||
|
||
class GPIO_LED_2 | ||
{ | ||
public: | ||
|
||
GPIO_LED_2(uint8_t _LED_A_PIN, uint8_t _LED_B_PIN) : | ||
LED_A_PIN{_LED_A_PIN}, | ||
LED_B_PIN{_LED_B_PIN} | ||
{ } | ||
|
||
void update(const class Aircraft &aircraft); | ||
|
||
private: | ||
|
||
void init(); | ||
bool init_done; | ||
|
||
SIM_LED_n<2>::LEDColour colours[2] { | ||
SIM_LED_n<2>::LEDColour::RED, | ||
SIM_LED_n<2>::LEDColour::BLUE, | ||
}; | ||
|
||
SIM_LED_n<2> leds{"GPIO_LED_2", colours}; | ||
|
||
uint8_t LED_A_PIN; | ||
uint8_t LED_B_PIN; | ||
}; | ||
|
||
} // namespace SITL | ||
|
||
#endif // AP_SIM_GPIO_LED_2_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "SIM_config.h" | ||
|
||
#if AP_SIM_GPIO_LED_3_ENABLED | ||
|
||
#include "SIM_GPIO_LED_3.h" | ||
|
||
#include <SITL/SITL.h> | ||
|
||
using namespace SITL; | ||
|
||
void GPIO_LED_3::init() | ||
{ | ||
leds.init(); | ||
} | ||
|
||
void GPIO_LED_3::update(const class Aircraft &aircraft) | ||
{ | ||
if (!init_done) { | ||
init(); | ||
init_done = true; | ||
} | ||
|
||
const uint16_t pin_mask = AP::sitl()->pin_mask.get(); | ||
const bool new_led_states[3] { | ||
((pin_mask & uint16_t((1U<<LED_A_PIN))) != 0), | ||
((pin_mask & uint16_t((1U<<LED_B_PIN))) != 0), | ||
((pin_mask & uint16_t((1U<<LED_C_PIN))) != 0) | ||
}; | ||
|
||
leds.set_state(new_led_states); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Simulator for GPIO-based "Board LEDs" | ||
./Tools/autotest/sim_vehicle.py -v ArduCopter --gdb --debug --rgbled | ||
reboot | ||
*/ | ||
|
||
|
||
#include "SIM_config.h" | ||
|
||
#if AP_SIM_GPIO_LED_3_ENABLED | ||
|
||
#include "SIM_LED_n.h" | ||
|
||
namespace SITL { | ||
|
||
class GPIO_LED_3 | ||
{ | ||
public: | ||
|
||
GPIO_LED_3(uint8_t _LED_A_PIN, uint8_t _LED_B_PIN, uint8_t _LED_C_PIN) : | ||
LED_A_PIN{_LED_A_PIN}, | ||
LED_B_PIN{_LED_B_PIN}, | ||
LED_C_PIN{_LED_C_PIN} | ||
{ } | ||
|
||
void update(const class Aircraft &aircraft); | ||
|
||
private: | ||
|
||
void init(); | ||
bool init_done; | ||
|
||
SIM_LED_n<3>::LEDColour colours[3] { | ||
SIM_LED_n<3>::LEDColour::RED, | ||
SIM_LED_n<3>::LEDColour::BLUE, | ||
SIM_LED_n<3>::LEDColour::YELLOW, | ||
}; | ||
|
||
SIM_LED_n<3> leds{"GPIO_LED_3", colours}; | ||
|
||
uint8_t LED_A_PIN; | ||
uint8_t LED_B_PIN; | ||
uint8_t LED_C_PIN; | ||
}; | ||
|
||
} // namespace SITL | ||
|
||
#endif // AP_SIM_GPIO_LED_3_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "SIM_config.h" | ||
|
||
#if AP_SIM_GPIO_LED_RGB_ENABLED | ||
|
||
#include "SIM_GPIO_LED_RGB.h" | ||
|
||
#include <SITL/SITL.h> | ||
|
||
using namespace SITL; | ||
|
||
void GPIO_LED_RGB::init() | ||
{ | ||
leds.init(); | ||
rgbled.init(); | ||
} | ||
|
||
void GPIO_LED_RGB::update(const class Aircraft &aircraft) | ||
{ | ||
if (!init_done) { | ||
init(); | ||
init_done = true; | ||
} | ||
|
||
const uint16_t pin_mask = AP::sitl()->pin_mask.get(); | ||
|
||
const bool red = ((pin_mask & uint16_t((1U<<LED_RED_PIN))) != 0); | ||
const bool green = ((pin_mask & uint16_t((1U<<LED_GREEN_PIN))) != 0); | ||
const bool blue = ((pin_mask & uint16_t((1U<<LED_BLUE_PIN))) != 0); | ||
|
||
const bool new_led_states[3] { red, green, blue }; | ||
leds.set_state(new_led_states); | ||
|
||
// FIXME: check why we need to "!" here; do we need to move | ||
// ON_VALUE into here? | ||
rgbled.set_colours((!red)*255, (!green)*255, (!blue)*255); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Simulator for GPIO-based "Board LEDs" | ||
./Tools/autotest/sim_vehicle.py -v ArduCopter --gdb --debug --rgbled | ||
reboot | ||
*/ | ||
|
||
|
||
#include "SIM_config.h" | ||
|
||
#if AP_SIM_GPIO_LED_RGB_ENABLED | ||
|
||
#include "SIM_LED_n.h" | ||
#include "SIM_RGBLED.h" | ||
|
||
namespace SITL { | ||
|
||
class GPIO_LED_RGB | ||
{ | ||
public: | ||
|
||
GPIO_LED_RGB(uint8_t _LED_RED_PIN, uint8_t _LED_GREEN_PIN, uint8_t _LED_BLUE_PIN) : | ||
LED_RED_PIN{_LED_RED_PIN}, | ||
LED_GREEN_PIN{_LED_GREEN_PIN}, | ||
LED_BLUE_PIN{_LED_BLUE_PIN} | ||
{ } | ||
|
||
void update(const class Aircraft &aircraft); | ||
|
||
private: | ||
|
||
void init(); | ||
bool init_done; | ||
|
||
SIM_LED_n<3>::LEDColour colours[3] { | ||
SIM_LED_n<3>::LEDColour::RED, | ||
SIM_LED_n<3>::LEDColour::GREEN, | ||
SIM_LED_n<3>::LEDColour::BLUE, | ||
}; | ||
|
||
SIM_LED_n<3> leds{"GPIO_LED_RGB", colours}; | ||
SIM_RGBLED rgbled{"GPIO_LED_RGB2"}; | ||
|
||
uint8_t LED_RED_PIN; | ||
uint8_t LED_GREEN_PIN; | ||
uint8_t LED_BLUE_PIN; | ||
}; | ||
|
||
} // namespace SITL | ||
|
||
#endif // AP_SIM_GPIO_LED_RGB_ENABLED |
Oops, something went wrong.