diff --git a/libraries/LineFormatter/.arduino-ci.yml b/libraries/LineFormatter/.arduino-ci.yml index ae8c403b..96747733 100644 --- a/libraries/LineFormatter/.arduino-ci.yml +++ b/libraries/LineFormatter/.arduino-ci.yml @@ -2,9 +2,13 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - - due - - zero + # - due + # - zero + # - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 libraries: - "Ethernet" - - "SD" \ No newline at end of file + - "SD" diff --git a/libraries/LineFormatter/.github/workflows/arduino_test_runner.yml b/libraries/LineFormatter/.github/workflows/arduino_test_runner.yml index 476456bb..096b975b 100644 --- a/libraries/LineFormatter/.github/workflows/arduino_test_runner.yml +++ b/libraries/LineFormatter/.github/workflows/arduino_test_runner.yml @@ -4,10 +4,14 @@ name: Arduino CI on: [push, pull_request] jobs: - arduino_ci: + runTest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: Arduino-CI/action@master - # Arduino-CI/action@v0.1.1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/LineFormatter/LineFormatter.cpp b/libraries/LineFormatter/LineFormatter.cpp index cfaf570a..ff6ad11c 100644 --- a/libraries/LineFormatter/LineFormatter.cpp +++ b/libraries/LineFormatter/LineFormatter.cpp @@ -1,8 +1,8 @@ // // FILE: LineFormatter.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 -// PURPOSE: Simpe positioning wrapper class for Serial +// VERSION: 0.1.3 +// PURPOSE: Simple positioning wrapper class for Serial // DATE: 2020-05-14 // URL: https://github.com/RobTillaart/LineFormatter // @@ -10,21 +10,30 @@ // 0.1.0 2020-05-14 initial version // 0.1.1 2020-06-19 fix library.json // 0.1.2 2020-12-30 Arduino-ci + unit tests +// 0.1.3 2021-11-06 update Arduino-CI, badges +// update readme.md, add reset(); +// #include "LineFormatter.h" + LineFormatter::LineFormatter(Print* stream) { _stream = stream; - // reset + reset(); +}; + + +void LineFormatter::reset() +{ _pos = 0; _maxPos = 0; _lineCount = 0; _anl = 0; _autoNewLine = 0; _tabCount = 0; -}; +} /////////////////////////////////////////// @@ -75,6 +84,7 @@ size_t LineFormatter::write(uint8_t c) return 1; } + /////////////////////////////////////////// // // REPEAT @@ -85,12 +95,14 @@ void LineFormatter::repeat(uint8_t n, char c, uint8_t newLine) while (newLine--) write('\n'); } + void LineFormatter::repeat(uint8_t n, const char* str, uint8_t newLine) { while (n--) print(str); while (newLine--) write('\n'); } + /////////////////////////////////////////// // // AUTONEWLINE @@ -101,6 +113,7 @@ void LineFormatter::setAutoNewLine(uint8_t n) _anl = 0; }; + /////////////////////////////////////////// // // TAB @@ -114,6 +127,7 @@ void LineFormatter::clearTabs() } }; + bool LineFormatter::addTab(uint8_t n) { if (_tabCount >= MAX_TAB_STOPS) return false; @@ -122,6 +136,7 @@ bool LineFormatter::addTab(uint8_t n) return true; } + bool LineFormatter::addRelTab(uint8_t n) { if (_tabCount >= MAX_TAB_STOPS) return false; @@ -131,6 +146,7 @@ bool LineFormatter::addRelTab(uint8_t n) return true; } + /////////////////////////////////////////// // // DEBUGGING @@ -156,4 +172,6 @@ void LineFormatter::printRuler(uint8_t n) write('\n'); } + // -- END OF FILE -- + diff --git a/libraries/LineFormatter/LineFormatter.h b/libraries/LineFormatter/LineFormatter.h index 8d14471f..a2c3d4ba 100644 --- a/libraries/LineFormatter/LineFormatter.h +++ b/libraries/LineFormatter/LineFormatter.h @@ -2,8 +2,8 @@ // // FILE: LineFormatter.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 -// PURPOSE: Simpe positioning wrapper class for Serial +// VERSION: 0.1.3 +// PURPOSE: Simple positioning wrapper class for Serial / Stream // DATE: 2020-05-14 // URL: https://github.com/RobTillaart/LineFormatter // @@ -15,29 +15,39 @@ #define MAX_TAB_STOPS 12 #endif +#define LINEFORMATTER_LIB_VERSION (F("0.1.3")) + + class LineFormatter: public Print { public: LineFormatter(Print* stream = &Serial); + void reset(); + size_t write(uint8_t c); + // set the maximum line length - bold cut off void setMaxLength(uint8_t maxPos) { _maxPos = maxPos; }; uint8_t getMaxLength() { return _maxPos; }; + // if position is smaller than n, move to the right uint8_t gotoPos(uint8_t n) { while (_pos < n) write(' '); return _pos; }; + // repeat a char or a "string" n times // followed by 0 or more newlines. void repeat(uint8_t n, char c, uint8_t newLine = 0); void repeat(uint8_t n, const char* str, uint8_t newLine = 0); + // n = 0 switches autoNewLine off void setAutoNewLine(uint8_t n); uint8_t getAutoNewLine() { return _autoNewLine; }; + // Add a tab at (absolute/relative) position // returns true on success bool addTab(uint8_t n); @@ -55,8 +65,10 @@ public: uint8_t getTabStop(uint8_t n) { return _tabStop[n]; }; void printRuler(uint8_t n); + private: Print * _stream; + uint8_t _pos = 0; uint8_t _maxPos = 0; uint16_t _lineCount = 0; @@ -67,4 +79,6 @@ private: uint8_t _tabCount = 0; }; + // -- END OF FILE -- + diff --git a/libraries/LineFormatter/README.md b/libraries/LineFormatter/README.md index 7f0f6f29..13de81ae 100644 --- a/libraries/LineFormatter/README.md +++ b/libraries/LineFormatter/README.md @@ -1,12 +1,16 @@ [![Arduino CI](https://github.com/RobTillaart/LineFormatter/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/LineFormatter/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/LineFormatter/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/LineFormatter/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/LineFormatter/actions/workflows/jsoncheck.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/LineFormatter/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/LineFormatter.svg?maxAge=3600)](https://github.com/RobTillaart/LineFormatter/releases) + # LineFormatter Arduino library to enhance the layout of tabular data on serial output, + # Description LineFormatter is a wrapper class for Serial (and other streams) to enhance @@ -40,15 +44,60 @@ of positions to the right e.g. when copying a file from disk to Serial. Setting the value to 0 results in no maximum line length. Note: the maximum value is 255. + +## Interface + +- **LineFormatter(Print\* stream = &Serial)** constructor +- **reset()** reset internal variables to start over again. + + +#### Printing + +- **size_t write(uint8_t c)** implements print. +- **uint8_t gotoPos(uint8_t n)** if position is smaller than n, move to the right +- **void repeat(uint8_t n, char c, uint8_t newLine = 0)** repeat a char n times +- **void repeat(uint8_t n, const char\* str, uint8_t newLine = 0)** repeat a "string" n times + + +#### Tab configuration + +- **bool addTab(uint8_t n)** Add a tab at an absolute position. returns true on success +- **bool addRelTab(uint8_t n)** Add a tab at a relative position. returns true on success +- **void clearTabs()** remove all the tabs. +- **void tab(uint8_t n = 1)** print zero or more tabs, similar as e.g. "\t\t\t" + + +#### Line configuration + +- **void setMaxLength(uint8_t maxPos)** set the maximum line length - bold cut off +- **uint8_t getMaxLength()** return max line length set. +- **void setAutoNewLine(uint8_t n)** n = 0 switches autoNewLine off +- **uint8_t getAutoNewLine()** returns number of newlines. + + ### Debugging For debugging purposes there are the following functions: -- **getPos()** - returns current position -- **resetLineCount()** - sets internal lineCounter to zero -- **getLineCount()** - returns current line number (since last reset) -- **getTabCount()** - get the number of tab positions added. -- **printRuler()** - prints a dotted line with 5 and 10 markers, and # for tab positions. + +- **uint8_t getPos()** returns current position +- **void resetLineCount()** sets internal lineCounter to zero +- **uint16_t getLineCount()** returns current line number (since last reset) +- **uint8_t getTabCount()** get the number of tab positions added. +- **uint8_t getTabStop(uint8_t n)** +- **void printRuler()** prints a dotted line with 5 and 10 markers, and # for tab positions. + # Operational See examples + + +## Future + +- improve documentation +- add examples +- add reset(); +- check if print interface is completely covered. +- set defaults for functions +- add **rmTab(position)** +- diff --git a/libraries/LineFormatter/examples/LineFormatter_Ethernet/.arduino-ci.yml b/libraries/LineFormatter/examples/LineFormatter_Ethernet/.arduino-ci.yml new file mode 100644 index 00000000..93b62a90 --- /dev/null +++ b/libraries/LineFormatter/examples/LineFormatter_Ethernet/.arduino-ci.yml @@ -0,0 +1,14 @@ +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + - uno + # - due + # - zero + # - leonardo + - m4 + # - esp32 # has other server code + # - esp8266 + # - mega2560 + libraries: + - "Ethernet" + - "SD" diff --git a/libraries/LineFormatter/examples/LineFormatter_Ethernet/LineFormatter_Ethernet.ino b/libraries/LineFormatter/examples/LineFormatter_Ethernet/LineFormatter_Ethernet.ino index 2a1fb623..feed941e 100644 --- a/libraries/LineFormatter/examples/LineFormatter_Ethernet/LineFormatter_Ethernet.ino +++ b/libraries/LineFormatter/examples/LineFormatter_Ethernet/LineFormatter_Ethernet.ino @@ -7,6 +7,7 @@ // URL: https://github.com/RobTillaart/LineFormatter // + #include #include @@ -22,6 +23,7 @@ EthernetServer server(80); // change to your config char httpRequest[40]; uint8_t reqCnt; + //////////////////////////////////////////////////////////////////// // // HTTP HELPER CODE @@ -172,6 +174,7 @@ void loop() } } + void test_table_1(LineFormatter L) { L.println(); @@ -231,6 +234,7 @@ void test_table_1(LineFormatter L) L.repeat(3, '\n'); } + void test_table_2(LineFormatter L) { L.println(); @@ -291,4 +295,6 @@ void test_table_2(LineFormatter L) L.repeat(3, '\n'); } -// -- END OF FILE -- \ No newline at end of file + +// -- END OF FILE -- + diff --git a/libraries/LineFormatter/examples/LineFormatter_SDcard/LineFormatter_SDcard.ino b/libraries/LineFormatter/examples/LineFormatter_SDcard/LineFormatter_SDcard.ino index 658a99ff..9c12739e 100644 --- a/libraries/LineFormatter/examples/LineFormatter_SDcard/LineFormatter_SDcard.ino +++ b/libraries/LineFormatter/examples/LineFormatter_SDcard/LineFormatter_SDcard.ino @@ -7,6 +7,7 @@ // URL: https://github.com/RobTillaart/LineFormatter // + #include #include // SPI PINS @@ -18,6 +19,7 @@ #include + void setup() { Serial.begin(115200); @@ -54,7 +56,6 @@ void loop() } - void test_table(LineFormatter L) { L.println(); @@ -117,4 +118,6 @@ void test_table(LineFormatter L) L.repeat(3, '\n'); } -// -- END OF FILE -- \ No newline at end of file + +// -- END OF FILE -- + diff --git a/libraries/LineFormatter/examples/LineFormatter_test_table/LineFormatter_test_table.ino b/libraries/LineFormatter/examples/LineFormatter_test_table/LineFormatter_test_table.ino index 3d00fc56..081bac05 100644 --- a/libraries/LineFormatter/examples/LineFormatter_test_table/LineFormatter_test_table.ino +++ b/libraries/LineFormatter/examples/LineFormatter_test_table/LineFormatter_test_table.ino @@ -9,10 +9,12 @@ // 0.1.0 2020-05-14 initial version // + #include "LineFormatter.h" LineFormatter L; + void setup() { Serial.begin(115200); @@ -34,10 +36,12 @@ void setup() L.println("Done..."); } + void loop() { } + void test_ruler() { L.println(); @@ -62,6 +66,7 @@ void test_ruler() L.repeat(3, '\n'); } + void test_table_1() { L.println(); @@ -119,6 +124,7 @@ void test_table_1() L.repeat(3, '\n'); } + void test_table_2() { L.println(); @@ -178,4 +184,6 @@ void test_table_2() L.repeat(3, '\n'); } + // -- END OF FILE -- + diff --git a/libraries/LineFormatter/keywords.txt b/libraries/LineFormatter/keywords.txt index da85a1f0..6f13bc10 100644 --- a/libraries/LineFormatter/keywords.txt +++ b/libraries/LineFormatter/keywords.txt @@ -1,25 +1,31 @@ -# Syntax Coloring Map For LineFormatter +# Syntax Colouring Map For LineFormatter -# Datatypes (KEYWORD1) +# Data types (KEYWORD1) LineFormatter KEYWORD1 # Methods and Functions (KEYWORD2) +reset KEYWORD2 write KEYWORD2 setMaxLength KEYWORD2 gotoPos KEYWORD2 getPos KEYWORD2 repeat KEYWORD2 + resetLineCount KEYWORD2 getLineCount KEYWORD2 setAutoNewLine KEYWORD2 + addTab KEYWORD2 addRelTab KEYWORD2 clearTabs KEYWORD2 getTabCount KEYWORD2 + tab KEYWORD2 printRuler KEYWORD2 # Constants (LITERAL1) +MAX_TAB_STOPS LITERAL1 +LINEFORMATTER_LIB_VERSION LITERAL1 diff --git a/libraries/LineFormatter/library.json b/libraries/LineFormatter/library.json index 3c52d7bb..e3b8b970 100644 --- a/libraries/LineFormatter/library.json +++ b/libraries/LineFormatter/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/LineFormatter.git" }, - "version": "0.1.2", + "version": "0.1.3", "license": "MIT", "frameworks": "arduino", "platforms": "*" diff --git a/libraries/LineFormatter/library.properties b/libraries/LineFormatter/library.properties index 9d7901d3..59762a50 100644 --- a/libraries/LineFormatter/library.properties +++ b/libraries/LineFormatter/library.properties @@ -1,5 +1,5 @@ name=LineFormatter -version=0.1.2 +version=0.1.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Wrapper class for Serial to enhance layout of tabular data. diff --git a/libraries/LineFormatter/test/unit_test_001.cpp b/libraries/LineFormatter/test/unit_test_001.cpp index 278ac506..bf3bfb32 100644 --- a/libraries/LineFormatter/test/unit_test_001.cpp +++ b/libraries/LineFormatter/test/unit_test_001.cpp @@ -29,6 +29,7 @@ // assertNAN(arg); // isnan(a) // assertNotNAN(arg); // !isnan(a) + #include @@ -44,69 +45,60 @@ unittest_teardown() { } -/* -unittest(test_new_operator) -{ - assertEqualINF(exp(800)); - assertEqualINF(0.0/0.0); - assertEqualINF(42); - - assertEqualNAN(INFINITY - INFINITY); - assertEqualNAN(0.0/0.0); - assertEqualNAN(42); -} -*/ unittest(test_constructor) { - LineFormatter L; + fprintf(stderr, "LINEFORMATTER_LIB_VERSION: %s\n", (char*) LINEFORMATTER_LIB_VERSION); - assertEqual(0, L.getMaxLength()); - L.setMaxLength(80); - assertEqual(80, L.getMaxLength()); + LineFormatter Line; - assertEqual(0, L.getAutoNewLine()); - L.setAutoNewLine(5); - assertEqual(5, L.getAutoNewLine()); + assertEqual(0, Line.getMaxLength()); + Line.setMaxLength(80); + assertEqual(80, Line.getMaxLength()); + + assertEqual(0, Line.getAutoNewLine()); + Line.setAutoNewLine(5); + assertEqual(5, Line.getAutoNewLine()); } unittest(test_position) { - LineFormatter L; + LineFormatter Line; - assertEqual(0, (int)L.getPos()); - assertEqual(20, (int)L.gotoPos(20)); - assertEqual(20, (int)L.gotoPos(15)); + assertEqual(0, (int)Line.getPos()); + assertEqual(20, (int)Line.gotoPos(20)); + assertEqual(20, (int)Line.gotoPos(15)); - L.repeat(10, '*'); - assertEqual(30, (int)L.getPos()); - L.repeat(10, "--"); - assertEqual(50, (int)L.getPos()); + Line.repeat(10, '*'); + assertEqual(30, (int)Line.getPos()); + Line.repeat(10, "--"); + assertEqual(50, (int)Line.getPos()); } + unittest(test_tab) { - LineFormatter L; + LineFormatter Line; fprintf(stderr, "tab setting\n"); for (int i = 8; i <= 80; i += 8) { - L.addTab(i); + Line.addTab(i); } - assertEqual(10, L.getTabCount()); - for (int i = 0; i < L.getTabCount(); i++) + assertEqual(10, Line.getTabCount()); + for (int i = 0; i < Line.getTabCount(); i++) { fprintf(stderr, "%d\t", 8 + i*8); - assertEqual(8 + i*8, L.getTabStop(i)); + assertEqual(8 + i*8, Line.getTabStop(i)); } - fprintf(stderr, "tab test - !! cur pos is one before tab pos\n"); - for (int i = 0; i < L.getTabCount(); i++) + fprintf(stderr, "tab test - !! cur position is one before tab position\n"); + for (int i = 0; i < Line.getTabCount(); i++) { - fprintf(stderr, "%d\t", 8 + i*8); // tabpos - L.write('\t'); - assertEqual(8 + i*8, (int)L.getPos() + 1 ); // current pos is just before + fprintf(stderr, "%d\t", 8 + i*8); // tab positions + Line.write('\t'); + assertEqual(8 + i*8, (int)Line.getPos() + 1 ); // current position is just before tab } }