Merge pull request #10485 from iNavFlight/mmosca-patch-5
[inav.git] / src / main / common / tristate.h
bloba54f6c00c58f27725f94e228e8344576917b9073
1 /*
2 * This file is part of INAV.
4 * INAV is free software. You can redistribute this software
5 * 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 * INAV is distributed in the hope that they will be
11 * 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 #pragma once
23 #include <stdbool.h>
25 // tristate_e represents something that can take a default AUTO
26 // value and two explicit ON and OFF values. To ease the transition
27 // from boolean settings (0 = OFF, 1 = ON), the 1 value has
28 // been picked as ON while OFF is represented by 2. AUTO is represented
29 // by 0.
30 typedef enum {
31 TRISTATE_AUTO = 0,
32 TRISTATE_ON = 1,
33 TRISTATE_OFF = 2,
34 } tristate_e;
36 // tristateWithDefaultOnIsActive returns false is tristate is TRISTATE_OFF
37 // and true otherwise.
38 static inline bool tristateWithDefaultOnIsActive(tristate_e tristate)
40 return tristate != TRISTATE_OFF;
43 // tristateWithDefaultOffIsActive returns true is tristate is TRISTATE_ON
44 // and false otherwise.
45 static inline bool tristateWithDefaultOffIsActive(tristate_e tristate)
47 return tristate == TRISTATE_ON;
50 // tristateWithDefaultIsActive() calls tristateWithDefaultOnIsActive() when
51 // def is true, and tristateWithDefaultOffIsActive() otherwise.
52 // See tristateWithDefaultOnIsActive() and tristateWithDefaultOffIsActive()
53 static inline bool tristateWithDefaultIsActive(tristate_e tristate, bool def)
55 return def ? tristateWithDefaultOnIsActive(tristate) : tristateWithDefaultOffIsActive(tristate);