| 18 | |
| 19 | |
| 20 | class ParallelPrinter: public Print |
| 21 | { |
| 22 | public: |
| 23 | // uint8_t dataPins[] = {3, 4, 5, 6, 7, 8, 9, 10}; |
| 24 | // ParallelPrinter(13, 2, 12, dataPins ); |
| 25 | // assume fixed pins for now, need 11 pins in total! |
| 26 | ParallelPrinter(); |
| 27 | ParallelPrinter(uint8_t STROBE, uint8_t BUSY, uint8_t OOP, uint8_t * dataPins ); |
| 28 | |
| 29 | void begin(uint8_t lineLength = 80, uint8_t pageLength = 60); |
| 30 | void reset(); |
| 31 | size_t write(uint8_t c); |
| 32 | |
| 33 | void setLineLength(uint8_t lineLength = 80) { _lineLength = lineLength; }; |
| 34 | uint8_t getLineLength() { return _lineLength; }; |
| 35 | |
| 36 | void setPageLength(uint8_t pageLength = 60) { _pageLength = pageLength; }; |
| 37 | uint8_t getPageLength() { return _pageLength; }; |
| 38 | |
| 39 | uint8_t getLineNumber() { return _lineNr; }; |
| 40 | uint8_t getPageNumber() { return _pageNr; }; |
| 41 | uint8_t getPosition() { return _pos; }; |
| 42 | |
| 43 | // n = 2,4,6,8 |
| 44 | void setTabSize(uint8_t n) { _tabSize = n; }; |
| 45 | uint8_t getTabSize() { return _tabSize; }; |
| 46 | // n = 1,2,3 |
| 47 | void setLineFeed(uint8_t n) { _lineFeed = constrain(n, 1, 3); }; |
| 48 | uint8_t getLineFeed() { return _lineFeed; }; |
| 49 | |
| 50 | void printLineNumber(bool b) { _printLineNumber = b; }; |
| 51 | void formfeed() { write(FORMFEED); }; |
| 52 | void linefeed() { write(LINEFEED); }; |
| 53 | bool isOutOfPaper() { return digitalRead(_busyPin) == LOW; }; |
| 54 | bool isBusy() { return digitalRead(_oopPin) == HIGH; }; |
| 55 | |
| 56 | // n = typical 2000; use with care |
| 57 | void setStrobeDelay(uint16_t n = 2000) { _strobeDelay = n; }; |
| 58 | uint16_t getStrobeDelay() { return _strobeDelay; }; |
| 59 | |
| 60 | |
| 61 | private: |
| 62 | // COMMUNICATION |
| 63 | uint8_t _strobePin; // inform printer new data on the line. |
| 64 | uint8_t _busyPin; // feedback from printer |
| 65 | uint8_t _oopPin; // Out of paper. |
| 66 | uint8_t _pin[8]; // data pins |
| 67 | |
| 68 | void processSingleChar(uint8_t c); |
| 69 | void sendByte(uint8_t c); |
| 70 | |
| 71 | // BEHAVIOR |
| 72 | uint8_t _pos; |
| 73 | uint8_t _lineLength; |
| 74 | uint8_t _lineNr; |
| 75 | uint8_t _pageLength; |
| 76 | uint8_t _pageNr; |
| 77 | uint8_t _tabSize; |