Forráskód Böngészése

Merge branch 'kbf-28' of kraxor/kbf into develop

Bence Balint 3 éve
szülő
commit
a4db17df6d
2 módosított fájl, 11 hozzáadás és 6 törlés
  1. 1 0
      src/driver/button.cpp
  2. 10 6
      test/driver/test_button.cpp

+ 1 - 0
src/driver/button.cpp

@@ -67,4 +67,5 @@ void driver::Button::longPressTaskHandler(void *arg) {
     if (button->onLongPress) button->onLongPress(*button);
     button->longPressEventGroup.waitForBit(eventLongRelease);
     if (button->onLongRelease) button->onLongRelease(*button);
+    button->longPressEventGroup.clear();
 }

+ 10 - 6
test/driver/test_button.cpp

@@ -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();