3 #if defined(GPIO_PIN_BUTTON)
10 #ifndef GPIO_BUTTON_INVERTED
11 #define GPIO_BUTTON_INVERTED false
13 #ifndef GPIO_BUTTON2_INVERTED
14 #define GPIO_BUTTON2_INVERTED false
16 #if !defined(GPIO_PIN_BUTTON2)
17 #define GPIO_PIN_BUTTON2 UNDEF_PIN
20 static Button button1
;
21 #if defined(GPIO_PIN_BUTTON2)
22 static Button button2
;
25 // only check every second if the device is in-use, i.e. RX connected, or TX is armed
26 static constexpr int MS_IN_USE
= 1000;
28 #if defined(TARGET_RX)
29 static constexpr struct {
33 } button_actions
[] = {
34 // half second durations + 1 (i.e. 2=1.5s)
35 {true, 2, ACTION_BIND
}, // 1.5s
36 {true, 9, ACTION_START_WIFI
}, // 5.0s
37 {true, 23, ACTION_RESET_REBOOT
} // 12.0s
41 static ButtonAction_fn actions
[ACTION_LAST
] = { nullptr };
43 void registerButtonFunction(action_e action
, ButtonAction_fn function
)
45 actions
[action
] = function
;
48 size_t button_GetActionCnt()
50 #if defined(TARGET_RX)
51 return ARRAY_SIZE(button_actions
);
53 return CONFIG_TX_BUTTON_ACTION_CNT
;
57 static void handlePress(uint8_t button
, bool longPress
, uint8_t count
)
59 DBGLN("handlePress(%u, %u, %u)", button
, (uint8_t)longPress
, count
);
60 #if defined(TARGET_TX)
61 const button_action_t
*button_actions
= config
.GetButtonActions(button
)->val
.actions
;
63 for (unsigned i
=0 ; i
<button_GetActionCnt() ; i
++)
65 if (button_actions
[i
].action
!= ACTION_NONE
&& button_actions
[i
].pressType
== longPress
&& button_actions
[i
].count
== count
-1)
67 if (actions
[button_actions
[i
].action
])
69 actions
[button_actions
[i
].action
]();
77 if (GPIO_PIN_BUTTON
== UNDEF_PIN
)
79 return DURATION_NEVER
;
82 if (GPIO_PIN_BUTTON
!= UNDEF_PIN
)
84 button1
.init(GPIO_PIN_BUTTON
, GPIO_BUTTON_INVERTED
);
85 button1
.OnShortPress
= [](){ handlePress(0, false, button1
.getCount()); };
86 button1
.OnLongPress
= [](){ handlePress(0, true, button1
.getLongCount()+1); };
88 #if defined(TARGET_TX)
89 if (GPIO_PIN_BUTTON2
!= UNDEF_PIN
)
91 button2
.init(GPIO_PIN_BUTTON2
, GPIO_BUTTON_INVERTED
);
92 button2
.OnShortPress
= [](){ handlePress(1, false, button2
.getCount()); };
93 button2
.OnLongPress
= [](){ handlePress(1, true, button2
.getLongCount()+1); };
97 return DURATION_IMMEDIATELY
;
102 if (GPIO_PIN_BUTTON
== UNDEF_PIN
)
104 return DURATION_NEVER
;
106 #if defined(TARGET_TX)
107 if (handset
->IsArmed())
110 if (connectionState
== connected
)
114 #if defined(GPIO_PIN_BUTTON2)
115 if (GPIO_PIN_BUTTON2
!= UNDEF_PIN
)
120 return button1
.update();
123 device_t Button_device
= {
124 .initialize
= nullptr,