From 3d2d5a2efaff57b98b4b415fe2fc2fb73628af48 Mon Sep 17 00:00:00 2001 From: Maciej Janowski Date: Wed, 13 Jun 2018 22:17:00 +0200 Subject: [PATCH] Initial implementation Percentage implementation Settings fix, formatting Add support for different number of motors Optimize and cut superfluous code Hard-add mixer.h Formatting adjustment to fit BF standards, linking error in unittest fix attempt Add stubs and variables for unittests Character based indicators Change output to special characters Fix spacing Update test code, add variable Include changes as per peer review --- src/main/interface/settings.c | 1 + src/main/io/osd.c | 19 ++++++++++++++++--- src/main/io/osd.h | 1 + src/test/unit/osd_unittest.cc | 7 +++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 45fb4cd34..e86edc331 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -933,6 +933,7 @@ const clivalue_t valueTable[] = { { "osd_ah_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ARTIFICIAL_HORIZON]) }, { "osd_current_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_CURRENT_DRAW]) }, { "osd_mah_drawn_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_MAH_DRAWN]) }, + { "osd_motor_diag_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_MOTOR_DIAG]) }, { "osd_craft_name_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_CRAFT_NAME]) }, { "osd_gps_speed_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_GPS_SPEED]) }, { "osd_gps_lon_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_GPS_LON]) }, diff --git a/src/main/io/osd.c b/src/main/io/osd.c index c0829e271..0367a2f25 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -67,9 +67,7 @@ #include "flight/position.h" #include "flight/imu.h" -#ifdef USE_ESC_SENSOR #include "flight/mixer.h" -#endif #include "flight/pid.h" #include "io/asyncfatfs/asyncfatfs.h" @@ -197,7 +195,8 @@ static const uint8_t osdElementDisplayOrder[] = { OSD_NUMERICAL_HEADING, OSD_NUMERICAL_VARIO, OSD_COMPASS_BAR, - OSD_ANTI_GRAVITY + OSD_ANTI_GRAVITY, + OSD_MOTOR_DIAG }; PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 3); @@ -600,6 +599,20 @@ static bool osdDrawSingleElement(uint8_t item) break; } + + case OSD_MOTOR_DIAG: + if(areMotorsRunning()) { + int maxIdx = 0; + int i = 0; + for(; i < getMotorCount(); i++) { + if(motor[i] > motor[maxIdx]) { + maxIdx = i; + } + buff[i] = 0x88 - scaleRange(motor[i], motorOutputLow, motorOutputHigh, 0, 8); + } + buff[i] = '\0'; + } + break; case OSD_CRAFT_NAME: // This does not strictly support iterative updating if the craft name changes at run time. But since the craft name is not supposed to be changing this should not matter, and blanking the entire length of the craft name string on update will make it impossible to configure elements to be displayed on the right hand side of the craft name. diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 644ed0718..4045a281b 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -95,6 +95,7 @@ typedef enum { OSD_ADJUSTMENT_RANGE, OSD_CORE_TEMPERATURE, OSD_ANTI_GRAVITY, + OSD_MOTOR_DIAG, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index 353fddcc9..718f10b27 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -51,6 +51,7 @@ extern "C" { #include "sensors/battery.h" #include "rx/rx.h" + #include "flight/mixer.h" void osdRefresh(timeUs_t currentTimeUs); void osdFormatTime(char * buff, osd_timer_precision_e precision, timeUs_t time); @@ -67,6 +68,10 @@ extern "C" { int16_t GPS_directionToHome; int32_t GPS_coord[2]; gpsSolutionData_t gpsSol; + float motor[8]; + float motorOutputHigh = 2047; + float motorOutputLow = 1000; + PG_REGISTER(batteryConfig_t, batteryConfig, PG_BATTERY_CONFIG, 0); PG_REGISTER(blackboxConfig_t, blackboxConfig, PG_BLACKBOX_CONFIG, 0); @@ -1032,4 +1037,6 @@ extern "C" { } float pidItermAccelerator(void) { return 1.0; } + uint8_t getMotorCount(void){ return 4; } + bool areMotorsRunning(void){ return true; } }