feat: Initialize ESP-IDF project with Zigbee HA_on_off_switch example

- Added .devcontainer configuration for development environment.
- Created .gitignore to exclude unnecessary files.
- Configured C/C++ properties for ESP-IDF in VSCode.
- Set up launch configurations for debugging.
- Defined project settings for ESP-IDF in VSCode.
- Created CMakeLists.txt for project build configuration.
- Added README.md with project overview and usage instructions.
- Established dependencies for Zigbee libraries in dependencies.lock.
- Implemented main application logic in esp_zb_switch.c and esp_zb_switch.h.
- Developed switch driver functionality in switch_driver.c and switch_driver.h.
- Configured partition table in partitions.csv for NVS and application storage.
- Set default SDK configuration in sdkconfig.defaults for project settings.
This commit is contained in:
2026-01-15 21:46:31 +00:00
commit a05ac96d97
18 changed files with 1038 additions and 0 deletions
+121
View File
@@ -0,0 +1,121 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: LicenseRef-Included
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Espressif Systems
* integrated circuit in a product or a software update for such product,
* must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* 4. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "driver/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
/* user should configure which I/O port as toggle switch input, default is GPIO9 */
#define GPIO_INPUT_IO_TOGGLE_SWITCH GPIO_NUM_9
/* GPIO para controlar o relay */
#define GPIO_OUTPUT_RELAY GPIO_NUM_8
/* config button level depends on the pull up/down setting
push button level is on level = 1 when pull-down enable
push button level is on level = 0 when pull-up enable
*/
#define GPIO_INPUT_LEVEL_ON 0
#define ESP_INTR_FLAG_DEFAULT 0
#define PAIR_SIZE(TYPE_STR_PAIR) (sizeof(TYPE_STR_PAIR) / sizeof(TYPE_STR_PAIR[0]))
typedef enum {
SWITCH_IDLE,
SWITCH_PRESS_ARMED,
SWITCH_PRESS_DETECTED,
SWITCH_PRESSED,
SWITCH_RELEASE_DETECTED,
} switch_state_t;
typedef enum {
SWITCH_ON_CONTROL,
SWITCH_OFF_CONTROL,
SWITCH_ONOFF_TOGGLE_CONTROL,
SWITCH_LEVEL_UP_CONTROL,
SWITCH_LEVEL_DOWN_CONTROL,
SWITCH_LEVEL_CYCLE_CONTROL,
SWITCH_COLOR_CONTROL,
} switch_func_t;
typedef struct {
uint32_t pin;
switch_func_t func;
} switch_func_pair_t;
typedef void (*esp_switch_callback_t)(switch_func_pair_t *param);
/**
* @brief init function for switch and callback setup
*
* @param button_func_pair pointer of the button pair.
* @param button_num number of button pair.
* @param cb callback pointer.
*/
bool switch_driver_init(switch_func_pair_t *button_func_pair, uint8_t button_num, esp_switch_callback_t cb);
/**
* @brief Inicializa o GPIO do relay
*/
void relay_driver_init(void);
/**
* @brief Define o estado do relay
*
* @param state true para ligar, false para desligar
*/
void relay_set_state(bool state);
/**
* @brief Inverte o estado atual do relay
*/
void relay_toggle(void);
/**
* @brief Obtém o estado atual do relay
*
* @return true se ligado, false se desligado
*/
bool relay_get_state(void);
#ifdef __cplusplus
} // extern "C"
#endif