I'm getting the following error on my xTaskCreatePinnedToCore, and it seems related to the trick described on this thread.
Code: Select all
Cannot convert 'void (Channel::*)()' to 'TaskFunction_t {aka void (*)(void*)}' for argument '1' to 'BaseType_t xTaskCreatePinnedToCore(TaskFunction_t, const char*, uint32_t, void*, UBaseType_t, void**, BaseType_t)'
Code: Select all
#ifndef Channel_h
#define Channel_h
#include <stdint.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// Channel parameters for pulses
typedef struct {
uint16_t tClose ;
uint16_t tOpen ;
bool loop ;
} _chParam ;
class Channel
{
public:
Channel( uint8_t _id, uint8_t _gpio, uint8_t _gpioRegBit ) ;
~Channel() {}
uint8_t id ;
uint8_t gpio ;
uint8_t gpioBit ;
_chParam Ch ;
bool state = false ;
void runOnceTask() ;
static void runOnceTaskW( void *pvParameter ); // Wrapper
private:
void on() ;
void off() ;
void runOnce() ;
protected:
#endif /* Channel_h */
};
Code: Select all
#include "Arduino.h"
#include "Channel.h"
/* Constructor */
Channel::Channel( uint8_t _id, uint8_t _gpio, uint8_t _gpioRegBit ) :
id( _id ), gpio( _gpio ), gpioBit( _gpioRegBit), Ch( {100,1000,false} ), state( LOW )
{
pinMode( gpio, OUTPUT ) ;
gpio = _gpio ;
gpioBit = _gpioRegBit ;
}
void Channel::on()
{
if ( state == LOW )
Serial.print("On") ;
state = HIGH ;
}
void Channel::off()
{
if ( state == HIGH )
Serial.print("Off") ;
state = LOW ;
}
//::::: Task Handling
void Channel::runOnceTask()
{
xTaskCreatePinnedToCore(
&Channel::runOnce, // Function that should be called
"Channel Run once", // Name of the task (for debugging)
1000, // Stack size (bytes)
NULL, // Parameter to pass
1, // Task priority, the lowest is the lowest, 24 is the max
this, // Task handle - instead of NULL
CORE_TASKS // Core you want to run the task on (0 or 1)
) ;
}
void Channel::runOnceTaskW( void *pvParameter )
{
Channel* _channel = reinterpret_cast<Channel*>(pvParameter) ; //obtain the instance pointer
_channel->runOnce() ; //dispatch to the member function, now that we have an instance pointer
}
void Channel::runOnce()
{
on() ;
// Pause the task
vTaskDelay(Ch.tClose / portTICK_PERIOD_MS) ;
off() ;
// Pause the task
vTaskDelay(Ch.tOpen / portTICK_PERIOD_MS) ;
// When you're done, call vTaskDelete. Don't forget this!
vTaskDelete(NULL) ;
}
Many thanks.