Paul Griffith
/
TextStar1
TextStar.cpp@0:775da631eb9a, 2010-01-17 (annotated)
- Committer:
- paulg
- Date:
- Sun Jan 17 11:06:20 2010 +0000
- Revision:
- 0:775da631eb9a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
paulg | 0:775da631eb9a | 1 | /* mbed TextStar serial LCD Library |
paulg | 0:775da631eb9a | 2 | * Copyright (c) 2009-2010 Paul Griffith |
paulg | 0:775da631eb9a | 3 | * Released under the MIT License: http://mbed.org/license/mit |
paulg | 0:775da631eb9a | 4 | * |
paulg | 0:775da631eb9a | 5 | * Last edit: 10 Jan 2010 |
paulg | 0:775da631eb9a | 6 | * |
paulg | 0:775da631eb9a | 7 | * TextStar CW-LCD-02 16x2 serial LCD module |
paulg | 0:775da631eb9a | 8 | * Cat's Whisker Technologies, http://www.cats-whisker.com |
paulg | 0:775da631eb9a | 9 | */ |
paulg | 0:775da631eb9a | 10 | |
paulg | 0:775da631eb9a | 11 | #include "TextStar.h" |
paulg | 0:775da631eb9a | 12 | #include "mbed.h" |
paulg | 0:775da631eb9a | 13 | |
paulg | 0:775da631eb9a | 14 | |
paulg | 0:775da631eb9a | 15 | TextStar::TextStar(PinName tx, PinName rx) : Serial(tx, rx) { |
paulg | 0:775da631eb9a | 16 | reset(); |
paulg | 0:775da631eb9a | 17 | } |
paulg | 0:775da631eb9a | 18 | |
paulg | 0:775da631eb9a | 19 | void TextStar::cls() { |
paulg | 0:775da631eb9a | 20 | //clear screen = 254,'S' |
paulg | 0:775da631eb9a | 21 | //does not affect auto-blank and auto-scroll |
paulg | 0:775da631eb9a | 22 | this->putc('\014'); |
paulg | 0:775da631eb9a | 23 | } |
paulg | 0:775da631eb9a | 24 | |
paulg | 0:775da631eb9a | 25 | void TextStar::locate(int column, int row) { |
paulg | 0:775da631eb9a | 26 | //position cursor = 254,'P',line (0-15), col (0-15) |
paulg | 0:775da631eb9a | 27 | this->printf("\376P%c%c", row + 1, column + 1); |
paulg | 0:775da631eb9a | 28 | } |
paulg | 0:775da631eb9a | 29 | |
paulg | 0:775da631eb9a | 30 | void TextStar::foreground(int colour) { |
paulg | 0:775da631eb9a | 31 | //colours not supported |
paulg | 0:775da631eb9a | 32 | } |
paulg | 0:775da631eb9a | 33 | |
paulg | 0:775da631eb9a | 34 | void TextStar::background(int colour) { |
paulg | 0:775da631eb9a | 35 | //colours not supported |
paulg | 0:775da631eb9a | 36 | } |
paulg | 0:775da631eb9a | 37 | |
paulg | 0:775da631eb9a | 38 | void TextStar::reset(int autoblank, int autoscroll) { |
paulg | 0:775da631eb9a | 39 | //reset screen = 254,'R' |
paulg | 0:775da631eb9a | 40 | this->printf("\376R"); |
paulg | 0:775da631eb9a | 41 | //set up auto-blank and auto-scroll as per arguments |
paulg | 0:775da631eb9a | 42 | _autoblank = (autoblank == 0) ? 0 : 1; |
paulg | 0:775da631eb9a | 43 | _autoscroll = (autoscroll == 0) ? 0 : 1; |
paulg | 0:775da631eb9a | 44 | this->printf("\376G%c", 1 + (_autoblank * 64) + (_autoscroll * 64) ); |
paulg | 0:775da631eb9a | 45 | // this->printf("AB = %d AS = %d", _autoblank, _autoscroll); |
paulg | 0:775da631eb9a | 46 | // wait(2.0); |
paulg | 0:775da631eb9a | 47 | // cls(); |
paulg | 0:775da631eb9a | 48 | } |
paulg | 0:775da631eb9a | 49 | |
paulg | 0:775da631eb9a | 50 | void TextStar::left(void) { |
paulg | 0:775da631eb9a | 51 | //move cursor left = 8 |
paulg | 0:775da631eb9a | 52 | this->putc('\010'); |
paulg | 0:775da631eb9a | 53 | } |
paulg | 0:775da631eb9a | 54 | |
paulg | 0:775da631eb9a | 55 | void TextStar::right(void) { |
paulg | 0:775da631eb9a | 56 | //move cursor right = 9 |
paulg | 0:775da631eb9a | 57 | this->putc('\011'); |
paulg | 0:775da631eb9a | 58 | } |
paulg | 0:775da631eb9a | 59 | |
paulg | 0:775da631eb9a | 60 | void TextStar::down(void) { |
paulg | 0:775da631eb9a | 61 | //move cursor down one line = 10 |
paulg | 0:775da631eb9a | 62 | this->putc('\012'); |
paulg | 0:775da631eb9a | 63 | } |
paulg | 0:775da631eb9a | 64 | |
paulg | 0:775da631eb9a | 65 | void TextStar::up(void) { |
paulg | 0:775da631eb9a | 66 | //move cursor up one line = 11 |
paulg | 0:775da631eb9a | 67 | this->putc('\013'); |
paulg | 0:775da631eb9a | 68 | } |
paulg | 0:775da631eb9a | 69 | |
paulg | 0:775da631eb9a | 70 | void TextStar::home(void) { |
paulg | 0:775da631eb9a | 71 | //cursor home = 254,'H' |
paulg | 0:775da631eb9a | 72 | this->printf("\376H"); |
paulg | 0:775da631eb9a | 73 | } |
paulg | 0:775da631eb9a | 74 | |
paulg | 0:775da631eb9a | 75 | void TextStar::crlf(void) { |
paulg | 0:775da631eb9a | 76 | //carriage return = 13 |
paulg | 0:775da631eb9a | 77 | this->putc('\015'); |
paulg | 0:775da631eb9a | 78 | } |
paulg | 0:775da631eb9a | 79 | |
paulg | 0:775da631eb9a | 80 | void TextStar::del(void) { |
paulg | 0:775da631eb9a | 81 | //delete character = 127 |
paulg | 0:775da631eb9a | 82 | this->putc('\177'); |
paulg | 0:775da631eb9a | 83 | } |
paulg | 0:775da631eb9a | 84 | |
paulg | 0:775da631eb9a | 85 | void TextStar::set_cursor(int style) { |
paulg | 0:775da631eb9a | 86 | //styles: 0 = none, 1 = solid block, 2 = flash block, 3 = solid uline, 4 = flash uline |
paulg | 0:775da631eb9a | 87 | if (style < 0 || style > 4) |
paulg | 0:775da631eb9a | 88 | return; |
paulg | 0:775da631eb9a | 89 | this->printf("\376C%c", style); |
paulg | 0:775da631eb9a | 90 | } |
paulg | 0:775da631eb9a | 91 | |
paulg | 0:775da631eb9a | 92 | void TextStar::window(int line) { |
paulg | 0:775da631eb9a | 93 | //move visible window to line (0-14) |
paulg | 0:775da631eb9a | 94 | if (line < 0 || line > 14) |
paulg | 0:775da631eb9a | 95 | return; |
paulg | 0:775da631eb9a | 96 | this->printf("\376G%c", line + 1 + (_autoblank * 64) + (_autoscroll * 128) ); |
paulg | 0:775da631eb9a | 97 | } |
paulg | 0:775da631eb9a | 98 | |
paulg | 0:775da631eb9a | 99 | void TextStar::scroll_up(void) { |
paulg | 0:775da631eb9a | 100 | //move visble window up one line |
paulg | 0:775da631eb9a | 101 | this->printf("\376O%c", 1); |
paulg | 0:775da631eb9a | 102 | } |
paulg | 0:775da631eb9a | 103 | |
paulg | 0:775da631eb9a | 104 | void TextStar::scroll_down(void) { |
paulg | 0:775da631eb9a | 105 | //move visible window down one line |
paulg | 0:775da631eb9a | 106 | this->printf("\376O%c", 0); |
paulg | 0:775da631eb9a | 107 | } |
paulg | 0:775da631eb9a | 108 | |
paulg | 0:775da631eb9a | 109 | void TextStar::bar_graph(int capped, int length, int percentage) { |
paulg | 0:775da631eb9a | 110 | if (length < 1 || length > 16) { |
paulg | 0:775da631eb9a | 111 | this->printf("Bad len %d", length); |
paulg | 0:775da631eb9a | 112 | wait(2.0); |
paulg | 0:775da631eb9a | 113 | return; |
paulg | 0:775da631eb9a | 114 | } |
paulg | 0:775da631eb9a | 115 | if (percentage < 0 || percentage > 100) { |
paulg | 0:775da631eb9a | 116 | this->printf("Bad val %d", percentage); |
paulg | 0:775da631eb9a | 117 | wait(2.0); |
paulg | 0:775da631eb9a | 118 | return; |
paulg | 0:775da631eb9a | 119 | } |
paulg | 0:775da631eb9a | 120 | this->printf("\376%c%c%c", (capped == 0)? 'B' : 'b', length, percentage); |
paulg | 0:775da631eb9a | 121 | } |
paulg | 0:775da631eb9a | 122 | |
paulg | 0:775da631eb9a | 123 | void TextStar::custom_char(int num, char *bitmap) { |
paulg | 0:775da631eb9a | 124 | //define custom character = 254,'D',bm1,bm2,bm3,bm4,bm5,bm6,bm7,bm8 |
paulg | 0:775da631eb9a | 125 | if (num < 128 || num > 135) { |
paulg | 0:775da631eb9a | 126 | this->printf("Bad CC num %d", num); |
paulg | 0:775da631eb9a | 127 | wait(2.0); |
paulg | 0:775da631eb9a | 128 | return; |
paulg | 0:775da631eb9a | 129 | } |
paulg | 0:775da631eb9a | 130 | this->printf("\376D%c%c%c%c%c%c%c%c%c", num, bitmap[0], bitmap[1], bitmap[2], bitmap[3], |
paulg | 0:775da631eb9a | 131 | bitmap[4], bitmap[5], bitmap[6], bitmap[7]); |
paulg | 0:775da631eb9a | 132 | } |
paulg | 0:775da631eb9a | 133 | |
paulg | 0:775da631eb9a | 134 | void TextStar::version(void) { |
paulg | 0:775da631eb9a | 135 | //display firmware version and custom characters = 254,'V' |
paulg | 0:775da631eb9a | 136 | this->printf("\376V"); |
paulg | 0:775da631eb9a | 137 | } |
paulg | 0:775da631eb9a | 138 | |
paulg | 0:775da631eb9a | 139 | void TextStar::send_version(void) { |
paulg | 0:775da631eb9a | 140 | //send firmware version = 254,'v' |
paulg | 0:775da631eb9a | 141 | this->printf("\376v"); |
paulg | 0:775da631eb9a | 142 | } |
paulg | 0:775da631eb9a | 143 | |
paulg | 0:775da631eb9a | 144 | void TextStar::send_keys(void) { |
paulg | 0:775da631eb9a | 145 | //send key states = 254,'K' |
paulg | 0:775da631eb9a | 146 | this->printf("\376K"); |
paulg | 0:775da631eb9a | 147 | } |