+ initial version

This commit is contained in:
Rob Tillaart 2013-10-11 16:04:06 +02:00
parent df54800ca6
commit 4592f98a04
2 changed files with 97 additions and 0 deletions

View File

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

View File

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