Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Rob Tillaart | ef43c007e0 | |
rob tillaart | dd8cc40840 | |
Rob Tillaart | a29596cc12 | |
rob tillaart | ed6fed3c41 | |
rob tillaart | 1dd306494e | |
rob tillaart | 77bd9a7e32 | |
rob tillaart | 5bf0f14ae6 | |
rob tillaart | 6eb460a2c3 | |
Rob Tillaart | 4c7c4d06ad | |
Rob Tillaart | e9fca01531 | |
Rob Tillaart | 9757263b82 | |
Ivan Kravets | 726847e91c |
|
@ -0,0 +1,11 @@
|
|||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
|
@ -0,0 +1,18 @@
|
|||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2013-2020 Rob Tillaart
|
||||
Copyright (c) 2013-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,17 +1,24 @@
|
|||
//
|
||||
// FILE: ParallelPrinter.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// VERSION: 0.2.4
|
||||
// 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 2021-01-04 Arduino-CI + unit test
|
||||
// 0.2.2 2021-01-14 update readme, add linefeed(), add keywords.txt
|
||||
// 0.2.3 2021-11-11 update Arduino-CI, readme,md
|
||||
// add isBusy();
|
||||
// 0.2.4 2021-12-23 update library.json, license, minor edits
|
||||
|
||||
|
||||
#include "ParallelPrinter.h"
|
||||
|
||||
|
||||
ParallelPrinter::ParallelPrinter()
|
||||
{
|
||||
uint8_t dataPins[] = {3, 4, 5, 6, 7, 8, 9, 10};
|
||||
|
@ -28,49 +35,49 @@ ParallelPrinter::ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint
|
|||
pinMode(_oopPin, INPUT);
|
||||
pinMode(_busyPin, INPUT);
|
||||
pinMode(_strobePin, OUTPUT);
|
||||
|
||||
|
||||
// DATA LINES
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
_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;
|
||||
}
|
||||
|
||||
|
||||
// write() implements the virtual write of the Print class
|
||||
size_t ParallelPrinter::write(uint8_t c)
|
||||
{
|
||||
if (c == '\t')
|
||||
if (c == '\t') // TAB
|
||||
{
|
||||
uint8_t spaces = _tabSize - _pos % _tabSize;
|
||||
for (uint8_t i = 0; i < spaces; i++) processSingleChar(' ');
|
||||
return spaces;
|
||||
}
|
||||
if (c == '\n')
|
||||
if (c == '\n') // LINEFEED
|
||||
{
|
||||
for (uint8_t i = 0; i < _lineFeed; i++)
|
||||
{
|
||||
|
@ -137,7 +144,7 @@ void ParallelPrinter::sendByte(uint8_t c)
|
|||
// BLOCK WHEN OUT OF PAPER TODO
|
||||
// while (digitalRead(_oopPin) == LOW) yield();
|
||||
// indication in hardware?
|
||||
|
||||
|
||||
Serial.write(c); // debugging
|
||||
return;
|
||||
|
||||
|
@ -162,3 +169,4 @@ void ParallelPrinter::sendByte(uint8_t c)
|
|||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
|
|
@ -2,17 +2,20 @@
|
|||
//
|
||||
// FILE: ParallelPrinter.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// VERSION: 0.2.4
|
||||
// PURPOSE: parallel printer class that implements the Print interface
|
||||
// DATE: 2013-09-30
|
||||
// URL: https://github.com/RobTillaart/ParallelPrinter
|
||||
//
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define PARALLELPRINTER_VERSION "0.2.0"
|
||||
|
||||
#define FORMFEED 12
|
||||
#define PARALLELPRINTER_VERSION (F("0.2.4"))
|
||||
|
||||
#define FORMFEED 12
|
||||
#define LINEFEED 10
|
||||
|
||||
|
||||
class ParallelPrinter: public Print
|
||||
{
|
||||
|
@ -20,41 +23,61 @@ 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; };
|
||||
|
||||
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); };
|
||||
void linefeed() { write(LINEFEED); };
|
||||
bool isOutOfPaper() { return digitalRead(_busyPin) == LOW; };
|
||||
bool isBusy() { return digitalRead(_oopPin) == HIGH; };
|
||||
|
||||
// n = typical 2000; use with care
|
||||
void setStrobeDelay(uint16_t n = 2000) { _strobeDelay = n; };
|
||||
uint16_t getStrobeDelay() { return _strobeDelay; };
|
||||
|
||||
// n = typical 2000; use with care
|
||||
void setStrobeDelay(uint16_t n) { _strobeDelay = n; };
|
||||
|
||||
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;
|
||||
|
||||
bool _printLineNumber;
|
||||
uint8_t _pos;
|
||||
uint8_t _lineLength;
|
||||
uint8_t _lineNr;
|
||||
uint8_t _pageLength;
|
||||
uint8_t _pageNr;
|
||||
uint8_t _tabSize;
|
||||
uint8_t _lineFeed;
|
||||
|
||||
bool _printLineNumber;
|
||||
uint16_t _strobeDelay;
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
|
95
README.md
95
README.md
|
@ -1,44 +1,103 @@
|
|||
|
||||
[![Arduino CI](https://github.com/RobTillaart/ParallelPrinter/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/ParallelPrinter/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ParallelPrinter/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/ParallelPrinter/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ParallelPrinter/actions/workflows/jsoncheck.yml)
|
||||
[![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
|
||||
Arduino library that implements a parallel printer (driver) - implements the PRINT interface.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
This **experimental** library defines a simple parallel printer object.
|
||||
This library defines a 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 data types
|
||||
using **write()**, **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** (OOP).
|
||||
|
||||
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 (13, 2, 12, \[3,4,5,6,7,8,9,10\])
|
||||
- **ParallelPrinter(uint8_t strobe, uint8_t busy, uint8_t oop, uint8_t \*arr)**
|
||||
define 3 control pins + 8 data pins (= arr\[8\]).
|
||||
- **void begin(uint8_t lineLength, uint8_t 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
|
||||
|
||||
* **setStrobeDelay(n)** make the strobe pulse shorter == faster printing
|
||||
allows tuning of performance. Typical value = 2000. Time in micros.
|
||||
use with care.
|
||||
### Print interface
|
||||
|
||||
- **size_t write(uint8_t c)** send a single byte to printer, implements Print interface.
|
||||
Therefore all **print()** and **println()** functions will work.
|
||||
- **void formfeed()** to eject current page or forced go to the next page.
|
||||
- **void linefeed()** send a linefeed.
|
||||
The number of actual lines is set by **setLineFeed()**
|
||||
|
||||
|
||||
### Configuration
|
||||
|
||||
These settings are pretty straightforward.
|
||||
|
||||
- **void setLineLength(uint8_t lineLength)** idem
|
||||
- **uint8_t getLineLength()** returns the current line length.
|
||||
- **void setPageLength(uint8_t pageLength)** idem
|
||||
- **uint8_t getPageLength()** returns the current page length.
|
||||
- **uint8_t getLineNumber()** returns current line number.
|
||||
- **uint8_t getPageNumber()** returns current page number.
|
||||
- **uint8_t getPosition()** returns the position on a line.
|
||||
- **uint8_t setTabSize(uint8_t tabsize)** tabs are replaced by spaces. n can be 0 or any size!
|
||||
- **uint8_t getTabSize()** returns tabSize set
|
||||
- **void setLineFeed(uint8_t lineFeeds)** lineFeeds = 1,2,3 1 = default.
|
||||
- **uint8_t getLineFeed()** returns lineFeeds set
|
||||
- **void printLineNr(bool b)** can be set to true, false.
|
||||
|
||||
|
||||
### Expert mode
|
||||
|
||||
- **bool isOutOfPaper()** to check paper tray before printing starts.
|
||||
- **void setStrobeDelay(uint16_t n = 2000)** allows tuning of performance.
|
||||
Make the strobe pulse shorter == faster printing (printer dependant).
|
||||
Default value = 2000. Time in microseconds.
|
||||
- **uint16_t getStrobeDelay()** returns value set.
|
||||
|
||||
**Note** mechanical printers e.g. dot matrix, really do need a way to stop receiving
|
||||
data as they do not have large buffers.
|
||||
|
||||
|
||||
## See also
|
||||
|
||||
https://en.wikipedia.org/wiki/Parallel_port#Centronics
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- update documentation
|
||||
- extend unit tests?
|
||||
- test more.
|
||||
- extend simulator sketch.
|
||||
- Make a front end of a parallel printer,
|
||||
- Accepts the clocked bytes and print them e.g. over serial.
|
||||
- derive e.g. an HP or an EPSON printer from this class.
|
||||
- special modes e.g. bold italic underline.
|
||||
- **write(uint8_t \* buf, uint8_t length)** should be added
|
||||
- might not really add to performance..
|
||||
- fix blocking TODO in sendByte
|
||||
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See examples
|
||||
See examples.
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
//
|
||||
// FILE: ParPrinter_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-05-26
|
||||
// (c) : MIT
|
||||
//
|
||||
|
||||
|
||||
#include "ParallelPrinter.h"
|
||||
|
||||
|
@ -23,11 +21,12 @@ void setup()
|
|||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void test1()
|
||||
{
|
||||
Serial.println(__FUNCTION__);
|
||||
|
@ -36,6 +35,7 @@ void test1()
|
|||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
void test2()
|
||||
{
|
||||
Serial.println(__FUNCTION__);
|
||||
|
@ -45,6 +45,7 @@ void test2()
|
|||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
void test3()
|
||||
{
|
||||
Serial.println(__FUNCTION__);
|
||||
|
@ -56,7 +57,7 @@ void test3()
|
|||
for (int i = 0; i < 100; i++) PP.print("Hello World ");
|
||||
PP.printLineNumber(false);
|
||||
for (int i = 0; i < 100; i++) PP.print("Hello World ");
|
||||
|
||||
|
||||
PP.setTabSize(4);
|
||||
PP.printLineNumber(true);
|
||||
for (int i = 0; i < 100; i++) PP.print("Hello World ");
|
||||
|
@ -80,3 +81,4 @@ void test3()
|
|||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
|
|
@ -1,63 +1,68 @@
|
|||
//
|
||||
// FILE: PrinterSimulator.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-06-24
|
||||
// (c) : MIT
|
||||
|
||||
//
|
||||
// Simple parallel printer simulator, prints to serial...
|
||||
// version could be made with a shiftin register ....
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
uint8_t STROBE = 2;
|
||||
uint8_t BUSY = 13;
|
||||
uint8_t OOP = 10;
|
||||
|
||||
uint8_t PIN_STROBE = 2;
|
||||
uint8_t PIN_BUSY = 13;
|
||||
uint8_t PIN_OOP = 10;
|
||||
uint8_t dataPins[] = { 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
pinMode(STROBE, INPUT);
|
||||
pinMode(OOP, OUTPUT);
|
||||
pinMode(BUSY, OUTPUT); // build in LED UNO.
|
||||
pinMode(PIN_STROBE, INPUT);
|
||||
pinMode(PIN_OOP, OUTPUT);
|
||||
pinMode(PIN_BUSY, OUTPUT); // build in LED UNO.
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
pinMode(dataPins[i], INPUT);
|
||||
}
|
||||
|
||||
digitalWrite(OOP, HIGH); // HIGH is OK
|
||||
digitalWrite(BUSY, HIGH); // BUSY during startup
|
||||
digitalWrite(PIN_OOP, HIGH); // HIGH is OK
|
||||
digitalWrite(PIN_BUSY, HIGH); // BUSY during startup
|
||||
|
||||
delay(5000); // do startup thingies.
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleInput();
|
||||
// do other things here
|
||||
}
|
||||
|
||||
|
||||
void handleInput()
|
||||
{
|
||||
uint8_t x = 0;
|
||||
|
||||
digitalWrite(BUSY, LOW);
|
||||
while (digitalRead(STROBE) == HIGH) yield();
|
||||
digitalWrite(PIN_BUSY, LOW);
|
||||
while (digitalRead(PIN_STROBE) == HIGH) yield();
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
x <<= 1;
|
||||
if (digitalRead(dataPins[i]) == HIGH) x += 1;
|
||||
}
|
||||
while (digitalRead(STROBE) == LOW) yield();
|
||||
digitalWrite(BUSY, HIGH);
|
||||
while (digitalRead(PIN_STROBE) == LOW) yield();
|
||||
digitalWrite(PIN_BUSY, HIGH);
|
||||
|
||||
// process data
|
||||
Serial.write(x);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
//
|
||||
// FILE: Serial2ParPrinter.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// PURPOSE: demo
|
||||
// DATE: 2020-05-26
|
||||
// (c) : MIT
|
||||
//
|
||||
|
||||
|
||||
#include "ParallelPrinter.h"
|
||||
|
||||
|
@ -15,6 +13,7 @@
|
|||
|
||||
ParallelPrinter PP;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -23,6 +22,7 @@ void setup()
|
|||
PP.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (Serial.available()) PP.write(Serial.read());
|
||||
|
@ -30,3 +30,4 @@ void loop()
|
|||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# Syntax Colouring Map For ParallelPrinter
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
ParallelPrinter KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
reset KEYWORD2
|
||||
write KEYWORD2
|
||||
|
||||
setLineLength KEYWORD2
|
||||
getLineLength KEYWORD2
|
||||
setPageLength KEYWORD2
|
||||
getPageLength KEYWORD2
|
||||
|
||||
getLineNumber KEYWORD2
|
||||
getPageNumber KEYWORD2
|
||||
getPosition KEYWORD2
|
||||
|
||||
setTabSize KEYWORD2
|
||||
getTabSize KEYWORD2
|
||||
setLineFeed KEYWORD2
|
||||
getLineFeed KEYWORD2
|
||||
|
||||
printLineNumber KEYWORD2
|
||||
formfeed KEYWORD2
|
||||
linefeed KEYWORD2
|
||||
|
||||
isOutOfPaper KEYWORD2
|
||||
isBusy KEYWORD2
|
||||
setStrobeDelay KEYWORD2
|
||||
getStrobeDelay KEYWORD2
|
||||
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
||||
# Constants (LITERAL1)
|
||||
PARALLELPRINTER_VERSION LITERAL1
|
||||
FORMFEED LITERAL1
|
||||
LINEFEED LITERAL1
|
|
@ -13,9 +13,11 @@
|
|||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/ParallelPrinter.git
|
||||
"url": "https://github.com/RobTillaart/ParallelPrinter.git"
|
||||
},
|
||||
"version":"0.2.0",
|
||||
"version": "0.2.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "ParallelPrinter.h"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name=ParallelPrinter
|
||||
version=0.2.0
|
||||
version=0.2.4
|
||||
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,140 @@
|
|||
//
|
||||
// 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>
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "ParallelPrinter.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "PARALLELPRINTER_VERSION: %s\n", (char *) PARALLELPRINTER_VERSION);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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