|
@@ -9,31 +9,35 @@
|
|
|
|
|
|
using namespace kbf;
|
|
|
|
|
|
-const char *const TAG = "test_kbf::driver::Button";
|
|
|
+static const char *const TAG = "test_kbf::driver::Button";
|
|
|
static auto eventGroup = rtos::EventGroup();
|
|
|
+static int longPressCount;
|
|
|
|
|
|
TEST_CASE("Button driver", "[kbf_driver_button]") {
|
|
|
auto button = driver::Button(KBF_TEST_BUTTON_PIN, 2000);
|
|
|
|
|
|
- button.onPress = {[](driver::Button &button) {
|
|
|
+ button.onPress = {[](driver::Button &button) {
|
|
|
ESP_LOGI(TAG, "onPress");
|
|
|
TEST_ASSERT_EQUAL(KBF_TEST_BUTTON_PIN, button.pin);
|
|
|
}};
|
|
|
- button.onRelease = {[](driver::Button &button) {
|
|
|
+ button.onRelease = {[](driver::Button &button) {
|
|
|
ESP_LOGI(TAG, "onRelease");
|
|
|
TEST_ASSERT_EQUAL(KBF_TEST_BUTTON_PIN, button.pin);
|
|
|
}};
|
|
|
- button.onLongPress = {[](driver::Button &button) {
|
|
|
+ button.onLongPress = {[](driver::Button &button) {
|
|
|
ESP_LOGI(TAG, "onLongPress");
|
|
|
TEST_ASSERT_EQUAL(KBF_TEST_BUTTON_PIN, button.pin);
|
|
|
}};
|
|
|
+ longPressCount = 0;
|
|
|
button.onLongRelease = {[](driver::Button &button) {
|
|
|
ESP_LOGI(TAG, "onLongRelease");
|
|
|
TEST_ASSERT_EQUAL(KBF_TEST_BUTTON_PIN, button.pin);
|
|
|
- eventGroup.setBit(0);
|
|
|
+ if (++longPressCount == 2) {
|
|
|
+ eventGroup.setBit(0);
|
|
|
+ }
|
|
|
}};
|
|
|
|
|
|
- ESP_LOGI(TAG, "waiting for onLongRelease...");
|
|
|
+ ESP_LOGI(TAG, "waiting for 2x onLongRelease...");
|
|
|
eventGroup.waitForBit(0);
|
|
|
ESP_LOGI(TAG, "success");
|
|
|
eventGroup.clear();
|