Microbug / MicroBitDAL_SB2_TEST

Fork of MicroBitDALImageRewrite by Joe Finney

Committer:
finneyj
Date:
Thu Apr 16 13:50:24 2015 +0000
Revision:
1:3e0360107f98
Parent:
0:47d8ba08580f
Child:
4:f998ee705a20
Updates to include:; ;   - Asynchronous Scrolltext();   - First iteration of MessageBus implementation;   - Hardware configuration for SquareBoard protoype

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