mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.2 DEVNULL
This commit is contained in:
parent
9b3643e687
commit
bf245088e1
@ -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
|
@ -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
|
||||
|
@ -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 --
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 --
|
@ -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...
|
||||
|
||||
|
@ -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...
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DEVNULL
|
||||
version=0.1.1
|
||||
version=0.1.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for a /dev/null stream
|
||||
|
Loading…
Reference in New Issue
Block a user