mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-03 20:54:32 +02:00
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:
@@ -6,6 +6,7 @@
|
|||||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
CONDITIONS OF ANY KIND, either express or implied.
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "esp_event_cxx.hpp"
|
#include "esp_event_cxx.hpp"
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
|
@@ -1,20 +1,15 @@
|
|||||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
/* ESP Timer C++ Example
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
Unless required by applicable law or agreed to in writing, this
|
||||||
//
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
//
|
*/
|
||||||
// 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.
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "freertos/FreeRTOS.h"
|
#include <thread>
|
||||||
#include "freertos/task.h"
|
#include <chrono>
|
||||||
|
|
||||||
#include "esp_timer_cxx.hpp"
|
#include "esp_timer_cxx.hpp"
|
||||||
#include "esp_exception.hpp"
|
#include "esp_exception.hpp"
|
||||||
@@ -30,14 +25,13 @@ extern "C" void app_main(void)
|
|||||||
ESPTimer timer([]() { cout << "timeout" << endl; });
|
ESPTimer timer([]() { cout << "timeout" << endl; });
|
||||||
timer.start(chrono::microseconds(200 * 1000));
|
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;
|
cout << "Setting up timer to trigger periodically every 200ms" << endl;
|
||||||
ESPTimer timer2([]() { cout << "periodic timeout" << endl; });
|
ESPTimer timer2([]() { cout << "periodic timeout" << endl; });
|
||||||
timer2.start_periodic(chrono::microseconds(200 * 1000));
|
timer2.start_periodic(chrono::microseconds(200 * 1000));
|
||||||
|
|
||||||
vTaskDelay(1050 / portTICK_PERIOD_MS);
|
this_thread::sleep_for(std::chrono::milliseconds(1050));
|
||||||
|
|
||||||
} catch (const ESPException &e) {
|
} catch (const ESPException &e) {
|
||||||
cout << "Exception with error: " << e.error << endl;
|
cout << "Exception with error: " << e.error << endl;
|
||||||
}
|
}
|
||||||
|
@@ -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 <iostream>
|
||||||
#include "i2c_cxx.hpp"
|
#include "i2c_cxx.hpp"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user