Microbug / MicroBitDAL_SB2_TEST

Fork of MicroBitDALImageRewrite by Joe Finney

Committer:
finneyj
Date:
Sat May 16 22:28:56 2015 +0000
Revision:
5:8bf639bbedb5
Parent:
4:f998ee705a20
Heap corruption bugfix... fixed:; ; - Heap corruption from BLE stack (hangover from BETA online build?); - BLEDevice can't be brought up in static context; - Calling scheduler callback when scheduler not initialised; - Rewrite of MicroBitImage linear bufs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
finneyj 0:47d8ba08580f 1 /**
finneyj 0:47d8ba08580f 2 * Class definition for a MicroBitDisplay.
finneyj 0:47d8ba08580f 3 *
finneyj 0:47d8ba08580f 4 * An MicroBitDisplay represents the LED matrix array on the MicroBit device.
finneyj 0:47d8ba08580f 5 */
finneyj 0:47d8ba08580f 6
finneyj 0:47d8ba08580f 7 #ifndef MICROBIT_DISPLAY_H
finneyj 0:47d8ba08580f 8 #define MICROBIT_DISPLAY_H
finneyj 0:47d8ba08580f 9
finneyj 1:3e0360107f98 10 #define MICROBIT_DISPLAY_REFRESH_PERIOD 0.002
finneyj 4:f998ee705a20 11
finneyj 5:8bf639bbedb5 12 #define MICROBIT_SB2
finneyj 4:f998ee705a20 13
finneyj 1:3e0360107f98 14 #define NO_CONN 0
finneyj 1:3e0360107f98 15
finneyj 1:3e0360107f98 16 #define MICROBIT_DEFAULT_SCROLL_SPEED 50
finneyj 0:47d8ba08580f 17 #define MICROBIT_DEFAULT_BRIGHTNESS 128
finneyj 0:47d8ba08580f 18
finneyj 1:3e0360107f98 19 #ifdef MICROBUG_REFERENCE_DEVICE
finneyj 1:3e0360107f98 20 #define MICROBIT_DISPLAY_ROW_COUNT 5
finneyj 1:3e0360107f98 21 #define MICROBIT_DISPLAY_ROW_PINS P0_0, P0_1, P0_2, P0_3, P0_4
finneyj 0:47d8ba08580f 22 #define MICROBIT_DISPLAY_COLUMN_COUNT 5
finneyj 0:47d8ba08580f 23 #define MICROBIT_DISPLAY_COLUMN_PINS P0_24, P0_25, P0_28, P0_29, P0_30
finneyj 1:3e0360107f98 24 #endif
finneyj 0:47d8ba08580f 25
finneyj 1:3e0360107f98 26 #ifdef MICROBIT_3X9
finneyj 1:3e0360107f98 27 #define MICROBIT_DISPLAY_ROW_COUNT 3
finneyj 1:3e0360107f98 28 #define MICROBIT_DISPLAY_ROW_PINS P0_12, P0_13, P0_14
finneyj 1:3e0360107f98 29 #define MICROBIT_DISPLAY_COLUMN_COUNT 9
finneyj 1:3e0360107f98 30 #define MICROBIT_DISPLAY_COLUMN_PINS P0_15, P0_16, P0_17, P0_18, P0_19, P0_24, P0_25, P0_28, P0_29
finneyj 1:3e0360107f98 31 #endif
finneyj 1:3e0360107f98 32
finneyj 4:f998ee705a20 33 #ifdef MICROBIT_SB1
finneyj 1:3e0360107f98 34 #define MICROBIT_DISPLAY_ROW_COUNT 9
finneyj 1:3e0360107f98 35 #define MICROBIT_DISPLAY_ROW_PINS P0_15, P0_16, P0_17, P0_18, P0_19, P0_24, P0_25, P0_28, P0_29
finneyj 1:3e0360107f98 36 #define MICROBIT_DISPLAY_COLUMN_COUNT 3
finneyj 1:3e0360107f98 37 #define MICROBIT_DISPLAY_COLUMN_PINS P0_12, P0_13, P0_14
finneyj 1:3e0360107f98 38 #endif
finneyj 0:47d8ba08580f 39
finneyj 4:f998ee705a20 40 #ifdef MICROBIT_SB2
finneyj 4:f998ee705a20 41 #define MICROBIT_DISPLAY_ROW_COUNT 3
finneyj 4:f998ee705a20 42 #define MICROBIT_DISPLAY_ROW_PINS P0_13, P0_14, P0_15
finneyj 4:f998ee705a20 43 #define MICROBIT_DISPLAY_COLUMN_COUNT 9
finneyj 4:f998ee705a20 44 #define MICROBIT_DISPLAY_COLUMN_PINS P0_4, P0_5, P0_6, P0_7, P0_8, P0_9, P0_10, P0_11, P0_12
finneyj 4:f998ee705a20 45 #endif
finneyj 4:f998ee705a20 46
finneyj 0:47d8ba08580f 47 #include "mbed.h"
finneyj 0:47d8ba08580f 48 #include "MicroBitImage.h"
finneyj 0:47d8ba08580f 49
finneyj 0:47d8ba08580f 50 struct MatrixPoint
finneyj 0:47d8ba08580f 51 {
finneyj 0:47d8ba08580f 52 int x;
finneyj 0:47d8ba08580f 53 int y;
finneyj 0:47d8ba08580f 54
finneyj 0:47d8ba08580f 55 MatrixPoint(int x, int y);
finneyj 0:47d8ba08580f 56 };
finneyj 0:47d8ba08580f 57
finneyj 0:47d8ba08580f 58 class MicroBitDisplay
finneyj 0:47d8ba08580f 59 {
finneyj 0:47d8ba08580f 60 int id;
finneyj 1:3e0360107f98 61 int width;
finneyj 1:3e0360107f98 62 int height;
finneyj 0:47d8ba08580f 63 int brightness;
finneyj 0:47d8ba08580f 64 int strobeRow;
finneyj 0:47d8ba08580f 65 Ticker strobe;
finneyj 0:47d8ba08580f 66 BusOut columnPins;
finneyj 0:47d8ba08580f 67 BusOut rowPins;
finneyj 1:3e0360107f98 68
finneyj 1:3e0360107f98 69 char *scrollingText;
finneyj 1:3e0360107f98 70 int scrollTextLength;
finneyj 1:3e0360107f98 71 int scrollingChar;
finneyj 1:3e0360107f98 72 int scrollingPosition;
finneyj 1:3e0360107f98 73 int scrollingDelay;
finneyj 1:3e0360107f98 74 int scrollingTick;
finneyj 1:3e0360107f98 75
finneyj 0:47d8ba08580f 76 static const MatrixPoint matrixMap[MICROBIT_DISPLAY_COLUMN_COUNT][MICROBIT_DISPLAY_ROW_COUNT];
finneyj 0:47d8ba08580f 77
finneyj 1:3e0360107f98 78 void updateScroll();
finneyj 1:3e0360107f98 79
finneyj 0:47d8ba08580f 80 public:
finneyj 0:47d8ba08580f 81 MicroBitImage image;
finneyj 0:47d8ba08580f 82
finneyj 0:47d8ba08580f 83 /**
finneyj 0:47d8ba08580f 84 * Constructor.
finneyj 0:47d8ba08580f 85 * Create a representation of a display of a given size.
finneyj 0:47d8ba08580f 86 * The display is initially blank.
finneyj 0:47d8ba08580f 87 *
finneyj 0:47d8ba08580f 88 * @param x the width of the display in pixels.
finneyj 0:47d8ba08580f 89 * @param y the height of the display in pixels.
finneyj 0:47d8ba08580f 90 */
finneyj 0:47d8ba08580f 91 MicroBitDisplay(int id, int x, int y);
finneyj 0:47d8ba08580f 92
finneyj 0:47d8ba08580f 93 /**
finneyj 0:47d8ba08580f 94 * Frame update method, invoked periodically to strobe the display.
finneyj 0:47d8ba08580f 95 */
finneyj 0:47d8ba08580f 96 void strobeUpdate();
finneyj 0:47d8ba08580f 97
finneyj 0:47d8ba08580f 98 /**
finneyj 5:8bf639bbedb5 99 * Registers the strobeUpdate method with the IRQ handler.
finneyj 5:8bf639bbedb5 100 * Display begins refreshing after this call.
finneyj 5:8bf639bbedb5 101 */
finneyj 5:8bf639bbedb5 102 void startDisplay();
finneyj 5:8bf639bbedb5 103
finneyj 5:8bf639bbedb5 104 /**
finneyj 0:47d8ba08580f 105 * Prints the given character to the display.
finneyj 0:47d8ba08580f 106 *
finneyj 0:47d8ba08580f 107 * @param c The character to display.
finneyj 0:47d8ba08580f 108 */
finneyj 0:47d8ba08580f 109 void print(char c);
finneyj 0:47d8ba08580f 110
finneyj 0:47d8ba08580f 111 /**
finneyj 0:47d8ba08580f 112 * Prints the given string to the display, one character at a time.
finneyj 0:47d8ba08580f 113 * Uses the default delay between characters as defined by DEFAULT_SCROLLTEXT_SPEED.
finneyj 0:47d8ba08580f 114 *
finneyj 0:47d8ba08580f 115 * @param str The string to display.
finneyj 0:47d8ba08580f 116 */
finneyj 0:47d8ba08580f 117 void printString(char *str);
finneyj 0:47d8ba08580f 118
finneyj 0:47d8ba08580f 119 /**
finneyj 0:47d8ba08580f 120 * Prints the given string to the display, one character at a time.
finneyj 0:47d8ba08580f 121 * Uses the given delay between characters.
finneyj 0:47d8ba08580f 122 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 123 *
finneyj 0:47d8ba08580f 124 * @param str The string to display.
finneyj 0:47d8ba08580f 125 * @param delay The time to delay between characters, in milliseconds.
finneyj 0:47d8ba08580f 126 */
finneyj 0:47d8ba08580f 127 void printString(char *str, int delay);
finneyj 0:47d8ba08580f 128
finneyj 0:47d8ba08580f 129 /**
finneyj 0:47d8ba08580f 130 * Scrolls the given string to the display, from right to left.
finneyj 0:47d8ba08580f 131 * Uses the default delay between characters as defined by DEFAULT_SCROLLTEXT_SPEED.
finneyj 0:47d8ba08580f 132 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 133 *
finneyj 0:47d8ba08580f 134 * @param str The string to display.
finneyj 0:47d8ba08580f 135 */
finneyj 0:47d8ba08580f 136 void scrollString(char *str);
finneyj 0:47d8ba08580f 137
finneyj 0:47d8ba08580f 138 /**
finneyj 0:47d8ba08580f 139 * Scrolls the given string to the display, from right to left.
finneyj 0:47d8ba08580f 140 * Uses the given delay between characters.
finneyj 0:47d8ba08580f 141 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 142 *
finneyj 0:47d8ba08580f 143 * @param str The string to display.
finneyj 0:47d8ba08580f 144 * @param delay The time to delay between characters, in milliseconds.
finneyj 0:47d8ba08580f 145 */
finneyj 0:47d8ba08580f 146 void scrollString(char *str, int delay);
finneyj 0:47d8ba08580f 147
finneyj 0:47d8ba08580f 148 /**
finneyj 0:47d8ba08580f 149 * Scrolls the given image across the display, from right to left.
finneyj 0:47d8ba08580f 150 * Uses the default delay between characters as defined by DEFAULT_SCROLLTEXT_SPEED.
finneyj 0:47d8ba08580f 151 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 152 *
finneyj 0:47d8ba08580f 153 * @param image The image to display.
finneyj 0:47d8ba08580f 154 */
finneyj 0:47d8ba08580f 155 void scrollImage(MicroBitImage *image);
finneyj 0:47d8ba08580f 156
finneyj 0:47d8ba08580f 157 /**
finneyj 0:47d8ba08580f 158 * Scrolls the given image across the display, from right to left.
finneyj 0:47d8ba08580f 159 * Uses the given delay between characters.
finneyj 0:47d8ba08580f 160 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 161 *
finneyj 0:47d8ba08580f 162 * @param image The image to display.
finneyj 0:47d8ba08580f 163 * @param delay The time to delay between characters, in milliseconds.
finneyj 0:47d8ba08580f 164 */
finneyj 0:47d8ba08580f 165 void scrollImage(MicroBitImage *image, int delay);
finneyj 0:47d8ba08580f 166
finneyj 0:47d8ba08580f 167 /**
finneyj 0:47d8ba08580f 168 * Sets the display brightness to the specified level.
finneyj 0:47d8ba08580f 169 * @param b The brightness to set the brightness to, in the range 0..255.
finneyj 0:47d8ba08580f 170 */
finneyj 0:47d8ba08580f 171 void setBrightness(int b);
finneyj 0:47d8ba08580f 172
finneyj 0:47d8ba08580f 173 /**
finneyj 0:47d8ba08580f 174 * Tests the brightness of this display.
finneyj 0:47d8ba08580f 175 * @return the brightness of this display, in the range 0..255.
finneyj 0:47d8ba08580f 176 */
finneyj 0:47d8ba08580f 177 int getBrightness();
finneyj 0:47d8ba08580f 178 };
finneyj 0:47d8ba08580f 179
finneyj 0:47d8ba08580f 180 #endif
finneyj 0:47d8ba08580f 181