add Arduino-CI

This commit is contained in:
rob tillaart 2021-01-04 16:38:24 +01:00
parent 9757263b82
commit 5d408b086a
9 changed files with 230 additions and 47 deletions

7
.arduino-ci.yml Normal file
View File

@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero

View File

@ -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

View File

@ -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

View File

@ -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};
@ -37,6 +40,7 @@ ParallelPrinter::ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint
}
}
void ParallelPrinter::begin(uint8_t lineLength, uint8_t pageLength)
{
_pos = 0;

View File

@ -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,50 @@ 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);
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; };
uint8_t getLineLength() { return _lineLength; };
uint8_t getPageLength() { return _pageLength; };
uint8_t getLineNumber() { return _lineNr; };
uint8_t getPageNumber() { return _pageNr; };
uint8_t getPosition() { return _pageNr; };
// n = 2,4,6,8
void setTabSize(uint8_t 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; };
// n = typical 2000; use with care
void setStrobeDelay(uint16_t n) { _strobeDelay = n; };
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;
};

View File

@ -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,49 @@ 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
- **getLineLength()** idem
- **getPageLength()** idem
- **getLineNumber()** idem
- **getPageNumber()** idem
- **getPosition()** idem
- **setTabSize(n)** tabs are replaced by spaces. n = 2,4,6,8
- **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

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ParallelPrinter.git"
},
"version":"0.2.0",
"version":"0.2.1",
"frameworks": "arduino",
"platforms": "*"
}

View File

@ -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.

128
test/unit_test_001.cpp Normal file
View File

@ -0,0 +1,128 @@
//
// 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;
assertEqual(0, PP.getLineLength());
assertEqual(0, PP.getPageLength());
assertEqual(0, PP.getLineNumber());
assertEqual(0, PP.getPageNumber());
assertEqual(0, PP.getPosition());
assertEqual(0, PP.getTabSize());
assertEqual(0, PP.getLineFeed());
PP.formfeed();
PP.println("This is a test");
PP.print("Hello World";
assertEqual(0, PP.getLineNumber());
assertEqual(0, PP.getPageNumber());
assertEqual(0, PP.getPosition());
}
unittest(test_tabs_linefeed)
{
fprintf(stderr, "VERSION: %s\n", PARALLELPRINTER_VERSION);
ParallelPrinter PP;
for (int tab = 0; tab < 10; tab +=2 )
{
fprintf(stderr, "%d\t", tab);
PP.setTabSize(tab):
assertEqual(tab, PP.getTabSize());
}
for (int LF = 0; LF < 10; LF +=2 )
{
fprintf(stderr, "%d\t", LF);
PP.setLineFeed(LF):
assertEqual(LF, PP.getLineFeed());
}
}
unittest(test_OutOfPaper)
{
GodmodeState* state = GODMODE();
state->reset();
ParallelPrinter PP;
state->digitalPin[12] = 0;
assertFalse(PP.isOutOfPaper());
state->digitalPin[12] = 1;
assertTrue(PP.isOutOfPaper());
}
unittest_main()
// --------