Microbug / MicroBitDAL_SB2_TEST

Fork of MicroBitDALImageRewrite by Joe Finney

Committer:
finneyj
Date:
Sun Apr 12 17:38:56 2015 +0000
Revision:
0:47d8ba08580f
Child:
1:3e0360107f98
First draft implementation of core functionality. Includes:; ;   - OO model of microBit device.;   - Flexible geometry LD matirx driver.;   - Lazy, instatiation free I/O; ; Please note this code is largely untested.

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