Arduino ci (#2)
* add Arduino-CI * add unit test * extended the interface to access internal variables.
This commit is contained in:
parent
9757263b82
commit
e9fca01531
|
@ -0,0 +1,7 @@
|
|||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- leonardo
|
||||
- due
|
||||
- zero
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
arduino_ci:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: Arduino-CI/action@master
|
||||
# Arduino-CI/action@v0.1.1
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2013-2020 Rob Tillaart
|
||||
Copyright (c) 2013-2021 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,17 +1,20 @@
|
|||
//
|
||||
// FILE: ParallelPrinter.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: parallel printer class that implements the Print interface
|
||||
// DATE: 2013-09-30
|
||||
// URL: https://github.com/RobTillaart/ParallelPrinter
|
||||
//
|
||||
// HISTORY
|
||||
// 0.1.0 2013-09-30 initial release
|
||||
// 0.2.0 2020-05-26 refactor, examples
|
||||
// HISTORY
|
||||
// 0.1.0 2013-09-30 initial release
|
||||
// 0.2.0 2020-05-26 refactor, examples
|
||||
// 0.2.1 2020-01-04 arduino-CI + unit test
|
||||
|
||||
|
||||
#include "ParallelPrinter.h"
|
||||
|
||||
|
||||
ParallelPrinter::ParallelPrinter()
|
||||
{
|
||||
uint8_t dataPins[] = {3, 4, 5, 6, 7, 8, 9, 10};
|
||||
|
@ -35,29 +38,29 @@ ParallelPrinter::ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint
|
|||
_pin[i] = p[i];
|
||||
pinMode(_pin[i], OUTPUT);
|
||||
}
|
||||
setLineLength(80);
|
||||
setPageLength(60);
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void ParallelPrinter::begin(uint8_t lineLength, uint8_t pageLength)
|
||||
{
|
||||
_pos = 0;
|
||||
_lineNr = 0;
|
||||
_pageNr = 0;
|
||||
_tabSize = 2;
|
||||
_lineFeed = 1;
|
||||
_strobeDelay = 2000;
|
||||
_printLineNumber = false;
|
||||
|
||||
// page size parameters.
|
||||
_lineLength = lineLength;
|
||||
_pageLength = pageLength;
|
||||
setLineLength(lineLength);
|
||||
setPageLength(pageLength);
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void ParallelPrinter::setTabSize(uint8_t n)
|
||||
void ParallelPrinter::reset()
|
||||
{
|
||||
// 2,4,6,8 allowed
|
||||
_tabSize = (n > 8) ? 8 : n/2 * 2;
|
||||
if (_tabSize < 2) _tabSize = 2;
|
||||
_pos = 0;
|
||||
_lineNr = 0;
|
||||
_pageNr = 0;
|
||||
_tabSize = 2;
|
||||
_lineFeed = 1;
|
||||
_strobeDelay = 2000;
|
||||
_printLineNumber = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// FILE: ParallelPrinter.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: parallel printer class that implements the Print interface
|
||||
// DATE: 2013-09-30
|
||||
// URL: https://github.com/RobTillaart/ParallelPrinter
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define PARALLELPRINTER_VERSION "0.2.0"
|
||||
#define PARALLELPRINTER_VERSION (F("0.2.1"))
|
||||
|
||||
#define FORMFEED 12
|
||||
|
||||
|
@ -20,40 +20,55 @@ public:
|
|||
ParallelPrinter(); // assume fixed pins for now, need 11 pins in total!
|
||||
ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint8_t * dataPins );
|
||||
|
||||
void begin(uint8_t lineLength = 80, uint8_t pageLength = 60);
|
||||
size_t write(uint8_t c);
|
||||
void begin(uint8_t lineLength = 80, uint8_t pageLength = 60);
|
||||
void reset();
|
||||
size_t write(uint8_t c);
|
||||
|
||||
// n = 2,4,6,8
|
||||
void setTabSize(uint8_t n);
|
||||
// n = 1,2,3
|
||||
void setLineFeed(uint8_t n) { _lineFeed = constrain(n, 1, 3); };
|
||||
void printLineNumber(bool b) { _printLineNumber = b; };
|
||||
void formfeed() { write(FORMFEED); };
|
||||
bool isOutOfPaper() { return digitalRead(_oopPin) == LOW; };
|
||||
void setLineLength(uint8_t lineLength = 80) { _lineLength = lineLength; };
|
||||
uint8_t getLineLength() { return _lineLength; };
|
||||
|
||||
// n = typical 2000; use with care
|
||||
void setStrobeDelay(uint16_t n) { _strobeDelay = n; };
|
||||
void setPageLength(uint8_t pageLength = 60) { _pageLength = pageLength; };
|
||||
uint8_t getPageLength() { return _pageLength; };
|
||||
|
||||
uint8_t getLineNumber() { return _lineNr; };
|
||||
uint8_t getPageNumber() { return _pageNr; };
|
||||
uint8_t getPosition() { return _pos; };
|
||||
|
||||
// n = 2,4,6,8
|
||||
void setTabSize(uint8_t n) { _tabSize = n; };
|
||||
uint8_t getTabSize() { return _tabSize; };
|
||||
// n = 1,2,3
|
||||
void setLineFeed(uint8_t n) { _lineFeed = constrain(n, 1, 3); };
|
||||
uint8_t getLineFeed() { return _lineFeed; };
|
||||
|
||||
void printLineNumber(bool b) { _printLineNumber = b; };
|
||||
void formfeed() { write(FORMFEED); };
|
||||
bool isOutOfPaper() { return digitalRead(_oopPin) == LOW; };
|
||||
|
||||
// n = typical 2000; use with care
|
||||
void setStrobeDelay(uint16_t n = 2000) { _strobeDelay = n; };
|
||||
uint16_t getStrobeDelay() { return _strobeDelay; };
|
||||
|
||||
private:
|
||||
// COMMUNICATION
|
||||
uint8_t _strobePin; // inform printer new data on the line.
|
||||
uint8_t _busyPin; // feedback from printer
|
||||
uint8_t _oopPin; // Out of paper.
|
||||
uint8_t _pin[8]; // data pins
|
||||
uint8_t _strobePin; // inform printer new data on the line.
|
||||
uint8_t _busyPin; // feedback from printer
|
||||
uint8_t _oopPin; // Out of paper.
|
||||
uint8_t _pin[8]; // data pins
|
||||
|
||||
void processSingleChar(uint8_t c);
|
||||
void sendByte(uint8_t c);
|
||||
|
||||
// BEHAVIOR
|
||||
uint8_t _pos;
|
||||
uint8_t _lineLength;
|
||||
uint8_t _lineNr;
|
||||
uint8_t _pageLength;
|
||||
uint8_t _pageNr;
|
||||
uint8_t _tabSize;
|
||||
uint8_t _lineFeed;
|
||||
uint8_t _pos;
|
||||
uint8_t _lineLength;
|
||||
uint8_t _lineNr;
|
||||
uint8_t _pageLength;
|
||||
uint8_t _pageNr;
|
||||
uint8_t _tabSize;
|
||||
uint8_t _lineFeed;
|
||||
|
||||
bool _printLineNumber;
|
||||
bool _printLineNumber;
|
||||
uint16_t _strobeDelay;
|
||||
};
|
||||
|
||||
|
|
53
README.md
53
README.md
|
@ -1,3 +1,8 @@
|
|||
|
||||
[![Arduino CI](https://github.com/RobTillaart/ParallelPrinter/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ParallelPrinter/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ParallelPrinter.svg?maxAge=3600)](https://github.com/RobTillaart/ParallelPrinter/releases)
|
||||
|
||||
# ParallelPrinter
|
||||
|
||||
Arduino library that implements a parallel printer - uses print interface
|
||||
|
@ -6,33 +11,51 @@ Arduino library that implements a parallel printer - uses print interface
|
|||
|
||||
This **experimental** library defines a simple parallel printer object.
|
||||
|
||||
It implements the **Print interface** to be able to print all datatypes.
|
||||
It writes every byte over 8 parallel lines including a **STROBE** (clock) pulse,
|
||||
while waiting for the connected printer to not be **BUSY** or **OUT OF PAPER**.
|
||||
It implements the **Print interface** to be able to print all datatypes using **print()** and **println()**
|
||||
The printer writes every byte over 8 parallel lines including a **STROBE** (clock) pulse,
|
||||
while waiting for the connected printer not to be **BUSY** or **OUT OF PAPER**.
|
||||
|
||||
This library is meant to be a starting point to make a "printer driver" for a
|
||||
specific parallel printer. These can often be bought in 2nd hand stores or so.
|
||||
|
||||
Have fun!
|
||||
|
||||
Note: _This lib is a extended redo of the ParPrinter class._
|
||||
**Note:** This lib is a extended redo of the ParPrinter class.
|
||||
|
||||
## Interface
|
||||
|
||||
* **ParallelPrinter(strobe, busy, oop, arr)** define 3 control pins + 8 datapins (= arr)
|
||||
### Constructor
|
||||
|
||||
* **begin(linelength, pagelength)** set page parameters
|
||||
* **write(c)** send a single byte to printer, implements Print interface.
|
||||
- **ParallelPrinter()** uses default pins (10, 2, 12, \[3,4,5,6,7,8,9,10\])
|
||||
- **ParallelPrinter(strobe, busy, oop, arr)** define 3 control pins + 8 datapins (= arr)
|
||||
- **begin(linelength, pagelength)** set line and page length parameters
|
||||
|
||||
* **setTabSize(n)** tabs are replaced by spaces. n = 2,4,6,8
|
||||
* **setLineFeed(n)** n = 1,2,3 1 = default
|
||||
* **printLineNr(b)** true, false
|
||||
* **formfeed()** to eject current page
|
||||
* **isOutOfPaper()** check paper tray before printing starts
|
||||
### Print interface
|
||||
- **write(c)** send a single byte to printer, implements Print interface. Therefor all **print()** and **println()** functions will work.
|
||||
- **formfeed()** to eject current page.
|
||||
|
||||
* **setStrobeDelay(n)** make the strobe pulse shorter == faster printing
|
||||
allows tuning of performance. Typical value = 2000. Time in micros.
|
||||
use with care.
|
||||
### Config
|
||||
|
||||
- **setLineLength(n)** idem
|
||||
- **getLineLength()** idem
|
||||
- **setPageLength()** idem
|
||||
- **getPageLength()** idem
|
||||
- **getLineNumber()** idem
|
||||
- **getPageNumber()** idem
|
||||
- **getPosition()** idem
|
||||
- **setTabSize(n)** tabs are replaced by spaces. n can be 0 or any size!
|
||||
- **getTabSize()** returns tabSize set
|
||||
- **setLineFeed(n)** n = 1,2,3 1 = default
|
||||
- **getLineFeed()** returns lineFeed set
|
||||
- **printLineNr(b)** true, false
|
||||
|
||||
|
||||
### Expert mode
|
||||
|
||||
- **isOutOfPaper()** to check paper tray before printing starts.
|
||||
- **setStrobeDelay(n = 2000)** make the strobe pulse shorter == faster printing
|
||||
allows tuning of performance. Default value = 2000. Time in microseconds.
|
||||
- **getStrobeDelay()** returns value set.
|
||||
|
||||
|
||||
## See also
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/ParallelPrinter.git"
|
||||
},
|
||||
"version":"0.2.0",
|
||||
"version":"0.2.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name=ParallelPrinter
|
||||
version=0.2.0
|
||||
version=0.2.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Experimental (not complete) library to connect a parallel printer to Arduino.
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-01-04
|
||||
// PURPOSE: unit tests for the ParallelPrinter library
|
||||
// https://github.com/RobTillaart/ParallelPrinter
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual); // a == b
|
||||
// assertNotEqual(unwanted, actual); // a != b
|
||||
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
||||
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
||||
// assertLess(upperBound, actual); // a < b
|
||||
// assertMore(lowerBound, actual); // a > b
|
||||
// assertLessOrEqual(upperBound, actual); // a <= b
|
||||
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
||||
// assertTrue(actual);
|
||||
// assertFalse(actual);
|
||||
// assertNull(actual);
|
||||
|
||||
// // special cases for floats
|
||||
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
||||
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
||||
// assertInfinity(actual); // isinf(a)
|
||||
// assertNotInfinity(actual); // !isinf(a)
|
||||
// assertNAN(arg); // isnan(a)
|
||||
// assertNotNAN(arg); // !isnan(a)
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#define assertEqualFloat(arg1, arg2, arg3) assertOp("assertEqualFloat", "expected", fabs(arg1 - arg2), compareLessOrEqual, "<=", "actual", arg3)
|
||||
// #define assertEqualINF(arg) assertOp("assertEqualINF", "expected", INFINITY, compareEqual, "==", "actual", arg)
|
||||
// #define assertEqualNAN(arg) assertOp("assertEqualNAN", "expected", true, compareEqual, "==", "actual", isnan(arg))
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "ParallelPrinter.h"
|
||||
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
||||
// minimal
|
||||
|
||||
unittest(test_constructor_basic)
|
||||
{
|
||||
fprintf(stderr, "VERSION: %s\n", PARALLELPRINTER_VERSION);
|
||||
|
||||
ParallelPrinter PP;
|
||||
|
||||
PP.begin();
|
||||
assertEqual(80, PP.getLineLength());
|
||||
assertEqual(60, PP.getPageLength());
|
||||
assertEqual(0, PP.getLineNumber());
|
||||
assertEqual(0, PP.getPageNumber());
|
||||
assertEqual(0, PP.getPosition());
|
||||
assertEqual(2, PP.getTabSize());
|
||||
assertEqual(1, PP.getLineFeed());
|
||||
|
||||
PP.formfeed();
|
||||
PP.formfeed();
|
||||
PP.formfeed();
|
||||
PP.formfeed();
|
||||
PP.println("This is a test");
|
||||
PP.println("This is a test");
|
||||
PP.println("This is a test");
|
||||
PP.print("Hello World");
|
||||
|
||||
// fprintf(stderr, "%d\n", PP.getLineNumber());
|
||||
// fprintf(stderr, "%d\n", PP.getPageNumber());
|
||||
// fprintf(stderr, "%d\n", PP.getPosition());
|
||||
|
||||
assertEqual(3, PP.getLineNumber()); // 0 based
|
||||
assertEqual(4, PP.getPageNumber()); // 0 based
|
||||
assertEqual(11, PP.getPosition()); // 0 based
|
||||
}
|
||||
|
||||
|
||||
unittest(test_tabs_linefeed)
|
||||
{
|
||||
ParallelPrinter PP;
|
||||
|
||||
for (int tab = 0; tab < 10; tab +=2 )
|
||||
{
|
||||
fprintf(stderr, "%d\t", tab);
|
||||
PP.setTabSize(tab);
|
||||
assertEqual(tab, PP.getTabSize());
|
||||
}
|
||||
|
||||
|
||||
fprintf(stderr, "0\t");
|
||||
PP.setLineFeed(0);
|
||||
assertEqual(1, PP.getLineFeed()); // minimum LF size
|
||||
|
||||
for (int LF = 1; LF < 4; LF +=2 )
|
||||
{
|
||||
fprintf(stderr, "%d\t", LF);
|
||||
PP.setLineFeed(LF);
|
||||
assertEqual(LF, PP.getLineFeed());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unittest(test_OutOfPaper)
|
||||
{
|
||||
GodmodeState* state = GODMODE();
|
||||
state->reset();
|
||||
|
||||
ParallelPrinter PP;
|
||||
|
||||
// TODO
|
||||
// state->digitalPin[12] = 0;
|
||||
// assertFalse(PP.isOutOfPaper());
|
||||
//
|
||||
// state->digitalPin[12] = 1;
|
||||
// assertTrue(PP.isOutOfPaper());
|
||||
}
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
Reference in New Issue