ESP32 button library for ESP32 HomeKit and applied in ESP32 HomeKit Demo
/**
Copyright 2024 Achim Pieters | StudioPieters®
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
for more information visit https://www.studiopieters.nl
**/
#include <driver/gpio.h>
#include <button.h>
#define BUTTON_GPIO CONFIG_ESP_BUTTON_GPIO
void button_callback(button_event_t event, void *context) {
switch (event) {
case button_event_single_press:
ESP_LOGI("SINGLE_PRESS", "single press");
break;
case button_event_double_press:
ESP_LOGI("DOUBLE_PRESS", "Double press");
break;
case button_event_long_press:
ESP_LOGI("LONG_PRESS", "Long press");
break;
default:
ESP_LOGI("UNKNOWN_BUTTON_EVENT", "unknown button event: %d", event);
}
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverride-init"
button_config_t button_config = BUTTON_CONFIG(
button_active_low,
.max_repeat_presses=3,
.long_press_time=1000,
);
#pragma GCC diagnostic pop
if (button_create(BUTTON_GPIO, button_config, button_callback, NULL)) {
ESP_LOGE("INITIALIZE_BUTTON", "Failed to initialize button");
}
-------------------------------------------------------------------------------------------------------------------------------------
ORIGINAL PROJECT
MIT LICENCE
Copyright © 2017 Maxim Kulkin | esp-button
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.