添加智能灯固件代码

This commit is contained in:
kerwincui
2021-07-13 17:14:51 +08:00
parent 332f74dd17
commit ecc0b91b8b
2568 changed files with 229441 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
# The following 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(cpp_exceptions_example)

View File

@@ -0,0 +1,9 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := cpp_exceptions_example
include $(IDF_PATH)/make/project.mk

View File

@@ -0,0 +1,49 @@
# Example: C++ exception handling
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates usage of C++ exceptions in ESP-IDF.
By default, C++ exceptions support is disabled in ESP-IDF. It can be enabled using `CONFIG_COMPILER_CXX_EXCEPTIONS` configuration option.
In this example, the `sdkconfig.defaults` file sets the `CONFIG_COMPILER_CXX_EXCEPTIONS` option. This enables both compile time support (`-fexceptions` compiler flag) and run-time support for C++ exception handling.
The example source code declares a class which can throw exception from the constructor if the argument provided is equal to `0`. This is used to demonstrate that exceptions can be thrown and caught using standard C++ facilities.
**Note: Due to the use of the C++ exceptions, this example is written in C++ instead of C.**
## How to use example
### Hardware Required
This example should be able to run on any commonly available ESP32 development board.
### Configure the project
```
idf.py menuconfig
```
### Build and Flash
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port.)
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
```
app_main starting
In constructor, arg=42
In constructor, arg=0
In destructor, m_arg=42
Exception caught: Exception in constructor
app_main done
```

View File

@@ -0,0 +1,23 @@
from __future__ import print_function
import ttfw_idf
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
def test_examples_system_cpp_exceptions(env, extra_data):
dut = env.get_dut('cpp_exceptions_example', 'examples/cxx/exceptions', dut_class=ttfw_idf.ESP32DUT)
# start test
dut.start_app()
lines = ['app_main starting',
'In constructor, arg=42',
'In constructor, arg=0',
'In destructor, m_arg=42',
'Exception caught: Exception in constructor',
'app_main done'
]
for line in lines:
dut.expect(line, timeout=2)
if __name__ == '__main__':
test_examples_system_cpp_exceptions()

View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "exception_example_main.cpp"
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,4 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

View File

@@ -0,0 +1,56 @@
/* C++ exception handling example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <iostream>
using std::cout;
using std::endl;
using std::runtime_error;
/* A simple class which may throw an exception from constructor */
class Throwing
{
public:
Throwing(int arg)
: m_arg(arg)
{
cout << "In constructor, arg=" << arg << endl;
if (arg == 0) {
throw runtime_error("Exception in constructor");
}
}
~Throwing()
{
cout << "In destructor, m_arg=" << m_arg << endl;
}
protected:
int m_arg;
};
/* Inside .cpp file, app_main function must be declared with C linkage */
extern "C" void app_main(void)
{
cout << "app_main starting" << endl;
try {
/* This will succeed */
Throwing obj1(42);
/* This will throw an exception */
Throwing obj2(0);
cout << "This will not be printed" << endl;
} catch (const runtime_error &e) {
cout << "Exception caught: " << e.what() << endl;
}
cout << "app_main done" << endl;
}

View File

@@ -0,0 +1,3 @@
# Enable C++ exceptions and set emergency pool size for exception objects
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE=1024