diff --git a/libraries/SITL/SIM_Aircraft.cpp b/libraries/SITL/SIM_Aircraft.cpp index 366ec90930..a6baf91eb9 100644 --- a/libraries/SITL/SIM_Aircraft.cpp +++ b/libraries/SITL/SIM_Aircraft.cpp @@ -1094,6 +1094,9 @@ void Aircraft::update_external_payload(const struct sitl_input &input) } #endif +#if AP_SIM_GPIO_LED_1_ENABLED + sim_led1.update(*this); +#endif #if AP_SIM_GPIO_LED_2_ENABLED sim_led2.update(*this); #endif diff --git a/libraries/SITL/SIM_Aircraft.h b/libraries/SITL/SIM_Aircraft.h index 4af43bb80c..90f07089ea 100644 --- a/libraries/SITL/SIM_Aircraft.h +++ b/libraries/SITL/SIM_Aircraft.h @@ -38,6 +38,7 @@ #include #include "SIM_JSON_Master.h" #include "ServoModel.h" +#include "SIM_GPIO_LED_1.h" #include "SIM_GPIO_LED_2.h" #include "SIM_GPIO_LED_3.h" #include "SIM_GPIO_LED_RGB.h" @@ -377,6 +378,9 @@ private: #endif +#if AP_SIM_GPIO_LED_1_ENABLED + GPIO_LED_1 sim_led1{8}; // pin to match sitl.h +#endif #if AP_SIM_GPIO_LED_2_ENABLED GPIO_LED_2 sim_led2{13, 14}; // pins to match sitl.h #endif diff --git a/libraries/SITL/SIM_GPIO_LED_1.cpp b/libraries/SITL/SIM_GPIO_LED_1.cpp new file mode 100644 index 0000000000..5ae8a40ef4 --- /dev/null +++ b/libraries/SITL/SIM_GPIO_LED_1.cpp @@ -0,0 +1,31 @@ +#include "SIM_config.h" + +#if AP_SIM_GPIO_LED_1_ENABLED + +#include "SIM_GPIO_LED_1.h" + +#include + +using namespace SITL; + +void GPIO_LED_1::init() +{ + leds.init(); +} + +void GPIO_LED_1::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[1] { + ((pin_mask & uint16_t((1U<::LEDColour colours[1] { + SIM_LED_n<1>::LEDColour::RED, + }; + + SIM_LED_n<1> leds{"GPIO_LED_1", colours}; + + uint8_t LED_A_PIN; +}; + +} // namespace SITL + +#endif // AP_SIM_GPIO_LED_2_ENABLED diff --git a/libraries/SITL/SIM_LED_n.cpp b/libraries/SITL/SIM_LED_n.cpp index 30cd3b90ef..df721612f7 100644 --- a/libraries/SITL/SIM_LED_n.cpp +++ b/libraries/SITL/SIM_LED_n.cpp @@ -90,6 +90,7 @@ void SIM_LED_n::init() pthread_create(&thread, NULL, update_thread_start, this); } +template class SIM_LED_n<1>; template class SIM_LED_n<2>; template class SIM_LED_n<3>; diff --git a/libraries/SITL/SIM_config.h b/libraries/SITL/SIM_config.h index 99a53bfb0f..bd5d07e799 100644 --- a/libraries/SITL/SIM_config.h +++ b/libraries/SITL/SIM_config.h @@ -27,6 +27,10 @@ #define AP_SIM_LED_N_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) && defined(WITH_SITL_RGBLED) #endif +#ifndef AP_SIM_GPIO_LED_1_ENABLED +#define AP_SIM_GPIO_LED_1_ENABLED AP_SIM_LED_N_ENABLED && 0 +#endif + #ifndef AP_SIM_GPIO_LED_2_ENABLED #define AP_SIM_GPIO_LED_2_ENABLED AP_SIM_LED_N_ENABLED && 0 #endif @@ -36,7 +40,7 @@ #endif #ifndef AP_SIM_GPIO_LED_RGB_ENABLED -#define AP_SIM_GPIO_LED_RGB_ENABLED AP_SIM_LED_N_ENABLED +#define AP_SIM_GPIO_LED_RGB_ENABLED AP_SIM_LED_N_ENABLED && 0 #endif #ifndef AP_SIM_LOWEHEISER_ENABLED