From f8c48f569aa43df8adadb34c5e475f55e2ec07cf Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 3 Nov 2016 03:35:33 +0900 Subject: [PATCH] Menu contents separation --- src/main/io/cms.c | 518 ++------------------- src/main/io/cms.h | 7 +- src/main/io/cms_blackbox.c | 77 +++ src/main/io/cms_blackbox.h | 4 + src/main/io/cms_imu.c | 206 ++++++++ src/main/io/cms_imu.h | 13 + src/main/io/cms_ledstrip.c | 107 +++++ src/main/io/cms_ledstrip.h | 6 + src/main/io/cms_osd.h | 2 + src/main/io/cms_vtx.c | 96 ++++ src/main/io/cms_vtx.h | 7 + src/main/io/osd.c | 52 +++ src/main/target/OMNIBUS/target.mk | 6 +- src/main/target/SIRINFPV/target.mk | 6 +- src/main/target/SPRACINGF3/target.mk | 6 +- src/main/target/STM32F3DISCOVERY/target.mk | 8 +- 16 files changed, 646 insertions(+), 475 deletions(-) create mode 100644 src/main/io/cms_blackbox.c create mode 100644 src/main/io/cms_blackbox.h create mode 100644 src/main/io/cms_imu.c create mode 100644 src/main/io/cms_imu.h create mode 100644 src/main/io/cms_ledstrip.c create mode 100644 src/main/io/cms_ledstrip.h create mode 100644 src/main/io/cms_osd.h create mode 100644 src/main/io/cms_vtx.c create mode 100644 src/main/io/cms_vtx.h diff --git a/src/main/io/cms.c b/src/main/io/cms.c index 13bed7f3f8..7c74a777ea 100644 --- a/src/main/io/cms.c +++ b/src/main/io/cms.c @@ -57,6 +57,20 @@ #include "build/debug.h" +// External menu contents +#include "io/cms_imu.h" +#include "io/cms_blackbox.h" +#include "io/cms_vtx.h" +#ifdef OSD +#include "io/cms_osd.h" +#endif // OSD +#include "io/cms_ledstrip.h" + +// Forwards +void cmsx_InfoInit(void); +void cmsx_FeatureRead(void); +void cmsx_FeatureWriteback(void); + // Device management #define CMS_MAX_DEVICE 4 @@ -164,9 +178,11 @@ void cmsScreenInit(displayPort_t *pDisp, cmsDeviceInitFuncPtr cmsDeviceInitFunc) // #define LEFT_MENU_COLUMN 1 -#define RIGHT_MENU_COLUMN(p) ((p)->cols - 7) +#define RIGHT_MENU_COLUMN(p) ((p)->cols - 10) #define MAX_MENU_ITEMS(p) ((p)->rows - 2) +displayPort_t currentDisplay; + bool cmsInMenu = false; OSD_Entry *menuStack[10]; //tab to save menu stack @@ -210,7 +226,7 @@ void cmsUpdateMaxRows(displayPort_t *instance) currentMenuIdx--; } -static void cmsFtoa(int32_t value, char *floatString) +static void cmsFormatFloat(int32_t value, char *floatString) { uint8_t k; // np. 3450 @@ -225,7 +241,8 @@ static void cmsFtoa(int32_t value, char *floatString) // 03.450 // usuwam koncowe zera i kropke - for (k = 5; k > 1; k--) + // Keep the first decimal place + for (k = 5; k > 3; k--) if (floatString[k] == '0' || floatString[k] == '.') floatString[k] = 0; else @@ -355,7 +372,7 @@ int cmsDrawMenuEntry(displayPort_t *pDisplay, OSD_Entry *p, uint8_t row, bool dr case OME_FLOAT: if (IS_PRINTVALUE(p) && p->data) { OSD_FLOAT_t *ptr = p->data; - cmsFtoa(*ptr->val * ptr->multipler, buff); + cmsFormatFloat(*ptr->val * ptr->multipler, buff); cmsPad(buff, 5); cnt = cmsScreenWrite(pDisplay, RIGHT_MENU_COLUMN(pDisplay) - 1, row, buff); // XXX One char left ??? CLR_PRINTVALUE(p); @@ -447,22 +464,14 @@ void cmsDrawMenu(displayPort_t *pDisplay) } } -// XXX Needs separation -OSD_Entry menuPid[]; -void cmsx_PidRead(void); -void cmsx_PidWriteback(void); -OSD_Entry menuRateExpo[]; -void cmsx_RateExpoRead(void); -void cmsx_RateExpoWriteback(void); - long cmsMenuChange(displayPort_t *pDisplay, void *ptr) { if (ptr) { // XXX (jflyper): This can be avoided by adding pre- and post- // XXX (or onEnter and onExit) functions? - if (ptr == &menuPid[0]) + if (ptr == cmsx_menuPid) cmsx_PidRead(); - if (ptr == &menuRateExpo[0]) + if (ptr == cmsx_menuRateExpo) cmsx_RateExpoRead(); if ((OSD_Entry *)ptr != currentMenu) { @@ -485,11 +494,11 @@ long cmsMenuBack(displayPort_t *pDisplay) { // becasue pids and rates may be stored in profiles we need some thicks to manipulate it // hack to save pid profile - if (currentMenu == &menuPid[0]) + if (currentMenu == cmsx_menuPid) cmsx_PidWriteback(); // hack - save rate config for current profile - if (currentMenu == &menuRateExpo[0]) + if (currentMenu == cmsx_menuRateExpo) cmsx_RateExpoWriteback(); if (menuStackIdx) { @@ -505,13 +514,6 @@ long cmsMenuBack(displayPort_t *pDisplay) return 0; } -// XXX Separation -void cmsx_FeatureRead(void); -void cmsx_FeatureWriteback(void); -void cmsx_InfoInit(void); - -displayPort_t currentDisplay; - void cmsMenuOpen(void) { cmsDeviceInitFuncPtr initfunc; @@ -744,8 +746,6 @@ uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key) return res; } -OSD_Entry menuRc[]; - void cmsUpdate(displayPort_t *pDisplay, uint32_t currentTime) { static int16_t rcDelay = BUTTON_TIME; @@ -785,7 +785,7 @@ void cmsUpdate(displayPort_t *pDisplay, uint32_t currentTime) key = KEY_RIGHT; rcDelay = BUTTON_TIME; } - else if ((IS_HI(YAW) || IS_LO(YAW)) && currentMenu != menuRc) // this menu is used to check transmitter signals so can't exit using YAW + else if ((IS_HI(YAW) || IS_LO(YAW)) && currentMenu != cmsx_menuRc) // this menu is used to check transmitter signals so can't exit using YAW { key = KEY_ESC; rcDelay = BUTTON_TIME; @@ -830,401 +830,11 @@ void cmsInit(void) } // -// Menu tables, should eventually be all GONE!? +// Menu contents // -// -// IMU -// - -OSD_UINT8_t entryPidProfile = {&masterConfig.current_profile_index, 0, MAX_PROFILE_COUNT, 1}; - -uint8_t tempPid[4][3]; - -static OSD_UINT8_t entryRollP = {&tempPid[PIDROLL][0], 10, 150, 1}; -static OSD_UINT8_t entryRollI = {&tempPid[PIDROLL][1], 1, 150, 1}; -static OSD_UINT8_t entryRollD = {&tempPid[PIDROLL][2], 0, 150, 1}; - -static OSD_UINT8_t entryPitchP = {&tempPid[PIDPITCH][0], 10, 150, 1}; -static OSD_UINT8_t entryPitchI = {&tempPid[PIDPITCH][1], 1, 150, 1}; -static OSD_UINT8_t entryPitchD = {&tempPid[PIDPITCH][2], 0, 150, 1}; - -static OSD_UINT8_t entryYawP = {&tempPid[PIDYAW][0], 10, 150, 1}; -static OSD_UINT8_t entryYawI = {&tempPid[PIDYAW][1], 1, 150, 1}; -static OSD_UINT8_t entryYawD = {&tempPid[PIDYAW][2], 0, 150, 1}; - -void cmsx_PidRead(void) -{ - uint8_t i; - - for (i = 0; i < 3; i++) { - tempPid[i][0] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[i]; - tempPid[i][1] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[i]; - tempPid[i][2] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[i]; - } - tempPid[3][0] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[PIDLEVEL]; - tempPid[3][1] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[PIDLEVEL]; - tempPid[3][2] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[PIDLEVEL]; -} - -void cmsx_PidWriteback(void) -{ - uint8_t i; - - for (i = 0; i < 3; i++) { - masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[i] = tempPid[i][0]; - masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[i] = tempPid[i][1]; - masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[i] = tempPid[i][2]; - } - - masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[PIDLEVEL] = tempPid[3][0]; - masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[PIDLEVEL] = tempPid[3][1]; - masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[PIDLEVEL] = tempPid[3][2]; -} - -OSD_Entry menuPid[] = -{ - {"--- PID ---", OME_Label, NULL, NULL, 0}, - {"ROLL P", OME_UINT8, NULL, &entryRollP, 0}, - {"ROLL I", OME_UINT8, NULL, &entryRollI, 0}, - {"ROLL D", OME_UINT8, NULL, &entryRollD, 0}, - - {"PITCH P", OME_UINT8, NULL, &entryPitchP, 0}, - {"PITCH I", OME_UINT8, NULL, &entryPitchI, 0}, - {"PITCH D", OME_UINT8, NULL, &entryPitchD, 0}, - - {"YAW P", OME_UINT8, NULL, &entryYawP, 0}, - {"YAW I", OME_UINT8, NULL, &entryYawI, 0}, - {"YAW D", OME_UINT8, NULL, &entryYawD, 0}, - - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -// -// Rate & Expo -// -controlRateConfig_t rateProfile; - -static OSD_FLOAT_t entryRollRate = {&rateProfile.rates[0], 0, 250, 1, 10}; -static OSD_FLOAT_t entryPitchRate = {&rateProfile.rates[1], 0, 250, 1, 10}; -static OSD_FLOAT_t entryYawRate = {&rateProfile.rates[2], 0, 250, 1, 10}; -static OSD_FLOAT_t entryRcRate = {&rateProfile.rcRate8, 0, 200, 1, 10}; -static OSD_FLOAT_t entryRcYawRate = {&rateProfile.rcYawRate8, 0, 200, 1, 10}; -static OSD_FLOAT_t entryRcExpo = {&rateProfile.rcExpo8, 0, 100, 1, 10}; -static OSD_FLOAT_t entryRcExpoYaw = {&rateProfile.rcYawExpo8, 0, 100, 1, 10}; -static OSD_FLOAT_t extryTpaEntry = {&rateProfile.dynThrPID, 0, 70, 1, 10}; -static OSD_UINT16_t entryTpaBreak = {&rateProfile.tpa_breakpoint, 1100, 1800, 10}; -static OSD_FLOAT_t entryPSetpoint = {&masterConfig.profile[0].pidProfile.setpointRelaxRatio, 0, 100, 1, 10}; -static OSD_FLOAT_t entryDSetpoint = {&masterConfig.profile[0].pidProfile.dtermSetpointWeight, 0, 255, 1, 10}; - -void cmsx_RateExpoRead() -{ - memcpy(&rateProfile, &masterConfig.profile[masterConfig.current_profile_index].controlRateProfile[masterConfig.profile[masterConfig.current_profile_index].activeRateProfile], sizeof(controlRateConfig_t)); -} - -void cmsx_RateExpoWriteback() -{ - memcpy(&masterConfig.profile[masterConfig.current_profile_index].controlRateProfile[masterConfig.profile[masterConfig.current_profile_index].activeRateProfile], &rateProfile, sizeof(controlRateConfig_t)); -} - -OSD_Entry menuRateExpo[] = -{ - {"--- RATE&EXPO ---", OME_Label, NULL, NULL, 0}, - {"RC RATE", OME_FLOAT, NULL, &entryRcYawRate, 0}, - {"RC YAW RATE", OME_FLOAT, NULL, &entryRcRate, 0}, - {"ROLL SUPER", OME_FLOAT, NULL, &entryRollRate, 0}, - {"PITCH SUPER", OME_FLOAT, NULL, &entryPitchRate, 0}, - {"YAW SUPER", OME_FLOAT, NULL, &entryYawRate, 0}, - {"RC EXPO", OME_FLOAT, NULL, &entryRcExpo, 0}, - {"RC YAW EXPO", OME_FLOAT, NULL, &entryRcExpoYaw, 0}, - {"THR PID ATT", OME_FLOAT, NULL, &extryTpaEntry, 0}, - {"TPA BRKPT", OME_UINT16, NULL, &entryTpaBreak, 0}, - {"D SETPT", OME_FLOAT, NULL, &entryDSetpoint, 0}, - {"D SETPT TRN", OME_FLOAT, NULL, &entryPSetpoint, 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -// -// RC preview -// -static OSD_INT16_t entryRcRoll = {&rcData[ROLL], 1, 2500, 0}; -static OSD_INT16_t entryRcPitch = {&rcData[PITCH], 1, 2500, 0}; -static OSD_INT16_t entryRcThr = {&rcData[THROTTLE], 1, 2500, 0}; -static OSD_INT16_t entryRcYaw = {&rcData[YAW], 1, 2500, 0}; -static OSD_INT16_t entryRcAux1 = {&rcData[AUX1], 1, 2500, 0}; -static OSD_INT16_t entryRcAux2 = {&rcData[AUX2], 1, 2500, 0}; -static OSD_INT16_t entryRcAux3 = {&rcData[AUX3], 1, 2500, 0}; -static OSD_INT16_t entryRcAux4 = {&rcData[AUX4], 1, 2500, 0}; - -OSD_Entry menuRc[] = -{ - {"--- RC PREV ---", OME_Label, NULL, NULL, 0}, - {"ROLL", OME_Poll_INT16, NULL, &entryRcRoll, 0}, - {"PITCH", OME_Poll_INT16, NULL, &entryRcPitch, 0}, - {"THR", OME_Poll_INT16, NULL, &entryRcThr, 0}, - {"YAW", OME_Poll_INT16, NULL, &entryRcYaw, 0}, - {"AUX1", OME_Poll_INT16, NULL, &entryRcAux1, 0}, - {"AUX2", OME_Poll_INT16, NULL, &entryRcAux2, 0}, - {"AUX3", OME_Poll_INT16, NULL, &entryRcAux3, 0}, - {"AUX4", OME_Poll_INT16, NULL, &entryRcAux4, 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -// -// Misc -// -OSD_UINT16_t entryMinThrottle = {&masterConfig.motorConfig.minthrottle, 1020, 1300, 10}; -OSD_UINT8_t entryGyroSoftLpfHz = {&masterConfig.gyro_soft_lpf_hz, 0, 255, 1}; -OSD_UINT16_t entryDtermLpf = {&masterConfig.profile[0].pidProfile.dterm_lpf_hz, 0, 500, 5}; -OSD_UINT16_t entryYawLpf = {&masterConfig.profile[0].pidProfile.yaw_lpf_hz, 0, 500, 5}; -OSD_UINT16_t entryYawPLimit = {&masterConfig.profile[0].pidProfile.yaw_p_limit, 100, 500, 5}; -OSD_UINT8_t entryVbatScale = {&masterConfig.batteryConfig.vbatscale, 1, 250, 1}; -OSD_UINT8_t entryVbatMaxCell = {&masterConfig.batteryConfig.vbatmaxcellvoltage, 10, 50, 1}; - -OSD_Entry menuImuMisc[]= -{ - {"--- MISC ---", OME_Label, NULL, NULL, 0}, - {"GYRO LPF", OME_UINT8, NULL, &entryGyroSoftLpfHz, 0}, - {"DTERM LPF", OME_UINT16, NULL, &entryDtermLpf, 0}, - {"YAW LPF", OME_UINT16, NULL, &entryYawLpf, 0}, - {"YAW P LIM", OME_UINT16, NULL, &entryYawPLimit, 0}, - {"MIN THR", OME_UINT16, NULL, &entryMinThrottle, 0}, - {"VBAT SCALE", OME_UINT8, NULL, &entryVbatScale, 0}, - {"VBAT CLMAX", OME_UINT8, NULL, &entryVbatMaxCell, 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -OSD_Entry menuImu[] = -{ - {"--- CFG.IMU ---", OME_Label, NULL, NULL, 0}, - {"PID PROF", OME_UINT8, NULL, &entryPidProfile, 0}, - {"PID", OME_Submenu, cmsMenuChange, &menuPid[0], 0}, - {"RATE&RXPO", OME_Submenu, cmsMenuChange, &menuRateExpo[0], 0}, - {"RC PREV", OME_Submenu, cmsMenuChange, &menuRc[0], 0}, - {"MISC", OME_Submenu, cmsMenuChange, &menuImuMisc[0], 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -// -// Black box -// - -// -// Should goto flashfs eventually. -// -#ifdef USE_FLASHFS -long cmsx_EraseFlash(displayPort_t *pDisplay, void *ptr) -{ - UNUSED(ptr); - - cmsScreenClear(pDisplay); - cmsScreenWrite(pDisplay, 5, 3, "ERASING FLASH..."); - cmsScreenResync(pDisplay); // Was max7456RefreshAll(); Why at this timing? - - flashfsEraseCompletely(); - while (!flashfsIsReady()) { - delay(100); - } - - cmsScreenClear(pDisplay); - cmsScreenResync(pDisplay); // Was max7456RefreshAll(); wedges during heavy SPI? - - return 0; -} -#endif // USE_FLASHFS - -uint8_t featureBlackbox = 0; - -OSD_UINT8_t entryBlackboxRateDenom = {&masterConfig.blackbox_rate_denom,1,32,1}; - -OSD_Entry menuBlackbox[] = -{ - {"--- BLACKBOX ---", OME_Label, NULL, NULL, 0}, - {"ENABLED", OME_Bool, NULL, &featureBlackbox, 0}, - {"RATE DENOM", OME_UINT8, NULL, &entryBlackboxRateDenom, 0}, -#ifdef USE_FLASHFS - {"ERASE FLASH", OME_Submenu, cmsx_EraseFlash, NULL, 0}, -#endif // USE_FLASHFS - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -// -// VTX -// -#if defined(VTX) || defined(USE_RTC6705) - -uint8_t featureVtx = 0, vtxBand, vtxChannel; - -static const char * const vtxBandNames[] = { - "BOSCAM A", - "BOSCAM B", - "BOSCAM E", - "FATSHARK", - "RACEBAND", -}; - -OSD_TAB_t entryVtxBand = {&vtxBand,4,&vtxBandNames[0]}; -OSD_UINT8_t entryVtxChannel = {&vtxChannel, 1, 8, 1}; - -#ifdef VTX -OSD_UINT8_t entryVtxMode = {&masterConfig.vtx_mode, 0, 2, 1}; -OSD_UINT16_t entryVtxMhz = {&masterConfig.vtx_mhz, 5600, 5950, 1}; -#endif // VTX - -OSD_Entry menu_vtx[] = -{ - {"--- VTX ---", OME_Label, NULL, NULL, 0}, - {"ENABLED", OME_Bool, NULL, &featureVtx, 0}, -#ifdef VTX - {"VTX MODE", OME_UINT8, NULL, &entryVtxMode, 0}, - {"VTX MHZ", OME_UINT16, NULL, &entryVtxMhz, 0}, -#endif // VTX - {"BAND", OME_TAB, NULL, &entryVtxBand, 0}, - {"CHANNEL", OME_UINT8, NULL, &entryVtxChannel, 0}, -#ifdef USE_RTC6705 - {"LOW POWER", OME_Bool, NULL, &masterConfig.vtx_power, 0}, -#endif // USE_RTC6705 - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; -#endif // VTX || USE_RTC6705 - -// -// LED_STRIP -// -#ifdef LED_STRIP - -//local variable to keep color value -uint8_t ledColor; - -static const char * const LED_COLOR_NAMES[] = { - "BLACK ", - "WHITE ", - "RED ", - "ORANGE ", - "YELLOW ", - "LIME GRN", - "GREEN ", - "MINT GRN", - "CYAN ", - "LT BLUE ", - "BLUE ", - "DK VIOLT", - "MAGENTA ", - "DEEP PNK" -}; - -//find first led with color flag and restore color index -//after saving all leds with flags color will have color set in OSD -static void getLedColor(void) -{ - for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) { - const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex]; - - int fn = ledGetFunction(ledConfig); - - if (fn == LED_FUNCTION_COLOR) { - ledColor = ledGetColor(ledConfig); - break; - } - } -} - -//udate all leds with flag color -static long applyLedColor(displayPort_t *pDisplay, void *ptr) -{ - UNUSED(ptr); - UNUSED(pDisplay); // Arrgh - - for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) { - ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex]; - if (ledGetFunction(ledConfig) == LED_FUNCTION_COLOR) - *ledConfig = DEFINE_LED(ledGetX(ledConfig), ledGetY(ledConfig), ledColor, ledGetDirection(ledConfig), ledGetFunction(ledConfig), ledGetOverlay(ledConfig), 0); - } - - return 0; -} - -static uint8_t featureLedstrip; - -OSD_TAB_t entryLed = {&ledColor, 13, &LED_COLOR_NAMES[0]}; - -OSD_Entry menuLedstrip[] = -{ - {"--- LED STRIP ---", OME_Label, NULL, NULL, 0}, - {"ENABLED", OME_Bool, NULL, &featureLedstrip, 0}, - {"LED COLOR", OME_TAB, applyLedColor, &entryLed, 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; -#endif // LED_STRIP - -#ifdef OSD -// -// OSD specific menu pages and items -// XXX Should be part of the osd.c, or new osd_cms.c. -// - -OSD_UINT8_t entryAlarmRssi = {&masterConfig.osdProfile.rssi_alarm, 5, 90, 5}; -OSD_UINT16_t entryAlarmCapacity = {&masterConfig.osdProfile.cap_alarm, 50, 30000, 50}; -OSD_UINT16_t enryAlarmFlyTime = {&masterConfig.osdProfile.time_alarm, 1, 200, 1}; -OSD_UINT16_t entryAlarmAltitude = {&masterConfig.osdProfile.alt_alarm, 1, 200, 1}; - -OSD_Entry menuAlarms[] = -{ - {"--- ALARMS ---", OME_Label, NULL, NULL, 0}, - {"RSSI", OME_UINT8, NULL, &entryAlarmRssi, 0}, - {"MAIN BAT", OME_UINT16, NULL, &entryAlarmCapacity, 0}, - {"FLY TIME", OME_UINT16, NULL, &enryAlarmFlyTime, 0}, - {"MAX ALT", OME_UINT16, NULL, &entryAlarmAltitude, 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -OSD_Entry menuOsdActiveElems[] = -{ - {"--- ACTIV ELEM ---", OME_Label, NULL, NULL, 0}, - {"RSSI", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_RSSI_VALUE], 0}, - {"MAIN BATTERY", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_MAIN_BATT_VOLTAGE], 0}, - {"HORIZON", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON], 0}, - {"HORIZON SIDEBARS", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_HORIZON_SIDEBARS], 0}, - {"UPTIME", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_ONTIME], 0}, - {"FLY TIME", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_FLYTIME], 0}, - {"FLY MODE", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_FLYMODE], 0}, - {"NAME", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_CRAFT_NAME], 0}, - {"THROTTLE", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_THROTTLE_POS], 0}, -#ifdef VTX - {"VTX CHAN", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_VTX_CHANNEL]}, -#endif // VTX - {"CURRENT (A)", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_CURRENT_DRAW], 0}, - {"USED MAH", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_MAH_DRAWN], 0}, -#ifdef GPS - {"GPS SPEED", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_GPS_SPEED], 0}, - {"GPS SATS.", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_GPS_SATS], 0}, -#endif // GPS - {"ALTITUDE", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_ALTITUDE], 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; - -OSD_Entry menuOsdLayout[] = -{ - {"---SCREEN LAYOUT---", OME_Label, NULL, NULL, 0}, - {"ACTIVE ELEM.", OME_Submenu, cmsMenuChange, &menuOsdActiveElems[0], 0}, - {"BACK", OME_Back, NULL, NULL, 0}, - {NULL, OME_END, NULL, NULL, 0} -}; -#endif // OSD - -// // Info -// + static char infoGitRev[GIT_SHORT_REVISION_LENGTH]; static char infoTargetName[] = __TARGET__; @@ -1236,13 +846,6 @@ OSD_Entry menuInfo[] = { { "FWVER", OME_String, NULL, FC_VERSION_STRING, 0 }, { "GITREV", OME_String, NULL, infoGitRev, 0 }, { "TARGET", OME_String, NULL, infoTargetName, 0 }, - -#if 0 - { BETAFLIGHT_IDENTIFIER, OME_Label, NULL, NULL, 0 }, - { FC_VERSION_STRING, OME_Label, NULL, NULL, 0 }, - { infoGitRev, OME_Label, NULL, NULL, 0 }, - { infoTargetName, OME_Label, NULL, NULL, 0 }, -#endif { "BACK", OME_Back, NULL, NULL, 0 }, { NULL, OME_END, NULL, NULL, 0 } }; @@ -1257,30 +860,34 @@ void cmsx_InfoInit(void) } } +// Features + OSD_Entry menuFeatures[] = { {"--- FEATURES ---", OME_Label, NULL, NULL, 0}, - {"BLACKBOX", OME_Submenu, cmsMenuChange, &menuBlackbox[0], 0}, + {"BLACKBOX", OME_Submenu, cmsMenuChange, cmsx_menuBlackbox, 0}, #if defined(VTX) || defined(USE_RTC6705) - {"VTX", OME_Submenu, cmsMenuChange, &menu_vtx[0], 0}, + {"VTX", OME_Submenu, cmsMenuChange, cmsx_menuVtx, 0}, #endif // VTX || USE_RTC6705 #ifdef LED_STRIP - {"LED STRIP", OME_Submenu, cmsMenuChange, &menuLedstrip[0], 0}, + {"LED STRIP", OME_Submenu, cmsMenuChange, &cmsx_menuLedstrip, 0}, #endif // LED_STRIP {"BACK", OME_Back, NULL, NULL, 0}, {NULL, OME_END, NULL, NULL, 0} }; +// Main + OSD_Entry menuMain[] = { {"--- MAIN MENU ---", OME_Label, NULL, NULL, 0}, - {"CFG&IMU", OME_Submenu, cmsMenuChange, &menuImu[0], 0}, - {"FEATURES", OME_Submenu, cmsMenuChange, &menuFeatures[0], 0}, + {"CFG&IMU", OME_Submenu, cmsMenuChange, cmsx_menuImu, 0}, + {"FEATURES", OME_Submenu, cmsMenuChange, menuFeatures, 0}, #ifdef OSD - {"SCR LAYOUT", OME_Submenu, cmsMenuChange, &menuOsdLayout[0], 0}, - {"ALARMS", OME_Submenu, cmsMenuChange, &menuAlarms[0], 0}, + {"SCR LAYOUT", OME_Submenu, cmsMenuChange, cmsx_menuOsdLayout, 0}, + {"ALARMS", OME_Submenu, cmsMenuChange, cmsx_menuAlarms, 0}, #endif - {"INFO", OME_Submenu, cmsMenuChange, &menuInfo[0], 0}, + {"FC&FW INFO", OME_Submenu, cmsMenuChange, menuInfo, 0}, {"SAVE&REBOOT", OME_OSD_Exit, cmsMenuExit, (void*)1, 0}, {"EXIT", OME_OSD_Exit, cmsMenuExit, (void*)0, 0}, {NULL,OME_END, NULL, NULL, 0} @@ -1288,60 +895,33 @@ OSD_Entry menuMain[] = void cmsx_FeatureRead(void) { - featureBlackbox = feature(FEATURE_BLACKBOX) ? 1 : 0; + cmsx_Blackbox_FeatureRead(); #ifdef LED_STRIP - featureLedstrip = feature(FEATURE_LED_STRIP) ? 1 : 0; - getLedColor(); + cmsx_Ledstrip_FeatureRead(); + cmsx_Ledstrip_ConfigRead(); #endif #if defined(VTX) || defined(USE_RTC6705) - featureVtx = feature(FEATURE_VTX) ? 1 : 0; + cmsx_Vtx_FeatureRead(); + cmsx_Vtx_ConfigRead(); #endif // VTX || USE_RTC6705 - -#ifdef VTX - vtxBand = masterConfig.vtxBand; - vtxChannel = masterConfig.vtx_channel + 1; -#endif // VTX - -#ifdef USE_RTC6705 - vtxBand = masterConfig.vtx_channel / 8; - vtxChannel = masterConfig.vtx_channel % 8 + 1; -#endif // USE_RTC6705 } void cmsx_FeatureWriteback(void) { - if (featureBlackbox) - featureSet(FEATURE_BLACKBOX); - else - featureClear(FEATURE_BLACKBOX); + cmsx_Blackbox_FeatureWriteback(); #ifdef LED_STRIP - if (featureLedstrip) - featureSet(FEATURE_LED_STRIP); - else - featureClear(FEATURE_LED_STRIP); + cmsx_Ledstrip_FeatureWriteback(); #endif #if defined(VTX) || defined(USE_RTC6705) - if (featureVtx) - featureSet(FEATURE_VTX); - else - featureClear(FEATURE_VTX); + cmsx_Vtx_FeatureWriteback(); + cmsx_Vtx_ConfigWriteback(); #endif // VTX || USE_RTC6705 -#ifdef VTX - masterConfig.vtxBand = vtxBand; - masterConfig.vtx_channel = vtxChannel - 1; -#endif // VTX - -#ifdef USE_RTC6705 - masterConfig.vtx_channel = vtxBand * 8 + vtxChannel - 1; -#endif // USE_RTC6705 - saveConfigAndNotify(); } - #endif // CMS diff --git a/src/main/io/cms.h b/src/main/io/cms.h index bef66c62e2..a7d0d21e08 100644 --- a/src/main/io/cms.h +++ b/src/main/io/cms.h @@ -32,9 +32,12 @@ void cmsInit(void); void cmsHandler(uint32_t currentTime); // Required for external CMS tables +void cmsScreenClear(displayPort_t *pPort); +void cmsScreenResync(displayPort_t *pPort); +int cmsScreenWrite(displayPort_t *pPort, uint8_t x, uint8_t y, char *s); -long cmsChangeScreen(displayPort_t *pPort, void *ptr); -long cmsExitMenu(displayPort_t *pPort, void *ptr); +long cmsMenuChange(displayPort_t *pPort, void *ptr); +long cmsMenuExit(displayPort_t *pPort, void *ptr); #define CMS_STARTUP_HELP_TEXT1 "MENU: THR MID" #define CMS_STARTUP_HELP_TEXT2 "+ YAW LEFT" diff --git a/src/main/io/cms_blackbox.c b/src/main/io/cms_blackbox.c new file mode 100644 index 0000000000..3f118f87ee --- /dev/null +++ b/src/main/io/cms_blackbox.c @@ -0,0 +1,77 @@ +// +// CMS things for blackbox and flashfs. +// Should be part of blackbox.c (or new blackbox/blackbox_cms.c) and io/flashfs.c +// +#include +#include +#include +#include + +#include "platform.h" + +#include "build/version.h" + +#ifdef CMS + +#include "drivers/system.h" + +#include "config/config_profile.h" +#include "config/config_master.h" +#include "config/feature.h" + +#include "io/cms.h" +#include "io/cms_types.h" +#include "io/cms_blackbox.h" + +#include "io/flashfs.h" + +#ifdef USE_FLASHFS +long cmsx_EraseFlash(displayPort_t *pDisplay, void *ptr) +{ + UNUSED(ptr); + + cmsScreenClear(pDisplay); + cmsScreenWrite(pDisplay, 5, 3, "ERASING FLASH..."); + cmsScreenResync(pDisplay); // Was max7456RefreshAll(); Why at this timing? + + flashfsEraseCompletely(); + while (!flashfsIsReady()) { + delay(100); + } + + cmsScreenClear(pDisplay); + cmsScreenResync(pDisplay); // Was max7456RefreshAll(); wedges during heavy SPI? + + return 0; +} +#endif // USE_FLASHFS + +uint8_t cmsx_FeatureBlackbox; + +OSD_UINT8_t entryBlackboxRateDenom = {&masterConfig.blackbox_rate_denom,1,32,1}; + +OSD_Entry cmsx_menuBlackbox[] = +{ + {"--- BLACKBOX ---", OME_Label, NULL, NULL, 0}, + {"ENABLED", OME_Bool, NULL, &cmsx_FeatureBlackbox, 0}, + {"RATE DENOM", OME_UINT8, NULL, &entryBlackboxRateDenom, 0}, +#ifdef USE_FLASHFS + {"ERASE FLASH", OME_Submenu, cmsx_EraseFlash, NULL, 0}, +#endif // USE_FLASHFS + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +void cmsx_Blackbox_FeatureRead(void) +{ + cmsx_FeatureBlackbox = feature(FEATURE_BLACKBOX) ? 1 : 0; +} + +void cmsx_Blackbox_FeatureWriteback(void) +{ + if (cmsx_FeatureBlackbox) + featureSet(FEATURE_BLACKBOX); + else + featureClear(FEATURE_BLACKBOX); +} +#endif diff --git a/src/main/io/cms_blackbox.h b/src/main/io/cms_blackbox.h new file mode 100644 index 0000000000..6e7d02eff2 --- /dev/null +++ b/src/main/io/cms_blackbox.h @@ -0,0 +1,4 @@ +extern OSD_Entry cmsx_menuBlackbox[]; + +void cmsx_Blackbox_FeatureRead(void); +void cmsx_Blackbox_FeatureWriteback(void); diff --git a/src/main/io/cms_imu.c b/src/main/io/cms_imu.c new file mode 100644 index 0000000000..9428d993d6 --- /dev/null +++ b/src/main/io/cms_imu.c @@ -0,0 +1,206 @@ + +// Menu contents for PID, RATES, RC preview, misc +// Should be part of the relevant .c file. + +#include +#include +#include +#include + +#include "platform.h" + +#include "build/version.h" + +#ifdef CMS + +#include "drivers/system.h" + +//#include "common/typeconversion.h" + +#include "io/cms.h" +#include "io/cms_types.h" +#include "io/cms_imu.h" + +#include "fc/config.h" +#include "fc/rc_controls.h" +#include "fc/runtime_config.h" + +#include "flight/pid.h" + +#include "config/config_profile.h" +#include "config/config_master.h" +#include "config/feature.h" + +OSD_UINT8_t entryPidProfile = {&masterConfig.current_profile_index, 0, MAX_PROFILE_COUNT, 1}; + +uint8_t tempPid[4][3]; + +static OSD_UINT8_t entryRollP = {&tempPid[PIDROLL][0], 10, 150, 1}; +static OSD_UINT8_t entryRollI = {&tempPid[PIDROLL][1], 1, 150, 1}; +static OSD_UINT8_t entryRollD = {&tempPid[PIDROLL][2], 0, 150, 1}; + +static OSD_UINT8_t entryPitchP = {&tempPid[PIDPITCH][0], 10, 150, 1}; +static OSD_UINT8_t entryPitchI = {&tempPid[PIDPITCH][1], 1, 150, 1}; +static OSD_UINT8_t entryPitchD = {&tempPid[PIDPITCH][2], 0, 150, 1}; + +static OSD_UINT8_t entryYawP = {&tempPid[PIDYAW][0], 10, 150, 1}; +static OSD_UINT8_t entryYawI = {&tempPid[PIDYAW][1], 1, 150, 1}; +static OSD_UINT8_t entryYawD = {&tempPid[PIDYAW][2], 0, 150, 1}; + +void cmsx_PidRead(void) +{ + uint8_t i; + + for (i = 0; i < 3; i++) { + tempPid[i][0] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[i]; + tempPid[i][1] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[i]; + tempPid[i][2] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[i]; + } + tempPid[3][0] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[PIDLEVEL]; + tempPid[3][1] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[PIDLEVEL]; + tempPid[3][2] = masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[PIDLEVEL]; +} + +void cmsx_PidWriteback(void) +{ + uint8_t i; + + for (i = 0; i < 3; i++) { + masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[i] = tempPid[i][0]; + masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[i] = tempPid[i][1]; + masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[i] = tempPid[i][2]; + } + + masterConfig.profile[masterConfig.current_profile_index].pidProfile.P8[PIDLEVEL] = tempPid[3][0]; + masterConfig.profile[masterConfig.current_profile_index].pidProfile.I8[PIDLEVEL] = tempPid[3][1]; + masterConfig.profile[masterConfig.current_profile_index].pidProfile.D8[PIDLEVEL] = tempPid[3][2]; +} + +OSD_Entry cmsx_menuPid[] = +{ + {"--- PID ---", OME_Label, NULL, NULL, 0}, + {"ROLL P", OME_UINT8, NULL, &entryRollP, 0}, + {"ROLL I", OME_UINT8, NULL, &entryRollI, 0}, + {"ROLL D", OME_UINT8, NULL, &entryRollD, 0}, + + {"PITCH P", OME_UINT8, NULL, &entryPitchP, 0}, + {"PITCH I", OME_UINT8, NULL, &entryPitchI, 0}, + {"PITCH D", OME_UINT8, NULL, &entryPitchD, 0}, + + {"YAW P", OME_UINT8, NULL, &entryYawP, 0}, + {"YAW I", OME_UINT8, NULL, &entryYawI, 0}, + {"YAW D", OME_UINT8, NULL, &entryYawD, 0}, + + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +// +// Rate & Expo +// +controlRateConfig_t rateProfile; + +static OSD_FLOAT_t entryRollRate = {&rateProfile.rates[0], 0, 250, 1, 10}; +static OSD_FLOAT_t entryPitchRate = {&rateProfile.rates[1], 0, 250, 1, 10}; +static OSD_FLOAT_t entryYawRate = {&rateProfile.rates[2], 0, 250, 1, 10}; +static OSD_FLOAT_t entryRcRate = {&rateProfile.rcRate8, 0, 200, 1, 10}; +static OSD_FLOAT_t entryRcYawRate = {&rateProfile.rcYawRate8, 0, 200, 1, 10}; +static OSD_FLOAT_t entryRcExpo = {&rateProfile.rcExpo8, 0, 100, 1, 10}; +static OSD_FLOAT_t entryRcExpoYaw = {&rateProfile.rcYawExpo8, 0, 100, 1, 10}; +static OSD_FLOAT_t extryTpaEntry = {&rateProfile.dynThrPID, 0, 70, 1, 10}; +static OSD_UINT16_t entryTpaBreak = {&rateProfile.tpa_breakpoint, 1100, 1800, 10}; +static OSD_FLOAT_t entryPSetpoint = {&masterConfig.profile[0].pidProfile.setpointRelaxRatio, 0, 100, 1, 10}; +static OSD_FLOAT_t entryDSetpoint = {&masterConfig.profile[0].pidProfile.dtermSetpointWeight, 0, 255, 1, 10}; + +void cmsx_RateExpoRead() +{ + memcpy(&rateProfile, &masterConfig.profile[masterConfig.current_profile_index].controlRateProfile[masterConfig.profile[masterConfig.current_profile_index].activeRateProfile], sizeof(controlRateConfig_t)); +} + +void cmsx_RateExpoWriteback() +{ + memcpy(&masterConfig.profile[masterConfig.current_profile_index].controlRateProfile[masterConfig.profile[masterConfig.current_profile_index].activeRateProfile], &rateProfile, sizeof(controlRateConfig_t)); +} + +OSD_Entry cmsx_menuRateExpo[] = +{ + {"--- RATE&EXPO ---", OME_Label, NULL, NULL, 0}, + {"RC RATE", OME_FLOAT, NULL, &entryRcYawRate, 0}, + {"RC YAW RATE", OME_FLOAT, NULL, &entryRcRate, 0}, + {"ROLL SUPER", OME_FLOAT, NULL, &entryRollRate, 0}, + {"PITCH SUPER", OME_FLOAT, NULL, &entryPitchRate, 0}, + {"YAW SUPER", OME_FLOAT, NULL, &entryYawRate, 0}, + {"RC EXPO", OME_FLOAT, NULL, &entryRcExpo, 0}, + {"RC YAW EXPO", OME_FLOAT, NULL, &entryRcExpoYaw, 0}, + {"THR PID ATT", OME_FLOAT, NULL, &extryTpaEntry, 0}, + {"TPA BRKPT", OME_UINT16, NULL, &entryTpaBreak, 0}, + {"D SETPT", OME_FLOAT, NULL, &entryDSetpoint, 0}, + {"D SETPT TRN", OME_FLOAT, NULL, &entryPSetpoint, 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +// +// RC preview +// +static OSD_INT16_t entryRcRoll = {&rcData[ROLL], 1, 2500, 0}; +static OSD_INT16_t entryRcPitch = {&rcData[PITCH], 1, 2500, 0}; +static OSD_INT16_t entryRcThr = {&rcData[THROTTLE], 1, 2500, 0}; +static OSD_INT16_t entryRcYaw = {&rcData[YAW], 1, 2500, 0}; +static OSD_INT16_t entryRcAux1 = {&rcData[AUX1], 1, 2500, 0}; +static OSD_INT16_t entryRcAux2 = {&rcData[AUX2], 1, 2500, 0}; +static OSD_INT16_t entryRcAux3 = {&rcData[AUX3], 1, 2500, 0}; +static OSD_INT16_t entryRcAux4 = {&rcData[AUX4], 1, 2500, 0}; + +OSD_Entry cmsx_menuRc[] = +{ + {"--- RC PREV ---", OME_Label, NULL, NULL, 0}, + {"ROLL", OME_Poll_INT16, NULL, &entryRcRoll, 0}, + {"PITCH", OME_Poll_INT16, NULL, &entryRcPitch, 0}, + {"THR", OME_Poll_INT16, NULL, &entryRcThr, 0}, + {"YAW", OME_Poll_INT16, NULL, &entryRcYaw, 0}, + {"AUX1", OME_Poll_INT16, NULL, &entryRcAux1, 0}, + {"AUX2", OME_Poll_INT16, NULL, &entryRcAux2, 0}, + {"AUX3", OME_Poll_INT16, NULL, &entryRcAux3, 0}, + {"AUX4", OME_Poll_INT16, NULL, &entryRcAux4, 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +// +// Misc +// +OSD_UINT16_t entryMinThrottle = {&masterConfig.motorConfig.minthrottle, 1020, 1300, 10}; +OSD_UINT8_t entryGyroSoftLpfHz = {&masterConfig.gyro_soft_lpf_hz, 0, 255, 1}; +OSD_UINT16_t entryDtermLpf = {&masterConfig.profile[0].pidProfile.dterm_lpf_hz, 0, 500, 5}; +OSD_UINT16_t entryYawLpf = {&masterConfig.profile[0].pidProfile.yaw_lpf_hz, 0, 500, 5}; +OSD_UINT16_t entryYawPLimit = {&masterConfig.profile[0].pidProfile.yaw_p_limit, 100, 500, 5}; +OSD_UINT8_t entryVbatScale = {&masterConfig.batteryConfig.vbatscale, 1, 250, 1}; +OSD_UINT8_t entryVbatMaxCell = {&masterConfig.batteryConfig.vbatmaxcellvoltage, 10, 50, 1}; + +OSD_Entry menuImuMisc[]= +{ + {"--- MISC ---", OME_Label, NULL, NULL, 0}, + {"GYRO LPF", OME_UINT8, NULL, &entryGyroSoftLpfHz, 0}, + {"DTERM LPF", OME_UINT16, NULL, &entryDtermLpf, 0}, + {"YAW LPF", OME_UINT16, NULL, &entryYawLpf, 0}, + {"YAW P LIM", OME_UINT16, NULL, &entryYawPLimit, 0}, + {"MIN THR", OME_UINT16, NULL, &entryMinThrottle, 0}, + {"VBAT SCALE", OME_UINT8, NULL, &entryVbatScale, 0}, + {"VBAT CLMAX", OME_UINT8, NULL, &entryVbatMaxCell, 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +OSD_Entry cmsx_menuImu[] = +{ + {"--- CFG.IMU ---", OME_Label, NULL, NULL, 0}, + {"PID PROF", OME_UINT8, NULL, &entryPidProfile, 0}, + {"PID", OME_Submenu, cmsMenuChange, cmsx_menuPid, 0}, + {"RATE&RXPO", OME_Submenu, cmsMenuChange, cmsx_menuRateExpo, 0}, + {"RC PREV", OME_Submenu, cmsMenuChange, cmsx_menuRc, 0}, + {"MISC", OME_Submenu, cmsMenuChange, menuImuMisc, 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; +#endif // CMS diff --git a/src/main/io/cms_imu.h b/src/main/io/cms_imu.h new file mode 100644 index 0000000000..b78c6ddb4b --- /dev/null +++ b/src/main/io/cms_imu.h @@ -0,0 +1,13 @@ +extern OSD_Entry cmsx_menuImu[]; + +// All of below should be gone. + +extern OSD_Entry cmsx_menuPid[]; +extern OSD_Entry cmsx_menuRc[]; +extern OSD_Entry cmsx_menuRateExpo[]; + +void cmsx_PidRead(void); +void cmsx_PidWriteback(void); +void cmsx_RateExpoRead(void); +void cmsx_RateExpoWriteback(void); + diff --git a/src/main/io/cms_ledstrip.c b/src/main/io/cms_ledstrip.c new file mode 100644 index 0000000000..63e15d74e6 --- /dev/null +++ b/src/main/io/cms_ledstrip.c @@ -0,0 +1,107 @@ +#include +#include +#include +#include + +#include "platform.h" + +#include "build/version.h" + +#ifdef CMS + +#include "drivers/system.h" + +#include "config/config_profile.h" +#include "config/config_master.h" +#include "config/feature.h" + +#include "io/cms.h" +#include "io/cms_types.h" +#include "io/cms_blackbox.h" + +#ifdef LED_STRIP + +//local variable to keep color value +uint8_t ledColor; + +static const char * const LED_COLOR_NAMES[] = { + "BLACK ", + "WHITE ", + "RED ", + "ORANGE ", + "YELLOW ", + "LIME GRN", + "GREEN ", + "MINT GRN", + "CYAN ", + "LT BLUE ", + "BLUE ", + "DK VIOLT", + "MAGENTA ", + "DEEP PNK" +}; + +//find first led with color flag and restore color index +//after saving all leds with flags color will have color set in OSD +void cmsx_GetLedColor(void) +{ + for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) { + const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex]; + + int fn = ledGetFunction(ledConfig); + + if (fn == LED_FUNCTION_COLOR) { + ledColor = ledGetColor(ledConfig); + break; + } + } +} + +//udate all leds with flag color +static long applyLedColor(displayPort_t *pDisplay, void *ptr) +{ + UNUSED(ptr); + UNUSED(pDisplay); // Arrgh + + for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) { + ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex]; + if (ledGetFunction(ledConfig) == LED_FUNCTION_COLOR) + *ledConfig = DEFINE_LED(ledGetX(ledConfig), ledGetY(ledConfig), ledColor, ledGetDirection(ledConfig), ledGetFunction(ledConfig), ledGetOverlay(ledConfig), 0); + } + + return 0; +} + +uint8_t cmsx_FeatureLedstrip; + +OSD_TAB_t entryLed = {&ledColor, 13, &LED_COLOR_NAMES[0]}; + +OSD_Entry cmsx_menuLedstrip[] = +{ + {"--- LED STRIP ---", OME_Label, NULL, NULL, 0}, + {"ENABLED", OME_Bool, NULL, &cmsx_FeatureLedstrip, 0}, + {"LED COLOR", OME_TAB, applyLedColor, &entryLed, 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +void cmsx_Ledstrip_FeatureRead(void) +{ + cmsx_FeatureLedstrip = feature(FEATURE_LED_STRIP) ? 1 : 0; +} + +void cmsx_Ledstrip_FeatureWriteback(void) +{ + if (cmsx_FeatureLedstrip) + featureSet(FEATURE_LED_STRIP); + else + featureClear(FEATURE_LED_STRIP); +} + +void cmsx_Ledstrip_ConfigRead(void) +{ + cmsx_GetLedColor(); +} + +#endif // LED_STRIP +#endif // CMS diff --git a/src/main/io/cms_ledstrip.h b/src/main/io/cms_ledstrip.h new file mode 100644 index 0000000000..1ce1d5009f --- /dev/null +++ b/src/main/io/cms_ledstrip.h @@ -0,0 +1,6 @@ +extern OSD_Entry cmsx_menuLedstrip[]; + +void cmsx_Ledstrip_FeatureRead(void); +void cmsx_Ledstrip_FeatureWriteback(void); + +void cmsx_Ledstrip_ConfigRead(void); diff --git a/src/main/io/cms_osd.h b/src/main/io/cms_osd.h new file mode 100644 index 0000000000..5c93a65215 --- /dev/null +++ b/src/main/io/cms_osd.h @@ -0,0 +1,2 @@ +extern OSD_Entry cmsx_menuAlarms[]; +extern OSD_Entry cmsx_menuOsdLayout[]; diff --git a/src/main/io/cms_vtx.c b/src/main/io/cms_vtx.c new file mode 100644 index 0000000000..61e0af60d0 --- /dev/null +++ b/src/main/io/cms_vtx.c @@ -0,0 +1,96 @@ +#include +#include +#include + +#include "platform.h" + +#include "build/version.h" + +#include "io/cms.h" +#include "io/cms_types.h" +#include "io/cms_vtx.h" + +#include "config/config_profile.h" +#include "config/config_master.h" +#include "config/feature.h" + +#ifdef CMS + +#if defined(VTX) || defined(USE_RTC6705) + +uint8_t cmsx_featureVtx = 0, cmsx_vtxBand, cmsx_vtxChannel; + +static const char * const vtxBandNames[] = { + "BOSCAM A", + "BOSCAM B", + "BOSCAM E", + "FATSHARK", + "RACEBAND", +}; + +OSD_TAB_t entryVtxBand = {&cmsx_vtxBand,4,&vtxBandNames[0]}; +OSD_UINT8_t entryVtxChannel = {&cmsx_vtxChannel, 1, 8, 1}; + +#ifdef VTX +OSD_UINT8_t entryVtxMode = {&masterConfig.vtx_mode, 0, 2, 1}; +OSD_UINT16_t entryVtxMhz = {&masterConfig.vtx_mhz, 5600, 5950, 1}; +#endif // VTX + +OSD_Entry cmsx_menuVtx[] = +{ + {"--- VTX ---", OME_Label, NULL, NULL, 0}, + {"ENABLED", OME_Bool, NULL, &featureVtx, 0}, +#ifdef VTX + {"VTX MODE", OME_UINT8, NULL, &entryVtxMode, 0}, + {"VTX MHZ", OME_UINT16, NULL, &entryVtxMhz, 0}, +#endif // VTX + {"BAND", OME_TAB, NULL, &entryVtxBand, 0}, + {"CHANNEL", OME_UINT8, NULL, &entryVtxChannel, 0}, +#ifdef USE_RTC6705 + {"LOW POWER", OME_Bool, NULL, &masterConfig.vtx_power, 0}, +#endif // USE_RTC6705 + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +void cmsx_Vtx_FeatureRead(void) +{ + cmsx_featureVtx = feature(FEATURE_VTX) ? 1 : 0; +} + +void cmsx_Vtx_FeatureWriteback(void) +{ + if (cmsx_featureVtx) + featureSet(FEATURE_VTX); + else + featureClear(FEATURE_VTX); +} + +void cmsx_Vtx_ConfigRead(void) +{ +#ifdef VTX + cmsx_vtxBand = masterConfig.vtxBand; + cmsx_vtxChannel = masterConfig.vtx_channel + 1; +#endif // VTX + +#ifdef USE_RTC6705 + cmsx_vtxBand = masterConfig.vtx_channel / 8; + cmsx_vtxChannel = masterConfig.vtx_channel % 8 + 1; +#endif // USE_RTC6705 +} + +void cmsx_Vtx_ConfigRead(void) +{ +#ifdef VTX + masterConfig.vtxBand = cmsx_vtxBand; + masterConfig.vtx_channel = cmsx_vtxChannel - 1; +#endif // VTX + +#ifdef USE_RTC6705 + masterConfig.vtx_channel = cmsx_vtxBand * 8 + cmsx_vtxChannel - 1; +#endif // USE_RTC6705 +} + +#endif // VTX || USE_RTC6705 + +#endif // CMS diff --git a/src/main/io/cms_vtx.h b/src/main/io/cms_vtx.h new file mode 100644 index 0000000000..412a9e4f73 --- /dev/null +++ b/src/main/io/cms_vtx.h @@ -0,0 +1,7 @@ +extern OSD_Entry cmsx_menuVtx[]; + +void cmsx_Vtx_FeatureRead(void); +void cmsx_Vtx_FeatureWriteback(void); + +void cmsx_Vtx_ConfigRead(void); +void cmsx_Vtx_ConfigWriteback(void); diff --git a/src/main/io/osd.c b/src/main/io/osd.c index e105a6f07c..c271d4339f 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -636,6 +636,7 @@ void osdUpdate(uint32_t currentTime) // // OSD specific CMS functions // +#include "io/cms_osd.h" uint8_t shiftdown; @@ -727,4 +728,55 @@ void osdCmsInit(displayPort_t *pPort) osdResync(pPort); pPort->vTable = &osdVTable; } + +OSD_UINT8_t entryAlarmRssi = {&masterConfig.osdProfile.rssi_alarm, 5, 90, 5}; +OSD_UINT16_t entryAlarmCapacity = {&masterConfig.osdProfile.cap_alarm, 50, 30000, 50}; +OSD_UINT16_t enryAlarmFlyTime = {&masterConfig.osdProfile.time_alarm, 1, 200, 1}; +OSD_UINT16_t entryAlarmAltitude = {&masterConfig.osdProfile.alt_alarm, 1, 200, 1}; + +OSD_Entry cmsx_menuAlarms[] = +{ + {"--- ALARMS ---", OME_Label, NULL, NULL, 0}, + {"RSSI", OME_UINT8, NULL, &entryAlarmRssi, 0}, + {"MAIN BAT", OME_UINT16, NULL, &entryAlarmCapacity, 0}, + {"FLY TIME", OME_UINT16, NULL, &enryAlarmFlyTime, 0}, + {"MAX ALT", OME_UINT16, NULL, &entryAlarmAltitude, 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +OSD_Entry menuOsdActiveElems[] = +{ + {"--- ACTIV ELEM ---", OME_Label, NULL, NULL, 0}, + {"RSSI", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_RSSI_VALUE], 0}, + {"MAIN BATTERY", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_MAIN_BATT_VOLTAGE], 0}, + {"HORIZON", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_ARTIFICIAL_HORIZON], 0}, + {"HORIZON SIDEBARS", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_HORIZON_SIDEBARS], 0}, + {"UPTIME", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_ONTIME], 0}, + {"FLY TIME", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_FLYTIME], 0}, + {"FLY MODE", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_FLYMODE], 0}, + {"NAME", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_CRAFT_NAME], 0}, + {"THROTTLE", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_THROTTLE_POS], 0}, +#ifdef VTX + {"VTX CHAN", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_VTX_CHANNEL]}, +#endif // VTX + {"CURRENT (A)", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_CURRENT_DRAW], 0}, + {"USED MAH", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_MAH_DRAWN], 0}, +#ifdef GPS + {"GPS SPEED", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_GPS_SPEED], 0}, + {"GPS SATS.", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_GPS_SATS], 0}, +#endif // GPS + {"ALTITUDE", OME_VISIBLE, NULL, &masterConfig.osdProfile.item_pos[OSD_ALTITUDE], 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + +OSD_Entry cmsx_menuOsdLayout[] = +{ + {"---SCREEN LAYOUT---", OME_Label, NULL, NULL, 0}, + {"ACTIVE ELEM.", OME_Submenu, cmsMenuChange, &menuOsdActiveElems[0], 0}, + {"BACK", OME_Back, NULL, NULL, 0}, + {NULL, OME_END, NULL, NULL, 0} +}; + #endif // OSD diff --git a/src/main/target/OMNIBUS/target.mk b/src/main/target/OMNIBUS/target.mk index 4ec2d2df37..5a7e1a2382 100644 --- a/src/main/target/OMNIBUS/target.mk +++ b/src/main/target/OMNIBUS/target.mk @@ -15,5 +15,9 @@ TARGET_SRC = \ io/transponder_ir.c \ drivers/max7456.c \ io/osd.c \ + io/canvas.c \ io/cms.c \ - io/canvas.c + io/cms_imu.c \ + io/cms_blackbox.c \ + io/cms_vtx.c \ + io/cms_ledstrip.c diff --git a/src/main/target/SIRINFPV/target.mk b/src/main/target/SIRINFPV/target.mk index 6481f94182..e64c9781b3 100644 --- a/src/main/target/SIRINFPV/target.mk +++ b/src/main/target/SIRINFPV/target.mk @@ -13,5 +13,9 @@ TARGET_SRC = \ drivers/vtx_soft_spi_rtc6705.c \ drivers/max7456.c \ io/osd.c \ + io/canvas.c \ io/cms.c \ - io/canvas.c + io/cms_imu.c \ + io/cms_blackbox.c \ + io/cms_vtx.c \ + io/cms_ledstrip.c diff --git a/src/main/target/SPRACINGF3/target.mk b/src/main/target/SPRACINGF3/target.mk index dd7702375e..f2a3df7442 100644 --- a/src/main/target/SPRACINGF3/target.mk +++ b/src/main/target/SPRACINGF3/target.mk @@ -9,6 +9,10 @@ TARGET_SRC = \ drivers/barometer_bmp280.c \ drivers/compass_ak8975.c \ drivers/compass_hmc5883l.c \ + io/canvas.c \ io/cms.c \ - io/canvas.c + io/cms_imu.c \ + io/cms_blackbox.c \ + io/cms_vtx.c \ + io/cms_ledstrip.c diff --git a/src/main/target/STM32F3DISCOVERY/target.mk b/src/main/target/STM32F3DISCOVERY/target.mk index 6b718b5b0a..4142776c47 100644 --- a/src/main/target/STM32F3DISCOVERY/target.mk +++ b/src/main/target/STM32F3DISCOVERY/target.mk @@ -27,4 +27,10 @@ TARGET_SRC = \ drivers/flash_m25p16.c \ drivers/max7456.c \ io/osd.c \ - io/cms.c + io/canvas.c \ + io/cms.c \ + io/cms_imu.c \ + io/cms_blackbox.c \ + io/cms_vtx.c \ + io/cms_ledstrip.c +