From 9ac7baf1a20f87f7d6e2d5c17155d083f41e5707 Mon Sep 17 00:00:00 2001 From: Griffin Della Grotte Date: Sun, 25 Jun 2017 16:03:11 -0400 Subject: [PATCH] Initial Commit with printimg and printtxt --- DirectPrint/Makefile | 3 + DirectPrint/apple_logo.txt | 45 ++++++++++ DirectPrint/printimg | Bin 0 -> 14016 bytes DirectPrint/printimg.cpp | 172 +++++++++++++++++++++++++++++++++++++ DirectPrint/printtxt | Bin 0 -> 13952 bytes DirectPrint/printtxt.cpp | 137 +++++++++++++++++++++++++++++ DirectPrint/test.txt | 36 ++++++++ 7 files changed, 393 insertions(+) create mode 100644 DirectPrint/Makefile create mode 100644 DirectPrint/apple_logo.txt create mode 100755 DirectPrint/printimg create mode 100644 DirectPrint/printimg.cpp create mode 100755 DirectPrint/printtxt create mode 100644 DirectPrint/printtxt.cpp create mode 100644 DirectPrint/test.txt 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 0000000000000000000000000000000000000000..0df54a65999d3b6848a5ed024c9661b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}tv7$h$_7>+0KEzHJf zD2suZaFrOsqNT2des;}ggiZWoJ4dk97(XR4a3iK!v;UkO4C z)dV^tLHH2U$vhC6jXn$#=EJ(yiM1-vD*O9G^gNA6klb^ed{30;+U356v`n(r^eHg3 zmw@G+r$)D5P)_FD3*>#>EX8vRGFE;0-l+?N>!qNePW^h|_*55@^&fZpx#V#HNdNJn zpQjQ*CE1P4V*I53klPQA_GLI><$}_F4YghBuQrPrJ%{3!m(!Q;yA#6EH-(%e&iFlo z0@_QF^~?9-3&LS~uc0LUmvWLGKpE}LNM61_PYDG-DI+=kH&MpueTQ6?`tm)yf)tQs zJ7xXO_8)-^>DQ4klH6ZXg}&U6B7L&u)c+bViir@?pxkGJ2u~ucl4S;RR(<(? z-z@Z-9RV*Bnv#CQp)dCVM#Kh~^jB8s zFGJshAI%|3^8Hl)KZjG^$>wY2U(ljUZ?(>kRcbPzT8LgenS1Xp-W>| z>dXBW`TsWZ|7zs;mi5bVaNJS9+?SbNhXN!iZ*sG|#D9YVtN+Z~Y>IkKGGdb4Rq9DP zjS{QAeD53ankv#yX+Y{p{suCH$@a_lfwb3@aLQ9%)>H(5unH@Pywu;~z@@&V%TO-s zwu(+|GCA7EuqFq~>y~rJDpzu+$)!aDXgF-fPqs&{i!?v;)&KfNQ-8H%!Z_>yUxc;` Ao&W#< literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..ebe7f265688d03f4f99f249e9dc14edf1a7f39fa GIT binary patch literal 13952 zcmeHOe^6Z4b-wI^gpjl#MYd(hiPoy{NSIJdV!-Hfhf$KVvAIt6oHiF%q z-M2Dwq67z{(FWtv)^XLDw8KmtSLwJ8O=A!BI08uy$W5D)>DY1Fw56%-VPmJkzZBvs z+J5K0dv@PGv599o{i8Fw%CnO8nDJx8;l^>TBWj$g^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6++fIw?Yibgi%|k z(O|ORXc|T*XDl8|m~E7q;bctj4MxKVsdXqWZwtrQ^p<;J2XCfqEDr$|LblU>g$>qG!9q;G z=eT}YEx3Js!DJGv%{uSrkb7WvEzJhb6B>!`V93y|cYDc*oEPLCFAPdbUcv<_X`LS| zG%I|`6a8ke3)Di-?3>tXsy#C9wT z-{qQJ_nMJfRP6eE-)Jg>+gMOhr+zbV zypD}=|7To&DS1W#?0=a=^UqflD-NNu8Xwl5bos&I-L3+*D@xB>C{E?nh_cZl;yzIP zWaaevesx|s%Fknz_%-o+5DoM!g!||F+8O1rPbsqhEXVX1+UeN}^L+oiq!j#0-|4@C z1>LWZtE|uW$ql4{!sF!ro#THLGNj)`!YKTFs7>kf^CZ$ITTcDQfl*wQc<#PiQ-b`Q z3?j0qure#ssM+=T{yeVqJE_rDs#Kln6X5Ood>=oj9$>M*Y{JR^sY9Qy8|RgN6D7B; zaK8-wIV$%4`MJP0b*Pn}qp`em{9jl4Jb!#$T%+`tSW!`@|9|b!=l`?d|Gx-3^qu`r zIrRB?#F)C7_?9F7&i-G9z6T##LsaWoZipKO5jn7@h&VLX1m{-5(&5>9#Q%U;|72&=J! zsIz{Z1804vl;+&GUGy6}EsmZ;*o%Xeee>F}%az}1apP(Lln%S_;qlO3Mupbra{Zs( NA)CcY$AWS8|37)nPTl|j literal 0 HcmV?d00001 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.