Private
Public Access
2
0

examples: Remove heap allocation from C++ examples

Small cleanup of MRAA C++ examples.  Switched from heap allocation to
stack allocation when possible.  This simplifies the samples since it
removes the need for explicit memory management.

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2017-08-08 13:55:23 -07:00
parent d50b646c35
commit 1217c5c034
7 changed files with 29 additions and 47 deletions

View File

@@ -43,22 +43,19 @@ main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
mraa::Pwm* pwm;
pwm = new mraa::Pwm(3);
mraa::Pwm pwm(3);
fprintf(stdout, "Cycling PWM on IO3 (pwm3) \n");
pwm->enable(true);
pwm.enable(true);
float value = 0.0f;
while (running == 0) {
value = value + 0.01f;
pwm->write(value);
pwm.write(value);
usleep(50000);
if (value >= 1.0f) {
value = 0.0f;
}
}
delete pwm;
//! [Interesting]
return MRAA_SUCCESS;