Skip to content

Commit

Permalink
ESP-Button
Browse files Browse the repository at this point in the history
  • Loading branch information
alibukharai authored and Lzw655 committed Nov 13, 2023
1 parent ee30cbf commit 4deeae7
Show file tree
Hide file tree
Showing 29 changed files with 3,214 additions and 1 deletion.
136 changes: 136 additions & 0 deletions .github/scripts/check_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/bash

# Function: Check version format
# Input parameters: $1 The version number
# Return value: 0 if the version numbers are correct, 1 if the first version is incorrect,
check_version_format() {
version_regex="^v[0-9]+\.[0-9]+\.[0-9]+$"

if [[ ! $1 =~ $version_regex ]]; then
return 1
fi

return 0
}

if [ $# -lt 1 ]; then
latest_version="0.0.0"
echo "Don't get the lastest version, use \"0.0.0\" as default"
else
# Get the first input parameter as the version to be compared
latest_version="$1"
# Check the version format
check_version_format "${latest_version}"
result=$?
if [ ${result} -ne 0 ]; then
echo "The latest release version (${latest_version}) format is incorrect."
exit 1
fi
fi

# Specify the directory path
target_directory="./"

echo "Checking directory: ${target_directory}"

# Function: Check if a file exists
# Input parameters: $1 The file to check
# Return value: 0 if the file exists, 1 if the file does not exist
check_file_exists() {
if [ ! -f "$1" ]; then
echo "File '$1' not found."
return 1
fi
return 0
}

# Function: Compare version numbers
# Input parameters: $1 The first version number, $2 The second version number
# Return value: 0 if the version numbers are equal, 1 if the first version is greater,
# 2 if the second version is greater,
compare_versions() {
version_regex="^v[0-9]+\.[0-9]+\.[0-9]+$"

version1=$(echo "$1" | cut -c 2-) # Remove the 'v' at the beginning of the version number
version2=$(echo "$2" | cut -c 2-)

IFS='.' read -ra v1_parts <<< "$version1"
IFS='.' read -ra v2_parts <<< "$version2"

for ((i=0; i<${#v1_parts[@]}; i++)); do
if [[ "${v1_parts[$i]}" -lt "${v2_parts[$i]}" ]]; then
return 2
elif [[ "${v1_parts[$i]}" -gt "${v2_parts[$i]}" ]]; then
return 1
fi
done

return 0
}

echo "Checking file: library.properties"
# Check if "library.properties" file exists
check_file_exists "${target_directory}/library.properties"
if [ $? -ne 0 ]; then
exit 1
fi
# Read the version information from the file
arduino_version=v$(grep -E '^version=' "${target_directory}/library.properties" | cut -d '=' -f 2)
echo "Get Arduino version: ${arduino_version}"
# Check the version format
check_version_format "${arduino_version}"
result=$?
if [ ${result} -ne 0 ]; then
echo "Arduino version (${arduino_version}) format is incorrect."
exit 1
fi

# Compare Arduino Library version with the latest release version
compare_versions "${arduino_version}" "${latest_version}"
result=$?
if [ ${result} -ne 1 ]; then
if [ ${result} -eq 3 ]; then
echo "Arduino version (${arduino_version}) is incorrect."
else
echo "Arduino version (${arduino_version}) is not greater than the latest release version (${latest_version})."
exit 1
fi
fi

echo "Checking file: idf_component.yml"
# Check if "idf_component.yml" file exists
check_file_exists "${target_directory}/idf_component.yml"
if [ $? -eq 0 ]; then
# Read the version information from the file
idf_version=v$(grep -E '^version:' "${target_directory}/idf_component.yml" | awk -F'"' '{print $2}')
echo "Get IDF component version: ${idf_version}"
# Check the version format
check_version_format "${idf_version}"
result=$?
if [ ${result} -ne 0 ]; then
echo "IDF component (${idf_version}) format is incorrect."
exit 1
fi
# Compare IDF Component version with Arduino Library version
compare_versions ${idf_version} ${arduino_version}
result=$?
if [ ${result} -ne 0 ]; then
if [ ${result} -eq 3 ]; then
echo "IDF component version (${idf_version}) is incorrect."
else
echo "IDF component version (${idf_version}) is not equal to the Arduino version (${arduino_version})."
exit 1
fi
fi
# Compare IDF Component version with the latest release version
compare_versions ${idf_version} ${latest_version}
result=$?
if [ ${result} -ne 1 ]; then
if [ ${result} -eq 3 ]; then
echo "IDF component version (${idf_version}) is incorrect."
else
echo "IDF component version (${idf_version}) is not greater than the latest release version (${latest_version})."
exit 1
fi
fi
fi
15 changes: 15 additions & 0 deletions .github/workflows/arduino_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Arduino Lint Action

on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
28 changes: 28 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build Test Application

on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
strategy:
matrix:
idf_ver: ["v4.4.5", "v5.0"]
idf_target: ["esp32"]
runs-on: ubuntu-20.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- uses: actions/checkout@v3
- name: Build ESP_Button Test Application
env:
IDF_TARGET: ${{ matrix.idf_target }}
working-directory: test_apps
shell: bash
run: |
. ${IDF_PATH}/export.sh
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
idf.py build
30 changes: 30 additions & 0 deletions .github/workflows/check_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check Versions

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
check_versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get latest release info of repository
id: last_release
uses: InsonusK/[email protected]
with:
myToken: ${{ github.token }}
exclude_types: "draft|prerelease"
view_top: 1
- name: Print result
run: |
echo "id: ${{ steps.last_release.outputs.id }}"
echo "name: ${{ steps.last_release.outputs.name }}"
echo "tag_name: ${{ steps.last_release.outputs.tag_name }}"
echo "created_at: ${{ steps.last_release.outputs.created_at }}"
echo "draft: ${{ steps.last_release.outputs.draft }}"
echo "prerelease: ${{ steps.last_release.outputs.prerelease }}"
echo "url: ${{ steps.last_release.outputs.url }}"
- name: Check & Compare versions
run: bash ./.github/scripts/check_versions.sh ${{ steps.last_release.outputs.tag_name }}

14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
71 changes: 71 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.config
*.o
*.pyc
*.orig

# gtags
GTAGS
GRTAGS
GPATH

# emacs
.dir-locals.el

# emacs temp file suffixes
*~
.#*
\#*#

# eclipse setting
.settings

# MacOS directory files
.DS_Store

# Unit Test CMake compile log folder
log_ut_cmake

TEST_LOGS

# gcov coverage reports
*.gcda
*.gcno
coverage.info
coverage_report/

test_multi_heap_host

# VS Code Settings
.vscode/

# VIM files
*.swp
*.swo

# Clion IDE CMake build & config
.idea/
cmake-build-*/

# Results for the checking of the Python coding style and static analysis
.mypy_cache
flake8_output.txt

# esp-idf default build directory name
build
build_esp*/
build_linux*/
size_info.txt
sdkconfig
sdkconfig.old

# lock files for examples and components
dependencies.lock

# managed_components for examples
managed_components

# pytest log
pytest_embedded_log/
pytest_log/
.pytest_cache/
XUNIT_RESULT.xml
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
exclude: 'src/original'
repos:
- repo: https://github.com/igrr/astyle_py.git
rev: master
hooks:
- id: astyle_py
args: ['--style=otbs', '--attach-namespaces', '--attach-classes', '--indent=spaces=4', '--convert-tabs', '--align-pointer=name', '--align-reference=name', '--keep-one-line-statements', '--pad-header', '--pad-oper']

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
types_or: [c, c++]
- id: end-of-file-fixer
types_or: [c, c++]
- id: check-merge-conflict
- id: mixed-line-ending
types_or: [c, c++]
args: ['--fix=lf']
description: Forces to replace line ending by the UNIX 'lf' character

- repo: https://github.com/espressif/check-copyright/
rev: v1.0.3
hooks:
- id: check-copyright
args: ['--config', 'check_copyright_config.yaml']
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ChangeLog

## v0.0.1 - [2023-11-10]

### Enhancements:

* Only support for ESP32-S2 and ESP32-S3 SoCs.
* Support video stream through UVC Stream interface.
* Support microphone stream and speaker stream through the UAC Stream interface
* Support volume, mute and other features control through the UAC Control interface
* Support stream separately suspend and resume
38 changes: 38 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
list(APPEND PRIVREQ esp_adc)
else()
list(APPEND PRIVREQ esp_adc_cal)
endif()

idf_component_register(SRCS "src/original/button_adc.c"
"src/original/button_gpio.c"
"src/original/button_matrix.c"
"src/original/iot_button.c"
# "src/original/adc_oneshot.c"
"src/Button.cpp"
INCLUDE_DIRS "src"
REQUIRES driver ${PRIVREQ}
PRIV_REQUIRES esp_timer)


# set(PRIVREQ esp_timer)

# if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
# list(APPEND REQ esp_adc)
# else()
# list(APPEND REQ esp_adc_cal)
# endif()

# idf_component_register(SRCS "src/original/button_adc.c"
# "src/original/button_gpio.c"
# "src/original/button_matrix.c"
# "src/original/iot_button.c"
# "src/Button.cpp"
# INCLUDE_DIRS "src"
# REQUIRES driver ${REQ}
# PRIV_REQUIRES ${PRIVREQ})
# # REQUIRES driver
# # PRIV_REQUIRES esp_timer)

# # include(package_manager)
# # cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
Loading

0 comments on commit 4deeae7

Please sign in to comment.