MCPcopy Create free account
hub / github.com/PricelessToolkit/MailBoxGuard / write

Method write

Code/Arduino_libraries/SSD1306/OLEDDisplay.cpp:879–930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

877}
878
879size_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
932size_t OLEDDisplay::write(const char* str) {
933 if (str == NULL) return 0;

Callers 7

_putcMethod · 0.95
displayMethod · 0.45
sendCommandMethod · 0.45
displayMethod · 0.45
sendCommandMethod · 0.45
displayMethod · 0.45
sendCommandMethod · 0.45

Calls 1

writeFunction · 0.50

Tested by

no test coverage detected