0.2.5 ParallelPrinter

This commit is contained in:
rob tillaart 2022-11-19 15:28:46 +01:00
parent b6ba560a83
commit 9145084977
8 changed files with 110 additions and 63 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -8,4 +23,6 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
- rpipico

View File

@ -0,0 +1,41 @@
# Change Log ParallelPrinter
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.5] - 2022-11-19
- add RP2040 in build-CI
- add changelog.md
## [0.2.4] - 2021-12-23
- update library.json
- update license
- minor edits
## [0.2.3] - 2021-11-11
- update Arduino-CI
- update readme.md
- add isBusy()
## [0.2.2] - 2021-01-14
- update readme
- add linefeed()
- add keywords.txt
## [0.2.1] - 2021-01-04
- add Arduino-CI + unit test
## [0.2.0] - 2020-05-26
- refactor
- add examples
----
.... eons ago ...
## [0.1.0] - 2013-09-30
- initial release

View File

@ -1,19 +1,11 @@
//
// FILE: ParallelPrinter.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.4
// VERSION: 0.2.5
// 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
// 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"
@ -28,7 +20,7 @@ ParallelPrinter::ParallelPrinter()
ParallelPrinter::ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint8_t * p )
{
// CONTROL LINES
// CONTROL LINES
_strobePin = STROBE;
_busyPin = BUSY;
_oopPin = OOP;
@ -36,7 +28,7 @@ ParallelPrinter::ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint
pinMode(_busyPin, INPUT);
pinMode(_strobePin, OUTPUT);
// DATA LINES
// DATA LINES
for (uint8_t i = 0; i < 8; i++)
{
_pin[i] = p[i];
@ -68,16 +60,16 @@ void ParallelPrinter::reset()
}
// write() implements the virtual write of the Print class
// write() implements the virtual write of the Print class
size_t ParallelPrinter::write(uint8_t c)
{
if (c == '\t') // TAB
if (c == '\t') // TAB
{
uint8_t spaces = _tabSize - _pos % _tabSize;
for (uint8_t i = 0; i < spaces; i++) processSingleChar(' ');
return spaces;
}
if (c == '\n') // LINEFEED
if (c == '\n') // LINEFEED
{
for (uint8_t i = 0; i < _lineFeed; i++)
{
@ -97,7 +89,7 @@ void ParallelPrinter::processSingleChar(uint8_t c)
_pos++;
if ((_pos == 1) && _printLineNumber)
{
// not nice - implicit recursion...
// not nice - implicit recursion...
print(_lineNr);
print('\t');
}
@ -114,7 +106,7 @@ void ParallelPrinter::processSingleChar(uint8_t c)
sendByte(c);
}
// HANDLE FULL LINE
// HANDLE FULL LINE
if (_pos > _lineLength)
{
_pos = 0;
@ -124,7 +116,7 @@ void ParallelPrinter::processSingleChar(uint8_t c)
_lineNr++;
}
}
// HANDLE FULL PAGE
// HANDLE FULL PAGE
if (_lineNr > _pageLength)
{
sendByte(FORMFEED);
@ -138,18 +130,18 @@ void ParallelPrinter::processSingleChar(uint8_t c)
}
// lowest level communication
// lowest level communication
void ParallelPrinter::sendByte(uint8_t c)
{
// BLOCK WHEN OUT OF PAPER TODO
// while (digitalRead(_oopPin) == LOW) yield();
// indication in hardware?
// BLOCK WHEN OUT OF PAPER TODO
// while (digitalRead(_oopPin) == LOW) yield();
// indication in hardware?
Serial.write(c); // debugging
Serial.write(c); // debugging
return;
// wait until printer is ready.
// wait until printer is ready.
while (digitalRead(_busyPin) == HIGH) yield();
uint8_t mask = 0x80;
@ -159,11 +151,11 @@ void ParallelPrinter::sendByte(uint8_t c)
mask >>= 1;
}
digitalWrite(_strobePin, LOW);
// time consuming part
// time consuming part
if (_strobeDelay) delayMicroseconds(_strobeDelay);
digitalWrite(_strobePin, HIGH);
// wait till data is read by printer.
// wait till data is read by printer.
while (digitalRead(_busyPin) == LOW) yield();
}

View File

@ -2,7 +2,7 @@
//
// FILE: ParallelPrinter.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.4
// VERSION: 0.2.5
// PURPOSE: parallel printer class that implements the Print interface
// DATE: 2013-09-30
// URL: https://github.com/RobTillaart/ParallelPrinter
@ -11,7 +11,7 @@
#include "Arduino.h"
#define PARALLELPRINTER_VERSION (F("0.2.4"))
#define PARALLELPRINTER_VERSION (F("0.2.5"))
#define FORMFEED 12
#define LINEFEED 10
@ -20,7 +20,10 @@
class ParallelPrinter: public Print
{
public:
ParallelPrinter(); // assume fixed pins for now, need 11 pins in total!
// uint8_t dataPins[] = {3, 4, 5, 6, 7, 8, 9, 10};
// ParallelPrinter(13, 2, 12, dataPins );
// assume fixed pins for now, need 11 pins in total!
ParallelPrinter();
ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint8_t * dataPins );
void begin(uint8_t lineLength = 80, uint8_t pageLength = 60);
@ -56,16 +59,16 @@ public:
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
// 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
void processSingleChar(uint8_t c);
void sendByte(uint8_t c);
// BEHAVIOR
// BEHAVIOR
uint8_t _pos;
uint8_t _lineLength;
uint8_t _lineNr;
@ -79,5 +82,5 @@ private:
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -74,7 +74,7 @@ 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.
data as they do not have large buffers. (==> BUSY line)
## See also
@ -82,22 +82,30 @@ data as they do not have large buffers.
https://en.wikipedia.org/wiki/Parallel_port#Centronics
## Operation
See examples.
## Future
#### must
- update documentation
#### should
- 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.
#### could
- 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
#### wont
## Operation
See examples.

View File

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

View File

@ -1,5 +1,5 @@
name=ParallelPrinter
version=0.2.4
version=0.2.5
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.

View File

@ -47,21 +47,7 @@ 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
// minimal
unittest(test_constructor_basic)
{
ParallelPrinter PP;
@ -88,9 +74,9 @@ unittest(test_constructor_basic)
// 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
assertEqual(3, PP.getLineNumber()); // 0 based
assertEqual(4, PP.getPageNumber()); // 0 based
assertEqual(11, PP.getPosition()); // 0 based
}
@ -108,7 +94,7 @@ unittest(test_tabs_linefeed)
fprintf(stderr, "0\t");
PP.setLineFeed(0);
assertEqual(1, PP.getLineFeed()); // minimum LF size
assertEqual(1, PP.getLineFeed()); // minimum LF size
for (int LF = 1; LF < 4; LF +=2 )
{