Giter Club home page Giter Club logo

Comments (2)

pjueon avatar pjueon commented on July 28, 2024 1

I'm not a matlab person so I don't really know what is S-Function Builder.
So I googled it. I guess it's something like exported C++ functions to matlab code, right?

Stopping pwm from the destructor of GPIO::PWM class is the design from the original python library(https://github.com/NVIDIA/jetson-gpio). We want preserve the original design as far as we can.

Here's my suggestion:
Why don't you just keep the PWM object and NOT destruct it?

something like this:

Header file

extern void init();
extern void start(double dutyCycle);
extern void cleanup();       // should be called when you don't need pwm anymore.

CPP file

static GPIO::PWM* pwm = nullptr; 
static bool is_started = false;

void init()
{
    if (pwm == nullptr)
    {
         // initialization routine here...

         // constrcut PWM object
         pwm = new GPIO::PWM(/* .....  */)
        // std::cout << "[DEBUG] pwm object constrcuted" << std::endl;
    }
}

void start(double dutyCycle)
{
    if (pwm == nullptr)
    {
         init();
    }


    if(is_started)
    {
        pwm->ChangeDutyCycle(dutyCycle);
    }
    else
    {
        pwm->start(dutyCycle);
        is_started = true;
    }
}

void cleanup()
{
    if (pwm == nulptr)
        return;
   
    is_started = false;
    delete pwm;
    pwm = nullptr;
    // std::cout << "[DEBUG] pwm object destructed" << std::endl;

    // other cleanup routine here...
}

I exported only 3 functions here,
but you can just export all of the public methods of GPIO::PWM class like this if you want.

If you can export the object itself, the answer will be much simpler, but I guess matlab doesn't support it.

from jetsongpio.

timscheuermann avatar timscheuermann commented on July 28, 2024 1

Thank you for your quick response.
This works like I hoped it would,
The trick with the nullptr solved my problem,
Thank you very much!

from jetsongpio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.