Robot Arm Controller Library
Dependents: PR_RobotArm lighthouse_2
display.h@0:9f7b70e0186e, 2017-02-16 (annotated)
- Committer:
- jah128
- Date:
- Thu Feb 16 23:57:45 2017 +0000
- Revision:
- 0:9f7b70e0186e
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:9f7b70e0186e | 1 | /* University of York Robotics Laboratory Robot Arm Controller Board |
jah128 | 0:9f7b70e0186e | 2 | * |
jah128 | 0:9f7b70e0186e | 3 | * Driver for the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD [Farnell part 2218942 or 2063206] |
jah128 | 0:9f7b70e0186e | 4 | * |
jah128 | 0:9f7b70e0186e | 5 | * File: display.cpp |
jah128 | 0:9f7b70e0186e | 6 | * |
jah128 | 0:9f7b70e0186e | 7 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:9f7b70e0186e | 8 | * |
jah128 | 0:9f7b70e0186e | 9 | * James Hilder, Alan Millard, Shuhei Miyashita, Homero Elizondo, Jon Timmis |
jah128 | 0:9f7b70e0186e | 10 | * |
jah128 | 0:9f7b70e0186e | 11 | * |
jah128 | 0:9f7b70e0186e | 12 | * January 2017 |
jah128 | 0:9f7b70e0186e | 13 | * |
jah128 | 0:9f7b70e0186e | 14 | * |
jah128 | 0:9f7b70e0186e | 15 | */ |
jah128 | 0:9f7b70e0186e | 16 | |
jah128 | 0:9f7b70e0186e | 17 | |
jah128 | 0:9f7b70e0186e | 18 | #ifndef DISPLAY_H |
jah128 | 0:9f7b70e0186e | 19 | #define DISPLAY_H |
jah128 | 0:9f7b70e0186e | 20 | |
jah128 | 0:9f7b70e0186e | 21 | |
jah128 | 0:9f7b70e0186e | 22 | /** |
jah128 | 0:9f7b70e0186e | 23 | * Display class |
jah128 | 0:9f7b70e0186e | 24 | * Functions for use with the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD |
jah128 | 0:9f7b70e0186e | 25 | * Farnell part 2218942 or 2063206 |
jah128 | 0:9f7b70e0186e | 26 | * |
jah128 | 0:9f7b70e0186e | 27 | * Example: |
jah128 | 0:9f7b70e0186e | 28 | * @code |
jah128 | 0:9f7b70e0186e | 29 | * #include "robotarm.h" |
jah128 | 0:9f7b70e0186e | 30 | * |
jah128 | 0:9f7b70e0186e | 31 | * Robotarm arm; |
jah128 | 0:9f7b70e0186e | 32 | * |
jah128 | 0:9f7b70e0186e | 33 | * int main() { |
jah128 | 0:9f7b70e0186e | 34 | * arm.init(); |
jah128 | 0:9f7b70e0186e | 35 | * display.clear_display; //Clears display |
jah128 | 0:9f7b70e0186e | 36 | * display.set_position(0,2); //Set cursor to row 0 column 2 |
jah128 | 0:9f7b70e0186e | 37 | * display.write_string("YORK ROBOTICS"); |
jah128 | 0:9f7b70e0186e | 38 | * display.set_position(1,3); //Set cursor to row 1 column 3 |
jah128 | 0:9f7b70e0186e | 39 | * display.write_string("LABORATORY"); |
jah128 | 0:9f7b70e0186e | 40 | * } |
jah128 | 0:9f7b70e0186e | 41 | * @endcode |
jah128 | 0:9f7b70e0186e | 42 | */ |
jah128 | 0:9f7b70e0186e | 43 | class Display : public Stream |
jah128 | 0:9f7b70e0186e | 44 | { |
jah128 | 0:9f7b70e0186e | 45 | |
jah128 | 0:9f7b70e0186e | 46 | // Public Functions |
jah128 | 0:9f7b70e0186e | 47 | |
jah128 | 0:9f7b70e0186e | 48 | public: |
jah128 | 0:9f7b70e0186e | 49 | |
jah128 | 0:9f7b70e0186e | 50 | /** Create the LCD Display object connected to the default pins |
jah128 | 0:9f7b70e0186e | 51 | * (sda = p28, scl = p27) |
jah128 | 0:9f7b70e0186e | 52 | */ |
jah128 | 0:9f7b70e0186e | 53 | Display(); |
jah128 | 0:9f7b70e0186e | 54 | |
jah128 | 0:9f7b70e0186e | 55 | /** Create the LCD Display object connected to specific pins |
jah128 | 0:9f7b70e0186e | 56 | * |
jah128 | 0:9f7b70e0186e | 57 | * @param sda pin - default is p28 |
jah128 | 0:9f7b70e0186e | 58 | * @param scl pin - default is p27 |
jah128 | 0:9f7b70e0186e | 59 | */ |
jah128 | 0:9f7b70e0186e | 60 | Display(PinName sda, PinName scl); |
jah128 | 0:9f7b70e0186e | 61 | |
jah128 | 0:9f7b70e0186e | 62 | /** Clear the display |
jah128 | 0:9f7b70e0186e | 63 | */ |
jah128 | 0:9f7b70e0186e | 64 | void clear_display(void); |
jah128 | 0:9f7b70e0186e | 65 | |
jah128 | 0:9f7b70e0186e | 66 | /** Set cursor to home position |
jah128 | 0:9f7b70e0186e | 67 | */ |
jah128 | 0:9f7b70e0186e | 68 | void home(void); |
jah128 | 0:9f7b70e0186e | 69 | |
jah128 | 0:9f7b70e0186e | 70 | /** Print string message |
jah128 | 0:9f7b70e0186e | 71 | * @param message - The null-terminated message to print |
jah128 | 0:9f7b70e0186e | 72 | */ |
jah128 | 0:9f7b70e0186e | 73 | void write_string(char * message); |
jah128 | 0:9f7b70e0186e | 74 | |
jah128 | 0:9f7b70e0186e | 75 | /** Print string message of given length |
jah128 | 0:9f7b70e0186e | 76 | * @param message - The message to print |
jah128 | 0:9f7b70e0186e | 77 | * @param length - The number of characters to display |
jah128 | 0:9f7b70e0186e | 78 | */ |
jah128 | 0:9f7b70e0186e | 79 | void write_string(char * message, char length); |
jah128 | 0:9f7b70e0186e | 80 | |
jah128 | 0:9f7b70e0186e | 81 | /** Set the row and column of cursor position |
jah128 | 0:9f7b70e0186e | 82 | * @param row - The row of the display to set the cursor to (either 0 or 1) |
jah128 | 0:9f7b70e0186e | 83 | * @param column - The column of the display to set the cursor to (range 0 to 15) |
jah128 | 0:9f7b70e0186e | 84 | */ |
jah128 | 0:9f7b70e0186e | 85 | void set_position(char row, char column); |
jah128 | 0:9f7b70e0186e | 86 | |
jah128 | 0:9f7b70e0186e | 87 | /** Enable or disable cursor |
jah128 | 0:9f7b70e0186e | 88 | * @param enable - Set to 1 to enable the cursor visibility |
jah128 | 0:9f7b70e0186e | 89 | */ |
jah128 | 0:9f7b70e0186e | 90 | void set_cursor(char enable); |
jah128 | 0:9f7b70e0186e | 91 | |
jah128 | 0:9f7b70e0186e | 92 | /** Enable or disable cursor blink |
jah128 | 0:9f7b70e0186e | 93 | * @param enable - Set to 1 to enable the cursor blinking mode |
jah128 | 0:9f7b70e0186e | 94 | */ |
jah128 | 0:9f7b70e0186e | 95 | void set_blink(char enable); |
jah128 | 0:9f7b70e0186e | 96 | |
jah128 | 0:9f7b70e0186e | 97 | /** Enable or disable display |
jah128 | 0:9f7b70e0186e | 98 | * @param enable - Set to 1 to enable the display output |
jah128 | 0:9f7b70e0186e | 99 | */ |
jah128 | 0:9f7b70e0186e | 100 | void set_display(char enable); |
jah128 | 0:9f7b70e0186e | 101 | |
jah128 | 0:9f7b70e0186e | 102 | //Parts of initialisation routine |
jah128 | 0:9f7b70e0186e | 103 | void post_init(void); |
jah128 | 0:9f7b70e0186e | 104 | void post_post_init(void); |
jah128 | 0:9f7b70e0186e | 105 | |
jah128 | 0:9f7b70e0186e | 106 | // Send a 1-byte control message to the display |
jah128 | 0:9f7b70e0186e | 107 | int i2c_message(char byte); |
jah128 | 0:9f7b70e0186e | 108 | |
jah128 | 0:9f7b70e0186e | 109 | // Default initialisation sequence for the display |
jah128 | 0:9f7b70e0186e | 110 | void init(void); |
jah128 | 0:9f7b70e0186e | 111 | |
jah128 | 0:9f7b70e0186e | 112 | int disp_putc(int c); |
jah128 | 0:9f7b70e0186e | 113 | |
jah128 | 0:9f7b70e0186e | 114 | |
jah128 | 0:9f7b70e0186e | 115 | private : |
jah128 | 0:9f7b70e0186e | 116 | |
jah128 | 0:9f7b70e0186e | 117 | I2C _i2c; |
jah128 | 0:9f7b70e0186e | 118 | |
jah128 | 0:9f7b70e0186e | 119 | char display_on; |
jah128 | 0:9f7b70e0186e | 120 | char cursor_on; |
jah128 | 0:9f7b70e0186e | 121 | char blink_on; |
jah128 | 0:9f7b70e0186e | 122 | |
jah128 | 0:9f7b70e0186e | 123 | void _set_display(); |
jah128 | 0:9f7b70e0186e | 124 | |
jah128 | 0:9f7b70e0186e | 125 | virtual int _putc(int c); |
jah128 | 0:9f7b70e0186e | 126 | virtual int _getc(); |
jah128 | 0:9f7b70e0186e | 127 | |
jah128 | 0:9f7b70e0186e | 128 | }; |
jah128 | 0:9f7b70e0186e | 129 | |
jah128 | 0:9f7b70e0186e | 130 | #endif // DISPLAY_H |
jah128 | 0:9f7b70e0186e | 131 | |
jah128 | 0:9f7b70e0186e | 132 | /* |
jah128 | 0:9f7b70e0186e | 133 | * Copyright 2017 University of York |
jah128 | 0:9f7b70e0186e | 134 | * |
jah128 | 0:9f7b70e0186e | 135 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. |
jah128 | 0:9f7b70e0186e | 136 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
jah128 | 0:9f7b70e0186e | 137 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS |
jah128 | 0:9f7b70e0186e | 138 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jah128 | 0:9f7b70e0186e | 139 | * See the License for the specific language governing permissions and limitations under the License. |
jah128 | 0:9f7b70e0186e | 140 | */ |