Skip to content

Instantly share code, notes, and snippets.

@CelliesProjects
Created May 11, 2018 10:46
Show Gist options
  • Select an option

  • Save CelliesProjects/1cb40b1914c27404d4ff87de8efd5f95 to your computer and use it in GitHub Desktop.

Select an option

Save CelliesProjects/1cb40b1914c27404d4ff87de8efd5f95 to your computer and use it in GitHub Desktop.
ESP32 - A simple class with a member that is a freertos task.
/* http://www.learncpp.com/cpp-tutorial/812-static-member-functions/ */
#include "myClass.h"
void setup() {
xTaskCreatePinnedToCore(
myClass::myFunction, /* Task function. */
"myFunction", /* String with name of task. */
10000, /* Stack size in words. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL, /* Task handle. */
1);
}
void loop() {
// put your main code here, to run repeatedly:
vTaskDelay( 500 );
}
#include "myClass.h"
#include "esp32-hal-gpio.h"
#include "esp_log.h"
#include <FreeRTOS.h>
void myClass::myFunction( void * parameter )
{
const uint8_t builtin_led = 2;
pinMode( builtin_led, OUTPUT );
while (1)
{
//a function;
const char * TAG = "myFunction";
ESP_LOGI( TAG, "My function" );
digitalWrite( builtin_led, !gpio_get_level( gpio_num_t( builtin_led ) ) );
vTaskDelay( 500 );
}
}
#ifndef MyClass_h
#define MyClass_h
class myClass
{
public:
static void myFunction( void * parameter );
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment