SITL: add simulator for 1-LED boards

This commit is contained in:
Peter Barker 2024-07-11 22:25:32 +10:00 committed by Andrew Tridgell
parent 7a15b4aae5
commit 647048f703
6 changed files with 90 additions and 1 deletions

View File

@ -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

View File

@ -38,6 +38,7 @@
#include <Filter/Filter.h>
#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

View File

@ -0,0 +1,31 @@
#include "SIM_config.h"
#if AP_SIM_GPIO_LED_1_ENABLED
#include "SIM_GPIO_LED_1.h"
#include <SITL/SITL.h>
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<<LED_A_PIN))) != 0),
};
leds.set_state(new_led_states);
}
#endif

View File

@ -0,0 +1,46 @@
/*
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_1_ENABLED
#include "SIM_LED_n.h"
namespace SITL {
class GPIO_LED_1
{
public:
GPIO_LED_1(uint8_t _LED_A_PIN) :
LED_A_PIN{_LED_A_PIN}
{ }
void update(const class Aircraft &aircraft);
private:
void init();
bool init_done;
SIM_LED_n<1>::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

View File

@ -90,6 +90,7 @@ void SIM_LED_n<NUM_LEDS>::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>;

View File

@ -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