-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
996917b
commit 640d3d9
Showing
35 changed files
with
1,328 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
#pragma once | ||
|
||
#include "driver/ledc.h" | ||
// #include "led_common.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
examples/lighting/indicator/components/cmd_led_indicator/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
idf_component_register(SRC_DIRS "." | ||
INCLUDE_DIRS "." | ||
REQUIRES console) |
102 changes: 102 additions & 0 deletions
102
examples/lighting/indicator/components/cmd_led_indicator/cmd_led_indicator.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include "cmd_led_indicator.h" | ||
#include "esp_console.h" | ||
#include "argtable3/argtable3.h" | ||
#include "esp_log.h" | ||
#include "esp_check.h" | ||
|
||
static struct { | ||
struct arg_int *start; | ||
struct arg_int *stop; | ||
struct arg_int *preempt_start; | ||
struct arg_int *preempt_stop; | ||
struct arg_end *end; | ||
} cmd_indicator_args; | ||
|
||
typedef struct { | ||
led_indicator_cmd_cb cmd_cb; | ||
} cmd_led_indicator_cmd_t; | ||
|
||
static const char *TAG = "cmd_led_indicator"; | ||
static cmd_led_indicator_cmd_t cmd_led_indicator_cmd = {0}; | ||
|
||
static int cmd_br_fdb_remove(int argc, char **argv) | ||
{ | ||
int nerrors = arg_parse(argc, argv, (void **) &cmd_indicator_args); \ | ||
if (nerrors != 0) { | ||
arg_print_errors(stderr, cmd_indicator_args.end, argv[0]); | ||
return 1; | ||
} | ||
|
||
if (cmd_indicator_args.start->count > 0) { | ||
cmd_led_indicator_cmd.cmd_cb(START, cmd_indicator_args.start->ival[0]); | ||
} else if (cmd_indicator_args.stop->count > 0) { | ||
cmd_led_indicator_cmd.cmd_cb(STOP, cmd_indicator_args.stop->ival[0]); | ||
} else if (cmd_indicator_args.preempt_start->count > 0) { | ||
cmd_led_indicator_cmd.cmd_cb(PREEMPT_START, cmd_indicator_args.preempt_start->ival[0]); | ||
} else if (cmd_indicator_args.preempt_stop->count > 0) { | ||
cmd_led_indicator_cmd.cmd_cb(PREEMPT_STOP, cmd_indicator_args.preempt_stop->ival[0]); | ||
} else { | ||
ESP_LOGE(TAG, "no valid arguments"); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
esp_err_t cmd_led_indicator_init(cmd_led_indicator_t *cmd_led_indicator) | ||
{ | ||
ESP_RETURN_ON_FALSE(cmd_led_indicator != NULL, ESP_ERR_INVALID_ARG, TAG, "cmd_led_indicator is NULL"); | ||
ESP_RETURN_ON_FALSE(cmd_led_indicator->cmd_cb != NULL, ESP_ERR_INVALID_ARG, TAG, "cmd_led_indicator->cmd_cb is NULL"); | ||
|
||
cmd_led_indicator_cmd.cmd_cb = cmd_led_indicator->cmd_cb; | ||
uint32_t max_mode = cmd_led_indicator->mode_count - 1; | ||
|
||
esp_console_repl_t *repl = NULL; | ||
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); | ||
|
||
/* Register commands */ | ||
esp_console_register_help_command(); | ||
|
||
#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM) | ||
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); | ||
ESP_RETURN_ON_ERROR(esp_console_new_repl_uart(&hw_config, &repl_config, &repl), TAG, "Failed to initialize UART REPL"); | ||
|
||
#elif defined(CONFIG_ESP_CONSOLE_USB_CDC) | ||
esp_console_dev_usb_cdc_config_t hw_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT(); | ||
ESP_RETURN_ON_ERROR(esp_console_new_repl_usb_cdc(&hw_config, &repl_config, &repl), TAG, "Failed to initialize USB CDC REPL"); | ||
|
||
#elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) | ||
esp_console_dev_usb_serial_jtag_config_t hw_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT(); | ||
ESP_RETURN_ON_ERROR(esp_console_new_repl_usb_serial_jtag(&hw_config, &repl_config, &repl), TAG, "Failed to initialize USB serial REPL"); | ||
|
||
#else | ||
#error Unsupported console type | ||
#endif | ||
|
||
cmd_indicator_args.start = arg_intn("s", "start", "<start>", 0, max_mode, "Start blinking the mode with given index"); | ||
cmd_indicator_args.stop = arg_intn("e", "stop", "<stop>", 0, max_mode, "Stop blinking the mode with given index"); | ||
cmd_indicator_args.preempt_start = arg_intn("p", "preempt_start", "<preempt_start>", 0, max_mode, "Preemptively start blinking the mode with given index"); | ||
cmd_indicator_args.preempt_stop = arg_intn("x", "preempt_stop", "<preempt_stop>", 0, max_mode, "Preemptively stop blinking the mode with given index"); | ||
cmd_indicator_args.end = arg_end(4); | ||
|
||
const esp_console_cmd_t cmd = { | ||
.command = "led", | ||
.help = "LED indicator commands", | ||
.hint = NULL, | ||
.func = &cmd_br_fdb_remove, | ||
.argtable = &cmd_indicator_args | ||
}; | ||
|
||
ESP_RETURN_ON_ERROR(esp_console_cmd_register(&cmd), TAG, "Failed to register command"); | ||
ESP_RETURN_ON_ERROR(esp_console_start_repl(repl), TAG, "Failed to start REPL"); | ||
|
||
return ESP_OK; | ||
} |
40 changes: 40 additions & 0 deletions
40
examples/lighting/indicator/components/cmd_led_indicator/cmd_led_indicator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "esp_err.h" | ||
|
||
typedef enum { | ||
START = 0, | ||
STOP, | ||
PREEMPT_START, | ||
PREEMPT_STOP, | ||
} cmd_type_t; | ||
|
||
typedef void (*led_indicator_cmd_cb)(cmd_type_t cmd_type, uint32_t mode_index); | ||
|
||
typedef struct { | ||
uint32_t mode_count; | ||
led_indicator_cmd_cb cmd_cb; | ||
} cmd_led_indicator_t; | ||
|
||
/** | ||
* @brief install led indicator cmd | ||
* | ||
* @param cmd_led_indicator led indicator cmd cfg | ||
* @return | ||
* ESP_OK success | ||
* ESP_FAIL failed | ||
*/ | ||
esp_err_t cmd_led_indicator_init(cmd_led_indicator_t *cmd_led_indicator); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(gpio_led_indicator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## LED Indicator WS2812 | ||
|
||
* Support ON/OFF | ||
|
||
### Hardware Required | ||
|
||
* LED | ||
|
||
### Configure the project | ||
|
||
``` | ||
idf.py menuconfig | ||
``` | ||
|
||
* Set `EXAMPLE_GPIO_NUM` to set led gpio. | ||
* Set `EXAMPLE_GPIO_ACTIVE_LEVEL` to set gpio level when led light | ||
|
||
### How to USE | ||
|
||
If the macro `EXAMPLE_ENABLE_CONSOLE_CONTROL` is enabled, please use the following method for control; otherwise, the indicator lights will flash sequentially in order. | ||
|
||
* Help | ||
```shell | ||
help | ||
``` | ||
|
||
* Immediate display mode, without considering priority. | ||
```shell | ||
led -p 0 # Start | ||
led -p 2 # Start | ||
led -x 2 # Stop | ||
``` | ||
|
||
* Display mode based on priority. | ||
```shell | ||
led -s 0 # Start 0 | ||
led -s 2 # Start 2 | ||
led -e 2 # Stop 2 | ||
``` | ||
|
||
Note: | ||
> Support replacing the LED with an active buzzer to achieve the functionality of a buzzer indicator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "main.c" | ||
INCLUDE_DIRS ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
menu "Example Configuration" | ||
|
||
config EXAMPLE_GPIO_NUM | ||
int "GPIO number" | ||
default 1 | ||
help | ||
GPIO number to use for example. | ||
|
||
config EXAMPLE_GPIO_ACTIVE_LEVEL | ||
bool "GPIO active level" | ||
default y | ||
help | ||
GPIO active level. | ||
|
||
config EXAMPLE_ENABLE_CONSOLE_CONTROL | ||
bool "Enable console control" | ||
default n | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "0.0.1" | ||
dependencies: | ||
idf: ">=4.4" | ||
cmd_led_indicator: | ||
version: "*" | ||
override_path: "../../components/cmd_led_indicator" | ||
led_indicator: | ||
version: "*" | ||
override_path: "../../../../../components/led/led_indicator" |
Oops, something went wrong.