From 4592f98a047dba741db16515d1f114077a6bb96f Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Fri, 11 Oct 2013 16:04:06 +0200 Subject: [PATCH] + initial version --- libraries/ParPrinter/ParPrinter.cpp | 56 +++++++++++++++++++++++++++++ libraries/ParPrinter/ParPrinter.h | 41 +++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 libraries/ParPrinter/ParPrinter.cpp create mode 100644 libraries/ParPrinter/ParPrinter.h diff --git a/libraries/ParPrinter/ParPrinter.cpp b/libraries/ParPrinter/ParPrinter.cpp new file mode 100644 index 00000000..610777b1 --- /dev/null +++ b/libraries/ParPrinter/ParPrinter.cpp @@ -0,0 +1,56 @@ +// +// FILE: parprinter.cpp +// AUTHOR: Rob Tillaart +// VERSION: 0.1.00 +// PURPOSE: parallel printer class that implements the Print interface +// DATE: 2013-09-30 +// URL: +// +// Released to the public domain +// + +#include "ParPrinter.h" + +ParPrinter::ParPrinter() +{ + // define pins + for (uint8_t i = 0; i < 8; i++) + { + pin[i] = 2+i; + } +} + +void ParPrinter::begin() +{ + pinMode(BUSY, INPUT); + pinMode(STROBE, OUTPUT); + for (uint8_t i = 0; i < 8; i++) + { + pinMode(pin[i], OUTPUT); + } +} + +// write() must implement the virtual write of the Print class +size_t ParPrinter::write(uint8_t data) +{ + while(digitalRead(BUSY) == HIGH); + + for (uint8_t i = 0; i < 8; i++) + { + digitalWrite(pin[i], bitRead(data, i) ); // direct port access will be faster + } + digitalWrite(STROBE, LOW); + delay(2); // main time consuming part, so max 500chars/second = 10 lines. + digitalWrite(STROBE, HIGH); + while (digitalRead(BUSY) == HIGH); + + return 1; +} + +/* +derive CLass HP: ParPrinter +{ +} +*/ + +// -- END OF FILE -- diff --git a/libraries/ParPrinter/ParPrinter.h b/libraries/ParPrinter/ParPrinter.h new file mode 100644 index 00000000..854cca25 --- /dev/null +++ b/libraries/ParPrinter/ParPrinter.h @@ -0,0 +1,41 @@ +// +// FILE: ParPrinter.h +// AUTHOR: Rob Tillaart +// VERSION: 0.1.00 +// PURPOSE: parallel printer class that implements the Print interface +// DATE: 2013-09-30 +// URL: +// +// Released to the public domain +// + +#ifndef ParPrinter_h +#define ParPrinter_h + +#if defined(ARDUINO) && ARDUINO >= 100 +#include "Arduino.h" +#else +#include "WProgram.h" +#endif + +#define PARPRINTER_VERSION "0.1.00" + +#include "Print.h" + +// constant pin numbers +#define STROBE 13 // same as build in LED ! makes it visible +#define BUSY 2 +#define OUT_OF_PAPER 12 + +class ParPrinter: public Print +{ +public: + ParPrinter(); // lets assume fixed pins for now, + void begin(); + size_t write(uint8_t); + +private: + uint8_t pin[8]; +}; +#endif +// -- END OF FILE --