| 877 | } |
| 878 | |
| 879 | size_t OLEDDisplay::write(uint8_t c) { |
| 880 | if (this->logBufferSize > 0) { |
| 881 | // Don't waste space on \r\n line endings, dropping \r |
| 882 | if (c == 13) return 1; |
| 883 | |
| 884 | // convert UTF-8 character to font table index |
| 885 | c = (this->fontTableLookupFunction)(c); |
| 886 | // drop unknown character |
| 887 | if (c == 0) return 1; |
| 888 | |
| 889 | bool maxLineNotReached = this->logBufferLine < this->logBufferMaxLines; |
| 890 | bool bufferNotFull = this->logBufferFilled < this->logBufferSize; |
| 891 | |
| 892 | // Can we write to the buffer? |
| 893 | if (bufferNotFull && maxLineNotReached) { |
| 894 | this->logBuffer[logBufferFilled] = c; |
| 895 | this->logBufferFilled++; |
| 896 | // Keep track of lines written |
| 897 | if (c == 10) this->logBufferLine++; |
| 898 | } else { |
| 899 | // Max line number is reached |
| 900 | if (!maxLineNotReached) this->logBufferLine--; |
| 901 | |
| 902 | // Find the end of the first line |
| 903 | uint16_t firstLineEnd = 0; |
| 904 | for (uint16_t i=0;i<this->logBufferFilled;i++) { |
| 905 | if (this->logBuffer[i] == 10){ |
| 906 | // Include last char too |
| 907 | firstLineEnd = i + 1; |
| 908 | break; |
| 909 | } |
| 910 | } |
| 911 | // If there was a line ending |
| 912 | if (firstLineEnd > 0) { |
| 913 | // Calculate the new logBufferFilled value |
| 914 | this->logBufferFilled = logBufferFilled - firstLineEnd; |
| 915 | // Now we move the lines infront of the buffer |
| 916 | memcpy(this->logBuffer, &this->logBuffer[firstLineEnd], logBufferFilled); |
| 917 | } else { |
| 918 | // Let's reuse the buffer if it was full |
| 919 | if (!bufferNotFull) { |
| 920 | this->logBufferFilled = 0; |
| 921 | }// else { |
| 922 | // Nothing to do here |
| 923 | //} |
| 924 | } |
| 925 | write(c); |
| 926 | } |
| 927 | } |
| 928 | // We are always writing all uint8_t to the buffer |
| 929 | return 1; |
| 930 | } |
| 931 | |
| 932 | size_t OLEDDisplay::write(const char* str) { |
| 933 | if (str == NULL) return 0; |
no test coverage detected