Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / src / main / cms / cms_menu_ledstrip.c
bloba0ad5dfda4222146d65b5a065ed27cec87ba4991
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include <ctype.h>
26 #include "platform.h"
28 #ifdef USE_CMS
30 #include "build/version.h"
32 #include "cli/settings.h"
34 #include "cms/cms.h"
35 #include "cms/cms_types.h"
37 #include "config/feature.h"
39 #include "config/config.h"
41 #include "io/ledstrip.h"
43 #include "pg/pg.h"
44 #include "pg/pg_ids.h"
46 #include "cms_menu_ledstrip.h"
48 #ifdef USE_LED_STRIP
50 static uint8_t cmsx_FeatureLedstrip;
51 static uint8_t cmsx_ledProfile;
52 static uint8_t cmsx_ledRaceColor;
53 static uint8_t cmsx_ledBeaconColor;
54 static uint16_t cmsx_ledBeaconPeriod;
55 static uint8_t cmsx_ledBeaconOnPercent;
56 static uint8_t cmsx_ledBeaconArmedOnly;
57 static uint8_t cmsx_ledVisualBeeper;
58 static uint8_t cmsx_ledVisualBeeperColor;
60 const char * const ledProfileNames[LED_PROFILE_COUNT] = {
61 "RACE",
62 "BEACON",
63 #ifdef USE_LED_STRIP_STATUS_MODE
64 "STATUS"
65 #endif
68 static const void *cmsx_Ledstrip_OnEnter(displayPort_t *pDisp)
70 UNUSED(pDisp);
72 cmsx_FeatureLedstrip = featureIsEnabled(FEATURE_LED_STRIP) ? 1 : 0;
73 cmsx_ledProfile = getLedProfile();
74 cmsx_ledRaceColor = ledStripConfig()->ledstrip_race_color;
75 cmsx_ledBeaconColor = ledStripConfig()->ledstrip_beacon_color;
76 cmsx_ledBeaconPeriod = ledStripConfig()->ledstrip_beacon_period_ms;
77 cmsx_ledBeaconOnPercent = ledStripConfig()->ledstrip_beacon_percent;
78 cmsx_ledBeaconArmedOnly = ledStripConfig()->ledstrip_beacon_armed_only;
79 cmsx_ledVisualBeeper = ledStripConfig()->ledstrip_visual_beeper;
80 cmsx_ledVisualBeeperColor = ledStripConfig()->ledstrip_visual_beeper_color;
82 return NULL;
85 static const void *cmsx_Ledstrip_OnExit(displayPort_t *pDisp, const OSD_Entry *self)
87 UNUSED(pDisp);
88 UNUSED(self);
90 if (cmsx_FeatureLedstrip) {
91 featureEnableImmediate(FEATURE_LED_STRIP);
92 ledStripEnable();
93 } else {
94 ledStripDisable();
95 featureDisableImmediate(FEATURE_LED_STRIP);
98 setLedProfile(cmsx_ledProfile);
99 ledStripConfigMutable()->ledstrip_race_color = cmsx_ledRaceColor;
100 ledStripConfigMutable()->ledstrip_beacon_color = cmsx_ledBeaconColor;
101 ledStripConfigMutable()->ledstrip_beacon_period_ms = cmsx_ledBeaconPeriod;
102 ledStripConfigMutable()->ledstrip_beacon_percent = cmsx_ledBeaconOnPercent;
103 ledStripConfigMutable()->ledstrip_beacon_armed_only = cmsx_ledBeaconArmedOnly;
104 ledStripConfigMutable()->ledstrip_visual_beeper = cmsx_ledVisualBeeper;
105 ledStripConfigMutable()->ledstrip_visual_beeper_color = cmsx_ledVisualBeeperColor;
107 return NULL;
110 static const OSD_Entry cmsx_menuLedstripEntries[] =
112 { "-- LED STRIP --", OME_Label, NULL, NULL },
113 { "ENABLED", OME_Bool, NULL, &cmsx_FeatureLedstrip },
114 { "PROFILE", OME_TAB, NULL, &(OSD_TAB_t){ &cmsx_ledProfile, LED_PROFILE_COUNT - 1, ledProfileNames } },
115 { "RACE COLOR", OME_TAB, NULL, &(OSD_TAB_t){ &cmsx_ledRaceColor, COLOR_COUNT - 1, lookupTableLedstripColors } },
116 { "BEACON COLOR", OME_TAB, NULL, &(OSD_TAB_t){ &cmsx_ledBeaconColor, COLOR_COUNT -1, lookupTableLedstripColors } },
117 { "BEACON PERIOD", OME_UINT16,NULL, &(OSD_UINT16_t){ &cmsx_ledBeaconPeriod, 50, 10000, 10 } },
118 { "BEACON ON %", OME_UINT8, NULL, &(OSD_UINT8_t){ &cmsx_ledBeaconOnPercent, 0, 100, 1 } },
119 { "BEACON ARMED ONLY",OME_Bool, NULL, &cmsx_ledBeaconArmedOnly },
120 { "VISUAL BEEPER", OME_Bool, NULL, &cmsx_ledVisualBeeper },
121 { "VISUAL COLOR", OME_TAB, NULL, &(OSD_TAB_t){ &cmsx_ledVisualBeeperColor, COLOR_COUNT - 1, lookupTableLedstripColors } },
122 { "BACK", OME_Back, NULL, NULL },
123 { NULL, OME_END, NULL, NULL}
126 CMS_Menu cmsx_menuLedstrip = {
127 #ifdef CMS_MENU_DEBUG
128 .GUARD_text = "MENULED",
129 .GUARD_type = OME_MENU,
130 #endif
131 .onEnter = cmsx_Ledstrip_OnEnter,
132 .onExit = cmsx_Ledstrip_OnExit,
133 .onDisplayUpdate = NULL,
134 .entries = cmsx_menuLedstripEntries
136 #endif // LED_STRIP
137 #endif // CMS