let's assume a function with a pointer in input (a struct of pointers exactly)
how can i resolve these pointers and create the same struct locally so that changes to the pointers won't affect my local struct?
let's assume a function with a pointer in input (a struct of pointers exactly)
how can i resolve these pointers and create the same struct locally so that changes to the pointers won't affect my local struct?
Please post a simple but complete sketch illustrating what you are trying to do
sample sketch from esp32 dove:
// Task to be created.
void vTaskCode( void * pvParameters )
{
for( ;; )
{
// Task code goes here.
}
}
// Function that creates a task.
void vOtherFunction( void )
{
static uint8_t ucParameterToPass;
TaskHandle_t xHandle = NULL;
// Create the task, storing the handle. Note that the passed parameter ucParameterToPass
// must exist for the lifetime of the task, so in this case is declared static. If it was just an
// an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
// the new task attempts to access it.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
configASSERT( xHandle );
// Use the handle to delete the task.
if( xHandle != NULL )
{
vTaskDelete( xHandle );
}
}
inside vTaskCode
i only have a pointer to the arguments. i need to dereference them and keep locally (inside the task)
i can post a Better code in a couple of hours
Are these actual void
pointers, or are they pointers to simple types or classes with a proper copy constructor?
i could do both.
best way would be to pass a struct with 2 or 3 pointers inside, in example 2 strings and 1 integer
I use pointers in a task like so.
void fProcessAirPressure ( void *pvParemeters )
{
int Ticks = 118; // Tick counter
bool Filled = false; // array has been filled before?
float *ptr = CollectionPressure; // pointer to the array
const int ticksTrigger = 120; // triggered at 1 minute intervals
for (;;)
{
//triggered by BME which is triggered by the 1 minute hardware timer.
xEventGroupWaitBits (eg, evtStoreAirPressure, pdTRUE, pdTRUE, portMAX_DELAY );
xSemaphoreTake( sema_CollectPressure, portMAX_DELAY );
xSemaphoreTake ( sema_eData, portMAX_DELAY );
if ( !Filled )
{
//if array has not been filled before, fill array with the same base value
for ( int j = 0; j < BufferCount; j++ )
{
*( ptr + j ) = x_eData.oPressure;
}
Filled = true;// array has been initially filled
} else {
if ( Ticks == ticksTrigger )
{
//when tick counter reaches the trigger level
//shift contents left and insert new value at the end
for ( int i = 0; i <= BufferCount - 2; i++ )
{
*( ptr + i ) = *( ptr + (i + 1) );
}
}
*( ptr + (BufferCount - 1) ) = x_eData.oPressure;//new value to be inserted
}
// find and store highest and lowest value
if ( x_eData.oPressure > x_eData.PressureH )
{
x_eData.PressureH = x_eData.oPressure;
}
if ( x_eData.oPressure < x_eData.PressureL )
{
x_eData.PressureL = x_eData.oPressure;
}
Ticks++;
if ( Ticks > ticksTrigger )
{
Ticks = 1;
}
//log_i( "ticks %d" , Ticks );
x_eData.cngPress = CalculatePressureFactors( *( ptr + 57), *( ptr + 59) ); // going back 4 hours
xSemaphoreGive( sema_eData );
xSemaphoreGive( sema_CollectPressure );
//
//log_i( " high watermark % d", uxTaskGetStackHighWaterMark( NULL ) );
} //for (;;)
vTaskDelete( NULL );
} //void fStoreAirPressure ( void *pvParemeters )
////
but you don't make use of pvParemeters
inside the task...
@gandalfthegray, you apparently missed the word COMPLETE in @UKHeliBob's request. In this sense, "complete" means something that actually compiles in the Arduino IDE.
Post an example of what you are trying to do.
Most likely passing a parameter to a task that will be running continuously will not work. Instead consider sending info from one task to another via a Queue that sends a copy of the original data.
you apparently missed the phrase i can post a Better code in a couple of hours
the task is not running cintinuosly, is started on demand, does a single job then exits
So call the task, passing a parameter to the task and in the task cast the parameter to the proper data type.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.