2015-08-10 05:51:57 +00:00
|
|
|
/* A very basic C++ example, really just proof of concept for C++
|
|
|
|
|
|
|
|
This sample code is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "espressif/esp_common.h"
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "queue.h"
|
|
|
|
|
|
|
|
class Counter
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
uint32_t _count;
|
|
|
|
public:
|
|
|
|
Counter(uint32_t initial_count)
|
|
|
|
{
|
|
|
|
this->_count = initial_count;
|
2015-09-12 06:25:36 +00:00
|
|
|
printf("Counter initialised with count %d\r\n", initial_count);
|
2015-08-10 05:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Increment()
|
|
|
|
{
|
|
|
|
_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t getCount()
|
|
|
|
{
|
|
|
|
return _count;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static Counter static_counter(99);
|
|
|
|
|
|
|
|
void task1(void *pvParameters)
|
|
|
|
{
|
|
|
|
Counter local_counter = Counter(12);
|
2015-08-12 22:32:34 +00:00
|
|
|
Counter *new_counter = new Counter(24);
|
2015-08-10 05:51:57 +00:00
|
|
|
while(1) {
|
2015-08-12 22:32:34 +00:00
|
|
|
Counter *counter = NULL;
|
|
|
|
switch(rand() % 3) {
|
|
|
|
case 0:
|
|
|
|
counter = &local_counter;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
counter = &static_counter;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
counter = new_counter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
counter->Increment();
|
2015-09-12 06:25:36 +00:00
|
|
|
printf("local counter %d static counter %d newly allocated counter %d\r\n", local_counter.getCount(),
|
2015-08-12 22:32:34 +00:00
|
|
|
static_counter.getCount(), new_counter->getCount());
|
2015-08-10 05:51:57 +00:00
|
|
|
vTaskDelay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void user_init(void)
|
|
|
|
{
|
|
|
|
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
|
|
|
xTaskCreate(task1, (signed char *)"tsk1", 256, NULL, 2, NULL);
|
|
|
|
}
|