mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
AP_Notify: factor out a probe_i2c_display method
This commit is contained in:
committed by
Andrew Tridgell
parent
7e3a1d3fc9
commit
cfbbebeb3f
@@ -327,6 +327,20 @@ static_assert(ARRAY_SIZE(_font) == 1280, "_font is correct size");
|
||||
static_assert(ARRAY_SIZE(_font) == 475, "_font is correct size");
|
||||
#endif
|
||||
|
||||
Display_Backend *Display::probe_i2c_display(uint8_t bus, probe_i2c_display_probefn_t probe)
|
||||
{
|
||||
|
||||
const auto dev_ptr = hal.i2c_mgr->get_device_ptr(bus, NOTIFY_DISPLAY_I2C_ADDR);
|
||||
if (dev_ptr == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
Display_Backend *ret = probe(*dev_ptr);
|
||||
if (ret == nullptr) {
|
||||
delete dev_ptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Display::init(void)
|
||||
{
|
||||
// exit immediately if already initialised
|
||||
@@ -338,14 +352,7 @@ bool Display::init(void)
|
||||
FOREACH_I2C(i) {
|
||||
switch (pNotify->_display_type) {
|
||||
case DISPLAY_SSD1306: {
|
||||
const auto dev_ptr = hal.i2c_mgr->get_device_ptr(i, NOTIFY_DISPLAY_I2C_ADDR);
|
||||
if (dev_ptr == nullptr) {
|
||||
break;
|
||||
}
|
||||
_driver = Display_SSD1306_I2C::probe(*dev_ptr);
|
||||
if (_driver == nullptr) {
|
||||
delete dev_ptr;
|
||||
}
|
||||
_driver = probe_i2c_display(i, Display_SSD1306_I2C::probe);
|
||||
break;
|
||||
}
|
||||
case DISPLAY_SH1106: {
|
||||
|
||||
@@ -23,6 +23,10 @@ public:
|
||||
void send_text_blocking(const char *text, uint8_t line) override;
|
||||
void release_text(uint8_t line) override;
|
||||
private:
|
||||
|
||||
using probe_i2c_display_probefn_t = Display_Backend* (*)(AP_HAL::Device&);
|
||||
Display_Backend *probe_i2c_display(uint8_t bus, probe_i2c_display_probefn_t probe);
|
||||
|
||||
void draw_char(uint16_t x, uint16_t y, const char c);
|
||||
void draw_text(uint16_t x, uint16_t y, const char *c);
|
||||
void update_all();
|
||||
|
||||
@@ -28,7 +28,7 @@ Display_SSD1306_I2C::~Display_SSD1306_I2C()
|
||||
}
|
||||
|
||||
|
||||
Display_SSD1306_I2C *Display_SSD1306_I2C::probe(AP_HAL::Device &_dev)
|
||||
Display_Backend *Display_SSD1306_I2C::probe(AP_HAL::Device &_dev)
|
||||
{
|
||||
Display_SSD1306_I2C *driver = NEW_NOTHROW Display_SSD1306_I2C(_dev);
|
||||
if (!driver || !driver->hw_init()) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class Display_SSD1306_I2C: public Display_Backend {
|
||||
|
||||
public:
|
||||
|
||||
static Display_SSD1306_I2C *probe(AP_HAL::Device &_dev);
|
||||
static Display_Backend *probe(AP_HAL::Device &_dev);
|
||||
|
||||
void hw_update() override;
|
||||
void set_pixel(uint16_t x, uint16_t y) override;
|
||||
|
||||
Reference in New Issue
Block a user