]> Devi Nivas Git - smartwatch.git/commitdiff
Add test program for button inputs
authorAdvaith Menon <noreply-git@bp4k.net>
Sun, 16 Nov 2025 07:41:42 +0000 (02:41 -0500)
committerAdvaith Menon <noreply-git@bp4k.net>
Sun, 16 Nov 2025 07:41:42 +0000 (02:41 -0500)
* Allow esp_driver_gpio privilege
* Remove restart code
* Add test program to read input buttons

main/CMakeLists.txt
main/hello_world_main.c

index 28ab405bd662534036a3adfbd9474cee41a937a1..3aeb4ccc2a6dee2bfa60888adc815af6cb4cd6ae 100644 (file)
@@ -1,3 +1,4 @@
 idf_component_register(SRCS "hello_world_main.c"
-                       PRIV_REQUIRES spi_flash
+                       INCLUDE_DIRS "."
+                       PRIV_REQUIRES spi_flash esp_driver_gpio
                        INCLUDE_DIRS "")
index 7010f3ef61c35a9ddc0bb3ec210b7a0089374808..08f0329ab0913b78258722d42163c092195ad7db 100644 (file)
 #include "esp_chip_info.h"
 #include "esp_flash.h"
 #include "esp_system.h"
+#include "driver/gpio.h"
+
+#define BUTTON_WHITE 0
+#define BUTTON_GREEN 10
+#define BUTTON_YELLOW 11
+#define BUTTON_BLUE 18
+#define BUTTON_RED 15
 
 void app_main(void)
 {
@@ -42,6 +49,22 @@ void app_main(void)
 
     printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
 
+    gpio_set_direction(BUTTON_WHITE, GPIO_MODE_INPUT);
+    gpio_pullup_en(BUTTON_WHITE);
+
+    gpio_set_direction(BUTTON_GREEN, GPIO_MODE_INPUT);
+    gpio_pullup_en(BUTTON_GREEN);
+
+    gpio_set_direction(BUTTON_YELLOW, GPIO_MODE_INPUT);
+    gpio_pullup_en(BUTTON_YELLOW);
+
+    gpio_set_direction(BUTTON_BLUE, GPIO_MODE_INPUT);
+    gpio_pullup_en(BUTTON_BLUE);
+
+    gpio_set_direction(BUTTON_RED, GPIO_MODE_INPUT);
+    gpio_pullup_en(BUTTON_RED);
+
+    /*
     for (int i = 10; i >= 0; i--) {
         printf("Restarting in %d seconds...\n", i);
         vTaskDelay(1000 / portTICK_PERIOD_MS);
@@ -49,4 +72,14 @@ void app_main(void)
     printf("Restarting now.\n");
     fflush(stdout);
     esp_restart();
+    */
+    while (1) {
+        printf("Button levels: [%d|%d|%d|%d|%d]\n",
+                gpio_get_level(BUTTON_WHITE),
+                gpio_get_level(BUTTON_GREEN),
+                gpio_get_level(BUTTON_YELLOW),
+                gpio_get_level(BUTTON_BLUE),
+                gpio_get_level(BUTTON_RED));
+        vTaskDelay(500 / portTICK_PERIOD_MS);
+    }
 }