Psi Swarm robot library version 0.9
Fork of PsiSwarmV9 by
display.cpp@20:1bc6c6dc477b, 2018-05-14 (annotated)
- Committer:
- jah128
- Date:
- Mon May 14 15:35:38 2018 +0000
- Revision:
- 20:1bc6c6dc477b
- Parent:
- 16:50686c07ad07
Updated?
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 Source File |
jah128 | 0:d6269d17c8cf | 2 | * |
jah128 | 16:50686c07ad07 | 3 | * Copyright 2017 University of York |
jah128 | 6:b340a527add9 | 4 | * |
jah128 | 6:b340a527add9 | 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 | 6:b340a527add9 | 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.cpp |
jah128 | 0:d6269d17c8cf | 12 | * |
jah128 | 0:d6269d17c8cf | 13 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:d6269d17c8cf | 14 | * |
jah128 | 0:d6269d17c8cf | 15 | * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:d6269d17c8cf | 16 | * |
jah128 | 16:50686c07ad07 | 17 | * PsiSwarm Library Version: 0.9 |
jah128 | 0:d6269d17c8cf | 18 | * |
jah128 | 16:50686c07ad07 | 19 | * June 2017 |
jah128 | 0:d6269d17c8cf | 20 | * |
jah128 | 0:d6269d17c8cf | 21 | * Driver for the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD |
jah128 | 0:d6269d17c8cf | 22 | * [Farnell part 2218942 or 2063206] |
jah128 | 0:d6269d17c8cf | 23 | * |
jah128 | 0:d6269d17c8cf | 24 | */ |
jah128 | 0:d6269d17c8cf | 25 | |
jah128 | 0:d6269d17c8cf | 26 | #include "psiswarm.h" |
jah128 | 0:d6269d17c8cf | 27 | |
jah128 | 0:d6269d17c8cf | 28 | Timeout init_timeout; |
jah128 | 0:d6269d17c8cf | 29 | Timeout backlight_timeout; |
jah128 | 0:d6269d17c8cf | 30 | Timeout debug_timeout; |
jah128 | 0:d6269d17c8cf | 31 | int backlight_on_time; |
jah128 | 0:d6269d17c8cf | 32 | int backlight_off_time; |
jah128 | 0:d6269d17c8cf | 33 | char backlight_step; |
jah128 | 0:d6269d17c8cf | 34 | char multipage[200]; |
jah128 | 0:d6269d17c8cf | 35 | char multipage_length = 0; |
jah128 | 0:d6269d17c8cf | 36 | char preserve_line_1 [17]; |
jah128 | 0:d6269d17c8cf | 37 | char preserve_line_2 [17]; |
jah128 | 0:d6269d17c8cf | 38 | char c_row=0; |
jah128 | 0:d6269d17c8cf | 39 | char c_column=0; |
jah128 | 0:d6269d17c8cf | 40 | char p_row; |
jah128 | 0:d6269d17c8cf | 41 | char p_column; |
jah128 | 0:d6269d17c8cf | 42 | |
jah128 | 0:d6269d17c8cf | 43 | |
jah128 | 0:d6269d17c8cf | 44 | Display::Display(PinName sda, PinName scl, PinName reset, PinName backlight) : Stream("display"), _i2c(sda,scl), _reset(reset), _backlight(backlight) { |
jah128 | 0:d6269d17c8cf | 45 | } |
jah128 | 0:d6269d17c8cf | 46 | |
jah128 | 0:d6269d17c8cf | 47 | Display::Display() : Stream("display"), _i2c(p28,p27), _reset(p29), _backlight(p30) { |
jah128 | 0:d6269d17c8cf | 48 | } |
jah128 | 0:d6269d17c8cf | 49 | |
jah128 | 0:d6269d17c8cf | 50 | int Display::i2c_message(char byte){ |
jah128 | 0:d6269d17c8cf | 51 | char bytes [2]; |
jah128 | 0:d6269d17c8cf | 52 | bytes[0]=0x80; |
jah128 | 0:d6269d17c8cf | 53 | bytes[1]=byte; |
jah128 | 0:d6269d17c8cf | 54 | int ret=_i2c.write(LCD_ADDRESS,bytes,2); |
jah128 | 0:d6269d17c8cf | 55 | wait(0.01); |
jah128 | 0:d6269d17c8cf | 56 | return ret; |
jah128 | 0:d6269d17c8cf | 57 | } |
jah128 | 0:d6269d17c8cf | 58 | |
jah128 | 0:d6269d17c8cf | 59 | int Display::disp_putc(int c){ |
jah128 | 0:d6269d17c8cf | 60 | char message [2]; |
jah128 | 0:d6269d17c8cf | 61 | message[0]=0x40; |
jah128 | 0:d6269d17c8cf | 62 | message[1]=c; |
jah128 | 0:d6269d17c8cf | 63 | _i2c.write(LCD_ADDRESS,message,2); |
jah128 | 0:d6269d17c8cf | 64 | wait(0.01); |
jah128 | 0:d6269d17c8cf | 65 | return c; |
jah128 | 0:d6269d17c8cf | 66 | } |
jah128 | 15:66be5ec52c3b | 67 | void Display::init_display_start(){ |
jah128 | 0:d6269d17c8cf | 68 | display_on = 1; |
jah128 | 0:d6269d17c8cf | 69 | set_backlight_brightness(1); |
jah128 | 0:d6269d17c8cf | 70 | cursor_on = 0; |
jah128 | 0:d6269d17c8cf | 71 | blink_on = 0; |
jah128 | 0:d6269d17c8cf | 72 | |
jah128 | 0:d6269d17c8cf | 73 | _reset=1; |
jah128 | 0:d6269d17c8cf | 74 | wait(0.02); |
jah128 | 0:d6269d17c8cf | 75 | //Set reset low |
jah128 | 0:d6269d17c8cf | 76 | _reset=0; |
jah128 | 0:d6269d17c8cf | 77 | wait(0.001); |
jah128 | 0:d6269d17c8cf | 78 | _reset=1; |
jah128 | 0:d6269d17c8cf | 79 | wait(0.03); |
jah128 | 0:d6269d17c8cf | 80 | i2c_message(0x38); |
jah128 | 0:d6269d17c8cf | 81 | i2c_message(0x39); |
jah128 | 0:d6269d17c8cf | 82 | i2c_message(0x14); |
jah128 | 0:d6269d17c8cf | 83 | i2c_message(0x74); |
jah128 | 0:d6269d17c8cf | 84 | i2c_message(0x54); |
jah128 | 0:d6269d17c8cf | 85 | i2c_message(0x6F); |
jah128 | 0:d6269d17c8cf | 86 | _set_display(); |
jah128 | 0:d6269d17c8cf | 87 | clear_display(); |
jah128 | 0:d6269d17c8cf | 88 | char psis[17]; |
jah128 | 0:d6269d17c8cf | 89 | for(int i=0;i<16;i++){ |
jah128 | 0:d6269d17c8cf | 90 | psis[i]=0x1D; |
jah128 | 0:d6269d17c8cf | 91 | } |
jah128 | 0:d6269d17c8cf | 92 | set_position(0,0); |
jah128 | 0:d6269d17c8cf | 93 | write_string(psis,16); |
jah128 | 0:d6269d17c8cf | 94 | set_position(1,0); |
jah128 | 0:d6269d17c8cf | 95 | write_string(psis,16); |
jah128 | 15:66be5ec52c3b | 96 | } |
jah128 | 15:66be5ec52c3b | 97 | |
jah128 | 15:66be5ec52c3b | 98 | void Display::init_display_end(char mode){ |
jah128 | 0:d6269d17c8cf | 99 | clear_display(); |
jah128 | 8:6c92789d5f87 | 100 | if(mode == 0) { |
jah128 | 8:6c92789d5f87 | 101 | set_position(0,0); |
jah128 | 8:6c92789d5f87 | 102 | write_string(" YORK ROBOTICS"); |
jah128 | 8:6c92789d5f87 | 103 | set_position(1,0); |
jah128 | 8:6c92789d5f87 | 104 | write_string(" LABORATORY"); |
jah128 | 15:66be5ec52c3b | 105 | init_timeout.attach(this,&Display::post_init,0.25);} |
jah128 | 0:d6269d17c8cf | 106 | else { |
jah128 | 0:d6269d17c8cf | 107 | set_position(0,0); |
jah128 | 0:d6269d17c8cf | 108 | write_string("Hold button to"); |
jah128 | 0:d6269d17c8cf | 109 | set_position(1,0); |
jah128 | 0:d6269d17c8cf | 110 | write_string("launch demo code"); |
jah128 | 0:d6269d17c8cf | 111 | } |
jah128 | 0:d6269d17c8cf | 112 | } |
jah128 | 0:d6269d17c8cf | 113 | |
jah128 | 15:66be5ec52c3b | 114 | void Display::show_switch_state(char switch_state){ |
jah128 | 15:66be5ec52c3b | 115 | switch(switch_state){ |
jah128 | 15:66be5ec52c3b | 116 | /// Switch_state = 1 if up is pressed, 2 if down is pressed, 4 if left is pressed, 8 if right is pressed and 16 if the center button is pressed |
jah128 | 15:66be5ec52c3b | 117 | case 0: write_string("REL "); break; |
jah128 | 15:66be5ec52c3b | 118 | case 1: write_string("UP "); break; |
jah128 | 15:66be5ec52c3b | 119 | case 2: write_string("DOWN "); break; |
jah128 | 15:66be5ec52c3b | 120 | case 4: write_string("LEFT "); break; |
jah128 | 15:66be5ec52c3b | 121 | case 5: write_string("UP-L "); break; |
jah128 | 15:66be5ec52c3b | 122 | case 6: write_string("DN-L "); break; |
jah128 | 15:66be5ec52c3b | 123 | case 8: write_string("RIGHT "); break; |
jah128 | 15:66be5ec52c3b | 124 | case 9: write_string("UP-R "); break; |
jah128 | 15:66be5ec52c3b | 125 | case 10: write_string("DN-R "); break; |
jah128 | 15:66be5ec52c3b | 126 | case 16: write_string("PRESS"); break; |
jah128 | 15:66be5ec52c3b | 127 | case 17: write_string("UP *"); break; |
jah128 | 15:66be5ec52c3b | 128 | case 18: write_string("DOWN *"); break; |
jah128 | 15:66be5ec52c3b | 129 | case 20: write_string("LEFT *"); break; |
jah128 | 15:66be5ec52c3b | 130 | case 21: write_string("UP-L *"); break; |
jah128 | 15:66be5ec52c3b | 131 | case 22: write_string("DN-L *"); break; |
jah128 | 15:66be5ec52c3b | 132 | case 24: write_string("RIGHT*"); break; |
jah128 | 15:66be5ec52c3b | 133 | case 25: write_string("UP-R *"); break; |
jah128 | 15:66be5ec52c3b | 134 | case 26: write_string("DN-R *"); break; |
jah128 | 15:66be5ec52c3b | 135 | } |
jah128 | 15:66be5ec52c3b | 136 | } |
jah128 | 15:66be5ec52c3b | 137 | |
jah128 | 0:d6269d17c8cf | 138 | void Display::post_init(){ |
jah128 | 0:d6269d17c8cf | 139 | clear_display(); |
jah128 | 0:d6269d17c8cf | 140 | home(); |
jah128 | 0:d6269d17c8cf | 141 | write_string("PSI SWARM ROBOT"); |
jah128 | 0:d6269d17c8cf | 142 | set_position(1,0); |
jah128 | 0:d6269d17c8cf | 143 | char line [17]; |
jah128 | 0:d6269d17c8cf | 144 | sprintf(line,"VERSION %1.2f", SOFTWARE_VERSION_CODE ); |
jah128 | 0:d6269d17c8cf | 145 | set_position(1,0); |
jah128 | 0:d6269d17c8cf | 146 | write_string(line); |
jah128 | 15:66be5ec52c3b | 147 | init_timeout.attach(this,&Display::post_post_init,0.25); |
jah128 | 0:d6269d17c8cf | 148 | } |
jah128 | 0:d6269d17c8cf | 149 | |
jah128 | 0:d6269d17c8cf | 150 | void Display::post_post_init(){ |
jah128 | 0:d6269d17c8cf | 151 | clear_display(); |
jah128 | 0:d6269d17c8cf | 152 | home(); |
jah128 | 0:d6269d17c8cf | 153 | } |
jah128 | 0:d6269d17c8cf | 154 | |
jah128 | 0:d6269d17c8cf | 155 | void Display::write_string(char * message){ |
jah128 | 0:d6269d17c8cf | 156 | size_t length = strlen(message); |
jah128 | 0:d6269d17c8cf | 157 | if (length > 16) length = 16; |
jah128 | 0:d6269d17c8cf | 158 | char to_send [length+1]; |
jah128 | 0:d6269d17c8cf | 159 | to_send[0]=0x40; |
jah128 | 0:d6269d17c8cf | 160 | for(int i=0;i<length;i++){ |
jah128 | 0:d6269d17c8cf | 161 | to_send[i+1] = message[i]; |
jah128 | 0:d6269d17c8cf | 162 | } |
jah128 | 0:d6269d17c8cf | 163 | _i2c.write(LCD_ADDRESS,to_send,length+1); |
jah128 | 0:d6269d17c8cf | 164 | // Add to saved buffer |
jah128 | 0:d6269d17c8cf | 165 | int count = 0; |
jah128 | 0:d6269d17c8cf | 166 | for(int i=c_column;i<16;i++){ |
jah128 | 0:d6269d17c8cf | 167 | if(count < length){ |
jah128 | 0:d6269d17c8cf | 168 | if(c_row == 0) preserve_line_1[i] = message[count]; |
jah128 | 0:d6269d17c8cf | 169 | else preserve_line_2[i] = message[count]; |
jah128 | 0:d6269d17c8cf | 170 | } |
jah128 | 0:d6269d17c8cf | 171 | count++; |
jah128 | 0:d6269d17c8cf | 172 | } |
jah128 | 0:d6269d17c8cf | 173 | c_column+=length; |
jah128 | 0:d6269d17c8cf | 174 | if(c_column>15) c_column=15; |
jah128 | 0:d6269d17c8cf | 175 | } |
jah128 | 0:d6269d17c8cf | 176 | |
jah128 | 0:d6269d17c8cf | 177 | |
jah128 | 0:d6269d17c8cf | 178 | void Display::write_string(char * message, char length){ |
jah128 | 0:d6269d17c8cf | 179 | char to_send [length+1]; |
jah128 | 0:d6269d17c8cf | 180 | to_send[0]=0x40; |
jah128 | 0:d6269d17c8cf | 181 | for(int i=0;i<length;i++){ |
jah128 | 0:d6269d17c8cf | 182 | to_send[i+1] = message[i]; |
jah128 | 0:d6269d17c8cf | 183 | } |
jah128 | 0:d6269d17c8cf | 184 | _i2c.write(LCD_ADDRESS,to_send,length+1); |
jah128 | 0:d6269d17c8cf | 185 | // Add to saved buffer |
jah128 | 0:d6269d17c8cf | 186 | int count = 0; |
jah128 | 0:d6269d17c8cf | 187 | for(int i=c_column;i<16;i++){ |
jah128 | 0:d6269d17c8cf | 188 | if(count < length){ |
jah128 | 0:d6269d17c8cf | 189 | if(c_row == 0) preserve_line_1[i] = message[count]; |
jah128 | 0:d6269d17c8cf | 190 | else preserve_line_2[i] = message[count]; |
jah128 | 0:d6269d17c8cf | 191 | } |
jah128 | 0:d6269d17c8cf | 192 | count++; |
jah128 | 0:d6269d17c8cf | 193 | } |
jah128 | 0:d6269d17c8cf | 194 | c_column+=length; |
jah128 | 0:d6269d17c8cf | 195 | if(c_column>15) c_column=15; |
jah128 | 0:d6269d17c8cf | 196 | } |
jah128 | 0:d6269d17c8cf | 197 | |
jah128 | 0:d6269d17c8cf | 198 | void Display::set_position(char row, char column){ |
jah128 | 0:d6269d17c8cf | 199 | if(row < 2 && column < 16){ |
jah128 | 0:d6269d17c8cf | 200 | char pos = 128 +((row * 64)+column); |
jah128 | 0:d6269d17c8cf | 201 | i2c_message(pos); |
jah128 | 0:d6269d17c8cf | 202 | c_row= row; |
jah128 | 0:d6269d17c8cf | 203 | c_column = column; |
jah128 | 0:d6269d17c8cf | 204 | } |
jah128 | 0:d6269d17c8cf | 205 | } |
jah128 | 0:d6269d17c8cf | 206 | |
jah128 | 0:d6269d17c8cf | 207 | void Display::set_cursor(char enable){ |
jah128 | 0:d6269d17c8cf | 208 | cursor_on=enable; |
jah128 | 0:d6269d17c8cf | 209 | _set_display(); |
jah128 | 0:d6269d17c8cf | 210 | } |
jah128 | 0:d6269d17c8cf | 211 | |
jah128 | 0:d6269d17c8cf | 212 | void Display::set_blink(char enable){ |
jah128 | 0:d6269d17c8cf | 213 | blink_on=enable; |
jah128 | 0:d6269d17c8cf | 214 | _set_display(); |
jah128 | 0:d6269d17c8cf | 215 | } |
jah128 | 0:d6269d17c8cf | 216 | |
jah128 | 0:d6269d17c8cf | 217 | void Display::set_display(char enable){ |
jah128 | 0:d6269d17c8cf | 218 | display_on=enable; |
jah128 | 0:d6269d17c8cf | 219 | _set_display(); |
jah128 | 0:d6269d17c8cf | 220 | } |
jah128 | 0:d6269d17c8cf | 221 | |
jah128 | 0:d6269d17c8cf | 222 | void Display::set_backlight_brightness(float brightness){ |
jah128 | 0:d6269d17c8cf | 223 | if(brightness > 1) brightness = 0; |
jah128 | 0:d6269d17c8cf | 224 | if(brightness < 0) brightness = 0; |
jah128 | 0:d6269d17c8cf | 225 | backlight_brightness = brightness; |
jah128 | 0:d6269d17c8cf | 226 | if(backlight_brightness == 1) { |
jah128 | 0:d6269d17c8cf | 227 | backlight_timeout.detach(); |
jah128 | 0:d6269d17c8cf | 228 | _backlight = 1; |
jah128 | 0:d6269d17c8cf | 229 | }else{ |
jah128 | 0:d6269d17c8cf | 230 | if(backlight_brightness == 0){ |
jah128 | 0:d6269d17c8cf | 231 | backlight_timeout.detach(); |
jah128 | 0:d6269d17c8cf | 232 | _backlight = 0; |
jah128 | 0:d6269d17c8cf | 233 | } else { |
jah128 | 0:d6269d17c8cf | 234 | backlight_on_time = (int) (10000.0f * backlight_brightness); |
jah128 | 0:d6269d17c8cf | 235 | backlight_off_time = 10000 - backlight_on_time; |
jah128 | 0:d6269d17c8cf | 236 | backlight_step = 0; |
jah128 | 0:d6269d17c8cf | 237 | _backlight = 0; |
jah128 | 0:d6269d17c8cf | 238 | backlight_timeout.attach_us(this,&Display::IF_backlight_toggle,backlight_off_time); |
jah128 | 0:d6269d17c8cf | 239 | } |
jah128 | 0:d6269d17c8cf | 240 | } |
jah128 | 0:d6269d17c8cf | 241 | } |
jah128 | 0:d6269d17c8cf | 242 | |
jah128 | 0:d6269d17c8cf | 243 | void Display::IF_backlight_toggle(){ |
jah128 | 0:d6269d17c8cf | 244 | if(backlight_step == 0){ |
jah128 | 0:d6269d17c8cf | 245 | _backlight = 1; |
jah128 | 0:d6269d17c8cf | 246 | backlight_step = 1; |
jah128 | 0:d6269d17c8cf | 247 | backlight_timeout.attach_us(this,&Display::IF_backlight_toggle,backlight_on_time); |
jah128 | 0:d6269d17c8cf | 248 | } else { |
jah128 | 0:d6269d17c8cf | 249 | _backlight = 0; |
jah128 | 0:d6269d17c8cf | 250 | backlight_step = 0; |
jah128 | 0:d6269d17c8cf | 251 | backlight_timeout.attach_us(this,&Display::IF_backlight_toggle,backlight_off_time); |
jah128 | 0:d6269d17c8cf | 252 | } |
jah128 | 0:d6269d17c8cf | 253 | } |
jah128 | 0:d6269d17c8cf | 254 | void Display::clear_display(){ |
jah128 | 0:d6269d17c8cf | 255 | for(int i=0;i<16;i++){ |
jah128 | 0:d6269d17c8cf | 256 | preserve_line_1[i] = 0x20; |
jah128 | 0:d6269d17c8cf | 257 | preserve_line_2[i] = 0x20; |
jah128 | 0:d6269d17c8cf | 258 | } |
jah128 | 0:d6269d17c8cf | 259 | i2c_message(0x01); |
jah128 | 0:d6269d17c8cf | 260 | } |
jah128 | 0:d6269d17c8cf | 261 | |
jah128 | 0:d6269d17c8cf | 262 | void Display::home(){ |
jah128 | 0:d6269d17c8cf | 263 | c_row = 0; |
jah128 | 0:d6269d17c8cf | 264 | c_column = 0; |
jah128 | 0:d6269d17c8cf | 265 | i2c_message(0x02); |
jah128 | 0:d6269d17c8cf | 266 | } |
jah128 | 0:d6269d17c8cf | 267 | |
jah128 | 0:d6269d17c8cf | 268 | void Display::debug_page(char * message, char length){ |
jah128 | 0:d6269d17c8cf | 269 | p_row=c_row; |
jah128 | 0:d6269d17c8cf | 270 | p_column=c_column; |
jah128 | 0:d6269d17c8cf | 271 | i2c_message(0x01); |
jah128 | 0:d6269d17c8cf | 272 | home(); |
jah128 | 0:d6269d17c8cf | 273 | char multipage_mode = 0; |
jah128 | 0:d6269d17c8cf | 274 | char line_1[18]; |
jah128 | 0:d6269d17c8cf | 275 | char line_2[18]; |
jah128 | 0:d6269d17c8cf | 276 | line_1[0]=0x40; |
jah128 | 0:d6269d17c8cf | 277 | line_2[0]=0x40; |
jah128 | 0:d6269d17c8cf | 278 | if(length > 16){ |
jah128 | 0:d6269d17c8cf | 279 | strncpy(line_1+1, message, 16); |
jah128 | 0:d6269d17c8cf | 280 | char f_length = length - 16; |
jah128 | 0:d6269d17c8cf | 281 | if(f_length > 16) { |
jah128 | 0:d6269d17c8cf | 282 | f_length = 16; |
jah128 | 0:d6269d17c8cf | 283 | multipage_mode = 1; |
jah128 | 0:d6269d17c8cf | 284 | } |
jah128 | 0:d6269d17c8cf | 285 | strncpy(line_2+1, message+16, f_length); |
jah128 | 0:d6269d17c8cf | 286 | line_1[17]=0; |
jah128 | 0:d6269d17c8cf | 287 | line_2[f_length+1]=0; |
jah128 | 0:d6269d17c8cf | 288 | _i2c.write(LCD_ADDRESS,line_1,17); |
jah128 | 0:d6269d17c8cf | 289 | set_position(1,0); |
jah128 | 0:d6269d17c8cf | 290 | _i2c.write(LCD_ADDRESS,line_2,f_length+1); |
jah128 | 0:d6269d17c8cf | 291 | } else { |
jah128 | 0:d6269d17c8cf | 292 | strncpy(line_1+1, message, length); |
jah128 | 0:d6269d17c8cf | 293 | _i2c.write(LCD_ADDRESS,line_1,length+1); |
jah128 | 0:d6269d17c8cf | 294 | } |
jah128 | 0:d6269d17c8cf | 295 | if(multipage_mode == 1){ |
jah128 | 0:d6269d17c8cf | 296 | strncpy(multipage, message + 32, length - 32); |
jah128 | 0:d6269d17c8cf | 297 | multipage_length = length - 32; |
jah128 | 0:d6269d17c8cf | 298 | debug_timeout.attach(this,&Display::IF_debug_multipage,PAGE_TIME); |
jah128 | 0:d6269d17c8cf | 299 | } else debug_timeout.attach(this,&Display::IF_restore_page,CLEAR_TIME); |
jah128 | 0:d6269d17c8cf | 300 | } |
jah128 | 0:d6269d17c8cf | 301 | |
jah128 | 0:d6269d17c8cf | 302 | void Display::IF_restore_page(){ |
jah128 | 0:d6269d17c8cf | 303 | i2c_message(0x01); |
jah128 | 0:d6269d17c8cf | 304 | home(); |
jah128 | 0:d6269d17c8cf | 305 | char line_1[17]; |
jah128 | 0:d6269d17c8cf | 306 | char line_2[17]; |
jah128 | 0:d6269d17c8cf | 307 | line_1[0]=0x40; |
jah128 | 0:d6269d17c8cf | 308 | line_2[0]=0x40; |
jah128 | 0:d6269d17c8cf | 309 | strncpy(line_1+1, preserve_line_1, 16); |
jah128 | 0:d6269d17c8cf | 310 | strncpy(line_2+1, preserve_line_2, 16); |
jah128 | 0:d6269d17c8cf | 311 | _i2c.write(LCD_ADDRESS,line_1,17); |
jah128 | 0:d6269d17c8cf | 312 | set_position(1,0); |
jah128 | 0:d6269d17c8cf | 313 | _i2c.write(LCD_ADDRESS,line_2,17); |
jah128 | 0:d6269d17c8cf | 314 | set_position(p_row,p_column); |
jah128 | 0:d6269d17c8cf | 315 | } |
jah128 | 0:d6269d17c8cf | 316 | |
jah128 | 0:d6269d17c8cf | 317 | void Display::IF_debug_multipage(){ |
jah128 | 0:d6269d17c8cf | 318 | i2c_message(0x01); |
jah128 | 0:d6269d17c8cf | 319 | home(); |
jah128 | 0:d6269d17c8cf | 320 | char multipage_mode = 0; |
jah128 | 0:d6269d17c8cf | 321 | char line_1[18]; |
jah128 | 0:d6269d17c8cf | 322 | char line_2[18]; |
jah128 | 0:d6269d17c8cf | 323 | line_1[0]=0x40; |
jah128 | 0:d6269d17c8cf | 324 | line_2[0]=0x40; |
jah128 | 0:d6269d17c8cf | 325 | if(multipage_length > 16){ |
jah128 | 0:d6269d17c8cf | 326 | strncpy(line_1+1, multipage, 16); |
jah128 | 0:d6269d17c8cf | 327 | char f_length = multipage_length - 16; |
jah128 | 0:d6269d17c8cf | 328 | if(f_length > 16) { |
jah128 | 0:d6269d17c8cf | 329 | f_length = 16; |
jah128 | 0:d6269d17c8cf | 330 | multipage_mode = 1; |
jah128 | 0:d6269d17c8cf | 331 | } |
jah128 | 0:d6269d17c8cf | 332 | strncpy(line_2+1, multipage+16, f_length); |
jah128 | 0:d6269d17c8cf | 333 | line_1[17]=0; |
jah128 | 0:d6269d17c8cf | 334 | line_2[f_length+1]=0; |
jah128 | 0:d6269d17c8cf | 335 | _i2c.write(LCD_ADDRESS,line_1,17); |
jah128 | 0:d6269d17c8cf | 336 | set_position(1,0); |
jah128 | 0:d6269d17c8cf | 337 | _i2c.write(LCD_ADDRESS,line_2,f_length+1); |
jah128 | 0:d6269d17c8cf | 338 | } else { |
jah128 | 0:d6269d17c8cf | 339 | strncpy(line_1+1, multipage, multipage_length); |
jah128 | 0:d6269d17c8cf | 340 | _i2c.write(LCD_ADDRESS,line_1,multipage_length+1); |
jah128 | 0:d6269d17c8cf | 341 | } |
jah128 | 0:d6269d17c8cf | 342 | if(multipage_mode == 1){ |
jah128 | 0:d6269d17c8cf | 343 | char temp[200]; |
jah128 | 0:d6269d17c8cf | 344 | strncpy(temp, multipage + 32, multipage_length - 32); |
jah128 | 0:d6269d17c8cf | 345 | multipage_length -= 32; |
jah128 | 0:d6269d17c8cf | 346 | strncpy(multipage, temp, multipage_length); |
jah128 | 0:d6269d17c8cf | 347 | debug_timeout.attach(this,&Display::IF_debug_multipage,PAGE_TIME); |
jah128 | 0:d6269d17c8cf | 348 | }else debug_timeout.attach(this,&Display::IF_restore_page,CLEAR_TIME); |
jah128 | 0:d6269d17c8cf | 349 | } |
jah128 | 0:d6269d17c8cf | 350 | |
jah128 | 0:d6269d17c8cf | 351 | void Display::_set_display(){ |
jah128 | 0:d6269d17c8cf | 352 | char mode = 8; |
jah128 | 0:d6269d17c8cf | 353 | if(display_on>0) mode += 4; |
jah128 | 0:d6269d17c8cf | 354 | if(cursor_on>0) mode += 2; |
jah128 | 0:d6269d17c8cf | 355 | if(blink_on>0) mode ++; |
jah128 | 0:d6269d17c8cf | 356 | i2c_message(mode); |
jah128 | 0:d6269d17c8cf | 357 | } |
jah128 | 0:d6269d17c8cf | 358 | |
jah128 | 0:d6269d17c8cf | 359 | |
jah128 | 0:d6269d17c8cf | 360 | int Display::_putc (int c) { |
jah128 | 0:d6269d17c8cf | 361 | putc(c); |
jah128 | 0:d6269d17c8cf | 362 | return(c); |
jah128 | 0:d6269d17c8cf | 363 | } |
jah128 | 0:d6269d17c8cf | 364 | |
jah128 | 0:d6269d17c8cf | 365 | int Display::_getc (void) { |
jah128 | 0:d6269d17c8cf | 366 | char r = 0; |
jah128 | 0:d6269d17c8cf | 367 | return(r); |
jah128 | 0:d6269d17c8cf | 368 | } |