AP_OSD: added option to pack decimal numbers

This commit is contained in:
Andrew Tridgell 2018-07-04 18:07:20 +10:00
parent d8b643a888
commit 141b9703a9
3 changed files with 25 additions and 0 deletions

View File

@ -70,6 +70,13 @@ const AP_Param::GroupInfo AP_OSD::var_info[] = {
// @User: Standard // @User: Standard
AP_GROUPINFO("_SW_METHOD", 7, AP_OSD, sw_method, AP_OSD::TOGGLE), AP_GROUPINFO("_SW_METHOD", 7, AP_OSD, sw_method, AP_OSD::TOGGLE),
// @Param: _OPTIONS
// @DisplayName: OSD Options
// @Description: This sets options that change the display
// @Bitmask: 0:UseDecimalPack
// @User: Standard
AP_GROUPINFO("_OPTIONS", 8, AP_OSD, options, 0),
AP_GROUPEND AP_GROUPEND
}; };

View File

@ -162,6 +162,12 @@ public:
AP_Int8 rc_channel; AP_Int8 rc_channel;
AP_Int8 sw_method; AP_Int8 sw_method;
enum {
OPTION_DECIMAL_PACK = 1U<<0,
};
AP_Int32 options;
AP_OSD_Screen screen[AP_OSD_NUM_SCREENS]; AP_OSD_Screen screen[AP_OSD_NUM_SCREENS];
private: private:

View File

@ -16,15 +16,27 @@
#include <AP_OSD/AP_OSD_Backend.h> #include <AP_OSD/AP_OSD_Backend.h>
#include <AP_HAL/Util.h> #include <AP_HAL/Util.h>
#include <ctype.h>
extern const AP_HAL::HAL& hal; extern const AP_HAL::HAL& hal;
#define SYM_DIG_OFS 0x90
void AP_OSD_Backend::write(uint8_t x, uint8_t y, bool blink, const char *fmt, ...) void AP_OSD_Backend::write(uint8_t x, uint8_t y, bool blink, const char *fmt, ...)
{ {
char buff[32]; char buff[32];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
int res = hal.util->vsnprintf(buff, sizeof(buff), fmt, ap); int res = hal.util->vsnprintf(buff, sizeof(buff), fmt, ap);
if (res > 0 && _osd.options.get() & AP_OSD::OPTION_DECIMAL_PACK) {
// automatically use packed decimal characters
char *p = strchr(&buff[1],'.');
if (p && isdigit(p[1]) && isdigit(p[-1])) {
p[-1] += SYM_DIG_OFS;
memmove(p, p+1, strlen(p+1)+1);
res--;
}
}
if (res < int(sizeof(buff))) { if (res < int(sizeof(buff))) {
write(x, y, buff, blink? AP_OSD_Backend::BLINK : 0); write(x, y, buff, blink? AP_OSD_Backend::BLINK : 0);
} }