10 static Button button2
;
12 // only check every second if the device is in-use, i.e. RX connected, or TX is armed
13 static constexpr int MS_IN_USE
= 1000;
15 #if defined(TARGET_RX)
16 static constexpr struct {
20 } button_actions
[] = {
21 // half second durations + 1 (i.e. 2=1.5s)
22 {true, 2, ACTION_BIND
}, // 1.5s
23 {true, 9, ACTION_START_WIFI
}, // 5.0s
24 {true, 23, ACTION_RESET_REBOOT
} // 12.0s
28 static ButtonAction_fn actions
[ACTION_LAST
] = { nullptr };
30 void registerButtonFunction(action_e action
, ButtonAction_fn function
)
32 actions
[action
] = function
;
35 size_t button_GetActionCnt()
37 #if defined(TARGET_RX)
38 return ARRAY_SIZE(button_actions
);
40 return CONFIG_TX_BUTTON_ACTION_CNT
;
44 static void handlePress(uint8_t button
, bool longPress
, uint8_t count
)
46 DBGLN("handlePress(%u, %u, %u)", button
, (uint8_t)longPress
, count
);
47 #if defined(TARGET_TX)
48 const button_action_t
*button_actions
= config
.GetButtonActions(button
)->val
.actions
;
50 for (unsigned i
=0 ; i
<button_GetActionCnt() ; i
++)
52 if (button_actions
[i
].action
!= ACTION_NONE
&& button_actions
[i
].pressType
== longPress
&& button_actions
[i
].count
== count
-1)
54 if (actions
[button_actions
[i
].action
])
56 actions
[button_actions
[i
].action
]();
64 if (GPIO_PIN_BUTTON
== UNDEF_PIN
&& GPIO_PIN_BUTTON2
== UNDEF_PIN
)
66 return DURATION_NEVER
;
69 if (GPIO_PIN_BUTTON
!= UNDEF_PIN
)
71 button1
.init(GPIO_PIN_BUTTON
);
72 button1
.OnShortPress
= [](){ handlePress(0, false, button1
.getCount()); };
73 button1
.OnLongPress
= [](){ handlePress(0, true, button1
.getLongCount()+1); };
75 if (GPIO_PIN_BUTTON2
!= UNDEF_PIN
)
77 button2
.init(GPIO_PIN_BUTTON2
);
78 button2
.OnShortPress
= [](){ handlePress(1, false, button2
.getCount()); };
79 button2
.OnLongPress
= [](){ handlePress(1, true, button2
.getLongCount()+1); };
82 return DURATION_IMMEDIATELY
;
87 if (GPIO_PIN_BUTTON
== UNDEF_PIN
&& GPIO_PIN_BUTTON2
== UNDEF_PIN
)
89 return DURATION_NEVER
;
91 #if defined(TARGET_TX)
92 if (handset
->IsArmed())
94 return DURATION_NEVER
;
97 if (connectionState
== connected
)
99 return DURATION_NEVER
;
102 return DURATION_IMMEDIATELY
;
107 int timeout
= DURATION_NEVER
;
108 if (GPIO_PIN_BUTTON
!= UNDEF_PIN
)
110 timeout
= button1
.update();
112 if (GPIO_PIN_BUTTON2
!= UNDEF_PIN
)
114 timeout
= button2
.update();
119 device_t Button_device
= {
120 .initialize
= nullptr,