ardupilot/libraries/AP_OSD/AP_OSD.cpp

112 lines
2.9 KiB
C++
Raw Normal View History

2018-06-23 04:11:05 -03:00
/*
* This file is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* AP_OSD partially based on betaflight and inav osd.c implemention.
* clarity.mcm font is taken from inav configurator.
* Many thanks to their authors.
*/
2018-06-24 07:00:23 -03:00
#include "AP_OSD.h"
#include "AP_OSD_MAX7456.h"
2018-06-23 04:11:05 -03:00
#include <AP_HAL/AP_HAL.h>
#include <AP_HAL/Util.h>
#include <utility>
const AP_Param::GroupInfo AP_OSD::var_info[] = {
2018-06-24 07:00:23 -03:00
// @Param: _TYPE
// @DisplayName: OSD type
// @Description: OSD type
// @Values: 0:None,1:MAX7456
2018-06-23 04:11:05 -03:00
// @User: Standard
2018-06-24 07:00:23 -03:00
AP_GROUPINFO_FLAGS("_TYPE", 1, AP_OSD, osd_type, 0, AP_PARAM_FLAG_ENABLE),
2018-06-23 04:11:05 -03:00
2018-06-24 07:00:23 -03:00
// @Param: _UPDATE_FONT
2018-06-23 04:11:05 -03:00
// @DisplayName: Update font
// @Description: Undate font inside osd chip
// @Values: 0:Do not update,1:Update
// @User: Standard
2018-06-24 07:00:23 -03:00
AP_GROUPINFO("_UPDATE_FONT", 2, AP_OSD, update_font, 1),
2018-06-23 04:11:05 -03:00
2018-06-24 07:00:23 -03:00
// @Group: 1_
// @Path: AP_OSD_Screen.cpp
AP_SUBGROUPINFO(screen[0], "1_", 3, AP_OSD, AP_OSD_Screen),
2018-06-23 04:11:05 -03:00
2018-06-24 07:00:23 -03:00
// @Group: 2_
// @Path: AP_OSD_Screen.cpp
AP_SUBGROUPINFO(screen[1], "2_", 4, AP_OSD, AP_OSD_Screen),
2018-06-23 04:11:05 -03:00
2018-06-24 07:00:23 -03:00
// @Group: 2_
// @Path: AP_OSD_Screen.cpp
AP_SUBGROUPINFO(screen[2], "3_", 5, AP_OSD, AP_OSD_Screen),
2018-06-23 04:11:05 -03:00
2018-06-24 07:00:23 -03:00
// @Group: 2_
// @Path: AP_OSD_Screen.cpp
AP_SUBGROUPINFO(screen[3], "4_", 6, AP_OSD, AP_OSD_Screen),
2018-06-23 04:11:05 -03:00
AP_GROUPEND
};
extern const AP_HAL::HAL& hal;
2018-06-24 07:45:58 -03:00
AP_OSD::AP_OSD()
2018-06-23 04:11:05 -03:00
{
AP_Param::setup_object_defaults(this, var_info);
2018-06-24 07:45:58 -03:00
// default first screen enabled
screen[0].enabled = 1;
2018-06-23 04:11:05 -03:00
}
void AP_OSD::init()
{
2018-06-24 07:00:23 -03:00
switch ((enum osd_types)osd_type.get()) {
case OSD_NONE:
break;
case OSD_MAX7456:
AP_HAL::OwnPtr<AP_HAL::Device> spi_dev = std::move(hal.spi->get_device("osd"));
if (!spi_dev) {
break;
}
backend = AP_OSD_MAX7456::probe(*this, std::move(spi_dev));
if (backend == nullptr) {
break;
}
hal.console->printf("Started MAX7456 OSD\n");
hal.scheduler->register_io_process(FUNCTOR_BIND_MEMBER(&AP_OSD::timer, void));
break;
2018-06-23 04:11:05 -03:00
}
}
void AP_OSD::timer()
{
uint32_t now = AP_HAL::millis();
2018-06-24 07:00:23 -03:00
if (now - last_update_ms > 100) {
2018-06-23 04:11:05 -03:00
last_update_ms = now;
update_osd();
}
}
void AP_OSD::update_osd()
{
backend->clear();
2018-06-24 07:00:23 -03:00
screen[current_screen].set_backend(backend);
screen[current_screen].draw();
2018-06-23 04:11:05 -03:00
backend->flush();
}