Skip to content

Commit

Permalink
Arduino ci (#2)
Browse files Browse the repository at this point in the history
* add Arduino-CI
* add unit test
* extended the interface to access internal variables.
  • Loading branch information
RobTillaart committed Jan 4, 2021
1 parent 9757263 commit e9fca01
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 62 deletions.
7 changes: 7 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
13 changes: 13 additions & 0 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 22 additions & 19 deletions ParallelPrinter.cpp
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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;
}


Expand Down
65 changes: 40 additions & 25 deletions ParallelPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
//
// 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
//

#include "Arduino.h"

#define PARALLELPRINTER_VERSION "0.2.0"
#define PARALLELPRINTER_VERSION (F("0.2.1"))

#define FORMFEED 12

Expand All @@ -20,40 +20,55 @@ class ParallelPrinter: public Print
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;
};

Expand Down
53 changes: 38 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

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

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

* **begin(linelength, pagelength)** set page parameters
* **write(c)** send a single byte to printer, implements Print interface.

* **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
### Expert mode

* **setStrobeDelay(n)** make the strobe pulse shorter == faster printing
allows tuning of performance. Typical value = 2000. Time in micros.
use with care.
- **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
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ParallelPrinter.git"
},
"version":"0.2.0",
"version":"0.2.1",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading

0 comments on commit e9fca01

Please sign in to comment.