Used for verbose tracing via printf(..) to the STM32F746 LCD.
Revision 0:ecd4f3e81bcf, committed 2017-01-05
- Comitter:
- mmills
- Date:
- Thu Jan 05 18:40:01 2017 +0000
- Commit message:
- Initial Revision.
Changed in this revision
LcdDiscoF746NgTracer.cpp | Show annotated file Show diff for this revision Revisions of this file |
LcdDiscoF746NgTracer.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r ecd4f3e81bcf LcdDiscoF746NgTracer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LcdDiscoF746NgTracer.cpp Thu Jan 05 18:40:01 2017 +0000 @@ -0,0 +1,75 @@ +/* + License: + Copyright (C) 2017 GroveStreams LLC. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "LcdDiscoF746NgTracer.h" + + +LcdDiscoF746NgTracer::LcdDiscoF746NgTracer() +{ + _line = 0; + _maxLines = 21; + _lcd.Clear(LCD_COLOR_GREEN); + _lcd.SetBackColor(LCD_COLOR_GREEN); + _lcd.SetTextColor(LCD_COLOR_WHITE); + _lcd.SetFont(&Font12); +} + +void LcdDiscoF746NgTracer::printf(const char* format, ...) +{ + char sbuffer[512] = {0}; + + va_list args; + va_start(args, format); + vsprintf(sbuffer, format, args); + + this->println(sbuffer); + + va_end(args); +} + +void LcdDiscoF746NgTracer::println(const char* sbuffer) +{ + + //LCD can only disply 60 chars at a time + int ichar = 0; + int charCount = strlen(sbuffer); + while (charCount>0) { + + char subbuff[61] = {0}; //Initialize buffer to nulls + if (charCount < 60) { + memcpy( subbuff, &sbuffer[ichar], charCount); + charCount=0; + } else { + memcpy( subbuff, &sbuffer[ichar], 60); + charCount -= 60; + } + + _lcd.DisplayStringAtLine(_line, (uint8_t *)subbuff); + + _line++; + if (_line == _maxLines) { + clear(); + } + + ichar+=60; + } +} + +void LcdDiscoF746NgTracer::clear() +{ + _line = 0; + _lcd.Clear(LCD_COLOR_GREEN); +} + +
diff -r 000000000000 -r ecd4f3e81bcf LcdDiscoF746NgTracer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LcdDiscoF746NgTracer.h Thu Jan 05 18:40:01 2017 +0000 @@ -0,0 +1,60 @@ +/* + License: + Copyright (C) 2017 GroveStreams LLC. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef LCDDISCOF746NG_H_ +#define LCDDISCOF746NG_H_ + +#include "LCD_DISCO_F746NG.h" + +class LcdDiscoF746NgTracer +{ +protected: + int _line; + int _maxLines; + LCD_DISCO_F746NG _lcd; + +public: + + /** Constructor + * + */ + LcdDiscoF746NgTracer(); + + /** Prints formatted strings to the LCD in a single line for each call. Long + * lines are wrapped. The LCD is cleared after it is full. + * Utilizes sprintf. sprintf does not support floats on many + * embed systems. + * + * \param format string format. + * \param ... variable number of format arguments + * Example: printf("Successful update"); + * Example: printf("Current status: %d", status); + * \return 0 on success + */ + void printf(const char* format, ...); + + /** Prints a string to the LCD in a single line for each call. Long + * lines are wrapped. The LCD is cleared after it is full. + * + * \param sbuffer string buffer + */ + void println(const char* sbuffer); + + /** Clears the LCD + * + */ + void clear(); +}; + +#endif /* LCDDISCOF746NG_H_ */ \ No newline at end of file