OpenAccess printer and log functions

This is one of many sub-articles to describe the function of my OpenAccess.  I started putting it in one article, but it is really not useful like that.

The dot matrix printer uses these pins:

//dot matrix printer stuff
const int dataPins[] = {
41,40,43,42,45,44,47,46};
const int strobePin = 39;//active low
const int busyPin = 49;//active low

It is initialized here:

void printer_init()
{
for (int i = 0; i < sizeof(dataPins) / sizeof(dataPins[0]); ++i)
pinMode(dataPins[i], OUTPUT);
pinMode(strobePin, OUTPUT);
pinMode(busyPin, INPUT);
digitalWrite(strobePin, HIGH);
}

The printer is actually called in this printing function here, which is blocking:

void printing(char buffer)//blocking? only if BusyPin is ever high?
{
//Write out our buffer
for (int j = 0; j < sizeof(dataPins) / sizeof(dataPins[0]); ++j)
digitalWrite(dataPins[j], (buffer & (1 << j)));
//buffer = 0x00;

//Block and wait for the printer to be ready
while (digitalRead(busyPin));

//Tell the printer to write out the data
digitalWrite(strobePin, LOW);
delay(10);
digitalWrite(strobePin, HIGH);
delay(10);//not needed?
//Reset the data lines
for (int j = 0; j < sizeof(dataPins) / sizeof(dataPins[0]); ++j)
digitalWrite(dataPins[j], LOW);
}

That function is called in these ones that act like serial print() and println() statements:

void printer(String printable)
{
//if (printable.length() != 0)
//{
for(int i=0;i<printable.length();i++)//change to not call .length every time
{
printing(printable[i]);
}
//}
//else {
//Serial.println(“No arguments”);
//}
}
void printerln(String printable)
{
printer(printable);
printing(0x0d);//CR
printing(0x0a);//LF
}

Those functions are called at the same time as serial’s print functions as log functions so the computer and printer can log stuff together:

void logging(String tolog)//wrapper
{
Serial.print(tolog);
printer(tolog);
}
void loggingln(String tolog)//wrapper
{
Serial.println(tolog);
printerln(tolog);
}

Those functions are called absolutely everywhere, very useful for logging things verbosely.

// uses printer
//format: PRINT;<string>
void SCmd_print()
{
char *arg;
//Serial.println(“print”);
arg = SCmd.next();
if (arg != NULL)
{
printerln(arg);
}
}

That function is the serial wrapper that just uses the printer, great for testing or taking manual control of the system.

This is a derivative of the dot matrix printer driver I used before and part of the OpenAccess project.

Advertisements

One Response to “OpenAccess printer and log functions”

  1. OpenAccess 3.0 replacement software | Evan's Techie-Blog Says:

    […] printer and log functions […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: