Working Menu with selectable fields yet to add comparison with healthy temperature ranges
Dependencies: TMP102_02
N5110.h
00001 #ifndef N5110_H 00002 #define N5110_H 00003 00004 #include "mbed.h" 00005 00006 // number of pixels on display 00007 #define WIDTH 84 00008 #define HEIGHT 48 00009 #define BANKS 6 00010 00011 /// Fill types for 2D shapes 00012 enum FillType { 00013 FILL_TRANSPARENT, ///< Transparent with outline 00014 FILL_BLACK, ///< Filled black 00015 FILL_WHITE, ///< Filled white (no outline) 00016 }; 00017 00018 00019 class N5110 00020 { 00021 private: 00022 // objects 00023 SPI *_spi; 00024 PwmOut *_led; 00025 DigitalOut *_pwr; 00026 DigitalOut *_sce; 00027 DigitalOut *_rst; 00028 DigitalOut *_dc; 00029 00030 // variables 00031 unsigned char buffer[84][6]; // screen buffer - the 6 is for the banks - each one is 8 bits; 00032 00033 public: 00034 /** Create a N5110 object connected to the specified pins 00035 * 00036 * @param pwr Pin connected to Vcc on the LCD display (pin 1) 00037 * @param sce Pin connected to chip enable (pin 3) 00038 * @param rst Pin connected to reset (pin 4) 00039 * @param dc Pin connected to data/command select (pin 5) 00040 * @param mosi Pin connected to data input (MOSI) (pin 6) 00041 * @param sclk Pin connected to serial clock (SCLK) (pin 7) 00042 * @param led Pin connected to LED backlight (must be PWM) (pin 8) 00043 * 00044 */ 00045 N5110(PinName const pwrPin, 00046 PinName const scePin, 00047 PinName const rstPin, 00048 PinName const dcPin, 00049 PinName const mosiPin, 00050 PinName const sclkPin, 00051 PinName const ledPin); 00052 00053 /** Create a N5110 object connected to the specified pins (Vcc to +3V3) 00054 * 00055 * @param sce Pin connected to chip enable (pin 3) 00056 * @param rst Pin connected to reset (pin 4) 00057 * @param dc Pin connected to data/command select (pin 5) 00058 * @param mosi Pin connected to data input (MOSI) (pin 6) 00059 * @param sclk Pin connected to serial clock (SCLK) (pin 7) 00060 * @param led Pin connected to LED backlight (must be PWM) (pin 8) 00061 * 00062 */ 00063 N5110(PinName const scePin, 00064 PinName const rstPin, 00065 PinName const dcPin, 00066 PinName const mosiPin, 00067 PinName const sclkPin, 00068 PinName const ledPin); 00069 00070 /** 00071 * Free allocated memory when object goes out of scope 00072 */ 00073 ~N5110(); 00074 00075 /** Initialise display 00076 * 00077 * Powers up the display and turns on backlight (50% brightness default). 00078 * Sets the display up in horizontal addressing mode and with normal video mode. 00079 */ 00080 void init(); 00081 00082 /** Turn off 00083 * 00084 * Powers down the display and turns of the backlight. 00085 * Needs to be reinitialised before being re-used. 00086 */ 00087 void turnOff(); 00088 00089 /** Clear 00090 * 00091 * Clears the screen buffer. 00092 */ 00093 void clear(); 00094 00095 /** Set screen constrast 00096 * @param constrast - float in range 0.0 to 1.0 (0.40 to 0.60 is usually a good value) 00097 */ 00098 void setContrast(float contrast); 00099 00100 /** Turn on normal video mode (default) 00101 * Black on white 00102 */ 00103 void normalMode(); 00104 00105 /** Turn on inverse video mode (default) 00106 * White on black 00107 */ 00108 void inverseMode(); 00109 00110 /** Set Brightness 00111 * 00112 * Sets brightness of LED backlight. 00113 * @param brightness - float in range 0.0 to 1.0 00114 */ 00115 void setBrightness(float const brightness); 00116 00117 /** Print String 00118 * 00119 * Prints a string of characters to the screen buffer. String is cut-off after the 83rd pixel. 00120 * @param x - the column number (0 to 83) 00121 * @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row 00122 */ 00123 void printString(char const *str, 00124 unsigned int const x, 00125 unsigned int const y); 00126 00127 /** Print Character 00128 * 00129 * Sends a character to the screen buffer. Printed at the specified location. Character is cut-off after the 83rd pixel. 00130 * @param c - the character to print. Can print ASCII as so printChar('C'). 00131 * @param x - the column number (0 to 83) 00132 * @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row 00133 */ 00134 void printChar(char const c, 00135 unsigned int const x, 00136 unsigned int const y); 00137 00138 /** 00139 * @brief Set a Pixel 00140 * 00141 * @param x The x co-ordinate of the pixel (0 to 83) 00142 * @param y The y co-ordinate of the pixel (0 to 47) 00143 * @param state The state of the pixel [true=black (default), false=white] 00144 * 00145 * @details This function sets the state of a pixel in the screen buffer. 00146 * The third parameter can be omitted, 00147 */ 00148 void setPixel(unsigned int const x, 00149 unsigned int const y, 00150 bool const state = true); 00151 00152 /** 00153 * @brief Clear a Pixel 00154 * 00155 * @param x - the x co-ordinate of the pixel (0 to 83) 00156 * @param y - the y co-ordinate of the pixel (0 to 47) 00157 * 00158 * @details This function clears pixel in the screen buffer 00159 * 00160 * @deprecated Use setPixel(x, y, false) instead 00161 */ 00162 void clearPixel(unsigned int const x, 00163 unsigned int const y) 00164 __attribute__((deprecated("Use setPixel(x,y,false) instead"))); 00165 00166 /** Get a Pixel 00167 * 00168 * This function gets the status of a pixel in the screen buffer. 00169 * @param x - the x co-ordinate of the pixel (0 to 83) 00170 * @param y - the y co-ordinate of the pixel (0 to 47) 00171 * @returns 00172 * 0 - pixel is clear 00173 * 1 - pixel is set 00174 */ 00175 int getPixel(unsigned int const x, 00176 unsigned int const y) const; 00177 00178 /** Refresh display 00179 * 00180 * This functions sends the screen buffer to the display. 00181 */ 00182 void refresh(); 00183 00184 /** Randomise buffer 00185 * 00186 * This function fills the buffer with random data. Can be used to test the display. 00187 * A call to refresh() must be made to update the display to reflect the change in pixels. 00188 * The seed is not set and so the generated pattern will probably be the same each time. 00189 * TODO: Randomise the seed - maybe using the noise on the AnalogIn pins. 00190 */ 00191 void randomiseBuffer(); 00192 00193 /** Plot Array 00194 * 00195 * This function plots a one-dimensional array in the buffer. 00196 * @param array[] - y values of the plot. Values should be normalised in the range 0.0 to 1.0. First 84 plotted. 00197 */ 00198 void plotArray(float const array[]); 00199 00200 /** Draw Circle 00201 * 00202 * This function draws a circle at the specified origin with specified radius in the screen buffer 00203 * Uses the midpoint circle algorithm. 00204 * @see http://en.wikipedia.org/wiki/Midpoint_circle_algorithm 00205 * @param x0 - x-coordinate of centre 00206 * @param y0 - y-coordinate of centre 00207 * @param radius - radius of circle in pixels 00208 * @param fill - fill-type for the shape 00209 */ 00210 void drawCircle(unsigned int const x0, 00211 unsigned int const y0, 00212 unsigned int const radius, 00213 FillType const fill); 00214 00215 /** Draw Line 00216 * 00217 * This function draws a line between the specified points using linear interpolation. 00218 * @param x0 - x-coordinate of first point 00219 * @param y0 - y-coordinate of first point 00220 * @param x1 - x-coordinate of last point 00221 * @param y1 - y-coordinate of last point 00222 * @param type - 0 white,1 black,2 dotted 00223 */ 00224 void drawLine(unsigned int const x0, 00225 unsigned int const y0, 00226 unsigned int const x1, 00227 unsigned int const y1, 00228 unsigned int const type); 00229 00230 /** Draw Rectangle 00231 * 00232 * This function draws a rectangle. 00233 * @param x0 - x-coordinate of origin (top-left) 00234 * @param y0 - y-coordinate of origin (top-left) 00235 * @param width - width of rectangle 00236 * @param height - height of rectangle 00237 * @param fill - fill-type for the shape 00238 */ 00239 void drawRect(unsigned int const x0, 00240 unsigned int const y0, 00241 unsigned int const width, 00242 unsigned int const height, 00243 FillType const fill); 00244 00245 /** Draw Sprite 00246 * 00247 * This function draws a sprite as defined in a 2D array 00248 * @param x0 - x-coordinate of origin (top-left) 00249 * @param y0 - y-coordinate of origin (top-left) 00250 * @param nrows - number of rows in sprite 00251 * @param ncols - number of columns in sprite 00252 * @param sprite - 2D array representing the sprite 00253 */ 00254 void drawSprite(int x0, 00255 int y0, 00256 int nrows, 00257 int ncols, 00258 int *sprite); 00259 00260 00261 private: 00262 // methods 00263 void setXYAddress(unsigned int const x, 00264 unsigned int const y); 00265 void initSPI(); 00266 void turnOn(); 00267 void reset(); 00268 void clearRAM(); 00269 void sendCommand(unsigned char command); 00270 void sendData(unsigned char data); 00271 void setTempCoefficient(char tc); // 0 to 3 00272 void setBias(char bias); // 0 to 7 00273 }; 00274 00275 const unsigned char font5x7[480] = { 00276 0x00, 0x00, 0x00, 0x00, 0x00,// (space) 00277 0x00, 0x00, 0x5F, 0x00, 0x00,// ! 00278 0x00, 0x07, 0x00, 0x07, 0x00,// " 00279 0x14, 0x7F, 0x14, 0x7F, 0x14,// # 00280 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $ 00281 0x23, 0x13, 0x08, 0x64, 0x62,// % 00282 0x36, 0x49, 0x55, 0x22, 0x50,// & 00283 0x00, 0x05, 0x03, 0x00, 0x00,// ' 00284 0x00, 0x1C, 0x22, 0x41, 0x00,// ( 00285 0x00, 0x41, 0x22, 0x1C, 0x00,// ) 00286 0x08, 0x2A, 0x1C, 0x2A, 0x08,// * 00287 0x08, 0x08, 0x3E, 0x08, 0x08,// + 00288 0x00, 0x50, 0x30, 0x00, 0x00,// , 00289 0x08, 0x08, 0x08, 0x08, 0x08,// - 00290 0x00, 0x60, 0x60, 0x00, 0x00,// . 00291 0x20, 0x10, 0x08, 0x04, 0x02,// / 00292 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 00293 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 00294 0x42, 0x61, 0x51, 0x49, 0x46,// 2 00295 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 00296 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 00297 0x27, 0x45, 0x45, 0x45, 0x39,// 5 00298 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 00299 0x01, 0x71, 0x09, 0x05, 0x03,// 7 00300 0x36, 0x49, 0x49, 0x49, 0x36,// 8 00301 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 00302 0x00, 0x36, 0x36, 0x00, 0x00,// : 00303 0x00, 0x56, 0x36, 0x00, 0x00,// ; 00304 0x00, 0x08, 0x14, 0x22, 0x41,// < 00305 0x14, 0x14, 0x14, 0x14, 0x14,// = 00306 0x41, 0x22, 0x14, 0x08, 0x00,// > 00307 0x02, 0x01, 0x51, 0x09, 0x06,// ? 00308 0x32, 0x49, 0x79, 0x41, 0x3E,// @ 00309 0x7E, 0x11, 0x11, 0x11, 0x7E,// A 00310 0x7F, 0x49, 0x49, 0x49, 0x36,// B 00311 0x3E, 0x41, 0x41, 0x41, 0x22,// C 00312 0x7F, 0x41, 0x41, 0x22, 0x1C,// D 00313 0x7F, 0x49, 0x49, 0x49, 0x41,// E 00314 0x7F, 0x09, 0x09, 0x01, 0x01,// F 00315 0x3E, 0x41, 0x41, 0x51, 0x32,// G 00316 0x7F, 0x08, 0x08, 0x08, 0x7F,// H 00317 0x00, 0x41, 0x7F, 0x41, 0x00,// I 00318 0x20, 0x40, 0x41, 0x3F, 0x01,// J 00319 0x7F, 0x08, 0x14, 0x22, 0x41,// K 00320 0x7F, 0x40, 0x40, 0x40, 0x40,// L 00321 0x7F, 0x02, 0x04, 0x02, 0x7F,// M 00322 0x7F, 0x04, 0x08, 0x10, 0x7F,// N 00323 0x3E, 0x41, 0x41, 0x41, 0x3E,// O 00324 0x7F, 0x09, 0x09, 0x09, 0x06,// P 00325 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q 00326 0x7F, 0x09, 0x19, 0x29, 0x46,// R 00327 0x46, 0x49, 0x49, 0x49, 0x31,// S 00328 0x01, 0x01, 0x7F, 0x01, 0x01,// T 00329 0x3F, 0x40, 0x40, 0x40, 0x3F,// U 00330 0x1F, 0x20, 0x40, 0x20, 0x1F,// V 00331 0x7F, 0x20, 0x18, 0x20, 0x7F,// W 00332 0x63, 0x14, 0x08, 0x14, 0x63,// X 00333 0x03, 0x04, 0x78, 0x04, 0x03,// Y 00334 0x61, 0x51, 0x49, 0x45, 0x43,// Z 00335 0x00, 0x00, 0x7F, 0x41, 0x41,// [ 00336 0x02, 0x04, 0x08, 0x10, 0x20,// "\" 00337 0x41, 0x41, 0x7F, 0x00, 0x00,// ] 00338 0x04, 0x02, 0x01, 0x02, 0x04,// ^ 00339 0x40, 0x40, 0x40, 0x40, 0x40,// _ 00340 0x00, 0x01, 0x02, 0x04, 0x00,// ` 00341 0x20, 0x54, 0x54, 0x54, 0x78,// a 00342 0x7F, 0x48, 0x44, 0x44, 0x38,// b 00343 0x38, 0x44, 0x44, 0x44, 0x20,// c 00344 0x38, 0x44, 0x44, 0x48, 0x7F,// d 00345 0x38, 0x54, 0x54, 0x54, 0x18,// e 00346 0x08, 0x7E, 0x09, 0x01, 0x02,// f 00347 0x08, 0x14, 0x54, 0x54, 0x3C,// g 00348 0x7F, 0x08, 0x04, 0x04, 0x78,// h 00349 0x00, 0x44, 0x7D, 0x40, 0x00,// i 00350 0x20, 0x40, 0x44, 0x3D, 0x00,// j 00351 0x00, 0x7F, 0x10, 0x28, 0x44,// k 00352 0x00, 0x41, 0x7F, 0x40, 0x00,// l 00353 0x7C, 0x04, 0x18, 0x04, 0x78,// m 00354 0x7C, 0x08, 0x04, 0x04, 0x78,// n 00355 0x38, 0x44, 0x44, 0x44, 0x38,// o 00356 0x7C, 0x14, 0x14, 0x14, 0x08,// p 00357 0x08, 0x14, 0x14, 0x18, 0x7C,// q 00358 0x7C, 0x08, 0x04, 0x04, 0x08,// r 00359 0x48, 0x54, 0x54, 0x54, 0x20,// s 00360 0x04, 0x3F, 0x44, 0x40, 0x20,// t 00361 0x3C, 0x40, 0x40, 0x20, 0x7C,// u 00362 0x1C, 0x20, 0x40, 0x20, 0x1C,// v 00363 0x3C, 0x40, 0x30, 0x40, 0x3C,// w 00364 0x44, 0x28, 0x10, 0x28, 0x44,// x 00365 0x0C, 0x50, 0x50, 0x50, 0x3C,// y 00366 0x44, 0x64, 0x54, 0x4C, 0x44,// z 00367 0x00, 0x08, 0x36, 0x41, 0x00,// { 00368 0x00, 0x00, 0x7F, 0x00, 0x00,// | 00369 0x00, 0x41, 0x36, 0x08, 0x00,// } 00370 0x08, 0x08, 0x2A, 0x1C, 0x08,// -> 00371 0x08, 0x1C, 0x2A, 0x08, 0x08 // <- 00372 }; 00373 00374 #endif
Generated on Thu Jul 28 2022 13:50:11 by
1.7.2