Microbug / MicroBitDAL_SB2_TEST

Fork of MicroBitDALImageRewrite by Joe Finney

Committer:
finneyj
Date:
Fri May 15 22:23:17 2015 +0000
Revision:
4:f998ee705a20
Parent:
1:3e0360107f98
Child:
5:8bf639bbedb5
SB2 support and minor bugfixes

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 4:f998ee705a20 12 #define MICROBIT_SB1
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
finneyj 0:47d8ba08580f 59 class MicroBitDisplay
finneyj 0:47d8ba08580f 60 {
finneyj 0:47d8ba08580f 61 int id;
finneyj 1:3e0360107f98 62 int width;
finneyj 1:3e0360107f98 63 int height;
finneyj 0:47d8ba08580f 64 int brightness;
finneyj 0:47d8ba08580f 65 int strobeRow;
finneyj 0:47d8ba08580f 66 Ticker strobe;
finneyj 0:47d8ba08580f 67 BusOut columnPins;
finneyj 0:47d8ba08580f 68 BusOut rowPins;
finneyj 1:3e0360107f98 69
finneyj 1:3e0360107f98 70 char *scrollingText;
finneyj 1:3e0360107f98 71 int scrollTextLength;
finneyj 1:3e0360107f98 72 int scrollingChar;
finneyj 1:3e0360107f98 73 int scrollingPosition;
finneyj 1:3e0360107f98 74 int scrollingDelay;
finneyj 1:3e0360107f98 75 int scrollingTick;
finneyj 1:3e0360107f98 76
finneyj 0:47d8ba08580f 77 static const MatrixPoint matrixMap[MICROBIT_DISPLAY_COLUMN_COUNT][MICROBIT_DISPLAY_ROW_COUNT];
finneyj 0:47d8ba08580f 78
finneyj 1:3e0360107f98 79 void updateScroll();
finneyj 1:3e0360107f98 80
finneyj 0:47d8ba08580f 81 public:
finneyj 0:47d8ba08580f 82 MicroBitImage image;
finneyj 0:47d8ba08580f 83
finneyj 0:47d8ba08580f 84 /**
finneyj 0:47d8ba08580f 85 * Constructor.
finneyj 0:47d8ba08580f 86 * Create a representation of a display of a given size.
finneyj 0:47d8ba08580f 87 * The display is initially blank.
finneyj 0:47d8ba08580f 88 *
finneyj 0:47d8ba08580f 89 * @param x the width of the display in pixels.
finneyj 0:47d8ba08580f 90 * @param y the height of the display in pixels.
finneyj 0:47d8ba08580f 91 */
finneyj 0:47d8ba08580f 92 MicroBitDisplay(int id, int x, int y);
finneyj 0:47d8ba08580f 93
finneyj 0:47d8ba08580f 94 /**
finneyj 0:47d8ba08580f 95 * Frame update method, invoked periodically to strobe the display.
finneyj 0:47d8ba08580f 96 */
finneyj 0:47d8ba08580f 97 void strobeUpdate();
finneyj 0:47d8ba08580f 98
finneyj 0:47d8ba08580f 99 /**
finneyj 0:47d8ba08580f 100 * Prints the given character to the display.
finneyj 0:47d8ba08580f 101 *
finneyj 0:47d8ba08580f 102 * @param c The character to display.
finneyj 0:47d8ba08580f 103 */
finneyj 0:47d8ba08580f 104 void print(char c);
finneyj 0:47d8ba08580f 105
finneyj 0:47d8ba08580f 106 /**
finneyj 0:47d8ba08580f 107 * Prints the given string to the display, one character at a time.
finneyj 0:47d8ba08580f 108 * Uses the default delay between characters as defined by DEFAULT_SCROLLTEXT_SPEED.
finneyj 0:47d8ba08580f 109 *
finneyj 0:47d8ba08580f 110 * @param str The string to display.
finneyj 0:47d8ba08580f 111 */
finneyj 0:47d8ba08580f 112 void printString(char *str);
finneyj 0:47d8ba08580f 113
finneyj 0:47d8ba08580f 114 /**
finneyj 0:47d8ba08580f 115 * Prints the given string to the display, one character at a time.
finneyj 0:47d8ba08580f 116 * Uses the given delay between characters.
finneyj 0:47d8ba08580f 117 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 118 *
finneyj 0:47d8ba08580f 119 * @param str The string to display.
finneyj 0:47d8ba08580f 120 * @param delay The time to delay between characters, in milliseconds.
finneyj 0:47d8ba08580f 121 */
finneyj 0:47d8ba08580f 122 void printString(char *str, int delay);
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 default delay between characters as defined by DEFAULT_SCROLLTEXT_SPEED.
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 */
finneyj 0:47d8ba08580f 131 void scrollString(char *str);
finneyj 0:47d8ba08580f 132
finneyj 0:47d8ba08580f 133 /**
finneyj 0:47d8ba08580f 134 * Scrolls the given string to the display, from right to left.
finneyj 0:47d8ba08580f 135 * Uses the given delay between characters.
finneyj 0:47d8ba08580f 136 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 137 *
finneyj 0:47d8ba08580f 138 * @param str The string to display.
finneyj 0:47d8ba08580f 139 * @param delay The time to delay between characters, in milliseconds.
finneyj 0:47d8ba08580f 140 */
finneyj 0:47d8ba08580f 141 void scrollString(char *str, int delay);
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 default delay between characters as defined by DEFAULT_SCROLLTEXT_SPEED.
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 */
finneyj 0:47d8ba08580f 150 void scrollImage(MicroBitImage *image);
finneyj 0:47d8ba08580f 151
finneyj 0:47d8ba08580f 152 /**
finneyj 0:47d8ba08580f 153 * Scrolls the given image across the display, from right to left.
finneyj 0:47d8ba08580f 154 * Uses the given delay between characters.
finneyj 0:47d8ba08580f 155 * Blocks the calling thread until all the text has been displayed.
finneyj 0:47d8ba08580f 156 *
finneyj 0:47d8ba08580f 157 * @param image The image to display.
finneyj 0:47d8ba08580f 158 * @param delay The time to delay between characters, in milliseconds.
finneyj 0:47d8ba08580f 159 */
finneyj 0:47d8ba08580f 160 void scrollImage(MicroBitImage *image, int delay);
finneyj 0:47d8ba08580f 161
finneyj 0:47d8ba08580f 162 /**
finneyj 0:47d8ba08580f 163 * Sets the display brightness to the specified level.
finneyj 0:47d8ba08580f 164 * @param b The brightness to set the brightness to, in the range 0..255.
finneyj 0:47d8ba08580f 165 */
finneyj 0:47d8ba08580f 166 void setBrightness(int b);
finneyj 0:47d8ba08580f 167
finneyj 0:47d8ba08580f 168 /**
finneyj 0:47d8ba08580f 169 * Tests the brightness of this display.
finneyj 0:47d8ba08580f 170 * @return the brightness of this display, in the range 0..255.
finneyj 0:47d8ba08580f 171 */
finneyj 0:47d8ba08580f 172 int getBrightness();
finneyj 0:47d8ba08580f 173 };
finneyj 0:47d8ba08580f 174
finneyj 0:47d8ba08580f 175 #endif
finneyj 0:47d8ba08580f 176