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