AP_Notify: Add send_text for scripting use

Added a send_test_src method to override the text on the display and display custom text on a given row
This commit is contained in:
Hayden Donald 2024-02-07 15:58:16 +11:00 committed by Peter Hall
parent 780045ee3a
commit dea51c9c50
5 changed files with 80 additions and 8 deletions

View File

@ -535,6 +535,27 @@ void AP_Notify::send_text(const char *str)
_send_text_updated_millis = AP_HAL::millis();
}
#if AP_SCRIPTING_ENABLED
void AP_Notify::send_text_scripting(const char *str, uint8_t r)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->send_text_blocking(str, r);
}
}
}
void AP_Notify::release_text_scripting(uint8_t r)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->release_text(r);
}
}
}
#endif
// convert 0-3 to 0-100
int8_t AP_Notify::get_rgb_led_brightness_percent() const
{

View File

@ -211,6 +211,12 @@ public:
const char* get_text() const { return _send_text; }
uint32_t get_text_updated_millis() const {return _send_text_updated_millis; }
#if AP_SCRIPTING_ENABLED
// send text to the display using scripting
void send_text_scripting(const char *str, uint8_t r);
void release_text_scripting(uint8_t r);
#endif
static const struct AP_Param::GroupInfo var_info[];
int8_t get_buzz_pin() const { return _buzzer_pin; }
uint8_t get_buzz_level() const { return _buzzer_level; }

View File

@ -404,17 +404,53 @@ void Display::update()
void Display::update_all()
{
if(!BIT_IS_SET(_send_text_scr_override, 0)) {
update_text(0);
}
if(!BIT_IS_SET(_send_text_scr_override, 1)) {
update_mode(1);
}
#if AP_BATTERY_ENABLED
if(!BIT_IS_SET(_send_text_scr_override, 2)) {
update_battery(2);
}
#endif
#if AP_GPS_ENABLED
if(!BIT_IS_SET(_send_text_scr_override, 3)) {
update_gps(3);
}
#endif
if(!BIT_IS_SET(_send_text_scr_override, 4)) {
//update_gps_sats(4);
update_prearm(4);
}
if(!BIT_IS_SET(_send_text_scr_override, 5)) {
update_ekf(5);
}
}
void Display::send_text_blocking(const char *text, uint8_t r)
{
if (text == nullptr) {
return;
}
if (r >= DISPLAY_TEXT_NUM_ROWS) {
return;
}
BIT_SET(_send_text_scr_override, r);
char txt [DISPLAY_MESSAGE_SIZE] = {};
memset(txt, ' ', DISPLAY_MESSAGE_SIZE);
memcpy(txt, text, strnlen(text, DISPLAY_MESSAGE_SIZE));
draw_text(COLUMN(0), ROW(r), txt);
}
void Display::release_text(uint8_t r)
{
BIT_CLEAR(_send_text_scr_override, r);
}
void Display::draw_text(uint16_t x, uint16_t y, const char* c)

View File

@ -9,6 +9,7 @@
#define ROW(Y) ((Y * 10) + 6)
#define COLUMN(X) ((X * 7) + 0)
#define DISPLAY_TEXT_NUM_ROWS 6
#define DISPLAY_MESSAGE_SIZE 19
class Display_Backend;
@ -19,7 +20,8 @@ public:
bool init(void) override;
void update() override;
void send_text_blocking(const char *text, uint8_t line) override;
void release_text(uint8_t line) override;
private:
void draw_char(uint16_t x, uint16_t y, const char c);
void draw_text(uint16_t x, uint16_t y, const char *c);
@ -42,6 +44,9 @@ private:
// stop showing text in display after this many millis:
const uint16_t _send_text_valid_millis = 20000;
//Bitmask of what lines send_text_scripting should override
uint8_t _send_text_scr_override;
};
#endif // HAL_DISPLAY_ENABLED

View File

@ -30,6 +30,10 @@ public:
// give RGB value for single led
virtual void rgb_set_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id) {}
// Allow text to be sent or removed from a display
virtual void send_text_blocking(const char *text, uint8_t line) {}
virtual void release_text(uint8_t line) {}
// this pointer is used to read the parameters relative to devices
const AP_Notify *pNotify;
};