Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LcdWindow by
window.h@3:e5d5e2fe4bf6, 2010-11-28 (annotated)
- Committer:
- hlipka
- Date:
- Sun Nov 28 22:09:54 2010 +0000
- Revision:
- 3:e5d5e2fe4bf6
- Parent:
- 2:5ac5bab7daaf
Made LCD driver thread safe (to allow usage from timers)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| hlipka | 0:ae5037e3d6e0 | 1 | /* |
| hlipka | 0:ae5037e3d6e0 | 2 | * mbed LCDWindow library |
| hlipka | 0:ae5037e3d6e0 | 3 | * Copyright (c) 2010 Hendrik Lipka |
| hlipka | 2:5ac5bab7daaf | 4 | * |
| hlipka | 0:ae5037e3d6e0 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| hlipka | 0:ae5037e3d6e0 | 6 | * of this software and associated documentation files (the "Software"), to deal |
| hlipka | 0:ae5037e3d6e0 | 7 | * in the Software without restriction, including without limitation the rights |
| hlipka | 0:ae5037e3d6e0 | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| hlipka | 0:ae5037e3d6e0 | 9 | * copies of the Software, and to permit persons to whom the Software is |
| hlipka | 0:ae5037e3d6e0 | 10 | * furnished to do so, subject to the following conditions: |
| hlipka | 2:5ac5bab7daaf | 11 | * |
| hlipka | 0:ae5037e3d6e0 | 12 | * The above copyright notice and this permission notice shall be included in |
| hlipka | 0:ae5037e3d6e0 | 13 | * all copies or substantial portions of the Software. |
| hlipka | 2:5ac5bab7daaf | 14 | * |
| hlipka | 0:ae5037e3d6e0 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| hlipka | 0:ae5037e3d6e0 | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| hlipka | 0:ae5037e3d6e0 | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| hlipka | 0:ae5037e3d6e0 | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| hlipka | 0:ae5037e3d6e0 | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| hlipka | 0:ae5037e3d6e0 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| hlipka | 0:ae5037e3d6e0 | 21 | * THE SOFTWARE. |
| hlipka | 0:ae5037e3d6e0 | 22 | */ |
| hlipka | 0:ae5037e3d6e0 | 23 | |
| hlipka | 0:ae5037e3d6e0 | 24 | #ifndef WINDOW_H_ |
| hlipka | 0:ae5037e3d6e0 | 25 | #define WINDOW_H_ |
| hlipka | 0:ae5037e3d6e0 | 26 | |
| hlipka | 2:5ac5bab7daaf | 27 | #include "Stream.h" |
| hlipka | 3:e5d5e2fe4bf6 | 28 | #include "semaphore.h" |
| hlipka | 2:5ac5bab7daaf | 29 | |
| hlipka | 2:5ac5bab7daaf | 30 | using namespace mbed; |
| hlipka | 2:5ac5bab7daaf | 31 | |
| hlipka | 0:ae5037e3d6e0 | 32 | /** |
| hlipka | 0:ae5037e3d6e0 | 33 | * the base window class, which proves the interface for all common methods. |
| hlipka | 0:ae5037e3d6e0 | 34 | */ |
| hlipka | 2:5ac5bab7daaf | 35 | class Window : public Stream { |
| hlipka | 2:5ac5bab7daaf | 36 | public: |
| hlipka | 2:5ac5bab7daaf | 37 | /** |
| hlipka | 2:5ac5bab7daaf | 38 | * write text into the window, at the given position. |
| hlipka | 2:5ac5bab7daaf | 39 | * this doesn't change the internal cursor position |
| hlipka | 2:5ac5bab7daaf | 40 | * Implementations should check for the length of the text and shorten it accordingly. |
| hlipka | 2:5ac5bab7daaf | 41 | * @params columns the column where to write |
| hlipka | 2:5ac5bab7daaf | 42 | * @params row the line where to write |
| hlipka | 2:5ac5bab7daaf | 43 | * @params text the text to write |
| hlipka | 2:5ac5bab7daaf | 44 | */ |
| hlipka | 2:5ac5bab7daaf | 45 | virtual void writeText(const unsigned int column, const unsigned int row, const char text[])=0; |
| hlipka | 2:5ac5bab7daaf | 46 | /** |
| hlipka | 2:5ac5bab7daaf | 47 | * @param returns the height of the window |
| hlipka | 2:5ac5bab7daaf | 48 | */ |
| hlipka | 2:5ac5bab7daaf | 49 | virtual int getRows()=0; |
| hlipka | 2:5ac5bab7daaf | 50 | /** |
| hlipka | 2:5ac5bab7daaf | 51 | * @param returns the width of the window |
| hlipka | 2:5ac5bab7daaf | 52 | */ |
| hlipka | 2:5ac5bab7daaf | 53 | virtual int getColumns()=0; |
| hlipka | 2:5ac5bab7daaf | 54 | /** |
| hlipka | 2:5ac5bab7daaf | 55 | * clears the window |
| hlipka | 2:5ac5bab7daaf | 56 | */ |
| hlipka | 2:5ac5bab7daaf | 57 | virtual void clear()=0; |
| hlipka | 2:5ac5bab7daaf | 58 | |
| hlipka | 3:e5d5e2fe4bf6 | 59 | /** |
| hlipka | 2:5ac5bab7daaf | 60 | * set (internal) cursor to a screen column and row |
| hlipka | 2:5ac5bab7daaf | 61 | * |
| hlipka | 2:5ac5bab7daaf | 62 | * @param column The horizontal position from the left, indexed from 0 |
| hlipka | 2:5ac5bab7daaf | 63 | * @param row The vertical position from the top, indexed from 0 |
| hlipka | 2:5ac5bab7daaf | 64 | */ |
| hlipka | 2:5ac5bab7daaf | 65 | virtual void locate(int column, int row); |
| hlipka | 2:5ac5bab7daaf | 66 | |
| hlipka | 2:5ac5bab7daaf | 67 | /** |
| hlipka | 2:5ac5bab7daaf | 68 | * writes a character to the specified position |
| hlipka | 2:5ac5bab7daaf | 69 | * must be public because it is used during delegation |
| hlipka | 2:5ac5bab7daaf | 70 | * |
| hlipka | 2:5ac5bab7daaf | 71 | * @param column The horizontal position from the left, indexed from 0 |
| hlipka | 2:5ac5bab7daaf | 72 | * @param row The vertical position from the top, indexed from 0 |
| hlipka | 2:5ac5bab7daaf | 73 | * @param c the character |
| hlipka | 2:5ac5bab7daaf | 74 | */ |
| hlipka | 2:5ac5bab7daaf | 75 | virtual void character(int column, int row, int c)=0; |
| hlipka | 2:5ac5bab7daaf | 76 | |
| hlipka | 2:5ac5bab7daaf | 77 | #if DOXYGEN_ONLY |
| hlipka | 3:e5d5e2fe4bf6 | 78 | /** |
| hlipka | 2:5ac5bab7daaf | 79 | * Write a character to the LCD, on the position specified by the cursor |
| hlipka | 2:5ac5bab7daaf | 80 | * sets the cursor to the next position, and wraps (from right to left, next line, and from bottom back to top) |
| hlipka | 2:5ac5bab7daaf | 81 | * |
| hlipka | 2:5ac5bab7daaf | 82 | * @param c The character to write to the display |
| hlipka | 2:5ac5bab7daaf | 83 | */ |
| hlipka | 2:5ac5bab7daaf | 84 | int putc(int c); |
| hlipka | 2:5ac5bab7daaf | 85 | |
| hlipka | 3:e5d5e2fe4bf6 | 86 | /** |
| hlipka | 2:5ac5bab7daaf | 87 | * Write a formated string to the LCD, on the position specified by the cursor |
| hlipka | 2:5ac5bab7daaf | 88 | * does wrap around (as specified by putc) |
| hlipka | 2:5ac5bab7daaf | 89 | * |
| hlipka | 2:5ac5bab7daaf | 90 | * @param format A printf-style format string, followed by the |
| hlipka | 2:5ac5bab7daaf | 91 | * variables to use in formating the string. |
| hlipka | 2:5ac5bab7daaf | 92 | */ |
| hlipka | 2:5ac5bab7daaf | 93 | int printf(const char* format, ...); |
| hlipka | 2:5ac5bab7daaf | 94 | #endif |
| hlipka | 2:5ac5bab7daaf | 95 | protected: |
| hlipka | 3:e5d5e2fe4bf6 | 96 | /** |
| hlipka | 3:e5d5e2fe4bf6 | 97 | * base constructor |
| hlipka | 3:e5d5e2fe4bf6 | 98 | * initializes the _guard semaphore needed for syncing parallel writes |
| hlipka | 3:e5d5e2fe4bf6 | 99 | */ |
| hlipka | 3:e5d5e2fe4bf6 | 100 | Window(); |
| hlipka | 3:e5d5e2fe4bf6 | 101 | |
| hlipka | 2:5ac5bab7daaf | 102 | // Stream implementation functions |
| hlipka | 2:5ac5bab7daaf | 103 | virtual int _putc(int value); |
| hlipka | 2:5ac5bab7daaf | 104 | virtual int _getc() { |
| hlipka | 2:5ac5bab7daaf | 105 | return -1; |
| hlipka | 2:5ac5bab7daaf | 106 | }; |
| hlipka | 2:5ac5bab7daaf | 107 | |
| hlipka | 2:5ac5bab7daaf | 108 | int _column; |
| hlipka | 2:5ac5bab7daaf | 109 | int _row; |
| hlipka | 3:e5d5e2fe4bf6 | 110 | |
| hlipka | 3:e5d5e2fe4bf6 | 111 | Semaphore *_guard; |
| hlipka | 0:ae5037e3d6e0 | 112 | }; |
| hlipka | 0:ae5037e3d6e0 | 113 | |
| hlipka | 0:ae5037e3d6e0 | 114 | #endif /*WINDOW_H_*/ |
