Skip to content

Commit

Permalink
Support for Arduino debug output
Browse files Browse the repository at this point in the history
- Add: InitDebug() to support redirection of stderr to Serial port
- Change: debug_print() renamed to GSLC_DEBUG_PRINT()
- Change: Improved RAM consumption on Arduino
- Change: Example code enables debug output, cleaned up error handling
- Change: Enable debugging output by default in Config (DEBUG_ERR 1), set to 0 to reduce memory
- Migration Notes (from 0.8.2):
  - To enable debug output on Arduino:
    - Add user DebugOut() function
    - Call gslc_InitDebug() at start of code
    - Please refer to example code for details
  • Loading branch information
ImpulseAdventure committed Jan 10, 2017
1 parent 67f3a93 commit cd27761
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 234 deletions.
8 changes: 7 additions & 1 deletion arduino/gslc_ex01_ard/gslc_ex01_ard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ gslc_tsPage m_asPage[MAX_PAGE];
gslc_tsElem m_asPageElem[MAX_ELEM_PG_MAIN];
gslc_tsElemRef m_asPageElemRef[MAX_ELEM_PG_MAIN];

// Define debug message function
static int16_t DebugOut(char ch, FILE *pStream) { Serial.write(ch); return 0; }

void setup()
{
gslc_tsElem* pElem = NULL;

// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&m_gui,&DebugOut);

// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0)) { exit(1); }
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0)) { return; }

gslc_PageAdd(&m_gui,E_PG_MAIN,m_asPageElem,MAX_ELEM_PG_MAIN,m_asPageElemRef,MAX_ELEM_PG_MAIN);

Expand Down
19 changes: 13 additions & 6 deletions arduino/gslc_ex02_ard/gslc_ex02_ard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ gslc_tsPage m_asPage[MAX_PAGE];
gslc_tsElem m_asPageElem[MAX_ELEM_PG_MAIN];
gslc_tsElemRef m_asPageElemRef[MAX_ELEM_PG_MAIN];

// Define debug message function
static int16_t DebugOut(char ch, FILE *pStream) { Serial.write(ch); return 0; }

// Button callbacks
bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
Expand All @@ -50,13 +52,15 @@ void setup()
bool bOk = true;
gslc_tsElem* pElem = NULL;

// -----------------------------------
// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&m_gui,&DebugOut);

// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { exit(1); }
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { return; }

// Load Fonts
bOk = gslc_FontAdd(&m_gui,E_FONT_BTN,"",1);
//if (!bOk) { printf("ERROR: gslc_FontAdd() failed\n"); exit(1); }
if (!gslc_FontAdd(&m_gui,E_FONT_BTN,"",1)) { return; }

// -----------------------------------
// Create page elements
Expand Down Expand Up @@ -88,10 +92,13 @@ void loop()
// Periodically call GUIslice update function
gslc_Update(&m_gui);

// Upon Quit, close down GUI and terminate loop
// In a real program, we would detect the button press and take an action.
// For this Arduino demo, we will pretend to exit by emulating it with an
// infinite loop. Note that interrupts are not disabled so that any debug
// messages via Serial have an opportunity to be transmitted.
if (m_bQuit) {
gslc_Quit(&m_gui);
exit(1); // In Arduino, this essentially starts infinite loop
while (1) { }
}
}

Expand Down
15 changes: 12 additions & 3 deletions arduino/gslc_ex03_ard/gslc_ex03_ard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ gslc_tsPage m_asPage[MAX_PAGE];
gslc_tsElem m_asPageElem[MAX_ELEM_PG_MAIN];
gslc_tsElemRef m_asPageElemRef[MAX_ELEM_PG_MAIN];

// Define debug message function
static int16_t DebugOut(char ch, FILE *pStream) { Serial.write(ch); return 0; }

// Button callbacks
bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
Expand Down Expand Up @@ -79,8 +81,12 @@ bool InitOverlays()

void setup()
{
// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&m_gui,&DebugOut);

// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0)) { exit(1); }
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0)) { return; }

// Create the graphic elements
InitOverlays();
Expand All @@ -96,10 +102,13 @@ void loop()
// Periodically call GUIslice update function
gslc_Update(&m_gui);

