No Changes
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
inc/drivers/MicroBitDisplay.h@20:ad2a5c7debf4, 2016-07-13 (annotated)
- Committer:
- LancasterUniversity
- Date:
- Wed Jul 13 12:17:51 2016 +0100
- Revision:
- 20:ad2a5c7debf4
- Parent:
- 1:8aa5cdb4ab67
- Child:
- 21:cab56b701601
Synchronized with git rev 94e2c661
Author: Joe Finney
microbit: Additional optional autoClear parameter to MicroBitDisplay::animate
The MicroBitDisplay::animate() and MicroBitDisplayAnimateAsync() function both
assumed that the display should be cleared once the requested animation was
complete.
This patch allows the user to control this funcitonality through an
addiitonal, optional boolean parameter to the animate() and animateAsync()
functions.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
1:8aa5cdb4ab67 | 1 | /* |
Jonathan Austin |
1:8aa5cdb4ab67 | 2 | The MIT License (MIT) |
Jonathan Austin |
1:8aa5cdb4ab67 | 3 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
Jonathan Austin |
1:8aa5cdb4ab67 | 6 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
Jonathan Austin |
1:8aa5cdb4ab67 | 8 | copy of this software and associated documentation files (the "Software"), |
Jonathan Austin |
1:8aa5cdb4ab67 | 9 | to deal in the Software without restriction, including without limitation |
Jonathan Austin |
1:8aa5cdb4ab67 | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Jonathan Austin |
1:8aa5cdb4ab67 | 11 | and/or sell copies of the Software, and to permit persons to whom the |
Jonathan Austin |
1:8aa5cdb4ab67 | 12 | Software is furnished to do so, subject to the following conditions: |
Jonathan Austin |
1:8aa5cdb4ab67 | 13 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 14 | The above copyright notice and this permission notice shall be included in |
Jonathan Austin |
1:8aa5cdb4ab67 | 15 | all copies or substantial portions of the Software. |
Jonathan Austin |
1:8aa5cdb4ab67 | 16 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Jonathan Austin |
1:8aa5cdb4ab67 | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Jonathan Austin |
1:8aa5cdb4ab67 | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Jonathan Austin |
1:8aa5cdb4ab67 | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
Jonathan Austin |
1:8aa5cdb4ab67 | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 23 | DEALINGS IN THE SOFTWARE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 24 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 25 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 26 | #ifndef MICROBIT_DISPLAY_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 27 | #define MICROBIT_DISPLAY_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 28 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 29 | #include "mbed.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 30 | #include "MicroBitConfig.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 31 | #include "ManagedString.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 32 | #include "MicroBitComponent.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 33 | #include "MicroBitImage.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 34 | #include "MicroBitFont.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 35 | #include "MicroBitMatrixMaps.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 36 | #include "MicroBitLightSensor.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 37 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 38 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 39 | * Event codes raised by MicroBitDisplay |
Jonathan Austin |
1:8aa5cdb4ab67 | 40 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 41 | #define MICROBIT_DISPLAY_EVT_ANIMATION_COMPLETE 1 |
Jonathan Austin |
1:8aa5cdb4ab67 | 42 | #define MICROBIT_DISPLAY_EVT_LIGHT_SENSE 2 |
Jonathan Austin |
1:8aa5cdb4ab67 | 43 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 44 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 45 | // Internal constants |
Jonathan Austin |
1:8aa5cdb4ab67 | 46 | // |
LancasterUniversity | 20:ad2a5c7debf4 | 47 | #define MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR 1 |
Jonathan Austin |
1:8aa5cdb4ab67 | 48 | #define MICROBIT_DISPLAY_SPACING 1 |
Jonathan Austin |
1:8aa5cdb4ab67 | 49 | #define MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH 8 |
Jonathan Austin |
1:8aa5cdb4ab67 | 50 | #define MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS -255 |
Jonathan Austin |
1:8aa5cdb4ab67 | 51 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 52 | enum AnimationMode { |
Jonathan Austin |
1:8aa5cdb4ab67 | 53 | ANIMATION_MODE_NONE, |
Jonathan Austin |
1:8aa5cdb4ab67 | 54 | ANIMATION_MODE_STOPPED, |
Jonathan Austin |
1:8aa5cdb4ab67 | 55 | ANIMATION_MODE_SCROLL_TEXT, |
Jonathan Austin |
1:8aa5cdb4ab67 | 56 | ANIMATION_MODE_PRINT_TEXT, |
Jonathan Austin |
1:8aa5cdb4ab67 | 57 | ANIMATION_MODE_SCROLL_IMAGE, |
Jonathan Austin |
1:8aa5cdb4ab67 | 58 | ANIMATION_MODE_ANIMATE_IMAGE, |
LancasterUniversity | 20:ad2a5c7debf4 | 59 | ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR, |
Jonathan Austin |
1:8aa5cdb4ab67 | 60 | ANIMATION_MODE_PRINT_CHARACTER |
Jonathan Austin |
1:8aa5cdb4ab67 | 61 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 62 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 63 | enum DisplayMode { |
Jonathan Austin |
1:8aa5cdb4ab67 | 64 | DISPLAY_MODE_BLACK_AND_WHITE, |
Jonathan Austin |
1:8aa5cdb4ab67 | 65 | DISPLAY_MODE_GREYSCALE, |
Jonathan Austin |
1:8aa5cdb4ab67 | 66 | DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE |
Jonathan Austin |
1:8aa5cdb4ab67 | 67 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 68 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 69 | enum DisplayRotation { |
Jonathan Austin |
1:8aa5cdb4ab67 | 70 | MICROBIT_DISPLAY_ROTATION_0, |
Jonathan Austin |
1:8aa5cdb4ab67 | 71 | MICROBIT_DISPLAY_ROTATION_90, |
Jonathan Austin |
1:8aa5cdb4ab67 | 72 | MICROBIT_DISPLAY_ROTATION_180, |
Jonathan Austin |
1:8aa5cdb4ab67 | 73 | MICROBIT_DISPLAY_ROTATION_270 |
Jonathan Austin |
1:8aa5cdb4ab67 | 74 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 75 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 76 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 77 | * Class definition for MicroBitDisplay. |
Jonathan Austin |
1:8aa5cdb4ab67 | 78 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 79 | * A MicroBitDisplay represents the LED matrix array on the micro:bit. |
Jonathan Austin |
1:8aa5cdb4ab67 | 80 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 81 | class MicroBitDisplay : public MicroBitComponent |
Jonathan Austin |
1:8aa5cdb4ab67 | 82 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 83 | uint8_t width; |
Jonathan Austin |
1:8aa5cdb4ab67 | 84 | uint8_t height; |
Jonathan Austin |
1:8aa5cdb4ab67 | 85 | uint8_t brightness; |
Jonathan Austin |
1:8aa5cdb4ab67 | 86 | uint8_t strobeRow; |
Jonathan Austin |
1:8aa5cdb4ab67 | 87 | uint8_t rotation; |
Jonathan Austin |
1:8aa5cdb4ab67 | 88 | uint8_t mode; |
Jonathan Austin |
1:8aa5cdb4ab67 | 89 | uint8_t greyscaleBitMsk; |
Jonathan Austin |
1:8aa5cdb4ab67 | 90 | uint8_t timingCount; |
Jonathan Austin |
1:8aa5cdb4ab67 | 91 | uint32_t col_mask; |
Jonathan Austin |
1:8aa5cdb4ab67 | 92 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 93 | Timeout renderTimer; |
Jonathan Austin |
1:8aa5cdb4ab67 | 94 | PortOut *LEDMatrix; |
Jonathan Austin |
1:8aa5cdb4ab67 | 95 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 96 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 97 | // State used by all animation routines. |
Jonathan Austin |
1:8aa5cdb4ab67 | 98 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 99 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 100 | // The animation mode that's currently running (if any) |
Jonathan Austin |
1:8aa5cdb4ab67 | 101 | volatile AnimationMode animationMode; |
Jonathan Austin |
1:8aa5cdb4ab67 | 102 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 103 | // The time in milliseconds between each frame update. |
Jonathan Austin |
1:8aa5cdb4ab67 | 104 | uint16_t animationDelay; |
Jonathan Austin |
1:8aa5cdb4ab67 | 105 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 106 | // The time in milliseconds since the frame update. |
Jonathan Austin |
1:8aa5cdb4ab67 | 107 | uint16_t animationTick; |
Jonathan Austin |
1:8aa5cdb4ab67 | 108 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 109 | // Stop playback of any animations |
Jonathan Austin |
1:8aa5cdb4ab67 | 110 | void stopAnimation(int delay); |
Jonathan Austin |
1:8aa5cdb4ab67 | 111 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 112 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 113 | // State for scrollString() method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 114 | // This is a surprisingly intricate method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 115 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 116 | // The text being displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 117 | ManagedString scrollingText; |
Jonathan Austin |
1:8aa5cdb4ab67 | 118 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 119 | // The index of the character currently being displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 120 | uint16_t scrollingChar; |
Jonathan Austin |
1:8aa5cdb4ab67 | 121 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 122 | // The number of pixels the current character has been shifted on the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 123 | uint8_t scrollingPosition; |
Jonathan Austin |
1:8aa5cdb4ab67 | 124 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 125 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 126 | // State for printString() method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 127 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 128 | // The text being displayed. NULL if no message is scheduled for playback. |
Jonathan Austin |
1:8aa5cdb4ab67 | 129 | // We *could* get some reuse in here with the scroll* variables above, |
Jonathan Austin |
1:8aa5cdb4ab67 | 130 | // but best to keep it clean in case kids try concurrent operation (they will!), |
Jonathan Austin |
1:8aa5cdb4ab67 | 131 | // given the small RAM overhead needed to maintain orthogonality. |
Jonathan Austin |
1:8aa5cdb4ab67 | 132 | ManagedString printingText; |
Jonathan Austin |
1:8aa5cdb4ab67 | 133 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 134 | // The index of the character currently being displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 135 | uint16_t printingChar; |
Jonathan Austin |
1:8aa5cdb4ab67 | 136 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 137 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 138 | // State for scrollImage() method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 139 | // |
Jonathan Austin |
1:8aa5cdb4ab67 | 140 | // The image being displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 141 | MicroBitImage scrollingImage; |
Jonathan Austin |
1:8aa5cdb4ab67 | 142 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 143 | // The number of pixels the image has been shifted on the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 144 | int16_t scrollingImagePosition; |
Jonathan Austin |
1:8aa5cdb4ab67 | 145 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 146 | // The number of pixels the image is shifted on the display in each quantum. |
Jonathan Austin |
1:8aa5cdb4ab67 | 147 | int8_t scrollingImageStride; |
Jonathan Austin |
1:8aa5cdb4ab67 | 148 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 149 | // A pointer to an instance of light sensor, if in use |
Jonathan Austin |
1:8aa5cdb4ab67 | 150 | MicroBitLightSensor* lightSensor; |
Jonathan Austin |
1:8aa5cdb4ab67 | 151 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 152 | // Flag to indicate if image has been rendered to screen yet (or not) |
Jonathan Austin |
1:8aa5cdb4ab67 | 153 | bool scrollingImageRendered; |
Jonathan Austin |
1:8aa5cdb4ab67 | 154 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 155 | const MatrixMap &matrixMap; |
Jonathan Austin |
1:8aa5cdb4ab67 | 156 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 157 | // Internal methods to handle animation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 158 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 159 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 160 | * Periodic callback, that we use to perform any animations we have running. |
Jonathan Austin |
1:8aa5cdb4ab67 | 161 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 162 | void animationUpdate(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 163 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 164 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 165 | * Called by the display in an interval determined by the brightness of the display, to give an impression |
Jonathan Austin |
1:8aa5cdb4ab67 | 166 | * of brightness. |
Jonathan Austin |
1:8aa5cdb4ab67 | 167 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 168 | void renderFinish(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 169 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 170 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 171 | * Translates a bit mask to a bit mask suitable for the nrf PORT0 and PORT1. |
Jonathan Austin |
1:8aa5cdb4ab67 | 172 | * Brightness has two levels on, or off. |
Jonathan Austin |
1:8aa5cdb4ab67 | 173 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 174 | void render(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 175 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 176 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 177 | * Renders the current image, and drops the fourth frame to allow for |
Jonathan Austin |
1:8aa5cdb4ab67 | 178 | * sensors that require the display to operate. |
Jonathan Austin |
1:8aa5cdb4ab67 | 179 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 180 | void renderWithLightSense(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 181 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 182 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 183 | * Translates a bit mask into a timer interrupt that gives the appearence of greyscale. |
Jonathan Austin |
1:8aa5cdb4ab67 | 184 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 185 | void renderGreyscale(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 186 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 187 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 188 | * Internal scrollText update method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 189 | * Shift the screen image by one pixel to the left. If necessary, paste in the next char. |
Jonathan Austin |
1:8aa5cdb4ab67 | 190 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 191 | void updateScrollText(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 192 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 193 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 194 | * Internal printText update method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 195 | * Paste the next character in the string. |
Jonathan Austin |
1:8aa5cdb4ab67 | 196 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 197 | void updatePrintText(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 198 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 199 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 200 | * Internal scrollImage update method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 201 | * Paste the stored bitmap at the appropriate point. |
Jonathan Austin |
1:8aa5cdb4ab67 | 202 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 203 | void updateScrollImage(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 204 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 205 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 206 | * Internal animateImage update method. |
Jonathan Austin |
1:8aa5cdb4ab67 | 207 | * Paste the stored bitmap at the appropriate point and stop on the last frame. |
Jonathan Austin |
1:8aa5cdb4ab67 | 208 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 209 | void updateAnimateImage(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 210 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 211 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 212 | * Broadcasts an event onto the defult EventModel indicating that the |
Jonathan Austin |
1:8aa5cdb4ab67 | 213 | * current animation has completed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 214 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 215 | void sendAnimationCompleteEvent(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 216 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 217 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 218 | * Blocks the current fiber until the display is available (i.e. does not effect is being displayed). |
Jonathan Austin |
1:8aa5cdb4ab67 | 219 | * Animations are queued until their time to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 220 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 221 | void waitForFreeDisplay(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 222 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 223 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 224 | * Blocks the current fiber until the current animation has finished. |
Jonathan Austin |
1:8aa5cdb4ab67 | 225 | * If the scheduler is not running, this call will essentially perform a spinning wait. |
Jonathan Austin |
1:8aa5cdb4ab67 | 226 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 227 | void fiberWait(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 228 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 229 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 230 | * Enables or disables the display entirely, and releases the pins for other uses. |
Jonathan Austin |
1:8aa5cdb4ab67 | 231 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 232 | * @param enableDisplay true to enabled the display, or false to disable it. |
Jonathan Austin |
1:8aa5cdb4ab67 | 233 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 234 | void setEnable(bool enableDisplay); |
Jonathan Austin |
1:8aa5cdb4ab67 | 235 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 236 | public: |
Jonathan Austin |
1:8aa5cdb4ab67 | 237 | // The mutable bitmap buffer being rendered to the LED matrix. |
Jonathan Austin |
1:8aa5cdb4ab67 | 238 | MicroBitImage image; |
Jonathan Austin |
1:8aa5cdb4ab67 | 239 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 240 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 241 | * Constructor. |
Jonathan Austin |
1:8aa5cdb4ab67 | 242 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 243 | * Create a software representation the micro:bit's 5x5 LED matrix. |
Jonathan Austin |
1:8aa5cdb4ab67 | 244 | * The display is initially blank. |
Jonathan Austin |
1:8aa5cdb4ab67 | 245 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 246 | * @param id The id the display should use when sending events on the MessageBus. Defaults to MICROBIT_ID_DISPLAY. |
Jonathan Austin |
1:8aa5cdb4ab67 | 247 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 248 | * @param map The mapping information that relates pin inputs/outputs to physical screen coordinates. |
Jonathan Austin |
1:8aa5cdb4ab67 | 249 | * Defaults to microbitMatrixMap, defined in MicroBitMatrixMaps.h. |
Jonathan Austin |
1:8aa5cdb4ab67 | 250 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 251 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 252 | * MicroBitDisplay display; |
Jonathan Austin |
1:8aa5cdb4ab67 | 253 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 254 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 255 | MicroBitDisplay(uint16_t id = MICROBIT_ID_DISPLAY, const MatrixMap &map = microbitMatrixMap); |
Jonathan Austin |
1:8aa5cdb4ab67 | 256 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 257 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 258 | * Stops any currently running animation, and any that are waiting to be displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 259 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 260 | void stopAnimation(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 261 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 262 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 263 | * Frame update method, invoked periodically to strobe the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 264 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 265 | virtual void systemTick(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 266 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 267 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 268 | * Prints the given character to the display, if it is not in use. |
Jonathan Austin |
1:8aa5cdb4ab67 | 269 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 270 | * @param c The character to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 271 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 272 | * @param delay Optional parameter - the time for which to show the character. Zero displays the character forever, |
Jonathan Austin |
1:8aa5cdb4ab67 | 273 | * or until the Displays next use. |
Jonathan Austin |
1:8aa5cdb4ab67 | 274 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 275 | * @return MICROBIT_OK, MICROBIT_BUSY is the screen is in use, or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 276 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 277 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 278 | * display.printAsync('p'); |
Jonathan Austin |
1:8aa5cdb4ab67 | 279 | * display.printAsync('p',100); |
Jonathan Austin |
1:8aa5cdb4ab67 | 280 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 281 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 282 | int printCharAsync(char c, int delay = 0); |
Jonathan Austin |
1:8aa5cdb4ab67 | 283 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 284 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 285 | * Prints the given ManagedString to the display, one character at a time. |
Jonathan Austin |
1:8aa5cdb4ab67 | 286 | * Returns immediately, and executes the animation asynchronously. |
Jonathan Austin |
1:8aa5cdb4ab67 | 287 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 288 | * @param s The string to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 289 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 290 | * @param delay The time to delay between characters, in milliseconds. Must be > 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 291 | * Defaults to: MICROBIT_DEFAULT_PRINT_SPEED. |
Jonathan Austin |
1:8aa5cdb4ab67 | 292 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 293 | * @return MICROBIT_OK, or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 294 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 295 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 296 | * display.printAsync("abc123",400); |
Jonathan Austin |
1:8aa5cdb4ab67 | 297 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 298 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 299 | int printAsync(ManagedString s, int delay = MICROBIT_DEFAULT_PRINT_SPEED); |
Jonathan Austin |
1:8aa5cdb4ab67 | 300 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 301 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 302 | * Prints the given image to the display, if the display is not in use. |
Jonathan Austin |
1:8aa5cdb4ab67 | 303 | * Returns immediately, and executes the animation asynchronously. |
Jonathan Austin |
1:8aa5cdb4ab67 | 304 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 305 | * @param i The image to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 306 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 307 | * @param x The horizontal position on the screen to display the image. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 308 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 309 | * @param y The vertical position on the screen to display the image. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 310 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 311 | * @param alpha Treats the brightness level '0' as transparent. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 312 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 313 | * @param delay The time to delay between characters, in milliseconds. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 314 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 315 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 316 | * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n"); |
Jonathan Austin |
1:8aa5cdb4ab67 | 317 | * display.print(i,400); |
Jonathan Austin |
1:8aa5cdb4ab67 | 318 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 319 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 320 | int printAsync(MicroBitImage i, int x = 0, int y = 0, int alpha = 0, int delay = 0); |
Jonathan Austin |
1:8aa5cdb4ab67 | 321 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 322 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 323 | * Prints the given character to the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 324 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 325 | * @param c The character to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 326 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 327 | * @param delay Optional parameter - the time for which to show the character. Zero displays the character forever, |
Jonathan Austin |
1:8aa5cdb4ab67 | 328 | * or until the Displays next use. |
Jonathan Austin |
1:8aa5cdb4ab67 | 329 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 330 | * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 331 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 332 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 333 | * display.printAsync('p'); |
Jonathan Austin |
1:8aa5cdb4ab67 | 334 | * display.printAsync('p',100); |
Jonathan Austin |
1:8aa5cdb4ab67 | 335 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 336 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 337 | int printChar(char c, int delay = 0); |
Jonathan Austin |
1:8aa5cdb4ab67 | 338 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 339 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 340 | * Prints the given string to the display, one character at a time. |
Jonathan Austin |
1:8aa5cdb4ab67 | 341 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 342 | * Blocks the calling thread until all the text has been displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 343 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 344 | * @param s The string to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 345 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 346 | * @param delay The time to delay between characters, in milliseconds. Defaults |
Jonathan Austin |
1:8aa5cdb4ab67 | 347 | * to: MICROBIT_DEFAULT_PRINT_SPEED. |
Jonathan Austin |
1:8aa5cdb4ab67 | 348 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 349 | * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 350 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 351 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 352 | * display.print("abc123",400); |
Jonathan Austin |
1:8aa5cdb4ab67 | 353 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 354 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 355 | int print(ManagedString s, int delay = MICROBIT_DEFAULT_PRINT_SPEED); |
Jonathan Austin |
1:8aa5cdb4ab67 | 356 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 357 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 358 | * Prints the given image to the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 359 | * Blocks the calling thread until all the image has been displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 360 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 361 | * @param i The image to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 362 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 363 | * @param x The horizontal position on the screen to display the image. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 364 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 365 | * @param y The vertical position on the screen to display the image. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 366 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 367 | * @param alpha Treats the brightness level '0' as transparent. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 368 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 369 | * @param delay The time to display the image for, or zero to show the image forever. Defaults to 0. |
Jonathan Austin |
1:8aa5cdb4ab67 | 370 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 371 | * @return MICROBIT_OK, MICROBIT_BUSY if the display is already in use, or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 372 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 373 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 374 | * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n"); |
Jonathan Austin |
1:8aa5cdb4ab67 | 375 | * display.print(i,400); |
Jonathan Austin |
1:8aa5cdb4ab67 | 376 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 377 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 378 | int print(MicroBitImage i, int x = 0, int y = 0, int alpha = 0, int delay = 0); |
Jonathan Austin |
1:8aa5cdb4ab67 | 379 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 380 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 381 | * Scrolls the given string to the display, from right to left. |
Jonathan Austin |
1:8aa5cdb4ab67 | 382 | * Returns immediately, and executes the animation asynchronously. |
Jonathan Austin |
1:8aa5cdb4ab67 | 383 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 384 | * @param s The string to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 385 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 386 | * @param delay The time to delay between characters, in milliseconds. Defaults |
Jonathan Austin |
1:8aa5cdb4ab67 | 387 | * to: MICROBIT_DEFAULT_SCROLL_SPEED. |
Jonathan Austin |
1:8aa5cdb4ab67 | 388 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 389 | * @return MICROBIT_OK, MICROBIT_BUSY if the display is already in use, or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 390 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 391 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 392 | * display.scrollAsync("abc123",100); |
Jonathan Austin |
1:8aa5cdb4ab67 | 393 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 394 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 395 | int scrollAsync(ManagedString s, int delay = MICROBIT_DEFAULT_SCROLL_SPEED); |
Jonathan Austin |
1:8aa5cdb4ab67 | 396 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 397 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 398 | * Scrolls the given image across the display, from right to left. |
Jonathan Austin |
1:8aa5cdb4ab67 | 399 | * Returns immediately, and executes the animation asynchronously. |
Jonathan Austin |
1:8aa5cdb4ab67 | 400 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 401 | * @param image The image to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 402 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 403 | * @param delay The time between updates, in milliseconds. Defaults |
Jonathan Austin |
1:8aa5cdb4ab67 | 404 | * to: MICROBIT_DEFAULT_SCROLL_SPEED. |
Jonathan Austin |
1:8aa5cdb4ab67 | 405 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 406 | * @param stride The number of pixels to shift by in each update. Defaults to MICROBIT_DEFAULT_SCROLL_STRIDE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 407 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 408 | * @return MICROBIT_OK, MICROBIT_BUSY if the display is already in use, or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 409 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 410 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 411 | * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n"); |
Jonathan Austin |
1:8aa5cdb4ab67 | 412 | * display.scrollAsync(i,100,1); |
Jonathan Austin |
1:8aa5cdb4ab67 | 413 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 414 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 415 | int scrollAsync(MicroBitImage image, int delay = MICROBIT_DEFAULT_SCROLL_SPEED, int stride = MICROBIT_DEFAULT_SCROLL_STRIDE); |
Jonathan Austin |
1:8aa5cdb4ab67 | 416 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 417 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 418 | * Scrolls the given string across the display, from right to left. |
Jonathan Austin |
1:8aa5cdb4ab67 | 419 | * Blocks the calling thread until all text has been displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 420 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 421 | * @param s The string to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 422 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 423 | * @param delay The time to delay between characters, in milliseconds. Defaults |
Jonathan Austin |
1:8aa5cdb4ab67 | 424 | * to: MICROBIT_DEFAULT_SCROLL_SPEED. |
Jonathan Austin |
1:8aa5cdb4ab67 | 425 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 426 | * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 427 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 428 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 429 | * display.scroll("abc123",100); |
Jonathan Austin |
1:8aa5cdb4ab67 | 430 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 431 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 432 | int scroll(ManagedString s, int delay = MICROBIT_DEFAULT_SCROLL_SPEED); |
Jonathan Austin |
1:8aa5cdb4ab67 | 433 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 434 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 435 | * Scrolls the given image across the display, from right to left. |
Jonathan Austin |
1:8aa5cdb4ab67 | 436 | * Blocks the calling thread until all the text has been displayed. |
Jonathan Austin |
1:8aa5cdb4ab67 | 437 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 438 | * @param image The image to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 439 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 440 | * @param delay The time between updates, in milliseconds. Defaults |
Jonathan Austin |
1:8aa5cdb4ab67 | 441 | * to: MICROBIT_DEFAULT_SCROLL_SPEED. |
Jonathan Austin |
1:8aa5cdb4ab67 | 442 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 443 | * @param stride The number of pixels to shift by in each update. Defaults to MICROBIT_DEFAULT_SCROLL_STRIDE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 444 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 445 | * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 446 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 447 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 448 | * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n"); |
Jonathan Austin |
1:8aa5cdb4ab67 | 449 | * display.scroll(i,100,1); |
Jonathan Austin |
1:8aa5cdb4ab67 | 450 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 451 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 452 | int scroll(MicroBitImage image, int delay = MICROBIT_DEFAULT_SCROLL_SPEED, int stride = MICROBIT_DEFAULT_SCROLL_STRIDE); |
Jonathan Austin |
1:8aa5cdb4ab67 | 453 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 454 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 455 | * "Animates" the current image across the display with a given stride, finishing on the last frame of the animation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 456 | * Returns immediately. |
Jonathan Austin |
1:8aa5cdb4ab67 | 457 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 458 | * @param image The image to display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 459 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 460 | * @param delay The time to delay between each update of the display, in milliseconds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 461 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 462 | * @param stride The number of pixels to shift by in each update. |
Jonathan Austin |
1:8aa5cdb4ab67 | 463 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 464 | * @param startingPosition the starting position on the display for the animation |
Jonathan Austin |
1:8aa5cdb4ab67 | 465 | * to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS. |
Jonathan Austin |
1:8aa5cdb4ab67 | 466 | * |
LancasterUniversity | 20:ad2a5c7debf4 | 467 | * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation. |
LancasterUniversity | 20:ad2a5c7debf4 | 468 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 469 | * @return MICROBIT_OK, MICROBIT_BUSY if the screen is in use, or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 470 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 471 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 472 | * const int heart_w = 10; |
Jonathan Austin |
1:8aa5cdb4ab67 | 473 | * const int heart_h = 5; |
Jonathan Austin |
1:8aa5cdb4ab67 | 474 | * const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 475 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 476 | * MicroBitImage i(heart_w,heart_h,heart); |
Jonathan Austin |
1:8aa5cdb4ab67 | 477 | * display.animateAsync(i,100,5); |
Jonathan Austin |
1:8aa5cdb4ab67 | 478 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 479 | */ |
LancasterUniversity | 20:ad2a5c7debf4 | 480 | int animateAsync(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR); |
Jonathan Austin |
1:8aa5cdb4ab67 | 481 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 482 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 483 | * "Animates" the current image across the display with a given stride, finishing on the last frame of the animation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 484 | * Blocks the calling thread until the animation is complete. |
Jonathan Austin |
1:8aa5cdb4ab67 | 485 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 486 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 487 | * @param delay The time to delay between each update of the display, in milliseconds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 488 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 489 | * @param stride The number of pixels to shift by in each update. |
Jonathan Austin |
1:8aa5cdb4ab67 | 490 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 491 | * @param startingPosition the starting position on the display for the animation |
Jonathan Austin |
1:8aa5cdb4ab67 | 492 | * to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS. |
Jonathan Austin |
1:8aa5cdb4ab67 | 493 | * |
LancasterUniversity | 20:ad2a5c7debf4 | 494 | * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation. |
LancasterUniversity | 20:ad2a5c7debf4 | 495 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 496 | * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER. |
Jonathan Austin |
1:8aa5cdb4ab67 | 497 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 498 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 499 | * const int heart_w = 10; |
Jonathan Austin |
1:8aa5cdb4ab67 | 500 | * const int heart_h = 5; |
Jonathan Austin |
1:8aa5cdb4ab67 | 501 | * const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 502 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 503 | * MicroBitImage i(heart_w,heart_h,heart); |
Jonathan Austin |
1:8aa5cdb4ab67 | 504 | * display.animate(i,100,5); |
Jonathan Austin |
1:8aa5cdb4ab67 | 505 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 506 | */ |
LancasterUniversity | 20:ad2a5c7debf4 | 507 | int animate(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR); |
Jonathan Austin |
1:8aa5cdb4ab67 | 508 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 509 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 510 | * Configures the brightness of the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 511 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 512 | * @param b The brightness to set the brightness to, in the range 0 - 255. |
Jonathan Austin |
1:8aa5cdb4ab67 | 513 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 514 | * @return MICROBIT_OK, or MICROBIT_INVALID_PARAMETER |
Jonathan Austin |
1:8aa5cdb4ab67 | 515 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 516 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 517 | * display.setBrightness(255); //max brightness |
Jonathan Austin |
1:8aa5cdb4ab67 | 518 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 519 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 520 | int setBrightness(int b); |
Jonathan Austin |
1:8aa5cdb4ab67 | 521 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 522 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 523 | * Configures the mode of the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 524 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 525 | * @param mode The mode to swap the display into. One of: DISPLAY_MODE_GREYSCALE, |
Jonathan Austin |
1:8aa5cdb4ab67 | 526 | * DISPLAY_MODE_BLACK_AND_WHITE, DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE |
Jonathan Austin |
1:8aa5cdb4ab67 | 527 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 528 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 529 | * display.setDisplayMode(DISPLAY_MODE_GREYSCALE); //per pixel brightness |
Jonathan Austin |
1:8aa5cdb4ab67 | 530 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 531 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 532 | void setDisplayMode(DisplayMode mode); |
Jonathan Austin |
1:8aa5cdb4ab67 | 533 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 534 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 535 | * Retrieves the mode of the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 536 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 537 | * @return the current mode of the display |
Jonathan Austin |
1:8aa5cdb4ab67 | 538 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 539 | int getDisplayMode(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 540 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 541 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 542 | * Fetches the current brightness of this display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 543 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 544 | * @return the brightness of this display, in the range 0..255. |
Jonathan Austin |
1:8aa5cdb4ab67 | 545 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 546 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 547 | * display.getBrightness(); //the current brightness |
Jonathan Austin |
1:8aa5cdb4ab67 | 548 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 549 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 550 | int getBrightness(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 551 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 552 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 553 | * Rotates the display to the given position. |
Jonathan Austin |
1:8aa5cdb4ab67 | 554 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 555 | * Axis aligned values only. |
Jonathan Austin |
1:8aa5cdb4ab67 | 556 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 557 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 558 | * display.rotateTo(MICROBIT_DISPLAY_ROTATION_180); //rotates 180 degrees from original orientation |
Jonathan Austin |
1:8aa5cdb4ab67 | 559 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 560 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 561 | void rotateTo(DisplayRotation position); |
Jonathan Austin |
1:8aa5cdb4ab67 | 562 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 563 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 564 | * Enables the display, should only be called if the display is disabled. |
Jonathan Austin |
1:8aa5cdb4ab67 | 565 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 566 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 567 | * display.enable(); //Enables the display mechanics |
Jonathan Austin |
1:8aa5cdb4ab67 | 568 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 569 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 570 | * @note Only enables the display if the display is currently disabled. |
Jonathan Austin |
1:8aa5cdb4ab67 | 571 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 572 | void enable(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 573 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 574 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 575 | * Disables the display, which releases control of the GPIO pins used by the display, |
Jonathan Austin |
1:8aa5cdb4ab67 | 576 | * which are exposed on the edge connector. |
Jonathan Austin |
1:8aa5cdb4ab67 | 577 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 578 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 579 | * display.disable(); //disables the display |
Jonathan Austin |
1:8aa5cdb4ab67 | 580 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 581 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 582 | * @note Only disables the display if the display is currently enabled. |
Jonathan Austin |
1:8aa5cdb4ab67 | 583 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 584 | void disable(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 585 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 586 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 587 | * Clears the display of any remaining pixels. |
Jonathan Austin |
1:8aa5cdb4ab67 | 588 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 589 | * `display.image.clear()` can also be used! |
Jonathan Austin |
1:8aa5cdb4ab67 | 590 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 591 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 592 | * display.clear(); //clears the display |
Jonathan Austin |
1:8aa5cdb4ab67 | 593 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 594 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 595 | void clear(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 596 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 597 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 598 | * Updates the font that will be used for display operations. |
Jonathan Austin |
1:8aa5cdb4ab67 | 599 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 600 | * @param font the new font that will be used to render characters. |
Jonathan Austin |
1:8aa5cdb4ab67 | 601 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 602 | * @note DEPRECATED! Please use MicroBitFont::setSystemFont() instead. |
Jonathan Austin |
1:8aa5cdb4ab67 | 603 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 604 | void setFont(MicroBitFont font); |
Jonathan Austin |
1:8aa5cdb4ab67 | 605 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 606 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 607 | * Retrieves the font object used for rendering characters on the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 608 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 609 | * @note DEPRECATED! Please use MicroBitFont::getSystemFont() instead. |
Jonathan Austin |
1:8aa5cdb4ab67 | 610 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 611 | MicroBitFont getFont(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 612 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 613 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 614 | * Captures the bitmap currently being rendered on the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 615 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 616 | * @return a MicroBitImage containing the captured data. |
Jonathan Austin |
1:8aa5cdb4ab67 | 617 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 618 | MicroBitImage screenShot(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 619 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 620 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 621 | * Gives a representative figure of the light level in the current environment |
Jonathan Austin |
1:8aa5cdb4ab67 | 622 | * where are micro:bit is situated. |
Jonathan Austin |
1:8aa5cdb4ab67 | 623 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 624 | * Internally, it constructs an instance of a MicroBitLightSensor if not already configured |
Jonathan Austin |
1:8aa5cdb4ab67 | 625 | * and sets the display mode to DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 626 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 627 | * This also changes the tickPeriod to MICROBIT_LIGHT_SENSOR_TICK_SPEED so |
Jonathan Austin |
1:8aa5cdb4ab67 | 628 | * that the display does not suffer from artifacts. |
Jonathan Austin |
1:8aa5cdb4ab67 | 629 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 630 | * @return an indicative light level in the range 0 - 255. |
Jonathan Austin |
1:8aa5cdb4ab67 | 631 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 632 | * @note this will return 0 on the first call to this method, a light reading |
Jonathan Austin |
1:8aa5cdb4ab67 | 633 | * will be available after the display has activated the light sensor for the |
Jonathan Austin |
1:8aa5cdb4ab67 | 634 | * first time. |
Jonathan Austin |
1:8aa5cdb4ab67 | 635 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 636 | int readLightLevel(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 637 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 638 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 639 | * Destructor for MicroBitDisplay, where we deregister this instance from the array of system components. |
Jonathan Austin |
1:8aa5cdb4ab67 | 640 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 641 | ~MicroBitDisplay(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 642 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 643 | |
LancasterUniversity | 20:ad2a5c7debf4 | 644 | #endif |