mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 02:11:15 +03:00
examples: Remove heap allocation from C++ examples
Cleanup of UPM C++ examples. Switched from heap allocation to stack allocation when possible. This simplifies the samples since it removes the need for explicit memory management. A script was used to identify and replace pointer use. To simplify the replace script, I re-formatted the C++ examples using the UPM .clang-format file. Unfortuantely this changes the look of the UPM C++ examples to a large degree. However, examples will now have a standard look/feel and uniform formatting. * Ran clang-format w/provided UPM .clang-format file * Removed new's/delete's whenever possible (left those in interface examples) * Added IIO sensor library implementation of callback void* arg * Converted all sleeps to upm defined delays (added header when necessary) * Scrubbed CXX example includes Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
bd6e4ec786
commit
5cefe7f5f3
@ -23,6 +23,8 @@
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "jhd1313m1.hpp"
|
||||
@ -30,14 +32,15 @@
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
@ -46,22 +49,16 @@ main(int argc, char **argv)
|
||||
upm::Jhd1313m1 lcd(0, 0x3E, 0x62);
|
||||
|
||||
int ndx = 0;
|
||||
uint8_t rgb[7][3] = {
|
||||
{0xd1, 0x00, 0x00},
|
||||
{0xff, 0x66, 0x22},
|
||||
{0xff, 0xda, 0x21},
|
||||
{0x33, 0xdd, 0x00},
|
||||
{0x11, 0x33, 0xcc},
|
||||
{0x22, 0x00, 0x66},
|
||||
{0x33, 0x00, 0x44}};
|
||||
while (shouldRun)
|
||||
{
|
||||
uint8_t rgb[7][3] = { { 0xd1, 0x00, 0x00 }, { 0xff, 0x66, 0x22 }, { 0xff, 0xda, 0x21 },
|
||||
{ 0x33, 0xdd, 0x00 }, { 0x11, 0x33, 0xcc }, { 0x22, 0x00, 0x66 },
|
||||
{ 0x33, 0x00, 0x44 } };
|
||||
while (shouldRun) {
|
||||
// Alternate rows on the LCD
|
||||
lcd.setCursor(ndx%2,0);
|
||||
lcd.setCursor(ndx % 2, 0);
|
||||
// Change the color
|
||||
uint8_t r = rgb[ndx%7][0];
|
||||
uint8_t g = rgb[ndx%7][1];
|
||||
uint8_t b = rgb[ndx%7][2];
|
||||
uint8_t r = rgb[ndx % 7][0];
|
||||
uint8_t g = rgb[ndx % 7][1];
|
||||
uint8_t b = rgb[ndx % 7][2];
|
||||
lcd.setColor(r, g, b);
|
||||
lcd.write("Hello World " + std::to_string(ndx));
|
||||
// Echo via printf
|
||||
|
Reference in New Issue
Block a user