Compare commits

...

9 Commits

Author SHA1 Message Date
Rob Tillaart ef43c007e0
update library.json, license, minor edits (#6) 2021-12-23 10:04:07 +01:00
rob tillaart dd8cc40840 add headers to library.json 2021-11-21 10:23:31 +01:00
Rob Tillaart a29596cc12
update build-CI, readme, badges, add isBusy() (#5)
* update build-CI, 
* update readme, badges, 
* add isBusy()
* fixed example for ESP32
2021-11-11 13:36:23 +01:00
rob tillaart ed6fed3c41 add license to library.json 2021-05-28 14:13:36 +02:00
rob tillaart 1dd306494e add arduino-lint check 2021-05-27 23:12:43 +02:00
rob tillaart 77bd9a7e32 add arduino-lint check 2021-05-27 18:42:15 +02:00
rob tillaart 5bf0f14ae6 add json check 2021-04-07 11:42:26 +02:00
rob tillaart 6eb460a2c3 update unit test 2021-01-16 19:59:28 +01:00
Rob Tillaart 4c7c4d06ad
update 0.2.2 (#4) 2021-01-14 20:00:47 +01:00
15 changed files with 223 additions and 88 deletions

View File

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

13
.github/workflows/arduino-lint.yml vendored Normal file
View File

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

View File

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

18
.github/workflows/jsoncheck.yml vendored Normal file
View File

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

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2013-2021 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

View File

@ -1,7 +1,7 @@
//
// FILE: ParallelPrinter.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.1
// VERSION: 0.2.4
// PURPOSE: parallel printer class that implements the Print interface
// DATE: 2013-09-30
// URL: https://github.com/RobTillaart/ParallelPrinter
@ -9,7 +9,11 @@
// 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
// 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"
@ -31,7 +35,7 @@ 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++)
{
@ -67,13 +71,13 @@ void ParallelPrinter::reset()
// 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++)
{
@ -140,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;
@ -165,3 +169,4 @@ void ParallelPrinter::sendByte(uint8_t c)
// -- END OF FILE --

View File

@ -2,17 +2,20 @@
//
// FILE: ParallelPrinter.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.1
// 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 (F("0.2.1"))
#define FORMFEED 12
#define PARALLELPRINTER_VERSION (F("0.2.4"))
#define FORMFEED 12
#define LINEFEED 10
class ParallelPrinter: public Print
{
@ -33,7 +36,7 @@ public:
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; };
@ -43,12 +46,15 @@ public:
void printLineNumber(bool b) { _printLineNumber = b; };
void formfeed() { write(FORMFEED); };
bool isOutOfPaper() { return digitalRead(_oopPin) == LOW; };
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; };
private:
// COMMUNICATION
uint8_t _strobePin; // inform printer new data on the line.
@ -67,9 +73,11 @@ private:
uint8_t _pageNr;
uint8_t _tabSize;
uint8_t _lineFeed;
bool _printLineNumber;
uint16_t _strobeDelay;
};
// -- END OF FILE --

View File

@ -1,19 +1,24 @@
[![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 using **print()** and **println()**
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**.
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.
@ -22,46 +27,77 @@ Have fun!
**Note:** This lib is a extended redo of the ParPrinter class.
## Interface
### Constructor
- **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
- **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
### 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.
### 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
- **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()**
### Expert mode
### Configuration
- **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.
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.

View File

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

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

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

40
keywords.txt Normal file
View 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

View File

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

View File

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

View File

@ -31,45 +31,41 @@
#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()
{
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
// minimal
unittest(test_constructor_basic)
{
fprintf(stderr, "VERSION: %s\n", PARALLELPRINTER_VERSION);
ParallelPrinter PP;
PP.begin();
assertEqual(80, PP.getLineLength());
assertEqual(60, PP.getPageLength());
@ -91,7 +87,7 @@ unittest(test_constructor_basic)
// 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
@ -113,7 +109,7 @@ unittest(test_tabs_linefeed)
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);
@ -133,11 +129,12 @@ unittest(test_OutOfPaper)
// TODO
// state->digitalPin[12] = 0;
// assertFalse(PP.isOutOfPaper());
//
//
// state->digitalPin[12] = 1;
// assertTrue(PP.isOutOfPaper());
}
unittest_main()
// --------