Merge branch 'feature/example_use_cpp_thread' into 'master'

cxx: improve experimental cxx examples

See merge request espressif/esp-idf!11638
This commit is contained in:
Ivan Grokhotkov 2020-12-17 22:02:00 +08:00
commit 41cd344c6b
3 changed files with 22 additions and 18 deletions

View File

@ -6,6 +6,7 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <iostream>
#include "esp_event_cxx.hpp"
#include "esp_event.h"

View File

@ -1,20 +1,15 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/* ESP Timer C++ 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>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <thread>
#include <chrono>
#include "esp_timer_cxx.hpp"
#include "esp_exception.hpp"
@ -30,14 +25,13 @@ extern "C" void app_main(void)
ESPTimer timer([]() { cout << "timeout" << endl; });
timer.start(chrono::microseconds(200 * 1000));
vTaskDelay(550 / portTICK_PERIOD_MS);
this_thread::sleep_for(std::chrono::milliseconds(550));
cout << "Setting up timer to trigger periodically every 200ms" << endl;
ESPTimer timer2([]() { cout << "periodic timeout" << endl; });
timer2.start_periodic(chrono::microseconds(200 * 1000));
vTaskDelay(1050 / portTICK_PERIOD_MS);
this_thread::sleep_for(std::chrono::milliseconds(1050));
} catch (const ESPException &e) {
cout << "Exception with error: " << e.error << endl;
}

View File

@ -1,3 +1,12 @@
/* ESP MCP9808 Sensor/I2C C++ 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>
#include "i2c_cxx.hpp"