mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.4 LineFormatter
This commit is contained in:
parent
20f3630360
commit
121f872926
@ -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
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: LineFormatter.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: Simple positioning wrapper class for Serial
|
||||
// DATE: 2020-05-14
|
||||
// URL: https://github.com/RobTillaart/LineFormatter
|
||||
@ -12,7 +12,7 @@
|
||||
// 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();
|
||||
//
|
||||
// 0.1.4 2021-12-20 update library.json, license, minor edits
|
||||
|
||||
|
||||
#include "LineFormatter.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: LineFormatter.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// PURPOSE: Simple positioning wrapper class for Serial / Stream
|
||||
// DATE: 2020-05-14
|
||||
// URL: https://github.com/RobTillaart/LineFormatter
|
||||
@ -15,7 +15,7 @@
|
||||
#define MAX_TAB_STOPS 12
|
||||
#endif
|
||||
|
||||
#define LINEFORMATTER_LIB_VERSION (F("0.1.3"))
|
||||
#define LINEFORMATTER_LIB_VERSION (F("0.1.4"))
|
||||
|
||||
|
||||
class LineFormatter: public Print
|
||||
@ -34,7 +34,7 @@ public:
|
||||
|
||||
|
||||
// if position is smaller than n, move to the right
|
||||
uint8_t gotoPos(uint8_t n) { while (_pos < n) write(' '); return _pos; };
|
||||
uint8_t gotoPos(uint8_t pos) { while (_pos < pos) write(' '); return _pos; };
|
||||
|
||||
|
||||
// repeat a char or a "string" n times
|
||||
|
@ -22,7 +22,7 @@ for absolute positions and **andRelTab(n)** for relative positions.
|
||||
|
||||
Absolute tab positions must be added in increasing order as the class does not
|
||||
check the input. Also adding same value twice is not checked for. The maximum
|
||||
number of tabs is defined by **MAX_TAB_STOPS** == 10 default. This value canbe
|
||||
number of tabs is defined by **MAX_TAB_STOPS** == 12 default. This value can be
|
||||
overruled by -D compile flag or edited in the LineFormatter.h file.
|
||||
|
||||
Tab positions can be cleared by **clearTabs()**. This removes all tabs in one call.
|
||||
@ -54,24 +54,24 @@ Note: the maximum value is 255.
|
||||
#### 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
|
||||
- **uint8_t gotoPos(uint8_t pos)** if position is smaller than pos, 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
|
||||
- **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
|
||||
- **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
|
||||
- **void setAutoNewLine(uint8_t n)** n = 0 switches autoNewLine off.
|
||||
- **uint8_t getAutoNewLine()** returns number of newlines.
|
||||
|
||||
|
||||
@ -79,11 +79,11 @@ Note: the maximum value is 255.
|
||||
|
||||
For debugging purposes there are the following functions:
|
||||
|
||||
- **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 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)**
|
||||
- **uint8_t getTabStop(uint8_t n)** returns the n-th tab position.
|
||||
- **void printRuler()** prints a dotted line with 5 and 10 markers, and # for tab positions.
|
||||
|
||||
|
||||
@ -97,7 +97,13 @@ See examples
|
||||
- improve documentation
|
||||
- add examples
|
||||
- add reset();
|
||||
- check if print interface is completely covered.
|
||||
- set defaults for functions
|
||||
- add **rmTab(position)**
|
||||
-
|
||||
|
||||
#### Wont
|
||||
|
||||
- check if print interface is completely covered.
|
||||
- due to tab parsing it is, so no speed up.
|
||||
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
//
|
||||
// FILE: LineFormatter_Ethernet.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo LineFormatter for EthernetClient
|
||||
// DATE: 2020-05-23
|
||||
// URL: https://github.com/RobTillaart/LineFormatter
|
||||
//
|
||||
|
||||
|
||||
#include <LineFormatter.h>
|
||||
|
@ -1,11 +1,9 @@
|
||||
//
|
||||
// FILE: LineFormatter_SDcard.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo LineFormatter for SDcard
|
||||
// DATE: 2020-05-23
|
||||
// URL: https://github.com/RobTillaart/LineFormatter
|
||||
//
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
|
@ -1,18 +1,15 @@
|
||||
//
|
||||
// FILE: LineFormatter_test_repeat.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo LineFormatter class
|
||||
// URL: https://github.com/RobTillaart/LineFormatter
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2020-05-14 initial version
|
||||
//
|
||||
|
||||
|
||||
#include "LineFormatter.h"
|
||||
|
||||
LineFormatter L;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -29,10 +26,12 @@ void setup()
|
||||
L.println("Done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
void test_repeat()
|
||||
@ -57,13 +56,13 @@ void test_repeat()
|
||||
L.repeat(3, '\n');
|
||||
}
|
||||
|
||||
|
||||
void test_graph()
|
||||
{
|
||||
L.println();
|
||||
L.println(__FUNCTION__);
|
||||
L.repeat(strlen(__FUNCTION__), "=", 2);
|
||||
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
uint8_t n = 40 + 20 * sin(i * 0.3);
|
||||
@ -73,6 +72,7 @@ void test_graph()
|
||||
L.repeat(3, '\n');
|
||||
}
|
||||
|
||||
|
||||
void test_setMaxLength()
|
||||
{
|
||||
L.println();
|
||||
@ -88,3 +88,4 @@ void test_setMaxLength()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
//
|
||||
// FILE: LineFormatter_test_table.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo LineFormatter class
|
||||
// URL: https://github.com/RobTillaart/LineFormatter
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2020-05-14 initial version
|
||||
//
|
||||
|
||||
|
||||
#include "LineFormatter.h"
|
||||
|
@ -26,6 +26,7 @@ printRuler KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
MAX_TAB_STOPS LITERAL1
|
||||
LINEFORMATTER_LIB_VERSION LITERAL1
|
||||
|
||||
MAX_TAB_STOPS LITERAL1
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/LineFormatter.git"
|
||||
},
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "LineFormatter.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=LineFormatter
|
||||
version=0.1.3
|
||||
version=0.1.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Wrapper class for Serial to enhance layout of tabular data.
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "LINEFORMATTER_LIB_VERSION: %s\n", (char*) LINEFORMATTER_LIB_VERSION);
|
||||
}
|
||||
|
||||
unittest_teardown()
|
||||
@ -48,8 +49,6 @@ unittest_teardown()
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
fprintf(stderr, "LINEFORMATTER_LIB_VERSION: %s\n", (char*) LINEFORMATTER_LIB_VERSION);
|
||||
|
||||
LineFormatter Line;
|
||||
|
||||
assertEqual(0, Line.getMaxLength());
|
||||
|
Loading…
Reference in New Issue
Block a user