// Upon Quit, close down GUI and terminate loop
// In a real program, we would detect the button press and take an action.
// For this Arduino demo, we will pretend to exit by emulating it with an
// infinite loop. Note that interrupts are not disabled so that any debug
// messages via Serial have an opportunity to be transmitted.
if (m_bQuit) {
gslc_Quit(&m_gui);
exit(1); // In Arduino, this essentially starts infinite loop
while (1) { }
}

}
Expand Down
36 changes: 19 additions & 17 deletions arduino/gslc_ex04_ard/gslc_ex04_ard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ gslc_tsXSlider m_sXSlider;
gslc_tsElem* m_pElemProgress = NULL;
gslc_tsElem* m_pElemSlider = NULL;
gslc_tsElem* m_pElemSliderTxt = NULL;

// Define debug message function
static int16_t DebugOut(char ch, FILE *pStream) { Serial.write(ch); return 0; }

// Button callbacks
bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
Expand Down Expand Up @@ -152,16 +155,19 @@ bool InitOverlays()

void setup()
{
bool bOk = true;

// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&m_gui,&DebugOut);

// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { exit(1); }
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { return; }

// Load Fonts
bOk = gslc_FontAdd(&m_gui,E_FONT_BTN,"",1); // m_asFont[0]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
bOk = gslc_FontAdd(&m_gui,E_FONT_TXT,"",1); // m_asFont[1]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
// - NOTE: If we are using the ElemCreate*_P() macros then it is important to note
// the font pointer (array index) as it will be provided to certain
// ElemCreate*_P() functions (eg. ElemCreateTxt_P).
if (!gslc_FontAdd(&m_gui,E_FONT_BTN,"",1)) { return; } // m_asFont[0]
if (!gslc_FontAdd(&m_gui,E_FONT_TXT,"",1)) { return; } // m_asFont[1]

// Create graphic elements
InitOverlays();
Expand Down Expand Up @@ -197,18 +203,14 @@ void loop()

// Slow down updates
delay(100);

// Upon Quit, close down GUI and terminate loop

// In a real program, we would detect the button press and take an action.
// For this Arduino demo, we will pretend to exit by emulating it with an
// infinite loop. Note that interrupts are not disabled so that any debug
// messages via Serial have an opportunity to be transmitted.
if (m_bQuit) {

// Example: Read checkbox state
// - Either read individual checkboxes
// bool bCheck = gslc_ElemXCheckboxGetState(&m_gui,E_ELEM_CHECK1);
// - Or find one in the group that was checked (eg. for radio buttons)
// gslc_tsElem* pElem = gslc_ElemXCheckboxFindChecked(&m_gui,GSLC_GROUP_ID_NONE);

gslc_Quit(&m_gui);
exit(1); // In Arduino, this essentially starts infinite loop
while (1) { }
}
}

Expand Down
33 changes: 19 additions & 14 deletions arduino/gslc_ex05_ard/gslc_ex05_ard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ gslc_tsXSelNum m_sXSelNum[3];
gslc_tsElem* m_pElemCnt = NULL;
gslc_tsElem* m_pElemProgress = NULL;

// Define debug message function
static int16_t DebugOut(char ch, FILE *pStream) { Serial.write(ch); return 0; }

