Merge pull request #1269 from pkendall64/crsf-max-output
[ExpressLRS.git] / src / lib / BUTTON / devButton.cpp
blob6948f3659d6aec4c5d595abe9184df689a71a698
1 #include "targets.h"
2 #include "common.h"
3 #include "device.h"
5 #if defined(GPIO_PIN_BUTTON) && (GPIO_PIN_BUTTON != UNDEF_PIN)
6 #include "logging.h"
7 #include "button.h"
9 static Button<GPIO_PIN_BUTTON, GPIO_BUTTON_INVERTED> button;
11 #if defined(TARGET_TX_BETAFPV_2400_V1) || defined(TARGET_TX_BETAFPV_900_V1) || defined(TARGET_TX_IFLIGHT)
12 #include "POWERMGNT.h"
13 void EnterBindingMode();
15 static void enterBindMode3Click()
17 if (button.getCount() == 3)
19 EnterBindingMode();
23 static void cyclePower()
25 // Only change power if we are running normally
26 if (connectionState < MODE_STATES)
28 PowerLevels_e curr = POWERMGNT::currPower();
29 if (curr == MaxPower)
31 POWERMGNT::setPower(MinPower);
33 else
35 POWERMGNT::incPower();
37 devicesTriggerEvent();
40 #endif
42 #if defined(TARGET_RX) && (defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266))
43 static void rxWebUpdateReboot()
45 if (button.getLongCount() > 4 && connectionState != wifiUpdate)
47 connectionState = wifiUpdate;
49 if (button.getLongCount() > 8)
51 ESP.restart();
54 #endif
56 static void initialize()
58 #if defined(TARGET_TX_BETAFPV_2400_V1) || defined(TARGET_TX_BETAFPV_900_V1) || defined(TARGET_TX_IFLIGHT)
59 button.OnShortPress = enterBindMode3Click;
60 button.OnLongPress = cyclePower;
61 #endif
62 #if defined(TARGET_RX) && (defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266))
63 button.OnLongPress = rxWebUpdateReboot;
64 #endif
67 static int start()
69 return DURATION_IMMEDIATELY;
72 static int timeout()
74 return button.update();
77 device_t Button_device = {
78 .initialize = initialize,
79 .start = start,
80 .event = NULL,
81 .timeout = timeout
84 #endif