@@ -506,6 +506,62 @@ void OLEDDisplay::clear(void) {
506506 memset (buffer, 0 , DISPLAY_BUFFER_SIZE);
507507}
508508
509+ void OLEDDisplay::drawLogBuffer (uint16_t xMove, uint16_t yMove) {
510+ setTextAlignment (TEXT_ALIGN_LEFT);
511+ uint16_t lineHeight = pgm_read_byte (fontData + HEIGHT_POS);
512+ uint16_t length = 0 ;
513+ uint16_t line = 0 ;
514+ uint16_t lastPos = 0 ;
515+ for (uint16_t i=0 ;i<this ->logBufferFilled ;i++){
516+ if (this ->logBuffer [i] == 10 ) {
517+ drawStringInternal (xMove, yMove + (line++) * lineHeight, &this ->logBuffer [lastPos], length, 0 );
518+ lastPos = i;
519+ length = 0 ;
520+ } else {
521+ length++;
522+ }
523+ }
524+ drawStringInternal (xMove, yMove + (line++) * lineHeight, &this ->logBuffer [lastPos], length, 0 );
525+ }
526+
527+ bool OLEDDisplay::setLogBuffer (uint16_t lines, uint16_t chars){
528+ if (logBuffer != NULL ) free (logBuffer);
529+ uint16_t size = lines * chars;
530+ if (size > 0 ) {
531+ this ->logBufferMaxLines = lines;
532+ this ->logBufferLine = 0 ;
533+ this ->logBufferSize = size;
534+ this ->logBuffer = (char *) malloc (size * sizeof (uint8_t ));
535+ if (!this ->logBuffer ) {
536+ DEBUG_OLEDDISPLAY (" [OLEDDISPLAY][setLogBuffer] Not enough memory to create log buffer\n " );
537+ return false ;
538+ }
539+ }
540+ return true ;
541+ }
542+
543+ size_t OLEDDisplay::write (uint8_t c) {
544+ if (this ->logBufferSize > 0 ) {
545+ if (this ->logBufferFilled < this ->logBufferSize && this ->logBufferLine < this ->logBufferMaxLines ) {
546+ this ->logBuffer [logBufferFilled] = utf8ascii (c);
547+ this ->logBufferFilled ++;
548+ if (c == 10 ) this ->logBufferLine ++;
549+ } else {
550+ if (this ->logBufferLine <= this ->logBufferMaxLines ) this ->logBufferLine = 0 ;
551+ this ->logBufferFilled = 0 ;
552+ write (c);
553+ }
554+ }
555+
556+ }
557+
558+ size_t OLEDDisplay::write (const char * str) {
559+ size_t length = strlen (str);
560+ for (size_t i = 0 ; i < length; i++) {
561+ write (str[i]);
562+ }
563+ }
564+
509565// Private functions
510566void OLEDDisplay::sendInitCommands (void ) {
511567 sendCommand (DISPLAYOFF);
0 commit comments