// Button callbacks
// - Show example of common callback function
bool CbBtnCommon(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
Expand Down Expand Up @@ -189,21 +192,20 @@ bool InitOverlays()

void setup()
{
bool bOk = true;

// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&m_gui,&DebugOut);

// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { exit(1); }
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { return; }

// Load Fonts
// - In this example, we are loading the same font but at
// different point sizes. We could also refer to other
// font files as well.
bOk = gslc_FontAdd(&m_gui,E_FONT_BTN,"",1); // m_asFont[0]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
bOk = gslc_FontAdd(&m_gui,E_FONT_TXT,"",1); // m_asFont[1]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
bOk = gslc_FontAdd(&m_gui,E_FONT_TITLE,"",3); // m_asFont[2]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
// - NOTE: If we are using the ElemCreate*_P() macros then it is important to note
// the font pointer (array index) as it will be provided to certain
// ElemCreate*_P() functions (eg. ElemCreateTxt_P).
if (!gslc_FontAdd(&m_gui,E_FONT_BTN,"",1)) { return; } // m_asFont[0]
if (!gslc_FontAdd(&m_gui,E_FONT_TXT,"",1)) { return; } // m_asFont[1]
if (!gslc_FontAdd(&m_gui,E_FONT_TITLE,"",1)) { return; } // m_asFont[2]

// Create page elements
InitOverlays();
Expand Down Expand Up @@ -239,10 +241,13 @@ void loop()
// Slow down updates
delay(100);

// Upon Quit, close down GUI and terminate loop
// In a real program, we would detect the button press and take an action.
// For this Arduino demo, we will pretend to exit by emulating it with an
// infinite loop. Note that interrupts are not disabled so that any debug
// messages via Serial have an opportunity to be transmitted.
if (m_bQuit) {
gslc_Quit(&m_gui);
exit(1); // In Arduino, this essentially starts infinite loop
while (1) { }
}
}

Expand Down
21 changes: 16 additions & 5 deletions arduino/gslc_ex06_ard/gslc_ex06_ard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ int16_t m_nOriginY = 0;
gslc_tsElem* m_pElemDataZ = NULL;
gslc_tsElem* m_pElemProgress = NULL;

// Define debug message function
static int16_t DebugOut(char ch, FILE *pStream) { Serial.write(ch); return 0; }


// Scanner drawing callback function
// - This is called when E_ELEM_SCAN is being rendered
// - The scanner implements a custom element that replaces
Expand Down Expand Up @@ -281,15 +285,19 @@ void setup()
{
bool bOk = true;

// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&m_gui,&DebugOut);

// -----------------------------------
// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { exit(1); }
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { return; }

// Load Fonts
bOk = gslc_FontAdd(&m_gui,E_FONT_BTN,"",1); // m_asFont[0]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
if (!bOk) { return; }
bOk = gslc_FontAdd(&m_gui,E_FONT_TXT,"",1); // m_asFont[1]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
if (!bOk) { return; }


// -----------------------------------
Expand Down Expand Up @@ -333,10 +341,13 @@ void loop()
// Slow down display
delay(10);

// Upon Quit, close down GUI and terminate loop
// In a real program, we would detect the button press and take an action.
// For this Arduino demo, we will pretend to exit by emulating it with an
// infinite loop. Note that interrupts are not disabled so that any debug
// messages via Serial have an opportunity to be transmitted.
if (m_bQuit) {
gslc_Quit(&m_gui);
exit(1); // In Arduino, this essentially starts infinite loop
while (1) { }
}

}
Expand Down
27 changes: 18 additions & 9 deletions arduino/gslc_ex07_ard/gslc_ex07_ard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "GUIslice_ex.h"
#include "GUIslice_drv.h"


// Defines for resources

// Enumerations for pages, elements, fonts, images
Expand Down Expand Up @@ -61,6 +62,8 @@ uint8_t m_nPosR = 255;
uint8_t m_nPosG = 128;
uint8_t m_nPosB = 0;

// Define debug message function
static int16_t DebugOut(char ch, FILE *pStream) { Serial.write(ch); return 0; }

// Quit button callback
bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
Expand Down Expand Up @@ -216,18 +219,20 @@ bool InitOverlays()
void setup()
{
bool bOk = true;


// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&m_gui,&DebugOut);

// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { exit(1); }
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,m_asFont,MAX_FONT)) { return; }

// Load Fonts
// - NOTE: If we are using the ElemCreate*_P() macros then it is important to note
// the font pointer (array index) as will be provided to certain
// the font pointer (array index) as it will be provided to certain
// ElemCreate*_P() functions (eg. ElemCreateTxt_P).
bOk = gslc_FontAdd(&m_gui,E_FONT_TXT,"",1); // m_asFont[0]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
bOk = gslc_FontAdd(&m_gui,E_FONT_TITLE,"",3); // m_asFont[1]
if (!bOk) { fprintf(stderr,"ERROR: FontAdd failed\n"); exit(1); }
if (!gslc_FontAdd(&m_gui,E_FONT_TXT,"",1)) { return; } // m_asFont[0]
if (!gslc_FontAdd(&m_gui,E_FONT_TITLE,"",3)) { return; } // m_asFont[1]

// Create pages display
InitOverlays();
Expand All @@ -236,6 +241,7 @@ void setup()
gslc_SetPageCur(&m_gui,E_PG_MAIN);

m_bQuit = false;
return;
}

void loop()
Expand All @@ -246,10 +252,13 @@ void loop()
// Periodically call GUIslice update function
gslc_Update(&m_gui);

// Upon Quit, close down GUI and terminate loop
// In a real program, we would detect the button press and take an action.
// For this Arduino demo, we will pretend to exit by emulating it with an
// infinite loop. Note that interrupts are not disabled so that any debug
// messages via Serial have an opportunity to be transmitted.
if (m_bQuit) {
gslc_Quit(&m_gui);
exit(1); // In Arduino, this essentially starts infinite loop
while (1) { }
}
}

2 changes: 1 addition & 1 deletion doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "GUIslice"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.8.2
PROJECT_NUMBER = 0.8.3

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
Loading

0 comments on commit cd27761

Please sign in to comment.