From bf245088e151bbeba3a614b1f37d28428cae6295 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Thu, 25 Nov 2021 12:55:36 +0100 Subject: [PATCH] 0.1.2 DEVNULL --- libraries/DEVNULL/.arduino-ci.yml | 10 ++- .../.github/workflows/arduino_test_runner.yml | 10 ++- libraries/DEVNULL/DEVNULL.h | 34 +++++-- libraries/DEVNULL/README.md | 53 +++++++++-- .../DEVNULL_performance.ino | 89 +++++++++++++++++++ .../DEVNULL_performance/performance_0.1.1.txt | 16 ++++ .../DEVNULL_performance/performance_0.1.2.txt | 15 ++++ libraries/DEVNULL/keywords.txt | 5 +- libraries/DEVNULL/library.json | 5 +- libraries/DEVNULL/library.properties | 2 +- 10 files changed, 215 insertions(+), 24 deletions(-) create mode 100644 libraries/DEVNULL/examples/DEVNULL_performance/DEVNULL_performance.ino create mode 100644 libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.1.txt create mode 100644 libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.2.txt diff --git a/libraries/DEVNULL/.arduino-ci.yml b/libraries/DEVNULL/.arduino-ci.yml index ff5659b9..e7cb4633 100644 --- a/libraries/DEVNULL/.arduino-ci.yml +++ b/libraries/DEVNULL/.arduino-ci.yml @@ -2,6 +2,10 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - - due - - zero + # - due + # - zero + # - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 \ No newline at end of file diff --git a/libraries/DEVNULL/.github/workflows/arduino_test_runner.yml b/libraries/DEVNULL/.github/workflows/arduino_test_runner.yml index 476456bb..096b975b 100644 --- a/libraries/DEVNULL/.github/workflows/arduino_test_runner.yml +++ b/libraries/DEVNULL/.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/DEVNULL/DEVNULL.h b/libraries/DEVNULL/DEVNULL.h index 8a1002b4..7a86c4e1 100644 --- a/libraries/DEVNULL/DEVNULL.h +++ b/libraries/DEVNULL/DEVNULL.h @@ -2,29 +2,51 @@ // // FILE: DEVNULL.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 -// PURPOSE: Arduino library for a /dev/null stream - usefull for testing +// VERSION: 0.1.2 +// PURPOSE: Arduino library for a /dev/null stream - useful for testing // URL: https://github.com/RobTillaart/DEVNULL // // HISTORY: -// 0.1.0 2020-06-23 initial version -// 0.1.1 2020-12-18 add arduino-ci + +// 0.1.0 2020-06-23 initial version. +// 0.1.1 2020-12-18 add Arduino-CI. +// 0.1.2 2021-11-24 update build-CI, badges, etc. +// added write(data, length) + _timeOut. + #include "Arduino.h" +#define DEVNULL_LIB_VERSION (F("0.1.2")) + + class DEVNULL : public Stream { public: - DEVNULL() {}; + DEVNULL() + { + setTimeout(0); // no timeout. + }; int available() { return 0; }; int peek() { return EOF; }; int read() { return EOF; }; void flush() { return; }; // placeholder to keep CI happy - size_t write(const uint8_t data) { _bottomLessPit = data; return 1; }; + + size_t write(const uint8_t data) + { + _bottomLessPit = data; + return 1; + }; + size_t write( const uint8_t *buffer, size_t size) + { + _bottomLessPit = buffer[size - 1]; + return size; + }; + private: uint8_t _bottomLessPit; }; + // -- END OF FILE -- + diff --git a/libraries/DEVNULL/README.md b/libraries/DEVNULL/README.md index 4f3f2fe7..8f898e43 100644 --- a/libraries/DEVNULL/README.md +++ b/libraries/DEVNULL/README.md @@ -1,20 +1,24 @@ [![Arduino CI](https://github.com/RobTillaart/DEVNULL/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/DEVNULL/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DEVNULL/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/DEVNULL/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DEVNULL/actions/workflows/jsoncheck.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DEVNULL/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/DEVNULL.svg?maxAge=3600)](https://github.com/RobTillaart/DEVNULL/releases) + # DEVNULL Arduino library for a /dev/null stream + ## Description -The library implements a stream class that mimics the /dev/null -device of a linux system. You can write everything to it, you can +The library implements a stream class that mimics the **/dev/null** +device of a Linux system. You can write everything to it, you can never read data from it as it always returns EOF (end of file); -THe 0.1.0 version is a minimal implementation that can be optimized. -Now it only implements the **write()** call and e.g. a float is still +The 0.1.0 version is a minimal implementation that can be optimized. +it implements the **write(const uint8_t data)** call and e.g. a float is still converted to individual characters that are send one after another. Strings and text send every byte. @@ -22,10 +26,45 @@ The advantage is that printing takes time and e.g. one can use it to measure the **print** class performance. Performance can be increased by implementing all methods of the print interface -with only a return 0; +with only a return 0; (or at least **print(Type)** as the **println(T)** would only +call once extra for the "\n". + + +#### Version 0.1.2 + +- sets the timeout for reading to 0. No need to wait longer with DEVNULl. + this improves the **find(...)** calls substantially. +- added **size_t write( const uint8_t \*buffer, size_t size)** for faster string processing. + + +## Interface + +- **DEVNULL()** constructor, sets the timeout to zero. +- **int available()** always return zero. +- **int peek()** always returns EOF. +- **int read()** always return EOF. +- **void flush()** does nothing but keeps some compilers happy. +- **size_t write(const uint8_t data)** implements print interface. returns 1. + +0.1.2 added to improve performance a few percent (UNO). + +- **size_t write( const uint8_t \*buffer, size_t size)** implements print interface. returns size. + ## Operation -use with care +Use with care. + +See examples. + + +## Future + +- add optional delay to mimic pause / tune behaviour for simulating other devices + microseconds - milliseconds? + delay per byte or per call to write? (esp long arrays might need other performance + feels out of scope for /dev/null +- add byte counter (uint32_t) +- add lastWrittenByte() - look at the last byte written to the bottomless pit. + -See example diff --git a/libraries/DEVNULL/examples/DEVNULL_performance/DEVNULL_performance.ino b/libraries/DEVNULL/examples/DEVNULL_performance/DEVNULL_performance.ino new file mode 100644 index 00000000..3876432e --- /dev/null +++ b/libraries/DEVNULL/examples/DEVNULL_performance/DEVNULL_performance.ino @@ -0,0 +1,89 @@ +// +// FILE: DEVNULL_performance.ino +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// PURPOSE: demo +// DATE: 2021-11-24 +// (c) : MIT +// + + +#include "DEVNULL.h" + +DEVNULL dn; + +uint32_t start, stop; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("DEVNULL_LIB_VERSION: "); + // Serial.println(DEVNULL_LIB_VERSION); + + start = micros(); + dn.println("it is dark in here..."); + stop = micros(); + Serial.print("text1: \t"); + Serial.println(stop - start); + delay(10); + + start = micros(); + // dn.write("it is dark in here...", 22); + stop = micros(); + Serial.print("text2: \t"); + Serial.println(stop - start); + delay(10); + + start = micros(); + dn.print(123456789L); + stop = micros(); + Serial.print("long: \t"); + Serial.println(stop - start); + delay(10); + + start = micros(); + dn.print(PI, 5); + stop = micros(); + Serial.print("float: \t"); + Serial.println(stop - start); + delay(10); + + start = micros(); + dn.print(PI, 10); + stop = micros(); + Serial.print("float: \t"); + Serial.println(stop - start); + delay(10); + + start = micros(); + dn.print(PI, 15); + stop = micros(); + Serial.print("float: \t"); + Serial.println(stop - start); + delay(10); + + start = micros(); + dn.print(PI, 20); + stop = micros(); + Serial.print("float: \t"); + Serial.println(stop - start); + delay(10); + + start = micros(); + bool b = dn.find("hello"); + stop = micros(); + Serial.print("find: \t"); + Serial.println(stop - start); + delay(10); + + Serial.println("Done..."); +} + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.1.txt b/libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.1.txt new file mode 100644 index 00000000..2d7a7af5 --- /dev/null +++ b/libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.1.txt @@ -0,0 +1,16 @@ +// test run on IDE 1.8.13 UNO +// test run while working on improvements for 0.1.2) + +DEVNULL_performance.ino +DEVNULL_LIB_VERSION: 0.1.1 +text1: 80 +text2: 0 +long: 384 +float: 616 +float: 1144 +float: 1684 +float: 2216 +find: 998580 +Done... + + diff --git a/libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.2.txt b/libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.2.txt new file mode 100644 index 00000000..aca6c6ad --- /dev/null +++ b/libraries/DEVNULL/examples/DEVNULL_performance/performance_0.1.2.txt @@ -0,0 +1,15 @@ +// test run on IDE 1.8.13 UNO + +DEVNULL_performance.ino +DEVNULL_LIB_VERSION: 0.1.2 +text1: 20 +text2: 4 +long: 356 +float: 592 +float: 1092 +float: 1604 +float: 2120 +find: 8 +Done... + + diff --git a/libraries/DEVNULL/keywords.txt b/libraries/DEVNULL/keywords.txt index b2a233c6..1cf2d941 100644 --- a/libraries/DEVNULL/keywords.txt +++ b/libraries/DEVNULL/keywords.txt @@ -1,9 +1,10 @@ -# Syntax Coloring Map For DEVNULL +# Syntax Colouring Map For DEVNULL -# Datatypes (KEYWORD1) +# Data types (KEYWORD1) DEVNULL KEYWORD1 # Methods and Functions (KEYWORD2) +# all known from Stream. # Instances (KEYWORD2) diff --git a/libraries/DEVNULL/library.json b/libraries/DEVNULL/library.json index 5a29ae56..a7749fd7 100644 --- a/libraries/DEVNULL/library.json +++ b/libraries/DEVNULL/library.json @@ -15,8 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/DEVNULL.git" }, - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "DEVNULL.h" } diff --git a/libraries/DEVNULL/library.properties b/libraries/DEVNULL/library.properties index 7242d980..982015f5 100644 --- a/libraries/DEVNULL/library.properties +++ b/libraries/DEVNULL/library.properties @@ -1,5 +1,5 @@ name=DEVNULL -version=0.1.1 +version=0.1.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for a /dev/null stream