Giter Club home page Giter Club logo

Comments (4)

pjueon avatar pjueon commented on July 28, 2024

I'm not sure if I understand your question correctly, but maybe something like this?

// factory function for PWM
GPIO::PWM CreatePWMObject(int output_pin)
{
        // Pin Setup.	
        // Board pin-numbering scheme	
        GPIO::setmode(GPIO::BOARD);
	// set pin as an output pin with optional initial state of HIGH	
        GPIO::setup(output_pin, GPIO::OUT, GPIO::HIGH);	

        GPIO::PWM p(output_pin, 50);

        return p;
}


// declare "p" as a global variable
static GPIO::PWM p = CreatePWMObject(output_pin);

int main()
{
    // your code...
}

from jetsongpio.

TungTT1311 avatar TungTT1311 commented on July 28, 2024

Oke thanks you

from jetsongpio.

TungTT1311 avatar TungTT1311 commented on July 28, 2024

/home/jetson/Desktop/person_detection/pedestrian_detection/test.cpp:246:10: error: use of deleted function β€˜GPIO::PWM::PWM(const GPIO::PWM&)’
return p;
I used it but error.

from jetsongpio.

pjueon avatar pjueon commented on July 28, 2024

Oops, my bad. I forgot that PWM objects cannot be copied.
I added move constructor and move assign operator to PWM class just now. Now you can move the PWM object.

So,

  1. Update your local repository:
    (Assume you're in the JetsonGPIO directory)
    git pull

  2. Rebuild & reinstall the library:

cd build
make all
sudo make install
  1. Try the above example code again.

Or you can also just use p as reference to the static instance.
Something like this:

// get the reference to static instance of PWM object
GPIO::PWM& GetPWMObject(int output_pin)
{
        // Pin Setup.	
        // Board pin-numbering scheme	
        GPIO::setmode(GPIO::BOARD);
	// set pin as an output pin with optional initial state of HIGH	
        GPIO::setup(output_pin, GPIO::OUT, GPIO::HIGH);	

        // note that p will be initialized only once even if you call GetPWMObject function multiple times. 
        static GPIO::PWM p(output_pin, 50);
        return p;
}


// declare "p" as a global reference to the static instance of PWM object. 
static GPIO::PWM& p = GetPWMObject(output_pin);

int main()
{
    // your code...
}

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.