diff --git a/LICENSE b/LICENSE index 8eba944..c3d6b3d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2021 Rob Tillaart +Copyright (c) 2020-2022 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b6e9d00..3e5f4c3 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,28 @@ Tests are done with Other terminal program's exist so please let me know if yours is working too. If not, please open an issue. -# Operation + +## Operation See examples + + +## Performance + +Since 0.1.5 there is some focus on performance. +Using **ansi.print()** and **ansi.println()** for printing text and numbers is +improved a bit since 0.1.4 by adding the private **write(array, length)**. + + +## Future + +- test more terminal programs (Linux mac) +- write more examples + - DOS emulator? +- increase functionality + - which codes are useful ? +- investigate performance. (first step made in 0.1.5 but more possible) + - add line buffer in write(c) to improve throughput? + - need for flush() with line buffer? + - rewrite functions, replace print() by **\_stream->write()** calls? (effect on size?) + diff --git a/ansi.cpp b/ansi.cpp index 9b1fd7d..6fc9137 100644 --- a/ansi.cpp +++ b/ansi.cpp @@ -1,7 +1,7 @@ // // FILE: ansi.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.4 +// VERSION: 0.1.5 // PURPOSE: Arduino library to send ANSI escape sequences // DATE: 2020-04-28 // URL: https://github.com/RobTillaart/ANSI @@ -11,6 +11,8 @@ // 0.1.2 2020-07-08 added clearLine + color support (thanks airbornemint) // 0.1.3 2020-12-11 added Arduino-CI + unit test (minimal) // 0.1.4 2020-10-18 updated Arduino-CI (esp32) + examples +// 0.1.5 2020-12-13 update library.json, license, minor edits +// add write(array, length); #include "ansi.h" @@ -21,11 +23,13 @@ ANSI::ANSI(Stream * stream) _stream = stream; } + int ANSI::available() { return _stream->available(); } + int ANSI::read() { return _stream->read(); @@ -36,18 +40,22 @@ int ANSI::peek() return _stream->peek(); } + void ANSI::clearScreen() { print("\033[2J"); home(); } + void ANSI::clearLine(uint8_t clear) { print("\033["); print(clear); print("K"); } + + // ANSI has three different color spaces: 4-bit color, 8-bit color, and 24-bit color // The are rendered with SGR 30-37,90-97/40-47,100-107, SGR 38;5/48;5, and SGR 38;2/48;2, respectively // The 4-bit color space is the most widely compatible and the most compactly transmitted @@ -61,6 +69,7 @@ enum { extended_color24 = 2, }; + void ANSI::color4_code(uint8_t base, uint8_t color) { if (color < 8) { print(base + color); @@ -69,12 +78,14 @@ void ANSI::color4_code(uint8_t base, uint8_t color) { } } + void ANSI::color4(uint8_t base, uint8_t color) { print("\033["); this->color4_code(base, color); print("m"); } + void ANSI::colors4(uint8_t fgcolor, uint8_t bgcolor) { print("\033["); this->color4_code(fg_normal, fgcolor); @@ -83,6 +94,7 @@ void ANSI::colors4(uint8_t fgcolor, uint8_t bgcolor) { print("m"); } + void ANSI::color8(uint8_t base, uint8_t color) { print("\033["); print(base + extended_color); @@ -93,6 +105,7 @@ void ANSI::color8(uint8_t base, uint8_t color) { print("m"); } + void ANSI::foreground(uint8_t fgcolor) { if (fgcolor < 16) { @@ -102,6 +115,7 @@ void ANSI::foreground(uint8_t fgcolor) } } + void ANSI::background(uint8_t bgcolor) { if (bgcolor < 16) { @@ -111,6 +125,7 @@ void ANSI::background(uint8_t bgcolor) } } + void ANSI::color(uint8_t fgcolor, uint8_t bgcolor) { if (fgcolor < 16 && bgcolor < 16) { @@ -121,13 +136,15 @@ void ANSI::color(uint8_t fgcolor, uint8_t bgcolor) } } + uint8_t ANSI::rgb2color(uint8_t r, uint8_t g, uint8_t b) { return 16 + 36 * (uint16_t(r) * 6 / 256) + - 6 * (uint16_t(g) * 6 / 256) + - (uint16_t(b) * 6 / 256); + 6 * (uint16_t(g) * 6 / 256) + + (uint16_t(b) * 6 / 256); } + void ANSI::gotoXY(uint8_t x, uint8_t y) { print("\033["); @@ -137,6 +154,7 @@ void ANSI::gotoXY(uint8_t x, uint8_t y) print("H"); } + void ANSI::cursorUp(uint8_t x) { print("\033["); @@ -144,6 +162,7 @@ void ANSI::cursorUp(uint8_t x) print("A"); } + void ANSI::cursorDown(uint8_t x) { print("\033["); @@ -151,6 +170,7 @@ void ANSI::cursorDown(uint8_t x) print("B"); } + void ANSI::cursorForward(uint8_t x) { print("\033["); @@ -158,6 +178,7 @@ void ANSI::cursorForward(uint8_t x) print("C"); } + void ANSI::cursorBack(uint8_t x) { print("\033["); @@ -165,11 +186,18 @@ void ANSI::cursorBack(uint8_t x) print("D"); } + size_t ANSI::write(uint8_t c) { - // todo add line buffer - _stream->write(c); - return 1; + // TODO add line buffer? - interference with write(array, length) !? + return _stream->write(c); } - + +size_t ANSI::write(uint8_t * array, uint8_t length) +{ + return _stream->write(array, length); +} + + // -- END OF FILE -- + diff --git a/ansi.h b/ansi.h index a554174..9c598f2 100644 --- a/ansi.h +++ b/ansi.h @@ -2,7 +2,7 @@ // // FILE: ansi.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.4 +// VERSION: 0.1.5 // PURPOSE: Arduino library to send ANSI escape sequences // DATE: 2020-04-28 // URL: https://github.com/RobTillaart/ANSI @@ -11,7 +11,7 @@ #include "Arduino.h" -#define ANSI_LIB_VERSION (F("0.1.4")) +#define ANSI_LIB_VERSION (F("0.1.5")) class ANSI : public Stream @@ -91,6 +91,7 @@ class ANSI : public Stream private: size_t write(uint8_t c); + size_t write(uint8_t * array, uint8_t length); void color4(uint8_t base, uint8_t color); void color4_code(uint8_t base, uint8_t color); void colors4(uint8_t fgcolor, uint8_t bgcolor); diff --git a/examples/ansiDemo01/ansiDemo01.ino b/examples/ansiDemo01/ansiDemo01.ino index 1a40fc9..9f2de8c 100644 --- a/examples/ansiDemo01/ansiDemo01.ino +++ b/examples/ansiDemo01/ansiDemo01.ino @@ -97,4 +97,5 @@ void loop() { } + // -- END OF FILE -- diff --git a/examples/ansiDemo02/ansiDemo02.ino b/examples/ansiDemo02/ansiDemo02.ino index 8f244b3..100c4ee 100644 --- a/examples/ansiDemo02/ansiDemo02.ino +++ b/examples/ansiDemo02/ansiDemo02.ino @@ -16,6 +16,7 @@ ANSI ansi(&Serial); int t; double d; + void setup() { Serial.begin(115200); @@ -30,6 +31,7 @@ void setup() ansi.clearScreen(); } + void loop() { // DISPLAY TEMPERATURE (dummy) @@ -92,4 +94,6 @@ void loop() delay(1000); } + // -- END OF FILE -- + diff --git a/examples/ansi_IO/ansi_IO.ino b/examples/ansi_IO/ansi_IO.ino index cee07a0..f473b44 100644 --- a/examples/ansi_IO/ansi_IO.ino +++ b/examples/ansi_IO/ansi_IO.ino @@ -16,6 +16,7 @@ ANSI ansi(&Serial); String user = ""; String password = ""; + void setup() { Serial.begin(115200); diff --git a/examples/ansi_char_test/ansi_char_test.ino b/examples/ansi_char_test/ansi_char_test.ino index 7e12b0e..c1e26db 100644 --- a/examples/ansi_char_test/ansi_char_test.ino +++ b/examples/ansi_char_test/ansi_char_test.ino @@ -36,4 +36,6 @@ void loop() { } + // -- END OF FILE -- + diff --git a/examples/ansi_clearline/ansi_clearline.ino b/examples/ansi_clearline/ansi_clearline.ino index c7d11ce..52bf49a 100644 --- a/examples/ansi_clearline/ansi_clearline.ino +++ b/examples/ansi_clearline/ansi_clearline.ino @@ -51,8 +51,11 @@ void setup() delay(1000); } + void loop() { } + // -- END OF FILE -- + diff --git a/examples/ansi_performance/ansi_performance.ino b/examples/ansi_performance/ansi_performance.ino new file mode 100644 index 0000000..40a99ce --- /dev/null +++ b/examples/ansi_performance/ansi_performance.ino @@ -0,0 +1,64 @@ +// +// FILE: ansi_performance.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: start of performance print statement. +// DATE: 2021-12-13 +// URL: https://github.com/RobTillaart/ANSI +// (c) : MIT +// + + +#include "ansi.h" + +ANSI ansi(&Serial); + +int t; +double d; + +uint32_t start, stop; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.println(ANSI_LIB_VERSION); + Serial.println(); + delay(100); + + start = micros(); + ansi.println("PERFORMANCE TEST ANSI TERMINAL PRINT"); + stop = micros(); + Serial.print("ANSITERM:\t"); + Serial.println(stop - start); + delay(100); + + start = micros(); + Serial.println("PERFORMANCE TEST ANSI TERMINAL PRINT"); + stop = micros(); + Serial.print("SERIAL:\t\t"); + Serial.println(stop - start); + Serial.println(); + delay(100); + + start = micros(); + ansi.clearScreen(); + stop = micros(); + Serial.print("ANSITERM:\t"); + Serial.println(stop - start); + delay(100); + + start = micros(); + Serial.print("\033[2J\033[H"); + stop = micros(); + Serial.print("SERIAL:\t\t"); + Serial.println(stop - start); + delay(100); + +} + +void loop() +{ +} + +// -- END OF FILE -- diff --git a/examples/ansi_performance/performance_0.1.4.txt b/examples/ansi_performance/performance_0.1.4.txt new file mode 100644 index 0000000..19db8c7 --- /dev/null +++ b/examples/ansi_performance/performance_0.1.4.txt @@ -0,0 +1,7 @@ +ansi_performance.ino +0.1.4 + +PERFORMANCE TEST ANSI TERMINAL PRINT +ANSITERM: 376 +PERFORMANCE TEST ANSI TERMINAL PRINT +SERIAL: 300 diff --git a/examples/ansi_performance/performance_0.1.5.txt b/examples/ansi_performance/performance_0.1.5.txt new file mode 100644 index 0000000..b97892f --- /dev/null +++ b/examples/ansi_performance/performance_0.1.5.txt @@ -0,0 +1,11 @@ +ansi_performance.ino +0.1.5 + +PERFORMANCE TEST ANSI TERMINAL PRINT +ANSITERM: 352 +PERFORMANCE TEST ANSI TERMINAL PRINT +SERIAL: 300 + +(cleaned output of clearScreen(); test) +ANSITERM: 72 +SERIAL: 56 diff --git a/keywords.txt b/keywords.txt index 2314294..bf28789 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,8 +1,10 @@ # Syntax Colouring Map For ANSI + # Data types (KEYWORD1) ANSI KEYWORD1 + # Methods and Functions (KEYWORD2) normal KEYWORD2 bold KEYWORD2 @@ -29,6 +31,7 @@ gray2color KEYWORD2 grey2color KEYWORD2 rgb2color KEYWORD2 + # Constants (LITERAL1) toEnd LITERAL1 toStart LITERAL1 diff --git a/library.json b/library.json index 955424b..f36126d 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/ANSI.git" }, - "version": "0.1.4", + "version": "0.1.5", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index c84b38f..b70c146 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ANSI -version=0.1.4 +version=0.1.5 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library to send ANSI escape sequences