Driver to control the EM027BS013 board from Embedded Artists

Dependencies:   EM027BS013

EM027BS013 Simple Driver

This library provides an easy way to write data to the EM027BS013 display, by providing interfaces to common C functions and methods. The library was originally written by Peter Drescher, who created the "EaEpaper" library for the EM027AS012 display (available here, but adapted to use the newer display type and driver (available here), as the existing display is now discontinued.

Big thanks go to the team from Pervasive Displays and Electronic Artists for producing such a nice display, and to Peter for providing the initial interface used in this driver.

Committer:
Leigh_LbR
Date:
Thu May 19 14:08:34 2016 +0000
Revision:
1:46dfef41919b
Parent:
0:e36f1973a674
Added API documentation;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Leigh_LbR 0:e36f1973a674 1 /* mbed TextDisplay Display Library Base Class
Leigh_LbR 0:e36f1973a674 2 * Copyright (c) 2007-2009 sford
Leigh_LbR 0:e36f1973a674 3 * Released under the MIT License: http://mbed.org/license/mit
Leigh_LbR 0:e36f1973a674 4 */
Leigh_LbR 0:e36f1973a674 5
Leigh_LbR 0:e36f1973a674 6 #include "TextDisplay.h"
Leigh_LbR 0:e36f1973a674 7
Leigh_LbR 0:e36f1973a674 8 TextDisplay::TextDisplay(const char *name) : Stream(name){
Leigh_LbR 0:e36f1973a674 9 _row = 0;
Leigh_LbR 0:e36f1973a674 10 _column = 0;
Leigh_LbR 0:e36f1973a674 11 if (name == NULL) {
Leigh_LbR 0:e36f1973a674 12 _path = NULL;
Leigh_LbR 0:e36f1973a674 13 } else {
Leigh_LbR 0:e36f1973a674 14 _path = new char[strlen(name) + 2];
Leigh_LbR 0:e36f1973a674 15 sprintf(_path, "/%s", name);
Leigh_LbR 0:e36f1973a674 16 }
Leigh_LbR 0:e36f1973a674 17 }
Leigh_LbR 0:e36f1973a674 18
Leigh_LbR 0:e36f1973a674 19 int TextDisplay::_putc(int value) {
Leigh_LbR 0:e36f1973a674 20 if(value == '\n') {
Leigh_LbR 0:e36f1973a674 21 _column = 0;
Leigh_LbR 0:e36f1973a674 22 _row++;
Leigh_LbR 0:e36f1973a674 23 if(_row >= rows()) {
Leigh_LbR 0:e36f1973a674 24 _row = 0;
Leigh_LbR 0:e36f1973a674 25 }
Leigh_LbR 0:e36f1973a674 26 } else {
Leigh_LbR 0:e36f1973a674 27 character(_column, _row, value);
Leigh_LbR 0:e36f1973a674 28 _column++;
Leigh_LbR 0:e36f1973a674 29 if(_column >= columns()) {
Leigh_LbR 0:e36f1973a674 30 _column = 0;
Leigh_LbR 0:e36f1973a674 31 _row++;
Leigh_LbR 0:e36f1973a674 32 if(_row >= rows()) {
Leigh_LbR 0:e36f1973a674 33 _row = 0;
Leigh_LbR 0:e36f1973a674 34 }
Leigh_LbR 0:e36f1973a674 35 }
Leigh_LbR 0:e36f1973a674 36 }
Leigh_LbR 0:e36f1973a674 37 return value;
Leigh_LbR 0:e36f1973a674 38 }
Leigh_LbR 0:e36f1973a674 39
Leigh_LbR 0:e36f1973a674 40 // crude cls implementation, should generally be overwritten in derived class
Leigh_LbR 0:e36f1973a674 41 void TextDisplay::cls() {
Leigh_LbR 0:e36f1973a674 42 locate(0, 0);
Leigh_LbR 0:e36f1973a674 43 for(int i=0; i<columns()*rows(); i++) {
Leigh_LbR 0:e36f1973a674 44 putc(' ');
Leigh_LbR 0:e36f1973a674 45 }
Leigh_LbR 0:e36f1973a674 46 }
Leigh_LbR 0:e36f1973a674 47
Leigh_LbR 0:e36f1973a674 48 void TextDisplay::locate(int column, int row) {
Leigh_LbR 0:e36f1973a674 49 _column = column;
Leigh_LbR 0:e36f1973a674 50 _row = row;
Leigh_LbR 0:e36f1973a674 51 }
Leigh_LbR 0:e36f1973a674 52
Leigh_LbR 0:e36f1973a674 53 int TextDisplay::_getc() {
Leigh_LbR 0:e36f1973a674 54 return -1;
Leigh_LbR 0:e36f1973a674 55 }
Leigh_LbR 0:e36f1973a674 56
Leigh_LbR 0:e36f1973a674 57 void TextDisplay::foreground(uint16_t colour) {
Leigh_LbR 0:e36f1973a674 58 _foreground = colour;
Leigh_LbR 0:e36f1973a674 59 }
Leigh_LbR 0:e36f1973a674 60
Leigh_LbR 0:e36f1973a674 61 void TextDisplay::background(uint16_t colour) {
Leigh_LbR 0:e36f1973a674 62 _background = colour;
Leigh_LbR 0:e36f1973a674 63 }
Leigh_LbR 0:e36f1973a674 64
Leigh_LbR 0:e36f1973a674 65 bool TextDisplay::claim (FILE *stream) {
Leigh_LbR 0:e36f1973a674 66 if ( _path == NULL) {
Leigh_LbR 0:e36f1973a674 67 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
Leigh_LbR 0:e36f1973a674 68 return false;
Leigh_LbR 0:e36f1973a674 69 }
Leigh_LbR 0:e36f1973a674 70 if (freopen(_path, "w", stream) == NULL) {
Leigh_LbR 0:e36f1973a674 71 // Failed, should not happen
Leigh_LbR 0:e36f1973a674 72 return false;
Leigh_LbR 0:e36f1973a674 73 }
Leigh_LbR 0:e36f1973a674 74 // make sure we use line buffering
Leigh_LbR 0:e36f1973a674 75 setvbuf(stdout, NULL, _IOLBF, columns());
Leigh_LbR 0:e36f1973a674 76 return true;
Leigh_LbR 0:e36f1973a674 77 }