Skip to content

Commit

Permalink
AP_Notify: Add send_text for scripting use
Browse files Browse the repository at this point in the history
Added a send_test_src method to override the text on the display and display custom text on a given row
  • Loading branch information
haydendonald committed Jan 23, 2024
1 parent 4ee81bc commit 8ec8ff2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
10 changes: 10 additions & 0 deletions libraries/AP_Notify/AP_Notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@ void AP_Notify::send_text(const char *str)
_send_text_updated_millis = AP_HAL::millis();
}

void AP_Notify::send_text_scripting(const char *str, uint8_t r)
{
BIT_SET(_send_text_src_override, r);
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->send_text(str, r);
}
}
}

// convert 0-3 to 0-100
int8_t AP_Notify::get_rgb_led_brightness_percent() const
{
Expand Down
6 changes: 6 additions & 0 deletions libraries/AP_Notify/AP_Notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define BUZZER_ON 1
#define BUZZER_OFF 0

#define NOTIFY_TEXT_NUM_ROWS 6
#define NOTIFY_TEXT_BUFFER_SIZE 51

//Type of on-board display
Expand Down Expand Up @@ -210,6 +211,9 @@ class AP_Notify
void send_text(const char *str);
const char* get_text() const { return _send_text; }
uint32_t get_text_updated_millis() const {return _send_text_updated_millis; }

// send text to the display using scripting
void send_text_scripting(const char *str, uint8_t r);

static const struct AP_Param::GroupInfo var_info[];
int8_t get_buzz_pin() const { return _buzzer_pin; }
Expand Down Expand Up @@ -248,6 +252,8 @@ class AP_Notify
uint32_t _send_text_updated_millis; // last time text changed
char _flight_mode_str[5];

uint8_t _send_text_src_override = 0; //Bitmask of what lines send_text_src should override

static NotifyDevice* _devices[];
static uint8_t _num_devices;
};
Expand Down
45 changes: 38 additions & 7 deletions libraries/AP_Notify/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,46 @@ void Display::update()

void Display::update_all()
{
update_text(0);
update_mode(1);
update_battery(2);
if(!BIT_IS_SET(pNotify->_send_text_src_override, 0)) {
update_text(0);
}

if(!BIT_IS_SET(pNotify->_send_text_src_override, 1)) {
update_mode(1);
}

if(!BIT_IS_SET(pNotify->_send_text_src_override, 2)) {
update_battery(2);
}

#if AP_GPS_ENABLED
update_gps(3);
if(!BIT_IS_SET(pNotify->_send_text_src_override, 3)) {
update_gps(3);
}
#endif
//update_gps_sats(4);
update_prearm(4);
update_ekf(5);

if(!BIT_IS_SET(pNotify->_send_text_src_override, 4)) {
//update_gps_sats(4);
update_prearm(4);
}

if(!BIT_IS_SET(pNotify->_send_text_src_override, 5)) {
update_ekf(5);
}
}

void Display::send_text(const char *text, uint8_t r)
{
if (nullptr == text) {
return;
}
if (r >= NOTIFY_TEXT_NUM_ROWS) {
return;
}
char txt [NOTIFY_TEXT_BUFFER_SIZE] = {};
memset(txt, ' ', NOTIFY_TEXT_BUFFER_SIZE);
memcpy(txt, text, strnlen(text, NOTIFY_TEXT_BUFFER_SIZE));
draw_text(COLUMN(0), ROW(r), txt);
}

void Display::draw_text(uint16_t x, uint16_t y, const char* c)
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Notify/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Display: public NotifyDevice {

bool init(void) override;
void update() override;

void send_text(const char *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);
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Notify/NotifyDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class NotifyDevice {
// give RGB value for single led
virtual void rgb_set_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id) {}

virtual void send_text(const char *text, uint8_t line) {}

// this pointer is used to read the parameters relative to devices
const AP_Notify *pNotify;
};

0 comments on commit 8ec8ff2

Please sign in to comment.