updates
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal-eddystone by
source/core/MicroBitFont.cpp@1:8aa5cdb4ab67, 2016-04-07 (annotated)
- Committer:
- Jonathan Austin
- Date:
- Thu Apr 07 01:33:22 2016 +0100
- Revision:
- 1:8aa5cdb4ab67
Synchronized with git rev 55cb9199
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 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 27 | * Class definition for a MicrobitFont |
Jonathan Austin |
1:8aa5cdb4ab67 | 28 | * This class represents a font that can be used by the display to render text. |
Jonathan Austin |
1:8aa5cdb4ab67 | 29 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 30 | * A MicroBitFont is 5x5. |
Jonathan Austin |
1:8aa5cdb4ab67 | 31 | * Each Row is represented by a byte in the array. |
Jonathan Austin |
1:8aa5cdb4ab67 | 32 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 33 | * Row Format: |
Jonathan Austin |
1:8aa5cdb4ab67 | 34 | * ================================================================ |
Jonathan Austin |
1:8aa5cdb4ab67 | 35 | * | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 36 | * ================================================================ |
Jonathan Austin |
1:8aa5cdb4ab67 | 37 | * | N/A | N/A | N/A | Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 38 | * | 0x80 | 0x40 | 0x20 | 0x10 | 0x08 | 0x04 | 0x02 | 0x01 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 39 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 40 | * Example: { 0x08, 0x08, 0x08, 0x0, 0x08 } |
Jonathan Austin |
1:8aa5cdb4ab67 | 41 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 42 | * The above will produce an exclaimation mark on the second column in form the left. |
Jonathan Austin |
1:8aa5cdb4ab67 | 43 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 44 | * We could compress further, but the complexity of decode would likely outweigh the gains. |
Jonathan Austin |
1:8aa5cdb4ab67 | 45 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 46 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 47 | #include "MicroBitConfig.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 48 | #include "MicroBitFont.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 49 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 50 | const unsigned char pendolino3[475] = { |
Jonathan Austin |
1:8aa5cdb4ab67 | 51 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x8, 0x8, 0x0, 0x8, 0xa, 0x4a, 0x40, 0x0, 0x0, 0xa, 0x5f, 0xea, 0x5f, 0xea, 0xe, 0xd9, 0x2e, 0xd3, 0x6e, 0x19, 0x32, 0x44, 0x89, 0x33, 0xc, 0x92, 0x4c, 0x92, 0x4d, 0x8, 0x8, 0x0, 0x0, 0x0, 0x4, 0x88, 0x8, 0x8, 0x4, 0x8, 0x4, 0x84, 0x84, 0x88, 0x0, 0xa, 0x44, 0x8a, 0x40, 0x0, 0x4, 0x8e, 0xc4, 0x80, 0x0, 0x0, 0x0, 0x4, 0x88, 0x0, 0x0, 0xe, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0,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x86, 0x8, 0x8, 0x8, 0x8, 0x8, 0x18, 0x8, 0xc, 0x88, 0x18, 0x0, 0x0, 0xc, 0x83, 0x60}; |
Jonathan Austin |
1:8aa5cdb4ab67 | 52 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 53 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 54 | const unsigned char* MicroBitFont::defaultFont = pendolino3; |
Jonathan Austin |
1:8aa5cdb4ab67 | 55 | MicroBitFont MicroBitFont::systemFont = MicroBitFont(defaultFont, MICROBIT_FONT_ASCII_END); |
Jonathan Austin |
1:8aa5cdb4ab67 | 56 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 57 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 58 | * Constructor. |
Jonathan Austin |
1:8aa5cdb4ab67 | 59 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 60 | * Sets the font represented by this font object. |
Jonathan Austin |
1:8aa5cdb4ab67 | 61 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 62 | * @param font A pointer to the beginning of the new font. |
Jonathan Austin |
1:8aa5cdb4ab67 | 63 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 64 | * @param asciiEnd the char value at which this font finishes. |
Jonathan Austin |
1:8aa5cdb4ab67 | 65 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 66 | MicroBitFont::MicroBitFont(const unsigned char* characters, int asciiEnd) |
Jonathan Austin |
1:8aa5cdb4ab67 | 67 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 68 | this->characters = characters; |
Jonathan Austin |
1:8aa5cdb4ab67 | 69 | this->asciiEnd = asciiEnd; |
Jonathan Austin |
1:8aa5cdb4ab67 | 70 | } |
Jonathan Austin |
1:8aa5cdb4ab67 | 71 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 72 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 73 | * Default Constructor. |
Jonathan Austin |
1:8aa5cdb4ab67 | 74 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 75 | * Configures the default font for the display to use. |
Jonathan Austin |
1:8aa5cdb4ab67 | 76 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 77 | MicroBitFont::MicroBitFont() |
Jonathan Austin |
1:8aa5cdb4ab67 | 78 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 79 | this->characters = defaultFont; |
Jonathan Austin |
1:8aa5cdb4ab67 | 80 | this->asciiEnd = MICROBIT_FONT_ASCII_END; |
Jonathan Austin |
1:8aa5cdb4ab67 | 81 | } |
Jonathan Austin |
1:8aa5cdb4ab67 | 82 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 83 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 84 | * Modifies the current system font to the given instance of MicroBitFont. |
Jonathan Austin |
1:8aa5cdb4ab67 | 85 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 86 | * @param font the new font that will be used to render characters on the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 87 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 88 | void MicroBitFont::setSystemFont(MicroBitFont font) |
Jonathan Austin |
1:8aa5cdb4ab67 | 89 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 90 | MicroBitFont::systemFont = font; |
Jonathan Austin |
1:8aa5cdb4ab67 | 91 | } |
Jonathan Austin |
1:8aa5cdb4ab67 | 92 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 93 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 94 | * Retreives the font object used for rendering characters on the display. |
Jonathan Austin |
1:8aa5cdb4ab67 | 95 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 96 | MicroBitFont MicroBitFont::getSystemFont() |
Jonathan Austin |
1:8aa5cdb4ab67 | 97 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 98 | return MicroBitFont::systemFont; |
Jonathan Austin |
1:8aa5cdb4ab67 | 99 | } |