Psi Swarm robot library version 0.9
Fork of PsiSwarmV8_CPP by
display.h@12:878c6e9d9e60, 2016-10-17 (annotated)
- Committer:
- jah128
- Date:
- Mon Oct 17 13:09:10 2016 +0000
- Revision:
- 12:878c6e9d9e60
- Parent:
- 8:6c92789d5f87
- Child:
- 15:66be5ec52c3b
Added Psiswarm class; changed Dances to Animations
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:d6269d17c8cf | 1 | /* University of York Robotics Laboratory PsiSwarm Library: Display Driver Header File |
jah128 | 8:6c92789d5f87 | 2 | * |
jah128 | 6:b340a527add9 | 3 | * Copyright 2016 University of York |
jah128 | 6:b340a527add9 | 4 | * |
jah128 | 8:6c92789d5f87 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. |
jah128 | 6:b340a527add9 | 6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
jah128 | 6:b340a527add9 | 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS |
jah128 | 8:6c92789d5f87 | 8 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jah128 | 6:b340a527add9 | 9 | * See the License for the specific language governing permissions and limitations under the License. |
jah128 | 6:b340a527add9 | 10 | * |
jah128 | 0:d6269d17c8cf | 11 | * File: display.h |
jah128 | 0:d6269d17c8cf | 12 | * |
jah128 | 0:d6269d17c8cf | 13 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:d6269d17c8cf | 14 | * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:d6269d17c8cf | 15 | * |
jah128 | 12:878c6e9d9e60 | 16 | * PsiSwarm Library Version: 0.8 |
jah128 | 0:d6269d17c8cf | 17 | * |
jah128 | 5:3cdd1a37cdd7 | 18 | * October 2016 |
jah128 | 0:d6269d17c8cf | 19 | * |
jah128 | 0:d6269d17c8cf | 20 | * |
jah128 | 0:d6269d17c8cf | 21 | * Driver for the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD |
jah128 | 0:d6269d17c8cf | 22 | * |
jah128 | 0:d6269d17c8cf | 23 | * Farnell part 2218942 or 2063206 |
jah128 | 0:d6269d17c8cf | 24 | * |
jah128 | 8:6c92789d5f87 | 25 | */ |
jah128 | 8:6c92789d5f87 | 26 | |
jah128 | 8:6c92789d5f87 | 27 | |
jah128 | 0:d6269d17c8cf | 28 | #ifndef DISPLAY_H |
jah128 | 0:d6269d17c8cf | 29 | #define DISPLAY_H |
jah128 | 0:d6269d17c8cf | 30 | |
jah128 | 0:d6269d17c8cf | 31 | #define PAGE_TIME 0.4 |
jah128 | 0:d6269d17c8cf | 32 | #define CLEAR_TIME 0.8 |
jah128 | 0:d6269d17c8cf | 33 | |
jah128 | 8:6c92789d5f87 | 34 | /** |
jah128 | 8:6c92789d5f87 | 35 | * Display class |
jah128 | 8:6c92789d5f87 | 36 | * Functions for use with the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD |
jah128 | 8:6c92789d5f87 | 37 | * Farnell part 2218942 or 2063206 |
jah128 | 8:6c92789d5f87 | 38 | * |
jah128 | 8:6c92789d5f87 | 39 | * Example: |
jah128 | 8:6c92789d5f87 | 40 | * @code |
jah128 | 8:6c92789d5f87 | 41 | * #include "psiswarm.h" |
jah128 | 8:6c92789d5f87 | 42 | * |
jah128 | 8:6c92789d5f87 | 43 | * int main() { |
jah128 | 8:6c92789d5f87 | 44 | * init(); |
jah128 | 8:6c92789d5f87 | 45 | * display.clear_display; //Clears display |
jah128 | 8:6c92789d5f87 | 46 | * display.set_position(0,2); //Set cursor to row 0 column 2 |
jah128 | 8:6c92789d5f87 | 47 | * display.write_string("YORK ROBOTICS"); |
jah128 | 8:6c92789d5f87 | 48 | * display.set_position(1,3); //Set cursor to row 1 column 3 |
jah128 | 8:6c92789d5f87 | 49 | * display.write_string("LABORATORY"); |
jah128 | 8:6c92789d5f87 | 50 | * } |
jah128 | 8:6c92789d5f87 | 51 | * @endcode |
jah128 | 8:6c92789d5f87 | 52 | */ |
jah128 | 8:6c92789d5f87 | 53 | class Display : public Stream |
jah128 | 8:6c92789d5f87 | 54 | { |
jah128 | 0:d6269d17c8cf | 55 | |
jah128 | 0:d6269d17c8cf | 56 | // Public Functions |
jah128 | 0:d6269d17c8cf | 57 | |
jah128 | 0:d6269d17c8cf | 58 | public: |
jah128 | 0:d6269d17c8cf | 59 | |
jah128 | 8:6c92789d5f87 | 60 | /** Create the LCD Display object connected to the default pins |
jah128 | 8:6c92789d5f87 | 61 | * (sda = p28, scl = p27, reset = p29, backlight = p30) |
jah128 | 8:6c92789d5f87 | 62 | */ |
jah128 | 8:6c92789d5f87 | 63 | Display(); |
jah128 | 8:6c92789d5f87 | 64 | |
jah128 | 8:6c92789d5f87 | 65 | /** Create the LCD Display object connected to specific pins |
jah128 | 0:d6269d17c8cf | 66 | * |
jah128 | 0:d6269d17c8cf | 67 | * @param sda pin - default is p28 |
jah128 | 0:d6269d17c8cf | 68 | * @param scl pin - default is p27 |
jah128 | 0:d6269d17c8cf | 69 | * @param reset pin - default is p29 |
jah128 | 0:d6269d17c8cf | 70 | * @param backlight pin - default is p30 |
jah128 | 0:d6269d17c8cf | 71 | */ |
jah128 | 0:d6269d17c8cf | 72 | Display(PinName sda, PinName scl, PinName reset, PinName backlight); |
jah128 | 0:d6269d17c8cf | 73 | |
jah128 | 8:6c92789d5f87 | 74 | /** Clear the display |
jah128 | 8:6c92789d5f87 | 75 | */ |
jah128 | 8:6c92789d5f87 | 76 | void clear_display(void); |
jah128 | 0:d6269d17c8cf | 77 | |
jah128 | 8:6c92789d5f87 | 78 | /** Set cursor to home position |
jah128 | 8:6c92789d5f87 | 79 | */ |
jah128 | 8:6c92789d5f87 | 80 | void home(void); |
jah128 | 0:d6269d17c8cf | 81 | |
jah128 | 8:6c92789d5f87 | 82 | /** Print string message |
jah128 | 8:6c92789d5f87 | 83 | * @param message - The null-terminated message to print |
jah128 | 8:6c92789d5f87 | 84 | */ |
jah128 | 8:6c92789d5f87 | 85 | void write_string(char * message); |
jah128 | 0:d6269d17c8cf | 86 | |
jah128 | 8:6c92789d5f87 | 87 | /** Print string message of given length |
jah128 | 8:6c92789d5f87 | 88 | * @param message - The message to print |
jah128 | 8:6c92789d5f87 | 89 | * @param length - The number of characters to display |
jah128 | 8:6c92789d5f87 | 90 | */ |
jah128 | 8:6c92789d5f87 | 91 | void write_string(char * message, char length); |
jah128 | 0:d6269d17c8cf | 92 | |
jah128 | 8:6c92789d5f87 | 93 | /** Set the row and column of cursor position |
jah128 | 8:6c92789d5f87 | 94 | * @param row - The row of the display to set the cursor to (either 0 or 1) |
jah128 | 8:6c92789d5f87 | 95 | * @param column - The column of the display to set the cursor to (range 0 to 15) |
jah128 | 8:6c92789d5f87 | 96 | */ |
jah128 | 8:6c92789d5f87 | 97 | void set_position(char row, char column); |
jah128 | 0:d6269d17c8cf | 98 | |
jah128 | 8:6c92789d5f87 | 99 | /** Enable or disable cursor |
jah128 | 8:6c92789d5f87 | 100 | * @param enable - Set to 1 to enable the cursor visibility |
jah128 | 8:6c92789d5f87 | 101 | */ |
jah128 | 8:6c92789d5f87 | 102 | void set_cursor(char enable); |
jah128 | 0:d6269d17c8cf | 103 | |
jah128 | 8:6c92789d5f87 | 104 | /** Enable or disable cursor blink |
jah128 | 8:6c92789d5f87 | 105 | * @param enable - Set to 1 to enable the cursor blinking mode |
jah128 | 8:6c92789d5f87 | 106 | */ |
jah128 | 8:6c92789d5f87 | 107 | void set_blink(char enable); |
jah128 | 0:d6269d17c8cf | 108 | |
jah128 | 8:6c92789d5f87 | 109 | /** Enable or disable display |
jah128 | 8:6c92789d5f87 | 110 | * @param enable - Set to 1 to enable the display output |
jah128 | 8:6c92789d5f87 | 111 | */ |
jah128 | 8:6c92789d5f87 | 112 | void set_display(char enable); |
jah128 | 0:d6269d17c8cf | 113 | |
jah128 | 8:6c92789d5f87 | 114 | /** Set the brightness of the backlight |
jah128 | 8:6c92789d5f87 | 115 | * @param brightness - Sets the brightness of the display (range 0.0 to 1.0) |
jah128 | 8:6c92789d5f87 | 116 | */ |
jah128 | 8:6c92789d5f87 | 117 | void set_backlight_brightness(float brightness); |
jah128 | 0:d6269d17c8cf | 118 | |
jah128 | 8:6c92789d5f87 | 119 | // Special function for when debug messages are sent to display |
jah128 | 8:6c92789d5f87 | 120 | void debug_page(char * message, char length); |
jah128 | 0:d6269d17c8cf | 121 | |
jah128 | 8:6c92789d5f87 | 122 | // Internal function used to restore display after debug messages |
jah128 | 8:6c92789d5f87 | 123 | void IF_restore_page(void); |
jah128 | 0:d6269d17c8cf | 124 | |
jah128 | 8:6c92789d5f87 | 125 | // Internal function used to show multi-page debug messages |
jah128 | 8:6c92789d5f87 | 126 | void IF_debug_multipage(void); |
jah128 | 8:6c92789d5f87 | 127 | |
jah128 | 8:6c92789d5f87 | 128 | // Internal function used to toggle backlight |
jah128 | 8:6c92789d5f87 | 129 | void IF_backlight_toggle(void); |
jah128 | 0:d6269d17c8cf | 130 | |
jah128 | 8:6c92789d5f87 | 131 | //Parts of initialisation routine |
jah128 | 8:6c92789d5f87 | 132 | void post_init(void); |
jah128 | 8:6c92789d5f87 | 133 | void post_post_init(void); |
jah128 | 0:d6269d17c8cf | 134 | |
jah128 | 8:6c92789d5f87 | 135 | // Send a 1-byte control message to the display |
jah128 | 8:6c92789d5f87 | 136 | int i2c_message(char byte); |
jah128 | 0:d6269d17c8cf | 137 | |
jah128 | 8:6c92789d5f87 | 138 | // Default initialisation sequence for the display |
jah128 | 8:6c92789d5f87 | 139 | void init_display(char mode); |
jah128 | 8:6c92789d5f87 | 140 | |
jah128 | 8:6c92789d5f87 | 141 | int disp_putc(int c); |
jah128 | 0:d6269d17c8cf | 142 | |
jah128 | 0:d6269d17c8cf | 143 | |
jah128 | 0:d6269d17c8cf | 144 | private : |
jah128 | 0:d6269d17c8cf | 145 | |
jah128 | 0:d6269d17c8cf | 146 | I2C _i2c; |
jah128 | 0:d6269d17c8cf | 147 | DigitalOut _reset; |
jah128 | 0:d6269d17c8cf | 148 | DigitalOut _backlight; |
jah128 | 8:6c92789d5f87 | 149 | |
jah128 | 0:d6269d17c8cf | 150 | char display_on; |
jah128 | 0:d6269d17c8cf | 151 | char cursor_on; |
jah128 | 0:d6269d17c8cf | 152 | char blink_on; |
jah128 | 8:6c92789d5f87 | 153 | |
jah128 | 0:d6269d17c8cf | 154 | void _set_display(); |
jah128 | 8:6c92789d5f87 | 155 | |
jah128 | 0:d6269d17c8cf | 156 | virtual int _putc(int c); |
jah128 | 0:d6269d17c8cf | 157 | virtual int _getc(); |
jah128 | 8:6c92789d5f87 | 158 | |
jah128 | 0:d6269d17c8cf | 159 | }; |
jah128 | 0:d6269d17c8cf | 160 | |
jah128 | 0:d6269d17c8cf | 161 | #endif // DISPLAY_H |