7 years, 5 months ago.

Using Thread in the Object

There is my code,I want to using own Object to call the thread object

but run() is wrong,

run()

Thread thread(key_thread);

there is error

Error description

Error: No instance of constructor "rtos::Thread::Thread" matches the argument list in "KeyParser/KeyParser.cpp", Line: 23, Col: 20

is any one know how to do??

main

#include "mbed.h"
#include "KeyParser.h"
#include "rtos.h"

Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut led1(LED1);

void test()
{
    led1=~led1;
}

Key Key1;

int main() {

    Key1.set(test);
    Key1.run();
    while(1) {   
        Thread::wait(1000);
    }
}

Keyparser.cpp

#include "KeyParser.h"
#include "mbed.h"
#include "rtos.h"

//Serial pc(SERIAL_TX, SERIAL_RX);

void Key::key_thread(void const *args)
{
    while(1)
    {
        (*process)();//not real
        Thread::wait(100);
    }
}
  
void Key::set(void (*_process)())
    {
        process=_process;
    }

void Key::run()
{
    Thread thread(key_thread);
}

Keyparser.h

#ifndef MBED_KEYPARSER_H
#define MBED_KEYPARSER_H
#include "mbed.h"
#include "rtos.h"

class Key //:public Thread
{
    public:
        //Key();
        void set(void (*_process)());
        void run();
        
    private:

        void key_thread(void const *args);
        void (*process)();
};

#endif

1 Answer

5 years, 9 months ago.

Hi

maybe this link will help you

https://developer.mbed.org/forum/mbed/topic/4388/