From 5b15f374588a3bd740bc6b6d87552eadf6b6fb33 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Wed, 16 Dec 2020 09:43:59 +0800 Subject: [PATCH] fix[cxx]: improve experimental cxx examples * use std::this_thread::sleep_for instead of FreeRTOS sleep functions * adjusted/added lincense headers in examples --- .../main/esp_event_async_cxx_example.cpp | 1 + .../esp_timer_cxx/main/esp_timer_example.cpp | 30 ++++++++----------- .../sensor_mcp9808/main/sensor_mcp9808.cpp | 9 ++++++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/examples/cxx/experimental/esp_event_async_cxx/main/esp_event_async_cxx_example.cpp b/examples/cxx/experimental/esp_event_async_cxx/main/esp_event_async_cxx_example.cpp index 0575cc9547..91156c29d1 100644 --- a/examples/cxx/experimental/esp_event_async_cxx/main/esp_event_async_cxx_example.cpp +++ b/examples/cxx/experimental/esp_event_async_cxx/main/esp_event_async_cxx_example.cpp @@ -6,6 +6,7 @@ software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ + #include #include "esp_event_cxx.hpp" #include "esp_event.h" diff --git a/examples/cxx/experimental/esp_timer_cxx/main/esp_timer_example.cpp b/examples/cxx/experimental/esp_timer_cxx/main/esp_timer_example.cpp index 47640f8659..a79856a75f 100644 --- a/examples/cxx/experimental/esp_timer_cxx/main/esp_timer_example.cpp +++ b/examples/cxx/experimental/esp_timer_cxx/main/esp_timer_example.cpp @@ -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 -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" +#include +#include #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; } diff --git a/examples/cxx/experimental/sensor_mcp9808/main/sensor_mcp9808.cpp b/examples/cxx/experimental/sensor_mcp9808/main/sensor_mcp9808.cpp index 21139819e9..79db14ae42 100644 --- a/examples/cxx/experimental/sensor_mcp9808/main/sensor_mcp9808.cpp +++ b/examples/cxx/experimental/sensor_mcp9808/main/sensor_mcp9808.cpp @@ -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 #include "i2c_cxx.hpp"