diff --git a/DirectPrint/Makefile b/DirectPrint/Makefile new file mode 100644 index 0000000..eeab8ac --- /dev/null +++ b/DirectPrint/Makefile @@ -0,0 +1,3 @@ +all: + g++ printtxt.cpp -o printtxt + g++ printimg.cpp -o printimg diff --git a/DirectPrint/apple_logo.txt b/DirectPrint/apple_logo.txt new file mode 100644 index 0000000..42f05c2 --- /dev/null +++ b/DirectPrint/apple_logo.txt @@ -0,0 +1,45 @@ + + `.://++` + .:++++++++` + `:+++++++++++ + `:++++++++++++: + .+++++++++++++/` + -++++++++++++++` + .+++++++++++++/` + `+++++++++++++- + -+++++++++++-` + :+++++++/:. + `--://///::-.` -///:-.` `.--:://///::-.` + .:/+++++++++++++++++/-.`` ``.:/++++++++++++++++++:.` + .:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++/. + ./++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- + ./++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. + -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++:. + -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-. + -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::. + .::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::` +`::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::` +.:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::. +://///////////////////////////////////////////////////////////// +/++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++: +/++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/ +/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. +:+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/` +.ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss+` + osssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssso. + -ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss/` + +sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssso/. + .ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssso/-` + :ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssso` + /ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssso` + +ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssso. + +ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssso` + /sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss+` + :sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss: + .ossssssssssssssssssssssssssssssssssssssssssssssssssssssssso. + `/sssssssssssssssssssssssssssssssssssssssssssssssssssssss/` `-.` + .+sssssssssssssssssssssssssssssssssssssssssssssssssss+. //////+. + -+ssssssssssssssssssssssssssssssssssssssssssssssso- /: y:++ y + ./osssssssssssso+/:..``````.-:/osssssssssssso/- :/ y.+:`y + .:/+oooo+/-. `-:/+oooo/:-` -/+:/+/` diff --git a/DirectPrint/printimg b/DirectPrint/printimg new file mode 100755 index 0000000..0df54a6 Binary files /dev/null and b/DirectPrint/printimg differ diff --git a/DirectPrint/printimg.cpp b/DirectPrint/printimg.cpp new file mode 100644 index 0000000..8101199 --- /dev/null +++ b/DirectPrint/printimg.cpp @@ -0,0 +1,172 @@ +#include +#include +#include +#include +#include +#include +#include + +/* + * In fast draft mode, set line spacing to 16/144 + * The resulting dot ratio is height:width of 1.38:1 + */ + +// Function credit: wallyk & RicoRico +int set_interface_attribs (int fd, int speed, int parity) { + struct termios tty; + memset (&tty, 0, sizeof tty); + if (tcgetattr (fd, &tty) != 0) + { + perror("error from tcgetattr"); + return -1; + } + + cfsetospeed (&tty, speed); + cfsetispeed (&tty, speed); + + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars + // disable IGNBRK for mismatched speed tests; otherwise receive break + // as \000 chars + tty.c_iflag &= ~IGNBRK; // disable break processing + tty.c_lflag = 0; // no signaling chars, no echo, + // no canonical processing + tty.c_oflag = 0; // no remapping, no delays + tty.c_cc[VMIN] = 0; // read doesn't block + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl + tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, + // enable reading + tty.c_cflag &= ~(PARENB | PARODD); // shut off parity + tty.c_cflag |= parity; + tty.c_cflag &= ~CSTOPB; + tty.c_cflag &= ~CRTSCTS; + + if (tcsetattr (fd, TCSANOW, &tty) != 0) + { + perror("error from tcsetattr"); + return -1; + } + return 0; +} + +// Function credit: wallyk & RicoRico +void set_blocking (int fd, int should_block) { + struct termios tty; + memset (&tty, 0, sizeof tty); + if (tcgetattr (fd, &tty) != 0) + { + perror("error from tggetattr"); + return; + } + + tty.c_cc[VMIN] = should_block ? 1 : 0; + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + + if (tcsetattr (fd, TCSANOW, &tty) != 0) + perror("error %d setting term attributes"); +} + +int init_port(char *portname){ + int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC); + if (fd < 0) + { + perror("error opening file"); + return 1; + } + + set_interface_attribs (fd, B9600, 0); // set speed to 9,600 bps, 8n1 (no parity) + set_blocking (fd, 0); // set no blocking + + return fd; +} + +void send_line(int iw, char *line, size_t len){ + write(iw, strcat(line, "\n\r"), len+2); +} + +void print_buffer(int iw, char *buf, size_t len){ + char seg[250]; + + int i = 0; + while (i < len){ + int amnt = 250; + if (len - i < 250) amnt = len - i; + memcpy(seg, (buf+i), amnt); + write(iw, seg, amnt); + i += 250; + //printf("Done segment!\n"); + usleep(990000); //Don't overfill buffer + } + + write(iw, "\n\r", 2); +} + +char * read_text(char * filename){ + char * filebuf = (char*)calloc(sizeof(char),4000); + char line[92]; + printf("Reading file %s...\n", filename); + FILE *fp = fopen(filename, "r"); // do not use "rb" + + size_t i = 0; + while (fgets(line, sizeof(line)-2, fp)) { + //printf(line); + if (strlen(line) >= 89) strcat(line, "\n"); + strcat(filebuf, line); + printf(filebuf); + } + + fclose(fp); + printf("Done! closing file read\n"); + return filebuf; +} + +void init_text(int iw){ + char std_sp[4] = {27, 'A'}; + write(iw, std_sp, 4); +} + +void init_graphics(int iw, int bytes){ + if (bytes > 1500) printf("Too many bytes for one section!"); + + char gr_sp[4] = {27, 'T', '1', '6'}; + write(iw, gr_sp, 4); + + char num[5]; + sprintf(num, "%04d", bytes); + char cmd[6] = {27, 71, 0, 0, 0, 0}; + memcpy(cmd+2, num, 4); + write(iw, cmd, 6); +} + +int main(int argc, char *argv[]){ + //if (argc != 2) printf("Please execute with filename of text file\n"); + + char txt[40]; + char *portname = "/dev/ttyS0"; + int iw = init_port(portname); + + int linelength = 128; + for(int foo = 0; foo < 16; foo++){ + init_graphics(iw, linelength); + char s[1] = {0}; + + for (size_t i = 0; i < linelength; i++) { + s[0] = (0xFF&i); + write(iw, s, 1); + } + + write(iw, strcpy(txt, "\n"), 1); + } + + init_text(iw); + write(iw, "Test!\n\r", 7); + write(iw, "Test!\n\r", 7); + + + usleep ((7 + 25) * 10000); // sleep enough to transmit the 7 plus + // receive 25: approx 100 uS per char transmit + //char buf [100]; + //int n = read (fd, buf, sizeof buf); // read up to 100 characters if ready to read + + return 0; +} diff --git a/DirectPrint/printtxt b/DirectPrint/printtxt new file mode 100755 index 0000000..ebe7f26 Binary files /dev/null and b/DirectPrint/printtxt differ diff --git a/DirectPrint/printtxt.cpp b/DirectPrint/printtxt.cpp new file mode 100644 index 0000000..906afb0 --- /dev/null +++ b/DirectPrint/printtxt.cpp @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include +#include +#include + +// Function credit: wallyk & RicoRico +int set_interface_attribs (int fd, int speed, int parity) { + struct termios tty; + memset (&tty, 0, sizeof tty); + if (tcgetattr (fd, &tty) != 0) + { + perror("error from tcgetattr"); + return -1; + } + + cfsetospeed (&tty, speed); + cfsetispeed (&tty, speed); + + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars + // disable IGNBRK for mismatched speed tests; otherwise receive break + // as \000 chars + tty.c_iflag &= ~IGNBRK; // disable break processing + tty.c_lflag = 0; // no signaling chars, no echo, + // no canonical processing + tty.c_oflag = 0; // no remapping, no delays + tty.c_cc[VMIN] = 0; // read doesn't block + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl + tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, + // enable reading + tty.c_cflag &= ~(PARENB | PARODD); // shut off parity + tty.c_cflag |= parity; + tty.c_cflag &= ~CSTOPB; + tty.c_cflag &= ~CRTSCTS; + + if (tcsetattr (fd, TCSANOW, &tty) != 0) + { + perror("error from tcsetattr"); + return -1; + } + return 0; +} + +// Function credit: wallyk & RicoRico +void set_blocking (int fd, int should_block) { + struct termios tty; + memset (&tty, 0, sizeof tty); + if (tcgetattr (fd, &tty) != 0) + { + perror("error from tggetattr"); + return; + } + + tty.c_cc[VMIN] = should_block ? 1 : 0; + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + + if (tcsetattr (fd, TCSANOW, &tty) != 0) + perror("error %d setting term attributes"); +} + +int init_port(char *portname){ + int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC); + if (fd < 0) + { + perror("error opening file"); + return 1; + } + + set_interface_attribs (fd, B9600, 0); // set speed to 9,600 bps, 8n1 (no parity) + set_blocking (fd, 0); // set no blocking + + return fd; +} + +void send_line(int iw, char *line, size_t len){ + write(iw, strcat(line, "\n\r"), len+2); +} + +void print_buffer(int iw, char *buf, size_t len){ + char seg[250]; + + int i = 0; + while (i < len){ + int amnt = 250; + if (len - i < 250) amnt = len - i; + memcpy(seg, (buf+i), amnt); + write(iw, seg, amnt); + i += 250; + //printf("Done segment!\n"); + usleep(990000); //Don't overfill buffer + } + + write(iw, "\n\r", 2); +} + +char * read_text(char * filename){ + char * filebuf = (char*)calloc(sizeof(char),4000); + char line[92]; + printf("Reading file %s...\n", filename); + FILE *fp = fopen(filename, "r"); // do not use "rb" + + size_t i = 0; + while (fgets(line, sizeof(line)-2, fp)) { + //printf(line); + if (strlen(line) >= 89) strcat(line, "\n"); + strcat(filebuf, line); + printf(filebuf); + } + + fclose(fp); + printf("Done! closing file read\n"); + return filebuf; +} + +int main(int argc, char *argv[]){ + if (argc != 2) printf("Please execute with filename of text file\n"); + + char txt[40]; + char *portname = "/dev/ttyS0"; + int iw_serial = init_port(portname); + + //strcpy(txt, "Hello world!"); + char * intext = read_text(argv[1]); + printf("String Length: %d\n", strlen(intext)); + print_buffer(iw_serial, intext, strlen(intext)); + free(intext); + + usleep ((7 + 25) * 10000); // sleep enough to transmit the 7 plus + // receive 25: approx 100 uS per char transmit + //char buf [100]; + //int n = read (fd, buf, sizeof buf); // read up to 100 characters if ready to read + + return 0; +} diff --git a/DirectPrint/test.txt b/DirectPrint/test.txt new file mode 100644 index 0000000..e2f78e6 --- /dev/null +++ b/DirectPrint/test.txt @@ -0,0 +1,36 @@ +Chapter 1: Meet the ImageWriter II + + +ImageWriter II Features + +The Apple ImageWriter II is the ideal addition to your Apple computer. The versatile ImageWriter II combines ease of operation with a host of high-performance features to produce professional-quality graphics and text printouts. You can expand the ImageWriter II’s capabilities by choosing among three optional accessories—the ImageWriter II SheetFeeder, ImageWriter II 32K Memory Option, and ImageWriter II AppleTalk Option. + +Features for Everyone + +Do you want presentation quality text for an important report? Do you need to print hundreds of mailing labels? Could you show sales increases more dramatically with a bar chart in your report? Is it time to get that novel off to your publisher? The flexible ImageWriter II easily does all this and more. Consider these features for your day-to-day work. + +Print Quality and Speed + +You can select from among three levels of print quality at the press of a button: +Near Letter Quality (NLQ) for formal communications and presentations +Standard Quality for everyday work +Draft Quality when you want a quick printout for review or editing + +The ImageWriter II can print high-resolution graphics, ideal for use with the Macintosh and with graphics programs written for the Apple II computers. The ImageWriter II’s high-speed print mechanism can turn out text at speeds up to 250 characters per second. + +Letters, Labels, and Forms + +The ImageWriter II can handle a variety of printing tasks: reports, letters, envelopes, mailing labels, even multi-part forms like invoices. + +Easy Paper Loading and Ribbon Changes + +With the automatic paper loading feature, you can load single-sheet paper with the push of a button. Thanks to the built-in forms tractor, the ImageWriter II makes loading computer paper easier than ever before. + +Likewise, ribbon changes are a snap. Ribbon cartridges click in and out quickly and neatly. Whether you print in black or color, you get high-quality images and long life from these continuous-loop, fabric ribbons. + +Seven-Color Printing + +To print color graphics, click in an ImageWriter II color ribbon. With color software, you can print documents in six colors plus black. You can even mix black text with color graphics. + +Programmable Features +To make more sophisticated demands on the ImageWriter II, consider these programmable features.